@hailer/mcp 0.1.17 → 0.2.2

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 (200) hide show
  1. package/dist/app.js +27 -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-server.d.ts +2 -2
  37. package/dist/mcp-server.js +161 -139
  38. package/package.json +1 -1
  39. package/REFACTOR_STATUS.md +0 -127
  40. package/dist/agents/bot-manager.d.ts +0 -48
  41. package/dist/agents/bot-manager.js +0 -254
  42. package/dist/agents/factory.d.ts +0 -150
  43. package/dist/agents/factory.js +0 -650
  44. package/dist/agents/giuseppe/ai.d.ts +0 -83
  45. package/dist/agents/giuseppe/ai.js +0 -466
  46. package/dist/agents/giuseppe/bot.d.ts +0 -110
  47. package/dist/agents/giuseppe/bot.js +0 -780
  48. package/dist/agents/giuseppe/config.d.ts +0 -25
  49. package/dist/agents/giuseppe/config.js +0 -227
  50. package/dist/agents/giuseppe/files.d.ts +0 -52
  51. package/dist/agents/giuseppe/files.js +0 -338
  52. package/dist/agents/giuseppe/git.d.ts +0 -48
  53. package/dist/agents/giuseppe/git.js +0 -298
  54. package/dist/agents/giuseppe/index.d.ts +0 -97
  55. package/dist/agents/giuseppe/index.js +0 -258
  56. package/dist/agents/giuseppe/lsp.d.ts +0 -113
  57. package/dist/agents/giuseppe/lsp.js +0 -485
  58. package/dist/agents/giuseppe/monitor.d.ts +0 -118
  59. package/dist/agents/giuseppe/monitor.js +0 -621
  60. package/dist/agents/giuseppe/prompt.d.ts +0 -5
  61. package/dist/agents/giuseppe/prompt.js +0 -94
  62. package/dist/agents/giuseppe/registries/pending-classification.d.ts +0 -28
  63. package/dist/agents/giuseppe/registries/pending-classification.js +0 -50
  64. package/dist/agents/giuseppe/registries/pending-fix.d.ts +0 -30
  65. package/dist/agents/giuseppe/registries/pending-fix.js +0 -42
  66. package/dist/agents/giuseppe/registries/pending.d.ts +0 -27
  67. package/dist/agents/giuseppe/registries/pending.js +0 -49
  68. package/dist/agents/giuseppe/specialist.d.ts +0 -47
  69. package/dist/agents/giuseppe/specialist.js +0 -237
  70. package/dist/agents/giuseppe/types.d.ts +0 -123
  71. package/dist/agents/giuseppe/types.js +0 -9
  72. package/dist/agents/hailer-expert/index.d.ts +0 -8
  73. package/dist/agents/hailer-expert/index.js +0 -14
  74. package/dist/agents/hal/daemon.d.ts +0 -142
  75. package/dist/agents/hal/daemon.js +0 -1103
  76. package/dist/agents/hal/definitions.d.ts +0 -55
  77. package/dist/agents/hal/definitions.js +0 -263
  78. package/dist/agents/hal/index.d.ts +0 -3
  79. package/dist/agents/hal/index.js +0 -8
  80. package/dist/agents/index.d.ts +0 -18
  81. package/dist/agents/index.js +0 -48
  82. package/dist/agents/shared/base.d.ts +0 -216
  83. package/dist/agents/shared/base.js +0 -846
  84. package/dist/agents/shared/services/agent-registry.d.ts +0 -107
  85. package/dist/agents/shared/services/agent-registry.js +0 -629
  86. package/dist/agents/shared/services/conversation-manager.d.ts +0 -50
  87. package/dist/agents/shared/services/conversation-manager.js +0 -136
  88. package/dist/agents/shared/services/mcp-client.d.ts +0 -56
  89. package/dist/agents/shared/services/mcp-client.js +0 -124
  90. package/dist/agents/shared/services/message-classifier.d.ts +0 -37
  91. package/dist/agents/shared/services/message-classifier.js +0 -187
  92. package/dist/agents/shared/services/message-formatter.d.ts +0 -89
  93. package/dist/agents/shared/services/message-formatter.js +0 -371
  94. package/dist/agents/shared/services/session-logger.d.ts +0 -106
  95. package/dist/agents/shared/services/session-logger.js +0 -446
  96. package/dist/agents/shared/services/tool-executor.d.ts +0 -41
  97. package/dist/agents/shared/services/tool-executor.js +0 -169
  98. package/dist/agents/shared/services/workspace-schema-cache.d.ts +0 -125
  99. package/dist/agents/shared/services/workspace-schema-cache.js +0 -578
  100. package/dist/agents/shared/specialist.d.ts +0 -91
  101. package/dist/agents/shared/specialist.js +0 -399
  102. package/dist/agents/shared/tool-schema-loader.d.ts +0 -62
  103. package/dist/agents/shared/tool-schema-loader.js +0 -232
  104. package/dist/agents/shared/types.d.ts +0 -327
  105. package/dist/agents/shared/types.js +0 -121
  106. package/dist/client/agents/base.d.ts +0 -207
  107. package/dist/client/agents/base.js +0 -744
  108. package/dist/client/agents/definitions.d.ts +0 -53
  109. package/dist/client/agents/definitions.js +0 -263
  110. package/dist/client/agents/orchestrator.d.ts +0 -141
  111. package/dist/client/agents/orchestrator.js +0 -1062
  112. package/dist/client/agents/specialist.d.ts +0 -86
  113. package/dist/client/agents/specialist.js +0 -340
  114. package/dist/client/bot-entrypoint.d.ts +0 -7
  115. package/dist/client/bot-entrypoint.js +0 -103
  116. package/dist/client/bot-manager.d.ts +0 -44
  117. package/dist/client/bot-manager.js +0 -173
  118. package/dist/client/bot-runner.d.ts +0 -35
  119. package/dist/client/bot-runner.js +0 -188
  120. package/dist/client/chat-agent-daemon.d.ts +0 -464
  121. package/dist/client/chat-agent-daemon.js +0 -1774
  122. package/dist/client/daemon-factory.d.ts +0 -106
  123. package/dist/client/daemon-factory.js +0 -301
  124. package/dist/client/factory.d.ts +0 -111
  125. package/dist/client/factory.js +0 -314
  126. package/dist/client/index.d.ts +0 -17
  127. package/dist/client/index.js +0 -38
  128. package/dist/client/multi-bot-manager.d.ts +0 -42
  129. package/dist/client/multi-bot-manager.js +0 -161
  130. package/dist/client/orchestrator-daemon.d.ts +0 -87
  131. package/dist/client/orchestrator-daemon.js +0 -444
  132. package/dist/client/server.d.ts +0 -8
  133. package/dist/client/server.js +0 -251
  134. package/dist/client/services/agent-registry.d.ts +0 -108
  135. package/dist/client/services/agent-registry.js +0 -630
  136. package/dist/client/services/conversation-manager.d.ts +0 -50
  137. package/dist/client/services/conversation-manager.js +0 -136
  138. package/dist/client/services/mcp-client.d.ts +0 -48
  139. package/dist/client/services/mcp-client.js +0 -105
  140. package/dist/client/services/message-classifier.d.ts +0 -37
  141. package/dist/client/services/message-classifier.js +0 -187
  142. package/dist/client/services/message-formatter.d.ts +0 -84
  143. package/dist/client/services/message-formatter.js +0 -353
  144. package/dist/client/services/session-logger.d.ts +0 -106
  145. package/dist/client/services/session-logger.js +0 -446
  146. package/dist/client/services/tool-executor.d.ts +0 -41
  147. package/dist/client/services/tool-executor.js +0 -169
  148. package/dist/client/services/workspace-schema-cache.d.ts +0 -149
  149. package/dist/client/services/workspace-schema-cache.js +0 -732
  150. package/dist/client/specialist-daemon.d.ts +0 -77
  151. package/dist/client/specialist-daemon.js +0 -197
  152. package/dist/client/specialists.d.ts +0 -53
  153. package/dist/client/specialists.js +0 -178
  154. package/dist/client/tool-schema-loader.d.ts +0 -62
  155. package/dist/client/tool-schema-loader.js +0 -232
  156. package/dist/client/types.d.ts +0 -327
  157. package/dist/client/types.js +0 -121
  158. package/dist/commands/seed-config.d.ts +0 -9
  159. package/dist/commands/seed-config.js +0 -372
  160. package/dist/lib/context-manager.d.ts +0 -111
  161. package/dist/lib/context-manager.js +0 -431
  162. package/dist/lib/prompt-length-manager.d.ts +0 -81
  163. package/dist/lib/prompt-length-manager.js +0 -457
  164. package/dist/mcp/tools/giuseppe-tools.d.ts +0 -21
  165. package/dist/modules/bug-reports/bug-config.d.ts +0 -25
  166. package/dist/modules/bug-reports/bug-config.js +0 -187
  167. package/dist/modules/bug-reports/bug-monitor.d.ts +0 -108
  168. package/dist/modules/bug-reports/bug-monitor.js +0 -510
  169. package/dist/modules/bug-reports/giuseppe-agent.d.ts +0 -58
  170. package/dist/modules/bug-reports/giuseppe-agent.js +0 -467
  171. package/dist/modules/bug-reports/giuseppe-ai.d.ts +0 -83
  172. package/dist/modules/bug-reports/giuseppe-ai.js +0 -466
  173. package/dist/modules/bug-reports/giuseppe-bot.d.ts +0 -110
  174. package/dist/modules/bug-reports/giuseppe-bot.js +0 -804
  175. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +0 -80
  176. package/dist/modules/bug-reports/giuseppe-daemon.js +0 -617
  177. package/dist/modules/bug-reports/giuseppe-files.d.ts +0 -64
  178. package/dist/modules/bug-reports/giuseppe-files.js +0 -375
  179. package/dist/modules/bug-reports/giuseppe-git.d.ts +0 -48
  180. package/dist/modules/bug-reports/giuseppe-git.js +0 -298
  181. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +0 -113
  182. package/dist/modules/bug-reports/giuseppe-lsp.js +0 -485
  183. package/dist/modules/bug-reports/giuseppe-prompt.d.ts +0 -5
  184. package/dist/modules/bug-reports/giuseppe-prompt.js +0 -94
  185. package/dist/modules/bug-reports/index.d.ts +0 -77
  186. package/dist/modules/bug-reports/index.js +0 -215
  187. package/dist/modules/bug-reports/pending-classification-registry.d.ts +0 -28
  188. package/dist/modules/bug-reports/pending-classification-registry.js +0 -50
  189. package/dist/modules/bug-reports/pending-fix-registry.d.ts +0 -30
  190. package/dist/modules/bug-reports/pending-fix-registry.js +0 -42
  191. package/dist/modules/bug-reports/pending-registry.d.ts +0 -27
  192. package/dist/modules/bug-reports/pending-registry.js +0 -49
  193. package/dist/modules/bug-reports/types.d.ts +0 -123
  194. package/dist/modules/bug-reports/types.js +0 -9
  195. package/dist/routes/agents.d.ts +0 -44
  196. package/dist/routes/agents.js +0 -311
  197. package/dist/services/agent-credential-store.d.ts +0 -73
  198. package/dist/services/agent-credential-store.js +0 -212
  199. package/dist/services/bug-monitor.d.ts +0 -23
  200. package/dist/services/bug-monitor.js +0 -275
@@ -1,127 +0,0 @@
1
- # Client Refactor Status
2
-
3
- ## Completed
4
-
5
- ### Services Created (src/client/services/)
6
- 1. **message-formatter.ts** - Tag formatting, mention resolution, activity linking
7
- 2. **mcp-client.ts** - MCP server communication, tool schema loading
8
- 3. **session-logger.ts** - Activity session tracking, idle detection, session flushing
9
- 4. **agent-registry.ts** - Agent Directory, Positions, Teams, Tool Registry, MCP Config
10
-
11
- ### Files Moved (src/client/agents/)
12
- 1. **definitions.ts** (was specialists.ts) - Specialist definitions
13
- 2. **orchestrator.ts** (was orchestrator-daemon.ts) - Updated imports ✓
14
- 3. **specialist.ts** (was specialist-daemon.ts) - Updated imports ✓
15
-
16
- ### Files Renamed (src/client/)
17
- 1. **factory.ts** (was daemon-factory.ts) - Needs import updates
18
- 2. **bot-manager.ts** (was multi-bot-manager.ts) - Needs import updates
19
-
20
- ### Types Extracted
21
- - **types.ts** - Already complete with all interfaces and constants
22
-
23
- ## Remaining Work
24
-
25
- ### 1. Create agents/base.ts
26
- Extract from chat-agent-daemon.ts (2109 lines):
27
- - Core LLM loop (~500 lines target)
28
- - Message queue management
29
- - Abstract getSystemPrompt()
30
- - Inject services via constructor:
31
- - MessageFormatterService
32
- - McpClientService
33
- - SessionLoggerService
34
- - AgentRegistryService
35
-
36
- ### 2. Update factory.ts imports
37
- ```typescript
38
- // Change:
39
- import { ChatAgentDaemon } from "./chat-agent-daemon";
40
- import { OrchestratorDaemon } from "./orchestrator-daemon";
41
- import { SpecialistDaemon } from "./specialist-daemon";
42
- import { SPECIALISTS } from "./specialists";
43
- import { MultiBotManager, BotClient } from "./multi-bot-manager";
44
-
45
- // To:
46
- import { ChatAgentDaemon } from "./agents/base";
47
- import { OrchestratorDaemon } from "./agents/orchestrator";
48
- import { SpecialistDaemon } from "./agents/specialist";
49
- import { SPECIALISTS } from "./agents/definitions";
50
- import { MultiBotManager, BotClient } from "./bot-manager";
51
- ```
52
-
53
- ### 3. Create index.ts (public exports)
54
- ```typescript
55
- export * from "./types";
56
- export * from "./bot-manager";
57
- export * from "./factory";
58
- export * from "./agents/base";
59
- export * from "./agents/orchestrator";
60
- export * from "./agents/specialist";
61
- export * from "./agents/definitions";
62
- export * from "./services/message-formatter";
63
- export * from "./services/mcp-client";
64
- export * from "./services/session-logger";
65
- export * from "./services/agent-registry";
66
- ```
67
-
68
- ### 4. Update all imports in codebase
69
- Files that import from src/client/:
70
- - src/core.ts
71
- - src/config.ts
72
- - Any test files
73
-
74
- ### 5. Delete old files
75
- After verifying build:
76
- - src/client/chat-agent-daemon.ts (replaced by agents/base.ts)
77
-
78
- ### 6. Verify build
79
- ```bash
80
- npm run build
81
- ```
82
-
83
- ## Architecture
84
-
85
- ### Before
86
- ```
87
- src/client/
88
- ├── chat-agent-daemon.ts (2109 lines - BLOATED)
89
- ├── orchestrator-daemon.ts
90
- ├── specialist-daemon.ts
91
- ├── specialists.ts
92
- ├── daemon-factory.ts
93
- ├── multi-bot-manager.ts
94
- └── types.ts
95
- ```
96
-
97
- ### After
98
- ```
99
- src/client/
100
- ├── index.ts # Public exports
101
- ├── factory.ts # DaemonManager
102
- ├── bot-manager.ts # MultiBotManager
103
- ├── types.ts # All interfaces
104
-
105
- ├── agents/
106
- │ ├── base.ts # Core LLM loop (~500 lines)
107
- │ ├── orchestrator.ts # HAL orchestrator ✓
108
- │ ├── specialist.ts # Domain experts ✓
109
- │ └── definitions.ts # SPECIALISTS config ✓
110
-
111
- └── services/
112
- ├── message-formatter.ts # Tags, mentions, links ✓
113
- ├── mcp-client.ts # Tool calling ✓
114
- ├── session-logger.ts # Session logging ✓
115
- └── agent-registry.ts # Agent Directory registration ✓
116
- ```
117
-
118
- ## Next Steps
119
-
120
- 1. Create agents/base.ts with service injection
121
- 2. Update factory.ts imports
122
- 3. Update bot-manager.ts imports (if any internal references)
123
- 4. Create index.ts
124
- 5. Update imports in src/core.ts and other files
125
- 6. Run npm run build
126
- 7. Delete chat-agent-daemon.ts
127
- 8. Test the refactored code
@@ -1,48 +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 "./shared/types";
8
- import { WorkspaceCache } from "../mcp/workspace-cache";
9
- export interface BotClient {
10
- userId: string;
11
- firstName: string;
12
- lastName: string;
13
- config: BotClientConfig;
14
- client: HailerClient;
15
- signalHandler: SignalHandler;
16
- workspaceCache?: WorkspaceCache;
17
- }
18
- export declare class MultiBotManager {
19
- private botConfigs;
20
- private botClients;
21
- constructor(botConfigs: BotClientConfig[]);
22
- initializeAllHailerClientsFromConfig(): Promise<void>;
23
- getBotClient(userId: string): BotClient | undefined;
24
- getAllBotClients(): BotClient[];
25
- getBotIds(): string[];
26
- private userNameCache;
27
- private static USER_CACHE_TTL;
28
- /**
29
- * Look up a user's full name by their user ID
30
- * Uses workspace cache first, then falls back to socket API call
31
- */
32
- getUserName(userId: string): string | undefined;
33
- /**
34
- * Initialize a single bot client from credentials
35
- * Used for dynamic bot creation from AI Hub
36
- */
37
- initializeBotClient(email: string, password: string, apiKey: string): Promise<string>;
38
- /**
39
- * Remove and disconnect a bot client
40
- */
41
- removeBotClient(userId: string): Promise<void>;
42
- /**
43
- * Get bot client by bot ID (hal, giuseppe, hailerExpert, vastuullisuus)
44
- */
45
- getBotClientByBotId(botId: string): BotClient | undefined;
46
- shutdown(): Promise<void>;
47
- }
48
- //# sourceMappingURL=bot-manager.d.ts.map
@@ -1,254 +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
- const bot_config_1 = require("../mcp/tools/bot-config");
13
- const logger_1 = require("../lib/logger");
14
- const logger = (0, logger_1.createLogger)({ component: 'bot-manager' });
15
- class MultiBotManager {
16
- botConfigs;
17
- botClients = new Map();
18
- constructor(botConfigs) {
19
- this.botConfigs = botConfigs;
20
- }
21
- // for client we may put initializeAllConfigClients method to do it at once
22
- // in case we only use MCP Server:
23
- // for MCP Server it may just get a specific client and this class initialize it specifically and even kill it later if not needed
24
- async initializeAllHailerClientsFromConfig() {
25
- logger.info('Initializing bot clients', { count: this.botConfigs.length });
26
- const appConfig = (0, config_1.createApplicationConfig)();
27
- for (const config of this.botConfigs) {
28
- try {
29
- // Use shared connection pool via API key lookup
30
- const client = await (0, hailer_clients_1.createHailerClientByApiKey)(config.mcpServerApiKey);
31
- // Get user ID automatically from authenticated session
32
- const userId = await (0, hailer_clients_1.getCurrentUserId)(client);
33
- // Fetch init data to get workspace cache with user names and teams
34
- let workspaceCache;
35
- try {
36
- const init = await client.socket.request('v2.core.init', [['users', 'network', 'networks', 'teams']]);
37
- workspaceCache = (0, workspace_cache_1.createWorkspaceCache)(init, appConfig.mcpConfig);
38
- const teamCount = Object.keys(init.teams || {}).length;
39
- logger.info('Loaded workspace cache', { userCount: workspaceCache.users.length, teamCount });
40
- }
41
- catch (initError) {
42
- logger.warn('Could not load workspace cache', { email: (0, config_1.maskEmail)(config.email), error: String(initError) });
43
- }
44
- const signalHandler = signal_handler_1.SignalHandler.getOrCreate(client, workspaceCache);
45
- // Look up user's name from workspace cache
46
- let firstName = 'Bot';
47
- let lastName = '';
48
- if (workspaceCache) {
49
- const userInfo = workspaceCache.usersById[userId];
50
- if (userInfo) {
51
- firstName = userInfo.firstname || 'Bot';
52
- lastName = userInfo.lastname || '';
53
- }
54
- }
55
- // Check if we have a display name from Agent Directory and update Hailer profile
56
- const localCreds = (0, bot_config_1.getLocalBotCredentials)(userId);
57
- if (localCreds?.displayName) {
58
- const currentFullName = `${firstName} ${lastName}`.trim();
59
- if (currentFullName !== localCreds.displayName) {
60
- try {
61
- // Parse display name into first/last
62
- const parts = localCreds.displayName.trim().split(/\s+/);
63
- const newFirstName = parts[0] || localCreds.displayName;
64
- const newLastName = parts.slice(1).join(' ') || '';
65
- // Update Hailer profile via API
66
- await client.socket.request('user.set_user_info', ['firstname', [newFirstName]]);
67
- if (newLastName) {
68
- await client.socket.request('user.set_user_info', ['lastname', [newLastName]]);
69
- }
70
- firstName = newFirstName;
71
- lastName = newLastName;
72
- logger.info('Updated bot display name', { from: currentFullName, to: localCreds.displayName });
73
- }
74
- catch (nameError) {
75
- logger.warn('Could not update bot display name', { error: String(nameError) });
76
- }
77
- }
78
- }
79
- const botClient = {
80
- userId,
81
- firstName,
82
- lastName,
83
- config,
84
- client,
85
- signalHandler,
86
- workspaceCache,
87
- };
88
- this.botClients.set(userId, botClient);
89
- logger.info('Bot client initialized', {
90
- email: (0, config_1.maskEmail)(config.email),
91
- userId,
92
- apiKey: (0, config_1.maskSensitiveData)(config.mcpServerApiKey),
93
- });
94
- }
95
- catch (error) {
96
- logger.error('Failed to initialize bot client', error, {
97
- email: (0, config_1.maskEmail)(config.email),
98
- });
99
- // Continue with other bots even if one fails
100
- }
101
- }
102
- logger.info('Bot clients initialization complete', { count: this.botClients.size });
103
- }
104
- getBotClient(userId) {
105
- const botClient = this.botClients.get(userId);
106
- if (!botClient) {
107
- logger.warn('No bot client found', { userId });
108
- }
109
- return botClient;
110
- }
111
- getAllBotClients() {
112
- return Array.from(this.botClients.values());
113
- }
114
- getBotIds() {
115
- return Array.from(this.botClients.keys());
116
- }
117
- // Simple in-memory cache for user lookups (refreshed on demand)
118
- userNameCache = new Map();
119
- static USER_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
120
- /**
121
- * Look up a user's full name by their user ID
122
- * Uses workspace cache first, then falls back to socket API call
123
- */
124
- getUserName(userId) {
125
- // Check in-memory cache first (for API-fetched users)
126
- const cached = this.userNameCache.get(userId);
127
- if (cached && Date.now() - cached.fetchedAt < MultiBotManager.USER_CACHE_TTL) {
128
- return cached.name;
129
- }
130
- // Try each bot client's workspace cache until we find the user
131
- for (const botClient of this.botClients.values()) {
132
- if (botClient.workspaceCache) {
133
- const user = (0, workspace_cache_1.getUserById)(botClient.workspaceCache, userId);
134
- if (user) {
135
- const fullName = `${user.firstname || ''} ${user.lastname || ''}`.trim();
136
- return fullName || user.fullName || undefined;
137
- }
138
- }
139
- }
140
- return undefined;
141
- }
142
- /**
143
- * Initialize a single bot client from credentials
144
- * Used for dynamic bot creation from AI Hub
145
- */
146
- async initializeBotClient(email, password, apiKey) {
147
- const appConfig = (0, config_1.createApplicationConfig)();
148
- // Check if bot with this email already exists
149
- const existingBot = Array.from(this.botClients.values())
150
- .find(bc => bc.config.email === email);
151
- if (existingBot) {
152
- logger.info('Bot client already exists', { email: (0, config_1.maskEmail)(email) });
153
- return existingBot.userId;
154
- }
155
- const config = {
156
- email,
157
- password,
158
- apiBaseUrl: 'https://api.hailer.com',
159
- mcpServerApiKey: apiKey,
160
- };
161
- try {
162
- const client = await (0, hailer_clients_1.createHailerClientByApiKey)(apiKey);
163
- const userId = await (0, hailer_clients_1.getCurrentUserId)(client);
164
- let workspaceCache;
165
- let workspaceId;
166
- try {
167
- const init = await client.socket.request('v2.core.init', [['users', 'network', 'networks', 'teams']]);
168
- workspaceCache = (0, workspace_cache_1.createWorkspaceCache)(init, appConfig.mcpConfig);
169
- workspaceId = init?.network?._id;
170
- }
171
- catch (initError) {
172
- logger.warn('Could not load workspace cache', { email: (0, config_1.maskEmail)(email), error: String(initError) });
173
- }
174
- const signalHandler = signal_handler_1.SignalHandler.getOrCreate(client, workspaceCache);
175
- // Initialize workspace schema for this bot's workspace (discover Agent Directory)
176
- if (workspaceId) {
177
- try {
178
- const hailerApiClient = { getClient: () => client, fetchInit: (modules) => client.socket.request('v2.core.init', [modules]), listWorkflows: async () => {
179
- const init = await client.socket.request('v2.core.init', [['processes']]);
180
- return Object.values(init?.processes || {});
181
- } };
182
- await (0, bot_config_1.initWorkspaceSchema)(hailerApiClient, workspaceId);
183
- logger.info('Workspace schema initialized', { email: (0, config_1.maskEmail)(email), workspaceId });
184
- }
185
- catch (schemaError) {
186
- logger.warn('Could not initialize workspace schema', { email: (0, config_1.maskEmail)(email), error: String(schemaError) });
187
- }
188
- }
189
- let firstName = 'Bot';
190
- let lastName = '';
191
- if (workspaceCache) {
192
- const userInfo = workspaceCache.usersById[userId];
193
- if (userInfo) {
194
- firstName = userInfo.firstname || 'Bot';
195
- lastName = userInfo.lastname || '';
196
- }
197
- }
198
- const botClient = {
199
- userId,
200
- firstName,
201
- lastName,
202
- config,
203
- client,
204
- signalHandler,
205
- workspaceCache,
206
- };
207
- this.botClients.set(userId, botClient);
208
- logger.info('Bot client initialized', { email: (0, config_1.maskEmail)(email), userId });
209
- return userId;
210
- }
211
- catch (error) {
212
- logger.error('Failed to initialize bot client', error, { email: (0, config_1.maskEmail)(email) });
213
- throw error;
214
- }
215
- }
216
- /**
217
- * Remove and disconnect a bot client
218
- */
219
- async removeBotClient(userId) {
220
- const botClient = this.botClients.get(userId);
221
- if (!botClient) {
222
- logger.warn('Bot client not found for removal', { userId });
223
- return;
224
- }
225
- (0, hailer_clients_1.disconnectHailerClientByApiKey)(botClient.config.mcpServerApiKey);
226
- this.botClients.delete(userId);
227
- logger.info('Bot client removed', { userId });
228
- }
229
- /**
230
- * Get bot client by bot ID (hal, giuseppe, hailerExpert, vastuullisuus)
231
- */
232
- getBotClientByBotId(botId) {
233
- // Match by email containing the bot ID
234
- return Array.from(this.botClients.values())
235
- .find(bc => bc.config.email.toLowerCase().includes(botId.toLowerCase()));
236
- }
237
- async shutdown() {
238
- logger.info('Shutting down all bot clients', { count: this.botClients.size });
239
- for (const [userId, botClient] of this.botClients) {
240
- try {
241
- // Properly disconnect from shared connection pool
242
- (0, hailer_clients_1.disconnectHailerClientByApiKey)(botClient.config.mcpServerApiKey);
243
- logger.info('Bot client shut down', { userId, apiKey: (0, config_1.maskSensitiveData)(botClient.config.mcpServerApiKey) });
244
- }
245
- catch (error) {
246
- logger.error('Error shutting down bot client', error, { userId });
247
- }
248
- }
249
- this.botClients.clear();
250
- logger.info('All bot clients shut down');
251
- }
252
- }
253
- exports.MultiBotManager = MultiBotManager;
254
- //# sourceMappingURL=bot-manager.js.map
@@ -1,150 +0,0 @@
1
- /**
2
- * Daemon Factory
3
- *
4
- * Creates and manages agent daemons in orchestrator mode:
5
- * - One orchestrator (HAL) handles general conversation
6
- * - Specialist daemons handle complex domain-specific tasks
7
- */
8
- import { ChatAgentDaemon } from "./shared/base";
9
- import { OrchestratorDaemon } from "./hal/daemon";
10
- import { SpecialistDaemon } from "./shared/specialist";
11
- import { MultiBotManager } from "./bot-manager";
12
- import { ConversationState } from "./shared/types";
13
- export interface DaemonManagerOptions {
14
- mcpServerUrl: string;
15
- anthropicApiKey: string;
16
- model?: string;
17
- /**
18
- * Enable orchestrator mode (default: true)
19
- * Set to false only for legacy compatibility
20
- */
21
- orchestratorMode?: boolean;
22
- /**
23
- * Email of the bot to use as orchestrator (defaults to first bot)
24
- */
25
- orchestratorEmail?: string;
26
- /**
27
- * Map of specialist key to bot email (e.g., { hailerExpert: "expert@bot.com" })
28
- */
29
- specialistEmails?: Record<string, string>;
30
- /**
31
- * Map of userId to botType (from workspace config)
32
- */
33
- botTypeMap?: Map<string, string>;
34
- /**
35
- * Map of userId to displayName (from Agent Directory activity name)
36
- */
37
- displayNameMap?: Map<string, string>;
38
- /**
39
- * Specific workspace ID to use (for webhook-triggered restarts)
40
- */
41
- workspaceId?: string;
42
- }
43
- /**
44
- * Manages orchestrator + specialist daemons
45
- */
46
- export declare class DaemonManager {
47
- private daemons;
48
- private orchestrator;
49
- private specialists;
50
- private botManager;
51
- private options;
52
- private botTypeMap;
53
- private displayNameMap;
54
- constructor(botManager: MultiBotManager, options: DaemonManagerOptions);
55
- /**
56
- * Get botType for a userId from the workspace config
57
- */
58
- private getBotType;
59
- /**
60
- * Get displayName for a userId from the workspace config (Agent Directory activity name)
61
- * Falls back to Hailer profile name if not set
62
- */
63
- private getDisplayName;
64
- /**
65
- * Start all daemons (orchestrator + specialists)
66
- */
67
- startAll(): Promise<void>;
68
- /**
69
- * Orchestrator mode: one orchestrator (HAL) + specialist daemons
70
- */
71
- private startOrchestratorMode;
72
- /**
73
- * Stop all daemons
74
- * Flushes session logs for each daemon before stopping
75
- */
76
- stopAll(): Promise<void>;
77
- /**
78
- * Get daemon for a specific bot
79
- */
80
- getDaemon(botId: string): ChatAgentDaemon | undefined;
81
- /**
82
- * Get status of all daemons
83
- */
84
- getStatus(): Array<{
85
- botId: string;
86
- state: ConversationState;
87
- }>;
88
- /**
89
- * Log current status to console (for monitoring)
90
- */
91
- logStatus(): void;
92
- /**
93
- * Get orchestrator instance (only in orchestrator mode)
94
- */
95
- getOrchestrator(): OrchestratorDaemon | null;
96
- /**
97
- * Get specialist by key (only in orchestrator mode)
98
- */
99
- getSpecialist(key: string): SpecialistDaemon | undefined;
100
- /**
101
- * Check if running in orchestrator mode
102
- */
103
- isOrchestratorMode(): boolean;
104
- /**
105
- * Trigger HAL to respond in a discussion with context
106
- */
107
- triggerHalResponse(discussionId: string, activityId: string, context: string): Promise<void>;
108
- /**
109
- * Hot-reload: Start a specialist daemon dynamically
110
- * Preserves orchestrator conversation context
111
- */
112
- startSpecialist(email: string, password: string, botType: string, userId?: string): Promise<boolean>;
113
- /**
114
- * Hot-reload: Stop a specialist daemon dynamically
115
- * Preserves orchestrator conversation context
116
- */
117
- stopSpecialist(botType: string): Promise<boolean>;
118
- /**
119
- * Hot-reload a specialist (stop if running, start if enabled)
120
- */
121
- hotReloadSpecialist(email: string, password: string, botType: string, enabled: boolean, userId?: string): Promise<boolean>;
122
- /**
123
- * Start periodic status logging
124
- */
125
- startStatusLogging(intervalMs?: number): NodeJS.Timeout;
126
- }
127
- export interface CreateDaemonManagerOptions {
128
- /** Enable orchestrator mode */
129
- orchestratorMode?: boolean;
130
- /** Email of orchestrator bot (defaults to first) */
131
- orchestratorEmail?: string;
132
- /** Map specialist keys to bot emails */
133
- specialistEmails?: Record<string, string>;
134
- /** Specific workspace ID to use (for webhook-triggered restarts) */
135
- workspaceId?: string;
136
- }
137
- /**
138
- * Create and start the daemon manager
139
- * This is the main entry point for daemon mode
140
- *
141
- * @param options - Optional settings for orchestrator mode
142
- */
143
- export declare function createDaemonManager(options?: CreateDaemonManagerOptions): Promise<DaemonManager | null>;
144
- /**
145
- * Quick start function for testing
146
- *
147
- * @param orchestratorMode - Enable orchestrator mode (default: true)
148
- */
149
- export declare function startDaemonMode(orchestratorMode?: boolean): Promise<void>;
150
- //# sourceMappingURL=factory.d.ts.map