From 50ba466bbc319e94f1e314f278bb421bcda48cca Mon Sep 17 00:00:00 2001 From: fuushyn Date: Tue, 27 Jan 2026 01:47:40 +0530 Subject: [PATCH] fix: correct types for before_tool_call hook wrapper - Remove toolCallId from hook context/event (not in type definitions) - Return proper AgentToolResult structure when blocking - Import AgentToolResult from pi-agent-core Co-Authored-By: Claude Opus 4.5 --- src/agents/pi-tools.before-call-hook.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/agents/pi-tools.before-call-hook.ts b/src/agents/pi-tools.before-call-hook.ts index 73cb620a4..9834da294 100644 --- a/src/agents/pi-tools.before-call-hook.ts +++ b/src/agents/pi-tools.before-call-hook.ts @@ -7,6 +7,7 @@ * - Block tool execution with a custom reason */ +import type { AgentToolResult } from "@mariozechner/pi-agent-core"; import type { HookRunner } from "../plugins/hooks.js"; import type { PluginHookToolContext } from "../plugins/hooks.js"; import type { AnyAgentTool } from "./pi-tools.types.js"; @@ -43,19 +44,17 @@ export function wrapToolWithBeforeCallHook( execute: async (toolCallId, params, signal, onUpdate) => { const toolName = tool.name; - // Build hook context + // Build hook context (matches PluginHookToolContext type) const hookCtx: PluginHookToolContext = { agentId, sessionKey, toolName, - toolCallId, }; // Run the before_tool_call hook const hookResult = await hookRunner.runBeforeToolCall( { toolName, - toolCallId, params: params as Record, }, hookCtx, @@ -64,11 +63,12 @@ export function wrapToolWithBeforeCallHook( // Check if the hook blocked the tool call if (hookResult?.block) { const reason = hookResult.blockReason ?? "Tool call blocked by policy"; - // Return a structured error that the agent can understand - return { - type: "text" as const, - text: `Error: ${reason}`, + // Return a properly structured AgentToolResult error + const blockedResult: AgentToolResult = { + content: [{ type: "text", text: `Error: ${reason}` }], + details: { blocked: true, reason }, }; + return blockedResult; } // Use modified params if provided, otherwise use original