@inkeep/agents-run-api 0.0.0-dev-20250919185254 → 0.0.0-dev-20250919185941

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
@@ -14,6 +14,7 @@ var resources = require('@opentelemetry/resources');
14
14
  var sdkNode = require('@opentelemetry/sdk-node');
15
15
  var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
16
16
  var semanticConventions = require('@opentelemetry/semantic-conventions');
17
+ var otel = require('@hono/otel');
17
18
  var zodOpenapi = require('@hono/zod-openapi');
18
19
  var api = require('@opentelemetry/api');
19
20
  var hono = require('hono');
@@ -34,7 +35,6 @@ var mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
34
35
  var streamableHttp_js = require('@modelcontextprotocol/sdk/server/streamableHttp.js');
35
36
  var v3 = require('zod/v3');
36
37
  var fetchToNode = require('fetch-to-node');
37
- var otel = require('@hono/otel');
38
38
 
39
39
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
40
40
 
@@ -6962,7 +6962,10 @@ app.openapi(
6962
6962
  const agent = await getRegisteredAgent(executionContext, credentialStores);
6963
6963
  logger17.info({ agent }, "agent registered: well-known agent.json");
6964
6964
  if (!agent) {
6965
- return c.json({ error: "Agent not found" }, 404);
6965
+ throw agentsCore.createApiError({
6966
+ code: "not_found",
6967
+ message: "Agent not found"
6968
+ });
6966
6969
  }
6967
6970
  return c.json(agent.agentCard);
6968
6971
  } else {
@@ -6977,7 +6980,10 @@ app.openapi(
6977
6980
  );
6978
6981
  const graph = await getRegisteredGraph(executionContext);
6979
6982
  if (!graph) {
6980
- return c.json({ error: "Graph not found" }, 404);
6983
+ throw agentsCore.createApiError({
6984
+ code: "not_found",
6985
+ message: "Graph not found"
6986
+ });
6981
6987
  }
6982
6988
  return c.json(graph.agentCard);
6983
6989
  }
@@ -8216,12 +8222,18 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8216
8222
  scopes: { tenantId, projectId, graphId }
8217
8223
  });
8218
8224
  if (!agentGraph) {
8219
- return c.json({ error: "Agent graph not found" }, 404);
8225
+ throw agentsCore.createApiError({
8226
+ code: "not_found",
8227
+ message: "Agent graph not found"
8228
+ });
8220
8229
  }
8221
8230
  defaultAgentId = agentGraph.defaultAgentId || "";
8222
8231
  }
8223
8232
  if (!defaultAgentId) {
8224
- return c.json({ error: "No default agent found in graph" }, 404);
8233
+ throw agentsCore.createApiError({
8234
+ code: "not_found",
8235
+ message: "No default agent found in graph"
8236
+ });
8225
8237
  }
8226
8238
  await agentsCore.createOrGetConversation(dbClient_default)({
8227
8239
  tenantId,
@@ -8246,7 +8258,10 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8246
8258
  agentId
8247
8259
  });
8248
8260
  if (!agentInfo) {
8249
- return c.json({ error: "Agent not found" }, 404);
8261
+ throw agentsCore.createApiError({
8262
+ code: "not_found",
8263
+ message: "Agent not found"
8264
+ });
8250
8265
  }
8251
8266
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8252
8267
  const credentialStores = c.get("credentialStores");
@@ -8304,41 +8319,69 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8304
8319
  });
8305
8320
  }
8306
8321
  return streaming.streamSSE(c, async (stream2) => {
8307
- const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8308
- await sseHelper.writeRole();
8309
- logger20.info({ agentId }, "Starting execution");
8310
- const executionHandler = new ExecutionHandler();
8311
- const result = await executionHandler.execute({
8312
- executionContext,
8313
- conversationId,
8314
- userMessage,
8315
- initialAgentId: agentId,
8316
- requestId: requestId2,
8317
- sseHelper
8318
- });
8319
- logger20.info(
8320
- { result },
8321
- `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
8322
- );
8323
- if (!result.success) {
8324
- await sseHelper.writeOperation(
8325
- errorOp("Sorry, I was unable to process your request at this time. Please try again.", "system")
8322
+ try {
8323
+ const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8324
+ await sseHelper.writeRole();
8325
+ logger20.info({ agentId }, "Starting execution");
8326
+ const executionHandler = new ExecutionHandler();
8327
+ const result = await executionHandler.execute({
8328
+ executionContext,
8329
+ conversationId,
8330
+ userMessage,
8331
+ initialAgentId: agentId,
8332
+ requestId: requestId2,
8333
+ sseHelper
8334
+ });
8335
+ logger20.info(
8336
+ { result },
8337
+ `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
8338
+ );
8339
+ if (!result.success) {
8340
+ await sseHelper.writeOperation(
8341
+ errorOp(
8342
+ "Sorry, I was unable to process your request at this time. Please try again.",
8343
+ "system"
8344
+ )
8345
+ );
8346
+ }
8347
+ await sseHelper.complete();
8348
+ } catch (error) {
8349
+ logger20.error(
8350
+ {
8351
+ error: error instanceof Error ? error.message : error,
8352
+ stack: error instanceof Error ? error.stack : void 0
8353
+ },
8354
+ "Error during streaming execution"
8326
8355
  );
8356
+ try {
8357
+ const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8358
+ await sseHelper.writeOperation(
8359
+ errorOp(
8360
+ "Sorry, I was unable to process your request at this time. Please try again.",
8361
+ "system"
8362
+ )
8363
+ );
8364
+ await sseHelper.complete();
8365
+ } catch (streamError) {
8366
+ logger20.error({ streamError }, "Failed to write error to stream");
8367
+ }
8327
8368
  }
8328
- await sseHelper.complete();
8329
8369
  });
8330
8370
  } catch (error) {
8331
- console.error("\u274C Error in chat completions endpoint:", {
8332
- error: error instanceof Error ? error.message : error,
8333
- stack: error instanceof Error ? error.stack : void 0
8334
- });
8335
- return c.json(
8371
+ logger20.error(
8336
8372
  {
8337
- error: "Failed to process chat completion",
8338
- message: error instanceof Error ? error.message : "Unknown error"
8373
+ error: error instanceof Error ? error.message : error,
8374
+ stack: error instanceof Error ? error.stack : void 0
8339
8375
  },
8340
- 500
8376
+ "Error in chat completions endpoint before streaming"
8341
8377
  );
8378
+ if (error && typeof error === "object" && "status" in error) {
8379
+ throw error;
8380
+ }
8381
+ throw agentsCore.createApiError({
8382
+ code: "internal_server_error",
8383
+ message: error instanceof Error ? error.message : "Failed to process chat completion"
8384
+ });
8342
8385
  }
8343
8386
  });
8344
8387
  var getMessageText = (content) => {
@@ -8421,12 +8464,18 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8421
8464
  scopes: { tenantId, projectId, graphId }
8422
8465
  });
8423
8466
  if (!agentGraph) {
8424
- return c.json({ error: "Agent graph not found" }, 404);
8467
+ throw agentsCore.createApiError({
8468
+ code: "not_found",
8469
+ message: "Agent graph not found"
8470
+ });
8425
8471
  }
8426
8472
  const defaultAgentId = agentGraph.defaultAgentId;
8427
8473
  const graphName = agentGraph.name;
8428
8474
  if (!defaultAgentId) {
8429
- return c.json({ error: "Graph does not have a default agent configured" }, 400);
8475
+ throw agentsCore.createApiError({
8476
+ code: "bad_request",
8477
+ message: "Graph does not have a default agent configured"
8478
+ });
8430
8479
  }
8431
8480
  const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
8432
8481
  scopes: { tenantId, projectId },
@@ -8445,7 +8494,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8445
8494
  agentId
8446
8495
  });
8447
8496
  if (!agentInfo) {
8448
- return c.json({ error: "Agent not found" }, 404);
8497
+ throw agentsCore.createApiError({
8498
+ code: "not_found",
8499
+ message: "Agent not found"
8500
+ });
8449
8501
  }
8450
8502
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8451
8503
  const credentialStores = c.get("credentialStores");
@@ -8524,7 +8576,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8524
8576
  );
8525
8577
  } catch (error) {
8526
8578
  logger21.error({ error }, "chatDataStream error");
8527
- return c.json({ error: "Failed to process chat completion" }, 500);
8579
+ throw agentsCore.createApiError({
8580
+ code: "internal_server_error",
8581
+ message: "Failed to process chat completion"
8582
+ });
8528
8583
  }
8529
8584
  });
8530
8585
  var chatDataStream_default = app3;
@@ -9068,6 +9123,8 @@ app4.delete("/", async (c) => {
9068
9123
  );
9069
9124
  });
9070
9125
  var mcp_default = app4;
9126
+
9127
+ // src/app.ts
9071
9128
  var logger23 = agentsCore.getLogger("agents-run-api");
9072
9129
  function createExecutionHono(serverConfig, credentialStores) {
9073
9130
  const app6 = new zodOpenapi.OpenAPIHono();
package/dist/index.js CHANGED
@@ -8,7 +8,8 @@ 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, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraphById, 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';
11
+ import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraphById, 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
+ import { otel } from '@hono/otel';
12
13
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
13
14
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
14
15
  import { Hono } from 'hono';
@@ -31,7 +32,6 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
31
32
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
32
33
  import { z as z$2 } from 'zod/v3';
33
34
  import { toReqRes, toFetchResponse } from 'fetch-to-node';
34
- import { otel } from '@hono/otel';
35
35
 
36
36
  var maxExportBatchSize = env.OTEL_MAX_EXPORT_BATCH_SIZE ?? (env.ENVIRONMENT === "development" ? 1 : 512);
37
37
  var otlpExporter = new OTLPTraceExporter();
@@ -6680,7 +6680,10 @@ app.openapi(
6680
6680
  const agent = await getRegisteredAgent(executionContext, credentialStores);
6681
6681
  logger17.info({ agent }, "agent registered: well-known agent.json");
6682
6682
  if (!agent) {
6683
- return c.json({ error: "Agent not found" }, 404);
6683
+ throw createApiError({
6684
+ code: "not_found",
6685
+ message: "Agent not found"
6686
+ });
6684
6687
  }
6685
6688
  return c.json(agent.agentCard);
6686
6689
  } else {
@@ -6695,7 +6698,10 @@ app.openapi(
6695
6698
  );
6696
6699
  const graph = await getRegisteredGraph(executionContext);
6697
6700
  if (!graph) {
6698
- return c.json({ error: "Graph not found" }, 404);
6701
+ throw createApiError({
6702
+ code: "not_found",
6703
+ message: "Graph not found"
6704
+ });
6699
6705
  }
6700
6706
  return c.json(graph.agentCard);
6701
6707
  }
@@ -7925,12 +7931,18 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7925
7931
  scopes: { tenantId, projectId, graphId }
7926
7932
  });
7927
7933
  if (!agentGraph) {
7928
- return c.json({ error: "Agent graph not found" }, 404);
7934
+ throw createApiError({
7935
+ code: "not_found",
7936
+ message: "Agent graph not found"
7937
+ });
7929
7938
  }
7930
7939
  defaultAgentId = agentGraph.defaultAgentId || "";
7931
7940
  }
7932
7941
  if (!defaultAgentId) {
7933
- return c.json({ error: "No default agent found in graph" }, 404);
7942
+ throw createApiError({
7943
+ code: "not_found",
7944
+ message: "No default agent found in graph"
7945
+ });
7934
7946
  }
7935
7947
  await createOrGetConversation(dbClient_default)({
7936
7948
  tenantId,
@@ -7955,7 +7967,10 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7955
7967
  agentId
7956
7968
  });
7957
7969
  if (!agentInfo) {
7958
- return c.json({ error: "Agent not found" }, 404);
7970
+ throw createApiError({
7971
+ code: "not_found",
7972
+ message: "Agent not found"
7973
+ });
7959
7974
  }
7960
7975
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
7961
7976
  const credentialStores = c.get("credentialStores");
@@ -8013,41 +8028,69 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8013
8028
  });
8014
8029
  }
8015
8030
  return streamSSE(c, async (stream2) => {
8016
- const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8017
- await sseHelper.writeRole();
8018
- logger20.info({ agentId }, "Starting execution");
8019
- const executionHandler = new ExecutionHandler();
8020
- const result = await executionHandler.execute({
8021
- executionContext,
8022
- conversationId,
8023
- userMessage,
8024
- initialAgentId: agentId,
8025
- requestId: requestId2,
8026
- sseHelper
8027
- });
8028
- logger20.info(
8029
- { result },
8030
- `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
8031
- );
8032
- if (!result.success) {
8033
- await sseHelper.writeOperation(
8034
- errorOp("Sorry, I was unable to process your request at this time. Please try again.", "system")
8031
+ try {
8032
+ const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8033
+ await sseHelper.writeRole();
8034
+ logger20.info({ agentId }, "Starting execution");
8035
+ const executionHandler = new ExecutionHandler();
8036
+ const result = await executionHandler.execute({
8037
+ executionContext,
8038
+ conversationId,
8039
+ userMessage,
8040
+ initialAgentId: agentId,
8041
+ requestId: requestId2,
8042
+ sseHelper
8043
+ });
8044
+ logger20.info(
8045
+ { result },
8046
+ `Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
8047
+ );
8048
+ if (!result.success) {
8049
+ await sseHelper.writeOperation(
8050
+ errorOp(
8051
+ "Sorry, I was unable to process your request at this time. Please try again.",
8052
+ "system"
8053
+ )
8054
+ );
8055
+ }
8056
+ await sseHelper.complete();
8057
+ } catch (error) {
8058
+ logger20.error(
8059
+ {
8060
+ error: error instanceof Error ? error.message : error,
8061
+ stack: error instanceof Error ? error.stack : void 0
8062
+ },
8063
+ "Error during streaming execution"
8035
8064
  );
8065
+ try {
8066
+ const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
8067
+ await sseHelper.writeOperation(
8068
+ errorOp(
8069
+ "Sorry, I was unable to process your request at this time. Please try again.",
8070
+ "system"
8071
+ )
8072
+ );
8073
+ await sseHelper.complete();
8074
+ } catch (streamError) {
8075
+ logger20.error({ streamError }, "Failed to write error to stream");
8076
+ }
8036
8077
  }
8037
- await sseHelper.complete();
8038
8078
  });
8039
8079
  } catch (error) {
8040
- console.error("\u274C Error in chat completions endpoint:", {
8041
- error: error instanceof Error ? error.message : error,
8042
- stack: error instanceof Error ? error.stack : void 0
8043
- });
8044
- return c.json(
8080
+ logger20.error(
8045
8081
  {
8046
- error: "Failed to process chat completion",
8047
- message: error instanceof Error ? error.message : "Unknown error"
8082
+ error: error instanceof Error ? error.message : error,
8083
+ stack: error instanceof Error ? error.stack : void 0
8048
8084
  },
8049
- 500
8085
+ "Error in chat completions endpoint before streaming"
8050
8086
  );
8087
+ if (error && typeof error === "object" && "status" in error) {
8088
+ throw error;
8089
+ }
8090
+ throw createApiError({
8091
+ code: "internal_server_error",
8092
+ message: error instanceof Error ? error.message : "Failed to process chat completion"
8093
+ });
8051
8094
  }
8052
8095
  });
8053
8096
  var getMessageText = (content) => {
@@ -8127,12 +8170,18 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8127
8170
  scopes: { tenantId, projectId, graphId }
8128
8171
  });
8129
8172
  if (!agentGraph) {
8130
- return c.json({ error: "Agent graph not found" }, 404);
8173
+ throw createApiError({
8174
+ code: "not_found",
8175
+ message: "Agent graph not found"
8176
+ });
8131
8177
  }
8132
8178
  const defaultAgentId = agentGraph.defaultAgentId;
8133
8179
  const graphName = agentGraph.name;
8134
8180
  if (!defaultAgentId) {
8135
- return c.json({ error: "Graph does not have a default agent configured" }, 400);
8181
+ throw createApiError({
8182
+ code: "bad_request",
8183
+ message: "Graph does not have a default agent configured"
8184
+ });
8136
8185
  }
8137
8186
  const activeAgent = await getActiveAgentForConversation(dbClient_default)({
8138
8187
  scopes: { tenantId, projectId },
@@ -8151,7 +8200,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8151
8200
  agentId
8152
8201
  });
8153
8202
  if (!agentInfo) {
8154
- return c.json({ error: "Agent not found" }, 404);
8203
+ throw createApiError({
8204
+ code: "not_found",
8205
+ message: "Agent not found"
8206
+ });
8155
8207
  }
8156
8208
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8157
8209
  const credentialStores = c.get("credentialStores");
@@ -8230,7 +8282,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8230
8282
  );
8231
8283
  } catch (error) {
8232
8284
  logger21.error({ error }, "chatDataStream error");
8233
- return c.json({ error: "Failed to process chat completion" }, 500);
8285
+ throw createApiError({
8286
+ code: "internal_server_error",
8287
+ message: "Failed to process chat completion"
8288
+ });
8234
8289
  }
8235
8290
  });
8236
8291
  var chatDataStream_default = app3;
@@ -8771,6 +8826,8 @@ app4.delete("/", async (c) => {
8771
8826
  );
8772
8827
  });
8773
8828
  var mcp_default = app4;
8829
+
8830
+ // src/app.ts
8774
8831
  var logger23 = getLogger("agents-run-api");
8775
8832
  function createExecutionHono(serverConfig, credentialStores) {
8776
8833
  const app6 = new OpenAPIHono();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20250919185254",
3
+ "version": "0.0.0-dev-20250919185941",
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",
@@ -45,7 +45,7 @@
45
45
  "traverse": "^0.6.11",
46
46
  "ts-pattern": "^5.7.1",
47
47
  "zod": "^4.1.5",
48
- "@inkeep/agents-core": "^0.0.0-dev-20250919185254"
48
+ "@inkeep/agents-core": "^0.0.0-dev-20250919185941"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@hono/vite-dev-server": "^0.20.1",