@hailer/mcp 0.1.16 → 0.2.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 (202) hide show
  1. package/dist/app.js +24 -20
  2. package/dist/core.d.ts +33 -9
  3. package/dist/core.js +279 -147
  4. package/dist/mcp/UserContextCache.js +18 -0
  5. package/dist/mcp/hailer-clients.d.ts +9 -1
  6. package/dist/mcp/hailer-clients.js +13 -3
  7. package/dist/mcp/signal-handler.js +1 -1
  8. package/dist/mcp/tool-registry.d.ts +3 -1
  9. package/dist/mcp/tool-registry.js +4 -1
  10. package/dist/mcp/tools/activity.js +43 -34
  11. package/dist/mcp/tools/bot-config/constants.d.ts +23 -0
  12. package/dist/mcp/tools/bot-config/constants.js +94 -0
  13. package/dist/mcp/tools/{bot-config.d.ts → bot-config/core.d.ts} +6 -6
  14. package/dist/mcp/tools/{bot-config.js → bot-config/core.js} +15 -15
  15. package/dist/mcp/tools/bot-config/index.d.ts +10 -0
  16. package/dist/mcp/tools/bot-config/index.js +59 -0
  17. package/dist/mcp/tools/bot-config/tools.d.ts +7 -0
  18. package/dist/mcp/tools/bot-config/tools.js +15 -0
  19. package/dist/mcp/tools/bot-config/types.d.ts +50 -0
  20. package/dist/mcp/tools/bot-config/types.js +6 -0
  21. package/dist/mcp/tools/bug-fixer-tools.d.ts +21 -0
  22. package/dist/mcp/tools/{giuseppe-tools.js → bug-fixer-tools.js} +61 -61
  23. package/dist/mcp/tools/user.js +10 -29
  24. package/dist/mcp/tools/workflow.js +36 -2
  25. package/dist/mcp/utils/data-transformers.d.ts +0 -8
  26. package/dist/mcp/utils/data-transformers.js +0 -28
  27. package/dist/mcp/utils/index.d.ts +4 -1
  28. package/dist/mcp/utils/index.js +17 -3
  29. package/dist/mcp/utils/pagination.d.ts +40 -0
  30. package/dist/mcp/utils/pagination.js +55 -0
  31. package/dist/mcp/utils/response-builder.d.ts +53 -0
  32. package/dist/mcp/utils/response-builder.js +110 -0
  33. package/dist/mcp/utils/tool-helpers.d.ts +0 -8
  34. package/dist/mcp/utils/tool-helpers.js +0 -24
  35. package/dist/mcp/utils/types.d.ts +1 -33
  36. package/dist/mcp/webhook-handler.d.ts +2 -2
  37. package/dist/mcp/webhook-handler.js +5 -3
  38. package/dist/mcp-server.d.ts +2 -2
  39. package/dist/mcp-server.js +167 -140
  40. package/package.json +1 -1
  41. package/REFACTOR_STATUS.md +0 -127
  42. package/dist/agents/bot-manager.d.ts +0 -48
  43. package/dist/agents/bot-manager.js +0 -254
  44. package/dist/agents/factory.d.ts +0 -150
  45. package/dist/agents/factory.js +0 -650
  46. package/dist/agents/giuseppe/ai.d.ts +0 -83
  47. package/dist/agents/giuseppe/ai.js +0 -466
  48. package/dist/agents/giuseppe/bot.d.ts +0 -110
  49. package/dist/agents/giuseppe/bot.js +0 -780
  50. package/dist/agents/giuseppe/config.d.ts +0 -25
  51. package/dist/agents/giuseppe/config.js +0 -227
  52. package/dist/agents/giuseppe/files.d.ts +0 -52
  53. package/dist/agents/giuseppe/files.js +0 -338
  54. package/dist/agents/giuseppe/git.d.ts +0 -48
  55. package/dist/agents/giuseppe/git.js +0 -298
  56. package/dist/agents/giuseppe/index.d.ts +0 -97
  57. package/dist/agents/giuseppe/index.js +0 -258
  58. package/dist/agents/giuseppe/lsp.d.ts +0 -113
  59. package/dist/agents/giuseppe/lsp.js +0 -485
  60. package/dist/agents/giuseppe/monitor.d.ts +0 -118
  61. package/dist/agents/giuseppe/monitor.js +0 -621
  62. package/dist/agents/giuseppe/prompt.d.ts +0 -5
  63. package/dist/agents/giuseppe/prompt.js +0 -94
  64. package/dist/agents/giuseppe/registries/pending-classification.d.ts +0 -28
  65. package/dist/agents/giuseppe/registries/pending-classification.js +0 -50
  66. package/dist/agents/giuseppe/registries/pending-fix.d.ts +0 -30
  67. package/dist/agents/giuseppe/registries/pending-fix.js +0 -42
  68. package/dist/agents/giuseppe/registries/pending.d.ts +0 -27
  69. package/dist/agents/giuseppe/registries/pending.js +0 -49
  70. package/dist/agents/giuseppe/specialist.d.ts +0 -47
  71. package/dist/agents/giuseppe/specialist.js +0 -237
  72. package/dist/agents/giuseppe/types.d.ts +0 -123
  73. package/dist/agents/giuseppe/types.js +0 -9
  74. package/dist/agents/hailer-expert/index.d.ts +0 -8
  75. package/dist/agents/hailer-expert/index.js +0 -14
  76. package/dist/agents/hal/daemon.d.ts +0 -142
  77. package/dist/agents/hal/daemon.js +0 -1103
  78. package/dist/agents/hal/definitions.d.ts +0 -55
  79. package/dist/agents/hal/definitions.js +0 -263
  80. package/dist/agents/hal/index.d.ts +0 -3
  81. package/dist/agents/hal/index.js +0 -8
  82. package/dist/agents/index.d.ts +0 -18
  83. package/dist/agents/index.js +0 -48
  84. package/dist/agents/shared/base.d.ts +0 -216
  85. package/dist/agents/shared/base.js +0 -846
  86. package/dist/agents/shared/services/agent-registry.d.ts +0 -107
  87. package/dist/agents/shared/services/agent-registry.js +0 -629
  88. package/dist/agents/shared/services/conversation-manager.d.ts +0 -50
  89. package/dist/agents/shared/services/conversation-manager.js +0 -136
  90. package/dist/agents/shared/services/mcp-client.d.ts +0 -56
  91. package/dist/agents/shared/services/mcp-client.js +0 -124
  92. package/dist/agents/shared/services/message-classifier.d.ts +0 -37
  93. package/dist/agents/shared/services/message-classifier.js +0 -187
  94. package/dist/agents/shared/services/message-formatter.d.ts +0 -89
  95. package/dist/agents/shared/services/message-formatter.js +0 -371
  96. package/dist/agents/shared/services/session-logger.d.ts +0 -106
  97. package/dist/agents/shared/services/session-logger.js +0 -446
  98. package/dist/agents/shared/services/tool-executor.d.ts +0 -41
  99. package/dist/agents/shared/services/tool-executor.js +0 -169
  100. package/dist/agents/shared/services/workspace-schema-cache.d.ts +0 -125
  101. package/dist/agents/shared/services/workspace-schema-cache.js +0 -578
  102. package/dist/agents/shared/specialist.d.ts +0 -91
  103. package/dist/agents/shared/specialist.js +0 -399
  104. package/dist/agents/shared/tool-schema-loader.d.ts +0 -62
  105. package/dist/agents/shared/tool-schema-loader.js +0 -232
  106. package/dist/agents/shared/types.d.ts +0 -327
  107. package/dist/agents/shared/types.js +0 -121
  108. package/dist/client/agents/base.d.ts +0 -207
  109. package/dist/client/agents/base.js +0 -744
  110. package/dist/client/agents/definitions.d.ts +0 -53
  111. package/dist/client/agents/definitions.js +0 -263
  112. package/dist/client/agents/orchestrator.d.ts +0 -141
  113. package/dist/client/agents/orchestrator.js +0 -1062
  114. package/dist/client/agents/specialist.d.ts +0 -86
  115. package/dist/client/agents/specialist.js +0 -340
  116. package/dist/client/bot-entrypoint.d.ts +0 -7
  117. package/dist/client/bot-entrypoint.js +0 -103
  118. package/dist/client/bot-manager.d.ts +0 -44
  119. package/dist/client/bot-manager.js +0 -173
  120. package/dist/client/bot-runner.d.ts +0 -35
  121. package/dist/client/bot-runner.js +0 -188
  122. package/dist/client/chat-agent-daemon.d.ts +0 -464
  123. package/dist/client/chat-agent-daemon.js +0 -1774
  124. package/dist/client/daemon-factory.d.ts +0 -106
  125. package/dist/client/daemon-factory.js +0 -301
  126. package/dist/client/factory.d.ts +0 -111
  127. package/dist/client/factory.js +0 -314
  128. package/dist/client/index.d.ts +0 -17
  129. package/dist/client/index.js +0 -38
  130. package/dist/client/multi-bot-manager.d.ts +0 -42
  131. package/dist/client/multi-bot-manager.js +0 -161
  132. package/dist/client/orchestrator-daemon.d.ts +0 -87
  133. package/dist/client/orchestrator-daemon.js +0 -444
  134. package/dist/client/server.d.ts +0 -8
  135. package/dist/client/server.js +0 -251
  136. package/dist/client/services/agent-registry.d.ts +0 -108
  137. package/dist/client/services/agent-registry.js +0 -630
  138. package/dist/client/services/conversation-manager.d.ts +0 -50
  139. package/dist/client/services/conversation-manager.js +0 -136
  140. package/dist/client/services/mcp-client.d.ts +0 -48
  141. package/dist/client/services/mcp-client.js +0 -105
  142. package/dist/client/services/message-classifier.d.ts +0 -37
  143. package/dist/client/services/message-classifier.js +0 -187
  144. package/dist/client/services/message-formatter.d.ts +0 -84
  145. package/dist/client/services/message-formatter.js +0 -353
  146. package/dist/client/services/session-logger.d.ts +0 -106
  147. package/dist/client/services/session-logger.js +0 -446
  148. package/dist/client/services/tool-executor.d.ts +0 -41
  149. package/dist/client/services/tool-executor.js +0 -169
  150. package/dist/client/services/workspace-schema-cache.d.ts +0 -149
  151. package/dist/client/services/workspace-schema-cache.js +0 -732
  152. package/dist/client/specialist-daemon.d.ts +0 -77
  153. package/dist/client/specialist-daemon.js +0 -197
  154. package/dist/client/specialists.d.ts +0 -53
  155. package/dist/client/specialists.js +0 -178
  156. package/dist/client/tool-schema-loader.d.ts +0 -62
  157. package/dist/client/tool-schema-loader.js +0 -232
  158. package/dist/client/types.d.ts +0 -327
  159. package/dist/client/types.js +0 -121
  160. package/dist/commands/seed-config.d.ts +0 -9
  161. package/dist/commands/seed-config.js +0 -372
  162. package/dist/lib/context-manager.d.ts +0 -111
  163. package/dist/lib/context-manager.js +0 -431
  164. package/dist/lib/prompt-length-manager.d.ts +0 -81
  165. package/dist/lib/prompt-length-manager.js +0 -457
  166. package/dist/mcp/tools/giuseppe-tools.d.ts +0 -21
  167. package/dist/modules/bug-reports/bug-config.d.ts +0 -25
  168. package/dist/modules/bug-reports/bug-config.js +0 -187
  169. package/dist/modules/bug-reports/bug-monitor.d.ts +0 -108
  170. package/dist/modules/bug-reports/bug-monitor.js +0 -510
  171. package/dist/modules/bug-reports/giuseppe-agent.d.ts +0 -58
  172. package/dist/modules/bug-reports/giuseppe-agent.js +0 -467
  173. package/dist/modules/bug-reports/giuseppe-ai.d.ts +0 -83
  174. package/dist/modules/bug-reports/giuseppe-ai.js +0 -466
  175. package/dist/modules/bug-reports/giuseppe-bot.d.ts +0 -110
  176. package/dist/modules/bug-reports/giuseppe-bot.js +0 -804
  177. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +0 -80
  178. package/dist/modules/bug-reports/giuseppe-daemon.js +0 -617
  179. package/dist/modules/bug-reports/giuseppe-files.d.ts +0 -64
  180. package/dist/modules/bug-reports/giuseppe-files.js +0 -375
  181. package/dist/modules/bug-reports/giuseppe-git.d.ts +0 -48
  182. package/dist/modules/bug-reports/giuseppe-git.js +0 -298
  183. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +0 -113
  184. package/dist/modules/bug-reports/giuseppe-lsp.js +0 -485
  185. package/dist/modules/bug-reports/giuseppe-prompt.d.ts +0 -5
  186. package/dist/modules/bug-reports/giuseppe-prompt.js +0 -94
  187. package/dist/modules/bug-reports/index.d.ts +0 -77
  188. package/dist/modules/bug-reports/index.js +0 -215
  189. package/dist/modules/bug-reports/pending-classification-registry.d.ts +0 -28
  190. package/dist/modules/bug-reports/pending-classification-registry.js +0 -50
  191. package/dist/modules/bug-reports/pending-fix-registry.d.ts +0 -30
  192. package/dist/modules/bug-reports/pending-fix-registry.js +0 -42
  193. package/dist/modules/bug-reports/pending-registry.d.ts +0 -27
  194. package/dist/modules/bug-reports/pending-registry.js +0 -49
  195. package/dist/modules/bug-reports/types.d.ts +0 -123
  196. package/dist/modules/bug-reports/types.js +0 -9
  197. package/dist/routes/agents.d.ts +0 -44
  198. package/dist/routes/agents.js +0 -311
  199. package/dist/services/agent-credential-store.d.ts +0 -73
  200. package/dist/services/agent-credential-store.js +0 -212
  201. package/dist/services/bug-monitor.d.ts +0 -23
  202. package/dist/services/bug-monitor.js +0 -275
@@ -1,314 +0,0 @@
1
- "use strict";
2
- /**
3
- * Daemon Factory
4
- *
5
- * Creates and manages agent daemons in orchestrator mode:
6
- * - One orchestrator (HAL) handles general conversation
7
- * - Specialist daemons handle complex domain-specific tasks
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.DaemonManager = void 0;
11
- exports.createDaemonManager = createDaemonManager;
12
- exports.startDaemonMode = startDaemonMode;
13
- const orchestrator_1 = require("./agents/orchestrator");
14
- const specialist_1 = require("./agents/specialist");
15
- const definitions_1 = require("./agents/definitions");
16
- const bot_manager_1 = require("./bot-manager");
17
- const config_1 = require("../config");
18
- const logger_1 = require("../lib/logger");
19
- const logger = (0, logger_1.createLogger)({ component: "DaemonFactory" });
20
- /**
21
- * Manages orchestrator + specialist daemons
22
- */
23
- class DaemonManager {
24
- daemons = new Map();
25
- orchestrator = null;
26
- specialists = new Map();
27
- botManager;
28
- options;
29
- constructor(botManager, options) {
30
- this.botManager = botManager;
31
- this.options = options;
32
- }
33
- /**
34
- * Start all daemons (orchestrator + specialists)
35
- */
36
- async startAll() {
37
- await this.startOrchestratorMode();
38
- }
39
- /**
40
- * Orchestrator mode: one orchestrator (HAL) + specialist daemons
41
- */
42
- async startOrchestratorMode() {
43
- const botClients = this.botManager.getAllBotClients();
44
- logger.info("Starting daemons in ORCHESTRATOR mode", {
45
- botCount: botClients.length,
46
- });
47
- // Find orchestrator bot
48
- let orchestratorClient;
49
- const specialistClients = new Map();
50
- for (const botClient of botClients) {
51
- const email = botClient.config.email;
52
- // Check if this is the orchestrator
53
- if (this.options.orchestratorEmail === email ||
54
- (!this.options.orchestratorEmail && !orchestratorClient)) {
55
- orchestratorClient = botClient;
56
- continue;
57
- }
58
- // Check if this matches a specialist
59
- if (this.options.specialistEmails) {
60
- for (const [specialistKey, specialistEmail] of Object.entries(this.options.specialistEmails)) {
61
- if (email === specialistEmail) {
62
- specialistClients.set(specialistKey, botClient);
63
- break;
64
- }
65
- }
66
- }
67
- else {
68
- // Auto-assign to first available specialist
69
- for (const specialistKey of Object.keys(definitions_1.SPECIALISTS)) {
70
- if (!specialistClients.has(specialistKey)) {
71
- specialistClients.set(specialistKey, botClient);
72
- break;
73
- }
74
- }
75
- }
76
- }
77
- if (!orchestratorClient) {
78
- throw new Error("No orchestrator bot found");
79
- }
80
- // Create specialist user ID map for orchestrator
81
- const specialistUserIds = new Map();
82
- for (const [key, client] of specialistClients) {
83
- specialistUserIds.set(key, client.userId);
84
- }
85
- // Start orchestrator
86
- const orchestratorConfig = {
87
- botClient: orchestratorClient,
88
- mcpServerUrl: this.options.mcpServerUrl,
89
- anthropicApiKey: this.options.anthropicApiKey,
90
- model: this.options.model,
91
- specialistUserIds,
92
- };
93
- this.orchestrator = new orchestrator_1.OrchestratorDaemon(orchestratorConfig);
94
- await this.orchestrator.initialize();
95
- // Register specialist user IDs with orchestrator
96
- for (const [key, userId] of specialistUserIds) {
97
- this.orchestrator.registerSpecialistUserId(key, userId);
98
- }
99
- this.daemons.set(orchestratorClient.userId, this.orchestrator);
100
- logger.info("Orchestrator started", {
101
- botId: orchestratorClient.userId,
102
- email: orchestratorClient.config.email,
103
- specialistCount: specialistClients.size,
104
- });
105
- // Start specialist daemons
106
- for (const [specialistKey, botClient] of specialistClients) {
107
- const specialist = definitions_1.SPECIALISTS[specialistKey];
108
- if (!specialist) {
109
- logger.warn("Unknown specialist key", { key: specialistKey });
110
- continue;
111
- }
112
- // Set the bot user ID on the specialist config
113
- specialist.botUserId = botClient.userId;
114
- const specialistConfig = {
115
- botClient,
116
- mcpServerUrl: this.options.mcpServerUrl,
117
- anthropicApiKey: this.options.anthropicApiKey,
118
- model: specialist.model || this.options.model,
119
- specialist,
120
- };
121
- const specialistDaemon = new specialist_1.SpecialistDaemon(specialistConfig);
122
- await specialistDaemon.initialize();
123
- this.specialists.set(specialistKey, specialistDaemon);
124
- this.daemons.set(botClient.userId, specialistDaemon);
125
- logger.info("Specialist daemon started", {
126
- key: specialistKey,
127
- name: specialist.name,
128
- botId: botClient.userId,
129
- email: botClient.config.email,
130
- });
131
- }
132
- logger.info("Orchestrator mode started", {
133
- orchestratorId: orchestratorClient.userId,
134
- specialistCount: this.specialists.size,
135
- totalDaemons: this.daemons.size,
136
- });
137
- }
138
- /**
139
- * Stop all daemons
140
- * Flushes session logs for each daemon before stopping
141
- */
142
- async stopAll() {
143
- const stopPromises = Array.from(this.daemons.entries()).map(async ([botId, daemon]) => {
144
- await daemon.stop();
145
- logger.info("Daemon stopped", { botId });
146
- });
147
- await Promise.all(stopPromises);
148
- this.daemons.clear();
149
- }
150
- /**
151
- * Get daemon for a specific bot
152
- */
153
- getDaemon(botId) {
154
- return this.daemons.get(botId);
155
- }
156
- /**
157
- * Get status of all daemons
158
- */
159
- getStatus() {
160
- return Array.from(this.daemons.entries()).map(([botId, daemon]) => ({
161
- botId,
162
- state: daemon.getConversationState(),
163
- }));
164
- }
165
- /**
166
- * Log current status to console (for monitoring)
167
- */
168
- logStatus() {
169
- const status = this.getStatus();
170
- if (this.options.orchestratorMode) {
171
- logger.info("=== ORCHESTRATOR MODE STATUS ===");
172
- // Log orchestrator
173
- if (this.orchestrator) {
174
- const orchStatus = this.orchestrator.getOrchestratorStatus();
175
- logger.info("ORCHESTRATOR (HAL):", {
176
- discussions: orchStatus.conversationState.discussionCount,
177
- messages: orchStatus.conversationState.currentMessageCount,
178
- queue: orchStatus.conversationState.queueLength,
179
- processing: orchStatus.conversationState.isProcessing,
180
- specialists: orchStatus.specialists.filter(s => s.available).length,
181
- });
182
- }
183
- // Log specialists
184
- for (const [key, specialist] of this.specialists) {
185
- const specStatus = specialist.getSpecialistStatus();
186
- logger.info(`SPECIALIST [${key}] ${specStatus.name}:`, {
187
- discussions: specStatus.conversationState.discussionCount,
188
- messages: specStatus.conversationState.currentMessageCount,
189
- queue: specStatus.conversationState.queueLength,
190
- processing: specStatus.conversationState.isProcessing,
191
- });
192
- }
193
- }
194
- else {
195
- logger.info("=== DAEMON STATUS ===");
196
- for (const { botId, state } of status) {
197
- logger.info(`Bot ${botId.substring(0, 8)}...`, {
198
- discussions: state.discussionCount,
199
- messages: state.currentMessageCount,
200
- queue: state.queueLength,
201
- processing: state.isProcessing,
202
- });
203
- if (state.lastMessages.length > 0) {
204
- logger.info("Last messages:");
205
- for (const msg of state.lastMessages) {
206
- logger.info(` [${msg.role}] ${msg.preview}`);
207
- }
208
- }
209
- }
210
- }
211
- logger.info("=====================");
212
- }
213
- /**
214
- * Get orchestrator instance (only in orchestrator mode)
215
- */
216
- getOrchestrator() {
217
- return this.orchestrator;
218
- }
219
- /**
220
- * Get specialist by key (only in orchestrator mode)
221
- */
222
- getSpecialist(key) {
223
- return this.specialists.get(key);
224
- }
225
- /**
226
- * Check if running in orchestrator mode
227
- */
228
- isOrchestratorMode() {
229
- return !!this.options.orchestratorMode;
230
- }
231
- /**
232
- * Trigger HAL to respond in a discussion with context
233
- */
234
- async triggerHalResponse(discussionId, activityId, context) {
235
- if (!this.orchestrator) {
236
- logger.warn('Cannot trigger HAL response - orchestrator not running');
237
- return;
238
- }
239
- await this.orchestrator.respondWithContext(discussionId, activityId, context);
240
- }
241
- /**
242
- * Start periodic status logging
243
- */
244
- startStatusLogging(intervalMs = 30000) {
245
- return setInterval(() => {
246
- this.logStatus();
247
- }, intervalMs);
248
- }
249
- }
250
- exports.DaemonManager = DaemonManager;
251
- /**
252
- * Create and start the daemon manager
253
- * This is the main entry point for daemon mode
254
- *
255
- * @param options - Optional settings for orchestrator mode
256
- */
257
- async function createDaemonManager(options) {
258
- const appConfig = (0, config_1.createApplicationConfig)();
259
- const mcpClientConfig = appConfig.mcpClient;
260
- if (!mcpClientConfig) {
261
- logger.error("MCP Client not configured - cannot start daemon mode");
262
- return null;
263
- }
264
- // Find Anthropic API key from providers
265
- const anthropicProvider = mcpClientConfig.providers.find(p => p.type === "anthropic");
266
- if (!anthropicProvider) {
267
- logger.error("Anthropic provider not configured - daemon mode requires Anthropic");
268
- return null;
269
- }
270
- // Create bot manager
271
- const botManager = new bot_manager_1.MultiBotManager(mcpClientConfig.botConfigs);
272
- await botManager.initializeAllHailerClientsFromConfig();
273
- // Check environment for orchestrator mode (defaults to TRUE)
274
- const orchestratorMode = options?.orchestratorMode ??
275
- process.env.DAEMON_ORCHESTRATOR_MODE !== "false";
276
- // Create daemon manager
277
- const daemonManager = new DaemonManager(botManager, {
278
- mcpServerUrl: mcpClientConfig.mcpServerUrl,
279
- anthropicApiKey: anthropicProvider.apiKey,
280
- model: anthropicProvider.model,
281
- orchestratorMode,
282
- orchestratorEmail: options?.orchestratorEmail,
283
- specialistEmails: options?.specialistEmails,
284
- });
285
- // Start all daemons
286
- await daemonManager.startAll();
287
- return daemonManager;
288
- }
289
- /**
290
- * Quick start function for testing
291
- *
292
- * @param orchestratorMode - Enable orchestrator mode (default: true)
293
- */
294
- async function startDaemonMode(orchestratorMode = true) {
295
- logger.info("Starting Chat Agent Daemon Mode (ORCHESTRATOR)...");
296
- const manager = await createDaemonManager({ orchestratorMode });
297
- if (!manager) {
298
- logger.error("Failed to create daemon manager");
299
- process.exit(1);
300
- }
301
- // Handle shutdown - await async stopAll() to flush session logs
302
- process.on("SIGINT", () => {
303
- logger.info("Shutting down daemons...");
304
- manager.stopAll().then(() => process.exit(0));
305
- });
306
- process.on("SIGTERM", () => {
307
- logger.info("Shutting down daemons...");
308
- manager.stopAll().then(() => process.exit(0));
309
- });
310
- logger.info("Chat Agent Daemon Mode (ORCHESTRATOR) running. Press Ctrl+C to stop.");
311
- // Start periodic status logging
312
- manager.startStatusLogging(60000);
313
- }
314
- //# sourceMappingURL=factory.js.map
@@ -1,17 +0,0 @@
1
- /**
2
- * Client Module - Public Exports
3
- *
4
- * Agent system for Hailer workspace automation
5
- */
6
- export * from "./types";
7
- export * from "./bot-manager";
8
- export * from "./factory";
9
- export * from "./agents/base";
10
- export * from "./agents/orchestrator";
11
- export * from "./agents/specialist";
12
- export * from "./agents/definitions";
13
- export * from "./services/message-formatter";
14
- export * from "./services/mcp-client";
15
- export * from "./services/session-logger";
16
- export * from "./services/agent-registry";
17
- //# sourceMappingURL=index.d.ts.map
@@ -1,38 +0,0 @@
1
- "use strict";
2
- /**
3
- * Client Module - Public Exports
4
- *
5
- * Agent system for Hailer workspace automation
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- // Core types and constants
23
- __exportStar(require("./types"), exports);
24
- // Bot management
25
- __exportStar(require("./bot-manager"), exports);
26
- // Daemon factory and management
27
- __exportStar(require("./factory"), exports);
28
- // Base agent classes
29
- __exportStar(require("./agents/base"), exports);
30
- __exportStar(require("./agents/orchestrator"), exports);
31
- __exportStar(require("./agents/specialist"), exports);
32
- __exportStar(require("./agents/definitions"), exports);
33
- // Services
34
- __exportStar(require("./services/message-formatter"), exports);
35
- __exportStar(require("./services/mcp-client"), exports);
36
- __exportStar(require("./services/session-logger"), exports);
37
- __exportStar(require("./services/agent-registry"), exports);
38
- //# sourceMappingURL=index.js.map
@@ -1,42 +0,0 @@
1
- /**
2
- * Multi-Bot Client Manager
3
- * Manages multiple bot clients, each with their own Hailer connection
4
- */
5
- import { HailerClient } from "../mcp/hailer-clients";
6
- import { SignalHandler } from "../mcp/signal-handler";
7
- import { BotClientConfig } from "./types";
8
- import { WorkspaceCache, UserInfo } from "../mcp/workspace-cache";
9
- export interface BotClient {
10
- userId: string;
11
- config: BotClientConfig;
12
- client: HailerClient;
13
- signalHandler: SignalHandler;
14
- workspaceCache?: WorkspaceCache;
15
- }
16
- export declare class MultiBotManager {
17
- private botConfigs;
18
- private botClients;
19
- constructor(botConfigs: BotClientConfig[]);
20
- initializeAllHailerClientsFromConfig(): Promise<void>;
21
- getBotClient(userId: string): BotClient | undefined;
22
- getAllBotClients(): BotClient[];
23
- getBotIds(): string[];
24
- private userNameCache;
25
- private static USER_CACHE_TTL;
26
- /**
27
- * Look up a user's full name by their user ID
28
- * Uses workspace cache first, then falls back to socket API call
29
- */
30
- getUserName(userId: string): string | undefined;
31
- /**
32
- * Look up a user's full name by their user ID (async version)
33
- * Falls back to socket API if not in cache
34
- */
35
- getUserNameAsync(userId: string): Promise<string | undefined>;
36
- /**
37
- * Get user info by ID (returns full UserInfo object)
38
- */
39
- getUserInfo(userId: string): UserInfo | undefined;
40
- shutdown(): Promise<void>;
41
- }
42
- //# sourceMappingURL=multi-bot-manager.d.ts.map
@@ -1,161 +0,0 @@
1
- "use strict";
2
- /**
3
- * Multi-Bot Client Manager
4
- * Manages multiple bot clients, each with their own Hailer connection
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MultiBotManager = void 0;
8
- const hailer_clients_1 = require("../mcp/hailer-clients");
9
- const signal_handler_1 = require("../mcp/signal-handler");
10
- const workspace_cache_1 = require("../mcp/workspace-cache");
11
- const config_1 = require("../config");
12
- class MultiBotManager {
13
- botConfigs;
14
- botClients = new Map();
15
- constructor(botConfigs) {
16
- this.botConfigs = botConfigs;
17
- }
18
- // for client we may put initializeAllConfigClients method to do it at once
19
- // in case we only use MCP Server:
20
- // for MCP Server it may just get a specific client and this class initialize it specifically and even kill it later if not needed
21
- async initializeAllHailerClientsFromConfig() {
22
- console.log(`🤖 Initializing ${this.botConfigs.length} bot clients...`);
23
- const appConfig = (0, config_1.createApplicationConfig)();
24
- for (const config of this.botConfigs) {
25
- try {
26
- // Use shared connection pool via API key lookup
27
- const client = await (0, hailer_clients_1.createHailerClientByApiKey)(config.mcpServerApiKey);
28
- // Get user ID automatically from authenticated session
29
- const userId = await (0, hailer_clients_1.getCurrentUserId)(client);
30
- // Fetch init data to get workspace cache with user names and teams
31
- let workspaceCache;
32
- try {
33
- const init = await client.socket.request('v2.core.init', [['users', 'network', 'networks', 'teams']]);
34
- workspaceCache = (0, workspace_cache_1.createWorkspaceCache)(init, appConfig.mcpConfig);
35
- const teamCount = Object.keys(init.teams || {}).length;
36
- console.log(`📋 Loaded workspace cache with ${workspaceCache.users.length} users, ${teamCount} teams`);
37
- }
38
- catch (initError) {
39
- console.warn(`⚠️ Could not load workspace cache for ${config.email}:`, initError);
40
- }
41
- const signalHandler = new signal_handler_1.SignalHandler(client, workspaceCache);
42
- const botClient = {
43
- userId,
44
- config,
45
- client,
46
- signalHandler,
47
- workspaceCache,
48
- };
49
- this.botClients.set(userId, botClient);
50
- console.log(`✅ Bot client initialized for ${config.email} (${userId}) via API key ${config.mcpServerApiKey.substring(0, 8)}...`);
51
- }
52
- catch (error) {
53
- console.error(`❌ Failed to initialize bot client for ${config.email}:`, error);
54
- // Continue with other bots even if one fails
55
- }
56
- }
57
- console.log(`✅ Initialized ${this.botClients.size} bot clients successfully`);
58
- }
59
- getBotClient(userId) {
60
- const botClient = this.botClients.get(userId);
61
- if (!botClient) {
62
- console.warn(`❌ No bot client found for userId: ${userId}`);
63
- }
64
- return botClient;
65
- }
66
- getAllBotClients() {
67
- return Array.from(this.botClients.values());
68
- }
69
- getBotIds() {
70
- return Array.from(this.botClients.keys());
71
- }
72
- // Simple in-memory cache for user lookups (refreshed on demand)
73
- userNameCache = new Map();
74
- static USER_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
75
- /**
76
- * Look up a user's full name by their user ID
77
- * Uses workspace cache first, then falls back to socket API call
78
- */
79
- getUserName(userId) {
80
- // Check in-memory cache first (for API-fetched users)
81
- const cached = this.userNameCache.get(userId);
82
- if (cached && Date.now() - cached.fetchedAt < MultiBotManager.USER_CACHE_TTL) {
83
- return cached.name;
84
- }
85
- // Try each bot client's workspace cache until we find the user
86
- for (const botClient of this.botClients.values()) {
87
- if (botClient.workspaceCache) {
88
- const user = (0, workspace_cache_1.getUserById)(botClient.workspaceCache, userId);
89
- if (user) {
90
- const fullName = `${user.firstname || ''} ${user.lastname || ''}`.trim();
91
- return fullName || user.fullName || undefined;
92
- }
93
- }
94
- }
95
- return undefined;
96
- }
97
- /**
98
- * Look up a user's full name by their user ID (async version)
99
- * Falls back to socket API if not in cache
100
- */
101
- async getUserNameAsync(userId) {
102
- // Try sync lookup first
103
- const syncResult = this.getUserName(userId);
104
- if (syncResult) {
105
- return syncResult;
106
- }
107
- // Fall back to socket API call
108
- const botClient = this.botClients.values().next().value;
109
- if (!botClient) {
110
- return undefined;
111
- }
112
- try {
113
- // Fetch fresh init data with users
114
- const init = await botClient.client.socket.request('v2.core.init', [['users']]);
115
- if (init.users && init.users[userId]) {
116
- const user = init.users[userId];
117
- const fullName = `${user.firstname || ''} ${user.lastname || ''}`.trim();
118
- // Cache the result
119
- if (fullName) {
120
- this.userNameCache.set(userId, { name: fullName, fetchedAt: Date.now() });
121
- return fullName;
122
- }
123
- }
124
- }
125
- catch (error) {
126
- console.warn(`⚠️ Could not fetch user info for ${userId}:`, error);
127
- }
128
- return undefined;
129
- }
130
- /**
131
- * Get user info by ID (returns full UserInfo object)
132
- */
133
- getUserInfo(userId) {
134
- for (const botClient of this.botClients.values()) {
135
- if (botClient.workspaceCache) {
136
- const user = (0, workspace_cache_1.getUserById)(botClient.workspaceCache, userId);
137
- if (user) {
138
- return user;
139
- }
140
- }
141
- }
142
- return undefined;
143
- }
144
- async shutdown() {
145
- console.log("🤖 Shutting down all bot clients...");
146
- for (const [userId, botClient] of this.botClients) {
147
- try {
148
- // Properly disconnect from shared connection pool
149
- (0, hailer_clients_1.disconnectHailerClientByApiKey)(botClient.config.mcpServerApiKey);
150
- console.log(`✅ Bot client ${userId} shut down (API key: ${botClient.config.mcpServerApiKey.substring(0, 8)}...)`);
151
- }
152
- catch (error) {
153
- console.error(`❌ Error shutting down bot client ${userId}:`, error);
154
- }
155
- }
156
- this.botClients.clear();
157
- console.log("✅ All bot clients shut down");
158
- }
159
- }
160
- exports.MultiBotManager = MultiBotManager;
161
- //# sourceMappingURL=multi-bot-manager.js.map
@@ -1,87 +0,0 @@
1
- /**
2
- * Orchestrator Daemon (HAL)
3
- *
4
- * The main conversational bot that handles general chat and coordinates
5
- * with specialist bots when tasks are too complex.
6
- *
7
- * HAL can:
8
- * - Handle general conversation and simple queries
9
- * - Detect when a task needs specialist help
10
- * - Invite specialist bots to the discussion
11
- * - Hand off context to specialists
12
- * - Summarize specialist responses for users
13
- */
14
- import { ChatAgentDaemon, ChatAgentDaemonConfig, IncomingMessage } from "./chat-agent-daemon";
15
- import Anthropic from "@anthropic-ai/sdk";
16
- export interface OrchestratorDaemonConfig extends ChatAgentDaemonConfig {
17
- /** Map of specialist key to their Hailer user ID */
18
- specialistUserIds?: Map<string, string>;
19
- }
20
- export declare class OrchestratorDaemon extends ChatAgentDaemon {
21
- private orchestratorLogger;
22
- private specialists;
23
- private activeSpecialistsInDiscussion;
24
- private specialistUserIds;
25
- private toolsUsedInCurrentMessage;
26
- constructor(config: OrchestratorDaemonConfig);
27
- /**
28
- * Override agent name for Agent Directory
29
- */
30
- protected getAgentName(): {
31
- firstName: string;
32
- lastName: string;
33
- };
34
- /**
35
- * Override agent description for Agent Directory
36
- */
37
- protected getAgentDescription(): string;
38
- /**
39
- * Override Position details for Orchestrator
40
- */
41
- protected getPositionDetails(): {
42
- name: string;
43
- purpose: string;
44
- personaTone: string;
45
- coreCapabilities: string;
46
- boundaries: string;
47
- };
48
- /**
49
- * Register a specialist's Hailer user ID
50
- * Called during initialization when we know the specialist bot's user ID
51
- */
52
- registerSpecialistUserId(specialistKey: string, userId: string): void;
53
- /**
54
- * Check if a specialist is already active in a discussion
55
- */
56
- private isSpecialistActiveInDiscussion;
57
- /**
58
- * Mark a specialist as active in a discussion
59
- */
60
- private markSpecialistActive;
61
- /**
62
- * Invite a specialist to a discussion
63
- */
64
- private inviteSpecialist;
65
- /**
66
- * Override system prompt to include orchestrator capabilities
67
- */
68
- protected getSystemPrompt(): string;
69
- /**
70
- * Override response handling to detect specialist invitations
71
- */
72
- protected handleLlmResponse(response: Anthropic.Message, originalMessage: IncomingMessage): Promise<void>;
73
- /**
74
- * Get orchestrator status including specialist info
75
- */
76
- getOrchestratorStatus(): {
77
- conversationState: ReturnType<ChatAgentDaemon["getConversationState"]>;
78
- specialists: Array<{
79
- key: string;
80
- name: string;
81
- available: boolean;
82
- userId?: string;
83
- }>;
84
- activeInDiscussions: Record<string, string[]>;
85
- };
86
- }
87
- //# sourceMappingURL=orchestrator-daemon.d.ts.map