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