@inkeep/agents-run-api 0.16.3 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { flushBatchProcessor } from './chunk-XO4RG36I.js';
2
2
  import { getLogger } from './chunk-A2S7GSHL.js';
3
- import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-5GUNCN5X.js';
3
+ import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-DQQRVSJS.js';
4
4
  import { dbClient_default } from './chunk-7IMXW4RD.js';
5
5
  import { env } from './chunk-NZHNG4A3.js';
6
6
  import { __publicField } from './chunk-PKBMQBKP.js';
7
- import { getLogger as getLogger$1, getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
7
+ import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } from '@inkeep/agents-core';
8
8
  import { otel } from '@hono/otel';
9
9
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
10
10
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
@@ -41,7 +41,7 @@ function createExecutionContext(params) {
41
41
  graphId: params.graphId,
42
42
  baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
43
43
  apiKeyId: params.apiKeyId,
44
- agentId: params.agentId
44
+ subAgentId: params.subAgentId
45
45
  };
46
46
  }
47
47
 
@@ -56,16 +56,18 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
56
56
  const tenantId = c.req.header("x-inkeep-tenant-id");
57
57
  const projectId = c.req.header("x-inkeep-project-id");
58
58
  const graphId = c.req.header("x-inkeep-graph-id");
59
- const agentId = c.req.header("x-inkeep-agent-id");
60
- const proto = c.req.header("x-forwarded-proto") ?? "http";
61
- const host = c.req.header("x-forwarded-host") ?? c.req.header("host");
62
- const baseUrl = `${proto}://${host}`;
59
+ const subAgentId = c.req.header("x-inkeep-agent-id");
60
+ const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
61
+ const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
62
+ const host = fwdHost ?? c.req.header("host");
63
+ const reqUrl = new URL(c.req.url);
64
+ const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
63
65
  if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
64
66
  let executionContext;
65
67
  if (authHeader?.startsWith("Bearer ")) {
66
68
  try {
67
69
  executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
68
- executionContext.agentId = agentId;
70
+ executionContext.subAgentId = subAgentId;
69
71
  logger.info({}, "Development/test environment - API key authenticated successfully");
70
72
  } catch {
71
73
  executionContext = createExecutionContext({
@@ -75,7 +77,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
75
77
  graphId: graphId || "test-graph",
76
78
  apiKeyId: "test-key",
77
79
  baseUrl,
78
- agentId
80
+ subAgentId
79
81
  });
80
82
  logger.info(
81
83
  {},
@@ -90,7 +92,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
90
92
  graphId: graphId || "test-graph",
91
93
  apiKeyId: "test-key",
92
94
  baseUrl,
93
- agentId
95
+ subAgentId
94
96
  });
95
97
  logger.info(
96
98
  {},
@@ -121,7 +123,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
121
123
  graphId,
122
124
  apiKeyId: "bypass",
123
125
  baseUrl,
124
- agentId
126
+ subAgentId
125
127
  });
126
128
  c.set("executionContext", executionContext);
127
129
  logger.info({}, "Bypass secret authenticated successfully");
@@ -129,7 +131,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
129
131
  return;
130
132
  } else if (apiKey) {
131
133
  const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
132
- executionContext.agentId = agentId;
134
+ executionContext.subAgentId = subAgentId;
133
135
  c.set("executionContext", executionContext);
134
136
  logger.info({}, "API key authenticated successfully");
135
137
  await next();
@@ -147,14 +149,14 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
147
149
  }
148
150
  try {
149
151
  const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
150
- executionContext.agentId = agentId;
152
+ executionContext.subAgentId = subAgentId;
151
153
  c.set("executionContext", executionContext);
152
154
  logger.debug(
153
155
  {
154
156
  tenantId: executionContext.tenantId,
155
157
  projectId: executionContext.projectId,
156
158
  graphId: executionContext.graphId,
157
- agentId: executionContext.agentId
159
+ subAgentId: executionContext.subAgentId
158
160
  },
159
161
  "API key authenticated successfully"
160
162
  );
@@ -322,7 +324,7 @@ async function handleMessageSend(c, agent, request) {
322
324
  logger2.warn(
323
325
  {
324
326
  taskId: task.id,
325
- agentId: agent.agentId,
327
+ subAgentId: agent.subAgentId,
326
328
  originalMessage: params.message
327
329
  },
328
330
  "Created fallback message content for empty delegation message"
@@ -343,7 +345,7 @@ async function handleMessageSend(c, agent, request) {
343
345
  taskContextId: task.context?.conversationId,
344
346
  metadataContextId: params.message.metadata?.conversationId,
345
347
  finalContextId: effectiveContextId,
346
- agentId: agent.agentId
348
+ subAgentId: agent.subAgentId
347
349
  },
348
350
  "A2A contextId resolution for delegation"
349
351
  );
@@ -359,11 +361,11 @@ async function handleMessageSend(c, agent, request) {
359
361
  message_id: params.message.messageId || "",
360
362
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
361
363
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
362
- agent_id: agent.agentId,
364
+ agent_id: agent.subAgentId,
363
365
  graph_id: graphId || "",
364
366
  stream_request_id: params.message.metadata?.stream_request_id
365
367
  },
366
- agentId: agent.agentId,
368
+ subAgentId: agent.subAgentId,
367
369
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
368
370
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
369
371
  });
@@ -386,17 +388,17 @@ async function handleMessageSend(c, agent, request) {
386
388
  };
387
389
  if (params.message.metadata?.fromAgentId) {
388
390
  messageData.fromAgentId = params.message.metadata.fromAgentId;
389
- messageData.toAgentId = agent.agentId;
391
+ messageData.toAgentId = agent.subAgentId;
390
392
  } else if (params.message.metadata?.fromExternalAgentId) {
391
393
  messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
392
- messageData.toAgentId = agent.agentId;
394
+ messageData.toAgentId = agent.subAgentId;
393
395
  }
394
396
  await createMessage(dbClient_default)(messageData);
395
397
  logger2.info(
396
398
  {
397
399
  fromAgentId: params.message.metadata.fromAgentId,
398
400
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
399
- toAgentId: agent.agentId,
401
+ toAgentId: agent.subAgentId,
400
402
  conversationId: effectiveContextId,
401
403
  messageType: "a2a-request",
402
404
  taskId: task.id
@@ -409,7 +411,7 @@ async function handleMessageSend(c, agent, request) {
409
411
  error,
410
412
  fromAgentId: params.message.metadata.fromAgentId,
411
413
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
412
- toAgentId: agent.agentId,
414
+ toAgentId: agent.subAgentId,
413
415
  conversationId: effectiveContextId
414
416
  },
415
417
  "Failed to store A2A message in database"
@@ -426,7 +428,7 @@ async function handleMessageSend(c, agent, request) {
426
428
  message_id: params.message.messageId || "",
427
429
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
428
430
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
429
- agent_id: agent.agentId,
431
+ agent_id: agent.subAgentId,
430
432
  graph_id: graphId || ""
431
433
  }
432
434
  }
@@ -460,7 +462,7 @@ async function handleMessageSend(c, agent, request) {
460
462
  kind: "data",
461
463
  data: {
462
464
  type: "transfer",
463
- targetAgentId: transferPart.data.target
465
+ targetSubAgentId: transferPart.data.target
464
466
  }
465
467
  },
466
468
  {
@@ -760,7 +762,7 @@ async function handleGetCapabilities(c, agent, request) {
760
762
  async function handleGetStatus(c, agent, request) {
761
763
  return c.json({
762
764
  jsonrpc: "2.0",
763
- result: { status: "ready", agentId: agent.agentId },
765
+ result: { status: "ready", subAgentId: agent.subAgentId },
764
766
  id: request.id
765
767
  });
766
768
  }
@@ -823,7 +825,6 @@ async function handleTasksResubscribe(c, agent, request) {
823
825
  });
824
826
  }
825
827
  }
826
- getLogger$1("agents");
827
828
  function createAgentCard({
828
829
  dbAgent,
829
830
  baseUrl
@@ -901,7 +902,7 @@ async function hydrateAgent({
901
902
  tenantId: dbAgent.tenantId,
902
903
  projectId: dbAgent.projectId,
903
904
  graphId,
904
- agentId: dbAgent.id,
905
+ subAgentId: dbAgent.id,
905
906
  baseUrl,
906
907
  apiKey
907
908
  });
@@ -911,7 +912,7 @@ async function hydrateAgent({
911
912
  baseUrl
912
913
  });
913
914
  return {
914
- agentId: dbAgent.id,
915
+ subAgentId: dbAgent.id,
915
916
  tenantId: dbAgent.tenantId,
916
917
  projectId: dbAgent.projectId,
917
918
  graphId,
@@ -924,13 +925,13 @@ async function hydrateAgent({
924
925
  }
925
926
  }
926
927
  async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
927
- const { tenantId, projectId, graphId, agentId, baseUrl, apiKey } = executionContext;
928
- if (!agentId) {
928
+ const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
929
+ if (!subAgentId) {
929
930
  throw new Error("Agent ID is required");
930
931
  }
931
- const dbAgent = await getAgentById(dbClient_default)({
932
+ const dbAgent = await getSubAgentById(dbClient_default)({
932
933
  scopes: { tenantId, projectId, graphId },
933
- agentId
934
+ subAgentId
934
935
  });
935
936
  if (!dbAgent) {
936
937
  return null;
@@ -944,7 +945,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
944
945
  apiKey
945
946
  });
946
947
  }
947
- var logger4 = getLogger("ModelFactory");
948
+ var logger3 = getLogger("ModelFactory");
948
949
  var _ModelFactory = class _ModelFactory {
949
950
  /**
950
951
  * Create a provider instance with custom configuration
@@ -1006,7 +1007,7 @@ var _ModelFactory = class _ModelFactory {
1006
1007
  }
1007
1008
  const modelString = modelSettings.model.trim();
1008
1009
  const { provider, modelName } = _ModelFactory.parseModelString(modelString);
1009
- logger4.debug(
1010
+ logger3.debug(
1010
1011
  {
1011
1012
  provider,
1012
1013
  model: modelName,
@@ -1017,7 +1018,7 @@ var _ModelFactory = class _ModelFactory {
1017
1018
  );
1018
1019
  const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
1019
1020
  if (Object.keys(providerConfig).length > 0) {
1020
- logger4.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
1021
+ logger3.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
1021
1022
  const customProvider = _ModelFactory.createProvider(provider, providerConfig);
1022
1023
  return customProvider.languageModel(modelName);
1023
1024
  }
@@ -1133,7 +1134,7 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
1133
1134
  "gateway"
1134
1135
  ]);
1135
1136
  var ModelFactory = _ModelFactory;
1136
- var logger5 = getLogger("ToolSessionManager");
1137
+ var logger4 = getLogger("ToolSessionManager");
1137
1138
  var _ToolSessionManager = class _ToolSessionManager {
1138
1139
  // 5 minutes
1139
1140
  constructor() {
@@ -1168,7 +1169,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1168
1169
  createdAt: Date.now()
1169
1170
  };
1170
1171
  this.sessions.set(sessionId, session);
1171
- logger5.debug(
1172
+ logger4.debug(
1172
1173
  {
1173
1174
  sessionId,
1174
1175
  tenantId,
@@ -1186,10 +1187,10 @@ var _ToolSessionManager = class _ToolSessionManager {
1186
1187
  */
1187
1188
  ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
1188
1189
  if (this.sessions.has(sessionId)) {
1189
- logger5.debug({ sessionId }, "Graph session already exists, reusing");
1190
+ logger4.debug({ sessionId }, "Graph session already exists, reusing");
1190
1191
  return sessionId;
1191
1192
  }
1192
- logger5.debug(
1193
+ logger4.debug(
1193
1194
  { sessionId, tenantId, contextId, taskId },
1194
1195
  "Creating new graph-scoped tool session"
1195
1196
  );
@@ -1201,7 +1202,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1201
1202
  recordToolResult(sessionId, toolResult) {
1202
1203
  const session = this.sessions.get(sessionId);
1203
1204
  if (!session) {
1204
- logger5.warn(
1205
+ logger4.warn(
1205
1206
  {
1206
1207
  sessionId,
1207
1208
  toolCallId: toolResult.toolCallId,
@@ -1213,7 +1214,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1213
1214
  return;
1214
1215
  }
1215
1216
  session.toolResults.set(toolResult.toolCallId, toolResult);
1216
- logger5.debug(
1217
+ logger4.debug(
1217
1218
  {
1218
1219
  sessionId,
1219
1220
  toolCallId: toolResult.toolCallId,
@@ -1228,7 +1229,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1228
1229
  getToolResult(sessionId, toolCallId) {
1229
1230
  const session = this.sessions.get(sessionId);
1230
1231
  if (!session) {
1231
- logger5.warn(
1232
+ logger4.warn(
1232
1233
  {
1233
1234
  sessionId,
1234
1235
  toolCallId,
@@ -1241,7 +1242,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1241
1242
  }
1242
1243
  const result = session.toolResults.get(toolCallId);
1243
1244
  if (!result) {
1244
- logger5.warn(
1245
+ logger4.warn(
1245
1246
  {
1246
1247
  sessionId,
1247
1248
  toolCallId,
@@ -1251,7 +1252,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1251
1252
  "Tool result not found"
1252
1253
  );
1253
1254
  } else {
1254
- logger5.debug(
1255
+ logger4.debug(
1255
1256
  {
1256
1257
  sessionId,
1257
1258
  toolCallId,
@@ -1290,10 +1291,10 @@ var _ToolSessionManager = class _ToolSessionManager {
1290
1291
  }
1291
1292
  for (const sessionId of expiredSessions) {
1292
1293
  this.sessions.delete(sessionId);
1293
- logger5.debug({ sessionId }, "Cleaned up expired tool session");
1294
+ logger4.debug({ sessionId }, "Cleaned up expired tool session");
1294
1295
  }
1295
1296
  if (expiredSessions.length > 0) {
1296
- logger5.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
1297
+ logger4.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
1297
1298
  }
1298
1299
  }
1299
1300
  };
@@ -1363,7 +1364,7 @@ function extractFullFields(schema) {
1363
1364
  }
1364
1365
 
1365
1366
  // src/services/ArtifactService.ts
1366
- var logger7 = getLogger("ArtifactService");
1367
+ var logger6 = getLogger("ArtifactService");
1367
1368
  var _ArtifactService = class _ArtifactService {
1368
1369
  constructor(context) {
1369
1370
  this.context = context;
@@ -1395,7 +1396,7 @@ var _ArtifactService = class _ArtifactService {
1395
1396
  id: taskId
1396
1397
  });
1397
1398
  if (!task) {
1398
- logger7.warn({ taskId }, "Task not found when fetching artifacts");
1399
+ logger6.warn({ taskId }, "Task not found when fetching artifacts");
1399
1400
  continue;
1400
1401
  }
1401
1402
  const taskArtifacts = await getLedgerArtifacts(dbClient_default)({
@@ -1413,21 +1414,21 @@ var _ArtifactService = class _ArtifactService {
1413
1414
  }
1414
1415
  }
1415
1416
  } catch (error) {
1416
- logger7.error({ error, contextId }, "Error loading context artifacts");
1417
+ logger6.error({ error, contextId }, "Error loading context artifacts");
1417
1418
  }
1418
1419
  return artifacts;
1419
1420
  }
1420
1421
  /**
1421
1422
  * Create artifact from tool result and request data
1422
1423
  */
1423
- async createArtifact(request, agentId) {
1424
+ async createArtifact(request, subAgentId) {
1424
1425
  if (!this.context.sessionId) {
1425
- logger7.warn({ request }, "No session ID available for artifact creation");
1426
+ logger6.warn({ request }, "No session ID available for artifact creation");
1426
1427
  return null;
1427
1428
  }
1428
1429
  const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
1429
1430
  if (!toolResult) {
1430
- logger7.warn(
1431
+ logger6.warn(
1431
1432
  { request, sessionId: this.context.sessionId },
1432
1433
  "Tool result not found for artifact"
1433
1434
  );
@@ -1443,7 +1444,7 @@ var _ArtifactService = class _ArtifactService {
1443
1444
  selectedData = selectedData.length > 0 ? selectedData[0] : {};
1444
1445
  }
1445
1446
  if (!selectedData) {
1446
- logger7.warn(
1447
+ logger6.warn(
1447
1448
  {
1448
1449
  request,
1449
1450
  baseSelector: request.baseSelector
@@ -1488,7 +1489,7 @@ var _ArtifactService = class _ArtifactService {
1488
1489
  type: request.type,
1489
1490
  data: cleanedSummaryData
1490
1491
  };
1491
- await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, agentId);
1492
+ await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
1492
1493
  await this.cacheArtifact(
1493
1494
  request.artifactId,
1494
1495
  request.toolCallId,
@@ -1497,7 +1498,7 @@ var _ArtifactService = class _ArtifactService {
1497
1498
  );
1498
1499
  return artifactData;
1499
1500
  } catch (error) {
1500
- logger7.error({ error, request }, "Failed to create artifact");
1501
+ logger6.error({ error, request }, "Failed to create artifact");
1501
1502
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1502
1503
  throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
1503
1504
  }
@@ -1526,7 +1527,7 @@ var _ArtifactService = class _ArtifactService {
1526
1527
  }
1527
1528
  try {
1528
1529
  if (!this.context.projectId || !this.context.taskId) {
1529
- logger7.warn(
1530
+ logger6.warn(
1530
1531
  { artifactId, toolCallId },
1531
1532
  "No projectId or taskId available for artifact lookup"
1532
1533
  );
@@ -1541,7 +1542,7 @@ var _ArtifactService = class _ArtifactService {
1541
1542
  return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
1542
1543
  }
1543
1544
  } catch (error) {
1544
- logger7.warn(
1545
+ logger6.warn(
1545
1546
  { artifactId, toolCallId, taskId: this.context.taskId, error },
1546
1547
  "Failed to fetch artifact"
1547
1548
  );
@@ -1572,7 +1573,7 @@ var _ArtifactService = class _ArtifactService {
1572
1573
  }
1573
1574
  try {
1574
1575
  if (!this.context.projectId || !this.context.taskId) {
1575
- logger7.warn(
1576
+ logger6.warn(
1576
1577
  { artifactId, toolCallId },
1577
1578
  "No projectId or taskId available for artifact lookup"
1578
1579
  );
@@ -1587,7 +1588,7 @@ var _ArtifactService = class _ArtifactService {
1587
1588
  return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
1588
1589
  }
1589
1590
  } catch (error) {
1590
- logger7.warn(
1591
+ logger6.warn(
1591
1592
  { artifactId, toolCallId, taskId: this.context.taskId, error },
1592
1593
  "Failed to fetch artifact"
1593
1594
  );
@@ -1623,8 +1624,8 @@ var _ArtifactService = class _ArtifactService {
1623
1624
  /**
1624
1625
  * Persist artifact to database via graph session
1625
1626
  */
1626
- async persistArtifact(request, summaryData, fullData, agentId) {
1627
- const effectiveAgentId = agentId || this.context.agentId;
1627
+ async persistArtifact(request, summaryData, fullData, subAgentId) {
1628
+ const effectiveAgentId = subAgentId || this.context.subAgentId;
1628
1629
  if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
1629
1630
  await graphSessionManager.recordEvent(
1630
1631
  this.context.streamRequestId,
@@ -1637,7 +1638,7 @@ var _ArtifactService = class _ArtifactService {
1637
1638
  artifactType: request.type,
1638
1639
  summaryData,
1639
1640
  data: fullData,
1640
- agentId: effectiveAgentId,
1641
+ subAgentId: effectiveAgentId,
1641
1642
  metadata: {
1642
1643
  toolCallId: request.toolCallId,
1643
1644
  baseSelector: request.baseSelector,
@@ -1652,14 +1653,14 @@ var _ArtifactService = class _ArtifactService {
1652
1653
  }
1653
1654
  );
1654
1655
  } else {
1655
- logger7.warn(
1656
+ logger6.warn(
1656
1657
  {
1657
1658
  artifactId: request.artifactId,
1658
1659
  hasStreamRequestId: !!this.context.streamRequestId,
1659
1660
  hasAgentId: !!effectiveAgentId,
1660
1661
  hasTaskId: !!this.context.taskId,
1661
- passedAgentId: agentId,
1662
- contextAgentId: this.context.agentId
1662
+ passedAgentId: subAgentId,
1663
+ contextAgentId: this.context.subAgentId
1663
1664
  },
1664
1665
  "Skipping artifact_saved event - missing required context"
1665
1666
  );
@@ -1727,7 +1728,7 @@ var _ArtifactService = class _ArtifactService {
1727
1728
  summaryData = this.filterBySchema(artifact.data, previewSchema);
1728
1729
  fullData = this.filterBySchema(artifact.data, fullSchema);
1729
1730
  } catch (error) {
1730
- logger7.warn(
1731
+ logger6.warn(
1731
1732
  {
1732
1733
  artifactType: artifact.type,
1733
1734
  error: error instanceof Error ? error.message : "Unknown error"
@@ -1765,7 +1766,7 @@ var _ArtifactService = class _ArtifactService {
1765
1766
  artifact: artifactToSave
1766
1767
  });
1767
1768
  if (!result.created && result.existing) {
1768
- logger7.debug(
1769
+ logger6.debug(
1769
1770
  {
1770
1771
  artifactId: artifact.artifactId,
1771
1772
  taskId: this.context.taskId
@@ -1818,7 +1819,7 @@ var _ArtifactService = class _ArtifactService {
1818
1819
  extracted[propName] = this.cleanEscapedContent(rawValue);
1819
1820
  }
1820
1821
  } catch (error) {
1821
- logger7.warn(
1822
+ logger6.warn(
1822
1823
  { propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
1823
1824
  "Failed to extract property"
1824
1825
  );
@@ -1850,7 +1851,7 @@ var _ArtifactService = class _ArtifactService {
1850
1851
  extracted[fieldName] = this.cleanEscapedContent(rawValue);
1851
1852
  }
1852
1853
  } catch (error) {
1853
- logger7.warn(
1854
+ logger6.warn(
1854
1855
  { fieldName, error: error instanceof Error ? error.message : "Unknown error" },
1855
1856
  "Failed to extract schema field"
1856
1857
  );
@@ -1881,7 +1882,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
1881
1882
  var ArtifactService = _ArtifactService;
1882
1883
 
1883
1884
  // src/services/ArtifactParser.ts
1884
- var logger8 = getLogger("ArtifactParser");
1885
+ var logger7 = getLogger("ArtifactParser");
1885
1886
  var _ArtifactParser = class _ArtifactParser {
1886
1887
  constructor(tenantId, options) {
1887
1888
  __publicField(this, "artifactService");
@@ -1969,7 +1970,7 @@ var _ArtifactParser = class _ArtifactParser {
1969
1970
  attrs[key] = value;
1970
1971
  }
1971
1972
  if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
1972
- logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
1973
+ logger7.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
1973
1974
  return null;
1974
1975
  }
1975
1976
  return {
@@ -2000,7 +2001,7 @@ var _ArtifactParser = class _ArtifactParser {
2000
2001
  /**
2001
2002
  * Extract artifact data from a create annotation - delegates to service
2002
2003
  */
2003
- async extractFromCreateAnnotation(annotation, agentId) {
2004
+ async extractFromCreateAnnotation(annotation, subAgentId) {
2004
2005
  const request = {
2005
2006
  artifactId: annotation.artifactId,
2006
2007
  toolCallId: annotation.toolCallId,
@@ -2008,21 +2009,21 @@ var _ArtifactParser = class _ArtifactParser {
2008
2009
  baseSelector: annotation.baseSelector,
2009
2010
  detailsSelector: annotation.detailsSelector
2010
2011
  };
2011
- return this.artifactService.createArtifact(request, agentId);
2012
+ return this.artifactService.createArtifact(request, subAgentId);
2012
2013
  }
2013
2014
  /**
2014
2015
  * Parse text with artifact markers into parts array
2015
2016
  * Handles both artifact:ref and artifact:create tags
2016
2017
  * Can work with or without pre-fetched artifact map
2017
2018
  */
2018
- async parseText(text, artifactMap, agentId) {
2019
+ async parseText(text, artifactMap, subAgentId) {
2019
2020
  let processedText = text;
2020
2021
  const createAnnotations = this.parseCreateAnnotations(text);
2021
2022
  const createdArtifactData = /* @__PURE__ */ new Map();
2022
2023
  const failedAnnotations = [];
2023
2024
  for (const annotation of createAnnotations) {
2024
2025
  try {
2025
- const artifactData = await this.extractFromCreateAnnotation(annotation, agentId);
2026
+ const artifactData = await this.extractFromCreateAnnotation(annotation, subAgentId);
2026
2027
  if (artifactData && annotation.raw) {
2027
2028
  createdArtifactData.set(annotation.raw, artifactData);
2028
2029
  } else if (annotation.raw) {
@@ -2030,7 +2031,7 @@ var _ArtifactParser = class _ArtifactParser {
2030
2031
  `Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
2031
2032
  );
2032
2033
  processedText = processedText.replace(annotation.raw, "");
2033
- logger8.warn(
2034
+ logger7.warn(
2034
2035
  { annotation, artifactData },
2035
2036
  "Removed failed artifact:create annotation from output"
2036
2037
  );
@@ -2041,11 +2042,11 @@ var _ArtifactParser = class _ArtifactParser {
2041
2042
  if (annotation.raw) {
2042
2043
  processedText = processedText.replace(annotation.raw, "");
2043
2044
  }
2044
- logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
2045
+ logger7.error({ annotation, error }, "Failed to extract artifact from create annotation");
2045
2046
  }
2046
2047
  }
2047
2048
  if (failedAnnotations.length > 0) {
2048
- logger8.warn(
2049
+ logger7.warn(
2049
2050
  {
2050
2051
  failedCount: failedAnnotations.length,
2051
2052
  failures: failedAnnotations
@@ -2109,7 +2110,7 @@ var _ArtifactParser = class _ArtifactParser {
2109
2110
  /**
2110
2111
  * Process object/dataComponents for artifact components
2111
2112
  */
2112
- async parseObject(obj, artifactMap, agentId) {
2113
+ async parseObject(obj, artifactMap, subAgentId) {
2113
2114
  if (obj?.dataComponents && Array.isArray(obj.dataComponents)) {
2114
2115
  const parts = [];
2115
2116
  for (const component of obj.dataComponents) {
@@ -2133,7 +2134,7 @@ var _ArtifactParser = class _ArtifactParser {
2133
2134
  });
2134
2135
  }
2135
2136
  } else if (this.isArtifactCreateComponent(component)) {
2136
- const createData = await this.extractFromArtifactCreateComponent(component, agentId);
2137
+ const createData = await this.extractFromArtifactCreateComponent(component, subAgentId);
2137
2138
  if (createData) {
2138
2139
  parts.push({
2139
2140
  kind: "data",
@@ -2174,7 +2175,7 @@ var _ArtifactParser = class _ArtifactParser {
2174
2175
  ] : [];
2175
2176
  }
2176
2177
  if (this.isArtifactCreateComponent(obj)) {
2177
- const createData = await this.extractFromArtifactCreateComponent(obj, agentId);
2178
+ const createData = await this.extractFromArtifactCreateComponent(obj, subAgentId);
2178
2179
  return createData ? [
2179
2180
  {
2180
2181
  kind: "data",
@@ -2206,7 +2207,7 @@ var _ArtifactParser = class _ArtifactParser {
2206
2207
  /**
2207
2208
  * Extract artifact from ArtifactCreate component
2208
2209
  */
2209
- async extractFromArtifactCreateComponent(component, agentId) {
2210
+ async extractFromArtifactCreateComponent(component, subAgentId) {
2210
2211
  const props = component.props;
2211
2212
  if (!props) {
2212
2213
  return null;
@@ -2218,7 +2219,7 @@ var _ArtifactParser = class _ArtifactParser {
2218
2219
  baseSelector: props.base_selector,
2219
2220
  detailsSelector: props.details_selector || {}
2220
2221
  };
2221
- return await this.extractFromCreateAnnotation(annotation, agentId);
2222
+ return await this.extractFromCreateAnnotation(annotation, subAgentId);
2222
2223
  }
2223
2224
  /**
2224
2225
  * Get artifact data - delegates to service
@@ -2258,7 +2259,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
2258
2259
  var ArtifactParser = _ArtifactParser;
2259
2260
 
2260
2261
  // src/services/GraphSession.ts
2261
- var logger9 = getLogger("GraphSession");
2262
+ var logger8 = getLogger("GraphSession");
2262
2263
  var GraphSession = class {
2263
2264
  // Whether to send data operations
2264
2265
  constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
@@ -2291,7 +2292,7 @@ var GraphSession = class {
2291
2292
  __publicField(this, "artifactParser");
2292
2293
  // Session-scoped ArtifactParser instance
2293
2294
  __publicField(this, "isEmitOperations", false);
2294
- logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
2295
+ logger8.debug({ sessionId, messageId, graphId }, "GraphSession created");
2295
2296
  if (tenantId && projectId) {
2296
2297
  toolSessionManager.createSessionWithId(
2297
2298
  sessionId,
@@ -2305,7 +2306,6 @@ var GraphSession = class {
2305
2306
  tenantId,
2306
2307
  projectId,
2307
2308
  sessionId,
2308
- // Same ID as ToolSession
2309
2309
  contextId,
2310
2310
  taskId: `task_${contextId}-${messageId}`,
2311
2311
  streamRequestId: sessionId
@@ -2326,7 +2326,7 @@ var GraphSession = class {
2326
2326
  */
2327
2327
  enableEmitOperations() {
2328
2328
  this.isEmitOperations = true;
2329
- logger9.info(
2329
+ logger8.info(
2330
2330
  { sessionId: this.sessionId },
2331
2331
  "\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
2332
2332
  );
@@ -2343,14 +2343,14 @@ var GraphSession = class {
2343
2343
  label: this.generateEventLabel(event),
2344
2344
  details: {
2345
2345
  timestamp: event.timestamp,
2346
- agentId: event.agentId,
2346
+ subAgentId: event.subAgentId,
2347
2347
  data: event.data
2348
2348
  }
2349
2349
  };
2350
2350
  await streamHelper.writeOperation(formattedOperation);
2351
2351
  }
2352
2352
  } catch (error) {
2353
- logger9.error(
2353
+ logger8.error(
2354
2354
  {
2355
2355
  sessionId: this.sessionId,
2356
2356
  eventType: event.eventType,
@@ -2366,29 +2366,19 @@ var GraphSession = class {
2366
2366
  generateEventLabel(event) {
2367
2367
  switch (event.eventType) {
2368
2368
  case "agent_generate":
2369
- return `Agent ${event.agentId} generating response`;
2369
+ return `Agent ${event.subAgentId} generating response`;
2370
2370
  case "agent_reasoning":
2371
- return `Agent ${event.agentId} reasoning through request`;
2372
- case "tool_execution": {
2373
- const toolData = event.data;
2374
- return `Tool execution: ${toolData.toolName || "unknown"}`;
2375
- }
2376
- case "transfer": {
2377
- const transferData = event.data;
2378
- return `Agent transfer: ${transferData.fromAgent} \u2192 ${transferData.targetAgent}`;
2379
- }
2380
- case "delegation_sent": {
2381
- const delegationData = event.data;
2382
- return `Task delegated: ${delegationData.fromAgent} \u2192 ${delegationData.targetAgent}`;
2383
- }
2384
- case "delegation_returned": {
2385
- const returnData = event.data;
2386
- return `Task completed: ${returnData.targetAgent} \u2192 ${returnData.fromAgent}`;
2387
- }
2388
- case "artifact_saved": {
2389
- const artifactData = event.data;
2390
- return `Artifact saved: ${artifactData.artifactType || "unknown type"}`;
2391
- }
2371
+ return `Agent ${event.subAgentId} reasoning through request`;
2372
+ case "tool_execution":
2373
+ return `Tool execution: ${event.data.toolName || "unknown"}`;
2374
+ case "transfer":
2375
+ return `Agent transfer: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
2376
+ case "delegation_sent":
2377
+ return `Task delegated: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
2378
+ case "delegation_returned":
2379
+ return `Task completed: ${event.data.targetSubAgent} \u2192 ${event.data.fromSubAgent}`;
2380
+ case "artifact_saved":
2381
+ return `Artifact saved: ${event.data.artifactType || "unknown type"}`;
2392
2382
  default:
2393
2383
  return `${event.eventType} event`;
2394
2384
  }
@@ -2413,7 +2403,7 @@ var GraphSession = class {
2413
2403
  if (this.statusUpdateState.config.timeInSeconds) {
2414
2404
  this.statusUpdateTimer = setInterval(async () => {
2415
2405
  if (!this.statusUpdateState || this.isEnded) {
2416
- logger9.debug(
2406
+ logger8.debug(
2417
2407
  { sessionId: this.sessionId },
2418
2408
  "Timer triggered but session already cleaned up or ended"
2419
2409
  );
@@ -2425,7 +2415,7 @@ var GraphSession = class {
2425
2415
  }
2426
2416
  await this.checkAndSendTimeBasedUpdate();
2427
2417
  }, this.statusUpdateState.config.timeInSeconds * 1e3);
2428
- logger9.info(
2418
+ logger8.info(
2429
2419
  {
2430
2420
  sessionId: this.sessionId,
2431
2421
  intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
@@ -2436,22 +2426,24 @@ var GraphSession = class {
2436
2426
  }
2437
2427
  /**
2438
2428
  * Record an event in the session and trigger status updates if configured
2429
+ * Generic type parameter T ensures eventType and data are correctly paired
2439
2430
  */
2440
- recordEvent(eventType, agentId, data) {
2431
+ recordEvent(eventType, subAgentId, data) {
2441
2432
  if (this.isEmitOperations) {
2442
- this.sendDataOperation({
2433
+ const dataOpEvent = {
2443
2434
  timestamp: Date.now(),
2444
2435
  eventType,
2445
- agentId,
2436
+ subAgentId,
2446
2437
  data
2447
- });
2438
+ };
2439
+ this.sendDataOperation(dataOpEvent);
2448
2440
  }
2449
2441
  if (this.isEnded) {
2450
- logger9.debug(
2442
+ logger8.debug(
2451
2443
  {
2452
2444
  sessionId: this.sessionId,
2453
2445
  eventType,
2454
- agentId
2446
+ subAgentId
2455
2447
  },
2456
2448
  "Event received after session ended - ignoring"
2457
2449
  );
@@ -2460,59 +2452,62 @@ var GraphSession = class {
2460
2452
  const event = {
2461
2453
  timestamp: Date.now(),
2462
2454
  eventType,
2463
- agentId,
2455
+ subAgentId,
2464
2456
  data
2465
2457
  };
2466
2458
  this.events.push(event);
2467
- if (eventType === "artifact_saved" && data.pendingGeneration) {
2468
- const artifactId = data.artifactId;
2469
- if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
2470
- logger9.warn(
2471
- {
2472
- sessionId: this.sessionId,
2473
- artifactId,
2474
- pendingCount: this.pendingArtifacts.size,
2475
- maxAllowed: this.MAX_PENDING_ARTIFACTS
2476
- },
2477
- "Too many pending artifacts, skipping processing"
2478
- );
2479
- return;
2480
- }
2481
- this.pendingArtifacts.add(artifactId);
2482
- setImmediate(() => {
2483
- const artifactDataWithAgent = { ...data, agentId };
2484
- this.processArtifact(artifactDataWithAgent).then(() => {
2485
- this.pendingArtifacts.delete(artifactId);
2486
- this.artifactProcessingErrors.delete(artifactId);
2487
- }).catch((error) => {
2488
- const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
2489
- this.artifactProcessingErrors.set(artifactId, errorCount);
2490
- if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
2459
+ if (eventType === "artifact_saved") {
2460
+ const artifactData = data;
2461
+ if (artifactData.pendingGeneration) {
2462
+ const artifactId = artifactData.artifactId;
2463
+ if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
2464
+ logger8.warn(
2465
+ {
2466
+ sessionId: this.sessionId,
2467
+ artifactId,
2468
+ pendingCount: this.pendingArtifacts.size,
2469
+ maxAllowed: this.MAX_PENDING_ARTIFACTS
2470
+ },
2471
+ "Too many pending artifacts, skipping processing"
2472
+ );
2473
+ return;
2474
+ }
2475
+ this.pendingArtifacts.add(artifactId);
2476
+ setImmediate(() => {
2477
+ const artifactDataWithAgent = { ...artifactData, subAgentId };
2478
+ this.processArtifact(artifactDataWithAgent).then(() => {
2491
2479
  this.pendingArtifacts.delete(artifactId);
2492
- logger9.error(
2493
- {
2494
- sessionId: this.sessionId,
2495
- artifactId,
2496
- errorCount,
2497
- maxRetries: this.MAX_ARTIFACT_RETRIES,
2498
- error: error instanceof Error ? error.message : "Unknown error",
2499
- stack: error instanceof Error ? error.stack : void 0
2500
- },
2501
- "Artifact processing failed after max retries, giving up"
2502
- );
2503
- } else {
2504
- logger9.warn(
2505
- {
2506
- sessionId: this.sessionId,
2507
- artifactId,
2508
- errorCount,
2509
- error: error instanceof Error ? error.message : "Unknown error"
2510
- },
2511
- "Artifact processing failed, may retry"
2512
- );
2513
- }
2480
+ this.artifactProcessingErrors.delete(artifactId);
2481
+ }).catch((error) => {
2482
+ const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
2483
+ this.artifactProcessingErrors.set(artifactId, errorCount);
2484
+ if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
2485
+ this.pendingArtifacts.delete(artifactId);
2486
+ logger8.error(
2487
+ {
2488
+ sessionId: this.sessionId,
2489
+ artifactId,
2490
+ errorCount,
2491
+ maxRetries: this.MAX_ARTIFACT_RETRIES,
2492
+ error: error instanceof Error ? error.message : "Unknown error",
2493
+ stack: error instanceof Error ? error.stack : void 0
2494
+ },
2495
+ "Artifact processing failed after max retries, giving up"
2496
+ );
2497
+ } else {
2498
+ logger8.warn(
2499
+ {
2500
+ sessionId: this.sessionId,
2501
+ artifactId,
2502
+ errorCount,
2503
+ error: error instanceof Error ? error.message : "Unknown error"
2504
+ },
2505
+ "Artifact processing failed, may retry"
2506
+ );
2507
+ }
2508
+ });
2514
2509
  });
2515
- });
2510
+ }
2516
2511
  }
2517
2512
  if (!this.isEnded) {
2518
2513
  this.checkStatusUpdates();
@@ -2523,14 +2518,14 @@ var GraphSession = class {
2523
2518
  */
2524
2519
  checkStatusUpdates() {
2525
2520
  if (this.isEnded) {
2526
- logger9.debug(
2521
+ logger8.debug(
2527
2522
  { sessionId: this.sessionId },
2528
2523
  "Session has ended - skipping status update check"
2529
2524
  );
2530
2525
  return;
2531
2526
  }
2532
2527
  if (!this.statusUpdateState) {
2533
- logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
2528
+ logger8.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
2534
2529
  return;
2535
2530
  }
2536
2531
  const statusUpdateState = this.statusUpdateState;
@@ -2541,11 +2536,11 @@ var GraphSession = class {
2541
2536
  */
2542
2537
  async checkAndSendTimeBasedUpdate() {
2543
2538
  if (this.isEnded) {
2544
- logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
2539
+ logger8.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
2545
2540
  return;
2546
2541
  }
2547
2542
  if (!this.statusUpdateState) {
2548
- logger9.debug(
2543
+ logger8.debug(
2549
2544
  { sessionId: this.sessionId },
2550
2545
  "No status updates configured for time-based check"
2551
2546
  );
@@ -2558,7 +2553,7 @@ var GraphSession = class {
2558
2553
  try {
2559
2554
  await this.generateAndSendUpdate();
2560
2555
  } catch (error) {
2561
- logger9.error(
2556
+ logger8.error(
2562
2557
  {
2563
2558
  sessionId: this.sessionId,
2564
2559
  error: error instanceof Error ? error.message : "Unknown error"
@@ -2582,8 +2577,8 @@ var GraphSession = class {
2582
2577
  /**
2583
2578
  * Get events filtered by agent
2584
2579
  */
2585
- getEventsByAgent(agentId) {
2586
- return this.events.filter((event) => event.agentId === agentId);
2580
+ getEventsByAgent(subAgentId) {
2581
+ return this.events.filter((event) => event.subAgentId === subAgentId);
2587
2582
  }
2588
2583
  /**
2589
2584
  * Get summary of session activity
@@ -2598,7 +2593,7 @@ var GraphSession = class {
2598
2593
  );
2599
2594
  const agentCounts = this.events.reduce(
2600
2595
  (counts, event) => {
2601
- counts[event.agentId] = (counts[event.agentId] || 0) + 1;
2596
+ counts[event.subAgentId] = (counts[event.subAgentId] || 0) + 1;
2602
2597
  return counts;
2603
2598
  },
2604
2599
  {}
@@ -2661,29 +2656,29 @@ var GraphSession = class {
2661
2656
  */
2662
2657
  async generateAndSendUpdate() {
2663
2658
  if (this.isEnded) {
2664
- logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
2659
+ logger8.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
2665
2660
  return;
2666
2661
  }
2667
2662
  if (this.isTextStreaming) {
2668
- logger9.debug(
2663
+ logger8.debug(
2669
2664
  { sessionId: this.sessionId },
2670
2665
  "Text is currently streaming - skipping status update"
2671
2666
  );
2672
2667
  return;
2673
2668
  }
2674
2669
  if (this.isGeneratingUpdate) {
2675
- logger9.debug(
2670
+ logger8.debug(
2676
2671
  { sessionId: this.sessionId },
2677
2672
  "Update already in progress - skipping duplicate generation"
2678
2673
  );
2679
2674
  return;
2680
2675
  }
2681
2676
  if (!this.statusUpdateState) {
2682
- logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
2677
+ logger8.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
2683
2678
  return;
2684
2679
  }
2685
2680
  if (!this.graphId) {
2686
- logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
2681
+ logger8.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
2687
2682
  return;
2688
2683
  }
2689
2684
  const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
@@ -2695,7 +2690,7 @@ var GraphSession = class {
2695
2690
  try {
2696
2691
  const streamHelper = getStreamHelper(this.sessionId);
2697
2692
  if (!streamHelper) {
2698
- logger9.warn(
2693
+ logger8.warn(
2699
2694
  { sessionId: this.sessionId },
2700
2695
  "No stream helper found - cannot send status update"
2701
2696
  );
@@ -2715,7 +2710,7 @@ var GraphSession = class {
2715
2710
  if (result.summaries && result.summaries.length > 0) {
2716
2711
  for (const summary of result.summaries) {
2717
2712
  if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
2718
- logger9.warn(
2713
+ logger8.warn(
2719
2714
  {
2720
2715
  sessionId: this.sessionId,
2721
2716
  summary
@@ -2752,7 +2747,7 @@ var GraphSession = class {
2752
2747
  this.statusUpdateState.lastEventCount = this.events.length;
2753
2748
  }
2754
2749
  } catch (error) {
2755
- logger9.error(
2750
+ logger8.error(
2756
2751
  {
2757
2752
  sessionId: this.sessionId,
2758
2753
  error: error instanceof Error ? error.message : "Unknown error",
@@ -2790,7 +2785,7 @@ var GraphSession = class {
2790
2785
  this.releaseUpdateLock();
2791
2786
  }
2792
2787
  } catch (error) {
2793
- logger9.error(
2788
+ logger8.error(
2794
2789
  {
2795
2790
  sessionId: this.sessionId,
2796
2791
  error: error instanceof Error ? error.message : "Unknown error"
@@ -2868,7 +2863,7 @@ User's Question/Context:
2868
2863
  ${conversationHistory}
2869
2864
  ` : "";
2870
2865
  } catch (error) {
2871
- logger9.warn(
2866
+ logger8.warn(
2872
2867
  { sessionId: this.sessionId, error },
2873
2868
  "Failed to fetch conversation history for structured status update"
2874
2869
  );
@@ -3002,7 +2997,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3002
2997
  return { summaries };
3003
2998
  } catch (error) {
3004
2999
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
3005
- logger9.error({ error }, "Failed to generate structured update, using fallback");
3000
+ logger8.error({ error }, "Failed to generate structured update, using fallback");
3006
3001
  return { summaries: [] };
3007
3002
  } finally {
3008
3003
  span.end();
@@ -3028,7 +3023,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3028
3023
  */
3029
3024
  buildZodSchemaFromJson(jsonSchema) {
3030
3025
  const properties = {};
3031
- properties["label"] = z.string().describe(
3026
+ properties.label = z.string().describe(
3032
3027
  'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
3033
3028
  );
3034
3029
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
@@ -3097,11 +3092,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3097
3092
  for (const event of events) {
3098
3093
  switch (event.eventType) {
3099
3094
  case "tool_execution": {
3100
- const data = event.data;
3101
- const resultStr = JSON.stringify(data.result);
3095
+ const resultStr = JSON.stringify(event.data.result);
3102
3096
  activities.push(
3103
- `\u{1F527} **${data.toolName}** ${data.duration ? `(${data.duration}ms)` : ""}
3104
- \u{1F4E5} Input: ${JSON.stringify(data.args)}
3097
+ `\u{1F527} **${event.data.toolName}** ${event.data.duration ? `(${event.data.duration}ms)` : ""}
3098
+ \u{1F4E5} Input: ${JSON.stringify(event.data.args)}
3105
3099
  \u{1F4E4} Output: ${resultStr}`
3106
3100
  );
3107
3101
  break;
@@ -3113,23 +3107,24 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3113
3107
  case "artifact_saved":
3114
3108
  break;
3115
3109
  case "agent_reasoning": {
3116
- const data = event.data;
3117
3110
  activities.push(
3118
3111
  `\u2699\uFE0F **Analyzing request**
3119
- Details: ${JSON.stringify(data.parts, null, 2)}`
3112
+ Details: ${JSON.stringify(event.data.parts, null, 2)}`
3120
3113
  );
3121
3114
  break;
3122
3115
  }
3123
3116
  case "agent_generate": {
3124
- const data = event.data;
3125
3117
  activities.push(
3126
3118
  `\u2699\uFE0F **Preparing response**
3127
- Details: ${JSON.stringify(data.parts, null, 2)}`
3119
+ Details: ${JSON.stringify(event.data.parts, null, 2)}`
3128
3120
  );
3129
3121
  break;
3130
3122
  }
3131
3123
  default: {
3132
- activities.push(`\u{1F4CB} **${event.eventType}**: ${JSON.stringify(event.data, null, 2)}`);
3124
+ const safeEvent = event;
3125
+ activities.push(
3126
+ `\u{1F4CB} **${safeEvent.eventType}**: ${JSON.stringify(safeEvent.data, null, 2)}`
3127
+ );
3133
3128
  break;
3134
3129
  }
3135
3130
  }
@@ -3147,7 +3142,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3147
3142
  "graph_session.id": this.sessionId,
3148
3143
  "artifact.id": artifactData.artifactId,
3149
3144
  "artifact.type": artifactData.artifactType || "unknown",
3150
- "artifact.agent_id": artifactData.agentId || "unknown",
3145
+ "artifact.agent_id": artifactData.subAgentId || "unknown",
3151
3146
  "artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
3152
3147
  "artifact.data": JSON.stringify(artifactData.data, null, 2),
3153
3148
  "tenant.id": artifactData.tenantId || "unknown",
@@ -3206,34 +3201,34 @@ Make it specific and relevant.`;
3206
3201
  let modelToUse = this.statusUpdateState?.summarizerModel;
3207
3202
  if (!modelToUse?.model?.trim()) {
3208
3203
  if (!this.statusUpdateState?.baseModel?.model?.trim()) {
3209
- if (artifactData.agentId && artifactData.tenantId && artifactData.projectId) {
3204
+ if (artifactData.subAgentId && artifactData.tenantId && artifactData.projectId) {
3210
3205
  try {
3211
- const agentData = await getAgentById(dbClient_default)({
3206
+ const agentData = await getSubAgentById(dbClient_default)({
3212
3207
  scopes: {
3213
3208
  tenantId: artifactData.tenantId,
3214
3209
  projectId: artifactData.projectId,
3215
3210
  graphId: this.graphId || ""
3216
3211
  },
3217
- agentId: artifactData.agentId
3212
+ subAgentId: artifactData.subAgentId
3218
3213
  });
3219
3214
  if (agentData && "models" in agentData && agentData.models?.base?.model) {
3220
3215
  modelToUse = agentData.models.base;
3221
- logger9.info(
3216
+ logger8.info(
3222
3217
  {
3223
3218
  sessionId: this.sessionId,
3224
3219
  artifactId: artifactData.artifactId,
3225
- agentId: artifactData.agentId,
3220
+ subAgentId: artifactData.subAgentId,
3226
3221
  model: modelToUse.model
3227
3222
  },
3228
3223
  "Using agent model configuration for artifact name generation"
3229
3224
  );
3230
3225
  }
3231
3226
  } catch (error) {
3232
- logger9.warn(
3227
+ logger8.warn(
3233
3228
  {
3234
3229
  sessionId: this.sessionId,
3235
3230
  artifactId: artifactData.artifactId,
3236
- agentId: artifactData.agentId,
3231
+ subAgentId: artifactData.subAgentId,
3237
3232
  error: error instanceof Error ? error.message : "Unknown error"
3238
3233
  },
3239
3234
  "Failed to get agent model configuration"
@@ -3241,7 +3236,7 @@ Make it specific and relevant.`;
3241
3236
  }
3242
3237
  }
3243
3238
  if (!modelToUse?.model?.trim()) {
3244
- logger9.warn(
3239
+ logger8.warn(
3245
3240
  {
3246
3241
  sessionId: this.sessionId,
3247
3242
  artifactId: artifactData.artifactId
@@ -3323,7 +3318,7 @@ Make it specific and relevant.`;
3323
3318
  return result2;
3324
3319
  } catch (error) {
3325
3320
  lastError = error instanceof Error ? error : new Error(String(error));
3326
- logger9.warn(
3321
+ logger8.warn(
3327
3322
  {
3328
3323
  sessionId: this.sessionId,
3329
3324
  artifactId: artifactData.artifactId,
@@ -3375,7 +3370,7 @@ Make it specific and relevant.`;
3375
3370
  });
3376
3371
  span.setStatus({ code: SpanStatusCode.OK });
3377
3372
  } catch (saveError) {
3378
- logger9.error(
3373
+ logger8.error(
3379
3374
  {
3380
3375
  sessionId: this.sessionId,
3381
3376
  artifactId: artifactData.artifactId,
@@ -3403,7 +3398,7 @@ Make it specific and relevant.`;
3403
3398
  metadata: artifactData.metadata || {},
3404
3399
  toolCallId: artifactData.toolCallId
3405
3400
  });
3406
- logger9.info(
3401
+ logger8.info(
3407
3402
  {
3408
3403
  sessionId: this.sessionId,
3409
3404
  artifactId: artifactData.artifactId
@@ -3414,7 +3409,7 @@ Make it specific and relevant.`;
3414
3409
  } catch (fallbackError) {
3415
3410
  const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
3416
3411
  if (isDuplicateError) ; else {
3417
- logger9.error(
3412
+ logger8.error(
3418
3413
  {
3419
3414
  sessionId: this.sessionId,
3420
3415
  artifactId: artifactData.artifactId,
@@ -3427,7 +3422,7 @@ Make it specific and relevant.`;
3427
3422
  }
3428
3423
  } catch (error) {
3429
3424
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
3430
- logger9.error(
3425
+ logger8.error(
3431
3426
  {
3432
3427
  sessionId: this.sessionId,
3433
3428
  artifactId: artifactData.artifactId,
@@ -3446,7 +3441,7 @@ Make it specific and relevant.`;
3446
3441
  */
3447
3442
  setArtifactCache(key, artifact) {
3448
3443
  this.artifactCache.set(key, artifact);
3449
- logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
3444
+ logger8.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
3450
3445
  }
3451
3446
  /**
3452
3447
  * Get session-scoped ArtifactService instance
@@ -3465,7 +3460,7 @@ Make it specific and relevant.`;
3465
3460
  */
3466
3461
  getArtifactCache(key) {
3467
3462
  const artifact = this.artifactCache.get(key);
3468
- logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
3463
+ logger8.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
3469
3464
  return artifact || null;
3470
3465
  }
3471
3466
  /**
@@ -3488,7 +3483,7 @@ var GraphSessionManager = class {
3488
3483
  const sessionId = messageId;
3489
3484
  const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
3490
3485
  this.sessions.set(sessionId, session);
3491
- logger9.info(
3486
+ logger8.info(
3492
3487
  { sessionId, messageId, graphId, tenantId, projectId, contextId },
3493
3488
  "GraphSession created"
3494
3489
  );
@@ -3502,7 +3497,7 @@ var GraphSessionManager = class {
3502
3497
  if (session) {
3503
3498
  session.initializeStatusUpdates(config, summarizerModel);
3504
3499
  } else {
3505
- logger9.error(
3500
+ logger8.error(
3506
3501
  {
3507
3502
  sessionId,
3508
3503
  availableSessions: Array.from(this.sessions.keys())
@@ -3519,7 +3514,7 @@ var GraphSessionManager = class {
3519
3514
  if (session) {
3520
3515
  session.enableEmitOperations();
3521
3516
  } else {
3522
- logger9.error(
3517
+ logger8.error(
3523
3518
  {
3524
3519
  sessionId,
3525
3520
  availableSessions: Array.from(this.sessions.keys())
@@ -3536,14 +3531,15 @@ var GraphSessionManager = class {
3536
3531
  }
3537
3532
  /**
3538
3533
  * Record an event in a session
3534
+ * Generic type parameter T ensures eventType and data are correctly paired
3539
3535
  */
3540
- recordEvent(sessionId, eventType, agentId, data) {
3536
+ recordEvent(sessionId, eventType, subAgentId, data) {
3541
3537
  const session = this.sessions.get(sessionId);
3542
3538
  if (!session) {
3543
- logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
3539
+ logger8.warn({ sessionId }, "Attempted to record event in non-existent session");
3544
3540
  return;
3545
3541
  }
3546
- session.recordEvent(eventType, agentId, data);
3542
+ session.recordEvent(eventType, subAgentId, data);
3547
3543
  }
3548
3544
  /**
3549
3545
  * End a session and return the final event data
@@ -3551,12 +3547,12 @@ var GraphSessionManager = class {
3551
3547
  endSession(sessionId) {
3552
3548
  const session = this.sessions.get(sessionId);
3553
3549
  if (!session) {
3554
- logger9.warn({ sessionId }, "Attempted to end non-existent session");
3550
+ logger8.warn({ sessionId }, "Attempted to end non-existent session");
3555
3551
  return [];
3556
3552
  }
3557
3553
  const events = session.getEvents();
3558
3554
  const summary = session.getSummary();
3559
- logger9.info({ sessionId, summary }, "GraphSession ended");
3555
+ logger8.info({ sessionId, summary }, "GraphSession ended");
3560
3556
  session.cleanup();
3561
3557
  this.sessions.delete(sessionId);
3562
3558
  return events;
@@ -3655,7 +3651,7 @@ async function resolveModelConfig(graphId, agent) {
3655
3651
  }
3656
3652
 
3657
3653
  // src/services/IncrementalStreamParser.ts
3658
- var logger10 = getLogger("IncrementalStreamParser");
3654
+ var logger9 = getLogger("IncrementalStreamParser");
3659
3655
  var _IncrementalStreamParser = class _IncrementalStreamParser {
3660
3656
  // Max number of collected parts to prevent unbounded growth
3661
3657
  constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
@@ -3671,10 +3667,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3671
3667
  __publicField(this, "lastStreamedComponents", /* @__PURE__ */ new Map());
3672
3668
  __publicField(this, "componentSnapshots", /* @__PURE__ */ new Map());
3673
3669
  __publicField(this, "artifactMap");
3674
- __publicField(this, "agentId");
3670
+ __publicField(this, "subAgentId");
3671
+ __publicField(this, "allStreamedContent", []);
3675
3672
  this.streamHelper = streamHelper;
3676
3673
  this.contextId = contextId;
3677
- this.agentId = artifactParserOptions?.agentId;
3674
+ this.subAgentId = artifactParserOptions?.subAgentId;
3678
3675
  if (artifactParserOptions?.streamRequestId) {
3679
3676
  const sessionParser = graphSessionManager.getArtifactParser(
3680
3677
  artifactParserOptions.streamRequestId
@@ -3707,7 +3704,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3707
3704
  async initializeArtifactMap() {
3708
3705
  try {
3709
3706
  this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
3710
- logger10.debug(
3707
+ logger9.debug(
3711
3708
  {
3712
3709
  contextId: this.contextId,
3713
3710
  artifactMapSize: this.artifactMap.size
@@ -3715,7 +3712,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3715
3712
  "Initialized artifact map for streaming"
3716
3713
  );
3717
3714
  } catch (error) {
3718
- logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
3715
+ logger9.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
3719
3716
  this.artifactMap = /* @__PURE__ */ new Map();
3720
3717
  }
3721
3718
  }
@@ -3790,10 +3787,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3790
3787
  this.hasStartedRole = true;
3791
3788
  }
3792
3789
  await this.streamHelper.streamText(newText, 50);
3793
- this.collectedParts.push({
3790
+ const textPart = {
3794
3791
  kind: "text",
3795
3792
  text: newText
3796
- });
3793
+ };
3794
+ this.collectedParts.push(textPart);
3795
+ this.allStreamedContent.push(textPart);
3797
3796
  }
3798
3797
  continue;
3799
3798
  }
@@ -3817,7 +3816,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3817
3816
  dataComponents: [component]
3818
3817
  },
3819
3818
  this.artifactMap,
3820
- this.agentId
3819
+ this.subAgentId
3821
3820
  );
3822
3821
  if (!Array.isArray(parts)) {
3823
3822
  console.warn("parseObject returned non-array:", parts);
@@ -3893,7 +3892,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3893
3892
  dataComponents: [component]
3894
3893
  },
3895
3894
  this.artifactMap,
3896
- this.agentId
3895
+ this.subAgentId
3897
3896
  );
3898
3897
  for (const part of parts) {
3899
3898
  await this.streamPart(part);
@@ -3919,10 +3918,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3919
3918
  if (this.pendingTextBuffer) {
3920
3919
  const cleanedText = this.pendingTextBuffer.replace(/<\/?artifact:ref(?:\s[^>]*)?>\/?>/g, "").replace(/<\/?artifact(?:\s[^>]*)?>\/?>/g, "").replace(/<\/artifact:ref>/g, "").replace(/<\/(?:\w+:)?artifact>/g, "");
3921
3920
  if (cleanedText) {
3922
- this.collectedParts.push({
3921
+ const textPart = {
3923
3922
  kind: "text",
3924
3923
  text: cleanedText
3925
- });
3924
+ };
3925
+ this.collectedParts.push(textPart);
3926
+ this.allStreamedContent.push(textPart);
3926
3927
  await this.streamHelper.streamText(cleanedText, 50);
3927
3928
  }
3928
3929
  this.pendingTextBuffer = "";
@@ -3937,6 +3938,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3937
3938
  getCollectedParts() {
3938
3939
  return [...this.collectedParts];
3939
3940
  }
3941
+ /**
3942
+ * Get all streamed content that was actually sent to the user
3943
+ */
3944
+ getAllStreamedContent() {
3945
+ return [...this.allStreamedContent];
3946
+ }
3940
3947
  /**
3941
3948
  * Parse buffer for complete artifacts and text parts (for text streaming)
3942
3949
  */
@@ -3947,7 +3954,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3947
3954
  const safeEnd = this.artifactParser.findSafeTextBoundary(workingBuffer);
3948
3955
  if (safeEnd > 0) {
3949
3956
  const safeText = workingBuffer.slice(0, safeEnd);
3950
- const parts2 = await this.artifactParser.parseText(safeText, this.artifactMap, this.agentId);
3957
+ const parts2 = await this.artifactParser.parseText(
3958
+ safeText,
3959
+ this.artifactMap,
3960
+ this.subAgentId
3961
+ );
3951
3962
  completeParts.push(...parts2);
3952
3963
  return {
3953
3964
  completeParts,
@@ -3962,7 +3973,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3962
3973
  const parts = await this.artifactParser.parseText(
3963
3974
  workingBuffer,
3964
3975
  this.artifactMap,
3965
- this.agentId
3976
+ this.subAgentId
3966
3977
  );
3967
3978
  if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
3968
3979
  const lastPart = parts[parts.length - 1];
@@ -3992,10 +4003,15 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3992
4003
  */
3993
4004
  async streamPart(part) {
3994
4005
  this.collectedParts.push({ ...part });
4006
+ this.allStreamedContent.push({ ...part });
3995
4007
  if (this.collectedParts.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
3996
4008
  const excess = this.collectedParts.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
3997
4009
  this.collectedParts.splice(0, excess);
3998
4010
  }
4011
+ if (this.allStreamedContent.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
4012
+ const excess = this.allStreamedContent.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
4013
+ this.allStreamedContent.splice(0, excess);
4014
+ }
3999
4015
  if (!this.hasStartedRole) {
4000
4016
  await this.streamHelper.writeRole("assistant");
4001
4017
  this.hasStartedRole = true;
@@ -4035,12 +4051,12 @@ __publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", 1e4);
4035
4051
  var IncrementalStreamParser = _IncrementalStreamParser;
4036
4052
 
4037
4053
  // src/services/ResponseFormatter.ts
4038
- var logger11 = getLogger("ResponseFormatter");
4054
+ var logger10 = getLogger("ResponseFormatter");
4039
4055
  var ResponseFormatter = class {
4040
4056
  constructor(tenantId, artifactParserOptions) {
4041
4057
  __publicField(this, "artifactParser");
4042
- __publicField(this, "agentId");
4043
- this.agentId = artifactParserOptions?.agentId;
4058
+ __publicField(this, "subAgentId");
4059
+ this.subAgentId = artifactParserOptions?.subAgentId;
4044
4060
  if (artifactParserOptions?.streamRequestId) {
4045
4061
  const sessionParser = graphSessionManager.getArtifactParser(
4046
4062
  artifactParserOptions.streamRequestId
@@ -4079,7 +4095,7 @@ var ResponseFormatter = class {
4079
4095
  const parts = await this.artifactParser.parseObject(
4080
4096
  responseObject,
4081
4097
  artifactMap,
4082
- this.agentId
4098
+ this.subAgentId
4083
4099
  );
4084
4100
  const uniqueArtifacts = this.countUniqueArtifacts(parts);
4085
4101
  span.setAttributes({
@@ -4094,7 +4110,7 @@ var ResponseFormatter = class {
4094
4110
  return { parts };
4095
4111
  } catch (error) {
4096
4112
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
4097
- logger11.error({ error, responseObject }, "Error formatting object response");
4113
+ logger10.error({ error, responseObject }, "Error formatting object response");
4098
4114
  return {
4099
4115
  parts: [{ kind: "data", data: responseObject }]
4100
4116
  };
@@ -4126,7 +4142,11 @@ var ResponseFormatter = class {
4126
4142
  "response.type": "text",
4127
4143
  "response.availableArtifacts": artifactMap.size
4128
4144
  });
4129
- const parts = await this.artifactParser.parseText(responseText, artifactMap, this.agentId);
4145
+ const parts = await this.artifactParser.parseText(
4146
+ responseText,
4147
+ artifactMap,
4148
+ this.subAgentId
4149
+ );
4130
4150
  if (parts.length === 1 && parts[0].kind === "text") {
4131
4151
  return { text: parts[0].text };
4132
4152
  }
@@ -4146,7 +4166,7 @@ var ResponseFormatter = class {
4146
4166
  return { parts };
4147
4167
  } catch (error) {
4148
4168
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
4149
- logger11.error({ error, responseText }, "Error formatting response");
4169
+ logger10.error({ error, responseText }, "Error formatting response");
4150
4170
  return { text: responseText };
4151
4171
  } finally {
4152
4172
  span.end();
@@ -4200,20 +4220,20 @@ function agentInitializingOp(sessionId, graphId) {
4200
4220
  }
4201
4221
  };
4202
4222
  }
4203
- function completionOp(agentId, iterations) {
4223
+ function completionOp(subAgentId, iterations) {
4204
4224
  return {
4205
4225
  type: "completion",
4206
4226
  details: {
4207
- agent: agentId,
4227
+ agent: subAgentId,
4208
4228
  iteration: iterations
4209
4229
  }
4210
4230
  };
4211
4231
  }
4212
- function errorOp(message, agentId, severity = "error", code) {
4232
+ function errorOp(message, subAgentId, severity = "error", code) {
4213
4233
  return {
4214
4234
  type: "error",
4215
4235
  message,
4216
- agent: agentId,
4236
+ agent: subAgentId,
4217
4237
  severity,
4218
4238
  code,
4219
4239
  timestamp: Date.now()
@@ -4222,10 +4242,10 @@ function errorOp(message, agentId, severity = "error", code) {
4222
4242
  function generateToolId() {
4223
4243
  return `tool_${nanoid(8)}`;
4224
4244
  }
4225
- var logger12 = getLogger("DataComponentSchema");
4245
+ var logger11 = getLogger("DataComponentSchema");
4226
4246
  function jsonSchemaToZod(jsonSchema) {
4227
4247
  if (!jsonSchema || typeof jsonSchema !== "object") {
4228
- logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
4248
+ logger11.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
4229
4249
  return z.string();
4230
4250
  }
4231
4251
  switch (jsonSchema.type) {
@@ -4252,7 +4272,7 @@ function jsonSchemaToZod(jsonSchema) {
4252
4272
  case "null":
4253
4273
  return z.null();
4254
4274
  default:
4255
- logger12.warn(
4275
+ logger11.warn(
4256
4276
  {
4257
4277
  unsupportedType: jsonSchema.type,
4258
4278
  schema: jsonSchema
@@ -4615,7 +4635,7 @@ function parseEmbeddedJson(data) {
4615
4635
  }
4616
4636
 
4617
4637
  // src/a2a/client.ts
4618
- var logger13 = getLogger("a2aClient");
4638
+ var logger12 = getLogger("a2aClient");
4619
4639
  var DEFAULT_BACKOFF = {
4620
4640
  initialInterval: 500,
4621
4641
  maxInterval: 6e4,
@@ -4821,7 +4841,7 @@ var A2AClient = class {
4821
4841
  try {
4822
4842
  const res = await fn();
4823
4843
  if (attempt > 0) {
4824
- logger13.info(
4844
+ logger12.info(
4825
4845
  {
4826
4846
  attempts: attempt + 1,
4827
4847
  elapsedTime: Date.now() - start
@@ -4836,7 +4856,7 @@ var A2AClient = class {
4836
4856
  }
4837
4857
  const elapsed = Date.now() - start;
4838
4858
  if (elapsed > maxElapsedTime) {
4839
- logger13.warn(
4859
+ logger12.warn(
4840
4860
  {
4841
4861
  attempts: attempt + 1,
4842
4862
  elapsedTime: elapsed,
@@ -4857,7 +4877,7 @@ var A2AClient = class {
4857
4877
  retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
4858
4878
  }
4859
4879
  const delayMs = Math.min(retryInterval, maxInterval);
4860
- logger13.info(
4880
+ logger12.info(
4861
4881
  {
4862
4882
  attempt: attempt + 1,
4863
4883
  delayMs,
@@ -4942,7 +4962,7 @@ var A2AClient = class {
4942
4962
  }
4943
4963
  const rpcResponse = await httpResponse.json();
4944
4964
  if (rpcResponse.id !== requestId2) {
4945
- logger13.warn(
4965
+ logger12.warn(
4946
4966
  {
4947
4967
  method,
4948
4968
  expectedId: requestId2,
@@ -5141,7 +5161,7 @@ var A2AClient = class {
5141
5161
  try {
5142
5162
  while (true) {
5143
5163
  const { done, value } = await reader.read();
5144
- logger13.info({ done, value }, "parseA2ASseStream");
5164
+ logger12.info({ done, value }, "parseA2ASseStream");
5145
5165
  if (done) {
5146
5166
  if (eventDataBuffer.trim()) {
5147
5167
  const result = this._processSseEventData(
@@ -5228,7 +5248,7 @@ var A2AClient = class {
5228
5248
  };
5229
5249
 
5230
5250
  // src/agents/relationTools.ts
5231
- var logger14 = getLogger("relationships Tools");
5251
+ var logger13 = getLogger("relationships Tools");
5232
5252
  var generateTransferToolDescription = (config) => {
5233
5253
  return `Hand off the conversation to agent ${config.id}.
5234
5254
 
@@ -5252,7 +5272,7 @@ Delegate a specific task to agent ${config.id} when it seems like the agent can
5252
5272
  var createTransferToAgentTool = ({
5253
5273
  transferConfig,
5254
5274
  callingAgentId,
5255
- agent,
5275
+ subAgent,
5256
5276
  streamRequestId
5257
5277
  }) => {
5258
5278
  return tool({
@@ -5262,11 +5282,11 @@ var createTransferToAgentTool = ({
5262
5282
  const activeSpan = trace.getActiveSpan();
5263
5283
  if (activeSpan) {
5264
5284
  activeSpan.setAttributes({
5265
- "transfer.from_agent_id": callingAgentId,
5266
- "transfer.to_agent_id": transferConfig.id ?? "unknown"
5285
+ [SPAN_KEYS.TRANSFER_FROM_SUB_AGENT_ID]: callingAgentId,
5286
+ [SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
5267
5287
  });
5268
5288
  }
5269
- logger14.info(
5289
+ logger13.info(
5270
5290
  {
5271
5291
  transferTo: transferConfig.id ?? "unknown",
5272
5292
  fromAgent: callingAgentId
@@ -5275,8 +5295,8 @@ var createTransferToAgentTool = ({
5275
5295
  );
5276
5296
  if (streamRequestId) {
5277
5297
  graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
5278
- fromAgent: callingAgentId,
5279
- targetAgent: transferConfig.id ?? "unknown",
5298
+ fromSubAgent: callingAgentId,
5299
+ targetSubAgent: transferConfig.id ?? "unknown",
5280
5300
  reason: `Transfer to ${transferConfig.name || transferConfig.id}`
5281
5301
  });
5282
5302
  }
@@ -5298,7 +5318,7 @@ function createDelegateToAgentTool({
5298
5318
  contextId,
5299
5319
  metadata,
5300
5320
  sessionId,
5301
- agent,
5321
+ subAgent,
5302
5322
  credentialStoreRegistry
5303
5323
  }) {
5304
5324
  return tool({
@@ -5309,9 +5329,9 @@ function createDelegateToAgentTool({
5309
5329
  const activeSpan = trace.getActiveSpan();
5310
5330
  if (activeSpan) {
5311
5331
  activeSpan.setAttributes({
5312
- "delegation.from_agent_id": callingAgentId,
5313
- "delegation.to_agent_id": delegateConfig.config.id ?? "unknown",
5314
- "delegation.id": delegationId
5332
+ [SPAN_KEYS.DELEGATION_FROM_SUB_AGENT_ID]: callingAgentId,
5333
+ [SPAN_KEYS.DELEGATION_TO_SUB_AGENT_ID]: delegateConfig.config.id ?? "unknown",
5334
+ [SPAN_KEYS.DELEGATION_ID]: delegationId
5315
5335
  });
5316
5336
  }
5317
5337
  if (metadata.streamRequestId) {
@@ -5321,8 +5341,8 @@ function createDelegateToAgentTool({
5321
5341
  callingAgentId,
5322
5342
  {
5323
5343
  delegationId,
5324
- fromAgent: callingAgentId,
5325
- targetAgent: delegateConfig.config.id,
5344
+ fromSubAgent: callingAgentId,
5345
+ targetSubAgent: delegateConfig.config.id,
5326
5346
  taskDescription: input.message
5327
5347
  }
5328
5348
  );
@@ -5336,7 +5356,7 @@ function createDelegateToAgentTool({
5336
5356
  projectId,
5337
5357
  graphId
5338
5358
  },
5339
- agentId: delegateConfig.config.id
5359
+ subAgentId: delegateConfig.config.id
5340
5360
  });
5341
5361
  if (externalAgent && (externalAgent.credentialReferenceId || externalAgent.headers) && credentialStoreRegistry) {
5342
5362
  const contextResolver = new ContextResolver(
@@ -5415,7 +5435,7 @@ function createDelegateToAgentTool({
5415
5435
  ...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
5416
5436
  }
5417
5437
  };
5418
- logger14.info({ messageToSend }, "messageToSend");
5438
+ logger13.info({ messageToSend }, "messageToSend");
5419
5439
  await createMessage(dbClient_default)({
5420
5440
  id: nanoid(),
5421
5441
  tenantId,
@@ -5427,7 +5447,7 @@ function createDelegateToAgentTool({
5427
5447
  },
5428
5448
  visibility: isInternal ? "internal" : "external",
5429
5449
  messageType: "a2a-request",
5430
- fromAgentId: callingAgentId,
5450
+ fromSubAgentId: callingAgentId,
5431
5451
  ...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
5432
5452
  });
5433
5453
  const response = await a2aClient.sendMessage({
@@ -5442,8 +5462,8 @@ function createDelegateToAgentTool({
5442
5462
  conversationId: contextId,
5443
5463
  messageType: "a2a-response",
5444
5464
  visibility: isInternal ? "internal" : "external",
5445
- toAgentId: callingAgentId,
5446
- ...isInternal ? { fromAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
5465
+ toSubAgentId: callingAgentId,
5466
+ ...isInternal ? { fromSubAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
5447
5467
  });
5448
5468
  if (sessionId && context?.toolCallId) {
5449
5469
  const toolResult = {
@@ -5462,8 +5482,8 @@ function createDelegateToAgentTool({
5462
5482
  callingAgentId,
5463
5483
  {
5464
5484
  delegationId,
5465
- fromAgent: delegateConfig.config.id,
5466
- targetAgent: callingAgentId,
5485
+ fromSubAgent: delegateConfig.config.id,
5486
+ targetSubAgent: callingAgentId,
5467
5487
  result: response.result
5468
5488
  }
5469
5489
  );
@@ -5477,7 +5497,7 @@ function createDelegateToAgentTool({
5477
5497
  }
5478
5498
 
5479
5499
  // src/agents/SystemPromptBuilder.ts
5480
- var logger15 = getLogger("SystemPromptBuilder");
5500
+ var logger14 = getLogger("SystemPromptBuilder");
5481
5501
  var SystemPromptBuilder = class {
5482
5502
  constructor(version, versionConfig) {
5483
5503
  this.version = version;
@@ -5493,12 +5513,12 @@ var SystemPromptBuilder = class {
5493
5513
  this.templates.set(name, content);
5494
5514
  }
5495
5515
  this.loaded = true;
5496
- logger15.debug(
5516
+ logger14.debug(
5497
5517
  { templateCount: this.templates.size, version: this.version },
5498
5518
  `Loaded ${this.templates.size} templates for version ${this.version}`
5499
5519
  );
5500
5520
  } catch (error) {
5501
- logger15.error({ error }, `Failed to load templates for version ${this.version}`);
5521
+ logger14.error({ error }, `Failed to load templates for version ${this.version}`);
5502
5522
  throw new Error(`Template loading failed: ${error}`);
5503
5523
  }
5504
5524
  }
@@ -6558,7 +6578,7 @@ function hasToolCallWithPrefix(prefix) {
6558
6578
  return false;
6559
6579
  };
6560
6580
  }
6561
- var logger17 = getLogger("Agent");
6581
+ var logger16 = getLogger("Agent");
6562
6582
  var CONSTANTS = {
6563
6583
  MAX_GENERATION_STEPS: 12,
6564
6584
  PHASE_1_TIMEOUT_MS: 27e4,
@@ -6788,7 +6808,7 @@ var Agent = class {
6788
6808
  }
6789
6809
  getRelationTools(runtimeContext, sessionId) {
6790
6810
  const { transferRelations = [], delegateRelations = [] } = this.config;
6791
- const createToolName = (prefix, agentId) => `${prefix}_to_${agentId.toLowerCase().replace(/\s+/g, "_")}`;
6811
+ const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
6792
6812
  return Object.fromEntries([
6793
6813
  ...transferRelations.map((agentConfig) => {
6794
6814
  const toolName = createToolName("transfer", agentConfig.id);
@@ -6799,7 +6819,7 @@ var Agent = class {
6799
6819
  createTransferToAgentTool({
6800
6820
  transferConfig: agentConfig,
6801
6821
  callingAgentId: this.config.id,
6802
- agent: this,
6822
+ subAgent: this,
6803
6823
  streamRequestId: runtimeContext?.metadata?.streamRequestId
6804
6824
  }),
6805
6825
  runtimeContext?.metadata?.streamRequestId,
@@ -6828,7 +6848,7 @@ var Agent = class {
6828
6848
  apiKey: runtimeContext?.metadata?.apiKey
6829
6849
  },
6830
6850
  sessionId,
6831
- agent: this,
6851
+ subAgent: this,
6832
6852
  credentialStoreRegistry: this.credentialStoreRegistry
6833
6853
  }),
6834
6854
  runtimeContext?.metadata?.streamRequestId,
@@ -6862,14 +6882,14 @@ var Agent = class {
6862
6882
  for (const toolSet of tools) {
6863
6883
  for (const [toolName, originalTool] of Object.entries(toolSet)) {
6864
6884
  if (!isValidTool(originalTool)) {
6865
- logger17.error({ toolName }, "Invalid MCP tool structure - missing required properties");
6885
+ logger16.error({ toolName }, "Invalid MCP tool structure - missing required properties");
6866
6886
  continue;
6867
6887
  }
6868
6888
  const sessionWrappedTool = tool({
6869
6889
  description: originalTool.description,
6870
6890
  inputSchema: originalTool.inputSchema,
6871
6891
  execute: async (args, { toolCallId }) => {
6872
- logger17.debug({ toolName, toolCallId }, "MCP Tool Called");
6892
+ logger16.debug({ toolName, toolCallId }, "MCP Tool Called");
6873
6893
  try {
6874
6894
  const rawResult = await originalTool.execute(args, { toolCallId });
6875
6895
  const parsedResult = parseEmbeddedJson(rawResult);
@@ -6883,7 +6903,7 @@ var Agent = class {
6883
6903
  });
6884
6904
  return { result: enhancedResult, toolCallId };
6885
6905
  } catch (error) {
6886
- logger17.error({ toolName, toolCallId, error }, "MCP tool execution failed");
6906
+ logger16.error({ toolName, toolCallId, error }, "MCP tool execution failed");
6887
6907
  throw error;
6888
6908
  }
6889
6909
  }
@@ -6928,7 +6948,7 @@ var Agent = class {
6928
6948
  tenantId: this.config.tenantId,
6929
6949
  projectId: this.config.projectId,
6930
6950
  graphId: this.config.graphId,
6931
- agentId: this.config.id
6951
+ subAgentId: this.config.id
6932
6952
  }
6933
6953
  });
6934
6954
  const agentToolRelationHeaders = toolsForAgent.data.find((t) => t.toolId === tool3.id)?.headers || void 0;
@@ -6984,7 +7004,7 @@ var Agent = class {
6984
7004
  headers: agentToolRelationHeaders
6985
7005
  };
6986
7006
  }
6987
- logger17.info(
7007
+ logger16.info(
6988
7008
  {
6989
7009
  toolName: tool3.name,
6990
7010
  credentialReferenceId,
@@ -7009,10 +7029,10 @@ var Agent = class {
7009
7029
  this.mcpClientCache.set(cacheKey, client);
7010
7030
  } catch (error) {
7011
7031
  this.mcpConnectionLocks.delete(cacheKey);
7012
- logger17.error(
7032
+ logger16.error(
7013
7033
  {
7014
7034
  toolName: tool3.name,
7015
- agentId: this.config.id,
7035
+ subAgentId: this.config.id,
7016
7036
  cacheKey,
7017
7037
  error: error instanceof Error ? error.message : String(error)
7018
7038
  },
@@ -7022,6 +7042,45 @@ var Agent = class {
7022
7042
  }
7023
7043
  }
7024
7044
  const tools = await client.tools();
7045
+ if (!tools || Object.keys(tools).length === 0) {
7046
+ const streamRequestId = this.getStreamRequestId();
7047
+ if (streamRequestId) {
7048
+ tracer.startActiveSpan(
7049
+ "ai.toolCall",
7050
+ {
7051
+ attributes: {
7052
+ "ai.toolCall.name": tool3.name,
7053
+ "ai.toolCall.args": JSON.stringify({ operation: "mcp_tool_discovery" }),
7054
+ "ai.toolCall.result": JSON.stringify({
7055
+ status: "no_tools_available",
7056
+ message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
7057
+ serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown",
7058
+ originalToolName: tool3.name
7059
+ }),
7060
+ "ai.toolType": "mcp",
7061
+ "ai.agentName": this.config.name || "unknown",
7062
+ "conversation.id": this.conversationId || "unknown",
7063
+ "graph.id": this.config.graphId || "unknown",
7064
+ "tenant.id": this.config.tenantId || "unknown",
7065
+ "project.id": this.config.projectId || "unknown"
7066
+ }
7067
+ },
7068
+ (span) => {
7069
+ setSpanWithError(span, new Error(`0 effective tools available for ${tool3.name}`));
7070
+ graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7071
+ toolName: tool3.name,
7072
+ args: { operation: "mcp_tool_discovery" },
7073
+ result: {
7074
+ status: "no_tools_available",
7075
+ message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
7076
+ serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown"
7077
+ }
7078
+ });
7079
+ span.end();
7080
+ }
7081
+ );
7082
+ }
7083
+ }
7025
7084
  return tools;
7026
7085
  }
7027
7086
  async createMcpConnection(tool3, serverConfig) {
@@ -7033,99 +7092,110 @@ var Agent = class {
7033
7092
  await client.connect();
7034
7093
  return client;
7035
7094
  } catch (error) {
7036
- logger17.error(
7095
+ logger16.error(
7037
7096
  {
7038
7097
  toolName: tool3.name,
7039
- agentId: this.config.id,
7098
+ subAgentId: this.config.id,
7040
7099
  error: error instanceof Error ? error.message : String(error)
7041
7100
  },
7042
7101
  "Agent failed to connect to MCP server"
7043
7102
  );
7103
+ if (error instanceof Error) {
7104
+ if (error?.cause && JSON.stringify(error.cause).includes("ECONNREFUSED")) {
7105
+ const errorMessage = "Connection refused. Please check if the MCP server is running.";
7106
+ throw new Error(errorMessage);
7107
+ } else if (error.message.includes("404")) {
7108
+ const errorMessage = "Error accessing endpoint (HTTP 404)";
7109
+ throw new Error(errorMessage);
7110
+ } else {
7111
+ throw new Error(`MCP server connection failed: ${error.message}`);
7112
+ }
7113
+ }
7044
7114
  throw error;
7045
7115
  }
7046
7116
  }
7047
7117
  async getFunctionTools(sessionId, streamRequestId) {
7048
7118
  const functionTools = {};
7049
7119
  try {
7050
- const toolsForAgent = await getToolsForAgent(dbClient_default)({
7120
+ const functionToolsForAgent = await getFunctionToolsForSubAgent(dbClient_default)({
7051
7121
  scopes: {
7052
- tenantId: this.config.tenantId || "default",
7053
- projectId: this.config.projectId || "default",
7054
- graphId: this.config.graphId,
7055
- agentId: this.config.id
7056
- }
7122
+ tenantId: this.config.tenantId,
7123
+ projectId: this.config.projectId,
7124
+ graphId: this.config.graphId
7125
+ },
7126
+ subAgentId: this.config.id
7057
7127
  });
7058
- const toolsData = toolsForAgent.data || [];
7059
- const functionToolDefs = toolsData.filter((tool3) => tool3.tool.config.type === "function");
7060
- if (functionToolDefs.length === 0) {
7128
+ const functionToolsData = functionToolsForAgent.data || [];
7129
+ if (functionToolsData.length === 0) {
7061
7130
  return functionTools;
7062
7131
  }
7063
- const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-JI4X2Z3N.js');
7132
+ const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-PQIRECLQ.js');
7064
7133
  const sandboxExecutor = LocalSandboxExecutor.getInstance();
7065
- for (const toolDef of functionToolDefs) {
7066
- if (toolDef.tool.config?.type === "function") {
7067
- const functionId = toolDef.tool.functionId;
7068
- if (!functionId) {
7069
- logger17.warn({ toolId: toolDef.tool.id }, "Function tool missing functionId reference");
7070
- continue;
7134
+ for (const functionToolDef of functionToolsData) {
7135
+ const functionId = functionToolDef.functionId;
7136
+ if (!functionId) {
7137
+ logger16.warn(
7138
+ { functionToolId: functionToolDef.id },
7139
+ "Function tool missing functionId reference"
7140
+ );
7141
+ continue;
7142
+ }
7143
+ const functionData = await getFunction(dbClient_default)({
7144
+ functionId,
7145
+ scopes: {
7146
+ tenantId: this.config.tenantId || "default",
7147
+ projectId: this.config.projectId || "default"
7071
7148
  }
7072
- const functionData = await getFunction(dbClient_default)({
7073
- functionId,
7074
- scopes: {
7075
- tenantId: this.config.tenantId || "default",
7076
- projectId: this.config.projectId || "default"
7077
- }
7078
- });
7079
- if (!functionData) {
7080
- logger17.warn(
7081
- { functionId, toolId: toolDef.tool.id },
7082
- "Function not found in functions table"
7149
+ });
7150
+ if (!functionData) {
7151
+ logger16.warn(
7152
+ { functionId, functionToolId: functionToolDef.id },
7153
+ "Function not found in functions table"
7154
+ );
7155
+ continue;
7156
+ }
7157
+ const zodSchema = jsonSchemaToZod(functionData.inputSchema);
7158
+ const aiTool = tool({
7159
+ description: functionToolDef.description || functionToolDef.name,
7160
+ inputSchema: zodSchema,
7161
+ execute: async (args, { toolCallId }) => {
7162
+ logger16.debug(
7163
+ { toolName: functionToolDef.name, toolCallId, args },
7164
+ "Function Tool Called"
7083
7165
  );
7084
- continue;
7085
- }
7086
- const zodSchema = jsonSchemaToZod(functionData.inputSchema);
7087
- const aiTool = tool({
7088
- description: toolDef.tool.description || toolDef.tool.name,
7089
- inputSchema: zodSchema,
7090
- execute: async (args, { toolCallId }) => {
7091
- logger17.debug(
7092
- { toolName: toolDef.tool.name, toolCallId, args },
7093
- "Function Tool Called"
7166
+ try {
7167
+ const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
7168
+ description: functionToolDef.description || functionToolDef.name,
7169
+ inputSchema: functionData.inputSchema || {},
7170
+ executeCode: functionData.executeCode,
7171
+ dependencies: functionData.dependencies || {}
7172
+ });
7173
+ toolSessionManager.recordToolResult(sessionId || "", {
7174
+ toolCallId,
7175
+ toolName: functionToolDef.name,
7176
+ args,
7177
+ result,
7178
+ timestamp: Date.now()
7179
+ });
7180
+ return { result, toolCallId };
7181
+ } catch (error) {
7182
+ logger16.error(
7183
+ { toolName: functionToolDef.name, toolCallId, error },
7184
+ "Function tool execution failed"
7094
7185
  );
7095
- try {
7096
- const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
7097
- description: toolDef.tool.description || toolDef.tool.name,
7098
- inputSchema: functionData.inputSchema || {},
7099
- executeCode: functionData.executeCode,
7100
- dependencies: functionData.dependencies || {}
7101
- });
7102
- toolSessionManager.recordToolResult(sessionId || "", {
7103
- toolCallId,
7104
- toolName: toolDef.tool.name,
7105
- args,
7106
- result,
7107
- timestamp: Date.now()
7108
- });
7109
- return { result, toolCallId };
7110
- } catch (error) {
7111
- logger17.error(
7112
- { toolName: toolDef.tool.name, toolCallId, error },
7113
- "Function tool execution failed"
7114
- );
7115
- throw error;
7116
- }
7186
+ throw error;
7117
7187
  }
7118
- });
7119
- functionTools[toolDef.tool.name] = this.wrapToolWithStreaming(
7120
- toolDef.tool.name,
7121
- aiTool,
7122
- streamRequestId || "",
7123
- "tool"
7124
- );
7125
- }
7188
+ }
7189
+ });
7190
+ functionTools[functionToolDef.name] = this.wrapToolWithStreaming(
7191
+ functionToolDef.name,
7192
+ aiTool,
7193
+ streamRequestId || "",
7194
+ "tool"
7195
+ );
7126
7196
  }
7127
7197
  } catch (error) {
7128
- logger17.error({ error }, "Failed to load function tools from database");
7198
+ logger16.error({ error }, "Failed to load function tools from database");
7129
7199
  }
7130
7200
  return functionTools;
7131
7201
  }
@@ -7135,7 +7205,7 @@ var Agent = class {
7135
7205
  async getResolvedContext(conversationId, headers) {
7136
7206
  try {
7137
7207
  if (!this.config.contextConfigId) {
7138
- logger17.debug({ graphId: this.config.graphId }, "No context config found for graph");
7208
+ logger16.debug({ graphId: this.config.graphId }, "No context config found for graph");
7139
7209
  return null;
7140
7210
  }
7141
7211
  const contextConfig = await getContextConfigById(dbClient_default)({
@@ -7147,7 +7217,7 @@ var Agent = class {
7147
7217
  id: this.config.contextConfigId
7148
7218
  });
7149
7219
  if (!contextConfig) {
7150
- logger17.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
7220
+ logger16.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
7151
7221
  return null;
7152
7222
  }
7153
7223
  if (!this.contextResolver) {
@@ -7164,7 +7234,7 @@ var Agent = class {
7164
7234
  $now: (/* @__PURE__ */ new Date()).toISOString(),
7165
7235
  $env: process.env
7166
7236
  };
7167
- logger17.debug(
7237
+ logger16.debug(
7168
7238
  {
7169
7239
  conversationId,
7170
7240
  contextConfigId: contextConfig.id,
@@ -7178,7 +7248,7 @@ var Agent = class {
7178
7248
  );
7179
7249
  return contextWithBuiltins;
7180
7250
  } catch (error) {
7181
- logger17.error(
7251
+ logger16.error(
7182
7252
  {
7183
7253
  conversationId,
7184
7254
  error: error instanceof Error ? error.message : "Unknown error"
@@ -7202,7 +7272,7 @@ var Agent = class {
7202
7272
  });
7203
7273
  return graphDefinition?.graphPrompt || void 0;
7204
7274
  } catch (error) {
7205
- logger17.warn(
7275
+ logger16.warn(
7206
7276
  {
7207
7277
  graphId: this.config.graphId,
7208
7278
  error: error instanceof Error ? error.message : "Unknown error"
@@ -7227,11 +7297,11 @@ var Agent = class {
7227
7297
  if (!graphDefinition) {
7228
7298
  return false;
7229
7299
  }
7230
- return Object.values(graphDefinition.agents).some(
7231
- (agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
7300
+ return Object.values(graphDefinition.subAgents).some(
7301
+ (subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
7232
7302
  );
7233
7303
  } catch (error) {
7234
- logger17.warn(
7304
+ logger16.warn(
7235
7305
  {
7236
7306
  graphId: this.config.graphId,
7237
7307
  tenantId: this.config.tenantId,
@@ -7260,7 +7330,7 @@ var Agent = class {
7260
7330
  preserveUnresolved: false
7261
7331
  });
7262
7332
  } catch (error) {
7263
- logger17.error(
7333
+ logger16.error(
7264
7334
  {
7265
7335
  conversationId,
7266
7336
  error: error instanceof Error ? error.message : "Unknown error"
@@ -7307,7 +7377,7 @@ var Agent = class {
7307
7377
  preserveUnresolved: false
7308
7378
  });
7309
7379
  } catch (error) {
7310
- logger17.error(
7380
+ logger16.error(
7311
7381
  {
7312
7382
  conversationId,
7313
7383
  error: error instanceof Error ? error.message : "Unknown error"
@@ -7322,7 +7392,7 @@ var Agent = class {
7322
7392
  const functionTools = await this.getFunctionTools(streamRequestId || "");
7323
7393
  const relationTools = this.getRelationTools(runtimeContext);
7324
7394
  const allTools = { ...mcpTools, ...functionTools, ...relationTools };
7325
- logger17.info(
7395
+ logger16.info(
7326
7396
  {
7327
7397
  mcpTools: Object.keys(mcpTools),
7328
7398
  functionTools: Object.keys(functionTools),
@@ -7343,7 +7413,7 @@ var Agent = class {
7343
7413
  inputSchema: tool3.inputSchema || tool3.parameters || {},
7344
7414
  usageGuidelines: name.startsWith("transfer_to_") || name.startsWith("delegate_to_") ? `Use this tool to ${name.startsWith("transfer_to_") ? "transfer" : "delegate"} to another agent when appropriate.` : "Use this tool when appropriate for the task at hand."
7345
7415
  }));
7346
- const { getConversationScopedArtifacts } = await import('./conversations-6HJ4FX5F.js');
7416
+ const { getConversationScopedArtifacts } = await import('./conversations-JSORLLWS.js');
7347
7417
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
7348
7418
  const referenceArtifacts = await getConversationScopedArtifacts({
7349
7419
  tenantId: this.config.tenantId,
@@ -7361,7 +7431,7 @@ var Agent = class {
7361
7431
  preserveUnresolved: false
7362
7432
  });
7363
7433
  } catch (error) {
7364
- logger17.error(
7434
+ logger16.error(
7365
7435
  {
7366
7436
  conversationId,
7367
7437
  error: error instanceof Error ? error.message : "Unknown error"
@@ -7394,7 +7464,7 @@ var Agent = class {
7394
7464
  toolCallId: z.string().describe("The tool call ID associated with this artifact.")
7395
7465
  }),
7396
7466
  execute: async ({ artifactId, toolCallId }) => {
7397
- logger17.info({ artifactId, toolCallId }, "get_artifact_full executed");
7467
+ logger16.info({ artifactId, toolCallId }, "get_artifact_full executed");
7398
7468
  const streamRequestId = this.getStreamRequestId();
7399
7469
  const artifactService = graphSessionManager.getArtifactService(streamRequestId);
7400
7470
  if (!artifactService) {
@@ -7428,7 +7498,7 @@ var Agent = class {
7428
7498
  });
7429
7499
  }
7430
7500
  // Provide a default tool set that is always available to the agent.
7431
- async getDefaultTools(_sessionId, streamRequestId) {
7501
+ async getDefaultTools(streamRequestId) {
7432
7502
  const defaultTools = {};
7433
7503
  if (await this.graphHasArtifactComponents()) {
7434
7504
  defaultTools.get_reference_artifact = this.getArtifactTools();
@@ -7654,7 +7724,7 @@ var Agent = class {
7654
7724
  };
7655
7725
  return enhanced;
7656
7726
  } catch (error) {
7657
- logger17.warn({ error }, "Failed to enhance tool result with structure hints");
7727
+ logger16.warn({ error }, "Failed to enhance tool result with structure hints");
7658
7728
  return result;
7659
7729
  }
7660
7730
  }
@@ -7669,7 +7739,7 @@ var Agent = class {
7669
7739
  }
7670
7740
  });
7671
7741
  } catch (error) {
7672
- logger17.error(
7742
+ logger16.error(
7673
7743
  { error, graphId: this.config.graphId },
7674
7744
  "Failed to check graph artifact components"
7675
7745
  );
@@ -7714,7 +7784,7 @@ var Agent = class {
7714
7784
  // Thinking prompt without data components
7715
7785
  this.getFunctionTools(sessionId, streamRequestId),
7716
7786
  Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
7717
- this.getDefaultTools(sessionId, streamRequestId)
7787
+ this.getDefaultTools(streamRequestId)
7718
7788
  ]);
7719
7789
  childSpan.setStatus({ code: SpanStatusCode.OK });
7720
7790
  return result;
@@ -7754,7 +7824,7 @@ var Agent = class {
7754
7824
  currentMessage: userMessage,
7755
7825
  options: historyConfig,
7756
7826
  filters: {
7757
- agentId: this.config.id,
7827
+ subAgentId: this.config.id,
7758
7828
  taskId
7759
7829
  }
7760
7830
  });
@@ -7770,7 +7840,7 @@ var Agent = class {
7770
7840
  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;
7771
7841
  const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
7772
7842
  if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
7773
- logger17.warn(
7843
+ logger16.warn(
7774
7844
  {
7775
7845
  requestedTimeout: modelSettings.maxDuration * 1e3,
7776
7846
  appliedTimeout: timeoutMs,
@@ -7812,7 +7882,7 @@ var Agent = class {
7812
7882
  }
7813
7883
  );
7814
7884
  } catch (error) {
7815
- logger17.debug({ error }, "Failed to track agent reasoning");
7885
+ logger16.debug({ error }, "Failed to track agent reasoning");
7816
7886
  }
7817
7887
  }
7818
7888
  if (last && "toolCalls" in last && last.toolCalls) {
@@ -7839,7 +7909,7 @@ var Agent = class {
7839
7909
  projectId: session?.projectId,
7840
7910
  artifactComponents: this.artifactComponents,
7841
7911
  streamRequestId: this.getStreamRequestId(),
7842
- agentId: this.config.id
7912
+ subAgentId: this.config.id
7843
7913
  };
7844
7914
  const parser = new IncrementalStreamParser(
7845
7915
  streamHelper,
@@ -7884,6 +7954,16 @@ var Agent = class {
7884
7954
  }))
7885
7955
  };
7886
7956
  }
7957
+ const streamedContent = parser.getAllStreamedContent();
7958
+ if (streamedContent.length > 0) {
7959
+ response.streamedContent = {
7960
+ parts: streamedContent.map((part) => ({
7961
+ kind: part.kind,
7962
+ ...part.kind === "text" && { text: part.text },
7963
+ ...part.kind === "data" && { data: part.data }
7964
+ }))
7965
+ };
7966
+ }
7887
7967
  } else {
7888
7968
  let genConfig;
7889
7969
  if (hasStructuredOutput) {
@@ -7916,7 +7996,7 @@ var Agent = class {
7916
7996
  }
7917
7997
  );
7918
7998
  } catch (error) {
7919
- logger17.debug({ error }, "Failed to track agent reasoning");
7999
+ logger16.debug({ error }, "Failed to track agent reasoning");
7920
8000
  }
7921
8001
  }
7922
8002
  if (last && "toolCalls" in last && last.toolCalls) {
@@ -8088,7 +8168,7 @@ ${output}${structureHintsFormatted}`;
8088
8168
  projectId: session?.projectId,
8089
8169
  artifactComponents: this.artifactComponents,
8090
8170
  streamRequestId: this.getStreamRequestId(),
8091
- agentId: this.config.id
8171
+ subAgentId: this.config.id
8092
8172
  };
8093
8173
  const parser = new IncrementalStreamParser(
8094
8174
  streamHelper,
@@ -8171,7 +8251,7 @@ ${output}${structureHintsFormatted}`;
8171
8251
  contextId,
8172
8252
  artifactComponents: this.artifactComponents,
8173
8253
  streamRequestId: this.getStreamRequestId(),
8174
- agentId: this.config.id
8254
+ subAgentId: this.config.id
8175
8255
  });
8176
8256
  if (response.object) {
8177
8257
  formattedContent = await responseFormatter.formatObjectResponse(
@@ -8208,7 +8288,7 @@ ${output}${structureHintsFormatted}`;
8208
8288
  };
8209
8289
 
8210
8290
  // src/agents/generateTaskHandler.ts
8211
- var logger18 = getLogger("generateTaskHandler");
8291
+ var logger17 = getLogger("generateTaskHandler");
8212
8292
  var createTaskHandler = (config, credentialStoreRegistry) => {
8213
8293
  return async (task) => {
8214
8294
  try {
@@ -8234,14 +8314,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8234
8314
  projectId: config.projectId,
8235
8315
  graphId: config.graphId
8236
8316
  },
8237
- agentId: config.agentId
8317
+ subAgentId: config.subAgentId
8238
8318
  }),
8239
8319
  getToolsForAgent(dbClient_default)({
8240
8320
  scopes: {
8241
8321
  tenantId: config.tenantId,
8242
8322
  projectId: config.projectId,
8243
8323
  graphId: config.graphId,
8244
- agentId: config.agentId
8324
+ subAgentId: config.subAgentId
8245
8325
  }
8246
8326
  }),
8247
8327
  getDataComponentsForAgent(dbClient_default)({
@@ -8249,7 +8329,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8249
8329
  tenantId: config.tenantId,
8250
8330
  projectId: config.projectId,
8251
8331
  graphId: config.graphId,
8252
- agentId: config.agentId
8332
+ subAgentId: config.subAgentId
8253
8333
  }
8254
8334
  }),
8255
8335
  getArtifactComponentsForAgent(dbClient_default)({
@@ -8257,21 +8337,21 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8257
8337
  tenantId: config.tenantId,
8258
8338
  projectId: config.projectId,
8259
8339
  graphId: config.graphId,
8260
- agentId: config.agentId
8340
+ subAgentId: config.subAgentId
8261
8341
  }
8262
8342
  })
8263
8343
  ]);
8264
- logger18.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
8344
+ logger17.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
8265
8345
  const enhancedInternalRelations = await Promise.all(
8266
8346
  internalRelations.map(async (relation) => {
8267
8347
  try {
8268
- const relatedAgent = await getAgentById(dbClient_default)({
8348
+ const relatedAgent = await getSubAgentById(dbClient_default)({
8269
8349
  scopes: {
8270
8350
  tenantId: config.tenantId,
8271
8351
  projectId: config.projectId,
8272
8352
  graphId: config.graphId
8273
8353
  },
8274
- agentId: relation.id
8354
+ subAgentId: relation.id
8275
8355
  });
8276
8356
  if (relatedAgent) {
8277
8357
  const relatedAgentRelations = await getRelatedAgentsForGraph(dbClient_default)({
@@ -8280,7 +8360,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8280
8360
  projectId: config.projectId,
8281
8361
  graphId: config.graphId
8282
8362
  },
8283
- agentId: relation.id
8363
+ subAgentId: relation.id
8284
8364
  });
8285
8365
  const enhancedDescription = generateDescriptionWithTransfers(
8286
8366
  relation.description || "",
@@ -8290,7 +8370,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8290
8370
  return { ...relation, description: enhancedDescription };
8291
8371
  }
8292
8372
  } catch (error) {
8293
- logger18.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
8373
+ logger17.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
8294
8374
  }
8295
8375
  return relation;
8296
8376
  })
@@ -8305,7 +8385,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8305
8385
  ) ?? [];
8306
8386
  const agent = new Agent(
8307
8387
  {
8308
- id: config.agentId,
8388
+ id: config.subAgentId,
8309
8389
  tenantId: config.tenantId,
8310
8390
  projectId: config.projectId,
8311
8391
  graphId: config.graphId,
@@ -8316,7 +8396,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8316
8396
  agentPrompt,
8317
8397
  models: models || void 0,
8318
8398
  stopWhen: stopWhen || void 0,
8319
- agentRelations: enhancedInternalRelations.map((relation) => ({
8399
+ subAgentRelations: enhancedInternalRelations.map((relation) => ({
8320
8400
  id: relation.id,
8321
8401
  tenantId: config.tenantId,
8322
8402
  projectId: config.projectId,
@@ -8327,7 +8407,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8327
8407
  description: relation.description,
8328
8408
  agentPrompt: "",
8329
8409
  delegateRelations: [],
8330
- agentRelations: [],
8410
+ subAgentRelations: [],
8331
8411
  transferRelations: []
8332
8412
  })),
8333
8413
  transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
@@ -8341,7 +8421,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8341
8421
  description: relation.description,
8342
8422
  agentPrompt: "",
8343
8423
  delegateRelations: [],
8344
- agentRelations: [],
8424
+ subAgentRelations: [],
8345
8425
  transferRelations: []
8346
8426
  })),
8347
8427
  delegateRelations: [
@@ -8359,7 +8439,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8359
8439
  description: relation.description,
8360
8440
  agentPrompt: "",
8361
8441
  delegateRelations: [],
8362
- agentRelations: [],
8442
+ subAgentRelations: [],
8363
8443
  transferRelations: []
8364
8444
  }
8365
8445
  })),
@@ -8394,11 +8474,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8394
8474
  const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
8395
8475
  if (taskIdMatch) {
8396
8476
  contextId = taskIdMatch[1];
8397
- logger18.info(
8477
+ logger17.info(
8398
8478
  {
8399
8479
  taskId: task.id,
8400
8480
  extractedContextId: contextId,
8401
- agentId: config.agentId
8481
+ subAgentId: config.subAgentId
8402
8482
  },
8403
8483
  "Extracted contextId from task ID for delegation"
8404
8484
  );
@@ -8410,8 +8490,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8410
8490
  const isDelegation = task.context?.metadata?.isDelegation === true;
8411
8491
  agent.setDelegationStatus(isDelegation);
8412
8492
  if (isDelegation) {
8413
- logger18.info(
8414
- { agentId: config.agentId, taskId: task.id },
8493
+ logger17.info(
8494
+ { subAgentId: config.subAgentId, taskId: task.id },
8415
8495
  "Delegated agent - streaming disabled"
8416
8496
  );
8417
8497
  if (streamRequestId && config.tenantId && config.projectId) {
@@ -8508,13 +8588,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8508
8588
  };
8509
8589
  };
8510
8590
  var createTaskHandlerConfig = async (params) => {
8511
- const agent = await getAgentById(dbClient_default)({
8591
+ const agent = await getSubAgentById(dbClient_default)({
8512
8592
  scopes: {
8513
8593
  tenantId: params.tenantId,
8514
8594
  projectId: params.projectId,
8515
8595
  graphId: params.graphId
8516
8596
  },
8517
- agentId: params.agentId
8597
+ subAgentId: params.subAgentId
8518
8598
  });
8519
8599
  const agentGraph = await getAgentGraphById(dbClient_default)({
8520
8600
  scopes: {
@@ -8524,7 +8604,7 @@ var createTaskHandlerConfig = async (params) => {
8524
8604
  }
8525
8605
  });
8526
8606
  if (!agent) {
8527
- throw new Error(`Agent not found: ${params.agentId}`);
8607
+ throw new Error(`Agent not found: ${params.subAgentId}`);
8528
8608
  }
8529
8609
  const effectiveModels = await resolveModelConfig(params.graphId, agent);
8530
8610
  const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
@@ -8532,7 +8612,7 @@ var createTaskHandlerConfig = async (params) => {
8532
8612
  tenantId: params.tenantId,
8533
8613
  projectId: params.projectId,
8534
8614
  graphId: params.graphId,
8535
- agentId: params.agentId,
8615
+ subAgentId: params.subAgentId,
8536
8616
  agentSchema: {
8537
8617
  id: agent.id,
8538
8618
  name: agent.name,
@@ -8560,25 +8640,27 @@ async function hydrateGraph({
8560
8640
  apiKey
8561
8641
  }) {
8562
8642
  try {
8563
- if (!dbGraph.defaultAgentId) {
8643
+ if (!dbGraph.defaultSubAgentId) {
8564
8644
  throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
8565
8645
  }
8566
- const defaultAgent = await getAgentById(dbClient_default)({
8646
+ const defaultSubAgent = await getSubAgentById(dbClient_default)({
8567
8647
  scopes: {
8568
8648
  tenantId: dbGraph.tenantId,
8569
8649
  projectId: dbGraph.projectId,
8570
8650
  graphId: dbGraph.id
8571
8651
  },
8572
- agentId: dbGraph.defaultAgentId
8652
+ subAgentId: dbGraph.defaultSubAgentId
8573
8653
  });
8574
- if (!defaultAgent) {
8575
- throw new Error(`Default agent ${dbGraph.defaultAgentId} not found for graph ${dbGraph.id}`);
8654
+ if (!defaultSubAgent) {
8655
+ throw new Error(
8656
+ `Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
8657
+ );
8576
8658
  }
8577
8659
  const taskHandlerConfig = await createTaskHandlerConfig({
8578
8660
  tenantId: dbGraph.tenantId,
8579
8661
  projectId: dbGraph.projectId,
8580
8662
  graphId: dbGraph.id,
8581
- agentId: dbGraph.defaultAgentId,
8663
+ subAgentId: dbGraph.defaultSubAgentId,
8582
8664
  baseUrl,
8583
8665
  apiKey
8584
8666
  });
@@ -8607,7 +8689,7 @@ async function hydrateGraph({
8607
8689
  }
8608
8690
  };
8609
8691
  return {
8610
- agentId: dbGraph.id,
8692
+ subAgentId: dbGraph.id,
8611
8693
  // Use graph ID as agent ID for A2A purposes
8612
8694
  tenantId: dbGraph.tenantId,
8613
8695
  projectId: dbGraph.projectId,
@@ -8632,7 +8714,7 @@ async function getRegisteredGraph(executionContext) {
8632
8714
 
8633
8715
  // src/routes/agents.ts
8634
8716
  var app = new OpenAPIHono();
8635
- var logger19 = getLogger("agents");
8717
+ var logger18 = getLogger("agents");
8636
8718
  app.openapi(
8637
8719
  createRoute({
8638
8720
  method: "get",
@@ -8670,7 +8752,7 @@ app.openapi(
8670
8752
  tracestate: c.req.header("tracestate"),
8671
8753
  baggage: c.req.header("baggage")
8672
8754
  };
8673
- logger19.info(
8755
+ logger18.info(
8674
8756
  {
8675
8757
  otelHeaders,
8676
8758
  path: c.req.path,
@@ -8679,22 +8761,22 @@ app.openapi(
8679
8761
  "OpenTelemetry headers: well-known agent.json"
8680
8762
  );
8681
8763
  const executionContext = getRequestExecutionContext(c);
8682
- const { tenantId, projectId, graphId, agentId } = executionContext;
8764
+ const { tenantId, projectId, graphId, subAgentId } = executionContext;
8683
8765
  console.dir("executionContext", executionContext);
8684
- if (agentId) {
8685
- logger19.info(
8766
+ if (subAgentId) {
8767
+ logger18.info(
8686
8768
  {
8687
8769
  message: "getRegisteredAgent (agent-level)",
8688
8770
  tenantId,
8689
8771
  projectId,
8690
8772
  graphId,
8691
- agentId
8773
+ subAgentId
8692
8774
  },
8693
8775
  "agent-level well-known agent.json"
8694
8776
  );
8695
8777
  const credentialStores = c.get("credentialStores");
8696
8778
  const agent = await getRegisteredAgent(executionContext, credentialStores);
8697
- logger19.info({ agent }, "agent registered: well-known agent.json");
8779
+ logger18.info({ agent }, "agent registered: well-known agent.json");
8698
8780
  if (!agent) {
8699
8781
  throw createApiError({
8700
8782
  code: "not_found",
@@ -8703,7 +8785,7 @@ app.openapi(
8703
8785
  }
8704
8786
  return c.json(agent.agentCard);
8705
8787
  } else {
8706
- logger19.info(
8788
+ logger18.info(
8707
8789
  {
8708
8790
  message: "getRegisteredGraph (graph-level)",
8709
8791
  tenantId,
@@ -8729,7 +8811,7 @@ app.post("/a2a", async (c) => {
8729
8811
  tracestate: c.req.header("tracestate"),
8730
8812
  baggage: c.req.header("baggage")
8731
8813
  };
8732
- logger19.info(
8814
+ logger18.info(
8733
8815
  {
8734
8816
  otelHeaders,
8735
8817
  path: c.req.path,
@@ -8738,15 +8820,15 @@ app.post("/a2a", async (c) => {
8738
8820
  "OpenTelemetry headers: a2a"
8739
8821
  );
8740
8822
  const executionContext = getRequestExecutionContext(c);
8741
- const { tenantId, projectId, graphId, agentId } = executionContext;
8742
- if (agentId) {
8743
- logger19.info(
8823
+ const { tenantId, projectId, graphId, subAgentId } = executionContext;
8824
+ if (subAgentId) {
8825
+ logger18.info(
8744
8826
  {
8745
8827
  message: "a2a (agent-level)",
8746
8828
  tenantId,
8747
8829
  projectId,
8748
8830
  graphId,
8749
- agentId
8831
+ subAgentId
8750
8832
  },
8751
8833
  "agent-level a2a endpoint"
8752
8834
  );
@@ -8764,7 +8846,7 @@ app.post("/a2a", async (c) => {
8764
8846
  }
8765
8847
  return a2aHandler(c, agent);
8766
8848
  } else {
8767
- logger19.info(
8849
+ logger18.info(
8768
8850
  {
8769
8851
  message: "a2a (graph-level)",
8770
8852
  tenantId,
@@ -8773,7 +8855,7 @@ app.post("/a2a", async (c) => {
8773
8855
  },
8774
8856
  "graph-level a2a endpoint"
8775
8857
  );
8776
- const graph = await getAgentGraphWithDefaultAgent(dbClient_default)({
8858
+ const graph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
8777
8859
  scopes: { tenantId, projectId, graphId }
8778
8860
  });
8779
8861
  if (!graph) {
@@ -8786,7 +8868,7 @@ app.post("/a2a", async (c) => {
8786
8868
  404
8787
8869
  );
8788
8870
  }
8789
- if (!graph.defaultAgentId) {
8871
+ if (!graph.defaultSubAgentId) {
8790
8872
  return c.json(
8791
8873
  {
8792
8874
  jsonrpc: "2.0",
@@ -8796,10 +8878,10 @@ app.post("/a2a", async (c) => {
8796
8878
  400
8797
8879
  );
8798
8880
  }
8799
- executionContext.agentId = graph.defaultAgentId;
8881
+ executionContext.subAgentId = graph.defaultSubAgentId;
8800
8882
  const credentialStores = c.get("credentialStores");
8801
- const defaultAgent = await getRegisteredAgent(executionContext, credentialStores);
8802
- if (!defaultAgent) {
8883
+ const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
8884
+ if (!defaultSubAgent) {
8803
8885
  return c.json(
8804
8886
  {
8805
8887
  jsonrpc: "2.0",
@@ -8809,24 +8891,24 @@ app.post("/a2a", async (c) => {
8809
8891
  404
8810
8892
  );
8811
8893
  }
8812
- return a2aHandler(c, defaultAgent);
8894
+ return a2aHandler(c, defaultSubAgent);
8813
8895
  }
8814
8896
  });
8815
8897
  var agents_default = app;
8816
- var logger20 = getLogger("Transfer");
8898
+ var logger19 = getLogger("Transfer");
8817
8899
  async function executeTransfer({
8818
8900
  tenantId,
8819
8901
  threadId,
8820
8902
  projectId,
8821
- targetAgentId
8903
+ targetSubAgentId
8822
8904
  }) {
8823
- logger20.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
8905
+ logger19.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
8824
8906
  await setActiveAgentForThread(dbClient_default)({
8825
8907
  scopes: { tenantId, projectId },
8826
8908
  threadId,
8827
- agentId: targetAgentId
8909
+ subAgentId: targetSubAgentId
8828
8910
  });
8829
- return { success: true, targetAgentId };
8911
+ return { success: true, targetSubAgentId };
8830
8912
  }
8831
8913
  function isTransferResponse(result) {
8832
8914
  return result?.artifacts.some(
@@ -9402,7 +9484,7 @@ function createMCPStreamHelper() {
9402
9484
  }
9403
9485
 
9404
9486
  // src/handlers/executionHandler.ts
9405
- var logger21 = getLogger("ExecutionHandler");
9487
+ var logger20 = getLogger("ExecutionHandler");
9406
9488
  var ExecutionHandler = class {
9407
9489
  constructor() {
9408
9490
  // Hardcoded error limit - separate from configurable stopWhen
@@ -9438,7 +9520,7 @@ var ExecutionHandler = class {
9438
9520
  if (emitOperations) {
9439
9521
  graphSessionManager.enableEmitOperations(requestId2);
9440
9522
  }
9441
- logger21.info(
9523
+ logger20.info(
9442
9524
  { sessionId: requestId2, graphId, conversationId, emitOperations },
9443
9525
  "Created GraphSession for message execution"
9444
9526
  );
@@ -9453,7 +9535,7 @@ var ExecutionHandler = class {
9453
9535
  );
9454
9536
  }
9455
9537
  } catch (error) {
9456
- logger21.error(
9538
+ logger20.error(
9457
9539
  {
9458
9540
  error: error instanceof Error ? error.message : "Unknown error",
9459
9541
  stack: error instanceof Error ? error.stack : void 0
@@ -9469,7 +9551,7 @@ var ExecutionHandler = class {
9469
9551
  try {
9470
9552
  await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
9471
9553
  const taskId = `task_${conversationId}-${requestId2}`;
9472
- logger21.info(
9554
+ logger20.info(
9473
9555
  { taskId, currentAgentId, conversationId, requestId: requestId2 },
9474
9556
  "Attempting to create or reuse existing task"
9475
9557
  );
@@ -9479,7 +9561,7 @@ var ExecutionHandler = class {
9479
9561
  tenantId,
9480
9562
  projectId,
9481
9563
  graphId,
9482
- agentId: currentAgentId,
9564
+ subAgentId: currentAgentId,
9483
9565
  contextId: conversationId,
9484
9566
  status: "pending",
9485
9567
  metadata: {
@@ -9493,7 +9575,7 @@ var ExecutionHandler = class {
9493
9575
  agent_id: currentAgentId
9494
9576
  }
9495
9577
  });
9496
- logger21.info(
9578
+ logger20.info(
9497
9579
  {
9498
9580
  taskId,
9499
9581
  createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
@@ -9502,27 +9584,27 @@ var ExecutionHandler = class {
9502
9584
  );
9503
9585
  } catch (error) {
9504
9586
  if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
9505
- logger21.info(
9587
+ logger20.info(
9506
9588
  { taskId, error: error.message },
9507
9589
  "Task already exists, fetching existing task"
9508
9590
  );
9509
9591
  const existingTask = await getTask(dbClient_default)({ id: taskId });
9510
9592
  if (existingTask) {
9511
9593
  task = existingTask;
9512
- logger21.info(
9594
+ logger20.info(
9513
9595
  { taskId, existingTask },
9514
9596
  "Successfully reused existing task from race condition"
9515
9597
  );
9516
9598
  } else {
9517
- logger21.error({ taskId, error }, "Task constraint failed but task not found");
9599
+ logger20.error({ taskId, error }, "Task constraint failed but task not found");
9518
9600
  throw error;
9519
9601
  }
9520
9602
  } else {
9521
- logger21.error({ taskId, error }, "Failed to create task due to non-constraint error");
9603
+ logger20.error({ taskId, error }, "Failed to create task due to non-constraint error");
9522
9604
  throw error;
9523
9605
  }
9524
9606
  }
9525
- logger21.debug(
9607
+ logger20.debug(
9526
9608
  {
9527
9609
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9528
9610
  executionType: "create_initial_task",
@@ -9540,7 +9622,7 @@ var ExecutionHandler = class {
9540
9622
  const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
9541
9623
  while (iterations < maxTransfers) {
9542
9624
  iterations++;
9543
- logger21.info(
9625
+ logger20.info(
9544
9626
  { iterations, currentAgentId, graphId, conversationId, fromAgentId },
9545
9627
  `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
9546
9628
  );
@@ -9548,10 +9630,10 @@ var ExecutionHandler = class {
9548
9630
  scopes: { tenantId, projectId },
9549
9631
  conversationId
9550
9632
  });
9551
- logger21.info({ activeAgent }, "activeAgent");
9552
- if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
9553
- currentAgentId = activeAgent.activeAgentId;
9554
- logger21.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
9633
+ logger20.info({ activeAgent }, "activeAgent");
9634
+ if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
9635
+ currentAgentId = activeAgent.activeSubAgentId;
9636
+ logger20.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
9555
9637
  }
9556
9638
  const agentBaseUrl = `${baseUrl}/agents`;
9557
9639
  const a2aClient = new A2AClient(agentBaseUrl, {
@@ -9592,13 +9674,13 @@ var ExecutionHandler = class {
9592
9674
  });
9593
9675
  if (!messageResponse?.result) {
9594
9676
  errorCount++;
9595
- logger21.error(
9677
+ logger20.error(
9596
9678
  { currentAgentId, iterations, errorCount },
9597
9679
  `No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
9598
9680
  );
9599
9681
  if (errorCount >= this.MAX_ERRORS) {
9600
9682
  const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
9601
- logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
9683
+ logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
9602
9684
  await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
9603
9685
  if (task) {
9604
9686
  await updateTask(dbClient_default)({
@@ -9621,20 +9703,20 @@ var ExecutionHandler = class {
9621
9703
  }
9622
9704
  if (isTransferResponse(messageResponse.result)) {
9623
9705
  const transferResponse = messageResponse.result;
9624
- const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
9706
+ const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
9625
9707
  const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
9626
- logger21.info({ targetAgentId, transferReason }, "transfer response");
9708
+ logger20.info({ targetSubAgentId, transferReason }, "transfer response");
9627
9709
  currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
9628
- const { success, targetAgentId: newAgentId } = await executeTransfer({
9710
+ const { success, targetSubAgentId: newAgentId } = await executeTransfer({
9629
9711
  projectId,
9630
9712
  tenantId,
9631
9713
  threadId: conversationId,
9632
- targetAgentId
9714
+ targetSubAgentId
9633
9715
  });
9634
9716
  if (success) {
9635
9717
  fromAgentId = currentAgentId;
9636
9718
  currentAgentId = newAgentId;
9637
- logger21.info(
9719
+ logger20.info(
9638
9720
  {
9639
9721
  transferFrom: fromAgentId,
9640
9722
  transferTo: currentAgentId,
@@ -9645,14 +9727,27 @@ var ExecutionHandler = class {
9645
9727
  }
9646
9728
  continue;
9647
9729
  }
9648
- const responseParts = messageResponse.result.artifacts?.flatMap(
9649
- (artifact) => artifact.parts || []
9650
- ) || [];
9730
+ let responseParts = [];
9731
+ if (messageResponse.result.streamedContent?.parts) {
9732
+ responseParts = messageResponse.result.streamedContent.parts;
9733
+ logger20.info(
9734
+ { partsCount: responseParts.length },
9735
+ "Using streamed content for conversation history"
9736
+ );
9737
+ } else {
9738
+ responseParts = messageResponse.result.artifacts?.flatMap(
9739
+ (artifact) => artifact.parts || []
9740
+ ) || [];
9741
+ logger20.info(
9742
+ { partsCount: responseParts.length },
9743
+ "Using artifacts for conversation history (fallback)"
9744
+ );
9745
+ }
9651
9746
  if (responseParts && responseParts.length > 0) {
9652
9747
  const graphSessionData = graphSessionManager.getSession(requestId2);
9653
9748
  if (graphSessionData) {
9654
9749
  const sessionSummary = graphSessionData.getSummary();
9655
- logger21.info(sessionSummary, "GraphSession data after completion");
9750
+ logger20.info(sessionSummary, "GraphSession data after completion");
9656
9751
  }
9657
9752
  let textContent = "";
9658
9753
  for (const part of responseParts) {
@@ -9684,8 +9779,7 @@ var ExecutionHandler = class {
9684
9779
  },
9685
9780
  visibility: "user-facing",
9686
9781
  messageType: "chat",
9687
- agentId: currentAgentId,
9688
- fromAgentId: currentAgentId,
9782
+ fromSubAgentId: currentAgentId,
9689
9783
  taskId: task.id
9690
9784
  });
9691
9785
  const updateTaskStart = Date.now();
@@ -9706,22 +9800,22 @@ var ExecutionHandler = class {
9706
9800
  }
9707
9801
  });
9708
9802
  const updateTaskEnd = Date.now();
9709
- logger21.info(
9803
+ logger20.info(
9710
9804
  { duration: updateTaskEnd - updateTaskStart },
9711
9805
  "Completed updateTask operation"
9712
9806
  );
9713
9807
  await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
9714
9808
  await sseHelper.complete();
9715
- logger21.info({}, "Ending GraphSession and cleaning up");
9809
+ logger20.info({}, "Ending GraphSession and cleaning up");
9716
9810
  graphSessionManager.endSession(requestId2);
9717
- logger21.info({}, "Cleaning up streamHelper");
9811
+ logger20.info({}, "Cleaning up streamHelper");
9718
9812
  unregisterStreamHelper(requestId2);
9719
9813
  let response;
9720
9814
  if (sseHelper instanceof MCPStreamHelper) {
9721
9815
  const captured = sseHelper.getCapturedResponse();
9722
9816
  response = captured.text || "No response content";
9723
9817
  }
9724
- logger21.info({}, "ExecutionHandler returning success");
9818
+ logger20.info({}, "ExecutionHandler returning success");
9725
9819
  return { success: true, iterations, response };
9726
9820
  } catch (error) {
9727
9821
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
@@ -9732,13 +9826,13 @@ var ExecutionHandler = class {
9732
9826
  });
9733
9827
  }
9734
9828
  errorCount++;
9735
- logger21.warn(
9829
+ logger20.warn(
9736
9830
  { iterations, errorCount },
9737
9831
  `No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
9738
9832
  );
9739
9833
  if (errorCount >= this.MAX_ERRORS) {
9740
9834
  const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
9741
- logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
9835
+ logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
9742
9836
  await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
9743
9837
  if (task) {
9744
9838
  await updateTask(dbClient_default)({
@@ -9759,7 +9853,7 @@ var ExecutionHandler = class {
9759
9853
  }
9760
9854
  }
9761
9855
  const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
9762
- logger21.error({ maxTransfers, iterations }, errorMessage);
9856
+ logger20.error({ maxTransfers, iterations }, errorMessage);
9763
9857
  await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
9764
9858
  if (task) {
9765
9859
  await updateTask(dbClient_default)({
@@ -9778,7 +9872,7 @@ var ExecutionHandler = class {
9778
9872
  unregisterStreamHelper(requestId2);
9779
9873
  return { success: false, error: errorMessage, iterations };
9780
9874
  } catch (error) {
9781
- logger21.error({ error }, "Error in execution handler");
9875
+ logger20.error({ error }, "Error in execution handler");
9782
9876
  const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
9783
9877
  await sseHelper.writeOperation(
9784
9878
  errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
@@ -9805,7 +9899,7 @@ var ExecutionHandler = class {
9805
9899
 
9806
9900
  // src/routes/chat.ts
9807
9901
  var app2 = new OpenAPIHono();
9808
- var logger22 = getLogger("completionsHandler");
9902
+ var logger21 = getLogger("completionsHandler");
9809
9903
  var chatCompletionsRoute = createRoute({
9810
9904
  method: "post",
9811
9905
  path: "/completions",
@@ -9923,7 +10017,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
9923
10017
  tracestate: c.req.header("tracestate"),
9924
10018
  baggage: c.req.header("baggage")
9925
10019
  };
9926
- logger22.info(
10020
+ logger21.info(
9927
10021
  {
9928
10022
  otelHeaders,
9929
10023
  path: c.req.path,
@@ -9947,20 +10041,20 @@ app2.openapi(chatCompletionsRoute, async (c) => {
9947
10041
  scopes: { tenantId, projectId, graphId }
9948
10042
  });
9949
10043
  let agentGraph;
9950
- let defaultAgentId;
10044
+ let defaultSubAgentId;
9951
10045
  if (fullGraph) {
9952
10046
  agentGraph = {
9953
10047
  id: fullGraph.id,
9954
10048
  name: fullGraph.name,
9955
10049
  tenantId,
9956
10050
  projectId,
9957
- defaultAgentId: fullGraph.defaultAgentId
10051
+ defaultSubAgentId: fullGraph.defaultSubAgentId
9958
10052
  };
9959
- const agentKeys = Object.keys(fullGraph.agents || {});
10053
+ const agentKeys = Object.keys(fullGraph.subAgents || {});
9960
10054
  const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
9961
- defaultAgentId = fullGraph.defaultAgentId || firstAgentId;
10055
+ defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
9962
10056
  } else {
9963
- agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
10057
+ agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
9964
10058
  scopes: { tenantId, projectId, graphId }
9965
10059
  });
9966
10060
  if (!agentGraph) {
@@ -9969,9 +10063,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
9969
10063
  message: "Agent graph not found"
9970
10064
  });
9971
10065
  }
9972
- defaultAgentId = agentGraph.defaultAgentId || "";
10066
+ defaultSubAgentId = agentGraph.defaultSubAgentId || "";
9973
10067
  }
9974
- if (!defaultAgentId) {
10068
+ if (!defaultSubAgentId) {
9975
10069
  throw createApiError({
9976
10070
  code: "not_found",
9977
10071
  message: "No default agent found in graph"
@@ -9981,7 +10075,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
9981
10075
  tenantId,
9982
10076
  projectId,
9983
10077
  id: conversationId,
9984
- activeAgentId: defaultAgentId
10078
+ activeSubAgentId: defaultSubAgentId
9985
10079
  });
9986
10080
  const activeAgent = await getActiveAgentForConversation(dbClient_default)({
9987
10081
  scopes: { tenantId, projectId },
@@ -9991,13 +10085,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
9991
10085
  setActiveAgentForConversation(dbClient_default)({
9992
10086
  scopes: { tenantId, projectId },
9993
10087
  conversationId,
9994
- agentId: defaultAgentId
10088
+ subAgentId: defaultSubAgentId
9995
10089
  });
9996
10090
  }
9997
- const agentId = activeAgent?.activeAgentId || defaultAgentId;
9998
- const agentInfo = await getAgentById(dbClient_default)({
10091
+ const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
10092
+ const agentInfo = await getSubAgentById(dbClient_default)({
9999
10093
  scopes: { tenantId, projectId, graphId },
10000
- agentId
10094
+ subAgentId
10001
10095
  });
10002
10096
  if (!agentInfo) {
10003
10097
  throw createApiError({
@@ -10016,14 +10110,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10016
10110
  dbClient: dbClient_default,
10017
10111
  credentialStores
10018
10112
  });
10019
- logger22.info(
10113
+ logger21.info(
10020
10114
  {
10021
10115
  tenantId,
10022
10116
  projectId,
10023
10117
  graphId,
10024
10118
  conversationId,
10025
- defaultAgentId,
10026
- activeAgentId: activeAgent?.activeAgentId || "none",
10119
+ defaultSubAgentId,
10120
+ activeSubAgentId: activeAgent?.activeSubAgentId || "none",
10027
10121
  hasContextConfig: !!agentGraph.contextConfigId,
10028
10122
  hasHeaders: !!body.headers,
10029
10123
  hasValidatedContext: !!validatedContext,
@@ -10064,7 +10158,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10064
10158
  try {
10065
10159
  const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
10066
10160
  await sseHelper.writeRole();
10067
- logger22.info({ agentId }, "Starting execution");
10161
+ logger21.info({ subAgentId }, "Starting execution");
10068
10162
  const emitOperationsHeader = c.req.header("x-emit-operations");
10069
10163
  const emitOperations = emitOperationsHeader === "true";
10070
10164
  const executionHandler = new ExecutionHandler();
@@ -10072,12 +10166,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10072
10166
  executionContext,
10073
10167
  conversationId,
10074
10168
  userMessage,
10075
- initialAgentId: agentId,
10169
+ initialAgentId: subAgentId,
10076
10170
  requestId: requestId2,
10077
10171
  sseHelper,
10078
10172
  emitOperations
10079
10173
  });
10080
- logger22.info(
10174
+ logger21.info(
10081
10175
  { result },
10082
10176
  `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
10083
10177
  );
@@ -10091,7 +10185,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10091
10185
  }
10092
10186
  await sseHelper.complete();
10093
10187
  } catch (error) {
10094
- logger22.error(
10188
+ logger21.error(
10095
10189
  {
10096
10190
  error: error instanceof Error ? error.message : error,
10097
10191
  stack: error instanceof Error ? error.stack : void 0
@@ -10108,12 +10202,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10108
10202
  );
10109
10203
  await sseHelper.complete();
10110
10204
  } catch (streamError) {
10111
- logger22.error({ streamError }, "Failed to write error to stream");
10205
+ logger21.error({ streamError }, "Failed to write error to stream");
10112
10206
  }
10113
10207
  }
10114
10208
  });
10115
10209
  } catch (error) {
10116
- logger22.error(
10210
+ logger21.error(
10117
10211
  {
10118
10212
  error: error instanceof Error ? error.message : error,
10119
10213
  stack: error instanceof Error ? error.stack : void 0
@@ -10137,7 +10231,7 @@ var getMessageText = (content) => {
10137
10231
  };
10138
10232
  var chat_default = app2;
10139
10233
  var app3 = new OpenAPIHono();
10140
- var logger23 = getLogger("chatDataStream");
10234
+ var logger22 = getLogger("chatDataStream");
10141
10235
  var chatDataStreamRoute = createRoute({
10142
10236
  method: "post",
10143
10237
  path: "/chat",
@@ -10202,7 +10296,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10202
10296
  "project.id": projectId
10203
10297
  });
10204
10298
  }
10205
- const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
10299
+ const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10206
10300
  scopes: { tenantId, projectId, graphId }
10207
10301
  });
10208
10302
  if (!agentGraph) {
@@ -10211,9 +10305,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10211
10305
  message: "Agent graph not found"
10212
10306
  });
10213
10307
  }
10214
- const defaultAgentId = agentGraph.defaultAgentId;
10308
+ const defaultSubAgentId = agentGraph.defaultSubAgentId;
10215
10309
  const graphName = agentGraph.name;
10216
- if (!defaultAgentId) {
10310
+ if (!defaultSubAgentId) {
10217
10311
  throw createApiError({
10218
10312
  code: "bad_request",
10219
10313
  message: "Graph does not have a default agent configured"
@@ -10227,13 +10321,13 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10227
10321
  setActiveAgentForConversation(dbClient_default)({
10228
10322
  scopes: { tenantId, projectId },
10229
10323
  conversationId,
10230
- agentId: defaultAgentId
10324
+ subAgentId: defaultSubAgentId
10231
10325
  });
10232
10326
  }
10233
- const agentId = activeAgent?.activeAgentId || defaultAgentId;
10234
- const agentInfo = await getAgentById(dbClient_default)({
10327
+ const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
10328
+ const agentInfo = await getSubAgentById(dbClient_default)({
10235
10329
  scopes: { tenantId, projectId, graphId },
10236
- agentId
10330
+ subAgentId
10237
10331
  });
10238
10332
  if (!agentInfo) {
10239
10333
  throw createApiError({
@@ -10254,7 +10348,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10254
10348
  });
10255
10349
  const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
10256
10350
  const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
10257
- logger23.info({ userText, lastUserMessage }, "userText");
10351
+ logger22.info({ userText, lastUserMessage }, "userText");
10258
10352
  const messageSpan = trace.getActiveSpan();
10259
10353
  if (messageSpan) {
10260
10354
  messageSpan.setAttributes({
@@ -10290,7 +10384,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10290
10384
  executionContext,
10291
10385
  conversationId,
10292
10386
  userMessage: userText,
10293
- initialAgentId: agentId,
10387
+ initialAgentId: subAgentId,
10294
10388
  requestId: `chatds-${Date.now()}`,
10295
10389
  sseHelper: streamHelper,
10296
10390
  emitOperations
@@ -10299,7 +10393,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10299
10393
  await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
10300
10394
  }
10301
10395
  } catch (err) {
10302
- logger23.error({ err }, "Streaming error");
10396
+ logger22.error({ err }, "Streaming error");
10303
10397
  await streamHelper.writeOperation(errorOp("Internal server error", "system"));
10304
10398
  } finally {
10305
10399
  if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
@@ -10320,7 +10414,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10320
10414
  )
10321
10415
  );
10322
10416
  } catch (error) {
10323
- logger23.error({ error }, "chatDataStream error");
10417
+ logger22.error({ error }, "chatDataStream error");
10324
10418
  throw createApiError({
10325
10419
  code: "internal_server_error",
10326
10420
  message: "Failed to process chat completion"
@@ -10331,7 +10425,7 @@ var chatDataStream_default = app3;
10331
10425
  function createMCPSchema(schema) {
10332
10426
  return schema;
10333
10427
  }
10334
- var logger24 = getLogger("mcp");
10428
+ var logger23 = getLogger("mcp");
10335
10429
  var _MockResponseSingleton = class _MockResponseSingleton {
10336
10430
  constructor() {
10337
10431
  __publicField(this, "mockRes");
@@ -10386,21 +10480,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
10386
10480
  id: 0
10387
10481
  });
10388
10482
  var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
10389
- logger24.info({ sessionId }, "Spoofing initialization message to set transport state");
10483
+ logger23.info({ sessionId }, "Spoofing initialization message to set transport state");
10390
10484
  const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
10391
10485
  const mockRes = MockResponseSingleton.getInstance().getMockResponse();
10392
10486
  try {
10393
10487
  await transport.handleRequest(req, mockRes, spoofInitMessage);
10394
- logger24.info({ sessionId }, "Successfully spoofed initialization");
10488
+ logger23.info({ sessionId }, "Successfully spoofed initialization");
10395
10489
  } catch (spoofError) {
10396
- logger24.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
10490
+ logger23.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
10397
10491
  }
10398
10492
  };
10399
10493
  var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10400
10494
  const sessionId = req.headers["mcp-session-id"];
10401
- logger24.info({ sessionId }, "Received MCP session ID");
10495
+ logger23.info({ sessionId }, "Received MCP session ID");
10402
10496
  if (!sessionId) {
10403
- logger24.info({ body }, "Missing session ID");
10497
+ logger23.info({ body }, "Missing session ID");
10404
10498
  res.writeHead(400).end(
10405
10499
  JSON.stringify({
10406
10500
  jsonrpc: "2.0",
@@ -10426,7 +10520,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10426
10520
  scopes: { tenantId, projectId },
10427
10521
  conversationId: sessionId
10428
10522
  });
10429
- logger24.info(
10523
+ logger23.info(
10430
10524
  {
10431
10525
  sessionId,
10432
10526
  conversationFound: !!conversation,
@@ -10437,7 +10531,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10437
10531
  "Conversation lookup result"
10438
10532
  );
10439
10533
  if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
10440
- logger24.info(
10534
+ logger23.info(
10441
10535
  { sessionId, conversationId: conversation?.id },
10442
10536
  "MCP session not found or invalid"
10443
10537
  );
@@ -10486,7 +10580,7 @@ var processUserMessage = async (tenantId, projectId, conversationId, query) => {
10486
10580
  messageType: "chat"
10487
10581
  });
10488
10582
  };
10489
- var executeAgentQuery = async (executionContext, conversationId, query, defaultAgentId) => {
10583
+ var executeAgentQuery = async (executionContext, conversationId, query, defaultSubAgentId) => {
10490
10584
  const requestId2 = `mcp-${Date.now()}`;
10491
10585
  const mcpStreamHelper = createMCPStreamHelper();
10492
10586
  const executionHandler = new ExecutionHandler();
@@ -10494,11 +10588,11 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
10494
10588
  executionContext,
10495
10589
  conversationId,
10496
10590
  userMessage: query,
10497
- initialAgentId: defaultAgentId,
10591
+ initialAgentId: defaultSubAgentId,
10498
10592
  requestId: requestId2,
10499
10593
  sseHelper: mcpStreamHelper
10500
10594
  });
10501
- logger24.info(
10595
+ logger23.info(
10502
10596
  { result },
10503
10597
  `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
10504
10598
  );
@@ -10525,7 +10619,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
10525
10619
  var getServer = async (headers, executionContext, conversationId, credentialStores) => {
10526
10620
  const { tenantId, projectId, graphId } = executionContext;
10527
10621
  setupTracing(conversationId, tenantId, graphId);
10528
- const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
10622
+ const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10529
10623
  scopes: { tenantId, projectId, graphId }
10530
10624
  });
10531
10625
  if (!agentGraph) {
@@ -10546,7 +10640,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10546
10640
  },
10547
10641
  async ({ query }) => {
10548
10642
  try {
10549
- if (!agentGraph.defaultAgentId) {
10643
+ if (!agentGraph.defaultSubAgentId) {
10550
10644
  return {
10551
10645
  content: [
10552
10646
  {
@@ -10557,10 +10651,10 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10557
10651
  isError: true
10558
10652
  };
10559
10653
  }
10560
- const defaultAgentId = agentGraph.defaultAgentId;
10561
- const agentInfo = await getAgentById(dbClient_default)({
10654
+ const defaultSubAgentId = agentGraph.defaultSubAgentId;
10655
+ const agentInfo = await getSubAgentById(dbClient_default)({
10562
10656
  scopes: { tenantId, projectId, graphId },
10563
- agentId: defaultAgentId
10657
+ subAgentId: defaultSubAgentId
10564
10658
  });
10565
10659
  if (!agentInfo) {
10566
10660
  return {
@@ -10582,7 +10676,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10582
10676
  dbClient: dbClient_default,
10583
10677
  credentialStores
10584
10678
  });
10585
- logger24.info(
10679
+ logger23.info(
10586
10680
  {
10587
10681
  tenantId,
10588
10682
  projectId,
@@ -10595,7 +10689,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10595
10689
  "parameters"
10596
10690
  );
10597
10691
  await processUserMessage(tenantId, projectId, conversationId, query);
10598
- return executeAgentQuery(executionContext, conversationId, query, defaultAgentId);
10692
+ return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
10599
10693
  } catch (error) {
10600
10694
  return {
10601
10695
  content: [
@@ -10644,9 +10738,9 @@ var validateRequestParameters = (c) => {
10644
10738
  };
10645
10739
  var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
10646
10740
  const { tenantId, projectId, graphId } = executionContext;
10647
- logger24.info({ body }, "Received initialization request");
10741
+ logger23.info({ body }, "Received initialization request");
10648
10742
  const sessionId = getConversationId();
10649
- const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
10743
+ const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10650
10744
  scopes: { tenantId, projectId, graphId }
10651
10745
  });
10652
10746
  if (!agentGraph) {
@@ -10659,7 +10753,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10659
10753
  { status: 404 }
10660
10754
  );
10661
10755
  }
10662
- if (!agentGraph.defaultAgentId) {
10756
+ if (!agentGraph.defaultSubAgentId) {
10663
10757
  return c.json(
10664
10758
  {
10665
10759
  jsonrpc: "2.0",
@@ -10673,7 +10767,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10673
10767
  id: sessionId,
10674
10768
  tenantId,
10675
10769
  projectId,
10676
- activeAgentId: agentGraph.defaultAgentId,
10770
+ activeSubAgentId: agentGraph.defaultSubAgentId,
10677
10771
  metadata: {
10678
10772
  sessionData: {
10679
10773
  graphId,
@@ -10684,7 +10778,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10684
10778
  }
10685
10779
  }
10686
10780
  });
10687
- logger24.info(
10781
+ logger23.info(
10688
10782
  { sessionId, conversationId: conversation.id },
10689
10783
  "Created MCP session as conversation"
10690
10784
  );
@@ -10693,9 +10787,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10693
10787
  });
10694
10788
  const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
10695
10789
  await server.connect(transport);
10696
- logger24.info({ sessionId }, "Server connected for initialization");
10790
+ logger23.info({ sessionId }, "Server connected for initialization");
10697
10791
  res.setHeader("Mcp-Session-Id", sessionId);
10698
- logger24.info(
10792
+ logger23.info(
10699
10793
  {
10700
10794
  sessionId,
10701
10795
  bodyMethod: body?.method,
@@ -10704,7 +10798,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10704
10798
  "About to handle initialization request"
10705
10799
  );
10706
10800
  await transport.handleRequest(req, res, body);
10707
- logger24.info({ sessionId }, "Successfully handled initialization request");
10801
+ logger23.info({ sessionId }, "Successfully handled initialization request");
10708
10802
  return toFetchResponse(res);
10709
10803
  };
10710
10804
  var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
@@ -10732,8 +10826,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
10732
10826
  sessionId,
10733
10827
  conversation.metadata?.session_data?.mcpProtocolVersion
10734
10828
  );
10735
- logger24.info({ sessionId }, "Server connected and transport initialized");
10736
- logger24.info(
10829
+ logger23.info({ sessionId }, "Server connected and transport initialized");
10830
+ logger23.info(
10737
10831
  {
10738
10832
  sessionId,
10739
10833
  bodyKeys: Object.keys(body || {}),
@@ -10747,9 +10841,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
10747
10841
  );
10748
10842
  try {
10749
10843
  await transport.handleRequest(req, res, body);
10750
- logger24.info({ sessionId }, "Successfully handled MCP request");
10844
+ logger23.info({ sessionId }, "Successfully handled MCP request");
10751
10845
  } catch (transportError) {
10752
- logger24.error(
10846
+ logger23.error(
10753
10847
  {
10754
10848
  sessionId,
10755
10849
  error: transportError,
@@ -10800,13 +10894,13 @@ app4.openapi(
10800
10894
  }
10801
10895
  const { executionContext } = paramValidation;
10802
10896
  const body = c.get("requestBody") || {};
10803
- logger24.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
10897
+ logger23.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
10804
10898
  const isInitRequest = body.method === "initialize";
10805
10899
  const { req, res } = toReqRes(c.req.raw);
10806
10900
  const validatedContext = c.get("validatedContext") || {};
10807
10901
  const credentialStores = c.get("credentialStores");
10808
- logger24.info({ validatedContext }, "Validated context");
10809
- logger24.info({ req }, "request");
10902
+ logger23.info({ validatedContext }, "Validated context");
10903
+ logger23.info({ req }, "request");
10810
10904
  if (isInitRequest) {
10811
10905
  return await handleInitializationRequest(
10812
10906
  body,
@@ -10828,7 +10922,7 @@ app4.openapi(
10828
10922
  );
10829
10923
  }
10830
10924
  } catch (e) {
10831
- logger24.error(
10925
+ logger23.error(
10832
10926
  {
10833
10927
  error: e instanceof Error ? e.message : e,
10834
10928
  stack: e instanceof Error ? e.stack : void 0
@@ -10840,7 +10934,7 @@ app4.openapi(
10840
10934
  }
10841
10935
  );
10842
10936
  app4.get("/", async (c) => {
10843
- logger24.info({}, "Received GET MCP request");
10937
+ logger23.info({}, "Received GET MCP request");
10844
10938
  return c.json(
10845
10939
  {
10846
10940
  jsonrpc: "2.0",
@@ -10854,7 +10948,7 @@ app4.get("/", async (c) => {
10854
10948
  );
10855
10949
  });
10856
10950
  app4.delete("/", async (c) => {
10857
- logger24.info({}, "Received DELETE MCP request");
10951
+ logger23.info({}, "Received DELETE MCP request");
10858
10952
  return c.json(
10859
10953
  {
10860
10954
  jsonrpc: "2.0",
@@ -10867,7 +10961,7 @@ app4.delete("/", async (c) => {
10867
10961
  var mcp_default = app4;
10868
10962
 
10869
10963
  // src/app.ts
10870
- var logger25 = getLogger("agents-run-api");
10964
+ var logger24 = getLogger("agents-run-api");
10871
10965
  function createExecutionHono(serverConfig, credentialStores) {
10872
10966
  const app6 = new OpenAPIHono();
10873
10967
  app6.use("*", otel());
@@ -10883,7 +10977,7 @@ function createExecutionHono(serverConfig, credentialStores) {
10883
10977
  const body = await c.req.json();
10884
10978
  c.set("requestBody", body);
10885
10979
  } catch (error) {
10886
- logger25.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
10980
+ logger24.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
10887
10981
  }
10888
10982
  }
10889
10983
  return next();
@@ -10934,8 +11028,8 @@ function createExecutionHono(serverConfig, credentialStores) {
10934
11028
  if (!isExpectedError) {
10935
11029
  const errorMessage = err instanceof Error ? err.message : String(err);
10936
11030
  const errorStack = err instanceof Error ? err.stack : void 0;
10937
- if (logger25) {
10938
- logger25.error(
11031
+ if (logger24) {
11032
+ logger24.error(
10939
11033
  {
10940
11034
  error: err,
10941
11035
  message: errorMessage,
@@ -10947,8 +11041,8 @@ function createExecutionHono(serverConfig, credentialStores) {
10947
11041
  );
10948
11042
  }
10949
11043
  } else {
10950
- if (logger25) {
10951
- logger25.error(
11044
+ if (logger24) {
11045
+ logger24.error(
10952
11046
  {
10953
11047
  error: err,
10954
11048
  path: c.req.path,
@@ -10965,8 +11059,8 @@ function createExecutionHono(serverConfig, credentialStores) {
10965
11059
  const response = err.getResponse();
10966
11060
  return response;
10967
11061
  } catch (responseError) {
10968
- if (logger25) {
10969
- logger25.error({ error: responseError }, "Error while handling HTTPException response");
11062
+ if (logger24) {
11063
+ logger24.error({ error: responseError }, "Error while handling HTTPException response");
10970
11064
  }
10971
11065
  }
10972
11066
  }
@@ -11000,7 +11094,7 @@ function createExecutionHono(serverConfig, credentialStores) {
11000
11094
  app6.use("*", async (c, next) => {
11001
11095
  const executionContext = c.get("executionContext");
11002
11096
  if (!executionContext) {
11003
- logger25.debug({}, "Empty execution context");
11097
+ logger24.debug({}, "Empty execution context");
11004
11098
  return next();
11005
11099
  }
11006
11100
  const { tenantId, projectId, graphId } = executionContext;
@@ -11009,7 +11103,7 @@ function createExecutionHono(serverConfig, credentialStores) {
11009
11103
  if (requestBody) {
11010
11104
  conversationId = requestBody.conversationId;
11011
11105
  if (!conversationId) {
11012
- logger25.debug({ requestBody }, "No conversation ID found in request body");
11106
+ logger24.debug({ requestBody }, "No conversation ID found in request body");
11013
11107
  }
11014
11108
  }
11015
11109
  const entries = Object.fromEntries(
@@ -11024,7 +11118,7 @@ function createExecutionHono(serverConfig, credentialStores) {
11024
11118
  })
11025
11119
  );
11026
11120
  if (!Object.keys(entries).length) {
11027
- logger25.debug({}, "Empty entries for baggage");
11121
+ logger24.debug({}, "Empty entries for baggage");
11028
11122
  return next();
11029
11123
  }
11030
11124
  const bag = Object.entries(entries).reduce(