@hailer/mcp 0.1.17 → 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 (200) 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-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,372 +0,0 @@
1
- #!/usr/bin/env tsx
2
- "use strict";
3
- /**
4
- * Seed Bot Configuration
5
- *
6
- * Connects as master user, discovers Agent Directory workflows across all workspaces,
7
- * and writes bot configuration to .bot-config/{workspaceId}.json
8
- */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || (function () {
26
- var ownKeys = function(o) {
27
- ownKeys = Object.getOwnPropertyNames || function (o) {
28
- var ar = [];
29
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
- return ar;
31
- };
32
- return ownKeys(o);
33
- };
34
- return function (mod) {
35
- if (mod && mod.__esModule) return mod;
36
- var result = {};
37
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
- __setModuleDefault(result, mod);
39
- return result;
40
- };
41
- })();
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- const dotenv = __importStar(require("dotenv"));
44
- const fs = __importStar(require("fs"));
45
- const path = __importStar(require("path"));
46
- const hailer_clients_1 = require("../mcp/hailer-clients");
47
- const hailer_api_client_1 = require("../mcp/utils/hailer-api-client");
48
- // Load environment variables
49
- dotenv.config();
50
- // Constants
51
- const BOT_CONFIG_DIR = '.bot-config';
52
- const AGENT_DIRECTORY_PATTERNS = ['Agent Directory', 'AI Agents', '🤖 Agent Directory'];
53
- const DEPLOYED_PHASE_PATTERNS = ['deployed', 'active', 'enabled'];
54
- const RETIRED_PHASE_PATTERNS = ['retired', 'disabled', 'inactive'];
55
- const FIELD_KEY_HAILER_PROFILE = ['hailerProfile', 'Agent Hailer profile'];
56
- const FIELD_KEY_EMAIL = ['agentEmailInHailer', 'email', 'Email of Hailer profile'];
57
- const FIELD_KEY_PASSWORD = ['password'];
58
- const FIELD_KEY_BOT_TYPE = ['botType', 'bot_type', 'type'];
59
- // Helper functions
60
- function findFieldId(fields, patterns) {
61
- for (const pattern of patterns) {
62
- if (fields[pattern])
63
- return fields[pattern];
64
- }
65
- return null;
66
- }
67
- function findPhaseByPattern(phases, patterns) {
68
- for (const pattern of patterns) {
69
- const match = phases.find(p => p.name.toLowerCase().includes(pattern.toLowerCase()));
70
- if (match)
71
- return match.id;
72
- }
73
- return null;
74
- }
75
- function looksLikeUserId(value) {
76
- return /^[a-f0-9]{24}$/i.test(value);
77
- }
78
- function extractCredentialsFromActivity(activity, schema) {
79
- const fields = activity.fields || {};
80
- let email = null;
81
- let password = null;
82
- // Try fields object format - by field KEY first (from returnFlat: true)
83
- if (fields.agentEmailInHailer) {
84
- email = typeof fields.agentEmailInHailer === 'string' ? fields.agentEmailInHailer : (fields.agentEmailInHailer?.value || null);
85
- }
86
- if (fields.password) {
87
- password = typeof fields.password === 'string' ? fields.password : (fields.password?.value || null);
88
- }
89
- // Try fields object format - by field ID
90
- if (!email && schema.emailFieldId) {
91
- const emailField = fields[schema.emailFieldId];
92
- if (emailField) {
93
- email = emailField.value || emailField;
94
- }
95
- }
96
- if (!password && schema.passwordFieldId) {
97
- const passwordField = fields[schema.passwordFieldId];
98
- if (passwordField) {
99
- password = passwordField.value || passwordField;
100
- }
101
- }
102
- // Fallback: find email by pattern
103
- if (!email) {
104
- for (const [, fieldValue] of Object.entries(fields)) {
105
- const strValue = typeof fieldValue === 'string' ? fieldValue : fieldValue?.value;
106
- if (typeof strValue === 'string' && strValue.includes('@') && strValue.includes('.')) {
107
- email = strValue.replace(/['"]/g, '').trim();
108
- break;
109
- }
110
- }
111
- }
112
- if (email && password) {
113
- return { email, password };
114
- }
115
- return null;
116
- }
117
- function extractUserIdFromActivity(activity, schema) {
118
- const fields = activity.fields || {};
119
- // Try fields object format - by field KEY first
120
- if (fields.hailerProfile) {
121
- const value = fields.hailerProfile;
122
- return typeof value === 'string' ? value : (Array.isArray(value) ? value[0] : null);
123
- }
124
- // Try fields object format - by field ID
125
- if (schema.hailerProfileFieldId) {
126
- const profileField = fields[schema.hailerProfileFieldId];
127
- if (profileField) {
128
- const value = profileField.value || profileField;
129
- return typeof value === 'string' ? value : (Array.isArray(value) ? value[0] : null);
130
- }
131
- }
132
- // Fallback: iterate ALL fields and look for users field type
133
- for (const [, fieldValue] of Object.entries(fields)) {
134
- if (fieldValue && typeof fieldValue === 'object' && !Array.isArray(fieldValue)) {
135
- const typedField = fieldValue;
136
- if (typedField.type === 'users' && typedField.value) {
137
- const value = typedField.value;
138
- const userId = typeof value === 'string' ? value : (Array.isArray(value) ? value[0] : null);
139
- if (userId && looksLikeUserId(userId)) {
140
- return userId;
141
- }
142
- }
143
- }
144
- if (Array.isArray(fieldValue) && fieldValue.length > 0) {
145
- const firstVal = fieldValue[0];
146
- if (typeof firstVal === 'string' && looksLikeUserId(firstVal)) {
147
- return firstVal;
148
- }
149
- }
150
- }
151
- return null;
152
- }
153
- function extractBotTypeFromActivity(activity, schema) {
154
- const fields = activity.fields || {};
155
- // Try fields object format - by field KEY first
156
- if (fields.botType) {
157
- return typeof fields.botType === 'string' ? fields.botType : (fields.botType?.value || null);
158
- }
159
- // Try fields object format - by field ID
160
- if (schema.botTypeFieldId) {
161
- const botTypeField = fields[schema.botTypeFieldId];
162
- if (botTypeField) {
163
- return botTypeField.value || botTypeField;
164
- }
165
- }
166
- return null;
167
- }
168
- async function discoverAgentDirectory(apiClient, workspaceId) {
169
- // Get list of workflows
170
- const workflows = await apiClient.listWorkflows(workspaceId);
171
- // Find Agent Directory workflow
172
- const agentDir = workflows.find((w) => AGENT_DIRECTORY_PATTERNS.some(p => w.name?.includes(p)));
173
- if (!agentDir) {
174
- return null;
175
- }
176
- const workflowId = agentDir._id;
177
- // Extract phases
178
- const phases = [];
179
- if (agentDir.phases) {
180
- for (const [phaseId, phase] of Object.entries(agentDir.phases)) {
181
- phases.push({ id: phaseId, name: phase.name || phaseId });
182
- }
183
- }
184
- const deployedPhaseId = findPhaseByPattern(phases, DEPLOYED_PHASE_PATTERNS);
185
- const retiredPhaseId = findPhaseByPattern(phases, RETIRED_PHASE_PATTERNS);
186
- // Extract field IDs by key
187
- const fieldMap = {};
188
- if (agentDir.fields) {
189
- for (const [fieldId, field] of Object.entries(agentDir.fields)) {
190
- const key = field.key;
191
- if (key)
192
- fieldMap[key] = fieldId;
193
- }
194
- }
195
- return {
196
- workflowId,
197
- deployedPhaseId,
198
- retiredPhaseId,
199
- hailerProfileFieldId: findFieldId(fieldMap, FIELD_KEY_HAILER_PROFILE),
200
- emailFieldId: findFieldId(fieldMap, FIELD_KEY_EMAIL),
201
- passwordFieldId: findFieldId(fieldMap, FIELD_KEY_PASSWORD),
202
- botTypeFieldId: findFieldId(fieldMap, FIELD_KEY_BOT_TYPE),
203
- };
204
- }
205
- async function fetchBotActivities(apiClient, workflowId, phaseId) {
206
- const result = await apiClient.fetchActivityList(workflowId, phaseId, 100, { returnFlat: true });
207
- return result.data || result.activities || result.list || [];
208
- }
209
- async function processWorkspace(apiClient, workspaceId, workspaceName) {
210
- console.log(`\n Discovering Agent Directory...`);
211
- const schema = await discoverAgentDirectory(apiClient, workspaceId);
212
- if (!schema) {
213
- console.log(` No Agent Directory found`);
214
- return null;
215
- }
216
- console.log(` Found workflow: ${schema.workflowId}`);
217
- if (!schema.deployedPhaseId) {
218
- console.log(` No deployed phase found`);
219
- return null;
220
- }
221
- // Fetch deployed activities
222
- console.log(` Fetching deployed bots...`);
223
- const deployedActivities = await fetchBotActivities(apiClient, schema.workflowId, schema.deployedPhaseId);
224
- // Fetch retired activities if available
225
- let retiredActivities = [];
226
- if (schema.retiredPhaseId) {
227
- retiredActivities = await fetchBotActivities(apiClient, schema.workflowId, schema.retiredPhaseId);
228
- }
229
- console.log(` Found ${deployedActivities.length} deployed, ${retiredActivities.length} retired bots`);
230
- const config = {
231
- workspaceId,
232
- workspaceName,
233
- specialists: [],
234
- lastSynced: new Date().toISOString(),
235
- };
236
- // Process deployed activities
237
- for (const activity of deployedActivities) {
238
- const creds = extractCredentialsFromActivity(activity, schema);
239
- const userId = extractUserIdFromActivity(activity, schema);
240
- const botType = extractBotTypeFromActivity(activity, schema);
241
- if (!creds || !userId) {
242
- console.log(` Skipping ${activity.name} - missing credentials or userId`);
243
- continue;
244
- }
245
- if (botType === 'orchestrator') {
246
- config.orchestrator = {
247
- activityId: activity._id,
248
- userId,
249
- email: creds.email,
250
- password: creds.password,
251
- };
252
- console.log(` Orchestrator: ${activity.name}`);
253
- }
254
- else {
255
- config.specialists.push({
256
- activityId: activity._id,
257
- userId,
258
- email: creds.email,
259
- password: creds.password,
260
- botType: botType || 'unknown',
261
- enabled: true,
262
- });
263
- console.log(` Specialist: ${activity.name} (${botType || 'unknown'})`);
264
- }
265
- }
266
- // Process retired activities (disabled specialists)
267
- for (const activity of retiredActivities) {
268
- const creds = extractCredentialsFromActivity(activity, schema);
269
- const userId = extractUserIdFromActivity(activity, schema);
270
- const botType = extractBotTypeFromActivity(activity, schema);
271
- if (!creds || !userId)
272
- continue;
273
- if (botType === 'orchestrator')
274
- continue; // Skip retired orchestrators
275
- config.specialists.push({
276
- activityId: activity._id,
277
- userId,
278
- email: creds.email,
279
- password: creds.password,
280
- botType: botType || 'unknown',
281
- enabled: false,
282
- });
283
- console.log(` Retired: ${activity.name} (${botType || 'unknown'})`);
284
- }
285
- // Skip workspaces without orchestrator
286
- if (!config.orchestrator) {
287
- console.log(` No orchestrator found - skipping workspace`);
288
- return null;
289
- }
290
- return config;
291
- }
292
- async function main() {
293
- console.log('\n Bot Config Seeder');
294
- console.log('==================\n');
295
- // Check environment variables
296
- const email = process.env.HAILER_EMAIL;
297
- const password = process.env.HAILER_PASSWORD;
298
- const host = process.env.HAILER_API_URL || 'https://app.hailer.com';
299
- if (!email || !password) {
300
- console.error(' Error: HAILER_EMAIL and HAILER_PASSWORD environment variables are required');
301
- console.error('\nSet them in your .env file or export them:');
302
- console.error(' export HAILER_EMAIL=your@email.com');
303
- console.error(' export HAILER_PASSWORD=yourpassword');
304
- process.exit(1);
305
- }
306
- console.log(` Connecting to ${host} as ${email}...`);
307
- // Connect to Hailer
308
- const clientManager = new hailer_clients_1.HailerClientManager(host, email, password);
309
- let hailerClient;
310
- try {
311
- hailerClient = await clientManager.connect();
312
- console.log(' Connected successfully\n');
313
- }
314
- catch (error) {
315
- console.error(' Failed to connect:', error instanceof Error ? error.message : error);
316
- process.exit(1);
317
- }
318
- const apiClient = new hailer_api_client_1.HailerApiClient(hailerClient);
319
- // Get all workspaces
320
- console.log(' Fetching workspaces...');
321
- const init = await apiClient.request('v2.core.init', [['networks']]);
322
- const workspaces = init.networks || {};
323
- const workspaceIds = Object.keys(workspaces);
324
- console.log(` Found ${workspaceIds.length} workspace(s)\n`);
325
- // Create config directory
326
- const configDir = path.join(process.cwd(), BOT_CONFIG_DIR);
327
- if (!fs.existsSync(configDir)) {
328
- fs.mkdirSync(configDir, { recursive: true });
329
- console.log(` Created ${BOT_CONFIG_DIR}/ directory\n`);
330
- }
331
- let successCount = 0;
332
- let skipCount = 0;
333
- // Process each workspace
334
- for (const wsId of workspaceIds) {
335
- const ws = workspaces[wsId];
336
- const wsName = ws.name || wsId;
337
- console.log(` [${wsName}]`);
338
- try {
339
- // Switch to workspace
340
- await apiClient.request('v2.network.switch', [wsId]);
341
- const config = await processWorkspace(apiClient, wsId, wsName);
342
- if (config) {
343
- // Write config file
344
- const configPath = path.join(configDir, `${wsId}.json`);
345
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
346
- console.log(` Saved to ${BOT_CONFIG_DIR}/${wsId}.json`);
347
- successCount++;
348
- }
349
- else {
350
- skipCount++;
351
- }
352
- }
353
- catch (error) {
354
- console.error(` Error: ${error instanceof Error ? error.message : error}`);
355
- skipCount++;
356
- }
357
- }
358
- // Disconnect
359
- clientManager.disconnect();
360
- // Summary
361
- console.log('\n==================');
362
- console.log(` Done!`);
363
- console.log(` ${successCount} workspace(s) configured`);
364
- console.log(` ${skipCount} workspace(s) skipped`);
365
- console.log(`\nConfig files saved to: ${configDir}/\n`);
366
- }
367
- // Run
368
- main().catch(error => {
369
- console.error('\n Unexpected error:', error);
370
- process.exit(1);
371
- });
372
- //# sourceMappingURL=seed-config.js.map
@@ -1,111 +0,0 @@
1
- /**
2
- * Context Manager
3
- *
4
- * Handles token counting and automatic summarization to prevent "prompt too long" errors.
5
- * Uses character-based token estimation and provider-specific limits with safety margins.
6
- */
7
- export type ProviderType = 'anthropic' | 'openai';
8
- export interface TokenLimits {
9
- maxTokens: number;
10
- safeTokens: number;
11
- safetyMargin: number;
12
- }
13
- export interface TokenCountResult {
14
- totalTokens: number;
15
- systemPromptTokens: number;
16
- messagesTokens: number;
17
- toolsTokens: number;
18
- exceedsLimit: boolean;
19
- provider: ProviderType;
20
- limit: TokenLimits;
21
- }
22
- export interface ToolResultGroup {
23
- messages: any[];
24
- tokens: number;
25
- startIndex: number;
26
- endIndex: number;
27
- }
28
- export interface SummarizationResult {
29
- summarizedMessages: any[];
30
- originalTokens: number;
31
- summarizedTokens: number;
32
- chunksProcessed: number;
33
- reductionPercent: number;
34
- }
35
- export interface ContextManagerConfig {
36
- safetyMarginPercent: number;
37
- enableAutoSummarization: boolean;
38
- maxSummarizationChunks: number;
39
- anthropicApiKey?: string;
40
- openaiApiKey?: string;
41
- }
42
- export declare class ContextManager {
43
- private logger;
44
- private config;
45
- private readonly PROVIDER_LIMITS;
46
- constructor(config?: Partial<ContextManagerConfig>);
47
- /**
48
- * Estimate tokens from text using character-based approximation
49
- * Formula: 1 token ≈ 4 characters
50
- */
51
- private estimateTokens;
52
- /**
53
- * Calculate token limits for a provider with safety margin
54
- */
55
- private getTokenLimits;
56
- /**
57
- * Count tokens for system prompt
58
- */
59
- private countSystemPromptTokens;
60
- /**
61
- * Count tokens for messages array
62
- */
63
- private countMessagesTokens;
64
- /**
65
- * Count tokens for tools definitions
66
- */
67
- private countToolsTokens;
68
- /**
69
- * Count total tokens for a complete prompt
70
- */
71
- countTokens(systemPrompt: string | any, messages: any[], tools: any[], provider: ProviderType): TokenCountResult;
72
- /**
73
- * Split messages into logical groups based on tool call patterns
74
- * Groups together: assistant message with tool_use -> tool results
75
- */
76
- private splitIntoToolResultGroups;
77
- /**
78
- * Split tool result groups into chunks that fit within safe limits
79
- */
80
- private splitIntoChunks;
81
- /**
82
- * Summarize a chunk of tool results using the LLM
83
- */
84
- private summarizeChunk;
85
- /**
86
- * Summarize using Anthropic
87
- */
88
- private summarizeWithAnthropic;
89
- /**
90
- * Summarize using OpenAI
91
- */
92
- private summarizeWithOpenAI;
93
- /**
94
- * Main summarization orchestration
95
- */
96
- summarizeContext(systemPrompt: string, messages: any[], provider: ProviderType, userQuery?: string): Promise<SummarizationResult>;
97
- /**
98
- * Check if token count exceeds safe limit
99
- */
100
- exceedsLimit(tokenCount: number, provider: ProviderType): boolean;
101
- /**
102
- * Get warning threshold (80% of safe limit)
103
- */
104
- approachingLimit(tokenCount: number, provider: ProviderType): boolean;
105
- /**
106
- * Get provider limits info
107
- */
108
- getProviderLimits(provider: ProviderType): TokenLimits;
109
- }
110
- export declare function getContextManager(config?: Partial<ContextManagerConfig>): ContextManager;
111
- //# sourceMappingURL=context-manager.d.ts.map