@dexto/core 1.8.12 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approval/manager.cjs +37 -325
- package/dist/approval/manager.d.ts +10 -109
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +37 -316
- package/dist/approval/schemas.cjs +8 -51
- package/dist/approval/schemas.d.ts +5 -179
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +8 -47
- package/dist/approval/types.cjs +0 -6
- package/dist/approval/types.d.ts +2 -27
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +0 -6
- package/dist/context/content-clone.cjs +12 -8
- package/dist/context/content-clone.d.ts.map +1 -1
- package/dist/context/content-clone.js +12 -8
- package/dist/errors/DextoRuntimeError.cjs +3 -1
- package/dist/errors/DextoRuntimeError.d.ts +5 -3
- package/dist/errors/DextoRuntimeError.d.ts.map +1 -1
- package/dist/errors/DextoRuntimeError.js +3 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/types.d.ts +1 -0
- package/dist/errors/types.d.ts.map +1 -1
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/llm/executor/provider-error.cjs +25 -4
- package/dist/llm/executor/provider-error.d.ts.map +1 -1
- package/dist/llm/executor/provider-error.js +25 -4
- package/dist/llm/executor/stream-processor.cjs +61 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +61 -0
- package/dist/llm/executor/turn-executor.cjs +93 -26
- package/dist/llm/executor/turn-executor.d.ts +2 -0
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +93 -26
- package/dist/llm/services/factory.cjs +3 -2
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +3 -2
- package/dist/llm/services/types.d.ts +8 -0
- package/dist/llm/services/types.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +6 -1
- package/dist/llm/services/vercel.d.ts +3 -2
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +6 -1
- package/dist/session/chat-session.cjs +3 -0
- package/dist/session/chat-session.d.ts +2 -1
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +3 -0
- package/dist/session/message-queue.cjs +48 -75
- package/dist/session/message-queue.d.ts +1 -2
- package/dist/session/message-queue.d.ts.map +1 -1
- package/dist/session/message-queue.js +48 -75
- package/dist/session/session-manager.cjs +14 -32
- package/dist/session/session-manager.d.ts +5 -2
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +14 -32
- package/dist/storage/approvals/types.cjs +2 -9
- package/dist/storage/approvals/types.d.ts +4 -16
- package/dist/storage/approvals/types.d.ts.map +1 -1
- package/dist/storage/approvals/types.js +2 -8
- package/dist/storage/database/types.d.ts +5 -0
- package/dist/storage/database/types.d.ts.map +1 -1
- package/dist/storage/index.cjs +0 -2
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +1 -2
- package/dist/storage/message-queue/types.d.ts +14 -6
- package/dist/storage/message-queue/types.d.ts.map +1 -1
- package/dist/storage/stores/backend.cjs +68 -32
- package/dist/storage/stores/backend.d.ts +17 -8
- package/dist/storage/stores/backend.d.ts.map +1 -1
- package/dist/storage/stores/backend.js +69 -33
- package/dist/storage/stores/in-memory.cjs +26 -11
- package/dist/storage/stores/in-memory.d.ts.map +1 -1
- package/dist/storage/stores/in-memory.js +27 -12
- package/dist/test-utils/in-memory-storage.cjs +11 -0
- package/dist/test-utils/in-memory-storage.js +11 -0
- package/dist/test-utils/session-state-stores.cjs +25 -9
- package/dist/test-utils/session-state-stores.js +26 -10
- package/dist/tools/approval/tool-approval-policy.cjs +87 -0
- package/dist/tools/approval/tool-approval-policy.d.ts +34 -0
- package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -0
- package/dist/tools/approval/tool-approval-policy.js +64 -0
- package/dist/tools/error-codes.cjs +0 -1
- package/dist/tools/error-codes.d.ts +0 -1
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +0 -1
- package/dist/tools/errors.cjs +0 -15
- package/dist/tools/errors.d.ts +0 -9
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +0 -15
- package/dist/tools/index.cjs +2 -0
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -1
- package/dist/tools/tool-manager.cjs +94 -312
- package/dist/tools/tool-manager.d.ts +4 -19
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +95 -316
- package/dist/tools/types.d.ts +10 -9
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/service-initializer.cjs +3 -0
- package/dist/utils/service-initializer.d.ts +2 -1
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +3 -0
- package/package.json +2 -2
- package/dist/tools/pattern-utils.cjs +0 -33
- package/dist/tools/pattern-utils.d.ts +0 -20
- package/dist/tools/pattern-utils.d.ts.map +0 -1
- package/dist/tools/pattern-utils.js +0 -10
|
@@ -127,6 +127,7 @@ export declare class ToolManager {
|
|
|
127
127
|
private cacheValid;
|
|
128
128
|
private logger;
|
|
129
129
|
private readonly sessionToolPolicy;
|
|
130
|
+
private readonly toolApprovalPolicy;
|
|
130
131
|
private readonly toolPresentation;
|
|
131
132
|
private cleanupHandlers;
|
|
132
133
|
private cleanupStarted;
|
|
@@ -248,12 +249,6 @@ export declare class ToolManager {
|
|
|
248
249
|
* Set up listeners for MCP notifications to invalidate cache on changes
|
|
249
250
|
*/
|
|
250
251
|
private setupNotificationListeners;
|
|
251
|
-
private getToolApprovalPatternKeyFn;
|
|
252
|
-
private getToolSuggestApprovalPatternsFn;
|
|
253
|
-
private getToolApprovalOverrideFn;
|
|
254
|
-
private getToolApprovalOnGrantedFn;
|
|
255
|
-
private getToolPatternKey;
|
|
256
|
-
private getToolSuggestedPatterns;
|
|
257
252
|
/**
|
|
258
253
|
* Auto-approve pending tool approval requests for the same tool.
|
|
259
254
|
* Called after a user selects "remember choice" for a tool.
|
|
@@ -263,16 +258,7 @@ export declare class ToolManager {
|
|
|
263
258
|
* @param sessionId The session ID for which the tool was allowed
|
|
264
259
|
*/
|
|
265
260
|
private autoApprovePendingToolRequests;
|
|
266
|
-
|
|
267
|
-
* Auto-approve pending tool approval requests that are now covered by a remembered pattern.
|
|
268
|
-
* Called after a user selects "remember pattern" for a tool.
|
|
269
|
-
*/
|
|
270
|
-
private autoApprovePendingPatternRequests;
|
|
271
|
-
/**
|
|
272
|
-
* Auto-approve pending tool approval requests that are now covered by a remembered directory.
|
|
273
|
-
* Called after a user selects "remember directory" for a directory-access prompt.
|
|
274
|
-
*/
|
|
275
|
-
private autoApprovePendingDirectoryRequests;
|
|
261
|
+
private autoApprovePendingApprovalKeyRequests;
|
|
276
262
|
getMcpManager(): MCPManager;
|
|
277
263
|
setContributorContextFactory(factory?: DynamicContributorContextFactory | null): void;
|
|
278
264
|
buildContributorContext(options?: {
|
|
@@ -310,8 +296,9 @@ export declare class ToolManager {
|
|
|
310
296
|
*/
|
|
311
297
|
getAllTools(): Promise<ToolSet>;
|
|
312
298
|
prepareToolCall(input: PrepareToolCallInput): Promise<PreparedToolCall>;
|
|
299
|
+
private prepareApprovalRequiredToolCall;
|
|
313
300
|
recordApprovalRequest(prepared: ApprovalRequiredPreparedToolCall, identity: ToolApprovalRecordIdentity): Promise<RecordedToolApproval>;
|
|
314
|
-
applyApprovalDecision(recorded: RecordedToolApproval, decision: ApprovalDecisionInput
|
|
301
|
+
applyApprovalDecision(recorded: RecordedToolApproval, decision: ApprovalDecisionInput): Promise<ToolApprovalDecisionApplication>;
|
|
315
302
|
requestApprovalDecision(recorded: RecordedToolApproval): Promise<ApprovalResponse>;
|
|
316
303
|
private assertRecordedApprovalMatchesPreparedCall;
|
|
317
304
|
private assertOnGrantedRequestMatchesPreparedCall;
|
|
@@ -321,8 +308,6 @@ export declare class ToolManager {
|
|
|
321
308
|
private resolveExecutableToolSource;
|
|
322
309
|
private createPreparedToolError;
|
|
323
310
|
private createPreparedToolTerminal;
|
|
324
|
-
private getToolApprovalOverrideRequest;
|
|
325
|
-
private classifyQuickApprovalRequirement;
|
|
326
311
|
executeTool(toolName: string, args: Record<string, unknown>, toolCallId: string, invocation?: ToolExecutionInvocation): Promise<import('./types.js').ToolExecutionResult>;
|
|
327
312
|
private emitPreparedToolCallEvent;
|
|
328
313
|
private replayExistingDirectToolExecution;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-manager.d.ts","sourceRoot":"","sources":["../../src/tools/tool-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACH,OAAO,EACP,oBAAoB,EACpB,wBAAwB,EACxB,IAAI,EACJ,0BAA0B,EAC1B,mBAAmB,EACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACR,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACzB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACR,eAAe,EACf,gBAAgB,EAChB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"tool-manager.d.ts","sourceRoot":"","sources":["../../src/tools/tool-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACH,OAA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M,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS;IAe5D;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;YACW,oBAAoB;IA4BlC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA0B5B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CASjC"}
|
|
@@ -10,11 +10,9 @@ import { DextoRuntimeError, ErrorScope, ErrorType } from "../errors/index.js";
|
|
|
10
10
|
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
11
11
|
import { convertZodSchemaToJsonSchema } from "../utils/schema.js";
|
|
12
12
|
import { ApprovalStatus, ApprovalType, DenialReason } from "../approval/types.js";
|
|
13
|
-
import {
|
|
14
|
-
DirectoryAccessMetadataSchema,
|
|
15
|
-
ToolApprovalResponseDataSchema
|
|
16
|
-
} from "../approval/schemas.js";
|
|
13
|
+
import { ToolApprovalMetadataSchema, ToolApprovalResponseDataSchema } from "../approval/schemas.js";
|
|
17
14
|
import { matchesToolPolicyPattern, SessionToolPolicy } from "./approval/session-tool-policy.js";
|
|
15
|
+
import { ToolApprovalPolicy } from "./approval/tool-approval-policy.js";
|
|
18
16
|
import { ToolPresentation } from "./presentation/tool-presentation.js";
|
|
19
17
|
import { InstrumentClass } from "../telemetry/decorators.js";
|
|
20
18
|
import {
|
|
@@ -49,6 +47,20 @@ let _ToolManager = class _ToolManager {
|
|
|
49
47
|
this.logger,
|
|
50
48
|
(pattern) => this.normalizeToolPolicyPattern(pattern)
|
|
51
49
|
);
|
|
50
|
+
this.toolApprovalPolicy = new ToolApprovalPolicy({
|
|
51
|
+
getApprovalMode: () => this.approvalMode,
|
|
52
|
+
getLocalTool: (toolName) => this.agentTools.get(toolName),
|
|
53
|
+
isApprovalKeySessionApproved: ({ approvalKey, sessionId }) => this.approvalManager.isApprovalKeySessionApproved(approvalKey, sessionId),
|
|
54
|
+
isToolExplicitlyAllowed: async ({ toolName, sessionId }) => {
|
|
55
|
+
if (sessionId !== void 0 && this.isToolAutoApprovedForSession(sessionId, toolName)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (this.isInAlwaysAllowList(toolName)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return await this.allowedToolsProvider.isToolAllowed(toolName, sessionId);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
52
64
|
this.toolPresentation = new ToolPresentation(
|
|
53
65
|
(toolName) => this.agentTools.get(toolName),
|
|
54
66
|
(toolName, args) => this.validateLocalToolArgs(toolName, args),
|
|
@@ -90,6 +102,7 @@ let _ToolManager = class _ToolManager {
|
|
|
90
102
|
cacheValid = false;
|
|
91
103
|
logger;
|
|
92
104
|
sessionToolPolicy;
|
|
105
|
+
toolApprovalPolicy;
|
|
93
106
|
toolPresentation;
|
|
94
107
|
cleanupHandlers = /* @__PURE__ */ new Set();
|
|
95
108
|
cleanupStarted = false;
|
|
@@ -409,58 +422,7 @@ let _ToolManager = class _ToolManager {
|
|
|
409
422
|
}
|
|
410
423
|
});
|
|
411
424
|
}
|
|
412
|
-
// ====================
|
|
413
|
-
getToolApprovalPatternKeyFn(toolName) {
|
|
414
|
-
const tool = this.agentTools.get(toolName);
|
|
415
|
-
return tool?.approval?.patternKey;
|
|
416
|
-
}
|
|
417
|
-
getToolSuggestApprovalPatternsFn(toolName) {
|
|
418
|
-
const tool = this.agentTools.get(toolName);
|
|
419
|
-
return tool?.approval?.suggestPatterns;
|
|
420
|
-
}
|
|
421
|
-
getToolApprovalOverrideFn(toolName) {
|
|
422
|
-
const tool = this.agentTools.get(toolName);
|
|
423
|
-
return tool?.approval?.override;
|
|
424
|
-
}
|
|
425
|
-
getToolApprovalOnGrantedFn(toolName) {
|
|
426
|
-
const tool = this.agentTools.get(toolName);
|
|
427
|
-
return tool?.approval?.onGranted;
|
|
428
|
-
}
|
|
429
|
-
getToolPatternKey(toolName, args) {
|
|
430
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
431
|
-
return null;
|
|
432
|
-
}
|
|
433
|
-
const getPatternKey = this.getToolApprovalPatternKeyFn(toolName);
|
|
434
|
-
if (!getPatternKey) {
|
|
435
|
-
return null;
|
|
436
|
-
}
|
|
437
|
-
try {
|
|
438
|
-
return getPatternKey(args);
|
|
439
|
-
} catch (error) {
|
|
440
|
-
this.logger.debug(
|
|
441
|
-
`Pattern key generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
442
|
-
);
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
getToolSuggestedPatterns(toolName, args) {
|
|
447
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
448
|
-
return void 0;
|
|
449
|
-
}
|
|
450
|
-
const suggestPatterns = this.getToolSuggestApprovalPatternsFn(toolName);
|
|
451
|
-
if (!suggestPatterns) {
|
|
452
|
-
return void 0;
|
|
453
|
-
}
|
|
454
|
-
try {
|
|
455
|
-
const patterns = suggestPatterns(args);
|
|
456
|
-
return patterns.length > 0 ? patterns : void 0;
|
|
457
|
-
} catch (error) {
|
|
458
|
-
this.logger.debug(
|
|
459
|
-
`Pattern suggestion failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
460
|
-
);
|
|
461
|
-
return void 0;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
425
|
+
// ==================== Approval Helpers ====================
|
|
464
426
|
/**
|
|
465
427
|
* Auto-approve pending tool approval requests for the same tool.
|
|
466
428
|
* Called after a user selects "remember choice" for a tool.
|
|
@@ -481,7 +443,7 @@ let _ToolManager = class _ToolManager {
|
|
|
481
443
|
if (request.metadata.toolName !== toolName) {
|
|
482
444
|
return false;
|
|
483
445
|
}
|
|
484
|
-
return
|
|
446
|
+
return true;
|
|
485
447
|
},
|
|
486
448
|
{ rememberChoice: false }
|
|
487
449
|
// Don't propagate remember choice to auto-approved requests
|
|
@@ -492,18 +454,7 @@ let _ToolManager = class _ToolManager {
|
|
|
492
454
|
);
|
|
493
455
|
}
|
|
494
456
|
}
|
|
495
|
-
|
|
496
|
-
* Auto-approve pending tool approval requests that are now covered by a remembered pattern.
|
|
497
|
-
* Called after a user selects "remember pattern" for a tool.
|
|
498
|
-
*/
|
|
499
|
-
autoApprovePendingPatternRequests(toolName, sessionId) {
|
|
500
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const getPatternKey = this.getToolApprovalPatternKeyFn(toolName);
|
|
504
|
-
if (!getPatternKey) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
457
|
+
autoApprovePendingApprovalKeyRequests(approvalKey, sessionId) {
|
|
507
458
|
const count = this.approvalManager.autoApprovePendingRequests(
|
|
508
459
|
(request) => {
|
|
509
460
|
if (request.type !== ApprovalType.TOOL_APPROVAL) {
|
|
@@ -512,64 +463,16 @@ let _ToolManager = class _ToolManager {
|
|
|
512
463
|
if (request.sessionId !== sessionId) {
|
|
513
464
|
return false;
|
|
514
465
|
}
|
|
515
|
-
|
|
516
|
-
return false;
|
|
517
|
-
}
|
|
518
|
-
if (request.metadata.directoryAccess !== void 0) {
|
|
519
|
-
return false;
|
|
520
|
-
}
|
|
521
|
-
let patternKey;
|
|
522
|
-
try {
|
|
523
|
-
patternKey = getPatternKey(request.metadata.args);
|
|
524
|
-
} catch (error) {
|
|
525
|
-
this.logger.debug(
|
|
526
|
-
`Pattern key generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
527
|
-
);
|
|
528
|
-
return false;
|
|
529
|
-
}
|
|
530
|
-
if (!patternKey) return false;
|
|
531
|
-
return this.approvalManager.matchesPattern(toolName, patternKey, sessionId);
|
|
466
|
+
return request.metadata.approvalKey === approvalKey;
|
|
532
467
|
},
|
|
533
|
-
{
|
|
534
|
-
// Don't propagate pattern choice to auto-approved requests
|
|
468
|
+
{ rememberChoice: false }
|
|
535
469
|
);
|
|
536
470
|
if (count > 0) {
|
|
537
471
|
this.logger.info(
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* Auto-approve pending tool approval requests that are now covered by a remembered directory.
|
|
544
|
-
* Called after a user selects "remember directory" for a directory-access prompt.
|
|
545
|
-
*/
|
|
546
|
-
autoApprovePendingDirectoryRequests(toolName, sessionId) {
|
|
547
|
-
const count = this.approvalManager.autoApprovePendingRequests(
|
|
548
|
-
(request) => {
|
|
549
|
-
if (request.type !== ApprovalType.TOOL_APPROVAL) {
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
|
-
if (request.sessionId !== sessionId) {
|
|
553
|
-
return false;
|
|
554
|
-
}
|
|
555
|
-
if (request.metadata.toolName !== toolName) {
|
|
556
|
-
return false;
|
|
557
|
-
}
|
|
558
|
-
const directoryAccess = request.metadata.directoryAccess;
|
|
559
|
-
if (!directoryAccess) {
|
|
560
|
-
return false;
|
|
472
|
+
"Auto-approved parallel request(s) after approval key was remembered",
|
|
473
|
+
{
|
|
474
|
+
count
|
|
561
475
|
}
|
|
562
|
-
return this.approvalManager.isDirectorySessionApproved(
|
|
563
|
-
directoryAccess.parentDir,
|
|
564
|
-
sessionId
|
|
565
|
-
);
|
|
566
|
-
},
|
|
567
|
-
{ rememberDirectory: false }
|
|
568
|
-
);
|
|
569
|
-
if (count > 0) {
|
|
570
|
-
this.logger.info(
|
|
571
|
-
'Auto-approved parallel request(s) after user selected "remember directory"',
|
|
572
|
-
{ count, toolName }
|
|
573
476
|
);
|
|
574
477
|
}
|
|
575
478
|
}
|
|
@@ -870,89 +773,57 @@ let _ToolManager = class _ToolManager {
|
|
|
870
773
|
...callDescription !== void 0 ? { callDescription } : {},
|
|
871
774
|
...eventMeta !== void 0 ? { meta: eventMeta } : {}
|
|
872
775
|
};
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
input.toolCallId,
|
|
877
|
-
sessionId,
|
|
878
|
-
input.runContext
|
|
879
|
-
);
|
|
880
|
-
if (overrideRequest) {
|
|
881
|
-
if (!overrideRequest.directoryAccess) {
|
|
882
|
-
return {
|
|
883
|
-
kind: "approval-required",
|
|
884
|
-
call,
|
|
885
|
-
onGrantedRequestDetails: overrideRequest.onGrantedRequestDetails,
|
|
886
|
-
requestDetails: overrideRequest.requestDetails
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
const quickResult2 = await this.classifyQuickApprovalRequirement(
|
|
890
|
-
input.toolName,
|
|
891
|
-
validatedArgs,
|
|
776
|
+
const approvalGate = await this.toolApprovalPolicy.resolve({
|
|
777
|
+
args: validatedArgs,
|
|
778
|
+
getContext: () => this.buildToolExecutionContext({
|
|
892
779
|
sessionId,
|
|
893
|
-
overrideRequest.directoryAccess
|
|
894
|
-
);
|
|
895
|
-
if (quickResult2 === "ready") {
|
|
896
|
-
return { kind: "ready", call };
|
|
897
|
-
}
|
|
898
|
-
const displayPreview2 = await this.toolPresentation.preview({
|
|
899
|
-
toolName: input.toolName,
|
|
900
|
-
args: validatedArgs,
|
|
901
780
|
toolCallId: input.toolCallId,
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
onGrantedRequestDetails: overrideRequest.onGrantedRequestDetails,
|
|
910
|
-
requestDetails: {
|
|
911
|
-
...overrideRequest.requestDetails,
|
|
912
|
-
metadata: {
|
|
913
|
-
...overrideRequest.requestDetails.metadata,
|
|
914
|
-
presentationSnapshot,
|
|
915
|
-
...callDescription !== void 0 ? { description: callDescription } : {},
|
|
916
|
-
...displayPreview2 !== void 0 ? { displayPreview: displayPreview2 } : {},
|
|
917
|
-
...suggestedPatterns2 !== void 0 ? { suggestedPatterns: suggestedPatterns2 } : {}
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
const quickResult = await this.classifyQuickApprovalRequirement(
|
|
923
|
-
input.toolName,
|
|
924
|
-
validatedArgs,
|
|
925
|
-
sessionId
|
|
926
|
-
);
|
|
927
|
-
if (quickResult === "ready") {
|
|
781
|
+
runContext: input.runContext
|
|
782
|
+
}),
|
|
783
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
784
|
+
source,
|
|
785
|
+
toolName: input.toolName
|
|
786
|
+
});
|
|
787
|
+
if (approvalGate.kind === "ready") {
|
|
928
788
|
return { kind: "ready", call };
|
|
929
789
|
}
|
|
930
|
-
|
|
931
|
-
|
|
790
|
+
return await this.prepareApprovalRequiredToolCall({
|
|
791
|
+
approvalGate,
|
|
932
792
|
args: validatedArgs,
|
|
933
|
-
|
|
793
|
+
call,
|
|
794
|
+
...callDescription !== void 0 ? { callDescription } : {},
|
|
795
|
+
...input.runContext !== void 0 ? { runContext: input.runContext } : {},
|
|
934
796
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
935
|
-
|
|
797
|
+
toolCallId: input.toolCallId,
|
|
798
|
+
toolName: input.toolName
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
async prepareApprovalRequiredToolCall(input) {
|
|
802
|
+
const displayPreview = await this.toolPresentation.preview({
|
|
803
|
+
args: input.args,
|
|
804
|
+
...input.runContext !== void 0 ? { runContext: input.runContext } : {},
|
|
805
|
+
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
806
|
+
toolCallId: input.toolCallId,
|
|
807
|
+
toolName: input.toolName
|
|
936
808
|
});
|
|
937
|
-
const suggestedPatterns = this.getToolSuggestedPatterns(input.toolName, validatedArgs);
|
|
938
809
|
const hostRuntime = input.runContext?.hostRuntime;
|
|
939
810
|
const requestDetails = {
|
|
940
811
|
type: ApprovalType.TOOL_APPROVAL,
|
|
941
|
-
...sessionId !== void 0 ? { sessionId } : {},
|
|
812
|
+
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
942
813
|
...hostRuntime !== void 0 ? { hostRuntime } : {},
|
|
943
814
|
metadata: {
|
|
944
815
|
toolName: input.toolName,
|
|
945
|
-
|
|
816
|
+
...input.approvalGate.approvalKey !== void 0 ? { approvalKey: input.approvalGate.approvalKey } : {},
|
|
817
|
+
presentationSnapshot: input.call.presentationSnapshot,
|
|
946
818
|
toolCallId: input.toolCallId,
|
|
947
|
-
args:
|
|
948
|
-
...callDescription !== void 0 ? { description: callDescription } : {},
|
|
949
|
-
...displayPreview !== void 0 ? { displayPreview } : {}
|
|
950
|
-
...suggestedPatterns !== void 0 ? { suggestedPatterns } : {}
|
|
819
|
+
args: input.args,
|
|
820
|
+
...input.callDescription !== void 0 ? { description: input.callDescription } : {},
|
|
821
|
+
...displayPreview !== void 0 ? { displayPreview } : {}
|
|
951
822
|
}
|
|
952
823
|
};
|
|
953
824
|
return {
|
|
954
825
|
kind: "approval-required",
|
|
955
|
-
call,
|
|
826
|
+
call: input.call,
|
|
956
827
|
onGrantedRequestDetails: requestDetails,
|
|
957
828
|
requestDetails
|
|
958
829
|
};
|
|
@@ -966,7 +837,7 @@ let _ToolManager = class _ToolManager {
|
|
|
966
837
|
this.assertRecordedApprovalMatchesPreparedCall(prepared, request);
|
|
967
838
|
return { prepared, request };
|
|
968
839
|
}
|
|
969
|
-
async applyApprovalDecision(recorded, decision
|
|
840
|
+
async applyApprovalDecision(recorded, decision) {
|
|
970
841
|
if (decision.approvalId !== recorded.request.approvalId) {
|
|
971
842
|
throw ToolError.executionFailed(
|
|
972
843
|
recorded.prepared.call.toolName,
|
|
@@ -989,7 +860,7 @@ let _ToolManager = class _ToolManager {
|
|
|
989
860
|
response: record.response
|
|
990
861
|
};
|
|
991
862
|
}
|
|
992
|
-
await this.applyApprovalGrantedEffects(recorded.prepared, record.response
|
|
863
|
+
await this.applyApprovalGrantedEffects(recorded.prepared, record.response);
|
|
993
864
|
return {
|
|
994
865
|
kind: "ready",
|
|
995
866
|
call: {
|
|
@@ -1028,28 +899,6 @@ let _ToolManager = class _ToolManager {
|
|
|
1028
899
|
assertOnGrantedRequestMatchesPreparedCall(prepared) {
|
|
1029
900
|
const approvalDetails = prepared.requestDetails;
|
|
1030
901
|
const grantedDetails = prepared.onGrantedRequestDetails;
|
|
1031
|
-
const directoryAccess = approvalDetails.type === ApprovalType.TOOL_APPROVAL && "directoryAccess" in approvalDetails.metadata ? DirectoryAccessMetadataSchema.parse(approvalDetails.metadata.directoryAccess) : void 0;
|
|
1032
|
-
if (directoryAccess !== void 0) {
|
|
1033
|
-
const expected = {
|
|
1034
|
-
type: ApprovalType.DIRECTORY_ACCESS,
|
|
1035
|
-
sessionId: approvalDetails.sessionId,
|
|
1036
|
-
hostRuntime: approvalDetails.hostRuntime,
|
|
1037
|
-
metadata: directoryAccess
|
|
1038
|
-
};
|
|
1039
|
-
const actual = {
|
|
1040
|
-
type: grantedDetails.type,
|
|
1041
|
-
sessionId: grantedDetails.sessionId,
|
|
1042
|
-
hostRuntime: grantedDetails.hostRuntime,
|
|
1043
|
-
metadata: grantedDetails.metadata
|
|
1044
|
-
};
|
|
1045
|
-
if (!isDeepStrictEqual(actual, expected)) {
|
|
1046
|
-
throw ToolError.executionFailed(
|
|
1047
|
-
prepared.call.toolName,
|
|
1048
|
-
"Approval granted-effects request does not match the prepared tool call"
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
902
|
if (!isDeepStrictEqual(grantedDetails, approvalDetails)) {
|
|
1054
903
|
throw ToolError.executionFailed(
|
|
1055
904
|
prepared.call.toolName,
|
|
@@ -1057,26 +906,30 @@ let _ToolManager = class _ToolManager {
|
|
|
1057
906
|
);
|
|
1058
907
|
}
|
|
1059
908
|
}
|
|
1060
|
-
async applyApprovalGrantedEffects(prepared, response
|
|
1061
|
-
const requestDetails = prepared.onGrantedRequestDetails;
|
|
909
|
+
async applyApprovalGrantedEffects(prepared, response) {
|
|
1062
910
|
const approvalRequestDetails = prepared.requestDetails;
|
|
1063
911
|
const sessionId = approvalRequestDetails.sessionId;
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
912
|
+
if (approvalRequestDetails.type === ApprovalType.TOOL_APPROVAL) {
|
|
913
|
+
const toolMetadata = ToolApprovalMetadataSchema.parse(approvalRequestDetails.metadata);
|
|
914
|
+
const approvalKey = toolMetadata.approvalKey;
|
|
915
|
+
const data = response.data ? ToolApprovalResponseDataSchema.parse(response.data) : void 0;
|
|
916
|
+
if (approvalKey !== void 0) {
|
|
917
|
+
await this.approvalManager.addApprovedKey(
|
|
918
|
+
approvalKey,
|
|
919
|
+
data?.rememberChoice ? "session" : "once",
|
|
920
|
+
sessionId
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
if (!data) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
1074
926
|
await this.handleRememberChoice(
|
|
1075
927
|
prepared.call.toolName,
|
|
1076
928
|
{
|
|
1077
|
-
data
|
|
929
|
+
data,
|
|
1078
930
|
...response.sessionId !== void 0 ? { sessionId: response.sessionId } : {}
|
|
1079
931
|
},
|
|
932
|
+
approvalKey,
|
|
1080
933
|
sessionId
|
|
1081
934
|
);
|
|
1082
935
|
}
|
|
@@ -1132,72 +985,6 @@ let _ToolManager = class _ToolManager {
|
|
|
1132
985
|
}
|
|
1133
986
|
};
|
|
1134
987
|
}
|
|
1135
|
-
async getToolApprovalOverrideRequest(toolName, args, toolCallId, sessionId, runContext) {
|
|
1136
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
1137
|
-
return null;
|
|
1138
|
-
}
|
|
1139
|
-
const getApprovalOverride = this.getToolApprovalOverrideFn(toolName);
|
|
1140
|
-
if (!getApprovalOverride) {
|
|
1141
|
-
return null;
|
|
1142
|
-
}
|
|
1143
|
-
const context = this.buildToolExecutionContext({ sessionId, toolCallId, runContext });
|
|
1144
|
-
const approvalRequest = await getApprovalOverride(args, context);
|
|
1145
|
-
if (!approvalRequest) {
|
|
1146
|
-
return null;
|
|
1147
|
-
}
|
|
1148
|
-
const requestDetails = {
|
|
1149
|
-
...approvalRequest,
|
|
1150
|
-
...sessionId && !approvalRequest.sessionId ? { sessionId } : {},
|
|
1151
|
-
...runContext?.hostRuntime !== void 0 && approvalRequest.hostRuntime === void 0 ? { hostRuntime: runContext.hostRuntime } : {}
|
|
1152
|
-
};
|
|
1153
|
-
if (requestDetails.type !== ApprovalType.DIRECTORY_ACCESS) {
|
|
1154
|
-
return { requestDetails, onGrantedRequestDetails: requestDetails };
|
|
1155
|
-
}
|
|
1156
|
-
const parseResult = DirectoryAccessMetadataSchema.safeParse(requestDetails.metadata);
|
|
1157
|
-
if (!parseResult.success) {
|
|
1158
|
-
throw ToolError.configInvalid(
|
|
1159
|
-
`Tool '${toolName}' returned invalid directory access metadata`
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
const directoryAccess = parseResult.data;
|
|
1163
|
-
return {
|
|
1164
|
-
directoryAccess,
|
|
1165
|
-
onGrantedRequestDetails: requestDetails,
|
|
1166
|
-
requestDetails: {
|
|
1167
|
-
type: ApprovalType.TOOL_APPROVAL,
|
|
1168
|
-
...requestDetails.sessionId !== void 0 ? { sessionId: requestDetails.sessionId } : {},
|
|
1169
|
-
...requestDetails.hostRuntime !== void 0 ? { hostRuntime: requestDetails.hostRuntime } : {},
|
|
1170
|
-
metadata: {
|
|
1171
|
-
toolName,
|
|
1172
|
-
toolCallId,
|
|
1173
|
-
args,
|
|
1174
|
-
directoryAccess
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
async classifyQuickApprovalRequirement(toolName, args, sessionId, directoryAccess) {
|
|
1180
|
-
if (directoryAccess) {
|
|
1181
|
-
return this.approvalMode === "auto-approve" ? "ready" : "approval-required";
|
|
1182
|
-
}
|
|
1183
|
-
if (sessionId && this.isToolAutoApprovedForSession(sessionId, toolName)) {
|
|
1184
|
-
return "ready";
|
|
1185
|
-
}
|
|
1186
|
-
if (this.isInAlwaysAllowList(toolName)) {
|
|
1187
|
-
return "ready";
|
|
1188
|
-
}
|
|
1189
|
-
if (await this.allowedToolsProvider.isToolAllowed(toolName, sessionId)) {
|
|
1190
|
-
return "ready";
|
|
1191
|
-
}
|
|
1192
|
-
const patternKey = this.getToolPatternKey(toolName, args);
|
|
1193
|
-
if (patternKey && this.approvalManager.matchesPattern(toolName, patternKey, sessionId)) {
|
|
1194
|
-
return "ready";
|
|
1195
|
-
}
|
|
1196
|
-
if (this.approvalMode === "auto-approve") {
|
|
1197
|
-
return "ready";
|
|
1198
|
-
}
|
|
1199
|
-
return "approval-required";
|
|
1200
|
-
}
|
|
1201
988
|
async executeTool(toolName, args, toolCallId, invocation) {
|
|
1202
989
|
const { sessionId, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
|
|
1203
990
|
this.logger.debug(`\u{1F527} Tool execution requested: '${toolName}' (toolCallId: ${toolCallId})`);
|
|
@@ -1230,17 +1017,14 @@ let _ToolManager = class _ToolManager {
|
|
|
1230
1017
|
this.resolveDirectApprovalIdentity(invocation, toolCallId)
|
|
1231
1018
|
);
|
|
1232
1019
|
const response = await this.requestApprovalDecision(recorded);
|
|
1233
|
-
applied = await this.applyApprovalDecision(
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
},
|
|
1242
|
-
runContext
|
|
1243
|
-
);
|
|
1020
|
+
applied = await this.applyApprovalDecision(recorded, {
|
|
1021
|
+
approvalId: response.approvalId,
|
|
1022
|
+
status: response.status,
|
|
1023
|
+
...response.reason !== void 0 ? { reason: response.reason } : {},
|
|
1024
|
+
...response.message !== void 0 ? { message: response.message } : {},
|
|
1025
|
+
...response.timeoutMs !== void 0 ? { timeoutMs: response.timeoutMs } : {},
|
|
1026
|
+
...response.data !== void 0 ? { data: response.data } : {}
|
|
1027
|
+
});
|
|
1244
1028
|
} catch (error) {
|
|
1245
1029
|
await this.recordDirectToolExecutionFailure(prepared.call, invocation, error);
|
|
1246
1030
|
throw error;
|
|
@@ -1746,26 +1530,21 @@ let _ToolManager = class _ToolManager {
|
|
|
1746
1530
|
/**
|
|
1747
1531
|
* Handle "remember" actions when user approves a tool.
|
|
1748
1532
|
*/
|
|
1749
|
-
async handleRememberChoice(toolName, response, sessionId) {
|
|
1533
|
+
async handleRememberChoice(toolName, response, approvalKey, sessionId) {
|
|
1750
1534
|
const data = response.data;
|
|
1751
1535
|
if (!data) return;
|
|
1752
1536
|
const rememberChoice = data.rememberChoice;
|
|
1753
|
-
const rememberPattern = data.rememberPattern;
|
|
1754
|
-
const rememberDirectory = data.rememberDirectory;
|
|
1755
1537
|
if (rememberChoice) {
|
|
1756
1538
|
const allowSessionId = sessionId ?? response.sessionId;
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
} else if (rememberDirectory) {
|
|
1767
|
-
const allowSessionId = sessionId ?? response.sessionId;
|
|
1768
|
-
this.autoApprovePendingDirectoryRequests(toolName, allowSessionId);
|
|
1539
|
+
if (approvalKey !== void 0) {
|
|
1540
|
+
this.autoApprovePendingApprovalKeyRequests(approvalKey, allowSessionId);
|
|
1541
|
+
} else {
|
|
1542
|
+
await this.allowedToolsProvider.allowTool(toolName, allowSessionId);
|
|
1543
|
+
this.logger.info(
|
|
1544
|
+
`Tool '${toolName}' added to allowed tools for session '${allowSessionId ?? "global"}' (remember choice selected)`
|
|
1545
|
+
);
|
|
1546
|
+
this.autoApprovePendingToolRequests(toolName, allowSessionId);
|
|
1547
|
+
}
|
|
1769
1548
|
}
|
|
1770
1549
|
}
|
|
1771
1550
|
/**
|