@inkeep/agents-run-api 0.37.1 → 0.37.2

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.
@@ -1,5 +1,5 @@
1
1
  import { getLogger } from './chunk-A2S7GSHL.js';
2
- import { FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS } from './chunk-IVALDC72.js';
2
+ import { FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS } from './chunk-SUUSOBLI.js';
3
3
  import { spawn } from 'child_process';
4
4
  import crypto, { createHash } from 'crypto';
5
5
  import { mkdirSync, existsSync, rmSync, writeFileSync } from 'fs';
@@ -1,5 +1,5 @@
1
- import { dbClient_default } from './chunk-V4RNZ6BX.js';
2
- import { CONVERSATION_HISTORY_DEFAULT_LIMIT } from './chunk-IVALDC72.js';
1
+ import { dbClient_default } from './chunk-W6UIBREL.js';
2
+ import { CONVERSATION_HISTORY_DEFAULT_LIMIT } from './chunk-SUUSOBLI.js';
3
3
  import { CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, createMessage, generateId, getConversationHistory } from '@inkeep/agents-core';
4
4
 
5
5
  function createDefaultConversationHistoryConfig(mode = "full") {
@@ -208,7 +208,7 @@ async function getConversationScopedArtifacts(params) {
208
208
  return [];
209
209
  }
210
210
  const { getLedgerArtifacts } = await import('@inkeep/agents-core');
211
- const dbClient = (await import('./dbClient-BXOIYVCJ.js')).default;
211
+ const dbClient = (await import('./dbClient-47AP7OHJ.js')).default;
212
212
  const visibleTaskIds = visibleMessages.map((msg) => msg.taskId).filter((taskId) => Boolean(taskId));
213
213
  const referenceArtifacts = [];
214
214
  for (const taskId of visibleTaskIds) {
@@ -1,5 +1,5 @@
1
1
  import { loadEnvironmentFiles } from '@inkeep/agents-core';
2
- import { z } from 'zod';
2
+ import { z } from '@hono/zod-openapi';
3
3
 
4
4
  // src/env.ts
5
5
  loadEnvironmentFiles();
@@ -1,4 +1,4 @@
1
- import { env } from './chunk-IYG4HUQ6.js';
1
+ import { env } from './chunk-CDYXP4BN.js';
2
2
  import { getLogger } from './chunk-A2S7GSHL.js';
3
3
  import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
4
4
  import { BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS } from '@opentelemetry/baggage-span-processor';
@@ -1,5 +1,5 @@
1
1
  import { loadEnvironmentFiles } from '@inkeep/agents-core';
2
- import { z } from 'zod';
2
+ import { z } from '@hono/zod-openapi';
3
3
 
4
4
  // src/constants/execution-limits/index.ts
5
5
 
@@ -1,4 +1,4 @@
1
- import { env } from './chunk-IYG4HUQ6.js';
1
+ import { env } from './chunk-CDYXP4BN.js';
2
2
  import { F, u, R, x, T, h, U, L, or, C, Vr, ce, ur, P } from './chunk-SBJLXGYG.js';
3
3
  import { createDatabaseClient } from '@inkeep/agents-core';
4
4
  import * as schema from '@inkeep/agents-core/db/schema';
@@ -1 +1 @@
1
- export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-M46DFVYB.js';
1
+ export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-BQB27EXW.js';
@@ -0,0 +1 @@
1
+ export { dbClient_default as default } from './chunk-W6UIBREL.js';
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var agentsCore = require('@inkeep/agents-core');
6
- var z8 = require('zod');
6
+ var zodOpenapi = require('@hono/zod-openapi');
7
7
  var s3 = require('fs');
8
8
  var o3 = require('path');
9
9
  var schema = require('@inkeep/agents-core/db/schema');
@@ -13,7 +13,6 @@ var crypto2 = require('crypto');
13
13
  var os = require('os');
14
14
  var sandbox = require('@vercel/sandbox');
15
15
  var otel = require('@hono/otel');
16
- var zodOpenapi = require('@hono/zod-openapi');
17
16
  var api = require('@opentelemetry/api');
18
17
  var hono = require('hono');
19
18
  var cors = require('hono/cors');
@@ -61,7 +60,6 @@ function _interopNamespace(e) {
61
60
  return Object.freeze(n);
62
61
  }
63
62
 
64
- var z8__default = /*#__PURE__*/_interopDefault(z8);
65
63
  var s3__namespace = /*#__PURE__*/_interopNamespace(s3);
66
64
  var o3__namespace = /*#__PURE__*/_interopNamespace(o3);
67
65
  var schema__namespace = /*#__PURE__*/_interopNamespace(schema);
@@ -84,29 +82,29 @@ var envSchema, parseEnv, env;
84
82
  var init_env = __esm({
85
83
  "src/env.ts"() {
86
84
  agentsCore.loadEnvironmentFiles();
87
- envSchema = z8.z.object({
88
- NODE_ENV: z8.z.enum(["development", "production", "test"]).optional(),
89
- ENVIRONMENT: z8.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
90
- DATABASE_URL: z8.z.string().optional(),
91
- INKEEP_AGENTS_RUN_API_URL: z8.z.string().optional().default("http://localhost:3003"),
92
- AGENTS_MANAGE_UI_URL: z8.z.string().optional().default("http://localhost:3000"),
93
- LOG_LEVEL: z8.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
94
- NANGO_SERVER_URL: z8.z.string().optional().default("https://api.nango.dev"),
95
- NANGO_SECRET_KEY: z8.z.string().optional(),
96
- ANTHROPIC_API_KEY: z8.z.string(),
97
- OPENAI_API_KEY: z8.z.string().optional(),
98
- GOOGLE_GENERATIVE_AI_API_KEY: z8.z.string().optional(),
99
- INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z8.z.string().optional(),
100
- INKEEP_AGENTS_JWT_SIGNING_SECRET: z8.z.string().optional(),
101
- INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: z8.z.string().optional(),
102
- OTEL_BSP_SCHEDULE_DELAY: z8.z.coerce.number().optional().default(500),
103
- OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z8.z.coerce.number().optional().default(64)
85
+ envSchema = zodOpenapi.z.object({
86
+ NODE_ENV: zodOpenapi.z.enum(["development", "production", "test"]).optional(),
87
+ ENVIRONMENT: zodOpenapi.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
88
+ DATABASE_URL: zodOpenapi.z.string().optional(),
89
+ INKEEP_AGENTS_RUN_API_URL: zodOpenapi.z.string().optional().default("http://localhost:3003"),
90
+ AGENTS_MANAGE_UI_URL: zodOpenapi.z.string().optional().default("http://localhost:3000"),
91
+ LOG_LEVEL: zodOpenapi.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
92
+ NANGO_SERVER_URL: zodOpenapi.z.string().optional().default("https://api.nango.dev"),
93
+ NANGO_SECRET_KEY: zodOpenapi.z.string().optional(),
94
+ ANTHROPIC_API_KEY: zodOpenapi.z.string(),
95
+ OPENAI_API_KEY: zodOpenapi.z.string().optional(),
96
+ GOOGLE_GENERATIVE_AI_API_KEY: zodOpenapi.z.string().optional(),
97
+ INKEEP_AGENTS_RUN_API_BYPASS_SECRET: zodOpenapi.z.string().optional(),
98
+ INKEEP_AGENTS_JWT_SIGNING_SECRET: zodOpenapi.z.string().optional(),
99
+ INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: zodOpenapi.z.string().optional(),
100
+ OTEL_BSP_SCHEDULE_DELAY: zodOpenapi.z.coerce.number().optional().default(500),
101
+ OTEL_BSP_MAX_EXPORT_BATCH_SIZE: zodOpenapi.z.coerce.number().optional().default(64)
104
102
  });
105
103
  parseEnv = () => {
106
104
  try {
107
105
  return envSchema.parse(process.env);
108
106
  } catch (error) {
109
- if (error instanceof z8.z.ZodError) {
107
+ if (error instanceof zodOpenapi.z.ZodError) {
110
108
  const missingVars = error.issues.map((issue) => issue.path.join("."));
111
109
  throw new Error(
112
110
  `\u274C Invalid environment variables: ${missingVars.join(", ")}
@@ -6244,11 +6242,11 @@ var init_execution_limits = __esm({
6244
6242
  init_defaults();
6245
6243
  init_defaults();
6246
6244
  agentsCore.loadEnvironmentFiles();
6247
- constantsSchema = z8.z.object(
6245
+ constantsSchema = zodOpenapi.z.object(
6248
6246
  Object.fromEntries(
6249
6247
  Object.keys(executionLimitsDefaults).map((key) => [
6250
6248
  `AGENTS_${key}`,
6251
- z8.z.coerce.number().optional()
6249
+ zodOpenapi.z.coerce.number().optional()
6252
6250
  ])
6253
6251
  )
6254
6252
  );
@@ -8232,6 +8230,21 @@ async function handleMessageSend(c2, agent, request) {
8232
8230
  });
8233
8231
  }
8234
8232
  }
8233
+ if (result.status.state === agentsCore.TaskState.Failed) {
8234
+ const isConnectionRefused = result.status.type === "connection_refused";
8235
+ if (isConnectionRefused) {
8236
+ return c2.json({
8237
+ jsonrpc: "2.0",
8238
+ error: {
8239
+ code: -32603,
8240
+ message: result.status.message || "Agent execution failed",
8241
+ data: {
8242
+ type: "connection_refused"
8243
+ }
8244
+ }
8245
+ });
8246
+ }
8247
+ }
8235
8248
  const taskStatus = {
8236
8249
  state: result.status.state,
8237
8250
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -10518,12 +10531,12 @@ ${conversationHistory}
10518
10531
  Previous updates sent to user:
10519
10532
  ${previousSummaries.map((s4, i3) => `${i3 + 1}. ${s4}`).join("\n")}
10520
10533
  ` : "";
10521
- const selectionSchema = z8.z.object(
10534
+ const selectionSchema = zodOpenapi.z.object(
10522
10535
  Object.fromEntries([
10523
10536
  [
10524
10537
  "no_relevant_updates",
10525
- z8.z.object({
10526
- no_updates: z8.z.boolean().default(true)
10538
+ zodOpenapi.z.object({
10539
+ no_updates: zodOpenapi.z.boolean().default(true)
10527
10540
  }).optional().describe(
10528
10541
  "Use when nothing substantially new to report. Should only use on its own."
10529
10542
  )
@@ -10657,8 +10670,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
10657
10670
  if (component.detailsSchema && "properties" in component.detailsSchema) {
10658
10671
  return this.buildZodSchemaFromJson(component.detailsSchema);
10659
10672
  }
10660
- return z8.z.object({
10661
- label: z8.z.string().describe(
10673
+ return zodOpenapi.z.object({
10674
+ label: zodOpenapi.z.string().describe(
10662
10675
  '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 ACTUAL finding or result, not the action. What specific information was discovered? (e.g., "Slack requires OAuth 2.0 setup", "Found 5 integration methods", "API rate limit is 100/minute"). Include the actual detail or insight, not just that you searched or processed. 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.'
10663
10676
  )
10664
10677
  });
@@ -10668,56 +10681,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
10668
10681
  */
10669
10682
  buildZodSchemaFromJson(jsonSchema) {
10670
10683
  const properties = {};
10671
- properties.label = z8.z.string().describe(
10684
+ properties.label = zodOpenapi.z.string().describe(
10672
10685
  '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.'
10673
10686
  );
10674
10687
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
10675
10688
  let zodType;
10676
10689
  if (value.enum && Array.isArray(value.enum)) {
10677
10690
  if (value.enum.length === 1) {
10678
- zodType = z8.z.literal(value.enum[0]);
10691
+ zodType = zodOpenapi.z.literal(value.enum[0]);
10679
10692
  } else {
10680
10693
  const [first, ...rest] = value.enum;
10681
- zodType = z8.z.enum([first, ...rest]);
10694
+ zodType = zodOpenapi.z.enum([first, ...rest]);
10682
10695
  }
10683
10696
  } else if (value.type === "string") {
10684
- zodType = z8.z.string();
10697
+ zodType = zodOpenapi.z.string();
10685
10698
  if (value.minLength) zodType = zodType.min(value.minLength);
10686
10699
  if (value.maxLength) zodType = zodType.max(value.maxLength);
10687
10700
  if (value.format === "email") zodType = zodType.email();
10688
10701
  if (value.format === "url" || value.format === "uri")
10689
10702
  zodType = zodType.url();
10690
10703
  } else if (value.type === "number" || value.type === "integer") {
10691
- zodType = value.type === "integer" ? z8.z.number().int() : z8.z.number();
10704
+ zodType = value.type === "integer" ? zodOpenapi.z.number().int() : zodOpenapi.z.number();
10692
10705
  if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
10693
10706
  if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
10694
10707
  } else if (value.type === "boolean") {
10695
- zodType = z8.z.boolean();
10708
+ zodType = zodOpenapi.z.boolean();
10696
10709
  } else if (value.type === "array") {
10697
10710
  if (value.items) {
10698
10711
  if (value.items.enum && Array.isArray(value.items.enum)) {
10699
10712
  const [first, ...rest] = value.items.enum;
10700
- zodType = z8.z.array(z8.z.enum([first, ...rest]));
10713
+ zodType = zodOpenapi.z.array(zodOpenapi.z.enum([first, ...rest]));
10701
10714
  } else if (value.items.type === "string") {
10702
- zodType = z8.z.array(z8.z.string());
10715
+ zodType = zodOpenapi.z.array(zodOpenapi.z.string());
10703
10716
  } else if (value.items.type === "number") {
10704
- zodType = z8.z.array(z8.z.number());
10717
+ zodType = zodOpenapi.z.array(zodOpenapi.z.number());
10705
10718
  } else if (value.items.type === "boolean") {
10706
- zodType = z8.z.array(z8.z.boolean());
10719
+ zodType = zodOpenapi.z.array(zodOpenapi.z.boolean());
10707
10720
  } else if (value.items.type === "object") {
10708
- zodType = z8.z.array(z8.z.record(z8.z.string(), z8.z.any()));
10721
+ zodType = zodOpenapi.z.array(zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.any()));
10709
10722
  } else {
10710
- zodType = z8.z.array(z8.z.any());
10723
+ zodType = zodOpenapi.z.array(zodOpenapi.z.any());
10711
10724
  }
10712
10725
  } else {
10713
- zodType = z8.z.array(z8.z.any());
10726
+ zodType = zodOpenapi.z.array(zodOpenapi.z.any());
10714
10727
  }
10715
10728
  if (value.minItems) zodType = zodType.min(value.minItems);
10716
10729
  if (value.maxItems) zodType = zodType.max(value.maxItems);
10717
10730
  } else if (value.type === "object") {
10718
- zodType = z8.z.record(z8.z.string(), z8.z.any());
10731
+ zodType = zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.any());
10719
10732
  } else {
10720
- zodType = z8.z.any();
10733
+ zodType = zodOpenapi.z.any();
10721
10734
  }
10722
10735
  if (value.description) {
10723
10736
  zodType = zodType.describe(value.description);
@@ -10727,7 +10740,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
10727
10740
  }
10728
10741
  properties[key] = zodType;
10729
10742
  }
10730
- return z8.z.object(properties);
10743
+ return zodOpenapi.z.object(properties);
10731
10744
  }
10732
10745
  /**
10733
10746
  * Extract user-visible activities with rich formatting and complete information
@@ -10958,9 +10971,9 @@ Make it specific and relevant.`;
10958
10971
  };
10959
10972
  } else {
10960
10973
  const model = agentsCore.ModelFactory.createModel(modelToUse);
10961
- const schema2 = z8.z.object({
10962
- name: z8.z.string().describe("Concise, descriptive name for the artifact"),
10963
- description: z8.z.string().describe("Brief description of the artifact's relevance to the user's question")
10974
+ const schema2 = zodOpenapi.z.object({
10975
+ name: zodOpenapi.z.string().describe("Concise, descriptive name for the artifact"),
10976
+ description: zodOpenapi.z.string().describe("Brief description of the artifact's relevance to the user's question")
10964
10977
  });
10965
10978
  const { object } = await tracer.startActiveSpan(
10966
10979
  "agent_session.generate_artifact_metadata",
@@ -12096,7 +12109,7 @@ var logger12 = agentsCore.getLogger("DataComponentSchema");
12096
12109
  function jsonSchemaToZod(jsonSchema) {
12097
12110
  if (!jsonSchema || typeof jsonSchema !== "object") {
12098
12111
  logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
12099
- return z8.z.string();
12112
+ return zodOpenapi.z.string();
12100
12113
  }
12101
12114
  switch (jsonSchema.type) {
12102
12115
  case "object":
@@ -12105,22 +12118,22 @@ function jsonSchemaToZod(jsonSchema) {
12105
12118
  for (const [key, prop] of Object.entries(jsonSchema.properties)) {
12106
12119
  shape[key] = jsonSchemaToZod(prop);
12107
12120
  }
12108
- return z8.z.object(shape);
12121
+ return zodOpenapi.z.object(shape);
12109
12122
  }
12110
- return z8.z.record(z8.z.string(), z8.z.unknown());
12123
+ return zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown());
12111
12124
  case "array": {
12112
- const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z8.z.unknown();
12113
- return z8.z.array(itemSchema);
12125
+ const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : zodOpenapi.z.unknown();
12126
+ return zodOpenapi.z.array(itemSchema);
12114
12127
  }
12115
12128
  case "string":
12116
- return z8.z.string();
12129
+ return zodOpenapi.z.string();
12117
12130
  case "number":
12118
12131
  case "integer":
12119
- return z8.z.number();
12132
+ return zodOpenapi.z.number();
12120
12133
  case "boolean":
12121
- return z8.z.boolean();
12134
+ return zodOpenapi.z.boolean();
12122
12135
  case "null":
12123
- return z8.z.null();
12136
+ return zodOpenapi.z.null();
12124
12137
  default:
12125
12138
  logger12.warn(
12126
12139
  {
@@ -12129,7 +12142,7 @@ function jsonSchemaToZod(jsonSchema) {
12129
12142
  },
12130
12143
  "Unsupported JSON schema type, using unknown validation"
12131
12144
  );
12132
- return z8.z.unknown();
12145
+ return zodOpenapi.z.unknown();
12133
12146
  }
12134
12147
  }
12135
12148
 
@@ -12376,9 +12389,9 @@ var ArtifactReferenceSchema = class _ArtifactReferenceSchema {
12376
12389
  * Get the standard Zod schema for artifact reference components
12377
12390
  */
12378
12391
  static getSchema() {
12379
- return z8.z.object({
12380
- id: z8.z.string(),
12381
- name: z8.z.literal("Artifact"),
12392
+ return zodOpenapi.z.object({
12393
+ id: zodOpenapi.z.string(),
12394
+ name: zodOpenapi.z.literal("Artifact"),
12382
12395
  props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
12383
12396
  });
12384
12397
  }
@@ -12429,9 +12442,9 @@ var ArtifactCreateSchema = class {
12429
12442
  },
12430
12443
  required: ["id", "tool_call_id", "type", "base_selector"]
12431
12444
  };
12432
- return z8.z.object({
12433
- id: z8.z.string(),
12434
- name: z8.z.literal(`ArtifactCreate_${component.name}`),
12445
+ return zodOpenapi.z.object({
12446
+ id: zodOpenapi.z.string(),
12447
+ name: zodOpenapi.z.literal(`ArtifactCreate_${component.name}`),
12435
12448
  props: jsonSchemaToZod(propsSchema)
12436
12449
  });
12437
12450
  });
@@ -12503,13 +12516,14 @@ var DEFAULT_BACKOFF = {
12503
12516
  var DEFAULT_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
12504
12517
  var PermanentError = class _PermanentError extends Error {
12505
12518
  cause;
12519
+ type;
12506
12520
  constructor(message, options) {
12507
12521
  let msg = message;
12508
12522
  if (options?.cause) {
12509
12523
  msg += `: ${options.cause}`;
12510
12524
  }
12511
12525
  super(msg, options);
12512
- this.name = "PermanentError";
12526
+ this.name = options?.type || "PermanentError";
12513
12527
  if (typeof this.cause === "undefined") {
12514
12528
  this.cause = options?.cause;
12515
12529
  }
@@ -12818,6 +12832,12 @@ var A2AClient = class {
12818
12832
  }
12819
12833
  }
12820
12834
  const rpcResponse = await httpResponse.json();
12835
+ if (rpcResponse.error?.data?.type === "connection_refused") {
12836
+ throw new PermanentError(rpcResponse.error.message, {
12837
+ cause: new Error(rpcResponse.error.message),
12838
+ type: "connection_refused"
12839
+ });
12840
+ }
12821
12841
  if (rpcResponse.id !== requestId2) {
12822
12842
  logger13.warn(
12823
12843
  {
@@ -13209,7 +13229,7 @@ var createTransferToAgentTool = ({
13209
13229
  const toolDescription = generateTransferToolDescription(transferConfig);
13210
13230
  return ai.tool({
13211
13231
  description: toolDescription,
13212
- inputSchema: z8__default.default.object({}),
13232
+ inputSchema: zodOpenapi.z.object({}),
13213
13233
  execute: async () => {
13214
13234
  const activeSpan = api.trace.getActiveSpan();
13215
13235
  if (activeSpan) {
@@ -13264,7 +13284,7 @@ function createDelegateToAgentTool({
13264
13284
  }) {
13265
13285
  return ai.tool({
13266
13286
  description: generateDelegateToolDescription(delegateConfig),
13267
- inputSchema: z8__default.default.object({ message: z8__default.default.string() }),
13287
+ inputSchema: zodOpenapi.z.object({ message: zodOpenapi.z.string() }),
13268
13288
  execute: async (input, context) => {
13269
13289
  const delegationId = `del_${agentsCore.generateId()}`;
13270
13290
  const activeSpan = api.trace.getActiveSpan();
@@ -15624,9 +15644,9 @@ var Agent = class {
15624
15644
  getArtifactTools() {
15625
15645
  return ai.tool({
15626
15646
  description: "Call this tool to get the complete artifact data with the given artifactId. This retrieves the full artifact content (not just the summary). Only use this when you need the complete artifact data and the summary shown in your context is insufficient.",
15627
- inputSchema: z8.z.object({
15628
- artifactId: z8.z.string().describe("The unique identifier of the artifact to get."),
15629
- toolCallId: z8.z.string().describe("The tool call ID associated with this artifact.")
15647
+ inputSchema: zodOpenapi.z.object({
15648
+ artifactId: zodOpenapi.z.string().describe("The unique identifier of the artifact to get."),
15649
+ toolCallId: zodOpenapi.z.string().describe("The tool call ID associated with this artifact.")
15630
15650
  }),
15631
15651
  execute: async ({ artifactId, toolCallId }) => {
15632
15652
  logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
@@ -15653,9 +15673,9 @@ var Agent = class {
15653
15673
  createThinkingCompleteTool() {
15654
15674
  return ai.tool({
15655
15675
  description: "\u{1F6A8} CRITICAL: Call this tool IMMEDIATELY when you have gathered enough information to answer the user. This is MANDATORY - you CANNOT provide text responses in thinking mode, only tool calls. Call thinking_complete as soon as you have sufficient data to generate a structured response.",
15656
- inputSchema: z8.z.object({
15657
- complete: z8.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
15658
- summary: z8.z.string().describe(
15676
+ inputSchema: zodOpenapi.z.object({
15677
+ complete: zodOpenapi.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
15678
+ summary: zodOpenapi.z.string().describe(
15659
15679
  "Brief summary of what information was gathered and why it is sufficient to answer the user"
15660
15680
  )
15661
15681
  }),
@@ -16102,6 +16122,15 @@ ${output}`;
16102
16122
  logger19.debug({ error }, "Failed to track agent reasoning");
16103
16123
  }
16104
16124
  }
16125
+ if (last && last["content"] && last["content"].length > 0) {
16126
+ const lastContent = last["content"][last["content"].length - 1];
16127
+ if (lastContent["type"] === "tool-error") {
16128
+ const error = lastContent["error"];
16129
+ if (error && typeof error === "object" && "name" in error && error.name === "connection_refused") {
16130
+ return true;
16131
+ }
16132
+ }
16133
+ }
16105
16134
  if (steps.length >= 2) {
16106
16135
  const previousStep = steps[steps.length - 2];
16107
16136
  if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
@@ -16337,9 +16366,9 @@ ${output}${structureHintsFormatted}`;
16337
16366
  this.config.dataComponents.forEach((dc) => {
16338
16367
  const propsSchema = jsonSchemaToZod(dc.props);
16339
16368
  componentSchemas.push(
16340
- z8.z.object({
16341
- id: z8.z.string(),
16342
- name: z8.z.literal(dc.name),
16369
+ zodOpenapi.z.object({
16370
+ id: zodOpenapi.z.string(),
16371
+ name: zodOpenapi.z.literal(dc.name),
16343
16372
  props: propsSchema
16344
16373
  })
16345
16374
  );
@@ -16356,7 +16385,7 @@ ${output}${structureHintsFormatted}`;
16356
16385
  if (componentSchemas.length === 1) {
16357
16386
  dataComponentsSchema = componentSchemas[0];
16358
16387
  } else {
16359
- dataComponentsSchema = z8.z.union(
16388
+ dataComponentsSchema = zodOpenapi.z.union(
16360
16389
  componentSchemas
16361
16390
  );
16362
16391
  }
@@ -16398,8 +16427,8 @@ ${output}${structureHintsFormatted}`;
16398
16427
  const streamResult = ai.streamObject({
16399
16428
  ...structuredModelSettings,
16400
16429
  messages: phase2Messages,
16401
- schema: z8.z.object({
16402
- dataComponents: z8.z.array(dataComponentsSchema)
16430
+ schema: zodOpenapi.z.object({
16431
+ dataComponents: zodOpenapi.z.array(dataComponentsSchema)
16403
16432
  }),
16404
16433
  experimental_telemetry: {
16405
16434
  isEnabled: true,
@@ -16469,8 +16498,8 @@ ${output}${structureHintsFormatted}`;
16469
16498
  withJsonPostProcessing2({
16470
16499
  ...structuredModelSettings,
16471
16500
  messages: phase2Messages,
16472
- schema: z8.z.object({
16473
- dataComponents: z8.z.array(dataComponentsSchema)
16501
+ schema: zodOpenapi.z.object({
16502
+ dataComponents: zodOpenapi.z.array(dataComponentsSchema)
16474
16503
  }),
16475
16504
  experimental_telemetry: {
16476
16505
  isEnabled: true,
@@ -17092,10 +17121,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
17092
17121
  };
17093
17122
  } catch (error) {
17094
17123
  console.error("Task handler error:", error);
17124
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
17125
+ const isConnectionRefused = errorMessage.includes("Connection refused. Please check if the MCP server is running.");
17095
17126
  return {
17096
17127
  status: {
17097
17128
  state: agentsCore.TaskState.Failed,
17098
- message: error instanceof Error ? error.message : "Unknown error occurred"
17129
+ message: errorMessage,
17130
+ type: isConnectionRefused ? "connection_refused" : "unknown"
17099
17131
  },
17100
17132
  artifacts: []
17101
17133
  };
@@ -17308,14 +17340,14 @@ app.openapi(
17308
17340
  description: "Agent Card for A2A discovery",
17309
17341
  content: {
17310
17342
  "application/json": {
17311
- schema: z8.z.object({
17312
- name: z8.z.string(),
17313
- description: z8.z.string().optional(),
17314
- url: z8.z.string(),
17315
- version: z8.z.string(),
17316
- defaultInputModes: z8.z.array(z8.z.string()),
17317
- defaultOutputModes: z8.z.array(z8.z.string()),
17318
- skills: z8.z.array(z8.z.any())
17343
+ schema: zodOpenapi.z.object({
17344
+ name: zodOpenapi.z.string(),
17345
+ description: zodOpenapi.z.string().optional(),
17346
+ url: zodOpenapi.z.string(),
17347
+ version: zodOpenapi.z.string(),
17348
+ defaultInputModes: zodOpenapi.z.array(zodOpenapi.z.string()),
17349
+ defaultOutputModes: zodOpenapi.z.array(zodOpenapi.z.string()),
17350
+ skills: zodOpenapi.z.array(zodOpenapi.z.any())
17319
17351
  })
17320
17352
  }
17321
17353
  }
@@ -18587,36 +18619,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
18587
18619
  body: {
18588
18620
  content: {
18589
18621
  "application/json": {
18590
- schema: z8.z.object({
18591
- model: z8.z.string().describe("The model to use for the completion"),
18592
- messages: z8.z.array(
18593
- z8.z.object({
18594
- role: z8.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
18595
- content: z8.z.union([
18596
- z8.z.string(),
18597
- z8.z.array(
18598
- z8.z.strictObject({
18599
- type: z8.z.string(),
18600
- text: z8.z.string().optional()
18622
+ schema: zodOpenapi.z.object({
18623
+ model: zodOpenapi.z.string().describe("The model to use for the completion"),
18624
+ messages: zodOpenapi.z.array(
18625
+ zodOpenapi.z.object({
18626
+ role: zodOpenapi.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
18627
+ content: zodOpenapi.z.union([
18628
+ zodOpenapi.z.string(),
18629
+ zodOpenapi.z.array(
18630
+ zodOpenapi.z.strictObject({
18631
+ type: zodOpenapi.z.string(),
18632
+ text: zodOpenapi.z.string().optional()
18601
18633
  })
18602
18634
  )
18603
18635
  ]).describe("The message content"),
18604
- name: z8.z.string().optional().describe("The name of the message sender")
18636
+ name: zodOpenapi.z.string().optional().describe("The name of the message sender")
18605
18637
  })
18606
18638
  ).describe("The conversation messages"),
18607
- temperature: z8.z.number().optional().describe("Controls randomness (0-1)"),
18608
- top_p: z8.z.number().optional().describe("Controls nucleus sampling"),
18609
- n: z8.z.number().optional().describe("Number of completions to generate"),
18610
- stream: z8.z.boolean().optional().describe("Whether to stream the response"),
18611
- max_tokens: z8.z.number().optional().describe("Maximum tokens to generate"),
18612
- presence_penalty: z8.z.number().optional().describe("Presence penalty (-2 to 2)"),
18613
- frequency_penalty: z8.z.number().optional().describe("Frequency penalty (-2 to 2)"),
18614
- logit_bias: z8.z.record(z8.z.string(), z8.z.number()).optional().describe("Token logit bias"),
18615
- user: z8.z.string().optional().describe("User identifier"),
18616
- conversationId: z8.z.string().optional().describe("Conversation ID for multi-turn chat"),
18617
- tools: z8.z.array(z8.z.string()).optional().describe("Available tools"),
18618
- runConfig: z8.z.record(z8.z.string(), z8.z.unknown()).optional().describe("Run configuration"),
18619
- headers: z8.z.record(z8.z.string(), z8.z.unknown()).optional().describe(
18639
+ temperature: zodOpenapi.z.number().optional().describe("Controls randomness (0-1)"),
18640
+ top_p: zodOpenapi.z.number().optional().describe("Controls nucleus sampling"),
18641
+ n: zodOpenapi.z.number().optional().describe("Number of completions to generate"),
18642
+ stream: zodOpenapi.z.boolean().optional().describe("Whether to stream the response"),
18643
+ max_tokens: zodOpenapi.z.number().optional().describe("Maximum tokens to generate"),
18644
+ presence_penalty: zodOpenapi.z.number().optional().describe("Presence penalty (-2 to 2)"),
18645
+ frequency_penalty: zodOpenapi.z.number().optional().describe("Frequency penalty (-2 to 2)"),
18646
+ logit_bias: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.number()).optional().describe("Token logit bias"),
18647
+ user: zodOpenapi.z.string().optional().describe("User identifier"),
18648
+ conversationId: zodOpenapi.z.string().optional().describe("Conversation ID for multi-turn chat"),
18649
+ tools: zodOpenapi.z.array(zodOpenapi.z.string()).optional().describe("Available tools"),
18650
+ runConfig: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).optional().describe("Run configuration"),
18651
+ headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).optional().describe(
18620
18652
  "Headers data for template processing (validated against context config schema)"
18621
18653
  )
18622
18654
  })
@@ -18627,14 +18659,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
18627
18659
  responses: {
18628
18660
  200: {
18629
18661
  description: "Streaming chat completion response in Server-Sent Events format",
18630
- headers: z8.z.object({
18631
- "Content-Type": z8.z.string().default("text/event-stream"),
18632
- "Cache-Control": z8.z.string().default("no-cache"),
18633
- Connection: z8.z.string().default("keep-alive")
18662
+ headers: zodOpenapi.z.object({
18663
+ "Content-Type": zodOpenapi.z.string().default("text/event-stream"),
18664
+ "Cache-Control": zodOpenapi.z.string().default("no-cache"),
18665
+ Connection: zodOpenapi.z.string().default("keep-alive")
18634
18666
  }),
18635
18667
  content: {
18636
18668
  "text/event-stream": {
18637
- schema: z8.z.string().describe("Server-Sent Events stream with chat completion chunks")
18669
+ schema: zodOpenapi.z.string().describe("Server-Sent Events stream with chat completion chunks")
18638
18670
  }
18639
18671
  }
18640
18672
  },
@@ -18642,13 +18674,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
18642
18674
  description: "Invalid request context or parameters",
18643
18675
  content: {
18644
18676
  "application/json": {
18645
- schema: z8.z.object({
18646
- error: z8.z.string(),
18647
- details: z8.z.array(
18648
- z8.z.object({
18649
- field: z8.z.string(),
18650
- message: z8.z.string(),
18651
- value: z8.z.unknown().optional()
18677
+ schema: zodOpenapi.z.object({
18678
+ error: zodOpenapi.z.string(),
18679
+ details: zodOpenapi.z.array(
18680
+ zodOpenapi.z.object({
18681
+ field: zodOpenapi.z.string(),
18682
+ message: zodOpenapi.z.string(),
18683
+ value: zodOpenapi.z.unknown().optional()
18652
18684
  })
18653
18685
  ).optional()
18654
18686
  })
@@ -18659,8 +18691,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
18659
18691
  description: "Agent or agent not found",
18660
18692
  content: {
18661
18693
  "application/json": {
18662
- schema: z8.z.object({
18663
- error: z8.z.string()
18694
+ schema: zodOpenapi.z.object({
18695
+ error: zodOpenapi.z.string()
18664
18696
  })
18665
18697
  }
18666
18698
  }
@@ -18669,9 +18701,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
18669
18701
  description: "Internal server error",
18670
18702
  content: {
18671
18703
  "application/json": {
18672
- schema: z8.z.object({
18673
- error: z8.z.string(),
18674
- message: z8.z.string()
18704
+ schema: zodOpenapi.z.object({
18705
+ error: zodOpenapi.z.string(),
18706
+ message: zodOpenapi.z.string()
18675
18707
  })
18676
18708
  }
18677
18709
  }
@@ -19522,7 +19554,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
19522
19554
  "send-query-to-agent",
19523
19555
  `Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
19524
19556
  {
19525
- query: z8.z.string().describe("The query to send to the agent")
19557
+ query: zodOpenapi.z.string().describe("The query to send to the agent")
19526
19558
  },
19527
19559
  async ({ query }) => {
19528
19560
  try {
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { flushBatchProcessor } from './chunk-AZFBQY6E.js';
2
- import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-M46DFVYB.js';
3
- import { dbClient_default } from './chunk-V4RNZ6BX.js';
4
- import { env } from './chunk-IYG4HUQ6.js';
1
+ import { flushBatchProcessor } from './chunk-QOUOKHYQ.js';
2
+ import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-BQB27EXW.js';
3
+ import { dbClient_default } from './chunk-W6UIBREL.js';
4
+ import { env } from './chunk-CDYXP4BN.js';
5
5
  import { getLogger } from './chunk-A2S7GSHL.js';
6
- import { SESSION_CLEANUP_INTERVAL_MS, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, STREAM_MAX_LIFETIME_MS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_TEXT_GAP_THRESHOLD_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, AGENT_EXECUTION_MAX_GENERATION_STEPS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS } from './chunk-IVALDC72.js';
6
+ import { SESSION_CLEANUP_INTERVAL_MS, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, STREAM_MAX_LIFETIME_MS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_TEXT_GAP_THRESHOLD_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, AGENT_EXECUTION_MAX_GENERATION_STEPS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS } from './chunk-SUUSOBLI.js';
7
7
  import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, getConversation, createDefaultCredentialStores, CredentialStoreRegistry, createTask, getTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, TaskState, getAgentById, getProject, setActiveAgentForThread, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, ModelFactory, verifyTempToken, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, listTaskIdsByContextId, getLedgerArtifacts, agentHasArtifactComponents, upsertLedgerArtifact, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
8
8
  import { otel } from '@hono/otel';
9
- import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
9
+ import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi';
10
10
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
11
11
  import { Hono } from 'hono';
12
12
  import { cors } from 'hono/cors';
@@ -14,7 +14,6 @@ import { HTTPException } from 'hono/http-exception';
14
14
  import { requestId } from 'hono/request-id';
15
15
  import { createMiddleware } from 'hono/factory';
16
16
  import { swaggerUI } from '@hono/swagger-ui';
17
- import z5, { z } from 'zod';
18
17
  import { streamSSE, stream } from 'hono/streaming';
19
18
  import { createUIMessageStream, JsonToSseTransformStream, parsePartialJson, generateObject, tool, streamText, generateText, streamObject } from 'ai';
20
19
  import jmespath from 'jmespath';
@@ -628,6 +627,21 @@ async function handleMessageSend(c, agent, request) {
628
627
  });
629
628
  }
630
629
  }
630
+ if (result.status.state === TaskState.Failed) {
631
+ const isConnectionRefused = result.status.type === "connection_refused";
632
+ if (isConnectionRefused) {
633
+ return c.json({
634
+ jsonrpc: "2.0",
635
+ error: {
636
+ code: -32603,
637
+ message: result.status.message || "Agent execution failed",
638
+ data: {
639
+ type: "connection_refused"
640
+ }
641
+ }
642
+ });
643
+ }
644
+ }
631
645
  const taskStatus = {
632
646
  state: result.status.state,
633
647
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -4856,13 +4870,14 @@ var DEFAULT_BACKOFF = {
4856
4870
  var DEFAULT_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
4857
4871
  var PermanentError = class _PermanentError extends Error {
4858
4872
  cause;
4873
+ type;
4859
4874
  constructor(message, options) {
4860
4875
  let msg = message;
4861
4876
  if (options?.cause) {
4862
4877
  msg += `: ${options.cause}`;
4863
4878
  }
4864
4879
  super(msg, options);
4865
- this.name = "PermanentError";
4880
+ this.name = options?.type || "PermanentError";
4866
4881
  if (typeof this.cause === "undefined") {
4867
4882
  this.cause = options?.cause;
4868
4883
  }
@@ -5171,6 +5186,12 @@ var A2AClient = class {
5171
5186
  }
5172
5187
  }
5173
5188
  const rpcResponse = await httpResponse.json();
5189
+ if (rpcResponse.error?.data?.type === "connection_refused") {
5190
+ throw new PermanentError(rpcResponse.error.message, {
5191
+ cause: new Error(rpcResponse.error.message),
5192
+ type: "connection_refused"
5193
+ });
5194
+ }
5174
5195
  if (rpcResponse.id !== requestId2) {
5175
5196
  logger12.warn(
5176
5197
  {
@@ -5558,7 +5579,7 @@ var createTransferToAgentTool = ({
5558
5579
  const toolDescription = generateTransferToolDescription(transferConfig);
5559
5580
  return tool({
5560
5581
  description: toolDescription,
5561
- inputSchema: z5.object({}),
5582
+ inputSchema: z.object({}),
5562
5583
  execute: async () => {
5563
5584
  const activeSpan = trace.getActiveSpan();
5564
5585
  if (activeSpan) {
@@ -5613,7 +5634,7 @@ function createDelegateToAgentTool({
5613
5634
  }) {
5614
5635
  return tool({
5615
5636
  description: generateDelegateToolDescription(delegateConfig),
5616
- inputSchema: z5.object({ message: z5.string() }),
5637
+ inputSchema: z.object({ message: z.string() }),
5617
5638
  execute: async (input, context) => {
5618
5639
  const delegationId = `del_${generateId()}`;
5619
5640
  const activeSpan = trace.getActiveSpan();
@@ -7631,7 +7652,7 @@ var Agent = class {
7631
7652
  if (functionToolsData.length === 0) {
7632
7653
  return functionTools;
7633
7654
  }
7634
- const { SandboxExecutorFactory } = await import('./SandboxExecutorFactory-FVKDJKKZ.js');
7655
+ const { SandboxExecutorFactory } = await import('./SandboxExecutorFactory-A2LTPE2X.js');
7635
7656
  const sandboxExecutor = SandboxExecutorFactory.getInstance();
7636
7657
  for (const functionToolDef of functionToolsData) {
7637
7658
  const functionId = functionToolDef.functionId;
@@ -7925,7 +7946,7 @@ var Agent = class {
7925
7946
  inputSchema: tool3.inputSchema || tool3.parameters || {},
7926
7947
  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."
7927
7948
  }));
7928
- const { getConversationScopedArtifacts } = await import('./conversations-NZLQK64L.js');
7949
+ const { getConversationScopedArtifacts } = await import('./conversations-33GSAG2C.js');
7929
7950
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
7930
7951
  const referenceArtifacts = await getConversationScopedArtifacts({
7931
7952
  tenantId: this.config.tenantId,
@@ -8449,6 +8470,15 @@ ${output}`;
8449
8470
  logger15.debug({ error }, "Failed to track agent reasoning");
8450
8471
  }
8451
8472
  }
8473
+ if (last && last["content"] && last["content"].length > 0) {
8474
+ const lastContent = last["content"][last["content"].length - 1];
8475
+ if (lastContent["type"] === "tool-error") {
8476
+ const error = lastContent["error"];
8477
+ if (error && typeof error === "object" && "name" in error && error.name === "connection_refused") {
8478
+ return true;
8479
+ }
8480
+ }
8481
+ }
8452
8482
  if (steps.length >= 2) {
8453
8483
  const previousStep = steps[steps.length - 2];
8454
8484
  if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
@@ -9439,10 +9469,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9439
9469
  };
9440
9470
  } catch (error) {
9441
9471
  console.error("Task handler error:", error);
9472
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
9473
+ const isConnectionRefused = errorMessage.includes("Connection refused. Please check if the MCP server is running.");
9442
9474
  return {
9443
9475
  status: {
9444
9476
  state: TaskState.Failed,
9445
- message: error instanceof Error ? error.message : "Unknown error occurred"
9477
+ message: errorMessage,
9478
+ type: isConnectionRefused ? "connection_refused" : "unknown"
9446
9479
  },
9447
9480
  artifacts: []
9448
9481
  };
@@ -11263,29 +11296,29 @@ var chatDataStreamRoute = createRoute({
11263
11296
  body: {
11264
11297
  content: {
11265
11298
  "application/json": {
11266
- schema: z$1.object({
11267
- model: z$1.string().optional(),
11268
- messages: z$1.array(
11269
- z$1.object({
11270
- role: z$1.enum(["system", "user", "assistant", "function", "tool"]),
11271
- content: z$1.any(),
11272
- parts: z$1.array(
11273
- z$1.object({
11274
- type: z$1.union([
11275
- z$1.enum(["text", "image", "audio", "video", "file"]),
11276
- z$1.string().regex(/^data-/, 'Type must start with "data-"')
11299
+ schema: z.object({
11300
+ model: z.string().optional(),
11301
+ messages: z.array(
11302
+ z.object({
11303
+ role: z.enum(["system", "user", "assistant", "function", "tool"]),
11304
+ content: z.any(),
11305
+ parts: z.array(
11306
+ z.object({
11307
+ type: z.union([
11308
+ z.enum(["text", "image", "audio", "video", "file"]),
11309
+ z.string().regex(/^data-/, 'Type must start with "data-"')
11277
11310
  ]),
11278
- text: z$1.string().optional()
11311
+ text: z.string().optional()
11279
11312
  })
11280
11313
  ).optional()
11281
11314
  })
11282
11315
  ),
11283
- id: z$1.string().optional(),
11284
- conversationId: z$1.string().optional(),
11285
- stream: z$1.boolean().optional().describe("Whether to stream the response").default(true),
11286
- max_tokens: z$1.number().optional().describe("Maximum tokens to generate"),
11287
- headers: z$1.record(z$1.string(), z$1.unknown()).optional().describe("Headers data for template processing"),
11288
- runConfig: z$1.record(z$1.string(), z$1.unknown()).optional().describe("Run configuration")
11316
+ id: z.string().optional(),
11317
+ conversationId: z.string().optional(),
11318
+ stream: z.boolean().optional().describe("Whether to stream the response").default(true),
11319
+ max_tokens: z.number().optional().describe("Maximum tokens to generate"),
11320
+ headers: z.record(z.string(), z.unknown()).optional().describe("Headers data for template processing"),
11321
+ runConfig: z.record(z.string(), z.unknown()).optional().describe("Run configuration")
11289
11322
  })
11290
11323
  }
11291
11324
  }
@@ -11294,9 +11327,9 @@ var chatDataStreamRoute = createRoute({
11294
11327
  responses: {
11295
11328
  200: {
11296
11329
  description: "Streamed chat completion",
11297
- headers: z$1.object({
11298
- "Content-Type": z$1.string().default("text/plain; charset=utf-8"),
11299
- "x-vercel-ai-data-stream": z$1.string().default("v1")
11330
+ headers: z.object({
11331
+ "Content-Type": z.string().default("text/plain; charset=utf-8"),
11332
+ "x-vercel-ai-data-stream": z.string().default("v1")
11300
11333
  })
11301
11334
  },
11302
11335
  ...commonGetErrorResponses
@@ -11509,11 +11542,11 @@ var toolApprovalRoute = createRoute({
11509
11542
  body: {
11510
11543
  content: {
11511
11544
  "application/json": {
11512
- schema: z$1.object({
11513
- conversationId: z$1.string().describe("The conversation ID"),
11514
- toolCallId: z$1.string().describe("The tool call ID to respond to"),
11515
- approved: z$1.boolean().describe("Whether the tool execution is approved"),
11516
- reason: z$1.string().optional().describe("Optional reason for the decision")
11545
+ schema: z.object({
11546
+ conversationId: z.string().describe("The conversation ID"),
11547
+ toolCallId: z.string().describe("The tool call ID to respond to"),
11548
+ approved: z.boolean().describe("Whether the tool execution is approved"),
11549
+ reason: z.string().optional().describe("Optional reason for the decision")
11517
11550
  })
11518
11551
  }
11519
11552
  }
@@ -11524,9 +11557,9 @@ var toolApprovalRoute = createRoute({
11524
11557
  description: "Tool approval response processed successfully",
11525
11558
  content: {
11526
11559
  "application/json": {
11527
- schema: z$1.object({
11528
- success: z$1.boolean(),
11529
- message: z$1.string().optional()
11560
+ schema: z.object({
11561
+ success: z.boolean(),
11562
+ message: z.string().optional()
11530
11563
  })
11531
11564
  }
11532
11565
  }
@@ -11535,8 +11568,8 @@ var toolApprovalRoute = createRoute({
11535
11568
  description: "Bad request - invalid tool call ID or conversation ID",
11536
11569
  content: {
11537
11570
  "application/json": {
11538
- schema: z$1.object({
11539
- error: z$1.string()
11571
+ schema: z.object({
11572
+ error: z.string()
11540
11573
  })
11541
11574
  }
11542
11575
  }
@@ -11545,8 +11578,8 @@ var toolApprovalRoute = createRoute({
11545
11578
  description: "Tool call not found or already processed",
11546
11579
  content: {
11547
11580
  "application/json": {
11548
- schema: z$1.object({
11549
- error: z$1.string()
11581
+ schema: z.object({
11582
+ error: z.string()
11550
11583
  })
11551
11584
  }
11552
11585
  }
@@ -11555,9 +11588,9 @@ var toolApprovalRoute = createRoute({
11555
11588
  description: "Internal server error",
11556
11589
  content: {
11557
11590
  "application/json": {
11558
- schema: z$1.object({
11559
- error: z$1.string(),
11560
- message: z$1.string()
11591
+ schema: z.object({
11592
+ error: z.string(),
11593
+ message: z.string()
11561
11594
  })
11562
11595
  }
11563
11596
  }
@@ -10,33 +10,33 @@ var sdkNode = require('@opentelemetry/sdk-node');
10
10
  var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
11
11
  var semanticConventions = require('@opentelemetry/semantic-conventions');
12
12
  var agentsCore = require('@inkeep/agents-core');
13
- var zod = require('zod');
13
+ var zodOpenapi = require('@hono/zod-openapi');
14
14
 
15
15
  // src/instrumentation.ts
16
16
  agentsCore.loadEnvironmentFiles();
17
- var envSchema = zod.z.object({
18
- NODE_ENV: zod.z.enum(["development", "production", "test"]).optional(),
19
- ENVIRONMENT: zod.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
20
- DATABASE_URL: zod.z.string().optional(),
21
- INKEEP_AGENTS_RUN_API_URL: zod.z.string().optional().default("http://localhost:3003"),
22
- AGENTS_MANAGE_UI_URL: zod.z.string().optional().default("http://localhost:3000"),
23
- LOG_LEVEL: zod.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
24
- NANGO_SERVER_URL: zod.z.string().optional().default("https://api.nango.dev"),
25
- NANGO_SECRET_KEY: zod.z.string().optional(),
26
- ANTHROPIC_API_KEY: zod.z.string(),
27
- OPENAI_API_KEY: zod.z.string().optional(),
28
- GOOGLE_GENERATIVE_AI_API_KEY: zod.z.string().optional(),
29
- INKEEP_AGENTS_RUN_API_BYPASS_SECRET: zod.z.string().optional(),
30
- INKEEP_AGENTS_JWT_SIGNING_SECRET: zod.z.string().optional(),
31
- INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: zod.z.string().optional(),
32
- OTEL_BSP_SCHEDULE_DELAY: zod.z.coerce.number().optional().default(500),
33
- OTEL_BSP_MAX_EXPORT_BATCH_SIZE: zod.z.coerce.number().optional().default(64)
17
+ var envSchema = zodOpenapi.z.object({
18
+ NODE_ENV: zodOpenapi.z.enum(["development", "production", "test"]).optional(),
19
+ ENVIRONMENT: zodOpenapi.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
20
+ DATABASE_URL: zodOpenapi.z.string().optional(),
21
+ INKEEP_AGENTS_RUN_API_URL: zodOpenapi.z.string().optional().default("http://localhost:3003"),
22
+ AGENTS_MANAGE_UI_URL: zodOpenapi.z.string().optional().default("http://localhost:3000"),
23
+ LOG_LEVEL: zodOpenapi.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
24
+ NANGO_SERVER_URL: zodOpenapi.z.string().optional().default("https://api.nango.dev"),
25
+ NANGO_SECRET_KEY: zodOpenapi.z.string().optional(),
26
+ ANTHROPIC_API_KEY: zodOpenapi.z.string(),
27
+ OPENAI_API_KEY: zodOpenapi.z.string().optional(),
28
+ GOOGLE_GENERATIVE_AI_API_KEY: zodOpenapi.z.string().optional(),
29
+ INKEEP_AGENTS_RUN_API_BYPASS_SECRET: zodOpenapi.z.string().optional(),
30
+ INKEEP_AGENTS_JWT_SIGNING_SECRET: zodOpenapi.z.string().optional(),
31
+ INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: zodOpenapi.z.string().optional(),
32
+ OTEL_BSP_SCHEDULE_DELAY: zodOpenapi.z.coerce.number().optional().default(500),
33
+ OTEL_BSP_MAX_EXPORT_BATCH_SIZE: zodOpenapi.z.coerce.number().optional().default(64)
34
34
  });
35
35
  var parseEnv = () => {
36
36
  try {
37
37
  return envSchema.parse(process.env);
38
38
  } catch (error) {
39
- if (error instanceof zod.z.ZodError) {
39
+ if (error instanceof zodOpenapi.z.ZodError) {
40
40
  const missingVars = error.issues.map((issue) => issue.path.join("."));
41
41
  throw new Error(
42
42
  `\u274C Invalid environment variables: ${missingVars.join(", ")}
@@ -1 +1 @@
1
- export { defaultBatchProcessor, defaultContextManager, defaultInstrumentations, defaultResource, defaultSDK, defaultSpanProcessors, defaultTextMapPropagator, flushBatchProcessor } from './chunk-AZFBQY6E.js';
1
+ export { defaultBatchProcessor, defaultContextManager, defaultInstrumentations, defaultResource, defaultSDK, defaultSpanProcessors, defaultTextMapPropagator, flushBatchProcessor } from './chunk-QOUOKHYQ.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.37.1",
3
+ "version": "0.37.2",
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",
@@ -24,7 +24,6 @@
24
24
  "@hono/node-server": "^1.14.3",
25
25
  "@hono/otel": "^0.4.0",
26
26
  "@hono/swagger-ui": "^0.5.1",
27
- "@hono/zod-openapi": "^1.0.2",
28
27
  "@openrouter/ai-sdk-provider": "^1.2.0",
29
28
  "@opentelemetry/api": "^1.9.0",
30
29
  "@opentelemetry/auto-instrumentations-node": "^0.64.1",
@@ -54,8 +53,11 @@
54
53
  "pino": "^9.11.0",
55
54
  "traverse": "^0.6.11",
56
55
  "ts-pattern": "^5.7.1",
57
- "zod": "4.1.5",
58
- "@inkeep/agents-core": "^0.37.1"
56
+ "@inkeep/agents-core": "^0.37.2"
57
+ },
58
+ "peerDependencies": {
59
+ "@hono/zod-openapi": "^1.1.5",
60
+ "zod": "^4.1.11"
59
61
  },
60
62
  "optionalDependencies": {
61
63
  "keytar": "^7.9.0"
@@ -1 +0,0 @@
1
- export { dbClient_default as default } from './chunk-V4RNZ6BX.js';