signalk-parquet
Version:
SignalK plugin to save marine data directly to Parquet files with regimen-based control
296 lines • 7.93 kB
TypeScript
import { ServerAPI } from '@signalk/server-api';
import { PluginState } from './types';
import { VesselContextManager } from './vessel-context';
export interface ClaudeAnalyzerConfig {
apiKey: string;
model: 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514';
maxTokens: number;
temperature: number;
}
export interface AnalysisRequest {
dataPath: string;
analysisType: 'summary' | 'anomaly' | 'trend' | 'correlation' | 'custom';
timeRange?: {
start: Date;
end: Date;
};
customPrompt?: string;
context?: Record<string, any>;
aggregationMethod?: string;
resolution?: string;
useDatabaseAccess?: boolean;
}
export interface FollowUpRequest {
conversationId: string;
question: string;
}
export interface AnomalyDetection {
timestamp: string;
value: any;
expectedRange: {
min: number;
max: number;
};
severity: 'low' | 'medium' | 'high';
description: string;
confidence: number;
}
export interface AnalysisResponse {
id: string;
analysis: string;
insights: string[];
recommendations?: string[];
anomalies?: AnomalyDetection[];
confidence: number;
dataQuality: string;
timestamp: string;
usage?: {
input_tokens: number;
output_tokens: number;
};
metadata: {
dataPath: string;
analysisType: string;
recordCount: number;
timeRange?: {
start: Date;
end: Date;
};
useDatabaseAccess?: boolean;
};
}
export interface DataSummary {
rowCount: number;
timeRange: {
start: Date;
end: Date;
};
columns: ColumnInfo[];
statisticalSummary: Record<string, Statistics>;
dataQuality: DataQualityMetrics;
}
export interface ColumnInfo {
name: string;
type: string;
nullCount: number;
uniqueCount: number;
sampleValues: any[];
}
export interface Statistics {
count: number;
mean?: number;
median?: number;
min?: any;
max?: any;
stdDev?: number;
}
export interface DataQualityMetrics {
completeness: number;
consistency: number;
timeliness: number;
accuracy: number;
}
export interface AvailablePathsFilter {
vesselContext?: string;
pathPattern?: string;
source?: string;
hasValue?: boolean;
includeMetadata?: boolean;
maxDepth?: number;
}
export interface AvailablePathInfo {
path: string;
fullPath: string;
vesselId?: string;
currentValue?: any;
source?: string;
lastUpdate?: string;
}
export declare class ClaudeAnalyzer {
private client;
private config;
private app?;
private dataDirectory?;
private vesselContextManager;
private activeConversations;
private state?;
constructor(config: ClaudeAnalyzerConfig, app?: ServerAPI, dataDirectory?: string, state?: PluginState);
/**
* Main analysis method - analyzes data and returns structured insights
*/
analyzeData(request: AnalysisRequest): Promise<AnalysisResponse>;
/**
* Quick analysis using predefined templates
*/
quickAnalysis(dataPath: string, analysisType: string, timeRange?: {
start: Date;
end: Date;
}): Promise<AnalysisResponse>;
/**
* Detect anomalies in the data
*/
detectAnomalies(dataPath: string, timeRange?: {
start: Date;
end: Date;
}): Promise<AnomalyDetection[]>;
/**
* Prepare data for analysis - includes sampling and summarization
*/
private prepareDataForAnalysis;
/**
* Load data from parquet files based on path and time range
*/
private loadDataFromPath;
/**
* Generate statistical summary of the data
*/
private generateDataSummary;
/**
* Calculate data quality metrics
*/
private calculateDataQuality;
/**
* Calculate data timeliness based on timestamps
*/
private calculateTimeliness;
/**
* Sample data for analysis to respect Claude token limits
*/
private sampleDataForAnalysis;
/**
* Safely stringify data that may contain BigInt values
*/
private safeStringify;
/**
* Analyze data structure to guide Claude on how to interpret the data
*/
private analyzeDataStructure;
/**
* Build analysis prompt based on data and request type
*/
private buildAnalysisPrompt;
/**
* Parse Claude's analysis response into structured format
*/
private parseAnalysisResponse;
/**
* Extract bullet points from text for insights
*/
private extractBulletPoints;
/**
* Save analysis to history for later retrieval
*/
private saveAnalysisToHistory;
/**
* Get analysis history
*/
getAnalysisHistory(limit?: number): Promise<AnalysisResponse[]>;
/**
* Delete an analysis from history
*/
deleteAnalysis(analysisId: string): Promise<{
success: boolean;
error?: string;
}>;
/**
* Tony's approach: Direct database access analysis
* Claude can query the database interactively during analysis
*/
analyzeWithDatabaseAccess(request: AnalysisRequest): Promise<AnalysisResponse>;
/**
* Call Claude API with retry logic for rate limit and overload errors
*/
private callClaudeWithRetry;
/**
* Continue conversation with follow-up question
*/
askFollowUp(request: FollowUpRequest): Promise<AnalysisResponse>;
/**
* Get all available SignalK sources (for debugging)
*/
private getAvailableSignalKSources;
/**
* Recursively collect unique sources from SignalK data
*/
private collectSources;
/**
* Get available real-time SignalK paths with filtering options
*/
private getAvailableSignalKPaths;
/**
* Recursively traverse SignalK data structure to find available paths
*/
private traverseSignalKPaths;
/**
* Get current real-time SignalK data values
*/
private getCurrentSignalKData;
/**
* Get current data from specific vessel buffers
*/
private getCurrentDataFromBuffers;
/**
* Get current data from all vessel buffers
*/
private getAllVesselsCurrentDataFromBuffers;
/**
* Clean SignalK data by removing functions and circular references
*/
private cleanSignalKData;
/**
* Identify relevant regimens based on user query keywords
*/
private identifyRelevantRegimens;
/**
* Get paths associated with a regimen
*/
private getPathsForRegimen;
/**
* Check if user request contains real-time keywords
*/
private checkForRealTimeKeywords;
/**
* Process a single tool call and return the result
*/
private processToolCall;
/**
* Find episodes for a specific regimen using command state transitions
*/
private findRegimenEpisodes;
/**
* Determine the appropriate column to use based on SignalK path type
*/
private getValueColumn;
/**
* Auto-correct column usage in SQL queries based on SignalK path patterns
*/
private correctColumnUsage;
/**
* Execute SQL query safely against Parquet database
*/
private executeSQLQuery;
/**
* Scan a vessel directory for available SignalK paths
*/
private scanVesselPaths;
/**
* Generate enhanced schema information for Claude
*/
private getEnhancedSchemaForClaude;
/**
* Test Claude API connection
*/
testConnection(): Promise<{
success: boolean;
error?: string;
}>;
/**
* Get vessel context manager
*/
getVesselContextManager(): VesselContextManager;
/**
* Refresh vessel information from SignalK
*/
refreshVesselContext(): Promise<void>;
}
//# sourceMappingURL=claude-analyzer.d.ts.map