analyze_logs
Perform statistical analysis on confirmation history logs by specifying a date range and grouping data by type, success, hour, or day.
Instructions
Perform statistical analysis on confirmation history logs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | No | End date for analysis (ISO 8601 format) | |
| groupBy | No | Group analysis by field | confirmationType |
| startDate | No | Start date for analysis (ISO 8601 format) |
Implementation Reference
- src/index.ts:1250-1291 (handler)Main handler function for the analyze_logs tool. Parses arguments, reads and filters log entries by date, calculates statistics, groups by specified field, formats analysis, and returns formatted text response.private async handleAnalyzeLogs(args: Record<string, unknown>) { try { const startDate = typeof args.startDate === "string" ? args.startDate : undefined; const endDate = typeof args.endDate === "string" ? args.endDate : undefined; const groupBy = typeof args.groupBy === "string" ? args.groupBy : "confirmationType"; const entries = await this.readLogEntries(); const filteredEntries = this.filterByDateRange( entries, startDate, endDate ); const stats = this.calculateBasicStats(filteredEntries); const groupedData = this.groupLogsByField(filteredEntries, groupBy); const groupAnalysis = this.formatGroupAnalysis(groupedData); const analysisText = this.formatAnalysisResult( stats, groupAnalysis, groupBy, startDate, endDate ); return { content: [ { type: "text", text: analysisText, }, ], }; } catch (error) { return this.createErrorResponse( `Log analysis failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:464-490 (schema)Tool definition including name, description, and input schema for date filtering and grouping options.private createAnalyzeLogsTool(): Tool { return { name: "analyze_logs", description: "Perform statistical analysis on confirmation history logs", inputSchema: { type: "object", properties: { startDate: { type: "string", description: "Start date for analysis (ISO 8601 format)", format: "date-time", }, endDate: { type: "string", description: "End date for analysis (ISO 8601 format)", format: "date-time", }, groupBy: { type: "string", description: "Group analysis by field", enum: ["confirmationType", "success", "hour", "day"], default: "confirmationType", }, }, }, }; }
- src/index.ts:231-242 (registration)Tool registration in the list of all available tools returned by getToolDefinitions().private getToolDefinitions(): Tool[] { return [ this.createAskYesNoTool(), this.createConfirmActionTool(), this.createClarifyIntentTool(), this.createVerifyUnderstandingTool(), this.createCollectRatingTool(), this.createElicitCustomTool(), this.createSearchLogsTool(), this.createAnalyzeLogsTool(), ]; }
- src/index.ts:516-537 (registration)Dispatch logic in executeToolCall that routes 'analyze_logs' calls to the handleAnalyzeLogs handler.private async executeToolCall(name: string, args: Record<string, unknown>) { switch (name) { case "ask_yes_no": return await this.handleAskYesNo(args); case "confirm_action": return await this.handleConfirmAction(args); case "clarify_intent": return await this.handleClarifyIntent(args); case "verify_understanding": return await this.handleVerifyUnderstanding(args); case "collect_rating": return await this.handleCollectRating(args); case "elicit_custom": return await this.handleElicitCustom(args); case "search_logs": return await this.handleSearchLogs(args); case "analyze_logs": return await this.handleAnalyzeLogs(args); default: throw new Error(`Unknown tool: ${name}`); } }
- src/index.ts:1383-1418 (helper)Helper function to group log entries by specified field (confirmationType, success, hour, day) used in analysis.private groupLogsByField( entries: ConfirmationLogEntry[], field: string ): Record<string, ConfirmationLogEntry[]> { const groups: Record<string, ConfirmationLogEntry[]> = {}; entries.forEach((entry) => { let key: string; switch (field) { case "confirmationType": key = entry.confirmationType; break; case "success": key = entry.success ? "Success" : "Failed"; break; case "hour": key = new Date(entry.timestamp).getHours().toString().padStart(2, "0") + ":00"; break; case "day": key = new Date(entry.timestamp).toISOString().split("T")[0]; break; default: key = "Unknown"; } if (!groups[key]) { groups[key] = []; } groups[key].push(entry); }); return groups; }