@inkeep/agents-run-api 0.37.0 → 0.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SandboxExecutorFactory-NUNGK35F.js → SandboxExecutorFactory-A2LTPE2X.js} +3 -4
- package/dist/{chunk-OAAX46OE.js → chunk-BQB27EXW.js} +3 -3
- package/dist/{chunk-HUZGFAUJ.js → chunk-CDYXP4BN.js} +2 -1
- package/dist/{chunk-2LBNQ773.js → chunk-QOUOKHYQ.js} +1 -1
- package/dist/{chunk-IVALDC72.js → chunk-SUUSOBLI.js} +1 -1
- package/dist/{chunk-D3AB2AZW.js → chunk-W6UIBREL.js} +1 -1
- package/dist/{conversations-YFQ52RQB.js → conversations-33GSAG2C.js} +1 -1
- package/dist/dbClient-47AP7OHJ.js +1 -0
- package/dist/index.cjs +673 -538
- package/dist/index.js +570 -432
- package/dist/instrumentation.cjs +19 -18
- package/dist/instrumentation.js +1 -1
- package/package.json +6 -4
- package/dist/dbClient-XK4IR7QF.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var agentsCore = require('@inkeep/agents-core');
|
|
6
|
-
var
|
|
6
|
+
var zodOpenapi = require('@hono/zod-openapi');
|
|
7
7
|
var s3 = require('fs');
|
|
8
8
|
var o3 = require('path');
|
|
9
9
|
var schema = require('@inkeep/agents-core/db/schema');
|
|
@@ -13,7 +13,6 @@ var crypto2 = require('crypto');
|
|
|
13
13
|
var os = require('os');
|
|
14
14
|
var sandbox = require('@vercel/sandbox');
|
|
15
15
|
var otel = require('@hono/otel');
|
|
16
|
-
var zodOpenapi = require('@hono/zod-openapi');
|
|
17
16
|
var api = require('@opentelemetry/api');
|
|
18
17
|
var hono = require('hono');
|
|
19
18
|
var cors = require('hono/cors');
|
|
@@ -32,12 +31,6 @@ var factory = require('hono/factory');
|
|
|
32
31
|
var swaggerUi = require('@hono/swagger-ui');
|
|
33
32
|
var streaming = require('hono/streaming');
|
|
34
33
|
var ai = require('ai');
|
|
35
|
-
var anthropic = require('@ai-sdk/anthropic');
|
|
36
|
-
var gateway = require('@ai-sdk/gateway');
|
|
37
|
-
var google = require('@ai-sdk/google');
|
|
38
|
-
var openai = require('@ai-sdk/openai');
|
|
39
|
-
var openaiCompatible = require('@ai-sdk/openai-compatible');
|
|
40
|
-
var aiSdkProvider = require('@openrouter/ai-sdk-provider');
|
|
41
34
|
var jmespath = require('jmespath');
|
|
42
35
|
var Ajv = require('ajv');
|
|
43
36
|
var destr = require('destr');
|
|
@@ -67,7 +60,6 @@ function _interopNamespace(e) {
|
|
|
67
60
|
return Object.freeze(n);
|
|
68
61
|
}
|
|
69
62
|
|
|
70
|
-
var z8__default = /*#__PURE__*/_interopDefault(z8);
|
|
71
63
|
var s3__namespace = /*#__PURE__*/_interopNamespace(s3);
|
|
72
64
|
var o3__namespace = /*#__PURE__*/_interopNamespace(o3);
|
|
73
65
|
var schema__namespace = /*#__PURE__*/_interopNamespace(schema);
|
|
@@ -90,28 +82,29 @@ var envSchema, parseEnv, env;
|
|
|
90
82
|
var init_env = __esm({
|
|
91
83
|
"src/env.ts"() {
|
|
92
84
|
agentsCore.loadEnvironmentFiles();
|
|
93
|
-
envSchema =
|
|
94
|
-
NODE_ENV:
|
|
95
|
-
ENVIRONMENT:
|
|
96
|
-
DATABASE_URL:
|
|
97
|
-
INKEEP_AGENTS_RUN_API_URL:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
envSchema = zodOpenapi.z.object({
|
|
86
|
+
NODE_ENV: zodOpenapi.z.enum(["development", "production", "test"]).optional(),
|
|
87
|
+
ENVIRONMENT: zodOpenapi.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
|
|
88
|
+
DATABASE_URL: zodOpenapi.z.string().optional(),
|
|
89
|
+
INKEEP_AGENTS_RUN_API_URL: zodOpenapi.z.string().optional().default("http://localhost:3003"),
|
|
90
|
+
AGENTS_MANAGE_UI_URL: zodOpenapi.z.string().optional().default("http://localhost:3000"),
|
|
91
|
+
LOG_LEVEL: zodOpenapi.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
|
|
92
|
+
NANGO_SERVER_URL: zodOpenapi.z.string().optional().default("https://api.nango.dev"),
|
|
93
|
+
NANGO_SECRET_KEY: zodOpenapi.z.string().optional(),
|
|
94
|
+
ANTHROPIC_API_KEY: zodOpenapi.z.string(),
|
|
95
|
+
OPENAI_API_KEY: zodOpenapi.z.string().optional(),
|
|
96
|
+
GOOGLE_GENERATIVE_AI_API_KEY: zodOpenapi.z.string().optional(),
|
|
97
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: zodOpenapi.z.string().optional(),
|
|
98
|
+
INKEEP_AGENTS_JWT_SIGNING_SECRET: zodOpenapi.z.string().optional(),
|
|
99
|
+
INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: zodOpenapi.z.string().optional(),
|
|
100
|
+
OTEL_BSP_SCHEDULE_DELAY: zodOpenapi.z.coerce.number().optional().default(500),
|
|
101
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: zodOpenapi.z.coerce.number().optional().default(64)
|
|
109
102
|
});
|
|
110
103
|
parseEnv = () => {
|
|
111
104
|
try {
|
|
112
105
|
return envSchema.parse(process.env);
|
|
113
106
|
} catch (error) {
|
|
114
|
-
if (error instanceof
|
|
107
|
+
if (error instanceof zodOpenapi.z.ZodError) {
|
|
115
108
|
const missingVars = error.issues.map((issue) => issue.path.join("."));
|
|
116
109
|
throw new Error(
|
|
117
110
|
`\u274C Invalid environment variables: ${missingVars.join(", ")}
|
|
@@ -6249,11 +6242,11 @@ var init_execution_limits = __esm({
|
|
|
6249
6242
|
init_defaults();
|
|
6250
6243
|
init_defaults();
|
|
6251
6244
|
agentsCore.loadEnvironmentFiles();
|
|
6252
|
-
constantsSchema =
|
|
6245
|
+
constantsSchema = zodOpenapi.z.object(
|
|
6253
6246
|
Object.fromEntries(
|
|
6254
6247
|
Object.keys(executionLimitsDefaults).map((key) => [
|
|
6255
6248
|
`AGENTS_${key}`,
|
|
6256
|
-
|
|
6249
|
+
zodOpenapi.z.coerce.number().optional()
|
|
6257
6250
|
])
|
|
6258
6251
|
)
|
|
6259
6252
|
);
|
|
@@ -6741,10 +6734,9 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6741
6734
|
"Reusing cached sandbox"
|
|
6742
6735
|
);
|
|
6743
6736
|
return sandbox.sandboxDir;
|
|
6744
|
-
} else {
|
|
6745
|
-
this.cleanupSandbox(sandbox.sandboxDir);
|
|
6746
|
-
delete this.sandboxPool[poolKey];
|
|
6747
6737
|
}
|
|
6738
|
+
this.cleanupSandbox(sandbox.sandboxDir);
|
|
6739
|
+
delete this.sandboxPool[poolKey];
|
|
6748
6740
|
}
|
|
6749
6741
|
return null;
|
|
6750
6742
|
}
|
|
@@ -8238,6 +8230,21 @@ async function handleMessageSend(c2, agent, request) {
|
|
|
8238
8230
|
});
|
|
8239
8231
|
}
|
|
8240
8232
|
}
|
|
8233
|
+
if (result.status.state === agentsCore.TaskState.Failed) {
|
|
8234
|
+
const isConnectionRefused = result.status.type === "connection_refused";
|
|
8235
|
+
if (isConnectionRefused) {
|
|
8236
|
+
return c2.json({
|
|
8237
|
+
jsonrpc: "2.0",
|
|
8238
|
+
error: {
|
|
8239
|
+
code: -32603,
|
|
8240
|
+
message: result.status.message || "Agent execution failed",
|
|
8241
|
+
data: {
|
|
8242
|
+
type: "connection_refused"
|
|
8243
|
+
}
|
|
8244
|
+
}
|
|
8245
|
+
});
|
|
8246
|
+
}
|
|
8247
|
+
}
|
|
8241
8248
|
const taskStatus = {
|
|
8242
8249
|
state: result.status.state,
|
|
8243
8250
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -8588,275 +8595,10 @@ async function handleTasksResubscribe(c2, agent, request) {
|
|
|
8588
8595
|
init_dbClient();
|
|
8589
8596
|
init_logger();
|
|
8590
8597
|
|
|
8591
|
-
// src/agents/ModelFactory.ts
|
|
8592
|
-
init_logger();
|
|
8593
|
-
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
8594
|
-
var nimDefault = openaiCompatible.createOpenAICompatible({
|
|
8595
|
-
name: "nim",
|
|
8596
|
-
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
8597
|
-
headers: {
|
|
8598
|
-
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
8599
|
-
}
|
|
8600
|
-
});
|
|
8601
|
-
var ModelFactory = class _ModelFactory {
|
|
8602
|
-
/**
|
|
8603
|
-
* Create a provider instance with custom configuration
|
|
8604
|
-
*/
|
|
8605
|
-
static createProvider(provider, config) {
|
|
8606
|
-
switch (provider) {
|
|
8607
|
-
case "anthropic":
|
|
8608
|
-
return anthropic.createAnthropic(config);
|
|
8609
|
-
case "openai":
|
|
8610
|
-
return openai.createOpenAI(config);
|
|
8611
|
-
case "google":
|
|
8612
|
-
return google.createGoogleGenerativeAI(config);
|
|
8613
|
-
case "openrouter":
|
|
8614
|
-
return {
|
|
8615
|
-
...aiSdkProvider.createOpenRouter(config),
|
|
8616
|
-
textEmbeddingModel: () => {
|
|
8617
|
-
throw new Error("OpenRouter does not support text embeddings");
|
|
8618
|
-
},
|
|
8619
|
-
imageModel: () => {
|
|
8620
|
-
throw new Error("OpenRouter does not support image generation");
|
|
8621
|
-
}
|
|
8622
|
-
};
|
|
8623
|
-
case "gateway":
|
|
8624
|
-
return gateway.createGateway(config);
|
|
8625
|
-
case "nim": {
|
|
8626
|
-
const nimConfig = {
|
|
8627
|
-
name: "nim",
|
|
8628
|
-
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
8629
|
-
headers: {
|
|
8630
|
-
Authorization: `Bearer ${process.env.NIM_API_KEY}`
|
|
8631
|
-
},
|
|
8632
|
-
...config
|
|
8633
|
-
};
|
|
8634
|
-
return openaiCompatible.createOpenAICompatible(nimConfig);
|
|
8635
|
-
}
|
|
8636
|
-
case "custom": {
|
|
8637
|
-
if (!config.baseURL && !config.baseUrl) {
|
|
8638
|
-
throw new Error(
|
|
8639
|
-
"Custom provider requires baseURL. Please provide it in providerOptions.baseURL or providerOptions.baseUrl"
|
|
8640
|
-
);
|
|
8641
|
-
}
|
|
8642
|
-
const customConfig = {
|
|
8643
|
-
name: "custom",
|
|
8644
|
-
baseURL: config.baseURL || config.baseUrl,
|
|
8645
|
-
headers: {
|
|
8646
|
-
...process.env.CUSTOM_LLM_API_KEY && {
|
|
8647
|
-
Authorization: `Bearer ${process.env.CUSTOM_LLM_API_KEY}`
|
|
8648
|
-
},
|
|
8649
|
-
...config.headers || {}
|
|
8650
|
-
},
|
|
8651
|
-
...config
|
|
8652
|
-
};
|
|
8653
|
-
logger4.info(
|
|
8654
|
-
{
|
|
8655
|
-
config: {
|
|
8656
|
-
baseURL: customConfig.baseURL,
|
|
8657
|
-
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
8658
|
-
apiKeyPrefix: process.env.CUSTOM_LLM_API_KEY?.substring(0, 10) + "...",
|
|
8659
|
-
headers: Object.keys(customConfig.headers || {})
|
|
8660
|
-
}
|
|
8661
|
-
},
|
|
8662
|
-
"Creating custom OpenAI-compatible provider"
|
|
8663
|
-
);
|
|
8664
|
-
return openaiCompatible.createOpenAICompatible(customConfig);
|
|
8665
|
-
}
|
|
8666
|
-
default:
|
|
8667
|
-
throw new Error(`Unsupported provider: ${provider}`);
|
|
8668
|
-
}
|
|
8669
|
-
}
|
|
8670
|
-
/**
|
|
8671
|
-
* Extract provider configuration from providerOptions
|
|
8672
|
-
* Only includes settings that go to the provider constructor (baseURL, apiKey, etc.)
|
|
8673
|
-
*/
|
|
8674
|
-
static extractProviderConfig(providerOptions) {
|
|
8675
|
-
if (!providerOptions) {
|
|
8676
|
-
return {};
|
|
8677
|
-
}
|
|
8678
|
-
const providerConfig = {};
|
|
8679
|
-
if (providerOptions.baseUrl || providerOptions.baseURL) {
|
|
8680
|
-
providerConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
8681
|
-
}
|
|
8682
|
-
if (providerOptions.headers) {
|
|
8683
|
-
providerConfig.headers = providerOptions.headers;
|
|
8684
|
-
}
|
|
8685
|
-
if (providerOptions.gateway) {
|
|
8686
|
-
Object.assign(providerConfig, providerOptions.gateway);
|
|
8687
|
-
}
|
|
8688
|
-
if (providerOptions.nim) {
|
|
8689
|
-
Object.assign(providerConfig, providerOptions.nim);
|
|
8690
|
-
}
|
|
8691
|
-
if (providerOptions.custom) {
|
|
8692
|
-
Object.assign(providerConfig, providerOptions.custom);
|
|
8693
|
-
}
|
|
8694
|
-
return providerConfig;
|
|
8695
|
-
}
|
|
8696
|
-
/**
|
|
8697
|
-
* Create a language model instance from configuration
|
|
8698
|
-
* Throws error if no config provided - models must be configured at project level
|
|
8699
|
-
*/
|
|
8700
|
-
static createModel(config) {
|
|
8701
|
-
if (!config?.model?.trim()) {
|
|
8702
|
-
throw new Error(
|
|
8703
|
-
"Model configuration is required. Please configure models at the project level."
|
|
8704
|
-
);
|
|
8705
|
-
}
|
|
8706
|
-
const modelSettings = config;
|
|
8707
|
-
if (!modelSettings.model) {
|
|
8708
|
-
throw new Error("Model configuration is required");
|
|
8709
|
-
}
|
|
8710
|
-
const modelString = modelSettings.model.trim();
|
|
8711
|
-
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
8712
|
-
logger4.debug(
|
|
8713
|
-
{
|
|
8714
|
-
provider,
|
|
8715
|
-
model: modelName,
|
|
8716
|
-
fullModelString: modelSettings.model,
|
|
8717
|
-
hasProviderOptions: !!modelSettings.providerOptions
|
|
8718
|
-
},
|
|
8719
|
-
"Creating language model from config"
|
|
8720
|
-
);
|
|
8721
|
-
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
8722
|
-
if (Object.keys(providerConfig).length > 0) {
|
|
8723
|
-
logger4.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
8724
|
-
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
8725
|
-
return customProvider.languageModel(modelName);
|
|
8726
|
-
}
|
|
8727
|
-
switch (provider) {
|
|
8728
|
-
case "anthropic":
|
|
8729
|
-
return anthropic.anthropic(modelName);
|
|
8730
|
-
case "openai":
|
|
8731
|
-
return openai.openai(modelName);
|
|
8732
|
-
case "google":
|
|
8733
|
-
return google.google(modelName);
|
|
8734
|
-
case "openrouter":
|
|
8735
|
-
return aiSdkProvider.openrouter(modelName);
|
|
8736
|
-
case "gateway":
|
|
8737
|
-
return gateway.gateway(modelName);
|
|
8738
|
-
case "nim":
|
|
8739
|
-
return nimDefault(modelName);
|
|
8740
|
-
case "custom":
|
|
8741
|
-
throw new Error(
|
|
8742
|
-
"Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL"
|
|
8743
|
-
);
|
|
8744
|
-
default:
|
|
8745
|
-
throw new Error(
|
|
8746
|
-
`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).`
|
|
8747
|
-
);
|
|
8748
|
-
}
|
|
8749
|
-
}
|
|
8750
|
-
/**
|
|
8751
|
-
* Built-in providers that have special handling
|
|
8752
|
-
*/
|
|
8753
|
-
static BUILT_IN_PROVIDERS = [
|
|
8754
|
-
"anthropic",
|
|
8755
|
-
"openai",
|
|
8756
|
-
"google",
|
|
8757
|
-
"openrouter",
|
|
8758
|
-
"gateway",
|
|
8759
|
-
"nim",
|
|
8760
|
-
"custom"
|
|
8761
|
-
];
|
|
8762
|
-
/**
|
|
8763
|
-
* Parse model string to extract provider and model name
|
|
8764
|
-
* Examples: "anthropic/claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" }
|
|
8765
|
-
* "openrouter/anthropic/claude-sonnet-4" -> { provider: "openrouter", modelName: "anthropic/claude-sonnet-4" }
|
|
8766
|
-
* "claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" } (default to anthropic)
|
|
8767
|
-
*/
|
|
8768
|
-
static parseModelString(modelString) {
|
|
8769
|
-
if (modelString.includes("/")) {
|
|
8770
|
-
const [provider, ...modelParts] = modelString.split("/");
|
|
8771
|
-
const normalizedProvider = provider.toLowerCase();
|
|
8772
|
-
if (!_ModelFactory.BUILT_IN_PROVIDERS.includes(normalizedProvider)) {
|
|
8773
|
-
throw new Error(
|
|
8774
|
-
`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).`
|
|
8775
|
-
);
|
|
8776
|
-
}
|
|
8777
|
-
return {
|
|
8778
|
-
provider: normalizedProvider,
|
|
8779
|
-
modelName: modelParts.join("/")
|
|
8780
|
-
// In case model name has slashes
|
|
8781
|
-
};
|
|
8782
|
-
}
|
|
8783
|
-
throw new Error(`No provider specified in model string: ${modelString}`);
|
|
8784
|
-
}
|
|
8785
|
-
/**
|
|
8786
|
-
* Get generation parameters from provider options
|
|
8787
|
-
* These are parameters that get passed to generateText/streamText calls
|
|
8788
|
-
*/
|
|
8789
|
-
static getGenerationParams(providerOptions) {
|
|
8790
|
-
if (!providerOptions) {
|
|
8791
|
-
return {};
|
|
8792
|
-
}
|
|
8793
|
-
const excludedKeys = [
|
|
8794
|
-
"apiKey",
|
|
8795
|
-
"baseURL",
|
|
8796
|
-
"baseUrl",
|
|
8797
|
-
"maxDuration",
|
|
8798
|
-
"headers",
|
|
8799
|
-
"gateway",
|
|
8800
|
-
"nim",
|
|
8801
|
-
"custom"
|
|
8802
|
-
];
|
|
8803
|
-
const params = {};
|
|
8804
|
-
for (const [key, value] of Object.entries(providerOptions)) {
|
|
8805
|
-
if (!excludedKeys.includes(key) && value !== void 0) {
|
|
8806
|
-
params[key] = value;
|
|
8807
|
-
}
|
|
8808
|
-
}
|
|
8809
|
-
return params;
|
|
8810
|
-
}
|
|
8811
|
-
/**
|
|
8812
|
-
* Prepare complete generation configuration from model settings
|
|
8813
|
-
* Returns model instance and generation parameters ready to spread into generateText/streamText
|
|
8814
|
-
* Includes maxDuration if specified in provider options (in seconds, following Vercel standard)
|
|
8815
|
-
*/
|
|
8816
|
-
static prepareGenerationConfig(modelSettings) {
|
|
8817
|
-
const modelString = modelSettings?.model?.trim();
|
|
8818
|
-
const model = _ModelFactory.createModel({
|
|
8819
|
-
model: modelString,
|
|
8820
|
-
providerOptions: modelSettings?.providerOptions
|
|
8821
|
-
});
|
|
8822
|
-
const generationParams = _ModelFactory.getGenerationParams(modelSettings?.providerOptions);
|
|
8823
|
-
const maxDuration = modelSettings?.providerOptions?.maxDuration;
|
|
8824
|
-
return {
|
|
8825
|
-
model,
|
|
8826
|
-
...generationParams,
|
|
8827
|
-
...maxDuration !== void 0 && { maxDuration }
|
|
8828
|
-
};
|
|
8829
|
-
}
|
|
8830
|
-
/**
|
|
8831
|
-
* Validate model settingsuration
|
|
8832
|
-
* Basic validation only - let AI SDK handle parameter-specific validation
|
|
8833
|
-
*/
|
|
8834
|
-
static validateConfig(config) {
|
|
8835
|
-
const errors = [];
|
|
8836
|
-
if (!config.model) {
|
|
8837
|
-
errors.push("Model name is required");
|
|
8838
|
-
}
|
|
8839
|
-
if (config.providerOptions) {
|
|
8840
|
-
if (config.providerOptions.apiKey) {
|
|
8841
|
-
errors.push(
|
|
8842
|
-
"API keys should not be stored in provider options. Use environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY) or credential store instead."
|
|
8843
|
-
);
|
|
8844
|
-
}
|
|
8845
|
-
if (config.providerOptions.maxDuration !== void 0) {
|
|
8846
|
-
const maxDuration = config.providerOptions.maxDuration;
|
|
8847
|
-
if (typeof maxDuration !== "number" || maxDuration <= 0) {
|
|
8848
|
-
errors.push("maxDuration must be a positive number (in seconds)");
|
|
8849
|
-
}
|
|
8850
|
-
}
|
|
8851
|
-
}
|
|
8852
|
-
return errors;
|
|
8853
|
-
}
|
|
8854
|
-
};
|
|
8855
|
-
|
|
8856
8598
|
// src/agents/ToolSessionManager.ts
|
|
8857
8599
|
init_execution_limits();
|
|
8858
8600
|
init_logger();
|
|
8859
|
-
var
|
|
8601
|
+
var logger4 = agentsCore.getLogger("ToolSessionManager");
|
|
8860
8602
|
var ToolSessionManager = class _ToolSessionManager {
|
|
8861
8603
|
static instance;
|
|
8862
8604
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -8890,7 +8632,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8890
8632
|
createdAt: Date.now()
|
|
8891
8633
|
};
|
|
8892
8634
|
this.sessions.set(sessionId, session);
|
|
8893
|
-
|
|
8635
|
+
logger4.debug(
|
|
8894
8636
|
{
|
|
8895
8637
|
sessionId,
|
|
8896
8638
|
tenantId,
|
|
@@ -8908,10 +8650,10 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8908
8650
|
*/
|
|
8909
8651
|
ensureAgentSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
8910
8652
|
if (this.sessions.has(sessionId)) {
|
|
8911
|
-
|
|
8653
|
+
logger4.debug({ sessionId }, "Agent session already exists, reusing");
|
|
8912
8654
|
return sessionId;
|
|
8913
8655
|
}
|
|
8914
|
-
|
|
8656
|
+
logger4.debug(
|
|
8915
8657
|
{ sessionId, tenantId, contextId, taskId },
|
|
8916
8658
|
"Creating new agent-scoped tool session"
|
|
8917
8659
|
);
|
|
@@ -8923,7 +8665,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8923
8665
|
recordToolResult(sessionId, toolResult) {
|
|
8924
8666
|
const session = this.sessions.get(sessionId);
|
|
8925
8667
|
if (!session) {
|
|
8926
|
-
|
|
8668
|
+
logger4.warn(
|
|
8927
8669
|
{
|
|
8928
8670
|
sessionId,
|
|
8929
8671
|
toolCallId: toolResult.toolCallId,
|
|
@@ -8935,7 +8677,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8935
8677
|
return;
|
|
8936
8678
|
}
|
|
8937
8679
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
8938
|
-
|
|
8680
|
+
logger4.debug(
|
|
8939
8681
|
{
|
|
8940
8682
|
sessionId,
|
|
8941
8683
|
toolCallId: toolResult.toolCallId,
|
|
@@ -8950,7 +8692,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8950
8692
|
getToolResult(sessionId, toolCallId) {
|
|
8951
8693
|
const session = this.sessions.get(sessionId);
|
|
8952
8694
|
if (!session) {
|
|
8953
|
-
|
|
8695
|
+
logger4.warn(
|
|
8954
8696
|
{
|
|
8955
8697
|
sessionId,
|
|
8956
8698
|
toolCallId,
|
|
@@ -8963,7 +8705,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8963
8705
|
}
|
|
8964
8706
|
const result = session.toolResults.get(toolCallId);
|
|
8965
8707
|
if (!result) {
|
|
8966
|
-
|
|
8708
|
+
logger4.warn(
|
|
8967
8709
|
{
|
|
8968
8710
|
sessionId,
|
|
8969
8711
|
toolCallId,
|
|
@@ -8973,7 +8715,7 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
8973
8715
|
"Tool result not found"
|
|
8974
8716
|
);
|
|
8975
8717
|
} else {
|
|
8976
|
-
|
|
8718
|
+
logger4.debug(
|
|
8977
8719
|
{
|
|
8978
8720
|
sessionId,
|
|
8979
8721
|
toolCallId,
|
|
@@ -9012,10 +8754,10 @@ var ToolSessionManager = class _ToolSessionManager {
|
|
|
9012
8754
|
}
|
|
9013
8755
|
for (const sessionId of expiredSessions) {
|
|
9014
8756
|
this.sessions.delete(sessionId);
|
|
9015
|
-
|
|
8757
|
+
logger4.debug({ sessionId }, "Cleaned up expired tool session");
|
|
9016
8758
|
}
|
|
9017
8759
|
if (expiredSessions.length > 0) {
|
|
9018
|
-
|
|
8760
|
+
logger4.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
9019
8761
|
}
|
|
9020
8762
|
}
|
|
9021
8763
|
};
|
|
@@ -9097,7 +8839,7 @@ function extractFullFields(schema2) {
|
|
|
9097
8839
|
}
|
|
9098
8840
|
|
|
9099
8841
|
// src/services/ArtifactService.ts
|
|
9100
|
-
var
|
|
8842
|
+
var logger6 = agentsCore.getLogger("ArtifactService");
|
|
9101
8843
|
var ArtifactService = class _ArtifactService {
|
|
9102
8844
|
constructor(context) {
|
|
9103
8845
|
this.context = context;
|
|
@@ -9130,7 +8872,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9130
8872
|
id: taskId
|
|
9131
8873
|
});
|
|
9132
8874
|
if (!task) {
|
|
9133
|
-
|
|
8875
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
9134
8876
|
continue;
|
|
9135
8877
|
}
|
|
9136
8878
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -9148,7 +8890,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9148
8890
|
}
|
|
9149
8891
|
}
|
|
9150
8892
|
} catch (error) {
|
|
9151
|
-
|
|
8893
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
9152
8894
|
}
|
|
9153
8895
|
return artifacts;
|
|
9154
8896
|
}
|
|
@@ -9157,12 +8899,12 @@ var ArtifactService = class _ArtifactService {
|
|
|
9157
8899
|
*/
|
|
9158
8900
|
async createArtifact(request, subAgentId) {
|
|
9159
8901
|
if (!this.context.sessionId) {
|
|
9160
|
-
|
|
8902
|
+
logger6.warn({ request }, "No session ID available for artifact creation");
|
|
9161
8903
|
return null;
|
|
9162
8904
|
}
|
|
9163
8905
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
9164
8906
|
if (!toolResult) {
|
|
9165
|
-
|
|
8907
|
+
logger6.warn(
|
|
9166
8908
|
{ request, sessionId: this.context.sessionId },
|
|
9167
8909
|
"Tool result not found for artifact"
|
|
9168
8910
|
);
|
|
@@ -9178,7 +8920,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9178
8920
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
9179
8921
|
}
|
|
9180
8922
|
if (!selectedData) {
|
|
9181
|
-
|
|
8923
|
+
logger6.warn(
|
|
9182
8924
|
{
|
|
9183
8925
|
request,
|
|
9184
8926
|
baseSelector: request.baseSelector
|
|
@@ -9249,7 +8991,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9249
8991
|
);
|
|
9250
8992
|
return artifactData;
|
|
9251
8993
|
} catch (error) {
|
|
9252
|
-
|
|
8994
|
+
logger6.error({ error, request }, "Failed to create artifact");
|
|
9253
8995
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
9254
8996
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
9255
8997
|
}
|
|
@@ -9278,7 +9020,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9278
9020
|
}
|
|
9279
9021
|
try {
|
|
9280
9022
|
if (!this.context.projectId || !this.context.taskId) {
|
|
9281
|
-
|
|
9023
|
+
logger6.warn(
|
|
9282
9024
|
{ artifactId, toolCallId },
|
|
9283
9025
|
"No projectId or taskId available for artifact lookup"
|
|
9284
9026
|
);
|
|
@@ -9302,7 +9044,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9302
9044
|
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
9303
9045
|
}
|
|
9304
9046
|
} catch (error) {
|
|
9305
|
-
|
|
9047
|
+
logger6.warn(
|
|
9306
9048
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
9307
9049
|
"Failed to fetch artifact"
|
|
9308
9050
|
);
|
|
@@ -9333,7 +9075,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9333
9075
|
}
|
|
9334
9076
|
try {
|
|
9335
9077
|
if (!this.context.projectId || !this.context.taskId) {
|
|
9336
|
-
|
|
9078
|
+
logger6.warn(
|
|
9337
9079
|
{ artifactId, toolCallId },
|
|
9338
9080
|
"No projectId or taskId available for artifact lookup"
|
|
9339
9081
|
);
|
|
@@ -9357,7 +9099,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9357
9099
|
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
9358
9100
|
}
|
|
9359
9101
|
} catch (error) {
|
|
9360
|
-
|
|
9102
|
+
logger6.warn(
|
|
9361
9103
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
9362
9104
|
"Failed to fetch artifact"
|
|
9363
9105
|
);
|
|
@@ -9374,7 +9116,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9374
9116
|
data = artifact.parts?.[0]?.data;
|
|
9375
9117
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
9376
9118
|
dataSource = "parts[0].data (fallback)";
|
|
9377
|
-
|
|
9119
|
+
logger6.debug(
|
|
9378
9120
|
{ artifactId, toolCallId, dataSource },
|
|
9379
9121
|
"Using fallback data source for artifact summary"
|
|
9380
9122
|
);
|
|
@@ -9382,14 +9124,14 @@ var ArtifactService = class _ArtifactService {
|
|
|
9382
9124
|
data = artifact.data;
|
|
9383
9125
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
9384
9126
|
dataSource = "artifact.data (fallback)";
|
|
9385
|
-
|
|
9127
|
+
logger6.debug(
|
|
9386
9128
|
{ artifactId, toolCallId, dataSource },
|
|
9387
9129
|
"Using fallback data source for artifact summary"
|
|
9388
9130
|
);
|
|
9389
9131
|
} else {
|
|
9390
9132
|
data = {};
|
|
9391
9133
|
dataSource = "empty (no data found)";
|
|
9392
|
-
|
|
9134
|
+
logger6.warn(
|
|
9393
9135
|
{
|
|
9394
9136
|
artifactId,
|
|
9395
9137
|
toolCallId,
|
|
@@ -9426,7 +9168,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9426
9168
|
data = artifact.parts?.[0]?.data;
|
|
9427
9169
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
9428
9170
|
dataSource = "parts[0].data (fallback)";
|
|
9429
|
-
|
|
9171
|
+
logger6.debug(
|
|
9430
9172
|
{ artifactId, toolCallId, dataSource },
|
|
9431
9173
|
"Using fallback data source for artifact full data"
|
|
9432
9174
|
);
|
|
@@ -9434,14 +9176,14 @@ var ArtifactService = class _ArtifactService {
|
|
|
9434
9176
|
data = artifact.data;
|
|
9435
9177
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
9436
9178
|
dataSource = "artifact.data (fallback)";
|
|
9437
|
-
|
|
9179
|
+
logger6.debug(
|
|
9438
9180
|
{ artifactId, toolCallId, dataSource },
|
|
9439
9181
|
"Using fallback data source for artifact full data"
|
|
9440
9182
|
);
|
|
9441
9183
|
} else {
|
|
9442
9184
|
data = {};
|
|
9443
9185
|
dataSource = "empty (no data found)";
|
|
9444
|
-
|
|
9186
|
+
logger6.warn(
|
|
9445
9187
|
{
|
|
9446
9188
|
artifactId,
|
|
9447
9189
|
toolCallId,
|
|
@@ -9495,7 +9237,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9495
9237
|
const error = new Error(
|
|
9496
9238
|
`Cannot save artifact: Missing required fields [${summaryValidation.missingRequired.join(", ")}] for '${artifactType}' schema. Required: [${summaryValidation.missingRequired.join(", ")}]. Found: [${summaryValidation.actualFields.join(", ")}]. Consider using a different artifact component type that matches your data structure.`
|
|
9497
9239
|
);
|
|
9498
|
-
|
|
9240
|
+
logger6.error(
|
|
9499
9241
|
{
|
|
9500
9242
|
artifactId,
|
|
9501
9243
|
artifactType,
|
|
@@ -9508,7 +9250,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9508
9250
|
throw error;
|
|
9509
9251
|
}
|
|
9510
9252
|
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) {
|
|
9511
|
-
|
|
9253
|
+
logger6.warn(
|
|
9512
9254
|
{
|
|
9513
9255
|
artifactId,
|
|
9514
9256
|
artifactType,
|
|
@@ -9522,7 +9264,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9522
9264
|
);
|
|
9523
9265
|
}
|
|
9524
9266
|
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) {
|
|
9525
|
-
|
|
9267
|
+
logger6.warn(
|
|
9526
9268
|
{
|
|
9527
9269
|
artifactId,
|
|
9528
9270
|
artifactType,
|
|
@@ -9594,7 +9336,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9594
9336
|
}
|
|
9595
9337
|
);
|
|
9596
9338
|
} else {
|
|
9597
|
-
|
|
9339
|
+
logger6.warn(
|
|
9598
9340
|
{
|
|
9599
9341
|
artifactId: request.artifactId,
|
|
9600
9342
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
@@ -9669,7 +9411,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9669
9411
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
9670
9412
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
9671
9413
|
} catch (error) {
|
|
9672
|
-
|
|
9414
|
+
logger6.warn(
|
|
9673
9415
|
{
|
|
9674
9416
|
artifactType: artifact.type,
|
|
9675
9417
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -9707,7 +9449,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9707
9449
|
artifact: artifactToSave
|
|
9708
9450
|
});
|
|
9709
9451
|
if (!result.created && result.existing) {
|
|
9710
|
-
|
|
9452
|
+
logger6.debug(
|
|
9711
9453
|
{
|
|
9712
9454
|
artifactId: artifact.artifactId,
|
|
9713
9455
|
taskId: this.context.taskId
|
|
@@ -9767,7 +9509,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9767
9509
|
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
9768
9510
|
}
|
|
9769
9511
|
} catch (error) {
|
|
9770
|
-
|
|
9512
|
+
logger6.warn(
|
|
9771
9513
|
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
9772
9514
|
"Failed to extract schema field"
|
|
9773
9515
|
);
|
|
@@ -9796,7 +9538,7 @@ var ArtifactService = class _ArtifactService {
|
|
|
9796
9538
|
};
|
|
9797
9539
|
|
|
9798
9540
|
// src/services/ArtifactParser.ts
|
|
9799
|
-
var
|
|
9541
|
+
var logger7 = agentsCore.getLogger("ArtifactParser");
|
|
9800
9542
|
var ArtifactParser = class _ArtifactParser {
|
|
9801
9543
|
static ARTIFACT_CHECK_REGEX = /<artifact:ref\s+(?=.*id=['"][^'"]+['"])(?=.*tool=['"][^'"]+['"])[^>]*\/>/;
|
|
9802
9544
|
static ATTR_REGEX = /(\w+)="([^"]*)"|(\w+)='([^']*)'|(\w+)=({[^}]+})/g;
|
|
@@ -9907,7 +9649,7 @@ var ArtifactParser = class _ArtifactParser {
|
|
|
9907
9649
|
attrs[key] = value;
|
|
9908
9650
|
}
|
|
9909
9651
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
9910
|
-
|
|
9652
|
+
logger7.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
9911
9653
|
return null;
|
|
9912
9654
|
}
|
|
9913
9655
|
return {
|
|
@@ -9968,7 +9710,7 @@ var ArtifactParser = class _ArtifactParser {
|
|
|
9968
9710
|
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
9969
9711
|
);
|
|
9970
9712
|
processedText = processedText.replace(annotation.raw, "");
|
|
9971
|
-
|
|
9713
|
+
logger7.warn(
|
|
9972
9714
|
{ annotation, artifactData },
|
|
9973
9715
|
"Removed failed artifact:create annotation from output"
|
|
9974
9716
|
);
|
|
@@ -9979,11 +9721,11 @@ var ArtifactParser = class _ArtifactParser {
|
|
|
9979
9721
|
if (annotation.raw) {
|
|
9980
9722
|
processedText = processedText.replace(annotation.raw, "");
|
|
9981
9723
|
}
|
|
9982
|
-
|
|
9724
|
+
logger7.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
9983
9725
|
}
|
|
9984
9726
|
}
|
|
9985
9727
|
if (failedAnnotations.length > 0) {
|
|
9986
|
-
|
|
9728
|
+
logger7.warn(
|
|
9987
9729
|
{
|
|
9988
9730
|
failedCount: failedAnnotations.length,
|
|
9989
9731
|
failures: failedAnnotations
|
|
@@ -10167,7 +9909,7 @@ var ArtifactParser = class _ArtifactParser {
|
|
|
10167
9909
|
};
|
|
10168
9910
|
|
|
10169
9911
|
// src/services/AgentSession.ts
|
|
10170
|
-
var
|
|
9912
|
+
var logger8 = agentsCore.getLogger("AgentSession");
|
|
10171
9913
|
var AgentSession = class {
|
|
10172
9914
|
// Whether to send data operations
|
|
10173
9915
|
constructor(sessionId, messageId, agentId, tenantId, projectId, contextId) {
|
|
@@ -10177,7 +9919,7 @@ var AgentSession = class {
|
|
|
10177
9919
|
this.tenantId = tenantId;
|
|
10178
9920
|
this.projectId = projectId;
|
|
10179
9921
|
this.contextId = contextId;
|
|
10180
|
-
|
|
9922
|
+
logger8.debug({ sessionId, messageId, agentId }, "AgentSession created");
|
|
10181
9923
|
if (tenantId && projectId) {
|
|
10182
9924
|
toolSessionManager.createSessionWithId(
|
|
10183
9925
|
sessionId,
|
|
@@ -10234,7 +9976,7 @@ var AgentSession = class {
|
|
|
10234
9976
|
*/
|
|
10235
9977
|
enableEmitOperations() {
|
|
10236
9978
|
this.isEmitOperations = true;
|
|
10237
|
-
|
|
9979
|
+
logger8.info(
|
|
10238
9980
|
{ sessionId: this.sessionId },
|
|
10239
9981
|
"\u{1F50D} DEBUG: Emit operations enabled for AgentSession"
|
|
10240
9982
|
);
|
|
@@ -10243,6 +9985,7 @@ var AgentSession = class {
|
|
|
10243
9985
|
* Send data operation to stream when emit operations is enabled
|
|
10244
9986
|
*/
|
|
10245
9987
|
async sendDataOperation(event) {
|
|
9988
|
+
console.log("sendDataOperation called with event", Date.now());
|
|
10246
9989
|
try {
|
|
10247
9990
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
10248
9991
|
if (streamHelper) {
|
|
@@ -10258,7 +10001,7 @@ var AgentSession = class {
|
|
|
10258
10001
|
await streamHelper.writeOperation(formattedOperation);
|
|
10259
10002
|
}
|
|
10260
10003
|
} catch (error) {
|
|
10261
|
-
|
|
10004
|
+
logger8.error(
|
|
10262
10005
|
{
|
|
10263
10006
|
sessionId: this.sessionId,
|
|
10264
10007
|
eventType: event.eventType,
|
|
@@ -10317,7 +10060,7 @@ var AgentSession = class {
|
|
|
10317
10060
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
10318
10061
|
this.statusUpdateTimer = setInterval(async () => {
|
|
10319
10062
|
if (!this.statusUpdateState || this.isEnded) {
|
|
10320
|
-
|
|
10063
|
+
logger8.debug(
|
|
10321
10064
|
{ sessionId: this.sessionId },
|
|
10322
10065
|
"Timer triggered but session already cleaned up or ended"
|
|
10323
10066
|
);
|
|
@@ -10329,7 +10072,7 @@ var AgentSession = class {
|
|
|
10329
10072
|
}
|
|
10330
10073
|
await this.checkAndSendTimeBasedUpdate();
|
|
10331
10074
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
10332
|
-
|
|
10075
|
+
logger8.info(
|
|
10333
10076
|
{
|
|
10334
10077
|
sessionId: this.sessionId,
|
|
10335
10078
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -10353,7 +10096,7 @@ var AgentSession = class {
|
|
|
10353
10096
|
this.sendDataOperation(dataOpEvent);
|
|
10354
10097
|
}
|
|
10355
10098
|
if (this.isEnded) {
|
|
10356
|
-
|
|
10099
|
+
logger8.debug(
|
|
10357
10100
|
{
|
|
10358
10101
|
sessionId: this.sessionId,
|
|
10359
10102
|
eventType,
|
|
@@ -10375,7 +10118,7 @@ var AgentSession = class {
|
|
|
10375
10118
|
if (artifactData.pendingGeneration) {
|
|
10376
10119
|
const artifactId = artifactData.artifactId;
|
|
10377
10120
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
10378
|
-
|
|
10121
|
+
logger8.warn(
|
|
10379
10122
|
{
|
|
10380
10123
|
sessionId: this.sessionId,
|
|
10381
10124
|
artifactId,
|
|
@@ -10397,7 +10140,7 @@ var AgentSession = class {
|
|
|
10397
10140
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
10398
10141
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
10399
10142
|
this.pendingArtifacts.delete(artifactId);
|
|
10400
|
-
|
|
10143
|
+
logger8.error(
|
|
10401
10144
|
{
|
|
10402
10145
|
sessionId: this.sessionId,
|
|
10403
10146
|
artifactId,
|
|
@@ -10409,7 +10152,7 @@ var AgentSession = class {
|
|
|
10409
10152
|
"Artifact processing failed after max retries, giving up"
|
|
10410
10153
|
);
|
|
10411
10154
|
} else {
|
|
10412
|
-
|
|
10155
|
+
logger8.warn(
|
|
10413
10156
|
{
|
|
10414
10157
|
sessionId: this.sessionId,
|
|
10415
10158
|
artifactId,
|
|
@@ -10432,14 +10175,14 @@ var AgentSession = class {
|
|
|
10432
10175
|
*/
|
|
10433
10176
|
checkStatusUpdates() {
|
|
10434
10177
|
if (this.isEnded) {
|
|
10435
|
-
|
|
10178
|
+
logger8.debug(
|
|
10436
10179
|
{ sessionId: this.sessionId },
|
|
10437
10180
|
"Session has ended - skipping status update check"
|
|
10438
10181
|
);
|
|
10439
10182
|
return;
|
|
10440
10183
|
}
|
|
10441
10184
|
if (!this.statusUpdateState) {
|
|
10442
|
-
|
|
10185
|
+
logger8.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
10443
10186
|
return;
|
|
10444
10187
|
}
|
|
10445
10188
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -10450,11 +10193,11 @@ var AgentSession = class {
|
|
|
10450
10193
|
*/
|
|
10451
10194
|
async checkAndSendTimeBasedUpdate() {
|
|
10452
10195
|
if (this.isEnded) {
|
|
10453
|
-
|
|
10196
|
+
logger8.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
10454
10197
|
return;
|
|
10455
10198
|
}
|
|
10456
10199
|
if (!this.statusUpdateState) {
|
|
10457
|
-
|
|
10200
|
+
logger8.debug(
|
|
10458
10201
|
{ sessionId: this.sessionId },
|
|
10459
10202
|
"No status updates configured for time-based check"
|
|
10460
10203
|
);
|
|
@@ -10467,7 +10210,7 @@ var AgentSession = class {
|
|
|
10467
10210
|
try {
|
|
10468
10211
|
await this.generateAndSendUpdate();
|
|
10469
10212
|
} catch (error) {
|
|
10470
|
-
|
|
10213
|
+
logger8.error(
|
|
10471
10214
|
{
|
|
10472
10215
|
sessionId: this.sessionId,
|
|
10473
10216
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -10570,29 +10313,29 @@ var AgentSession = class {
|
|
|
10570
10313
|
*/
|
|
10571
10314
|
async generateAndSendUpdate() {
|
|
10572
10315
|
if (this.isEnded) {
|
|
10573
|
-
|
|
10316
|
+
logger8.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
10574
10317
|
return;
|
|
10575
10318
|
}
|
|
10576
10319
|
if (this.isTextStreaming) {
|
|
10577
|
-
|
|
10320
|
+
logger8.debug(
|
|
10578
10321
|
{ sessionId: this.sessionId },
|
|
10579
10322
|
"Text is currently streaming - skipping status update"
|
|
10580
10323
|
);
|
|
10581
10324
|
return;
|
|
10582
10325
|
}
|
|
10583
10326
|
if (this.isGeneratingUpdate) {
|
|
10584
|
-
|
|
10327
|
+
logger8.debug(
|
|
10585
10328
|
{ sessionId: this.sessionId },
|
|
10586
10329
|
"Update already in progress - skipping duplicate generation"
|
|
10587
10330
|
);
|
|
10588
10331
|
return;
|
|
10589
10332
|
}
|
|
10590
10333
|
if (!this.statusUpdateState) {
|
|
10591
|
-
|
|
10334
|
+
logger8.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
10592
10335
|
return;
|
|
10593
10336
|
}
|
|
10594
10337
|
if (!this.agentId) {
|
|
10595
|
-
|
|
10338
|
+
logger8.warn({ sessionId: this.sessionId }, "No agent ID - cannot generate update");
|
|
10596
10339
|
return;
|
|
10597
10340
|
}
|
|
10598
10341
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -10604,7 +10347,7 @@ var AgentSession = class {
|
|
|
10604
10347
|
try {
|
|
10605
10348
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
10606
10349
|
if (!streamHelper) {
|
|
10607
|
-
|
|
10350
|
+
logger8.warn(
|
|
10608
10351
|
{ sessionId: this.sessionId },
|
|
10609
10352
|
"No stream helper found - cannot send status update"
|
|
10610
10353
|
);
|
|
@@ -10624,7 +10367,7 @@ var AgentSession = class {
|
|
|
10624
10367
|
if (result.summaries && result.summaries.length > 0) {
|
|
10625
10368
|
for (const summary of result.summaries) {
|
|
10626
10369
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
10627
|
-
|
|
10370
|
+
logger8.warn(
|
|
10628
10371
|
{
|
|
10629
10372
|
sessionId: this.sessionId,
|
|
10630
10373
|
summary
|
|
@@ -10661,7 +10404,7 @@ var AgentSession = class {
|
|
|
10661
10404
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
10662
10405
|
}
|
|
10663
10406
|
} catch (error) {
|
|
10664
|
-
|
|
10407
|
+
logger8.error(
|
|
10665
10408
|
{
|
|
10666
10409
|
sessionId: this.sessionId,
|
|
10667
10410
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -10699,7 +10442,7 @@ var AgentSession = class {
|
|
|
10699
10442
|
this.releaseUpdateLock();
|
|
10700
10443
|
}
|
|
10701
10444
|
} catch (error) {
|
|
10702
|
-
|
|
10445
|
+
logger8.error(
|
|
10703
10446
|
{
|
|
10704
10447
|
sessionId: this.sessionId,
|
|
10705
10448
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -10778,7 +10521,7 @@ User's Question/Context:
|
|
|
10778
10521
|
${conversationHistory}
|
|
10779
10522
|
` : "";
|
|
10780
10523
|
} catch (error) {
|
|
10781
|
-
|
|
10524
|
+
logger8.warn(
|
|
10782
10525
|
{ sessionId: this.sessionId, error },
|
|
10783
10526
|
"Failed to fetch conversation history for structured status update"
|
|
10784
10527
|
);
|
|
@@ -10788,12 +10531,12 @@ ${conversationHistory}
|
|
|
10788
10531
|
Previous updates sent to user:
|
|
10789
10532
|
${previousSummaries.map((s4, i3) => `${i3 + 1}. ${s4}`).join("\n")}
|
|
10790
10533
|
` : "";
|
|
10791
|
-
const selectionSchema =
|
|
10534
|
+
const selectionSchema = zodOpenapi.z.object(
|
|
10792
10535
|
Object.fromEntries([
|
|
10793
10536
|
[
|
|
10794
10537
|
"no_relevant_updates",
|
|
10795
|
-
|
|
10796
|
-
no_updates:
|
|
10538
|
+
zodOpenapi.z.object({
|
|
10539
|
+
no_updates: zodOpenapi.z.boolean().default(true)
|
|
10797
10540
|
}).optional().describe(
|
|
10798
10541
|
"Use when nothing substantially new to report. Should only use on its own."
|
|
10799
10542
|
)
|
|
@@ -10872,7 +10615,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10872
10615
|
if (!modelToUse) {
|
|
10873
10616
|
throw new Error("No model configuration available");
|
|
10874
10617
|
}
|
|
10875
|
-
const model = ModelFactory.createModel(modelToUse);
|
|
10618
|
+
const model = agentsCore.ModelFactory.createModel(modelToUse);
|
|
10876
10619
|
const { object } = await ai.generateObject({
|
|
10877
10620
|
model,
|
|
10878
10621
|
prompt,
|
|
@@ -10889,10 +10632,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10889
10632
|
}
|
|
10890
10633
|
});
|
|
10891
10634
|
const result = object;
|
|
10892
|
-
|
|
10635
|
+
logger8.info({ result: JSON.stringify(result) }, "DEBUG: Result");
|
|
10893
10636
|
const summaries = [];
|
|
10894
10637
|
for (const [componentId, data] of Object.entries(result)) {
|
|
10895
|
-
|
|
10638
|
+
logger8.info({ componentId, data: JSON.stringify(data) }, "DEBUG: Component data");
|
|
10896
10639
|
if (componentId === "no_relevant_updates") {
|
|
10897
10640
|
continue;
|
|
10898
10641
|
}
|
|
@@ -10912,7 +10655,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10912
10655
|
return { summaries };
|
|
10913
10656
|
} catch (error) {
|
|
10914
10657
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
10915
|
-
|
|
10658
|
+
logger8.error({ error }, "Failed to generate structured update, using fallback");
|
|
10916
10659
|
return { summaries: [] };
|
|
10917
10660
|
} finally {
|
|
10918
10661
|
span.end();
|
|
@@ -10927,8 +10670,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10927
10670
|
if (component.detailsSchema && "properties" in component.detailsSchema) {
|
|
10928
10671
|
return this.buildZodSchemaFromJson(component.detailsSchema);
|
|
10929
10672
|
}
|
|
10930
|
-
return
|
|
10931
|
-
label:
|
|
10673
|
+
return zodOpenapi.z.object({
|
|
10674
|
+
label: zodOpenapi.z.string().describe(
|
|
10932
10675
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The ACTUAL finding or result, not the action. What specific information was discovered? (e.g., "Slack requires OAuth 2.0 setup", "Found 5 integration methods", "API rate limit is 100/minute"). Include the actual detail or insight, not just that you searched or processed. CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
10933
10676
|
)
|
|
10934
10677
|
});
|
|
@@ -10938,56 +10681,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10938
10681
|
*/
|
|
10939
10682
|
buildZodSchemaFromJson(jsonSchema) {
|
|
10940
10683
|
const properties = {};
|
|
10941
|
-
properties.label =
|
|
10684
|
+
properties.label = zodOpenapi.z.string().describe(
|
|
10942
10685
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
10943
10686
|
);
|
|
10944
10687
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
10945
10688
|
let zodType;
|
|
10946
10689
|
if (value.enum && Array.isArray(value.enum)) {
|
|
10947
10690
|
if (value.enum.length === 1) {
|
|
10948
|
-
zodType =
|
|
10691
|
+
zodType = zodOpenapi.z.literal(value.enum[0]);
|
|
10949
10692
|
} else {
|
|
10950
10693
|
const [first, ...rest] = value.enum;
|
|
10951
|
-
zodType =
|
|
10694
|
+
zodType = zodOpenapi.z.enum([first, ...rest]);
|
|
10952
10695
|
}
|
|
10953
10696
|
} else if (value.type === "string") {
|
|
10954
|
-
zodType =
|
|
10697
|
+
zodType = zodOpenapi.z.string();
|
|
10955
10698
|
if (value.minLength) zodType = zodType.min(value.minLength);
|
|
10956
10699
|
if (value.maxLength) zodType = zodType.max(value.maxLength);
|
|
10957
10700
|
if (value.format === "email") zodType = zodType.email();
|
|
10958
10701
|
if (value.format === "url" || value.format === "uri")
|
|
10959
10702
|
zodType = zodType.url();
|
|
10960
10703
|
} else if (value.type === "number" || value.type === "integer") {
|
|
10961
|
-
zodType = value.type === "integer" ?
|
|
10704
|
+
zodType = value.type === "integer" ? zodOpenapi.z.number().int() : zodOpenapi.z.number();
|
|
10962
10705
|
if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
|
|
10963
10706
|
if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
|
|
10964
10707
|
} else if (value.type === "boolean") {
|
|
10965
|
-
zodType =
|
|
10708
|
+
zodType = zodOpenapi.z.boolean();
|
|
10966
10709
|
} else if (value.type === "array") {
|
|
10967
10710
|
if (value.items) {
|
|
10968
10711
|
if (value.items.enum && Array.isArray(value.items.enum)) {
|
|
10969
10712
|
const [first, ...rest] = value.items.enum;
|
|
10970
|
-
zodType =
|
|
10713
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.enum([first, ...rest]));
|
|
10971
10714
|
} else if (value.items.type === "string") {
|
|
10972
|
-
zodType =
|
|
10715
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.string());
|
|
10973
10716
|
} else if (value.items.type === "number") {
|
|
10974
|
-
zodType =
|
|
10717
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.number());
|
|
10975
10718
|
} else if (value.items.type === "boolean") {
|
|
10976
|
-
zodType =
|
|
10719
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.boolean());
|
|
10977
10720
|
} else if (value.items.type === "object") {
|
|
10978
|
-
zodType =
|
|
10721
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.any()));
|
|
10979
10722
|
} else {
|
|
10980
|
-
zodType =
|
|
10723
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.any());
|
|
10981
10724
|
}
|
|
10982
10725
|
} else {
|
|
10983
|
-
zodType =
|
|
10726
|
+
zodType = zodOpenapi.z.array(zodOpenapi.z.any());
|
|
10984
10727
|
}
|
|
10985
10728
|
if (value.minItems) zodType = zodType.min(value.minItems);
|
|
10986
10729
|
if (value.maxItems) zodType = zodType.max(value.maxItems);
|
|
10987
10730
|
} else if (value.type === "object") {
|
|
10988
|
-
zodType =
|
|
10731
|
+
zodType = zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.any());
|
|
10989
10732
|
} else {
|
|
10990
|
-
zodType =
|
|
10733
|
+
zodType = zodOpenapi.z.any();
|
|
10991
10734
|
}
|
|
10992
10735
|
if (value.description) {
|
|
10993
10736
|
zodType = zodType.describe(value.description);
|
|
@@ -10997,7 +10740,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
10997
10740
|
}
|
|
10998
10741
|
properties[key] = zodType;
|
|
10999
10742
|
}
|
|
11000
|
-
return
|
|
10743
|
+
return zodOpenapi.z.object(properties);
|
|
11001
10744
|
}
|
|
11002
10745
|
/**
|
|
11003
10746
|
* Extract user-visible activities with rich formatting and complete information
|
|
@@ -11184,7 +10927,7 @@ Make it specific and relevant.`;
|
|
|
11184
10927
|
});
|
|
11185
10928
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
11186
10929
|
modelToUse = agentData.models.base;
|
|
11187
|
-
|
|
10930
|
+
logger8.info(
|
|
11188
10931
|
{
|
|
11189
10932
|
sessionId: this.sessionId,
|
|
11190
10933
|
artifactId: artifactData.artifactId,
|
|
@@ -11195,7 +10938,7 @@ Make it specific and relevant.`;
|
|
|
11195
10938
|
);
|
|
11196
10939
|
}
|
|
11197
10940
|
} catch (error) {
|
|
11198
|
-
|
|
10941
|
+
logger8.warn(
|
|
11199
10942
|
{
|
|
11200
10943
|
sessionId: this.sessionId,
|
|
11201
10944
|
artifactId: artifactData.artifactId,
|
|
@@ -11207,7 +10950,7 @@ Make it specific and relevant.`;
|
|
|
11207
10950
|
}
|
|
11208
10951
|
}
|
|
11209
10952
|
if (!modelToUse?.model?.trim()) {
|
|
11210
|
-
|
|
10953
|
+
logger8.warn(
|
|
11211
10954
|
{
|
|
11212
10955
|
sessionId: this.sessionId,
|
|
11213
10956
|
artifactId: artifactData.artifactId
|
|
@@ -11227,10 +10970,10 @@ Make it specific and relevant.`;
|
|
|
11227
10970
|
description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolCallId || "tool results"}`
|
|
11228
10971
|
};
|
|
11229
10972
|
} else {
|
|
11230
|
-
const model = ModelFactory.createModel(modelToUse);
|
|
11231
|
-
const schema2 =
|
|
11232
|
-
name:
|
|
11233
|
-
description:
|
|
10973
|
+
const model = agentsCore.ModelFactory.createModel(modelToUse);
|
|
10974
|
+
const schema2 = zodOpenapi.z.object({
|
|
10975
|
+
name: zodOpenapi.z.string().describe("Concise, descriptive name for the artifact"),
|
|
10976
|
+
description: zodOpenapi.z.string().describe("Brief description of the artifact's relevance to the user's question")
|
|
11234
10977
|
});
|
|
11235
10978
|
const { object } = await tracer.startActiveSpan(
|
|
11236
10979
|
"agent_session.generate_artifact_metadata",
|
|
@@ -11289,7 +11032,7 @@ Make it specific and relevant.`;
|
|
|
11289
11032
|
return result2;
|
|
11290
11033
|
} catch (error) {
|
|
11291
11034
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
11292
|
-
|
|
11035
|
+
logger8.warn(
|
|
11293
11036
|
{
|
|
11294
11037
|
sessionId: this.sessionId,
|
|
11295
11038
|
artifactId: artifactData.artifactId,
|
|
@@ -11337,7 +11080,7 @@ Make it specific and relevant.`;
|
|
|
11337
11080
|
});
|
|
11338
11081
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
11339
11082
|
} catch (saveError) {
|
|
11340
|
-
|
|
11083
|
+
logger8.error(
|
|
11341
11084
|
{
|
|
11342
11085
|
sessionId: this.sessionId,
|
|
11343
11086
|
artifactId: artifactData.artifactId,
|
|
@@ -11365,7 +11108,7 @@ Make it specific and relevant.`;
|
|
|
11365
11108
|
metadata: artifactData.metadata || {},
|
|
11366
11109
|
toolCallId: artifactData.toolCallId
|
|
11367
11110
|
});
|
|
11368
|
-
|
|
11111
|
+
logger8.info(
|
|
11369
11112
|
{
|
|
11370
11113
|
sessionId: this.sessionId,
|
|
11371
11114
|
artifactId: artifactData.artifactId
|
|
@@ -11376,7 +11119,7 @@ Make it specific and relevant.`;
|
|
|
11376
11119
|
} catch (fallbackError) {
|
|
11377
11120
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
11378
11121
|
if (isDuplicateError) ; else {
|
|
11379
|
-
|
|
11122
|
+
logger8.error(
|
|
11380
11123
|
{
|
|
11381
11124
|
sessionId: this.sessionId,
|
|
11382
11125
|
artifactId: artifactData.artifactId,
|
|
@@ -11389,7 +11132,7 @@ Make it specific and relevant.`;
|
|
|
11389
11132
|
}
|
|
11390
11133
|
} catch (error) {
|
|
11391
11134
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
11392
|
-
|
|
11135
|
+
logger8.error(
|
|
11393
11136
|
{
|
|
11394
11137
|
sessionId: this.sessionId,
|
|
11395
11138
|
artifactId: artifactData.artifactId,
|
|
@@ -11408,7 +11151,7 @@ Make it specific and relevant.`;
|
|
|
11408
11151
|
*/
|
|
11409
11152
|
setArtifactCache(key, artifact) {
|
|
11410
11153
|
this.artifactCache.set(key, artifact);
|
|
11411
|
-
|
|
11154
|
+
logger8.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
11412
11155
|
}
|
|
11413
11156
|
/**
|
|
11414
11157
|
* Get session-scoped ArtifactService instance
|
|
@@ -11427,7 +11170,7 @@ Make it specific and relevant.`;
|
|
|
11427
11170
|
*/
|
|
11428
11171
|
getArtifactCache(key) {
|
|
11429
11172
|
const artifact = this.artifactCache.get(key);
|
|
11430
|
-
|
|
11173
|
+
logger8.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
11431
11174
|
return artifact || null;
|
|
11432
11175
|
}
|
|
11433
11176
|
/**
|
|
@@ -11448,7 +11191,7 @@ var AgentSessionManager = class {
|
|
|
11448
11191
|
const sessionId = messageId;
|
|
11449
11192
|
const session = new AgentSession(sessionId, messageId, agentId, tenantId, projectId, contextId);
|
|
11450
11193
|
this.sessions.set(sessionId, session);
|
|
11451
|
-
|
|
11194
|
+
logger8.info(
|
|
11452
11195
|
{ sessionId, messageId, agentId, tenantId, projectId, contextId },
|
|
11453
11196
|
"AgentSession created"
|
|
11454
11197
|
);
|
|
@@ -11462,7 +11205,7 @@ var AgentSessionManager = class {
|
|
|
11462
11205
|
if (session) {
|
|
11463
11206
|
session.initializeStatusUpdates(config, summarizerModel, baseModel);
|
|
11464
11207
|
} else {
|
|
11465
|
-
|
|
11208
|
+
logger8.error(
|
|
11466
11209
|
{
|
|
11467
11210
|
sessionId,
|
|
11468
11211
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -11479,7 +11222,7 @@ var AgentSessionManager = class {
|
|
|
11479
11222
|
if (session) {
|
|
11480
11223
|
session.enableEmitOperations();
|
|
11481
11224
|
} else {
|
|
11482
|
-
|
|
11225
|
+
logger8.error(
|
|
11483
11226
|
{
|
|
11484
11227
|
sessionId,
|
|
11485
11228
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -11501,7 +11244,7 @@ var AgentSessionManager = class {
|
|
|
11501
11244
|
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
11502
11245
|
const session = this.sessions.get(sessionId);
|
|
11503
11246
|
if (!session) {
|
|
11504
|
-
|
|
11247
|
+
logger8.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
11505
11248
|
return;
|
|
11506
11249
|
}
|
|
11507
11250
|
session.recordEvent(eventType, subAgentId, data);
|
|
@@ -11512,12 +11255,12 @@ var AgentSessionManager = class {
|
|
|
11512
11255
|
endSession(sessionId) {
|
|
11513
11256
|
const session = this.sessions.get(sessionId);
|
|
11514
11257
|
if (!session) {
|
|
11515
|
-
|
|
11258
|
+
logger8.warn({ sessionId }, "Attempted to end non-existent session");
|
|
11516
11259
|
return [];
|
|
11517
11260
|
}
|
|
11518
11261
|
const events = session.getEvents();
|
|
11519
11262
|
const summary = session.getSummary();
|
|
11520
|
-
|
|
11263
|
+
logger8.info({ sessionId, summary }, "AgentSession ended");
|
|
11521
11264
|
session.cleanup();
|
|
11522
11265
|
this.sessions.delete(sessionId);
|
|
11523
11266
|
return events;
|
|
@@ -11627,7 +11370,7 @@ init_logger();
|
|
|
11627
11370
|
// src/services/IncrementalStreamParser.ts
|
|
11628
11371
|
init_execution_limits();
|
|
11629
11372
|
init_logger();
|
|
11630
|
-
var
|
|
11373
|
+
var logger9 = agentsCore.getLogger("IncrementalStreamParser");
|
|
11631
11374
|
var IncrementalStreamParser = class _IncrementalStreamParser {
|
|
11632
11375
|
buffer = "";
|
|
11633
11376
|
pendingTextBuffer = "";
|
|
@@ -11685,7 +11428,7 @@ var IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
11685
11428
|
async initializeArtifactMap() {
|
|
11686
11429
|
try {
|
|
11687
11430
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
11688
|
-
|
|
11431
|
+
logger9.debug(
|
|
11689
11432
|
{
|
|
11690
11433
|
contextId: this.contextId,
|
|
11691
11434
|
artifactMapSize: this.artifactMap.size
|
|
@@ -11693,7 +11436,7 @@ var IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
11693
11436
|
"Initialized artifact map for streaming"
|
|
11694
11437
|
);
|
|
11695
11438
|
} catch (error) {
|
|
11696
|
-
|
|
11439
|
+
logger9.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
11697
11440
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
11698
11441
|
}
|
|
11699
11442
|
}
|
|
@@ -12026,6 +11769,143 @@ ${chunk}`;
|
|
|
12026
11769
|
}
|
|
12027
11770
|
};
|
|
12028
11771
|
|
|
11772
|
+
// src/services/PendingToolApprovalManager.ts
|
|
11773
|
+
init_logger();
|
|
11774
|
+
var logger10 = agentsCore.getLogger("PendingToolApprovalManager");
|
|
11775
|
+
var APPROVAL_CLEANUP_INTERVAL_MS = 2 * 60 * 1e3;
|
|
11776
|
+
var APPROVAL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
11777
|
+
var PendingToolApprovalManager = class _PendingToolApprovalManager {
|
|
11778
|
+
static instance;
|
|
11779
|
+
pendingApprovals = /* @__PURE__ */ new Map();
|
|
11780
|
+
constructor() {
|
|
11781
|
+
setInterval(() => this.cleanupExpiredApprovals(), APPROVAL_CLEANUP_INTERVAL_MS);
|
|
11782
|
+
}
|
|
11783
|
+
static getInstance() {
|
|
11784
|
+
if (!_PendingToolApprovalManager.instance) {
|
|
11785
|
+
_PendingToolApprovalManager.instance = new _PendingToolApprovalManager();
|
|
11786
|
+
}
|
|
11787
|
+
return _PendingToolApprovalManager.instance;
|
|
11788
|
+
}
|
|
11789
|
+
/**
|
|
11790
|
+
* Create a new pending approval and return a promise that resolves with approval status
|
|
11791
|
+
*/
|
|
11792
|
+
async waitForApproval(toolCallId, toolName, args2, conversationId, subAgentId) {
|
|
11793
|
+
return new Promise((resolve2, reject) => {
|
|
11794
|
+
const timeoutId = setTimeout(() => {
|
|
11795
|
+
this.pendingApprovals.delete(toolCallId);
|
|
11796
|
+
resolve2({
|
|
11797
|
+
approved: false,
|
|
11798
|
+
reason: `Tool approval timeout for ${toolName} (${toolCallId})`
|
|
11799
|
+
});
|
|
11800
|
+
}, APPROVAL_TIMEOUT_MS);
|
|
11801
|
+
const approval = {
|
|
11802
|
+
toolCallId,
|
|
11803
|
+
toolName,
|
|
11804
|
+
args: args2,
|
|
11805
|
+
conversationId,
|
|
11806
|
+
subAgentId,
|
|
11807
|
+
createdAt: Date.now(),
|
|
11808
|
+
resolve: resolve2,
|
|
11809
|
+
reject,
|
|
11810
|
+
timeoutId
|
|
11811
|
+
};
|
|
11812
|
+
this.pendingApprovals.set(toolCallId, approval);
|
|
11813
|
+
logger10.info(
|
|
11814
|
+
{
|
|
11815
|
+
toolCallId,
|
|
11816
|
+
toolName,
|
|
11817
|
+
conversationId,
|
|
11818
|
+
subAgentId
|
|
11819
|
+
},
|
|
11820
|
+
"Tool approval request created, waiting for user response"
|
|
11821
|
+
);
|
|
11822
|
+
});
|
|
11823
|
+
}
|
|
11824
|
+
/**
|
|
11825
|
+
* Approve a pending tool call
|
|
11826
|
+
*/
|
|
11827
|
+
approveToolCall(toolCallId) {
|
|
11828
|
+
const approval = this.pendingApprovals.get(toolCallId);
|
|
11829
|
+
if (!approval) {
|
|
11830
|
+
logger10.warn({ toolCallId }, "Tool approval not found or already processed");
|
|
11831
|
+
return false;
|
|
11832
|
+
}
|
|
11833
|
+
logger10.info(
|
|
11834
|
+
{
|
|
11835
|
+
toolCallId,
|
|
11836
|
+
toolName: approval.toolName,
|
|
11837
|
+
conversationId: approval.conversationId
|
|
11838
|
+
},
|
|
11839
|
+
"Tool approved by user, resuming execution"
|
|
11840
|
+
);
|
|
11841
|
+
clearTimeout(approval.timeoutId);
|
|
11842
|
+
this.pendingApprovals.delete(toolCallId);
|
|
11843
|
+
approval.resolve({ approved: true });
|
|
11844
|
+
return true;
|
|
11845
|
+
}
|
|
11846
|
+
/**
|
|
11847
|
+
* Deny a pending tool call
|
|
11848
|
+
*/
|
|
11849
|
+
denyToolCall(toolCallId, reason) {
|
|
11850
|
+
const approval = this.pendingApprovals.get(toolCallId);
|
|
11851
|
+
if (!approval) {
|
|
11852
|
+
logger10.warn({ toolCallId }, "Tool approval not found or already processed");
|
|
11853
|
+
return false;
|
|
11854
|
+
}
|
|
11855
|
+
logger10.info(
|
|
11856
|
+
{
|
|
11857
|
+
toolCallId,
|
|
11858
|
+
toolName: approval.toolName,
|
|
11859
|
+
conversationId: approval.conversationId,
|
|
11860
|
+
reason
|
|
11861
|
+
},
|
|
11862
|
+
"Tool execution denied by user"
|
|
11863
|
+
);
|
|
11864
|
+
clearTimeout(approval.timeoutId);
|
|
11865
|
+
this.pendingApprovals.delete(toolCallId);
|
|
11866
|
+
approval.resolve({
|
|
11867
|
+
approved: false,
|
|
11868
|
+
reason: reason || "User denied approval"
|
|
11869
|
+
});
|
|
11870
|
+
return true;
|
|
11871
|
+
}
|
|
11872
|
+
/**
|
|
11873
|
+
* Clean up expired approvals (called by interval timer)
|
|
11874
|
+
*/
|
|
11875
|
+
cleanupExpiredApprovals() {
|
|
11876
|
+
const now = Date.now();
|
|
11877
|
+
let cleanedUp = 0;
|
|
11878
|
+
for (const [toolCallId, approval] of this.pendingApprovals) {
|
|
11879
|
+
if (now - approval.createdAt > APPROVAL_TIMEOUT_MS) {
|
|
11880
|
+
clearTimeout(approval.timeoutId);
|
|
11881
|
+
this.pendingApprovals.delete(toolCallId);
|
|
11882
|
+
approval.resolve({ approved: false, reason: "Tool approval expired" });
|
|
11883
|
+
cleanedUp++;
|
|
11884
|
+
}
|
|
11885
|
+
}
|
|
11886
|
+
if (cleanedUp > 0) {
|
|
11887
|
+
logger10.info({ cleanedUp }, "Cleaned up expired tool approvals");
|
|
11888
|
+
}
|
|
11889
|
+
}
|
|
11890
|
+
/**
|
|
11891
|
+
* Get current status for monitoring
|
|
11892
|
+
*/
|
|
11893
|
+
getStatus() {
|
|
11894
|
+
return {
|
|
11895
|
+
pendingApprovals: this.pendingApprovals.size,
|
|
11896
|
+
approvals: Array.from(this.pendingApprovals.values()).map((approval) => ({
|
|
11897
|
+
toolCallId: approval.toolCallId,
|
|
11898
|
+
toolName: approval.toolName,
|
|
11899
|
+
conversationId: approval.conversationId,
|
|
11900
|
+
subAgentId: approval.subAgentId,
|
|
11901
|
+
createdAt: approval.createdAt,
|
|
11902
|
+
age: Date.now() - approval.createdAt
|
|
11903
|
+
}))
|
|
11904
|
+
};
|
|
11905
|
+
}
|
|
11906
|
+
};
|
|
11907
|
+
var pendingToolApprovalManager = PendingToolApprovalManager.getInstance();
|
|
11908
|
+
|
|
12029
11909
|
// src/services/ResponseFormatter.ts
|
|
12030
11910
|
init_logger();
|
|
12031
11911
|
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
@@ -12229,7 +12109,7 @@ var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
|
12229
12109
|
function jsonSchemaToZod(jsonSchema) {
|
|
12230
12110
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
12231
12111
|
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
12232
|
-
return
|
|
12112
|
+
return zodOpenapi.z.string();
|
|
12233
12113
|
}
|
|
12234
12114
|
switch (jsonSchema.type) {
|
|
12235
12115
|
case "object":
|
|
@@ -12238,22 +12118,22 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
12238
12118
|
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
12239
12119
|
shape[key] = jsonSchemaToZod(prop);
|
|
12240
12120
|
}
|
|
12241
|
-
return
|
|
12121
|
+
return zodOpenapi.z.object(shape);
|
|
12242
12122
|
}
|
|
12243
|
-
return
|
|
12123
|
+
return zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown());
|
|
12244
12124
|
case "array": {
|
|
12245
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) :
|
|
12246
|
-
return
|
|
12125
|
+
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : zodOpenapi.z.unknown();
|
|
12126
|
+
return zodOpenapi.z.array(itemSchema);
|
|
12247
12127
|
}
|
|
12248
12128
|
case "string":
|
|
12249
|
-
return
|
|
12129
|
+
return zodOpenapi.z.string();
|
|
12250
12130
|
case "number":
|
|
12251
12131
|
case "integer":
|
|
12252
|
-
return
|
|
12132
|
+
return zodOpenapi.z.number();
|
|
12253
12133
|
case "boolean":
|
|
12254
|
-
return
|
|
12134
|
+
return zodOpenapi.z.boolean();
|
|
12255
12135
|
case "null":
|
|
12256
|
-
return
|
|
12136
|
+
return zodOpenapi.z.null();
|
|
12257
12137
|
default:
|
|
12258
12138
|
logger12.warn(
|
|
12259
12139
|
{
|
|
@@ -12262,7 +12142,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
12262
12142
|
},
|
|
12263
12143
|
"Unsupported JSON schema type, using unknown validation"
|
|
12264
12144
|
);
|
|
12265
|
-
return
|
|
12145
|
+
return zodOpenapi.z.unknown();
|
|
12266
12146
|
}
|
|
12267
12147
|
}
|
|
12268
12148
|
|
|
@@ -12509,9 +12389,9 @@ var ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
|
12509
12389
|
* Get the standard Zod schema for artifact reference components
|
|
12510
12390
|
*/
|
|
12511
12391
|
static getSchema() {
|
|
12512
|
-
return
|
|
12513
|
-
id:
|
|
12514
|
-
name:
|
|
12392
|
+
return zodOpenapi.z.object({
|
|
12393
|
+
id: zodOpenapi.z.string(),
|
|
12394
|
+
name: zodOpenapi.z.literal("Artifact"),
|
|
12515
12395
|
props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
12516
12396
|
});
|
|
12517
12397
|
}
|
|
@@ -12562,9 +12442,9 @@ var ArtifactCreateSchema = class {
|
|
|
12562
12442
|
},
|
|
12563
12443
|
required: ["id", "tool_call_id", "type", "base_selector"]
|
|
12564
12444
|
};
|
|
12565
|
-
return
|
|
12566
|
-
id:
|
|
12567
|
-
name:
|
|
12445
|
+
return zodOpenapi.z.object({
|
|
12446
|
+
id: zodOpenapi.z.string(),
|
|
12447
|
+
name: zodOpenapi.z.literal(`ArtifactCreate_${component.name}`),
|
|
12568
12448
|
props: jsonSchemaToZod(propsSchema)
|
|
12569
12449
|
});
|
|
12570
12450
|
});
|
|
@@ -12636,13 +12516,14 @@ var DEFAULT_BACKOFF = {
|
|
|
12636
12516
|
var DEFAULT_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
12637
12517
|
var PermanentError = class _PermanentError extends Error {
|
|
12638
12518
|
cause;
|
|
12519
|
+
type;
|
|
12639
12520
|
constructor(message, options) {
|
|
12640
12521
|
let msg = message;
|
|
12641
12522
|
if (options?.cause) {
|
|
12642
12523
|
msg += `: ${options.cause}`;
|
|
12643
12524
|
}
|
|
12644
12525
|
super(msg, options);
|
|
12645
|
-
this.name = "PermanentError";
|
|
12526
|
+
this.name = options?.type || "PermanentError";
|
|
12646
12527
|
if (typeof this.cause === "undefined") {
|
|
12647
12528
|
this.cause = options?.cause;
|
|
12648
12529
|
}
|
|
@@ -12951,6 +12832,12 @@ var A2AClient = class {
|
|
|
12951
12832
|
}
|
|
12952
12833
|
}
|
|
12953
12834
|
const rpcResponse = await httpResponse.json();
|
|
12835
|
+
if (rpcResponse.error?.data?.type === "connection_refused") {
|
|
12836
|
+
throw new PermanentError(rpcResponse.error.message, {
|
|
12837
|
+
cause: new Error(rpcResponse.error.message),
|
|
12838
|
+
type: "connection_refused"
|
|
12839
|
+
});
|
|
12840
|
+
}
|
|
12954
12841
|
if (rpcResponse.id !== requestId2) {
|
|
12955
12842
|
logger13.warn(
|
|
12956
12843
|
{
|
|
@@ -13342,7 +13229,7 @@ var createTransferToAgentTool = ({
|
|
|
13342
13229
|
const toolDescription = generateTransferToolDescription(transferConfig);
|
|
13343
13230
|
return ai.tool({
|
|
13344
13231
|
description: toolDescription,
|
|
13345
|
-
inputSchema:
|
|
13232
|
+
inputSchema: zodOpenapi.z.object({}),
|
|
13346
13233
|
execute: async () => {
|
|
13347
13234
|
const activeSpan = api.trace.getActiveSpan();
|
|
13348
13235
|
if (activeSpan) {
|
|
@@ -13397,7 +13284,7 @@ function createDelegateToAgentTool({
|
|
|
13397
13284
|
}) {
|
|
13398
13285
|
return ai.tool({
|
|
13399
13286
|
description: generateDelegateToolDescription(delegateConfig),
|
|
13400
|
-
inputSchema:
|
|
13287
|
+
inputSchema: zodOpenapi.z.object({ message: zodOpenapi.z.string() }),
|
|
13401
13288
|
execute: async (input, context) => {
|
|
13402
13289
|
const delegationId = `del_${agentsCore.generateId()}`;
|
|
13403
13290
|
const activeSpan = api.trace.getActiveSpan();
|
|
@@ -14847,7 +14734,7 @@ var Agent = class {
|
|
|
14847
14734
|
/**
|
|
14848
14735
|
* Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
|
|
14849
14736
|
*/
|
|
14850
|
-
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId) {
|
|
14737
|
+
wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId, options) {
|
|
14851
14738
|
if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
|
|
14852
14739
|
return toolDefinition;
|
|
14853
14740
|
}
|
|
@@ -14869,13 +14756,24 @@ var Agent = class {
|
|
|
14869
14756
|
});
|
|
14870
14757
|
}
|
|
14871
14758
|
const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_");
|
|
14759
|
+
const needsApproval = options?.needsApproval || false;
|
|
14872
14760
|
if (streamRequestId && !isInternalTool) {
|
|
14873
|
-
|
|
14761
|
+
const toolCallData = {
|
|
14874
14762
|
toolName,
|
|
14875
14763
|
input: args2,
|
|
14876
14764
|
toolCallId,
|
|
14877
14765
|
relationshipId
|
|
14878
|
-
}
|
|
14766
|
+
};
|
|
14767
|
+
if (needsApproval) {
|
|
14768
|
+
toolCallData.needsApproval = true;
|
|
14769
|
+
toolCallData.conversationId = this.conversationId;
|
|
14770
|
+
}
|
|
14771
|
+
await agentSessionManager.recordEvent(
|
|
14772
|
+
streamRequestId,
|
|
14773
|
+
"tool_call",
|
|
14774
|
+
this.config.id,
|
|
14775
|
+
toolCallData
|
|
14776
|
+
);
|
|
14879
14777
|
}
|
|
14880
14778
|
try {
|
|
14881
14779
|
const result = await originalExecute(args2, context);
|
|
@@ -14920,7 +14818,8 @@ var Agent = class {
|
|
|
14920
14818
|
output: result,
|
|
14921
14819
|
toolCallId,
|
|
14922
14820
|
duration,
|
|
14923
|
-
relationshipId
|
|
14821
|
+
relationshipId,
|
|
14822
|
+
needsApproval
|
|
14924
14823
|
});
|
|
14925
14824
|
}
|
|
14926
14825
|
return result;
|
|
@@ -14934,7 +14833,8 @@ var Agent = class {
|
|
|
14934
14833
|
toolCallId,
|
|
14935
14834
|
duration,
|
|
14936
14835
|
error: errorMessage,
|
|
14937
|
-
relationshipId
|
|
14836
|
+
relationshipId,
|
|
14837
|
+
needsApproval
|
|
14938
14838
|
});
|
|
14939
14839
|
}
|
|
14940
14840
|
throw error;
|
|
@@ -15003,30 +14903,120 @@ var Agent = class {
|
|
|
15003
14903
|
const wrappedTools2 = {};
|
|
15004
14904
|
for (const [index, toolSet] of tools.entries()) {
|
|
15005
14905
|
const relationshipId = mcpTools[index]?.relationshipId;
|
|
15006
|
-
for (const [toolName, toolDef] of Object.entries(toolSet)) {
|
|
14906
|
+
for (const [toolName, toolDef] of Object.entries(toolSet.tools)) {
|
|
14907
|
+
const needsApproval = toolSet.toolPolicies?.[toolName]?.needsApproval || false;
|
|
14908
|
+
const enhancedTool = {
|
|
14909
|
+
...toolDef,
|
|
14910
|
+
needsApproval
|
|
14911
|
+
};
|
|
15007
14912
|
wrappedTools2[toolName] = this.wrapToolWithStreaming(
|
|
15008
14913
|
toolName,
|
|
15009
|
-
|
|
14914
|
+
enhancedTool,
|
|
15010
14915
|
streamRequestId,
|
|
15011
14916
|
"mcp",
|
|
15012
|
-
relationshipId
|
|
14917
|
+
relationshipId,
|
|
14918
|
+
{ needsApproval }
|
|
15013
14919
|
);
|
|
15014
14920
|
}
|
|
15015
14921
|
}
|
|
15016
14922
|
return wrappedTools2;
|
|
15017
14923
|
}
|
|
15018
14924
|
const wrappedTools = {};
|
|
15019
|
-
for (const [index,
|
|
14925
|
+
for (const [index, toolResult] of tools.entries()) {
|
|
15020
14926
|
const relationshipId = mcpTools[index]?.relationshipId;
|
|
15021
|
-
for (const [toolName, originalTool] of Object.entries(
|
|
14927
|
+
for (const [toolName, originalTool] of Object.entries(toolResult.tools)) {
|
|
15022
14928
|
if (!isValidTool(originalTool)) {
|
|
15023
14929
|
logger19.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
15024
14930
|
continue;
|
|
15025
14931
|
}
|
|
14932
|
+
const needsApproval = toolResult.toolPolicies?.[toolName]?.needsApproval || false;
|
|
14933
|
+
logger19.debug(
|
|
14934
|
+
{
|
|
14935
|
+
toolName,
|
|
14936
|
+
toolPolicies: toolResult.toolPolicies,
|
|
14937
|
+
needsApproval,
|
|
14938
|
+
policyForThisTool: toolResult.toolPolicies?.[toolName]
|
|
14939
|
+
},
|
|
14940
|
+
"Tool approval check"
|
|
14941
|
+
);
|
|
15026
14942
|
const sessionWrappedTool = ai.tool({
|
|
15027
14943
|
description: originalTool.description,
|
|
15028
14944
|
inputSchema: originalTool.inputSchema,
|
|
15029
14945
|
execute: async (args2, { toolCallId }) => {
|
|
14946
|
+
if (needsApproval) {
|
|
14947
|
+
logger19.info(
|
|
14948
|
+
{ toolName, toolCallId, args: args2 },
|
|
14949
|
+
"Tool requires approval - waiting for user response"
|
|
14950
|
+
);
|
|
14951
|
+
const currentSpan = api.trace.getActiveSpan();
|
|
14952
|
+
if (currentSpan) {
|
|
14953
|
+
currentSpan.addEvent("tool.approval.requested", {
|
|
14954
|
+
"tool.name": toolName,
|
|
14955
|
+
"tool.callId": toolCallId,
|
|
14956
|
+
"subAgent.id": this.config.id
|
|
14957
|
+
});
|
|
14958
|
+
}
|
|
14959
|
+
tracer.startActiveSpan(
|
|
14960
|
+
"tool.approval_requested",
|
|
14961
|
+
{
|
|
14962
|
+
attributes: {
|
|
14963
|
+
"tool.name": toolName,
|
|
14964
|
+
"tool.callId": toolCallId,
|
|
14965
|
+
"subAgent.id": this.config.id,
|
|
14966
|
+
"subAgent.name": this.config.name
|
|
14967
|
+
}
|
|
14968
|
+
},
|
|
14969
|
+
(requestSpan) => {
|
|
14970
|
+
requestSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
14971
|
+
requestSpan.end();
|
|
14972
|
+
}
|
|
14973
|
+
);
|
|
14974
|
+
const approvalResult = await pendingToolApprovalManager.waitForApproval(
|
|
14975
|
+
toolCallId,
|
|
14976
|
+
toolName,
|
|
14977
|
+
args2,
|
|
14978
|
+
this.conversationId || "unknown",
|
|
14979
|
+
this.config.id
|
|
14980
|
+
);
|
|
14981
|
+
if (!approvalResult.approved) {
|
|
14982
|
+
return tracer.startActiveSpan(
|
|
14983
|
+
"tool.approval_denied",
|
|
14984
|
+
{
|
|
14985
|
+
attributes: {
|
|
14986
|
+
"tool.name": toolName,
|
|
14987
|
+
"tool.callId": toolCallId,
|
|
14988
|
+
"subAgent.id": this.config.id,
|
|
14989
|
+
"subAgent.name": this.config.name
|
|
14990
|
+
}
|
|
14991
|
+
},
|
|
14992
|
+
(denialSpan) => {
|
|
14993
|
+
logger19.info(
|
|
14994
|
+
{ toolName, toolCallId, reason: approvalResult.reason },
|
|
14995
|
+
"Tool execution denied by user"
|
|
14996
|
+
);
|
|
14997
|
+
denialSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
14998
|
+
denialSpan.end();
|
|
14999
|
+
return `User denied approval to run this tool: ${approvalResult.reason}`;
|
|
15000
|
+
}
|
|
15001
|
+
);
|
|
15002
|
+
}
|
|
15003
|
+
tracer.startActiveSpan(
|
|
15004
|
+
"tool.approval_approved",
|
|
15005
|
+
{
|
|
15006
|
+
attributes: {
|
|
15007
|
+
"tool.name": toolName,
|
|
15008
|
+
"tool.callId": toolCallId,
|
|
15009
|
+
"subAgent.id": this.config.id,
|
|
15010
|
+
"subAgent.name": this.config.name
|
|
15011
|
+
}
|
|
15012
|
+
},
|
|
15013
|
+
(approvedSpan) => {
|
|
15014
|
+
logger19.info({ toolName, toolCallId }, "Tool approved, continuing with execution");
|
|
15015
|
+
approvedSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
15016
|
+
approvedSpan.end();
|
|
15017
|
+
}
|
|
15018
|
+
);
|
|
15019
|
+
}
|
|
15030
15020
|
logger19.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
15031
15021
|
try {
|
|
15032
15022
|
const rawResult = await originalTool.execute(args2, { toolCallId });
|
|
@@ -15092,7 +15082,8 @@ var Agent = class {
|
|
|
15092
15082
|
sessionWrappedTool,
|
|
15093
15083
|
streamRequestId,
|
|
15094
15084
|
"mcp",
|
|
15095
|
-
relationshipId
|
|
15085
|
+
relationshipId,
|
|
15086
|
+
{ needsApproval }
|
|
15096
15087
|
);
|
|
15097
15088
|
}
|
|
15098
15089
|
}
|
|
@@ -15131,8 +15122,10 @@ var Agent = class {
|
|
|
15131
15122
|
subAgentId: this.config.id
|
|
15132
15123
|
}
|
|
15133
15124
|
});
|
|
15134
|
-
const
|
|
15135
|
-
const
|
|
15125
|
+
const toolRelation = toolsForAgent.data.find((t2) => t2.toolId === tool3.id);
|
|
15126
|
+
const agentToolRelationHeaders = toolRelation?.headers || void 0;
|
|
15127
|
+
const selectedTools = toolRelation?.selectedTools || void 0;
|
|
15128
|
+
const toolPolicies = toolRelation?.toolPolicies || {};
|
|
15136
15129
|
let serverConfig;
|
|
15137
15130
|
if (credentialReferenceId && this.credentialStuffer) {
|
|
15138
15131
|
const credentialReference = await agentsCore.getCredentialReference(dbClient_default)({
|
|
@@ -15263,7 +15256,7 @@ var Agent = class {
|
|
|
15263
15256
|
);
|
|
15264
15257
|
}
|
|
15265
15258
|
}
|
|
15266
|
-
return tools;
|
|
15259
|
+
return { tools, toolPolicies };
|
|
15267
15260
|
}
|
|
15268
15261
|
async createMcpConnection(tool3, serverConfig) {
|
|
15269
15262
|
const client = new agentsCore.McpClient({
|
|
@@ -15286,12 +15279,12 @@ var Agent = class {
|
|
|
15286
15279
|
if (error?.cause && JSON.stringify(error.cause).includes("ECONNREFUSED")) {
|
|
15287
15280
|
const errorMessage = "Connection refused. Please check if the MCP server is running.";
|
|
15288
15281
|
throw new Error(errorMessage);
|
|
15289
|
-
}
|
|
15282
|
+
}
|
|
15283
|
+
if (error.message.includes("404")) {
|
|
15290
15284
|
const errorMessage = "Error accessing endpoint (HTTP 404)";
|
|
15291
15285
|
throw new Error(errorMessage);
|
|
15292
|
-
} else {
|
|
15293
|
-
throw new Error(`MCP server connection failed: ${error.message}`);
|
|
15294
15286
|
}
|
|
15287
|
+
throw new Error(`MCP server connection failed: ${error.message}`);
|
|
15295
15288
|
}
|
|
15296
15289
|
throw error;
|
|
15297
15290
|
}
|
|
@@ -15651,9 +15644,9 @@ var Agent = class {
|
|
|
15651
15644
|
getArtifactTools() {
|
|
15652
15645
|
return ai.tool({
|
|
15653
15646
|
description: "Call this tool to get the complete artifact data with the given artifactId. This retrieves the full artifact content (not just the summary). Only use this when you need the complete artifact data and the summary shown in your context is insufficient.",
|
|
15654
|
-
inputSchema:
|
|
15655
|
-
artifactId:
|
|
15656
|
-
toolCallId:
|
|
15647
|
+
inputSchema: zodOpenapi.z.object({
|
|
15648
|
+
artifactId: zodOpenapi.z.string().describe("The unique identifier of the artifact to get."),
|
|
15649
|
+
toolCallId: zodOpenapi.z.string().describe("The tool call ID associated with this artifact.")
|
|
15657
15650
|
}),
|
|
15658
15651
|
execute: async ({ artifactId, toolCallId }) => {
|
|
15659
15652
|
logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
@@ -15680,9 +15673,9 @@ var Agent = class {
|
|
|
15680
15673
|
createThinkingCompleteTool() {
|
|
15681
15674
|
return ai.tool({
|
|
15682
15675
|
description: "\u{1F6A8} CRITICAL: Call this tool IMMEDIATELY when you have gathered enough information to answer the user. This is MANDATORY - you CANNOT provide text responses in thinking mode, only tool calls. Call thinking_complete as soon as you have sufficient data to generate a structured response.",
|
|
15683
|
-
inputSchema:
|
|
15684
|
-
complete:
|
|
15685
|
-
summary:
|
|
15676
|
+
inputSchema: zodOpenapi.z.object({
|
|
15677
|
+
complete: zodOpenapi.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
|
|
15678
|
+
summary: zodOpenapi.z.string().describe(
|
|
15686
15679
|
"Brief summary of what information was gathered and why it is sufficient to answer the user"
|
|
15687
15680
|
)
|
|
15688
15681
|
}),
|
|
@@ -16076,7 +16069,7 @@ ${output}`;
|
|
|
16076
16069
|
}
|
|
16077
16070
|
}
|
|
16078
16071
|
const primaryModelSettings = this.getPrimaryModel();
|
|
16079
|
-
const modelSettings = ModelFactory.prepareGenerationConfig(primaryModelSettings);
|
|
16072
|
+
const modelSettings = agentsCore.ModelFactory.prepareGenerationConfig(primaryModelSettings);
|
|
16080
16073
|
let response;
|
|
16081
16074
|
let textResponse;
|
|
16082
16075
|
const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
|
|
@@ -16129,6 +16122,15 @@ ${output}`;
|
|
|
16129
16122
|
logger19.debug({ error }, "Failed to track agent reasoning");
|
|
16130
16123
|
}
|
|
16131
16124
|
}
|
|
16125
|
+
if (last && last["content"] && last["content"].length > 0) {
|
|
16126
|
+
const lastContent = last["content"][last["content"].length - 1];
|
|
16127
|
+
if (lastContent["type"] === "tool-error") {
|
|
16128
|
+
const error = lastContent["error"];
|
|
16129
|
+
if (error && typeof error === "object" && "name" in error && error.name === "connection_refused") {
|
|
16130
|
+
return true;
|
|
16131
|
+
}
|
|
16132
|
+
}
|
|
16133
|
+
}
|
|
16132
16134
|
if (steps.length >= 2) {
|
|
16133
16135
|
const previousStep = steps[steps.length - 2];
|
|
16134
16136
|
if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
|
|
@@ -16189,13 +16191,13 @@ ${output}`;
|
|
|
16189
16191
|
parser.markToolResult();
|
|
16190
16192
|
}
|
|
16191
16193
|
break;
|
|
16192
|
-
case "error":
|
|
16194
|
+
case "error": {
|
|
16193
16195
|
if (event.error instanceof Error) {
|
|
16194
16196
|
throw event.error;
|
|
16195
|
-
} else {
|
|
16196
|
-
const errorMessage = event.error?.error?.message;
|
|
16197
|
-
throw new Error(errorMessage);
|
|
16198
16197
|
}
|
|
16198
|
+
const errorMessage = event.error?.error?.message;
|
|
16199
|
+
throw new Error(errorMessage);
|
|
16200
|
+
}
|
|
16199
16201
|
}
|
|
16200
16202
|
}
|
|
16201
16203
|
await parser.finalize();
|
|
@@ -16364,9 +16366,9 @@ ${output}${structureHintsFormatted}`;
|
|
|
16364
16366
|
this.config.dataComponents.forEach((dc) => {
|
|
16365
16367
|
const propsSchema = jsonSchemaToZod(dc.props);
|
|
16366
16368
|
componentSchemas.push(
|
|
16367
|
-
|
|
16368
|
-
id:
|
|
16369
|
-
name:
|
|
16369
|
+
zodOpenapi.z.object({
|
|
16370
|
+
id: zodOpenapi.z.string(),
|
|
16371
|
+
name: zodOpenapi.z.literal(dc.name),
|
|
16370
16372
|
props: propsSchema
|
|
16371
16373
|
})
|
|
16372
16374
|
);
|
|
@@ -16383,11 +16385,11 @@ ${output}${structureHintsFormatted}`;
|
|
|
16383
16385
|
if (componentSchemas.length === 1) {
|
|
16384
16386
|
dataComponentsSchema = componentSchemas[0];
|
|
16385
16387
|
} else {
|
|
16386
|
-
dataComponentsSchema =
|
|
16388
|
+
dataComponentsSchema = zodOpenapi.z.union(
|
|
16387
16389
|
componentSchemas
|
|
16388
16390
|
);
|
|
16389
16391
|
}
|
|
16390
|
-
const structuredModelSettings = ModelFactory.prepareGenerationConfig(
|
|
16392
|
+
const structuredModelSettings = agentsCore.ModelFactory.prepareGenerationConfig(
|
|
16391
16393
|
this.getStructuredOutputModel()
|
|
16392
16394
|
);
|
|
16393
16395
|
const configuredPhase2Timeout = structuredModelSettings.maxDuration ? Math.min(
|
|
@@ -16425,8 +16427,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
16425
16427
|
const streamResult = ai.streamObject({
|
|
16426
16428
|
...structuredModelSettings,
|
|
16427
16429
|
messages: phase2Messages,
|
|
16428
|
-
schema:
|
|
16429
|
-
dataComponents:
|
|
16430
|
+
schema: zodOpenapi.z.object({
|
|
16431
|
+
dataComponents: zodOpenapi.z.array(dataComponentsSchema)
|
|
16430
16432
|
}),
|
|
16431
16433
|
experimental_telemetry: {
|
|
16432
16434
|
isEnabled: true,
|
|
@@ -16496,8 +16498,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
16496
16498
|
withJsonPostProcessing2({
|
|
16497
16499
|
...structuredModelSettings,
|
|
16498
16500
|
messages: phase2Messages,
|
|
16499
|
-
schema:
|
|
16500
|
-
dataComponents:
|
|
16501
|
+
schema: zodOpenapi.z.object({
|
|
16502
|
+
dataComponents: zodOpenapi.z.array(dataComponentsSchema)
|
|
16501
16503
|
}),
|
|
16502
16504
|
experimental_telemetry: {
|
|
16503
16505
|
isEnabled: true,
|
|
@@ -17090,17 +17092,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17090
17092
|
}
|
|
17091
17093
|
]
|
|
17092
17094
|
};
|
|
17093
|
-
} else {
|
|
17094
|
-
logger20.warn(
|
|
17095
|
-
{
|
|
17096
|
-
hasToolResult: !!toolResult,
|
|
17097
|
-
hasOutput: !!toolResult?.output,
|
|
17098
|
-
validationPassed: false,
|
|
17099
|
-
output: toolResult?.output
|
|
17100
|
-
},
|
|
17101
|
-
"[DEBUG] Transfer validation FAILED"
|
|
17102
|
-
);
|
|
17103
17095
|
}
|
|
17096
|
+
logger20.warn(
|
|
17097
|
+
{
|
|
17098
|
+
hasToolResult: !!toolResult,
|
|
17099
|
+
hasOutput: !!toolResult?.output,
|
|
17100
|
+
validationPassed: false,
|
|
17101
|
+
output: toolResult?.output
|
|
17102
|
+
},
|
|
17103
|
+
"[DEBUG] Transfer validation FAILED"
|
|
17104
|
+
);
|
|
17104
17105
|
}
|
|
17105
17106
|
}
|
|
17106
17107
|
}
|
|
@@ -17120,10 +17121,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17120
17121
|
};
|
|
17121
17122
|
} catch (error) {
|
|
17122
17123
|
console.error("Task handler error:", error);
|
|
17124
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
17125
|
+
const isConnectionRefused = errorMessage.includes("Connection refused. Please check if the MCP server is running.");
|
|
17123
17126
|
return {
|
|
17124
17127
|
status: {
|
|
17125
17128
|
state: agentsCore.TaskState.Failed,
|
|
17126
|
-
message:
|
|
17129
|
+
message: errorMessage,
|
|
17130
|
+
type: isConnectionRefused ? "connection_refused" : "unknown"
|
|
17127
17131
|
},
|
|
17128
17132
|
artifacts: []
|
|
17129
17133
|
};
|
|
@@ -17336,14 +17340,14 @@ app.openapi(
|
|
|
17336
17340
|
description: "Agent Card for A2A discovery",
|
|
17337
17341
|
content: {
|
|
17338
17342
|
"application/json": {
|
|
17339
|
-
schema:
|
|
17340
|
-
name:
|
|
17341
|
-
description:
|
|
17342
|
-
url:
|
|
17343
|
-
version:
|
|
17344
|
-
defaultInputModes:
|
|
17345
|
-
defaultOutputModes:
|
|
17346
|
-
skills:
|
|
17343
|
+
schema: zodOpenapi.z.object({
|
|
17344
|
+
name: zodOpenapi.z.string(),
|
|
17345
|
+
description: zodOpenapi.z.string().optional(),
|
|
17346
|
+
url: zodOpenapi.z.string(),
|
|
17347
|
+
version: zodOpenapi.z.string(),
|
|
17348
|
+
defaultInputModes: zodOpenapi.z.array(zodOpenapi.z.string()),
|
|
17349
|
+
defaultOutputModes: zodOpenapi.z.array(zodOpenapi.z.string()),
|
|
17350
|
+
skills: zodOpenapi.z.array(zodOpenapi.z.any())
|
|
17347
17351
|
})
|
|
17348
17352
|
}
|
|
17349
17353
|
}
|
|
@@ -18019,7 +18023,7 @@ var VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
18019
18023
|
}
|
|
18020
18024
|
const now = Date.now();
|
|
18021
18025
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
18022
|
-
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
18026
|
+
if (operation.type !== "tool_call" && operation.type !== "tool_result" && (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS)) {
|
|
18023
18027
|
this.queuedEvents.push({ type: "data-operation", event: operation });
|
|
18024
18028
|
return;
|
|
18025
18029
|
}
|
|
@@ -18615,36 +18619,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
18615
18619
|
body: {
|
|
18616
18620
|
content: {
|
|
18617
18621
|
"application/json": {
|
|
18618
|
-
schema:
|
|
18619
|
-
model:
|
|
18620
|
-
messages:
|
|
18621
|
-
|
|
18622
|
-
role:
|
|
18623
|
-
content:
|
|
18624
|
-
|
|
18625
|
-
|
|
18626
|
-
|
|
18627
|
-
type:
|
|
18628
|
-
text:
|
|
18622
|
+
schema: zodOpenapi.z.object({
|
|
18623
|
+
model: zodOpenapi.z.string().describe("The model to use for the completion"),
|
|
18624
|
+
messages: zodOpenapi.z.array(
|
|
18625
|
+
zodOpenapi.z.object({
|
|
18626
|
+
role: zodOpenapi.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
|
|
18627
|
+
content: zodOpenapi.z.union([
|
|
18628
|
+
zodOpenapi.z.string(),
|
|
18629
|
+
zodOpenapi.z.array(
|
|
18630
|
+
zodOpenapi.z.strictObject({
|
|
18631
|
+
type: zodOpenapi.z.string(),
|
|
18632
|
+
text: zodOpenapi.z.string().optional()
|
|
18629
18633
|
})
|
|
18630
18634
|
)
|
|
18631
18635
|
]).describe("The message content"),
|
|
18632
|
-
name:
|
|
18636
|
+
name: zodOpenapi.z.string().optional().describe("The name of the message sender")
|
|
18633
18637
|
})
|
|
18634
18638
|
).describe("The conversation messages"),
|
|
18635
|
-
temperature:
|
|
18636
|
-
top_p:
|
|
18637
|
-
n:
|
|
18638
|
-
stream:
|
|
18639
|
-
max_tokens:
|
|
18640
|
-
presence_penalty:
|
|
18641
|
-
frequency_penalty:
|
|
18642
|
-
logit_bias:
|
|
18643
|
-
user:
|
|
18644
|
-
conversationId:
|
|
18645
|
-
tools:
|
|
18646
|
-
runConfig:
|
|
18647
|
-
headers:
|
|
18639
|
+
temperature: zodOpenapi.z.number().optional().describe("Controls randomness (0-1)"),
|
|
18640
|
+
top_p: zodOpenapi.z.number().optional().describe("Controls nucleus sampling"),
|
|
18641
|
+
n: zodOpenapi.z.number().optional().describe("Number of completions to generate"),
|
|
18642
|
+
stream: zodOpenapi.z.boolean().optional().describe("Whether to stream the response"),
|
|
18643
|
+
max_tokens: zodOpenapi.z.number().optional().describe("Maximum tokens to generate"),
|
|
18644
|
+
presence_penalty: zodOpenapi.z.number().optional().describe("Presence penalty (-2 to 2)"),
|
|
18645
|
+
frequency_penalty: zodOpenapi.z.number().optional().describe("Frequency penalty (-2 to 2)"),
|
|
18646
|
+
logit_bias: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.number()).optional().describe("Token logit bias"),
|
|
18647
|
+
user: zodOpenapi.z.string().optional().describe("User identifier"),
|
|
18648
|
+
conversationId: zodOpenapi.z.string().optional().describe("Conversation ID for multi-turn chat"),
|
|
18649
|
+
tools: zodOpenapi.z.array(zodOpenapi.z.string()).optional().describe("Available tools"),
|
|
18650
|
+
runConfig: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).optional().describe("Run configuration"),
|
|
18651
|
+
headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).optional().describe(
|
|
18648
18652
|
"Headers data for template processing (validated against context config schema)"
|
|
18649
18653
|
)
|
|
18650
18654
|
})
|
|
@@ -18655,14 +18659,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
18655
18659
|
responses: {
|
|
18656
18660
|
200: {
|
|
18657
18661
|
description: "Streaming chat completion response in Server-Sent Events format",
|
|
18658
|
-
headers:
|
|
18659
|
-
"Content-Type":
|
|
18660
|
-
"Cache-Control":
|
|
18661
|
-
Connection:
|
|
18662
|
+
headers: zodOpenapi.z.object({
|
|
18663
|
+
"Content-Type": zodOpenapi.z.string().default("text/event-stream"),
|
|
18664
|
+
"Cache-Control": zodOpenapi.z.string().default("no-cache"),
|
|
18665
|
+
Connection: zodOpenapi.z.string().default("keep-alive")
|
|
18662
18666
|
}),
|
|
18663
18667
|
content: {
|
|
18664
18668
|
"text/event-stream": {
|
|
18665
|
-
schema:
|
|
18669
|
+
schema: zodOpenapi.z.string().describe("Server-Sent Events stream with chat completion chunks")
|
|
18666
18670
|
}
|
|
18667
18671
|
}
|
|
18668
18672
|
},
|
|
@@ -18670,13 +18674,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
18670
18674
|
description: "Invalid request context or parameters",
|
|
18671
18675
|
content: {
|
|
18672
18676
|
"application/json": {
|
|
18673
|
-
schema:
|
|
18674
|
-
error:
|
|
18675
|
-
details:
|
|
18676
|
-
|
|
18677
|
-
field:
|
|
18678
|
-
message:
|
|
18679
|
-
value:
|
|
18677
|
+
schema: zodOpenapi.z.object({
|
|
18678
|
+
error: zodOpenapi.z.string(),
|
|
18679
|
+
details: zodOpenapi.z.array(
|
|
18680
|
+
zodOpenapi.z.object({
|
|
18681
|
+
field: zodOpenapi.z.string(),
|
|
18682
|
+
message: zodOpenapi.z.string(),
|
|
18683
|
+
value: zodOpenapi.z.unknown().optional()
|
|
18680
18684
|
})
|
|
18681
18685
|
).optional()
|
|
18682
18686
|
})
|
|
@@ -18687,8 +18691,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
18687
18691
|
description: "Agent or agent not found",
|
|
18688
18692
|
content: {
|
|
18689
18693
|
"application/json": {
|
|
18690
|
-
schema:
|
|
18691
|
-
error:
|
|
18694
|
+
schema: zodOpenapi.z.object({
|
|
18695
|
+
error: zodOpenapi.z.string()
|
|
18692
18696
|
})
|
|
18693
18697
|
}
|
|
18694
18698
|
}
|
|
@@ -18697,9 +18701,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
18697
18701
|
description: "Internal server error",
|
|
18698
18702
|
content: {
|
|
18699
18703
|
"application/json": {
|
|
18700
|
-
schema:
|
|
18701
|
-
error:
|
|
18702
|
-
message:
|
|
18704
|
+
schema: zodOpenapi.z.object({
|
|
18705
|
+
error: zodOpenapi.z.string(),
|
|
18706
|
+
message: zodOpenapi.z.string()
|
|
18703
18707
|
})
|
|
18704
18708
|
}
|
|
18705
18709
|
}
|
|
@@ -19203,6 +19207,137 @@ app3.openapi(chatDataStreamRoute, async (c2) => {
|
|
|
19203
19207
|
});
|
|
19204
19208
|
}
|
|
19205
19209
|
});
|
|
19210
|
+
var toolApprovalRoute = zodOpenapi.createRoute({
|
|
19211
|
+
method: "post",
|
|
19212
|
+
path: "/tool-approvals",
|
|
19213
|
+
tags: ["chat"],
|
|
19214
|
+
summary: "Approve or deny tool execution",
|
|
19215
|
+
description: "Handle user approval/denial of tool execution requests during conversations",
|
|
19216
|
+
security: [{ bearerAuth: [] }],
|
|
19217
|
+
request: {
|
|
19218
|
+
body: {
|
|
19219
|
+
content: {
|
|
19220
|
+
"application/json": {
|
|
19221
|
+
schema: zodOpenapi.z.object({
|
|
19222
|
+
conversationId: zodOpenapi.z.string().describe("The conversation ID"),
|
|
19223
|
+
toolCallId: zodOpenapi.z.string().describe("The tool call ID to respond to"),
|
|
19224
|
+
approved: zodOpenapi.z.boolean().describe("Whether the tool execution is approved"),
|
|
19225
|
+
reason: zodOpenapi.z.string().optional().describe("Optional reason for the decision")
|
|
19226
|
+
})
|
|
19227
|
+
}
|
|
19228
|
+
}
|
|
19229
|
+
}
|
|
19230
|
+
},
|
|
19231
|
+
responses: {
|
|
19232
|
+
200: {
|
|
19233
|
+
description: "Tool approval response processed successfully",
|
|
19234
|
+
content: {
|
|
19235
|
+
"application/json": {
|
|
19236
|
+
schema: zodOpenapi.z.object({
|
|
19237
|
+
success: zodOpenapi.z.boolean(),
|
|
19238
|
+
message: zodOpenapi.z.string().optional()
|
|
19239
|
+
})
|
|
19240
|
+
}
|
|
19241
|
+
}
|
|
19242
|
+
},
|
|
19243
|
+
400: {
|
|
19244
|
+
description: "Bad request - invalid tool call ID or conversation ID",
|
|
19245
|
+
content: {
|
|
19246
|
+
"application/json": {
|
|
19247
|
+
schema: zodOpenapi.z.object({
|
|
19248
|
+
error: zodOpenapi.z.string()
|
|
19249
|
+
})
|
|
19250
|
+
}
|
|
19251
|
+
}
|
|
19252
|
+
},
|
|
19253
|
+
404: {
|
|
19254
|
+
description: "Tool call not found or already processed",
|
|
19255
|
+
content: {
|
|
19256
|
+
"application/json": {
|
|
19257
|
+
schema: zodOpenapi.z.object({
|
|
19258
|
+
error: zodOpenapi.z.string()
|
|
19259
|
+
})
|
|
19260
|
+
}
|
|
19261
|
+
}
|
|
19262
|
+
},
|
|
19263
|
+
500: {
|
|
19264
|
+
description: "Internal server error",
|
|
19265
|
+
content: {
|
|
19266
|
+
"application/json": {
|
|
19267
|
+
schema: zodOpenapi.z.object({
|
|
19268
|
+
error: zodOpenapi.z.string(),
|
|
19269
|
+
message: zodOpenapi.z.string()
|
|
19270
|
+
})
|
|
19271
|
+
}
|
|
19272
|
+
}
|
|
19273
|
+
}
|
|
19274
|
+
}
|
|
19275
|
+
});
|
|
19276
|
+
app3.openapi(toolApprovalRoute, async (c2) => {
|
|
19277
|
+
const tracer2 = api.trace.getTracer("tool-approval-handler");
|
|
19278
|
+
return tracer2.startActiveSpan("tool_approval_request", async (span) => {
|
|
19279
|
+
try {
|
|
19280
|
+
const executionContext = agentsCore.getRequestExecutionContext(c2);
|
|
19281
|
+
const { tenantId, projectId } = executionContext;
|
|
19282
|
+
const requestBody = await c2.req.json();
|
|
19283
|
+
const { conversationId, toolCallId, approved, reason } = requestBody;
|
|
19284
|
+
logger26.info(
|
|
19285
|
+
{
|
|
19286
|
+
conversationId,
|
|
19287
|
+
toolCallId,
|
|
19288
|
+
approved,
|
|
19289
|
+
reason,
|
|
19290
|
+
tenantId,
|
|
19291
|
+
projectId
|
|
19292
|
+
},
|
|
19293
|
+
"Processing tool approval request"
|
|
19294
|
+
);
|
|
19295
|
+
const conversation = await agentsCore.getConversation(dbClient_default)({
|
|
19296
|
+
scopes: { tenantId, projectId },
|
|
19297
|
+
conversationId
|
|
19298
|
+
});
|
|
19299
|
+
if (!conversation) {
|
|
19300
|
+
span.setStatus({ code: 1, message: "Conversation not found" });
|
|
19301
|
+
return c2.json({ error: "Conversation not found" }, 404);
|
|
19302
|
+
}
|
|
19303
|
+
let success = false;
|
|
19304
|
+
if (approved) {
|
|
19305
|
+
success = pendingToolApprovalManager.approveToolCall(toolCallId);
|
|
19306
|
+
} else {
|
|
19307
|
+
success = pendingToolApprovalManager.denyToolCall(toolCallId, reason);
|
|
19308
|
+
}
|
|
19309
|
+
if (!success) {
|
|
19310
|
+
span.setStatus({ code: 1, message: "Tool call not found" });
|
|
19311
|
+
return c2.json({ error: "Tool call not found or already processed" }, 404);
|
|
19312
|
+
}
|
|
19313
|
+
logger26.info({ conversationId, toolCallId, approved }, "Tool approval processed successfully");
|
|
19314
|
+
span.setStatus({ code: 1, message: "Success" });
|
|
19315
|
+
return c2.json({
|
|
19316
|
+
success: true,
|
|
19317
|
+
message: approved ? "Tool execution approved" : "Tool execution denied"
|
|
19318
|
+
});
|
|
19319
|
+
} catch (error) {
|
|
19320
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
19321
|
+
logger26.error(
|
|
19322
|
+
{
|
|
19323
|
+
error: errorMessage,
|
|
19324
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
19325
|
+
},
|
|
19326
|
+
"Failed to process tool approval"
|
|
19327
|
+
);
|
|
19328
|
+
span.setStatus({ code: 2, message: errorMessage });
|
|
19329
|
+
return c2.json(
|
|
19330
|
+
{
|
|
19331
|
+
error: "Internal server error",
|
|
19332
|
+
message: errorMessage
|
|
19333
|
+
},
|
|
19334
|
+
500
|
|
19335
|
+
);
|
|
19336
|
+
} finally {
|
|
19337
|
+
span.end();
|
|
19338
|
+
}
|
|
19339
|
+
});
|
|
19340
|
+
});
|
|
19206
19341
|
var chatDataStream_default = app3;
|
|
19207
19342
|
|
|
19208
19343
|
// src/routes/mcp.ts
|
|
@@ -19285,7 +19420,8 @@ var validateSession = async (req, res, body2, tenantId, projectId, agentId) => {
|
|
|
19285
19420
|
})
|
|
19286
19421
|
);
|
|
19287
19422
|
return false;
|
|
19288
|
-
}
|
|
19423
|
+
}
|
|
19424
|
+
if (Array.isArray(sessionId)) {
|
|
19289
19425
|
res.writeHead(400).end(
|
|
19290
19426
|
JSON.stringify({
|
|
19291
19427
|
jsonrpc: "2.0",
|
|
@@ -19418,7 +19554,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
19418
19554
|
"send-query-to-agent",
|
|
19419
19555
|
`Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
|
|
19420
19556
|
{
|
|
19421
|
-
query:
|
|
19557
|
+
query: zodOpenapi.z.string().describe("The query to send to the agent")
|
|
19422
19558
|
},
|
|
19423
19559
|
async ({ query }) => {
|
|
19424
19560
|
try {
|
|
@@ -19708,16 +19844,15 @@ app4.openapi(
|
|
|
19708
19844
|
c2,
|
|
19709
19845
|
credentialStores
|
|
19710
19846
|
);
|
|
19711
|
-
} else {
|
|
19712
|
-
return await handleExistingSessionRequest(
|
|
19713
|
-
body2,
|
|
19714
|
-
executionContext,
|
|
19715
|
-
validatedContext,
|
|
19716
|
-
req,
|
|
19717
|
-
res,
|
|
19718
|
-
credentialStores
|
|
19719
|
-
);
|
|
19720
19847
|
}
|
|
19848
|
+
return await handleExistingSessionRequest(
|
|
19849
|
+
body2,
|
|
19850
|
+
executionContext,
|
|
19851
|
+
validatedContext,
|
|
19852
|
+
req,
|
|
19853
|
+
res,
|
|
19854
|
+
credentialStores
|
|
19855
|
+
);
|
|
19721
19856
|
} catch (e) {
|
|
19722
19857
|
logger27.error(
|
|
19723
19858
|
{
|