@hailer/mcp 0.1.6 → 0.1.9

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 (137) hide show
  1. package/.claude/agents/agent-dmitri-activity-crud.md +3 -1
  2. package/.claude/agents/agent-giuseppe-app-builder.md +11 -12
  3. package/.claude/agents/agent-kenji-data-reader.md +5 -3
  4. package/.claude/hooks/sync-marketplace-agents.cjs +117 -56
  5. package/.claude/skills/hailer-app-builder/SKILL.md +506 -0
  6. package/.claude/skills/publish-hailer-app/SKILL.md +169 -0
  7. package/.claude/skills/tool-parameter-usage/SKILL.md +112 -0
  8. package/CHANGELOG.md +20 -0
  9. package/CLAUDE.md +37 -16
  10. package/REFACTOR_STATUS.md +127 -0
  11. package/dist/cli.js +0 -0
  12. package/dist/client/agents/base.d.ts +202 -0
  13. package/dist/client/agents/base.js +737 -0
  14. package/dist/client/agents/definitions.d.ts +53 -0
  15. package/dist/client/agents/definitions.js +178 -0
  16. package/dist/client/agents/orchestrator.d.ts +119 -0
  17. package/dist/client/agents/orchestrator.js +760 -0
  18. package/dist/client/agents/specialist.d.ts +86 -0
  19. package/dist/client/agents/specialist.js +340 -0
  20. package/dist/client/bot-manager.d.ts +44 -0
  21. package/dist/client/bot-manager.js +173 -0
  22. package/dist/client/chat-agent-daemon.d.ts +464 -0
  23. package/dist/client/chat-agent-daemon.js +1774 -0
  24. package/dist/client/daemon-factory.d.ts +106 -0
  25. package/dist/client/daemon-factory.js +301 -0
  26. package/dist/client/factory.d.ts +107 -0
  27. package/dist/client/factory.js +304 -0
  28. package/dist/client/index.d.ts +17 -0
  29. package/dist/client/index.js +38 -0
  30. package/dist/client/multi-bot-manager.d.ts +18 -0
  31. package/dist/client/multi-bot-manager.js +88 -1
  32. package/dist/client/orchestrator-daemon.d.ts +87 -0
  33. package/dist/client/orchestrator-daemon.js +444 -0
  34. package/dist/client/services/agent-registry.d.ts +108 -0
  35. package/dist/client/services/agent-registry.js +630 -0
  36. package/dist/client/services/conversation-manager.d.ts +50 -0
  37. package/dist/client/services/conversation-manager.js +136 -0
  38. package/dist/client/services/mcp-client.d.ts +48 -0
  39. package/dist/client/services/mcp-client.js +105 -0
  40. package/dist/client/services/message-classifier.d.ts +37 -0
  41. package/dist/client/services/message-classifier.js +187 -0
  42. package/dist/client/services/message-formatter.d.ts +84 -0
  43. package/dist/client/services/message-formatter.js +353 -0
  44. package/dist/client/services/session-logger.d.ts +106 -0
  45. package/dist/client/services/session-logger.js +446 -0
  46. package/dist/client/services/tool-executor.d.ts +41 -0
  47. package/dist/client/services/tool-executor.js +169 -0
  48. package/dist/client/services/workspace-schema-cache.d.ts +149 -0
  49. package/dist/client/services/workspace-schema-cache.js +732 -0
  50. package/dist/client/specialist-daemon.d.ts +77 -0
  51. package/dist/client/specialist-daemon.js +197 -0
  52. package/dist/client/specialists.d.ts +53 -0
  53. package/dist/client/specialists.js +178 -0
  54. package/dist/client/tool-schema-loader.d.ts +4 -3
  55. package/dist/client/tool-schema-loader.js +54 -8
  56. package/dist/client/types.d.ts +283 -55
  57. package/dist/client/types.js +113 -2
  58. package/dist/config.d.ts +1 -1
  59. package/dist/config.js +1 -1
  60. package/dist/core.d.ts +10 -2
  61. package/dist/core.js +43 -27
  62. package/dist/lib/logger.js +15 -3
  63. package/dist/mcp/UserContextCache.js +2 -2
  64. package/dist/mcp/hailer-clients.js +5 -5
  65. package/dist/mcp/signal-handler.js +27 -5
  66. package/dist/mcp/tools/activity.js +137 -65
  67. package/dist/mcp/tools/app-core.js +4 -140
  68. package/dist/mcp/tools/app-marketplace.js +15 -260
  69. package/dist/mcp/tools/app-member.js +2 -73
  70. package/dist/mcp/tools/app-scaffold.js +146 -87
  71. package/dist/mcp/tools/discussion.js +348 -73
  72. package/dist/mcp/tools/insight.js +74 -190
  73. package/dist/mcp/tools/workflow.js +20 -94
  74. package/dist/mcp/utils/hailer-api-client.d.ts +4 -2
  75. package/dist/mcp/utils/hailer-api-client.js +24 -10
  76. package/dist/mcp-server.d.ts +4 -0
  77. package/dist/mcp-server.js +24 -4
  78. package/dist/routes/agents.d.ts +44 -0
  79. package/dist/routes/agents.js +311 -0
  80. package/dist/services/agent-credential-store.d.ts +73 -0
  81. package/dist/services/agent-credential-store.js +212 -0
  82. package/lineup-manager/dist/assets/index-8ce6041d.css +1 -0
  83. package/lineup-manager/dist/assets/index-e168f265.js +600 -0
  84. package/lineup-manager/dist/index.html +15 -0
  85. package/lineup-manager/dist/manifest.json +17 -0
  86. package/lineup-manager/dist/vite.svg +1 -0
  87. package/package.json +1 -1
  88. package/dist/client/adaptive-documentation-bot.d.ts +0 -106
  89. package/dist/client/adaptive-documentation-bot.js +0 -464
  90. package/dist/client/adaptive-documentation-types.d.ts +0 -66
  91. package/dist/client/adaptive-documentation-types.js +0 -9
  92. package/dist/client/agent-activity-bot.d.ts +0 -51
  93. package/dist/client/agent-activity-bot.js +0 -166
  94. package/dist/client/agent-tracker.d.ts +0 -499
  95. package/dist/client/agent-tracker.js +0 -659
  96. package/dist/client/description-updater.d.ts +0 -56
  97. package/dist/client/description-updater.js +0 -259
  98. package/dist/client/log-parser.d.ts +0 -72
  99. package/dist/client/log-parser.js +0 -387
  100. package/dist/client/mcp-assistant.d.ts +0 -21
  101. package/dist/client/mcp-assistant.js +0 -58
  102. package/dist/client/mcp-client.d.ts +0 -50
  103. package/dist/client/mcp-client.js +0 -538
  104. package/dist/client/message-processor.d.ts +0 -35
  105. package/dist/client/message-processor.js +0 -357
  106. package/dist/client/providers/anthropic-provider.d.ts +0 -19
  107. package/dist/client/providers/anthropic-provider.js +0 -645
  108. package/dist/client/providers/assistant-provider.d.ts +0 -17
  109. package/dist/client/providers/assistant-provider.js +0 -51
  110. package/dist/client/providers/llm-provider.d.ts +0 -47
  111. package/dist/client/providers/llm-provider.js +0 -367
  112. package/dist/client/providers/openai-provider.d.ts +0 -23
  113. package/dist/client/providers/openai-provider.js +0 -630
  114. package/dist/client/simple-llm-caller.d.ts +0 -19
  115. package/dist/client/simple-llm-caller.js +0 -100
  116. package/dist/client/skill-generator.d.ts +0 -81
  117. package/dist/client/skill-generator.js +0 -386
  118. package/dist/client/test-adaptive-bot.d.ts +0 -9
  119. package/dist/client/test-adaptive-bot.js +0 -82
  120. package/dist/client/token-pricing.d.ts +0 -38
  121. package/dist/client/token-pricing.js +0 -127
  122. package/dist/client/token-tracker.d.ts +0 -232
  123. package/dist/client/token-tracker.js +0 -457
  124. package/dist/client/token-usage-bot.d.ts +0 -53
  125. package/dist/client/token-usage-bot.js +0 -153
  126. package/dist/client/tool-executor.d.ts +0 -69
  127. package/dist/client/tool-executor.js +0 -159
  128. package/dist/lib/materialize.d.ts +0 -3
  129. package/dist/lib/materialize.js +0 -101
  130. package/dist/lib/normalizedName.d.ts +0 -7
  131. package/dist/lib/normalizedName.js +0 -48
  132. package/dist/lib/terminal-prompt.d.ts +0 -9
  133. package/dist/lib/terminal-prompt.js +0 -108
  134. package/dist/mcp/tools/skill.d.ts +0 -10
  135. package/dist/mcp/tools/skill.js +0 -279
  136. package/dist/mcp/tools/workflow-template.d.ts +0 -19
  137. package/dist/mcp/tools/workflow-template.js +0 -822
@@ -0,0 +1,444 @@
1
+ "use strict";
2
+ /**
3
+ * Orchestrator Daemon (HAL)
4
+ *
5
+ * The main conversational bot that handles general chat and coordinates
6
+ * with specialist bots when tasks are too complex.
7
+ *
8
+ * HAL can:
9
+ * - Handle general conversation and simple queries
10
+ * - Detect when a task needs specialist help
11
+ * - Invite specialist bots to the discussion
12
+ * - Hand off context to specialists
13
+ * - Summarize specialist responses for users
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.OrchestratorDaemon = void 0;
17
+ const chat_agent_daemon_1 = require("./chat-agent-daemon");
18
+ const specialists_1 = require("./specialists");
19
+ const logger_1 = require("../lib/logger");
20
+ class OrchestratorDaemon extends chat_agent_daemon_1.ChatAgentDaemon {
21
+ orchestratorLogger;
22
+ specialists = new Map();
23
+ activeSpecialistsInDiscussion = new Map(); // discussionId -> Set<specialistUserId>
24
+ specialistUserIds = new Map(); // specialistKey -> userId
25
+ toolsUsedInCurrentMessage = false; // Track if tools were used in current message processing
26
+ constructor(config) {
27
+ super(config);
28
+ this.orchestratorLogger = (0, logger_1.createLogger)({
29
+ component: "OrchestratorDaemon",
30
+ botId: config.botClient.userId,
31
+ });
32
+ // Register specialists from config
33
+ for (const [key, specialist] of Object.entries(specialists_1.SPECIALISTS)) {
34
+ this.specialists.set(key, specialist);
35
+ }
36
+ // Set specialist user IDs if provided
37
+ if (config.specialistUserIds) {
38
+ this.specialistUserIds = config.specialistUserIds;
39
+ }
40
+ }
41
+ // ===== AGENT DIRECTORY OVERRIDES =====
42
+ /**
43
+ * Override agent name for Agent Directory
44
+ */
45
+ getAgentName() {
46
+ return { firstName: "HAL", lastName: "Orchestrator" };
47
+ }
48
+ /**
49
+ * Override agent description for Agent Directory
50
+ */
51
+ getAgentDescription() {
52
+ return "HAL - the main Hailer Assistant orchestrator. Handles general conversation and coordinates specialist bots for complex tasks.";
53
+ }
54
+ /**
55
+ * Override Position details for Orchestrator
56
+ */
57
+ getPositionDetails() {
58
+ return {
59
+ name: "HAL Orchestrator",
60
+ purpose: "Main point of contact for users. Handles general conversation, triages requests, and coordinates specialist bots for complex tasks.",
61
+ personaTone: "Sharp, efficient, and helpful. Professional but approachable. Uses clear, concise language.",
62
+ coreCapabilities: "- Monitor all workspace discussions\n- Respond to general queries and greetings\n- Detect when specialist help is needed\n- Invite specialists to discussions\n- Coordinate multi-step workflows\n- Execute MCP tools for data operations",
63
+ boundaries: "- Never fabricate data - always use tools\n- Don't attempt complex technical tasks alone\n- Hand off to specialists for: bulk operations, report creation, workflow setup\n- Don't share credentials or sensitive config",
64
+ };
65
+ }
66
+ /**
67
+ * Register a specialist's Hailer user ID
68
+ * Called during initialization when we know the specialist bot's user ID
69
+ */
70
+ registerSpecialistUserId(specialistKey, userId) {
71
+ this.specialistUserIds.set(specialistKey, userId);
72
+ const specialist = this.specialists.get(specialistKey);
73
+ if (specialist) {
74
+ specialist.botUserId = userId;
75
+ this.orchestratorLogger.info("Specialist registered", {
76
+ key: specialistKey,
77
+ name: specialist.name,
78
+ userId,
79
+ });
80
+ }
81
+ }
82
+ /**
83
+ * Check if a specialist is already active in a discussion
84
+ */
85
+ isSpecialistActiveInDiscussion(discussionId, specialistUserId) {
86
+ const active = this.activeSpecialistsInDiscussion.get(discussionId);
87
+ return active?.has(specialistUserId) ?? false;
88
+ }
89
+ /**
90
+ * Mark a specialist as active in a discussion
91
+ */
92
+ markSpecialistActive(discussionId, specialistUserId) {
93
+ if (!this.activeSpecialistsInDiscussion.has(discussionId)) {
94
+ this.activeSpecialistsInDiscussion.set(discussionId, new Set());
95
+ }
96
+ this.activeSpecialistsInDiscussion.get(discussionId).add(specialistUserId);
97
+ }
98
+ /**
99
+ * Invite a specialist to a discussion
100
+ */
101
+ async inviteSpecialist(specialist, discussionId, handoffContext) {
102
+ const specialistUserId = specialist.botUserId;
103
+ if (!specialistUserId) {
104
+ this.orchestratorLogger.warn("Specialist has no user ID", {
105
+ name: specialist.name,
106
+ });
107
+ return false;
108
+ }
109
+ // Check if already active
110
+ if (this.isSpecialistActiveInDiscussion(discussionId, specialistUserId)) {
111
+ this.orchestratorLogger.debug("Specialist already in discussion", {
112
+ name: specialist.name,
113
+ discussionId,
114
+ });
115
+ // Just tag them again
116
+ await this.postResponse(discussionId, `@"${specialist.name}" - ${handoffContext}`);
117
+ return true;
118
+ }
119
+ try {
120
+ this.orchestratorLogger.info("Inviting specialist to discussion", {
121
+ name: specialist.name,
122
+ userId: specialistUserId,
123
+ discussionId,
124
+ });
125
+ // Invite using MCP tool
126
+ await this.callMcpTool("invite_discussion_members", {
127
+ discussionId,
128
+ userIds: [specialistUserId],
129
+ });
130
+ this.markSpecialistActive(discussionId, specialistUserId);
131
+ // Post handoff message
132
+ await this.postResponse(discussionId, `@"${specialist.name}" - ${handoffContext}`);
133
+ this.orchestratorLogger.info("Specialist invited successfully", {
134
+ name: specialist.name,
135
+ discussionId,
136
+ });
137
+ return true;
138
+ }
139
+ catch (error) {
140
+ this.orchestratorLogger.error("Failed to invite specialist", {
141
+ name: specialist.name,
142
+ discussionId,
143
+ error: error instanceof Error ? error.message : String(error),
144
+ });
145
+ return false;
146
+ }
147
+ }
148
+ /**
149
+ * Override system prompt to include orchestrator capabilities
150
+ */
151
+ getSystemPrompt() {
152
+ const now = new Date();
153
+ // Build specialist info for prompt
154
+ const specialistInfo = Array.from(this.specialists.entries())
155
+ .map(([key, spec]) => {
156
+ const hasUserId = !!spec.botUserId;
157
+ return `- **${spec.name}** ${hasUserId ? "(available)" : "(not configured)"}
158
+ Expertise: ${spec.expertise.join(", ")}
159
+ Triggers: ${spec.triggerKeywords.slice(0, 5).join(", ")}`;
160
+ })
161
+ .join("\n\n");
162
+ return `<identity>
163
+ You are HAL - the Hailer Assistant. Sharp, efficient, and helpful.
164
+ Bot ID: ${this.botClient.userId}
165
+
166
+ You're the main point of contact for users. You handle general conversation
167
+ and simple tasks yourself, but can bring in specialist bots for complex work.
168
+ </identity>
169
+
170
+ <current_time>${now.toISOString()}</current_time>
171
+
172
+ <personality>
173
+ **BUSINESS MODE** (default):
174
+ - Professional, direct, competent
175
+ - Get things done efficiently
176
+ - Provide accurate information
177
+
178
+ **SARCASM MODE** (for ridiculous requests):
179
+ - Dry wit, not mean-spirited
180
+ - Still help after the gentle mockery
181
+ </personality>
182
+
183
+ <decision_framework>
184
+ For each message, decide:
185
+
186
+ 1. **HIGH PRIORITY** (priority="high"):
187
+ - Direct messages (1:1) -> ALWAYS respond helpfully
188
+ - @mentions -> ALWAYS respond
189
+ - Replies to your messages -> ALWAYS respond
190
+
191
+ 2. **NORMAL PRIORITY** (general chat) - STRICT FILTERING:
192
+
193
+ **RESPOND ONLY IF the message:**
194
+ - Explicitly asks about Hailer (workflows, activities, insights, apps, discussions)
195
+ - Requests to find/list/create/update workspace data
196
+ - Discusses a specific activity, customer, project, or workflow by name
197
+ - You can genuinely help with workspace-related context
198
+ - Is a complex task needing specialist help
199
+
200
+ **ALWAYS IGNORE (output <ignore/>) if:**
201
+ - Random characters, gibberish, keyboard mashing (no real words, repeated patterns)
202
+ - General chit-chat unrelated to workspace ("how are you", jokes)
203
+ - Conversations between other users that don't need you
204
+ - Bare greetings without a question ("hi", "hey")
205
+ - Off-topic discussions (sports, weather, personal chat)
206
+ - Anything you're uncertain about
207
+
208
+ **CRITICAL:** If no clear workspace-related question/task, output <ignore/>.
209
+ When in doubt, IGNORE. Your DEFAULT for normal priority is <ignore/>.
210
+
211
+ 3. **RESPOND FORMAT** (only when you have something helpful):
212
+ <respond discussion="DISCUSSION_ID">
213
+ Your response
214
+ </respond>
215
+
216
+ 4. **IGNORE FORMAT** (use liberally - this is your DEFAULT):
217
+ <ignore/>
218
+ </decision_framework>
219
+
220
+ <specialists>
221
+ You can invite specialist bots when tasks are too complex.
222
+
223
+ ${specialistInfo}
224
+
225
+ **When to invite a specialist:**
226
+ - Creating new workflows/pipelines
227
+ - Setting up reports/insights/dashboards
228
+ - Bulk operations (10+ items)
229
+ - Complex multi-step data tasks
230
+ - Workflow configuration changes
231
+
232
+ **When to handle yourself:**
233
+ - General chat, greetings
234
+ - Simple queries (list activities, show details)
235
+ - Single create/update operations
236
+ - Questions about the conversation
237
+ - Clarifying user requirements
238
+
239
+ **How to invite:**
240
+ <invite specialist="hailerExpert">
241
+ Clear description of what you need done.
242
+ Include relevant context from the conversation.
243
+ </invite>
244
+
245
+ After using <invite>, I will:
246
+ 1. Invite them to the discussion
247
+ 2. Post your handoff message mentioning them
248
+ 3. They will see it and take action
249
+ </specialists>
250
+
251
+ <your_tools>
252
+ You have access to basic MCP tools for simple operations:
253
+ - list_workflows, list_workflow_phases, get_workflow_schema
254
+ - list_activities, show_activity_by_id, count_activities
255
+ - create_activity, update_activity (single operations)
256
+ - search_workspace_users
257
+ - Discussion tools (join_discussion, add_discussion_message, invite_discussion_members)
258
+
259
+ For complex operations (workflow creation, insights, bulk ops), invite a specialist.
260
+
261
+ **CRITICAL for join_discussion when inviting users:**
262
+ ALWAYS pass these parameters from the incoming message:
263
+ - inviteUserId = user_id attribute
264
+ - sourceActivityId = activity_id attribute (creates "came from" link!)
265
+ - welcomeReason = why they're being invited
266
+ </your_tools>
267
+
268
+ <tagging>
269
+ **Activity Tags:** #ACTIVITY_ID (24-char hex)
270
+ - Correct: "Check out #691ffe874217e9e8434e57fc"
271
+ - Wrong: "Check out #691ffe874217e9e8434e57fc (Name)" - name auto-displays
272
+
273
+ **User Mentions:** @"Full Name" or @userId
274
+ </tagging>
275
+
276
+ <rules>
277
+ - Be concise - snappy responses, not essays
278
+ - Use your memory - reference past conversations
279
+ - For HIGH priority: respond immediately
280
+ - For NORMAL priority: your DEFAULT is <ignore/>. Only break if you see a clear workspace question.
281
+ - **Gibberish test:** No recognizable words, no vowels, repeated patterns = <ignore/>
282
+ - **Relevance test:** Is this about workflows/activities/insights? If not = <ignore/>
283
+ - When inviting specialists, explain to the user what's happening
284
+ - After specialist responds, summarize for the user if needed
285
+ </rules>`;
286
+ }
287
+ /**
288
+ * Override response handling to detect specialist invitations
289
+ */
290
+ async handleLlmResponse(response, originalMessage) {
291
+ // Add assistant response to conversation
292
+ this.conversationMessages.push({
293
+ role: "assistant",
294
+ content: response.content,
295
+ });
296
+ // Check for specialist invitation in text content
297
+ const textBlocks = response.content.filter((block) => block.type === "text");
298
+ const textContent = textBlocks.map((b) => b.text).join("\n");
299
+ // Look for <invite specialist="...">...</invite> pattern
300
+ const inviteMatch = textContent.match(/<invite specialist="(\w+)">([\s\S]*?)<\/invite>/);
301
+ if (inviteMatch) {
302
+ const [fullMatch, specialistKey, handoffContext] = inviteMatch;
303
+ const specialist = this.specialists.get(specialistKey);
304
+ if (specialist && specialist.botUserId) {
305
+ this.orchestratorLogger.info("LLM requested specialist invitation", {
306
+ specialist: specialistKey,
307
+ discussionId: originalMessage.discussionId,
308
+ });
309
+ // Extract any text before the invite tag to post as acknowledgment
310
+ const preInviteText = textContent
311
+ .substring(0, textContent.indexOf("<invite"))
312
+ .trim();
313
+ // Check for respond wrapper
314
+ const respondMatch = preInviteText.match(/<respond discussion="([^"]+)">([\s\S]*)/);
315
+ if (respondMatch) {
316
+ const [, discussionId, content] = respondMatch;
317
+ const cleanContent = content.replace(/<\/respond>.*$/s, "").trim();
318
+ if (cleanContent) {
319
+ await this.postResponse(discussionId, cleanContent);
320
+ }
321
+ }
322
+ else if (preInviteText) {
323
+ // No respond wrapper, but there's text - might be for high priority
324
+ if (originalMessage.priority === "high") {
325
+ await this.postResponse(originalMessage.discussionId, preInviteText);
326
+ }
327
+ }
328
+ // Invite the specialist
329
+ const invited = await this.inviteSpecialist(specialist, originalMessage.discussionId, handoffContext.trim());
330
+ if (!invited) {
331
+ // Failed to invite - let user know
332
+ await this.postResponse(originalMessage.discussionId, `I tried to bring in ${specialist.name} but couldn't reach them. Let me try handling this myself...`);
333
+ // Continue with normal handling
334
+ }
335
+ return; // Don't continue with normal response handling
336
+ }
337
+ else {
338
+ this.orchestratorLogger.warn("Specialist not available", {
339
+ key: specialistKey,
340
+ hasSpecialist: !!specialist,
341
+ hasUserId: !!specialist?.botUserId,
342
+ });
343
+ }
344
+ }
345
+ // Check for tool calls
346
+ const toolUseBlocks = response.content.filter((block) => block.type === "tool_use");
347
+ if (toolUseBlocks.length > 0) {
348
+ // Mark that tools were used - subsequent responses should be posted
349
+ this.toolsUsedInCurrentMessage = true;
350
+ // Execute tools and continue conversation
351
+ await this.executeToolsAndContinue(toolUseBlocks, originalMessage);
352
+ return;
353
+ }
354
+ // Check for regular response (no invite, no tools)
355
+ if (textBlocks.length > 0) {
356
+ const responseText = textContent.trim();
357
+ this.orchestratorLogger.info("LLM raw response", {
358
+ discussion: originalMessage.discussionId,
359
+ priority: originalMessage.priority,
360
+ responseLength: responseText.length,
361
+ fullResponse: responseText.substring(0, 500),
362
+ hasIgnoreTag: responseText.includes("<ignore"),
363
+ hasRespondTag: responseText.includes("<respond"),
364
+ });
365
+ // Check for IGNORE decision - remove from context to keep it clean
366
+ if (responseText.includes("<decision>IGNORE</decision>") ||
367
+ responseText.includes("<ignore")) {
368
+ this.orchestratorLogger.debug("LLM decided to ignore - removing from context", {
369
+ discussion: originalMessage.discussionId,
370
+ });
371
+ // Remove both the assistant's response AND the incoming message from context
372
+ this.conversationMessages.pop(); // Remove assistant response we just added
373
+ this.conversationMessages.pop(); // Remove the incoming message
374
+ this.toolsUsedInCurrentMessage = false; // Reset for next message
375
+ return;
376
+ }
377
+ // Check for explicit response directive
378
+ const responseMatch = responseText.match(/<respond discussion="([^"]+)">([\s\S]*?)<\/respond>/);
379
+ if (responseMatch) {
380
+ const targetDiscussion = responseMatch[1];
381
+ const content = responseMatch[2].trim();
382
+ await this.postResponse(targetDiscussion, content);
383
+ this.toolsUsedInCurrentMessage = false; // Reset for next message
384
+ return;
385
+ }
386
+ // For high priority messages, always send substantive responses
387
+ if (originalMessage.priority === "high" &&
388
+ responseText &&
389
+ !responseText.includes("<thinking>") &&
390
+ !responseText.startsWith("I'll") &&
391
+ responseText.length > 10) {
392
+ await this.postResponse(originalMessage.discussionId, responseText);
393
+ this.toolsUsedInCurrentMessage = false; // Reset for next message
394
+ return;
395
+ }
396
+ // For normal priority:
397
+ // - If tools were used, post substantive responses (LLM was doing real work)
398
+ // - Otherwise, require explicit <respond> tag
399
+ if (originalMessage.priority === "normal") {
400
+ if (this.toolsUsedInCurrentMessage && responseText.length > 50 && !responseText.includes("<ignore")) {
401
+ // Tools were used and we have a substantive response - post it
402
+ this.orchestratorLogger.info("Posting tool-assisted response", {
403
+ discussion: originalMessage.discussionId,
404
+ responseLength: responseText.length,
405
+ });
406
+ await this.postResponse(originalMessage.discussionId, responseText);
407
+ this.toolsUsedInCurrentMessage = false; // Reset for next message
408
+ return;
409
+ }
410
+ this.orchestratorLogger.debug("Normal priority without <respond> tag - removing from context", {
411
+ discussion: originalMessage.discussionId,
412
+ responsePreview: responseText.substring(0, 100),
413
+ toolsUsed: this.toolsUsedInCurrentMessage,
414
+ });
415
+ // Remove from context - we didn't respond
416
+ this.conversationMessages.pop(); // Remove assistant response
417
+ this.conversationMessages.pop(); // Remove incoming message
418
+ this.toolsUsedInCurrentMessage = false; // Reset for next message
419
+ }
420
+ }
421
+ }
422
+ /**
423
+ * Get orchestrator status including specialist info
424
+ */
425
+ getOrchestratorStatus() {
426
+ const specialists = Array.from(this.specialists.entries()).map(([key, spec]) => ({
427
+ key,
428
+ name: spec.name,
429
+ available: !!spec.botUserId,
430
+ userId: spec.botUserId,
431
+ }));
432
+ const activeInDiscussions = {};
433
+ for (const [discussionId, userIds] of this.activeSpecialistsInDiscussion) {
434
+ activeInDiscussions[discussionId] = Array.from(userIds);
435
+ }
436
+ return {
437
+ conversationState: this.getConversationState(),
438
+ specialists,
439
+ activeInDiscussions,
440
+ };
441
+ }
442
+ }
443
+ exports.OrchestratorDaemon = OrchestratorDaemon;
444
+ //# sourceMappingURL=orchestrator-daemon.js.map
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Agent Registry Service
3
+ *
4
+ * Handles registration of agents in Hailer workspace workflows:
5
+ * - Agent Directory: Main registry of all bots
6
+ * - Positions: Job descriptions/roles
7
+ * - Teams: Groups of agents
8
+ * - Tool Registry: MCP server configurations
9
+ * - MCP Config: Per-agent MCP configuration
10
+ *
11
+ * WORKSPACE ISOLATION: Uses WorkspaceSchemaCacheService for dynamic ID lookup.
12
+ * Never relies on hardcoded IDs - each workspace has its own workflow IDs.
13
+ */
14
+ import { Logger } from "../../lib/logger";
15
+ import { McpToolCallback, ToolDefinition } from "../types";
16
+ import { WorkspaceSchemaCacheService } from "./workspace-schema-cache";
17
+ export interface AgentInfo {
18
+ firstName: string;
19
+ lastName: string;
20
+ description: string;
21
+ email: string;
22
+ userId: string;
23
+ }
24
+ export interface PositionDetails {
25
+ name: string;
26
+ purpose: string;
27
+ personaTone: string;
28
+ coreCapabilities: string;
29
+ boundaries: string;
30
+ }
31
+ export declare class AgentRegistryService {
32
+ private schemaCache;
33
+ private logger;
34
+ private callMcpTool;
35
+ private getDefaultTeamId;
36
+ private agentDirectoryId;
37
+ private positionId;
38
+ private teamId;
39
+ private toolRegistryId;
40
+ private mcpConfigId;
41
+ private currentWorkspaceId;
42
+ constructor(schemaCache: WorkspaceSchemaCacheService, logger: Logger, callMcpTool: McpToolCallback, getDefaultTeamId: () => string | undefined);
43
+ /**
44
+ * Load registration data - always returns false to force fresh Hailer lookup
45
+ * Kept for API compatibility with base.ts
46
+ */
47
+ loadFromCache(_userId: string, _workspaceId: string): Promise<boolean>;
48
+ /**
49
+ * Get agent directory ID
50
+ */
51
+ getAgentDirectoryId(): string | null;
52
+ /**
53
+ * Get position ID
54
+ */
55
+ getPositionId(): string | null;
56
+ /**
57
+ * Get team ID
58
+ */
59
+ getTeamId(): string | null;
60
+ /**
61
+ * Register all agent data across all workflows
62
+ * Uses schemaCache for dynamic workflow ID lookup
63
+ */
64
+ registerAllAgentData(agentInfo: AgentInfo, positionDetails: PositionDetails, mcpServerUrl: string, toolIndex: ToolDefinition[], workspaceId: string): Promise<void>;
65
+ /**
66
+ * Register this agent in the Agent Directory
67
+ * Uses dynamic schema lookup for workflow/field IDs
68
+ */
69
+ private registerAgentInDirectory;
70
+ /**
71
+ * Find phase ID by trying multiple names (case insensitive, partial match)
72
+ */
73
+ private findPhaseId;
74
+ /**
75
+ * Find existing agent entry by hailerProfile (userId) - most reliable method
76
+ */
77
+ private findAgentByUserId;
78
+ /**
79
+ * Parse first activity from list_activities response
80
+ */
81
+ private parseFirstActivity;
82
+ /**
83
+ * Register/find shared Team for AI agents
84
+ */
85
+ private registerTeam;
86
+ /**
87
+ * Register MCP server in Tool Registry (per-agent)
88
+ */
89
+ private registerToolRegistry;
90
+ /**
91
+ * Register Position for this agent
92
+ */
93
+ private registerPosition;
94
+ /**
95
+ * Register MCP Config for this agent
96
+ */
97
+ private registerMcpConfig;
98
+ /**
99
+ * Link Agent Directory entry to Position and Team
100
+ */
101
+ private linkAgentToPositionAndTeam;
102
+ /**
103
+ * Extract activity ID from MCP tool response text
104
+ * Specifically looks for created activity IDs, not workflow IDs
105
+ */
106
+ private extractActivityId;
107
+ }
108
+ //# sourceMappingURL=agent-registry.d.ts.map