@inkeep/agents-run-api 0.39.0 → 0.39.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.
- package/dist/index.cjs +74 -30
- package/dist/index.js +73 -27
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32,10 +32,9 @@ var swaggerUi = require('@hono/swagger-ui');
|
|
|
32
32
|
var streaming = require('hono/streaming');
|
|
33
33
|
var ai = require('ai');
|
|
34
34
|
var jmespath = require('jmespath');
|
|
35
|
+
var schemaConversion = require('@inkeep/agents-core/utils/schema-conversion');
|
|
35
36
|
var Ajv = require('ajv');
|
|
36
37
|
var zod = require('zod');
|
|
37
|
-
var destr = require('destr');
|
|
38
|
-
var traverse = require('traverse');
|
|
39
38
|
var mcp_js = require('@alcyone-labs/modelcontextprotocol-sdk/server/mcp.js');
|
|
40
39
|
var streamableHttp_js = require('@alcyone-labs/modelcontextprotocol-sdk/server/streamableHttp.js');
|
|
41
40
|
var fetchToNode = require('fetch-to-node');
|
|
@@ -67,8 +66,6 @@ var schema__namespace = /*#__PURE__*/_interopNamespace(schema);
|
|
|
67
66
|
var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
|
|
68
67
|
var jmespath__default = /*#__PURE__*/_interopDefault(jmespath);
|
|
69
68
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
70
|
-
var destr__default = /*#__PURE__*/_interopDefault(destr);
|
|
71
|
-
var traverse__default = /*#__PURE__*/_interopDefault(traverse);
|
|
72
69
|
|
|
73
70
|
var __defProp = Object.defineProperty;
|
|
74
71
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -13200,16 +13197,6 @@ var ArtifactCreateSchema = class {
|
|
|
13200
13197
|
});
|
|
13201
13198
|
}
|
|
13202
13199
|
};
|
|
13203
|
-
function parseEmbeddedJson(data) {
|
|
13204
|
-
return traverse__default.default(data).map(function(x6) {
|
|
13205
|
-
if (typeof x6 === "string") {
|
|
13206
|
-
const v3 = destr__default.default(x6);
|
|
13207
|
-
if (v3 !== x6 && (Array.isArray(v3) || v3 && typeof v3 === "object")) {
|
|
13208
|
-
this.update(v3);
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
|
-
});
|
|
13212
|
-
}
|
|
13213
13200
|
|
|
13214
13201
|
// src/a2a/client.ts
|
|
13215
13202
|
init_logger();
|
|
@@ -14433,6 +14420,19 @@ var Phase1Config = class _Phase1Config {
|
|
|
14433
14420
|
const firstItem = tools[0];
|
|
14434
14421
|
return "usageGuidelines" in firstItem && !("config" in firstItem);
|
|
14435
14422
|
}
|
|
14423
|
+
normalizeSchema(inputSchema) {
|
|
14424
|
+
if (!inputSchema || typeof inputSchema !== "object") {
|
|
14425
|
+
return inputSchema || {};
|
|
14426
|
+
}
|
|
14427
|
+
if (schemaConversion.isZodSchema(inputSchema)) {
|
|
14428
|
+
try {
|
|
14429
|
+
return schemaConversion.convertZodToJsonSchema(inputSchema);
|
|
14430
|
+
} catch (error) {
|
|
14431
|
+
return {};
|
|
14432
|
+
}
|
|
14433
|
+
}
|
|
14434
|
+
return inputSchema;
|
|
14435
|
+
}
|
|
14436
14436
|
assemble(templates, config) {
|
|
14437
14437
|
const systemPromptTemplate = templates.get("system-prompt");
|
|
14438
14438
|
if (!systemPromptTemplate) {
|
|
@@ -14449,7 +14449,11 @@ var Phase1Config = class _Phase1Config {
|
|
|
14449
14449
|
}
|
|
14450
14450
|
const agentContextSection = this.generateAgentContextSection(config.prompt);
|
|
14451
14451
|
systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
|
|
14452
|
-
const
|
|
14452
|
+
const rawToolData = this.isToolDataArray(config.tools) ? config.tools : _Phase1Config.convertMcpToolsToToolData(config.tools);
|
|
14453
|
+
const toolData = rawToolData.map((tool4) => ({
|
|
14454
|
+
...tool4,
|
|
14455
|
+
inputSchema: this.normalizeSchema(tool4.inputSchema)
|
|
14456
|
+
}));
|
|
14453
14457
|
const hasArtifactComponents = config.artifactComponents && config.artifactComponents.length > 0;
|
|
14454
14458
|
const artifactsSection = this.generateArtifactsSection(
|
|
14455
14459
|
templates,
|
|
@@ -15761,9 +15765,26 @@ var Agent = class {
|
|
|
15761
15765
|
description: originalTool.description,
|
|
15762
15766
|
inputSchema: originalTool.inputSchema,
|
|
15763
15767
|
execute: async (args2, { toolCallId }) => {
|
|
15768
|
+
let processedArgs;
|
|
15769
|
+
try {
|
|
15770
|
+
processedArgs = agentsCore.parseEmbeddedJson(args2);
|
|
15771
|
+
if (JSON.stringify(args2) !== JSON.stringify(processedArgs)) {
|
|
15772
|
+
logger20.warn(
|
|
15773
|
+
{ toolName, toolCallId },
|
|
15774
|
+
"Fixed stringified JSON parameters (indicates schema ambiguity)"
|
|
15775
|
+
);
|
|
15776
|
+
}
|
|
15777
|
+
} catch (error) {
|
|
15778
|
+
logger20.warn(
|
|
15779
|
+
{ toolName, toolCallId, error: error.message },
|
|
15780
|
+
"Failed to parse embedded JSON, using original args"
|
|
15781
|
+
);
|
|
15782
|
+
processedArgs = args2;
|
|
15783
|
+
}
|
|
15784
|
+
const finalArgs = processedArgs;
|
|
15764
15785
|
if (needsApproval) {
|
|
15765
15786
|
logger20.info(
|
|
15766
|
-
{ toolName, toolCallId, args:
|
|
15787
|
+
{ toolName, toolCallId, args: finalArgs },
|
|
15767
15788
|
"Tool requires approval - waiting for user response"
|
|
15768
15789
|
);
|
|
15769
15790
|
const currentSpan = api.trace.getActiveSpan();
|
|
@@ -15837,7 +15858,7 @@ var Agent = class {
|
|
|
15837
15858
|
}
|
|
15838
15859
|
logger20.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
15839
15860
|
try {
|
|
15840
|
-
const rawResult = await originalTool.execute(
|
|
15861
|
+
const rawResult = await originalTool.execute(finalArgs, { toolCallId });
|
|
15841
15862
|
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
15842
15863
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
15843
15864
|
logger20.error(
|
|
@@ -15847,7 +15868,7 @@ var Agent = class {
|
|
|
15847
15868
|
toolSessionManager.recordToolResult(sessionId, {
|
|
15848
15869
|
toolCallId,
|
|
15849
15870
|
toolName,
|
|
15850
|
-
args:
|
|
15871
|
+
args: finalArgs,
|
|
15851
15872
|
result: { error: errorMessage, failed: true },
|
|
15852
15873
|
timestamp: Date.now()
|
|
15853
15874
|
});
|
|
@@ -15880,12 +15901,12 @@ var Agent = class {
|
|
|
15880
15901
|
`Tool "${toolName}" failed: ${errorMessage}. This tool is currently unavailable. Please try a different approach or inform the user of the issue.`
|
|
15881
15902
|
);
|
|
15882
15903
|
}
|
|
15883
|
-
const parsedResult = parseEmbeddedJson(rawResult);
|
|
15904
|
+
const parsedResult = agentsCore.parseEmbeddedJson(rawResult);
|
|
15884
15905
|
const enhancedResult = this.enhanceToolResultWithStructureHints(parsedResult);
|
|
15885
15906
|
toolSessionManager.recordToolResult(sessionId, {
|
|
15886
15907
|
toolCallId,
|
|
15887
15908
|
toolName,
|
|
15888
|
-
args:
|
|
15909
|
+
args: finalArgs,
|
|
15889
15910
|
result: enhancedResult,
|
|
15890
15911
|
timestamp: Date.now()
|
|
15891
15912
|
});
|
|
@@ -16213,8 +16234,25 @@ var Agent = class {
|
|
|
16213
16234
|
description: functionToolDef.description || functionToolDef.name,
|
|
16214
16235
|
inputSchema: zodSchema,
|
|
16215
16236
|
execute: async (args2, { toolCallId }) => {
|
|
16237
|
+
let processedArgs;
|
|
16238
|
+
try {
|
|
16239
|
+
processedArgs = agentsCore.parseEmbeddedJson(args2);
|
|
16240
|
+
if (JSON.stringify(args2) !== JSON.stringify(processedArgs)) {
|
|
16241
|
+
logger20.warn(
|
|
16242
|
+
{ toolName: functionToolDef.name, toolCallId },
|
|
16243
|
+
"Fixed stringified JSON parameters (indicates schema ambiguity)"
|
|
16244
|
+
);
|
|
16245
|
+
}
|
|
16246
|
+
} catch (error) {
|
|
16247
|
+
logger20.warn(
|
|
16248
|
+
{ toolName: functionToolDef.name, toolCallId, error: error.message },
|
|
16249
|
+
"Failed to parse embedded JSON, using original args"
|
|
16250
|
+
);
|
|
16251
|
+
processedArgs = args2;
|
|
16252
|
+
}
|
|
16253
|
+
const finalArgs = processedArgs;
|
|
16216
16254
|
logger20.debug(
|
|
16217
|
-
{ toolName: functionToolDef.name, toolCallId, args:
|
|
16255
|
+
{ toolName: functionToolDef.name, toolCallId, args: finalArgs },
|
|
16218
16256
|
"Function Tool Called"
|
|
16219
16257
|
);
|
|
16220
16258
|
try {
|
|
@@ -16224,17 +16262,21 @@ var Agent = class {
|
|
|
16224
16262
|
timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
16225
16263
|
vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
|
|
16226
16264
|
};
|
|
16227
|
-
const result = await sandboxExecutor.executeFunctionTool(
|
|
16228
|
-
|
|
16229
|
-
|
|
16230
|
-
|
|
16231
|
-
|
|
16232
|
-
|
|
16233
|
-
|
|
16265
|
+
const result = await sandboxExecutor.executeFunctionTool(
|
|
16266
|
+
functionToolDef.id,
|
|
16267
|
+
finalArgs,
|
|
16268
|
+
{
|
|
16269
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
16270
|
+
inputSchema: functionData.inputSchema || {},
|
|
16271
|
+
executeCode: functionData.executeCode,
|
|
16272
|
+
dependencies: functionData.dependencies || {},
|
|
16273
|
+
sandboxConfig: this.config.sandboxConfig || defaultSandboxConfig
|
|
16274
|
+
}
|
|
16275
|
+
);
|
|
16234
16276
|
toolSessionManager.recordToolResult(sessionId || "", {
|
|
16235
16277
|
toolCallId,
|
|
16236
16278
|
toolName: functionToolDef.name,
|
|
16237
|
-
args:
|
|
16279
|
+
args: finalArgs,
|
|
16238
16280
|
result,
|
|
16239
16281
|
timestamp: Date.now()
|
|
16240
16282
|
});
|
|
@@ -16668,7 +16710,7 @@ ${output}`;
|
|
|
16668
16710
|
let parsedForAnalysis = result;
|
|
16669
16711
|
if (typeof result === "string") {
|
|
16670
16712
|
try {
|
|
16671
|
-
parsedForAnalysis = parseEmbeddedJson(result);
|
|
16713
|
+
parsedForAnalysis = agentsCore.parseEmbeddedJson(result);
|
|
16672
16714
|
} catch (_error) {
|
|
16673
16715
|
parsedForAnalysis = result;
|
|
16674
16716
|
}
|
|
@@ -19656,6 +19698,8 @@ var ExecutionHandler = class {
|
|
|
19656
19698
|
throw error;
|
|
19657
19699
|
} finally {
|
|
19658
19700
|
span.end();
|
|
19701
|
+
await new Promise((resolve2) => setImmediate(resolve2));
|
|
19702
|
+
await flushBatchProcessor();
|
|
19659
19703
|
}
|
|
19660
19704
|
});
|
|
19661
19705
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { dbClient_default } from './chunk-EVOISBFH.js';
|
|
|
4
4
|
import { env } from './chunk-KBZIYCPJ.js';
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
6
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-THWNUGWP.js';
|
|
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, getLedgerArtifacts, verifyTempToken, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getUserScopedCredentialReference, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, jsonSchemaToZod, getContextConfigById, getFullAgentDefinition, TemplateEngine, listTaskIdsByContextId, agentHasArtifactComponents, upsertLedgerArtifact, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
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, getLedgerArtifacts, verifyTempToken, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, parseEmbeddedJson, MCPServerType, getUserScopedCredentialReference, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, jsonSchemaToZod, getContextConfigById, getFullAgentDefinition, TemplateEngine, listTaskIdsByContextId, agentHasArtifactComponents, upsertLedgerArtifact, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
8
8
|
import { otel } from '@hono/otel';
|
|
9
9
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
10
10
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -17,11 +17,10 @@ import { swaggerUI } from '@hono/swagger-ui';
|
|
|
17
17
|
import { streamSSE, stream } from 'hono/streaming';
|
|
18
18
|
import { createUIMessageStream, JsonToSseTransformStream, parsePartialJson, generateObject, tool, streamText, generateText, streamObject } from 'ai';
|
|
19
19
|
import jmespath from 'jmespath';
|
|
20
|
+
import { isZodSchema, convertZodToJsonSchema } from '@inkeep/agents-core/utils/schema-conversion';
|
|
20
21
|
import Ajv from 'ajv';
|
|
21
22
|
import { randomUUID } from 'crypto';
|
|
22
23
|
import { z } from 'zod';
|
|
23
|
-
import destr from 'destr';
|
|
24
|
-
import traverse from 'traverse';
|
|
25
24
|
import { McpServer } from '@alcyone-labs/modelcontextprotocol-sdk/server/mcp.js';
|
|
26
25
|
import { StreamableHTTPServerTransport } from '@alcyone-labs/modelcontextprotocol-sdk/server/streamableHttp.js';
|
|
27
26
|
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
@@ -5555,16 +5554,6 @@ var ArtifactCreateSchema = class {
|
|
|
5555
5554
|
});
|
|
5556
5555
|
}
|
|
5557
5556
|
};
|
|
5558
|
-
function parseEmbeddedJson(data) {
|
|
5559
|
-
return traverse(data).map(function(x) {
|
|
5560
|
-
if (typeof x === "string") {
|
|
5561
|
-
const v = destr(x);
|
|
5562
|
-
if (v !== x && (Array.isArray(v) || v && typeof v === "object")) {
|
|
5563
|
-
this.update(v);
|
|
5564
|
-
}
|
|
5565
|
-
}
|
|
5566
|
-
});
|
|
5567
|
-
}
|
|
5568
5557
|
|
|
5569
5558
|
// src/a2a/client.ts
|
|
5570
5559
|
var logger13 = getLogger("a2aClient");
|
|
@@ -6781,6 +6770,19 @@ var Phase1Config = class _Phase1Config {
|
|
|
6781
6770
|
const firstItem = tools[0];
|
|
6782
6771
|
return "usageGuidelines" in firstItem && !("config" in firstItem);
|
|
6783
6772
|
}
|
|
6773
|
+
normalizeSchema(inputSchema) {
|
|
6774
|
+
if (!inputSchema || typeof inputSchema !== "object") {
|
|
6775
|
+
return inputSchema || {};
|
|
6776
|
+
}
|
|
6777
|
+
if (isZodSchema(inputSchema)) {
|
|
6778
|
+
try {
|
|
6779
|
+
return convertZodToJsonSchema(inputSchema);
|
|
6780
|
+
} catch (error) {
|
|
6781
|
+
return {};
|
|
6782
|
+
}
|
|
6783
|
+
}
|
|
6784
|
+
return inputSchema;
|
|
6785
|
+
}
|
|
6784
6786
|
assemble(templates, config) {
|
|
6785
6787
|
const systemPromptTemplate = templates.get("system-prompt");
|
|
6786
6788
|
if (!systemPromptTemplate) {
|
|
@@ -6797,7 +6799,11 @@ var Phase1Config = class _Phase1Config {
|
|
|
6797
6799
|
}
|
|
6798
6800
|
const agentContextSection = this.generateAgentContextSection(config.prompt);
|
|
6799
6801
|
systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
|
|
6800
|
-
const
|
|
6802
|
+
const rawToolData = this.isToolDataArray(config.tools) ? config.tools : _Phase1Config.convertMcpToolsToToolData(config.tools);
|
|
6803
|
+
const toolData = rawToolData.map((tool4) => ({
|
|
6804
|
+
...tool4,
|
|
6805
|
+
inputSchema: this.normalizeSchema(tool4.inputSchema)
|
|
6806
|
+
}));
|
|
6801
6807
|
const hasArtifactComponents = config.artifactComponents && config.artifactComponents.length > 0;
|
|
6802
6808
|
const artifactsSection = this.generateArtifactsSection(
|
|
6803
6809
|
templates,
|
|
@@ -8109,9 +8115,26 @@ var Agent = class {
|
|
|
8109
8115
|
description: originalTool.description,
|
|
8110
8116
|
inputSchema: originalTool.inputSchema,
|
|
8111
8117
|
execute: async (args, { toolCallId }) => {
|
|
8118
|
+
let processedArgs;
|
|
8119
|
+
try {
|
|
8120
|
+
processedArgs = parseEmbeddedJson(args);
|
|
8121
|
+
if (JSON.stringify(args) !== JSON.stringify(processedArgs)) {
|
|
8122
|
+
logger16.warn(
|
|
8123
|
+
{ toolName, toolCallId },
|
|
8124
|
+
"Fixed stringified JSON parameters (indicates schema ambiguity)"
|
|
8125
|
+
);
|
|
8126
|
+
}
|
|
8127
|
+
} catch (error) {
|
|
8128
|
+
logger16.warn(
|
|
8129
|
+
{ toolName, toolCallId, error: error.message },
|
|
8130
|
+
"Failed to parse embedded JSON, using original args"
|
|
8131
|
+
);
|
|
8132
|
+
processedArgs = args;
|
|
8133
|
+
}
|
|
8134
|
+
const finalArgs = processedArgs;
|
|
8112
8135
|
if (needsApproval) {
|
|
8113
8136
|
logger16.info(
|
|
8114
|
-
{ toolName, toolCallId, args },
|
|
8137
|
+
{ toolName, toolCallId, args: finalArgs },
|
|
8115
8138
|
"Tool requires approval - waiting for user response"
|
|
8116
8139
|
);
|
|
8117
8140
|
const currentSpan = trace.getActiveSpan();
|
|
@@ -8185,7 +8208,7 @@ var Agent = class {
|
|
|
8185
8208
|
}
|
|
8186
8209
|
logger16.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
8187
8210
|
try {
|
|
8188
|
-
const rawResult = await originalTool.execute(
|
|
8211
|
+
const rawResult = await originalTool.execute(finalArgs, { toolCallId });
|
|
8189
8212
|
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
8190
8213
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
8191
8214
|
logger16.error(
|
|
@@ -8195,7 +8218,7 @@ var Agent = class {
|
|
|
8195
8218
|
toolSessionManager.recordToolResult(sessionId, {
|
|
8196
8219
|
toolCallId,
|
|
8197
8220
|
toolName,
|
|
8198
|
-
args,
|
|
8221
|
+
args: finalArgs,
|
|
8199
8222
|
result: { error: errorMessage, failed: true },
|
|
8200
8223
|
timestamp: Date.now()
|
|
8201
8224
|
});
|
|
@@ -8233,7 +8256,7 @@ var Agent = class {
|
|
|
8233
8256
|
toolSessionManager.recordToolResult(sessionId, {
|
|
8234
8257
|
toolCallId,
|
|
8235
8258
|
toolName,
|
|
8236
|
-
args,
|
|
8259
|
+
args: finalArgs,
|
|
8237
8260
|
result: enhancedResult,
|
|
8238
8261
|
timestamp: Date.now()
|
|
8239
8262
|
});
|
|
@@ -8561,8 +8584,25 @@ var Agent = class {
|
|
|
8561
8584
|
description: functionToolDef.description || functionToolDef.name,
|
|
8562
8585
|
inputSchema: zodSchema,
|
|
8563
8586
|
execute: async (args, { toolCallId }) => {
|
|
8587
|
+
let processedArgs;
|
|
8588
|
+
try {
|
|
8589
|
+
processedArgs = parseEmbeddedJson(args);
|
|
8590
|
+
if (JSON.stringify(args) !== JSON.stringify(processedArgs)) {
|
|
8591
|
+
logger16.warn(
|
|
8592
|
+
{ toolName: functionToolDef.name, toolCallId },
|
|
8593
|
+
"Fixed stringified JSON parameters (indicates schema ambiguity)"
|
|
8594
|
+
);
|
|
8595
|
+
}
|
|
8596
|
+
} catch (error) {
|
|
8597
|
+
logger16.warn(
|
|
8598
|
+
{ toolName: functionToolDef.name, toolCallId, error: error.message },
|
|
8599
|
+
"Failed to parse embedded JSON, using original args"
|
|
8600
|
+
);
|
|
8601
|
+
processedArgs = args;
|
|
8602
|
+
}
|
|
8603
|
+
const finalArgs = processedArgs;
|
|
8564
8604
|
logger16.debug(
|
|
8565
|
-
{ toolName: functionToolDef.name, toolCallId, args },
|
|
8605
|
+
{ toolName: functionToolDef.name, toolCallId, args: finalArgs },
|
|
8566
8606
|
"Function Tool Called"
|
|
8567
8607
|
);
|
|
8568
8608
|
try {
|
|
@@ -8572,17 +8612,21 @@ var Agent = class {
|
|
|
8572
8612
|
timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
8573
8613
|
vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
|
|
8574
8614
|
};
|
|
8575
|
-
const result = await sandboxExecutor.executeFunctionTool(
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8615
|
+
const result = await sandboxExecutor.executeFunctionTool(
|
|
8616
|
+
functionToolDef.id,
|
|
8617
|
+
finalArgs,
|
|
8618
|
+
{
|
|
8619
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
8620
|
+
inputSchema: functionData.inputSchema || {},
|
|
8621
|
+
executeCode: functionData.executeCode,
|
|
8622
|
+
dependencies: functionData.dependencies || {},
|
|
8623
|
+
sandboxConfig: this.config.sandboxConfig || defaultSandboxConfig
|
|
8624
|
+
}
|
|
8625
|
+
);
|
|
8582
8626
|
toolSessionManager.recordToolResult(sessionId || "", {
|
|
8583
8627
|
toolCallId,
|
|
8584
8628
|
toolName: functionToolDef.name,
|
|
8585
|
-
args,
|
|
8629
|
+
args: finalArgs,
|
|
8586
8630
|
result,
|
|
8587
8631
|
timestamp: Date.now()
|
|
8588
8632
|
});
|
|
@@ -11985,6 +12029,8 @@ var ExecutionHandler = class {
|
|
|
11985
12029
|
throw error;
|
|
11986
12030
|
} finally {
|
|
11987
12031
|
span.end();
|
|
12032
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
12033
|
+
await flushBatchProcessor();
|
|
11988
12034
|
}
|
|
11989
12035
|
});
|
|
11990
12036
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"pino": "^9.11.0",
|
|
54
54
|
"traverse": "^0.6.11",
|
|
55
55
|
"ts-pattern": "^5.7.1",
|
|
56
|
-
"@inkeep/agents-core": "^0.39.
|
|
56
|
+
"@inkeep/agents-core": "^0.39.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@hono/zod-openapi": "^1.1.5",
|