@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.
- package/dist/app.js +27 -20
- package/dist/core.d.ts +33 -9
- package/dist/core.js +279 -147
- package/dist/mcp/UserContextCache.js +18 -0
- package/dist/mcp/hailer-clients.d.ts +9 -1
- package/dist/mcp/hailer-clients.js +13 -3
- package/dist/mcp/signal-handler.js +1 -1
- package/dist/mcp/tool-registry.d.ts +3 -1
- package/dist/mcp/tool-registry.js +4 -1
- package/dist/mcp/tools/activity.js +43 -34
- package/dist/mcp/tools/bot-config/constants.d.ts +23 -0
- package/dist/mcp/tools/bot-config/constants.js +94 -0
- package/dist/mcp/tools/{bot-config.d.ts → bot-config/core.d.ts} +6 -6
- package/dist/mcp/tools/{bot-config.js → bot-config/core.js} +15 -15
- package/dist/mcp/tools/bot-config/index.d.ts +10 -0
- package/dist/mcp/tools/bot-config/index.js +59 -0
- package/dist/mcp/tools/bot-config/tools.d.ts +7 -0
- package/dist/mcp/tools/bot-config/tools.js +15 -0
- package/dist/mcp/tools/bot-config/types.d.ts +50 -0
- package/dist/mcp/tools/bot-config/types.js +6 -0
- package/dist/mcp/tools/bug-fixer-tools.d.ts +21 -0
- package/dist/mcp/tools/{giuseppe-tools.js → bug-fixer-tools.js} +61 -61
- package/dist/mcp/tools/user.js +10 -29
- package/dist/mcp/tools/workflow.js +36 -2
- package/dist/mcp/utils/data-transformers.d.ts +0 -8
- package/dist/mcp/utils/data-transformers.js +0 -28
- package/dist/mcp/utils/index.d.ts +4 -1
- package/dist/mcp/utils/index.js +17 -3
- package/dist/mcp/utils/pagination.d.ts +40 -0
- package/dist/mcp/utils/pagination.js +55 -0
- package/dist/mcp/utils/response-builder.d.ts +53 -0
- package/dist/mcp/utils/response-builder.js +110 -0
- package/dist/mcp/utils/tool-helpers.d.ts +0 -8
- package/dist/mcp/utils/tool-helpers.js +0 -24
- package/dist/mcp/utils/types.d.ts +1 -33
- package/dist/mcp-server.d.ts +2 -2
- package/dist/mcp-server.js +161 -139
- package/package.json +1 -1
- package/REFACTOR_STATUS.md +0 -127
- package/dist/agents/bot-manager.d.ts +0 -48
- package/dist/agents/bot-manager.js +0 -254
- package/dist/agents/factory.d.ts +0 -150
- package/dist/agents/factory.js +0 -650
- package/dist/agents/giuseppe/ai.d.ts +0 -83
- package/dist/agents/giuseppe/ai.js +0 -466
- package/dist/agents/giuseppe/bot.d.ts +0 -110
- package/dist/agents/giuseppe/bot.js +0 -780
- package/dist/agents/giuseppe/config.d.ts +0 -25
- package/dist/agents/giuseppe/config.js +0 -227
- package/dist/agents/giuseppe/files.d.ts +0 -52
- package/dist/agents/giuseppe/files.js +0 -338
- package/dist/agents/giuseppe/git.d.ts +0 -48
- package/dist/agents/giuseppe/git.js +0 -298
- package/dist/agents/giuseppe/index.d.ts +0 -97
- package/dist/agents/giuseppe/index.js +0 -258
- package/dist/agents/giuseppe/lsp.d.ts +0 -113
- package/dist/agents/giuseppe/lsp.js +0 -485
- package/dist/agents/giuseppe/monitor.d.ts +0 -118
- package/dist/agents/giuseppe/monitor.js +0 -621
- package/dist/agents/giuseppe/prompt.d.ts +0 -5
- package/dist/agents/giuseppe/prompt.js +0 -94
- package/dist/agents/giuseppe/registries/pending-classification.d.ts +0 -28
- package/dist/agents/giuseppe/registries/pending-classification.js +0 -50
- package/dist/agents/giuseppe/registries/pending-fix.d.ts +0 -30
- package/dist/agents/giuseppe/registries/pending-fix.js +0 -42
- package/dist/agents/giuseppe/registries/pending.d.ts +0 -27
- package/dist/agents/giuseppe/registries/pending.js +0 -49
- package/dist/agents/giuseppe/specialist.d.ts +0 -47
- package/dist/agents/giuseppe/specialist.js +0 -237
- package/dist/agents/giuseppe/types.d.ts +0 -123
- package/dist/agents/giuseppe/types.js +0 -9
- package/dist/agents/hailer-expert/index.d.ts +0 -8
- package/dist/agents/hailer-expert/index.js +0 -14
- package/dist/agents/hal/daemon.d.ts +0 -142
- package/dist/agents/hal/daemon.js +0 -1103
- package/dist/agents/hal/definitions.d.ts +0 -55
- package/dist/agents/hal/definitions.js +0 -263
- package/dist/agents/hal/index.d.ts +0 -3
- package/dist/agents/hal/index.js +0 -8
- package/dist/agents/index.d.ts +0 -18
- package/dist/agents/index.js +0 -48
- package/dist/agents/shared/base.d.ts +0 -216
- package/dist/agents/shared/base.js +0 -846
- package/dist/agents/shared/services/agent-registry.d.ts +0 -107
- package/dist/agents/shared/services/agent-registry.js +0 -629
- package/dist/agents/shared/services/conversation-manager.d.ts +0 -50
- package/dist/agents/shared/services/conversation-manager.js +0 -136
- package/dist/agents/shared/services/mcp-client.d.ts +0 -56
- package/dist/agents/shared/services/mcp-client.js +0 -124
- package/dist/agents/shared/services/message-classifier.d.ts +0 -37
- package/dist/agents/shared/services/message-classifier.js +0 -187
- package/dist/agents/shared/services/message-formatter.d.ts +0 -89
- package/dist/agents/shared/services/message-formatter.js +0 -371
- package/dist/agents/shared/services/session-logger.d.ts +0 -106
- package/dist/agents/shared/services/session-logger.js +0 -446
- package/dist/agents/shared/services/tool-executor.d.ts +0 -41
- package/dist/agents/shared/services/tool-executor.js +0 -169
- package/dist/agents/shared/services/workspace-schema-cache.d.ts +0 -125
- package/dist/agents/shared/services/workspace-schema-cache.js +0 -578
- package/dist/agents/shared/specialist.d.ts +0 -91
- package/dist/agents/shared/specialist.js +0 -399
- package/dist/agents/shared/tool-schema-loader.d.ts +0 -62
- package/dist/agents/shared/tool-schema-loader.js +0 -232
- package/dist/agents/shared/types.d.ts +0 -327
- package/dist/agents/shared/types.js +0 -121
- package/dist/client/agents/base.d.ts +0 -207
- package/dist/client/agents/base.js +0 -744
- package/dist/client/agents/definitions.d.ts +0 -53
- package/dist/client/agents/definitions.js +0 -263
- package/dist/client/agents/orchestrator.d.ts +0 -141
- package/dist/client/agents/orchestrator.js +0 -1062
- package/dist/client/agents/specialist.d.ts +0 -86
- package/dist/client/agents/specialist.js +0 -340
- package/dist/client/bot-entrypoint.d.ts +0 -7
- package/dist/client/bot-entrypoint.js +0 -103
- package/dist/client/bot-manager.d.ts +0 -44
- package/dist/client/bot-manager.js +0 -173
- package/dist/client/bot-runner.d.ts +0 -35
- package/dist/client/bot-runner.js +0 -188
- package/dist/client/chat-agent-daemon.d.ts +0 -464
- package/dist/client/chat-agent-daemon.js +0 -1774
- package/dist/client/daemon-factory.d.ts +0 -106
- package/dist/client/daemon-factory.js +0 -301
- package/dist/client/factory.d.ts +0 -111
- package/dist/client/factory.js +0 -314
- package/dist/client/index.d.ts +0 -17
- package/dist/client/index.js +0 -38
- package/dist/client/multi-bot-manager.d.ts +0 -42
- package/dist/client/multi-bot-manager.js +0 -161
- package/dist/client/orchestrator-daemon.d.ts +0 -87
- package/dist/client/orchestrator-daemon.js +0 -444
- package/dist/client/server.d.ts +0 -8
- package/dist/client/server.js +0 -251
- package/dist/client/services/agent-registry.d.ts +0 -108
- package/dist/client/services/agent-registry.js +0 -630
- package/dist/client/services/conversation-manager.d.ts +0 -50
- package/dist/client/services/conversation-manager.js +0 -136
- package/dist/client/services/mcp-client.d.ts +0 -48
- package/dist/client/services/mcp-client.js +0 -105
- package/dist/client/services/message-classifier.d.ts +0 -37
- package/dist/client/services/message-classifier.js +0 -187
- package/dist/client/services/message-formatter.d.ts +0 -84
- package/dist/client/services/message-formatter.js +0 -353
- package/dist/client/services/session-logger.d.ts +0 -106
- package/dist/client/services/session-logger.js +0 -446
- package/dist/client/services/tool-executor.d.ts +0 -41
- package/dist/client/services/tool-executor.js +0 -169
- package/dist/client/services/workspace-schema-cache.d.ts +0 -149
- package/dist/client/services/workspace-schema-cache.js +0 -732
- package/dist/client/specialist-daemon.d.ts +0 -77
- package/dist/client/specialist-daemon.js +0 -197
- package/dist/client/specialists.d.ts +0 -53
- package/dist/client/specialists.js +0 -178
- package/dist/client/tool-schema-loader.d.ts +0 -62
- package/dist/client/tool-schema-loader.js +0 -232
- package/dist/client/types.d.ts +0 -327
- package/dist/client/types.js +0 -121
- package/dist/commands/seed-config.d.ts +0 -9
- package/dist/commands/seed-config.js +0 -372
- package/dist/lib/context-manager.d.ts +0 -111
- package/dist/lib/context-manager.js +0 -431
- package/dist/lib/prompt-length-manager.d.ts +0 -81
- package/dist/lib/prompt-length-manager.js +0 -457
- package/dist/mcp/tools/giuseppe-tools.d.ts +0 -21
- package/dist/modules/bug-reports/bug-config.d.ts +0 -25
- package/dist/modules/bug-reports/bug-config.js +0 -187
- package/dist/modules/bug-reports/bug-monitor.d.ts +0 -108
- package/dist/modules/bug-reports/bug-monitor.js +0 -510
- package/dist/modules/bug-reports/giuseppe-agent.d.ts +0 -58
- package/dist/modules/bug-reports/giuseppe-agent.js +0 -467
- package/dist/modules/bug-reports/giuseppe-ai.d.ts +0 -83
- package/dist/modules/bug-reports/giuseppe-ai.js +0 -466
- package/dist/modules/bug-reports/giuseppe-bot.d.ts +0 -110
- package/dist/modules/bug-reports/giuseppe-bot.js +0 -804
- package/dist/modules/bug-reports/giuseppe-daemon.d.ts +0 -80
- package/dist/modules/bug-reports/giuseppe-daemon.js +0 -617
- package/dist/modules/bug-reports/giuseppe-files.d.ts +0 -64
- package/dist/modules/bug-reports/giuseppe-files.js +0 -375
- package/dist/modules/bug-reports/giuseppe-git.d.ts +0 -48
- package/dist/modules/bug-reports/giuseppe-git.js +0 -298
- package/dist/modules/bug-reports/giuseppe-lsp.d.ts +0 -113
- package/dist/modules/bug-reports/giuseppe-lsp.js +0 -485
- package/dist/modules/bug-reports/giuseppe-prompt.d.ts +0 -5
- package/dist/modules/bug-reports/giuseppe-prompt.js +0 -94
- package/dist/modules/bug-reports/index.d.ts +0 -77
- package/dist/modules/bug-reports/index.js +0 -215
- package/dist/modules/bug-reports/pending-classification-registry.d.ts +0 -28
- package/dist/modules/bug-reports/pending-classification-registry.js +0 -50
- package/dist/modules/bug-reports/pending-fix-registry.d.ts +0 -30
- package/dist/modules/bug-reports/pending-fix-registry.js +0 -42
- package/dist/modules/bug-reports/pending-registry.d.ts +0 -27
- package/dist/modules/bug-reports/pending-registry.js +0 -49
- package/dist/modules/bug-reports/types.d.ts +0 -123
- package/dist/modules/bug-reports/types.js +0 -9
- package/dist/routes/agents.d.ts +0 -44
- package/dist/routes/agents.js +0 -311
- package/dist/services/agent-credential-store.d.ts +0 -73
- package/dist/services/agent-credential-store.js +0 -212
- package/dist/services/bug-monitor.d.ts +0 -23
- package/dist/services/bug-monitor.js +0 -275
|
@@ -1,629 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Agent Registry Service
|
|
4
|
-
*
|
|
5
|
-
* Handles registration of agents in Hailer workspace workflows:
|
|
6
|
-
* - Agent Directory: Main registry of all bots
|
|
7
|
-
* - Positions: Job descriptions/roles
|
|
8
|
-
* - Teams: Groups of agents
|
|
9
|
-
* - Tool Registry: MCP server configurations
|
|
10
|
-
* - MCP Config: Per-agent MCP configuration
|
|
11
|
-
*
|
|
12
|
-
* WORKSPACE ISOLATION: Uses WorkspaceSchemaCacheService for dynamic ID lookup.
|
|
13
|
-
* Never relies on hardcoded IDs - each workspace has its own workflow IDs.
|
|
14
|
-
*/
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.AgentRegistryService = void 0;
|
|
17
|
-
const config_1 = require("../../../config");
|
|
18
|
-
class AgentRegistryService {
|
|
19
|
-
schemaCache;
|
|
20
|
-
logger;
|
|
21
|
-
callMcpTool;
|
|
22
|
-
getDefaultTeamId;
|
|
23
|
-
agentDirectoryId = null;
|
|
24
|
-
positionId = null;
|
|
25
|
-
teamId = null;
|
|
26
|
-
toolRegistryId = null;
|
|
27
|
-
mcpConfigId = null;
|
|
28
|
-
constructor(schemaCache, logger, callMcpTool, getDefaultTeamId) {
|
|
29
|
-
this.schemaCache = schemaCache;
|
|
30
|
-
this.logger = logger;
|
|
31
|
-
this.callMcpTool = callMcpTool;
|
|
32
|
-
this.getDefaultTeamId = getDefaultTeamId;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Load registration data - always returns false to force fresh Hailer lookup
|
|
36
|
-
* Kept for API compatibility with base.ts
|
|
37
|
-
*/
|
|
38
|
-
async loadFromCache(_userId, _workspaceId) {
|
|
39
|
-
// Always return false - agent should query Hailer on every startup
|
|
40
|
-
// The findAgentByUserId() method in registerAllAgentData handles deduplication
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get agent directory ID
|
|
45
|
-
*/
|
|
46
|
-
getAgentDirectoryId() {
|
|
47
|
-
return this.agentDirectoryId;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get position ID
|
|
51
|
-
*/
|
|
52
|
-
getPositionId() {
|
|
53
|
-
return this.positionId;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get team ID
|
|
57
|
-
*/
|
|
58
|
-
getTeamId() {
|
|
59
|
-
return this.teamId;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Register all agent data across all workflows
|
|
63
|
-
* Uses schemaCache for dynamic workflow ID lookup
|
|
64
|
-
*/
|
|
65
|
-
async registerAllAgentData(agentInfo, positionDetails, mcpServerUrl, toolIndex, workspaceId) {
|
|
66
|
-
this.logger.info("Starting full agent registration", { workspaceId });
|
|
67
|
-
// Verify schema cache has required workflows
|
|
68
|
-
const agentDirSchema = this.schemaCache.getAgentDirectorySchema(workspaceId);
|
|
69
|
-
if (!agentDirSchema) {
|
|
70
|
-
this.logger.warn("Agent Directory workflow not found in workspace - skipping registration", { workspaceId });
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
// 1. Register in Agent Directory first (required for other links)
|
|
75
|
-
await this.registerAgentInDirectory(agentInfo, workspaceId);
|
|
76
|
-
// 2. Create/find shared Team for AI agents
|
|
77
|
-
await this.registerTeam(workspaceId);
|
|
78
|
-
// 3. Register MCP server in Tool Registry (per-agent)
|
|
79
|
-
const agentName = `${agentInfo.firstName} ${agentInfo.lastName}`;
|
|
80
|
-
await this.registerToolRegistry(mcpServerUrl, toolIndex, workspaceId, agentName);
|
|
81
|
-
// 4. Create Position for this agent
|
|
82
|
-
await this.registerPosition(positionDetails, workspaceId);
|
|
83
|
-
// 5. Create MCP Config for this agent
|
|
84
|
-
await this.registerMcpConfig(agentInfo, workspaceId);
|
|
85
|
-
// 6. Update Agent Directory with Position and Team links
|
|
86
|
-
await this.linkAgentToPositionAndTeam(workspaceId);
|
|
87
|
-
this.logger.info("Full agent registration completed", {
|
|
88
|
-
workspaceId,
|
|
89
|
-
agentDirectoryId: this.agentDirectoryId,
|
|
90
|
-
positionId: this.positionId,
|
|
91
|
-
teamId: this.teamId,
|
|
92
|
-
toolRegistryId: this.toolRegistryId,
|
|
93
|
-
mcpConfigId: this.mcpConfigId,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
this.logger.warn("Agent registration incomplete", {
|
|
98
|
-
error: error instanceof Error ? error.message : String(error),
|
|
99
|
-
workspaceId,
|
|
100
|
-
agentDirectoryId: this.agentDirectoryId,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Register this agent in the Agent Directory
|
|
106
|
-
* Uses dynamic schema lookup for workflow/field IDs
|
|
107
|
-
*/
|
|
108
|
-
async registerAgentInDirectory(agentInfo, workspaceId) {
|
|
109
|
-
const schema = this.schemaCache.getAgentDirectorySchema(workspaceId);
|
|
110
|
-
if (!schema) {
|
|
111
|
-
this.logger.debug("Skipping agent directory registration - no schema");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.logger.info("Registering agent in directory", {
|
|
115
|
-
email: (0, config_1.maskEmail)(agentInfo.email),
|
|
116
|
-
userId: agentInfo.userId,
|
|
117
|
-
workflowId: schema.workflowId,
|
|
118
|
-
});
|
|
119
|
-
try {
|
|
120
|
-
// First, try to find existing agent by hailerProfile (userId) - most reliable
|
|
121
|
-
const existingAgent = await this.findAgentByUserId(agentInfo.userId, schema);
|
|
122
|
-
if (existingAgent) {
|
|
123
|
-
this.agentDirectoryId = existingAgent._id;
|
|
124
|
-
this.logger.info("Found existing agent in directory", {
|
|
125
|
-
agentDirectoryId: this.agentDirectoryId,
|
|
126
|
-
name: existingAgent.name,
|
|
127
|
-
});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
// Create new agent entry
|
|
131
|
-
const wsTeamId = this.getDefaultTeamId();
|
|
132
|
-
// Get phase ID - try "deployed agents" first, then partial match, then first available
|
|
133
|
-
const phaseId = this.findPhaseId(schema.phases, ["deployed agents", "deployed", "active"]);
|
|
134
|
-
this.logger.info("Creating new agent in directory", {
|
|
135
|
-
firstName: agentInfo.firstName,
|
|
136
|
-
lastName: agentInfo.lastName,
|
|
137
|
-
teamId: wsTeamId,
|
|
138
|
-
phaseId,
|
|
139
|
-
});
|
|
140
|
-
// Build fields using dynamic field IDs (support multiple key variants)
|
|
141
|
-
const fields = {};
|
|
142
|
-
// firstName field
|
|
143
|
-
const firstNameFieldId = schema.fields["firstName"] || schema.fields["Etunimi"];
|
|
144
|
-
if (firstNameFieldId)
|
|
145
|
-
fields[firstNameFieldId] = agentInfo.firstName;
|
|
146
|
-
// lastName field
|
|
147
|
-
const lastNameFieldId = schema.fields["lastName"] || schema.fields["Sukunimi"];
|
|
148
|
-
if (lastNameFieldId)
|
|
149
|
-
fields[lastNameFieldId] = agentInfo.lastName;
|
|
150
|
-
// description field
|
|
151
|
-
const descFieldId = schema.fields["description"] || schema.fields["agentmemoryThatAgentUsesToFindWhatToDo"] || schema.fields["Description"];
|
|
152
|
-
if (descFieldId)
|
|
153
|
-
fields[descFieldId] = agentInfo.description;
|
|
154
|
-
// email field (key varies by template)
|
|
155
|
-
const emailFieldId = schema.fields["agentEmailInHailer"] || schema.fields["email"] || schema.fields["Email of Hailer profile"];
|
|
156
|
-
if (emailFieldId)
|
|
157
|
-
fields[emailFieldId] = agentInfo.email;
|
|
158
|
-
// hailerProfile field (user ID link)
|
|
159
|
-
const profileFieldId = schema.fields["hailerProfile"] || schema.fields["Agent Hailer profile"];
|
|
160
|
-
if (profileFieldId)
|
|
161
|
-
fields[profileFieldId] = agentInfo.userId;
|
|
162
|
-
// startDate field
|
|
163
|
-
const startDateFieldId = schema.fields["startDate"] || schema.fields["Aloituspäivämäärä"];
|
|
164
|
-
if (startDateFieldId)
|
|
165
|
-
fields[startDateFieldId] = Date.now();
|
|
166
|
-
const createParams = {
|
|
167
|
-
workflowId: schema.workflowId,
|
|
168
|
-
name: `${agentInfo.firstName} ${agentInfo.lastName}`,
|
|
169
|
-
phaseId,
|
|
170
|
-
fields,
|
|
171
|
-
};
|
|
172
|
-
if (wsTeamId) {
|
|
173
|
-
createParams.teamId = wsTeamId;
|
|
174
|
-
}
|
|
175
|
-
const result = await this.callMcpTool("create_activity", createParams);
|
|
176
|
-
// Parse result to get the created activity ID
|
|
177
|
-
const resultText = result?.content?.[0]?.text;
|
|
178
|
-
if (resultText) {
|
|
179
|
-
this.agentDirectoryId = this.extractActivityId(resultText);
|
|
180
|
-
if (this.agentDirectoryId) {
|
|
181
|
-
this.logger.info("Agent registered in directory", {
|
|
182
|
-
agentDirectoryId: this.agentDirectoryId,
|
|
183
|
-
phaseId,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
this.logger.warn("Could not extract activity ID from create response", {
|
|
188
|
-
responsePreview: resultText.substring(0, 200),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
this.logger.warn("Failed to register agent in directory", {
|
|
195
|
-
error: error instanceof Error ? error.message : String(error),
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Find phase ID by trying multiple names (case insensitive, partial match)
|
|
201
|
-
*/
|
|
202
|
-
findPhaseId(phases, preferredNames) {
|
|
203
|
-
// Normalize phase keys for lookup
|
|
204
|
-
const normalizedPhases = Object.entries(phases).map(([name, id]) => ({
|
|
205
|
-
name: name.toLowerCase(),
|
|
206
|
-
id,
|
|
207
|
-
}));
|
|
208
|
-
// Try each preferred name in order
|
|
209
|
-
for (const preferred of preferredNames) {
|
|
210
|
-
const match = normalizedPhases.find(p => p.name.includes(preferred.toLowerCase()));
|
|
211
|
-
if (match)
|
|
212
|
-
return match.id;
|
|
213
|
-
}
|
|
214
|
-
// Fallback to first phase
|
|
215
|
-
return Object.values(phases)[0];
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Find existing agent entry by hailerProfile (userId) - most reliable method
|
|
219
|
-
*/
|
|
220
|
-
async findAgentByUserId(userId, schema) {
|
|
221
|
-
const hailerProfileFieldId = schema.fields["hailerProfile"] || schema.fields["Agent Hailer profile"];
|
|
222
|
-
if (!hailerProfileFieldId) {
|
|
223
|
-
this.logger.debug("No hailerProfile field in Agent Directory schema");
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
// Search across all phases (agent might be in any phase)
|
|
227
|
-
const phasesToSearch = Object.values(schema.phases);
|
|
228
|
-
for (const phaseId of phasesToSearch) {
|
|
229
|
-
try {
|
|
230
|
-
const result = await this.callMcpTool("list_activities", {
|
|
231
|
-
workflowId: schema.workflowId,
|
|
232
|
-
phaseId,
|
|
233
|
-
fields: [hailerProfileFieldId],
|
|
234
|
-
filters: {
|
|
235
|
-
[hailerProfileFieldId]: {
|
|
236
|
-
operator: "equals",
|
|
237
|
-
value: userId,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
limit: 1,
|
|
241
|
-
});
|
|
242
|
-
const resultText = result?.content?.[0]?.text;
|
|
243
|
-
if (resultText) {
|
|
244
|
-
const activity = this.parseFirstActivity(resultText);
|
|
245
|
-
if (activity) {
|
|
246
|
-
this.logger.debug("Found agent by userId", { phaseId, activityId: activity._id });
|
|
247
|
-
return activity;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
catch (error) {
|
|
252
|
-
this.logger.debug("Error searching phase for agent", { phaseId, error });
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Parse first activity from list_activities response
|
|
259
|
-
*/
|
|
260
|
-
parseFirstActivity(text) {
|
|
261
|
-
try {
|
|
262
|
-
// Try JSON parse first
|
|
263
|
-
const jsonMatch = text.match(/```json\s*([\s\S]*?)\s*```/) ||
|
|
264
|
-
text.match(/\[[\s\S]*?\]/);
|
|
265
|
-
if (jsonMatch) {
|
|
266
|
-
const jsonStr = jsonMatch[1] || jsonMatch[0];
|
|
267
|
-
const activities = JSON.parse(jsonStr);
|
|
268
|
-
if (Array.isArray(activities) && activities.length > 0) {
|
|
269
|
-
return activities[0];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
catch {
|
|
274
|
-
// Regex fallback
|
|
275
|
-
const idMatch = text.match(/"_id":\s*"([a-f0-9]{24})"/i);
|
|
276
|
-
const nameMatch = text.match(/"name":\s*"([^"]+)"/i);
|
|
277
|
-
if (idMatch) {
|
|
278
|
-
return { _id: idMatch[1], name: nameMatch?.[1] || "Unknown" };
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Register/find shared Team for AI agents
|
|
285
|
-
*/
|
|
286
|
-
async registerTeam(workspaceId) {
|
|
287
|
-
const schema = this.schemaCache.getTeamsSchema(workspaceId);
|
|
288
|
-
if (!schema) {
|
|
289
|
-
this.logger.debug("Teams workflow not found - skipping team registration");
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const teamName = "AI Agents";
|
|
293
|
-
const phaseId = this.findPhaseId(schema.phases, ["tiimit", "teams", "active"]);
|
|
294
|
-
const infoFieldId = schema.fields["teamInfo"] || schema.fields["info"] || schema.fields["Tiimi-info"];
|
|
295
|
-
try {
|
|
296
|
-
// Search for existing team
|
|
297
|
-
const result = await this.callMcpTool("list_activities", {
|
|
298
|
-
workflowId: schema.workflowId,
|
|
299
|
-
phaseId,
|
|
300
|
-
fields: infoFieldId ? [infoFieldId] : [],
|
|
301
|
-
search: teamName,
|
|
302
|
-
limit: 1,
|
|
303
|
-
});
|
|
304
|
-
const resultText = result?.content?.[0]?.text;
|
|
305
|
-
const existingId = this.extractActivityId(resultText);
|
|
306
|
-
if (existingId) {
|
|
307
|
-
this.teamId = existingId;
|
|
308
|
-
this.logger.info("Found existing AI Agents team", { teamId: this.teamId });
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
// Create new team
|
|
312
|
-
const wsTeamId = this.getDefaultTeamId();
|
|
313
|
-
const fields = {};
|
|
314
|
-
if (infoFieldId) {
|
|
315
|
-
fields[infoFieldId] = "Team of AI agent bots that assist with workspace operations.";
|
|
316
|
-
}
|
|
317
|
-
const createParams = {
|
|
318
|
-
workflowId: schema.workflowId,
|
|
319
|
-
name: teamName,
|
|
320
|
-
phaseId,
|
|
321
|
-
fields,
|
|
322
|
-
};
|
|
323
|
-
if (wsTeamId)
|
|
324
|
-
createParams.teamId = wsTeamId;
|
|
325
|
-
const createResult = await this.callMcpTool("create_activity", createParams);
|
|
326
|
-
this.teamId = this.extractActivityId(createResult?.content?.[0]?.text);
|
|
327
|
-
this.logger.info("Created AI Agents team", { teamId: this.teamId });
|
|
328
|
-
}
|
|
329
|
-
catch (error) {
|
|
330
|
-
this.logger.warn("Failed to register team", { error });
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Register MCP server in Tool Registry (per-agent)
|
|
335
|
-
*/
|
|
336
|
-
async registerToolRegistry(mcpServerUrl, toolIndex, workspaceId, agentName) {
|
|
337
|
-
const schema = this.schemaCache.getToolRegistrySchema(workspaceId);
|
|
338
|
-
if (!schema) {
|
|
339
|
-
this.logger.debug("Tool Registry workflow not found - skipping");
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
// Each agent gets its own Tool Registry entry
|
|
343
|
-
const serverName = `MCP Tools - ${agentName}`;
|
|
344
|
-
const phaseId = this.findPhaseId(schema.phases, ["active", "new phase"]);
|
|
345
|
-
try {
|
|
346
|
-
// Get field IDs with fallbacks
|
|
347
|
-
const baseUrlFieldId = schema.fields["mcpBaseUrl"] || schema.fields["baseUrl"] || schema.fields["mcp_base_url"];
|
|
348
|
-
const protocolFieldId = schema.fields["protocolVersion"] || schema.fields["protocol_version"];
|
|
349
|
-
const toolRegistryFieldId = schema.fields["toolRegistry"] || schema.fields["tool_registry"];
|
|
350
|
-
// Search for existing registry entry
|
|
351
|
-
const result = await this.callMcpTool("list_activities", {
|
|
352
|
-
workflowId: schema.workflowId,
|
|
353
|
-
phaseId,
|
|
354
|
-
fields: baseUrlFieldId ? [baseUrlFieldId] : [],
|
|
355
|
-
search: serverName,
|
|
356
|
-
limit: 1,
|
|
357
|
-
});
|
|
358
|
-
const resultText = result?.content?.[0]?.text;
|
|
359
|
-
const existingId = this.extractActivityId(resultText);
|
|
360
|
-
if (existingId) {
|
|
361
|
-
this.toolRegistryId = existingId;
|
|
362
|
-
this.logger.info("Found existing Tool Registry entry", { toolRegistryId: this.toolRegistryId });
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
// Create new tool registry entry
|
|
366
|
-
const wsTeamId = this.getDefaultTeamId();
|
|
367
|
-
const toolNames = toolIndex.map((t) => t.name).join(", ");
|
|
368
|
-
const fields = {};
|
|
369
|
-
if (baseUrlFieldId)
|
|
370
|
-
fields[baseUrlFieldId] = mcpServerUrl;
|
|
371
|
-
if (protocolFieldId)
|
|
372
|
-
fields[protocolFieldId] = "2024-11-05";
|
|
373
|
-
if (toolRegistryFieldId)
|
|
374
|
-
fields[toolRegistryFieldId] = `Available tools (${toolIndex.length}):\n${toolNames}`;
|
|
375
|
-
const createParams = {
|
|
376
|
-
workflowId: schema.workflowId,
|
|
377
|
-
name: serverName,
|
|
378
|
-
phaseId,
|
|
379
|
-
fields,
|
|
380
|
-
};
|
|
381
|
-
if (wsTeamId)
|
|
382
|
-
createParams.teamId = wsTeamId;
|
|
383
|
-
const createResult = await this.callMcpTool("create_activity", createParams);
|
|
384
|
-
this.toolRegistryId = this.extractActivityId(createResult?.content?.[0]?.text);
|
|
385
|
-
this.logger.info("Created Tool Registry entry", { toolRegistryId: this.toolRegistryId });
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
this.logger.warn("Failed to register tool registry", { error });
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Register Position for this agent
|
|
393
|
-
*/
|
|
394
|
-
async registerPosition(details, workspaceId) {
|
|
395
|
-
const schema = this.schemaCache.getPositionsSchema(workspaceId);
|
|
396
|
-
if (!schema) {
|
|
397
|
-
this.logger.debug("Positions workflow not found - skipping");
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
const phaseId = this.findPhaseId(schema.phases, ["positiot", "positions", "active"]);
|
|
401
|
-
// Get field IDs with fallbacks
|
|
402
|
-
const purposeFieldId = schema.fields["purpose"] || schema.fields["Purpose"];
|
|
403
|
-
const personaFieldId = schema.fields["personaTone"] || schema.fields["Persona & Tone"];
|
|
404
|
-
const capabilitiesFieldId = schema.fields["coreCapabilities"] || schema.fields["Core Capabilities"];
|
|
405
|
-
const boundariesFieldId = schema.fields["boundaries"] || schema.fields["Boundaries & Restrictions"];
|
|
406
|
-
const multiAllowedFieldId = schema.fields["multipleAllowed"] || schema.fields[">1 allowed in role"];
|
|
407
|
-
const agentCountFieldId = schema.fields["numberOfAgents"] || schema.fields["Number of agents in position"];
|
|
408
|
-
try {
|
|
409
|
-
// Search for existing position by name
|
|
410
|
-
const result = await this.callMcpTool("list_activities", {
|
|
411
|
-
workflowId: schema.workflowId,
|
|
412
|
-
phaseId,
|
|
413
|
-
fields: purposeFieldId ? [purposeFieldId] : [],
|
|
414
|
-
search: details.name,
|
|
415
|
-
limit: 1,
|
|
416
|
-
});
|
|
417
|
-
const resultText = result?.content?.[0]?.text;
|
|
418
|
-
const existingId = this.extractActivityId(resultText);
|
|
419
|
-
if (existingId) {
|
|
420
|
-
this.positionId = existingId;
|
|
421
|
-
this.logger.info("Found existing Position", { positionId: this.positionId });
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
// Create new position
|
|
425
|
-
const wsTeamId = this.getDefaultTeamId();
|
|
426
|
-
const fields = {};
|
|
427
|
-
if (purposeFieldId)
|
|
428
|
-
fields[purposeFieldId] = details.purpose;
|
|
429
|
-
if (personaFieldId)
|
|
430
|
-
fields[personaFieldId] = details.personaTone;
|
|
431
|
-
if (capabilitiesFieldId)
|
|
432
|
-
fields[capabilitiesFieldId] = details.coreCapabilities;
|
|
433
|
-
if (boundariesFieldId)
|
|
434
|
-
fields[boundariesFieldId] = details.boundaries;
|
|
435
|
-
if (multiAllowedFieldId)
|
|
436
|
-
fields[multiAllowedFieldId] = "Yes";
|
|
437
|
-
if (agentCountFieldId)
|
|
438
|
-
fields[agentCountFieldId] = 1;
|
|
439
|
-
const createParams = {
|
|
440
|
-
workflowId: schema.workflowId,
|
|
441
|
-
name: details.name,
|
|
442
|
-
phaseId,
|
|
443
|
-
fields,
|
|
444
|
-
};
|
|
445
|
-
if (wsTeamId)
|
|
446
|
-
createParams.teamId = wsTeamId;
|
|
447
|
-
const createResult = await this.callMcpTool("create_activity", createParams);
|
|
448
|
-
this.positionId = this.extractActivityId(createResult?.content?.[0]?.text);
|
|
449
|
-
this.logger.info("Created Position", { positionId: this.positionId });
|
|
450
|
-
}
|
|
451
|
-
catch (error) {
|
|
452
|
-
this.logger.warn("Failed to register position", { error });
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Register MCP Config for this agent
|
|
457
|
-
*/
|
|
458
|
-
async registerMcpConfig(agentInfo, workspaceId) {
|
|
459
|
-
if (!this.agentDirectoryId) {
|
|
460
|
-
this.logger.debug("Skipping MCP config - no agent directory ID");
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
const schema = this.schemaCache.getMcpConfigSchema(workspaceId);
|
|
464
|
-
if (!schema) {
|
|
465
|
-
this.logger.debug("MCP Config workflow not found - skipping");
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
const configName = `${agentInfo.firstName} ${agentInfo.lastName} Config`;
|
|
469
|
-
const phaseId = this.findPhaseId(schema.phases, ["active", "new phase"]);
|
|
470
|
-
// Get field IDs with fallbacks
|
|
471
|
-
const agentNameFieldId = schema.fields["agentName"] || schema.fields["agent_name"];
|
|
472
|
-
const agentIdFieldId = schema.fields["agentId"] || schema.fields["Agent_ID"];
|
|
473
|
-
const workspaceIdFieldId = schema.fields["workspaceId"] || schema.fields["workspace_id"];
|
|
474
|
-
const permissionsFieldId = schema.fields["permissions"] || schema.fields["Permissions"];
|
|
475
|
-
const permCreateFieldId = schema.fields["permissionCreate"] || schema.fields["Create"];
|
|
476
|
-
const permReadFieldId = schema.fields["permissionRead"] || schema.fields["Read"];
|
|
477
|
-
const permUpdateFieldId = schema.fields["permissionUpdate"] || schema.fields["Update"];
|
|
478
|
-
const permDeleteFieldId = schema.fields["permissionDelete"] || schema.fields["Delete"];
|
|
479
|
-
const accessToFieldId = schema.fields["accessTo"] || schema.fields["Access to"];
|
|
480
|
-
try {
|
|
481
|
-
// Search for existing config
|
|
482
|
-
const result = await this.callMcpTool("list_activities", {
|
|
483
|
-
workflowId: schema.workflowId,
|
|
484
|
-
phaseId,
|
|
485
|
-
fields: agentIdFieldId ? [agentIdFieldId] : [],
|
|
486
|
-
search: configName,
|
|
487
|
-
limit: 1,
|
|
488
|
-
});
|
|
489
|
-
const resultText = result?.content?.[0]?.text;
|
|
490
|
-
const existingId = this.extractActivityId(resultText);
|
|
491
|
-
if (existingId) {
|
|
492
|
-
this.mcpConfigId = existingId;
|
|
493
|
-
this.logger.info("Found existing MCP Config", { mcpConfigId: this.mcpConfigId });
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
// Create new MCP config
|
|
497
|
-
const wsTeamId = this.getDefaultTeamId();
|
|
498
|
-
const fields = {};
|
|
499
|
-
if (agentNameFieldId)
|
|
500
|
-
fields[agentNameFieldId] = this.agentDirectoryId;
|
|
501
|
-
if (agentIdFieldId)
|
|
502
|
-
fields[agentIdFieldId] = agentInfo.userId;
|
|
503
|
-
if (workspaceIdFieldId)
|
|
504
|
-
fields[workspaceIdFieldId] = workspaceId;
|
|
505
|
-
if (permissionsFieldId)
|
|
506
|
-
fields[permissionsFieldId] = "read, write";
|
|
507
|
-
if (permCreateFieldId)
|
|
508
|
-
fields[permCreateFieldId] = 1;
|
|
509
|
-
if (permReadFieldId)
|
|
510
|
-
fields[permReadFieldId] = 1;
|
|
511
|
-
if (permUpdateFieldId)
|
|
512
|
-
fields[permUpdateFieldId] = 1;
|
|
513
|
-
if (permDeleteFieldId)
|
|
514
|
-
fields[permDeleteFieldId] = 0;
|
|
515
|
-
// Link to Tool Registry if available
|
|
516
|
-
if (this.toolRegistryId && accessToFieldId) {
|
|
517
|
-
fields[accessToFieldId] = this.toolRegistryId;
|
|
518
|
-
}
|
|
519
|
-
const createParams = {
|
|
520
|
-
workflowId: schema.workflowId,
|
|
521
|
-
name: configName,
|
|
522
|
-
phaseId,
|
|
523
|
-
fields,
|
|
524
|
-
};
|
|
525
|
-
if (wsTeamId)
|
|
526
|
-
createParams.teamId = wsTeamId;
|
|
527
|
-
const createResult = await this.callMcpTool("create_activity", createParams);
|
|
528
|
-
this.mcpConfigId = this.extractActivityId(createResult?.content?.[0]?.text);
|
|
529
|
-
this.logger.info("Created MCP Config", { mcpConfigId: this.mcpConfigId });
|
|
530
|
-
}
|
|
531
|
-
catch (error) {
|
|
532
|
-
this.logger.warn("Failed to register MCP config", { error });
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Link Agent Directory entry to Position and Team
|
|
537
|
-
*/
|
|
538
|
-
async linkAgentToPositionAndTeam(workspaceId) {
|
|
539
|
-
if (!this.agentDirectoryId) {
|
|
540
|
-
this.logger.debug("Skipping agent linking - no agent directory ID");
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
const schema = this.schemaCache.getAgentDirectorySchema(workspaceId);
|
|
544
|
-
if (!schema)
|
|
545
|
-
return;
|
|
546
|
-
// Get field IDs with fallbacks
|
|
547
|
-
const positionFieldId = schema.fields["position"] || schema.fields["Työpositio"];
|
|
548
|
-
const teamFieldId = schema.fields["team"] || schema.fields["Tiimi"];
|
|
549
|
-
const updates = {};
|
|
550
|
-
if (this.positionId && positionFieldId) {
|
|
551
|
-
updates[positionFieldId] = this.positionId;
|
|
552
|
-
}
|
|
553
|
-
if (this.teamId && teamFieldId) {
|
|
554
|
-
updates[teamFieldId] = this.teamId;
|
|
555
|
-
}
|
|
556
|
-
if (Object.keys(updates).length === 0) {
|
|
557
|
-
this.logger.debug("No links to update");
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
try {
|
|
561
|
-
await this.callMcpTool("update_activity", {
|
|
562
|
-
activityId: this.agentDirectoryId,
|
|
563
|
-
fields: updates,
|
|
564
|
-
});
|
|
565
|
-
this.logger.info("Linked agent to Position and Team", {
|
|
566
|
-
agentDirectoryId: this.agentDirectoryId,
|
|
567
|
-
positionId: this.positionId,
|
|
568
|
-
teamId: this.teamId,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
catch (error) {
|
|
572
|
-
this.logger.warn("Failed to link agent to Position/Team", { error });
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Extract activity ID from MCP tool response text
|
|
577
|
-
* Specifically looks for created activity IDs, not workflow IDs
|
|
578
|
-
*/
|
|
579
|
-
extractActivityId(text) {
|
|
580
|
-
if (!text)
|
|
581
|
-
return null;
|
|
582
|
-
// Priority 1: Look for "**ID**:" pattern from create_activity single response
|
|
583
|
-
// Format: "- **ID**: 69576c7cce2c07784299e5a3"
|
|
584
|
-
const boldIdMatch = text.match(/\*\*ID\*\*:\s*([a-f0-9]{24})/i);
|
|
585
|
-
if (boldIdMatch)
|
|
586
|
-
return boldIdMatch[1];
|
|
587
|
-
// Priority 2: Look for "(ID: xxx," pattern from create_activity bulk response
|
|
588
|
-
// Format: '1. "Name" (ID: 69576c7cce2c07784299e5a3, Phase: ...)'
|
|
589
|
-
const parenIdMatch = text.match(/\(ID:\s*([a-f0-9]{24})[,)]/i);
|
|
590
|
-
if (parenIdMatch)
|
|
591
|
-
return parenIdMatch[1];
|
|
592
|
-
// Priority 3: Look in JSON arrays (list_activities response format)
|
|
593
|
-
// Use proper JSON parsing like parseFirstActivity
|
|
594
|
-
try {
|
|
595
|
-
const jsonMatch = text.match(/```json\s*([\s\S]*?)\s*```/) || text.match(/(\[[\s\S]*?\])/);
|
|
596
|
-
if (jsonMatch) {
|
|
597
|
-
const jsonStr = jsonMatch[1] || jsonMatch[0];
|
|
598
|
-
const activities = JSON.parse(jsonStr);
|
|
599
|
-
if (Array.isArray(activities) && activities.length > 0 && activities[0]._id) {
|
|
600
|
-
return activities[0]._id;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
catch {
|
|
605
|
-
// Ignore parse errors - try regex fallback
|
|
606
|
-
const idMatch = text.match(/"_id":\s*"([a-f0-9]{24})"/i);
|
|
607
|
-
if (idMatch)
|
|
608
|
-
return idMatch[1];
|
|
609
|
-
}
|
|
610
|
-
// Priority 4: Look for Activity ID label (from various tool responses)
|
|
611
|
-
const activityIdMatch = text.match(/Activity ID[:\s]+`?([a-f0-9]{24})`?/i);
|
|
612
|
-
if (activityIdMatch)
|
|
613
|
-
return activityIdMatch[1];
|
|
614
|
-
// Priority 5: Look for "created_ids" array (backup format)
|
|
615
|
-
const createdIdsMatch = text.match(/"created_ids":\s*\[\s*"([a-f0-9]{24})"/i);
|
|
616
|
-
if (createdIdsMatch)
|
|
617
|
-
return createdIdsMatch[1];
|
|
618
|
-
// Priority 6: Last resort - look for backtick-wrapped IDs (but NOT after "workflow")
|
|
619
|
-
const backtickIdMatch = text.match(/`([a-f0-9]{24})`/g);
|
|
620
|
-
if (backtickIdMatch && backtickIdMatch.length > 0) {
|
|
621
|
-
// Get the last backtick-wrapped ID (more likely to be the activity, not workflow)
|
|
622
|
-
const lastId = backtickIdMatch[backtickIdMatch.length - 1].replace(/`/g, '');
|
|
623
|
-
return lastId;
|
|
624
|
-
}
|
|
625
|
-
return null;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
exports.AgentRegistryService = AgentRegistryService;
|
|
629
|
-
//# sourceMappingURL=agent-registry.js.map
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation Manager Service
|
|
3
|
-
*
|
|
4
|
-
* Manages per-discussion conversation state:
|
|
5
|
-
* - LRU cache of conversation histories
|
|
6
|
-
* - Context size management with summarization
|
|
7
|
-
* - Conversation state access
|
|
8
|
-
*/
|
|
9
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
10
|
-
import { Logger } from "../../../lib/logger";
|
|
11
|
-
/** Conversation message using Anthropic's MessageParam type */
|
|
12
|
-
export type ConversationMessage = Anthropic.MessageParam;
|
|
13
|
-
export declare class ConversationManager {
|
|
14
|
-
private maxConversations;
|
|
15
|
-
private maxContextMessages;
|
|
16
|
-
private anthropicClient;
|
|
17
|
-
private logger;
|
|
18
|
-
private conversationsByDiscussion;
|
|
19
|
-
constructor(maxConversations: number, maxContextMessages: number, anthropicClient: Anthropic, logger: Logger);
|
|
20
|
-
/**
|
|
21
|
-
* Get or create conversation history for a specific discussion
|
|
22
|
-
* Each discussion has its own isolated context to prevent bloat
|
|
23
|
-
* Uses LRU eviction when map exceeds maxConversations
|
|
24
|
-
*/
|
|
25
|
-
getConversation(discussionId: string): ConversationMessage[];
|
|
26
|
-
/**
|
|
27
|
-
* Add a message to a conversation
|
|
28
|
-
*/
|
|
29
|
-
addMessage(discussionId: string, message: ConversationMessage): void;
|
|
30
|
-
/**
|
|
31
|
-
* Manage conversation context size - summarize if too large
|
|
32
|
-
*/
|
|
33
|
-
manageContextSize(discussionId: string): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Get conversation state for debugging
|
|
36
|
-
*/
|
|
37
|
-
getState(currentDiscussionId?: string): {
|
|
38
|
-
discussionCount: number;
|
|
39
|
-
currentMessageCount: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Get full conversation for a discussion (for debugging)
|
|
43
|
-
*/
|
|
44
|
-
getFullConversation(discussionId?: string): ConversationMessage[];
|
|
45
|
-
/**
|
|
46
|
-
* Clear all conversations
|
|
47
|
-
*/
|
|
48
|
-
clear(): void;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=conversation-manager.d.ts.map
|