import type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode } from "@earendil-works/pi-agent-core";
import type { Component } from "@earendil-works/pi-tui";
import type { Static, TSchema } from "typebox";
import type { Theme } from "../../modes/interactive/theme/theme.ts";
import type { SourceInfo } from "../source-info.ts";
import type { ExtensionContext } from "./context-types.ts";
/** Rendering options for tool results */
export interface ToolRenderResultOptions {
    /** Whether the result view is expanded */
    expanded: boolean;
    /** Whether this is a partial/streaming result */
    isPartial: boolean;
}
/** Context passed to tool renderers. */
export interface ToolRenderContext<TState = unknown, TArgs = unknown> {
    /** Current tool call arguments. Shared across call/result renders for the same tool call. */
    args: TArgs;
    /** Unique id for this tool execution. Stable across call/result renders for the same tool call. */
    toolCallId: string;
    /** Invalidate just this tool execution component for redraw. */
    invalidate: () => void;
    /** Previously returned component for this render slot, if any. */
    lastComponent: Component | undefined;
    /** Shared renderer state for this tool row. Initialized by tool-execution.ts. */
    state: TState;
    /** Working directory for this tool execution. */
    cwd: string;
    /** Whether the tool execution has started. */
    executionStarted: boolean;
    /** Whether the tool call arguments are complete. */
    argsComplete: boolean;
    /** Whether the tool result is partial/streaming. */
    isPartial: boolean;
    /** Whether the result view is expanded. */
    expanded: boolean;
    /** Whether inline images are currently shown in the TUI. */
    showImages: boolean;
    /** Whether the current result is an error. */
    isError: boolean;
}
type ToolRenderCall<TParams extends TSchema, TState> = {
    bivarianceHack(args: Static<TParams>, theme: Theme, context: ToolRenderContext<TState, Static<TParams>>): Component;
}["bivarianceHack"];
type ToolRenderResult<TParams extends TSchema, TDetails, TState> = {
    bivarianceHack(result: AgentToolResult<TDetails>, options: ToolRenderResultOptions, theme: Theme, context: ToolRenderContext<TState, Static<TParams>>): Component;
}["bivarianceHack"];
/**
 * Tool definition for registerTool().
 */
export interface ToolDefinition<TParams extends TSchema = TSchema, TDetails = unknown, TState = unknown> {
    /** Tool name (used in LLM tool calls) */
    name: string;
    /** Human-readable label for UI */
    label: string;
    /** Description for LLM */
    description: string;
    /** Optional one-line snippet for the Available tools section in the default system prompt. Custom tools are omitted from that section when this is not provided. */
    promptSnippet?: string;
    /** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
    promptGuidelines?: string[];
    /** Parameter schema (TypeBox) */
    parameters: TParams;
    /** Optional per-tool character cap for model-visible result persistence. Use Infinity to opt out for self-bounded tools. */
    maxResultSizeChars?: number;
    /** Marks a terminating tool created by createStructuredOutputTool() so print mode can emit custom-named final JSON without treating every terminating tool as printable. */
    structuredOutput?: true;
    /** Controls whether ToolExecutionComponent renders the standard colored shell or the tool renders its own framing. */
    renderShell?: "default" | "self";
    /** Optional compatibility shim to prepare raw tool call arguments before schema validation. Must return an object conforming to TParams. */
    prepareArguments?: (args: unknown) => Static<TParams>;
    /**
     * Per-tool execution mode override.
     * - "sequential": this tool must execute one at a time with other tool calls.
     * - "parallel": this tool can execute concurrently with other tool calls.
     *
     * If omitted, the default execution mode applies.
     */
    executionMode?: ToolExecutionMode;
    /** Execute the tool. */
    execute(toolCallId: string, params: Static<TParams>, signal: AbortSignal | undefined, onUpdate: AgentToolUpdateCallback<TDetails> | undefined, ctx: ExtensionContext): Promise<AgentToolResult<TDetails>>;
    /** Custom rendering for tool call display */
    renderCall?: ToolRenderCall<TParams, TState>;
    /** Custom rendering for tool result display */
    renderResult?: ToolRenderResult<TParams, TDetails, TState>;
}
type AnyToolDefinition = ToolDefinition<TSchema, unknown, unknown>;
/**
 * Preserve parameter inference for standalone tool definitions.
 *
 * Use this when assigning a tool to a variable or passing it through arrays such
 * as `customTools`, where contextual typing would otherwise widen params to
 * `unknown`.
 */
export declare function defineTool<TParams extends TSchema, TDetails = unknown, TState = unknown>(tool: ToolDefinition<TParams, TDetails, TState>): ToolDefinition<TParams, TDetails, TState> & AnyToolDefinition;
/** Tool info with name, description, parameter schema, and source metadata */
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters" | "promptGuidelines"> & {
    sourceInfo: SourceInfo;
};
export {};
//# sourceMappingURL=tool-types.d.ts.map