@inkeep/agents-run-api 0.0.0-dev-20250915105321 → 0.0.0-dev-20250915190940

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -461,6 +461,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
461
461
  return;
462
462
  } else if (apiKey) {
463
463
  const executionContext = await extractContextFromApiKey(apiKey);
464
+ executionContext.agentId = agentId;
464
465
  c.set("executionContext", executionContext);
465
466
  logger.info({}, "API key authenticated successfully");
466
467
  await next();
@@ -478,12 +479,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
478
479
  }
479
480
  try {
480
481
  const executionContext = await extractContextFromApiKey(apiKey);
482
+ executionContext.agentId = agentId;
481
483
  c.set("executionContext", executionContext);
482
484
  logger.debug(
483
485
  {
484
486
  tenantId: executionContext.tenantId,
485
487
  projectId: executionContext.projectId,
486
- graphId: executionContext.graphId
488
+ graphId: executionContext.graphId,
489
+ agentId: executionContext.agentId
487
490
  },
488
491
  "API key authenticated successfully"
489
492
  );
@@ -7707,69 +7710,75 @@ var ExecutionHandler = class {
7707
7710
  textContent += part.text;
7708
7711
  }
7709
7712
  }
7710
- const activeSpan = api.trace.getActiveSpan();
7711
- if (activeSpan) {
7712
- activeSpan.setAttributes({
7713
- "ai.response.content": textContent || "No response content",
7714
- "ai.response.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7715
- "ai.agent.name": currentAgentId
7716
- });
7717
- }
7718
- await agentsCore.createMessage(dbClient_default)({
7719
- id: nanoid.nanoid(),
7720
- tenantId,
7721
- projectId,
7722
- conversationId,
7723
- role: "agent",
7724
- content: {
7725
- text: textContent || void 0,
7726
- parts: responseParts.map((part) => ({
7727
- type: part.kind === "text" ? "text" : "data",
7728
- text: part.kind === "text" ? part.text : void 0,
7729
- data: part.kind === "data" ? JSON.stringify(part.data) : void 0
7730
- }))
7731
- },
7732
- visibility: "user-facing",
7733
- messageType: "chat",
7734
- agentId: currentAgentId,
7735
- fromAgentId: currentAgentId,
7736
- taskId: task.id
7737
- });
7738
- const updateTaskStart = Date.now();
7739
- await agentsCore.updateTask(dbClient_default)({
7740
- taskId: task.id,
7741
- data: {
7742
- status: "completed",
7743
- metadata: {
7744
- ...task.metadata,
7745
- completed_at: (/* @__PURE__ */ new Date()).toISOString(),
7746
- response: {
7747
- text: textContent,
7748
- parts: responseParts,
7749
- hasText: !!textContent,
7750
- hasData: responseParts.some((p) => p.kind === "data")
7713
+ return tracer.startActiveSpan("execution_handler.execute", {}, async (span) => {
7714
+ try {
7715
+ span.setAttributes({
7716
+ "ai.response.content": textContent || "No response content",
7717
+ "ai.response.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7718
+ "ai.agent.name": currentAgentId
7719
+ });
7720
+ await agentsCore.createMessage(dbClient_default)({
7721
+ id: nanoid.nanoid(),
7722
+ tenantId,
7723
+ projectId,
7724
+ conversationId,
7725
+ role: "agent",
7726
+ content: {
7727
+ text: textContent || void 0,
7728
+ parts: responseParts.map((part) => ({
7729
+ type: part.kind === "text" ? "text" : "data",
7730
+ text: part.kind === "text" ? part.text : void 0,
7731
+ data: part.kind === "data" ? JSON.stringify(part.data) : void 0
7732
+ }))
7733
+ },
7734
+ visibility: "user-facing",
7735
+ messageType: "chat",
7736
+ agentId: currentAgentId,
7737
+ fromAgentId: currentAgentId,
7738
+ taskId: task.id
7739
+ });
7740
+ const updateTaskStart = Date.now();
7741
+ await agentsCore.updateTask(dbClient_default)({
7742
+ taskId: task.id,
7743
+ data: {
7744
+ status: "completed",
7745
+ metadata: {
7746
+ ...task.metadata,
7747
+ completed_at: (/* @__PURE__ */ new Date()).toISOString(),
7748
+ response: {
7749
+ text: textContent,
7750
+ parts: responseParts,
7751
+ hasText: !!textContent,
7752
+ hasData: responseParts.some((p) => p.kind === "data")
7753
+ }
7754
+ }
7751
7755
  }
7756
+ });
7757
+ const updateTaskEnd = Date.now();
7758
+ logger18.info(
7759
+ { duration: updateTaskEnd - updateTaskStart },
7760
+ "Completed updateTask operation"
7761
+ );
7762
+ await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
7763
+ await sseHelper.complete();
7764
+ logger18.info({}, "Ending GraphSession and cleaning up");
7765
+ graphSessionManager.endSession(requestId2);
7766
+ logger18.info({}, "Cleaning up streamHelper");
7767
+ unregisterStreamHelper(requestId2);
7768
+ let response;
7769
+ if (sseHelper instanceof MCPStreamHelper) {
7770
+ const captured = sseHelper.getCapturedResponse();
7771
+ response = captured.text || "No response content";
7752
7772
  }
7773
+ logger18.info({}, "ExecutionHandler returning success");
7774
+ return { success: true, iterations, response };
7775
+ } catch (error) {
7776
+ agentsCore.setSpanWithError(span, error);
7777
+ throw error;
7778
+ } finally {
7779
+ span.end();
7753
7780
  }
7754
7781
  });
7755
- const updateTaskEnd = Date.now();
7756
- logger18.info(
7757
- { duration: updateTaskEnd - updateTaskStart },
7758
- "Completed updateTask operation"
7759
- );
7760
- await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
7761
- await sseHelper.complete();
7762
- logger18.info({}, "Ending GraphSession and cleaning up");
7763
- graphSessionManager.endSession(requestId2);
7764
- logger18.info({}, "Cleaning up streamHelper");
7765
- unregisterStreamHelper(requestId2);
7766
- let response;
7767
- if (sseHelper instanceof MCPStreamHelper) {
7768
- const captured = sseHelper.getCapturedResponse();
7769
- response = captured.text || "No response content";
7770
- }
7771
- logger18.info({}, "ExecutionHandler returning success");
7772
- return { success: true, iterations, response };
7773
7782
  }
7774
7783
  errorCount++;
7775
7784
  logger18.warn(
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
8
8
  import { NodeSDK } from '@opentelemetry/sdk-node';
9
9
  import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
10
10
  import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
11
- import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraph, createTask, updateTask, updateConversation, handleApiError, setSpanWithError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
11
+ import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraph, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
12
12
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
13
13
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
14
14
  import { Hono } from 'hono';
@@ -166,6 +166,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
166
166
  return;
167
167
  } else if (apiKey) {
168
168
  const executionContext = await extractContextFromApiKey(apiKey);
169
+ executionContext.agentId = agentId;
169
170
  c.set("executionContext", executionContext);
170
171
  logger.info({}, "API key authenticated successfully");
171
172
  await next();
@@ -183,12 +184,14 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
183
184
  }
184
185
  try {
185
186
  const executionContext = await extractContextFromApiKey(apiKey);
187
+ executionContext.agentId = agentId;
186
188
  c.set("executionContext", executionContext);
187
189
  logger.debug(
188
190
  {
189
191
  tenantId: executionContext.tenantId,
190
192
  projectId: executionContext.projectId,
191
- graphId: executionContext.graphId
193
+ graphId: executionContext.graphId,
194
+ agentId: executionContext.agentId
192
195
  },
193
196
  "API key authenticated successfully"
194
197
  );
@@ -7375,69 +7378,75 @@ var ExecutionHandler = class {
7375
7378
  textContent += part.text;
7376
7379
  }
7377
7380
  }
7378
- const activeSpan = trace.getActiveSpan();
7379
- if (activeSpan) {
7380
- activeSpan.setAttributes({
7381
- "ai.response.content": textContent || "No response content",
7382
- "ai.response.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7383
- "ai.agent.name": currentAgentId
7384
- });
7385
- }
7386
- await createMessage(dbClient_default)({
7387
- id: nanoid(),
7388
- tenantId,
7389
- projectId,
7390
- conversationId,
7391
- role: "agent",
7392
- content: {
7393
- text: textContent || void 0,
7394
- parts: responseParts.map((part) => ({
7395
- type: part.kind === "text" ? "text" : "data",
7396
- text: part.kind === "text" ? part.text : void 0,
7397
- data: part.kind === "data" ? JSON.stringify(part.data) : void 0
7398
- }))
7399
- },
7400
- visibility: "user-facing",
7401
- messageType: "chat",
7402
- agentId: currentAgentId,
7403
- fromAgentId: currentAgentId,
7404
- taskId: task.id
7405
- });
7406
- const updateTaskStart = Date.now();
7407
- await updateTask(dbClient_default)({
7408
- taskId: task.id,
7409
- data: {
7410
- status: "completed",
7411
- metadata: {
7412
- ...task.metadata,
7413
- completed_at: (/* @__PURE__ */ new Date()).toISOString(),
7414
- response: {
7415
- text: textContent,
7416
- parts: responseParts,
7417
- hasText: !!textContent,
7418
- hasData: responseParts.some((p) => p.kind === "data")
7381
+ return tracer.startActiveSpan("execution_handler.execute", {}, async (span) => {
7382
+ try {
7383
+ span.setAttributes({
7384
+ "ai.response.content": textContent || "No response content",
7385
+ "ai.response.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7386
+ "ai.agent.name": currentAgentId
7387
+ });
7388
+ await createMessage(dbClient_default)({
7389
+ id: nanoid(),
7390
+ tenantId,
7391
+ projectId,
7392
+ conversationId,
7393
+ role: "agent",
7394
+ content: {
7395
+ text: textContent || void 0,
7396
+ parts: responseParts.map((part) => ({
7397
+ type: part.kind === "text" ? "text" : "data",
7398
+ text: part.kind === "text" ? part.text : void 0,
7399
+ data: part.kind === "data" ? JSON.stringify(part.data) : void 0
7400
+ }))
7401
+ },
7402
+ visibility: "user-facing",
7403
+ messageType: "chat",
7404
+ agentId: currentAgentId,
7405
+ fromAgentId: currentAgentId,
7406
+ taskId: task.id
7407
+ });
7408
+ const updateTaskStart = Date.now();
7409
+ await updateTask(dbClient_default)({
7410
+ taskId: task.id,
7411
+ data: {
7412
+ status: "completed",
7413
+ metadata: {
7414
+ ...task.metadata,
7415
+ completed_at: (/* @__PURE__ */ new Date()).toISOString(),
7416
+ response: {
7417
+ text: textContent,
7418
+ parts: responseParts,
7419
+ hasText: !!textContent,
7420
+ hasData: responseParts.some((p) => p.kind === "data")
7421
+ }
7422
+ }
7419
7423
  }
7424
+ });
7425
+ const updateTaskEnd = Date.now();
7426
+ logger18.info(
7427
+ { duration: updateTaskEnd - updateTaskStart },
7428
+ "Completed updateTask operation"
7429
+ );
7430
+ await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
7431
+ await sseHelper.complete();
7432
+ logger18.info({}, "Ending GraphSession and cleaning up");
7433
+ graphSessionManager.endSession(requestId2);
7434
+ logger18.info({}, "Cleaning up streamHelper");
7435
+ unregisterStreamHelper(requestId2);
7436
+ let response;
7437
+ if (sseHelper instanceof MCPStreamHelper) {
7438
+ const captured = sseHelper.getCapturedResponse();
7439
+ response = captured.text || "No response content";
7420
7440
  }
7441
+ logger18.info({}, "ExecutionHandler returning success");
7442
+ return { success: true, iterations, response };
7443
+ } catch (error) {
7444
+ setSpanWithError(span, error);
7445
+ throw error;
7446
+ } finally {
7447
+ span.end();
7421
7448
  }
7422
7449
  });
7423
- const updateTaskEnd = Date.now();
7424
- logger18.info(
7425
- { duration: updateTaskEnd - updateTaskStart },
7426
- "Completed updateTask operation"
7427
- );
7428
- await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
7429
- await sseHelper.complete();
7430
- logger18.info({}, "Ending GraphSession and cleaning up");
7431
- graphSessionManager.endSession(requestId2);
7432
- logger18.info({}, "Cleaning up streamHelper");
7433
- unregisterStreamHelper(requestId2);
7434
- let response;
7435
- if (sseHelper instanceof MCPStreamHelper) {
7436
- const captured = sseHelper.getCapturedResponse();
7437
- response = captured.text || "No response content";
7438
- }
7439
- logger18.info({}, "ExecutionHandler returning success");
7440
- return { success: true, iterations, response };
7441
7450
  }
7442
7451
  errorCount++;
7443
7452
  logger18.warn(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20250915105321",
3
+ "version": "0.0.0-dev-20250915190940",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "traverse": "^0.6.11",
45
45
  "ts-pattern": "^5.7.1",
46
46
  "zod": "^4.1.5",
47
- "@inkeep/agents-core": "^0.0.0-dev-20250915105321"
47
+ "@inkeep/agents-core": "^0.0.0-dev-20250915190940"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@hono/vite-dev-server": "^0.20.1",