@dexto/core 1.12.1 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/DextoAgent.cjs +7 -0
- package/dist/agent/DextoAgent.d.ts +2 -5
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +7 -0
- package/dist/approval/index.cjs +4 -2
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +3 -2
- package/dist/approval/manager.cjs +23 -4
- package/dist/approval/manager.d.ts +3 -2
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +21 -3
- package/dist/approval/schemas.cjs +5 -0
- package/dist/approval/schemas.d.ts +8 -0
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +5 -0
- package/dist/approval/types.d.ts +2 -2
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/context/manager.cjs +34 -31
- package/dist/context/manager.d.ts +5 -6
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +36 -32
- package/dist/context/utils.cjs +6 -17
- package/dist/context/utils.d.ts +2 -0
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +5 -17
- package/dist/events/index.cjs +8 -0
- package/dist/events/index.d.ts +18 -5
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +8 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.cjs +69 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.d.ts +17 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.d.ts.map +1 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.js +46 -0
- package/dist/llm/executor/tool-output-spill.cjs +92 -0
- package/dist/llm/executor/tool-output-spill.d.ts +24 -0
- package/dist/llm/executor/tool-output-spill.d.ts.map +1 -0
- package/dist/llm/executor/tool-output-spill.js +65 -0
- package/dist/llm/executor/turn-executor.cjs +116 -35
- package/dist/llm/executor/turn-executor.d.ts +21 -5
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +122 -35
- package/dist/llm/services/factory.cjs +2 -1
- package/dist/llm/services/factory.d.ts +2 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +2 -1
- package/dist/llm/services/vercel.cjs +2 -1
- package/dist/llm/services/vercel.d.ts +2 -1
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +2 -1
- package/dist/mcp/errors.cjs +9 -0
- package/dist/mcp/errors.d.ts +4 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +9 -0
- package/dist/mcp/manager.cjs +79 -3
- package/dist/mcp/manager.d.ts +14 -7
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +79 -3
- package/dist/mcp/mcp-client.cjs +52 -62
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +54 -63
- package/dist/session/chat-session.cjs +1 -0
- package/dist/session/chat-session.d.ts +2 -0
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +1 -0
- package/dist/session/session-manager.cjs +16 -2
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +16 -2
- package/dist/storage/index.cjs +2 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/stores/backend.cjs +26 -0
- package/dist/storage/stores/backend.d.ts +20 -0
- package/dist/storage/stores/backend.d.ts.map +1 -1
- package/dist/storage/stores/backend.js +25 -0
- package/dist/storage/stores/in-memory.cjs +20 -3
- package/dist/storage/stores/in-memory.d.ts +16 -0
- package/dist/storage/stores/in-memory.d.ts.map +1 -1
- package/dist/storage/stores/in-memory.js +18 -2
- package/dist/storage/stores/types.d.ts +3 -0
- package/dist/storage/stores/types.d.ts.map +1 -1
- package/dist/storage/tool-executions/types.cjs +12 -8
- package/dist/storage/tool-executions/types.d.ts +11 -2
- package/dist/storage/tool-executions/types.d.ts.map +1 -1
- package/dist/storage/tool-executions/types.js +12 -8
- package/dist/storage/tool-outputs/types.cjs +16 -0
- package/dist/storage/tool-outputs/types.d.ts +19 -0
- package/dist/storage/tool-outputs/types.d.ts.map +1 -0
- package/dist/storage/tool-outputs/types.js +0 -0
- package/dist/telemetry/decorators.cjs +47 -23
- package/dist/telemetry/decorators.d.ts +6 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +47 -23
- package/dist/telemetry/operation-span.cjs +5 -2
- package/dist/telemetry/operation-span.d.ts +3 -0
- package/dist/telemetry/operation-span.d.ts.map +1 -1
- package/dist/telemetry/operation-span.js +5 -2
- package/dist/tools/activity.cjs +8 -0
- package/dist/tools/activity.d.ts +1 -0
- package/dist/tools/activity.d.ts.map +1 -1
- package/dist/tools/activity.js +8 -0
- package/dist/tools/approval/tool-approval-policy.cjs +11 -1
- package/dist/tools/approval/tool-approval-policy.d.ts +2 -2
- package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
- package/dist/tools/approval/tool-approval-policy.js +11 -1
- package/dist/tools/identity.cjs +36 -0
- package/dist/tools/identity.d.ts +6 -0
- package/dist/tools/identity.d.ts.map +1 -0
- package/dist/tools/identity.js +13 -0
- package/dist/tools/index.cjs +2 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -1
- package/dist/tools/presentation/tool-presentation.d.ts +5 -0
- package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
- package/dist/tools/schema-fingerprint.cjs +48 -0
- package/dist/tools/schema-fingerprint.d.ts +4 -0
- package/dist/tools/schema-fingerprint.d.ts.map +1 -0
- package/dist/tools/schema-fingerprint.js +25 -0
- package/dist/tools/schemas.cjs +3 -0
- package/dist/tools/schemas.d.ts +1 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +2 -0
- package/dist/tools/tool-manager.cjs +199 -48
- package/dist/tools/tool-manager.d.ts +25 -11
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +199 -48
- package/dist/tools/tool-output-read.cjs +129 -0
- package/dist/tools/tool-output-read.d.ts +19 -0
- package/dist/tools/tool-output-read.d.ts.map +1 -0
- package/dist/tools/tool-output-read.js +106 -0
- package/dist/tools/types.d.ts +55 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/schema.cjs +2 -2
- package/dist/utils/schema.d.ts +1 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +2 -2
- package/dist/utils/service-initializer.cjs +4 -0
- package/dist/utils/service-initializer.d.ts +2 -0
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +4 -0
- package/dist/utils/stable-fingerprint.cjs +32 -0
- package/dist/utils/stable-fingerprint.d.ts +3 -0
- package/dist/utils/stable-fingerprint.d.ts.map +1 -0
- package/dist/utils/stable-fingerprint.js +9 -0
- package/package.json +9 -2
- package/dist/llm/executor/tool-output-truncator.cjs +0 -75
- package/dist/llm/executor/tool-output-truncator.d.ts +0 -27
- package/dist/llm/executor/tool-output-truncator.d.ts.map +0 -1
- package/dist/llm/executor/tool-output-truncator.js +0 -48
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var schema_fingerprint_exports = {};
|
|
20
|
+
__export(schema_fingerprint_exports, {
|
|
21
|
+
toolSchemaFingerprint: () => toolSchemaFingerprint
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_fingerprint_exports);
|
|
24
|
+
var import_stable_fingerprint = require("../utils/stable-fingerprint.js");
|
|
25
|
+
function toolSchemaFingerprint(inputSchema, outputSchema) {
|
|
26
|
+
return (0, import_stable_fingerprint.stableFingerprint)(
|
|
27
|
+
canonicalJson({ inputSchema, ...outputSchema === void 0 ? {} : { outputSchema } })
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function canonicalJson(value) {
|
|
31
|
+
if (value === null) return "null";
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
return `[${value.map((entry) => canonicalJson(entry ?? null)).join(",")}]`;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "object") {
|
|
36
|
+
const properties = Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`);
|
|
37
|
+
return `{${properties.join(",")}}`;
|
|
38
|
+
}
|
|
39
|
+
const serialized = JSON.stringify(value);
|
|
40
|
+
if (serialized === void 0) {
|
|
41
|
+
throw new Error(`Tool schema contains a non-JSON ${typeof value} value.`);
|
|
42
|
+
}
|
|
43
|
+
return serialized;
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
toolSchemaFingerprint
|
|
48
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
/** Fingerprints the callable input/output contract independent of object key order. */
|
|
3
|
+
export declare function toolSchemaFingerprint(inputSchema: JSONSchema7, outputSchema?: JSONSchema7): string;
|
|
4
|
+
//# sourceMappingURL=schema-fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-fingerprint.d.ts","sourceRoot":"","sources":["../../src/tools/schema-fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,uFAAuF;AACvF,wBAAgB,qBAAqB,CACjC,WAAW,EAAE,WAAW,EACxB,YAAY,CAAC,EAAE,WAAW,GAC3B,MAAM,CAIR"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "../chunk-C6A6W6XS.js";
|
|
2
|
+
import { stableFingerprint } from "../utils/stable-fingerprint.js";
|
|
3
|
+
function toolSchemaFingerprint(inputSchema, outputSchema) {
|
|
4
|
+
return stableFingerprint(
|
|
5
|
+
canonicalJson({ inputSchema, ...outputSchema === void 0 ? {} : { outputSchema } })
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
function canonicalJson(value) {
|
|
9
|
+
if (value === null) return "null";
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return `[${value.map((entry) => canonicalJson(entry ?? null)).join(",")}]`;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === "object") {
|
|
14
|
+
const properties = Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`);
|
|
15
|
+
return `{${properties.join(",")}}`;
|
|
16
|
+
}
|
|
17
|
+
const serialized = JSON.stringify(value);
|
|
18
|
+
if (serialized === void 0) {
|
|
19
|
+
throw new Error(`Tool schema contains a non-JSON ${typeof value} value.`);
|
|
20
|
+
}
|
|
21
|
+
return serialized;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
toolSchemaFingerprint
|
|
25
|
+
};
|
package/dist/tools/schemas.cjs
CHANGED
|
@@ -24,12 +24,14 @@ __export(schemas_exports, {
|
|
|
24
24
|
ElicitationConfigSchema: () => ElicitationConfigSchema,
|
|
25
25
|
PERMISSIONS_MODES: () => PERMISSIONS_MODES,
|
|
26
26
|
PermissionsConfigSchema: () => PermissionsConfigSchema,
|
|
27
|
+
ToolIdentitySchema: () => import_identity.ToolIdentitySchema,
|
|
27
28
|
ToolLimitsSchema: () => ToolLimitsSchema,
|
|
28
29
|
ToolPoliciesSchema: () => ToolPoliciesSchema,
|
|
29
30
|
ToolsConfigSchema: () => ToolsConfigSchema
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(schemas_exports);
|
|
32
33
|
var import_zod = require("zod");
|
|
34
|
+
var import_identity = require("./identity.js");
|
|
33
35
|
const PERMISSIONS_MODES = ["manual", "auto-approve"];
|
|
34
36
|
const ALLOWED_TOOLS_STORAGE_TYPES = ["memory", "storage"];
|
|
35
37
|
const DEFAULT_PERMISSIONS_MODE = "auto-approve";
|
|
@@ -75,6 +77,7 @@ const ToolsConfigSchema = import_zod.z.record(import_zod.z.string(), ToolLimitsS
|
|
|
75
77
|
ElicitationConfigSchema,
|
|
76
78
|
PERMISSIONS_MODES,
|
|
77
79
|
PermissionsConfigSchema,
|
|
80
|
+
ToolIdentitySchema,
|
|
78
81
|
ToolLimitsSchema,
|
|
79
82
|
ToolPoliciesSchema,
|
|
80
83
|
ToolsConfigSchema
|
package/dist/tools/schemas.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export { ToolIdentitySchema } from './identity.js';
|
|
2
3
|
export declare const PERMISSIONS_MODES: readonly ["manual", "auto-approve"];
|
|
3
4
|
export type PermissionsMode = (typeof PERMISSIONS_MODES)[number];
|
|
4
5
|
export declare const ALLOWED_TOOLS_STORAGE_TYPES: readonly ["memory", "storage"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,eAAO,MAAM,iBAAiB,qCAAsC,CAAC;AACrE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,eAAO,MAAM,2BAA2B,gCAAiC,CAAC;AAC1E,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,eAAO,MAAM,wBAAwB,EAAE,eAAgC,CAAC;AACxE,eAAO,MAAM,6BAA6B,EAAE,uBAAmC,CAAC;AAGhF,eAAO,MAAM,kBAAkB;;mBAW+B,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE/D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;kBAyBwB,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAGlF,eAAO,MAAM,uBAAuB;;;kBAoB/B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAGlF,eAAO,MAAM,gBAAgB;;;;kBAShB,CAAC;AAEd,eAAO,MAAM,iBAAiB;;;;mBAEgB,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
package/dist/tools/schemas.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../chunk-C6A6W6XS.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { ToolIdentitySchema } from "./identity.js";
|
|
3
4
|
const PERMISSIONS_MODES = ["manual", "auto-approve"];
|
|
4
5
|
const ALLOWED_TOOLS_STORAGE_TYPES = ["memory", "storage"];
|
|
5
6
|
const DEFAULT_PERMISSIONS_MODE = "auto-approve";
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
ElicitationConfigSchema,
|
|
45
46
|
PERMISSIONS_MODES,
|
|
46
47
|
PermissionsConfigSchema,
|
|
48
|
+
ToolIdentitySchema,
|
|
47
49
|
ToolLimitsSchema,
|
|
48
50
|
ToolPoliciesSchema,
|
|
49
51
|
ToolsConfigSchema
|
|
@@ -71,6 +71,7 @@ var import_errors = require("./errors.js");
|
|
|
71
71
|
var import_errors2 = require("../errors/index.js");
|
|
72
72
|
var import_types2 = require("../logger/v2/types.js");
|
|
73
73
|
var import_schema = require("../utils/schema.js");
|
|
74
|
+
var import_schema_fingerprint = require("./schema-fingerprint.js");
|
|
74
75
|
var import_types3 = require("../approval/types.js");
|
|
75
76
|
var import_schemas = require("../approval/schemas.js");
|
|
76
77
|
var import_session_tool_policy = require("./approval/session-tool-policy.js");
|
|
@@ -85,6 +86,9 @@ function isRecord(value) {
|
|
|
85
86
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
86
87
|
}
|
|
87
88
|
_ToolManager_decorators = [(0, import_decorators.InstrumentClass)({
|
|
89
|
+
captureArguments: false,
|
|
90
|
+
captureErrors: false,
|
|
91
|
+
captureResult: false,
|
|
88
92
|
prefix: "tool",
|
|
89
93
|
excludeMethods: ["setHookSupport", "getApprovalManager", "getAllowedToolsProvider"]
|
|
90
94
|
})];
|
|
@@ -135,6 +139,8 @@ let _ToolManager = class _ToolManager {
|
|
|
135
139
|
}
|
|
136
140
|
mcpManager;
|
|
137
141
|
agentTools = /* @__PURE__ */ new Map();
|
|
142
|
+
/** Core-owned tools: always registered, never replaced by host tools or filtered per session. */
|
|
143
|
+
coreTools = [];
|
|
138
144
|
approvalManager;
|
|
139
145
|
allowedToolsProvider;
|
|
140
146
|
approvalMode;
|
|
@@ -198,9 +204,23 @@ let _ToolManager = class _ToolManager {
|
|
|
198
204
|
async initialize() {
|
|
199
205
|
this.logger.debug("ToolManager initialization complete");
|
|
200
206
|
}
|
|
207
|
+
registerCoreTools(tools) {
|
|
208
|
+
this.coreTools = tools;
|
|
209
|
+
for (const tool of tools) {
|
|
210
|
+
this.agentTools.set(tool.id, tool);
|
|
211
|
+
}
|
|
212
|
+
this.invalidateCache();
|
|
213
|
+
}
|
|
201
214
|
setTools(tools) {
|
|
202
215
|
this.agentTools.clear();
|
|
216
|
+
for (const tool of this.coreTools) {
|
|
217
|
+
this.agentTools.set(tool.id, tool);
|
|
218
|
+
}
|
|
203
219
|
for (const tool of tools) {
|
|
220
|
+
if (this.coreTools.some((coreTool) => coreTool.id === tool.id)) {
|
|
221
|
+
this.logger.warn(`Ignoring host tool '${tool.id}': the id belongs to a core tool`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
204
224
|
this.agentTools.set(tool.id, tool);
|
|
205
225
|
}
|
|
206
226
|
this.invalidateCache();
|
|
@@ -377,7 +397,12 @@ let _ToolManager = class _ToolManager {
|
|
|
377
397
|
* Filter a tool set based on disabled tools for a session.
|
|
378
398
|
*/
|
|
379
399
|
filterToolsForSession(toolSet, sessionId) {
|
|
380
|
-
|
|
400
|
+
const filtered = this.sessionToolPolicy.filterToolsForSession(toolSet, sessionId);
|
|
401
|
+
for (const tool of this.coreTools) {
|
|
402
|
+
const definition = toolSet[tool.id];
|
|
403
|
+
if (definition !== void 0) filtered[tool.id] = definition;
|
|
404
|
+
}
|
|
405
|
+
return filtered;
|
|
381
406
|
}
|
|
382
407
|
/**
|
|
383
408
|
* Check if a session has auto-approve tools set.
|
|
@@ -595,15 +620,77 @@ let _ToolManager = class _ToolManager {
|
|
|
595
620
|
async getMcpTools() {
|
|
596
621
|
return await this.mcpManager.getAllTools();
|
|
597
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Return canonical tool descriptions for host-owned discovery and type generation.
|
|
625
|
+
* Unlike getAllTools(), schemas are not rewritten for model-provider compatibility.
|
|
626
|
+
*/
|
|
627
|
+
async getToolDescriptors() {
|
|
628
|
+
const descriptors = [];
|
|
629
|
+
for (const tool of this.agentTools.values()) {
|
|
630
|
+
descriptors.push(await this.buildLocalToolDescriptor(tool));
|
|
631
|
+
}
|
|
632
|
+
for (const descriptor of this.mcpManager.getToolDescriptors()) {
|
|
633
|
+
descriptors.push(this.prefixMcpToolDescriptor(descriptor));
|
|
634
|
+
}
|
|
635
|
+
return descriptors;
|
|
636
|
+
}
|
|
637
|
+
async getToolDescriptor(toolName) {
|
|
638
|
+
const localTool = this.agentTools.get(toolName);
|
|
639
|
+
if (localTool !== void 0) {
|
|
640
|
+
return await this.buildLocalToolDescriptor(localTool);
|
|
641
|
+
}
|
|
642
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
643
|
+
return void 0;
|
|
644
|
+
}
|
|
645
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
646
|
+
if (mcpName.length === 0) {
|
|
647
|
+
return void 0;
|
|
648
|
+
}
|
|
649
|
+
const descriptor = this.mcpManager.getToolDescriptor(mcpName);
|
|
650
|
+
return descriptor === void 0 ? void 0 : this.prefixMcpToolDescriptor(descriptor);
|
|
651
|
+
}
|
|
652
|
+
resolveToolIdentity(toolName) {
|
|
653
|
+
if (this.agentTools.has(toolName)) {
|
|
654
|
+
return { type: "local", toolId: toolName };
|
|
655
|
+
}
|
|
656
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
660
|
+
return this.mcpManager.getToolDescriptor(mcpName)?.identity;
|
|
661
|
+
}
|
|
662
|
+
async buildLocalToolDescriptor(tool) {
|
|
663
|
+
const inputSchema = (0, import_schema.convertZodSchemaToJsonSchema)(tool.inputSchema, this.logger);
|
|
664
|
+
const outputSchema = tool.outputSchema === void 0 ? void 0 : (0, import_schema.convertZodSchemaToJsonSchema)(tool.outputSchema, this.logger, "output");
|
|
665
|
+
return {
|
|
666
|
+
name: tool.id,
|
|
667
|
+
description: await this.getLocalToolDescription(tool),
|
|
668
|
+
approval: this.approvalMode === "auto-approve" || tool.needsApproval === false || tool.needsApproval === null ? "never" : "possible",
|
|
669
|
+
identity: { type: "local", toolId: tool.id },
|
|
670
|
+
inputSchema,
|
|
671
|
+
...outputSchema === void 0 ? {} : { outputSchema },
|
|
672
|
+
schemaFingerprint: (0, import_schema_fingerprint.toolSchemaFingerprint)(inputSchema, outputSchema)
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
prefixMcpToolDescriptor(descriptor) {
|
|
676
|
+
return {
|
|
677
|
+
...descriptor,
|
|
678
|
+
approval: this.approvalMode === "auto-approve" ? "never" : "possible",
|
|
679
|
+
name: `${_ToolManager.MCP_TOOL_PREFIX}${descriptor.name}`,
|
|
680
|
+
description: `${descriptor.description || "No description provided"} (via MCP servers)`
|
|
681
|
+
};
|
|
682
|
+
}
|
|
598
683
|
buildToolExecutionContext(options) {
|
|
599
684
|
const workspace = this.currentWorkspace;
|
|
600
685
|
const baseContext = {
|
|
601
686
|
sessionId: options.sessionId,
|
|
602
687
|
runContext: options.runContext,
|
|
688
|
+
executionIdentity: options.executionIdentity,
|
|
603
689
|
workspaceId: workspace?.id,
|
|
604
690
|
workspace,
|
|
605
691
|
abortSignal: options.abortSignal,
|
|
606
692
|
toolCallId: options.toolCallId,
|
|
693
|
+
parentToolCallId: options.parentToolCallId,
|
|
607
694
|
hostRuntime: options.runContext?.hostRuntime,
|
|
608
695
|
logger: this.logger
|
|
609
696
|
};
|
|
@@ -617,8 +704,14 @@ let _ToolManager = class _ToolManager {
|
|
|
617
704
|
const sessionId = options.runContext?.sessionId ?? options.sessionId;
|
|
618
705
|
return { ...options, sessionId, hostRuntime: options.runContext?.hostRuntime };
|
|
619
706
|
}
|
|
620
|
-
resolveToolExecutionIdentity(invocation, toolCallId) {
|
|
707
|
+
resolveToolExecutionIdentity(invocation, toolCallId, parentToolCallId) {
|
|
621
708
|
if (invocation.executionIdentity !== void 0) {
|
|
709
|
+
if (invocation.executionIdentity.toolCallId !== toolCallId || invocation.executionIdentity.parentToolCallId !== parentToolCallId) {
|
|
710
|
+
throw import_errors.ToolError.executionFailed(
|
|
711
|
+
toolCallId,
|
|
712
|
+
"Tool execution identity does not match the prepared call"
|
|
713
|
+
);
|
|
714
|
+
}
|
|
622
715
|
return invocation.executionIdentity;
|
|
623
716
|
}
|
|
624
717
|
const ids = invocation.runContext?.hostRuntime?.ids;
|
|
@@ -635,6 +728,7 @@ let _ToolManager = class _ToolManager {
|
|
|
635
728
|
runId,
|
|
636
729
|
turnId,
|
|
637
730
|
modelStepId,
|
|
731
|
+
...parentToolCallId === void 0 ? {} : { parentToolCallId },
|
|
638
732
|
toolCallId
|
|
639
733
|
};
|
|
640
734
|
}
|
|
@@ -680,6 +774,16 @@ let _ToolManager = class _ToolManager {
|
|
|
680
774
|
}
|
|
681
775
|
return validated;
|
|
682
776
|
}
|
|
777
|
+
validateToolArgs(toolName, args) {
|
|
778
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
779
|
+
return this.validateLocalToolArgs(toolName, args);
|
|
780
|
+
}
|
|
781
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
782
|
+
if (mcpName.length === 0) {
|
|
783
|
+
throw import_errors.ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
784
|
+
}
|
|
785
|
+
return this.mcpManager.validateToolInput(mcpName, args);
|
|
786
|
+
}
|
|
683
787
|
async executeLocalTool(toolName, args, options) {
|
|
684
788
|
const tool = this.agentTools.get(toolName);
|
|
685
789
|
if (!tool) {
|
|
@@ -693,15 +797,15 @@ let _ToolManager = class _ToolManager {
|
|
|
693
797
|
const context = this.buildToolExecutionContext({
|
|
694
798
|
sessionId: options?.sessionId,
|
|
695
799
|
abortSignal: options?.abortSignal,
|
|
800
|
+
executionIdentity: options?.executionIdentity,
|
|
696
801
|
toolCallId: options?.toolCallId,
|
|
802
|
+
parentToolCallId: options?.parentToolCallId,
|
|
697
803
|
runContext: options?.runContext
|
|
698
804
|
});
|
|
699
805
|
const result = await tool.execute(args, context);
|
|
700
806
|
return result;
|
|
701
807
|
} catch (error) {
|
|
702
|
-
this.logger.error(
|
|
703
|
-
error: error instanceof Error ? error.message : String(error)
|
|
704
|
-
});
|
|
808
|
+
this.logger.error(`Local tool execution failed: ${toolName}`);
|
|
705
809
|
throw error;
|
|
706
810
|
}
|
|
707
811
|
}
|
|
@@ -730,21 +834,7 @@ let _ToolManager = class _ToolManager {
|
|
|
730
834
|
mcpTools = {};
|
|
731
835
|
}
|
|
732
836
|
for (const [toolName, tool] of this.agentTools) {
|
|
733
|
-
|
|
734
|
-
if (tool.getDescription) {
|
|
735
|
-
try {
|
|
736
|
-
const dynamicDescription = await tool.getDescription(
|
|
737
|
-
this.buildToolExecutionContext({})
|
|
738
|
-
);
|
|
739
|
-
if (dynamicDescription.trim()) {
|
|
740
|
-
description = dynamicDescription;
|
|
741
|
-
}
|
|
742
|
-
} catch (error) {
|
|
743
|
-
this.logger.warn(
|
|
744
|
-
`Failed to build dynamic description for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
837
|
+
const description = await this.getLocalToolDescription(tool);
|
|
748
838
|
allTools[toolName] = {
|
|
749
839
|
name: toolName,
|
|
750
840
|
description,
|
|
@@ -770,6 +860,21 @@ let _ToolManager = class _ToolManager {
|
|
|
770
860
|
);
|
|
771
861
|
return allTools;
|
|
772
862
|
}
|
|
863
|
+
async getLocalToolDescription(tool) {
|
|
864
|
+
const fallback = tool.description || "No description provided";
|
|
865
|
+
if (!tool.getDescription) {
|
|
866
|
+
return fallback;
|
|
867
|
+
}
|
|
868
|
+
try {
|
|
869
|
+
const description = await tool.getDescription(this.buildToolExecutionContext({}));
|
|
870
|
+
return description.trim() ? description : fallback;
|
|
871
|
+
} catch (error) {
|
|
872
|
+
this.logger.warn(
|
|
873
|
+
`Failed to build dynamic description for '${tool.id}': ${error instanceof Error ? error.message : String(error)}`
|
|
874
|
+
);
|
|
875
|
+
return fallback;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
773
878
|
/**
|
|
774
879
|
* Get all available tools from all sources with conflict resolution
|
|
775
880
|
* This is the single interface the LLM uses to discover tools
|
|
@@ -786,8 +891,8 @@ let _ToolManager = class _ToolManager {
|
|
|
786
891
|
}
|
|
787
892
|
async prepareToolCall(input) {
|
|
788
893
|
const sessionId = input.runContext?.sessionId ?? input.sessionId;
|
|
789
|
-
const
|
|
790
|
-
if (
|
|
894
|
+
const identity = this.resolveToolIdentity(input.toolName);
|
|
895
|
+
if (identity === void 0) {
|
|
791
896
|
return this.createPreparedToolError(
|
|
792
897
|
"unknown-tool",
|
|
793
898
|
input.toolName,
|
|
@@ -806,7 +911,7 @@ let _ToolManager = class _ToolManager {
|
|
|
806
911
|
const approvalDescription = typeof meta.callActivity?.running === "string" ? meta.callActivity.running : typeof rawToolArgs.description === "string" ? rawToolArgs.description : void 0;
|
|
807
912
|
let validatedArgs;
|
|
808
913
|
try {
|
|
809
|
-
validatedArgs = this.
|
|
914
|
+
validatedArgs = this.validateToolArgs(input.toolName, rawToolArgs);
|
|
810
915
|
} catch (error) {
|
|
811
916
|
return this.createPreparedToolError(
|
|
812
917
|
"invalid-input",
|
|
@@ -818,13 +923,15 @@ let _ToolManager = class _ToolManager {
|
|
|
818
923
|
toolName: input.toolName,
|
|
819
924
|
args: validatedArgs,
|
|
820
925
|
toolCallId: input.toolCallId,
|
|
926
|
+
...input.parentToolCallId === void 0 ? {} : { parentToolCallId: input.parentToolCallId },
|
|
821
927
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
822
928
|
...input.runContext !== void 0 ? { runContext: input.runContext } : {}
|
|
823
929
|
});
|
|
824
930
|
const call = {
|
|
931
|
+
identity,
|
|
825
932
|
input: validatedArgs,
|
|
933
|
+
...input.parentToolCallId === void 0 ? {} : { parentToolCallId: input.parentToolCallId },
|
|
826
934
|
presentationSnapshot,
|
|
827
|
-
source,
|
|
828
935
|
toolCallId: input.toolCallId,
|
|
829
936
|
toolName: input.toolName,
|
|
830
937
|
...eventMeta !== void 0 ? { meta: eventMeta } : {}
|
|
@@ -834,10 +941,11 @@ let _ToolManager = class _ToolManager {
|
|
|
834
941
|
getContext: () => this.buildToolExecutionContext({
|
|
835
942
|
sessionId,
|
|
836
943
|
toolCallId: input.toolCallId,
|
|
944
|
+
parentToolCallId: input.parentToolCallId,
|
|
837
945
|
runContext: input.runContext
|
|
838
946
|
}),
|
|
839
947
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
840
|
-
|
|
948
|
+
identity,
|
|
841
949
|
toolName: input.toolName
|
|
842
950
|
});
|
|
843
951
|
if (approvalGate.kind === "ready") {
|
|
@@ -860,6 +968,7 @@ let _ToolManager = class _ToolManager {
|
|
|
860
968
|
...input.runContext !== void 0 ? { runContext: input.runContext } : {},
|
|
861
969
|
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
862
970
|
toolCallId: input.toolCallId,
|
|
971
|
+
...input.call.parentToolCallId === void 0 ? {} : { parentToolCallId: input.call.parentToolCallId },
|
|
863
972
|
toolName: input.toolName
|
|
864
973
|
});
|
|
865
974
|
const hostRuntime = input.runContext?.hostRuntime;
|
|
@@ -869,9 +978,11 @@ let _ToolManager = class _ToolManager {
|
|
|
869
978
|
...hostRuntime !== void 0 ? { hostRuntime } : {},
|
|
870
979
|
metadata: {
|
|
871
980
|
toolName: input.toolName,
|
|
981
|
+
toolIdentity: input.call.identity,
|
|
872
982
|
...input.approvalGate.approvalKey !== void 0 ? { approvalKey: input.approvalGate.approvalKey } : {},
|
|
873
983
|
presentationSnapshot: input.call.presentationSnapshot,
|
|
874
984
|
toolCallId: input.toolCallId,
|
|
985
|
+
...input.call.parentToolCallId === void 0 ? {} : { parentToolCallId: input.call.parentToolCallId },
|
|
875
986
|
args: input.args,
|
|
876
987
|
...input.approvalDescription !== void 0 ? { description: input.approvalDescription } : {},
|
|
877
988
|
...displayPreview !== void 0 ? { displayPreview } : {}
|
|
@@ -932,6 +1043,14 @@ let _ToolManager = class _ToolManager {
|
|
|
932
1043
|
async requestApprovalDecision(recorded) {
|
|
933
1044
|
return this.approvalManager.requestApprovalDecision(recorded.request);
|
|
934
1045
|
}
|
|
1046
|
+
async cancelApprovalRequest(recorded) {
|
|
1047
|
+
await this.approvalManager.cancelApproval(recorded.request.approvalId);
|
|
1048
|
+
await this.applyApprovalDecision(recorded, {
|
|
1049
|
+
approvalId: recorded.request.approvalId,
|
|
1050
|
+
reason: "system_cancelled",
|
|
1051
|
+
status: import_types3.ApprovalStatus.CANCELLED
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
935
1054
|
assertRecordedApprovalMatchesPreparedCall(prepared, request) {
|
|
936
1055
|
const expected = {
|
|
937
1056
|
type: prepared.requestDetails.type,
|
|
@@ -1008,15 +1127,6 @@ let _ToolManager = class _ToolManager {
|
|
|
1008
1127
|
const outcome = response.status === import_types3.ApprovalStatus.DENIED ? "approval was denied" : "approval was cancelled";
|
|
1009
1128
|
return `Tool '${toolName}' was not executed because ${outcome}${response.message ? `: ${response.message}` : ""}.`;
|
|
1010
1129
|
}
|
|
1011
|
-
async resolveExecutableToolSource(toolName) {
|
|
1012
|
-
if (this.agentTools.has(toolName)) {
|
|
1013
|
-
return "local";
|
|
1014
|
-
}
|
|
1015
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX) && toolName.length > _ToolManager.MCP_TOOL_PREFIX.length) {
|
|
1016
|
-
return "mcp";
|
|
1017
|
-
}
|
|
1018
|
-
return "unknown";
|
|
1019
|
-
}
|
|
1020
1130
|
createPreparedToolError(kind, toolName, error) {
|
|
1021
1131
|
return {
|
|
1022
1132
|
kind: "terminal",
|
|
@@ -1044,7 +1154,6 @@ let _ToolManager = class _ToolManager {
|
|
|
1044
1154
|
async executeTool(toolName, args, toolCallId, invocation) {
|
|
1045
1155
|
const { sessionId, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
|
|
1046
1156
|
this.logger.debug(`\u{1F527} Tool execution requested: '${toolName}' (toolCallId: ${toolCallId})`);
|
|
1047
|
-
this.logger.debug(`Tool args: ${JSON.stringify(args, null, 2)}`);
|
|
1048
1157
|
if (toolName === _ToolManager.MCP_TOOL_PREFIX) {
|
|
1049
1158
|
throw import_errors.ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
1050
1159
|
}
|
|
@@ -1052,6 +1161,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1052
1161
|
toolName,
|
|
1053
1162
|
input: args,
|
|
1054
1163
|
toolCallId,
|
|
1164
|
+
...invocation?.executionIdentity?.parentToolCallId === void 0 ? {} : { parentToolCallId: invocation.executionIdentity.parentToolCallId },
|
|
1055
1165
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
1056
1166
|
...runContext !== void 0 ? { runContext } : {}
|
|
1057
1167
|
});
|
|
@@ -1070,7 +1180,11 @@ let _ToolManager = class _ToolManager {
|
|
|
1070
1180
|
try {
|
|
1071
1181
|
const recorded = await this.recordApprovalRequest(
|
|
1072
1182
|
prepared,
|
|
1073
|
-
this.resolveDirectApprovalIdentity(
|
|
1183
|
+
this.resolveDirectApprovalIdentity(
|
|
1184
|
+
invocation,
|
|
1185
|
+
toolCallId,
|
|
1186
|
+
prepared.call.parentToolCallId
|
|
1187
|
+
)
|
|
1074
1188
|
);
|
|
1075
1189
|
const response = await this.requestApprovalDecision(recorded);
|
|
1076
1190
|
applied = await this.applyApprovalDecision(recorded, {
|
|
@@ -1099,6 +1213,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1099
1213
|
if (!sessionId) {
|
|
1100
1214
|
return;
|
|
1101
1215
|
}
|
|
1216
|
+
if (call.parentToolCallId !== void 0) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1102
1219
|
this.agentEventBus.emit("llm:tool-call", {
|
|
1103
1220
|
toolName: call.toolName,
|
|
1104
1221
|
presentationSnapshot: this.toolPresentation.snapshotForToolCallEvent({
|
|
@@ -1120,7 +1237,11 @@ let _ToolManager = class _ToolManager {
|
|
|
1120
1237
|
if ((0, import_env.isBackgroundTasksEnabled)() && call.meta?.runInBackground === true && sessionId !== void 0) {
|
|
1121
1238
|
return void 0;
|
|
1122
1239
|
}
|
|
1123
|
-
const identity = this.resolveToolExecutionIdentity(
|
|
1240
|
+
const identity = this.resolveToolExecutionIdentity(
|
|
1241
|
+
invocation ?? {},
|
|
1242
|
+
call.toolCallId,
|
|
1243
|
+
call.parentToolCallId
|
|
1244
|
+
);
|
|
1124
1245
|
if (identity === void 0) {
|
|
1125
1246
|
return void 0;
|
|
1126
1247
|
}
|
|
@@ -1148,13 +1269,24 @@ let _ToolManager = class _ToolManager {
|
|
|
1148
1269
|
`Tool execution already failed: ${executionId}`
|
|
1149
1270
|
);
|
|
1150
1271
|
}
|
|
1272
|
+
if (this.resumesRunningExecution(call, record.status)) {
|
|
1273
|
+
return void 0;
|
|
1274
|
+
}
|
|
1151
1275
|
throw import_errors.ToolError.executionFailed(
|
|
1152
1276
|
call.toolName,
|
|
1153
1277
|
`Tool execution already ${record.status}: ${executionId}`
|
|
1154
1278
|
);
|
|
1155
1279
|
}
|
|
1280
|
+
/** A `resumable` local tool re-enters its own matching record that is still running. */
|
|
1281
|
+
resumesRunningExecution(call, status) {
|
|
1282
|
+
return status === "running" && call.identity.type === "local" && this.agentTools.get(call.identity.toolId)?.resumable === true;
|
|
1283
|
+
}
|
|
1156
1284
|
async recordDirectToolExecutionFailure(call, invocation, error) {
|
|
1157
|
-
const identity = this.resolveToolExecutionIdentity(
|
|
1285
|
+
const identity = this.resolveToolExecutionIdentity(
|
|
1286
|
+
invocation ?? {},
|
|
1287
|
+
call.toolCallId,
|
|
1288
|
+
call.parentToolCallId
|
|
1289
|
+
);
|
|
1158
1290
|
if (identity === void 0) {
|
|
1159
1291
|
return;
|
|
1160
1292
|
}
|
|
@@ -1187,8 +1319,12 @@ let _ToolManager = class _ToolManager {
|
|
|
1187
1319
|
error: error instanceof Error ? error.message : String(error)
|
|
1188
1320
|
});
|
|
1189
1321
|
}
|
|
1190
|
-
resolveDirectApprovalIdentity(invocation, toolCallId) {
|
|
1191
|
-
const executionIdentity = this.resolveToolExecutionIdentity(
|
|
1322
|
+
resolveDirectApprovalIdentity(invocation, toolCallId, parentToolCallId) {
|
|
1323
|
+
const executionIdentity = this.resolveToolExecutionIdentity(
|
|
1324
|
+
invocation ?? {},
|
|
1325
|
+
toolCallId,
|
|
1326
|
+
parentToolCallId
|
|
1327
|
+
);
|
|
1192
1328
|
if (executionIdentity !== void 0) {
|
|
1193
1329
|
return {
|
|
1194
1330
|
runId: executionIdentity.runId,
|
|
@@ -1239,7 +1375,8 @@ let _ToolManager = class _ToolManager {
|
|
|
1239
1375
|
const { sessionId, abortSignal, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
|
|
1240
1376
|
const durableIdentity = this.resolveToolExecutionIdentity(
|
|
1241
1377
|
invocation ?? {},
|
|
1242
|
-
call.toolCallId
|
|
1378
|
+
call.toolCallId,
|
|
1379
|
+
call.parentToolCallId
|
|
1243
1380
|
);
|
|
1244
1381
|
const backgroundTasksEnabled = (0, import_env.isBackgroundTasksEnabled)();
|
|
1245
1382
|
const willRunInBackground = backgroundTasksEnabled && call.meta?.runInBackground === true && sessionId !== void 0;
|
|
@@ -1288,10 +1425,16 @@ let _ToolManager = class _ToolManager {
|
|
|
1288
1425
|
}
|
|
1289
1426
|
return this.createFailedPreparedToolResult(call, started.record.error);
|
|
1290
1427
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1428
|
+
if (!this.resumesRunningExecution(call, started.record.status)) {
|
|
1429
|
+
throw import_errors.ToolError.executionFailed(
|
|
1430
|
+
call.toolName,
|
|
1431
|
+
`Tool execution already ${started.record.status}: ${executionId}`
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
this.logger.info("Resuming running prepared tool execution", {
|
|
1435
|
+
executionId,
|
|
1436
|
+
toolName: call.toolName
|
|
1437
|
+
});
|
|
1295
1438
|
}
|
|
1296
1439
|
}
|
|
1297
1440
|
const startTime = Date.now();
|
|
@@ -1303,6 +1446,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1303
1446
|
this.agentEventBus.emit("tool:running", {
|
|
1304
1447
|
toolName: call.toolName,
|
|
1305
1448
|
toolCallId: call.toolCallId,
|
|
1449
|
+
...call.parentToolCallId !== void 0 && {
|
|
1450
|
+
parentToolCallId: call.parentToolCallId
|
|
1451
|
+
},
|
|
1306
1452
|
sessionId,
|
|
1307
1453
|
...hostRuntime !== void 0 && { hostRuntime }
|
|
1308
1454
|
});
|
|
@@ -1327,7 +1473,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1327
1473
|
);
|
|
1328
1474
|
toolArgs = modifiedPayload.args;
|
|
1329
1475
|
try {
|
|
1330
|
-
toolArgs = this.
|
|
1476
|
+
toolArgs = this.validateToolArgs(call.toolName, toolArgs);
|
|
1331
1477
|
} catch (error) {
|
|
1332
1478
|
this.logger.error(
|
|
1333
1479
|
`Post-hook validation failed for tool '${call.toolName}': a beforeToolCall hook may have set invalid args`
|
|
@@ -1346,7 +1492,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1346
1492
|
promise
|
|
1347
1493
|
};
|
|
1348
1494
|
};
|
|
1349
|
-
if (call.
|
|
1495
|
+
if (call.identity.type === "mcp") {
|
|
1350
1496
|
const actualToolName = call.toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
1351
1497
|
if (actualToolName.length === 0) {
|
|
1352
1498
|
throw import_errors.ToolError.invalidName(
|
|
@@ -1403,7 +1549,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1403
1549
|
this.executeLocalTool(call.toolName, toolArgs, {
|
|
1404
1550
|
sessionId: backgroundSessionId,
|
|
1405
1551
|
abortSignal,
|
|
1552
|
+
executionIdentity,
|
|
1406
1553
|
toolCallId: call.toolCallId,
|
|
1554
|
+
parentToolCallId: call.parentToolCallId,
|
|
1407
1555
|
runContext
|
|
1408
1556
|
}),
|
|
1409
1557
|
`Tool ${call.toolName}`
|
|
@@ -1427,7 +1575,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1427
1575
|
result = await this.executeLocalTool(call.toolName, toolArgs, {
|
|
1428
1576
|
sessionId,
|
|
1429
1577
|
abortSignal,
|
|
1578
|
+
executionIdentity,
|
|
1430
1579
|
toolCallId: call.toolCallId,
|
|
1580
|
+
parentToolCallId: call.parentToolCallId,
|
|
1431
1581
|
runContext
|
|
1432
1582
|
});
|
|
1433
1583
|
}
|
|
@@ -1463,6 +1613,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1463
1613
|
result,
|
|
1464
1614
|
args: toolArgs,
|
|
1465
1615
|
toolCallId: call.toolCallId,
|
|
1616
|
+
...call.parentToolCallId === void 0 ? {} : { parentToolCallId: call.parentToolCallId },
|
|
1466
1617
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
1467
1618
|
...runContext !== void 0 ? { runContext } : {}
|
|
1468
1619
|
});
|
|
@@ -1494,7 +1645,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1494
1645
|
} catch (error) {
|
|
1495
1646
|
const duration = Date.now() - startTime;
|
|
1496
1647
|
this.logger.error(
|
|
1497
|
-
|
|
1648
|
+
`Prepared tool execution failed for ${call.toolName} after ${duration}ms, sessionId: ${sessionId ?? "global"}`
|
|
1498
1649
|
);
|
|
1499
1650
|
const message = error instanceof Error ? error.message : String(error);
|
|
1500
1651
|
if (executionId !== void 0) {
|