import type { Static, TSchema } from "@earendil-works/pi-ai"; import type { ExtensionAPI, ExtensionContext, ToolDefinition, ToolRenderResultOptions as PiToolRenderResultOptions, } from "@earendil-works/pi-coding-agent"; import type { Component } from "@earendil-works/pi-tui"; import type { PiToolShell } from "../types.ts"; /** Receives partial Pi tool shells emitted while a long-running tool executes. */ export type ToolUpdate = (result: PiToolShell) => void | Promise; /** Pi execution context used by tools that need interactive confirmation. */ export type ToolExecutionContext = Partial>; /** Executes a Gemini tool with typed params and optional streaming updates. */ export type ToolExecute = ( toolCallId: string, params: TParams, signal: AbortSignal, onUpdate?: ToolUpdate, ctx?: ToolExecutionContext, ) => Promise; type OfficialToolRenderCall = NonNullable["renderCall"]>; type OfficialToolRenderContext = Parameters[2] & { args: TParams; }; /** Pi renderer state for a tool result or partial progress update. */ export type ToolRenderResultOptions = PiToolRenderResultOptions; /** Minimal render context consumed by this extension's custom renderers. */ export type ToolRenderContext = Partial> & Pick, "expanded" | "isPartial">; /** Renders the tool call title row for Pi's interactive tool UI. */ export type ToolRenderCall = ( args: TParams, theme: unknown, context: ToolRenderContext, ) => Component; /** Renders tool output for Pi's interactive collapsed/expanded tool UI. */ export type ToolRenderResult = ( result: PiToolShell, options: ToolRenderResultOptions, theme: unknown, context: ToolRenderContext, ) => Component; /** Public Gemini-prefixed Pi tool definition used by registration. */ export type GeminiTool = Omit< ToolDefinition, "name" | "execute" | "renderCall" | "renderResult" > & { name: `gemini_${string}`; execute: ToolExecute>; renderCall?: ToolRenderCall>; renderResult?: ToolRenderResult; }; type AnyGeminiTool = Omit, "execute" | "renderCall"> & { // oxlint-disable-next-line typescript/no-explicit-any execute: ToolExecute; // oxlint-disable-next-line typescript/no-explicit-any renderCall?: ToolRenderCall; }; /** Subset of the Pi extension API required to register Gemini tools. */ export interface PiToolRegistrar { registerTool(tool: AnyGeminiTool): ReturnType; } /** Preserves TypeBox parameter inference for standalone Gemini tool objects. */ export function defineGeminiTool( tool: GeminiTool, ): GeminiTool { return tool; }