@hailer/mcp 0.1.15 → 0.1.16

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 (112) hide show
  1. package/.claude/agents/agent-giuseppe-app-builder.md +7 -6
  2. package/.claude/agents/agent-lars-code-inspector.md +26 -14
  3. package/dist/agents/bot-manager.d.ts +48 -0
  4. package/dist/agents/bot-manager.js +254 -0
  5. package/dist/agents/factory.d.ts +150 -0
  6. package/dist/agents/factory.js +650 -0
  7. package/dist/agents/giuseppe/ai.d.ts +83 -0
  8. package/dist/agents/giuseppe/ai.js +466 -0
  9. package/dist/agents/giuseppe/bot.d.ts +110 -0
  10. package/dist/agents/giuseppe/bot.js +780 -0
  11. package/dist/agents/giuseppe/config.d.ts +25 -0
  12. package/dist/agents/giuseppe/config.js +227 -0
  13. package/dist/agents/giuseppe/files.d.ts +52 -0
  14. package/dist/agents/giuseppe/files.js +338 -0
  15. package/dist/agents/giuseppe/git.d.ts +48 -0
  16. package/dist/agents/giuseppe/git.js +298 -0
  17. package/dist/agents/giuseppe/index.d.ts +97 -0
  18. package/dist/agents/giuseppe/index.js +258 -0
  19. package/dist/agents/giuseppe/lsp.d.ts +113 -0
  20. package/dist/agents/giuseppe/lsp.js +485 -0
  21. package/dist/agents/giuseppe/monitor.d.ts +118 -0
  22. package/dist/agents/giuseppe/monitor.js +621 -0
  23. package/dist/agents/giuseppe/prompt.d.ts +5 -0
  24. package/dist/agents/giuseppe/prompt.js +94 -0
  25. package/dist/agents/giuseppe/registries/pending-classification.d.ts +28 -0
  26. package/dist/agents/giuseppe/registries/pending-classification.js +50 -0
  27. package/dist/agents/giuseppe/registries/pending-fix.d.ts +30 -0
  28. package/dist/agents/giuseppe/registries/pending-fix.js +42 -0
  29. package/dist/agents/giuseppe/registries/pending.d.ts +27 -0
  30. package/dist/agents/giuseppe/registries/pending.js +49 -0
  31. package/dist/agents/giuseppe/specialist.d.ts +47 -0
  32. package/dist/agents/giuseppe/specialist.js +237 -0
  33. package/dist/agents/giuseppe/types.d.ts +123 -0
  34. package/dist/agents/giuseppe/types.js +9 -0
  35. package/dist/agents/hailer-expert/index.d.ts +8 -0
  36. package/dist/agents/hailer-expert/index.js +14 -0
  37. package/dist/agents/hal/daemon.d.ts +142 -0
  38. package/dist/agents/hal/daemon.js +1103 -0
  39. package/dist/agents/hal/definitions.d.ts +55 -0
  40. package/dist/agents/hal/definitions.js +263 -0
  41. package/dist/agents/hal/index.d.ts +3 -0
  42. package/dist/agents/hal/index.js +8 -0
  43. package/dist/agents/index.d.ts +18 -0
  44. package/dist/agents/index.js +48 -0
  45. package/dist/agents/shared/base.d.ts +216 -0
  46. package/dist/agents/shared/base.js +846 -0
  47. package/dist/agents/shared/services/agent-registry.d.ts +107 -0
  48. package/dist/agents/shared/services/agent-registry.js +629 -0
  49. package/dist/agents/shared/services/conversation-manager.d.ts +50 -0
  50. package/dist/agents/shared/services/conversation-manager.js +136 -0
  51. package/dist/agents/shared/services/mcp-client.d.ts +56 -0
  52. package/dist/agents/shared/services/mcp-client.js +124 -0
  53. package/dist/agents/shared/services/message-classifier.d.ts +37 -0
  54. package/dist/agents/shared/services/message-classifier.js +187 -0
  55. package/dist/agents/shared/services/message-formatter.d.ts +89 -0
  56. package/dist/agents/shared/services/message-formatter.js +371 -0
  57. package/dist/agents/shared/services/session-logger.d.ts +106 -0
  58. package/dist/agents/shared/services/session-logger.js +446 -0
  59. package/dist/agents/shared/services/tool-executor.d.ts +41 -0
  60. package/dist/agents/shared/services/tool-executor.js +169 -0
  61. package/dist/agents/shared/services/workspace-schema-cache.d.ts +125 -0
  62. package/dist/agents/shared/services/workspace-schema-cache.js +578 -0
  63. package/dist/agents/shared/specialist.d.ts +91 -0
  64. package/dist/agents/shared/specialist.js +399 -0
  65. package/dist/agents/shared/tool-schema-loader.d.ts +62 -0
  66. package/dist/agents/shared/tool-schema-loader.js +232 -0
  67. package/dist/agents/shared/types.d.ts +327 -0
  68. package/dist/agents/shared/types.js +121 -0
  69. package/dist/app.js +21 -4
  70. package/dist/cli.js +0 -0
  71. package/dist/client/agents/orchestrator.d.ts +1 -0
  72. package/dist/client/agents/orchestrator.js +12 -1
  73. package/dist/commands/seed-config.d.ts +9 -0
  74. package/dist/commands/seed-config.js +372 -0
  75. package/dist/config.d.ts +10 -0
  76. package/dist/config.js +61 -1
  77. package/dist/core.d.ts +8 -0
  78. package/dist/core.js +137 -6
  79. package/dist/lib/discussion-lock.d.ts +42 -0
  80. package/dist/lib/discussion-lock.js +110 -0
  81. package/dist/mcp/UserContextCache.js +2 -2
  82. package/dist/mcp/hailer-clients.d.ts +15 -0
  83. package/dist/mcp/hailer-clients.js +100 -6
  84. package/dist/mcp/signal-handler.d.ts +16 -5
  85. package/dist/mcp/signal-handler.js +173 -122
  86. package/dist/mcp/tools/activity.js +9 -1
  87. package/dist/mcp/tools/bot-config.d.ts +184 -9
  88. package/dist/mcp/tools/bot-config.js +2177 -163
  89. package/dist/mcp/tools/giuseppe-tools.d.ts +21 -0
  90. package/dist/mcp/tools/giuseppe-tools.js +525 -0
  91. package/dist/mcp/utils/hailer-api-client.d.ts +42 -1
  92. package/dist/mcp/utils/hailer-api-client.js +128 -2
  93. package/dist/mcp/webhook-handler.d.ts +87 -0
  94. package/dist/mcp/webhook-handler.js +343 -0
  95. package/dist/mcp/workspace-cache.d.ts +5 -0
  96. package/dist/mcp/workspace-cache.js +11 -0
  97. package/dist/mcp-server.js +55 -5
  98. package/dist/modules/bug-reports/giuseppe-agent.d.ts +58 -0
  99. package/dist/modules/bug-reports/giuseppe-agent.js +467 -0
  100. package/dist/modules/bug-reports/giuseppe-ai.d.ts +25 -1
  101. package/dist/modules/bug-reports/giuseppe-ai.js +133 -2
  102. package/dist/modules/bug-reports/giuseppe-bot.d.ts +2 -2
  103. package/dist/modules/bug-reports/giuseppe-bot.js +66 -42
  104. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +80 -0
  105. package/dist/modules/bug-reports/giuseppe-daemon.js +617 -0
  106. package/dist/modules/bug-reports/giuseppe-files.d.ts +12 -0
  107. package/dist/modules/bug-reports/giuseppe-files.js +37 -0
  108. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +84 -13
  109. package/dist/modules/bug-reports/giuseppe-lsp.js +403 -61
  110. package/dist/modules/bug-reports/index.d.ts +1 -0
  111. package/dist/modules/bug-reports/index.js +31 -29
  112. package/package.json +3 -2
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Specialist Daemon
3
+ *
4
+ * A lightweight daemon for specialist bots that only responds when @mentioned.
5
+ * Specialists are invited to discussions by the orchestrator (HAL) to handle
6
+ * specific complex tasks.
7
+ *
8
+ * Key differences from ChatAgentDaemon:
9
+ * - Only responds when @mentioned (not all messages)
10
+ * - Has specialized system prompt from Specialist config
11
+ * - More tool-focused, less conversational
12
+ */
13
+ import { ChatAgentDaemon, ChatAgentDaemonConfig, IncomingMessage } from "./base";
14
+ import { Specialist } from "../hal/definitions";
15
+ import { HailerSignal } from "../../mcp/signal-handler";
16
+ import { ToolInput } from "./types";
17
+ export interface SpecialistDaemonConfig extends ChatAgentDaemonConfig {
18
+ /** The specialist configuration */
19
+ specialist: Specialist;
20
+ }
21
+ export declare class SpecialistDaemon extends ChatAgentDaemon {
22
+ private specialistLogger;
23
+ private specialist;
24
+ private lastResponseTime;
25
+ private minResponseGap;
26
+ constructor(config: SpecialistDaemonConfig);
27
+ /**
28
+ * Override agent name for Agent Directory - uses specialist's configured name
29
+ */
30
+ protected getAgentName(): {
31
+ firstName: string;
32
+ lastName: string;
33
+ };
34
+ /**
35
+ * Override agent description for Agent Directory - uses specialist's expertise
36
+ */
37
+ protected getAgentDescription(): string;
38
+ /**
39
+ * Override Position details for Specialist - uses specialist's expertise
40
+ */
41
+ protected getPositionDetails(): {
42
+ name: string;
43
+ purpose: string;
44
+ personaTone: string;
45
+ coreCapabilities: string;
46
+ boundaries: string;
47
+ };
48
+ /**
49
+ * Specialist gets more tools for complex operations
50
+ */
51
+ protected getToolWhitelist(): string[];
52
+ /**
53
+ * Force compact output for schema tools (avoid verbose field dumps in discussions)
54
+ */
55
+ protected preprocessToolInput(toolName: string, input: ToolInput): ToolInput;
56
+ /**
57
+ * Override to only process messages where we're @mentioned
58
+ */
59
+ protected extractIncomingMessage(signal: HailerSignal): Promise<IncomingMessage | null>;
60
+ /**
61
+ * Check if this specialist is mentioned in the message
62
+ * Supports various mention formats:
63
+ * - @"Specialist Name"
64
+ * - @SpecialistName (no spaces)
65
+ * - Direct user tag [hailerTag|Name](userId)
66
+ */
67
+ private isMentionedInMessage;
68
+ /**
69
+ * Override system prompt with specialist-specific prompt
70
+ */
71
+ protected getSystemPrompt(): string;
72
+ /**
73
+ * Track response time for rate limiting
74
+ */
75
+ protected postResponse(discussionId: string, content: string): Promise<void>;
76
+ /**
77
+ * Get specialist status
78
+ */
79
+ getSpecialistStatus(): {
80
+ name: string;
81
+ expertise: string[];
82
+ conversationState: ReturnType<ChatAgentDaemon["getConversationState"]>;
83
+ lastResponseTime: number;
84
+ };
85
+ /**
86
+ * Trigger specialist to respond in a discussion with specific context
87
+ * Used for proactive responses (e.g., bug detection triggering Giuseppe)
88
+ */
89
+ respondWithContext(discussionId: string, activityId: string, contextMessage: string): Promise<void>;
90
+ }
91
+ //# sourceMappingURL=specialist.d.ts.map
@@ -0,0 +1,399 @@
1
+ "use strict";
2
+ /**
3
+ * Specialist Daemon
4
+ *
5
+ * A lightweight daemon for specialist bots that only responds when @mentioned.
6
+ * Specialists are invited to discussions by the orchestrator (HAL) to handle
7
+ * specific complex tasks.
8
+ *
9
+ * Key differences from ChatAgentDaemon:
10
+ * - Only responds when @mentioned (not all messages)
11
+ * - Has specialized system prompt from Specialist config
12
+ * - More tool-focused, less conversational
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SpecialistDaemon = void 0;
16
+ const base_1 = require("./base");
17
+ const logger_1 = require("../../lib/logger");
18
+ class SpecialistDaemon extends base_1.ChatAgentDaemon {
19
+ specialistLogger;
20
+ specialist;
21
+ lastResponseTime = 0;
22
+ minResponseGap = 2000; // 2 seconds minimum between responses
23
+ constructor(config) {
24
+ super(config);
25
+ this.specialist = config.specialist;
26
+ this.specialistLogger = (0, logger_1.createLogger)({
27
+ component: "SpecialistDaemon",
28
+ botId: config.botClient.userId,
29
+ specialistName: config.specialist.name,
30
+ });
31
+ }
32
+ // ===== AGENT DIRECTORY OVERRIDES =====
33
+ /**
34
+ * Override agent name for Agent Directory - uses specialist's configured name
35
+ */
36
+ getAgentName() {
37
+ const nameParts = this.specialist.name.split(" ");
38
+ const firstName = nameParts[0] || "Specialist";
39
+ const lastName = nameParts.slice(1).join(" ") || "Bot";
40
+ return { firstName, lastName };
41
+ }
42
+ /**
43
+ * Override agent description for Agent Directory - uses specialist's expertise
44
+ */
45
+ getAgentDescription() {
46
+ return `${this.specialist.name} - Specialist bot.\n\nExpertise: ${this.specialist.expertise.join(", ")}\n\n${this.specialist.systemPrompt.substring(0, 500)}...`;
47
+ }
48
+ /**
49
+ * Override Position details for Specialist - uses specialist's expertise
50
+ */
51
+ getPositionDetails() {
52
+ return {
53
+ name: `${this.specialist.name} Position`,
54
+ purpose: `Specialist bot for: ${this.specialist.expertise.join(", ")}`,
55
+ personaTone: "Technical, precise, and data-focused. Responds with structured results.",
56
+ coreCapabilities: this.specialist.expertise.map(e => `- ${e}`).join("\n"),
57
+ boundaries: "- Only respond when explicitly @mentioned\n- Never fabricate data - always use tools\n- Stay focused on specialty area\n- Hand back to orchestrator when done",
58
+ };
59
+ }
60
+ /**
61
+ * Specialist gets more tools for complex operations
62
+ */
63
+ getToolWhitelist() {
64
+ return [
65
+ // All orchestrator tools
66
+ "list_workflows",
67
+ "list_workflow_phases",
68
+ "get_workflow_schema",
69
+ "list_workflows_minimal",
70
+ "list_activities",
71
+ "show_activity_by_id",
72
+ "count_activities",
73
+ "create_activity",
74
+ "update_activity",
75
+ "join_discussion",
76
+ "add_discussion_message",
77
+ "invite_discussion_members",
78
+ "fetch_discussion_messages",
79
+ "get_activity_from_discussion",
80
+ "list_my_discussions",
81
+ "search_workspace_users",
82
+ // Insight tools
83
+ "list_insights",
84
+ "get_insight_data",
85
+ "preview_insight",
86
+ "create_insight",
87
+ "update_insight",
88
+ "remove_insight",
89
+ // Workflow config
90
+ "update_workflow_field",
91
+ "update_workflow_phase",
92
+ "install_workflow",
93
+ "remove_workflow",
94
+ // Template tools
95
+ "list_templates",
96
+ "get_template",
97
+ "create_template",
98
+ "install_template",
99
+ // Other
100
+ "upload_files",
101
+ "test_function_field",
102
+ ];
103
+ }
104
+ /**
105
+ * Force compact output for schema tools (avoid verbose field dumps in discussions)
106
+ */
107
+ preprocessToolInput(toolName, input) {
108
+ if (toolName === "get_workflow_schema") {
109
+ return { ...input, compact: true };
110
+ }
111
+ return input;
112
+ }
113
+ /**
114
+ * Override to only process messages where we're @mentioned
115
+ */
116
+ async extractIncomingMessage(signal) {
117
+ // Get base message extraction
118
+ const message = await super.extractIncomingMessage(signal);
119
+ if (!message)
120
+ return null;
121
+ // Specialists only respond when mentioned
122
+ if (!this.isMentionedInMessage(message)) {
123
+ this.specialistLogger.debug("Message doesn't mention specialist, ignoring", {
124
+ discussion: message.discussionId,
125
+ from: message.senderName,
126
+ });
127
+ return null;
128
+ }
129
+ // Rate limit responses
130
+ const now = Date.now();
131
+ if (now - this.lastResponseTime < this.minResponseGap) {
132
+ this.specialistLogger.debug("Rate limiting specialist response", {
133
+ timeSinceLastResponse: now - this.lastResponseTime,
134
+ });
135
+ return null;
136
+ }
137
+ // Mark as high priority since we're explicitly mentioned
138
+ message.priority = "high";
139
+ message.priorityReason = `Specialist ${this.specialist.name} was tagged`;
140
+ this.specialistLogger.info("Specialist mentioned, processing message", {
141
+ discussion: message.discussionId,
142
+ from: message.senderName,
143
+ preview: message.content.substring(0, 50),
144
+ });
145
+ return message;
146
+ }
147
+ /**
148
+ * Check if this specialist is mentioned in the message
149
+ * Supports various mention formats:
150
+ * - @"Specialist Name"
151
+ * - @SpecialistName (no spaces)
152
+ * - Direct user tag [hailerTag|Name](userId)
153
+ */
154
+ isMentionedInMessage(message) {
155
+ const content = message.content;
156
+ const name = this.specialist.name;
157
+ const userId = this.botClient.userId;
158
+ // Check for hailerTag mention (most reliable)
159
+ const hailerTagPattern = new RegExp(`\\[hailerTag\\|[^\\]]*\\]\\(${userId}\\)`, "i");
160
+ if (hailerTagPattern.test(content)) {
161
+ return true;
162
+ }
163
+ // Check for @"Name" mention
164
+ if (content.includes(`@"${name}"`)) {
165
+ return true;
166
+ }
167
+ // Check for @Name (no spaces version)
168
+ const nameNoSpaces = name.replace(/\s+/g, "");
169
+ if (content.includes(`@${nameNoSpaces}`)) {
170
+ return true;
171
+ }
172
+ // Check for @Name (first word)
173
+ const firstName = name.split(" ")[0];
174
+ if (content.includes(`@${firstName}`)) {
175
+ return true;
176
+ }
177
+ // Check message.isMention (set by parent class)
178
+ if (message.isMention) {
179
+ return true;
180
+ }
181
+ return false;
182
+ }
183
+ /**
184
+ * Override system prompt with specialist-specific prompt
185
+ */
186
+ getSystemPrompt() {
187
+ const now = new Date();
188
+ return `${this.specialist.systemPrompt}
189
+
190
+ <current_time>${now.toISOString()}</current_time>
191
+
192
+ <bot_info>
193
+ Bot ID: ${this.botClient.userId}
194
+ Name: ${this.specialist.name}
195
+ </bot_info>
196
+
197
+ <response_rules>
198
+ - You were invited to this discussion to help with a specific task
199
+ - Read HAL's handoff message to understand what's needed
200
+ - Use MCP tools to complete the task - NEVER fabricate data
201
+ - Respond with clear, structured results
202
+ - Include activity links using #activityId format
203
+ - Be concise and technical - data first, explanation second
204
+ </response_rules>
205
+
206
+ <tool_parameters>
207
+ <context_ids>
208
+ Extract IDs from the incoming tag and HAL's handoff:
209
+ - activityId attribute → show_activity_by_id, update_activity
210
+ - discussionId attribute → get_activity_from_discussion
211
+ - workflowId, fieldId → insight tools
212
+ </context_ids>
213
+
214
+ <never_do>
215
+ - Call tools with empty parameters {}
216
+ - Use field LABELS as fieldIds (fieldId must be 24-char hex)
217
+ - Guess IDs - always extract from context
218
+ </never_do>
219
+
220
+ <update_activity_formats>
221
+ - Single mode: use activityId parameter
222
+ - Bulk mode: use _id inside activities array (NOT activityId)
223
+ </update_activity_formats>
224
+
225
+ <field_values>
226
+ - numericunit: 78 (NOT {"type":"numericunit","value":78})
227
+ - activitylink: "abc123..." (NOT {"_id":"abc123","name":"..."})
228
+ </field_values>
229
+ </tool_parameters>
230
+
231
+ <insight_tools>
232
+ <critical>
233
+ - fieldId MUST be 24-character hex ID, NOT the field label!
234
+ - Field names must be SQL-safe: no spaces (use camelCase)
235
+ </critical>
236
+
237
+ <create_insight_format>
238
+ sources: [{
239
+ name: "tableAlias",
240
+ workflowId: "691ffdf84217e9e8434e56ad",
241
+ fields: [
242
+ { name: "playerName", fieldId: "691ffdf84217e9e8434e56b1" },
243
+ { name: "injuryType", fieldId: "691ffdf84217e9e8434e56b2" }
244
+ ]
245
+ }]
246
+ </create_insight_format>
247
+
248
+ <hailer_sql_syntax>
249
+ Hailer insights: fields are mapped in sources.fields, then referenced by ALIAS in query.
250
+
251
+ HOW IT WORKS:
252
+ 1. Define fields in sources: { name: "playerName", fieldId: "691fff..." }
253
+ 2. Use the NAME (alias) in SQL: SELECT playerName FROM tableName
254
+
255
+ SELECT columns - use the field ALIAS names you defined:
256
+ - playerName, injuryType ← custom fields (by alias)
257
+ - name ← built-in activity name
258
+
259
+ Column aliases with spaces need quotes:
260
+ - playerName as "Player Name"
261
+ - injuryType as "Injury Type"
262
+
263
+ LIMITATIONS - DO NOT USE:
264
+ - Phase filtering (no _phase column)
265
+ - Date functions like NOW(), date('now'), CURRENT_DATE
266
+ - Complex WHERE clauses with dates
267
+
268
+ Keep queries SIMPLE: SELECT, FROM, basic WHERE (string comparisons), ORDER BY.
269
+ Users can filter via UI "Show Filters" button.
270
+ </hailer_sql_syntax>
271
+
272
+ <correct_query_example>
273
+ sources: [{
274
+ name: "injuries",
275
+ workflowId: "691ffdf84217e9e8434e56ad",
276
+ fields: [
277
+ { name: "playerName", fieldId: "691ffdf84217e9e8434e5694" },
278
+ { name: "injuryType", fieldId: "691ffdf84217e9e8434e5695" }
279
+ ]
280
+ }]
281
+
282
+ query: "SELECT playerName as \\"Player\\", injuryType as \\"Injury Type\\" FROM injuries ORDER BY playerName ASC"
283
+
284
+ WRONG (will fail):
285
+ - WHERE expectedRecovery > date('now')
286
+ - WHERE _phase = 'phaseId'
287
+ - SELECT FIELD(fieldId) as column
288
+ </correct_query_example>
289
+
290
+ <where_to_get_ids>
291
+ HAL's handoff contains workflowId, fieldIds, and phaseIds. Use them exactly.
292
+ If not provided, call get_workflow_schema AND list_workflow_phases.
293
+ </where_to_get_ids>
294
+ </insight_tools>
295
+
296
+ <response_format>
297
+ When you complete a task, respond with:
298
+ <respond discussion="DISCUSSION_ID">
299
+ [Status emoji] [Brief summary]
300
+
301
+ **What I did:**
302
+ - Step 1: ...
303
+ - Step 2: ...
304
+
305
+ **Results:**
306
+ [Data, links, or confirmation]
307
+
308
+ **Next steps (if applicable):**
309
+ [Suggestions for follow-up]
310
+ </respond>
311
+
312
+ If you need clarification:
313
+ <respond discussion="DISCUSSION_ID">
314
+ I need more information to complete this task:
315
+ - Question 1?
316
+ - Question 2?
317
+ </respond>
318
+ </response_format>`;
319
+ }
320
+ /**
321
+ * Track response time for rate limiting
322
+ */
323
+ async postResponse(discussionId, content) {
324
+ await super.postResponse(discussionId, content);
325
+ this.lastResponseTime = Date.now();
326
+ }
327
+ /**
328
+ * Get specialist status
329
+ */
330
+ getSpecialistStatus() {
331
+ return {
332
+ name: this.specialist.name,
333
+ expertise: this.specialist.expertise,
334
+ conversationState: this.getConversationState(),
335
+ lastResponseTime: this.lastResponseTime,
336
+ };
337
+ }
338
+ /**
339
+ * Trigger specialist to respond in a discussion with specific context
340
+ * Used for proactive responses (e.g., bug detection triggering Giuseppe)
341
+ */
342
+ async respondWithContext(discussionId, activityId, contextMessage) {
343
+ this.specialistLogger.info('Triggering contextual response', { discussionId, activityId });
344
+ try {
345
+ // Join the discussion first using MCP tool
346
+ // Note: join_discussion expects activityId to find the linked discussion
347
+ const joinResult = await this.callMcpTool("join_discussion", { activityId });
348
+ const joinResultText = joinResult?.content?.[0]?.text || '';
349
+ this.specialistLogger.debug('Join discussion result', {
350
+ activityId,
351
+ resultPreview: joinResultText.substring(0, 200)
352
+ });
353
+ // Get workspace ID from bot client cache
354
+ const workspaceId = this.botClient.workspaceCache?.currentWorkspace?._id || '';
355
+ if (!workspaceId) {
356
+ this.specialistLogger.warn('No workspace ID available from cache');
357
+ }
358
+ // Create a synthetic incoming message with the context
359
+ const syntheticMessage = {
360
+ id: `synthetic-${Date.now()}`,
361
+ discussionId,
362
+ linkedActivityId: activityId,
363
+ workspaceId,
364
+ content: contextMessage,
365
+ senderName: 'System',
366
+ senderId: 'system',
367
+ timestamp: Date.now(),
368
+ priority: 'high',
369
+ priorityReason: 'system_notification',
370
+ isReplyToBot: false,
371
+ isMention: true, // Treat as mention so specialist responds
372
+ isDirectMessage: false,
373
+ };
374
+ this.specialistLogger.info('Queuing synthetic message for LLM pipeline', {
375
+ discussionId,
376
+ activityId,
377
+ contentLength: contextMessage.length
378
+ });
379
+ // Process through normal LLM pipeline
380
+ await this['processMessage'](syntheticMessage);
381
+ this.specialistLogger.info('Contextual response completed', { discussionId, activityId });
382
+ }
383
+ catch (error) {
384
+ // Properly serialize error for logging
385
+ const errorMessage = error instanceof Error ? error.message : String(error);
386
+ const errorStack = error instanceof Error ? error.stack : undefined;
387
+ this.specialistLogger.error('Failed to respond with context', {
388
+ discussionId,
389
+ activityId,
390
+ errorMessage,
391
+ errorStack
392
+ });
393
+ // Re-throw so caller knows it failed
394
+ throw error;
395
+ }
396
+ }
397
+ }
398
+ exports.SpecialistDaemon = SpecialistDaemon;
399
+ //# sourceMappingURL=specialist.js.map
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Tool Schema Loader
3
+ *
4
+ * Manages MCP tool discovery, schema loading, and filtering.
5
+ * Shared between all LLM providers (Anthropic, OpenAI, etc.)
6
+ *
7
+ * Key Features:
8
+ * - Load lightweight tool index from MCP server
9
+ * - Filter tools by groups (READ, WRITE, PLAYGROUND)
10
+ * - Load full schemas on-demand (token-efficient)
11
+ * - Cache loaded schemas
12
+ */
13
+ import { ToolGroup } from '../../mcp/tool-registry';
14
+ import { JsonSchema } from './types';
15
+ import Anthropic from '@anthropic-ai/sdk';
16
+ export interface ToolIndexEntry {
17
+ name: string;
18
+ category: string;
19
+ description: string;
20
+ }
21
+ export interface ToolDefinition {
22
+ name: string;
23
+ description: string;
24
+ input_schema: JsonSchema;
25
+ }
26
+ export interface LoadToolsOptions {
27
+ mcpServerUrl: string;
28
+ mcpServerApiKey: string;
29
+ allowedGroups: ToolGroup[];
30
+ allowedTools?: string[];
31
+ excludeMessageFetchTools?: boolean;
32
+ }
33
+ export declare class ToolSchemaLoader {
34
+ private toolSchemaCache;
35
+ /**
36
+ * Load tool index with filtering
37
+ * Returns lightweight tool list with optional exclusions
38
+ */
39
+ loadToolIndex(options: LoadToolsOptions): Promise<ToolIndexEntry[]>;
40
+ /**
41
+ * Load full schema for a specific tool on-demand
42
+ */
43
+ loadToolSchema(mcpServerUrl: string, mcpServerApiKey: string, toolName: string): Promise<any>;
44
+ /**
45
+ * Convert tool index to minimal tool definitions (stubs)
46
+ * Full schemas will be loaded on-demand when needed
47
+ */
48
+ toMinimalToolDefinitions(toolIndex: ToolIndexEntry[]): Anthropic.Tool[];
49
+ /**
50
+ * Get count of loaded schemas
51
+ */
52
+ getLoadedSchemaCount(): number;
53
+ /**
54
+ * Clear schema cache
55
+ */
56
+ clearCache(): void;
57
+ /**
58
+ * Fetch tool index from MCP server
59
+ */
60
+ private fetchMcpToolIndex;
61
+ }
62
+ //# sourceMappingURL=tool-schema-loader.d.ts.map