@inkeep/agents-run-api 0.33.2 → 0.34.1
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 +152 -31
- package/dist/index.js +153 -32
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var anthropic = require('@ai-sdk/anthropic');
|
|
|
34
34
|
var gateway = require('@ai-sdk/gateway');
|
|
35
35
|
var google = require('@ai-sdk/google');
|
|
36
36
|
var openai = require('@ai-sdk/openai');
|
|
37
|
+
var openaiCompatible = require('@ai-sdk/openai-compatible');
|
|
37
38
|
var aiSdkProvider = require('@openrouter/ai-sdk-provider');
|
|
38
39
|
var jmespath = require('jmespath');
|
|
39
40
|
var Ajv = require('ajv');
|
|
@@ -2578,6 +2579,13 @@ init_logger();
|
|
|
2578
2579
|
// src/agents/ModelFactory.ts
|
|
2579
2580
|
init_logger();
|
|
2580
2581
|
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
2582
|
+
var nimDefault = openaiCompatible.createOpenAICompatible({
|
|
2583
|
+
name: "nim",
|
|
2584
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
2585
|
+
headers: {
|
|
2586
|
+
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2581
2589
|
var _ModelFactory = class _ModelFactory {
|
|
2582
2590
|
/**
|
|
2583
2591
|
* Create a provider instance with custom configuration
|
|
@@ -2602,6 +2610,47 @@ var _ModelFactory = class _ModelFactory {
|
|
|
2602
2610
|
};
|
|
2603
2611
|
case "gateway":
|
|
2604
2612
|
return gateway.createGateway(config);
|
|
2613
|
+
case "nim": {
|
|
2614
|
+
const nimConfig = {
|
|
2615
|
+
name: "nim",
|
|
2616
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
2617
|
+
headers: {
|
|
2618
|
+
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
2619
|
+
},
|
|
2620
|
+
...config
|
|
2621
|
+
};
|
|
2622
|
+
return openaiCompatible.createOpenAICompatible(nimConfig);
|
|
2623
|
+
}
|
|
2624
|
+
case "custom": {
|
|
2625
|
+
if (!config.baseURL && !config.baseUrl) {
|
|
2626
|
+
throw new Error(
|
|
2627
|
+
"Custom provider requires baseURL. Please provide it in providerOptions.baseURL or providerOptions.baseUrl"
|
|
2628
|
+
);
|
|
2629
|
+
}
|
|
2630
|
+
const customConfig = {
|
|
2631
|
+
name: "custom",
|
|
2632
|
+
baseURL: config.baseURL || config.baseUrl,
|
|
2633
|
+
headers: {
|
|
2634
|
+
...process.env.CUSTOM_LLM_API_KEY && {
|
|
2635
|
+
Authorization: `Bearer ${process.env.CUSTOM_LLM_API_KEY}`
|
|
2636
|
+
},
|
|
2637
|
+
...config.headers || {}
|
|
2638
|
+
},
|
|
2639
|
+
...config
|
|
2640
|
+
};
|
|
2641
|
+
logger4.info(
|
|
2642
|
+
{
|
|
2643
|
+
config: {
|
|
2644
|
+
baseURL: customConfig.baseURL,
|
|
2645
|
+
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
2646
|
+
apiKeyPrefix: process.env.CUSTOM_LLM_API_KEY?.substring(0, 10) + "...",
|
|
2647
|
+
headers: Object.keys(customConfig.headers || {})
|
|
2648
|
+
}
|
|
2649
|
+
},
|
|
2650
|
+
"Creating custom OpenAI-compatible provider"
|
|
2651
|
+
);
|
|
2652
|
+
return openaiCompatible.createOpenAICompatible(customConfig);
|
|
2653
|
+
}
|
|
2605
2654
|
default:
|
|
2606
2655
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
2607
2656
|
}
|
|
@@ -2618,9 +2667,18 @@ var _ModelFactory = class _ModelFactory {
|
|
|
2618
2667
|
if (providerOptions.baseUrl || providerOptions.baseURL) {
|
|
2619
2668
|
providerConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
2620
2669
|
}
|
|
2670
|
+
if (providerOptions.headers) {
|
|
2671
|
+
providerConfig.headers = providerOptions.headers;
|
|
2672
|
+
}
|
|
2621
2673
|
if (providerOptions.gateway) {
|
|
2622
2674
|
Object.assign(providerConfig, providerOptions.gateway);
|
|
2623
2675
|
}
|
|
2676
|
+
if (providerOptions.nim) {
|
|
2677
|
+
Object.assign(providerConfig, providerOptions.nim);
|
|
2678
|
+
}
|
|
2679
|
+
if (providerOptions.custom) {
|
|
2680
|
+
Object.assign(providerConfig, providerOptions.custom);
|
|
2681
|
+
}
|
|
2624
2682
|
return providerConfig;
|
|
2625
2683
|
}
|
|
2626
2684
|
/**
|
|
@@ -2665,9 +2723,15 @@ var _ModelFactory = class _ModelFactory {
|
|
|
2665
2723
|
return aiSdkProvider.openrouter(modelName);
|
|
2666
2724
|
case "gateway":
|
|
2667
2725
|
return gateway.gateway(modelName);
|
|
2726
|
+
case "nim":
|
|
2727
|
+
return nimDefault(modelName);
|
|
2728
|
+
case "custom":
|
|
2729
|
+
throw new Error(
|
|
2730
|
+
"Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL"
|
|
2731
|
+
);
|
|
2668
2732
|
default:
|
|
2669
2733
|
throw new Error(
|
|
2670
|
-
`Unsupported provider: ${provider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id)
|
|
2734
|
+
`Unsupported provider: ${provider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`
|
|
2671
2735
|
);
|
|
2672
2736
|
}
|
|
2673
2737
|
}
|
|
@@ -2683,7 +2747,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
2683
2747
|
const normalizedProvider = provider.toLowerCase();
|
|
2684
2748
|
if (!_ModelFactory.BUILT_IN_PROVIDERS.includes(normalizedProvider)) {
|
|
2685
2749
|
throw new Error(
|
|
2686
|
-
`Unsupported provider: ${normalizedProvider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id)
|
|
2750
|
+
`Unsupported provider: ${normalizedProvider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`
|
|
2687
2751
|
);
|
|
2688
2752
|
}
|
|
2689
2753
|
return {
|
|
@@ -2702,7 +2766,16 @@ var _ModelFactory = class _ModelFactory {
|
|
|
2702
2766
|
if (!providerOptions) {
|
|
2703
2767
|
return {};
|
|
2704
2768
|
}
|
|
2705
|
-
const excludedKeys = [
|
|
2769
|
+
const excludedKeys = [
|
|
2770
|
+
"apiKey",
|
|
2771
|
+
"baseURL",
|
|
2772
|
+
"baseUrl",
|
|
2773
|
+
"maxDuration",
|
|
2774
|
+
"headers",
|
|
2775
|
+
"gateway",
|
|
2776
|
+
"nim",
|
|
2777
|
+
"custom"
|
|
2778
|
+
];
|
|
2706
2779
|
const params = {};
|
|
2707
2780
|
for (const [key, value] of Object.entries(providerOptions)) {
|
|
2708
2781
|
if (!excludedKeys.includes(key) && value !== void 0) {
|
|
@@ -2763,7 +2836,9 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
|
|
|
2763
2836
|
"openai",
|
|
2764
2837
|
"google",
|
|
2765
2838
|
"openrouter",
|
|
2766
|
-
"gateway"
|
|
2839
|
+
"gateway",
|
|
2840
|
+
"nim",
|
|
2841
|
+
"custom"
|
|
2767
2842
|
]);
|
|
2768
2843
|
var ModelFactory = _ModelFactory;
|
|
2769
2844
|
|
|
@@ -4806,8 +4881,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4806
4881
|
}
|
|
4807
4882
|
});
|
|
4808
4883
|
const result = object;
|
|
4884
|
+
logger9.info({ result: JSON.stringify(result) }, "DEBUG: Result");
|
|
4809
4885
|
const summaries = [];
|
|
4810
4886
|
for (const [componentId, data] of Object.entries(result)) {
|
|
4887
|
+
logger9.info({ componentId, data: JSON.stringify(data) }, "DEBUG: Component data");
|
|
4811
4888
|
if (componentId === "no_relevant_updates") {
|
|
4812
4889
|
continue;
|
|
4813
4890
|
}
|
|
@@ -5374,10 +5451,10 @@ var AgentSessionManager = class {
|
|
|
5374
5451
|
/**
|
|
5375
5452
|
* Initialize status updates for a session
|
|
5376
5453
|
*/
|
|
5377
|
-
initializeStatusUpdates(sessionId, config, summarizerModel) {
|
|
5454
|
+
initializeStatusUpdates(sessionId, config, summarizerModel, baseModel) {
|
|
5378
5455
|
const session = this.sessions.get(sessionId);
|
|
5379
5456
|
if (session) {
|
|
5380
|
-
session.initializeStatusUpdates(config, summarizerModel);
|
|
5457
|
+
session.initializeStatusUpdates(config, summarizerModel, baseModel);
|
|
5381
5458
|
} else {
|
|
5382
5459
|
logger9.error(
|
|
5383
5460
|
{
|
|
@@ -8767,7 +8844,7 @@ var Agent = class {
|
|
|
8767
8844
|
/**
|
|
8768
8845
|
* Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
|
|
8769
8846
|
*/
|
|
8770
|
-
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType) {
|
|
8847
|
+
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId) {
|
|
8771
8848
|
if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
|
|
8772
8849
|
return toolDefinition;
|
|
8773
8850
|
}
|
|
@@ -8793,7 +8870,8 @@ var Agent = class {
|
|
|
8793
8870
|
agentSessionManager.recordEvent(streamRequestId, "tool_call", this.config.id, {
|
|
8794
8871
|
toolName,
|
|
8795
8872
|
input: args,
|
|
8796
|
-
toolCallId
|
|
8873
|
+
toolCallId,
|
|
8874
|
+
relationshipId
|
|
8797
8875
|
});
|
|
8798
8876
|
}
|
|
8799
8877
|
try {
|
|
@@ -8838,7 +8916,8 @@ var Agent = class {
|
|
|
8838
8916
|
toolName,
|
|
8839
8917
|
output: result,
|
|
8840
8918
|
toolCallId,
|
|
8841
|
-
duration
|
|
8919
|
+
duration,
|
|
8920
|
+
relationshipId
|
|
8842
8921
|
});
|
|
8843
8922
|
}
|
|
8844
8923
|
return result;
|
|
@@ -8851,7 +8930,8 @@ var Agent = class {
|
|
|
8851
8930
|
output: null,
|
|
8852
8931
|
toolCallId,
|
|
8853
8932
|
duration,
|
|
8854
|
-
error: errorMessage
|
|
8933
|
+
error: errorMessage,
|
|
8934
|
+
relationshipId
|
|
8855
8935
|
});
|
|
8856
8936
|
}
|
|
8857
8937
|
throw error;
|
|
@@ -8917,22 +8997,24 @@ var Agent = class {
|
|
|
8917
8997
|
}) || [];
|
|
8918
8998
|
const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
|
|
8919
8999
|
if (!sessionId) {
|
|
8920
|
-
const combinedTools = tools.reduce((acc, tool3) => {
|
|
8921
|
-
return Object.assign(acc, tool3);
|
|
8922
|
-
}, {});
|
|
8923
9000
|
const wrappedTools2 = {};
|
|
8924
|
-
for (const [
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
9001
|
+
for (const [index, toolSet] of tools.entries()) {
|
|
9002
|
+
const relationshipId = mcpTools[index]?.relationshipId;
|
|
9003
|
+
for (const [toolName, toolDef] of Object.entries(toolSet)) {
|
|
9004
|
+
wrappedTools2[toolName] = this.wrapToolWithStreaming(
|
|
9005
|
+
toolName,
|
|
9006
|
+
toolDef,
|
|
9007
|
+
streamRequestId,
|
|
9008
|
+
"mcp",
|
|
9009
|
+
relationshipId
|
|
9010
|
+
);
|
|
9011
|
+
}
|
|
8931
9012
|
}
|
|
8932
9013
|
return wrappedTools2;
|
|
8933
9014
|
}
|
|
8934
9015
|
const wrappedTools = {};
|
|
8935
|
-
for (const toolSet of tools) {
|
|
9016
|
+
for (const [index, toolSet] of tools.entries()) {
|
|
9017
|
+
const relationshipId = mcpTools[index]?.relationshipId;
|
|
8936
9018
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
8937
9019
|
if (!isValidTool(originalTool)) {
|
|
8938
9020
|
logger19.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
@@ -8945,7 +9027,7 @@ var Agent = class {
|
|
|
8945
9027
|
logger19.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
8946
9028
|
try {
|
|
8947
9029
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
8948
|
-
if (rawResult && typeof rawResult === "object" &&
|
|
9030
|
+
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
8949
9031
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
8950
9032
|
logger19.error(
|
|
8951
9033
|
{ toolName, toolCallId, errorMessage, rawResult },
|
|
@@ -8966,7 +9048,8 @@ var Agent = class {
|
|
|
8966
9048
|
context: {
|
|
8967
9049
|
toolName,
|
|
8968
9050
|
toolCallId,
|
|
8969
|
-
errorMessage
|
|
9051
|
+
errorMessage,
|
|
9052
|
+
relationshipId
|
|
8970
9053
|
}
|
|
8971
9054
|
});
|
|
8972
9055
|
}
|
|
@@ -9005,7 +9088,8 @@ var Agent = class {
|
|
|
9005
9088
|
toolName,
|
|
9006
9089
|
sessionWrappedTool,
|
|
9007
9090
|
streamRequestId,
|
|
9008
|
-
"mcp"
|
|
9091
|
+
"mcp",
|
|
9092
|
+
relationshipId
|
|
9009
9093
|
);
|
|
9010
9094
|
}
|
|
9011
9095
|
}
|
|
@@ -10677,7 +10761,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10677
10761
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
10678
10762
|
const toolsForAgentResult = await Promise.all(
|
|
10679
10763
|
toolsForAgent.data.map(async (item) => {
|
|
10680
|
-
const mcpTool = await agentsCore.dbResultToMcpTool(
|
|
10764
|
+
const mcpTool = await agentsCore.dbResultToMcpTool(
|
|
10765
|
+
item.tool,
|
|
10766
|
+
dbClient_default,
|
|
10767
|
+
credentialStoreRegistry,
|
|
10768
|
+
item.id
|
|
10769
|
+
);
|
|
10681
10770
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
10682
10771
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
10683
10772
|
mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
|
|
@@ -10759,7 +10848,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10759
10848
|
const mcpTool = await agentsCore.dbResultToMcpTool(
|
|
10760
10849
|
item.tool,
|
|
10761
10850
|
dbClient_default,
|
|
10762
|
-
credentialStoreRegistry
|
|
10851
|
+
credentialStoreRegistry,
|
|
10852
|
+
item.id
|
|
10763
10853
|
);
|
|
10764
10854
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
10765
10855
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -12083,11 +12173,42 @@ var ExecutionHandler = class {
|
|
|
12083
12173
|
scopes: { tenantId, projectId, agentId }
|
|
12084
12174
|
});
|
|
12085
12175
|
if (agentConfig?.statusUpdates && agentConfig.statusUpdates.enabled !== false) {
|
|
12086
|
-
|
|
12087
|
-
|
|
12088
|
-
|
|
12089
|
-
|
|
12090
|
-
|
|
12176
|
+
try {
|
|
12177
|
+
const agentWithDefault = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
|
|
12178
|
+
scopes: { tenantId, projectId, agentId }
|
|
12179
|
+
});
|
|
12180
|
+
if (agentWithDefault?.defaultSubAgent) {
|
|
12181
|
+
const resolvedModels = await resolveModelConfig(
|
|
12182
|
+
agentId,
|
|
12183
|
+
agentWithDefault.defaultSubAgent
|
|
12184
|
+
);
|
|
12185
|
+
agentSessionManager.initializeStatusUpdates(
|
|
12186
|
+
requestId2,
|
|
12187
|
+
agentConfig.statusUpdates,
|
|
12188
|
+
resolvedModels.summarizer,
|
|
12189
|
+
resolvedModels.base
|
|
12190
|
+
);
|
|
12191
|
+
} else {
|
|
12192
|
+
agentSessionManager.initializeStatusUpdates(
|
|
12193
|
+
requestId2,
|
|
12194
|
+
agentConfig.statusUpdates,
|
|
12195
|
+
agentConfig.models?.summarizer
|
|
12196
|
+
);
|
|
12197
|
+
}
|
|
12198
|
+
} catch (modelError) {
|
|
12199
|
+
logger24.warn(
|
|
12200
|
+
{
|
|
12201
|
+
error: modelError instanceof Error ? modelError.message : "Unknown error",
|
|
12202
|
+
agentId
|
|
12203
|
+
},
|
|
12204
|
+
"Failed to resolve models for status updates, using agent-level config"
|
|
12205
|
+
);
|
|
12206
|
+
agentSessionManager.initializeStatusUpdates(
|
|
12207
|
+
requestId2,
|
|
12208
|
+
agentConfig.statusUpdates,
|
|
12209
|
+
agentConfig.models?.summarizer
|
|
12210
|
+
);
|
|
12211
|
+
}
|
|
12091
12212
|
}
|
|
12092
12213
|
} catch (error) {
|
|
12093
12214
|
logger24.error(
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { env } from './chunk-UZXC6MEO.js';
|
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
6
6
|
import { STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS, STREAM_BUFFER_MAX_SIZE_BYTES, SESSION_CLEANUP_INTERVAL_MS, STREAM_MAX_LIFETIME_MS, STREAM_TEXT_GAP_THRESHOLD_MS, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, AGENT_EXECUTION_MAX_GENERATION_STEPS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_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 } from './chunk-IVALDC72.js';
|
|
7
7
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
8
|
-
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, TaskState, setActiveAgentForThread, getConversation,
|
|
8
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, TaskState, getAgentById, getProject, setActiveAgentForThread, getConversation, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
9
9
|
import { otel } from '@hono/otel';
|
|
10
10
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
11
11
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -22,6 +22,7 @@ import { createAnthropic, anthropic } from '@ai-sdk/anthropic';
|
|
|
22
22
|
import { createGateway, gateway } from '@ai-sdk/gateway';
|
|
23
23
|
import { createGoogleGenerativeAI, google } from '@ai-sdk/google';
|
|
24
24
|
import { createOpenAI, openai } from '@ai-sdk/openai';
|
|
25
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
25
26
|
import { createOpenRouter, openrouter } from '@openrouter/ai-sdk-provider';
|
|
26
27
|
import jmespath from 'jmespath';
|
|
27
28
|
import Ajv from 'ajv';
|
|
@@ -932,6 +933,13 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
932
933
|
}
|
|
933
934
|
}
|
|
934
935
|
var logger3 = getLogger("ModelFactory");
|
|
936
|
+
var nimDefault = createOpenAICompatible({
|
|
937
|
+
name: "nim",
|
|
938
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
939
|
+
headers: {
|
|
940
|
+
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
941
|
+
}
|
|
942
|
+
});
|
|
935
943
|
var _ModelFactory = class _ModelFactory {
|
|
936
944
|
/**
|
|
937
945
|
* Create a provider instance with custom configuration
|
|
@@ -956,6 +964,47 @@ var _ModelFactory = class _ModelFactory {
|
|
|
956
964
|
};
|
|
957
965
|
case "gateway":
|
|
958
966
|
return createGateway(config);
|
|
967
|
+
case "nim": {
|
|
968
|
+
const nimConfig = {
|
|
969
|
+
name: "nim",
|
|
970
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
971
|
+
headers: {
|
|
972
|
+
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
973
|
+
},
|
|
974
|
+
...config
|
|
975
|
+
};
|
|
976
|
+
return createOpenAICompatible(nimConfig);
|
|
977
|
+
}
|
|
978
|
+
case "custom": {
|
|
979
|
+
if (!config.baseURL && !config.baseUrl) {
|
|
980
|
+
throw new Error(
|
|
981
|
+
"Custom provider requires baseURL. Please provide it in providerOptions.baseURL or providerOptions.baseUrl"
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
const customConfig = {
|
|
985
|
+
name: "custom",
|
|
986
|
+
baseURL: config.baseURL || config.baseUrl,
|
|
987
|
+
headers: {
|
|
988
|
+
...process.env.CUSTOM_LLM_API_KEY && {
|
|
989
|
+
Authorization: `Bearer ${process.env.CUSTOM_LLM_API_KEY}`
|
|
990
|
+
},
|
|
991
|
+
...config.headers || {}
|
|
992
|
+
},
|
|
993
|
+
...config
|
|
994
|
+
};
|
|
995
|
+
logger3.info(
|
|
996
|
+
{
|
|
997
|
+
config: {
|
|
998
|
+
baseURL: customConfig.baseURL,
|
|
999
|
+
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
1000
|
+
apiKeyPrefix: process.env.CUSTOM_LLM_API_KEY?.substring(0, 10) + "...",
|
|
1001
|
+
headers: Object.keys(customConfig.headers || {})
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
"Creating custom OpenAI-compatible provider"
|
|
1005
|
+
);
|
|
1006
|
+
return createOpenAICompatible(customConfig);
|
|
1007
|
+
}
|
|
959
1008
|
default:
|
|
960
1009
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
961
1010
|
}
|
|
@@ -972,9 +1021,18 @@ var _ModelFactory = class _ModelFactory {
|
|
|
972
1021
|
if (providerOptions.baseUrl || providerOptions.baseURL) {
|
|
973
1022
|
providerConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
974
1023
|
}
|
|
1024
|
+
if (providerOptions.headers) {
|
|
1025
|
+
providerConfig.headers = providerOptions.headers;
|
|
1026
|
+
}
|
|
975
1027
|
if (providerOptions.gateway) {
|
|
976
1028
|
Object.assign(providerConfig, providerOptions.gateway);
|
|
977
1029
|
}
|
|
1030
|
+
if (providerOptions.nim) {
|
|
1031
|
+
Object.assign(providerConfig, providerOptions.nim);
|
|
1032
|
+
}
|
|
1033
|
+
if (providerOptions.custom) {
|
|
1034
|
+
Object.assign(providerConfig, providerOptions.custom);
|
|
1035
|
+
}
|
|
978
1036
|
return providerConfig;
|
|
979
1037
|
}
|
|
980
1038
|
/**
|
|
@@ -1019,9 +1077,15 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1019
1077
|
return openrouter(modelName);
|
|
1020
1078
|
case "gateway":
|
|
1021
1079
|
return gateway(modelName);
|
|
1080
|
+
case "nim":
|
|
1081
|
+
return nimDefault(modelName);
|
|
1082
|
+
case "custom":
|
|
1083
|
+
throw new Error(
|
|
1084
|
+
"Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL"
|
|
1085
|
+
);
|
|
1022
1086
|
default:
|
|
1023
1087
|
throw new Error(
|
|
1024
|
-
`Unsupported provider: ${provider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id)
|
|
1088
|
+
`Unsupported provider: ${provider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`
|
|
1025
1089
|
);
|
|
1026
1090
|
}
|
|
1027
1091
|
}
|
|
@@ -1037,7 +1101,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1037
1101
|
const normalizedProvider = provider.toLowerCase();
|
|
1038
1102
|
if (!_ModelFactory.BUILT_IN_PROVIDERS.includes(normalizedProvider)) {
|
|
1039
1103
|
throw new Error(
|
|
1040
|
-
`Unsupported provider: ${normalizedProvider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id)
|
|
1104
|
+
`Unsupported provider: ${normalizedProvider}. Supported providers are: ${_ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`
|
|
1041
1105
|
);
|
|
1042
1106
|
}
|
|
1043
1107
|
return {
|
|
@@ -1056,7 +1120,16 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1056
1120
|
if (!providerOptions) {
|
|
1057
1121
|
return {};
|
|
1058
1122
|
}
|
|
1059
|
-
const excludedKeys = [
|
|
1123
|
+
const excludedKeys = [
|
|
1124
|
+
"apiKey",
|
|
1125
|
+
"baseURL",
|
|
1126
|
+
"baseUrl",
|
|
1127
|
+
"maxDuration",
|
|
1128
|
+
"headers",
|
|
1129
|
+
"gateway",
|
|
1130
|
+
"nim",
|
|
1131
|
+
"custom"
|
|
1132
|
+
];
|
|
1060
1133
|
const params = {};
|
|
1061
1134
|
for (const [key, value] of Object.entries(providerOptions)) {
|
|
1062
1135
|
if (!excludedKeys.includes(key) && value !== void 0) {
|
|
@@ -1117,7 +1190,9 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
|
|
|
1117
1190
|
"openai",
|
|
1118
1191
|
"google",
|
|
1119
1192
|
"openrouter",
|
|
1120
|
-
"gateway"
|
|
1193
|
+
"gateway",
|
|
1194
|
+
"nim",
|
|
1195
|
+
"custom"
|
|
1121
1196
|
]);
|
|
1122
1197
|
var ModelFactory = _ModelFactory;
|
|
1123
1198
|
var logger4 = getLogger("ToolSessionManager");
|
|
@@ -3142,8 +3217,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3142
3217
|
}
|
|
3143
3218
|
});
|
|
3144
3219
|
const result = object;
|
|
3220
|
+
logger8.info({ result: JSON.stringify(result) }, "DEBUG: Result");
|
|
3145
3221
|
const summaries = [];
|
|
3146
3222
|
for (const [componentId, data] of Object.entries(result)) {
|
|
3223
|
+
logger8.info({ componentId, data: JSON.stringify(data) }, "DEBUG: Component data");
|
|
3147
3224
|
if (componentId === "no_relevant_updates") {
|
|
3148
3225
|
continue;
|
|
3149
3226
|
}
|
|
@@ -3710,10 +3787,10 @@ var AgentSessionManager = class {
|
|
|
3710
3787
|
/**
|
|
3711
3788
|
* Initialize status updates for a session
|
|
3712
3789
|
*/
|
|
3713
|
-
initializeStatusUpdates(sessionId, config, summarizerModel) {
|
|
3790
|
+
initializeStatusUpdates(sessionId, config, summarizerModel, baseModel) {
|
|
3714
3791
|
const session = this.sessions.get(sessionId);
|
|
3715
3792
|
if (session) {
|
|
3716
|
-
session.initializeStatusUpdates(config, summarizerModel);
|
|
3793
|
+
session.initializeStatusUpdates(config, summarizerModel, baseModel);
|
|
3717
3794
|
} else {
|
|
3718
3795
|
logger8.error(
|
|
3719
3796
|
{
|
|
@@ -7075,7 +7152,7 @@ var Agent = class {
|
|
|
7075
7152
|
/**
|
|
7076
7153
|
* Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
|
|
7077
7154
|
*/
|
|
7078
|
-
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType) {
|
|
7155
|
+
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId) {
|
|
7079
7156
|
if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
|
|
7080
7157
|
return toolDefinition;
|
|
7081
7158
|
}
|
|
@@ -7101,7 +7178,8 @@ var Agent = class {
|
|
|
7101
7178
|
agentSessionManager.recordEvent(streamRequestId, "tool_call", this.config.id, {
|
|
7102
7179
|
toolName,
|
|
7103
7180
|
input: args,
|
|
7104
|
-
toolCallId
|
|
7181
|
+
toolCallId,
|
|
7182
|
+
relationshipId
|
|
7105
7183
|
});
|
|
7106
7184
|
}
|
|
7107
7185
|
try {
|
|
@@ -7146,7 +7224,8 @@ var Agent = class {
|
|
|
7146
7224
|
toolName,
|
|
7147
7225
|
output: result,
|
|
7148
7226
|
toolCallId,
|
|
7149
|
-
duration
|
|
7227
|
+
duration,
|
|
7228
|
+
relationshipId
|
|
7150
7229
|
});
|
|
7151
7230
|
}
|
|
7152
7231
|
return result;
|
|
@@ -7159,7 +7238,8 @@ var Agent = class {
|
|
|
7159
7238
|
output: null,
|
|
7160
7239
|
toolCallId,
|
|
7161
7240
|
duration,
|
|
7162
|
-
error: errorMessage
|
|
7241
|
+
error: errorMessage,
|
|
7242
|
+
relationshipId
|
|
7163
7243
|
});
|
|
7164
7244
|
}
|
|
7165
7245
|
throw error;
|
|
@@ -7225,22 +7305,24 @@ var Agent = class {
|
|
|
7225
7305
|
}) || [];
|
|
7226
7306
|
const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
|
|
7227
7307
|
if (!sessionId) {
|
|
7228
|
-
const combinedTools = tools.reduce((acc, tool3) => {
|
|
7229
|
-
return Object.assign(acc, tool3);
|
|
7230
|
-
}, {});
|
|
7231
7308
|
const wrappedTools2 = {};
|
|
7232
|
-
for (const [
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7309
|
+
for (const [index, toolSet] of tools.entries()) {
|
|
7310
|
+
const relationshipId = mcpTools[index]?.relationshipId;
|
|
7311
|
+
for (const [toolName, toolDef] of Object.entries(toolSet)) {
|
|
7312
|
+
wrappedTools2[toolName] = this.wrapToolWithStreaming(
|
|
7313
|
+
toolName,
|
|
7314
|
+
toolDef,
|
|
7315
|
+
streamRequestId,
|
|
7316
|
+
"mcp",
|
|
7317
|
+
relationshipId
|
|
7318
|
+
);
|
|
7319
|
+
}
|
|
7239
7320
|
}
|
|
7240
7321
|
return wrappedTools2;
|
|
7241
7322
|
}
|
|
7242
7323
|
const wrappedTools = {};
|
|
7243
|
-
for (const toolSet of tools) {
|
|
7324
|
+
for (const [index, toolSet] of tools.entries()) {
|
|
7325
|
+
const relationshipId = mcpTools[index]?.relationshipId;
|
|
7244
7326
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7245
7327
|
if (!isValidTool(originalTool)) {
|
|
7246
7328
|
logger15.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
@@ -7253,7 +7335,7 @@ var Agent = class {
|
|
|
7253
7335
|
logger15.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7254
7336
|
try {
|
|
7255
7337
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7256
|
-
if (rawResult && typeof rawResult === "object" &&
|
|
7338
|
+
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
7257
7339
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
7258
7340
|
logger15.error(
|
|
7259
7341
|
{ toolName, toolCallId, errorMessage, rawResult },
|
|
@@ -7274,7 +7356,8 @@ var Agent = class {
|
|
|
7274
7356
|
context: {
|
|
7275
7357
|
toolName,
|
|
7276
7358
|
toolCallId,
|
|
7277
|
-
errorMessage
|
|
7359
|
+
errorMessage,
|
|
7360
|
+
relationshipId
|
|
7278
7361
|
}
|
|
7279
7362
|
});
|
|
7280
7363
|
}
|
|
@@ -7313,7 +7396,8 @@ var Agent = class {
|
|
|
7313
7396
|
toolName,
|
|
7314
7397
|
sessionWrappedTool,
|
|
7315
7398
|
streamRequestId,
|
|
7316
|
-
"mcp"
|
|
7399
|
+
"mcp",
|
|
7400
|
+
relationshipId
|
|
7317
7401
|
);
|
|
7318
7402
|
}
|
|
7319
7403
|
}
|
|
@@ -8985,7 +9069,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8985
9069
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
8986
9070
|
const toolsForAgentResult = await Promise.all(
|
|
8987
9071
|
toolsForAgent.data.map(async (item) => {
|
|
8988
|
-
const mcpTool = await dbResultToMcpTool(
|
|
9072
|
+
const mcpTool = await dbResultToMcpTool(
|
|
9073
|
+
item.tool,
|
|
9074
|
+
dbClient_default,
|
|
9075
|
+
credentialStoreRegistry,
|
|
9076
|
+
item.id
|
|
9077
|
+
);
|
|
8989
9078
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
8990
9079
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
8991
9080
|
mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
|
|
@@ -9067,7 +9156,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9067
9156
|
const mcpTool = await dbResultToMcpTool(
|
|
9068
9157
|
item.tool,
|
|
9069
9158
|
dbClient_default,
|
|
9070
|
-
credentialStoreRegistry
|
|
9159
|
+
credentialStoreRegistry,
|
|
9160
|
+
item.id
|
|
9071
9161
|
);
|
|
9072
9162
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
9073
9163
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -10372,11 +10462,42 @@ var ExecutionHandler = class {
|
|
|
10372
10462
|
scopes: { tenantId, projectId, agentId }
|
|
10373
10463
|
});
|
|
10374
10464
|
if (agentConfig?.statusUpdates && agentConfig.statusUpdates.enabled !== false) {
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10465
|
+
try {
|
|
10466
|
+
const agentWithDefault = await getAgentWithDefaultSubAgent(dbClient_default)({
|
|
10467
|
+
scopes: { tenantId, projectId, agentId }
|
|
10468
|
+
});
|
|
10469
|
+
if (agentWithDefault?.defaultSubAgent) {
|
|
10470
|
+
const resolvedModels = await resolveModelConfig(
|
|
10471
|
+
agentId,
|
|
10472
|
+
agentWithDefault.defaultSubAgent
|
|
10473
|
+
);
|
|
10474
|
+
agentSessionManager.initializeStatusUpdates(
|
|
10475
|
+
requestId2,
|
|
10476
|
+
agentConfig.statusUpdates,
|
|
10477
|
+
resolvedModels.summarizer,
|
|
10478
|
+
resolvedModels.base
|
|
10479
|
+
);
|
|
10480
|
+
} else {
|
|
10481
|
+
agentSessionManager.initializeStatusUpdates(
|
|
10482
|
+
requestId2,
|
|
10483
|
+
agentConfig.statusUpdates,
|
|
10484
|
+
agentConfig.models?.summarizer
|
|
10485
|
+
);
|
|
10486
|
+
}
|
|
10487
|
+
} catch (modelError) {
|
|
10488
|
+
logger20.warn(
|
|
10489
|
+
{
|
|
10490
|
+
error: modelError instanceof Error ? modelError.message : "Unknown error",
|
|
10491
|
+
agentId
|
|
10492
|
+
},
|
|
10493
|
+
"Failed to resolve models for status updates, using agent-level config"
|
|
10494
|
+
);
|
|
10495
|
+
agentSessionManager.initializeStatusUpdates(
|
|
10496
|
+
requestId2,
|
|
10497
|
+
agentConfig.statusUpdates,
|
|
10498
|
+
agentConfig.models?.summarizer
|
|
10499
|
+
);
|
|
10500
|
+
}
|
|
10380
10501
|
}
|
|
10381
10502
|
} catch (error) {
|
|
10382
10503
|
logger20.error(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.1",
|
|
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",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@ai-sdk/gateway": "^1.0.23",
|
|
19
19
|
"@ai-sdk/google": "^2.0.14",
|
|
20
20
|
"@ai-sdk/openai": "2.0.11",
|
|
21
|
+
"@ai-sdk/openai-compatible": "^1.0.27",
|
|
21
22
|
"@ai-sdk/react": "2.0.11",
|
|
22
23
|
"@alcyone-labs/modelcontextprotocol-sdk": "^1.16.0",
|
|
23
24
|
"@hono/node-server": "^1.14.3",
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"traverse": "^0.6.11",
|
|
54
55
|
"ts-pattern": "^5.7.1",
|
|
55
56
|
"zod": "4.1.5",
|
|
56
|
-
"@inkeep/agents-core": "^0.
|
|
57
|
+
"@inkeep/agents-core": "^0.34.1"
|
|
57
58
|
},
|
|
58
59
|
"optionalDependencies": {
|
|
59
60
|
"keytar": "^7.9.0"
|