@inkeep/agents-run-api 0.0.0-dev-20251008200151 → 0.0.0-dev-20251009000750

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.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 { getLogger as getLogger$1, getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, 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, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
7
+ import { getLogger as getLogger$1, getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, 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, 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';
@@ -6837,7 +6837,10 @@ var Agent = class {
6837
6837
  ]);
6838
6838
  }
6839
6839
  async getMcpTools(sessionId, streamRequestId) {
6840
- const tools = await Promise.all(this.config.tools?.map((tool3) => this.getMcpTool(tool3)) || []) || [];
6840
+ const mcpTools = this.config.tools?.filter((tool3) => {
6841
+ return tool3.config?.type === "mcp";
6842
+ }) || [];
6843
+ const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
6841
6844
  if (!sessionId) {
6842
6845
  const combinedTools = tools.reduce((acc, tool3) => {
6843
6846
  return Object.assign(acc, tool3);
@@ -6897,6 +6900,9 @@ var Agent = class {
6897
6900
  * Convert database McpTool to builder MCPToolConfig format
6898
6901
  */
6899
6902
  convertToMCPToolConfig(tool3, agentToolRelationHeaders) {
6903
+ if (tool3.config.type !== "mcp") {
6904
+ throw new Error(`Cannot convert non-MCP tool to MCP config: ${tool3.id}`);
6905
+ }
6900
6906
  return {
6901
6907
  id: tool3.id,
6902
6908
  name: tool3.name,
@@ -6965,6 +6971,9 @@ var Agent = class {
6965
6971
  selectedTools
6966
6972
  );
6967
6973
  } else {
6974
+ if (tool3.config.type !== "mcp") {
6975
+ throw new Error(`Cannot build server config for non-MCP tool: ${tool3.id}`);
6976
+ }
6968
6977
  serverConfig = {
6969
6978
  type: tool3.config.mcp.transport?.type || MCPTransportType.streamableHttp,
6970
6979
  url: tool3.config.mcp.server.url,
@@ -7033,21 +7042,88 @@ var Agent = class {
7033
7042
  throw error;
7034
7043
  }
7035
7044
  }
7036
- getFunctionTools(streamRequestId) {
7037
- if (!this.config.functionTools) return {};
7045
+ async getFunctionTools(sessionId, streamRequestId) {
7038
7046
  const functionTools = {};
7039
- for (const funcTool of this.config.functionTools) {
7040
- const aiTool = tool({
7041
- description: funcTool.description,
7042
- inputSchema: funcTool.schema || z.object({}),
7043
- execute: funcTool.execute
7047
+ try {
7048
+ const toolsForAgent = await getToolsForAgent(dbClient_default)({
7049
+ scopes: {
7050
+ tenantId: this.config.tenantId || "default",
7051
+ projectId: this.config.projectId || "default",
7052
+ graphId: this.config.graphId,
7053
+ agentId: this.config.id
7054
+ }
7044
7055
  });
7045
- functionTools[funcTool.name] = this.wrapToolWithStreaming(
7046
- funcTool.name,
7047
- aiTool,
7048
- streamRequestId,
7049
- "tool"
7050
- );
7056
+ const toolsData = toolsForAgent.data || [];
7057
+ const functionToolDefs = toolsData.filter((tool3) => tool3.tool.config.type === "function");
7058
+ if (functionToolDefs.length === 0) {
7059
+ return functionTools;
7060
+ }
7061
+ const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-JI4X2Z3N.js');
7062
+ const sandboxExecutor = LocalSandboxExecutor.getInstance();
7063
+ for (const toolDef of functionToolDefs) {
7064
+ if (toolDef.tool.config?.type === "function") {
7065
+ const functionId = toolDef.tool.functionId;
7066
+ if (!functionId) {
7067
+ logger17.warn({ toolId: toolDef.tool.id }, "Function tool missing functionId reference");
7068
+ continue;
7069
+ }
7070
+ const functionData = await getFunction(dbClient_default)({
7071
+ functionId,
7072
+ scopes: {
7073
+ tenantId: this.config.tenantId || "default",
7074
+ projectId: this.config.projectId || "default"
7075
+ }
7076
+ });
7077
+ if (!functionData) {
7078
+ logger17.warn(
7079
+ { functionId, toolId: toolDef.tool.id },
7080
+ "Function not found in functions table"
7081
+ );
7082
+ continue;
7083
+ }
7084
+ const zodSchema = jsonSchemaToZod(functionData.inputSchema);
7085
+ const aiTool = tool({
7086
+ description: toolDef.tool.description || toolDef.tool.name,
7087
+ inputSchema: zodSchema,
7088
+ execute: async (args, { toolCallId }) => {
7089
+ logger17.debug(
7090
+ { toolName: toolDef.tool.name, toolCallId, args },
7091
+ "Function Tool Called"
7092
+ );
7093
+ try {
7094
+ const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
7095
+ description: toolDef.tool.description || toolDef.tool.name,
7096
+ inputSchema: functionData.inputSchema || {},
7097
+ executeCode: functionData.executeCode,
7098
+ dependencies: functionData.dependencies || {}
7099
+ });
7100
+ toolSessionManager.recordToolResult(sessionId || "", {
7101
+ toolCallId,
7102
+ toolName: toolDef.tool.name,
7103
+ args,
7104
+ result,
7105
+ timestamp: Date.now()
7106
+ });
7107
+ return { result, toolCallId };
7108
+ } catch (error) {
7109
+ logger17.error(
7110
+ { toolName: toolDef.tool.name, toolCallId, error },
7111
+ "Function tool execution failed"
7112
+ );
7113
+ throw error;
7114
+ }
7115
+ }
7116
+ });
7117
+ functionTools[toolDef.tool.name] = this.wrapToolWithStreaming(
7118
+ toolDef.tool.name,
7119
+ aiTool,
7120
+ streamRequestId || "",
7121
+ "tool"
7122
+ );
7123
+ }
7124
+ }
7125
+ } catch (error) {
7126
+ logger17.error({ error }, "Failed to load function tools from database");
7051
7127
  }
7052
7128
  return functionTools;
7053
7129
  }
@@ -7241,9 +7317,24 @@ var Agent = class {
7241
7317
  }
7242
7318
  const streamRequestId = runtimeContext?.metadata?.streamRequestId;
7243
7319
  const mcpTools = await this.getMcpTools(void 0, streamRequestId);
7244
- const functionTools = this.getFunctionTools(streamRequestId);
7320
+ const functionTools = await this.getFunctionTools(streamRequestId || "");
7245
7321
  const relationTools = this.getRelationTools(runtimeContext);
7246
7322
  const allTools = { ...mcpTools, ...functionTools, ...relationTools };
7323
+ logger17.info(
7324
+ {
7325
+ mcpTools: Object.keys(mcpTools),
7326
+ functionTools: Object.keys(functionTools),
7327
+ relationTools: Object.keys(relationTools),
7328
+ allTools: Object.keys(allTools),
7329
+ functionToolsDetails: Object.entries(functionTools).map(([name, tool3]) => ({
7330
+ name,
7331
+ hasExecute: typeof tool3.execute === "function",
7332
+ hasDescription: !!tool3.description,
7333
+ hasInputSchema: !!tool3.inputSchema
7334
+ }))
7335
+ },
7336
+ "Tools loaded for agent"
7337
+ );
7247
7338
  const toolDefinitions = Object.entries(allTools).map(([name, tool3]) => ({
7248
7339
  name,
7249
7340
  description: tool3.description || "",
@@ -7335,7 +7426,7 @@ var Agent = class {
7335
7426
  });
7336
7427
  }
7337
7428
  // Provide a default tool set that is always available to the agent.
7338
- async getDefaultTools(sessionId, streamRequestId) {
7429
+ async getDefaultTools(_sessionId, streamRequestId) {
7339
7430
  const defaultTools = {};
7340
7431
  if (await this.graphHasArtifactComponents()) {
7341
7432
  defaultTools.get_reference_artifact = this.getArtifactTools();
@@ -7423,13 +7514,19 @@ var Agent = class {
7423
7514
  if (Array.isArray(obj)) {
7424
7515
  obj.slice(0, 3).forEach((item) => {
7425
7516
  if (item && typeof item === "object") {
7426
- Object.keys(item).forEach((key) => fields.add(key));
7517
+ Object.keys(item).forEach((key) => {
7518
+ fields.add(key);
7519
+ });
7427
7520
  }
7428
7521
  });
7429
7522
  } else if (obj && typeof obj === "object") {
7430
- Object.keys(obj).forEach((key) => fields.add(key));
7523
+ Object.keys(obj).forEach((key) => {
7524
+ fields.add(key);
7525
+ });
7431
7526
  Object.values(obj).forEach((value) => {
7432
- findCommonFields(value, depth + 1).forEach((field) => fields.add(field));
7527
+ findCommonFields(value, depth + 1).forEach((field) => {
7528
+ fields.add(field);
7529
+ });
7433
7530
  });
7434
7531
  }
7435
7532
  return fields;
@@ -7613,7 +7710,7 @@ var Agent = class {
7613
7710
  // Normal prompt with data components
7614
7711
  this.buildSystemPrompt(runtimeContext, true),
7615
7712
  // Thinking prompt without data components
7616
- Promise.resolve(this.getFunctionTools(streamRequestId)),
7713
+ this.getFunctionTools(sessionId, streamRequestId),
7617
7714
  Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
7618
7715
  this.getDefaultTools(sessionId, streamRequestId)
7619
7716
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20251008200151",
3
+ "version": "0.0.0-dev-20251009000750",
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-20251008200151"
54
+ "@inkeep/agents-core": "^0.0.0-dev-20251009000750"
55
55
  },
56
56
  "optionalDependencies": {
57
57
  "keytar": "^7.9.0"