@inkeep/agents-run-api 0.31.7 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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 z6 = require('zod');
6
+ var z7 = require('zod');
7
7
  var child_process = require('child_process');
8
8
  var crypto = require('crypto');
9
9
  var fs = require('fs');
@@ -45,7 +45,7 @@ var fetchToNode = require('fetch-to-node');
45
45
 
46
46
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
47
47
 
48
- var z6__default = /*#__PURE__*/_interopDefault(z6);
48
+ var z7__default = /*#__PURE__*/_interopDefault(z7);
49
49
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
50
50
  var jmespath__default = /*#__PURE__*/_interopDefault(jmespath);
51
51
  var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
@@ -67,30 +67,28 @@ var envSchema, parseEnv, env;
67
67
  var init_env = __esm({
68
68
  "src/env.ts"() {
69
69
  agentsCore.loadEnvironmentFiles();
70
- envSchema = z6.z.object({
71
- NODE_ENV: z6.z.enum(["development", "production", "test"]).optional(),
72
- ENVIRONMENT: z6.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
73
- DB_FILE_NAME: z6.z.string().optional(),
74
- TURSO_DATABASE_URL: z6.z.string().optional(),
75
- TURSO_AUTH_TOKEN: z6.z.string().optional(),
76
- AGENTS_RUN_API_URL: z6.z.string().optional().default("http://localhost:3003"),
77
- LOG_LEVEL: z6.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
78
- NANGO_SERVER_URL: z6.z.string().optional().default("https://api.nango.dev"),
79
- NANGO_SECRET_KEY: z6.z.string().optional(),
80
- ANTHROPIC_API_KEY: z6.z.string(),
81
- OPENAI_API_KEY: z6.z.string().optional(),
82
- GOOGLE_GENERATIVE_AI_API_KEY: z6.z.string().optional(),
83
- INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z6.z.string().optional(),
84
- INKEEP_AGENTS_JWT_SIGNING_SECRET: z6.z.string().optional(),
85
- OTEL_BSP_SCHEDULE_DELAY: z6.z.coerce.number().optional().default(500),
86
- OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z6.z.coerce.number().optional().default(64)
70
+ envSchema = z7.z.object({
71
+ NODE_ENV: z7.z.enum(["development", "production", "test"]).optional(),
72
+ ENVIRONMENT: z7.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
73
+ DATABASE_URL: z7.z.string().optional(),
74
+ AGENTS_RUN_API_URL: z7.z.string().optional().default("http://localhost:3003"),
75
+ LOG_LEVEL: z7.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
76
+ NANGO_SERVER_URL: z7.z.string().optional().default("https://api.nango.dev"),
77
+ NANGO_SECRET_KEY: z7.z.string().optional(),
78
+ ANTHROPIC_API_KEY: z7.z.string(),
79
+ OPENAI_API_KEY: z7.z.string().optional(),
80
+ GOOGLE_GENERATIVE_AI_API_KEY: z7.z.string().optional(),
81
+ INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z7.z.string().optional(),
82
+ INKEEP_AGENTS_JWT_SIGNING_SECRET: z7.z.string().optional(),
83
+ OTEL_BSP_SCHEDULE_DELAY: z7.z.coerce.number().optional().default(500),
84
+ OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z7.z.coerce.number().optional().default(64)
87
85
  });
88
86
  parseEnv = () => {
89
87
  try {
90
88
  const parsedEnv = envSchema.parse(process.env);
91
89
  return parsedEnv;
92
90
  } catch (error) {
93
- if (error instanceof z6.z.ZodError) {
91
+ if (error instanceof z7.z.ZodError) {
94
92
  const missingVars = error.issues.map((issue) => issue.path.join("."));
95
93
  throw new Error(
96
94
  `\u274C Invalid environment variables: ${missingVars.join(", ")}
@@ -125,28 +123,228 @@ var init_dbClient = __esm({
125
123
  init_env();
126
124
  getDbConfig = () => {
127
125
  if (env.ENVIRONMENT === "test") {
128
- return { url: ":memory:" };
126
+ return {};
129
127
  }
130
- if (env.TURSO_DATABASE_URL && env.TURSO_AUTH_TOKEN) {
131
- return {
132
- url: env.TURSO_DATABASE_URL,
133
- authToken: env.TURSO_AUTH_TOKEN
134
- };
135
- }
136
- if (!env.DB_FILE_NAME) {
137
- throw new Error(
138
- "Database configuration error: DB_FILE_NAME must be set if Turso is not configured."
139
- );
140
- }
141
- return {
142
- url: env.DB_FILE_NAME
143
- };
128
+ return { connectionString: env.DATABASE_URL };
144
129
  };
145
130
  dbClient = agentsCore.createDatabaseClient(getDbConfig());
146
131
  dbClient_default = dbClient;
147
132
  }
148
133
  });
149
134
 
135
+ // src/constants/execution-limits/defaults.ts
136
+ var executionLimitsDefaults;
137
+ var init_defaults = __esm({
138
+ "src/constants/execution-limits/defaults.ts"() {
139
+ executionLimitsDefaults = {
140
+ // Sub Agent Turn Execution
141
+ // During a Sub Agent's turn, it makes decisions by calling the LLM (language model). Each decision
142
+ // point is called a "generation step" - for example, deciding to call a tool, transfer to another
143
+ // Sub Agent, delegate a subtask, or send a response to the user.
144
+ // AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: Maximum errors tolerated during a single Sub Agent's turn before stopping execution
145
+ // AGENT_EXECUTION_MAX_GENERATION_STEPS: Maximum LLM inference calls allowed within a single Sub Agent turn
146
+ AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: 3,
147
+ AGENT_EXECUTION_MAX_GENERATION_STEPS: 5,
148
+ // Sub Agent Decision-Making Timeouts
149
+ // These control how long to wait for the LLM to make decisions during a Sub Agent's turn.
150
+ // "First call" = initial decision at start of turn (may include tool results from previous actions)
151
+ // "Subsequent call" = follow-up decisions after executing tools within the same turn
152
+ // Streaming mode has longer timeout because it waits for the full streamed response to the user
153
+ // LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: Timeout for initial streaming response to user
154
+ // LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: Timeout for initial non-streaming (internal) decision
155
+ // LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: Timeout for follow-up decisions after tool execution
156
+ // LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: Maximum timeout allowed regardless of configuration
157
+ LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: 27e4,
158
+ // 4.5 minutes
159
+ LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: 9e4,
160
+ // 1.5 minutes
161
+ LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: 9e4,
162
+ // 1.5 minutes
163
+ LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: 6e5,
164
+ // 10 minutes
165
+ // Function Tool Execution (Sandboxed Environments)
166
+ // Function Tools are custom JavaScript functions that Sub Agents can call. They run in secure
167
+ // isolated sandboxes (containerized environments) to prevent malicious code execution.
168
+ // For performance, sandboxes are cached and reused across multiple tool calls until they expire.
169
+ // FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: Maximum execution time for a Function Tool call
170
+ // FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: Virtual CPUs allocated to each sandbox (affects compute capacity)
171
+ // FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: Time-to-live for cached sandboxes (after this, sandbox is discarded)
172
+ // FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: Maximum reuses of a sandbox before it's refreshed (prevents resource leaks)
173
+ // FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: Maximum size of Function Tool output (prevents memory exhaustion)
174
+ // FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: Maximum wait time for sandbox to become available when pool is full
175
+ // FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: How often to check for and remove expired sandboxes from the pool
176
+ FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: 3e4,
177
+ // 30 seconds
178
+ FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: 4,
179
+ FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: 3e5,
180
+ // 5 minutes
181
+ FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: 50,
182
+ FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: 1048576,
183
+ // 1 MB
184
+ FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: 3e4,
185
+ // 30 seconds
186
+ FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: 6e4,
187
+ // 1 minute
188
+ // MCP Tool Execution
189
+ // MCP (Model Context Protocol) Servers are external services that provide tools to Sub Agents.
190
+ // When a Sub Agent calls an MCP Tool, the request is sent to the external MCP Server.
191
+ // Note: MCP connection/retry constants are defined in @inkeep/agents-core/constants/execution-limits-shared
192
+ // MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: Maximum wait time for an MCP tool call to complete
193
+ MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: 6e4,
194
+ // 60 seconds
195
+ // Sub Agent Delegation (Retry Strategy)
196
+ // When a Sub Agent delegates a subtask to another Sub Agent, it uses the A2A (Agent-to-Agent)
197
+ // protocol to communicate. If the delegation request fails, these constants control the
198
+ // exponential backoff retry strategy. Formula: delay = min(INITIAL * EXPONENT^attempt, MAX)
199
+ // DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
200
+ // DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries (caps exponential growth)
201
+ // DELEGATION_TOOL_BACKOFF_EXPONENT: Multiplier applied to delay after each retry (2 = doubles each time)
202
+ // DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
203
+ DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: 100,
204
+ DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: 1e4,
205
+ // 10 seconds
206
+ DELEGATION_TOOL_BACKOFF_EXPONENT: 2,
207
+ DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: 2e4,
208
+ // 20 seconds
209
+ // General Agent-to-Agent (A2A) Communication (Retry Strategy)
210
+ // These control retries for broader A2A protocol operations beyond delegation (e.g., status checks,
211
+ // conversation updates). Uses more conservative retry parameters than delegation-specific retries.
212
+ // A2A_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
213
+ // A2A_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries
214
+ // A2A_BACKOFF_EXPONENT: Multiplier for exponential backoff (1.5 = grows 50% each retry)
215
+ // A2A_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
216
+ A2A_BACKOFF_INITIAL_INTERVAL_MS: 500,
217
+ A2A_BACKOFF_MAX_INTERVAL_MS: 6e4,
218
+ // 1 minute
219
+ A2A_BACKOFF_EXPONENT: 1.5,
220
+ A2A_BACKOFF_MAX_ELAPSED_TIME_MS: 3e4,
221
+ // 30 seconds
222
+ // Artifact Processing
223
+ // Artifacts are tool outputs saved for later reference by Sub Agents or users. When a tool generates
224
+ // an artifact, the system automatically generates a human-readable name and description using the LLM.
225
+ // These constants control artifact name/description generation and context window management.
226
+ // ARTIFACT_GENERATION_MAX_RETRIES: Retry attempts for LLM-based artifact name/description generation
227
+ // ARTIFACT_SESSION_MAX_PENDING: Maximum unprocessed artifacts in queue (prevents unbounded growth)
228
+ // ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: Historical artifact summaries kept in context for reference
229
+ // ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: Starting delay for retry backoff when generation fails
230
+ // ARTIFACT_GENERATION_BACKOFF_MAX_MS: Maximum delay between retries (formula: min(INITIAL * 2^attempt, MAX))
231
+ ARTIFACT_GENERATION_MAX_RETRIES: 3,
232
+ ARTIFACT_SESSION_MAX_PENDING: 100,
233
+ ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: 3,
234
+ ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: 1e3,
235
+ // 1 second
236
+ ARTIFACT_GENERATION_BACKOFF_MAX_MS: 1e4,
237
+ // 10 seconds
238
+ // Conversation Session & Cache Management
239
+ // A "session" represents the state of an ongoing conversation with an Agent. Tool results are cached
240
+ // within the session for performance - this is especially important for artifact processing where the
241
+ // same tool outputs may be referenced multiple times across Sub Agent turns.
242
+ // SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: How long tool results are kept in cache before expiring
243
+ // SESSION_CLEANUP_INTERVAL_MS: How often to check for and remove expired cached tool results
244
+ SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: 3e5,
245
+ // 5 minutes
246
+ SESSION_CLEANUP_INTERVAL_MS: 6e4,
247
+ // 1 minute
248
+ // Status Updates
249
+ // Status Updates are real-time progress messages sent to users during longer Sub Agent operations.
250
+ // The system automatically generates status updates based on activity thresholds - either after a
251
+ // certain number of significant events OR after a time interval (whichever comes first).
252
+ // Events include: tool calls, Sub Agent transfers, delegations, or other significant activities.
253
+ // STATUS_UPDATE_DEFAULT_NUM_EVENTS: Number of significant events before triggering a status update
254
+ // STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: Time interval (in seconds) before generating status update
255
+ STATUS_UPDATE_DEFAULT_NUM_EVENTS: 1,
256
+ STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: 2,
257
+ // Response Streaming (Internal Buffering Limits)
258
+ // These are internal infrastructure limits for streaming responses to users. Streaming enables
259
+ // real-time updates as Sub Agents generate responses, Data Components, and Status Updates.
260
+ // STREAM_PARSER_MAX_SNAPSHOT_SIZE: Maximum Data Component snapshots buffered before clearing old ones
261
+ // STREAM_PARSER_MAX_STREAMED_SIZE: Maximum streamed component IDs tracked simultaneously
262
+ // STREAM_PARSER_MAX_COLLECTED_PARTS: Maximum accumulated stream parts before forcing flush
263
+ // STREAM_BUFFER_MAX_SIZE_BYTES: Maximum total buffer size in bytes (prevents memory exhaustion)
264
+ // STREAM_TEXT_GAP_THRESHOLD_MS: Time gap that triggers bundling text with artifact data vs separate send
265
+ // STREAM_MAX_LIFETIME_MS: Maximum duration a stream can stay open before forced closure
266
+ STREAM_PARSER_MAX_SNAPSHOT_SIZE: 100,
267
+ STREAM_PARSER_MAX_STREAMED_SIZE: 1e3,
268
+ STREAM_PARSER_MAX_COLLECTED_PARTS: 1e4,
269
+ STREAM_BUFFER_MAX_SIZE_BYTES: 5242880,
270
+ // 5 MB
271
+ STREAM_TEXT_GAP_THRESHOLD_MS: 2e3,
272
+ // 2 seconds
273
+ STREAM_MAX_LIFETIME_MS: 6e5,
274
+ // 10 minutes
275
+ // Conversation History Message Retrieval
276
+ // CONVERSATION_HISTORY_DEFAULT_LIMIT: Default number of recent conversation messages to retrieve
277
+ CONVERSATION_HISTORY_DEFAULT_LIMIT: 50
278
+ };
279
+ }
280
+ });
281
+ var constantsSchema, parseConstants, constants, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, AGENT_EXECUTION_MAX_GENERATION_STEPS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, A2A_BACKOFF_INITIAL_INTERVAL_MS, A2A_BACKOFF_MAX_INTERVAL_MS, A2A_BACKOFF_EXPONENT, A2A_BACKOFF_MAX_ELAPSED_TIME_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, SESSION_CLEANUP_INTERVAL_MS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_TEXT_GAP_THRESHOLD_MS, STREAM_MAX_LIFETIME_MS, CONVERSATION_HISTORY_DEFAULT_LIMIT;
282
+ var init_execution_limits = __esm({
283
+ "src/constants/execution-limits/index.ts"() {
284
+ init_defaults();
285
+ init_defaults();
286
+ agentsCore.loadEnvironmentFiles();
287
+ constantsSchema = z7.z.object(
288
+ Object.fromEntries(
289
+ Object.keys(executionLimitsDefaults).map((key) => [
290
+ `AGENTS_${key}`,
291
+ z7.z.coerce.number().optional()
292
+ ])
293
+ )
294
+ );
295
+ parseConstants = () => {
296
+ const envOverrides = constantsSchema.parse(process.env);
297
+ return Object.fromEntries(
298
+ Object.entries(executionLimitsDefaults).map(([key, defaultValue]) => [
299
+ key,
300
+ envOverrides[`AGENTS_${key}`] ?? defaultValue
301
+ ])
302
+ );
303
+ };
304
+ constants = parseConstants();
305
+ ({
306
+ AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS,
307
+ AGENT_EXECUTION_MAX_GENERATION_STEPS,
308
+ LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING,
309
+ LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING,
310
+ LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS,
311
+ LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
312
+ FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
313
+ FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT,
314
+ FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
315
+ FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT,
316
+ FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES,
317
+ FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS,
318
+ FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS,
319
+ MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT,
320
+ DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
321
+ DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
322
+ DELEGATION_TOOL_BACKOFF_EXPONENT,
323
+ DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS,
324
+ A2A_BACKOFF_INITIAL_INTERVAL_MS,
325
+ A2A_BACKOFF_MAX_INTERVAL_MS,
326
+ A2A_BACKOFF_EXPONENT,
327
+ A2A_BACKOFF_MAX_ELAPSED_TIME_MS,
328
+ ARTIFACT_GENERATION_MAX_RETRIES,
329
+ ARTIFACT_SESSION_MAX_PENDING,
330
+ ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES,
331
+ ARTIFACT_GENERATION_BACKOFF_INITIAL_MS,
332
+ ARTIFACT_GENERATION_BACKOFF_MAX_MS,
333
+ SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS,
334
+ SESSION_CLEANUP_INTERVAL_MS,
335
+ STATUS_UPDATE_DEFAULT_NUM_EVENTS,
336
+ STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
337
+ STREAM_PARSER_MAX_SNAPSHOT_SIZE,
338
+ STREAM_PARSER_MAX_STREAMED_SIZE,
339
+ STREAM_PARSER_MAX_COLLECTED_PARTS,
340
+ STREAM_BUFFER_MAX_SIZE_BYTES,
341
+ STREAM_TEXT_GAP_THRESHOLD_MS,
342
+ STREAM_MAX_LIFETIME_MS,
343
+ CONVERSATION_HISTORY_DEFAULT_LIMIT
344
+ } = constants);
345
+ }
346
+ });
347
+
150
348
  // src/data/conversations.ts
151
349
  var conversations_exports = {};
152
350
  __export(conversations_exports, {
@@ -161,10 +359,10 @@ __export(conversations_exports, {
161
359
  function createDefaultConversationHistoryConfig(mode = "full") {
162
360
  return {
163
361
  mode,
164
- limit: 50,
362
+ limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
165
363
  includeInternal: true,
166
364
  messageTypes: ["chat"],
167
- maxOutputTokens: 4e3
365
+ maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
168
366
  };
169
367
  }
170
368
  function extractA2AMessageText(parts) {
@@ -253,7 +451,7 @@ async function getScopedHistory({
253
451
  return [];
254
452
  }
255
453
  }
256
- async function getUserFacingHistory(tenantId, projectId, conversationId, limit = 50) {
454
+ async function getUserFacingHistory(tenantId, projectId, conversationId, limit = CONVERSATION_HISTORY_DEFAULT_LIMIT) {
257
455
  return await agentsCore.getConversationHistory(dbClient_default)({
258
456
  scopes: { tenantId, projectId },
259
457
  conversationId,
@@ -383,6 +581,7 @@ async function getConversationScopedArtifacts(params) {
383
581
  }
384
582
  var init_conversations = __esm({
385
583
  "src/data/conversations.ts"() {
584
+ init_execution_limits();
386
585
  init_dbClient();
387
586
  }
388
587
  });
@@ -438,10 +637,12 @@ var init_sandbox_utils = __esm({
438
637
  var logger16, ExecutionSemaphore, _NativeSandboxExecutor, NativeSandboxExecutor;
439
638
  var init_NativeSandboxExecutor = __esm({
440
639
  "src/tools/NativeSandboxExecutor.ts"() {
640
+ init_execution_limits();
641
+ init_logger();
441
642
  init_sandbox_utils();
442
643
  logger16 = agentsCore.getLogger("native-sandbox-executor");
443
644
  ExecutionSemaphore = class {
444
- constructor(permits, maxWaitTimeMs = 3e4) {
645
+ constructor(permits, maxWaitTimeMs = FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS) {
445
646
  __publicField(this, "permits");
446
647
  __publicField(this, "waitQueue", []);
447
648
  __publicField(this, "maxWaitTime");
@@ -496,9 +697,6 @@ var init_NativeSandboxExecutor = __esm({
496
697
  constructor() {
497
698
  __publicField(this, "tempDir");
498
699
  __publicField(this, "sandboxPool", {});
499
- __publicField(this, "POOL_TTL", 5 * 60 * 1e3);
500
- // 5 minutes
501
- __publicField(this, "MAX_USE_COUNT", 50);
502
700
  __publicField(this, "executionSemaphores", /* @__PURE__ */ new Map());
503
701
  this.tempDir = path.join(os.tmpdir(), "inkeep-sandboxes");
504
702
  this.ensureTempDir();
@@ -547,7 +745,7 @@ var init_NativeSandboxExecutor = __esm({
547
745
  const sandbox = this.sandboxPool[poolKey];
548
746
  if (sandbox && fs.existsSync(sandbox.sandboxDir)) {
549
747
  const now = Date.now();
550
- if (now - sandbox.lastUsed < this.POOL_TTL && sandbox.useCount < this.MAX_USE_COUNT) {
748
+ if (now - sandbox.lastUsed < FUNCTION_TOOL_SANDBOX_POOL_TTL_MS && sandbox.useCount < FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
551
749
  sandbox.lastUsed = now;
552
750
  sandbox.useCount++;
553
751
  logger16.debug(
@@ -555,7 +753,7 @@ var init_NativeSandboxExecutor = __esm({
555
753
  poolKey,
556
754
  useCount: sandbox.useCount,
557
755
  sandboxDir: sandbox.sandboxDir,
558
- lastUsed: new Date(sandbox.lastUsed).toISOString()
756
+ lastUsed: new Date(sandbox.lastUsed)
559
757
  },
560
758
  "Reusing cached sandbox"
561
759
  );
@@ -593,7 +791,7 @@ var init_NativeSandboxExecutor = __esm({
593
791
  const now = Date.now();
594
792
  const keysToDelete = [];
595
793
  for (const [key, sandbox] of Object.entries(this.sandboxPool)) {
596
- if (now - sandbox.lastUsed > this.POOL_TTL || sandbox.useCount >= this.MAX_USE_COUNT) {
794
+ if (now - sandbox.lastUsed > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || sandbox.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
597
795
  this.cleanupSandbox(sandbox.sandboxDir);
598
796
  keysToDelete.push(key);
599
797
  }
@@ -604,7 +802,7 @@ var init_NativeSandboxExecutor = __esm({
604
802
  if (keysToDelete.length > 0) {
605
803
  logger16.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
606
804
  }
607
- }, 6e4);
805
+ }, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
608
806
  }
609
807
  detectModuleType(executeCode, configuredRuntime) {
610
808
  const esmPatterns = [
@@ -714,7 +912,7 @@ var init_NativeSandboxExecutor = __esm({
714
912
  fs.writeFileSync(path.join(sandboxDir, `index.${fileExtension}`), executionCode, "utf8");
715
913
  const result = await this.executeInSandbox(
716
914
  sandboxDir,
717
- config.sandboxConfig?.timeout || 3e4,
915
+ config.sandboxConfig?.timeout || FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
718
916
  moduleType,
719
917
  config.sandboxConfig
720
918
  );
@@ -779,13 +977,16 @@ var init_NativeSandboxExecutor = __esm({
779
977
  let stdout = "";
780
978
  let stderr = "";
781
979
  let outputSize = 0;
782
- const MAX_OUTPUT_SIZE = 1024 * 1024;
783
980
  node.stdout?.on("data", (data) => {
784
981
  const dataStr = data.toString();
785
982
  outputSize += dataStr.length;
786
- if (outputSize > MAX_OUTPUT_SIZE) {
983
+ if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
787
984
  node.kill("SIGTERM");
788
- reject(new Error(`Output size exceeded limit of ${MAX_OUTPUT_SIZE} bytes`));
985
+ reject(
986
+ new Error(
987
+ `Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
988
+ )
989
+ );
789
990
  return;
790
991
  }
791
992
  stdout += dataStr;
@@ -793,9 +994,13 @@ var init_NativeSandboxExecutor = __esm({
793
994
  node.stderr?.on("data", (data) => {
794
995
  const dataStr = data.toString();
795
996
  outputSize += dataStr.length;
796
- if (outputSize > MAX_OUTPUT_SIZE) {
997
+ if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
797
998
  node.kill("SIGTERM");
798
- reject(new Error(`Output size exceeded limit of ${MAX_OUTPUT_SIZE} bytes`));
999
+ reject(
1000
+ new Error(
1001
+ `Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
1002
+ )
1003
+ );
799
1004
  return;
800
1005
  }
801
1006
  stderr += dataStr;
@@ -852,6 +1057,7 @@ var init_NativeSandboxExecutor = __esm({
852
1057
  var logger17, _VercelSandboxExecutor, VercelSandboxExecutor;
853
1058
  var init_VercelSandboxExecutor = __esm({
854
1059
  "src/tools/VercelSandboxExecutor.ts"() {
1060
+ init_execution_limits();
855
1061
  init_logger();
856
1062
  init_sandbox_utils();
857
1063
  logger17 = agentsCore.getLogger("VercelSandboxExecutor");
@@ -859,9 +1065,6 @@ var init_VercelSandboxExecutor = __esm({
859
1065
  constructor(config) {
860
1066
  __publicField(this, "config");
861
1067
  __publicField(this, "sandboxPool", /* @__PURE__ */ new Map());
862
- __publicField(this, "POOL_TTL", 5 * 60 * 1e3);
863
- // 5 minutes
864
- __publicField(this, "MAX_USE_COUNT", 50);
865
1068
  __publicField(this, "cleanupInterval", null);
866
1069
  this.config = config;
867
1070
  logger17.info(
@@ -900,14 +1103,14 @@ var init_VercelSandboxExecutor = __esm({
900
1103
  if (!cached) return null;
901
1104
  const now = Date.now();
902
1105
  const age = now - cached.createdAt;
903
- if (age > this.POOL_TTL || cached.useCount >= this.MAX_USE_COUNT) {
1106
+ if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
904
1107
  logger17.debug(
905
1108
  {
906
1109
  dependencyHash,
907
1110
  age,
908
1111
  useCount: cached.useCount,
909
- ttl: this.POOL_TTL,
910
- maxUseCount: this.MAX_USE_COUNT
1112
+ ttl: FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
1113
+ maxUseCount: FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT
911
1114
  },
912
1115
  "Sandbox expired, will create new one"
913
1116
  );
@@ -970,32 +1173,28 @@ var init_VercelSandboxExecutor = __esm({
970
1173
  * Start periodic cleanup of expired sandboxes
971
1174
  */
972
1175
  startPoolCleanup() {
973
- this.cleanupInterval = setInterval(
974
- () => {
975
- const now = Date.now();
976
- const toRemove = [];
977
- for (const [hash, cached] of this.sandboxPool.entries()) {
978
- const age = now - cached.createdAt;
979
- if (age > this.POOL_TTL || cached.useCount >= this.MAX_USE_COUNT) {
980
- toRemove.push(hash);
981
- }
1176
+ this.cleanupInterval = setInterval(() => {
1177
+ const now = Date.now();
1178
+ const toRemove = [];
1179
+ for (const [hash, cached] of this.sandboxPool.entries()) {
1180
+ const age = now - cached.createdAt;
1181
+ if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
1182
+ toRemove.push(hash);
982
1183
  }
983
- if (toRemove.length > 0) {
984
- logger17.info(
985
- {
986
- count: toRemove.length,
987
- poolSize: this.sandboxPool.size
988
- },
989
- "Cleaning up expired sandboxes"
990
- );
991
- for (const hash of toRemove) {
992
- this.removeSandbox(hash);
993
- }
1184
+ }
1185
+ if (toRemove.length > 0) {
1186
+ logger17.info(
1187
+ {
1188
+ count: toRemove.length,
1189
+ poolSize: this.sandboxPool.size
1190
+ },
1191
+ "Cleaning up expired sandboxes"
1192
+ );
1193
+ for (const hash of toRemove) {
1194
+ this.removeSandbox(hash);
994
1195
  }
995
- },
996
- 60 * 1e3
997
- // Run every minute
998
- );
1196
+ }
1197
+ }, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
999
1198
  }
1000
1199
  /**
1001
1200
  * Cleanup all sandboxes and stop cleanup interval
@@ -2552,14 +2751,13 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
2552
2751
  var ModelFactory = _ModelFactory;
2553
2752
 
2554
2753
  // src/agents/ToolSessionManager.ts
2754
+ init_execution_limits();
2555
2755
  init_logger();
2556
2756
  var logger5 = agentsCore.getLogger("ToolSessionManager");
2557
2757
  var _ToolSessionManager = class _ToolSessionManager {
2558
- // 5 minutes
2559
2758
  constructor() {
2560
2759
  __publicField(this, "sessions", /* @__PURE__ */ new Map());
2561
- __publicField(this, "SESSION_TIMEOUT", 5 * 60 * 1e3);
2562
- setInterval(() => this.cleanupExpiredSessions(), 6e4);
2760
+ setInterval(() => this.cleanupExpiredSessions(), SESSION_CLEANUP_INTERVAL_MS);
2563
2761
  }
2564
2762
  static getInstance() {
2565
2763
  if (!_ToolSessionManager.instance) {
@@ -2704,7 +2902,7 @@ var _ToolSessionManager = class _ToolSessionManager {
2704
2902
  const now = Date.now();
2705
2903
  const expiredSessions = [];
2706
2904
  for (const [sessionId, session] of this.sessions.entries()) {
2707
- if (now - session.createdAt > this.SESSION_TIMEOUT) {
2905
+ if (now - session.createdAt > SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS) {
2708
2906
  expiredSessions.push(sessionId);
2709
2907
  }
2710
2908
  }
@@ -2722,6 +2920,7 @@ var ToolSessionManager = _ToolSessionManager;
2722
2920
  var toolSessionManager = ToolSessionManager.getInstance();
2723
2921
 
2724
2922
  // src/services/AgentSession.ts
2923
+ init_execution_limits();
2725
2924
  init_conversations();
2726
2925
  init_dbClient();
2727
2926
  init_logger();
@@ -3889,8 +4088,8 @@ var AgentSession = class {
3889
4088
  // Track pending artifact processing
3890
4089
  __publicField(this, "artifactProcessingErrors", /* @__PURE__ */ new Map());
3891
4090
  // Track errors per artifact
3892
- __publicField(this, "MAX_ARTIFACT_RETRIES", 3);
3893
- __publicField(this, "MAX_PENDING_ARTIFACTS", 100);
4091
+ __publicField(this, "MAX_ARTIFACT_RETRIES", ARTIFACT_GENERATION_MAX_RETRIES);
4092
+ __publicField(this, "MAX_PENDING_ARTIFACTS", ARTIFACT_SESSION_MAX_PENDING);
3894
4093
  // Prevent unbounded growth
3895
4094
  __publicField(this, "scheduledTimeouts");
3896
4095
  // Track scheduled timeouts for cleanup
@@ -4010,8 +4209,8 @@ var AgentSession = class {
4010
4209
  summarizerModel,
4011
4210
  baseModel,
4012
4211
  config: {
4013
- numEvents: config.numEvents || 1,
4014
- timeInSeconds: config.timeInSeconds || 2,
4212
+ numEvents: config.numEvents || STATUS_UPDATE_DEFAULT_NUM_EVENTS,
4213
+ timeInSeconds: config.timeInSeconds || STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
4015
4214
  ...config
4016
4215
  }
4017
4216
  };
@@ -4354,7 +4553,7 @@ var AgentSession = class {
4354
4553
  }
4355
4554
  return;
4356
4555
  }
4357
- if (this.previousSummaries.length > 3) {
4556
+ if (this.previousSummaries.length > ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES) {
4358
4557
  this.previousSummaries.shift();
4359
4558
  }
4360
4559
  if (this.statusUpdateState) {
@@ -4467,9 +4666,8 @@ var AgentSession = class {
4467
4666
  projectId: this.projectId,
4468
4667
  conversationId: this.sessionId,
4469
4668
  options: {
4470
- limit: 10,
4471
- // Get recent conversation context
4472
- maxOutputTokens: 2e3
4669
+ limit: agentsCore.CONVERSATION_HISTORY_DEFAULT_LIMIT,
4670
+ maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
4473
4671
  },
4474
4672
  filters: {}
4475
4673
  });
@@ -4488,12 +4686,12 @@ ${conversationHistory}
4488
4686
  Previous updates sent to user:
4489
4687
  ${previousSummaries.map((s, i) => `${i + 1}. ${s}`).join("\n")}
4490
4688
  ` : "";
4491
- const selectionSchema = z6.z.object(
4689
+ const selectionSchema = z7.z.object(
4492
4690
  Object.fromEntries([
4493
4691
  [
4494
4692
  "no_relevant_updates",
4495
- z6.z.object({
4496
- no_updates: z6.z.boolean().default(true)
4693
+ z7.z.object({
4694
+ no_updates: z7.z.boolean().default(true)
4497
4695
  }).optional().describe(
4498
4696
  "Use when nothing substantially new to report. Should only use on its own."
4499
4697
  )
@@ -4625,8 +4823,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
4625
4823
  if (component.detailsSchema && "properties" in component.detailsSchema) {
4626
4824
  return this.buildZodSchemaFromJson(component.detailsSchema);
4627
4825
  }
4628
- return z6.z.object({
4629
- label: z6.z.string().describe(
4826
+ return z7.z.object({
4827
+ label: z7.z.string().describe(
4630
4828
  '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.'
4631
4829
  )
4632
4830
  });
@@ -4636,56 +4834,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
4636
4834
  */
4637
4835
  buildZodSchemaFromJson(jsonSchema) {
4638
4836
  const properties = {};
4639
- properties.label = z6.z.string().describe(
4837
+ properties.label = z7.z.string().describe(
4640
4838
  '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.'
4641
4839
  );
4642
4840
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
4643
4841
  let zodType;
4644
4842
  if (value.enum && Array.isArray(value.enum)) {
4645
4843
  if (value.enum.length === 1) {
4646
- zodType = z6.z.literal(value.enum[0]);
4844
+ zodType = z7.z.literal(value.enum[0]);
4647
4845
  } else {
4648
4846
  const [first, ...rest] = value.enum;
4649
- zodType = z6.z.enum([first, ...rest]);
4847
+ zodType = z7.z.enum([first, ...rest]);
4650
4848
  }
4651
4849
  } else if (value.type === "string") {
4652
- zodType = z6.z.string();
4850
+ zodType = z7.z.string();
4653
4851
  if (value.minLength) zodType = zodType.min(value.minLength);
4654
4852
  if (value.maxLength) zodType = zodType.max(value.maxLength);
4655
4853
  if (value.format === "email") zodType = zodType.email();
4656
4854
  if (value.format === "url" || value.format === "uri")
4657
4855
  zodType = zodType.url();
4658
4856
  } else if (value.type === "number" || value.type === "integer") {
4659
- zodType = value.type === "integer" ? z6.z.number().int() : z6.z.number();
4857
+ zodType = value.type === "integer" ? z7.z.number().int() : z7.z.number();
4660
4858
  if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
4661
4859
  if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
4662
4860
  } else if (value.type === "boolean") {
4663
- zodType = z6.z.boolean();
4861
+ zodType = z7.z.boolean();
4664
4862
  } else if (value.type === "array") {
4665
4863
  if (value.items) {
4666
4864
  if (value.items.enum && Array.isArray(value.items.enum)) {
4667
4865
  const [first, ...rest] = value.items.enum;
4668
- zodType = z6.z.array(z6.z.enum([first, ...rest]));
4866
+ zodType = z7.z.array(z7.z.enum([first, ...rest]));
4669
4867
  } else if (value.items.type === "string") {
4670
- zodType = z6.z.array(z6.z.string());
4868
+ zodType = z7.z.array(z7.z.string());
4671
4869
  } else if (value.items.type === "number") {
4672
- zodType = z6.z.array(z6.z.number());
4870
+ zodType = z7.z.array(z7.z.number());
4673
4871
  } else if (value.items.type === "boolean") {
4674
- zodType = z6.z.array(z6.z.boolean());
4872
+ zodType = z7.z.array(z7.z.boolean());
4675
4873
  } else if (value.items.type === "object") {
4676
- zodType = z6.z.array(z6.z.record(z6.z.string(), z6.z.any()));
4874
+ zodType = z7.z.array(z7.z.record(z7.z.string(), z7.z.any()));
4677
4875
  } else {
4678
- zodType = z6.z.array(z6.z.any());
4876
+ zodType = z7.z.array(z7.z.any());
4679
4877
  }
4680
4878
  } else {
4681
- zodType = z6.z.array(z6.z.any());
4879
+ zodType = z7.z.array(z7.z.any());
4682
4880
  }
4683
4881
  if (value.minItems) zodType = zodType.min(value.minItems);
4684
4882
  if (value.maxItems) zodType = zodType.max(value.maxItems);
4685
4883
  } else if (value.type === "object") {
4686
- zodType = z6.z.record(z6.z.string(), z6.z.any());
4884
+ zodType = z7.z.record(z7.z.string(), z7.z.any());
4687
4885
  } else {
4688
- zodType = z6.z.any();
4886
+ zodType = z7.z.any();
4689
4887
  }
4690
4888
  if (value.description) {
4691
4889
  zodType = zodType.describe(value.description);
@@ -4695,7 +4893,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
4695
4893
  }
4696
4894
  properties[key] = zodType;
4697
4895
  }
4698
- return z6.z.object(properties);
4896
+ return z7.z.object(properties);
4699
4897
  }
4700
4898
  /**
4701
4899
  * Extract user-visible activities with rich formatting and complete information
@@ -4926,9 +5124,9 @@ Make it specific and relevant.`;
4926
5124
  };
4927
5125
  } else {
4928
5126
  const model = ModelFactory.createModel(modelToUse);
4929
- const schema = z6.z.object({
4930
- name: z6.z.string().describe("Concise, descriptive name for the artifact"),
4931
- description: z6.z.string().describe("Brief description of the artifact's relevance to the user's question")
5127
+ const schema = z7.z.object({
5128
+ name: z7.z.string().describe("Concise, descriptive name for the artifact"),
5129
+ description: z7.z.string().describe("Brief description of the artifact's relevance to the user's question")
4932
5130
  });
4933
5131
  const { object } = await tracer.startActiveSpan(
4934
5132
  "agent_session.generate_artifact_metadata",
@@ -4998,7 +5196,10 @@ Make it specific and relevant.`;
4998
5196
  `Artifact name/description generation failed, attempt ${attempt}/${maxRetries}`
4999
5197
  );
5000
5198
  if (attempt < maxRetries) {
5001
- const backoffMs = Math.min(1e3 * 2 ** (attempt - 1), 1e4);
5199
+ const backoffMs = Math.min(
5200
+ ARTIFACT_GENERATION_BACKOFF_INITIAL_MS * 2 ** (attempt - 1),
5201
+ ARTIFACT_GENERATION_BACKOFF_MAX_MS
5202
+ );
5002
5203
  await new Promise((resolve) => setTimeout(resolve, backoffMs));
5003
5204
  }
5004
5205
  }
@@ -5316,11 +5517,13 @@ async function resolveModelConfig(agentId, subAgent) {
5316
5517
  }
5317
5518
 
5318
5519
  // src/agents/Agent.ts
5520
+ init_execution_limits();
5319
5521
  init_conversations();
5320
5522
  init_dbClient();
5321
5523
  init_logger();
5322
5524
 
5323
5525
  // src/services/IncrementalStreamParser.ts
5526
+ init_execution_limits();
5324
5527
  init_logger();
5325
5528
  var logger10 = agentsCore.getLogger("IncrementalStreamParser");
5326
5529
  var _IncrementalStreamParser = class _IncrementalStreamParser {
@@ -5715,11 +5918,11 @@ ${chunk}`;
5715
5918
  }
5716
5919
  }
5717
5920
  };
5718
- __publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE", 100);
5921
+ __publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE", STREAM_PARSER_MAX_SNAPSHOT_SIZE);
5719
5922
  // Max number of snapshots to keep
5720
- __publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE", 1e3);
5923
+ __publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE", STREAM_PARSER_MAX_STREAMED_SIZE);
5721
5924
  // Max number of streamed component IDs to track
5722
- __publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", 1e4);
5925
+ __publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", STREAM_PARSER_MAX_COLLECTED_PARTS);
5723
5926
  var IncrementalStreamParser = _IncrementalStreamParser;
5724
5927
 
5725
5928
  // src/services/ResponseFormatter.ts
@@ -5925,7 +6128,7 @@ var logger12 = agentsCore.getLogger("DataComponentSchema");
5925
6128
  function jsonSchemaToZod(jsonSchema) {
5926
6129
  if (!jsonSchema || typeof jsonSchema !== "object") {
5927
6130
  logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
5928
- return z6.z.string();
6131
+ return z7.z.string();
5929
6132
  }
5930
6133
  switch (jsonSchema.type) {
5931
6134
  case "object":
@@ -5934,22 +6137,22 @@ function jsonSchemaToZod(jsonSchema) {
5934
6137
  for (const [key, prop] of Object.entries(jsonSchema.properties)) {
5935
6138
  shape[key] = jsonSchemaToZod(prop);
5936
6139
  }
5937
- return z6.z.object(shape);
6140
+ return z7.z.object(shape);
5938
6141
  }
5939
- return z6.z.record(z6.z.string(), z6.z.unknown());
6142
+ return z7.z.record(z7.z.string(), z7.z.unknown());
5940
6143
  case "array": {
5941
- const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z6.z.unknown();
5942
- return z6.z.array(itemSchema);
6144
+ const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z7.z.unknown();
6145
+ return z7.z.array(itemSchema);
5943
6146
  }
5944
6147
  case "string":
5945
- return z6.z.string();
6148
+ return z7.z.string();
5946
6149
  case "number":
5947
6150
  case "integer":
5948
- return z6.z.number();
6151
+ return z7.z.number();
5949
6152
  case "boolean":
5950
- return z6.z.boolean();
6153
+ return z7.z.boolean();
5951
6154
  case "null":
5952
- return z6.z.null();
6155
+ return z7.z.null();
5953
6156
  default:
5954
6157
  logger12.warn(
5955
6158
  {
@@ -5958,7 +6161,7 @@ function jsonSchemaToZod(jsonSchema) {
5958
6161
  },
5959
6162
  "Unsupported JSON schema type, using unknown validation"
5960
6163
  );
5961
- return z6.z.unknown();
6164
+ return z7.z.unknown();
5962
6165
  }
5963
6166
  }
5964
6167
 
@@ -6191,9 +6394,9 @@ var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
6191
6394
  * Get the standard Zod schema for artifact reference components
6192
6395
  */
6193
6396
  static getSchema() {
6194
- return z6.z.object({
6195
- id: z6.z.string(),
6196
- name: z6.z.literal("Artifact"),
6397
+ return z7.z.object({
6398
+ id: z7.z.string(),
6399
+ name: z7.z.literal("Artifact"),
6197
6400
  props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
6198
6401
  });
6199
6402
  }
@@ -6260,9 +6463,9 @@ var ArtifactCreateSchema = class {
6260
6463
  },
6261
6464
  required: ["id", "tool_call_id", "type", "base_selector"]
6262
6465
  };
6263
- return z6.z.object({
6264
- id: z6.z.string(),
6265
- name: z6.z.literal(`ArtifactCreate_${component.name}`),
6466
+ return z7.z.object({
6467
+ id: z7.z.string(),
6468
+ name: z7.z.literal(`ArtifactCreate_${component.name}`),
6266
6469
  props: jsonSchemaToZod(propsSchema)
6267
6470
  });
6268
6471
  });
@@ -6934,10 +7137,12 @@ var A2AClient = class {
6934
7137
  };
6935
7138
 
6936
7139
  // src/agents/relationTools.ts
7140
+ init_execution_limits();
6937
7141
  init_conversations();
6938
7142
  init_dbClient();
6939
7143
  init_logger();
6940
7144
  var logger14 = agentsCore.getLogger("relationships Tools");
7145
+ var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
6941
7146
  var generateTransferToolDescription = (config) => {
6942
7147
  let toolsSection = "";
6943
7148
  let transferSection = "";
@@ -7038,7 +7243,7 @@ var createTransferToAgentTool = ({
7038
7243
  const toolDescription = generateTransferToolDescription(transferConfig);
7039
7244
  return ai.tool({
7040
7245
  description: toolDescription,
7041
- inputSchema: z6__default.default.object({}),
7246
+ inputSchema: z7__default.default.object({}),
7042
7247
  execute: async () => {
7043
7248
  const activeSpan = api.trace.getActiveSpan();
7044
7249
  if (activeSpan) {
@@ -7093,7 +7298,7 @@ function createDelegateToAgentTool({
7093
7298
  }) {
7094
7299
  return ai.tool({
7095
7300
  description: generateDelegateToolDescription(delegateConfig),
7096
- inputSchema: z6__default.default.object({ message: z6__default.default.string() }),
7301
+ inputSchema: z7__default.default.object({ message: z7__default.default.string() }),
7097
7302
  execute: async (input, context) => {
7098
7303
  const delegationId = `del_${agentsCore.generateId()}`;
7099
7304
  const activeSpan = api.trace.getActiveSpan();
@@ -7190,13 +7395,12 @@ function createDelegateToAgentTool({
7190
7395
  retryConfig: {
7191
7396
  strategy: "backoff",
7192
7397
  retryConnectionErrors: true,
7193
- statusCodes: ["429", "500", "502", "503", "504"],
7398
+ statusCodes: [...A2A_RETRY_STATUS_CODES],
7194
7399
  backoff: {
7195
- initialInterval: 100,
7196
- maxInterval: 1e4,
7197
- exponent: 2,
7198
- maxElapsedTime: 2e4
7199
- // 1 minute max retry time
7400
+ initialInterval: DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
7401
+ maxInterval: DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
7402
+ exponent: DELEGATION_TOOL_BACKOFF_EXPONENT,
7403
+ maxElapsedTime: DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS
7200
7404
  }
7201
7405
  }
7202
7406
  });
@@ -8371,12 +8575,6 @@ function hasToolCallWithPrefix(prefix) {
8371
8575
  };
8372
8576
  }
8373
8577
  var logger19 = agentsCore.getLogger("Agent");
8374
- var CONSTANTS = {
8375
- MAX_GENERATION_STEPS: 12,
8376
- PHASE_1_TIMEOUT_MS: 27e4,
8377
- NON_STREAMING_PHASE_1_TIMEOUT_MS: 9e4,
8378
- PHASE_2_TIMEOUT_MS: 9e4
8379
- };
8380
8578
  function validateModel(modelString, modelType) {
8381
8579
  if (!modelString?.trim()) {
8382
8580
  throw new Error(
@@ -8445,10 +8643,10 @@ var Agent = class {
8445
8643
  }
8446
8644
  /**
8447
8645
  * Get the maximum number of generation steps for this agent
8448
- * Uses agent's stopWhen.stepCountIs config or defaults to CONSTANTS.MAX_GENERATION_STEPS
8646
+ * Uses agent's stopWhen.stepCountIs config or defaults to AGENT_EXECUTION_MAX_GENERATION_STEPS
8449
8647
  */
8450
8648
  getMaxGenerationSteps() {
8451
- return this.config.stopWhen?.stepCountIs ?? CONSTANTS.MAX_GENERATION_STEPS;
8649
+ return this.config.stopWhen?.stepCountIs ?? AGENT_EXECUTION_MAX_GENERATION_STEPS;
8452
8650
  }
8453
8651
  /**
8454
8652
  * Sanitizes tool names at runtime for AI SDK compatibility.
@@ -9004,8 +9202,8 @@ var Agent = class {
9004
9202
  const defaultSandboxConfig = {
9005
9203
  provider: "native",
9006
9204
  runtime: "node22",
9007
- timeout: 3e4,
9008
- vcpus: 4
9205
+ timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
9206
+ vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
9009
9207
  };
9010
9208
  const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
9011
9209
  description: functionToolDef.description || functionToolDef.name,
@@ -9306,9 +9504,9 @@ var Agent = class {
9306
9504
  getArtifactTools() {
9307
9505
  return ai.tool({
9308
9506
  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.",
9309
- inputSchema: z6.z.object({
9310
- artifactId: z6.z.string().describe("The unique identifier of the artifact to get."),
9311
- toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
9507
+ inputSchema: z7.z.object({
9508
+ artifactId: z7.z.string().describe("The unique identifier of the artifact to get."),
9509
+ toolCallId: z7.z.string().describe("The tool call ID associated with this artifact.")
9312
9510
  }),
9313
9511
  execute: async ({ artifactId, toolCallId }) => {
9314
9512
  logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
@@ -9335,9 +9533,9 @@ var Agent = class {
9335
9533
  createThinkingCompleteTool() {
9336
9534
  return ai.tool({
9337
9535
  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.",
9338
- inputSchema: z6.z.object({
9339
- complete: z6.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
9340
- summary: z6.z.string().describe(
9536
+ inputSchema: z7.z.object({
9537
+ complete: z7.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
9538
+ summary: z7.z.string().describe(
9341
9539
  "Brief summary of what information was gathered and why it is sufficient to answer the user"
9342
9540
  )
9343
9541
  }),
@@ -9694,15 +9892,14 @@ var Agent = class {
9694
9892
  let textResponse;
9695
9893
  const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
9696
9894
  const shouldStreamPhase1 = this.getStreamingHelper() && !hasStructuredOutput;
9697
- const MAX_ALLOWED_TIMEOUT_MS = 6e5;
9698
- const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
9699
- const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
9700
- if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
9895
+ const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING : LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING;
9896
+ const timeoutMs = Math.min(configuredTimeout, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS);
9897
+ if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
9701
9898
  logger19.warn(
9702
9899
  {
9703
9900
  requestedTimeout: modelSettings.maxDuration * 1e3,
9704
9901
  appliedTimeout: timeoutMs,
9705
- maxAllowed: MAX_ALLOWED_TIMEOUT_MS
9902
+ maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
9706
9903
  },
9707
9904
  "Requested timeout exceeded maximum allowed, capping to 10 minutes"
9708
9905
  );
@@ -9978,9 +10175,9 @@ ${output}${structureHintsFormatted}`;
9978
10175
  this.config.dataComponents.forEach((dc) => {
9979
10176
  const propsSchema = jsonSchemaToZod(dc.props);
9980
10177
  componentSchemas.push(
9981
- z6.z.object({
9982
- id: z6.z.string(),
9983
- name: z6.z.literal(dc.name),
10178
+ z7.z.object({
10179
+ id: z7.z.string(),
10180
+ name: z7.z.literal(dc.name),
9984
10181
  props: propsSchema
9985
10182
  })
9986
10183
  );
@@ -9997,14 +10194,32 @@ ${output}${structureHintsFormatted}`;
9997
10194
  if (componentSchemas.length === 1) {
9998
10195
  dataComponentsSchema = componentSchemas[0];
9999
10196
  } else {
10000
- dataComponentsSchema = z6.z.union(
10197
+ dataComponentsSchema = z7.z.union(
10001
10198
  componentSchemas
10002
10199
  );
10003
10200
  }
10004
10201
  const structuredModelSettings = ModelFactory.prepareGenerationConfig(
10005
10202
  this.getStructuredOutputModel()
10006
10203
  );
10007
- const phase2TimeoutMs = structuredModelSettings.maxDuration ? structuredModelSettings.maxDuration * 1e3 : CONSTANTS.PHASE_2_TIMEOUT_MS;
10204
+ const configuredPhase2Timeout = structuredModelSettings.maxDuration ? Math.min(
10205
+ structuredModelSettings.maxDuration * 1e3,
10206
+ LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
10207
+ ) : LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS;
10208
+ const phase2TimeoutMs = Math.min(
10209
+ configuredPhase2Timeout,
10210
+ LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
10211
+ );
10212
+ if (structuredModelSettings.maxDuration && structuredModelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
10213
+ logger19.warn(
10214
+ {
10215
+ requestedTimeout: structuredModelSettings.maxDuration * 1e3,
10216
+ appliedTimeout: phase2TimeoutMs,
10217
+ maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
10218
+ phase: "structured_generation"
10219
+ },
10220
+ "Phase 2 requested timeout exceeded maximum allowed, capping to 10 minutes"
10221
+ );
10222
+ }
10008
10223
  const shouldStreamPhase2 = this.getStreamingHelper();
10009
10224
  if (shouldStreamPhase2) {
10010
10225
  const phase2Messages = [
@@ -10021,8 +10236,8 @@ ${output}${structureHintsFormatted}`;
10021
10236
  const streamResult = ai.streamObject({
10022
10237
  ...structuredModelSettings,
10023
10238
  messages: phase2Messages,
10024
- schema: z6.z.object({
10025
- dataComponents: z6.z.array(dataComponentsSchema)
10239
+ schema: z7.z.object({
10240
+ dataComponents: z7.z.array(dataComponentsSchema)
10026
10241
  }),
10027
10242
  experimental_telemetry: {
10028
10243
  isEnabled: true,
@@ -10092,8 +10307,8 @@ ${output}${structureHintsFormatted}`;
10092
10307
  withJsonPostProcessing2({
10093
10308
  ...structuredModelSettings,
10094
10309
  messages: phase2Messages,
10095
- schema: z6.z.object({
10096
- dataComponents: z6.z.array(dataComponentsSchema)
10310
+ schema: z7.z.object({
10311
+ dataComponents: z7.z.array(dataComponentsSchema)
10097
10312
  }),
10098
10313
  experimental_telemetry: {
10099
10314
  isEnabled: true,
@@ -10925,14 +11140,14 @@ app.openapi(
10925
11140
  description: "Agent Card for A2A discovery",
10926
11141
  content: {
10927
11142
  "application/json": {
10928
- schema: z6.z.object({
10929
- name: z6.z.string(),
10930
- description: z6.z.string().optional(),
10931
- url: z6.z.string(),
10932
- version: z6.z.string(),
10933
- defaultInputModes: z6.z.array(z6.z.string()),
10934
- defaultOutputModes: z6.z.array(z6.z.string()),
10935
- skills: z6.z.array(z6.z.any())
11143
+ schema: z7.z.object({
11144
+ name: z7.z.string(),
11145
+ description: z7.z.string().optional(),
11146
+ url: z7.z.string(),
11147
+ version: z7.z.string(),
11148
+ defaultInputModes: z7.z.array(z7.z.string()),
11149
+ defaultOutputModes: z7.z.array(z7.z.string()),
11150
+ skills: z7.z.array(z7.z.any())
10936
11151
  })
10937
11152
  }
10938
11153
  }
@@ -11179,8 +11394,12 @@ async function executeTransfer({
11179
11394
  }
11180
11395
 
11181
11396
  // src/handlers/executionHandler.ts
11397
+ init_execution_limits();
11182
11398
  init_dbClient();
11183
11399
  init_logger();
11400
+
11401
+ // src/utils/stream-helpers.ts
11402
+ init_execution_limits();
11184
11403
  var SSEStreamHelper = class {
11185
11404
  constructor(stream2, requestId2, timestamp) {
11186
11405
  this.stream = stream2;
@@ -11353,7 +11572,6 @@ function createSSEStreamHelper(stream2, requestId2, timestamp) {
11353
11572
  return new SSEStreamHelper(stream2, requestId2, timestamp);
11354
11573
  }
11355
11574
  var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11356
- // 10 minutes max lifetime
11357
11575
  constructor(writer) {
11358
11576
  this.writer = writer;
11359
11577
  __publicField(this, "textId", null);
@@ -11363,18 +11581,14 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11363
11581
  __publicField(this, "completedItems", /* @__PURE__ */ new Set());
11364
11582
  // Track completed items
11365
11583
  __publicField(this, "sessionId");
11366
- // 5MB limit (more generous during request)
11367
11584
  __publicField(this, "isCompleted", false);
11368
11585
  __publicField(this, "isTextStreaming", false);
11369
11586
  __publicField(this, "queuedEvents", []);
11370
11587
  __publicField(this, "lastTextEndTimestamp", 0);
11371
- __publicField(this, "TEXT_GAP_THRESHOLD", 2e3);
11372
- // milliseconds - if gap between text sequences is less than this, queue operations
11373
11588
  __publicField(this, "connectionDropTimer");
11374
- __publicField(this, "MAX_LIFETIME_MS", 6e5);
11375
11589
  this.connectionDropTimer = setTimeout(() => {
11376
11590
  this.forceCleanup("Connection lifetime exceeded");
11377
- }, this.MAX_LIFETIME_MS);
11591
+ }, STREAM_MAX_LIFETIME_MS);
11378
11592
  }
11379
11593
  setSessionId(sessionId) {
11380
11594
  this.sessionId = sessionId;
@@ -11428,7 +11642,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11428
11642
  const id = this.textId;
11429
11643
  const startTime = Date.now();
11430
11644
  const gapFromLastSequence = this.lastTextEndTimestamp > 0 ? startTime - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
11431
- if (gapFromLastSequence >= this.TEXT_GAP_THRESHOLD) {
11645
+ if (gapFromLastSequence >= STREAM_TEXT_GAP_THRESHOLD_MS) {
11432
11646
  await this.flushQueuedOperations();
11433
11647
  }
11434
11648
  this.isTextStreaming = true;
@@ -11462,7 +11676,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11462
11676
  if (type === "data-artifact") {
11463
11677
  const now = Date.now();
11464
11678
  const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
11465
- if (this.isTextStreaming || gapFromLastTextEnd < this.TEXT_GAP_THRESHOLD) {
11679
+ if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
11466
11680
  this.writer.write({
11467
11681
  type: `${type}`,
11468
11682
  data
@@ -11615,7 +11829,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11615
11829
  }
11616
11830
  const now = Date.now();
11617
11831
  const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
11618
- if (this.isTextStreaming || gapFromLastTextEnd < this.TEXT_GAP_THRESHOLD) {
11832
+ if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
11619
11833
  this.queuedEvents.push({ type: "data-summary", event: summary });
11620
11834
  return;
11621
11835
  }
@@ -11633,7 +11847,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11633
11847
  }
11634
11848
  const now = Date.now();
11635
11849
  const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
11636
- if (this.isTextStreaming || gapFromLastTextEnd < this.TEXT_GAP_THRESHOLD) {
11850
+ if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
11637
11851
  this.queuedEvents.push({ type: "data-operation", event: operation });
11638
11852
  return;
11639
11853
  }
@@ -11676,7 +11890,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
11676
11890
  this.cleanup();
11677
11891
  }
11678
11892
  };
11679
- __publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE", 5 * 1024 * 1024);
11893
+ __publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE", STREAM_BUFFER_MAX_SIZE_BYTES);
11680
11894
  var VercelDataStreamHelper = _VercelDataStreamHelper;
11681
11895
  function createVercelStreamHelper(writer) {
11682
11896
  return new VercelDataStreamHelper(writer);
@@ -11748,7 +11962,7 @@ var createMCPStreamHelper = createBufferingStreamHelper;
11748
11962
  var logger24 = agentsCore.getLogger("ExecutionHandler");
11749
11963
  var ExecutionHandler = class {
11750
11964
  constructor() {
11751
- __publicField(this, "MAX_ERRORS", 3);
11965
+ __publicField(this, "MAX_ERRORS", AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS);
11752
11966
  }
11753
11967
  /**
11754
11968
  * performs exeuction loop
@@ -11845,7 +12059,7 @@ var ExecutionHandler = class {
11845
12059
  "Task created with metadata"
11846
12060
  );
11847
12061
  } catch (error) {
11848
- if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
12062
+ if (error?.cause?.code === "23505") {
11849
12063
  logger24.info(
11850
12064
  { taskId, error: error.message },
11851
12065
  "Task already exists, fetching existing task"
@@ -11868,7 +12082,7 @@ var ExecutionHandler = class {
11868
12082
  }
11869
12083
  logger24.debug(
11870
12084
  {
11871
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
12085
+ timestamp: /* @__PURE__ */ new Date(),
11872
12086
  executionType: "create_initial_task",
11873
12087
  conversationId,
11874
12088
  agentId,
@@ -11882,7 +12096,7 @@ var ExecutionHandler = class {
11882
12096
  );
11883
12097
  if (Array.isArray(task)) task = task[0];
11884
12098
  let currentMessage = userMessage;
11885
- const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
12099
+ const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? agentsCore.AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
11886
12100
  while (iterations < maxTransfers) {
11887
12101
  iterations++;
11888
12102
  logger24.info(
@@ -12081,7 +12295,7 @@ var ExecutionHandler = class {
12081
12295
  status: "completed",
12082
12296
  metadata: {
12083
12297
  ...task.metadata,
12084
- completed_at: (/* @__PURE__ */ new Date()).toISOString(),
12298
+ completed_at: /* @__PURE__ */ new Date(),
12085
12299
  response: {
12086
12300
  text: textContent,
12087
12301
  parts: responseParts,
@@ -12133,7 +12347,7 @@ var ExecutionHandler = class {
12133
12347
  status: "failed",
12134
12348
  metadata: {
12135
12349
  ...task.metadata,
12136
- failed_at: (/* @__PURE__ */ new Date()).toISOString(),
12350
+ failed_at: /* @__PURE__ */ new Date(),
12137
12351
  error: errorMessage2
12138
12352
  }
12139
12353
  }
@@ -12154,7 +12368,7 @@ var ExecutionHandler = class {
12154
12368
  status: "failed",
12155
12369
  metadata: {
12156
12370
  ...task.metadata,
12157
- failed_at: (/* @__PURE__ */ new Date()).toISOString(),
12371
+ failed_at: /* @__PURE__ */ new Date(),
12158
12372
  error: errorMessage
12159
12373
  }
12160
12374
  }
@@ -12176,7 +12390,7 @@ var ExecutionHandler = class {
12176
12390
  status: "failed",
12177
12391
  metadata: {
12178
12392
  ...task.metadata,
12179
- failed_at: (/* @__PURE__ */ new Date()).toISOString(),
12393
+ failed_at: /* @__PURE__ */ new Date(),
12180
12394
  error: errorMessage
12181
12395
  }
12182
12396
  }
@@ -12204,36 +12418,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
12204
12418
  body: {
12205
12419
  content: {
12206
12420
  "application/json": {
12207
- schema: z6.z.object({
12208
- model: z6.z.string().describe("The model to use for the completion"),
12209
- messages: z6.z.array(
12210
- z6.z.object({
12211
- role: z6.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
12212
- content: z6.z.union([
12213
- z6.z.string(),
12214
- z6.z.array(
12215
- z6.z.strictObject({
12216
- type: z6.z.string(),
12217
- text: z6.z.string().optional()
12421
+ schema: z7.z.object({
12422
+ model: z7.z.string().describe("The model to use for the completion"),
12423
+ messages: z7.z.array(
12424
+ z7.z.object({
12425
+ role: z7.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
12426
+ content: z7.z.union([
12427
+ z7.z.string(),
12428
+ z7.z.array(
12429
+ z7.z.strictObject({
12430
+ type: z7.z.string(),
12431
+ text: z7.z.string().optional()
12218
12432
  })
12219
12433
  )
12220
12434
  ]).describe("The message content"),
12221
- name: z6.z.string().optional().describe("The name of the message sender")
12435
+ name: z7.z.string().optional().describe("The name of the message sender")
12222
12436
  })
12223
12437
  ).describe("The conversation messages"),
12224
- temperature: z6.z.number().optional().describe("Controls randomness (0-1)"),
12225
- top_p: z6.z.number().optional().describe("Controls nucleus sampling"),
12226
- n: z6.z.number().optional().describe("Number of completions to generate"),
12227
- stream: z6.z.boolean().optional().describe("Whether to stream the response"),
12228
- max_tokens: z6.z.number().optional().describe("Maximum tokens to generate"),
12229
- presence_penalty: z6.z.number().optional().describe("Presence penalty (-2 to 2)"),
12230
- frequency_penalty: z6.z.number().optional().describe("Frequency penalty (-2 to 2)"),
12231
- logit_bias: z6.z.record(z6.z.string(), z6.z.number()).optional().describe("Token logit bias"),
12232
- user: z6.z.string().optional().describe("User identifier"),
12233
- conversationId: z6.z.string().optional().describe("Conversation ID for multi-turn chat"),
12234
- tools: z6.z.array(z6.z.string()).optional().describe("Available tools"),
12235
- runConfig: z6.z.record(z6.z.string(), z6.z.unknown()).optional().describe("Run configuration"),
12236
- headers: z6.z.record(z6.z.string(), z6.z.unknown()).optional().describe(
12438
+ temperature: z7.z.number().optional().describe("Controls randomness (0-1)"),
12439
+ top_p: z7.z.number().optional().describe("Controls nucleus sampling"),
12440
+ n: z7.z.number().optional().describe("Number of completions to generate"),
12441
+ stream: z7.z.boolean().optional().describe("Whether to stream the response"),
12442
+ max_tokens: z7.z.number().optional().describe("Maximum tokens to generate"),
12443
+ presence_penalty: z7.z.number().optional().describe("Presence penalty (-2 to 2)"),
12444
+ frequency_penalty: z7.z.number().optional().describe("Frequency penalty (-2 to 2)"),
12445
+ logit_bias: z7.z.record(z7.z.string(), z7.z.number()).optional().describe("Token logit bias"),
12446
+ user: z7.z.string().optional().describe("User identifier"),
12447
+ conversationId: z7.z.string().optional().describe("Conversation ID for multi-turn chat"),
12448
+ tools: z7.z.array(z7.z.string()).optional().describe("Available tools"),
12449
+ runConfig: z7.z.record(z7.z.string(), z7.z.unknown()).optional().describe("Run configuration"),
12450
+ headers: z7.z.record(z7.z.string(), z7.z.unknown()).optional().describe(
12237
12451
  "Headers data for template processing (validated against context config schema)"
12238
12452
  )
12239
12453
  })
@@ -12244,14 +12458,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
12244
12458
  responses: {
12245
12459
  200: {
12246
12460
  description: "Streaming chat completion response in Server-Sent Events format",
12247
- headers: z6.z.object({
12248
- "Content-Type": z6.z.string().default("text/event-stream"),
12249
- "Cache-Control": z6.z.string().default("no-cache"),
12250
- Connection: z6.z.string().default("keep-alive")
12461
+ headers: z7.z.object({
12462
+ "Content-Type": z7.z.string().default("text/event-stream"),
12463
+ "Cache-Control": z7.z.string().default("no-cache"),
12464
+ Connection: z7.z.string().default("keep-alive")
12251
12465
  }),
12252
12466
  content: {
12253
12467
  "text/event-stream": {
12254
- schema: z6.z.string().describe("Server-Sent Events stream with chat completion chunks")
12468
+ schema: z7.z.string().describe("Server-Sent Events stream with chat completion chunks")
12255
12469
  }
12256
12470
  }
12257
12471
  },
@@ -12259,13 +12473,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
12259
12473
  description: "Invalid request context or parameters",
12260
12474
  content: {
12261
12475
  "application/json": {
12262
- schema: z6.z.object({
12263
- error: z6.z.string(),
12264
- details: z6.z.array(
12265
- z6.z.object({
12266
- field: z6.z.string(),
12267
- message: z6.z.string(),
12268
- value: z6.z.unknown().optional()
12476
+ schema: z7.z.object({
12477
+ error: z7.z.string(),
12478
+ details: z7.z.array(
12479
+ z7.z.object({
12480
+ field: z7.z.string(),
12481
+ message: z7.z.string(),
12482
+ value: z7.z.unknown().optional()
12269
12483
  })
12270
12484
  ).optional()
12271
12485
  })
@@ -12276,8 +12490,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
12276
12490
  description: "Agent or agent not found",
12277
12491
  content: {
12278
12492
  "application/json": {
12279
- schema: z6.z.object({
12280
- error: z6.z.string()
12493
+ schema: z7.z.object({
12494
+ error: z7.z.string()
12281
12495
  })
12282
12496
  }
12283
12497
  }
@@ -12286,9 +12500,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
12286
12500
  description: "Internal server error",
12287
12501
  content: {
12288
12502
  "application/json": {
12289
- schema: z6.z.object({
12290
- error: z6.z.string(),
12291
- message: z6.z.string()
12503
+ schema: z7.z.object({
12504
+ error: z7.z.string(),
12505
+ message: z7.z.string()
12292
12506
  })
12293
12507
  }
12294
12508
  }
@@ -13000,7 +13214,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
13000
13214
  "send-query-to-agent",
13001
13215
  `Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
13002
13216
  {
13003
- query: z6.z.string().describe("The query to send to the agent")
13217
+ query: z7.z.string().describe("The query to send to the agent")
13004
13218
  },
13005
13219
  async ({ query }) => {
13006
13220
  try {