























@@ -1,5 +1,8 @@
11import { afterEach, describe, expect, it, vi } from "vitest";
2-import { wrapToolWithBeforeToolCallHook } from "../agents/pi-tools.before-tool-call.js";
2+import {
3+type HookContext,
4+wrapToolWithBeforeToolCallHook,
5+} from "../agents/pi-tools.before-tool-call.js";
36import type { AnyAgentTool } from "../agents/tools/common.js";
47import {
58initializeGlobalHookRunner,
@@ -277,28 +280,41 @@ describe("plugin tools MCP server", () => {
277280const execute = vi.fn().mockResolvedValue({
278281content: "Stored.",
279282});
283+const originalContext = {
284+agentId: "agent-with-plugins",
285+sessionKey: "session-with-plugins",
286+} satisfies HookContext;
280287initializeGlobalHookRunner(
281288createMockPluginRegistry([
282289{
283290hookName: "before_tool_call",
284-handler: async () => ({
285-requireApproval: {
286-pluginId: "test-plugin",
287-title: "Approval required",
288-description: "Approval required",
289- onResolution,
290-},
291-}),
291+handler: async (_event, ctx) => {
292+const hookContext = ctx as HookContext | undefined;
293+if (hookContext?.sessionKey !== originalContext.sessionKey) {
294+return undefined;
295+}
296+return {
297+requireApproval: {
298+pluginId: "test-plugin",
299+title: "Approval required",
300+description: "Approval required",
301+ onResolution,
302+},
303+};
304+},
292305},
293306]),
294307);
295308callGatewayTool.mockRejectedValue(new Error("gateway unavailable"));
296-const tool = wrapToolWithBeforeToolCallHook({
297-name: "memory_store",
298-description: "Store memory",
299-parameters: { type: "object", properties: {} },
300- execute,
301-} as unknown as AnyAgentTool);
309+const tool = wrapToolWithBeforeToolCallHook(
310+{
311+name: "memory_store",
312+description: "Store memory",
313+parameters: { type: "object", properties: {} },
314+ execute,
315+} as unknown as AnyAgentTool,
316+originalContext,
317+);
302318303319const handlers = createPluginToolsMcpHandlers([tool]);
304320const result = await handlers.callTool({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。