@inkeep/agents-run-api 0.0.0-dev-20251009192735 → 0.0.0-dev-20251009215610
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.cjs
CHANGED
|
@@ -198,8 +198,8 @@ async function saveA2AMessageResponse(response, params) {
|
|
|
198
198
|
},
|
|
199
199
|
visibility: params.visibility,
|
|
200
200
|
messageType: params.messageType,
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
fromSubAgentId: params.fromSubAgentId,
|
|
202
|
+
toSubAgentId: params.toSubAgentId,
|
|
203
203
|
fromExternalAgentId: params.fromExternalAgentId,
|
|
204
204
|
toExternalAgentId: params.toExternalAgentId,
|
|
205
205
|
a2aTaskId: params.a2aTaskId,
|
|
@@ -220,23 +220,23 @@ async function getScopedHistory({
|
|
|
220
220
|
conversationId,
|
|
221
221
|
options
|
|
222
222
|
});
|
|
223
|
-
if (!filters || !filters.
|
|
223
|
+
if (!filters || !filters.subAgentId && !filters.taskId) {
|
|
224
224
|
return messages;
|
|
225
225
|
}
|
|
226
226
|
const relevantMessages = messages.filter((msg) => {
|
|
227
227
|
if (msg.role === "user") return true;
|
|
228
228
|
let matchesAgent = true;
|
|
229
229
|
let matchesTask = true;
|
|
230
|
-
if (filters.
|
|
231
|
-
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.
|
|
230
|
+
if (filters.subAgentId) {
|
|
231
|
+
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.subAgentId || msg.fromAgentId === filters.subAgentId;
|
|
232
232
|
}
|
|
233
233
|
if (filters.taskId) {
|
|
234
234
|
matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
|
|
235
235
|
}
|
|
236
|
-
if (filters.
|
|
236
|
+
if (filters.subAgentId && filters.taskId) {
|
|
237
237
|
return matchesAgent && matchesTask;
|
|
238
238
|
}
|
|
239
|
-
if (filters.
|
|
239
|
+
if (filters.subAgentId) {
|
|
240
240
|
return matchesAgent;
|
|
241
241
|
}
|
|
242
242
|
if (filters.taskId) {
|
|
@@ -337,7 +337,9 @@ async function getConversationScopedArtifacts(params) {
|
|
|
337
337
|
if (visibleMessages.length === 0) {
|
|
338
338
|
return [];
|
|
339
339
|
}
|
|
340
|
-
const visibleMessageIds = visibleMessages.filter(
|
|
340
|
+
const visibleMessageIds = visibleMessages.filter(
|
|
341
|
+
(msg) => !(msg.messageType === "system" && msg.content?.text?.includes("Previous conversation history truncated"))
|
|
342
|
+
).map((msg) => msg.id);
|
|
341
343
|
if (visibleMessageIds.length === 0) {
|
|
342
344
|
return [];
|
|
343
345
|
}
|
|
@@ -352,8 +354,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
352
354
|
});
|
|
353
355
|
referenceArtifacts.push(...artifacts);
|
|
354
356
|
}
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
358
|
+
logger27.debug(
|
|
357
359
|
{
|
|
358
360
|
conversationId,
|
|
359
361
|
visibleMessages: visibleMessages.length,
|
|
@@ -365,8 +367,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
365
367
|
);
|
|
366
368
|
return referenceArtifacts;
|
|
367
369
|
} catch (error) {
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
371
|
+
logger27.error(
|
|
370
372
|
{
|
|
371
373
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
372
374
|
conversationId
|
|
@@ -387,10 +389,10 @@ var LocalSandboxExecutor_exports = {};
|
|
|
387
389
|
__export(LocalSandboxExecutor_exports, {
|
|
388
390
|
LocalSandboxExecutor: () => LocalSandboxExecutor
|
|
389
391
|
});
|
|
390
|
-
var
|
|
392
|
+
var logger17, _LocalSandboxExecutor, LocalSandboxExecutor;
|
|
391
393
|
var init_LocalSandboxExecutor = __esm({
|
|
392
394
|
"src/tools/LocalSandboxExecutor.ts"() {
|
|
393
|
-
|
|
395
|
+
logger17 = agentsCore.getLogger("local-sandbox-executor");
|
|
394
396
|
_LocalSandboxExecutor = class _LocalSandboxExecutor {
|
|
395
397
|
constructor() {
|
|
396
398
|
__publicField(this, "tempDir");
|
|
@@ -426,7 +428,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
426
428
|
if (now - sandbox.lastUsed < this.POOL_TTL && sandbox.useCount < this.MAX_USE_COUNT) {
|
|
427
429
|
sandbox.lastUsed = now;
|
|
428
430
|
sandbox.useCount++;
|
|
429
|
-
|
|
431
|
+
logger17.debug(
|
|
430
432
|
{
|
|
431
433
|
poolKey,
|
|
432
434
|
useCount: sandbox.useCount,
|
|
@@ -454,14 +456,14 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
454
456
|
useCount: 1,
|
|
455
457
|
dependencies
|
|
456
458
|
};
|
|
457
|
-
|
|
459
|
+
logger17.debug({ poolKey, sandboxDir }, "Added sandbox to pool");
|
|
458
460
|
}
|
|
459
461
|
cleanupSandbox(sandboxDir) {
|
|
460
462
|
try {
|
|
461
463
|
fs.rmSync(sandboxDir, { recursive: true, force: true });
|
|
462
|
-
|
|
464
|
+
logger17.debug({ sandboxDir }, "Cleaned up sandbox");
|
|
463
465
|
} catch (error) {
|
|
464
|
-
|
|
466
|
+
logger17.warn({ sandboxDir, error }, "Failed to clean up sandbox");
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
startPoolCleanup() {
|
|
@@ -478,7 +480,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
478
480
|
delete this.sandboxPool[key];
|
|
479
481
|
});
|
|
480
482
|
if (keysToDelete.length > 0) {
|
|
481
|
-
|
|
483
|
+
logger17.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
482
484
|
}
|
|
483
485
|
}, 6e4);
|
|
484
486
|
}
|
|
@@ -504,7 +506,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
504
506
|
const hasEsmSyntax = esmPatterns.some((pattern) => pattern.test(executeCode));
|
|
505
507
|
const hasCjsSyntax = cjsPatterns.some((pattern) => pattern.test(executeCode));
|
|
506
508
|
if (hasEsmSyntax && hasCjsSyntax) {
|
|
507
|
-
|
|
509
|
+
logger17.warn(
|
|
508
510
|
{ executeCode: `${executeCode.substring(0, 100)}...` },
|
|
509
511
|
"Both ESM and CommonJS syntax detected, defaulting to ESM"
|
|
510
512
|
);
|
|
@@ -521,7 +523,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
521
523
|
async executeFunctionTool(toolId, args, config) {
|
|
522
524
|
const dependencies = config.dependencies || {};
|
|
523
525
|
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
524
|
-
|
|
526
|
+
logger17.debug(
|
|
525
527
|
{
|
|
526
528
|
toolId,
|
|
527
529
|
dependencies,
|
|
@@ -536,7 +538,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
536
538
|
sandboxDir = path.join(this.tempDir, `sandbox-${dependencyHash}-${Date.now()}`);
|
|
537
539
|
fs.mkdirSync(sandboxDir, { recursive: true });
|
|
538
540
|
isNewSandbox = true;
|
|
539
|
-
|
|
541
|
+
logger17.debug(
|
|
540
542
|
{
|
|
541
543
|
toolId,
|
|
542
544
|
dependencyHash,
|
|
@@ -595,15 +597,15 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
595
597
|
});
|
|
596
598
|
npm.on("close", (code) => {
|
|
597
599
|
if (code === 0) {
|
|
598
|
-
|
|
600
|
+
logger17.debug({ sandboxDir }, "Dependencies installed successfully");
|
|
599
601
|
resolve();
|
|
600
602
|
} else {
|
|
601
|
-
|
|
603
|
+
logger17.error({ sandboxDir, code, stderr }, "Failed to install dependencies");
|
|
602
604
|
reject(new Error(`npm install failed with code ${code}: ${stderr}`));
|
|
603
605
|
}
|
|
604
606
|
});
|
|
605
607
|
npm.on("error", (err) => {
|
|
606
|
-
|
|
608
|
+
logger17.error({ sandboxDir, error: err }, "Failed to spawn npm install");
|
|
607
609
|
reject(err);
|
|
608
610
|
});
|
|
609
611
|
});
|
|
@@ -644,7 +646,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
644
646
|
stderr += dataStr;
|
|
645
647
|
});
|
|
646
648
|
const timeoutId = setTimeout(() => {
|
|
647
|
-
|
|
649
|
+
logger17.warn({ sandboxDir, timeout }, "Function execution timed out, killing process");
|
|
648
650
|
node.kill("SIGTERM");
|
|
649
651
|
setTimeout(() => {
|
|
650
652
|
try {
|
|
@@ -665,18 +667,18 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
665
667
|
reject(new Error(result.error || "Function execution failed"));
|
|
666
668
|
}
|
|
667
669
|
} catch (parseError) {
|
|
668
|
-
|
|
670
|
+
logger17.error({ stdout, stderr, parseError }, "Failed to parse function result");
|
|
669
671
|
reject(new Error(`Invalid function result: ${stdout}`));
|
|
670
672
|
}
|
|
671
673
|
} else {
|
|
672
674
|
const errorMsg = signal ? `Function execution killed by signal ${signal}: ${stderr}` : `Function execution failed with code ${code}: ${stderr}`;
|
|
673
|
-
|
|
675
|
+
logger17.error({ code, signal, stderr }, "Function execution failed");
|
|
674
676
|
reject(new Error(errorMsg));
|
|
675
677
|
}
|
|
676
678
|
});
|
|
677
679
|
node.on("error", (error) => {
|
|
678
680
|
clearTimeout(timeoutId);
|
|
679
|
-
|
|
681
|
+
logger17.error({ sandboxDir, error }, "Failed to spawn node process");
|
|
680
682
|
reject(error);
|
|
681
683
|
});
|
|
682
684
|
});
|
|
@@ -807,7 +809,7 @@ function createExecutionContext(params) {
|
|
|
807
809
|
graphId: params.graphId,
|
|
808
810
|
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
809
811
|
apiKeyId: params.apiKeyId,
|
|
810
|
-
|
|
812
|
+
subAgentId: params.subAgentId
|
|
811
813
|
};
|
|
812
814
|
}
|
|
813
815
|
|
|
@@ -822,16 +824,18 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
822
824
|
const tenantId = c.req.header("x-inkeep-tenant-id");
|
|
823
825
|
const projectId = c.req.header("x-inkeep-project-id");
|
|
824
826
|
const graphId = c.req.header("x-inkeep-graph-id");
|
|
825
|
-
const
|
|
826
|
-
const proto = c.req.header("x-forwarded-proto")
|
|
827
|
-
const
|
|
828
|
-
const
|
|
827
|
+
const subAgentId = c.req.header("x-inkeep-agent-id");
|
|
828
|
+
const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
|
|
829
|
+
const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
|
|
830
|
+
const host = fwdHost ?? c.req.header("host");
|
|
831
|
+
const reqUrl = new URL(c.req.url);
|
|
832
|
+
const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
|
|
829
833
|
if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
|
|
830
834
|
let executionContext;
|
|
831
835
|
if (authHeader?.startsWith("Bearer ")) {
|
|
832
836
|
try {
|
|
833
837
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
834
|
-
executionContext.
|
|
838
|
+
executionContext.subAgentId = subAgentId;
|
|
835
839
|
logger2.info({}, "Development/test environment - API key authenticated successfully");
|
|
836
840
|
} catch {
|
|
837
841
|
executionContext = createExecutionContext({
|
|
@@ -841,7 +845,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
841
845
|
graphId: graphId || "test-graph",
|
|
842
846
|
apiKeyId: "test-key",
|
|
843
847
|
baseUrl,
|
|
844
|
-
|
|
848
|
+
subAgentId
|
|
845
849
|
});
|
|
846
850
|
logger2.info(
|
|
847
851
|
{},
|
|
@@ -856,7 +860,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
856
860
|
graphId: graphId || "test-graph",
|
|
857
861
|
apiKeyId: "test-key",
|
|
858
862
|
baseUrl,
|
|
859
|
-
|
|
863
|
+
subAgentId
|
|
860
864
|
});
|
|
861
865
|
logger2.info(
|
|
862
866
|
{},
|
|
@@ -887,7 +891,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
887
891
|
graphId,
|
|
888
892
|
apiKeyId: "bypass",
|
|
889
893
|
baseUrl,
|
|
890
|
-
|
|
894
|
+
subAgentId
|
|
891
895
|
});
|
|
892
896
|
c.set("executionContext", executionContext);
|
|
893
897
|
logger2.info({}, "Bypass secret authenticated successfully");
|
|
@@ -895,7 +899,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
895
899
|
return;
|
|
896
900
|
} else if (apiKey) {
|
|
897
901
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
898
|
-
executionContext.
|
|
902
|
+
executionContext.subAgentId = subAgentId;
|
|
899
903
|
c.set("executionContext", executionContext);
|
|
900
904
|
logger2.info({}, "API key authenticated successfully");
|
|
901
905
|
await next();
|
|
@@ -913,14 +917,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
913
917
|
}
|
|
914
918
|
try {
|
|
915
919
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
916
|
-
executionContext.
|
|
920
|
+
executionContext.subAgentId = subAgentId;
|
|
917
921
|
c.set("executionContext", executionContext);
|
|
918
922
|
logger2.debug(
|
|
919
923
|
{
|
|
920
924
|
tenantId: executionContext.tenantId,
|
|
921
925
|
projectId: executionContext.projectId,
|
|
922
926
|
graphId: executionContext.graphId,
|
|
923
|
-
|
|
927
|
+
subAgentId: executionContext.subAgentId
|
|
924
928
|
},
|
|
925
929
|
"API key authenticated successfully"
|
|
926
930
|
);
|
|
@@ -1095,7 +1099,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1095
1099
|
logger3.warn(
|
|
1096
1100
|
{
|
|
1097
1101
|
taskId: task.id,
|
|
1098
|
-
|
|
1102
|
+
subAgentId: agent.subAgentId,
|
|
1099
1103
|
originalMessage: params.message
|
|
1100
1104
|
},
|
|
1101
1105
|
"Created fallback message content for empty delegation message"
|
|
@@ -1116,7 +1120,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1116
1120
|
taskContextId: task.context?.conversationId,
|
|
1117
1121
|
metadataContextId: params.message.metadata?.conversationId,
|
|
1118
1122
|
finalContextId: effectiveContextId,
|
|
1119
|
-
|
|
1123
|
+
subAgentId: agent.subAgentId
|
|
1120
1124
|
},
|
|
1121
1125
|
"A2A contextId resolution for delegation"
|
|
1122
1126
|
);
|
|
@@ -1132,11 +1136,11 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1132
1136
|
message_id: params.message.messageId || "",
|
|
1133
1137
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1134
1138
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1135
|
-
agent_id: agent.
|
|
1139
|
+
agent_id: agent.subAgentId,
|
|
1136
1140
|
graph_id: graphId || "",
|
|
1137
1141
|
stream_request_id: params.message.metadata?.stream_request_id
|
|
1138
1142
|
},
|
|
1139
|
-
|
|
1143
|
+
subAgentId: agent.subAgentId,
|
|
1140
1144
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1141
1145
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1142
1146
|
});
|
|
@@ -1159,17 +1163,17 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1159
1163
|
};
|
|
1160
1164
|
if (params.message.metadata?.fromAgentId) {
|
|
1161
1165
|
messageData.fromAgentId = params.message.metadata.fromAgentId;
|
|
1162
|
-
messageData.toAgentId = agent.
|
|
1166
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1163
1167
|
} else if (params.message.metadata?.fromExternalAgentId) {
|
|
1164
1168
|
messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
|
|
1165
|
-
messageData.toAgentId = agent.
|
|
1169
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1166
1170
|
}
|
|
1167
1171
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
1168
1172
|
logger3.info(
|
|
1169
1173
|
{
|
|
1170
1174
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1171
1175
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1172
|
-
toAgentId: agent.
|
|
1176
|
+
toAgentId: agent.subAgentId,
|
|
1173
1177
|
conversationId: effectiveContextId,
|
|
1174
1178
|
messageType: "a2a-request",
|
|
1175
1179
|
taskId: task.id
|
|
@@ -1182,7 +1186,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1182
1186
|
error,
|
|
1183
1187
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1184
1188
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1185
|
-
toAgentId: agent.
|
|
1189
|
+
toAgentId: agent.subAgentId,
|
|
1186
1190
|
conversationId: effectiveContextId
|
|
1187
1191
|
},
|
|
1188
1192
|
"Failed to store A2A message in database"
|
|
@@ -1199,7 +1203,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1199
1203
|
message_id: params.message.messageId || "",
|
|
1200
1204
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1201
1205
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1202
|
-
agent_id: agent.
|
|
1206
|
+
agent_id: agent.subAgentId,
|
|
1203
1207
|
graph_id: graphId || ""
|
|
1204
1208
|
}
|
|
1205
1209
|
}
|
|
@@ -1233,7 +1237,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1233
1237
|
kind: "data",
|
|
1234
1238
|
data: {
|
|
1235
1239
|
type: "transfer",
|
|
1236
|
-
|
|
1240
|
+
targetSubAgentId: transferPart.data.target
|
|
1237
1241
|
}
|
|
1238
1242
|
},
|
|
1239
1243
|
{
|
|
@@ -1533,7 +1537,7 @@ async function handleGetCapabilities(c, agent, request) {
|
|
|
1533
1537
|
async function handleGetStatus(c, agent, request) {
|
|
1534
1538
|
return c.json({
|
|
1535
1539
|
jsonrpc: "2.0",
|
|
1536
|
-
result: { status: "ready",
|
|
1540
|
+
result: { status: "ready", subAgentId: agent.subAgentId },
|
|
1537
1541
|
id: request.id
|
|
1538
1542
|
});
|
|
1539
1543
|
}
|
|
@@ -1597,7 +1601,6 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
1597
1601
|
}
|
|
1598
1602
|
}
|
|
1599
1603
|
init_dbClient();
|
|
1600
|
-
agentsCore.getLogger("agents");
|
|
1601
1604
|
function createAgentCard({
|
|
1602
1605
|
dbAgent,
|
|
1603
1606
|
baseUrl
|
|
@@ -1675,7 +1678,7 @@ async function hydrateAgent({
|
|
|
1675
1678
|
tenantId: dbAgent.tenantId,
|
|
1676
1679
|
projectId: dbAgent.projectId,
|
|
1677
1680
|
graphId,
|
|
1678
|
-
|
|
1681
|
+
subAgentId: dbAgent.id,
|
|
1679
1682
|
baseUrl,
|
|
1680
1683
|
apiKey
|
|
1681
1684
|
});
|
|
@@ -1685,7 +1688,7 @@ async function hydrateAgent({
|
|
|
1685
1688
|
baseUrl
|
|
1686
1689
|
});
|
|
1687
1690
|
return {
|
|
1688
|
-
|
|
1691
|
+
subAgentId: dbAgent.id,
|
|
1689
1692
|
tenantId: dbAgent.tenantId,
|
|
1690
1693
|
projectId: dbAgent.projectId,
|
|
1691
1694
|
graphId,
|
|
@@ -1698,13 +1701,13 @@ async function hydrateAgent({
|
|
|
1698
1701
|
}
|
|
1699
1702
|
}
|
|
1700
1703
|
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
1701
|
-
const { tenantId, projectId, graphId,
|
|
1702
|
-
if (!
|
|
1704
|
+
const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
1705
|
+
if (!subAgentId) {
|
|
1703
1706
|
throw new Error("Agent ID is required");
|
|
1704
1707
|
}
|
|
1705
|
-
const dbAgent = await agentsCore.
|
|
1708
|
+
const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
1706
1709
|
scopes: { tenantId, projectId, graphId },
|
|
1707
|
-
|
|
1710
|
+
subAgentId
|
|
1708
1711
|
});
|
|
1709
1712
|
if (!dbAgent) {
|
|
1710
1713
|
return null;
|
|
@@ -1725,7 +1728,7 @@ init_logger();
|
|
|
1725
1728
|
|
|
1726
1729
|
// src/agents/ModelFactory.ts
|
|
1727
1730
|
init_logger();
|
|
1728
|
-
var
|
|
1731
|
+
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
1729
1732
|
var _ModelFactory = class _ModelFactory {
|
|
1730
1733
|
/**
|
|
1731
1734
|
* Create a provider instance with custom configuration
|
|
@@ -1787,7 +1790,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1787
1790
|
}
|
|
1788
1791
|
const modelString = modelSettings.model.trim();
|
|
1789
1792
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1790
|
-
|
|
1793
|
+
logger4.debug(
|
|
1791
1794
|
{
|
|
1792
1795
|
provider,
|
|
1793
1796
|
model: modelName,
|
|
@@ -1798,7 +1801,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1798
1801
|
);
|
|
1799
1802
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1800
1803
|
if (Object.keys(providerConfig).length > 0) {
|
|
1801
|
-
|
|
1804
|
+
logger4.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1802
1805
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1803
1806
|
return customProvider.languageModel(modelName);
|
|
1804
1807
|
}
|
|
@@ -1917,7 +1920,7 @@ var ModelFactory = _ModelFactory;
|
|
|
1917
1920
|
|
|
1918
1921
|
// src/agents/ToolSessionManager.ts
|
|
1919
1922
|
init_logger();
|
|
1920
|
-
var
|
|
1923
|
+
var logger5 = agentsCore.getLogger("ToolSessionManager");
|
|
1921
1924
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1922
1925
|
// 5 minutes
|
|
1923
1926
|
constructor() {
|
|
@@ -1952,7 +1955,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1952
1955
|
createdAt: Date.now()
|
|
1953
1956
|
};
|
|
1954
1957
|
this.sessions.set(sessionId, session);
|
|
1955
|
-
|
|
1958
|
+
logger5.debug(
|
|
1956
1959
|
{
|
|
1957
1960
|
sessionId,
|
|
1958
1961
|
tenantId,
|
|
@@ -1970,10 +1973,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1970
1973
|
*/
|
|
1971
1974
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1972
1975
|
if (this.sessions.has(sessionId)) {
|
|
1973
|
-
|
|
1976
|
+
logger5.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1974
1977
|
return sessionId;
|
|
1975
1978
|
}
|
|
1976
|
-
|
|
1979
|
+
logger5.debug(
|
|
1977
1980
|
{ sessionId, tenantId, contextId, taskId },
|
|
1978
1981
|
"Creating new graph-scoped tool session"
|
|
1979
1982
|
);
|
|
@@ -1985,7 +1988,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1985
1988
|
recordToolResult(sessionId, toolResult) {
|
|
1986
1989
|
const session = this.sessions.get(sessionId);
|
|
1987
1990
|
if (!session) {
|
|
1988
|
-
|
|
1991
|
+
logger5.warn(
|
|
1989
1992
|
{
|
|
1990
1993
|
sessionId,
|
|
1991
1994
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1997,7 +2000,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1997
2000
|
return;
|
|
1998
2001
|
}
|
|
1999
2002
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
2000
|
-
|
|
2003
|
+
logger5.debug(
|
|
2001
2004
|
{
|
|
2002
2005
|
sessionId,
|
|
2003
2006
|
toolCallId: toolResult.toolCallId,
|
|
@@ -2012,7 +2015,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2012
2015
|
getToolResult(sessionId, toolCallId) {
|
|
2013
2016
|
const session = this.sessions.get(sessionId);
|
|
2014
2017
|
if (!session) {
|
|
2015
|
-
|
|
2018
|
+
logger5.warn(
|
|
2016
2019
|
{
|
|
2017
2020
|
sessionId,
|
|
2018
2021
|
toolCallId,
|
|
@@ -2025,7 +2028,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2025
2028
|
}
|
|
2026
2029
|
const result = session.toolResults.get(toolCallId);
|
|
2027
2030
|
if (!result) {
|
|
2028
|
-
|
|
2031
|
+
logger5.warn(
|
|
2029
2032
|
{
|
|
2030
2033
|
sessionId,
|
|
2031
2034
|
toolCallId,
|
|
@@ -2035,7 +2038,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2035
2038
|
"Tool result not found"
|
|
2036
2039
|
);
|
|
2037
2040
|
} else {
|
|
2038
|
-
|
|
2041
|
+
logger5.debug(
|
|
2039
2042
|
{
|
|
2040
2043
|
sessionId,
|
|
2041
2044
|
toolCallId,
|
|
@@ -2074,10 +2077,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2074
2077
|
}
|
|
2075
2078
|
for (const sessionId of expiredSessions) {
|
|
2076
2079
|
this.sessions.delete(sessionId);
|
|
2077
|
-
|
|
2080
|
+
logger5.debug({ sessionId }, "Cleaned up expired tool session");
|
|
2078
2081
|
}
|
|
2079
2082
|
if (expiredSessions.length > 0) {
|
|
2080
|
-
|
|
2083
|
+
logger5.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
2081
2084
|
}
|
|
2082
2085
|
}
|
|
2083
2086
|
};
|
|
@@ -2160,7 +2163,7 @@ function extractFullFields(schema) {
|
|
|
2160
2163
|
}
|
|
2161
2164
|
|
|
2162
2165
|
// src/services/ArtifactService.ts
|
|
2163
|
-
var
|
|
2166
|
+
var logger7 = agentsCore.getLogger("ArtifactService");
|
|
2164
2167
|
var _ArtifactService = class _ArtifactService {
|
|
2165
2168
|
constructor(context) {
|
|
2166
2169
|
this.context = context;
|
|
@@ -2192,7 +2195,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2192
2195
|
id: taskId
|
|
2193
2196
|
});
|
|
2194
2197
|
if (!task) {
|
|
2195
|
-
|
|
2198
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2196
2199
|
continue;
|
|
2197
2200
|
}
|
|
2198
2201
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2210,21 +2213,21 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2210
2213
|
}
|
|
2211
2214
|
}
|
|
2212
2215
|
} catch (error) {
|
|
2213
|
-
|
|
2216
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
2214
2217
|
}
|
|
2215
2218
|
return artifacts;
|
|
2216
2219
|
}
|
|
2217
2220
|
/**
|
|
2218
2221
|
* Create artifact from tool result and request data
|
|
2219
2222
|
*/
|
|
2220
|
-
async createArtifact(request,
|
|
2223
|
+
async createArtifact(request, subAgentId) {
|
|
2221
2224
|
if (!this.context.sessionId) {
|
|
2222
|
-
|
|
2225
|
+
logger7.warn({ request }, "No session ID available for artifact creation");
|
|
2223
2226
|
return null;
|
|
2224
2227
|
}
|
|
2225
2228
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
2226
2229
|
if (!toolResult) {
|
|
2227
|
-
|
|
2230
|
+
logger7.warn(
|
|
2228
2231
|
{ request, sessionId: this.context.sessionId },
|
|
2229
2232
|
"Tool result not found for artifact"
|
|
2230
2233
|
);
|
|
@@ -2240,7 +2243,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2240
2243
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
2241
2244
|
}
|
|
2242
2245
|
if (!selectedData) {
|
|
2243
|
-
|
|
2246
|
+
logger7.warn(
|
|
2244
2247
|
{
|
|
2245
2248
|
request,
|
|
2246
2249
|
baseSelector: request.baseSelector
|
|
@@ -2285,7 +2288,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2285
2288
|
type: request.type,
|
|
2286
2289
|
data: cleanedSummaryData
|
|
2287
2290
|
};
|
|
2288
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData,
|
|
2291
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
2289
2292
|
await this.cacheArtifact(
|
|
2290
2293
|
request.artifactId,
|
|
2291
2294
|
request.toolCallId,
|
|
@@ -2294,7 +2297,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2294
2297
|
);
|
|
2295
2298
|
return artifactData;
|
|
2296
2299
|
} catch (error) {
|
|
2297
|
-
|
|
2300
|
+
logger7.error({ error, request }, "Failed to create artifact");
|
|
2298
2301
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
2299
2302
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
2300
2303
|
}
|
|
@@ -2323,7 +2326,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2323
2326
|
}
|
|
2324
2327
|
try {
|
|
2325
2328
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2326
|
-
|
|
2329
|
+
logger7.warn(
|
|
2327
2330
|
{ artifactId, toolCallId },
|
|
2328
2331
|
"No projectId or taskId available for artifact lookup"
|
|
2329
2332
|
);
|
|
@@ -2338,7 +2341,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2338
2341
|
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
2339
2342
|
}
|
|
2340
2343
|
} catch (error) {
|
|
2341
|
-
|
|
2344
|
+
logger7.warn(
|
|
2342
2345
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2343
2346
|
"Failed to fetch artifact"
|
|
2344
2347
|
);
|
|
@@ -2369,7 +2372,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2369
2372
|
}
|
|
2370
2373
|
try {
|
|
2371
2374
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2372
|
-
|
|
2375
|
+
logger7.warn(
|
|
2373
2376
|
{ artifactId, toolCallId },
|
|
2374
2377
|
"No projectId or taskId available for artifact lookup"
|
|
2375
2378
|
);
|
|
@@ -2384,7 +2387,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2384
2387
|
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
2385
2388
|
}
|
|
2386
2389
|
} catch (error) {
|
|
2387
|
-
|
|
2390
|
+
logger7.warn(
|
|
2388
2391
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2389
2392
|
"Failed to fetch artifact"
|
|
2390
2393
|
);
|
|
@@ -2420,8 +2423,8 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2420
2423
|
/**
|
|
2421
2424
|
* Persist artifact to database via graph session
|
|
2422
2425
|
*/
|
|
2423
|
-
async persistArtifact(request, summaryData, fullData,
|
|
2424
|
-
const effectiveAgentId =
|
|
2426
|
+
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
2427
|
+
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
2425
2428
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
2426
2429
|
await graphSessionManager.recordEvent(
|
|
2427
2430
|
this.context.streamRequestId,
|
|
@@ -2434,7 +2437,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2434
2437
|
artifactType: request.type,
|
|
2435
2438
|
summaryData,
|
|
2436
2439
|
data: fullData,
|
|
2437
|
-
|
|
2440
|
+
subAgentId: effectiveAgentId,
|
|
2438
2441
|
metadata: {
|
|
2439
2442
|
toolCallId: request.toolCallId,
|
|
2440
2443
|
baseSelector: request.baseSelector,
|
|
@@ -2449,14 +2452,14 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2449
2452
|
}
|
|
2450
2453
|
);
|
|
2451
2454
|
} else {
|
|
2452
|
-
|
|
2455
|
+
logger7.warn(
|
|
2453
2456
|
{
|
|
2454
2457
|
artifactId: request.artifactId,
|
|
2455
2458
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2456
2459
|
hasAgentId: !!effectiveAgentId,
|
|
2457
2460
|
hasTaskId: !!this.context.taskId,
|
|
2458
|
-
passedAgentId:
|
|
2459
|
-
contextAgentId: this.context.
|
|
2461
|
+
passedAgentId: subAgentId,
|
|
2462
|
+
contextAgentId: this.context.subAgentId
|
|
2460
2463
|
},
|
|
2461
2464
|
"Skipping artifact_saved event - missing required context"
|
|
2462
2465
|
);
|
|
@@ -2524,7 +2527,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2524
2527
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
2525
2528
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
2526
2529
|
} catch (error) {
|
|
2527
|
-
|
|
2530
|
+
logger7.warn(
|
|
2528
2531
|
{
|
|
2529
2532
|
artifactType: artifact.type,
|
|
2530
2533
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2562,7 +2565,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2562
2565
|
artifact: artifactToSave
|
|
2563
2566
|
});
|
|
2564
2567
|
if (!result.created && result.existing) {
|
|
2565
|
-
|
|
2568
|
+
logger7.debug(
|
|
2566
2569
|
{
|
|
2567
2570
|
artifactId: artifact.artifactId,
|
|
2568
2571
|
taskId: this.context.taskId
|
|
@@ -2615,7 +2618,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2615
2618
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2616
2619
|
}
|
|
2617
2620
|
} catch (error) {
|
|
2618
|
-
|
|
2621
|
+
logger7.warn(
|
|
2619
2622
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2620
2623
|
"Failed to extract property"
|
|
2621
2624
|
);
|
|
@@ -2647,7 +2650,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2647
2650
|
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
2648
2651
|
}
|
|
2649
2652
|
} catch (error) {
|
|
2650
|
-
|
|
2653
|
+
logger7.warn(
|
|
2651
2654
|
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2652
2655
|
"Failed to extract schema field"
|
|
2653
2656
|
);
|
|
@@ -2678,7 +2681,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2678
2681
|
var ArtifactService = _ArtifactService;
|
|
2679
2682
|
|
|
2680
2683
|
// src/services/ArtifactParser.ts
|
|
2681
|
-
var
|
|
2684
|
+
var logger8 = agentsCore.getLogger("ArtifactParser");
|
|
2682
2685
|
var _ArtifactParser = class _ArtifactParser {
|
|
2683
2686
|
constructor(tenantId, options) {
|
|
2684
2687
|
__publicField(this, "artifactService");
|
|
@@ -2766,7 +2769,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2766
2769
|
attrs[key] = value;
|
|
2767
2770
|
}
|
|
2768
2771
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2769
|
-
|
|
2772
|
+
logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2770
2773
|
return null;
|
|
2771
2774
|
}
|
|
2772
2775
|
return {
|
|
@@ -2797,7 +2800,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2797
2800
|
/**
|
|
2798
2801
|
* Extract artifact data from a create annotation - delegates to service
|
|
2799
2802
|
*/
|
|
2800
|
-
async extractFromCreateAnnotation(annotation,
|
|
2803
|
+
async extractFromCreateAnnotation(annotation, subAgentId) {
|
|
2801
2804
|
const request = {
|
|
2802
2805
|
artifactId: annotation.artifactId,
|
|
2803
2806
|
toolCallId: annotation.toolCallId,
|
|
@@ -2805,21 +2808,21 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2805
2808
|
baseSelector: annotation.baseSelector,
|
|
2806
2809
|
detailsSelector: annotation.detailsSelector
|
|
2807
2810
|
};
|
|
2808
|
-
return this.artifactService.createArtifact(request,
|
|
2811
|
+
return this.artifactService.createArtifact(request, subAgentId);
|
|
2809
2812
|
}
|
|
2810
2813
|
/**
|
|
2811
2814
|
* Parse text with artifact markers into parts array
|
|
2812
2815
|
* Handles both artifact:ref and artifact:create tags
|
|
2813
2816
|
* Can work with or without pre-fetched artifact map
|
|
2814
2817
|
*/
|
|
2815
|
-
async parseText(text, artifactMap,
|
|
2818
|
+
async parseText(text, artifactMap, subAgentId) {
|
|
2816
2819
|
let processedText = text;
|
|
2817
2820
|
const createAnnotations = this.parseCreateAnnotations(text);
|
|
2818
2821
|
const createdArtifactData = /* @__PURE__ */ new Map();
|
|
2819
2822
|
const failedAnnotations = [];
|
|
2820
2823
|
for (const annotation of createAnnotations) {
|
|
2821
2824
|
try {
|
|
2822
|
-
const artifactData = await this.extractFromCreateAnnotation(annotation,
|
|
2825
|
+
const artifactData = await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
2823
2826
|
if (artifactData && annotation.raw) {
|
|
2824
2827
|
createdArtifactData.set(annotation.raw, artifactData);
|
|
2825
2828
|
} else if (annotation.raw) {
|
|
@@ -2827,7 +2830,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2827
2830
|
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
2828
2831
|
);
|
|
2829
2832
|
processedText = processedText.replace(annotation.raw, "");
|
|
2830
|
-
|
|
2833
|
+
logger8.warn(
|
|
2831
2834
|
{ annotation, artifactData },
|
|
2832
2835
|
"Removed failed artifact:create annotation from output"
|
|
2833
2836
|
);
|
|
@@ -2838,11 +2841,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2838
2841
|
if (annotation.raw) {
|
|
2839
2842
|
processedText = processedText.replace(annotation.raw, "");
|
|
2840
2843
|
}
|
|
2841
|
-
|
|
2844
|
+
logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2842
2845
|
}
|
|
2843
2846
|
}
|
|
2844
2847
|
if (failedAnnotations.length > 0) {
|
|
2845
|
-
|
|
2848
|
+
logger8.warn(
|
|
2846
2849
|
{
|
|
2847
2850
|
failedCount: failedAnnotations.length,
|
|
2848
2851
|
failures: failedAnnotations
|
|
@@ -2906,7 +2909,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2906
2909
|
/**
|
|
2907
2910
|
* Process object/dataComponents for artifact components
|
|
2908
2911
|
*/
|
|
2909
|
-
async parseObject(obj, artifactMap,
|
|
2912
|
+
async parseObject(obj, artifactMap, subAgentId) {
|
|
2910
2913
|
if (obj?.dataComponents && Array.isArray(obj.dataComponents)) {
|
|
2911
2914
|
const parts = [];
|
|
2912
2915
|
for (const component of obj.dataComponents) {
|
|
@@ -2930,7 +2933,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2930
2933
|
});
|
|
2931
2934
|
}
|
|
2932
2935
|
} else if (this.isArtifactCreateComponent(component)) {
|
|
2933
|
-
const createData = await this.extractFromArtifactCreateComponent(component,
|
|
2936
|
+
const createData = await this.extractFromArtifactCreateComponent(component, subAgentId);
|
|
2934
2937
|
if (createData) {
|
|
2935
2938
|
parts.push({
|
|
2936
2939
|
kind: "data",
|
|
@@ -2971,7 +2974,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2971
2974
|
] : [];
|
|
2972
2975
|
}
|
|
2973
2976
|
if (this.isArtifactCreateComponent(obj)) {
|
|
2974
|
-
const createData = await this.extractFromArtifactCreateComponent(obj,
|
|
2977
|
+
const createData = await this.extractFromArtifactCreateComponent(obj, subAgentId);
|
|
2975
2978
|
return createData ? [
|
|
2976
2979
|
{
|
|
2977
2980
|
kind: "data",
|
|
@@ -3003,7 +3006,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3003
3006
|
/**
|
|
3004
3007
|
* Extract artifact from ArtifactCreate component
|
|
3005
3008
|
*/
|
|
3006
|
-
async extractFromArtifactCreateComponent(component,
|
|
3009
|
+
async extractFromArtifactCreateComponent(component, subAgentId) {
|
|
3007
3010
|
const props = component.props;
|
|
3008
3011
|
if (!props) {
|
|
3009
3012
|
return null;
|
|
@@ -3015,7 +3018,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3015
3018
|
baseSelector: props.base_selector,
|
|
3016
3019
|
detailsSelector: props.details_selector || {}
|
|
3017
3020
|
};
|
|
3018
|
-
return await this.extractFromCreateAnnotation(annotation,
|
|
3021
|
+
return await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
3019
3022
|
}
|
|
3020
3023
|
/**
|
|
3021
3024
|
* Get artifact data - delegates to service
|
|
@@ -3055,7 +3058,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
3055
3058
|
var ArtifactParser = _ArtifactParser;
|
|
3056
3059
|
|
|
3057
3060
|
// src/services/GraphSession.ts
|
|
3058
|
-
var
|
|
3061
|
+
var logger9 = agentsCore.getLogger("GraphSession");
|
|
3059
3062
|
var GraphSession = class {
|
|
3060
3063
|
// Whether to send data operations
|
|
3061
3064
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -3088,7 +3091,7 @@ var GraphSession = class {
|
|
|
3088
3091
|
__publicField(this, "artifactParser");
|
|
3089
3092
|
// Session-scoped ArtifactParser instance
|
|
3090
3093
|
__publicField(this, "isEmitOperations", false);
|
|
3091
|
-
|
|
3094
|
+
logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
3092
3095
|
if (tenantId && projectId) {
|
|
3093
3096
|
toolSessionManager.createSessionWithId(
|
|
3094
3097
|
sessionId,
|
|
@@ -3102,7 +3105,6 @@ var GraphSession = class {
|
|
|
3102
3105
|
tenantId,
|
|
3103
3106
|
projectId,
|
|
3104
3107
|
sessionId,
|
|
3105
|
-
// Same ID as ToolSession
|
|
3106
3108
|
contextId,
|
|
3107
3109
|
taskId: `task_${contextId}-${messageId}`,
|
|
3108
3110
|
streamRequestId: sessionId
|
|
@@ -3123,7 +3125,7 @@ var GraphSession = class {
|
|
|
3123
3125
|
*/
|
|
3124
3126
|
enableEmitOperations() {
|
|
3125
3127
|
this.isEmitOperations = true;
|
|
3126
|
-
|
|
3128
|
+
logger9.info(
|
|
3127
3129
|
{ sessionId: this.sessionId },
|
|
3128
3130
|
"\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
|
|
3129
3131
|
);
|
|
@@ -3140,14 +3142,14 @@ var GraphSession = class {
|
|
|
3140
3142
|
label: this.generateEventLabel(event),
|
|
3141
3143
|
details: {
|
|
3142
3144
|
timestamp: event.timestamp,
|
|
3143
|
-
|
|
3145
|
+
subAgentId: event.subAgentId,
|
|
3144
3146
|
data: event.data
|
|
3145
3147
|
}
|
|
3146
3148
|
};
|
|
3147
3149
|
await streamHelper.writeOperation(formattedOperation);
|
|
3148
3150
|
}
|
|
3149
3151
|
} catch (error) {
|
|
3150
|
-
|
|
3152
|
+
logger9.error(
|
|
3151
3153
|
{
|
|
3152
3154
|
sessionId: this.sessionId,
|
|
3153
3155
|
eventType: event.eventType,
|
|
@@ -3163,29 +3165,19 @@ var GraphSession = class {
|
|
|
3163
3165
|
generateEventLabel(event) {
|
|
3164
3166
|
switch (event.eventType) {
|
|
3165
3167
|
case "agent_generate":
|
|
3166
|
-
return `Agent ${event.
|
|
3168
|
+
return `Agent ${event.subAgentId} generating response`;
|
|
3167
3169
|
case "agent_reasoning":
|
|
3168
|
-
return `Agent ${event.
|
|
3169
|
-
case "tool_execution":
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
case "
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
case "
|
|
3178
|
-
|
|
3179
|
-
return `Task delegated: ${delegationData.fromAgent} \u2192 ${delegationData.targetAgent}`;
|
|
3180
|
-
}
|
|
3181
|
-
case "delegation_returned": {
|
|
3182
|
-
const returnData = event.data;
|
|
3183
|
-
return `Task completed: ${returnData.targetAgent} \u2192 ${returnData.fromAgent}`;
|
|
3184
|
-
}
|
|
3185
|
-
case "artifact_saved": {
|
|
3186
|
-
const artifactData = event.data;
|
|
3187
|
-
return `Artifact saved: ${artifactData.artifactType || "unknown type"}`;
|
|
3188
|
-
}
|
|
3170
|
+
return `Agent ${event.subAgentId} reasoning through request`;
|
|
3171
|
+
case "tool_execution":
|
|
3172
|
+
return `Tool execution: ${event.data.toolName || "unknown"}`;
|
|
3173
|
+
case "transfer":
|
|
3174
|
+
return `Agent transfer: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3175
|
+
case "delegation_sent":
|
|
3176
|
+
return `Task delegated: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3177
|
+
case "delegation_returned":
|
|
3178
|
+
return `Task completed: ${event.data.targetSubAgent} \u2192 ${event.data.fromSubAgent}`;
|
|
3179
|
+
case "artifact_saved":
|
|
3180
|
+
return `Artifact saved: ${event.data.artifactType || "unknown type"}`;
|
|
3189
3181
|
default:
|
|
3190
3182
|
return `${event.eventType} event`;
|
|
3191
3183
|
}
|
|
@@ -3210,7 +3202,7 @@ var GraphSession = class {
|
|
|
3210
3202
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
3211
3203
|
this.statusUpdateTimer = setInterval(async () => {
|
|
3212
3204
|
if (!this.statusUpdateState || this.isEnded) {
|
|
3213
|
-
|
|
3205
|
+
logger9.debug(
|
|
3214
3206
|
{ sessionId: this.sessionId },
|
|
3215
3207
|
"Timer triggered but session already cleaned up or ended"
|
|
3216
3208
|
);
|
|
@@ -3222,7 +3214,7 @@ var GraphSession = class {
|
|
|
3222
3214
|
}
|
|
3223
3215
|
await this.checkAndSendTimeBasedUpdate();
|
|
3224
3216
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
3225
|
-
|
|
3217
|
+
logger9.info(
|
|
3226
3218
|
{
|
|
3227
3219
|
sessionId: this.sessionId,
|
|
3228
3220
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -3233,22 +3225,24 @@ var GraphSession = class {
|
|
|
3233
3225
|
}
|
|
3234
3226
|
/**
|
|
3235
3227
|
* Record an event in the session and trigger status updates if configured
|
|
3228
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
3236
3229
|
*/
|
|
3237
|
-
recordEvent(eventType,
|
|
3230
|
+
recordEvent(eventType, subAgentId, data) {
|
|
3238
3231
|
if (this.isEmitOperations) {
|
|
3239
|
-
|
|
3232
|
+
const dataOpEvent = {
|
|
3240
3233
|
timestamp: Date.now(),
|
|
3241
3234
|
eventType,
|
|
3242
|
-
|
|
3235
|
+
subAgentId,
|
|
3243
3236
|
data
|
|
3244
|
-
}
|
|
3237
|
+
};
|
|
3238
|
+
this.sendDataOperation(dataOpEvent);
|
|
3245
3239
|
}
|
|
3246
3240
|
if (this.isEnded) {
|
|
3247
|
-
|
|
3241
|
+
logger9.debug(
|
|
3248
3242
|
{
|
|
3249
3243
|
sessionId: this.sessionId,
|
|
3250
3244
|
eventType,
|
|
3251
|
-
|
|
3245
|
+
subAgentId
|
|
3252
3246
|
},
|
|
3253
3247
|
"Event received after session ended - ignoring"
|
|
3254
3248
|
);
|
|
@@ -3257,59 +3251,62 @@ var GraphSession = class {
|
|
|
3257
3251
|
const event = {
|
|
3258
3252
|
timestamp: Date.now(),
|
|
3259
3253
|
eventType,
|
|
3260
|
-
|
|
3254
|
+
subAgentId,
|
|
3261
3255
|
data
|
|
3262
3256
|
};
|
|
3263
3257
|
this.events.push(event);
|
|
3264
|
-
if (eventType === "artifact_saved"
|
|
3265
|
-
const
|
|
3266
|
-
if (
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
this.
|
|
3284
|
-
}).catch((error) => {
|
|
3285
|
-
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3286
|
-
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3287
|
-
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3258
|
+
if (eventType === "artifact_saved") {
|
|
3259
|
+
const artifactData = data;
|
|
3260
|
+
if (artifactData.pendingGeneration) {
|
|
3261
|
+
const artifactId = artifactData.artifactId;
|
|
3262
|
+
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
3263
|
+
logger9.warn(
|
|
3264
|
+
{
|
|
3265
|
+
sessionId: this.sessionId,
|
|
3266
|
+
artifactId,
|
|
3267
|
+
pendingCount: this.pendingArtifacts.size,
|
|
3268
|
+
maxAllowed: this.MAX_PENDING_ARTIFACTS
|
|
3269
|
+
},
|
|
3270
|
+
"Too many pending artifacts, skipping processing"
|
|
3271
|
+
);
|
|
3272
|
+
return;
|
|
3273
|
+
}
|
|
3274
|
+
this.pendingArtifacts.add(artifactId);
|
|
3275
|
+
setImmediate(() => {
|
|
3276
|
+
const artifactDataWithAgent = { ...artifactData, subAgentId };
|
|
3277
|
+
this.processArtifact(artifactDataWithAgent).then(() => {
|
|
3288
3278
|
this.pendingArtifacts.delete(artifactId);
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3279
|
+
this.artifactProcessingErrors.delete(artifactId);
|
|
3280
|
+
}).catch((error) => {
|
|
3281
|
+
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3282
|
+
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3283
|
+
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3284
|
+
this.pendingArtifacts.delete(artifactId);
|
|
3285
|
+
logger9.error(
|
|
3286
|
+
{
|
|
3287
|
+
sessionId: this.sessionId,
|
|
3288
|
+
artifactId,
|
|
3289
|
+
errorCount,
|
|
3290
|
+
maxRetries: this.MAX_ARTIFACT_RETRIES,
|
|
3291
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
3292
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
3293
|
+
},
|
|
3294
|
+
"Artifact processing failed after max retries, giving up"
|
|
3295
|
+
);
|
|
3296
|
+
} else {
|
|
3297
|
+
logger9.warn(
|
|
3298
|
+
{
|
|
3299
|
+
sessionId: this.sessionId,
|
|
3300
|
+
artifactId,
|
|
3301
|
+
errorCount,
|
|
3302
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
3303
|
+
},
|
|
3304
|
+
"Artifact processing failed, may retry"
|
|
3305
|
+
);
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3311
3308
|
});
|
|
3312
|
-
}
|
|
3309
|
+
}
|
|
3313
3310
|
}
|
|
3314
3311
|
if (!this.isEnded) {
|
|
3315
3312
|
this.checkStatusUpdates();
|
|
@@ -3320,14 +3317,14 @@ var GraphSession = class {
|
|
|
3320
3317
|
*/
|
|
3321
3318
|
checkStatusUpdates() {
|
|
3322
3319
|
if (this.isEnded) {
|
|
3323
|
-
|
|
3320
|
+
logger9.debug(
|
|
3324
3321
|
{ sessionId: this.sessionId },
|
|
3325
3322
|
"Session has ended - skipping status update check"
|
|
3326
3323
|
);
|
|
3327
3324
|
return;
|
|
3328
3325
|
}
|
|
3329
3326
|
if (!this.statusUpdateState) {
|
|
3330
|
-
|
|
3327
|
+
logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
3331
3328
|
return;
|
|
3332
3329
|
}
|
|
3333
3330
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -3338,11 +3335,11 @@ var GraphSession = class {
|
|
|
3338
3335
|
*/
|
|
3339
3336
|
async checkAndSendTimeBasedUpdate() {
|
|
3340
3337
|
if (this.isEnded) {
|
|
3341
|
-
|
|
3338
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
3342
3339
|
return;
|
|
3343
3340
|
}
|
|
3344
3341
|
if (!this.statusUpdateState) {
|
|
3345
|
-
|
|
3342
|
+
logger9.debug(
|
|
3346
3343
|
{ sessionId: this.sessionId },
|
|
3347
3344
|
"No status updates configured for time-based check"
|
|
3348
3345
|
);
|
|
@@ -3355,7 +3352,7 @@ var GraphSession = class {
|
|
|
3355
3352
|
try {
|
|
3356
3353
|
await this.generateAndSendUpdate();
|
|
3357
3354
|
} catch (error) {
|
|
3358
|
-
|
|
3355
|
+
logger9.error(
|
|
3359
3356
|
{
|
|
3360
3357
|
sessionId: this.sessionId,
|
|
3361
3358
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3379,8 +3376,8 @@ var GraphSession = class {
|
|
|
3379
3376
|
/**
|
|
3380
3377
|
* Get events filtered by agent
|
|
3381
3378
|
*/
|
|
3382
|
-
getEventsByAgent(
|
|
3383
|
-
return this.events.filter((event) => event.
|
|
3379
|
+
getEventsByAgent(subAgentId) {
|
|
3380
|
+
return this.events.filter((event) => event.subAgentId === subAgentId);
|
|
3384
3381
|
}
|
|
3385
3382
|
/**
|
|
3386
3383
|
* Get summary of session activity
|
|
@@ -3395,7 +3392,7 @@ var GraphSession = class {
|
|
|
3395
3392
|
);
|
|
3396
3393
|
const agentCounts = this.events.reduce(
|
|
3397
3394
|
(counts, event) => {
|
|
3398
|
-
counts[event.
|
|
3395
|
+
counts[event.subAgentId] = (counts[event.subAgentId] || 0) + 1;
|
|
3399
3396
|
return counts;
|
|
3400
3397
|
},
|
|
3401
3398
|
{}
|
|
@@ -3458,29 +3455,29 @@ var GraphSession = class {
|
|
|
3458
3455
|
*/
|
|
3459
3456
|
async generateAndSendUpdate() {
|
|
3460
3457
|
if (this.isEnded) {
|
|
3461
|
-
|
|
3458
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
3462
3459
|
return;
|
|
3463
3460
|
}
|
|
3464
3461
|
if (this.isTextStreaming) {
|
|
3465
|
-
|
|
3462
|
+
logger9.debug(
|
|
3466
3463
|
{ sessionId: this.sessionId },
|
|
3467
3464
|
"Text is currently streaming - skipping status update"
|
|
3468
3465
|
);
|
|
3469
3466
|
return;
|
|
3470
3467
|
}
|
|
3471
3468
|
if (this.isGeneratingUpdate) {
|
|
3472
|
-
|
|
3469
|
+
logger9.debug(
|
|
3473
3470
|
{ sessionId: this.sessionId },
|
|
3474
3471
|
"Update already in progress - skipping duplicate generation"
|
|
3475
3472
|
);
|
|
3476
3473
|
return;
|
|
3477
3474
|
}
|
|
3478
3475
|
if (!this.statusUpdateState) {
|
|
3479
|
-
|
|
3476
|
+
logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
3480
3477
|
return;
|
|
3481
3478
|
}
|
|
3482
3479
|
if (!this.graphId) {
|
|
3483
|
-
|
|
3480
|
+
logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
3484
3481
|
return;
|
|
3485
3482
|
}
|
|
3486
3483
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -3492,7 +3489,7 @@ var GraphSession = class {
|
|
|
3492
3489
|
try {
|
|
3493
3490
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
3494
3491
|
if (!streamHelper) {
|
|
3495
|
-
|
|
3492
|
+
logger9.warn(
|
|
3496
3493
|
{ sessionId: this.sessionId },
|
|
3497
3494
|
"No stream helper found - cannot send status update"
|
|
3498
3495
|
);
|
|
@@ -3512,7 +3509,7 @@ var GraphSession = class {
|
|
|
3512
3509
|
if (result.summaries && result.summaries.length > 0) {
|
|
3513
3510
|
for (const summary of result.summaries) {
|
|
3514
3511
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
3515
|
-
|
|
3512
|
+
logger9.warn(
|
|
3516
3513
|
{
|
|
3517
3514
|
sessionId: this.sessionId,
|
|
3518
3515
|
summary
|
|
@@ -3549,7 +3546,7 @@ var GraphSession = class {
|
|
|
3549
3546
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
3550
3547
|
}
|
|
3551
3548
|
} catch (error) {
|
|
3552
|
-
|
|
3549
|
+
logger9.error(
|
|
3553
3550
|
{
|
|
3554
3551
|
sessionId: this.sessionId,
|
|
3555
3552
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -3587,7 +3584,7 @@ var GraphSession = class {
|
|
|
3587
3584
|
this.releaseUpdateLock();
|
|
3588
3585
|
}
|
|
3589
3586
|
} catch (error) {
|
|
3590
|
-
|
|
3587
|
+
logger9.error(
|
|
3591
3588
|
{
|
|
3592
3589
|
sessionId: this.sessionId,
|
|
3593
3590
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3665,7 +3662,7 @@ User's Question/Context:
|
|
|
3665
3662
|
${conversationHistory}
|
|
3666
3663
|
` : "";
|
|
3667
3664
|
} catch (error) {
|
|
3668
|
-
|
|
3665
|
+
logger9.warn(
|
|
3669
3666
|
{ sessionId: this.sessionId, error },
|
|
3670
3667
|
"Failed to fetch conversation history for structured status update"
|
|
3671
3668
|
);
|
|
@@ -3799,7 +3796,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3799
3796
|
return { summaries };
|
|
3800
3797
|
} catch (error) {
|
|
3801
3798
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3802
|
-
|
|
3799
|
+
logger9.error({ error }, "Failed to generate structured update, using fallback");
|
|
3803
3800
|
return { summaries: [] };
|
|
3804
3801
|
} finally {
|
|
3805
3802
|
span.end();
|
|
@@ -3825,7 +3822,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3825
3822
|
*/
|
|
3826
3823
|
buildZodSchemaFromJson(jsonSchema) {
|
|
3827
3824
|
const properties = {};
|
|
3828
|
-
properties
|
|
3825
|
+
properties.label = z6.z.string().describe(
|
|
3829
3826
|
'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.'
|
|
3830
3827
|
);
|
|
3831
3828
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
@@ -3894,11 +3891,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3894
3891
|
for (const event of events) {
|
|
3895
3892
|
switch (event.eventType) {
|
|
3896
3893
|
case "tool_execution": {
|
|
3897
|
-
const
|
|
3898
|
-
const resultStr = JSON.stringify(data.result);
|
|
3894
|
+
const resultStr = JSON.stringify(event.data.result);
|
|
3899
3895
|
activities.push(
|
|
3900
|
-
`\u{1F527} **${data.toolName}** ${data.duration ? `(${data.duration}ms)` : ""}
|
|
3901
|
-
\u{1F4E5} Input: ${JSON.stringify(data.args)}
|
|
3896
|
+
`\u{1F527} **${event.data.toolName}** ${event.data.duration ? `(${event.data.duration}ms)` : ""}
|
|
3897
|
+
\u{1F4E5} Input: ${JSON.stringify(event.data.args)}
|
|
3902
3898
|
\u{1F4E4} Output: ${resultStr}`
|
|
3903
3899
|
);
|
|
3904
3900
|
break;
|
|
@@ -3910,23 +3906,24 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3910
3906
|
case "artifact_saved":
|
|
3911
3907
|
break;
|
|
3912
3908
|
case "agent_reasoning": {
|
|
3913
|
-
const data = event.data;
|
|
3914
3909
|
activities.push(
|
|
3915
3910
|
`\u2699\uFE0F **Analyzing request**
|
|
3916
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3911
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3917
3912
|
);
|
|
3918
3913
|
break;
|
|
3919
3914
|
}
|
|
3920
3915
|
case "agent_generate": {
|
|
3921
|
-
const data = event.data;
|
|
3922
3916
|
activities.push(
|
|
3923
3917
|
`\u2699\uFE0F **Preparing response**
|
|
3924
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3918
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3925
3919
|
);
|
|
3926
3920
|
break;
|
|
3927
3921
|
}
|
|
3928
3922
|
default: {
|
|
3929
|
-
|
|
3923
|
+
const safeEvent = event;
|
|
3924
|
+
activities.push(
|
|
3925
|
+
`\u{1F4CB} **${safeEvent.eventType}**: ${JSON.stringify(safeEvent.data, null, 2)}`
|
|
3926
|
+
);
|
|
3930
3927
|
break;
|
|
3931
3928
|
}
|
|
3932
3929
|
}
|
|
@@ -3944,7 +3941,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3944
3941
|
"graph_session.id": this.sessionId,
|
|
3945
3942
|
"artifact.id": artifactData.artifactId,
|
|
3946
3943
|
"artifact.type": artifactData.artifactType || "unknown",
|
|
3947
|
-
"artifact.agent_id": artifactData.
|
|
3944
|
+
"artifact.agent_id": artifactData.subAgentId || "unknown",
|
|
3948
3945
|
"artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
|
|
3949
3946
|
"artifact.data": JSON.stringify(artifactData.data, null, 2),
|
|
3950
3947
|
"tenant.id": artifactData.tenantId || "unknown",
|
|
@@ -4003,34 +4000,34 @@ Make it specific and relevant.`;
|
|
|
4003
4000
|
let modelToUse = this.statusUpdateState?.summarizerModel;
|
|
4004
4001
|
if (!modelToUse?.model?.trim()) {
|
|
4005
4002
|
if (!this.statusUpdateState?.baseModel?.model?.trim()) {
|
|
4006
|
-
if (artifactData.
|
|
4003
|
+
if (artifactData.subAgentId && artifactData.tenantId && artifactData.projectId) {
|
|
4007
4004
|
try {
|
|
4008
|
-
const agentData = await agentsCore.
|
|
4005
|
+
const agentData = await agentsCore.getSubAgentById(dbClient_default)({
|
|
4009
4006
|
scopes: {
|
|
4010
4007
|
tenantId: artifactData.tenantId,
|
|
4011
4008
|
projectId: artifactData.projectId,
|
|
4012
4009
|
graphId: this.graphId || ""
|
|
4013
4010
|
},
|
|
4014
|
-
|
|
4011
|
+
subAgentId: artifactData.subAgentId
|
|
4015
4012
|
});
|
|
4016
4013
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
4017
4014
|
modelToUse = agentData.models.base;
|
|
4018
|
-
|
|
4015
|
+
logger9.info(
|
|
4019
4016
|
{
|
|
4020
4017
|
sessionId: this.sessionId,
|
|
4021
4018
|
artifactId: artifactData.artifactId,
|
|
4022
|
-
|
|
4019
|
+
subAgentId: artifactData.subAgentId,
|
|
4023
4020
|
model: modelToUse.model
|
|
4024
4021
|
},
|
|
4025
4022
|
"Using agent model configuration for artifact name generation"
|
|
4026
4023
|
);
|
|
4027
4024
|
}
|
|
4028
4025
|
} catch (error) {
|
|
4029
|
-
|
|
4026
|
+
logger9.warn(
|
|
4030
4027
|
{
|
|
4031
4028
|
sessionId: this.sessionId,
|
|
4032
4029
|
artifactId: artifactData.artifactId,
|
|
4033
|
-
|
|
4030
|
+
subAgentId: artifactData.subAgentId,
|
|
4034
4031
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
4035
4032
|
},
|
|
4036
4033
|
"Failed to get agent model configuration"
|
|
@@ -4038,7 +4035,7 @@ Make it specific and relevant.`;
|
|
|
4038
4035
|
}
|
|
4039
4036
|
}
|
|
4040
4037
|
if (!modelToUse?.model?.trim()) {
|
|
4041
|
-
|
|
4038
|
+
logger9.warn(
|
|
4042
4039
|
{
|
|
4043
4040
|
sessionId: this.sessionId,
|
|
4044
4041
|
artifactId: artifactData.artifactId
|
|
@@ -4120,7 +4117,7 @@ Make it specific and relevant.`;
|
|
|
4120
4117
|
return result2;
|
|
4121
4118
|
} catch (error) {
|
|
4122
4119
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
4123
|
-
|
|
4120
|
+
logger9.warn(
|
|
4124
4121
|
{
|
|
4125
4122
|
sessionId: this.sessionId,
|
|
4126
4123
|
artifactId: artifactData.artifactId,
|
|
@@ -4172,7 +4169,7 @@ Make it specific and relevant.`;
|
|
|
4172
4169
|
});
|
|
4173
4170
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
4174
4171
|
} catch (saveError) {
|
|
4175
|
-
|
|
4172
|
+
logger9.error(
|
|
4176
4173
|
{
|
|
4177
4174
|
sessionId: this.sessionId,
|
|
4178
4175
|
artifactId: artifactData.artifactId,
|
|
@@ -4200,7 +4197,7 @@ Make it specific and relevant.`;
|
|
|
4200
4197
|
metadata: artifactData.metadata || {},
|
|
4201
4198
|
toolCallId: artifactData.toolCallId
|
|
4202
4199
|
});
|
|
4203
|
-
|
|
4200
|
+
logger9.info(
|
|
4204
4201
|
{
|
|
4205
4202
|
sessionId: this.sessionId,
|
|
4206
4203
|
artifactId: artifactData.artifactId
|
|
@@ -4211,7 +4208,7 @@ Make it specific and relevant.`;
|
|
|
4211
4208
|
} catch (fallbackError) {
|
|
4212
4209
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
4213
4210
|
if (isDuplicateError) ; else {
|
|
4214
|
-
|
|
4211
|
+
logger9.error(
|
|
4215
4212
|
{
|
|
4216
4213
|
sessionId: this.sessionId,
|
|
4217
4214
|
artifactId: artifactData.artifactId,
|
|
@@ -4224,7 +4221,7 @@ Make it specific and relevant.`;
|
|
|
4224
4221
|
}
|
|
4225
4222
|
} catch (error) {
|
|
4226
4223
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4227
|
-
|
|
4224
|
+
logger9.error(
|
|
4228
4225
|
{
|
|
4229
4226
|
sessionId: this.sessionId,
|
|
4230
4227
|
artifactId: artifactData.artifactId,
|
|
@@ -4243,7 +4240,7 @@ Make it specific and relevant.`;
|
|
|
4243
4240
|
*/
|
|
4244
4241
|
setArtifactCache(key, artifact) {
|
|
4245
4242
|
this.artifactCache.set(key, artifact);
|
|
4246
|
-
|
|
4243
|
+
logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
4247
4244
|
}
|
|
4248
4245
|
/**
|
|
4249
4246
|
* Get session-scoped ArtifactService instance
|
|
@@ -4262,7 +4259,7 @@ Make it specific and relevant.`;
|
|
|
4262
4259
|
*/
|
|
4263
4260
|
getArtifactCache(key) {
|
|
4264
4261
|
const artifact = this.artifactCache.get(key);
|
|
4265
|
-
|
|
4262
|
+
logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
4266
4263
|
return artifact || null;
|
|
4267
4264
|
}
|
|
4268
4265
|
/**
|
|
@@ -4285,7 +4282,7 @@ var GraphSessionManager = class {
|
|
|
4285
4282
|
const sessionId = messageId;
|
|
4286
4283
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
4287
4284
|
this.sessions.set(sessionId, session);
|
|
4288
|
-
|
|
4285
|
+
logger9.info(
|
|
4289
4286
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
4290
4287
|
"GraphSession created"
|
|
4291
4288
|
);
|
|
@@ -4299,7 +4296,7 @@ var GraphSessionManager = class {
|
|
|
4299
4296
|
if (session) {
|
|
4300
4297
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
4301
4298
|
} else {
|
|
4302
|
-
|
|
4299
|
+
logger9.error(
|
|
4303
4300
|
{
|
|
4304
4301
|
sessionId,
|
|
4305
4302
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4316,7 +4313,7 @@ var GraphSessionManager = class {
|
|
|
4316
4313
|
if (session) {
|
|
4317
4314
|
session.enableEmitOperations();
|
|
4318
4315
|
} else {
|
|
4319
|
-
|
|
4316
|
+
logger9.error(
|
|
4320
4317
|
{
|
|
4321
4318
|
sessionId,
|
|
4322
4319
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4333,14 +4330,15 @@ var GraphSessionManager = class {
|
|
|
4333
4330
|
}
|
|
4334
4331
|
/**
|
|
4335
4332
|
* Record an event in a session
|
|
4333
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
4336
4334
|
*/
|
|
4337
|
-
recordEvent(sessionId, eventType,
|
|
4335
|
+
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
4338
4336
|
const session = this.sessions.get(sessionId);
|
|
4339
4337
|
if (!session) {
|
|
4340
|
-
|
|
4338
|
+
logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
4341
4339
|
return;
|
|
4342
4340
|
}
|
|
4343
|
-
session.recordEvent(eventType,
|
|
4341
|
+
session.recordEvent(eventType, subAgentId, data);
|
|
4344
4342
|
}
|
|
4345
4343
|
/**
|
|
4346
4344
|
* End a session and return the final event data
|
|
@@ -4348,12 +4346,12 @@ var GraphSessionManager = class {
|
|
|
4348
4346
|
endSession(sessionId) {
|
|
4349
4347
|
const session = this.sessions.get(sessionId);
|
|
4350
4348
|
if (!session) {
|
|
4351
|
-
|
|
4349
|
+
logger9.warn({ sessionId }, "Attempted to end non-existent session");
|
|
4352
4350
|
return [];
|
|
4353
4351
|
}
|
|
4354
4352
|
const events = session.getEvents();
|
|
4355
4353
|
const summary = session.getSummary();
|
|
4356
|
-
|
|
4354
|
+
logger9.info({ sessionId, summary }, "GraphSession ended");
|
|
4357
4355
|
session.cleanup();
|
|
4358
4356
|
this.sessions.delete(sessionId);
|
|
4359
4357
|
return events;
|
|
@@ -4461,7 +4459,7 @@ init_logger();
|
|
|
4461
4459
|
|
|
4462
4460
|
// src/services/IncrementalStreamParser.ts
|
|
4463
4461
|
init_logger();
|
|
4464
|
-
var
|
|
4462
|
+
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
4465
4463
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
4466
4464
|
// Max number of collected parts to prevent unbounded growth
|
|
4467
4465
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -4477,10 +4475,10 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4477
4475
|
__publicField(this, "lastStreamedComponents", /* @__PURE__ */ new Map());
|
|
4478
4476
|
__publicField(this, "componentSnapshots", /* @__PURE__ */ new Map());
|
|
4479
4477
|
__publicField(this, "artifactMap");
|
|
4480
|
-
__publicField(this, "
|
|
4478
|
+
__publicField(this, "subAgentId");
|
|
4481
4479
|
this.streamHelper = streamHelper;
|
|
4482
4480
|
this.contextId = contextId;
|
|
4483
|
-
this.
|
|
4481
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4484
4482
|
if (artifactParserOptions?.streamRequestId) {
|
|
4485
4483
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4486
4484
|
artifactParserOptions.streamRequestId
|
|
@@ -4513,7 +4511,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4513
4511
|
async initializeArtifactMap() {
|
|
4514
4512
|
try {
|
|
4515
4513
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
4516
|
-
|
|
4514
|
+
logger10.debug(
|
|
4517
4515
|
{
|
|
4518
4516
|
contextId: this.contextId,
|
|
4519
4517
|
artifactMapSize: this.artifactMap.size
|
|
@@ -4521,7 +4519,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4521
4519
|
"Initialized artifact map for streaming"
|
|
4522
4520
|
);
|
|
4523
4521
|
} catch (error) {
|
|
4524
|
-
|
|
4522
|
+
logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
4525
4523
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
4526
4524
|
}
|
|
4527
4525
|
}
|
|
@@ -4623,7 +4621,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4623
4621
|
dataComponents: [component]
|
|
4624
4622
|
},
|
|
4625
4623
|
this.artifactMap,
|
|
4626
|
-
this.
|
|
4624
|
+
this.subAgentId
|
|
4627
4625
|
);
|
|
4628
4626
|
if (!Array.isArray(parts)) {
|
|
4629
4627
|
console.warn("parseObject returned non-array:", parts);
|
|
@@ -4699,7 +4697,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4699
4697
|
dataComponents: [component]
|
|
4700
4698
|
},
|
|
4701
4699
|
this.artifactMap,
|
|
4702
|
-
this.
|
|
4700
|
+
this.subAgentId
|
|
4703
4701
|
);
|
|
4704
4702
|
for (const part of parts) {
|
|
4705
4703
|
await this.streamPart(part);
|
|
@@ -4753,7 +4751,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4753
4751
|
const safeEnd = this.artifactParser.findSafeTextBoundary(workingBuffer);
|
|
4754
4752
|
if (safeEnd > 0) {
|
|
4755
4753
|
const safeText = workingBuffer.slice(0, safeEnd);
|
|
4756
|
-
const parts2 = await this.artifactParser.parseText(
|
|
4754
|
+
const parts2 = await this.artifactParser.parseText(
|
|
4755
|
+
safeText,
|
|
4756
|
+
this.artifactMap,
|
|
4757
|
+
this.subAgentId
|
|
4758
|
+
);
|
|
4757
4759
|
completeParts.push(...parts2);
|
|
4758
4760
|
return {
|
|
4759
4761
|
completeParts,
|
|
@@ -4768,7 +4770,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4768
4770
|
const parts = await this.artifactParser.parseText(
|
|
4769
4771
|
workingBuffer,
|
|
4770
4772
|
this.artifactMap,
|
|
4771
|
-
this.
|
|
4773
|
+
this.subAgentId
|
|
4772
4774
|
);
|
|
4773
4775
|
if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
|
|
4774
4776
|
const lastPart = parts[parts.length - 1];
|
|
@@ -4842,12 +4844,12 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4842
4844
|
|
|
4843
4845
|
// src/services/ResponseFormatter.ts
|
|
4844
4846
|
init_logger();
|
|
4845
|
-
var
|
|
4847
|
+
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
4846
4848
|
var ResponseFormatter = class {
|
|
4847
4849
|
constructor(tenantId, artifactParserOptions) {
|
|
4848
4850
|
__publicField(this, "artifactParser");
|
|
4849
|
-
__publicField(this, "
|
|
4850
|
-
this.
|
|
4851
|
+
__publicField(this, "subAgentId");
|
|
4852
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4851
4853
|
if (artifactParserOptions?.streamRequestId) {
|
|
4852
4854
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4853
4855
|
artifactParserOptions.streamRequestId
|
|
@@ -4886,7 +4888,7 @@ var ResponseFormatter = class {
|
|
|
4886
4888
|
const parts = await this.artifactParser.parseObject(
|
|
4887
4889
|
responseObject,
|
|
4888
4890
|
artifactMap,
|
|
4889
|
-
this.
|
|
4891
|
+
this.subAgentId
|
|
4890
4892
|
);
|
|
4891
4893
|
const uniqueArtifacts = this.countUniqueArtifacts(parts);
|
|
4892
4894
|
span.setAttributes({
|
|
@@ -4901,7 +4903,7 @@ var ResponseFormatter = class {
|
|
|
4901
4903
|
return { parts };
|
|
4902
4904
|
} catch (error) {
|
|
4903
4905
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4904
|
-
|
|
4906
|
+
logger11.error({ error, responseObject }, "Error formatting object response");
|
|
4905
4907
|
return {
|
|
4906
4908
|
parts: [{ kind: "data", data: responseObject }]
|
|
4907
4909
|
};
|
|
@@ -4933,7 +4935,11 @@ var ResponseFormatter = class {
|
|
|
4933
4935
|
"response.type": "text",
|
|
4934
4936
|
"response.availableArtifacts": artifactMap.size
|
|
4935
4937
|
});
|
|
4936
|
-
const parts = await this.artifactParser.parseText(
|
|
4938
|
+
const parts = await this.artifactParser.parseText(
|
|
4939
|
+
responseText,
|
|
4940
|
+
artifactMap,
|
|
4941
|
+
this.subAgentId
|
|
4942
|
+
);
|
|
4937
4943
|
if (parts.length === 1 && parts[0].kind === "text") {
|
|
4938
4944
|
return { text: parts[0].text };
|
|
4939
4945
|
}
|
|
@@ -4953,7 +4959,7 @@ var ResponseFormatter = class {
|
|
|
4953
4959
|
return { parts };
|
|
4954
4960
|
} catch (error) {
|
|
4955
4961
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4956
|
-
|
|
4962
|
+
logger11.error({ error, responseText }, "Error formatting response");
|
|
4957
4963
|
return { text: responseText };
|
|
4958
4964
|
} finally {
|
|
4959
4965
|
span.end();
|
|
@@ -5007,20 +5013,20 @@ function agentInitializingOp(sessionId, graphId) {
|
|
|
5007
5013
|
}
|
|
5008
5014
|
};
|
|
5009
5015
|
}
|
|
5010
|
-
function completionOp(
|
|
5016
|
+
function completionOp(subAgentId, iterations) {
|
|
5011
5017
|
return {
|
|
5012
5018
|
type: "completion",
|
|
5013
5019
|
details: {
|
|
5014
|
-
agent:
|
|
5020
|
+
agent: subAgentId,
|
|
5015
5021
|
iteration: iterations
|
|
5016
5022
|
}
|
|
5017
5023
|
};
|
|
5018
5024
|
}
|
|
5019
|
-
function errorOp(message,
|
|
5025
|
+
function errorOp(message, subAgentId, severity = "error", code) {
|
|
5020
5026
|
return {
|
|
5021
5027
|
type: "error",
|
|
5022
5028
|
message,
|
|
5023
|
-
agent:
|
|
5029
|
+
agent: subAgentId,
|
|
5024
5030
|
severity,
|
|
5025
5031
|
code,
|
|
5026
5032
|
timestamp: Date.now()
|
|
@@ -5035,10 +5041,10 @@ init_logger();
|
|
|
5035
5041
|
|
|
5036
5042
|
// src/utils/data-component-schema.ts
|
|
5037
5043
|
init_logger();
|
|
5038
|
-
var
|
|
5044
|
+
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
5039
5045
|
function jsonSchemaToZod(jsonSchema) {
|
|
5040
5046
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
5041
|
-
|
|
5047
|
+
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
5042
5048
|
return z6.z.string();
|
|
5043
5049
|
}
|
|
5044
5050
|
switch (jsonSchema.type) {
|
|
@@ -5065,7 +5071,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5065
5071
|
case "null":
|
|
5066
5072
|
return z6.z.null();
|
|
5067
5073
|
default:
|
|
5068
|
-
|
|
5074
|
+
logger12.warn(
|
|
5069
5075
|
{
|
|
5070
5076
|
unsupportedType: jsonSchema.type,
|
|
5071
5077
|
schema: jsonSchema
|
|
@@ -5432,7 +5438,7 @@ function parseEmbeddedJson(data) {
|
|
|
5432
5438
|
|
|
5433
5439
|
// src/a2a/client.ts
|
|
5434
5440
|
init_logger();
|
|
5435
|
-
var
|
|
5441
|
+
var logger13 = agentsCore.getLogger("a2aClient");
|
|
5436
5442
|
var DEFAULT_BACKOFF = {
|
|
5437
5443
|
initialInterval: 500,
|
|
5438
5444
|
maxInterval: 6e4,
|
|
@@ -5638,7 +5644,7 @@ var A2AClient = class {
|
|
|
5638
5644
|
try {
|
|
5639
5645
|
const res = await fn();
|
|
5640
5646
|
if (attempt > 0) {
|
|
5641
|
-
|
|
5647
|
+
logger13.info(
|
|
5642
5648
|
{
|
|
5643
5649
|
attempts: attempt + 1,
|
|
5644
5650
|
elapsedTime: Date.now() - start
|
|
@@ -5653,7 +5659,7 @@ var A2AClient = class {
|
|
|
5653
5659
|
}
|
|
5654
5660
|
const elapsed = Date.now() - start;
|
|
5655
5661
|
if (elapsed > maxElapsedTime) {
|
|
5656
|
-
|
|
5662
|
+
logger13.warn(
|
|
5657
5663
|
{
|
|
5658
5664
|
attempts: attempt + 1,
|
|
5659
5665
|
elapsedTime: elapsed,
|
|
@@ -5674,7 +5680,7 @@ var A2AClient = class {
|
|
|
5674
5680
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
5675
5681
|
}
|
|
5676
5682
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
5677
|
-
|
|
5683
|
+
logger13.info(
|
|
5678
5684
|
{
|
|
5679
5685
|
attempt: attempt + 1,
|
|
5680
5686
|
delayMs,
|
|
@@ -5759,7 +5765,7 @@ var A2AClient = class {
|
|
|
5759
5765
|
}
|
|
5760
5766
|
const rpcResponse = await httpResponse.json();
|
|
5761
5767
|
if (rpcResponse.id !== requestId2) {
|
|
5762
|
-
|
|
5768
|
+
logger13.warn(
|
|
5763
5769
|
{
|
|
5764
5770
|
method,
|
|
5765
5771
|
expectedId: requestId2,
|
|
@@ -5958,7 +5964,7 @@ var A2AClient = class {
|
|
|
5958
5964
|
try {
|
|
5959
5965
|
while (true) {
|
|
5960
5966
|
const { done, value } = await reader.read();
|
|
5961
|
-
|
|
5967
|
+
logger13.info({ done, value }, "parseA2ASseStream");
|
|
5962
5968
|
if (done) {
|
|
5963
5969
|
if (eventDataBuffer.trim()) {
|
|
5964
5970
|
const result = this._processSseEventData(
|
|
@@ -6048,7 +6054,7 @@ var A2AClient = class {
|
|
|
6048
6054
|
init_conversations();
|
|
6049
6055
|
init_dbClient();
|
|
6050
6056
|
init_logger();
|
|
6051
|
-
var
|
|
6057
|
+
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
6052
6058
|
var generateTransferToolDescription = (config) => {
|
|
6053
6059
|
return `Hand off the conversation to agent ${config.id}.
|
|
6054
6060
|
|
|
@@ -6072,7 +6078,7 @@ Delegate a specific task to agent ${config.id} when it seems like the agent can
|
|
|
6072
6078
|
var createTransferToAgentTool = ({
|
|
6073
6079
|
transferConfig,
|
|
6074
6080
|
callingAgentId,
|
|
6075
|
-
|
|
6081
|
+
subAgent,
|
|
6076
6082
|
streamRequestId
|
|
6077
6083
|
}) => {
|
|
6078
6084
|
return ai.tool({
|
|
@@ -6082,11 +6088,11 @@ var createTransferToAgentTool = ({
|
|
|
6082
6088
|
const activeSpan = api.trace.getActiveSpan();
|
|
6083
6089
|
if (activeSpan) {
|
|
6084
6090
|
activeSpan.setAttributes({
|
|
6085
|
-
|
|
6086
|
-
|
|
6091
|
+
[agentsCore.SPAN_KEYS.TRANSFER_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6092
|
+
[agentsCore.SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
6087
6093
|
});
|
|
6088
6094
|
}
|
|
6089
|
-
|
|
6095
|
+
logger14.info(
|
|
6090
6096
|
{
|
|
6091
6097
|
transferTo: transferConfig.id ?? "unknown",
|
|
6092
6098
|
fromAgent: callingAgentId
|
|
@@ -6095,8 +6101,8 @@ var createTransferToAgentTool = ({
|
|
|
6095
6101
|
);
|
|
6096
6102
|
if (streamRequestId) {
|
|
6097
6103
|
graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
|
|
6098
|
-
|
|
6099
|
-
|
|
6104
|
+
fromSubAgent: callingAgentId,
|
|
6105
|
+
targetSubAgent: transferConfig.id ?? "unknown",
|
|
6100
6106
|
reason: `Transfer to ${transferConfig.name || transferConfig.id}`
|
|
6101
6107
|
});
|
|
6102
6108
|
}
|
|
@@ -6118,7 +6124,7 @@ function createDelegateToAgentTool({
|
|
|
6118
6124
|
contextId,
|
|
6119
6125
|
metadata,
|
|
6120
6126
|
sessionId,
|
|
6121
|
-
|
|
6127
|
+
subAgent,
|
|
6122
6128
|
credentialStoreRegistry
|
|
6123
6129
|
}) {
|
|
6124
6130
|
return ai.tool({
|
|
@@ -6129,9 +6135,9 @@ function createDelegateToAgentTool({
|
|
|
6129
6135
|
const activeSpan = api.trace.getActiveSpan();
|
|
6130
6136
|
if (activeSpan) {
|
|
6131
6137
|
activeSpan.setAttributes({
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6138
|
+
[agentsCore.SPAN_KEYS.DELEGATION_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6139
|
+
[agentsCore.SPAN_KEYS.DELEGATION_TO_SUB_AGENT_ID]: delegateConfig.config.id ?? "unknown",
|
|
6140
|
+
[agentsCore.SPAN_KEYS.DELEGATION_ID]: delegationId
|
|
6135
6141
|
});
|
|
6136
6142
|
}
|
|
6137
6143
|
if (metadata.streamRequestId) {
|
|
@@ -6141,8 +6147,8 @@ function createDelegateToAgentTool({
|
|
|
6141
6147
|
callingAgentId,
|
|
6142
6148
|
{
|
|
6143
6149
|
delegationId,
|
|
6144
|
-
|
|
6145
|
-
|
|
6150
|
+
fromSubAgent: callingAgentId,
|
|
6151
|
+
targetSubAgent: delegateConfig.config.id,
|
|
6146
6152
|
taskDescription: input.message
|
|
6147
6153
|
}
|
|
6148
6154
|
);
|
|
@@ -6156,7 +6162,7 @@ function createDelegateToAgentTool({
|
|
|
6156
6162
|
projectId,
|
|
6157
6163
|
graphId
|
|
6158
6164
|
},
|
|
6159
|
-
|
|
6165
|
+
subAgentId: delegateConfig.config.id
|
|
6160
6166
|
});
|
|
6161
6167
|
if (externalAgent && (externalAgent.credentialReferenceId || externalAgent.headers) && credentialStoreRegistry) {
|
|
6162
6168
|
const contextResolver = new agentsCore.ContextResolver(
|
|
@@ -6235,7 +6241,7 @@ function createDelegateToAgentTool({
|
|
|
6235
6241
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
6236
6242
|
}
|
|
6237
6243
|
};
|
|
6238
|
-
|
|
6244
|
+
logger14.info({ messageToSend }, "messageToSend");
|
|
6239
6245
|
await agentsCore.createMessage(dbClient_default)({
|
|
6240
6246
|
id: nanoid.nanoid(),
|
|
6241
6247
|
tenantId,
|
|
@@ -6247,7 +6253,7 @@ function createDelegateToAgentTool({
|
|
|
6247
6253
|
},
|
|
6248
6254
|
visibility: isInternal ? "internal" : "external",
|
|
6249
6255
|
messageType: "a2a-request",
|
|
6250
|
-
|
|
6256
|
+
fromSubAgentId: callingAgentId,
|
|
6251
6257
|
...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
|
|
6252
6258
|
});
|
|
6253
6259
|
const response = await a2aClient.sendMessage({
|
|
@@ -6262,8 +6268,8 @@ function createDelegateToAgentTool({
|
|
|
6262
6268
|
conversationId: contextId,
|
|
6263
6269
|
messageType: "a2a-response",
|
|
6264
6270
|
visibility: isInternal ? "internal" : "external",
|
|
6265
|
-
|
|
6266
|
-
...isInternal ? {
|
|
6271
|
+
toSubAgentId: callingAgentId,
|
|
6272
|
+
...isInternal ? { fromSubAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
|
|
6267
6273
|
});
|
|
6268
6274
|
if (sessionId && context?.toolCallId) {
|
|
6269
6275
|
const toolResult = {
|
|
@@ -6282,8 +6288,8 @@ function createDelegateToAgentTool({
|
|
|
6282
6288
|
callingAgentId,
|
|
6283
6289
|
{
|
|
6284
6290
|
delegationId,
|
|
6285
|
-
|
|
6286
|
-
|
|
6291
|
+
fromSubAgent: delegateConfig.config.id,
|
|
6292
|
+
targetSubAgent: callingAgentId,
|
|
6287
6293
|
result: response.result
|
|
6288
6294
|
}
|
|
6289
6295
|
);
|
|
@@ -6298,7 +6304,7 @@ function createDelegateToAgentTool({
|
|
|
6298
6304
|
|
|
6299
6305
|
// src/agents/SystemPromptBuilder.ts
|
|
6300
6306
|
init_logger();
|
|
6301
|
-
var
|
|
6307
|
+
var logger15 = agentsCore.getLogger("SystemPromptBuilder");
|
|
6302
6308
|
var SystemPromptBuilder = class {
|
|
6303
6309
|
constructor(version, versionConfig) {
|
|
6304
6310
|
this.version = version;
|
|
@@ -6314,12 +6320,12 @@ var SystemPromptBuilder = class {
|
|
|
6314
6320
|
this.templates.set(name, content);
|
|
6315
6321
|
}
|
|
6316
6322
|
this.loaded = true;
|
|
6317
|
-
|
|
6323
|
+
logger15.debug(
|
|
6318
6324
|
{ templateCount: this.templates.size, version: this.version },
|
|
6319
6325
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
6320
6326
|
);
|
|
6321
6327
|
} catch (error) {
|
|
6322
|
-
|
|
6328
|
+
logger15.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
6323
6329
|
throw new Error(`Template loading failed: ${error}`);
|
|
6324
6330
|
}
|
|
6325
6331
|
}
|
|
@@ -7380,7 +7386,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
7380
7386
|
return false;
|
|
7381
7387
|
};
|
|
7382
7388
|
}
|
|
7383
|
-
var
|
|
7389
|
+
var logger18 = agentsCore.getLogger("Agent");
|
|
7384
7390
|
var CONSTANTS = {
|
|
7385
7391
|
MAX_GENERATION_STEPS: 12,
|
|
7386
7392
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -7610,7 +7616,7 @@ var Agent = class {
|
|
|
7610
7616
|
}
|
|
7611
7617
|
getRelationTools(runtimeContext, sessionId) {
|
|
7612
7618
|
const { transferRelations = [], delegateRelations = [] } = this.config;
|
|
7613
|
-
const createToolName = (prefix,
|
|
7619
|
+
const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
|
|
7614
7620
|
return Object.fromEntries([
|
|
7615
7621
|
...transferRelations.map((agentConfig) => {
|
|
7616
7622
|
const toolName = createToolName("transfer", agentConfig.id);
|
|
@@ -7621,7 +7627,7 @@ var Agent = class {
|
|
|
7621
7627
|
createTransferToAgentTool({
|
|
7622
7628
|
transferConfig: agentConfig,
|
|
7623
7629
|
callingAgentId: this.config.id,
|
|
7624
|
-
|
|
7630
|
+
subAgent: this,
|
|
7625
7631
|
streamRequestId: runtimeContext?.metadata?.streamRequestId
|
|
7626
7632
|
}),
|
|
7627
7633
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7650,7 +7656,7 @@ var Agent = class {
|
|
|
7650
7656
|
apiKey: runtimeContext?.metadata?.apiKey
|
|
7651
7657
|
},
|
|
7652
7658
|
sessionId,
|
|
7653
|
-
|
|
7659
|
+
subAgent: this,
|
|
7654
7660
|
credentialStoreRegistry: this.credentialStoreRegistry
|
|
7655
7661
|
}),
|
|
7656
7662
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7684,14 +7690,14 @@ var Agent = class {
|
|
|
7684
7690
|
for (const toolSet of tools) {
|
|
7685
7691
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7686
7692
|
if (!isValidTool(originalTool)) {
|
|
7687
|
-
|
|
7693
|
+
logger18.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7688
7694
|
continue;
|
|
7689
7695
|
}
|
|
7690
7696
|
const sessionWrappedTool = ai.tool({
|
|
7691
7697
|
description: originalTool.description,
|
|
7692
7698
|
inputSchema: originalTool.inputSchema,
|
|
7693
7699
|
execute: async (args, { toolCallId }) => {
|
|
7694
|
-
|
|
7700
|
+
logger18.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7695
7701
|
try {
|
|
7696
7702
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7697
7703
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -7705,7 +7711,7 @@ var Agent = class {
|
|
|
7705
7711
|
});
|
|
7706
7712
|
return { result: enhancedResult, toolCallId };
|
|
7707
7713
|
} catch (error) {
|
|
7708
|
-
|
|
7714
|
+
logger18.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7709
7715
|
throw error;
|
|
7710
7716
|
}
|
|
7711
7717
|
}
|
|
@@ -7750,7 +7756,7 @@ var Agent = class {
|
|
|
7750
7756
|
tenantId: this.config.tenantId,
|
|
7751
7757
|
projectId: this.config.projectId,
|
|
7752
7758
|
graphId: this.config.graphId,
|
|
7753
|
-
|
|
7759
|
+
subAgentId: this.config.id
|
|
7754
7760
|
}
|
|
7755
7761
|
});
|
|
7756
7762
|
const agentToolRelationHeaders = toolsForAgent.data.find((t) => t.toolId === tool3.id)?.headers || void 0;
|
|
@@ -7806,7 +7812,7 @@ var Agent = class {
|
|
|
7806
7812
|
headers: agentToolRelationHeaders
|
|
7807
7813
|
};
|
|
7808
7814
|
}
|
|
7809
|
-
|
|
7815
|
+
logger18.info(
|
|
7810
7816
|
{
|
|
7811
7817
|
toolName: tool3.name,
|
|
7812
7818
|
credentialReferenceId,
|
|
@@ -7831,10 +7837,10 @@ var Agent = class {
|
|
|
7831
7837
|
this.mcpClientCache.set(cacheKey, client);
|
|
7832
7838
|
} catch (error) {
|
|
7833
7839
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7834
|
-
|
|
7840
|
+
logger18.error(
|
|
7835
7841
|
{
|
|
7836
7842
|
toolName: tool3.name,
|
|
7837
|
-
|
|
7843
|
+
subAgentId: this.config.id,
|
|
7838
7844
|
cacheKey,
|
|
7839
7845
|
error: error instanceof Error ? error.message : String(error)
|
|
7840
7846
|
},
|
|
@@ -7855,10 +7861,10 @@ var Agent = class {
|
|
|
7855
7861
|
await client.connect();
|
|
7856
7862
|
return client;
|
|
7857
7863
|
} catch (error) {
|
|
7858
|
-
|
|
7864
|
+
logger18.error(
|
|
7859
7865
|
{
|
|
7860
7866
|
toolName: tool3.name,
|
|
7861
|
-
|
|
7867
|
+
subAgentId: this.config.id,
|
|
7862
7868
|
error: error instanceof Error ? error.message : String(error)
|
|
7863
7869
|
},
|
|
7864
7870
|
"Agent failed to connect to MCP server"
|
|
@@ -7874,7 +7880,7 @@ var Agent = class {
|
|
|
7874
7880
|
tenantId: this.config.tenantId || "default",
|
|
7875
7881
|
projectId: this.config.projectId || "default",
|
|
7876
7882
|
graphId: this.config.graphId,
|
|
7877
|
-
|
|
7883
|
+
subAgentId: this.config.id
|
|
7878
7884
|
}
|
|
7879
7885
|
});
|
|
7880
7886
|
const toolsData = toolsForAgent.data || [];
|
|
@@ -7888,7 +7894,7 @@ var Agent = class {
|
|
|
7888
7894
|
if (toolDef.tool.config?.type === "function") {
|
|
7889
7895
|
const functionId = toolDef.tool.functionId;
|
|
7890
7896
|
if (!functionId) {
|
|
7891
|
-
|
|
7897
|
+
logger18.warn({ toolId: toolDef.tool.id }, "Function tool missing functionId reference");
|
|
7892
7898
|
continue;
|
|
7893
7899
|
}
|
|
7894
7900
|
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
@@ -7899,7 +7905,7 @@ var Agent = class {
|
|
|
7899
7905
|
}
|
|
7900
7906
|
});
|
|
7901
7907
|
if (!functionData) {
|
|
7902
|
-
|
|
7908
|
+
logger18.warn(
|
|
7903
7909
|
{ functionId, toolId: toolDef.tool.id },
|
|
7904
7910
|
"Function not found in functions table"
|
|
7905
7911
|
);
|
|
@@ -7910,7 +7916,7 @@ var Agent = class {
|
|
|
7910
7916
|
description: toolDef.tool.description || toolDef.tool.name,
|
|
7911
7917
|
inputSchema: zodSchema,
|
|
7912
7918
|
execute: async (args, { toolCallId }) => {
|
|
7913
|
-
|
|
7919
|
+
logger18.debug(
|
|
7914
7920
|
{ toolName: toolDef.tool.name, toolCallId, args },
|
|
7915
7921
|
"Function Tool Called"
|
|
7916
7922
|
);
|
|
@@ -7930,7 +7936,7 @@ var Agent = class {
|
|
|
7930
7936
|
});
|
|
7931
7937
|
return { result, toolCallId };
|
|
7932
7938
|
} catch (error) {
|
|
7933
|
-
|
|
7939
|
+
logger18.error(
|
|
7934
7940
|
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7935
7941
|
"Function tool execution failed"
|
|
7936
7942
|
);
|
|
@@ -7947,7 +7953,7 @@ var Agent = class {
|
|
|
7947
7953
|
}
|
|
7948
7954
|
}
|
|
7949
7955
|
} catch (error) {
|
|
7950
|
-
|
|
7956
|
+
logger18.error({ error }, "Failed to load function tools from database");
|
|
7951
7957
|
}
|
|
7952
7958
|
return functionTools;
|
|
7953
7959
|
}
|
|
@@ -7957,7 +7963,7 @@ var Agent = class {
|
|
|
7957
7963
|
async getResolvedContext(conversationId, headers) {
|
|
7958
7964
|
try {
|
|
7959
7965
|
if (!this.config.contextConfigId) {
|
|
7960
|
-
|
|
7966
|
+
logger18.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7961
7967
|
return null;
|
|
7962
7968
|
}
|
|
7963
7969
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7969,7 +7975,7 @@ var Agent = class {
|
|
|
7969
7975
|
id: this.config.contextConfigId
|
|
7970
7976
|
});
|
|
7971
7977
|
if (!contextConfig) {
|
|
7972
|
-
|
|
7978
|
+
logger18.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7973
7979
|
return null;
|
|
7974
7980
|
}
|
|
7975
7981
|
if (!this.contextResolver) {
|
|
@@ -7986,7 +7992,7 @@ var Agent = class {
|
|
|
7986
7992
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7987
7993
|
$env: process.env
|
|
7988
7994
|
};
|
|
7989
|
-
|
|
7995
|
+
logger18.debug(
|
|
7990
7996
|
{
|
|
7991
7997
|
conversationId,
|
|
7992
7998
|
contextConfigId: contextConfig.id,
|
|
@@ -8000,7 +8006,7 @@ var Agent = class {
|
|
|
8000
8006
|
);
|
|
8001
8007
|
return contextWithBuiltins;
|
|
8002
8008
|
} catch (error) {
|
|
8003
|
-
|
|
8009
|
+
logger18.error(
|
|
8004
8010
|
{
|
|
8005
8011
|
conversationId,
|
|
8006
8012
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8024,7 +8030,7 @@ var Agent = class {
|
|
|
8024
8030
|
});
|
|
8025
8031
|
return graphDefinition?.graphPrompt || void 0;
|
|
8026
8032
|
} catch (error) {
|
|
8027
|
-
|
|
8033
|
+
logger18.warn(
|
|
8028
8034
|
{
|
|
8029
8035
|
graphId: this.config.graphId,
|
|
8030
8036
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8049,11 +8055,11 @@ var Agent = class {
|
|
|
8049
8055
|
if (!graphDefinition) {
|
|
8050
8056
|
return false;
|
|
8051
8057
|
}
|
|
8052
|
-
return Object.values(graphDefinition.
|
|
8053
|
-
(
|
|
8058
|
+
return Object.values(graphDefinition.subAgents).some(
|
|
8059
|
+
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
8054
8060
|
);
|
|
8055
8061
|
} catch (error) {
|
|
8056
|
-
|
|
8062
|
+
logger18.warn(
|
|
8057
8063
|
{
|
|
8058
8064
|
graphId: this.config.graphId,
|
|
8059
8065
|
tenantId: this.config.tenantId,
|
|
@@ -8082,7 +8088,7 @@ var Agent = class {
|
|
|
8082
8088
|
preserveUnresolved: false
|
|
8083
8089
|
});
|
|
8084
8090
|
} catch (error) {
|
|
8085
|
-
|
|
8091
|
+
logger18.error(
|
|
8086
8092
|
{
|
|
8087
8093
|
conversationId,
|
|
8088
8094
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8129,7 +8135,7 @@ var Agent = class {
|
|
|
8129
8135
|
preserveUnresolved: false
|
|
8130
8136
|
});
|
|
8131
8137
|
} catch (error) {
|
|
8132
|
-
|
|
8138
|
+
logger18.error(
|
|
8133
8139
|
{
|
|
8134
8140
|
conversationId,
|
|
8135
8141
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8144,7 +8150,7 @@ var Agent = class {
|
|
|
8144
8150
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
8145
8151
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
8146
8152
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
8147
|
-
|
|
8153
|
+
logger18.info(
|
|
8148
8154
|
{
|
|
8149
8155
|
mcpTools: Object.keys(mcpTools),
|
|
8150
8156
|
functionTools: Object.keys(functionTools),
|
|
@@ -8183,7 +8189,7 @@ var Agent = class {
|
|
|
8183
8189
|
preserveUnresolved: false
|
|
8184
8190
|
});
|
|
8185
8191
|
} catch (error) {
|
|
8186
|
-
|
|
8192
|
+
logger18.error(
|
|
8187
8193
|
{
|
|
8188
8194
|
conversationId,
|
|
8189
8195
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8216,7 +8222,7 @@ var Agent = class {
|
|
|
8216
8222
|
toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
|
|
8217
8223
|
}),
|
|
8218
8224
|
execute: async ({ artifactId, toolCallId }) => {
|
|
8219
|
-
|
|
8225
|
+
logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
8220
8226
|
const streamRequestId = this.getStreamRequestId();
|
|
8221
8227
|
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
8222
8228
|
if (!artifactService) {
|
|
@@ -8250,7 +8256,7 @@ var Agent = class {
|
|
|
8250
8256
|
});
|
|
8251
8257
|
}
|
|
8252
8258
|
// Provide a default tool set that is always available to the agent.
|
|
8253
|
-
async getDefaultTools(
|
|
8259
|
+
async getDefaultTools(streamRequestId) {
|
|
8254
8260
|
const defaultTools = {};
|
|
8255
8261
|
if (await this.graphHasArtifactComponents()) {
|
|
8256
8262
|
defaultTools.get_reference_artifact = this.getArtifactTools();
|
|
@@ -8476,7 +8482,7 @@ var Agent = class {
|
|
|
8476
8482
|
};
|
|
8477
8483
|
return enhanced;
|
|
8478
8484
|
} catch (error) {
|
|
8479
|
-
|
|
8485
|
+
logger18.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
8480
8486
|
return result;
|
|
8481
8487
|
}
|
|
8482
8488
|
}
|
|
@@ -8491,7 +8497,7 @@ var Agent = class {
|
|
|
8491
8497
|
}
|
|
8492
8498
|
});
|
|
8493
8499
|
} catch (error) {
|
|
8494
|
-
|
|
8500
|
+
logger18.error(
|
|
8495
8501
|
{ error, graphId: this.config.graphId },
|
|
8496
8502
|
"Failed to check graph artifact components"
|
|
8497
8503
|
);
|
|
@@ -8536,7 +8542,7 @@ var Agent = class {
|
|
|
8536
8542
|
// Thinking prompt without data components
|
|
8537
8543
|
this.getFunctionTools(sessionId, streamRequestId),
|
|
8538
8544
|
Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
|
|
8539
|
-
this.getDefaultTools(
|
|
8545
|
+
this.getDefaultTools(streamRequestId)
|
|
8540
8546
|
]);
|
|
8541
8547
|
childSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
8542
8548
|
return result;
|
|
@@ -8576,7 +8582,7 @@ var Agent = class {
|
|
|
8576
8582
|
currentMessage: userMessage,
|
|
8577
8583
|
options: historyConfig,
|
|
8578
8584
|
filters: {
|
|
8579
|
-
|
|
8585
|
+
subAgentId: this.config.id,
|
|
8580
8586
|
taskId
|
|
8581
8587
|
}
|
|
8582
8588
|
});
|
|
@@ -8592,7 +8598,7 @@ var Agent = class {
|
|
|
8592
8598
|
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;
|
|
8593
8599
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
8594
8600
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
8595
|
-
|
|
8601
|
+
logger18.warn(
|
|
8596
8602
|
{
|
|
8597
8603
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8598
8604
|
appliedTimeout: timeoutMs,
|
|
@@ -8634,7 +8640,7 @@ var Agent = class {
|
|
|
8634
8640
|
}
|
|
8635
8641
|
);
|
|
8636
8642
|
} catch (error) {
|
|
8637
|
-
|
|
8643
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8638
8644
|
}
|
|
8639
8645
|
}
|
|
8640
8646
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8661,7 +8667,7 @@ var Agent = class {
|
|
|
8661
8667
|
projectId: session?.projectId,
|
|
8662
8668
|
artifactComponents: this.artifactComponents,
|
|
8663
8669
|
streamRequestId: this.getStreamRequestId(),
|
|
8664
|
-
|
|
8670
|
+
subAgentId: this.config.id
|
|
8665
8671
|
};
|
|
8666
8672
|
const parser = new IncrementalStreamParser(
|
|
8667
8673
|
streamHelper,
|
|
@@ -8738,7 +8744,7 @@ var Agent = class {
|
|
|
8738
8744
|
}
|
|
8739
8745
|
);
|
|
8740
8746
|
} catch (error) {
|
|
8741
|
-
|
|
8747
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8742
8748
|
}
|
|
8743
8749
|
}
|
|
8744
8750
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8910,7 +8916,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8910
8916
|
projectId: session?.projectId,
|
|
8911
8917
|
artifactComponents: this.artifactComponents,
|
|
8912
8918
|
streamRequestId: this.getStreamRequestId(),
|
|
8913
|
-
|
|
8919
|
+
subAgentId: this.config.id
|
|
8914
8920
|
};
|
|
8915
8921
|
const parser = new IncrementalStreamParser(
|
|
8916
8922
|
streamHelper,
|
|
@@ -8993,7 +8999,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8993
8999
|
contextId,
|
|
8994
9000
|
artifactComponents: this.artifactComponents,
|
|
8995
9001
|
streamRequestId: this.getStreamRequestId(),
|
|
8996
|
-
|
|
9002
|
+
subAgentId: this.config.id
|
|
8997
9003
|
});
|
|
8998
9004
|
if (response.object) {
|
|
8999
9005
|
formattedContent = await responseFormatter.formatObjectResponse(
|
|
@@ -9030,7 +9036,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
9030
9036
|
};
|
|
9031
9037
|
|
|
9032
9038
|
// src/agents/generateTaskHandler.ts
|
|
9033
|
-
var
|
|
9039
|
+
var logger19 = agentsCore.getLogger("generateTaskHandler");
|
|
9034
9040
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
9035
9041
|
return async (task) => {
|
|
9036
9042
|
try {
|
|
@@ -9056,14 +9062,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9056
9062
|
projectId: config.projectId,
|
|
9057
9063
|
graphId: config.graphId
|
|
9058
9064
|
},
|
|
9059
|
-
|
|
9065
|
+
subAgentId: config.subAgentId
|
|
9060
9066
|
}),
|
|
9061
9067
|
agentsCore.getToolsForAgent(dbClient_default)({
|
|
9062
9068
|
scopes: {
|
|
9063
9069
|
tenantId: config.tenantId,
|
|
9064
9070
|
projectId: config.projectId,
|
|
9065
9071
|
graphId: config.graphId,
|
|
9066
|
-
|
|
9072
|
+
subAgentId: config.subAgentId
|
|
9067
9073
|
}
|
|
9068
9074
|
}),
|
|
9069
9075
|
agentsCore.getDataComponentsForAgent(dbClient_default)({
|
|
@@ -9071,7 +9077,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9071
9077
|
tenantId: config.tenantId,
|
|
9072
9078
|
projectId: config.projectId,
|
|
9073
9079
|
graphId: config.graphId,
|
|
9074
|
-
|
|
9080
|
+
subAgentId: config.subAgentId
|
|
9075
9081
|
}
|
|
9076
9082
|
}),
|
|
9077
9083
|
agentsCore.getArtifactComponentsForAgent(dbClient_default)({
|
|
@@ -9079,21 +9085,21 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9079
9085
|
tenantId: config.tenantId,
|
|
9080
9086
|
projectId: config.projectId,
|
|
9081
9087
|
graphId: config.graphId,
|
|
9082
|
-
|
|
9088
|
+
subAgentId: config.subAgentId
|
|
9083
9089
|
}
|
|
9084
9090
|
})
|
|
9085
9091
|
]);
|
|
9086
|
-
|
|
9092
|
+
logger19.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
9087
9093
|
const enhancedInternalRelations = await Promise.all(
|
|
9088
9094
|
internalRelations.map(async (relation) => {
|
|
9089
9095
|
try {
|
|
9090
|
-
const relatedAgent = await agentsCore.
|
|
9096
|
+
const relatedAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9091
9097
|
scopes: {
|
|
9092
9098
|
tenantId: config.tenantId,
|
|
9093
9099
|
projectId: config.projectId,
|
|
9094
9100
|
graphId: config.graphId
|
|
9095
9101
|
},
|
|
9096
|
-
|
|
9102
|
+
subAgentId: relation.id
|
|
9097
9103
|
});
|
|
9098
9104
|
if (relatedAgent) {
|
|
9099
9105
|
const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
|
|
@@ -9102,7 +9108,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9102
9108
|
projectId: config.projectId,
|
|
9103
9109
|
graphId: config.graphId
|
|
9104
9110
|
},
|
|
9105
|
-
|
|
9111
|
+
subAgentId: relation.id
|
|
9106
9112
|
});
|
|
9107
9113
|
const enhancedDescription = generateDescriptionWithTransfers(
|
|
9108
9114
|
relation.description || "",
|
|
@@ -9112,7 +9118,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9112
9118
|
return { ...relation, description: enhancedDescription };
|
|
9113
9119
|
}
|
|
9114
9120
|
} catch (error) {
|
|
9115
|
-
|
|
9121
|
+
logger19.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
9116
9122
|
}
|
|
9117
9123
|
return relation;
|
|
9118
9124
|
})
|
|
@@ -9127,7 +9133,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9127
9133
|
) ?? [];
|
|
9128
9134
|
const agent = new Agent(
|
|
9129
9135
|
{
|
|
9130
|
-
id: config.
|
|
9136
|
+
id: config.subAgentId,
|
|
9131
9137
|
tenantId: config.tenantId,
|
|
9132
9138
|
projectId: config.projectId,
|
|
9133
9139
|
graphId: config.graphId,
|
|
@@ -9138,7 +9144,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9138
9144
|
agentPrompt,
|
|
9139
9145
|
models: models || void 0,
|
|
9140
9146
|
stopWhen: stopWhen || void 0,
|
|
9141
|
-
|
|
9147
|
+
subAgentRelations: enhancedInternalRelations.map((relation) => ({
|
|
9142
9148
|
id: relation.id,
|
|
9143
9149
|
tenantId: config.tenantId,
|
|
9144
9150
|
projectId: config.projectId,
|
|
@@ -9149,7 +9155,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9149
9155
|
description: relation.description,
|
|
9150
9156
|
agentPrompt: "",
|
|
9151
9157
|
delegateRelations: [],
|
|
9152
|
-
|
|
9158
|
+
subAgentRelations: [],
|
|
9153
9159
|
transferRelations: []
|
|
9154
9160
|
})),
|
|
9155
9161
|
transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
|
|
@@ -9163,7 +9169,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9163
9169
|
description: relation.description,
|
|
9164
9170
|
agentPrompt: "",
|
|
9165
9171
|
delegateRelations: [],
|
|
9166
|
-
|
|
9172
|
+
subAgentRelations: [],
|
|
9167
9173
|
transferRelations: []
|
|
9168
9174
|
})),
|
|
9169
9175
|
delegateRelations: [
|
|
@@ -9181,7 +9187,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9181
9187
|
description: relation.description,
|
|
9182
9188
|
agentPrompt: "",
|
|
9183
9189
|
delegateRelations: [],
|
|
9184
|
-
|
|
9190
|
+
subAgentRelations: [],
|
|
9185
9191
|
transferRelations: []
|
|
9186
9192
|
}
|
|
9187
9193
|
})),
|
|
@@ -9216,11 +9222,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9216
9222
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
9217
9223
|
if (taskIdMatch) {
|
|
9218
9224
|
contextId = taskIdMatch[1];
|
|
9219
|
-
|
|
9225
|
+
logger19.info(
|
|
9220
9226
|
{
|
|
9221
9227
|
taskId: task.id,
|
|
9222
9228
|
extractedContextId: contextId,
|
|
9223
|
-
|
|
9229
|
+
subAgentId: config.subAgentId
|
|
9224
9230
|
},
|
|
9225
9231
|
"Extracted contextId from task ID for delegation"
|
|
9226
9232
|
);
|
|
@@ -9232,8 +9238,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9232
9238
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
9233
9239
|
agent.setDelegationStatus(isDelegation);
|
|
9234
9240
|
if (isDelegation) {
|
|
9235
|
-
|
|
9236
|
-
{
|
|
9241
|
+
logger19.info(
|
|
9242
|
+
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
9237
9243
|
"Delegated agent - streaming disabled"
|
|
9238
9244
|
);
|
|
9239
9245
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -9330,13 +9336,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9330
9336
|
};
|
|
9331
9337
|
};
|
|
9332
9338
|
var createTaskHandlerConfig = async (params) => {
|
|
9333
|
-
const agent = await agentsCore.
|
|
9339
|
+
const agent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9334
9340
|
scopes: {
|
|
9335
9341
|
tenantId: params.tenantId,
|
|
9336
9342
|
projectId: params.projectId,
|
|
9337
9343
|
graphId: params.graphId
|
|
9338
9344
|
},
|
|
9339
|
-
|
|
9345
|
+
subAgentId: params.subAgentId
|
|
9340
9346
|
});
|
|
9341
9347
|
const agentGraph = await agentsCore.getAgentGraphById(dbClient_default)({
|
|
9342
9348
|
scopes: {
|
|
@@ -9346,7 +9352,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9346
9352
|
}
|
|
9347
9353
|
});
|
|
9348
9354
|
if (!agent) {
|
|
9349
|
-
throw new Error(`Agent not found: ${params.
|
|
9355
|
+
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
9350
9356
|
}
|
|
9351
9357
|
const effectiveModels = await resolveModelConfig(params.graphId, agent);
|
|
9352
9358
|
const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
|
|
@@ -9354,7 +9360,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9354
9360
|
tenantId: params.tenantId,
|
|
9355
9361
|
projectId: params.projectId,
|
|
9356
9362
|
graphId: params.graphId,
|
|
9357
|
-
|
|
9363
|
+
subAgentId: params.subAgentId,
|
|
9358
9364
|
agentSchema: {
|
|
9359
9365
|
id: agent.id,
|
|
9360
9366
|
name: agent.name,
|
|
@@ -9383,25 +9389,27 @@ async function hydrateGraph({
|
|
|
9383
9389
|
apiKey
|
|
9384
9390
|
}) {
|
|
9385
9391
|
try {
|
|
9386
|
-
if (!dbGraph.
|
|
9392
|
+
if (!dbGraph.defaultSubAgentId) {
|
|
9387
9393
|
throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
|
|
9388
9394
|
}
|
|
9389
|
-
const
|
|
9395
|
+
const defaultSubAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9390
9396
|
scopes: {
|
|
9391
9397
|
tenantId: dbGraph.tenantId,
|
|
9392
9398
|
projectId: dbGraph.projectId,
|
|
9393
9399
|
graphId: dbGraph.id
|
|
9394
9400
|
},
|
|
9395
|
-
|
|
9401
|
+
subAgentId: dbGraph.defaultSubAgentId
|
|
9396
9402
|
});
|
|
9397
|
-
if (!
|
|
9398
|
-
throw new Error(
|
|
9403
|
+
if (!defaultSubAgent) {
|
|
9404
|
+
throw new Error(
|
|
9405
|
+
`Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
|
|
9406
|
+
);
|
|
9399
9407
|
}
|
|
9400
9408
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
9401
9409
|
tenantId: dbGraph.tenantId,
|
|
9402
9410
|
projectId: dbGraph.projectId,
|
|
9403
9411
|
graphId: dbGraph.id,
|
|
9404
|
-
|
|
9412
|
+
subAgentId: dbGraph.defaultSubAgentId,
|
|
9405
9413
|
baseUrl,
|
|
9406
9414
|
apiKey
|
|
9407
9415
|
});
|
|
@@ -9430,7 +9438,7 @@ async function hydrateGraph({
|
|
|
9430
9438
|
}
|
|
9431
9439
|
};
|
|
9432
9440
|
return {
|
|
9433
|
-
|
|
9441
|
+
subAgentId: dbGraph.id,
|
|
9434
9442
|
// Use graph ID as agent ID for A2A purposes
|
|
9435
9443
|
tenantId: dbGraph.tenantId,
|
|
9436
9444
|
projectId: dbGraph.projectId,
|
|
@@ -9457,7 +9465,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
9457
9465
|
init_dbClient();
|
|
9458
9466
|
init_logger();
|
|
9459
9467
|
var app = new zodOpenapi.OpenAPIHono();
|
|
9460
|
-
var
|
|
9468
|
+
var logger20 = agentsCore.getLogger("agents");
|
|
9461
9469
|
app.openapi(
|
|
9462
9470
|
zodOpenapi.createRoute({
|
|
9463
9471
|
method: "get",
|
|
@@ -9495,7 +9503,7 @@ app.openapi(
|
|
|
9495
9503
|
tracestate: c.req.header("tracestate"),
|
|
9496
9504
|
baggage: c.req.header("baggage")
|
|
9497
9505
|
};
|
|
9498
|
-
|
|
9506
|
+
logger20.info(
|
|
9499
9507
|
{
|
|
9500
9508
|
otelHeaders,
|
|
9501
9509
|
path: c.req.path,
|
|
@@ -9504,22 +9512,22 @@ app.openapi(
|
|
|
9504
9512
|
"OpenTelemetry headers: well-known agent.json"
|
|
9505
9513
|
);
|
|
9506
9514
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9507
|
-
const { tenantId, projectId, graphId,
|
|
9515
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9508
9516
|
console.dir("executionContext", executionContext);
|
|
9509
|
-
if (
|
|
9510
|
-
|
|
9517
|
+
if (subAgentId) {
|
|
9518
|
+
logger20.info(
|
|
9511
9519
|
{
|
|
9512
9520
|
message: "getRegisteredAgent (agent-level)",
|
|
9513
9521
|
tenantId,
|
|
9514
9522
|
projectId,
|
|
9515
9523
|
graphId,
|
|
9516
|
-
|
|
9524
|
+
subAgentId
|
|
9517
9525
|
},
|
|
9518
9526
|
"agent-level well-known agent.json"
|
|
9519
9527
|
);
|
|
9520
9528
|
const credentialStores = c.get("credentialStores");
|
|
9521
9529
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9522
|
-
|
|
9530
|
+
logger20.info({ agent }, "agent registered: well-known agent.json");
|
|
9523
9531
|
if (!agent) {
|
|
9524
9532
|
throw agentsCore.createApiError({
|
|
9525
9533
|
code: "not_found",
|
|
@@ -9528,7 +9536,7 @@ app.openapi(
|
|
|
9528
9536
|
}
|
|
9529
9537
|
return c.json(agent.agentCard);
|
|
9530
9538
|
} else {
|
|
9531
|
-
|
|
9539
|
+
logger20.info(
|
|
9532
9540
|
{
|
|
9533
9541
|
message: "getRegisteredGraph (graph-level)",
|
|
9534
9542
|
tenantId,
|
|
@@ -9554,7 +9562,7 @@ app.post("/a2a", async (c) => {
|
|
|
9554
9562
|
tracestate: c.req.header("tracestate"),
|
|
9555
9563
|
baggage: c.req.header("baggage")
|
|
9556
9564
|
};
|
|
9557
|
-
|
|
9565
|
+
logger20.info(
|
|
9558
9566
|
{
|
|
9559
9567
|
otelHeaders,
|
|
9560
9568
|
path: c.req.path,
|
|
@@ -9563,15 +9571,15 @@ app.post("/a2a", async (c) => {
|
|
|
9563
9571
|
"OpenTelemetry headers: a2a"
|
|
9564
9572
|
);
|
|
9565
9573
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9566
|
-
const { tenantId, projectId, graphId,
|
|
9567
|
-
if (
|
|
9568
|
-
|
|
9574
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9575
|
+
if (subAgentId) {
|
|
9576
|
+
logger20.info(
|
|
9569
9577
|
{
|
|
9570
9578
|
message: "a2a (agent-level)",
|
|
9571
9579
|
tenantId,
|
|
9572
9580
|
projectId,
|
|
9573
9581
|
graphId,
|
|
9574
|
-
|
|
9582
|
+
subAgentId
|
|
9575
9583
|
},
|
|
9576
9584
|
"agent-level a2a endpoint"
|
|
9577
9585
|
);
|
|
@@ -9589,7 +9597,7 @@ app.post("/a2a", async (c) => {
|
|
|
9589
9597
|
}
|
|
9590
9598
|
return a2aHandler(c, agent);
|
|
9591
9599
|
} else {
|
|
9592
|
-
|
|
9600
|
+
logger20.info(
|
|
9593
9601
|
{
|
|
9594
9602
|
message: "a2a (graph-level)",
|
|
9595
9603
|
tenantId,
|
|
@@ -9598,7 +9606,7 @@ app.post("/a2a", async (c) => {
|
|
|
9598
9606
|
},
|
|
9599
9607
|
"graph-level a2a endpoint"
|
|
9600
9608
|
);
|
|
9601
|
-
const graph = await agentsCore.
|
|
9609
|
+
const graph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
9602
9610
|
scopes: { tenantId, projectId, graphId }
|
|
9603
9611
|
});
|
|
9604
9612
|
if (!graph) {
|
|
@@ -9611,7 +9619,7 @@ app.post("/a2a", async (c) => {
|
|
|
9611
9619
|
404
|
|
9612
9620
|
);
|
|
9613
9621
|
}
|
|
9614
|
-
if (!graph.
|
|
9622
|
+
if (!graph.defaultSubAgentId) {
|
|
9615
9623
|
return c.json(
|
|
9616
9624
|
{
|
|
9617
9625
|
jsonrpc: "2.0",
|
|
@@ -9621,10 +9629,10 @@ app.post("/a2a", async (c) => {
|
|
|
9621
9629
|
400
|
|
9622
9630
|
);
|
|
9623
9631
|
}
|
|
9624
|
-
executionContext.
|
|
9632
|
+
executionContext.subAgentId = graph.defaultSubAgentId;
|
|
9625
9633
|
const credentialStores = c.get("credentialStores");
|
|
9626
|
-
const
|
|
9627
|
-
if (!
|
|
9634
|
+
const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9635
|
+
if (!defaultSubAgent) {
|
|
9628
9636
|
return c.json(
|
|
9629
9637
|
{
|
|
9630
9638
|
jsonrpc: "2.0",
|
|
@@ -9634,7 +9642,7 @@ app.post("/a2a", async (c) => {
|
|
|
9634
9642
|
404
|
|
9635
9643
|
);
|
|
9636
9644
|
}
|
|
9637
|
-
return a2aHandler(c,
|
|
9645
|
+
return a2aHandler(c, defaultSubAgent);
|
|
9638
9646
|
}
|
|
9639
9647
|
});
|
|
9640
9648
|
var agents_default = app;
|
|
@@ -9645,20 +9653,20 @@ init_dbClient();
|
|
|
9645
9653
|
// src/a2a/transfer.ts
|
|
9646
9654
|
init_dbClient();
|
|
9647
9655
|
init_logger();
|
|
9648
|
-
var
|
|
9656
|
+
var logger21 = agentsCore.getLogger("Transfer");
|
|
9649
9657
|
async function executeTransfer({
|
|
9650
9658
|
tenantId,
|
|
9651
9659
|
threadId,
|
|
9652
9660
|
projectId,
|
|
9653
|
-
|
|
9661
|
+
targetSubAgentId
|
|
9654
9662
|
}) {
|
|
9655
|
-
|
|
9663
|
+
logger21.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
|
|
9656
9664
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
9657
9665
|
scopes: { tenantId, projectId },
|
|
9658
9666
|
threadId,
|
|
9659
|
-
|
|
9667
|
+
subAgentId: targetSubAgentId
|
|
9660
9668
|
});
|
|
9661
|
-
return { success: true,
|
|
9669
|
+
return { success: true, targetSubAgentId };
|
|
9662
9670
|
}
|
|
9663
9671
|
function isTransferResponse(result) {
|
|
9664
9672
|
return result?.artifacts.some(
|
|
@@ -10238,7 +10246,7 @@ function createMCPStreamHelper() {
|
|
|
10238
10246
|
}
|
|
10239
10247
|
|
|
10240
10248
|
// src/handlers/executionHandler.ts
|
|
10241
|
-
var
|
|
10249
|
+
var logger22 = agentsCore.getLogger("ExecutionHandler");
|
|
10242
10250
|
var ExecutionHandler = class {
|
|
10243
10251
|
constructor() {
|
|
10244
10252
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -10274,7 +10282,7 @@ var ExecutionHandler = class {
|
|
|
10274
10282
|
if (emitOperations) {
|
|
10275
10283
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
10276
10284
|
}
|
|
10277
|
-
|
|
10285
|
+
logger22.info(
|
|
10278
10286
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
10279
10287
|
"Created GraphSession for message execution"
|
|
10280
10288
|
);
|
|
@@ -10289,7 +10297,7 @@ var ExecutionHandler = class {
|
|
|
10289
10297
|
);
|
|
10290
10298
|
}
|
|
10291
10299
|
} catch (error) {
|
|
10292
|
-
|
|
10300
|
+
logger22.error(
|
|
10293
10301
|
{
|
|
10294
10302
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
10295
10303
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10305,7 +10313,7 @@ var ExecutionHandler = class {
|
|
|
10305
10313
|
try {
|
|
10306
10314
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
10307
10315
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
10308
|
-
|
|
10316
|
+
logger22.info(
|
|
10309
10317
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
10310
10318
|
"Attempting to create or reuse existing task"
|
|
10311
10319
|
);
|
|
@@ -10315,7 +10323,7 @@ var ExecutionHandler = class {
|
|
|
10315
10323
|
tenantId,
|
|
10316
10324
|
projectId,
|
|
10317
10325
|
graphId,
|
|
10318
|
-
|
|
10326
|
+
subAgentId: currentAgentId,
|
|
10319
10327
|
contextId: conversationId,
|
|
10320
10328
|
status: "pending",
|
|
10321
10329
|
metadata: {
|
|
@@ -10329,7 +10337,7 @@ var ExecutionHandler = class {
|
|
|
10329
10337
|
agent_id: currentAgentId
|
|
10330
10338
|
}
|
|
10331
10339
|
});
|
|
10332
|
-
|
|
10340
|
+
logger22.info(
|
|
10333
10341
|
{
|
|
10334
10342
|
taskId,
|
|
10335
10343
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -10338,27 +10346,27 @@ var ExecutionHandler = class {
|
|
|
10338
10346
|
);
|
|
10339
10347
|
} catch (error) {
|
|
10340
10348
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
10341
|
-
|
|
10349
|
+
logger22.info(
|
|
10342
10350
|
{ taskId, error: error.message },
|
|
10343
10351
|
"Task already exists, fetching existing task"
|
|
10344
10352
|
);
|
|
10345
10353
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
10346
10354
|
if (existingTask) {
|
|
10347
10355
|
task = existingTask;
|
|
10348
|
-
|
|
10356
|
+
logger22.info(
|
|
10349
10357
|
{ taskId, existingTask },
|
|
10350
10358
|
"Successfully reused existing task from race condition"
|
|
10351
10359
|
);
|
|
10352
10360
|
} else {
|
|
10353
|
-
|
|
10361
|
+
logger22.error({ taskId, error }, "Task constraint failed but task not found");
|
|
10354
10362
|
throw error;
|
|
10355
10363
|
}
|
|
10356
10364
|
} else {
|
|
10357
|
-
|
|
10365
|
+
logger22.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
10358
10366
|
throw error;
|
|
10359
10367
|
}
|
|
10360
10368
|
}
|
|
10361
|
-
|
|
10369
|
+
logger22.debug(
|
|
10362
10370
|
{
|
|
10363
10371
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10364
10372
|
executionType: "create_initial_task",
|
|
@@ -10376,7 +10384,7 @@ var ExecutionHandler = class {
|
|
|
10376
10384
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
10377
10385
|
while (iterations < maxTransfers) {
|
|
10378
10386
|
iterations++;
|
|
10379
|
-
|
|
10387
|
+
logger22.info(
|
|
10380
10388
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
10381
10389
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
10382
10390
|
);
|
|
@@ -10384,10 +10392,10 @@ var ExecutionHandler = class {
|
|
|
10384
10392
|
scopes: { tenantId, projectId },
|
|
10385
10393
|
conversationId
|
|
10386
10394
|
});
|
|
10387
|
-
|
|
10388
|
-
if (activeAgent && activeAgent.
|
|
10389
|
-
currentAgentId = activeAgent.
|
|
10390
|
-
|
|
10395
|
+
logger22.info({ activeAgent }, "activeAgent");
|
|
10396
|
+
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
10397
|
+
currentAgentId = activeAgent.activeSubAgentId;
|
|
10398
|
+
logger22.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
10391
10399
|
}
|
|
10392
10400
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
10393
10401
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -10428,13 +10436,13 @@ var ExecutionHandler = class {
|
|
|
10428
10436
|
});
|
|
10429
10437
|
if (!messageResponse?.result) {
|
|
10430
10438
|
errorCount++;
|
|
10431
|
-
|
|
10439
|
+
logger22.error(
|
|
10432
10440
|
{ currentAgentId, iterations, errorCount },
|
|
10433
10441
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10434
10442
|
);
|
|
10435
10443
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10436
10444
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10437
|
-
|
|
10445
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10438
10446
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10439
10447
|
if (task) {
|
|
10440
10448
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10457,20 +10465,20 @@ var ExecutionHandler = class {
|
|
|
10457
10465
|
}
|
|
10458
10466
|
if (isTransferResponse(messageResponse.result)) {
|
|
10459
10467
|
const transferResponse = messageResponse.result;
|
|
10460
|
-
const
|
|
10468
|
+
const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
|
|
10461
10469
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
10462
|
-
|
|
10470
|
+
logger22.info({ targetSubAgentId, transferReason }, "transfer response");
|
|
10463
10471
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
10464
|
-
const { success,
|
|
10472
|
+
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
10465
10473
|
projectId,
|
|
10466
10474
|
tenantId,
|
|
10467
10475
|
threadId: conversationId,
|
|
10468
|
-
|
|
10476
|
+
targetSubAgentId
|
|
10469
10477
|
});
|
|
10470
10478
|
if (success) {
|
|
10471
10479
|
fromAgentId = currentAgentId;
|
|
10472
10480
|
currentAgentId = newAgentId;
|
|
10473
|
-
|
|
10481
|
+
logger22.info(
|
|
10474
10482
|
{
|
|
10475
10483
|
transferFrom: fromAgentId,
|
|
10476
10484
|
transferTo: currentAgentId,
|
|
@@ -10488,7 +10496,7 @@ var ExecutionHandler = class {
|
|
|
10488
10496
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
10489
10497
|
if (graphSessionData) {
|
|
10490
10498
|
const sessionSummary = graphSessionData.getSummary();
|
|
10491
|
-
|
|
10499
|
+
logger22.info(sessionSummary, "GraphSession data after completion");
|
|
10492
10500
|
}
|
|
10493
10501
|
let textContent = "";
|
|
10494
10502
|
for (const part of responseParts) {
|
|
@@ -10520,8 +10528,7 @@ var ExecutionHandler = class {
|
|
|
10520
10528
|
},
|
|
10521
10529
|
visibility: "user-facing",
|
|
10522
10530
|
messageType: "chat",
|
|
10523
|
-
|
|
10524
|
-
fromAgentId: currentAgentId,
|
|
10531
|
+
fromSubAgentId: currentAgentId,
|
|
10525
10532
|
taskId: task.id
|
|
10526
10533
|
});
|
|
10527
10534
|
const updateTaskStart = Date.now();
|
|
@@ -10542,22 +10549,22 @@ var ExecutionHandler = class {
|
|
|
10542
10549
|
}
|
|
10543
10550
|
});
|
|
10544
10551
|
const updateTaskEnd = Date.now();
|
|
10545
|
-
|
|
10552
|
+
logger22.info(
|
|
10546
10553
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
10547
10554
|
"Completed updateTask operation"
|
|
10548
10555
|
);
|
|
10549
10556
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
10550
10557
|
await sseHelper.complete();
|
|
10551
|
-
|
|
10558
|
+
logger22.info({}, "Ending GraphSession and cleaning up");
|
|
10552
10559
|
graphSessionManager.endSession(requestId2);
|
|
10553
|
-
|
|
10560
|
+
logger22.info({}, "Cleaning up streamHelper");
|
|
10554
10561
|
unregisterStreamHelper(requestId2);
|
|
10555
10562
|
let response;
|
|
10556
10563
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
10557
10564
|
const captured = sseHelper.getCapturedResponse();
|
|
10558
10565
|
response = captured.text || "No response content";
|
|
10559
10566
|
}
|
|
10560
|
-
|
|
10567
|
+
logger22.info({}, "ExecutionHandler returning success");
|
|
10561
10568
|
return { success: true, iterations, response };
|
|
10562
10569
|
} catch (error) {
|
|
10563
10570
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -10568,13 +10575,13 @@ var ExecutionHandler = class {
|
|
|
10568
10575
|
});
|
|
10569
10576
|
}
|
|
10570
10577
|
errorCount++;
|
|
10571
|
-
|
|
10578
|
+
logger22.warn(
|
|
10572
10579
|
{ iterations, errorCount },
|
|
10573
10580
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10574
10581
|
);
|
|
10575
10582
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10576
10583
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10577
|
-
|
|
10584
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10578
10585
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10579
10586
|
if (task) {
|
|
10580
10587
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10595,7 +10602,7 @@ var ExecutionHandler = class {
|
|
|
10595
10602
|
}
|
|
10596
10603
|
}
|
|
10597
10604
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
10598
|
-
|
|
10605
|
+
logger22.error({ maxTransfers, iterations }, errorMessage);
|
|
10599
10606
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
10600
10607
|
if (task) {
|
|
10601
10608
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10614,7 +10621,7 @@ var ExecutionHandler = class {
|
|
|
10614
10621
|
unregisterStreamHelper(requestId2);
|
|
10615
10622
|
return { success: false, error: errorMessage, iterations };
|
|
10616
10623
|
} catch (error) {
|
|
10617
|
-
|
|
10624
|
+
logger22.error({ error }, "Error in execution handler");
|
|
10618
10625
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
10619
10626
|
await sseHelper.writeOperation(
|
|
10620
10627
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -10642,7 +10649,7 @@ var ExecutionHandler = class {
|
|
|
10642
10649
|
// src/routes/chat.ts
|
|
10643
10650
|
init_logger();
|
|
10644
10651
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
10645
|
-
var
|
|
10652
|
+
var logger23 = agentsCore.getLogger("completionsHandler");
|
|
10646
10653
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
10647
10654
|
method: "post",
|
|
10648
10655
|
path: "/completions",
|
|
@@ -10760,7 +10767,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10760
10767
|
tracestate: c.req.header("tracestate"),
|
|
10761
10768
|
baggage: c.req.header("baggage")
|
|
10762
10769
|
};
|
|
10763
|
-
|
|
10770
|
+
logger23.info(
|
|
10764
10771
|
{
|
|
10765
10772
|
otelHeaders,
|
|
10766
10773
|
path: c.req.path,
|
|
@@ -10784,20 +10791,20 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10784
10791
|
scopes: { tenantId, projectId, graphId }
|
|
10785
10792
|
});
|
|
10786
10793
|
let agentGraph;
|
|
10787
|
-
let
|
|
10794
|
+
let defaultSubAgentId;
|
|
10788
10795
|
if (fullGraph) {
|
|
10789
10796
|
agentGraph = {
|
|
10790
10797
|
id: fullGraph.id,
|
|
10791
10798
|
name: fullGraph.name,
|
|
10792
10799
|
tenantId,
|
|
10793
10800
|
projectId,
|
|
10794
|
-
|
|
10801
|
+
defaultSubAgentId: fullGraph.defaultSubAgentId
|
|
10795
10802
|
};
|
|
10796
|
-
const agentKeys = Object.keys(fullGraph.
|
|
10803
|
+
const agentKeys = Object.keys(fullGraph.subAgents || {});
|
|
10797
10804
|
const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
|
|
10798
|
-
|
|
10805
|
+
defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
|
|
10799
10806
|
} else {
|
|
10800
|
-
agentGraph = await agentsCore.
|
|
10807
|
+
agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10801
10808
|
scopes: { tenantId, projectId, graphId }
|
|
10802
10809
|
});
|
|
10803
10810
|
if (!agentGraph) {
|
|
@@ -10806,9 +10813,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10806
10813
|
message: "Agent graph not found"
|
|
10807
10814
|
});
|
|
10808
10815
|
}
|
|
10809
|
-
|
|
10816
|
+
defaultSubAgentId = agentGraph.defaultSubAgentId || "";
|
|
10810
10817
|
}
|
|
10811
|
-
if (!
|
|
10818
|
+
if (!defaultSubAgentId) {
|
|
10812
10819
|
throw agentsCore.createApiError({
|
|
10813
10820
|
code: "not_found",
|
|
10814
10821
|
message: "No default agent found in graph"
|
|
@@ -10818,7 +10825,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10818
10825
|
tenantId,
|
|
10819
10826
|
projectId,
|
|
10820
10827
|
id: conversationId,
|
|
10821
|
-
|
|
10828
|
+
activeSubAgentId: defaultSubAgentId
|
|
10822
10829
|
});
|
|
10823
10830
|
const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
|
|
10824
10831
|
scopes: { tenantId, projectId },
|
|
@@ -10828,13 +10835,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10828
10835
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
10829
10836
|
scopes: { tenantId, projectId },
|
|
10830
10837
|
conversationId,
|
|
10831
|
-
|
|
10838
|
+
subAgentId: defaultSubAgentId
|
|
10832
10839
|
});
|
|
10833
10840
|
}
|
|
10834
|
-
const
|
|
10835
|
-
const agentInfo = await agentsCore.
|
|
10841
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
10842
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10836
10843
|
scopes: { tenantId, projectId, graphId },
|
|
10837
|
-
|
|
10844
|
+
subAgentId
|
|
10838
10845
|
});
|
|
10839
10846
|
if (!agentInfo) {
|
|
10840
10847
|
throw agentsCore.createApiError({
|
|
@@ -10853,14 +10860,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10853
10860
|
dbClient: dbClient_default,
|
|
10854
10861
|
credentialStores
|
|
10855
10862
|
});
|
|
10856
|
-
|
|
10863
|
+
logger23.info(
|
|
10857
10864
|
{
|
|
10858
10865
|
tenantId,
|
|
10859
10866
|
projectId,
|
|
10860
10867
|
graphId,
|
|
10861
10868
|
conversationId,
|
|
10862
|
-
|
|
10863
|
-
|
|
10869
|
+
defaultSubAgentId,
|
|
10870
|
+
activeSubAgentId: activeAgent?.activeSubAgentId || "none",
|
|
10864
10871
|
hasContextConfig: !!agentGraph.contextConfigId,
|
|
10865
10872
|
hasHeaders: !!body.headers,
|
|
10866
10873
|
hasValidatedContext: !!validatedContext,
|
|
@@ -10901,7 +10908,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10901
10908
|
try {
|
|
10902
10909
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10903
10910
|
await sseHelper.writeRole();
|
|
10904
|
-
|
|
10911
|
+
logger23.info({ subAgentId }, "Starting execution");
|
|
10905
10912
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10906
10913
|
const emitOperations = emitOperationsHeader === "true";
|
|
10907
10914
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10909,12 +10916,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10909
10916
|
executionContext,
|
|
10910
10917
|
conversationId,
|
|
10911
10918
|
userMessage,
|
|
10912
|
-
initialAgentId:
|
|
10919
|
+
initialAgentId: subAgentId,
|
|
10913
10920
|
requestId: requestId2,
|
|
10914
10921
|
sseHelper,
|
|
10915
10922
|
emitOperations
|
|
10916
10923
|
});
|
|
10917
|
-
|
|
10924
|
+
logger23.info(
|
|
10918
10925
|
{ result },
|
|
10919
10926
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10920
10927
|
);
|
|
@@ -10928,7 +10935,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10928
10935
|
}
|
|
10929
10936
|
await sseHelper.complete();
|
|
10930
10937
|
} catch (error) {
|
|
10931
|
-
|
|
10938
|
+
logger23.error(
|
|
10932
10939
|
{
|
|
10933
10940
|
error: error instanceof Error ? error.message : error,
|
|
10934
10941
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10945,12 +10952,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10945
10952
|
);
|
|
10946
10953
|
await sseHelper.complete();
|
|
10947
10954
|
} catch (streamError) {
|
|
10948
|
-
|
|
10955
|
+
logger23.error({ streamError }, "Failed to write error to stream");
|
|
10949
10956
|
}
|
|
10950
10957
|
}
|
|
10951
10958
|
});
|
|
10952
10959
|
} catch (error) {
|
|
10953
|
-
|
|
10960
|
+
logger23.error(
|
|
10954
10961
|
{
|
|
10955
10962
|
error: error instanceof Error ? error.message : error,
|
|
10956
10963
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10978,7 +10985,7 @@ var chat_default = app2;
|
|
|
10978
10985
|
init_dbClient();
|
|
10979
10986
|
init_logger();
|
|
10980
10987
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10981
|
-
var
|
|
10988
|
+
var logger24 = agentsCore.getLogger("chatDataStream");
|
|
10982
10989
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10983
10990
|
method: "post",
|
|
10984
10991
|
path: "/chat",
|
|
@@ -11043,7 +11050,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11043
11050
|
"project.id": projectId
|
|
11044
11051
|
});
|
|
11045
11052
|
}
|
|
11046
|
-
const agentGraph = await agentsCore.
|
|
11053
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11047
11054
|
scopes: { tenantId, projectId, graphId }
|
|
11048
11055
|
});
|
|
11049
11056
|
if (!agentGraph) {
|
|
@@ -11052,9 +11059,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11052
11059
|
message: "Agent graph not found"
|
|
11053
11060
|
});
|
|
11054
11061
|
}
|
|
11055
|
-
const
|
|
11062
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11056
11063
|
const graphName = agentGraph.name;
|
|
11057
|
-
if (!
|
|
11064
|
+
if (!defaultSubAgentId) {
|
|
11058
11065
|
throw agentsCore.createApiError({
|
|
11059
11066
|
code: "bad_request",
|
|
11060
11067
|
message: "Graph does not have a default agent configured"
|
|
@@ -11068,13 +11075,13 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11068
11075
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
11069
11076
|
scopes: { tenantId, projectId },
|
|
11070
11077
|
conversationId,
|
|
11071
|
-
|
|
11078
|
+
subAgentId: defaultSubAgentId
|
|
11072
11079
|
});
|
|
11073
11080
|
}
|
|
11074
|
-
const
|
|
11075
|
-
const agentInfo = await agentsCore.
|
|
11081
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
11082
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11076
11083
|
scopes: { tenantId, projectId, graphId },
|
|
11077
|
-
|
|
11084
|
+
subAgentId
|
|
11078
11085
|
});
|
|
11079
11086
|
if (!agentInfo) {
|
|
11080
11087
|
throw agentsCore.createApiError({
|
|
@@ -11095,7 +11102,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11095
11102
|
});
|
|
11096
11103
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
11097
11104
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
11098
|
-
|
|
11105
|
+
logger24.info({ userText, lastUserMessage }, "userText");
|
|
11099
11106
|
const messageSpan = api.trace.getActiveSpan();
|
|
11100
11107
|
if (messageSpan) {
|
|
11101
11108
|
messageSpan.setAttributes({
|
|
@@ -11131,7 +11138,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11131
11138
|
executionContext,
|
|
11132
11139
|
conversationId,
|
|
11133
11140
|
userMessage: userText,
|
|
11134
|
-
initialAgentId:
|
|
11141
|
+
initialAgentId: subAgentId,
|
|
11135
11142
|
requestId: `chatds-${Date.now()}`,
|
|
11136
11143
|
sseHelper: streamHelper,
|
|
11137
11144
|
emitOperations
|
|
@@ -11140,7 +11147,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11140
11147
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
11141
11148
|
}
|
|
11142
11149
|
} catch (err) {
|
|
11143
|
-
|
|
11150
|
+
logger24.error({ err }, "Streaming error");
|
|
11144
11151
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
11145
11152
|
} finally {
|
|
11146
11153
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -11161,7 +11168,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11161
11168
|
)
|
|
11162
11169
|
);
|
|
11163
11170
|
} catch (error) {
|
|
11164
|
-
|
|
11171
|
+
logger24.error({ error }, "chatDataStream error");
|
|
11165
11172
|
throw agentsCore.createApiError({
|
|
11166
11173
|
code: "internal_server_error",
|
|
11167
11174
|
message: "Failed to process chat completion"
|
|
@@ -11176,7 +11183,7 @@ init_logger();
|
|
|
11176
11183
|
function createMCPSchema(schema) {
|
|
11177
11184
|
return schema;
|
|
11178
11185
|
}
|
|
11179
|
-
var
|
|
11186
|
+
var logger25 = agentsCore.getLogger("mcp");
|
|
11180
11187
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
11181
11188
|
constructor() {
|
|
11182
11189
|
__publicField(this, "mockRes");
|
|
@@ -11231,21 +11238,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
11231
11238
|
id: 0
|
|
11232
11239
|
});
|
|
11233
11240
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
11234
|
-
|
|
11241
|
+
logger25.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
11235
11242
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
11236
11243
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
11237
11244
|
try {
|
|
11238
11245
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
11239
|
-
|
|
11246
|
+
logger25.info({ sessionId }, "Successfully spoofed initialization");
|
|
11240
11247
|
} catch (spoofError) {
|
|
11241
|
-
|
|
11248
|
+
logger25.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
11242
11249
|
}
|
|
11243
11250
|
};
|
|
11244
11251
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
11245
11252
|
const sessionId = req.headers["mcp-session-id"];
|
|
11246
|
-
|
|
11253
|
+
logger25.info({ sessionId }, "Received MCP session ID");
|
|
11247
11254
|
if (!sessionId) {
|
|
11248
|
-
|
|
11255
|
+
logger25.info({ body }, "Missing session ID");
|
|
11249
11256
|
res.writeHead(400).end(
|
|
11250
11257
|
JSON.stringify({
|
|
11251
11258
|
jsonrpc: "2.0",
|
|
@@ -11271,7 +11278,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11271
11278
|
scopes: { tenantId, projectId },
|
|
11272
11279
|
conversationId: sessionId
|
|
11273
11280
|
});
|
|
11274
|
-
|
|
11281
|
+
logger25.info(
|
|
11275
11282
|
{
|
|
11276
11283
|
sessionId,
|
|
11277
11284
|
conversationFound: !!conversation,
|
|
@@ -11282,7 +11289,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11282
11289
|
"Conversation lookup result"
|
|
11283
11290
|
);
|
|
11284
11291
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
11285
|
-
|
|
11292
|
+
logger25.info(
|
|
11286
11293
|
{ sessionId, conversationId: conversation?.id },
|
|
11287
11294
|
"MCP session not found or invalid"
|
|
11288
11295
|
);
|
|
@@ -11331,7 +11338,7 @@ var processUserMessage = async (tenantId, projectId, conversationId, query) => {
|
|
|
11331
11338
|
messageType: "chat"
|
|
11332
11339
|
});
|
|
11333
11340
|
};
|
|
11334
|
-
var executeAgentQuery = async (executionContext, conversationId, query,
|
|
11341
|
+
var executeAgentQuery = async (executionContext, conversationId, query, defaultSubAgentId) => {
|
|
11335
11342
|
const requestId2 = `mcp-${Date.now()}`;
|
|
11336
11343
|
const mcpStreamHelper = createMCPStreamHelper();
|
|
11337
11344
|
const executionHandler = new ExecutionHandler();
|
|
@@ -11339,11 +11346,11 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11339
11346
|
executionContext,
|
|
11340
11347
|
conversationId,
|
|
11341
11348
|
userMessage: query,
|
|
11342
|
-
initialAgentId:
|
|
11349
|
+
initialAgentId: defaultSubAgentId,
|
|
11343
11350
|
requestId: requestId2,
|
|
11344
11351
|
sseHelper: mcpStreamHelper
|
|
11345
11352
|
});
|
|
11346
|
-
|
|
11353
|
+
logger25.info(
|
|
11347
11354
|
{ result },
|
|
11348
11355
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11349
11356
|
);
|
|
@@ -11370,7 +11377,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11370
11377
|
var getServer = async (headers, executionContext, conversationId, credentialStores) => {
|
|
11371
11378
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11372
11379
|
setupTracing(conversationId, tenantId, graphId);
|
|
11373
|
-
const agentGraph = await agentsCore.
|
|
11380
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11374
11381
|
scopes: { tenantId, projectId, graphId }
|
|
11375
11382
|
});
|
|
11376
11383
|
if (!agentGraph) {
|
|
@@ -11391,7 +11398,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11391
11398
|
},
|
|
11392
11399
|
async ({ query }) => {
|
|
11393
11400
|
try {
|
|
11394
|
-
if (!agentGraph.
|
|
11401
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11395
11402
|
return {
|
|
11396
11403
|
content: [
|
|
11397
11404
|
{
|
|
@@ -11402,10 +11409,10 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11402
11409
|
isError: true
|
|
11403
11410
|
};
|
|
11404
11411
|
}
|
|
11405
|
-
const
|
|
11406
|
-
const agentInfo = await agentsCore.
|
|
11412
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11413
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11407
11414
|
scopes: { tenantId, projectId, graphId },
|
|
11408
|
-
|
|
11415
|
+
subAgentId: defaultSubAgentId
|
|
11409
11416
|
});
|
|
11410
11417
|
if (!agentInfo) {
|
|
11411
11418
|
return {
|
|
@@ -11427,7 +11434,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11427
11434
|
dbClient: dbClient_default,
|
|
11428
11435
|
credentialStores
|
|
11429
11436
|
});
|
|
11430
|
-
|
|
11437
|
+
logger25.info(
|
|
11431
11438
|
{
|
|
11432
11439
|
tenantId,
|
|
11433
11440
|
projectId,
|
|
@@ -11440,7 +11447,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11440
11447
|
"parameters"
|
|
11441
11448
|
);
|
|
11442
11449
|
await processUserMessage(tenantId, projectId, conversationId, query);
|
|
11443
|
-
return executeAgentQuery(executionContext, conversationId, query,
|
|
11450
|
+
return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
|
|
11444
11451
|
} catch (error) {
|
|
11445
11452
|
return {
|
|
11446
11453
|
content: [
|
|
@@ -11489,9 +11496,9 @@ var validateRequestParameters = (c) => {
|
|
|
11489
11496
|
};
|
|
11490
11497
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
11491
11498
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11492
|
-
|
|
11499
|
+
logger25.info({ body }, "Received initialization request");
|
|
11493
11500
|
const sessionId = agentsCore.getConversationId();
|
|
11494
|
-
const agentGraph = await agentsCore.
|
|
11501
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11495
11502
|
scopes: { tenantId, projectId, graphId }
|
|
11496
11503
|
});
|
|
11497
11504
|
if (!agentGraph) {
|
|
@@ -11504,7 +11511,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11504
11511
|
{ status: 404 }
|
|
11505
11512
|
);
|
|
11506
11513
|
}
|
|
11507
|
-
if (!agentGraph.
|
|
11514
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11508
11515
|
return c.json(
|
|
11509
11516
|
{
|
|
11510
11517
|
jsonrpc: "2.0",
|
|
@@ -11518,7 +11525,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11518
11525
|
id: sessionId,
|
|
11519
11526
|
tenantId,
|
|
11520
11527
|
projectId,
|
|
11521
|
-
|
|
11528
|
+
activeSubAgentId: agentGraph.defaultSubAgentId,
|
|
11522
11529
|
metadata: {
|
|
11523
11530
|
sessionData: {
|
|
11524
11531
|
graphId,
|
|
@@ -11529,7 +11536,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11529
11536
|
}
|
|
11530
11537
|
}
|
|
11531
11538
|
});
|
|
11532
|
-
|
|
11539
|
+
logger25.info(
|
|
11533
11540
|
{ sessionId, conversationId: conversation.id },
|
|
11534
11541
|
"Created MCP session as conversation"
|
|
11535
11542
|
);
|
|
@@ -11538,9 +11545,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11538
11545
|
});
|
|
11539
11546
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
11540
11547
|
await server.connect(transport);
|
|
11541
|
-
|
|
11548
|
+
logger25.info({ sessionId }, "Server connected for initialization");
|
|
11542
11549
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
11543
|
-
|
|
11550
|
+
logger25.info(
|
|
11544
11551
|
{
|
|
11545
11552
|
sessionId,
|
|
11546
11553
|
bodyMethod: body?.method,
|
|
@@ -11549,7 +11556,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11549
11556
|
"About to handle initialization request"
|
|
11550
11557
|
);
|
|
11551
11558
|
await transport.handleRequest(req, res, body);
|
|
11552
|
-
|
|
11559
|
+
logger25.info({ sessionId }, "Successfully handled initialization request");
|
|
11553
11560
|
return fetchToNode.toFetchResponse(res);
|
|
11554
11561
|
};
|
|
11555
11562
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -11577,8 +11584,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11577
11584
|
sessionId,
|
|
11578
11585
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
11579
11586
|
);
|
|
11580
|
-
|
|
11581
|
-
|
|
11587
|
+
logger25.info({ sessionId }, "Server connected and transport initialized");
|
|
11588
|
+
logger25.info(
|
|
11582
11589
|
{
|
|
11583
11590
|
sessionId,
|
|
11584
11591
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -11592,9 +11599,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11592
11599
|
);
|
|
11593
11600
|
try {
|
|
11594
11601
|
await transport.handleRequest(req, res, body);
|
|
11595
|
-
|
|
11602
|
+
logger25.info({ sessionId }, "Successfully handled MCP request");
|
|
11596
11603
|
} catch (transportError) {
|
|
11597
|
-
|
|
11604
|
+
logger25.error(
|
|
11598
11605
|
{
|
|
11599
11606
|
sessionId,
|
|
11600
11607
|
error: transportError,
|
|
@@ -11645,13 +11652,13 @@ app4.openapi(
|
|
|
11645
11652
|
}
|
|
11646
11653
|
const { executionContext } = paramValidation;
|
|
11647
11654
|
const body = c.get("requestBody") || {};
|
|
11648
|
-
|
|
11655
|
+
logger25.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
11649
11656
|
const isInitRequest = body.method === "initialize";
|
|
11650
11657
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
11651
11658
|
const validatedContext = c.get("validatedContext") || {};
|
|
11652
11659
|
const credentialStores = c.get("credentialStores");
|
|
11653
|
-
|
|
11654
|
-
|
|
11660
|
+
logger25.info({ validatedContext }, "Validated context");
|
|
11661
|
+
logger25.info({ req }, "request");
|
|
11655
11662
|
if (isInitRequest) {
|
|
11656
11663
|
return await handleInitializationRequest(
|
|
11657
11664
|
body,
|
|
@@ -11673,7 +11680,7 @@ app4.openapi(
|
|
|
11673
11680
|
);
|
|
11674
11681
|
}
|
|
11675
11682
|
} catch (e) {
|
|
11676
|
-
|
|
11683
|
+
logger25.error(
|
|
11677
11684
|
{
|
|
11678
11685
|
error: e instanceof Error ? e.message : e,
|
|
11679
11686
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -11685,7 +11692,7 @@ app4.openapi(
|
|
|
11685
11692
|
}
|
|
11686
11693
|
);
|
|
11687
11694
|
app4.get("/", async (c) => {
|
|
11688
|
-
|
|
11695
|
+
logger25.info({}, "Received GET MCP request");
|
|
11689
11696
|
return c.json(
|
|
11690
11697
|
{
|
|
11691
11698
|
jsonrpc: "2.0",
|
|
@@ -11699,7 +11706,7 @@ app4.get("/", async (c) => {
|
|
|
11699
11706
|
);
|
|
11700
11707
|
});
|
|
11701
11708
|
app4.delete("/", async (c) => {
|
|
11702
|
-
|
|
11709
|
+
logger25.info({}, "Received DELETE MCP request");
|
|
11703
11710
|
return c.json(
|
|
11704
11711
|
{
|
|
11705
11712
|
jsonrpc: "2.0",
|
|
@@ -11712,7 +11719,7 @@ app4.delete("/", async (c) => {
|
|
|
11712
11719
|
var mcp_default = app4;
|
|
11713
11720
|
|
|
11714
11721
|
// src/app.ts
|
|
11715
|
-
var
|
|
11722
|
+
var logger26 = agentsCore.getLogger("agents-run-api");
|
|
11716
11723
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
11717
11724
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
11718
11725
|
app6.use("*", otel.otel());
|
|
@@ -11728,7 +11735,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11728
11735
|
const body = await c.req.json();
|
|
11729
11736
|
c.set("requestBody", body);
|
|
11730
11737
|
} catch (error) {
|
|
11731
|
-
|
|
11738
|
+
logger26.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
11732
11739
|
}
|
|
11733
11740
|
}
|
|
11734
11741
|
return next();
|
|
@@ -11779,8 +11786,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11779
11786
|
if (!isExpectedError) {
|
|
11780
11787
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11781
11788
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11782
|
-
if (
|
|
11783
|
-
|
|
11789
|
+
if (logger26) {
|
|
11790
|
+
logger26.error(
|
|
11784
11791
|
{
|
|
11785
11792
|
error: err,
|
|
11786
11793
|
message: errorMessage,
|
|
@@ -11792,8 +11799,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11792
11799
|
);
|
|
11793
11800
|
}
|
|
11794
11801
|
} else {
|
|
11795
|
-
if (
|
|
11796
|
-
|
|
11802
|
+
if (logger26) {
|
|
11803
|
+
logger26.error(
|
|
11797
11804
|
{
|
|
11798
11805
|
error: err,
|
|
11799
11806
|
path: c.req.path,
|
|
@@ -11810,8 +11817,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11810
11817
|
const response = err.getResponse();
|
|
11811
11818
|
return response;
|
|
11812
11819
|
} catch (responseError) {
|
|
11813
|
-
if (
|
|
11814
|
-
|
|
11820
|
+
if (logger26) {
|
|
11821
|
+
logger26.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11815
11822
|
}
|
|
11816
11823
|
}
|
|
11817
11824
|
}
|
|
@@ -11845,7 +11852,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11845
11852
|
app6.use("*", async (c, next) => {
|
|
11846
11853
|
const executionContext = c.get("executionContext");
|
|
11847
11854
|
if (!executionContext) {
|
|
11848
|
-
|
|
11855
|
+
logger26.debug({}, "Empty execution context");
|
|
11849
11856
|
return next();
|
|
11850
11857
|
}
|
|
11851
11858
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11854,7 +11861,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11854
11861
|
if (requestBody) {
|
|
11855
11862
|
conversationId = requestBody.conversationId;
|
|
11856
11863
|
if (!conversationId) {
|
|
11857
|
-
|
|
11864
|
+
logger26.debug({ requestBody }, "No conversation ID found in request body");
|
|
11858
11865
|
}
|
|
11859
11866
|
}
|
|
11860
11867
|
const entries = Object.fromEntries(
|
|
@@ -11869,7 +11876,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11869
11876
|
})
|
|
11870
11877
|
);
|
|
11871
11878
|
if (!Object.keys(entries).length) {
|
|
11872
|
-
|
|
11879
|
+
logger26.debug({}, "Empty entries for baggage");
|
|
11873
11880
|
return next();
|
|
11874
11881
|
}
|
|
11875
11882
|
const bag = Object.entries(entries).reduce(
|