@inkeep/agents-run-api 0.39.4 → 0.40.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/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
- package/dist/a2a/client.d.ts +184 -0
- package/dist/a2a/client.js +510 -0
- package/dist/a2a/handlers.d.ts +7 -0
- package/dist/a2a/handlers.js +560 -0
- package/dist/a2a/transfer.d.ts +22 -0
- package/dist/a2a/transfer.js +46 -0
- package/dist/a2a/types.d.ts +79 -0
- package/dist/a2a/types.js +22 -0
- package/dist/agents/Agent.d.ts +266 -0
- package/dist/agents/Agent.js +1927 -0
- package/dist/agents/ModelFactory.d.ts +63 -0
- package/dist/agents/ModelFactory.js +194 -0
- package/dist/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/agents/SystemPromptBuilder.js +48 -0
- package/dist/agents/ToolSessionManager.d.ts +63 -0
- package/dist/agents/ToolSessionManager.js +146 -0
- package/dist/agents/generateTaskHandler.d.ts +49 -0
- package/dist/agents/generateTaskHandler.js +521 -0
- package/dist/agents/relationTools.d.ts +57 -0
- package/dist/agents/relationTools.js +262 -0
- package/dist/agents/types.d.ts +28 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/versions/v1/Phase1Config.d.ts +27 -0
- package/dist/agents/versions/v1/Phase1Config.js +424 -0
- package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
- package/dist/agents/versions/v1/Phase2Config.js +330 -0
- package/dist/constants/execution-limits/defaults.d.ts +51 -0
- package/dist/constants/execution-limits/defaults.js +52 -0
- package/dist/constants/execution-limits/index.d.ts +6 -0
- package/dist/constants/execution-limits/index.js +21 -0
- package/dist/create-app.d.ts +9 -0
- package/dist/create-app.js +195 -0
- package/dist/data/agent.d.ts +7 -0
- package/dist/data/agent.js +72 -0
- package/dist/data/agents.d.ts +34 -0
- package/dist/data/agents.js +139 -0
- package/dist/data/conversations.d.ts +128 -0
- package/dist/data/conversations.js +522 -0
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.js +1 -2
- package/dist/handlers/executionHandler.d.ts +39 -0
- package/dist/handlers/executionHandler.js +456 -0
- package/dist/index.d.ts +8 -29
- package/dist/index.js +5 -11235
- package/dist/instrumentation.d.ts +1 -2
- package/dist/instrumentation.js +66 -3
- package/dist/{logger2.js → logger.d.ts} +1 -2
- package/dist/logger.js +1 -1
- package/dist/middleware/api-key-auth.d.ts +26 -0
- package/dist/middleware/api-key-auth.js +240 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +3 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.js +54 -0
- package/dist/routes/agents.d.ts +12 -0
- package/dist/routes/agents.js +147 -0
- package/dist/routes/chat.d.ts +13 -0
- package/dist/routes/chat.js +293 -0
- package/dist/routes/chatDataStream.d.ts +13 -0
- package/dist/routes/chatDataStream.js +352 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +495 -0
- package/dist/services/AgentSession.d.ts +356 -0
- package/dist/services/AgentSession.js +1208 -0
- package/dist/services/ArtifactParser.d.ts +105 -0
- package/dist/services/ArtifactParser.js +338 -0
- package/dist/services/ArtifactService.d.ts +123 -0
- package/dist/services/ArtifactService.js +612 -0
- package/dist/services/BaseCompressor.d.ts +183 -0
- package/dist/services/BaseCompressor.js +504 -0
- package/dist/services/ConversationCompressor.d.ts +32 -0
- package/dist/services/ConversationCompressor.js +91 -0
- package/dist/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/services/IncrementalStreamParser.js +327 -0
- package/dist/services/MidGenerationCompressor.d.ts +63 -0
- package/dist/services/MidGenerationCompressor.js +104 -0
- package/dist/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/services/PendingToolApprovalManager.js +133 -0
- package/dist/services/ResponseFormatter.d.ts +39 -0
- package/dist/services/ResponseFormatter.js +152 -0
- package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/tools/NativeSandboxExecutor.js +432 -0
- package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/tools/SandboxExecutorFactory.js +80 -0
- package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/tools/VercelSandboxExecutor.js +340 -0
- package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/tools/distill-conversation-history-tool.js +206 -0
- package/dist/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/tools/distill-conversation-tool.js +141 -0
- package/dist/tools/sandbox-utils.d.ts +18 -0
- package/dist/tools/sandbox-utils.js +53 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/execution-context.d.ts +46 -0
- package/dist/types/execution-context.js +27 -0
- package/dist/types/xml.d.ts +5 -0
- package/dist/utils/SchemaProcessor.d.ts +52 -0
- package/dist/utils/SchemaProcessor.js +182 -0
- package/dist/utils/agent-operations.d.ts +62 -0
- package/dist/utils/agent-operations.js +53 -0
- package/dist/utils/artifact-component-schema.d.ts +42 -0
- package/dist/utils/artifact-component-schema.js +186 -0
- package/dist/utils/cleanup.d.ts +21 -0
- package/dist/utils/cleanup.js +59 -0
- package/dist/utils/data-component-schema.d.ts +2 -0
- package/dist/utils/data-component-schema.js +3 -0
- package/dist/utils/default-status-schemas.d.ts +20 -0
- package/dist/utils/default-status-schemas.js +24 -0
- package/dist/utils/json-postprocessor.d.ts +13 -0
- package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +1 -2
- package/dist/utils/model-context-utils.d.ts +39 -0
- package/dist/utils/model-context-utils.js +181 -0
- package/dist/utils/model-resolver.d.ts +6 -0
- package/dist/utils/model-resolver.js +34 -0
- package/dist/utils/schema-validation.d.ts +44 -0
- package/dist/utils/schema-validation.js +97 -0
- package/dist/utils/stream-helpers.d.ts +197 -0
- package/dist/utils/stream-helpers.js +518 -0
- package/dist/utils/stream-registry.d.ts +22 -0
- package/dist/utils/stream-registry.js +34 -0
- package/dist/utils/token-estimator.d.ts +69 -0
- package/dist/utils/token-estimator.js +53 -0
- package/dist/utils/tracer.d.ts +7 -0
- package/dist/utils/tracer.js +7 -0
- package/package.json +5 -20
- package/dist/SandboxExecutorFactory.cjs +0 -895
- package/dist/SandboxExecutorFactory.js +0 -893
- package/dist/SandboxExecutorFactory.js.map +0 -1
- package/dist/chunk-VBDAOXYI.cjs +0 -927
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/chunk.cjs +0 -34
- package/dist/conversations.cjs +0 -7
- package/dist/conversations.js +0 -7
- package/dist/conversations2.cjs +0 -209
- package/dist/conversations2.js +0 -180
- package/dist/conversations2.js.map +0 -1
- package/dist/dbClient.cjs +0 -9676
- package/dist/dbClient.js +0 -9670
- package/dist/dbClient.js.map +0 -1
- package/dist/dbClient2.cjs +0 -5
- package/dist/dbClient2.js +0 -5
- package/dist/env.cjs +0 -59
- package/dist/env.js.map +0 -1
- package/dist/execution-limits.cjs +0 -260
- package/dist/execution-limits.js +0 -63
- package/dist/execution-limits.js.map +0 -1
- package/dist/index.cjs +0 -11260
- package/dist/index.d.cts +0 -36
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.cjs +0 -12
- package/dist/instrumentation.d.cts +0 -18
- package/dist/instrumentation.d.cts.map +0 -1
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation2.cjs +0 -116
- package/dist/instrumentation2.js +0 -69
- package/dist/instrumentation2.js.map +0 -1
- package/dist/json-postprocessor.js +0 -20
- package/dist/json-postprocessor.js.map +0 -1
- package/dist/logger.cjs +0 -5
- package/dist/logger2.cjs +0 -1
- package/dist/nodefs.cjs +0 -29
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.cjs +0 -367
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { LanguageModel } from "ai";
|
|
2
|
+
|
|
3
|
+
//#region src/agents/ModelFactory.d.ts
|
|
4
|
+
interface ModelSettings {
|
|
5
|
+
model?: string;
|
|
6
|
+
providerOptions?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Factory for creating AI SDK language models from configuration
|
|
10
|
+
* Supports multiple providers and AI Gateway integration
|
|
11
|
+
*/
|
|
12
|
+
declare class ModelFactory {
|
|
13
|
+
/**
|
|
14
|
+
* Create a provider instance with custom configuration
|
|
15
|
+
* Returns a provider with at least languageModel method
|
|
16
|
+
*/
|
|
17
|
+
private static createProvider;
|
|
18
|
+
/**
|
|
19
|
+
* Extract provider configuration from providerOptions
|
|
20
|
+
* Only includes settings that go to the provider constructor (baseURL, apiKey, etc.)
|
|
21
|
+
*/
|
|
22
|
+
private static extractProviderConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Create a language model instance from configuration
|
|
25
|
+
* Throws error if no config provided - models must be configured at project level
|
|
26
|
+
*/
|
|
27
|
+
static createModel(config: ModelSettings): LanguageModel;
|
|
28
|
+
/**
|
|
29
|
+
* Built-in providers that have special handling
|
|
30
|
+
*/
|
|
31
|
+
private static readonly BUILT_IN_PROVIDERS;
|
|
32
|
+
/**
|
|
33
|
+
* Parse model string to extract provider and model name
|
|
34
|
+
* Examples: "anthropic/claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" }
|
|
35
|
+
* "openrouter/anthropic/claude-sonnet-4" -> { provider: "openrouter", modelName: "anthropic/claude-sonnet-4" }
|
|
36
|
+
* "claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" } (default to anthropic)
|
|
37
|
+
*/
|
|
38
|
+
static parseModelString(modelString: string): {
|
|
39
|
+
provider: string;
|
|
40
|
+
modelName: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Get generation parameters from provider options
|
|
44
|
+
* These are parameters that get passed to generateText/streamText calls
|
|
45
|
+
*/
|
|
46
|
+
static getGenerationParams(providerOptions?: Record<string, unknown>): Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Prepare complete generation configuration from model settings
|
|
49
|
+
* Returns model instance and generation parameters ready to spread into generateText/streamText
|
|
50
|
+
* Includes maxDuration if specified in provider options (in seconds, following Vercel standard)
|
|
51
|
+
*/
|
|
52
|
+
static prepareGenerationConfig(modelSettings?: ModelSettings): {
|
|
53
|
+
model: LanguageModel;
|
|
54
|
+
maxDuration?: number;
|
|
55
|
+
} & Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Validate model settingsuration
|
|
58
|
+
* Basic validation only - let AI SDK handle parameter-specific validation
|
|
59
|
+
*/
|
|
60
|
+
static validateConfig(config: ModelSettings): string[];
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ModelFactory, ModelSettings };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
3
|
+
import { createGateway, gateway } from "@ai-sdk/gateway";
|
|
4
|
+
import { createGoogleGenerativeAI, google } from "@ai-sdk/google";
|
|
5
|
+
import { createOpenAI, openai } from "@ai-sdk/openai";
|
|
6
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
7
|
+
import { createOpenRouter, openrouter } from "@openrouter/ai-sdk-provider";
|
|
8
|
+
|
|
9
|
+
//#region src/agents/ModelFactory.ts
|
|
10
|
+
const logger = getLogger("ModelFactory");
|
|
11
|
+
const nimDefault = createOpenAICompatible({
|
|
12
|
+
name: "nim",
|
|
13
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
14
|
+
headers: { Authorization: `Bearer ${process.env.NIM_API_KEY}` }
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Factory for creating AI SDK language models from configuration
|
|
18
|
+
* Supports multiple providers and AI Gateway integration
|
|
19
|
+
*/
|
|
20
|
+
var ModelFactory = class ModelFactory {
|
|
21
|
+
/**
|
|
22
|
+
* Create a provider instance with custom configuration
|
|
23
|
+
* Returns a provider with at least languageModel method
|
|
24
|
+
*/
|
|
25
|
+
static createProvider(provider, config) {
|
|
26
|
+
switch (provider) {
|
|
27
|
+
case "anthropic": return createAnthropic(config);
|
|
28
|
+
case "openai": return createOpenAI(config);
|
|
29
|
+
case "google": return createGoogleGenerativeAI(config);
|
|
30
|
+
case "openrouter": return createOpenRouter(config);
|
|
31
|
+
case "gateway": return createGateway(config);
|
|
32
|
+
case "nim": return createOpenAICompatible({
|
|
33
|
+
name: "nim",
|
|
34
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
35
|
+
headers: { Authorization: `Bearer ${process.env.NIM_API_KEY}` },
|
|
36
|
+
...config
|
|
37
|
+
});
|
|
38
|
+
case "custom": {
|
|
39
|
+
if (!config.baseURL && !config.baseUrl) throw new Error("Custom provider requires baseURL. Please provide it in providerOptions.baseURL or providerOptions.baseUrl");
|
|
40
|
+
const customConfig = {
|
|
41
|
+
name: "custom",
|
|
42
|
+
baseURL: config.baseURL || config.baseUrl,
|
|
43
|
+
headers: {
|
|
44
|
+
...process.env.CUSTOM_LLM_API_KEY && { Authorization: `Bearer ${process.env.CUSTOM_LLM_API_KEY}` },
|
|
45
|
+
...config.headers || {}
|
|
46
|
+
},
|
|
47
|
+
...config
|
|
48
|
+
};
|
|
49
|
+
logger.info({ config: {
|
|
50
|
+
baseURL: customConfig.baseURL,
|
|
51
|
+
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
52
|
+
apiKeyPrefix: process.env.CUSTOM_LLM_API_KEY?.substring(0, 10) + "...",
|
|
53
|
+
headers: Object.keys(customConfig.headers || {})
|
|
54
|
+
} }, "Creating custom OpenAI-compatible provider");
|
|
55
|
+
return createOpenAICompatible(customConfig);
|
|
56
|
+
}
|
|
57
|
+
default: throw new Error(`Unsupported provider: ${provider}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract provider configuration from providerOptions
|
|
62
|
+
* Only includes settings that go to the provider constructor (baseURL, apiKey, etc.)
|
|
63
|
+
*/
|
|
64
|
+
static extractProviderConfig(providerOptions) {
|
|
65
|
+
if (!providerOptions) return {};
|
|
66
|
+
const providerConfig = {};
|
|
67
|
+
if (providerOptions.baseUrl || providerOptions.baseURL) providerConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
68
|
+
if (providerOptions.headers) providerConfig.headers = providerOptions.headers;
|
|
69
|
+
if (providerOptions.gateway) Object.assign(providerConfig, providerOptions.gateway);
|
|
70
|
+
if (providerOptions.nim) Object.assign(providerConfig, providerOptions.nim);
|
|
71
|
+
if (providerOptions.custom) Object.assign(providerConfig, providerOptions.custom);
|
|
72
|
+
return providerConfig;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a language model instance from configuration
|
|
76
|
+
* Throws error if no config provided - models must be configured at project level
|
|
77
|
+
*/
|
|
78
|
+
static createModel(config) {
|
|
79
|
+
if (!config?.model?.trim()) throw new Error("Model configuration is required. Please configure models at the project level.");
|
|
80
|
+
const modelSettings = config;
|
|
81
|
+
if (!modelSettings.model) throw new Error("Model configuration is required");
|
|
82
|
+
const modelString = modelSettings.model.trim();
|
|
83
|
+
const { provider, modelName } = ModelFactory.parseModelString(modelString);
|
|
84
|
+
logger.debug({
|
|
85
|
+
provider,
|
|
86
|
+
model: modelName,
|
|
87
|
+
fullModelString: modelSettings.model,
|
|
88
|
+
hasProviderOptions: !!modelSettings.providerOptions
|
|
89
|
+
}, "Creating language model from config");
|
|
90
|
+
const providerConfig = ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
91
|
+
if (Object.keys(providerConfig).length > 0) {
|
|
92
|
+
logger.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
93
|
+
return ModelFactory.createProvider(provider, providerConfig).languageModel(modelName);
|
|
94
|
+
}
|
|
95
|
+
switch (provider) {
|
|
96
|
+
case "anthropic": return anthropic(modelName);
|
|
97
|
+
case "openai": return openai(modelName);
|
|
98
|
+
case "google": return google(modelName);
|
|
99
|
+
case "openrouter": return openrouter(modelName);
|
|
100
|
+
case "gateway": return gateway(modelName);
|
|
101
|
+
case "nim": return nimDefault(modelName);
|
|
102
|
+
case "custom": throw new Error("Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL");
|
|
103
|
+
default: throw new Error(`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).`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Built-in providers that have special handling
|
|
108
|
+
*/
|
|
109
|
+
static BUILT_IN_PROVIDERS = [
|
|
110
|
+
"anthropic",
|
|
111
|
+
"openai",
|
|
112
|
+
"google",
|
|
113
|
+
"openrouter",
|
|
114
|
+
"gateway",
|
|
115
|
+
"nim",
|
|
116
|
+
"custom"
|
|
117
|
+
];
|
|
118
|
+
/**
|
|
119
|
+
* Parse model string to extract provider and model name
|
|
120
|
+
* Examples: "anthropic/claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" }
|
|
121
|
+
* "openrouter/anthropic/claude-sonnet-4" -> { provider: "openrouter", modelName: "anthropic/claude-sonnet-4" }
|
|
122
|
+
* "claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" } (default to anthropic)
|
|
123
|
+
*/
|
|
124
|
+
static parseModelString(modelString) {
|
|
125
|
+
if (modelString.includes("/")) {
|
|
126
|
+
const [provider, ...modelParts] = modelString.split("/");
|
|
127
|
+
const normalizedProvider = provider.toLowerCase();
|
|
128
|
+
if (!ModelFactory.BUILT_IN_PROVIDERS.includes(normalizedProvider)) throw new Error(`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).`);
|
|
129
|
+
return {
|
|
130
|
+
provider: normalizedProvider,
|
|
131
|
+
modelName: modelParts.join("/")
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`No provider specified in model string: ${modelString}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get generation parameters from provider options
|
|
138
|
+
* These are parameters that get passed to generateText/streamText calls
|
|
139
|
+
*/
|
|
140
|
+
static getGenerationParams(providerOptions) {
|
|
141
|
+
if (!providerOptions) return {};
|
|
142
|
+
const excludedKeys = [
|
|
143
|
+
"apiKey",
|
|
144
|
+
"baseURL",
|
|
145
|
+
"baseUrl",
|
|
146
|
+
"maxDuration",
|
|
147
|
+
"headers",
|
|
148
|
+
"gateway",
|
|
149
|
+
"nim",
|
|
150
|
+
"custom"
|
|
151
|
+
];
|
|
152
|
+
const params = {};
|
|
153
|
+
for (const [key, value] of Object.entries(providerOptions)) if (!excludedKeys.includes(key) && value !== void 0) params[key] = value;
|
|
154
|
+
return params;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Prepare complete generation configuration from model settings
|
|
158
|
+
* Returns model instance and generation parameters ready to spread into generateText/streamText
|
|
159
|
+
* Includes maxDuration if specified in provider options (in seconds, following Vercel standard)
|
|
160
|
+
*/
|
|
161
|
+
static prepareGenerationConfig(modelSettings) {
|
|
162
|
+
const modelString = modelSettings?.model?.trim();
|
|
163
|
+
const model = ModelFactory.createModel({
|
|
164
|
+
model: modelString,
|
|
165
|
+
providerOptions: modelSettings?.providerOptions
|
|
166
|
+
});
|
|
167
|
+
const generationParams = ModelFactory.getGenerationParams(modelSettings?.providerOptions);
|
|
168
|
+
const maxDuration = modelSettings?.providerOptions?.maxDuration;
|
|
169
|
+
return {
|
|
170
|
+
model,
|
|
171
|
+
...generationParams,
|
|
172
|
+
...maxDuration !== void 0 && { maxDuration }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validate model settingsuration
|
|
177
|
+
* Basic validation only - let AI SDK handle parameter-specific validation
|
|
178
|
+
*/
|
|
179
|
+
static validateConfig(config) {
|
|
180
|
+
const errors = [];
|
|
181
|
+
if (!config.model) errors.push("Model name is required");
|
|
182
|
+
if (config.providerOptions) {
|
|
183
|
+
if (config.providerOptions.apiKey) errors.push("API keys should not be stored in provider options. Use environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY) or credential store instead.");
|
|
184
|
+
if (config.providerOptions.maxDuration !== void 0) {
|
|
185
|
+
const maxDuration = config.providerOptions.maxDuration;
|
|
186
|
+
if (typeof maxDuration !== "number" || maxDuration <= 0) errors.push("maxDuration must be a positive number (in seconds)");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return errors;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { ModelFactory };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AssembleResult } from "../utils/token-estimator.js";
|
|
2
|
+
import { VersionConfig } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/agents/SystemPromptBuilder.d.ts
|
|
5
|
+
declare class SystemPromptBuilder<TConfig> {
|
|
6
|
+
private version;
|
|
7
|
+
private versionConfig;
|
|
8
|
+
private templates;
|
|
9
|
+
private loaded;
|
|
10
|
+
constructor(version: string, versionConfig: VersionConfig<TConfig>);
|
|
11
|
+
private loadTemplates;
|
|
12
|
+
/**
|
|
13
|
+
* Build the system prompt and return both the prompt string and token breakdown
|
|
14
|
+
*/
|
|
15
|
+
buildSystemPrompt(config: TConfig): AssembleResult;
|
|
16
|
+
private validateTemplateVariables;
|
|
17
|
+
getLoadedTemplates(): string[];
|
|
18
|
+
isLoaded(): boolean;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SystemPromptBuilder };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/agents/SystemPromptBuilder.ts
|
|
4
|
+
const logger = getLogger("SystemPromptBuilder");
|
|
5
|
+
var SystemPromptBuilder = class {
|
|
6
|
+
templates = /* @__PURE__ */ new Map();
|
|
7
|
+
loaded = false;
|
|
8
|
+
constructor(version, versionConfig) {
|
|
9
|
+
this.version = version;
|
|
10
|
+
this.versionConfig = versionConfig;
|
|
11
|
+
}
|
|
12
|
+
loadTemplates() {
|
|
13
|
+
if (this.loaded) return;
|
|
14
|
+
try {
|
|
15
|
+
const loadedTemplates = this.versionConfig.loadTemplates();
|
|
16
|
+
for (const [name, content] of loadedTemplates) this.templates.set(name, content);
|
|
17
|
+
this.loaded = true;
|
|
18
|
+
logger.debug({
|
|
19
|
+
templateCount: this.templates.size,
|
|
20
|
+
version: this.version
|
|
21
|
+
}, `Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
24
|
+
throw new Error(`Template loading failed: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the system prompt and return both the prompt string and token breakdown
|
|
29
|
+
*/
|
|
30
|
+
buildSystemPrompt(config) {
|
|
31
|
+
this.loadTemplates();
|
|
32
|
+
this.validateTemplateVariables(config);
|
|
33
|
+
return this.versionConfig.assemble(this.templates, config);
|
|
34
|
+
}
|
|
35
|
+
validateTemplateVariables(config) {
|
|
36
|
+
if (!config) throw new Error("Configuration object is required");
|
|
37
|
+
if (typeof config !== "object") throw new Error("Configuration must be an object");
|
|
38
|
+
}
|
|
39
|
+
getLoadedTemplates() {
|
|
40
|
+
return Array.from(this.templates.keys());
|
|
41
|
+
}
|
|
42
|
+
isLoaded() {
|
|
43
|
+
return this.loaded;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { SystemPromptBuilder };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/agents/ToolSessionManager.d.ts
|
|
2
|
+
interface ToolResultRecord {
|
|
3
|
+
toolCallId: string;
|
|
4
|
+
toolName: string;
|
|
5
|
+
args?: any;
|
|
6
|
+
result: any;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}
|
|
9
|
+
interface ToolSession {
|
|
10
|
+
sessionId: string;
|
|
11
|
+
tenantId: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
contextId: string;
|
|
14
|
+
taskId: string;
|
|
15
|
+
toolResults: Map<string, ToolResultRecord>;
|
|
16
|
+
createdAt: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages tool execution state during agent generation sessions.
|
|
20
|
+
* Allows tools to access previous tool call results within the same execution.
|
|
21
|
+
*/
|
|
22
|
+
declare class ToolSessionManager {
|
|
23
|
+
private static instance;
|
|
24
|
+
private sessions;
|
|
25
|
+
private constructor();
|
|
26
|
+
static getInstance(): ToolSessionManager;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new tool session for an agent execution
|
|
29
|
+
*/
|
|
30
|
+
createSession(tenantId: string, projectId: string, contextId: string, taskId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new tool session with a specific ID (for coordination with AgentSession)
|
|
33
|
+
*/
|
|
34
|
+
createSessionWithId(sessionId: string, tenantId: string, projectId: string, contextId: string, taskId: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Ensure an agent-scoped session exists (idempotent)
|
|
37
|
+
* All agents in the same agent execution share this session
|
|
38
|
+
*/
|
|
39
|
+
ensureAgentSession(sessionId: string, tenantId: string, projectId: string, contextId: string, taskId: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Record a tool result in the session
|
|
42
|
+
*/
|
|
43
|
+
recordToolResult(sessionId: string, toolResult: ToolResultRecord): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get a tool result by toolCallId within a session
|
|
46
|
+
*/
|
|
47
|
+
getToolResult(sessionId: string, toolCallId: string): ToolResultRecord | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Get session info
|
|
50
|
+
*/
|
|
51
|
+
getSession(sessionId: string): ToolSession | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Clean up a session after agent execution completes
|
|
54
|
+
*/
|
|
55
|
+
endSession(sessionId: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Remove expired sessions to prevent memory leaks
|
|
58
|
+
*/
|
|
59
|
+
private cleanupExpiredSessions;
|
|
60
|
+
}
|
|
61
|
+
declare const toolSessionManager: ToolSessionManager;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ToolResultRecord, ToolSession, ToolSessionManager, toolSessionManager };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { SESSION_CLEANUP_INTERVAL_MS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS } from "../constants/execution-limits/index.js";
|
|
3
|
+
import { generateId } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/agents/ToolSessionManager.ts
|
|
6
|
+
const logger = getLogger("ToolSessionManager");
|
|
7
|
+
/**
|
|
8
|
+
* Manages tool execution state during agent generation sessions.
|
|
9
|
+
* Allows tools to access previous tool call results within the same execution.
|
|
10
|
+
*/
|
|
11
|
+
var ToolSessionManager = class ToolSessionManager {
|
|
12
|
+
static instance;
|
|
13
|
+
sessions = /* @__PURE__ */ new Map();
|
|
14
|
+
constructor() {
|
|
15
|
+
setInterval(() => this.cleanupExpiredSessions(), SESSION_CLEANUP_INTERVAL_MS);
|
|
16
|
+
}
|
|
17
|
+
static getInstance() {
|
|
18
|
+
if (!ToolSessionManager.instance) ToolSessionManager.instance = new ToolSessionManager();
|
|
19
|
+
return ToolSessionManager.instance;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a new tool session for an agent execution
|
|
23
|
+
*/
|
|
24
|
+
createSession(tenantId, projectId, contextId, taskId) {
|
|
25
|
+
const sessionId = generateId();
|
|
26
|
+
return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a new tool session with a specific ID (for coordination with AgentSession)
|
|
30
|
+
*/
|
|
31
|
+
createSessionWithId(sessionId, tenantId, projectId, contextId, taskId) {
|
|
32
|
+
const session = {
|
|
33
|
+
sessionId,
|
|
34
|
+
tenantId,
|
|
35
|
+
projectId,
|
|
36
|
+
contextId,
|
|
37
|
+
taskId,
|
|
38
|
+
toolResults: /* @__PURE__ */ new Map(),
|
|
39
|
+
createdAt: Date.now()
|
|
40
|
+
};
|
|
41
|
+
this.sessions.set(sessionId, session);
|
|
42
|
+
logger.debug({
|
|
43
|
+
sessionId,
|
|
44
|
+
tenantId,
|
|
45
|
+
contextId,
|
|
46
|
+
taskId,
|
|
47
|
+
totalSessions: this.sessions.size
|
|
48
|
+
}, "Created tool session with ID");
|
|
49
|
+
return sessionId;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Ensure an agent-scoped session exists (idempotent)
|
|
53
|
+
* All agents in the same agent execution share this session
|
|
54
|
+
*/
|
|
55
|
+
ensureAgentSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
56
|
+
if (this.sessions.has(sessionId)) {
|
|
57
|
+
logger.debug({ sessionId }, "Agent session already exists, reusing");
|
|
58
|
+
return sessionId;
|
|
59
|
+
}
|
|
60
|
+
logger.debug({
|
|
61
|
+
sessionId,
|
|
62
|
+
tenantId,
|
|
63
|
+
contextId,
|
|
64
|
+
taskId
|
|
65
|
+
}, "Creating new agent-scoped tool session");
|
|
66
|
+
return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Record a tool result in the session
|
|
70
|
+
*/
|
|
71
|
+
recordToolResult(sessionId, toolResult) {
|
|
72
|
+
const session = this.sessions.get(sessionId);
|
|
73
|
+
if (!session) {
|
|
74
|
+
logger.warn({
|
|
75
|
+
sessionId,
|
|
76
|
+
toolCallId: toolResult.toolCallId,
|
|
77
|
+
availableSessionIds: Array.from(this.sessions.keys()),
|
|
78
|
+
totalSessions: this.sessions.size
|
|
79
|
+
}, "Tool result recorded for unknown session");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
83
|
+
logger.debug({
|
|
84
|
+
sessionId,
|
|
85
|
+
toolCallId: toolResult.toolCallId,
|
|
86
|
+
toolName: toolResult.toolName
|
|
87
|
+
}, "Tool result recorded successfully");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get a tool result by toolCallId within a session
|
|
91
|
+
*/
|
|
92
|
+
getToolResult(sessionId, toolCallId) {
|
|
93
|
+
const session = this.sessions.get(sessionId);
|
|
94
|
+
if (!session) {
|
|
95
|
+
logger.warn({
|
|
96
|
+
sessionId,
|
|
97
|
+
toolCallId,
|
|
98
|
+
availableSessionIds: Array.from(this.sessions.keys()),
|
|
99
|
+
totalSessions: this.sessions.size
|
|
100
|
+
}, "Requested tool result for unknown session");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const result = session.toolResults.get(toolCallId);
|
|
104
|
+
if (!result) logger.warn({
|
|
105
|
+
sessionId,
|
|
106
|
+
toolCallId,
|
|
107
|
+
availableToolResultIds: Array.from(session.toolResults.keys()),
|
|
108
|
+
totalToolResults: session.toolResults.size
|
|
109
|
+
}, "Tool result not found");
|
|
110
|
+
else logger.debug({
|
|
111
|
+
sessionId,
|
|
112
|
+
toolCallId,
|
|
113
|
+
toolName: result.toolName
|
|
114
|
+
}, "Tool result found successfully");
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get session info
|
|
119
|
+
*/
|
|
120
|
+
getSession(sessionId) {
|
|
121
|
+
return this.sessions.get(sessionId);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Clean up a session after agent execution completes
|
|
125
|
+
*/
|
|
126
|
+
endSession(sessionId) {
|
|
127
|
+
if (this.sessions.get(sessionId)) this.sessions.delete(sessionId);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Remove expired sessions to prevent memory leaks
|
|
131
|
+
*/
|
|
132
|
+
cleanupExpiredSessions() {
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
const expiredSessions = [];
|
|
135
|
+
for (const [sessionId, session] of this.sessions.entries()) if (now - session.createdAt > SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS) expiredSessions.push(sessionId);
|
|
136
|
+
for (const sessionId of expiredSessions) {
|
|
137
|
+
this.sessions.delete(sessionId);
|
|
138
|
+
logger.debug({ sessionId }, "Cleaned up expired tool session");
|
|
139
|
+
}
|
|
140
|
+
if (expiredSessions.length > 0) logger.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const toolSessionManager = ToolSessionManager.getInstance();
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
export { ToolSessionManager, toolSessionManager };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { A2ATask, A2ATaskResult } from "../a2a/types.js";
|
|
2
|
+
import { SandboxConfig } from "../types/execution-context.js";
|
|
3
|
+
import { AgentConversationHistoryConfig, CredentialStoreRegistry, SubAgentApiSelect } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/agents/generateTaskHandler.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Serializable configuration for creating task handlers
|
|
9
|
+
*/
|
|
10
|
+
interface TaskHandlerConfig {
|
|
11
|
+
tenantId: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
agentId: string;
|
|
14
|
+
subAgentId: string;
|
|
15
|
+
agentSchema: SubAgentApiSelect;
|
|
16
|
+
name: string;
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
contextConfigId?: string;
|
|
21
|
+
conversationHistoryConfig?: AgentConversationHistoryConfig;
|
|
22
|
+
sandboxConfig?: SandboxConfig;
|
|
23
|
+
/** User ID for user-scoped credential lookups (available when request is from authenticated user) */
|
|
24
|
+
userId?: string;
|
|
25
|
+
}
|
|
26
|
+
declare const createTaskHandler: (config: TaskHandlerConfig, credentialStoreRegistry?: CredentialStoreRegistry) => (task: A2ATask) => Promise<A2ATaskResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes a TaskHandlerConfig to JSON
|
|
29
|
+
*/
|
|
30
|
+
declare const serializeTaskHandlerConfig: (config: TaskHandlerConfig) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Deserializes a TaskHandlerConfig from JSON
|
|
33
|
+
*/
|
|
34
|
+
declare const deserializeTaskHandlerConfig: (configJson: string) => TaskHandlerConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a task handler configuration from agent data
|
|
37
|
+
*/
|
|
38
|
+
declare const createTaskHandlerConfig: (params: {
|
|
39
|
+
tenantId: string;
|
|
40
|
+
projectId: string;
|
|
41
|
+
agentId: string;
|
|
42
|
+
subAgentId: string;
|
|
43
|
+
baseUrl: string;
|
|
44
|
+
apiKey?: string;
|
|
45
|
+
sandboxConfig?: SandboxConfig;
|
|
46
|
+
userId?: string;
|
|
47
|
+
}) => Promise<TaskHandlerConfig>;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { TaskHandlerConfig, createTaskHandler, createTaskHandlerConfig, deserializeTaskHandlerConfig, serializeTaskHandlerConfig };
|