@hailer/mcp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/.claude/commands/tool-builder.md +37 -0
  2. package/.claude/commands/ws-pull.md +44 -0
  3. package/.claude/settings.json +8 -0
  4. package/.claude/settings.local.json +49 -0
  5. package/.claude/skills/activity-api/SKILL.md +96 -0
  6. package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
  7. package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
  8. package/.claude/skills/agent-building/SKILL.md +243 -0
  9. package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
  10. package/.claude/skills/agent-building/references/code-examples.md +587 -0
  11. package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
  12. package/.claude/skills/app-api/SKILL.md +219 -0
  13. package/.claude/skills/app-api/references/app-endpoints.md +759 -0
  14. package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
  15. package/.claude/skills/create-app-skill/SKILL.md +1101 -0
  16. package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
  17. package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
  18. package/.claude/skills/hailer-api/SKILL.md +283 -0
  19. package/.claude/skills/hailer-api/references/activities.md +620 -0
  20. package/.claude/skills/hailer-api/references/authentication.md +216 -0
  21. package/.claude/skills/hailer-api/references/datasets.md +437 -0
  22. package/.claude/skills/hailer-api/references/files.md +301 -0
  23. package/.claude/skills/hailer-api/references/insights.md +469 -0
  24. package/.claude/skills/hailer-api/references/workflows.md +720 -0
  25. package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
  26. package/.claude/skills/insight-api/SKILL.md +185 -0
  27. package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
  28. package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
  29. package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
  30. package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
  31. package/.claude/skills/local-first-skill/SKILL.md +570 -0
  32. package/.claude/skills/mcp-tools/SKILL.md +419 -0
  33. package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
  34. package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
  35. package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
  36. package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
  37. package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
  38. package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
  39. package/.claude/skills/remove-app-skill/SKILL.md +985 -0
  40. package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
  41. package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
  42. package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
  43. package/.claude/skills/skill-testing/README.md +137 -0
  44. package/.claude/skills/skill-testing/SKILL.md +348 -0
  45. package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
  46. package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
  47. package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
  48. package/.claude/skills/tool-builder/SKILL.md +328 -0
  49. package/.claude/skills/update-app-skill/SKILL.md +970 -0
  50. package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
  51. package/.env.example +81 -0
  52. package/.mcp.json +13 -0
  53. package/README.md +297 -0
  54. package/dist/app.d.ts +4 -0
  55. package/dist/app.js +74 -0
  56. package/dist/cli.d.ts +3 -0
  57. package/dist/cli.js +5 -0
  58. package/dist/client/adaptive-documentation-bot.d.ts +108 -0
  59. package/dist/client/adaptive-documentation-bot.js +475 -0
  60. package/dist/client/adaptive-documentation-types.d.ts +66 -0
  61. package/dist/client/adaptive-documentation-types.js +9 -0
  62. package/dist/client/agent-activity-bot.d.ts +51 -0
  63. package/dist/client/agent-activity-bot.js +166 -0
  64. package/dist/client/agent-tracker.d.ts +499 -0
  65. package/dist/client/agent-tracker.js +659 -0
  66. package/dist/client/description-updater.d.ts +56 -0
  67. package/dist/client/description-updater.js +259 -0
  68. package/dist/client/log-parser.d.ts +72 -0
  69. package/dist/client/log-parser.js +387 -0
  70. package/dist/client/mcp-client.d.ts +50 -0
  71. package/dist/client/mcp-client.js +532 -0
  72. package/dist/client/message-processor.d.ts +35 -0
  73. package/dist/client/message-processor.js +352 -0
  74. package/dist/client/multi-bot-manager.d.ts +24 -0
  75. package/dist/client/multi-bot-manager.js +74 -0
  76. package/dist/client/providers/anthropic-provider.d.ts +19 -0
  77. package/dist/client/providers/anthropic-provider.js +631 -0
  78. package/dist/client/providers/llm-provider.d.ts +47 -0
  79. package/dist/client/providers/llm-provider.js +367 -0
  80. package/dist/client/providers/openai-provider.d.ts +23 -0
  81. package/dist/client/providers/openai-provider.js +621 -0
  82. package/dist/client/simple-llm-caller.d.ts +19 -0
  83. package/dist/client/simple-llm-caller.js +100 -0
  84. package/dist/client/skill-generator.d.ts +81 -0
  85. package/dist/client/skill-generator.js +386 -0
  86. package/dist/client/test-adaptive-bot.d.ts +9 -0
  87. package/dist/client/test-adaptive-bot.js +82 -0
  88. package/dist/client/token-pricing.d.ts +38 -0
  89. package/dist/client/token-pricing.js +127 -0
  90. package/dist/client/token-tracker.d.ts +232 -0
  91. package/dist/client/token-tracker.js +457 -0
  92. package/dist/client/token-usage-bot.d.ts +53 -0
  93. package/dist/client/token-usage-bot.js +153 -0
  94. package/dist/client/tool-executor.d.ts +69 -0
  95. package/dist/client/tool-executor.js +159 -0
  96. package/dist/client/tool-schema-loader.d.ts +60 -0
  97. package/dist/client/tool-schema-loader.js +178 -0
  98. package/dist/client/types.d.ts +69 -0
  99. package/dist/client/types.js +7 -0
  100. package/dist/config.d.ts +162 -0
  101. package/dist/config.js +296 -0
  102. package/dist/core.d.ts +26 -0
  103. package/dist/core.js +147 -0
  104. package/dist/lib/context-manager.d.ts +111 -0
  105. package/dist/lib/context-manager.js +431 -0
  106. package/dist/lib/logger.d.ts +74 -0
  107. package/dist/lib/logger.js +277 -0
  108. package/dist/lib/materialize.d.ts +3 -0
  109. package/dist/lib/materialize.js +101 -0
  110. package/dist/lib/normalizedName.d.ts +7 -0
  111. package/dist/lib/normalizedName.js +48 -0
  112. package/dist/lib/prompt-length-manager.d.ts +81 -0
  113. package/dist/lib/prompt-length-manager.js +457 -0
  114. package/dist/lib/terminal-prompt.d.ts +9 -0
  115. package/dist/lib/terminal-prompt.js +108 -0
  116. package/dist/mcp/UserContextCache.d.ts +56 -0
  117. package/dist/mcp/UserContextCache.js +163 -0
  118. package/dist/mcp/auth.d.ts +2 -0
  119. package/dist/mcp/auth.js +29 -0
  120. package/dist/mcp/hailer-clients.d.ts +42 -0
  121. package/dist/mcp/hailer-clients.js +246 -0
  122. package/dist/mcp/signal-handler.d.ts +45 -0
  123. package/dist/mcp/signal-handler.js +317 -0
  124. package/dist/mcp/tool-registry.d.ts +100 -0
  125. package/dist/mcp/tool-registry.js +306 -0
  126. package/dist/mcp/tools/activity.d.ts +15 -0
  127. package/dist/mcp/tools/activity.js +955 -0
  128. package/dist/mcp/tools/app.d.ts +20 -0
  129. package/dist/mcp/tools/app.js +1488 -0
  130. package/dist/mcp/tools/discussion.d.ts +19 -0
  131. package/dist/mcp/tools/discussion.js +950 -0
  132. package/dist/mcp/tools/file.d.ts +15 -0
  133. package/dist/mcp/tools/file.js +119 -0
  134. package/dist/mcp/tools/insight.d.ts +17 -0
  135. package/dist/mcp/tools/insight.js +806 -0
  136. package/dist/mcp/tools/skill.d.ts +10 -0
  137. package/dist/mcp/tools/skill.js +279 -0
  138. package/dist/mcp/tools/user.d.ts +10 -0
  139. package/dist/mcp/tools/user.js +108 -0
  140. package/dist/mcp/tools/workflow-template.d.ts +19 -0
  141. package/dist/mcp/tools/workflow-template.js +822 -0
  142. package/dist/mcp/tools/workflow.d.ts +18 -0
  143. package/dist/mcp/tools/workflow.js +1362 -0
  144. package/dist/mcp/utils/api-errors.d.ts +45 -0
  145. package/dist/mcp/utils/api-errors.js +160 -0
  146. package/dist/mcp/utils/data-transformers.d.ts +102 -0
  147. package/dist/mcp/utils/data-transformers.js +194 -0
  148. package/dist/mcp/utils/file-upload.d.ts +33 -0
  149. package/dist/mcp/utils/file-upload.js +148 -0
  150. package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
  151. package/dist/mcp/utils/hailer-api-client.js +323 -0
  152. package/dist/mcp/utils/index.d.ts +13 -0
  153. package/dist/mcp/utils/index.js +39 -0
  154. package/dist/mcp/utils/logger.d.ts +42 -0
  155. package/dist/mcp/utils/logger.js +103 -0
  156. package/dist/mcp/utils/types.d.ts +286 -0
  157. package/dist/mcp/utils/types.js +7 -0
  158. package/dist/mcp/workspace-cache.d.ts +42 -0
  159. package/dist/mcp/workspace-cache.js +97 -0
  160. package/dist/mcp-server.d.ts +42 -0
  161. package/dist/mcp-server.js +280 -0
  162. package/package.json +56 -0
  163. package/tsconfig.json +23 -0
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /**
3
+ * Agent Activity Bot
4
+ *
5
+ * Monitors agent activity and posts summaries to discussions.
6
+ * Can respond to queries about agent performance and tool usage.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AgentActivityBot = void 0;
10
+ exports.createAgentActivityBot = createAgentActivityBot;
11
+ const logger_1 = require("../lib/logger");
12
+ const logger = (0, logger_1.createLogger)({ component: 'agent-activity-bot' });
13
+ class AgentActivityBot {
14
+ agentTracker;
15
+ config;
16
+ lastPostedConversation = new Map(); // discussionId -> timestamp
17
+ constructor(agentTracker, config) {
18
+ this.agentTracker = agentTracker;
19
+ this.config = {
20
+ minDurationThreshold: 1000,
21
+ ...config
22
+ };
23
+ if (this.config.enabled) {
24
+ logger.info('Agent Activity Bot initialized', {
25
+ postSummaries: this.config.postSummaryAfterConversation,
26
+ minThreshold: this.config.minDurationThreshold
27
+ });
28
+ }
29
+ }
30
+ /**
31
+ * Generate a summary message for the last conversation in a discussion
32
+ */
33
+ generateSummary(requestId, discussionId, duration, toolsCalled) {
34
+ const recentActivity = this.agentTracker.getRecentActivity(50);
35
+ // Find the specific request
36
+ const trigger = recentActivity.find(e => e.type === 'trigger' && e.requestId === requestId);
37
+ const completion = recentActivity.find(e => e.type === 'completion' && e.requestId === requestId);
38
+ if (!trigger || !completion || trigger.type !== 'trigger' || completion.type !== 'completion') {
39
+ return `🤖 **Agent Activity**\n\nProcessing completed but details unavailable.`;
40
+ }
41
+ return this.formatSummaryMessage(trigger.trigger.type, completion.completion.success, duration, toolsCalled, completion.completion.provider || 'unknown');
42
+ }
43
+ /**
44
+ * Format a concise summary message
45
+ */
46
+ formatSummaryMessage(triggerType, success, duration, toolsCalled, provider) {
47
+ const statusIcon = success ? '✅' : '❌';
48
+ const triggerIcon = triggerType === 'mention' ? '💬' : '📩';
49
+ return `🤖 **Agent Activity**
50
+ ${statusIcon} ${success ? 'Completed' : 'Failed'} ${triggerIcon} ${triggerType === 'mention' ? 'Mention' : 'Direct message'}
51
+ ⏱️ Duration: ${(duration / 1000).toFixed(2)}s | 🔧 Tools: ${toolsCalled.length > 0 ? toolsCalled.slice(0, 3).join(', ') : 'none'}${toolsCalled.length > 3 ? '...' : ''}
52
+ 🧠 Provider: ${provider}`;
53
+ }
54
+ /**
55
+ * Generate detailed agent activity report
56
+ */
57
+ generateDetailedReport(discussionId) {
58
+ const stats = this.agentTracker.getStats();
59
+ const recentActivity = this.agentTracker.getRecentActivity(100);
60
+ let report = `📊 **Detailed Agent Activity Report**\n\n`;
61
+ if (discussionId) {
62
+ // Filter for specific discussion
63
+ const discussionActivity = recentActivity.filter(e => {
64
+ if (e.type === 'trigger')
65
+ return e.trigger.discussionId === discussionId;
66
+ if (e.type === 'tool_call')
67
+ return e.toolCall.discussionId === discussionId;
68
+ return false;
69
+ });
70
+ const discussionTriggers = discussionActivity.filter(e => e.type === 'trigger');
71
+ const discussionToolCalls = discussionActivity.filter(e => e.type === 'tool_call');
72
+ report += `**This Conversation:**\n`;
73
+ report += `- Total Interactions: ${discussionTriggers.length}\n`;
74
+ report += `- Tool Calls: ${discussionToolCalls.length}\n`;
75
+ report += `\n`;
76
+ // Show last 5 interactions
77
+ if (discussionTriggers.length > 0) {
78
+ report += `**Recent Interactions:**\n`;
79
+ discussionTriggers.slice(-5).forEach((event, i) => {
80
+ if (event.type === 'trigger') {
81
+ report += `${i + 1}. ${event.trigger.type} - ${event.trigger.messagePreview}\n`;
82
+ }
83
+ });
84
+ report += `\n`;
85
+ }
86
+ }
87
+ // Overall stats
88
+ report += `**Overall Stats:**\n`;
89
+ report += `- Total Triggers: ${stats.totalTriggers}\n`;
90
+ report += `- Total Completions: ${stats.totalCompletions}\n`;
91
+ report += `- Success Rate: ${stats.successRate.toFixed(1)}%\n`;
92
+ report += `- Avg Response Time: ${(stats.averageResponseTime / 1000).toFixed(2)}s\n`;
93
+ report += `- Total Tool Calls: ${stats.totalToolCalls}\n\n`;
94
+ // Most active agent
95
+ if (stats.mostActiveBot) {
96
+ report += `**Most Active Agent:**\n`;
97
+ report += `- Bot ID: ${stats.mostActiveBot.substring(0, 8)}...\n\n`;
98
+ }
99
+ // Top tools
100
+ if (stats.mostUsedTool) {
101
+ report += `**Most Used Tool:** ${stats.mostUsedTool}\n\n`;
102
+ }
103
+ // Recent tool calls
104
+ const recentToolCalls = this.agentTracker.getRecentToolCalls(5);
105
+ if (recentToolCalls.length > 0) {
106
+ report += `**Recent Tool Calls:**\n`;
107
+ recentToolCalls.forEach((call, i) => {
108
+ const status = call.toolCall.response.success ? '✅' : '❌';
109
+ report += `${i + 1}. ${status} ${call.toolCall.toolName} (${(call.toolCall.duration / 1000).toFixed(2)}s)\n`;
110
+ });
111
+ }
112
+ return report;
113
+ }
114
+ /**
115
+ * Check if message is asking for agent activity details
116
+ */
117
+ isActivityQuery(messageContent) {
118
+ const lower = messageContent.toLowerCase();
119
+ return ((lower.includes('agent') || lower.includes('bot') || lower.includes('activity')) && (lower.includes('activity') ||
120
+ lower.includes('stats') ||
121
+ lower.includes('performance') ||
122
+ lower.includes('detail') ||
123
+ lower.includes('report') ||
124
+ lower.includes('how') ||
125
+ lower.includes('what tools') ||
126
+ lower.includes('tool usage')));
127
+ }
128
+ /**
129
+ * Should post summary after this conversation?
130
+ */
131
+ shouldPostSummary(discussionId, duration) {
132
+ if (!this.config.enabled || !this.config.postSummaryAfterConversation) {
133
+ return false;
134
+ }
135
+ // Check duration threshold
136
+ if (duration < (this.config.minDurationThreshold || 0)) {
137
+ return false;
138
+ }
139
+ // Debounce: Don't post if we posted recently (within 30 seconds)
140
+ const lastPosted = this.lastPostedConversation.get(discussionId);
141
+ if (lastPosted && Date.now() - lastPosted < 30000) {
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+ /**
147
+ * Mark that we posted a summary for this discussion
148
+ */
149
+ markPosted(discussionId) {
150
+ this.lastPostedConversation.set(discussionId, Date.now());
151
+ }
152
+ /**
153
+ * Get agent tracker instance
154
+ */
155
+ getAgentTracker() {
156
+ return this.agentTracker;
157
+ }
158
+ }
159
+ exports.AgentActivityBot = AgentActivityBot;
160
+ /**
161
+ * Factory function to create AgentActivityBot
162
+ */
163
+ function createAgentActivityBot(agentTracker, config) {
164
+ return new AgentActivityBot(agentTracker, config);
165
+ }
166
+ //# sourceMappingURL=agent-activity-bot.js.map
@@ -0,0 +1,499 @@
1
+ /**
2
+ * Agent Activity Tracker
3
+ *
4
+ * Provides comprehensive tracking and analytics for AI agent interactions within
5
+ * the Hailer MCP ecosystem. This module captures conversation flows, performance
6
+ * metrics, and usage patterns to enable business intelligence and system optimization.
7
+ *
8
+ * Key Features:
9
+ * - End-to-end conversation flow tracking (trigger → completion correlation)
10
+ * - Detailed tool usage analytics with request/response data
11
+ * - Performance metrics (response times, success rates)
12
+ * - Agent usage statistics and behavioral insights
13
+ * - Persistent JSON-based storage with automatic rotation
14
+ *
15
+ * Environment Behavior:
16
+ * - Development (NODE_ENV !== 'production'): JSON file tracking enabled by default
17
+ * - Production (NODE_ENV === 'production'): JSON file tracking disabled by default
18
+ * - Override: Set AGENT_TRACKING_ENABLED=true to force enable in production
19
+ *
20
+ * In production, all tracking events are still logged via the unified logger
21
+ * (OTLP) but no JSON files are created to avoid disk I/O and storage costs.
22
+ */
23
+ import { Logger } from '../lib/logger';
24
+ /**
25
+ * Represents an agent trigger event when a user activates an AI agent
26
+ * Links to completion events via requestId for end-to-end flow analysis
27
+ */
28
+ export interface AgentTriggerLog {
29
+ type: 'trigger';
30
+ /** Unique identifier linking trigger to completion events */
31
+ requestId: string;
32
+ /** ISO timestamp when the trigger occurred */
33
+ timestamp: string;
34
+ /** Details about how and why the agent was triggered */
35
+ trigger: {
36
+ /** Method of agent activation */
37
+ type: 'mention' | 'direct';
38
+ /** Conversation thread identifier */
39
+ discussionId: string;
40
+ /** User who triggered the agent */
41
+ userId: string;
42
+ /** Display name of the triggering user */
43
+ userName: string;
44
+ /** Unique identifier of the responding agent */
45
+ botId: string;
46
+ /** Truncated preview of the message that triggered the agent */
47
+ messagePreview: string;
48
+ /** Optional workspace context */
49
+ workspaceId?: string;
50
+ };
51
+ }
52
+ /**
53
+ * Represents an agent completion event when processing finishes
54
+ * Correlated with trigger events to measure end-to-end performance
55
+ */
56
+ export interface AgentCompletionLog {
57
+ type: 'completion';
58
+ /** Unique identifier linking to original trigger event */
59
+ requestId: string;
60
+ /** ISO timestamp when processing completed */
61
+ timestamp: string;
62
+ /** Results and metrics from the agent's processing */
63
+ completion: {
64
+ /** Whether the agent completed successfully */
65
+ success: boolean;
66
+ /** LLM provider used (anthropic, openai, etc) */
67
+ provider?: string;
68
+ /** List of tools/functions called during processing */
69
+ toolsCalled: string[];
70
+ /** Truncated preview of the agent's response */
71
+ responsePreview?: string;
72
+ /** Total processing time in milliseconds */
73
+ duration: number;
74
+ /** Error message if processing failed */
75
+ error?: string;
76
+ };
77
+ }
78
+ /**
79
+ * Represents a detailed tool/function call made during agent processing
80
+ * Provides granular visibility into agent decision-making and API usage
81
+ */
82
+ export interface AgentToolCallLog {
83
+ type: 'tool_call';
84
+ /** Request identifier (may be shared across multiple tool calls) */
85
+ requestId: string;
86
+ /** ISO timestamp when the tool call was made */
87
+ timestamp: string;
88
+ /** Detailed information about the tool invocation */
89
+ toolCall: {
90
+ /** Name of the tool/function called */
91
+ toolName: string;
92
+ /** Provider handling the tool call */
93
+ provider: string;
94
+ /** Input data sent to the tool */
95
+ request: {
96
+ /** Arguments passed to the tool */
97
+ arguments: any;
98
+ /** API endpoint if applicable */
99
+ endpoint?: string;
100
+ /** HTTP method if applicable */
101
+ method?: string;
102
+ };
103
+ /** Output data received from the tool */
104
+ response: {
105
+ /** Whether the tool call succeeded */
106
+ success: boolean;
107
+ /** Response data if successful */
108
+ data?: any;
109
+ /** Error details if failed */
110
+ error?: string;
111
+ };
112
+ /** Tool execution time in milliseconds */
113
+ duration: number;
114
+ /** Agent that made the tool call */
115
+ botId?: string;
116
+ /** Conversation context */
117
+ discussionId?: string;
118
+ /** Workspace context */
119
+ workspaceId?: string;
120
+ };
121
+ }
122
+ /**
123
+ * Represents system-level events related to agent operations
124
+ * Captures infrastructure events, initialization, errors, etc.
125
+ */
126
+ export interface AgentSystemLog {
127
+ type: 'system';
128
+ /** Unique identifier for the system event */
129
+ requestId: string;
130
+ /** ISO timestamp when the system event occurred */
131
+ timestamp: string;
132
+ /** Details about the system event */
133
+ system: {
134
+ /** Whether the system operation succeeded */
135
+ success: boolean;
136
+ /** Human-readable description of the event */
137
+ message: string;
138
+ /** Additional technical details */
139
+ details?: string;
140
+ /** Error information if the operation failed */
141
+ error?: string;
142
+ };
143
+ }
144
+ /** Union type for all possible agent log entry types */
145
+ export type AgentLogEntry = AgentTriggerLog | AgentCompletionLog | AgentToolCallLog | AgentSystemLog;
146
+ /**
147
+ * Root structure of the agent activity log file
148
+ * Contains all tracked events with automatic rotation
149
+ */
150
+ export interface AgentActivityLog {
151
+ /** Array of all logged agent activity events */
152
+ entries: AgentLogEntry[];
153
+ }
154
+ /**
155
+ * Agent Activity Tracker
156
+ *
157
+ * Main class for tracking AI agent interactions, performance, and usage patterns.
158
+ * Provides both real-time logging capabilities and historical analytics.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const logger = createLogger({ component: 'my-component' });
163
+ * const tracker = new AgentTracker(logger);
164
+ *
165
+ * // Track a conversation flow
166
+ * const requestId = tracker.logTrigger({
167
+ * triggerType: 'mention',
168
+ * discussionId: 'disc_123',
169
+ * userId: 'user_456',
170
+ * userName: 'John Doe',
171
+ * botId: 'bot_789',
172
+ * messageContent: '@bot help me with this task'
173
+ * });
174
+ *
175
+ * // Later, track completion
176
+ * tracker.logCompletion({
177
+ * requestId,
178
+ * success: true,
179
+ * provider: 'anthropic',
180
+ * toolsCalled: ['list_activities', 'create_activity'],
181
+ * duration: 2500
182
+ * });
183
+ * ```
184
+ */
185
+ export declare class AgentTracker {
186
+ private logger;
187
+ private logFilePath?;
188
+ private maxEntries;
189
+ private isProduction;
190
+ private isTrackingEnabled;
191
+ /**
192
+ * Creates a new Agent Activity Tracker instance
193
+ *
194
+ * @param logger - Optional logger instance for operational logging. If not provided, creates a new logger
195
+ * @param logDir - Directory where agent activity logs will be stored (default: 'logs')
196
+ * @param maxEntries - Maximum number of log entries before rotation (default: 1000)
197
+ */
198
+ constructor(logger?: Logger, logDir?: string, maxEntries?: number);
199
+ /**
200
+ * Initializes the agent activity log file if it doesn't exist
201
+ * Creates the necessary directory structure and empty log file
202
+ * Only runs in development mode or when explicitly enabled
203
+ *
204
+ * @private
205
+ */
206
+ private initializeLogFile;
207
+ /**
208
+ * Reads the current agent activity log from disk
209
+ * Returns empty log in production mode or when tracking is disabled
210
+ *
211
+ * @private
212
+ * @returns The current log data, or empty log if file cannot be read or tracking is disabled
213
+ */
214
+ private readLogFile;
215
+ /**
216
+ * Writes the agent activity log to disk with automatic rotation
217
+ * Skips file writing in production mode unless explicitly enabled
218
+ *
219
+ * @private
220
+ * @param log - The log data to write
221
+ */
222
+ private writeLogFile;
223
+ /**
224
+ * Generates a unique request identifier for correlation
225
+ *
226
+ * @private
227
+ * @returns A unique request ID string
228
+ */
229
+ private generateRequestId;
230
+ /**
231
+ * Truncates text to a specified maximum length for preview purposes
232
+ *
233
+ * @private
234
+ * @param text - The text to truncate
235
+ * @param maxLength - Maximum length before truncation (default: 50)
236
+ * @returns Truncated text with ellipsis if needed
237
+ */
238
+ private truncateText;
239
+ /**
240
+ * Logs when an AI agent is triggered to respond to a user message
241
+ *
242
+ * Creates a correlation ID that links trigger events to completion events,
243
+ * enabling end-to-end conversation flow analysis and performance tracking.
244
+ *
245
+ * @param params - Trigger event details
246
+ * @param params.triggerType - How the agent was activated ('mention' | 'direct')
247
+ * @param params.discussionId - Unique identifier for the conversation thread
248
+ * @param params.userId - User who triggered the agent
249
+ * @param params.userName - Display name of the triggering user
250
+ * @param params.botId - Unique identifier of the responding agent
251
+ * @param params.messageContent - Original message content that triggered the agent
252
+ * @param params.workspaceId - Optional workspace context
253
+ *
254
+ * @returns {string} requestId - Unique correlation ID for linking with completion events
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const requestId = agentTracker.logTrigger({
259
+ * triggerType: 'mention',
260
+ * discussionId: 'disc_123',
261
+ * userId: 'user_456',
262
+ * userName: 'John Doe',
263
+ * botId: 'bot_789',
264
+ * messageContent: '@bot help me with this task'
265
+ * });
266
+ * ```
267
+ */
268
+ logTrigger(params: {
269
+ triggerType: 'mention' | 'direct';
270
+ discussionId: string;
271
+ userId: string;
272
+ userName: string;
273
+ botId: string;
274
+ messageContent: string;
275
+ workspaceId?: string;
276
+ }): string;
277
+ /**
278
+ * Logs when an AI agent completes processing a user request
279
+ *
280
+ * Records the final outcome, performance metrics, and tools used during processing.
281
+ * Must be correlated with a trigger event using the same requestId for complete
282
+ * conversation flow analysis.
283
+ *
284
+ * @param params - Completion event details
285
+ * @param params.requestId - Correlation ID from the original trigger event
286
+ * @param params.success - Whether the agent completed successfully
287
+ * @param params.provider - LLM provider used (anthropic, openai, etc)
288
+ * @param params.toolsCalled - Array of tool names that were invoked
289
+ * @param params.responseContent - The agent's response content
290
+ * @param params.duration - Total processing time in milliseconds
291
+ * @param params.error - Error message if processing failed
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * agentTracker.logCompletion({
296
+ * requestId: 'req-123-abc',
297
+ * success: true,
298
+ * provider: 'anthropic',
299
+ * toolsCalled: ['list_activities', 'create_activity'],
300
+ * responseContent: 'I created the task for you',
301
+ * duration: 2500
302
+ * });
303
+ * ```
304
+ */
305
+ logCompletion(params: {
306
+ requestId: string;
307
+ success: boolean;
308
+ provider?: string;
309
+ toolsCalled?: string[];
310
+ responseContent?: string;
311
+ duration: number;
312
+ error?: string;
313
+ }): void;
314
+ /**
315
+ * Logs individual tool calls made during agent processing
316
+ *
317
+ * Provides granular visibility into agent decision-making by recording each
318
+ * tool invocation with full request/response data. Essential for debugging
319
+ * agent behavior and optimizing tool usage patterns.
320
+ *
321
+ * @param params - Tool call event details
322
+ * @param params.requestId - Optional correlation ID (generates new one if not provided)
323
+ * @param params.toolName - Name of the tool/function that was called
324
+ * @param params.provider - Provider handling the tool execution
325
+ * @param params.request - Input data sent to the tool
326
+ * @param params.request.arguments - Arguments passed to the tool
327
+ * @param params.request.endpoint - API endpoint if applicable
328
+ * @param params.request.method - HTTP method if applicable
329
+ * @param params.response - Output data received from the tool
330
+ * @param params.response.success - Whether the tool call succeeded
331
+ * @param params.response.data - Response data if successful
332
+ * @param params.response.error - Error details if failed
333
+ * @param params.duration - Tool execution time in milliseconds
334
+ * @param params.botId - Agent that made the tool call
335
+ * @param params.discussionId - Conversation context
336
+ * @param params.workspaceId - Workspace context
337
+ *
338
+ * @returns {string} requestId - The correlation ID used for this tool call
339
+ *
340
+ * @example
341
+ * ```typescript
342
+ * agentTracker.logToolCall({
343
+ * requestId: 'req-123-abc',
344
+ * toolName: 'list_activities',
345
+ * provider: 'hailer-mcp',
346
+ * request: {
347
+ * arguments: { workflowId: 'wf_456', limit: 10 }
348
+ * },
349
+ * response: {
350
+ * success: true,
351
+ * data: { activities: [...] }
352
+ * },
353
+ * duration: 850,
354
+ * botId: 'bot_789'
355
+ * });
356
+ * ```
357
+ */
358
+ logToolCall(params: {
359
+ requestId?: string;
360
+ toolName: string;
361
+ provider: string;
362
+ request: {
363
+ arguments: any;
364
+ endpoint?: string;
365
+ method?: string;
366
+ };
367
+ response: {
368
+ success: boolean;
369
+ data?: any;
370
+ error?: string;
371
+ };
372
+ duration: number;
373
+ botId?: string;
374
+ discussionId?: string;
375
+ workspaceId?: string;
376
+ }): string;
377
+ /**
378
+ * Logs system-level events related to agent operations
379
+ *
380
+ * Captures infrastructure events such as agent initialization, shutdown,
381
+ * configuration changes, and other system-level activities that affect
382
+ * agent behavior but aren't directly part of user conversations.
383
+ *
384
+ * @param params - System event details
385
+ * @param params.success - Whether the system operation succeeded
386
+ * @param params.message - Human-readable description of the event
387
+ * @param params.details - Additional technical details about the event
388
+ * @param params.error - Error information if the operation failed
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * agentTracker.logSystem({
393
+ * success: true,
394
+ * message: 'Agent client initialized',
395
+ * details: 'Connected to MCP server with 5 tools available'
396
+ * });
397
+ * ```
398
+ */
399
+ logSystem(params: {
400
+ success: boolean;
401
+ message: string;
402
+ details?: string;
403
+ error?: string;
404
+ }): void;
405
+ /**
406
+ * Retrieves recent agent activity entries for monitoring and debugging
407
+ *
408
+ * Returns the most recent log entries in chronological order (newest last).
409
+ * Useful for real-time monitoring dashboards and recent activity analysis.
410
+ *
411
+ * @param limit - Maximum number of entries to return (default: 10)
412
+ * @returns Array of recent agent log entries
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const recentActivity = agentTracker.getRecentActivity(20);
417
+ * console.log(`Found ${recentActivity.length} recent events`);
418
+ * ```
419
+ */
420
+ getRecentActivity(limit?: number): AgentLogEntry[];
421
+ /**
422
+ * Retrieves recent tool call logs for analysis and debugging
423
+ *
424
+ * Filters the log entries to return only tool call events, providing
425
+ * focused visibility into agent decision-making and API usage patterns.
426
+ *
427
+ * @param limit - Maximum number of tool call entries to return (default: 50)
428
+ * @returns Array of recent tool call log entries
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * const recentToolCalls = agentTracker.getRecentToolCalls(100);
433
+ * const failedCalls = recentToolCalls.filter(call => !call.toolCall.response.success);
434
+ * ```
435
+ */
436
+ getRecentToolCalls(limit?: number): AgentToolCallLog[];
437
+ /**
438
+ * Generates comprehensive statistics about agent activity and performance
439
+ *
440
+ * Analyzes all logged events to provide business intelligence metrics including
441
+ * success rates, performance trends, usage patterns, and identifying top
442
+ * performers. Essential for monitoring agent effectiveness and optimization.
443
+ *
444
+ * @returns Comprehensive statistics object with performance and usage metrics
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * const stats = agentTracker.getStats();
449
+ * console.log(`Success rate: ${stats.successRate}%`);
450
+ * console.log(`Average response time: ${stats.averageResponseTime}ms`);
451
+ * console.log(`Most active agent: ${stats.mostActiveBot}`);
452
+ * console.log(`Most used tool: ${stats.mostUsedTool}`);
453
+ * ```
454
+ */
455
+ getStats(): {
456
+ /** Total number of agent trigger events */
457
+ totalTriggers: number;
458
+ /** Total number of agent completion events */
459
+ totalCompletions: number;
460
+ /** Total number of tool calls made by agents */
461
+ totalToolCalls: number;
462
+ /** Percentage of successful agent completions (0-100) */
463
+ successRate: number;
464
+ /** Average response time in milliseconds */
465
+ averageResponseTime: number;
466
+ /** ID of the most frequently triggered agent */
467
+ mostActiveBot: string | null;
468
+ /** Number of system-level events logged */
469
+ systemEvents: number;
470
+ /** Name of the most frequently used tool */
471
+ mostUsedTool: string | null;
472
+ };
473
+ }
474
+ /**
475
+ * Factory function to create a new AgentTracker instance
476
+ *
477
+ * Provides a clean way to instantiate agent trackers with dependency injection.
478
+ * Follows modern patterns and makes testing easier by allowing logger mocking.
479
+ *
480
+ * @param logger - Optional logger instance for operational logging
481
+ * @param logDir - Directory where agent activity logs will be stored
482
+ * @param maxEntries - Maximum number of log entries before rotation
483
+ * @returns A new AgentTracker instance
484
+ *
485
+ * @example
486
+ * ```typescript
487
+ * // Basic usage
488
+ * const agentTracker = createAgentTracker();
489
+ *
490
+ * // With custom logger
491
+ * const logger = createLogger({ component: 'my-service' });
492
+ * const agentTracker = createAgentTracker(logger);
493
+ *
494
+ * // With custom configuration
495
+ * const agentTracker = createAgentTracker(logger, '/var/log/agents', 5000);
496
+ * ```
497
+ */
498
+ export declare function createAgentTracker(logger?: Logger, logDir?: string, maxEntries?: number): AgentTracker;
499
+ //# sourceMappingURL=agent-tracker.d.ts.map