@inkeep/agents-run-api 0.0.0-dev-20251009194333 → 0.0.0-dev-20251009221341
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/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { flushBatchProcessor } from './chunk-XO4RG36I.js';
|
|
2
2
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
3
|
-
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-
|
|
3
|
+
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-DQQRVSJS.js';
|
|
4
4
|
import { dbClient_default } from './chunk-7IMXW4RD.js';
|
|
5
5
|
import { env } from './chunk-NZHNG4A3.js';
|
|
6
6
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } from '@inkeep/agents-core';
|
|
8
8
|
import { otel } from '@hono/otel';
|
|
9
9
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
10
10
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -41,7 +41,7 @@ function createExecutionContext(params) {
|
|
|
41
41
|
graphId: params.graphId,
|
|
42
42
|
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
43
43
|
apiKeyId: params.apiKeyId,
|
|
44
|
-
|
|
44
|
+
subAgentId: params.subAgentId
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -56,7 +56,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
56
56
|
const tenantId = c.req.header("x-inkeep-tenant-id");
|
|
57
57
|
const projectId = c.req.header("x-inkeep-project-id");
|
|
58
58
|
const graphId = c.req.header("x-inkeep-graph-id");
|
|
59
|
-
const
|
|
59
|
+
const subAgentId = c.req.header("x-inkeep-agent-id");
|
|
60
60
|
const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
|
|
61
61
|
const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
|
|
62
62
|
const host = fwdHost ?? c.req.header("host");
|
|
@@ -67,7 +67,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
67
67
|
if (authHeader?.startsWith("Bearer ")) {
|
|
68
68
|
try {
|
|
69
69
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
70
|
-
executionContext.
|
|
70
|
+
executionContext.subAgentId = subAgentId;
|
|
71
71
|
logger.info({}, "Development/test environment - API key authenticated successfully");
|
|
72
72
|
} catch {
|
|
73
73
|
executionContext = createExecutionContext({
|
|
@@ -77,7 +77,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
77
77
|
graphId: graphId || "test-graph",
|
|
78
78
|
apiKeyId: "test-key",
|
|
79
79
|
baseUrl,
|
|
80
|
-
|
|
80
|
+
subAgentId
|
|
81
81
|
});
|
|
82
82
|
logger.info(
|
|
83
83
|
{},
|
|
@@ -92,7 +92,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
92
92
|
graphId: graphId || "test-graph",
|
|
93
93
|
apiKeyId: "test-key",
|
|
94
94
|
baseUrl,
|
|
95
|
-
|
|
95
|
+
subAgentId
|
|
96
96
|
});
|
|
97
97
|
logger.info(
|
|
98
98
|
{},
|
|
@@ -123,7 +123,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
123
123
|
graphId,
|
|
124
124
|
apiKeyId: "bypass",
|
|
125
125
|
baseUrl,
|
|
126
|
-
|
|
126
|
+
subAgentId
|
|
127
127
|
});
|
|
128
128
|
c.set("executionContext", executionContext);
|
|
129
129
|
logger.info({}, "Bypass secret authenticated successfully");
|
|
@@ -131,7 +131,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
131
131
|
return;
|
|
132
132
|
} else if (apiKey) {
|
|
133
133
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
134
|
-
executionContext.
|
|
134
|
+
executionContext.subAgentId = subAgentId;
|
|
135
135
|
c.set("executionContext", executionContext);
|
|
136
136
|
logger.info({}, "API key authenticated successfully");
|
|
137
137
|
await next();
|
|
@@ -149,14 +149,14 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
149
149
|
}
|
|
150
150
|
try {
|
|
151
151
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
152
|
-
executionContext.
|
|
152
|
+
executionContext.subAgentId = subAgentId;
|
|
153
153
|
c.set("executionContext", executionContext);
|
|
154
154
|
logger.debug(
|
|
155
155
|
{
|
|
156
156
|
tenantId: executionContext.tenantId,
|
|
157
157
|
projectId: executionContext.projectId,
|
|
158
158
|
graphId: executionContext.graphId,
|
|
159
|
-
|
|
159
|
+
subAgentId: executionContext.subAgentId
|
|
160
160
|
},
|
|
161
161
|
"API key authenticated successfully"
|
|
162
162
|
);
|
|
@@ -324,7 +324,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
324
324
|
logger2.warn(
|
|
325
325
|
{
|
|
326
326
|
taskId: task.id,
|
|
327
|
-
|
|
327
|
+
subAgentId: agent.subAgentId,
|
|
328
328
|
originalMessage: params.message
|
|
329
329
|
},
|
|
330
330
|
"Created fallback message content for empty delegation message"
|
|
@@ -345,7 +345,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
345
345
|
taskContextId: task.context?.conversationId,
|
|
346
346
|
metadataContextId: params.message.metadata?.conversationId,
|
|
347
347
|
finalContextId: effectiveContextId,
|
|
348
|
-
|
|
348
|
+
subAgentId: agent.subAgentId
|
|
349
349
|
},
|
|
350
350
|
"A2A contextId resolution for delegation"
|
|
351
351
|
);
|
|
@@ -361,11 +361,11 @@ async function handleMessageSend(c, agent, request) {
|
|
|
361
361
|
message_id: params.message.messageId || "",
|
|
362
362
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
363
363
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
364
|
-
agent_id: agent.
|
|
364
|
+
agent_id: agent.subAgentId,
|
|
365
365
|
graph_id: graphId || "",
|
|
366
366
|
stream_request_id: params.message.metadata?.stream_request_id
|
|
367
367
|
},
|
|
368
|
-
|
|
368
|
+
subAgentId: agent.subAgentId,
|
|
369
369
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
370
370
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
371
371
|
});
|
|
@@ -388,17 +388,17 @@ async function handleMessageSend(c, agent, request) {
|
|
|
388
388
|
};
|
|
389
389
|
if (params.message.metadata?.fromAgentId) {
|
|
390
390
|
messageData.fromAgentId = params.message.metadata.fromAgentId;
|
|
391
|
-
messageData.toAgentId = agent.
|
|
391
|
+
messageData.toAgentId = agent.subAgentId;
|
|
392
392
|
} else if (params.message.metadata?.fromExternalAgentId) {
|
|
393
393
|
messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
|
|
394
|
-
messageData.toAgentId = agent.
|
|
394
|
+
messageData.toAgentId = agent.subAgentId;
|
|
395
395
|
}
|
|
396
396
|
await createMessage(dbClient_default)(messageData);
|
|
397
397
|
logger2.info(
|
|
398
398
|
{
|
|
399
399
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
400
400
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
401
|
-
toAgentId: agent.
|
|
401
|
+
toAgentId: agent.subAgentId,
|
|
402
402
|
conversationId: effectiveContextId,
|
|
403
403
|
messageType: "a2a-request",
|
|
404
404
|
taskId: task.id
|
|
@@ -411,7 +411,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
411
411
|
error,
|
|
412
412
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
413
413
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
414
|
-
toAgentId: agent.
|
|
414
|
+
toAgentId: agent.subAgentId,
|
|
415
415
|
conversationId: effectiveContextId
|
|
416
416
|
},
|
|
417
417
|
"Failed to store A2A message in database"
|
|
@@ -428,7 +428,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
428
428
|
message_id: params.message.messageId || "",
|
|
429
429
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
430
430
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
431
|
-
agent_id: agent.
|
|
431
|
+
agent_id: agent.subAgentId,
|
|
432
432
|
graph_id: graphId || ""
|
|
433
433
|
}
|
|
434
434
|
}
|
|
@@ -462,7 +462,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
462
462
|
kind: "data",
|
|
463
463
|
data: {
|
|
464
464
|
type: "transfer",
|
|
465
|
-
|
|
465
|
+
targetSubAgentId: transferPart.data.target
|
|
466
466
|
}
|
|
467
467
|
},
|
|
468
468
|
{
|
|
@@ -762,7 +762,7 @@ async function handleGetCapabilities(c, agent, request) {
|
|
|
762
762
|
async function handleGetStatus(c, agent, request) {
|
|
763
763
|
return c.json({
|
|
764
764
|
jsonrpc: "2.0",
|
|
765
|
-
result: { status: "ready",
|
|
765
|
+
result: { status: "ready", subAgentId: agent.subAgentId },
|
|
766
766
|
id: request.id
|
|
767
767
|
});
|
|
768
768
|
}
|
|
@@ -825,7 +825,6 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
825
825
|
});
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
|
-
getLogger$1("agents");
|
|
829
828
|
function createAgentCard({
|
|
830
829
|
dbAgent,
|
|
831
830
|
baseUrl
|
|
@@ -903,7 +902,7 @@ async function hydrateAgent({
|
|
|
903
902
|
tenantId: dbAgent.tenantId,
|
|
904
903
|
projectId: dbAgent.projectId,
|
|
905
904
|
graphId,
|
|
906
|
-
|
|
905
|
+
subAgentId: dbAgent.id,
|
|
907
906
|
baseUrl,
|
|
908
907
|
apiKey
|
|
909
908
|
});
|
|
@@ -913,7 +912,7 @@ async function hydrateAgent({
|
|
|
913
912
|
baseUrl
|
|
914
913
|
});
|
|
915
914
|
return {
|
|
916
|
-
|
|
915
|
+
subAgentId: dbAgent.id,
|
|
917
916
|
tenantId: dbAgent.tenantId,
|
|
918
917
|
projectId: dbAgent.projectId,
|
|
919
918
|
graphId,
|
|
@@ -926,13 +925,13 @@ async function hydrateAgent({
|
|
|
926
925
|
}
|
|
927
926
|
}
|
|
928
927
|
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
929
|
-
const { tenantId, projectId, graphId,
|
|
930
|
-
if (!
|
|
928
|
+
const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
929
|
+
if (!subAgentId) {
|
|
931
930
|
throw new Error("Agent ID is required");
|
|
932
931
|
}
|
|
933
|
-
const dbAgent = await
|
|
932
|
+
const dbAgent = await getSubAgentById(dbClient_default)({
|
|
934
933
|
scopes: { tenantId, projectId, graphId },
|
|
935
|
-
|
|
934
|
+
subAgentId
|
|
936
935
|
});
|
|
937
936
|
if (!dbAgent) {
|
|
938
937
|
return null;
|
|
@@ -946,7 +945,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
946
945
|
apiKey
|
|
947
946
|
});
|
|
948
947
|
}
|
|
949
|
-
var
|
|
948
|
+
var logger3 = getLogger("ModelFactory");
|
|
950
949
|
var _ModelFactory = class _ModelFactory {
|
|
951
950
|
/**
|
|
952
951
|
* Create a provider instance with custom configuration
|
|
@@ -1008,7 +1007,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1008
1007
|
}
|
|
1009
1008
|
const modelString = modelSettings.model.trim();
|
|
1010
1009
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1011
|
-
|
|
1010
|
+
logger3.debug(
|
|
1012
1011
|
{
|
|
1013
1012
|
provider,
|
|
1014
1013
|
model: modelName,
|
|
@@ -1019,7 +1018,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1019
1018
|
);
|
|
1020
1019
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1021
1020
|
if (Object.keys(providerConfig).length > 0) {
|
|
1022
|
-
|
|
1021
|
+
logger3.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1023
1022
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1024
1023
|
return customProvider.languageModel(modelName);
|
|
1025
1024
|
}
|
|
@@ -1135,7 +1134,7 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
|
|
|
1135
1134
|
"gateway"
|
|
1136
1135
|
]);
|
|
1137
1136
|
var ModelFactory = _ModelFactory;
|
|
1138
|
-
var
|
|
1137
|
+
var logger4 = getLogger("ToolSessionManager");
|
|
1139
1138
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1140
1139
|
// 5 minutes
|
|
1141
1140
|
constructor() {
|
|
@@ -1170,7 +1169,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1170
1169
|
createdAt: Date.now()
|
|
1171
1170
|
};
|
|
1172
1171
|
this.sessions.set(sessionId, session);
|
|
1173
|
-
|
|
1172
|
+
logger4.debug(
|
|
1174
1173
|
{
|
|
1175
1174
|
sessionId,
|
|
1176
1175
|
tenantId,
|
|
@@ -1188,10 +1187,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1188
1187
|
*/
|
|
1189
1188
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1190
1189
|
if (this.sessions.has(sessionId)) {
|
|
1191
|
-
|
|
1190
|
+
logger4.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1192
1191
|
return sessionId;
|
|
1193
1192
|
}
|
|
1194
|
-
|
|
1193
|
+
logger4.debug(
|
|
1195
1194
|
{ sessionId, tenantId, contextId, taskId },
|
|
1196
1195
|
"Creating new graph-scoped tool session"
|
|
1197
1196
|
);
|
|
@@ -1203,7 +1202,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1203
1202
|
recordToolResult(sessionId, toolResult) {
|
|
1204
1203
|
const session = this.sessions.get(sessionId);
|
|
1205
1204
|
if (!session) {
|
|
1206
|
-
|
|
1205
|
+
logger4.warn(
|
|
1207
1206
|
{
|
|
1208
1207
|
sessionId,
|
|
1209
1208
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1215,7 +1214,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1215
1214
|
return;
|
|
1216
1215
|
}
|
|
1217
1216
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
1218
|
-
|
|
1217
|
+
logger4.debug(
|
|
1219
1218
|
{
|
|
1220
1219
|
sessionId,
|
|
1221
1220
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1230,7 +1229,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1230
1229
|
getToolResult(sessionId, toolCallId) {
|
|
1231
1230
|
const session = this.sessions.get(sessionId);
|
|
1232
1231
|
if (!session) {
|
|
1233
|
-
|
|
1232
|
+
logger4.warn(
|
|
1234
1233
|
{
|
|
1235
1234
|
sessionId,
|
|
1236
1235
|
toolCallId,
|
|
@@ -1243,7 +1242,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1243
1242
|
}
|
|
1244
1243
|
const result = session.toolResults.get(toolCallId);
|
|
1245
1244
|
if (!result) {
|
|
1246
|
-
|
|
1245
|
+
logger4.warn(
|
|
1247
1246
|
{
|
|
1248
1247
|
sessionId,
|
|
1249
1248
|
toolCallId,
|
|
@@ -1253,7 +1252,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1253
1252
|
"Tool result not found"
|
|
1254
1253
|
);
|
|
1255
1254
|
} else {
|
|
1256
|
-
|
|
1255
|
+
logger4.debug(
|
|
1257
1256
|
{
|
|
1258
1257
|
sessionId,
|
|
1259
1258
|
toolCallId,
|
|
@@ -1292,10 +1291,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1292
1291
|
}
|
|
1293
1292
|
for (const sessionId of expiredSessions) {
|
|
1294
1293
|
this.sessions.delete(sessionId);
|
|
1295
|
-
|
|
1294
|
+
logger4.debug({ sessionId }, "Cleaned up expired tool session");
|
|
1296
1295
|
}
|
|
1297
1296
|
if (expiredSessions.length > 0) {
|
|
1298
|
-
|
|
1297
|
+
logger4.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
1299
1298
|
}
|
|
1300
1299
|
}
|
|
1301
1300
|
};
|
|
@@ -1365,7 +1364,7 @@ function extractFullFields(schema) {
|
|
|
1365
1364
|
}
|
|
1366
1365
|
|
|
1367
1366
|
// src/services/ArtifactService.ts
|
|
1368
|
-
var
|
|
1367
|
+
var logger6 = getLogger("ArtifactService");
|
|
1369
1368
|
var _ArtifactService = class _ArtifactService {
|
|
1370
1369
|
constructor(context) {
|
|
1371
1370
|
this.context = context;
|
|
@@ -1397,7 +1396,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1397
1396
|
id: taskId
|
|
1398
1397
|
});
|
|
1399
1398
|
if (!task) {
|
|
1400
|
-
|
|
1399
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
1401
1400
|
continue;
|
|
1402
1401
|
}
|
|
1403
1402
|
const taskArtifacts = await getLedgerArtifacts(dbClient_default)({
|
|
@@ -1415,21 +1414,21 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1415
1414
|
}
|
|
1416
1415
|
}
|
|
1417
1416
|
} catch (error) {
|
|
1418
|
-
|
|
1417
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
1419
1418
|
}
|
|
1420
1419
|
return artifacts;
|
|
1421
1420
|
}
|
|
1422
1421
|
/**
|
|
1423
1422
|
* Create artifact from tool result and request data
|
|
1424
1423
|
*/
|
|
1425
|
-
async createArtifact(request,
|
|
1424
|
+
async createArtifact(request, subAgentId) {
|
|
1426
1425
|
if (!this.context.sessionId) {
|
|
1427
|
-
|
|
1426
|
+
logger6.warn({ request }, "No session ID available for artifact creation");
|
|
1428
1427
|
return null;
|
|
1429
1428
|
}
|
|
1430
1429
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
1431
1430
|
if (!toolResult) {
|
|
1432
|
-
|
|
1431
|
+
logger6.warn(
|
|
1433
1432
|
{ request, sessionId: this.context.sessionId },
|
|
1434
1433
|
"Tool result not found for artifact"
|
|
1435
1434
|
);
|
|
@@ -1445,7 +1444,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1445
1444
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
1446
1445
|
}
|
|
1447
1446
|
if (!selectedData) {
|
|
1448
|
-
|
|
1447
|
+
logger6.warn(
|
|
1449
1448
|
{
|
|
1450
1449
|
request,
|
|
1451
1450
|
baseSelector: request.baseSelector
|
|
@@ -1490,7 +1489,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1490
1489
|
type: request.type,
|
|
1491
1490
|
data: cleanedSummaryData
|
|
1492
1491
|
};
|
|
1493
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData,
|
|
1492
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
1494
1493
|
await this.cacheArtifact(
|
|
1495
1494
|
request.artifactId,
|
|
1496
1495
|
request.toolCallId,
|
|
@@ -1499,7 +1498,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1499
1498
|
);
|
|
1500
1499
|
return artifactData;
|
|
1501
1500
|
} catch (error) {
|
|
1502
|
-
|
|
1501
|
+
logger6.error({ error, request }, "Failed to create artifact");
|
|
1503
1502
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1504
1503
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
1505
1504
|
}
|
|
@@ -1528,7 +1527,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1528
1527
|
}
|
|
1529
1528
|
try {
|
|
1530
1529
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1531
|
-
|
|
1530
|
+
logger6.warn(
|
|
1532
1531
|
{ artifactId, toolCallId },
|
|
1533
1532
|
"No projectId or taskId available for artifact lookup"
|
|
1534
1533
|
);
|
|
@@ -1543,7 +1542,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1543
1542
|
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
1544
1543
|
}
|
|
1545
1544
|
} catch (error) {
|
|
1546
|
-
|
|
1545
|
+
logger6.warn(
|
|
1547
1546
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
1548
1547
|
"Failed to fetch artifact"
|
|
1549
1548
|
);
|
|
@@ -1574,7 +1573,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1574
1573
|
}
|
|
1575
1574
|
try {
|
|
1576
1575
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1577
|
-
|
|
1576
|
+
logger6.warn(
|
|
1578
1577
|
{ artifactId, toolCallId },
|
|
1579
1578
|
"No projectId or taskId available for artifact lookup"
|
|
1580
1579
|
);
|
|
@@ -1589,7 +1588,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1589
1588
|
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
1590
1589
|
}
|
|
1591
1590
|
} catch (error) {
|
|
1592
|
-
|
|
1591
|
+
logger6.warn(
|
|
1593
1592
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
1594
1593
|
"Failed to fetch artifact"
|
|
1595
1594
|
);
|
|
@@ -1625,8 +1624,8 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1625
1624
|
/**
|
|
1626
1625
|
* Persist artifact to database via graph session
|
|
1627
1626
|
*/
|
|
1628
|
-
async persistArtifact(request, summaryData, fullData,
|
|
1629
|
-
const effectiveAgentId =
|
|
1627
|
+
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
1628
|
+
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
1630
1629
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
1631
1630
|
await graphSessionManager.recordEvent(
|
|
1632
1631
|
this.context.streamRequestId,
|
|
@@ -1639,7 +1638,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1639
1638
|
artifactType: request.type,
|
|
1640
1639
|
summaryData,
|
|
1641
1640
|
data: fullData,
|
|
1642
|
-
|
|
1641
|
+
subAgentId: effectiveAgentId,
|
|
1643
1642
|
metadata: {
|
|
1644
1643
|
toolCallId: request.toolCallId,
|
|
1645
1644
|
baseSelector: request.baseSelector,
|
|
@@ -1654,14 +1653,14 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1654
1653
|
}
|
|
1655
1654
|
);
|
|
1656
1655
|
} else {
|
|
1657
|
-
|
|
1656
|
+
logger6.warn(
|
|
1658
1657
|
{
|
|
1659
1658
|
artifactId: request.artifactId,
|
|
1660
1659
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
1661
1660
|
hasAgentId: !!effectiveAgentId,
|
|
1662
1661
|
hasTaskId: !!this.context.taskId,
|
|
1663
|
-
passedAgentId:
|
|
1664
|
-
contextAgentId: this.context.
|
|
1662
|
+
passedAgentId: subAgentId,
|
|
1663
|
+
contextAgentId: this.context.subAgentId
|
|
1665
1664
|
},
|
|
1666
1665
|
"Skipping artifact_saved event - missing required context"
|
|
1667
1666
|
);
|
|
@@ -1729,7 +1728,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1729
1728
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
1730
1729
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
1731
1730
|
} catch (error) {
|
|
1732
|
-
|
|
1731
|
+
logger6.warn(
|
|
1733
1732
|
{
|
|
1734
1733
|
artifactType: artifact.type,
|
|
1735
1734
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1767,7 +1766,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1767
1766
|
artifact: artifactToSave
|
|
1768
1767
|
});
|
|
1769
1768
|
if (!result.created && result.existing) {
|
|
1770
|
-
|
|
1769
|
+
logger6.debug(
|
|
1771
1770
|
{
|
|
1772
1771
|
artifactId: artifact.artifactId,
|
|
1773
1772
|
taskId: this.context.taskId
|
|
@@ -1820,7 +1819,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1820
1819
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
1821
1820
|
}
|
|
1822
1821
|
} catch (error) {
|
|
1823
|
-
|
|
1822
|
+
logger6.warn(
|
|
1824
1823
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
1825
1824
|
"Failed to extract property"
|
|
1826
1825
|
);
|
|
@@ -1852,7 +1851,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1852
1851
|
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
1853
1852
|
}
|
|
1854
1853
|
} catch (error) {
|
|
1855
|
-
|
|
1854
|
+
logger6.warn(
|
|
1856
1855
|
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
1857
1856
|
"Failed to extract schema field"
|
|
1858
1857
|
);
|
|
@@ -1883,7 +1882,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
1883
1882
|
var ArtifactService = _ArtifactService;
|
|
1884
1883
|
|
|
1885
1884
|
// src/services/ArtifactParser.ts
|
|
1886
|
-
var
|
|
1885
|
+
var logger7 = getLogger("ArtifactParser");
|
|
1887
1886
|
var _ArtifactParser = class _ArtifactParser {
|
|
1888
1887
|
constructor(tenantId, options) {
|
|
1889
1888
|
__publicField(this, "artifactService");
|
|
@@ -1971,7 +1970,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
1971
1970
|
attrs[key] = value;
|
|
1972
1971
|
}
|
|
1973
1972
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
1974
|
-
|
|
1973
|
+
logger7.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
1975
1974
|
return null;
|
|
1976
1975
|
}
|
|
1977
1976
|
return {
|
|
@@ -2002,7 +2001,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2002
2001
|
/**
|
|
2003
2002
|
* Extract artifact data from a create annotation - delegates to service
|
|
2004
2003
|
*/
|
|
2005
|
-
async extractFromCreateAnnotation(annotation,
|
|
2004
|
+
async extractFromCreateAnnotation(annotation, subAgentId) {
|
|
2006
2005
|
const request = {
|
|
2007
2006
|
artifactId: annotation.artifactId,
|
|
2008
2007
|
toolCallId: annotation.toolCallId,
|
|
@@ -2010,21 +2009,21 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2010
2009
|
baseSelector: annotation.baseSelector,
|
|
2011
2010
|
detailsSelector: annotation.detailsSelector
|
|
2012
2011
|
};
|
|
2013
|
-
return this.artifactService.createArtifact(request,
|
|
2012
|
+
return this.artifactService.createArtifact(request, subAgentId);
|
|
2014
2013
|
}
|
|
2015
2014
|
/**
|
|
2016
2015
|
* Parse text with artifact markers into parts array
|
|
2017
2016
|
* Handles both artifact:ref and artifact:create tags
|
|
2018
2017
|
* Can work with or without pre-fetched artifact map
|
|
2019
2018
|
*/
|
|
2020
|
-
async parseText(text, artifactMap,
|
|
2019
|
+
async parseText(text, artifactMap, subAgentId) {
|
|
2021
2020
|
let processedText = text;
|
|
2022
2021
|
const createAnnotations = this.parseCreateAnnotations(text);
|
|
2023
2022
|
const createdArtifactData = /* @__PURE__ */ new Map();
|
|
2024
2023
|
const failedAnnotations = [];
|
|
2025
2024
|
for (const annotation of createAnnotations) {
|
|
2026
2025
|
try {
|
|
2027
|
-
const artifactData = await this.extractFromCreateAnnotation(annotation,
|
|
2026
|
+
const artifactData = await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
2028
2027
|
if (artifactData && annotation.raw) {
|
|
2029
2028
|
createdArtifactData.set(annotation.raw, artifactData);
|
|
2030
2029
|
} else if (annotation.raw) {
|
|
@@ -2032,7 +2031,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2032
2031
|
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
2033
2032
|
);
|
|
2034
2033
|
processedText = processedText.replace(annotation.raw, "");
|
|
2035
|
-
|
|
2034
|
+
logger7.warn(
|
|
2036
2035
|
{ annotation, artifactData },
|
|
2037
2036
|
"Removed failed artifact:create annotation from output"
|
|
2038
2037
|
);
|
|
@@ -2043,11 +2042,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2043
2042
|
if (annotation.raw) {
|
|
2044
2043
|
processedText = processedText.replace(annotation.raw, "");
|
|
2045
2044
|
}
|
|
2046
|
-
|
|
2045
|
+
logger7.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2047
2046
|
}
|
|
2048
2047
|
}
|
|
2049
2048
|
if (failedAnnotations.length > 0) {
|
|
2050
|
-
|
|
2049
|
+
logger7.warn(
|
|
2051
2050
|
{
|
|
2052
2051
|
failedCount: failedAnnotations.length,
|
|
2053
2052
|
failures: failedAnnotations
|
|
@@ -2111,7 +2110,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2111
2110
|
/**
|
|
2112
2111
|
* Process object/dataComponents for artifact components
|
|
2113
2112
|
*/
|
|
2114
|
-
async parseObject(obj, artifactMap,
|
|
2113
|
+
async parseObject(obj, artifactMap, subAgentId) {
|
|
2115
2114
|
if (obj?.dataComponents && Array.isArray(obj.dataComponents)) {
|
|
2116
2115
|
const parts = [];
|
|
2117
2116
|
for (const component of obj.dataComponents) {
|
|
@@ -2135,7 +2134,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2135
2134
|
});
|
|
2136
2135
|
}
|
|
2137
2136
|
} else if (this.isArtifactCreateComponent(component)) {
|
|
2138
|
-
const createData = await this.extractFromArtifactCreateComponent(component,
|
|
2137
|
+
const createData = await this.extractFromArtifactCreateComponent(component, subAgentId);
|
|
2139
2138
|
if (createData) {
|
|
2140
2139
|
parts.push({
|
|
2141
2140
|
kind: "data",
|
|
@@ -2176,7 +2175,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2176
2175
|
] : [];
|
|
2177
2176
|
}
|
|
2178
2177
|
if (this.isArtifactCreateComponent(obj)) {
|
|
2179
|
-
const createData = await this.extractFromArtifactCreateComponent(obj,
|
|
2178
|
+
const createData = await this.extractFromArtifactCreateComponent(obj, subAgentId);
|
|
2180
2179
|
return createData ? [
|
|
2181
2180
|
{
|
|
2182
2181
|
kind: "data",
|
|
@@ -2208,7 +2207,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2208
2207
|
/**
|
|
2209
2208
|
* Extract artifact from ArtifactCreate component
|
|
2210
2209
|
*/
|
|
2211
|
-
async extractFromArtifactCreateComponent(component,
|
|
2210
|
+
async extractFromArtifactCreateComponent(component, subAgentId) {
|
|
2212
2211
|
const props = component.props;
|
|
2213
2212
|
if (!props) {
|
|
2214
2213
|
return null;
|
|
@@ -2220,7 +2219,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2220
2219
|
baseSelector: props.base_selector,
|
|
2221
2220
|
detailsSelector: props.details_selector || {}
|
|
2222
2221
|
};
|
|
2223
|
-
return await this.extractFromCreateAnnotation(annotation,
|
|
2222
|
+
return await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
2224
2223
|
}
|
|
2225
2224
|
/**
|
|
2226
2225
|
* Get artifact data - delegates to service
|
|
@@ -2260,7 +2259,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
2260
2259
|
var ArtifactParser = _ArtifactParser;
|
|
2261
2260
|
|
|
2262
2261
|
// src/services/GraphSession.ts
|
|
2263
|
-
var
|
|
2262
|
+
var logger8 = getLogger("GraphSession");
|
|
2264
2263
|
var GraphSession = class {
|
|
2265
2264
|
// Whether to send data operations
|
|
2266
2265
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -2293,7 +2292,7 @@ var GraphSession = class {
|
|
|
2293
2292
|
__publicField(this, "artifactParser");
|
|
2294
2293
|
// Session-scoped ArtifactParser instance
|
|
2295
2294
|
__publicField(this, "isEmitOperations", false);
|
|
2296
|
-
|
|
2295
|
+
logger8.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
2297
2296
|
if (tenantId && projectId) {
|
|
2298
2297
|
toolSessionManager.createSessionWithId(
|
|
2299
2298
|
sessionId,
|
|
@@ -2307,7 +2306,6 @@ var GraphSession = class {
|
|
|
2307
2306
|
tenantId,
|
|
2308
2307
|
projectId,
|
|
2309
2308
|
sessionId,
|
|
2310
|
-
// Same ID as ToolSession
|
|
2311
2309
|
contextId,
|
|
2312
2310
|
taskId: `task_${contextId}-${messageId}`,
|
|
2313
2311
|
streamRequestId: sessionId
|
|
@@ -2328,7 +2326,7 @@ var GraphSession = class {
|
|
|
2328
2326
|
*/
|
|
2329
2327
|
enableEmitOperations() {
|
|
2330
2328
|
this.isEmitOperations = true;
|
|
2331
|
-
|
|
2329
|
+
logger8.info(
|
|
2332
2330
|
{ sessionId: this.sessionId },
|
|
2333
2331
|
"\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
|
|
2334
2332
|
);
|
|
@@ -2345,14 +2343,14 @@ var GraphSession = class {
|
|
|
2345
2343
|
label: this.generateEventLabel(event),
|
|
2346
2344
|
details: {
|
|
2347
2345
|
timestamp: event.timestamp,
|
|
2348
|
-
|
|
2346
|
+
subAgentId: event.subAgentId,
|
|
2349
2347
|
data: event.data
|
|
2350
2348
|
}
|
|
2351
2349
|
};
|
|
2352
2350
|
await streamHelper.writeOperation(formattedOperation);
|
|
2353
2351
|
}
|
|
2354
2352
|
} catch (error) {
|
|
2355
|
-
|
|
2353
|
+
logger8.error(
|
|
2356
2354
|
{
|
|
2357
2355
|
sessionId: this.sessionId,
|
|
2358
2356
|
eventType: event.eventType,
|
|
@@ -2368,29 +2366,19 @@ var GraphSession = class {
|
|
|
2368
2366
|
generateEventLabel(event) {
|
|
2369
2367
|
switch (event.eventType) {
|
|
2370
2368
|
case "agent_generate":
|
|
2371
|
-
return `Agent ${event.
|
|
2369
|
+
return `Agent ${event.subAgentId} generating response`;
|
|
2372
2370
|
case "agent_reasoning":
|
|
2373
|
-
return `Agent ${event.
|
|
2374
|
-
case "tool_execution":
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
case "
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
case "
|
|
2383
|
-
|
|
2384
|
-
return `Task delegated: ${delegationData.fromAgent} \u2192 ${delegationData.targetAgent}`;
|
|
2385
|
-
}
|
|
2386
|
-
case "delegation_returned": {
|
|
2387
|
-
const returnData = event.data;
|
|
2388
|
-
return `Task completed: ${returnData.targetAgent} \u2192 ${returnData.fromAgent}`;
|
|
2389
|
-
}
|
|
2390
|
-
case "artifact_saved": {
|
|
2391
|
-
const artifactData = event.data;
|
|
2392
|
-
return `Artifact saved: ${artifactData.artifactType || "unknown type"}`;
|
|
2393
|
-
}
|
|
2371
|
+
return `Agent ${event.subAgentId} reasoning through request`;
|
|
2372
|
+
case "tool_execution":
|
|
2373
|
+
return `Tool execution: ${event.data.toolName || "unknown"}`;
|
|
2374
|
+
case "transfer":
|
|
2375
|
+
return `Agent transfer: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
2376
|
+
case "delegation_sent":
|
|
2377
|
+
return `Task delegated: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
2378
|
+
case "delegation_returned":
|
|
2379
|
+
return `Task completed: ${event.data.targetSubAgent} \u2192 ${event.data.fromSubAgent}`;
|
|
2380
|
+
case "artifact_saved":
|
|
2381
|
+
return `Artifact saved: ${event.data.artifactType || "unknown type"}`;
|
|
2394
2382
|
default:
|
|
2395
2383
|
return `${event.eventType} event`;
|
|
2396
2384
|
}
|
|
@@ -2415,7 +2403,7 @@ var GraphSession = class {
|
|
|
2415
2403
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
2416
2404
|
this.statusUpdateTimer = setInterval(async () => {
|
|
2417
2405
|
if (!this.statusUpdateState || this.isEnded) {
|
|
2418
|
-
|
|
2406
|
+
logger8.debug(
|
|
2419
2407
|
{ sessionId: this.sessionId },
|
|
2420
2408
|
"Timer triggered but session already cleaned up or ended"
|
|
2421
2409
|
);
|
|
@@ -2427,7 +2415,7 @@ var GraphSession = class {
|
|
|
2427
2415
|
}
|
|
2428
2416
|
await this.checkAndSendTimeBasedUpdate();
|
|
2429
2417
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
2430
|
-
|
|
2418
|
+
logger8.info(
|
|
2431
2419
|
{
|
|
2432
2420
|
sessionId: this.sessionId,
|
|
2433
2421
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -2438,22 +2426,24 @@ var GraphSession = class {
|
|
|
2438
2426
|
}
|
|
2439
2427
|
/**
|
|
2440
2428
|
* Record an event in the session and trigger status updates if configured
|
|
2429
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
2441
2430
|
*/
|
|
2442
|
-
recordEvent(eventType,
|
|
2431
|
+
recordEvent(eventType, subAgentId, data) {
|
|
2443
2432
|
if (this.isEmitOperations) {
|
|
2444
|
-
|
|
2433
|
+
const dataOpEvent = {
|
|
2445
2434
|
timestamp: Date.now(),
|
|
2446
2435
|
eventType,
|
|
2447
|
-
|
|
2436
|
+
subAgentId,
|
|
2448
2437
|
data
|
|
2449
|
-
}
|
|
2438
|
+
};
|
|
2439
|
+
this.sendDataOperation(dataOpEvent);
|
|
2450
2440
|
}
|
|
2451
2441
|
if (this.isEnded) {
|
|
2452
|
-
|
|
2442
|
+
logger8.debug(
|
|
2453
2443
|
{
|
|
2454
2444
|
sessionId: this.sessionId,
|
|
2455
2445
|
eventType,
|
|
2456
|
-
|
|
2446
|
+
subAgentId
|
|
2457
2447
|
},
|
|
2458
2448
|
"Event received after session ended - ignoring"
|
|
2459
2449
|
);
|
|
@@ -2462,59 +2452,62 @@ var GraphSession = class {
|
|
|
2462
2452
|
const event = {
|
|
2463
2453
|
timestamp: Date.now(),
|
|
2464
2454
|
eventType,
|
|
2465
|
-
|
|
2455
|
+
subAgentId,
|
|
2466
2456
|
data
|
|
2467
2457
|
};
|
|
2468
2458
|
this.events.push(event);
|
|
2469
|
-
if (eventType === "artifact_saved"
|
|
2470
|
-
const
|
|
2471
|
-
if (
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
this.
|
|
2489
|
-
}).catch((error) => {
|
|
2490
|
-
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
2491
|
-
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2492
|
-
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2459
|
+
if (eventType === "artifact_saved") {
|
|
2460
|
+
const artifactData = data;
|
|
2461
|
+
if (artifactData.pendingGeneration) {
|
|
2462
|
+
const artifactId = artifactData.artifactId;
|
|
2463
|
+
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
2464
|
+
logger8.warn(
|
|
2465
|
+
{
|
|
2466
|
+
sessionId: this.sessionId,
|
|
2467
|
+
artifactId,
|
|
2468
|
+
pendingCount: this.pendingArtifacts.size,
|
|
2469
|
+
maxAllowed: this.MAX_PENDING_ARTIFACTS
|
|
2470
|
+
},
|
|
2471
|
+
"Too many pending artifacts, skipping processing"
|
|
2472
|
+
);
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
this.pendingArtifacts.add(artifactId);
|
|
2476
|
+
setImmediate(() => {
|
|
2477
|
+
const artifactDataWithAgent = { ...artifactData, subAgentId };
|
|
2478
|
+
this.processArtifact(artifactDataWithAgent).then(() => {
|
|
2493
2479
|
this.pendingArtifacts.delete(artifactId);
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2480
|
+
this.artifactProcessingErrors.delete(artifactId);
|
|
2481
|
+
}).catch((error) => {
|
|
2482
|
+
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
2483
|
+
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2484
|
+
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2485
|
+
this.pendingArtifacts.delete(artifactId);
|
|
2486
|
+
logger8.error(
|
|
2487
|
+
{
|
|
2488
|
+
sessionId: this.sessionId,
|
|
2489
|
+
artifactId,
|
|
2490
|
+
errorCount,
|
|
2491
|
+
maxRetries: this.MAX_ARTIFACT_RETRIES,
|
|
2492
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
2493
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
2494
|
+
},
|
|
2495
|
+
"Artifact processing failed after max retries, giving up"
|
|
2496
|
+
);
|
|
2497
|
+
} else {
|
|
2498
|
+
logger8.warn(
|
|
2499
|
+
{
|
|
2500
|
+
sessionId: this.sessionId,
|
|
2501
|
+
artifactId,
|
|
2502
|
+
errorCount,
|
|
2503
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2504
|
+
},
|
|
2505
|
+
"Artifact processing failed, may retry"
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
});
|
|
2516
2509
|
});
|
|
2517
|
-
}
|
|
2510
|
+
}
|
|
2518
2511
|
}
|
|
2519
2512
|
if (!this.isEnded) {
|
|
2520
2513
|
this.checkStatusUpdates();
|
|
@@ -2525,14 +2518,14 @@ var GraphSession = class {
|
|
|
2525
2518
|
*/
|
|
2526
2519
|
checkStatusUpdates() {
|
|
2527
2520
|
if (this.isEnded) {
|
|
2528
|
-
|
|
2521
|
+
logger8.debug(
|
|
2529
2522
|
{ sessionId: this.sessionId },
|
|
2530
2523
|
"Session has ended - skipping status update check"
|
|
2531
2524
|
);
|
|
2532
2525
|
return;
|
|
2533
2526
|
}
|
|
2534
2527
|
if (!this.statusUpdateState) {
|
|
2535
|
-
|
|
2528
|
+
logger8.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
2536
2529
|
return;
|
|
2537
2530
|
}
|
|
2538
2531
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -2543,11 +2536,11 @@ var GraphSession = class {
|
|
|
2543
2536
|
*/
|
|
2544
2537
|
async checkAndSendTimeBasedUpdate() {
|
|
2545
2538
|
if (this.isEnded) {
|
|
2546
|
-
|
|
2539
|
+
logger8.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
2547
2540
|
return;
|
|
2548
2541
|
}
|
|
2549
2542
|
if (!this.statusUpdateState) {
|
|
2550
|
-
|
|
2543
|
+
logger8.debug(
|
|
2551
2544
|
{ sessionId: this.sessionId },
|
|
2552
2545
|
"No status updates configured for time-based check"
|
|
2553
2546
|
);
|
|
@@ -2560,7 +2553,7 @@ var GraphSession = class {
|
|
|
2560
2553
|
try {
|
|
2561
2554
|
await this.generateAndSendUpdate();
|
|
2562
2555
|
} catch (error) {
|
|
2563
|
-
|
|
2556
|
+
logger8.error(
|
|
2564
2557
|
{
|
|
2565
2558
|
sessionId: this.sessionId,
|
|
2566
2559
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2584,8 +2577,8 @@ var GraphSession = class {
|
|
|
2584
2577
|
/**
|
|
2585
2578
|
* Get events filtered by agent
|
|
2586
2579
|
*/
|
|
2587
|
-
getEventsByAgent(
|
|
2588
|
-
return this.events.filter((event) => event.
|
|
2580
|
+
getEventsByAgent(subAgentId) {
|
|
2581
|
+
return this.events.filter((event) => event.subAgentId === subAgentId);
|
|
2589
2582
|
}
|
|
2590
2583
|
/**
|
|
2591
2584
|
* Get summary of session activity
|
|
@@ -2600,7 +2593,7 @@ var GraphSession = class {
|
|
|
2600
2593
|
);
|
|
2601
2594
|
const agentCounts = this.events.reduce(
|
|
2602
2595
|
(counts, event) => {
|
|
2603
|
-
counts[event.
|
|
2596
|
+
counts[event.subAgentId] = (counts[event.subAgentId] || 0) + 1;
|
|
2604
2597
|
return counts;
|
|
2605
2598
|
},
|
|
2606
2599
|
{}
|
|
@@ -2663,29 +2656,29 @@ var GraphSession = class {
|
|
|
2663
2656
|
*/
|
|
2664
2657
|
async generateAndSendUpdate() {
|
|
2665
2658
|
if (this.isEnded) {
|
|
2666
|
-
|
|
2659
|
+
logger8.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
2667
2660
|
return;
|
|
2668
2661
|
}
|
|
2669
2662
|
if (this.isTextStreaming) {
|
|
2670
|
-
|
|
2663
|
+
logger8.debug(
|
|
2671
2664
|
{ sessionId: this.sessionId },
|
|
2672
2665
|
"Text is currently streaming - skipping status update"
|
|
2673
2666
|
);
|
|
2674
2667
|
return;
|
|
2675
2668
|
}
|
|
2676
2669
|
if (this.isGeneratingUpdate) {
|
|
2677
|
-
|
|
2670
|
+
logger8.debug(
|
|
2678
2671
|
{ sessionId: this.sessionId },
|
|
2679
2672
|
"Update already in progress - skipping duplicate generation"
|
|
2680
2673
|
);
|
|
2681
2674
|
return;
|
|
2682
2675
|
}
|
|
2683
2676
|
if (!this.statusUpdateState) {
|
|
2684
|
-
|
|
2677
|
+
logger8.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
2685
2678
|
return;
|
|
2686
2679
|
}
|
|
2687
2680
|
if (!this.graphId) {
|
|
2688
|
-
|
|
2681
|
+
logger8.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
2689
2682
|
return;
|
|
2690
2683
|
}
|
|
2691
2684
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -2697,7 +2690,7 @@ var GraphSession = class {
|
|
|
2697
2690
|
try {
|
|
2698
2691
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
2699
2692
|
if (!streamHelper) {
|
|
2700
|
-
|
|
2693
|
+
logger8.warn(
|
|
2701
2694
|
{ sessionId: this.sessionId },
|
|
2702
2695
|
"No stream helper found - cannot send status update"
|
|
2703
2696
|
);
|
|
@@ -2717,7 +2710,7 @@ var GraphSession = class {
|
|
|
2717
2710
|
if (result.summaries && result.summaries.length > 0) {
|
|
2718
2711
|
for (const summary of result.summaries) {
|
|
2719
2712
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
2720
|
-
|
|
2713
|
+
logger8.warn(
|
|
2721
2714
|
{
|
|
2722
2715
|
sessionId: this.sessionId,
|
|
2723
2716
|
summary
|
|
@@ -2754,7 +2747,7 @@ var GraphSession = class {
|
|
|
2754
2747
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
2755
2748
|
}
|
|
2756
2749
|
} catch (error) {
|
|
2757
|
-
|
|
2750
|
+
logger8.error(
|
|
2758
2751
|
{
|
|
2759
2752
|
sessionId: this.sessionId,
|
|
2760
2753
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -2792,7 +2785,7 @@ var GraphSession = class {
|
|
|
2792
2785
|
this.releaseUpdateLock();
|
|
2793
2786
|
}
|
|
2794
2787
|
} catch (error) {
|
|
2795
|
-
|
|
2788
|
+
logger8.error(
|
|
2796
2789
|
{
|
|
2797
2790
|
sessionId: this.sessionId,
|
|
2798
2791
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2870,7 +2863,7 @@ User's Question/Context:
|
|
|
2870
2863
|
${conversationHistory}
|
|
2871
2864
|
` : "";
|
|
2872
2865
|
} catch (error) {
|
|
2873
|
-
|
|
2866
|
+
logger8.warn(
|
|
2874
2867
|
{ sessionId: this.sessionId, error },
|
|
2875
2868
|
"Failed to fetch conversation history for structured status update"
|
|
2876
2869
|
);
|
|
@@ -3004,7 +2997,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3004
2997
|
return { summaries };
|
|
3005
2998
|
} catch (error) {
|
|
3006
2999
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3007
|
-
|
|
3000
|
+
logger8.error({ error }, "Failed to generate structured update, using fallback");
|
|
3008
3001
|
return { summaries: [] };
|
|
3009
3002
|
} finally {
|
|
3010
3003
|
span.end();
|
|
@@ -3030,7 +3023,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3030
3023
|
*/
|
|
3031
3024
|
buildZodSchemaFromJson(jsonSchema) {
|
|
3032
3025
|
const properties = {};
|
|
3033
|
-
properties
|
|
3026
|
+
properties.label = z.string().describe(
|
|
3034
3027
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
3035
3028
|
);
|
|
3036
3029
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
@@ -3099,11 +3092,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3099
3092
|
for (const event of events) {
|
|
3100
3093
|
switch (event.eventType) {
|
|
3101
3094
|
case "tool_execution": {
|
|
3102
|
-
const
|
|
3103
|
-
const resultStr = JSON.stringify(data.result);
|
|
3095
|
+
const resultStr = JSON.stringify(event.data.result);
|
|
3104
3096
|
activities.push(
|
|
3105
|
-
`\u{1F527} **${data.toolName}** ${data.duration ? `(${data.duration}ms)` : ""}
|
|
3106
|
-
\u{1F4E5} Input: ${JSON.stringify(data.args)}
|
|
3097
|
+
`\u{1F527} **${event.data.toolName}** ${event.data.duration ? `(${event.data.duration}ms)` : ""}
|
|
3098
|
+
\u{1F4E5} Input: ${JSON.stringify(event.data.args)}
|
|
3107
3099
|
\u{1F4E4} Output: ${resultStr}`
|
|
3108
3100
|
);
|
|
3109
3101
|
break;
|
|
@@ -3115,23 +3107,24 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3115
3107
|
case "artifact_saved":
|
|
3116
3108
|
break;
|
|
3117
3109
|
case "agent_reasoning": {
|
|
3118
|
-
const data = event.data;
|
|
3119
3110
|
activities.push(
|
|
3120
3111
|
`\u2699\uFE0F **Analyzing request**
|
|
3121
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3112
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3122
3113
|
);
|
|
3123
3114
|
break;
|
|
3124
3115
|
}
|
|
3125
3116
|
case "agent_generate": {
|
|
3126
|
-
const data = event.data;
|
|
3127
3117
|
activities.push(
|
|
3128
3118
|
`\u2699\uFE0F **Preparing response**
|
|
3129
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3119
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3130
3120
|
);
|
|
3131
3121
|
break;
|
|
3132
3122
|
}
|
|
3133
3123
|
default: {
|
|
3134
|
-
|
|
3124
|
+
const safeEvent = event;
|
|
3125
|
+
activities.push(
|
|
3126
|
+
`\u{1F4CB} **${safeEvent.eventType}**: ${JSON.stringify(safeEvent.data, null, 2)}`
|
|
3127
|
+
);
|
|
3135
3128
|
break;
|
|
3136
3129
|
}
|
|
3137
3130
|
}
|
|
@@ -3149,7 +3142,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3149
3142
|
"graph_session.id": this.sessionId,
|
|
3150
3143
|
"artifact.id": artifactData.artifactId,
|
|
3151
3144
|
"artifact.type": artifactData.artifactType || "unknown",
|
|
3152
|
-
"artifact.agent_id": artifactData.
|
|
3145
|
+
"artifact.agent_id": artifactData.subAgentId || "unknown",
|
|
3153
3146
|
"artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
|
|
3154
3147
|
"artifact.data": JSON.stringify(artifactData.data, null, 2),
|
|
3155
3148
|
"tenant.id": artifactData.tenantId || "unknown",
|
|
@@ -3208,34 +3201,34 @@ Make it specific and relevant.`;
|
|
|
3208
3201
|
let modelToUse = this.statusUpdateState?.summarizerModel;
|
|
3209
3202
|
if (!modelToUse?.model?.trim()) {
|
|
3210
3203
|
if (!this.statusUpdateState?.baseModel?.model?.trim()) {
|
|
3211
|
-
if (artifactData.
|
|
3204
|
+
if (artifactData.subAgentId && artifactData.tenantId && artifactData.projectId) {
|
|
3212
3205
|
try {
|
|
3213
|
-
const agentData = await
|
|
3206
|
+
const agentData = await getSubAgentById(dbClient_default)({
|
|
3214
3207
|
scopes: {
|
|
3215
3208
|
tenantId: artifactData.tenantId,
|
|
3216
3209
|
projectId: artifactData.projectId,
|
|
3217
3210
|
graphId: this.graphId || ""
|
|
3218
3211
|
},
|
|
3219
|
-
|
|
3212
|
+
subAgentId: artifactData.subAgentId
|
|
3220
3213
|
});
|
|
3221
3214
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
3222
3215
|
modelToUse = agentData.models.base;
|
|
3223
|
-
|
|
3216
|
+
logger8.info(
|
|
3224
3217
|
{
|
|
3225
3218
|
sessionId: this.sessionId,
|
|
3226
3219
|
artifactId: artifactData.artifactId,
|
|
3227
|
-
|
|
3220
|
+
subAgentId: artifactData.subAgentId,
|
|
3228
3221
|
model: modelToUse.model
|
|
3229
3222
|
},
|
|
3230
3223
|
"Using agent model configuration for artifact name generation"
|
|
3231
3224
|
);
|
|
3232
3225
|
}
|
|
3233
3226
|
} catch (error) {
|
|
3234
|
-
|
|
3227
|
+
logger8.warn(
|
|
3235
3228
|
{
|
|
3236
3229
|
sessionId: this.sessionId,
|
|
3237
3230
|
artifactId: artifactData.artifactId,
|
|
3238
|
-
|
|
3231
|
+
subAgentId: artifactData.subAgentId,
|
|
3239
3232
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
3240
3233
|
},
|
|
3241
3234
|
"Failed to get agent model configuration"
|
|
@@ -3243,7 +3236,7 @@ Make it specific and relevant.`;
|
|
|
3243
3236
|
}
|
|
3244
3237
|
}
|
|
3245
3238
|
if (!modelToUse?.model?.trim()) {
|
|
3246
|
-
|
|
3239
|
+
logger8.warn(
|
|
3247
3240
|
{
|
|
3248
3241
|
sessionId: this.sessionId,
|
|
3249
3242
|
artifactId: artifactData.artifactId
|
|
@@ -3325,7 +3318,7 @@ Make it specific and relevant.`;
|
|
|
3325
3318
|
return result2;
|
|
3326
3319
|
} catch (error) {
|
|
3327
3320
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
3328
|
-
|
|
3321
|
+
logger8.warn(
|
|
3329
3322
|
{
|
|
3330
3323
|
sessionId: this.sessionId,
|
|
3331
3324
|
artifactId: artifactData.artifactId,
|
|
@@ -3377,7 +3370,7 @@ Make it specific and relevant.`;
|
|
|
3377
3370
|
});
|
|
3378
3371
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
3379
3372
|
} catch (saveError) {
|
|
3380
|
-
|
|
3373
|
+
logger8.error(
|
|
3381
3374
|
{
|
|
3382
3375
|
sessionId: this.sessionId,
|
|
3383
3376
|
artifactId: artifactData.artifactId,
|
|
@@ -3405,7 +3398,7 @@ Make it specific and relevant.`;
|
|
|
3405
3398
|
metadata: artifactData.metadata || {},
|
|
3406
3399
|
toolCallId: artifactData.toolCallId
|
|
3407
3400
|
});
|
|
3408
|
-
|
|
3401
|
+
logger8.info(
|
|
3409
3402
|
{
|
|
3410
3403
|
sessionId: this.sessionId,
|
|
3411
3404
|
artifactId: artifactData.artifactId
|
|
@@ -3416,7 +3409,7 @@ Make it specific and relevant.`;
|
|
|
3416
3409
|
} catch (fallbackError) {
|
|
3417
3410
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
3418
3411
|
if (isDuplicateError) ; else {
|
|
3419
|
-
|
|
3412
|
+
logger8.error(
|
|
3420
3413
|
{
|
|
3421
3414
|
sessionId: this.sessionId,
|
|
3422
3415
|
artifactId: artifactData.artifactId,
|
|
@@ -3429,7 +3422,7 @@ Make it specific and relevant.`;
|
|
|
3429
3422
|
}
|
|
3430
3423
|
} catch (error) {
|
|
3431
3424
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3432
|
-
|
|
3425
|
+
logger8.error(
|
|
3433
3426
|
{
|
|
3434
3427
|
sessionId: this.sessionId,
|
|
3435
3428
|
artifactId: artifactData.artifactId,
|
|
@@ -3448,7 +3441,7 @@ Make it specific and relevant.`;
|
|
|
3448
3441
|
*/
|
|
3449
3442
|
setArtifactCache(key, artifact) {
|
|
3450
3443
|
this.artifactCache.set(key, artifact);
|
|
3451
|
-
|
|
3444
|
+
logger8.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
3452
3445
|
}
|
|
3453
3446
|
/**
|
|
3454
3447
|
* Get session-scoped ArtifactService instance
|
|
@@ -3467,7 +3460,7 @@ Make it specific and relevant.`;
|
|
|
3467
3460
|
*/
|
|
3468
3461
|
getArtifactCache(key) {
|
|
3469
3462
|
const artifact = this.artifactCache.get(key);
|
|
3470
|
-
|
|
3463
|
+
logger8.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
3471
3464
|
return artifact || null;
|
|
3472
3465
|
}
|
|
3473
3466
|
/**
|
|
@@ -3490,7 +3483,7 @@ var GraphSessionManager = class {
|
|
|
3490
3483
|
const sessionId = messageId;
|
|
3491
3484
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
3492
3485
|
this.sessions.set(sessionId, session);
|
|
3493
|
-
|
|
3486
|
+
logger8.info(
|
|
3494
3487
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
3495
3488
|
"GraphSession created"
|
|
3496
3489
|
);
|
|
@@ -3504,7 +3497,7 @@ var GraphSessionManager = class {
|
|
|
3504
3497
|
if (session) {
|
|
3505
3498
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
3506
3499
|
} else {
|
|
3507
|
-
|
|
3500
|
+
logger8.error(
|
|
3508
3501
|
{
|
|
3509
3502
|
sessionId,
|
|
3510
3503
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3521,7 +3514,7 @@ var GraphSessionManager = class {
|
|
|
3521
3514
|
if (session) {
|
|
3522
3515
|
session.enableEmitOperations();
|
|
3523
3516
|
} else {
|
|
3524
|
-
|
|
3517
|
+
logger8.error(
|
|
3525
3518
|
{
|
|
3526
3519
|
sessionId,
|
|
3527
3520
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3538,14 +3531,15 @@ var GraphSessionManager = class {
|
|
|
3538
3531
|
}
|
|
3539
3532
|
/**
|
|
3540
3533
|
* Record an event in a session
|
|
3534
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
3541
3535
|
*/
|
|
3542
|
-
recordEvent(sessionId, eventType,
|
|
3536
|
+
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
3543
3537
|
const session = this.sessions.get(sessionId);
|
|
3544
3538
|
if (!session) {
|
|
3545
|
-
|
|
3539
|
+
logger8.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
3546
3540
|
return;
|
|
3547
3541
|
}
|
|
3548
|
-
session.recordEvent(eventType,
|
|
3542
|
+
session.recordEvent(eventType, subAgentId, data);
|
|
3549
3543
|
}
|
|
3550
3544
|
/**
|
|
3551
3545
|
* End a session and return the final event data
|
|
@@ -3553,12 +3547,12 @@ var GraphSessionManager = class {
|
|
|
3553
3547
|
endSession(sessionId) {
|
|
3554
3548
|
const session = this.sessions.get(sessionId);
|
|
3555
3549
|
if (!session) {
|
|
3556
|
-
|
|
3550
|
+
logger8.warn({ sessionId }, "Attempted to end non-existent session");
|
|
3557
3551
|
return [];
|
|
3558
3552
|
}
|
|
3559
3553
|
const events = session.getEvents();
|
|
3560
3554
|
const summary = session.getSummary();
|
|
3561
|
-
|
|
3555
|
+
logger8.info({ sessionId, summary }, "GraphSession ended");
|
|
3562
3556
|
session.cleanup();
|
|
3563
3557
|
this.sessions.delete(sessionId);
|
|
3564
3558
|
return events;
|
|
@@ -3657,7 +3651,7 @@ async function resolveModelConfig(graphId, agent) {
|
|
|
3657
3651
|
}
|
|
3658
3652
|
|
|
3659
3653
|
// src/services/IncrementalStreamParser.ts
|
|
3660
|
-
var
|
|
3654
|
+
var logger9 = getLogger("IncrementalStreamParser");
|
|
3661
3655
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
3662
3656
|
// Max number of collected parts to prevent unbounded growth
|
|
3663
3657
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -3673,10 +3667,10 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3673
3667
|
__publicField(this, "lastStreamedComponents", /* @__PURE__ */ new Map());
|
|
3674
3668
|
__publicField(this, "componentSnapshots", /* @__PURE__ */ new Map());
|
|
3675
3669
|
__publicField(this, "artifactMap");
|
|
3676
|
-
__publicField(this, "
|
|
3670
|
+
__publicField(this, "subAgentId");
|
|
3677
3671
|
this.streamHelper = streamHelper;
|
|
3678
3672
|
this.contextId = contextId;
|
|
3679
|
-
this.
|
|
3673
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
3680
3674
|
if (artifactParserOptions?.streamRequestId) {
|
|
3681
3675
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
3682
3676
|
artifactParserOptions.streamRequestId
|
|
@@ -3709,7 +3703,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3709
3703
|
async initializeArtifactMap() {
|
|
3710
3704
|
try {
|
|
3711
3705
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
3712
|
-
|
|
3706
|
+
logger9.debug(
|
|
3713
3707
|
{
|
|
3714
3708
|
contextId: this.contextId,
|
|
3715
3709
|
artifactMapSize: this.artifactMap.size
|
|
@@ -3717,7 +3711,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3717
3711
|
"Initialized artifact map for streaming"
|
|
3718
3712
|
);
|
|
3719
3713
|
} catch (error) {
|
|
3720
|
-
|
|
3714
|
+
logger9.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
3721
3715
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
3722
3716
|
}
|
|
3723
3717
|
}
|
|
@@ -3819,7 +3813,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3819
3813
|
dataComponents: [component]
|
|
3820
3814
|
},
|
|
3821
3815
|
this.artifactMap,
|
|
3822
|
-
this.
|
|
3816
|
+
this.subAgentId
|
|
3823
3817
|
);
|
|
3824
3818
|
if (!Array.isArray(parts)) {
|
|
3825
3819
|
console.warn("parseObject returned non-array:", parts);
|
|
@@ -3895,7 +3889,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3895
3889
|
dataComponents: [component]
|
|
3896
3890
|
},
|
|
3897
3891
|
this.artifactMap,
|
|
3898
|
-
this.
|
|
3892
|
+
this.subAgentId
|
|
3899
3893
|
);
|
|
3900
3894
|
for (const part of parts) {
|
|
3901
3895
|
await this.streamPart(part);
|
|
@@ -3949,7 +3943,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3949
3943
|
const safeEnd = this.artifactParser.findSafeTextBoundary(workingBuffer);
|
|
3950
3944
|
if (safeEnd > 0) {
|
|
3951
3945
|
const safeText = workingBuffer.slice(0, safeEnd);
|
|
3952
|
-
const parts2 = await this.artifactParser.parseText(
|
|
3946
|
+
const parts2 = await this.artifactParser.parseText(
|
|
3947
|
+
safeText,
|
|
3948
|
+
this.artifactMap,
|
|
3949
|
+
this.subAgentId
|
|
3950
|
+
);
|
|
3953
3951
|
completeParts.push(...parts2);
|
|
3954
3952
|
return {
|
|
3955
3953
|
completeParts,
|
|
@@ -3964,7 +3962,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3964
3962
|
const parts = await this.artifactParser.parseText(
|
|
3965
3963
|
workingBuffer,
|
|
3966
3964
|
this.artifactMap,
|
|
3967
|
-
this.
|
|
3965
|
+
this.subAgentId
|
|
3968
3966
|
);
|
|
3969
3967
|
if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
|
|
3970
3968
|
const lastPart = parts[parts.length - 1];
|
|
@@ -4037,12 +4035,12 @@ __publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", 1e4);
|
|
|
4037
4035
|
var IncrementalStreamParser = _IncrementalStreamParser;
|
|
4038
4036
|
|
|
4039
4037
|
// src/services/ResponseFormatter.ts
|
|
4040
|
-
var
|
|
4038
|
+
var logger10 = getLogger("ResponseFormatter");
|
|
4041
4039
|
var ResponseFormatter = class {
|
|
4042
4040
|
constructor(tenantId, artifactParserOptions) {
|
|
4043
4041
|
__publicField(this, "artifactParser");
|
|
4044
|
-
__publicField(this, "
|
|
4045
|
-
this.
|
|
4042
|
+
__publicField(this, "subAgentId");
|
|
4043
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4046
4044
|
if (artifactParserOptions?.streamRequestId) {
|
|
4047
4045
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4048
4046
|
artifactParserOptions.streamRequestId
|
|
@@ -4081,7 +4079,7 @@ var ResponseFormatter = class {
|
|
|
4081
4079
|
const parts = await this.artifactParser.parseObject(
|
|
4082
4080
|
responseObject,
|
|
4083
4081
|
artifactMap,
|
|
4084
|
-
this.
|
|
4082
|
+
this.subAgentId
|
|
4085
4083
|
);
|
|
4086
4084
|
const uniqueArtifacts = this.countUniqueArtifacts(parts);
|
|
4087
4085
|
span.setAttributes({
|
|
@@ -4096,7 +4094,7 @@ var ResponseFormatter = class {
|
|
|
4096
4094
|
return { parts };
|
|
4097
4095
|
} catch (error) {
|
|
4098
4096
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4099
|
-
|
|
4097
|
+
logger10.error({ error, responseObject }, "Error formatting object response");
|
|
4100
4098
|
return {
|
|
4101
4099
|
parts: [{ kind: "data", data: responseObject }]
|
|
4102
4100
|
};
|
|
@@ -4128,7 +4126,11 @@ var ResponseFormatter = class {
|
|
|
4128
4126
|
"response.type": "text",
|
|
4129
4127
|
"response.availableArtifacts": artifactMap.size
|
|
4130
4128
|
});
|
|
4131
|
-
const parts = await this.artifactParser.parseText(
|
|
4129
|
+
const parts = await this.artifactParser.parseText(
|
|
4130
|
+
responseText,
|
|
4131
|
+
artifactMap,
|
|
4132
|
+
this.subAgentId
|
|
4133
|
+
);
|
|
4132
4134
|
if (parts.length === 1 && parts[0].kind === "text") {
|
|
4133
4135
|
return { text: parts[0].text };
|
|
4134
4136
|
}
|
|
@@ -4148,7 +4150,7 @@ var ResponseFormatter = class {
|
|
|
4148
4150
|
return { parts };
|
|
4149
4151
|
} catch (error) {
|
|
4150
4152
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4151
|
-
|
|
4153
|
+
logger10.error({ error, responseText }, "Error formatting response");
|
|
4152
4154
|
return { text: responseText };
|
|
4153
4155
|
} finally {
|
|
4154
4156
|
span.end();
|
|
@@ -4202,20 +4204,20 @@ function agentInitializingOp(sessionId, graphId) {
|
|
|
4202
4204
|
}
|
|
4203
4205
|
};
|
|
4204
4206
|
}
|
|
4205
|
-
function completionOp(
|
|
4207
|
+
function completionOp(subAgentId, iterations) {
|
|
4206
4208
|
return {
|
|
4207
4209
|
type: "completion",
|
|
4208
4210
|
details: {
|
|
4209
|
-
agent:
|
|
4211
|
+
agent: subAgentId,
|
|
4210
4212
|
iteration: iterations
|
|
4211
4213
|
}
|
|
4212
4214
|
};
|
|
4213
4215
|
}
|
|
4214
|
-
function errorOp(message,
|
|
4216
|
+
function errorOp(message, subAgentId, severity = "error", code) {
|
|
4215
4217
|
return {
|
|
4216
4218
|
type: "error",
|
|
4217
4219
|
message,
|
|
4218
|
-
agent:
|
|
4220
|
+
agent: subAgentId,
|
|
4219
4221
|
severity,
|
|
4220
4222
|
code,
|
|
4221
4223
|
timestamp: Date.now()
|
|
@@ -4224,10 +4226,10 @@ function errorOp(message, agentId, severity = "error", code) {
|
|
|
4224
4226
|
function generateToolId() {
|
|
4225
4227
|
return `tool_${nanoid(8)}`;
|
|
4226
4228
|
}
|
|
4227
|
-
var
|
|
4229
|
+
var logger11 = getLogger("DataComponentSchema");
|
|
4228
4230
|
function jsonSchemaToZod(jsonSchema) {
|
|
4229
4231
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
4230
|
-
|
|
4232
|
+
logger11.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
4231
4233
|
return z.string();
|
|
4232
4234
|
}
|
|
4233
4235
|
switch (jsonSchema.type) {
|
|
@@ -4254,7 +4256,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
4254
4256
|
case "null":
|
|
4255
4257
|
return z.null();
|
|
4256
4258
|
default:
|
|
4257
|
-
|
|
4259
|
+
logger11.warn(
|
|
4258
4260
|
{
|
|
4259
4261
|
unsupportedType: jsonSchema.type,
|
|
4260
4262
|
schema: jsonSchema
|
|
@@ -4617,7 +4619,7 @@ function parseEmbeddedJson(data) {
|
|
|
4617
4619
|
}
|
|
4618
4620
|
|
|
4619
4621
|
// src/a2a/client.ts
|
|
4620
|
-
var
|
|
4622
|
+
var logger12 = getLogger("a2aClient");
|
|
4621
4623
|
var DEFAULT_BACKOFF = {
|
|
4622
4624
|
initialInterval: 500,
|
|
4623
4625
|
maxInterval: 6e4,
|
|
@@ -4823,7 +4825,7 @@ var A2AClient = class {
|
|
|
4823
4825
|
try {
|
|
4824
4826
|
const res = await fn();
|
|
4825
4827
|
if (attempt > 0) {
|
|
4826
|
-
|
|
4828
|
+
logger12.info(
|
|
4827
4829
|
{
|
|
4828
4830
|
attempts: attempt + 1,
|
|
4829
4831
|
elapsedTime: Date.now() - start
|
|
@@ -4838,7 +4840,7 @@ var A2AClient = class {
|
|
|
4838
4840
|
}
|
|
4839
4841
|
const elapsed = Date.now() - start;
|
|
4840
4842
|
if (elapsed > maxElapsedTime) {
|
|
4841
|
-
|
|
4843
|
+
logger12.warn(
|
|
4842
4844
|
{
|
|
4843
4845
|
attempts: attempt + 1,
|
|
4844
4846
|
elapsedTime: elapsed,
|
|
@@ -4859,7 +4861,7 @@ var A2AClient = class {
|
|
|
4859
4861
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4860
4862
|
}
|
|
4861
4863
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4862
|
-
|
|
4864
|
+
logger12.info(
|
|
4863
4865
|
{
|
|
4864
4866
|
attempt: attempt + 1,
|
|
4865
4867
|
delayMs,
|
|
@@ -4944,7 +4946,7 @@ var A2AClient = class {
|
|
|
4944
4946
|
}
|
|
4945
4947
|
const rpcResponse = await httpResponse.json();
|
|
4946
4948
|
if (rpcResponse.id !== requestId2) {
|
|
4947
|
-
|
|
4949
|
+
logger12.warn(
|
|
4948
4950
|
{
|
|
4949
4951
|
method,
|
|
4950
4952
|
expectedId: requestId2,
|
|
@@ -5143,7 +5145,7 @@ var A2AClient = class {
|
|
|
5143
5145
|
try {
|
|
5144
5146
|
while (true) {
|
|
5145
5147
|
const { done, value } = await reader.read();
|
|
5146
|
-
|
|
5148
|
+
logger12.info({ done, value }, "parseA2ASseStream");
|
|
5147
5149
|
if (done) {
|
|
5148
5150
|
if (eventDataBuffer.trim()) {
|
|
5149
5151
|
const result = this._processSseEventData(
|
|
@@ -5230,7 +5232,7 @@ var A2AClient = class {
|
|
|
5230
5232
|
};
|
|
5231
5233
|
|
|
5232
5234
|
// src/agents/relationTools.ts
|
|
5233
|
-
var
|
|
5235
|
+
var logger13 = getLogger("relationships Tools");
|
|
5234
5236
|
var generateTransferToolDescription = (config) => {
|
|
5235
5237
|
return `Hand off the conversation to agent ${config.id}.
|
|
5236
5238
|
|
|
@@ -5254,7 +5256,7 @@ Delegate a specific task to agent ${config.id} when it seems like the agent can
|
|
|
5254
5256
|
var createTransferToAgentTool = ({
|
|
5255
5257
|
transferConfig,
|
|
5256
5258
|
callingAgentId,
|
|
5257
|
-
|
|
5259
|
+
subAgent,
|
|
5258
5260
|
streamRequestId
|
|
5259
5261
|
}) => {
|
|
5260
5262
|
return tool({
|
|
@@ -5264,11 +5266,11 @@ var createTransferToAgentTool = ({
|
|
|
5264
5266
|
const activeSpan = trace.getActiveSpan();
|
|
5265
5267
|
if (activeSpan) {
|
|
5266
5268
|
activeSpan.setAttributes({
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
+
[SPAN_KEYS.TRANSFER_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
5270
|
+
[SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
5269
5271
|
});
|
|
5270
5272
|
}
|
|
5271
|
-
|
|
5273
|
+
logger13.info(
|
|
5272
5274
|
{
|
|
5273
5275
|
transferTo: transferConfig.id ?? "unknown",
|
|
5274
5276
|
fromAgent: callingAgentId
|
|
@@ -5277,8 +5279,8 @@ var createTransferToAgentTool = ({
|
|
|
5277
5279
|
);
|
|
5278
5280
|
if (streamRequestId) {
|
|
5279
5281
|
graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
+
fromSubAgent: callingAgentId,
|
|
5283
|
+
targetSubAgent: transferConfig.id ?? "unknown",
|
|
5282
5284
|
reason: `Transfer to ${transferConfig.name || transferConfig.id}`
|
|
5283
5285
|
});
|
|
5284
5286
|
}
|
|
@@ -5300,7 +5302,7 @@ function createDelegateToAgentTool({
|
|
|
5300
5302
|
contextId,
|
|
5301
5303
|
metadata,
|
|
5302
5304
|
sessionId,
|
|
5303
|
-
|
|
5305
|
+
subAgent,
|
|
5304
5306
|
credentialStoreRegistry
|
|
5305
5307
|
}) {
|
|
5306
5308
|
return tool({
|
|
@@ -5311,9 +5313,9 @@ function createDelegateToAgentTool({
|
|
|
5311
5313
|
const activeSpan = trace.getActiveSpan();
|
|
5312
5314
|
if (activeSpan) {
|
|
5313
5315
|
activeSpan.setAttributes({
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5316
|
+
[SPAN_KEYS.DELEGATION_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
5317
|
+
[SPAN_KEYS.DELEGATION_TO_SUB_AGENT_ID]: delegateConfig.config.id ?? "unknown",
|
|
5318
|
+
[SPAN_KEYS.DELEGATION_ID]: delegationId
|
|
5317
5319
|
});
|
|
5318
5320
|
}
|
|
5319
5321
|
if (metadata.streamRequestId) {
|
|
@@ -5323,8 +5325,8 @@ function createDelegateToAgentTool({
|
|
|
5323
5325
|
callingAgentId,
|
|
5324
5326
|
{
|
|
5325
5327
|
delegationId,
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
+
fromSubAgent: callingAgentId,
|
|
5329
|
+
targetSubAgent: delegateConfig.config.id,
|
|
5328
5330
|
taskDescription: input.message
|
|
5329
5331
|
}
|
|
5330
5332
|
);
|
|
@@ -5338,7 +5340,7 @@ function createDelegateToAgentTool({
|
|
|
5338
5340
|
projectId,
|
|
5339
5341
|
graphId
|
|
5340
5342
|
},
|
|
5341
|
-
|
|
5343
|
+
subAgentId: delegateConfig.config.id
|
|
5342
5344
|
});
|
|
5343
5345
|
if (externalAgent && (externalAgent.credentialReferenceId || externalAgent.headers) && credentialStoreRegistry) {
|
|
5344
5346
|
const contextResolver = new ContextResolver(
|
|
@@ -5417,7 +5419,7 @@ function createDelegateToAgentTool({
|
|
|
5417
5419
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
5418
5420
|
}
|
|
5419
5421
|
};
|
|
5420
|
-
|
|
5422
|
+
logger13.info({ messageToSend }, "messageToSend");
|
|
5421
5423
|
await createMessage(dbClient_default)({
|
|
5422
5424
|
id: nanoid(),
|
|
5423
5425
|
tenantId,
|
|
@@ -5429,7 +5431,7 @@ function createDelegateToAgentTool({
|
|
|
5429
5431
|
},
|
|
5430
5432
|
visibility: isInternal ? "internal" : "external",
|
|
5431
5433
|
messageType: "a2a-request",
|
|
5432
|
-
|
|
5434
|
+
fromSubAgentId: callingAgentId,
|
|
5433
5435
|
...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
|
|
5434
5436
|
});
|
|
5435
5437
|
const response = await a2aClient.sendMessage({
|
|
@@ -5444,8 +5446,8 @@ function createDelegateToAgentTool({
|
|
|
5444
5446
|
conversationId: contextId,
|
|
5445
5447
|
messageType: "a2a-response",
|
|
5446
5448
|
visibility: isInternal ? "internal" : "external",
|
|
5447
|
-
|
|
5448
|
-
...isInternal ? {
|
|
5449
|
+
toSubAgentId: callingAgentId,
|
|
5450
|
+
...isInternal ? { fromSubAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
|
|
5449
5451
|
});
|
|
5450
5452
|
if (sessionId && context?.toolCallId) {
|
|
5451
5453
|
const toolResult = {
|
|
@@ -5464,8 +5466,8 @@ function createDelegateToAgentTool({
|
|
|
5464
5466
|
callingAgentId,
|
|
5465
5467
|
{
|
|
5466
5468
|
delegationId,
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
+
fromSubAgent: delegateConfig.config.id,
|
|
5470
|
+
targetSubAgent: callingAgentId,
|
|
5469
5471
|
result: response.result
|
|
5470
5472
|
}
|
|
5471
5473
|
);
|
|
@@ -5479,7 +5481,7 @@ function createDelegateToAgentTool({
|
|
|
5479
5481
|
}
|
|
5480
5482
|
|
|
5481
5483
|
// src/agents/SystemPromptBuilder.ts
|
|
5482
|
-
var
|
|
5484
|
+
var logger14 = getLogger("SystemPromptBuilder");
|
|
5483
5485
|
var SystemPromptBuilder = class {
|
|
5484
5486
|
constructor(version, versionConfig) {
|
|
5485
5487
|
this.version = version;
|
|
@@ -5495,12 +5497,12 @@ var SystemPromptBuilder = class {
|
|
|
5495
5497
|
this.templates.set(name, content);
|
|
5496
5498
|
}
|
|
5497
5499
|
this.loaded = true;
|
|
5498
|
-
|
|
5500
|
+
logger14.debug(
|
|
5499
5501
|
{ templateCount: this.templates.size, version: this.version },
|
|
5500
5502
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
5501
5503
|
);
|
|
5502
5504
|
} catch (error) {
|
|
5503
|
-
|
|
5505
|
+
logger14.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
5504
5506
|
throw new Error(`Template loading failed: ${error}`);
|
|
5505
5507
|
}
|
|
5506
5508
|
}
|
|
@@ -6560,7 +6562,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6560
6562
|
return false;
|
|
6561
6563
|
};
|
|
6562
6564
|
}
|
|
6563
|
-
var
|
|
6565
|
+
var logger16 = getLogger("Agent");
|
|
6564
6566
|
var CONSTANTS = {
|
|
6565
6567
|
MAX_GENERATION_STEPS: 12,
|
|
6566
6568
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -6790,7 +6792,7 @@ var Agent = class {
|
|
|
6790
6792
|
}
|
|
6791
6793
|
getRelationTools(runtimeContext, sessionId) {
|
|
6792
6794
|
const { transferRelations = [], delegateRelations = [] } = this.config;
|
|
6793
|
-
const createToolName = (prefix,
|
|
6795
|
+
const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
|
|
6794
6796
|
return Object.fromEntries([
|
|
6795
6797
|
...transferRelations.map((agentConfig) => {
|
|
6796
6798
|
const toolName = createToolName("transfer", agentConfig.id);
|
|
@@ -6801,7 +6803,7 @@ var Agent = class {
|
|
|
6801
6803
|
createTransferToAgentTool({
|
|
6802
6804
|
transferConfig: agentConfig,
|
|
6803
6805
|
callingAgentId: this.config.id,
|
|
6804
|
-
|
|
6806
|
+
subAgent: this,
|
|
6805
6807
|
streamRequestId: runtimeContext?.metadata?.streamRequestId
|
|
6806
6808
|
}),
|
|
6807
6809
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -6830,7 +6832,7 @@ var Agent = class {
|
|
|
6830
6832
|
apiKey: runtimeContext?.metadata?.apiKey
|
|
6831
6833
|
},
|
|
6832
6834
|
sessionId,
|
|
6833
|
-
|
|
6835
|
+
subAgent: this,
|
|
6834
6836
|
credentialStoreRegistry: this.credentialStoreRegistry
|
|
6835
6837
|
}),
|
|
6836
6838
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -6864,14 +6866,14 @@ var Agent = class {
|
|
|
6864
6866
|
for (const toolSet of tools) {
|
|
6865
6867
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
6866
6868
|
if (!isValidTool(originalTool)) {
|
|
6867
|
-
|
|
6869
|
+
logger16.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
6868
6870
|
continue;
|
|
6869
6871
|
}
|
|
6870
6872
|
const sessionWrappedTool = tool({
|
|
6871
6873
|
description: originalTool.description,
|
|
6872
6874
|
inputSchema: originalTool.inputSchema,
|
|
6873
6875
|
execute: async (args, { toolCallId }) => {
|
|
6874
|
-
|
|
6876
|
+
logger16.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
6875
6877
|
try {
|
|
6876
6878
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
6877
6879
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -6885,7 +6887,7 @@ var Agent = class {
|
|
|
6885
6887
|
});
|
|
6886
6888
|
return { result: enhancedResult, toolCallId };
|
|
6887
6889
|
} catch (error) {
|
|
6888
|
-
|
|
6890
|
+
logger16.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
6889
6891
|
throw error;
|
|
6890
6892
|
}
|
|
6891
6893
|
}
|
|
@@ -6930,7 +6932,7 @@ var Agent = class {
|
|
|
6930
6932
|
tenantId: this.config.tenantId,
|
|
6931
6933
|
projectId: this.config.projectId,
|
|
6932
6934
|
graphId: this.config.graphId,
|
|
6933
|
-
|
|
6935
|
+
subAgentId: this.config.id
|
|
6934
6936
|
}
|
|
6935
6937
|
});
|
|
6936
6938
|
const agentToolRelationHeaders = toolsForAgent.data.find((t) => t.toolId === tool3.id)?.headers || void 0;
|
|
@@ -6986,7 +6988,7 @@ var Agent = class {
|
|
|
6986
6988
|
headers: agentToolRelationHeaders
|
|
6987
6989
|
};
|
|
6988
6990
|
}
|
|
6989
|
-
|
|
6991
|
+
logger16.info(
|
|
6990
6992
|
{
|
|
6991
6993
|
toolName: tool3.name,
|
|
6992
6994
|
credentialReferenceId,
|
|
@@ -7011,10 +7013,10 @@ var Agent = class {
|
|
|
7011
7013
|
this.mcpClientCache.set(cacheKey, client);
|
|
7012
7014
|
} catch (error) {
|
|
7013
7015
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7014
|
-
|
|
7016
|
+
logger16.error(
|
|
7015
7017
|
{
|
|
7016
7018
|
toolName: tool3.name,
|
|
7017
|
-
|
|
7019
|
+
subAgentId: this.config.id,
|
|
7018
7020
|
cacheKey,
|
|
7019
7021
|
error: error instanceof Error ? error.message : String(error)
|
|
7020
7022
|
},
|
|
@@ -7035,10 +7037,10 @@ var Agent = class {
|
|
|
7035
7037
|
await client.connect();
|
|
7036
7038
|
return client;
|
|
7037
7039
|
} catch (error) {
|
|
7038
|
-
|
|
7040
|
+
logger16.error(
|
|
7039
7041
|
{
|
|
7040
7042
|
toolName: tool3.name,
|
|
7041
|
-
|
|
7043
|
+
subAgentId: this.config.id,
|
|
7042
7044
|
error: error instanceof Error ? error.message : String(error)
|
|
7043
7045
|
},
|
|
7044
7046
|
"Agent failed to connect to MCP server"
|
|
@@ -7054,7 +7056,7 @@ var Agent = class {
|
|
|
7054
7056
|
tenantId: this.config.tenantId || "default",
|
|
7055
7057
|
projectId: this.config.projectId || "default",
|
|
7056
7058
|
graphId: this.config.graphId,
|
|
7057
|
-
|
|
7059
|
+
subAgentId: this.config.id
|
|
7058
7060
|
}
|
|
7059
7061
|
});
|
|
7060
7062
|
const toolsData = toolsForAgent.data || [];
|
|
@@ -7068,7 +7070,7 @@ var Agent = class {
|
|
|
7068
7070
|
if (toolDef.tool.config?.type === "function") {
|
|
7069
7071
|
const functionId = toolDef.tool.functionId;
|
|
7070
7072
|
if (!functionId) {
|
|
7071
|
-
|
|
7073
|
+
logger16.warn({ toolId: toolDef.tool.id }, "Function tool missing functionId reference");
|
|
7072
7074
|
continue;
|
|
7073
7075
|
}
|
|
7074
7076
|
const functionData = await getFunction(dbClient_default)({
|
|
@@ -7079,7 +7081,7 @@ var Agent = class {
|
|
|
7079
7081
|
}
|
|
7080
7082
|
});
|
|
7081
7083
|
if (!functionData) {
|
|
7082
|
-
|
|
7084
|
+
logger16.warn(
|
|
7083
7085
|
{ functionId, toolId: toolDef.tool.id },
|
|
7084
7086
|
"Function not found in functions table"
|
|
7085
7087
|
);
|
|
@@ -7090,7 +7092,7 @@ var Agent = class {
|
|
|
7090
7092
|
description: toolDef.tool.description || toolDef.tool.name,
|
|
7091
7093
|
inputSchema: zodSchema,
|
|
7092
7094
|
execute: async (args, { toolCallId }) => {
|
|
7093
|
-
|
|
7095
|
+
logger16.debug(
|
|
7094
7096
|
{ toolName: toolDef.tool.name, toolCallId, args },
|
|
7095
7097
|
"Function Tool Called"
|
|
7096
7098
|
);
|
|
@@ -7110,7 +7112,7 @@ var Agent = class {
|
|
|
7110
7112
|
});
|
|
7111
7113
|
return { result, toolCallId };
|
|
7112
7114
|
} catch (error) {
|
|
7113
|
-
|
|
7115
|
+
logger16.error(
|
|
7114
7116
|
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7115
7117
|
"Function tool execution failed"
|
|
7116
7118
|
);
|
|
@@ -7127,7 +7129,7 @@ var Agent = class {
|
|
|
7127
7129
|
}
|
|
7128
7130
|
}
|
|
7129
7131
|
} catch (error) {
|
|
7130
|
-
|
|
7132
|
+
logger16.error({ error }, "Failed to load function tools from database");
|
|
7131
7133
|
}
|
|
7132
7134
|
return functionTools;
|
|
7133
7135
|
}
|
|
@@ -7137,7 +7139,7 @@ var Agent = class {
|
|
|
7137
7139
|
async getResolvedContext(conversationId, headers) {
|
|
7138
7140
|
try {
|
|
7139
7141
|
if (!this.config.contextConfigId) {
|
|
7140
|
-
|
|
7142
|
+
logger16.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7141
7143
|
return null;
|
|
7142
7144
|
}
|
|
7143
7145
|
const contextConfig = await getContextConfigById(dbClient_default)({
|
|
@@ -7149,7 +7151,7 @@ var Agent = class {
|
|
|
7149
7151
|
id: this.config.contextConfigId
|
|
7150
7152
|
});
|
|
7151
7153
|
if (!contextConfig) {
|
|
7152
|
-
|
|
7154
|
+
logger16.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7153
7155
|
return null;
|
|
7154
7156
|
}
|
|
7155
7157
|
if (!this.contextResolver) {
|
|
@@ -7166,7 +7168,7 @@ var Agent = class {
|
|
|
7166
7168
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7167
7169
|
$env: process.env
|
|
7168
7170
|
};
|
|
7169
|
-
|
|
7171
|
+
logger16.debug(
|
|
7170
7172
|
{
|
|
7171
7173
|
conversationId,
|
|
7172
7174
|
contextConfigId: contextConfig.id,
|
|
@@ -7180,7 +7182,7 @@ var Agent = class {
|
|
|
7180
7182
|
);
|
|
7181
7183
|
return contextWithBuiltins;
|
|
7182
7184
|
} catch (error) {
|
|
7183
|
-
|
|
7185
|
+
logger16.error(
|
|
7184
7186
|
{
|
|
7185
7187
|
conversationId,
|
|
7186
7188
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7204,7 +7206,7 @@ var Agent = class {
|
|
|
7204
7206
|
});
|
|
7205
7207
|
return graphDefinition?.graphPrompt || void 0;
|
|
7206
7208
|
} catch (error) {
|
|
7207
|
-
|
|
7209
|
+
logger16.warn(
|
|
7208
7210
|
{
|
|
7209
7211
|
graphId: this.config.graphId,
|
|
7210
7212
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7229,11 +7231,11 @@ var Agent = class {
|
|
|
7229
7231
|
if (!graphDefinition) {
|
|
7230
7232
|
return false;
|
|
7231
7233
|
}
|
|
7232
|
-
return Object.values(graphDefinition.
|
|
7233
|
-
(
|
|
7234
|
+
return Object.values(graphDefinition.subAgents).some(
|
|
7235
|
+
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
7234
7236
|
);
|
|
7235
7237
|
} catch (error) {
|
|
7236
|
-
|
|
7238
|
+
logger16.warn(
|
|
7237
7239
|
{
|
|
7238
7240
|
graphId: this.config.graphId,
|
|
7239
7241
|
tenantId: this.config.tenantId,
|
|
@@ -7262,7 +7264,7 @@ var Agent = class {
|
|
|
7262
7264
|
preserveUnresolved: false
|
|
7263
7265
|
});
|
|
7264
7266
|
} catch (error) {
|
|
7265
|
-
|
|
7267
|
+
logger16.error(
|
|
7266
7268
|
{
|
|
7267
7269
|
conversationId,
|
|
7268
7270
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7309,7 +7311,7 @@ var Agent = class {
|
|
|
7309
7311
|
preserveUnresolved: false
|
|
7310
7312
|
});
|
|
7311
7313
|
} catch (error) {
|
|
7312
|
-
|
|
7314
|
+
logger16.error(
|
|
7313
7315
|
{
|
|
7314
7316
|
conversationId,
|
|
7315
7317
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7324,7 +7326,7 @@ var Agent = class {
|
|
|
7324
7326
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
7325
7327
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
7326
7328
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
7327
|
-
|
|
7329
|
+
logger16.info(
|
|
7328
7330
|
{
|
|
7329
7331
|
mcpTools: Object.keys(mcpTools),
|
|
7330
7332
|
functionTools: Object.keys(functionTools),
|
|
@@ -7345,7 +7347,7 @@ var Agent = class {
|
|
|
7345
7347
|
inputSchema: tool3.inputSchema || tool3.parameters || {},
|
|
7346
7348
|
usageGuidelines: name.startsWith("transfer_to_") || name.startsWith("delegate_to_") ? `Use this tool to ${name.startsWith("transfer_to_") ? "transfer" : "delegate"} to another agent when appropriate.` : "Use this tool when appropriate for the task at hand."
|
|
7347
7349
|
}));
|
|
7348
|
-
const { getConversationScopedArtifacts } = await import('./conversations-
|
|
7350
|
+
const { getConversationScopedArtifacts } = await import('./conversations-JSORLLWS.js');
|
|
7349
7351
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
7350
7352
|
const referenceArtifacts = await getConversationScopedArtifacts({
|
|
7351
7353
|
tenantId: this.config.tenantId,
|
|
@@ -7363,7 +7365,7 @@ var Agent = class {
|
|
|
7363
7365
|
preserveUnresolved: false
|
|
7364
7366
|
});
|
|
7365
7367
|
} catch (error) {
|
|
7366
|
-
|
|
7368
|
+
logger16.error(
|
|
7367
7369
|
{
|
|
7368
7370
|
conversationId,
|
|
7369
7371
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7396,7 +7398,7 @@ var Agent = class {
|
|
|
7396
7398
|
toolCallId: z.string().describe("The tool call ID associated with this artifact.")
|
|
7397
7399
|
}),
|
|
7398
7400
|
execute: async ({ artifactId, toolCallId }) => {
|
|
7399
|
-
|
|
7401
|
+
logger16.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
7400
7402
|
const streamRequestId = this.getStreamRequestId();
|
|
7401
7403
|
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
7402
7404
|
if (!artifactService) {
|
|
@@ -7430,7 +7432,7 @@ var Agent = class {
|
|
|
7430
7432
|
});
|
|
7431
7433
|
}
|
|
7432
7434
|
// Provide a default tool set that is always available to the agent.
|
|
7433
|
-
async getDefaultTools(
|
|
7435
|
+
async getDefaultTools(streamRequestId) {
|
|
7434
7436
|
const defaultTools = {};
|
|
7435
7437
|
if (await this.graphHasArtifactComponents()) {
|
|
7436
7438
|
defaultTools.get_reference_artifact = this.getArtifactTools();
|
|
@@ -7656,7 +7658,7 @@ var Agent = class {
|
|
|
7656
7658
|
};
|
|
7657
7659
|
return enhanced;
|
|
7658
7660
|
} catch (error) {
|
|
7659
|
-
|
|
7661
|
+
logger16.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
7660
7662
|
return result;
|
|
7661
7663
|
}
|
|
7662
7664
|
}
|
|
@@ -7671,7 +7673,7 @@ var Agent = class {
|
|
|
7671
7673
|
}
|
|
7672
7674
|
});
|
|
7673
7675
|
} catch (error) {
|
|
7674
|
-
|
|
7676
|
+
logger16.error(
|
|
7675
7677
|
{ error, graphId: this.config.graphId },
|
|
7676
7678
|
"Failed to check graph artifact components"
|
|
7677
7679
|
);
|
|
@@ -7716,7 +7718,7 @@ var Agent = class {
|
|
|
7716
7718
|
// Thinking prompt without data components
|
|
7717
7719
|
this.getFunctionTools(sessionId, streamRequestId),
|
|
7718
7720
|
Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
|
|
7719
|
-
this.getDefaultTools(
|
|
7721
|
+
this.getDefaultTools(streamRequestId)
|
|
7720
7722
|
]);
|
|
7721
7723
|
childSpan.setStatus({ code: SpanStatusCode.OK });
|
|
7722
7724
|
return result;
|
|
@@ -7756,7 +7758,7 @@ var Agent = class {
|
|
|
7756
7758
|
currentMessage: userMessage,
|
|
7757
7759
|
options: historyConfig,
|
|
7758
7760
|
filters: {
|
|
7759
|
-
|
|
7761
|
+
subAgentId: this.config.id,
|
|
7760
7762
|
taskId
|
|
7761
7763
|
}
|
|
7762
7764
|
});
|
|
@@ -7772,7 +7774,7 @@ var Agent = class {
|
|
|
7772
7774
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
|
|
7773
7775
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
7774
7776
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
7775
|
-
|
|
7777
|
+
logger16.warn(
|
|
7776
7778
|
{
|
|
7777
7779
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
7778
7780
|
appliedTimeout: timeoutMs,
|
|
@@ -7814,7 +7816,7 @@ var Agent = class {
|
|
|
7814
7816
|
}
|
|
7815
7817
|
);
|
|
7816
7818
|
} catch (error) {
|
|
7817
|
-
|
|
7819
|
+
logger16.debug({ error }, "Failed to track agent reasoning");
|
|
7818
7820
|
}
|
|
7819
7821
|
}
|
|
7820
7822
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -7841,7 +7843,7 @@ var Agent = class {
|
|
|
7841
7843
|
projectId: session?.projectId,
|
|
7842
7844
|
artifactComponents: this.artifactComponents,
|
|
7843
7845
|
streamRequestId: this.getStreamRequestId(),
|
|
7844
|
-
|
|
7846
|
+
subAgentId: this.config.id
|
|
7845
7847
|
};
|
|
7846
7848
|
const parser = new IncrementalStreamParser(
|
|
7847
7849
|
streamHelper,
|
|
@@ -7918,7 +7920,7 @@ var Agent = class {
|
|
|
7918
7920
|
}
|
|
7919
7921
|
);
|
|
7920
7922
|
} catch (error) {
|
|
7921
|
-
|
|
7923
|
+
logger16.debug({ error }, "Failed to track agent reasoning");
|
|
7922
7924
|
}
|
|
7923
7925
|
}
|
|
7924
7926
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8090,7 +8092,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8090
8092
|
projectId: session?.projectId,
|
|
8091
8093
|
artifactComponents: this.artifactComponents,
|
|
8092
8094
|
streamRequestId: this.getStreamRequestId(),
|
|
8093
|
-
|
|
8095
|
+
subAgentId: this.config.id
|
|
8094
8096
|
};
|
|
8095
8097
|
const parser = new IncrementalStreamParser(
|
|
8096
8098
|
streamHelper,
|
|
@@ -8173,7 +8175,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8173
8175
|
contextId,
|
|
8174
8176
|
artifactComponents: this.artifactComponents,
|
|
8175
8177
|
streamRequestId: this.getStreamRequestId(),
|
|
8176
|
-
|
|
8178
|
+
subAgentId: this.config.id
|
|
8177
8179
|
});
|
|
8178
8180
|
if (response.object) {
|
|
8179
8181
|
formattedContent = await responseFormatter.formatObjectResponse(
|
|
@@ -8210,7 +8212,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8210
8212
|
};
|
|
8211
8213
|
|
|
8212
8214
|
// src/agents/generateTaskHandler.ts
|
|
8213
|
-
var
|
|
8215
|
+
var logger17 = getLogger("generateTaskHandler");
|
|
8214
8216
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8215
8217
|
return async (task) => {
|
|
8216
8218
|
try {
|
|
@@ -8236,14 +8238,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8236
8238
|
projectId: config.projectId,
|
|
8237
8239
|
graphId: config.graphId
|
|
8238
8240
|
},
|
|
8239
|
-
|
|
8241
|
+
subAgentId: config.subAgentId
|
|
8240
8242
|
}),
|
|
8241
8243
|
getToolsForAgent(dbClient_default)({
|
|
8242
8244
|
scopes: {
|
|
8243
8245
|
tenantId: config.tenantId,
|
|
8244
8246
|
projectId: config.projectId,
|
|
8245
8247
|
graphId: config.graphId,
|
|
8246
|
-
|
|
8248
|
+
subAgentId: config.subAgentId
|
|
8247
8249
|
}
|
|
8248
8250
|
}),
|
|
8249
8251
|
getDataComponentsForAgent(dbClient_default)({
|
|
@@ -8251,7 +8253,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8251
8253
|
tenantId: config.tenantId,
|
|
8252
8254
|
projectId: config.projectId,
|
|
8253
8255
|
graphId: config.graphId,
|
|
8254
|
-
|
|
8256
|
+
subAgentId: config.subAgentId
|
|
8255
8257
|
}
|
|
8256
8258
|
}),
|
|
8257
8259
|
getArtifactComponentsForAgent(dbClient_default)({
|
|
@@ -8259,21 +8261,21 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8259
8261
|
tenantId: config.tenantId,
|
|
8260
8262
|
projectId: config.projectId,
|
|
8261
8263
|
graphId: config.graphId,
|
|
8262
|
-
|
|
8264
|
+
subAgentId: config.subAgentId
|
|
8263
8265
|
}
|
|
8264
8266
|
})
|
|
8265
8267
|
]);
|
|
8266
|
-
|
|
8268
|
+
logger17.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8267
8269
|
const enhancedInternalRelations = await Promise.all(
|
|
8268
8270
|
internalRelations.map(async (relation) => {
|
|
8269
8271
|
try {
|
|
8270
|
-
const relatedAgent = await
|
|
8272
|
+
const relatedAgent = await getSubAgentById(dbClient_default)({
|
|
8271
8273
|
scopes: {
|
|
8272
8274
|
tenantId: config.tenantId,
|
|
8273
8275
|
projectId: config.projectId,
|
|
8274
8276
|
graphId: config.graphId
|
|
8275
8277
|
},
|
|
8276
|
-
|
|
8278
|
+
subAgentId: relation.id
|
|
8277
8279
|
});
|
|
8278
8280
|
if (relatedAgent) {
|
|
8279
8281
|
const relatedAgentRelations = await getRelatedAgentsForGraph(dbClient_default)({
|
|
@@ -8282,7 +8284,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8282
8284
|
projectId: config.projectId,
|
|
8283
8285
|
graphId: config.graphId
|
|
8284
8286
|
},
|
|
8285
|
-
|
|
8287
|
+
subAgentId: relation.id
|
|
8286
8288
|
});
|
|
8287
8289
|
const enhancedDescription = generateDescriptionWithTransfers(
|
|
8288
8290
|
relation.description || "",
|
|
@@ -8292,7 +8294,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8292
8294
|
return { ...relation, description: enhancedDescription };
|
|
8293
8295
|
}
|
|
8294
8296
|
} catch (error) {
|
|
8295
|
-
|
|
8297
|
+
logger17.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
8296
8298
|
}
|
|
8297
8299
|
return relation;
|
|
8298
8300
|
})
|
|
@@ -8307,7 +8309,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8307
8309
|
) ?? [];
|
|
8308
8310
|
const agent = new Agent(
|
|
8309
8311
|
{
|
|
8310
|
-
id: config.
|
|
8312
|
+
id: config.subAgentId,
|
|
8311
8313
|
tenantId: config.tenantId,
|
|
8312
8314
|
projectId: config.projectId,
|
|
8313
8315
|
graphId: config.graphId,
|
|
@@ -8318,7 +8320,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8318
8320
|
agentPrompt,
|
|
8319
8321
|
models: models || void 0,
|
|
8320
8322
|
stopWhen: stopWhen || void 0,
|
|
8321
|
-
|
|
8323
|
+
subAgentRelations: enhancedInternalRelations.map((relation) => ({
|
|
8322
8324
|
id: relation.id,
|
|
8323
8325
|
tenantId: config.tenantId,
|
|
8324
8326
|
projectId: config.projectId,
|
|
@@ -8329,7 +8331,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8329
8331
|
description: relation.description,
|
|
8330
8332
|
agentPrompt: "",
|
|
8331
8333
|
delegateRelations: [],
|
|
8332
|
-
|
|
8334
|
+
subAgentRelations: [],
|
|
8333
8335
|
transferRelations: []
|
|
8334
8336
|
})),
|
|
8335
8337
|
transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
|
|
@@ -8343,7 +8345,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8343
8345
|
description: relation.description,
|
|
8344
8346
|
agentPrompt: "",
|
|
8345
8347
|
delegateRelations: [],
|
|
8346
|
-
|
|
8348
|
+
subAgentRelations: [],
|
|
8347
8349
|
transferRelations: []
|
|
8348
8350
|
})),
|
|
8349
8351
|
delegateRelations: [
|
|
@@ -8361,7 +8363,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8361
8363
|
description: relation.description,
|
|
8362
8364
|
agentPrompt: "",
|
|
8363
8365
|
delegateRelations: [],
|
|
8364
|
-
|
|
8366
|
+
subAgentRelations: [],
|
|
8365
8367
|
transferRelations: []
|
|
8366
8368
|
}
|
|
8367
8369
|
})),
|
|
@@ -8396,11 +8398,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8396
8398
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
8397
8399
|
if (taskIdMatch) {
|
|
8398
8400
|
contextId = taskIdMatch[1];
|
|
8399
|
-
|
|
8401
|
+
logger17.info(
|
|
8400
8402
|
{
|
|
8401
8403
|
taskId: task.id,
|
|
8402
8404
|
extractedContextId: contextId,
|
|
8403
|
-
|
|
8405
|
+
subAgentId: config.subAgentId
|
|
8404
8406
|
},
|
|
8405
8407
|
"Extracted contextId from task ID for delegation"
|
|
8406
8408
|
);
|
|
@@ -8412,8 +8414,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8412
8414
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
8413
8415
|
agent.setDelegationStatus(isDelegation);
|
|
8414
8416
|
if (isDelegation) {
|
|
8415
|
-
|
|
8416
|
-
{
|
|
8417
|
+
logger17.info(
|
|
8418
|
+
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
8417
8419
|
"Delegated agent - streaming disabled"
|
|
8418
8420
|
);
|
|
8419
8421
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -8510,13 +8512,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8510
8512
|
};
|
|
8511
8513
|
};
|
|
8512
8514
|
var createTaskHandlerConfig = async (params) => {
|
|
8513
|
-
const agent = await
|
|
8515
|
+
const agent = await getSubAgentById(dbClient_default)({
|
|
8514
8516
|
scopes: {
|
|
8515
8517
|
tenantId: params.tenantId,
|
|
8516
8518
|
projectId: params.projectId,
|
|
8517
8519
|
graphId: params.graphId
|
|
8518
8520
|
},
|
|
8519
|
-
|
|
8521
|
+
subAgentId: params.subAgentId
|
|
8520
8522
|
});
|
|
8521
8523
|
const agentGraph = await getAgentGraphById(dbClient_default)({
|
|
8522
8524
|
scopes: {
|
|
@@ -8526,7 +8528,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
8526
8528
|
}
|
|
8527
8529
|
});
|
|
8528
8530
|
if (!agent) {
|
|
8529
|
-
throw new Error(`Agent not found: ${params.
|
|
8531
|
+
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
8530
8532
|
}
|
|
8531
8533
|
const effectiveModels = await resolveModelConfig(params.graphId, agent);
|
|
8532
8534
|
const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
|
|
@@ -8534,7 +8536,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
8534
8536
|
tenantId: params.tenantId,
|
|
8535
8537
|
projectId: params.projectId,
|
|
8536
8538
|
graphId: params.graphId,
|
|
8537
|
-
|
|
8539
|
+
subAgentId: params.subAgentId,
|
|
8538
8540
|
agentSchema: {
|
|
8539
8541
|
id: agent.id,
|
|
8540
8542
|
name: agent.name,
|
|
@@ -8562,25 +8564,27 @@ async function hydrateGraph({
|
|
|
8562
8564
|
apiKey
|
|
8563
8565
|
}) {
|
|
8564
8566
|
try {
|
|
8565
|
-
if (!dbGraph.
|
|
8567
|
+
if (!dbGraph.defaultSubAgentId) {
|
|
8566
8568
|
throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
|
|
8567
8569
|
}
|
|
8568
|
-
const
|
|
8570
|
+
const defaultSubAgent = await getSubAgentById(dbClient_default)({
|
|
8569
8571
|
scopes: {
|
|
8570
8572
|
tenantId: dbGraph.tenantId,
|
|
8571
8573
|
projectId: dbGraph.projectId,
|
|
8572
8574
|
graphId: dbGraph.id
|
|
8573
8575
|
},
|
|
8574
|
-
|
|
8576
|
+
subAgentId: dbGraph.defaultSubAgentId
|
|
8575
8577
|
});
|
|
8576
|
-
if (!
|
|
8577
|
-
throw new Error(
|
|
8578
|
+
if (!defaultSubAgent) {
|
|
8579
|
+
throw new Error(
|
|
8580
|
+
`Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
|
|
8581
|
+
);
|
|
8578
8582
|
}
|
|
8579
8583
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
8580
8584
|
tenantId: dbGraph.tenantId,
|
|
8581
8585
|
projectId: dbGraph.projectId,
|
|
8582
8586
|
graphId: dbGraph.id,
|
|
8583
|
-
|
|
8587
|
+
subAgentId: dbGraph.defaultSubAgentId,
|
|
8584
8588
|
baseUrl,
|
|
8585
8589
|
apiKey
|
|
8586
8590
|
});
|
|
@@ -8609,7 +8613,7 @@ async function hydrateGraph({
|
|
|
8609
8613
|
}
|
|
8610
8614
|
};
|
|
8611
8615
|
return {
|
|
8612
|
-
|
|
8616
|
+
subAgentId: dbGraph.id,
|
|
8613
8617
|
// Use graph ID as agent ID for A2A purposes
|
|
8614
8618
|
tenantId: dbGraph.tenantId,
|
|
8615
8619
|
projectId: dbGraph.projectId,
|
|
@@ -8634,7 +8638,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
8634
8638
|
|
|
8635
8639
|
// src/routes/agents.ts
|
|
8636
8640
|
var app = new OpenAPIHono();
|
|
8637
|
-
var
|
|
8641
|
+
var logger18 = getLogger("agents");
|
|
8638
8642
|
app.openapi(
|
|
8639
8643
|
createRoute({
|
|
8640
8644
|
method: "get",
|
|
@@ -8672,7 +8676,7 @@ app.openapi(
|
|
|
8672
8676
|
tracestate: c.req.header("tracestate"),
|
|
8673
8677
|
baggage: c.req.header("baggage")
|
|
8674
8678
|
};
|
|
8675
|
-
|
|
8679
|
+
logger18.info(
|
|
8676
8680
|
{
|
|
8677
8681
|
otelHeaders,
|
|
8678
8682
|
path: c.req.path,
|
|
@@ -8681,22 +8685,22 @@ app.openapi(
|
|
|
8681
8685
|
"OpenTelemetry headers: well-known agent.json"
|
|
8682
8686
|
);
|
|
8683
8687
|
const executionContext = getRequestExecutionContext(c);
|
|
8684
|
-
const { tenantId, projectId, graphId,
|
|
8688
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
8685
8689
|
console.dir("executionContext", executionContext);
|
|
8686
|
-
if (
|
|
8687
|
-
|
|
8690
|
+
if (subAgentId) {
|
|
8691
|
+
logger18.info(
|
|
8688
8692
|
{
|
|
8689
8693
|
message: "getRegisteredAgent (agent-level)",
|
|
8690
8694
|
tenantId,
|
|
8691
8695
|
projectId,
|
|
8692
8696
|
graphId,
|
|
8693
|
-
|
|
8697
|
+
subAgentId
|
|
8694
8698
|
},
|
|
8695
8699
|
"agent-level well-known agent.json"
|
|
8696
8700
|
);
|
|
8697
8701
|
const credentialStores = c.get("credentialStores");
|
|
8698
8702
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
8699
|
-
|
|
8703
|
+
logger18.info({ agent }, "agent registered: well-known agent.json");
|
|
8700
8704
|
if (!agent) {
|
|
8701
8705
|
throw createApiError({
|
|
8702
8706
|
code: "not_found",
|
|
@@ -8705,7 +8709,7 @@ app.openapi(
|
|
|
8705
8709
|
}
|
|
8706
8710
|
return c.json(agent.agentCard);
|
|
8707
8711
|
} else {
|
|
8708
|
-
|
|
8712
|
+
logger18.info(
|
|
8709
8713
|
{
|
|
8710
8714
|
message: "getRegisteredGraph (graph-level)",
|
|
8711
8715
|
tenantId,
|
|
@@ -8731,7 +8735,7 @@ app.post("/a2a", async (c) => {
|
|
|
8731
8735
|
tracestate: c.req.header("tracestate"),
|
|
8732
8736
|
baggage: c.req.header("baggage")
|
|
8733
8737
|
};
|
|
8734
|
-
|
|
8738
|
+
logger18.info(
|
|
8735
8739
|
{
|
|
8736
8740
|
otelHeaders,
|
|
8737
8741
|
path: c.req.path,
|
|
@@ -8740,15 +8744,15 @@ app.post("/a2a", async (c) => {
|
|
|
8740
8744
|
"OpenTelemetry headers: a2a"
|
|
8741
8745
|
);
|
|
8742
8746
|
const executionContext = getRequestExecutionContext(c);
|
|
8743
|
-
const { tenantId, projectId, graphId,
|
|
8744
|
-
if (
|
|
8745
|
-
|
|
8747
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
8748
|
+
if (subAgentId) {
|
|
8749
|
+
logger18.info(
|
|
8746
8750
|
{
|
|
8747
8751
|
message: "a2a (agent-level)",
|
|
8748
8752
|
tenantId,
|
|
8749
8753
|
projectId,
|
|
8750
8754
|
graphId,
|
|
8751
|
-
|
|
8755
|
+
subAgentId
|
|
8752
8756
|
},
|
|
8753
8757
|
"agent-level a2a endpoint"
|
|
8754
8758
|
);
|
|
@@ -8766,7 +8770,7 @@ app.post("/a2a", async (c) => {
|
|
|
8766
8770
|
}
|
|
8767
8771
|
return a2aHandler(c, agent);
|
|
8768
8772
|
} else {
|
|
8769
|
-
|
|
8773
|
+
logger18.info(
|
|
8770
8774
|
{
|
|
8771
8775
|
message: "a2a (graph-level)",
|
|
8772
8776
|
tenantId,
|
|
@@ -8775,7 +8779,7 @@ app.post("/a2a", async (c) => {
|
|
|
8775
8779
|
},
|
|
8776
8780
|
"graph-level a2a endpoint"
|
|
8777
8781
|
);
|
|
8778
|
-
const graph = await
|
|
8782
|
+
const graph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
8779
8783
|
scopes: { tenantId, projectId, graphId }
|
|
8780
8784
|
});
|
|
8781
8785
|
if (!graph) {
|
|
@@ -8788,7 +8792,7 @@ app.post("/a2a", async (c) => {
|
|
|
8788
8792
|
404
|
|
8789
8793
|
);
|
|
8790
8794
|
}
|
|
8791
|
-
if (!graph.
|
|
8795
|
+
if (!graph.defaultSubAgentId) {
|
|
8792
8796
|
return c.json(
|
|
8793
8797
|
{
|
|
8794
8798
|
jsonrpc: "2.0",
|
|
@@ -8798,10 +8802,10 @@ app.post("/a2a", async (c) => {
|
|
|
8798
8802
|
400
|
|
8799
8803
|
);
|
|
8800
8804
|
}
|
|
8801
|
-
executionContext.
|
|
8805
|
+
executionContext.subAgentId = graph.defaultSubAgentId;
|
|
8802
8806
|
const credentialStores = c.get("credentialStores");
|
|
8803
|
-
const
|
|
8804
|
-
if (!
|
|
8807
|
+
const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
|
|
8808
|
+
if (!defaultSubAgent) {
|
|
8805
8809
|
return c.json(
|
|
8806
8810
|
{
|
|
8807
8811
|
jsonrpc: "2.0",
|
|
@@ -8811,24 +8815,24 @@ app.post("/a2a", async (c) => {
|
|
|
8811
8815
|
404
|
|
8812
8816
|
);
|
|
8813
8817
|
}
|
|
8814
|
-
return a2aHandler(c,
|
|
8818
|
+
return a2aHandler(c, defaultSubAgent);
|
|
8815
8819
|
}
|
|
8816
8820
|
});
|
|
8817
8821
|
var agents_default = app;
|
|
8818
|
-
var
|
|
8822
|
+
var logger19 = getLogger("Transfer");
|
|
8819
8823
|
async function executeTransfer({
|
|
8820
8824
|
tenantId,
|
|
8821
8825
|
threadId,
|
|
8822
8826
|
projectId,
|
|
8823
|
-
|
|
8827
|
+
targetSubAgentId
|
|
8824
8828
|
}) {
|
|
8825
|
-
|
|
8829
|
+
logger19.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
|
|
8826
8830
|
await setActiveAgentForThread(dbClient_default)({
|
|
8827
8831
|
scopes: { tenantId, projectId },
|
|
8828
8832
|
threadId,
|
|
8829
|
-
|
|
8833
|
+
subAgentId: targetSubAgentId
|
|
8830
8834
|
});
|
|
8831
|
-
return { success: true,
|
|
8835
|
+
return { success: true, targetSubAgentId };
|
|
8832
8836
|
}
|
|
8833
8837
|
function isTransferResponse(result) {
|
|
8834
8838
|
return result?.artifacts.some(
|
|
@@ -9404,7 +9408,7 @@ function createMCPStreamHelper() {
|
|
|
9404
9408
|
}
|
|
9405
9409
|
|
|
9406
9410
|
// src/handlers/executionHandler.ts
|
|
9407
|
-
var
|
|
9411
|
+
var logger20 = getLogger("ExecutionHandler");
|
|
9408
9412
|
var ExecutionHandler = class {
|
|
9409
9413
|
constructor() {
|
|
9410
9414
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -9440,7 +9444,7 @@ var ExecutionHandler = class {
|
|
|
9440
9444
|
if (emitOperations) {
|
|
9441
9445
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
9442
9446
|
}
|
|
9443
|
-
|
|
9447
|
+
logger20.info(
|
|
9444
9448
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
9445
9449
|
"Created GraphSession for message execution"
|
|
9446
9450
|
);
|
|
@@ -9455,7 +9459,7 @@ var ExecutionHandler = class {
|
|
|
9455
9459
|
);
|
|
9456
9460
|
}
|
|
9457
9461
|
} catch (error) {
|
|
9458
|
-
|
|
9462
|
+
logger20.error(
|
|
9459
9463
|
{
|
|
9460
9464
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9461
9465
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9471,7 +9475,7 @@ var ExecutionHandler = class {
|
|
|
9471
9475
|
try {
|
|
9472
9476
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
9473
9477
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
9474
|
-
|
|
9478
|
+
logger20.info(
|
|
9475
9479
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
9476
9480
|
"Attempting to create or reuse existing task"
|
|
9477
9481
|
);
|
|
@@ -9481,7 +9485,7 @@ var ExecutionHandler = class {
|
|
|
9481
9485
|
tenantId,
|
|
9482
9486
|
projectId,
|
|
9483
9487
|
graphId,
|
|
9484
|
-
|
|
9488
|
+
subAgentId: currentAgentId,
|
|
9485
9489
|
contextId: conversationId,
|
|
9486
9490
|
status: "pending",
|
|
9487
9491
|
metadata: {
|
|
@@ -9495,7 +9499,7 @@ var ExecutionHandler = class {
|
|
|
9495
9499
|
agent_id: currentAgentId
|
|
9496
9500
|
}
|
|
9497
9501
|
});
|
|
9498
|
-
|
|
9502
|
+
logger20.info(
|
|
9499
9503
|
{
|
|
9500
9504
|
taskId,
|
|
9501
9505
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -9504,27 +9508,27 @@ var ExecutionHandler = class {
|
|
|
9504
9508
|
);
|
|
9505
9509
|
} catch (error) {
|
|
9506
9510
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
9507
|
-
|
|
9511
|
+
logger20.info(
|
|
9508
9512
|
{ taskId, error: error.message },
|
|
9509
9513
|
"Task already exists, fetching existing task"
|
|
9510
9514
|
);
|
|
9511
9515
|
const existingTask = await getTask(dbClient_default)({ id: taskId });
|
|
9512
9516
|
if (existingTask) {
|
|
9513
9517
|
task = existingTask;
|
|
9514
|
-
|
|
9518
|
+
logger20.info(
|
|
9515
9519
|
{ taskId, existingTask },
|
|
9516
9520
|
"Successfully reused existing task from race condition"
|
|
9517
9521
|
);
|
|
9518
9522
|
} else {
|
|
9519
|
-
|
|
9523
|
+
logger20.error({ taskId, error }, "Task constraint failed but task not found");
|
|
9520
9524
|
throw error;
|
|
9521
9525
|
}
|
|
9522
9526
|
} else {
|
|
9523
|
-
|
|
9527
|
+
logger20.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
9524
9528
|
throw error;
|
|
9525
9529
|
}
|
|
9526
9530
|
}
|
|
9527
|
-
|
|
9531
|
+
logger20.debug(
|
|
9528
9532
|
{
|
|
9529
9533
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9530
9534
|
executionType: "create_initial_task",
|
|
@@ -9542,7 +9546,7 @@ var ExecutionHandler = class {
|
|
|
9542
9546
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
9543
9547
|
while (iterations < maxTransfers) {
|
|
9544
9548
|
iterations++;
|
|
9545
|
-
|
|
9549
|
+
logger20.info(
|
|
9546
9550
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
9547
9551
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
9548
9552
|
);
|
|
@@ -9550,10 +9554,10 @@ var ExecutionHandler = class {
|
|
|
9550
9554
|
scopes: { tenantId, projectId },
|
|
9551
9555
|
conversationId
|
|
9552
9556
|
});
|
|
9553
|
-
|
|
9554
|
-
if (activeAgent && activeAgent.
|
|
9555
|
-
currentAgentId = activeAgent.
|
|
9556
|
-
|
|
9557
|
+
logger20.info({ activeAgent }, "activeAgent");
|
|
9558
|
+
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
9559
|
+
currentAgentId = activeAgent.activeSubAgentId;
|
|
9560
|
+
logger20.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
9557
9561
|
}
|
|
9558
9562
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
9559
9563
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -9594,13 +9598,13 @@ var ExecutionHandler = class {
|
|
|
9594
9598
|
});
|
|
9595
9599
|
if (!messageResponse?.result) {
|
|
9596
9600
|
errorCount++;
|
|
9597
|
-
|
|
9601
|
+
logger20.error(
|
|
9598
9602
|
{ currentAgentId, iterations, errorCount },
|
|
9599
9603
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9600
9604
|
);
|
|
9601
9605
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9602
9606
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9603
|
-
|
|
9607
|
+
logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9604
9608
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9605
9609
|
if (task) {
|
|
9606
9610
|
await updateTask(dbClient_default)({
|
|
@@ -9623,20 +9627,20 @@ var ExecutionHandler = class {
|
|
|
9623
9627
|
}
|
|
9624
9628
|
if (isTransferResponse(messageResponse.result)) {
|
|
9625
9629
|
const transferResponse = messageResponse.result;
|
|
9626
|
-
const
|
|
9630
|
+
const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
|
|
9627
9631
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
9628
|
-
|
|
9632
|
+
logger20.info({ targetSubAgentId, transferReason }, "transfer response");
|
|
9629
9633
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
9630
|
-
const { success,
|
|
9634
|
+
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
9631
9635
|
projectId,
|
|
9632
9636
|
tenantId,
|
|
9633
9637
|
threadId: conversationId,
|
|
9634
|
-
|
|
9638
|
+
targetSubAgentId
|
|
9635
9639
|
});
|
|
9636
9640
|
if (success) {
|
|
9637
9641
|
fromAgentId = currentAgentId;
|
|
9638
9642
|
currentAgentId = newAgentId;
|
|
9639
|
-
|
|
9643
|
+
logger20.info(
|
|
9640
9644
|
{
|
|
9641
9645
|
transferFrom: fromAgentId,
|
|
9642
9646
|
transferTo: currentAgentId,
|
|
@@ -9654,7 +9658,7 @@ var ExecutionHandler = class {
|
|
|
9654
9658
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
9655
9659
|
if (graphSessionData) {
|
|
9656
9660
|
const sessionSummary = graphSessionData.getSummary();
|
|
9657
|
-
|
|
9661
|
+
logger20.info(sessionSummary, "GraphSession data after completion");
|
|
9658
9662
|
}
|
|
9659
9663
|
let textContent = "";
|
|
9660
9664
|
for (const part of responseParts) {
|
|
@@ -9686,8 +9690,7 @@ var ExecutionHandler = class {
|
|
|
9686
9690
|
},
|
|
9687
9691
|
visibility: "user-facing",
|
|
9688
9692
|
messageType: "chat",
|
|
9689
|
-
|
|
9690
|
-
fromAgentId: currentAgentId,
|
|
9693
|
+
fromSubAgentId: currentAgentId,
|
|
9691
9694
|
taskId: task.id
|
|
9692
9695
|
});
|
|
9693
9696
|
const updateTaskStart = Date.now();
|
|
@@ -9708,22 +9711,22 @@ var ExecutionHandler = class {
|
|
|
9708
9711
|
}
|
|
9709
9712
|
});
|
|
9710
9713
|
const updateTaskEnd = Date.now();
|
|
9711
|
-
|
|
9714
|
+
logger20.info(
|
|
9712
9715
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
9713
9716
|
"Completed updateTask operation"
|
|
9714
9717
|
);
|
|
9715
9718
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
9716
9719
|
await sseHelper.complete();
|
|
9717
|
-
|
|
9720
|
+
logger20.info({}, "Ending GraphSession and cleaning up");
|
|
9718
9721
|
graphSessionManager.endSession(requestId2);
|
|
9719
|
-
|
|
9722
|
+
logger20.info({}, "Cleaning up streamHelper");
|
|
9720
9723
|
unregisterStreamHelper(requestId2);
|
|
9721
9724
|
let response;
|
|
9722
9725
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
9723
9726
|
const captured = sseHelper.getCapturedResponse();
|
|
9724
9727
|
response = captured.text || "No response content";
|
|
9725
9728
|
}
|
|
9726
|
-
|
|
9729
|
+
logger20.info({}, "ExecutionHandler returning success");
|
|
9727
9730
|
return { success: true, iterations, response };
|
|
9728
9731
|
} catch (error) {
|
|
9729
9732
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -9734,13 +9737,13 @@ var ExecutionHandler = class {
|
|
|
9734
9737
|
});
|
|
9735
9738
|
}
|
|
9736
9739
|
errorCount++;
|
|
9737
|
-
|
|
9740
|
+
logger20.warn(
|
|
9738
9741
|
{ iterations, errorCount },
|
|
9739
9742
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9740
9743
|
);
|
|
9741
9744
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9742
9745
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9743
|
-
|
|
9746
|
+
logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9744
9747
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9745
9748
|
if (task) {
|
|
9746
9749
|
await updateTask(dbClient_default)({
|
|
@@ -9761,7 +9764,7 @@ var ExecutionHandler = class {
|
|
|
9761
9764
|
}
|
|
9762
9765
|
}
|
|
9763
9766
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
9764
|
-
|
|
9767
|
+
logger20.error({ maxTransfers, iterations }, errorMessage);
|
|
9765
9768
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
9766
9769
|
if (task) {
|
|
9767
9770
|
await updateTask(dbClient_default)({
|
|
@@ -9780,7 +9783,7 @@ var ExecutionHandler = class {
|
|
|
9780
9783
|
unregisterStreamHelper(requestId2);
|
|
9781
9784
|
return { success: false, error: errorMessage, iterations };
|
|
9782
9785
|
} catch (error) {
|
|
9783
|
-
|
|
9786
|
+
logger20.error({ error }, "Error in execution handler");
|
|
9784
9787
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
9785
9788
|
await sseHelper.writeOperation(
|
|
9786
9789
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -9807,7 +9810,7 @@ var ExecutionHandler = class {
|
|
|
9807
9810
|
|
|
9808
9811
|
// src/routes/chat.ts
|
|
9809
9812
|
var app2 = new OpenAPIHono();
|
|
9810
|
-
var
|
|
9813
|
+
var logger21 = getLogger("completionsHandler");
|
|
9811
9814
|
var chatCompletionsRoute = createRoute({
|
|
9812
9815
|
method: "post",
|
|
9813
9816
|
path: "/completions",
|
|
@@ -9925,7 +9928,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9925
9928
|
tracestate: c.req.header("tracestate"),
|
|
9926
9929
|
baggage: c.req.header("baggage")
|
|
9927
9930
|
};
|
|
9928
|
-
|
|
9931
|
+
logger21.info(
|
|
9929
9932
|
{
|
|
9930
9933
|
otelHeaders,
|
|
9931
9934
|
path: c.req.path,
|
|
@@ -9949,20 +9952,20 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9949
9952
|
scopes: { tenantId, projectId, graphId }
|
|
9950
9953
|
});
|
|
9951
9954
|
let agentGraph;
|
|
9952
|
-
let
|
|
9955
|
+
let defaultSubAgentId;
|
|
9953
9956
|
if (fullGraph) {
|
|
9954
9957
|
agentGraph = {
|
|
9955
9958
|
id: fullGraph.id,
|
|
9956
9959
|
name: fullGraph.name,
|
|
9957
9960
|
tenantId,
|
|
9958
9961
|
projectId,
|
|
9959
|
-
|
|
9962
|
+
defaultSubAgentId: fullGraph.defaultSubAgentId
|
|
9960
9963
|
};
|
|
9961
|
-
const agentKeys = Object.keys(fullGraph.
|
|
9964
|
+
const agentKeys = Object.keys(fullGraph.subAgents || {});
|
|
9962
9965
|
const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
|
|
9963
|
-
|
|
9966
|
+
defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
|
|
9964
9967
|
} else {
|
|
9965
|
-
agentGraph = await
|
|
9968
|
+
agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
9966
9969
|
scopes: { tenantId, projectId, graphId }
|
|
9967
9970
|
});
|
|
9968
9971
|
if (!agentGraph) {
|
|
@@ -9971,9 +9974,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9971
9974
|
message: "Agent graph not found"
|
|
9972
9975
|
});
|
|
9973
9976
|
}
|
|
9974
|
-
|
|
9977
|
+
defaultSubAgentId = agentGraph.defaultSubAgentId || "";
|
|
9975
9978
|
}
|
|
9976
|
-
if (!
|
|
9979
|
+
if (!defaultSubAgentId) {
|
|
9977
9980
|
throw createApiError({
|
|
9978
9981
|
code: "not_found",
|
|
9979
9982
|
message: "No default agent found in graph"
|
|
@@ -9983,7 +9986,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9983
9986
|
tenantId,
|
|
9984
9987
|
projectId,
|
|
9985
9988
|
id: conversationId,
|
|
9986
|
-
|
|
9989
|
+
activeSubAgentId: defaultSubAgentId
|
|
9987
9990
|
});
|
|
9988
9991
|
const activeAgent = await getActiveAgentForConversation(dbClient_default)({
|
|
9989
9992
|
scopes: { tenantId, projectId },
|
|
@@ -9993,13 +9996,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9993
9996
|
setActiveAgentForConversation(dbClient_default)({
|
|
9994
9997
|
scopes: { tenantId, projectId },
|
|
9995
9998
|
conversationId,
|
|
9996
|
-
|
|
9999
|
+
subAgentId: defaultSubAgentId
|
|
9997
10000
|
});
|
|
9998
10001
|
}
|
|
9999
|
-
const
|
|
10000
|
-
const agentInfo = await
|
|
10002
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
10003
|
+
const agentInfo = await getSubAgentById(dbClient_default)({
|
|
10001
10004
|
scopes: { tenantId, projectId, graphId },
|
|
10002
|
-
|
|
10005
|
+
subAgentId
|
|
10003
10006
|
});
|
|
10004
10007
|
if (!agentInfo) {
|
|
10005
10008
|
throw createApiError({
|
|
@@ -10018,14 +10021,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10018
10021
|
dbClient: dbClient_default,
|
|
10019
10022
|
credentialStores
|
|
10020
10023
|
});
|
|
10021
|
-
|
|
10024
|
+
logger21.info(
|
|
10022
10025
|
{
|
|
10023
10026
|
tenantId,
|
|
10024
10027
|
projectId,
|
|
10025
10028
|
graphId,
|
|
10026
10029
|
conversationId,
|
|
10027
|
-
|
|
10028
|
-
|
|
10030
|
+
defaultSubAgentId,
|
|
10031
|
+
activeSubAgentId: activeAgent?.activeSubAgentId || "none",
|
|
10029
10032
|
hasContextConfig: !!agentGraph.contextConfigId,
|
|
10030
10033
|
hasHeaders: !!body.headers,
|
|
10031
10034
|
hasValidatedContext: !!validatedContext,
|
|
@@ -10066,7 +10069,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10066
10069
|
try {
|
|
10067
10070
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10068
10071
|
await sseHelper.writeRole();
|
|
10069
|
-
|
|
10072
|
+
logger21.info({ subAgentId }, "Starting execution");
|
|
10070
10073
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10071
10074
|
const emitOperations = emitOperationsHeader === "true";
|
|
10072
10075
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10074,12 +10077,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10074
10077
|
executionContext,
|
|
10075
10078
|
conversationId,
|
|
10076
10079
|
userMessage,
|
|
10077
|
-
initialAgentId:
|
|
10080
|
+
initialAgentId: subAgentId,
|
|
10078
10081
|
requestId: requestId2,
|
|
10079
10082
|
sseHelper,
|
|
10080
10083
|
emitOperations
|
|
10081
10084
|
});
|
|
10082
|
-
|
|
10085
|
+
logger21.info(
|
|
10083
10086
|
{ result },
|
|
10084
10087
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10085
10088
|
);
|
|
@@ -10093,7 +10096,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10093
10096
|
}
|
|
10094
10097
|
await sseHelper.complete();
|
|
10095
10098
|
} catch (error) {
|
|
10096
|
-
|
|
10099
|
+
logger21.error(
|
|
10097
10100
|
{
|
|
10098
10101
|
error: error instanceof Error ? error.message : error,
|
|
10099
10102
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10110,12 +10113,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10110
10113
|
);
|
|
10111
10114
|
await sseHelper.complete();
|
|
10112
10115
|
} catch (streamError) {
|
|
10113
|
-
|
|
10116
|
+
logger21.error({ streamError }, "Failed to write error to stream");
|
|
10114
10117
|
}
|
|
10115
10118
|
}
|
|
10116
10119
|
});
|
|
10117
10120
|
} catch (error) {
|
|
10118
|
-
|
|
10121
|
+
logger21.error(
|
|
10119
10122
|
{
|
|
10120
10123
|
error: error instanceof Error ? error.message : error,
|
|
10121
10124
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10139,7 +10142,7 @@ var getMessageText = (content) => {
|
|
|
10139
10142
|
};
|
|
10140
10143
|
var chat_default = app2;
|
|
10141
10144
|
var app3 = new OpenAPIHono();
|
|
10142
|
-
var
|
|
10145
|
+
var logger22 = getLogger("chatDataStream");
|
|
10143
10146
|
var chatDataStreamRoute = createRoute({
|
|
10144
10147
|
method: "post",
|
|
10145
10148
|
path: "/chat",
|
|
@@ -10204,7 +10207,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10204
10207
|
"project.id": projectId
|
|
10205
10208
|
});
|
|
10206
10209
|
}
|
|
10207
|
-
const agentGraph = await
|
|
10210
|
+
const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10208
10211
|
scopes: { tenantId, projectId, graphId }
|
|
10209
10212
|
});
|
|
10210
10213
|
if (!agentGraph) {
|
|
@@ -10213,9 +10216,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10213
10216
|
message: "Agent graph not found"
|
|
10214
10217
|
});
|
|
10215
10218
|
}
|
|
10216
|
-
const
|
|
10219
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
10217
10220
|
const graphName = agentGraph.name;
|
|
10218
|
-
if (!
|
|
10221
|
+
if (!defaultSubAgentId) {
|
|
10219
10222
|
throw createApiError({
|
|
10220
10223
|
code: "bad_request",
|
|
10221
10224
|
message: "Graph does not have a default agent configured"
|
|
@@ -10229,13 +10232,13 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10229
10232
|
setActiveAgentForConversation(dbClient_default)({
|
|
10230
10233
|
scopes: { tenantId, projectId },
|
|
10231
10234
|
conversationId,
|
|
10232
|
-
|
|
10235
|
+
subAgentId: defaultSubAgentId
|
|
10233
10236
|
});
|
|
10234
10237
|
}
|
|
10235
|
-
const
|
|
10236
|
-
const agentInfo = await
|
|
10238
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
10239
|
+
const agentInfo = await getSubAgentById(dbClient_default)({
|
|
10237
10240
|
scopes: { tenantId, projectId, graphId },
|
|
10238
|
-
|
|
10241
|
+
subAgentId
|
|
10239
10242
|
});
|
|
10240
10243
|
if (!agentInfo) {
|
|
10241
10244
|
throw createApiError({
|
|
@@ -10256,7 +10259,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10256
10259
|
});
|
|
10257
10260
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
10258
10261
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
10259
|
-
|
|
10262
|
+
logger22.info({ userText, lastUserMessage }, "userText");
|
|
10260
10263
|
const messageSpan = trace.getActiveSpan();
|
|
10261
10264
|
if (messageSpan) {
|
|
10262
10265
|
messageSpan.setAttributes({
|
|
@@ -10292,7 +10295,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10292
10295
|
executionContext,
|
|
10293
10296
|
conversationId,
|
|
10294
10297
|
userMessage: userText,
|
|
10295
|
-
initialAgentId:
|
|
10298
|
+
initialAgentId: subAgentId,
|
|
10296
10299
|
requestId: `chatds-${Date.now()}`,
|
|
10297
10300
|
sseHelper: streamHelper,
|
|
10298
10301
|
emitOperations
|
|
@@ -10301,7 +10304,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10301
10304
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
10302
10305
|
}
|
|
10303
10306
|
} catch (err) {
|
|
10304
|
-
|
|
10307
|
+
logger22.error({ err }, "Streaming error");
|
|
10305
10308
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
10306
10309
|
} finally {
|
|
10307
10310
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -10322,7 +10325,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10322
10325
|
)
|
|
10323
10326
|
);
|
|
10324
10327
|
} catch (error) {
|
|
10325
|
-
|
|
10328
|
+
logger22.error({ error }, "chatDataStream error");
|
|
10326
10329
|
throw createApiError({
|
|
10327
10330
|
code: "internal_server_error",
|
|
10328
10331
|
message: "Failed to process chat completion"
|
|
@@ -10333,7 +10336,7 @@ var chatDataStream_default = app3;
|
|
|
10333
10336
|
function createMCPSchema(schema) {
|
|
10334
10337
|
return schema;
|
|
10335
10338
|
}
|
|
10336
|
-
var
|
|
10339
|
+
var logger23 = getLogger("mcp");
|
|
10337
10340
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
10338
10341
|
constructor() {
|
|
10339
10342
|
__publicField(this, "mockRes");
|
|
@@ -10388,21 +10391,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
10388
10391
|
id: 0
|
|
10389
10392
|
});
|
|
10390
10393
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
10391
|
-
|
|
10394
|
+
logger23.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
10392
10395
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
10393
10396
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
10394
10397
|
try {
|
|
10395
10398
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
10396
|
-
|
|
10399
|
+
logger23.info({ sessionId }, "Successfully spoofed initialization");
|
|
10397
10400
|
} catch (spoofError) {
|
|
10398
|
-
|
|
10401
|
+
logger23.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
10399
10402
|
}
|
|
10400
10403
|
};
|
|
10401
10404
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
10402
10405
|
const sessionId = req.headers["mcp-session-id"];
|
|
10403
|
-
|
|
10406
|
+
logger23.info({ sessionId }, "Received MCP session ID");
|
|
10404
10407
|
if (!sessionId) {
|
|
10405
|
-
|
|
10408
|
+
logger23.info({ body }, "Missing session ID");
|
|
10406
10409
|
res.writeHead(400).end(
|
|
10407
10410
|
JSON.stringify({
|
|
10408
10411
|
jsonrpc: "2.0",
|
|
@@ -10428,7 +10431,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10428
10431
|
scopes: { tenantId, projectId },
|
|
10429
10432
|
conversationId: sessionId
|
|
10430
10433
|
});
|
|
10431
|
-
|
|
10434
|
+
logger23.info(
|
|
10432
10435
|
{
|
|
10433
10436
|
sessionId,
|
|
10434
10437
|
conversationFound: !!conversation,
|
|
@@ -10439,7 +10442,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10439
10442
|
"Conversation lookup result"
|
|
10440
10443
|
);
|
|
10441
10444
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
10442
|
-
|
|
10445
|
+
logger23.info(
|
|
10443
10446
|
{ sessionId, conversationId: conversation?.id },
|
|
10444
10447
|
"MCP session not found or invalid"
|
|
10445
10448
|
);
|
|
@@ -10488,7 +10491,7 @@ var processUserMessage = async (tenantId, projectId, conversationId, query) => {
|
|
|
10488
10491
|
messageType: "chat"
|
|
10489
10492
|
});
|
|
10490
10493
|
};
|
|
10491
|
-
var executeAgentQuery = async (executionContext, conversationId, query,
|
|
10494
|
+
var executeAgentQuery = async (executionContext, conversationId, query, defaultSubAgentId) => {
|
|
10492
10495
|
const requestId2 = `mcp-${Date.now()}`;
|
|
10493
10496
|
const mcpStreamHelper = createMCPStreamHelper();
|
|
10494
10497
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10496,11 +10499,11 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10496
10499
|
executionContext,
|
|
10497
10500
|
conversationId,
|
|
10498
10501
|
userMessage: query,
|
|
10499
|
-
initialAgentId:
|
|
10502
|
+
initialAgentId: defaultSubAgentId,
|
|
10500
10503
|
requestId: requestId2,
|
|
10501
10504
|
sseHelper: mcpStreamHelper
|
|
10502
10505
|
});
|
|
10503
|
-
|
|
10506
|
+
logger23.info(
|
|
10504
10507
|
{ result },
|
|
10505
10508
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10506
10509
|
);
|
|
@@ -10527,7 +10530,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10527
10530
|
var getServer = async (headers, executionContext, conversationId, credentialStores) => {
|
|
10528
10531
|
const { tenantId, projectId, graphId } = executionContext;
|
|
10529
10532
|
setupTracing(conversationId, tenantId, graphId);
|
|
10530
|
-
const agentGraph = await
|
|
10533
|
+
const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10531
10534
|
scopes: { tenantId, projectId, graphId }
|
|
10532
10535
|
});
|
|
10533
10536
|
if (!agentGraph) {
|
|
@@ -10548,7 +10551,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
10548
10551
|
},
|
|
10549
10552
|
async ({ query }) => {
|
|
10550
10553
|
try {
|
|
10551
|
-
if (!agentGraph.
|
|
10554
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
10552
10555
|
return {
|
|
10553
10556
|
content: [
|
|
10554
10557
|
{
|
|
@@ -10559,10 +10562,10 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
10559
10562
|
isError: true
|
|
10560
10563
|
};
|
|
10561
10564
|
}
|
|
10562
|
-
const
|
|
10563
|
-
const agentInfo = await
|
|
10565
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
10566
|
+
const agentInfo = await getSubAgentById(dbClient_default)({
|
|
10564
10567
|
scopes: { tenantId, projectId, graphId },
|
|
10565
|
-
|
|
10568
|
+
subAgentId: defaultSubAgentId
|
|
10566
10569
|
});
|
|
10567
10570
|
if (!agentInfo) {
|
|
10568
10571
|
return {
|
|
@@ -10584,7 +10587,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
10584
10587
|
dbClient: dbClient_default,
|
|
10585
10588
|
credentialStores
|
|
10586
10589
|
});
|
|
10587
|
-
|
|
10590
|
+
logger23.info(
|
|
10588
10591
|
{
|
|
10589
10592
|
tenantId,
|
|
10590
10593
|
projectId,
|
|
@@ -10597,7 +10600,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
10597
10600
|
"parameters"
|
|
10598
10601
|
);
|
|
10599
10602
|
await processUserMessage(tenantId, projectId, conversationId, query);
|
|
10600
|
-
return executeAgentQuery(executionContext, conversationId, query,
|
|
10603
|
+
return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
|
|
10601
10604
|
} catch (error) {
|
|
10602
10605
|
return {
|
|
10603
10606
|
content: [
|
|
@@ -10646,9 +10649,9 @@ var validateRequestParameters = (c) => {
|
|
|
10646
10649
|
};
|
|
10647
10650
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
10648
10651
|
const { tenantId, projectId, graphId } = executionContext;
|
|
10649
|
-
|
|
10652
|
+
logger23.info({ body }, "Received initialization request");
|
|
10650
10653
|
const sessionId = getConversationId();
|
|
10651
|
-
const agentGraph = await
|
|
10654
|
+
const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10652
10655
|
scopes: { tenantId, projectId, graphId }
|
|
10653
10656
|
});
|
|
10654
10657
|
if (!agentGraph) {
|
|
@@ -10661,7 +10664,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10661
10664
|
{ status: 404 }
|
|
10662
10665
|
);
|
|
10663
10666
|
}
|
|
10664
|
-
if (!agentGraph.
|
|
10667
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
10665
10668
|
return c.json(
|
|
10666
10669
|
{
|
|
10667
10670
|
jsonrpc: "2.0",
|
|
@@ -10675,7 +10678,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10675
10678
|
id: sessionId,
|
|
10676
10679
|
tenantId,
|
|
10677
10680
|
projectId,
|
|
10678
|
-
|
|
10681
|
+
activeSubAgentId: agentGraph.defaultSubAgentId,
|
|
10679
10682
|
metadata: {
|
|
10680
10683
|
sessionData: {
|
|
10681
10684
|
graphId,
|
|
@@ -10686,7 +10689,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10686
10689
|
}
|
|
10687
10690
|
}
|
|
10688
10691
|
});
|
|
10689
|
-
|
|
10692
|
+
logger23.info(
|
|
10690
10693
|
{ sessionId, conversationId: conversation.id },
|
|
10691
10694
|
"Created MCP session as conversation"
|
|
10692
10695
|
);
|
|
@@ -10695,9 +10698,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10695
10698
|
});
|
|
10696
10699
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
10697
10700
|
await server.connect(transport);
|
|
10698
|
-
|
|
10701
|
+
logger23.info({ sessionId }, "Server connected for initialization");
|
|
10699
10702
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
10700
|
-
|
|
10703
|
+
logger23.info(
|
|
10701
10704
|
{
|
|
10702
10705
|
sessionId,
|
|
10703
10706
|
bodyMethod: body?.method,
|
|
@@ -10706,7 +10709,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10706
10709
|
"About to handle initialization request"
|
|
10707
10710
|
);
|
|
10708
10711
|
await transport.handleRequest(req, res, body);
|
|
10709
|
-
|
|
10712
|
+
logger23.info({ sessionId }, "Successfully handled initialization request");
|
|
10710
10713
|
return toFetchResponse(res);
|
|
10711
10714
|
};
|
|
10712
10715
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -10734,8 +10737,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10734
10737
|
sessionId,
|
|
10735
10738
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
10736
10739
|
);
|
|
10737
|
-
|
|
10738
|
-
|
|
10740
|
+
logger23.info({ sessionId }, "Server connected and transport initialized");
|
|
10741
|
+
logger23.info(
|
|
10739
10742
|
{
|
|
10740
10743
|
sessionId,
|
|
10741
10744
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -10749,9 +10752,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10749
10752
|
);
|
|
10750
10753
|
try {
|
|
10751
10754
|
await transport.handleRequest(req, res, body);
|
|
10752
|
-
|
|
10755
|
+
logger23.info({ sessionId }, "Successfully handled MCP request");
|
|
10753
10756
|
} catch (transportError) {
|
|
10754
|
-
|
|
10757
|
+
logger23.error(
|
|
10755
10758
|
{
|
|
10756
10759
|
sessionId,
|
|
10757
10760
|
error: transportError,
|
|
@@ -10802,13 +10805,13 @@ app4.openapi(
|
|
|
10802
10805
|
}
|
|
10803
10806
|
const { executionContext } = paramValidation;
|
|
10804
10807
|
const body = c.get("requestBody") || {};
|
|
10805
|
-
|
|
10808
|
+
logger23.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
10806
10809
|
const isInitRequest = body.method === "initialize";
|
|
10807
10810
|
const { req, res } = toReqRes(c.req.raw);
|
|
10808
10811
|
const validatedContext = c.get("validatedContext") || {};
|
|
10809
10812
|
const credentialStores = c.get("credentialStores");
|
|
10810
|
-
|
|
10811
|
-
|
|
10813
|
+
logger23.info({ validatedContext }, "Validated context");
|
|
10814
|
+
logger23.info({ req }, "request");
|
|
10812
10815
|
if (isInitRequest) {
|
|
10813
10816
|
return await handleInitializationRequest(
|
|
10814
10817
|
body,
|
|
@@ -10830,7 +10833,7 @@ app4.openapi(
|
|
|
10830
10833
|
);
|
|
10831
10834
|
}
|
|
10832
10835
|
} catch (e) {
|
|
10833
|
-
|
|
10836
|
+
logger23.error(
|
|
10834
10837
|
{
|
|
10835
10838
|
error: e instanceof Error ? e.message : e,
|
|
10836
10839
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -10842,7 +10845,7 @@ app4.openapi(
|
|
|
10842
10845
|
}
|
|
10843
10846
|
);
|
|
10844
10847
|
app4.get("/", async (c) => {
|
|
10845
|
-
|
|
10848
|
+
logger23.info({}, "Received GET MCP request");
|
|
10846
10849
|
return c.json(
|
|
10847
10850
|
{
|
|
10848
10851
|
jsonrpc: "2.0",
|
|
@@ -10856,7 +10859,7 @@ app4.get("/", async (c) => {
|
|
|
10856
10859
|
);
|
|
10857
10860
|
});
|
|
10858
10861
|
app4.delete("/", async (c) => {
|
|
10859
|
-
|
|
10862
|
+
logger23.info({}, "Received DELETE MCP request");
|
|
10860
10863
|
return c.json(
|
|
10861
10864
|
{
|
|
10862
10865
|
jsonrpc: "2.0",
|
|
@@ -10869,7 +10872,7 @@ app4.delete("/", async (c) => {
|
|
|
10869
10872
|
var mcp_default = app4;
|
|
10870
10873
|
|
|
10871
10874
|
// src/app.ts
|
|
10872
|
-
var
|
|
10875
|
+
var logger24 = getLogger("agents-run-api");
|
|
10873
10876
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
10874
10877
|
const app6 = new OpenAPIHono();
|
|
10875
10878
|
app6.use("*", otel());
|
|
@@ -10885,7 +10888,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10885
10888
|
const body = await c.req.json();
|
|
10886
10889
|
c.set("requestBody", body);
|
|
10887
10890
|
} catch (error) {
|
|
10888
|
-
|
|
10891
|
+
logger24.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
10889
10892
|
}
|
|
10890
10893
|
}
|
|
10891
10894
|
return next();
|
|
@@ -10936,8 +10939,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10936
10939
|
if (!isExpectedError) {
|
|
10937
10940
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
10938
10941
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
10939
|
-
if (
|
|
10940
|
-
|
|
10942
|
+
if (logger24) {
|
|
10943
|
+
logger24.error(
|
|
10941
10944
|
{
|
|
10942
10945
|
error: err,
|
|
10943
10946
|
message: errorMessage,
|
|
@@ -10949,8 +10952,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10949
10952
|
);
|
|
10950
10953
|
}
|
|
10951
10954
|
} else {
|
|
10952
|
-
if (
|
|
10953
|
-
|
|
10955
|
+
if (logger24) {
|
|
10956
|
+
logger24.error(
|
|
10954
10957
|
{
|
|
10955
10958
|
error: err,
|
|
10956
10959
|
path: c.req.path,
|
|
@@ -10967,8 +10970,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10967
10970
|
const response = err.getResponse();
|
|
10968
10971
|
return response;
|
|
10969
10972
|
} catch (responseError) {
|
|
10970
|
-
if (
|
|
10971
|
-
|
|
10973
|
+
if (logger24) {
|
|
10974
|
+
logger24.error({ error: responseError }, "Error while handling HTTPException response");
|
|
10972
10975
|
}
|
|
10973
10976
|
}
|
|
10974
10977
|
}
|
|
@@ -11002,7 +11005,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11002
11005
|
app6.use("*", async (c, next) => {
|
|
11003
11006
|
const executionContext = c.get("executionContext");
|
|
11004
11007
|
if (!executionContext) {
|
|
11005
|
-
|
|
11008
|
+
logger24.debug({}, "Empty execution context");
|
|
11006
11009
|
return next();
|
|
11007
11010
|
}
|
|
11008
11011
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11011,7 +11014,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11011
11014
|
if (requestBody) {
|
|
11012
11015
|
conversationId = requestBody.conversationId;
|
|
11013
11016
|
if (!conversationId) {
|
|
11014
|
-
|
|
11017
|
+
logger24.debug({ requestBody }, "No conversation ID found in request body");
|
|
11015
11018
|
}
|
|
11016
11019
|
}
|
|
11017
11020
|
const entries = Object.fromEntries(
|
|
@@ -11026,7 +11029,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11026
11029
|
})
|
|
11027
11030
|
);
|
|
11028
11031
|
if (!Object.keys(entries).length) {
|
|
11029
|
-
|
|
11032
|
+
logger24.debug({}, "Empty entries for baggage");
|
|
11030
11033
|
return next();
|
|
11031
11034
|
}
|
|
11032
11035
|
const bag = Object.entries(entries).reduce(
|