

























@@ -147,6 +147,7 @@ export function hasBeforeToolCallPolicy(): boolean {
147147const log = createSubsystemLogger("agents/tools");
148148const BEFORE_TOOL_CALL_WRAPPED = Symbol("beforeToolCallWrapped");
149149const BEFORE_TOOL_CALL_DIAGNOSTIC_OPTIONS = Symbol("beforeToolCallDiagnosticOptions");
150+const BEFORE_TOOL_CALL_SOURCE_TOOL = Symbol("beforeToolCallSourceTool");
150151const BEFORE_TOOL_CALL_HOOK_FAILURE_REASON =
151152"Tool call blocked because before_tool_call hook failed";
152153const MAX_TRACKED_ADJUSTED_PARAMS = 1024;
@@ -1071,6 +1072,10 @@ export function wrapToolWithBeforeToolCallHook(
10711072value: hookOptions,
10721073enumerable: false,
10731074});
1075+Object.defineProperty(wrappedTool, BEFORE_TOOL_CALL_SOURCE_TOOL, {
1076+value: tool,
1077+enumerable: false,
1078+});
10741079return wrappedTool;
10751080}
10761081@@ -1087,15 +1092,18 @@ export function setBeforeToolCallDiagnosticsEnabled(tool: AnyAgentTool, enabled:
10871092}
10881093}
108910941090-export function setBeforeToolCallApprovalMode(
1095+export function rewrapToolWithBeforeToolCallHook(
10911096tool: AnyAgentTool,
1092-approvalMode: "request" | "report" | undefined,
1093-): void {
1097+ctx?: HookContext,
1098+options: { approvalMode?: "request" | "report"; emitDiagnostics?: boolean } = {},
1099+): AnyAgentTool {
10941100const taggedTool = tool as unknown as Record<symbol, unknown>;
1095-const options = taggedTool[BEFORE_TOOL_CALL_DIAGNOSTIC_OPTIONS];
1096-if (options && typeof options === "object") {
1097-(options as BeforeToolCallWrapperOptions).approvalMode = approvalMode;
1098-}
1101+const source = taggedTool[BEFORE_TOOL_CALL_SOURCE_TOOL];
1102+return wrapToolWithBeforeToolCallHook(
1103+source && typeof source === "object" ? (source as AnyAgentTool) : tool,
1104+ctx,
1105+options,
1106+);
10991107}
1100110811011109export function copyBeforeToolCallHookMarker(source: AnyAgentTool, target: AnyAgentTool): void {
@@ -1106,6 +1114,14 @@ export function copyBeforeToolCallHookMarker(source: AnyAgentTool, target: AnyAg
11061114value: true,
11071115enumerable: true,
11081116});
1117+const taggedSource = source as unknown as Record<symbol, unknown>;
1118+const sourceTool = taggedSource[BEFORE_TOOL_CALL_SOURCE_TOOL];
1119+if (sourceTool && typeof sourceTool === "object") {
1120+Object.defineProperty(target, BEFORE_TOOL_CALL_SOURCE_TOOL, {
1121+value: sourceTool,
1122+enumerable: false,
1123+});
1124+}
11091125}
1110112611111127export function consumeAdjustedParamsForToolCall(toolCallId: string, runId?: string): unknown {
@@ -1117,6 +1133,7 @@ export function consumeAdjustedParamsForToolCall(toolCallId: string, runId?: str
1117113311181134export const testing = {
11191135BEFORE_TOOL_CALL_DIAGNOSTIC_OPTIONS,
1136+BEFORE_TOOL_CALL_SOURCE_TOOL,
11201137BEFORE_TOOL_CALL_WRAPPED,
11211138 buildAdjustedParamsKey,
11221139 adjustedParamsByToolCallId,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。