@inkeep/agents-run-api 0.0.0-dev-20251010175818 → 0.0.0-dev-20251010180500
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.
|
@@ -303,13 +303,26 @@ var _LocalSandboxExecutor = class _LocalSandboxExecutor {
|
|
|
303
303
|
const execute = ${executeCode};
|
|
304
304
|
const args = ${JSON.stringify(args)};
|
|
305
305
|
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
try {
|
|
307
|
+
const result = execute(args);
|
|
308
|
+
|
|
309
|
+
// Handle both sync and async functions
|
|
310
|
+
if (result && typeof result.then === 'function') {
|
|
311
|
+
// Async function - result is a Promise
|
|
312
|
+
result
|
|
313
|
+
.then(result => {
|
|
314
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
315
|
+
})
|
|
316
|
+
.catch(error => {
|
|
317
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
// Sync function - result is immediate
|
|
308
321
|
console.log(JSON.stringify({ success: true, result }));
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
322
|
+
}
|
|
323
|
+
} catch (error) {
|
|
324
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
325
|
+
}
|
|
313
326
|
`;
|
|
314
327
|
}
|
|
315
328
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -689,13 +689,26 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
689
689
|
const execute = ${executeCode};
|
|
690
690
|
const args = ${JSON.stringify(args)};
|
|
691
691
|
|
|
692
|
-
|
|
693
|
-
|
|
692
|
+
try {
|
|
693
|
+
const result = execute(args);
|
|
694
|
+
|
|
695
|
+
// Handle both sync and async functions
|
|
696
|
+
if (result && typeof result.then === 'function') {
|
|
697
|
+
// Async function - result is a Promise
|
|
698
|
+
result
|
|
699
|
+
.then(result => {
|
|
700
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
701
|
+
})
|
|
702
|
+
.catch(error => {
|
|
703
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
704
|
+
});
|
|
705
|
+
} else {
|
|
706
|
+
// Sync function - result is immediate
|
|
694
707
|
console.log(JSON.stringify({ success: true, result }));
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
708
|
+
}
|
|
709
|
+
} catch (error) {
|
|
710
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
711
|
+
}
|
|
699
712
|
`;
|
|
700
713
|
}
|
|
701
714
|
};
|
|
@@ -7941,82 +7954,82 @@ var Agent = class {
|
|
|
7941
7954
|
async getFunctionTools(sessionId, streamRequestId) {
|
|
7942
7955
|
const functionTools = {};
|
|
7943
7956
|
try {
|
|
7944
|
-
const
|
|
7957
|
+
const functionToolsForAgent = await agentsCore.getFunctionToolsForSubAgent(dbClient_default)({
|
|
7945
7958
|
scopes: {
|
|
7946
|
-
tenantId: this.config.tenantId
|
|
7947
|
-
projectId: this.config.projectId
|
|
7948
|
-
graphId: this.config.graphId
|
|
7949
|
-
|
|
7950
|
-
|
|
7959
|
+
tenantId: this.config.tenantId,
|
|
7960
|
+
projectId: this.config.projectId,
|
|
7961
|
+
graphId: this.config.graphId
|
|
7962
|
+
},
|
|
7963
|
+
subAgentId: this.config.id
|
|
7951
7964
|
});
|
|
7952
|
-
const
|
|
7953
|
-
|
|
7954
|
-
if (functionToolDefs.length === 0) {
|
|
7965
|
+
const functionToolsData = functionToolsForAgent.data || [];
|
|
7966
|
+
if (functionToolsData.length === 0) {
|
|
7955
7967
|
return functionTools;
|
|
7956
7968
|
}
|
|
7957
7969
|
const { LocalSandboxExecutor: LocalSandboxExecutor2 } = await Promise.resolve().then(() => (init_LocalSandboxExecutor(), LocalSandboxExecutor_exports));
|
|
7958
7970
|
const sandboxExecutor = LocalSandboxExecutor2.getInstance();
|
|
7959
|
-
for (const
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7971
|
+
for (const functionToolDef of functionToolsData) {
|
|
7972
|
+
const functionId = functionToolDef.functionId;
|
|
7973
|
+
if (!functionId) {
|
|
7974
|
+
logger18.warn(
|
|
7975
|
+
{ functionToolId: functionToolDef.id },
|
|
7976
|
+
"Function tool missing functionId reference"
|
|
7977
|
+
);
|
|
7978
|
+
continue;
|
|
7979
|
+
}
|
|
7980
|
+
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
7981
|
+
functionId,
|
|
7982
|
+
scopes: {
|
|
7983
|
+
tenantId: this.config.tenantId || "default",
|
|
7984
|
+
projectId: this.config.projectId || "default"
|
|
7965
7985
|
}
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7986
|
+
});
|
|
7987
|
+
if (!functionData) {
|
|
7988
|
+
logger18.warn(
|
|
7989
|
+
{ functionId, functionToolId: functionToolDef.id },
|
|
7990
|
+
"Function not found in functions table"
|
|
7991
|
+
);
|
|
7992
|
+
continue;
|
|
7993
|
+
}
|
|
7994
|
+
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
7995
|
+
const aiTool = ai.tool({
|
|
7996
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
7997
|
+
inputSchema: zodSchema,
|
|
7998
|
+
execute: async (args, { toolCallId }) => {
|
|
7999
|
+
logger18.debug(
|
|
8000
|
+
{ toolName: functionToolDef.name, toolCallId, args },
|
|
8001
|
+
"Function Tool Called"
|
|
7977
8002
|
);
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
8003
|
+
try {
|
|
8004
|
+
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
8005
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
8006
|
+
inputSchema: functionData.inputSchema || {},
|
|
8007
|
+
executeCode: functionData.executeCode,
|
|
8008
|
+
dependencies: functionData.dependencies || {}
|
|
8009
|
+
});
|
|
8010
|
+
toolSessionManager.recordToolResult(sessionId || "", {
|
|
8011
|
+
toolCallId,
|
|
8012
|
+
toolName: functionToolDef.name,
|
|
8013
|
+
args,
|
|
8014
|
+
result,
|
|
8015
|
+
timestamp: Date.now()
|
|
8016
|
+
});
|
|
8017
|
+
return { result, toolCallId };
|
|
8018
|
+
} catch (error) {
|
|
8019
|
+
logger18.error(
|
|
8020
|
+
{ toolName: functionToolDef.name, toolCallId, error },
|
|
8021
|
+
"Function tool execution failed"
|
|
7988
8022
|
);
|
|
7989
|
-
|
|
7990
|
-
const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
|
|
7991
|
-
description: toolDef.tool.description || toolDef.tool.name,
|
|
7992
|
-
inputSchema: functionData.inputSchema || {},
|
|
7993
|
-
executeCode: functionData.executeCode,
|
|
7994
|
-
dependencies: functionData.dependencies || {}
|
|
7995
|
-
});
|
|
7996
|
-
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7997
|
-
toolCallId,
|
|
7998
|
-
toolName: toolDef.tool.name,
|
|
7999
|
-
args,
|
|
8000
|
-
result,
|
|
8001
|
-
timestamp: Date.now()
|
|
8002
|
-
});
|
|
8003
|
-
return { result, toolCallId };
|
|
8004
|
-
} catch (error) {
|
|
8005
|
-
logger18.error(
|
|
8006
|
-
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
8007
|
-
"Function tool execution failed"
|
|
8008
|
-
);
|
|
8009
|
-
throw error;
|
|
8010
|
-
}
|
|
8023
|
+
throw error;
|
|
8011
8024
|
}
|
|
8012
|
-
}
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8025
|
+
}
|
|
8026
|
+
});
|
|
8027
|
+
functionTools[functionToolDef.name] = this.wrapToolWithStreaming(
|
|
8028
|
+
functionToolDef.name,
|
|
8029
|
+
aiTool,
|
|
8030
|
+
streamRequestId || "",
|
|
8031
|
+
"tool"
|
|
8032
|
+
);
|
|
8020
8033
|
}
|
|
8021
8034
|
} catch (error) {
|
|
8022
8035
|
logger18.error({ error }, "Failed to load function tools from database");
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getFormattedConversationHistory, createDefaultConversationHistoryConfig
|
|
|
4
4
|
import { dbClient_default } from './chunk-7IMXW4RD.js';
|
|
5
5
|
import { env } from './chunk-NZHNG4A3.js';
|
|
6
6
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
7
|
-
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } from '@inkeep/agents-core';
|
|
7
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } 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';
|
|
@@ -7117,82 +7117,82 @@ var Agent = class {
|
|
|
7117
7117
|
async getFunctionTools(sessionId, streamRequestId) {
|
|
7118
7118
|
const functionTools = {};
|
|
7119
7119
|
try {
|
|
7120
|
-
const
|
|
7120
|
+
const functionToolsForAgent = await getFunctionToolsForSubAgent(dbClient_default)({
|
|
7121
7121
|
scopes: {
|
|
7122
|
-
tenantId: this.config.tenantId
|
|
7123
|
-
projectId: this.config.projectId
|
|
7124
|
-
graphId: this.config.graphId
|
|
7125
|
-
|
|
7126
|
-
|
|
7122
|
+
tenantId: this.config.tenantId,
|
|
7123
|
+
projectId: this.config.projectId,
|
|
7124
|
+
graphId: this.config.graphId
|
|
7125
|
+
},
|
|
7126
|
+
subAgentId: this.config.id
|
|
7127
7127
|
});
|
|
7128
|
-
const
|
|
7129
|
-
|
|
7130
|
-
if (functionToolDefs.length === 0) {
|
|
7128
|
+
const functionToolsData = functionToolsForAgent.data || [];
|
|
7129
|
+
if (functionToolsData.length === 0) {
|
|
7131
7130
|
return functionTools;
|
|
7132
7131
|
}
|
|
7133
|
-
const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-
|
|
7132
|
+
const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-PQIRECLQ.js');
|
|
7134
7133
|
const sandboxExecutor = LocalSandboxExecutor.getInstance();
|
|
7135
|
-
for (const
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7134
|
+
for (const functionToolDef of functionToolsData) {
|
|
7135
|
+
const functionId = functionToolDef.functionId;
|
|
7136
|
+
if (!functionId) {
|
|
7137
|
+
logger16.warn(
|
|
7138
|
+
{ functionToolId: functionToolDef.id },
|
|
7139
|
+
"Function tool missing functionId reference"
|
|
7140
|
+
);
|
|
7141
|
+
continue;
|
|
7142
|
+
}
|
|
7143
|
+
const functionData = await getFunction(dbClient_default)({
|
|
7144
|
+
functionId,
|
|
7145
|
+
scopes: {
|
|
7146
|
+
tenantId: this.config.tenantId || "default",
|
|
7147
|
+
projectId: this.config.projectId || "default"
|
|
7141
7148
|
}
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7149
|
+
});
|
|
7150
|
+
if (!functionData) {
|
|
7151
|
+
logger16.warn(
|
|
7152
|
+
{ functionId, functionToolId: functionToolDef.id },
|
|
7153
|
+
"Function not found in functions table"
|
|
7154
|
+
);
|
|
7155
|
+
continue;
|
|
7156
|
+
}
|
|
7157
|
+
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
7158
|
+
const aiTool = tool({
|
|
7159
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
7160
|
+
inputSchema: zodSchema,
|
|
7161
|
+
execute: async (args, { toolCallId }) => {
|
|
7162
|
+
logger16.debug(
|
|
7163
|
+
{ toolName: functionToolDef.name, toolCallId, args },
|
|
7164
|
+
"Function Tool Called"
|
|
7153
7165
|
);
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7166
|
+
try {
|
|
7167
|
+
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
7168
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
7169
|
+
inputSchema: functionData.inputSchema || {},
|
|
7170
|
+
executeCode: functionData.executeCode,
|
|
7171
|
+
dependencies: functionData.dependencies || {}
|
|
7172
|
+
});
|
|
7173
|
+
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7174
|
+
toolCallId,
|
|
7175
|
+
toolName: functionToolDef.name,
|
|
7176
|
+
args,
|
|
7177
|
+
result,
|
|
7178
|
+
timestamp: Date.now()
|
|
7179
|
+
});
|
|
7180
|
+
return { result, toolCallId };
|
|
7181
|
+
} catch (error) {
|
|
7182
|
+
logger16.error(
|
|
7183
|
+
{ toolName: functionToolDef.name, toolCallId, error },
|
|
7184
|
+
"Function tool execution failed"
|
|
7164
7185
|
);
|
|
7165
|
-
|
|
7166
|
-
const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
|
|
7167
|
-
description: toolDef.tool.description || toolDef.tool.name,
|
|
7168
|
-
inputSchema: functionData.inputSchema || {},
|
|
7169
|
-
executeCode: functionData.executeCode,
|
|
7170
|
-
dependencies: functionData.dependencies || {}
|
|
7171
|
-
});
|
|
7172
|
-
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7173
|
-
toolCallId,
|
|
7174
|
-
toolName: toolDef.tool.name,
|
|
7175
|
-
args,
|
|
7176
|
-
result,
|
|
7177
|
-
timestamp: Date.now()
|
|
7178
|
-
});
|
|
7179
|
-
return { result, toolCallId };
|
|
7180
|
-
} catch (error) {
|
|
7181
|
-
logger16.error(
|
|
7182
|
-
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7183
|
-
"Function tool execution failed"
|
|
7184
|
-
);
|
|
7185
|
-
throw error;
|
|
7186
|
-
}
|
|
7186
|
+
throw error;
|
|
7187
7187
|
}
|
|
7188
|
-
}
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7188
|
+
}
|
|
7189
|
+
});
|
|
7190
|
+
functionTools[functionToolDef.name] = this.wrapToolWithStreaming(
|
|
7191
|
+
functionToolDef.name,
|
|
7192
|
+
aiTool,
|
|
7193
|
+
streamRequestId || "",
|
|
7194
|
+
"tool"
|
|
7195
|
+
);
|
|
7196
7196
|
}
|
|
7197
7197
|
} catch (error) {
|
|
7198
7198
|
logger16.error({ error }, "Failed to load function tools from database");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20251010180500",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"traverse": "^0.6.11",
|
|
52
52
|
"ts-pattern": "^5.7.1",
|
|
53
53
|
"zod": "^4.1.11",
|
|
54
|
-
"@inkeep/agents-core": "^0.0.0-dev-
|
|
54
|
+
"@inkeep/agents-core": "^0.0.0-dev-20251010180500"
|
|
55
55
|
},
|
|
56
56
|
"optionalDependencies": {
|
|
57
57
|
"keytar": "^7.9.0"
|