@inkeep/agents-run-api 0.0.0-dev-20251022171155 → 0.0.0-dev-20251022211302

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
- import { flushBatchProcessor } from './chunk-TVLDBLRZ.js';
2
- import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-XLUE6U2L.js';
3
- import { dbClient_default } from './chunk-IBMWBEXH.js';
4
- import { env } from './chunk-LHCIBW34.js';
1
+ import { flushBatchProcessor } from './chunk-DWEFKQTA.js';
2
+ import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-IMJLQGAX.js';
3
+ import { dbClient_default } from './chunk-TRNLEUK2.js';
4
+ import { env } from './chunk-Z4TYO3W3.js';
5
5
  import { getLogger } from './chunk-A2S7GSHL.js';
6
6
  import { __publicField } from './chunk-PKBMQBKP.js';
7
- import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, getDataComponent, getProject, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS } from '@inkeep/agents-core';
7
+ import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, getDataComponent, getProject, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } 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';
@@ -40,7 +40,8 @@ function createExecutionContext(params) {
40
40
  agentId: params.agentId,
41
41
  baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
42
42
  apiKeyId: params.apiKeyId,
43
- subAgentId: params.subAgentId
43
+ subAgentId: params.subAgentId,
44
+ metadata: params.metadata || {}
44
45
  };
45
46
  }
46
47
 
@@ -62,28 +63,36 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
62
63
  const reqUrl = new URL(c.req.url);
63
64
  const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
64
65
  if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
66
+ logger.info({}, "development environment");
65
67
  let executionContext;
66
68
  if (authHeader?.startsWith("Bearer ")) {
69
+ const apiKey2 = authHeader.substring(7);
67
70
  try {
68
- executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
71
+ executionContext = await extractContextFromApiKey(apiKey2, baseUrl);
69
72
  if (subAgentId) {
70
73
  executionContext.subAgentId = subAgentId;
71
74
  }
72
- logger.info({}, "Development/test environment - API key authenticated successfully");
75
+ c.set("executionContext", executionContext);
73
76
  } catch {
74
- executionContext = createExecutionContext({
75
- apiKey: "development",
76
- tenantId: tenantId || "test-tenant",
77
- projectId: projectId || "test-project",
78
- agentId: agentId || "test-agent",
79
- apiKeyId: "test-key",
80
- baseUrl,
81
- subAgentId
82
- });
83
- logger.info(
84
- {},
85
- "Development/test environment - fallback to default context due to invalid API key"
86
- );
77
+ try {
78
+ executionContext = await extractContextFromTeamAgentToken(apiKey2, baseUrl, subAgentId);
79
+ c.set("executionContext", executionContext);
80
+ } catch {
81
+ executionContext = createExecutionContext({
82
+ apiKey: "development",
83
+ tenantId: tenantId || "test-tenant",
84
+ projectId: projectId || "test-project",
85
+ agentId: agentId || "test-agent",
86
+ apiKeyId: "test-key",
87
+ baseUrl,
88
+ subAgentId
89
+ });
90
+ c.set("executionContext", executionContext);
91
+ logger.info(
92
+ {},
93
+ "Development/test environment - fallback to default context due to invalid API key"
94
+ );
95
+ }
87
96
  }
88
97
  } else {
89
98
  executionContext = createExecutionContext({
@@ -95,12 +104,12 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
95
104
  baseUrl,
96
105
  subAgentId
97
106
  });
107
+ c.set("executionContext", executionContext);
98
108
  logger.info(
99
109
  {},
100
110
  "Development/test environment - no API key provided, using default context"
101
111
  );
102
112
  }
103
- c.set("executionContext", executionContext);
104
113
  await next();
105
114
  return;
106
115
  }
@@ -131,12 +140,21 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
131
140
  await next();
132
141
  return;
133
142
  } else if (apiKey) {
134
- const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
135
- if (subAgentId) {
136
- executionContext.subAgentId = subAgentId;
143
+ try {
144
+ const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
145
+ if (subAgentId) {
146
+ executionContext.subAgentId = subAgentId;
147
+ }
148
+ c.set("executionContext", executionContext);
149
+ logger.info({}, "API key authenticated successfully");
150
+ } catch {
151
+ const executionContext = await extractContextFromTeamAgentToken(
152
+ apiKey,
153
+ baseUrl,
154
+ subAgentId
155
+ );
156
+ c.set("executionContext", executionContext);
137
157
  }
138
- c.set("executionContext", executionContext);
139
- logger.info({}, "API key authenticated successfully");
140
158
  await next();
141
159
  return;
142
160
  } else {
@@ -166,14 +184,24 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
166
184
  "API key authenticated successfully"
167
185
  );
168
186
  await next();
169
- } catch (error) {
170
- if (error instanceof HTTPException) {
171
- throw error;
187
+ } catch {
188
+ try {
189
+ const executionContext = await extractContextFromTeamAgentToken(
190
+ apiKey,
191
+ baseUrl,
192
+ subAgentId
193
+ );
194
+ c.set("executionContext", executionContext);
195
+ await next();
196
+ } catch (error) {
197
+ if (error instanceof HTTPException) {
198
+ throw error;
199
+ }
200
+ logger.error({ error }, "API key authentication error");
201
+ throw new HTTPException(500, {
202
+ message: "Authentication failed"
203
+ });
172
204
  }
173
- logger.error({ error }, "API key authentication error");
174
- throw new HTTPException(500, {
175
- message: "Authentication failed"
176
- });
177
205
  }
178
206
  });
179
207
  var extractContextFromApiKey = async (apiKey, baseUrl) => {
@@ -195,8 +223,15 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
195
223
  message: "Invalid or expired API key"
196
224
  });
197
225
  }
198
- logger.info({ agent }, "agent");
199
- logger.info({ defaultSubAgentId: agent.defaultSubAgentId }, "agent.defaultSubAgentId");
226
+ logger.debug(
227
+ {
228
+ tenantId: apiKeyRecord.tenantId,
229
+ projectId: apiKeyRecord.projectId,
230
+ agentId: apiKeyRecord.agentId,
231
+ subAgentId: agent.defaultSubAgentId || void 0
232
+ },
233
+ "API key authenticated successfully"
234
+ );
200
235
  return createExecutionContext({
201
236
  apiKey,
202
237
  tenantId: apiKeyRecord.tenantId,
@@ -207,6 +242,53 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
207
242
  subAgentId: agent.defaultSubAgentId || void 0
208
243
  });
209
244
  };
245
+ var extractContextFromTeamAgentToken = async (token, baseUrl, expectedSubAgentId) => {
246
+ const result = await verifyServiceToken(token);
247
+ if (!result.valid || !result.payload) {
248
+ logger.warn({ error: result.error }, "Invalid team agent JWT token");
249
+ throw new HTTPException(401, {
250
+ message: `Invalid team agent token: ${result.error || "Unknown error"}`
251
+ });
252
+ }
253
+ const payload = result.payload;
254
+ if (expectedSubAgentId && !validateTargetAgent(payload, expectedSubAgentId)) {
255
+ logger.error(
256
+ {
257
+ tokenTargetAgentId: payload.aud,
258
+ expectedSubAgentId,
259
+ originAgentId: payload.sub
260
+ },
261
+ "Team agent token target mismatch"
262
+ );
263
+ throw new HTTPException(403, {
264
+ message: "Token not valid for the requested agent"
265
+ });
266
+ }
267
+ logger.info(
268
+ {
269
+ originAgentId: payload.sub,
270
+ targetAgentId: payload.aud,
271
+ tenantId: payload.tenantId,
272
+ projectId: payload.projectId
273
+ },
274
+ "Team agent JWT token authenticated successfully"
275
+ );
276
+ return createExecutionContext({
277
+ apiKey: "team-agent-jwt",
278
+ // Not an actual API key
279
+ tenantId: payload.tenantId,
280
+ projectId: payload.projectId,
281
+ agentId: payload.aud,
282
+ // Target agent ID
283
+ apiKeyId: "team-agent-token",
284
+ baseUrl,
285
+ subAgentId: void 0,
286
+ metadata: {
287
+ teamDelegation: true,
288
+ originAgentId: payload.sub
289
+ }
290
+ });
291
+ };
210
292
  function setupOpenAPIRoutes(app7) {
211
293
  app7.get("/openapi.json", (c) => {
212
294
  try {
@@ -387,7 +469,7 @@ async function handleMessageSend(c, agent, request) {
387
469
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
388
470
  });
389
471
  logger2.info({ metadata: params.message.metadata }, "message metadata");
390
- if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId) {
472
+ if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId || params.message.metadata?.fromTeamAgentId) {
391
473
  const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
392
474
  try {
393
475
  const messageData = {
@@ -409,13 +491,18 @@ async function handleMessageSend(c, agent, request) {
409
491
  } else if (params.message.metadata?.fromExternalAgentId) {
410
492
  messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
411
493
  messageData.toSubAgentId = agent.subAgentId;
494
+ } else if (params.message.metadata?.fromTeamAgentId) {
495
+ messageData.fromTeamAgentId = params.message.metadata.fromTeamAgentId;
496
+ messageData.toTeamAgentId = agent.subAgentId;
412
497
  }
413
498
  await createMessage(dbClient_default)(messageData);
414
499
  logger2.info(
415
500
  {
416
501
  fromSubAgentId: params.message.metadata.fromSubAgentId,
417
502
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
503
+ fromTeamAgentId: params.message.metadata.fromTeamAgentId,
418
504
  toSubAgentId: agent.subAgentId,
505
+ toTeamAgentId: params.message.metadata.fromTeamAgentId ? agent.subAgentId : void 0,
419
506
  conversationId: effectiveContextId,
420
507
  messageType: "a2a-request",
421
508
  taskId: task.id
@@ -428,6 +515,7 @@ async function handleMessageSend(c, agent, request) {
428
515
  error,
429
516
  fromSubAgentId: params.message.metadata.fromSubAgentId,
430
517
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
518
+ fromTeamAgentId: params.message.metadata.fromTeamAgentId,
431
519
  toSubAgentId: agent.subAgentId,
432
520
  conversationId: effectiveContextId
433
521
  },
@@ -5434,8 +5522,10 @@ function createDelegateToAgentTool({
5434
5522
  );
5435
5523
  }
5436
5524
  const isInternal = delegateConfig.type === "internal";
5525
+ const isExternal = delegateConfig.type === "external";
5526
+ const isTeam = delegateConfig.type === "team";
5437
5527
  let resolvedHeaders = {};
5438
- if (!isInternal) {
5528
+ if (isExternal) {
5439
5529
  if ((delegateConfig.config.credentialReferenceId || delegateConfig.config.headers) && credentialStoreRegistry) {
5440
5530
  const contextResolver = new ContextResolver(
5441
5531
  tenantId,
@@ -5473,6 +5563,23 @@ function createDelegateToAgentTool({
5473
5563
  headers: delegateConfig.config.headers || void 0
5474
5564
  });
5475
5565
  }
5566
+ } else if (isTeam) {
5567
+ const contextResolver = new ContextResolver(
5568
+ tenantId,
5569
+ projectId,
5570
+ dbClient_default,
5571
+ credentialStoreRegistry
5572
+ );
5573
+ const context2 = await contextResolver.resolveHeaders(metadata.conversationId, contextId);
5574
+ for (const [key, value] of Object.entries(headers)) {
5575
+ resolvedHeaders[key] = TemplateEngine.render(value, context2, { strict: true });
5576
+ }
5577
+ resolvedHeaders.Authorization = `Bearer ${await generateServiceToken({
5578
+ tenantId,
5579
+ projectId,
5580
+ originAgentId: agentId,
5581
+ targetAgentId: delegateConfig.config.id
5582
+ })}`;
5476
5583
  } else {
5477
5584
  resolvedHeaders = {
5478
5585
  Authorization: `Bearer ${metadata.apiKey}`,
@@ -7333,7 +7440,7 @@ var Agent = class {
7333
7440
  /**
7334
7441
  * Get resolved context using ContextResolver - will return cached data or fetch fresh data as needed
7335
7442
  */
7336
- async getResolvedContext(conversationId, headers) {
7443
+ async getResolvedContext(conversationId, headers2) {
7337
7444
  try {
7338
7445
  if (!this.config.contextConfigId) {
7339
7446
  logger15.debug({ agentId: this.config.agentId }, "No context config found for agent");
@@ -7357,7 +7464,7 @@ var Agent = class {
7357
7464
  const result = await this.contextResolver.resolve(contextConfig, {
7358
7465
  triggerEvent: "invocation",
7359
7466
  conversationId,
7360
- headers: headers || {},
7467
+ headers: headers2 || {},
7361
7468
  tenantId: this.config.tenantId
7362
7469
  });
7363
7470
  const contextWithBuiltins = {
@@ -7544,7 +7651,7 @@ var Agent = class {
7544
7651
  inputSchema: tool3.inputSchema || tool3.parameters || {},
7545
7652
  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."
7546
7653
  }));
7547
- const { getConversationScopedArtifacts } = await import('./conversations-H2TSLD3U.js');
7654
+ const { getConversationScopedArtifacts } = await import('./conversations-V6DNH5MW.js');
7548
7655
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
7549
7656
  const referenceArtifacts = await getConversationScopedArtifacts({
7550
7657
  tenantId: this.config.tenantId,
@@ -8459,6 +8566,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8459
8566
  const [
8460
8567
  internalRelations,
8461
8568
  externalRelations,
8569
+ teamRelations,
8462
8570
  toolsForAgent,
8463
8571
  dataComponents,
8464
8572
  artifactComponents
@@ -8479,6 +8587,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8479
8587
  subAgentId: config.subAgentId
8480
8588
  }
8481
8589
  }),
8590
+ getTeamAgentsForSubAgent(dbClient_default)({
8591
+ scopes: {
8592
+ tenantId: config.tenantId,
8593
+ projectId: config.projectId,
8594
+ agentId: config.agentId,
8595
+ subAgentId: config.subAgentId
8596
+ }
8597
+ }),
8482
8598
  getToolsForAgent(dbClient_default)({
8483
8599
  scopes: {
8484
8600
  tenantId: config.tenantId,
@@ -8627,6 +8743,17 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8627
8743
  relationId: relation.id,
8628
8744
  relationType: "delegate"
8629
8745
  }
8746
+ })),
8747
+ ...teamRelations.data.map((relation) => ({
8748
+ type: "team",
8749
+ config: {
8750
+ id: relation.targetAgent.id,
8751
+ name: relation.targetAgent.name,
8752
+ description: relation.targetAgent.description || "",
8753
+ baseUrl: config.baseUrl,
8754
+ headers: relation.headers,
8755
+ relationId: relation.id
8756
+ }
8630
8757
  }))
8631
8758
  ],
8632
8759
  tools: toolsForAgentResult,
@@ -8848,6 +8975,7 @@ var createTaskHandlerConfig = async (params) => {
8848
8975
  };
8849
8976
 
8850
8977
  // src/data/agents.ts
8978
+ var logger17 = getLogger("agents");
8851
8979
  function createAgentCard({
8852
8980
  dbAgent,
8853
8981
  baseUrl
@@ -8949,13 +9077,26 @@ async function hydrateAgent({
8949
9077
  async function getRegisteredAgent(params) {
8950
9078
  const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
8951
9079
  const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
9080
+ let dbAgent;
8952
9081
  if (!subAgentId) {
8953
- throw new Error("Agent ID is required");
9082
+ const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
9083
+ scopes: { tenantId, projectId, agentId }
9084
+ });
9085
+ logger17.info({ agent }, "agent with default sub agent");
9086
+ if (!agent || !agent.defaultSubAgent) {
9087
+ return null;
9088
+ }
9089
+ dbAgent = agent.defaultSubAgent;
9090
+ } else {
9091
+ const response = await getSubAgentById(dbClient_default)({
9092
+ scopes: { tenantId, projectId, agentId },
9093
+ subAgentId
9094
+ });
9095
+ if (!response) {
9096
+ return null;
9097
+ }
9098
+ dbAgent = response;
8954
9099
  }
8955
- const dbAgent = await getSubAgentById(dbClient_default)({
8956
- scopes: { tenantId, projectId, agentId },
8957
- subAgentId
8958
- });
8959
9100
  if (!dbAgent) {
8960
9101
  return null;
8961
9102
  }
@@ -8972,7 +9113,7 @@ async function getRegisteredAgent(params) {
8972
9113
 
8973
9114
  // src/routes/agents.ts
8974
9115
  var app = new OpenAPIHono();
8975
- var logger17 = getLogger("agents");
9116
+ var logger18 = getLogger("agents");
8976
9117
  app.openapi(
8977
9118
  createRoute({
8978
9119
  method: "get",
@@ -9010,7 +9151,7 @@ app.openapi(
9010
9151
  tracestate: c.req.header("tracestate"),
9011
9152
  baggage: c.req.header("baggage")
9012
9153
  };
9013
- logger17.info(
9154
+ logger18.info(
9014
9155
  {
9015
9156
  otelHeaders,
9016
9157
  path: c.req.path,
@@ -9020,56 +9161,32 @@ app.openapi(
9020
9161
  );
9021
9162
  const executionContext = getRequestExecutionContext(c);
9022
9163
  const { tenantId, projectId, agentId, subAgentId } = executionContext;
9023
- logger17.info({ executionContext }, "executionContext");
9024
- if (subAgentId) {
9025
- logger17.info(
9026
- {
9027
- message: "getRegisteredAgent (agent-level)",
9028
- tenantId,
9029
- projectId,
9030
- agentId,
9031
- subAgentId
9032
- },
9033
- "agent-level well-known agent.json"
9034
- );
9035
- const credentialStores = c.get("credentialStores");
9036
- const sandboxConfig = c.get("sandboxConfig");
9037
- const agent = await getRegisteredAgent({
9038
- executionContext,
9039
- credentialStoreRegistry: credentialStores,
9040
- sandboxConfig
9041
- });
9042
- logger17.info({ agent }, "agent registered: well-known agent.json");
9043
- if (!agent) {
9044
- throw createApiError({
9045
- code: "not_found",
9046
- message: "Agent not found"
9047
- });
9048
- }
9049
- return c.json(agent.agentCard);
9050
- } else {
9051
- logger17.info(
9052
- {
9053
- message: "getRegisteredAgent (agent-level)",
9054
- tenantId,
9055
- projectId,
9056
- agentId
9057
- },
9058
- "agent-level well-known agent.json"
9059
- );
9060
- const sandboxConfig = c.get("sandboxConfig");
9061
- const agent = await getRegisteredAgent({
9062
- executionContext,
9063
- sandboxConfig
9164
+ logger18.info({ executionContext }, "executionContext");
9165
+ logger18.info(
9166
+ {
9167
+ message: "getRegisteredAgent (agent-level)",
9168
+ tenantId,
9169
+ projectId,
9170
+ agentId,
9171
+ subAgentId
9172
+ },
9173
+ "agent-level well-known agent.json"
9174
+ );
9175
+ const credentialStores = c.get("credentialStores");
9176
+ const sandboxConfig = c.get("sandboxConfig");
9177
+ const agent = await getRegisteredAgent({
9178
+ executionContext,
9179
+ credentialStoreRegistry: credentialStores,
9180
+ sandboxConfig
9181
+ });
9182
+ logger18.info({ agent }, "agent registered: well-known agent.json");
9183
+ if (!agent) {
9184
+ throw createApiError({
9185
+ code: "not_found",
9186
+ message: "Agent not found"
9064
9187
  });
9065
- if (!agent) {
9066
- throw createApiError({
9067
- code: "not_found",
9068
- message: "Agent not found"
9069
- });
9070
- }
9071
- return c.json(agent.agentCard);
9072
9188
  }
9189
+ return c.json(agent.agentCard);
9073
9190
  }
9074
9191
  );
9075
9192
  app.post("/a2a", async (c) => {
@@ -9078,7 +9195,7 @@ app.post("/a2a", async (c) => {
9078
9195
  tracestate: c.req.header("tracestate"),
9079
9196
  baggage: c.req.header("baggage")
9080
9197
  };
9081
- logger17.info(
9198
+ logger18.info(
9082
9199
  {
9083
9200
  otelHeaders,
9084
9201
  path: c.req.path,
@@ -9089,7 +9206,7 @@ app.post("/a2a", async (c) => {
9089
9206
  const executionContext = getRequestExecutionContext(c);
9090
9207
  const { tenantId, projectId, agentId, subAgentId } = executionContext;
9091
9208
  if (subAgentId) {
9092
- logger17.info(
9209
+ logger18.info(
9093
9210
  {
9094
9211
  message: "a2a (agent-level)",
9095
9212
  tenantId,
@@ -9118,7 +9235,7 @@ app.post("/a2a", async (c) => {
9118
9235
  }
9119
9236
  return a2aHandler(c, agent);
9120
9237
  } else {
9121
- logger17.info(
9238
+ logger18.info(
9122
9239
  {
9123
9240
  message: "a2a (agent-level)",
9124
9241
  tenantId,
@@ -9221,14 +9338,14 @@ function extractTransferData(task) {
9221
9338
  }
9222
9339
 
9223
9340
  // src/a2a/transfer.ts
9224
- var logger18 = getLogger("Transfer");
9341
+ var logger19 = getLogger("Transfer");
9225
9342
  async function executeTransfer({
9226
9343
  tenantId,
9227
9344
  threadId,
9228
9345
  projectId,
9229
9346
  targetSubAgentId
9230
9347
  }) {
9231
- logger18.info(
9348
+ logger19.info(
9232
9349
  {
9233
9350
  targetAgent: targetSubAgentId,
9234
9351
  threadId,
@@ -9243,12 +9360,12 @@ async function executeTransfer({
9243
9360
  threadId,
9244
9361
  subAgentId: targetSubAgentId
9245
9362
  });
9246
- logger18.info(
9363
+ logger19.info(
9247
9364
  { targetAgent: targetSubAgentId, threadId },
9248
9365
  "Successfully updated active_sub_agent_id in database"
9249
9366
  );
9250
9367
  } catch (error) {
9251
- logger18.error(
9368
+ logger19.error(
9252
9369
  { error, targetAgent: targetSubAgentId, threadId },
9253
9370
  "Failed to update active_sub_agent_id"
9254
9371
  );
@@ -9819,7 +9936,7 @@ function createMCPStreamHelper() {
9819
9936
  }
9820
9937
 
9821
9938
  // src/handlers/executionHandler.ts
9822
- var logger19 = getLogger("ExecutionHandler");
9939
+ var logger20 = getLogger("ExecutionHandler");
9823
9940
  var ExecutionHandler = class {
9824
9941
  constructor() {
9825
9942
  __publicField(this, "MAX_ERRORS", 3);
@@ -9854,7 +9971,7 @@ var ExecutionHandler = class {
9854
9971
  if (emitOperations) {
9855
9972
  agentSessionManager.enableEmitOperations(requestId2);
9856
9973
  }
9857
- logger19.info(
9974
+ logger20.info(
9858
9975
  { sessionId: requestId2, agentId, conversationId, emitOperations },
9859
9976
  "Created AgentSession for message execution"
9860
9977
  );
@@ -9871,7 +9988,7 @@ var ExecutionHandler = class {
9871
9988
  );
9872
9989
  }
9873
9990
  } catch (error) {
9874
- logger19.error(
9991
+ logger20.error(
9875
9992
  {
9876
9993
  error: error instanceof Error ? error.message : "Unknown error",
9877
9994
  stack: error instanceof Error ? error.stack : void 0
@@ -9887,7 +10004,7 @@ var ExecutionHandler = class {
9887
10004
  try {
9888
10005
  await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
9889
10006
  const taskId = `task_${conversationId}-${requestId2}`;
9890
- logger19.info(
10007
+ logger20.info(
9891
10008
  { taskId, currentAgentId, conversationId, requestId: requestId2 },
9892
10009
  "Attempting to create or reuse existing task"
9893
10010
  );
@@ -9911,7 +10028,7 @@ var ExecutionHandler = class {
9911
10028
  sub_agent_id: currentAgentId
9912
10029
  }
9913
10030
  });
9914
- logger19.info(
10031
+ logger20.info(
9915
10032
  {
9916
10033
  taskId,
9917
10034
  createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
@@ -9920,27 +10037,27 @@ var ExecutionHandler = class {
9920
10037
  );
9921
10038
  } catch (error) {
9922
10039
  if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
9923
- logger19.info(
10040
+ logger20.info(
9924
10041
  { taskId, error: error.message },
9925
10042
  "Task already exists, fetching existing task"
9926
10043
  );
9927
10044
  const existingTask = await getTask(dbClient_default)({ id: taskId });
9928
10045
  if (existingTask) {
9929
10046
  task = existingTask;
9930
- logger19.info(
10047
+ logger20.info(
9931
10048
  { taskId, existingTask },
9932
10049
  "Successfully reused existing task from race condition"
9933
10050
  );
9934
10051
  } else {
9935
- logger19.error({ taskId, error }, "Task constraint failed but task not found");
10052
+ logger20.error({ taskId, error }, "Task constraint failed but task not found");
9936
10053
  throw error;
9937
10054
  }
9938
10055
  } else {
9939
- logger19.error({ taskId, error }, "Failed to create task due to non-constraint error");
10056
+ logger20.error({ taskId, error }, "Failed to create task due to non-constraint error");
9940
10057
  throw error;
9941
10058
  }
9942
10059
  }
9943
- logger19.debug(
10060
+ logger20.debug(
9944
10061
  {
9945
10062
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9946
10063
  executionType: "create_initial_task",
@@ -9959,7 +10076,7 @@ var ExecutionHandler = class {
9959
10076
  const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
9960
10077
  while (iterations < maxTransfers) {
9961
10078
  iterations++;
9962
- logger19.info(
10079
+ logger20.info(
9963
10080
  { iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
9964
10081
  `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
9965
10082
  );
@@ -9967,10 +10084,10 @@ var ExecutionHandler = class {
9967
10084
  scopes: { tenantId, projectId },
9968
10085
  conversationId
9969
10086
  });
9970
- logger19.info({ activeAgent }, "activeAgent");
10087
+ logger20.info({ activeAgent }, "activeAgent");
9971
10088
  if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
9972
10089
  currentAgentId = activeAgent.activeSubAgentId;
9973
- logger19.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
10090
+ logger20.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
9974
10091
  }
9975
10092
  const agentBaseUrl = `${baseUrl}/agents`;
9976
10093
  const a2aClient = new A2AClient(agentBaseUrl, {
@@ -10011,13 +10128,13 @@ var ExecutionHandler = class {
10011
10128
  });
10012
10129
  if (!messageResponse?.result) {
10013
10130
  errorCount++;
10014
- logger19.error(
10131
+ logger20.error(
10015
10132
  { currentAgentId, iterations, errorCount },
10016
10133
  `No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
10017
10134
  );
10018
10135
  if (errorCount >= this.MAX_ERRORS) {
10019
10136
  const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
10020
- logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
10137
+ logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
10021
10138
  await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
10022
10139
  if (task) {
10023
10140
  await updateTask(dbClient_default)({
@@ -10041,7 +10158,7 @@ var ExecutionHandler = class {
10041
10158
  if (isTransferTask(messageResponse.result)) {
10042
10159
  const transferData = extractTransferData(messageResponse.result);
10043
10160
  if (!transferData) {
10044
- logger19.error(
10161
+ logger20.error(
10045
10162
  { result: messageResponse.result },
10046
10163
  "Transfer detected but no transfer data found"
10047
10164
  );
@@ -10050,7 +10167,7 @@ var ExecutionHandler = class {
10050
10167
  const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
10051
10168
  const firstArtifact = messageResponse.result.artifacts[0];
10052
10169
  const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
10053
- logger19.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
10170
+ logger20.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
10054
10171
  currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
10055
10172
  const { success, targetSubAgentId: newAgentId } = await executeTransfer({
10056
10173
  projectId,
@@ -10061,7 +10178,7 @@ var ExecutionHandler = class {
10061
10178
  if (success) {
10062
10179
  fromSubAgentId = currentAgentId;
10063
10180
  currentAgentId = newAgentId;
10064
- logger19.info(
10181
+ logger20.info(
10065
10182
  {
10066
10183
  transferFrom: fromSubAgentId,
10067
10184
  transferTo: currentAgentId,
@@ -10075,7 +10192,7 @@ var ExecutionHandler = class {
10075
10192
  let responseParts = [];
10076
10193
  if (messageResponse.result.streamedContent?.parts) {
10077
10194
  responseParts = messageResponse.result.streamedContent.parts;
10078
- logger19.info(
10195
+ logger20.info(
10079
10196
  { partsCount: responseParts.length },
10080
10197
  "Using streamed content for conversation history"
10081
10198
  );
@@ -10083,7 +10200,7 @@ var ExecutionHandler = class {
10083
10200
  responseParts = messageResponse.result.artifacts?.flatMap(
10084
10201
  (artifact) => artifact.parts || []
10085
10202
  ) || [];
10086
- logger19.info(
10203
+ logger20.info(
10087
10204
  { partsCount: responseParts.length },
10088
10205
  "Using artifacts for conversation history (fallback)"
10089
10206
  );
@@ -10092,7 +10209,7 @@ var ExecutionHandler = class {
10092
10209
  const agentSessionData = agentSessionManager.getSession(requestId2);
10093
10210
  if (agentSessionData) {
10094
10211
  const sessionSummary = agentSessionData.getSummary();
10095
- logger19.info(sessionSummary, "AgentSession data after completion");
10212
+ logger20.info(sessionSummary, "AgentSession data after completion");
10096
10213
  }
10097
10214
  let textContent = "";
10098
10215
  for (const part of responseParts) {
@@ -10145,22 +10262,22 @@ var ExecutionHandler = class {
10145
10262
  }
10146
10263
  });
10147
10264
  const updateTaskEnd = Date.now();
10148
- logger19.info(
10265
+ logger20.info(
10149
10266
  { duration: updateTaskEnd - updateTaskStart },
10150
10267
  "Completed updateTask operation"
10151
10268
  );
10152
10269
  await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
10153
10270
  await sseHelper.complete();
10154
- logger19.info({}, "Ending AgentSession and cleaning up");
10271
+ logger20.info({}, "Ending AgentSession and cleaning up");
10155
10272
  agentSessionManager.endSession(requestId2);
10156
- logger19.info({}, "Cleaning up streamHelper");
10273
+ logger20.info({}, "Cleaning up streamHelper");
10157
10274
  unregisterStreamHelper(requestId2);
10158
10275
  let response;
10159
10276
  if (sseHelper instanceof MCPStreamHelper) {
10160
10277
  const captured = sseHelper.getCapturedResponse();
10161
10278
  response = captured.text || "No response content";
10162
10279
  }
10163
- logger19.info({}, "ExecutionHandler returning success");
10280
+ logger20.info({}, "ExecutionHandler returning success");
10164
10281
  return { success: true, iterations, response };
10165
10282
  } catch (error) {
10166
10283
  setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
@@ -10171,13 +10288,13 @@ var ExecutionHandler = class {
10171
10288
  });
10172
10289
  }
10173
10290
  errorCount++;
10174
- logger19.warn(
10291
+ logger20.warn(
10175
10292
  { iterations, errorCount },
10176
10293
  `No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
10177
10294
  );
10178
10295
  if (errorCount >= this.MAX_ERRORS) {
10179
10296
  const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
10180
- logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
10297
+ logger20.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
10181
10298
  await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
10182
10299
  if (task) {
10183
10300
  await updateTask(dbClient_default)({
@@ -10198,7 +10315,7 @@ var ExecutionHandler = class {
10198
10315
  }
10199
10316
  }
10200
10317
  const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
10201
- logger19.error({ maxTransfers, iterations }, errorMessage);
10318
+ logger20.error({ maxTransfers, iterations }, errorMessage);
10202
10319
  await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
10203
10320
  if (task) {
10204
10321
  await updateTask(dbClient_default)({
@@ -10217,7 +10334,7 @@ var ExecutionHandler = class {
10217
10334
  unregisterStreamHelper(requestId2);
10218
10335
  return { success: false, error: errorMessage, iterations };
10219
10336
  } catch (error) {
10220
- logger19.error({ error }, "Error in execution handler");
10337
+ logger20.error({ error }, "Error in execution handler");
10221
10338
  const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
10222
10339
  await sseHelper.writeOperation(
10223
10340
  errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
@@ -10244,7 +10361,7 @@ var ExecutionHandler = class {
10244
10361
 
10245
10362
  // src/routes/chat.ts
10246
10363
  var app2 = new OpenAPIHono();
10247
- var logger20 = getLogger("completionsHandler");
10364
+ var logger21 = getLogger("completionsHandler");
10248
10365
  var chatCompletionsRoute = createRoute({
10249
10366
  method: "post",
10250
10367
  path: "/completions",
@@ -10362,7 +10479,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10362
10479
  tracestate: c.req.header("tracestate"),
10363
10480
  baggage: c.req.header("baggage")
10364
10481
  };
10365
- logger20.info(
10482
+ logger21.info(
10366
10483
  {
10367
10484
  otelHeaders,
10368
10485
  path: c.req.path,
@@ -10471,7 +10588,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10471
10588
  dbClient: dbClient_default,
10472
10589
  credentialStores
10473
10590
  });
10474
- logger20.info(
10591
+ logger21.info(
10475
10592
  {
10476
10593
  tenantId,
10477
10594
  projectId,
@@ -10519,7 +10636,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10519
10636
  try {
10520
10637
  const sseHelper = createSSEStreamHelper(stream3, requestId2, timestamp);
10521
10638
  await sseHelper.writeRole();
10522
- logger20.info({ subAgentId }, "Starting execution");
10639
+ logger21.info({ subAgentId }, "Starting execution");
10523
10640
  const emitOperationsHeader = c.req.header("x-emit-operations");
10524
10641
  const emitOperations = emitOperationsHeader === "true";
10525
10642
  const executionHandler = new ExecutionHandler();
@@ -10532,7 +10649,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10532
10649
  sseHelper,
10533
10650
  emitOperations
10534
10651
  });
10535
- logger20.info(
10652
+ logger21.info(
10536
10653
  { result },
10537
10654
  `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
10538
10655
  );
@@ -10546,7 +10663,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10546
10663
  }
10547
10664
  await sseHelper.complete();
10548
10665
  } catch (error) {
10549
- logger20.error(
10666
+ logger21.error(
10550
10667
  {
10551
10668
  error: error instanceof Error ? error.message : error,
10552
10669
  stack: error instanceof Error ? error.stack : void 0
@@ -10563,13 +10680,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10563
10680
  );
10564
10681
  await sseHelper.complete();
10565
10682
  } catch (streamError) {
10566
- logger20.error({ streamError }, "Failed to write error to stream");
10683
+ logger21.error({ streamError }, "Failed to write error to stream");
10567
10684
  }
10568
10685
  }
10569
10686
  });
10570
10687
  });
10571
10688
  } catch (error) {
10572
- logger20.error(
10689
+ logger21.error(
10573
10690
  {
10574
10691
  error: error instanceof Error ? error.message : error,
10575
10692
  stack: error instanceof Error ? error.stack : void 0
@@ -10593,7 +10710,7 @@ var getMessageText = (content) => {
10593
10710
  };
10594
10711
  var chat_default = app2;
10595
10712
  var app3 = new OpenAPIHono();
10596
- var logger21 = getLogger("chatDataStream");
10713
+ var logger22 = getLogger("chatDataStream");
10597
10714
  var chatDataStreamRoute = createRoute({
10598
10715
  method: "post",
10599
10716
  path: "/chat",
@@ -10717,7 +10834,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10717
10834
  });
10718
10835
  const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
10719
10836
  const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
10720
- logger21.info({ userText, lastUserMessage }, "userText");
10837
+ logger22.info({ userText, lastUserMessage }, "userText");
10721
10838
  const messageSpan = trace.getActiveSpan();
10722
10839
  if (messageSpan) {
10723
10840
  messageSpan.setAttributes({
@@ -10762,7 +10879,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10762
10879
  await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
10763
10880
  }
10764
10881
  } catch (err) {
10765
- logger21.error({ err }, "Streaming error");
10882
+ logger22.error({ err }, "Streaming error");
10766
10883
  await streamHelper.writeOperation(errorOp("Internal server error", "system"));
10767
10884
  } finally {
10768
10885
  if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
@@ -10784,7 +10901,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10784
10901
  );
10785
10902
  });
10786
10903
  } catch (error) {
10787
- logger21.error({ error }, "chatDataStream error");
10904
+ logger22.error({ error }, "chatDataStream error");
10788
10905
  throw createApiError({
10789
10906
  code: "internal_server_error",
10790
10907
  message: "Failed to process chat completion"
@@ -10792,7 +10909,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10792
10909
  }
10793
10910
  });
10794
10911
  var chatDataStream_default = app3;
10795
- var logger22 = getLogger("dataComponentPreview");
10912
+ var logger23 = getLogger("dataComponentPreview");
10796
10913
  var app4 = new OpenAPIHono();
10797
10914
  var generatePreviewRoute = createRoute({
10798
10915
  method: "post",
@@ -10838,7 +10955,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
10838
10955
  const { tenantId, projectId, id } = c.req.valid("param");
10839
10956
  const body = c.req.valid("json");
10840
10957
  const { instructions, existingCode } = body;
10841
- logger22.info(
10958
+ logger23.info(
10842
10959
  {
10843
10960
  tenantId,
10844
10961
  projectId,
@@ -10891,7 +11008,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
10891
11008
  await stream3.write(JSON.stringify(outputObject) + "\n");
10892
11009
  }
10893
11010
  } catch (error) {
10894
- logger22.error(
11011
+ logger23.error(
10895
11012
  { error, tenantId, projectId, dataComponentId: id },
10896
11013
  "Error streaming preview generation"
10897
11014
  );
@@ -10901,7 +11018,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
10901
11018
  }
10902
11019
  });
10903
11020
  } catch (error) {
10904
- logger22.error(
11021
+ logger23.error(
10905
11022
  { error, tenantId, projectId, dataComponentId: id },
10906
11023
  "Error generating component preview"
10907
11024
  );
@@ -11034,7 +11151,7 @@ var dataComponentPreview_default = app4;
11034
11151
  function createMCPSchema(schema) {
11035
11152
  return schema;
11036
11153
  }
11037
- var logger23 = getLogger("mcp");
11154
+ var logger24 = getLogger("mcp");
11038
11155
  var _MockResponseSingleton = class _MockResponseSingleton {
11039
11156
  constructor() {
11040
11157
  __publicField(this, "mockRes");
@@ -11089,21 +11206,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
11089
11206
  id: 0
11090
11207
  });
11091
11208
  var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
11092
- logger23.info({ sessionId }, "Spoofing initialization message to set transport state");
11209
+ logger24.info({ sessionId }, "Spoofing initialization message to set transport state");
11093
11210
  const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
11094
11211
  const mockRes = MockResponseSingleton.getInstance().getMockResponse();
11095
11212
  try {
11096
11213
  await transport.handleRequest(req, mockRes, spoofInitMessage);
11097
- logger23.info({ sessionId }, "Successfully spoofed initialization");
11214
+ logger24.info({ sessionId }, "Successfully spoofed initialization");
11098
11215
  } catch (spoofError) {
11099
- logger23.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
11216
+ logger24.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
11100
11217
  }
11101
11218
  };
11102
11219
  var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
11103
11220
  const sessionId = req.headers["mcp-session-id"];
11104
- logger23.info({ sessionId }, "Received MCP session ID");
11221
+ logger24.info({ sessionId }, "Received MCP session ID");
11105
11222
  if (!sessionId) {
11106
- logger23.info({ body }, "Missing session ID");
11223
+ logger24.info({ body }, "Missing session ID");
11107
11224
  res.writeHead(400).end(
11108
11225
  JSON.stringify({
11109
11226
  jsonrpc: "2.0",
@@ -11129,7 +11246,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
11129
11246
  scopes: { tenantId, projectId },
11130
11247
  conversationId: sessionId
11131
11248
  });
11132
- logger23.info(
11249
+ logger24.info(
11133
11250
  {
11134
11251
  sessionId,
11135
11252
  conversationFound: !!conversation,
@@ -11140,7 +11257,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
11140
11257
  "Conversation lookup result"
11141
11258
  );
11142
11259
  if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
11143
- logger23.info(
11260
+ logger24.info(
11144
11261
  { sessionId, conversationId: conversation?.id },
11145
11262
  "MCP session not found or invalid"
11146
11263
  );
@@ -11201,7 +11318,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
11201
11318
  requestId: requestId2,
11202
11319
  sseHelper: mcpStreamHelper
11203
11320
  });
11204
- logger23.info(
11321
+ logger24.info(
11205
11322
  { result },
11206
11323
  `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
11207
11324
  );
@@ -11225,7 +11342,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
11225
11342
  ]
11226
11343
  };
11227
11344
  };
11228
- var getServer = async (headers, executionContext, conversationId, credentialStores) => {
11345
+ var getServer = async (headers2, executionContext, conversationId, credentialStores) => {
11229
11346
  const { tenantId, projectId, agentId } = executionContext;
11230
11347
  setupTracing(conversationId, tenantId, agentId);
11231
11348
  const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
@@ -11281,18 +11398,18 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
11281
11398
  projectId,
11282
11399
  agentId,
11283
11400
  conversationId,
11284
- headers,
11401
+ headers: headers2,
11285
11402
  dbClient: dbClient_default,
11286
11403
  credentialStores
11287
11404
  });
11288
- logger23.info(
11405
+ logger24.info(
11289
11406
  {
11290
11407
  tenantId,
11291
11408
  projectId,
11292
11409
  agentId,
11293
11410
  conversationId,
11294
11411
  hasContextConfig: !!agent.contextConfigId,
11295
- hasHeaders: !!headers,
11412
+ hasHeaders: !!headers2,
11296
11413
  hasValidatedContext: !!resolvedContext
11297
11414
  },
11298
11415
  "parameters"
@@ -11347,7 +11464,7 @@ var validateRequestParameters = (c) => {
11347
11464
  };
11348
11465
  var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
11349
11466
  const { tenantId, projectId, agentId } = executionContext;
11350
- logger23.info({ body }, "Received initialization request");
11467
+ logger24.info({ body }, "Received initialization request");
11351
11468
  const sessionId = getConversationId();
11352
11469
  const activeSpan = trace.getActiveSpan();
11353
11470
  if (activeSpan) {
@@ -11403,7 +11520,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
11403
11520
  }
11404
11521
  }
11405
11522
  });
11406
- logger23.info(
11523
+ logger24.info(
11407
11524
  { sessionId, conversationId: conversation.id },
11408
11525
  "Created MCP session as conversation"
11409
11526
  );
@@ -11412,9 +11529,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
11412
11529
  });
11413
11530
  const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
11414
11531
  await server.connect(transport);
11415
- logger23.info({ sessionId }, "Server connected for initialization");
11532
+ logger24.info({ sessionId }, "Server connected for initialization");
11416
11533
  res.setHeader("Mcp-Session-Id", sessionId);
11417
- logger23.info(
11534
+ logger24.info(
11418
11535
  {
11419
11536
  sessionId,
11420
11537
  bodyMethod: body?.method,
@@ -11423,7 +11540,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
11423
11540
  "About to handle initialization request"
11424
11541
  );
11425
11542
  await transport.handleRequest(req, res, body);
11426
- logger23.info({ sessionId }, "Successfully handled initialization request");
11543
+ logger24.info({ sessionId }, "Successfully handled initialization request");
11427
11544
  return toFetchResponse(res);
11428
11545
  });
11429
11546
  };
@@ -11450,8 +11567,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
11450
11567
  sessionId,
11451
11568
  conversation.metadata?.session_data?.mcpProtocolVersion
11452
11569
  );
11453
- logger23.info({ sessionId }, "Server connected and transport initialized");
11454
- logger23.info(
11570
+ logger24.info({ sessionId }, "Server connected and transport initialized");
11571
+ logger24.info(
11455
11572
  {
11456
11573
  sessionId,
11457
11574
  bodyKeys: Object.keys(body || {}),
@@ -11465,9 +11582,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
11465
11582
  );
11466
11583
  try {
11467
11584
  await transport.handleRequest(req, res, body);
11468
- logger23.info({ sessionId }, "Successfully handled MCP request");
11585
+ logger24.info({ sessionId }, "Successfully handled MCP request");
11469
11586
  } catch (transportError) {
11470
- logger23.error(
11587
+ logger24.error(
11471
11588
  {
11472
11589
  sessionId,
11473
11590
  error: transportError,
@@ -11518,13 +11635,13 @@ app5.openapi(
11518
11635
  }
11519
11636
  const { executionContext } = paramValidation;
11520
11637
  const body = c.get("requestBody") || {};
11521
- logger23.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
11638
+ logger24.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
11522
11639
  const isInitRequest = body.method === "initialize";
11523
11640
  const { req, res } = toReqRes(c.req.raw);
11524
11641
  const validatedContext = c.get("validatedContext") || {};
11525
11642
  const credentialStores = c.get("credentialStores");
11526
- logger23.info({ validatedContext }, "Validated context");
11527
- logger23.info({ req }, "request");
11643
+ logger24.info({ validatedContext }, "Validated context");
11644
+ logger24.info({ req }, "request");
11528
11645
  if (isInitRequest) {
11529
11646
  return await handleInitializationRequest(
11530
11647
  body,
@@ -11546,7 +11663,7 @@ app5.openapi(
11546
11663
  );
11547
11664
  }
11548
11665
  } catch (e) {
11549
- logger23.error(
11666
+ logger24.error(
11550
11667
  {
11551
11668
  error: e instanceof Error ? e.message : e,
11552
11669
  stack: e instanceof Error ? e.stack : void 0
@@ -11558,7 +11675,7 @@ app5.openapi(
11558
11675
  }
11559
11676
  );
11560
11677
  app5.get("/", async (c) => {
11561
- logger23.info({}, "Received GET MCP request");
11678
+ logger24.info({}, "Received GET MCP request");
11562
11679
  return c.json(
11563
11680
  {
11564
11681
  jsonrpc: "2.0",
@@ -11572,7 +11689,7 @@ app5.get("/", async (c) => {
11572
11689
  );
11573
11690
  });
11574
11691
  app5.delete("/", async (c) => {
11575
- logger23.info({}, "Received DELETE MCP request");
11692
+ logger24.info({}, "Received DELETE MCP request");
11576
11693
  return c.json(
11577
11694
  {
11578
11695
  jsonrpc: "2.0",
@@ -11585,7 +11702,7 @@ app5.delete("/", async (c) => {
11585
11702
  var mcp_default = app5;
11586
11703
 
11587
11704
  // src/app.ts
11588
- var logger24 = getLogger("agents-run-api");
11705
+ var logger25 = getLogger("agents-run-api");
11589
11706
  function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11590
11707
  const app7 = new OpenAPIHono();
11591
11708
  app7.use("*", otel());
@@ -11604,7 +11721,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11604
11721
  const body = await c.req.json();
11605
11722
  c.set("requestBody", body);
11606
11723
  } catch (error) {
11607
- logger24.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
11724
+ logger25.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
11608
11725
  }
11609
11726
  }
11610
11727
  return next();
@@ -11655,8 +11772,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11655
11772
  if (!isExpectedError) {
11656
11773
  const errorMessage = err instanceof Error ? err.message : String(err);
11657
11774
  const errorStack = err instanceof Error ? err.stack : void 0;
11658
- if (logger24) {
11659
- logger24.error(
11775
+ if (logger25) {
11776
+ logger25.error(
11660
11777
  {
11661
11778
  error: err,
11662
11779
  message: errorMessage,
@@ -11668,8 +11785,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11668
11785
  );
11669
11786
  }
11670
11787
  } else {
11671
- if (logger24) {
11672
- logger24.error(
11788
+ if (logger25) {
11789
+ logger25.error(
11673
11790
  {
11674
11791
  error: err,
11675
11792
  path: c.req.path,
@@ -11686,8 +11803,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11686
11803
  const response = err.getResponse();
11687
11804
  return response;
11688
11805
  } catch (responseError) {
11689
- if (logger24) {
11690
- logger24.error({ error: responseError }, "Error while handling HTTPException response");
11806
+ if (logger25) {
11807
+ logger25.error({ error: responseError }, "Error while handling HTTPException response");
11691
11808
  }
11692
11809
  }
11693
11810
  }
@@ -11721,7 +11838,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11721
11838
  app7.use("*", async (c, next) => {
11722
11839
  const executionContext = c.get("executionContext");
11723
11840
  if (!executionContext) {
11724
- logger24.debug({}, "Empty execution context");
11841
+ logger25.debug({}, "Empty execution context");
11725
11842
  return next();
11726
11843
  }
11727
11844
  const { tenantId, projectId, agentId } = executionContext;
@@ -11730,7 +11847,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11730
11847
  if (requestBody) {
11731
11848
  conversationId = requestBody.conversationId;
11732
11849
  if (!conversationId) {
11733
- logger24.debug({ requestBody }, "No conversation ID found in request body");
11850
+ logger25.debug({ requestBody }, "No conversation ID found in request body");
11734
11851
  }
11735
11852
  }
11736
11853
  const entries = Object.fromEntries(
@@ -11745,7 +11862,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
11745
11862
  })
11746
11863
  );
11747
11864
  if (!Object.keys(entries).length) {
11748
- logger24.debug({}, "Empty entries for baggage");
11865
+ logger25.debug({}, "Empty entries for baggage");
11749
11866
  return next();
11750
11867
  }
11751
11868
  const bag = Object.entries(entries).reduce(