export interface TextContent { type: "text"; text: string; } /** Result a tool returns to the model; isError marks a failure result. */ export interface PiToolResult { content: TextContent[]; details: TDetails; isError?: boolean; } /** Streams partial progress for a running tool call. */ export type PiToolUpdateCallback = (partial: PiToolResult) => void; export interface PiUIContext { notify?(message: string, type?: "info" | "warning" | "error"): void; } /** The slice of pi's extension context the adapter reads. */ export interface PiContext { cwd: string; ui?: PiUIContext; sessionManager?: { getSessionId(): string }; } /** Plain JSON-schema parameters; structurally what pi's TypeBox schemas are. */ export interface PiParameterSchema { type: "object"; properties: Record; required?: string[]; } export interface PiToolDefinition { name: string; label: string; description: string; parameters: PiParameterSchema; execute( toolCallId: string, params: TParams, signal: AbortSignal | undefined, onUpdate: PiToolUpdateCallback | undefined, context: PiContext, ): Promise>; } /** Fired before a tool executes; a handler can block it. */ export interface PiToolCallEvent { type: "tool_call"; toolCallId: string; toolName: string; input: unknown; } export interface PiToolCallResult { block?: boolean; reason?: string; } export type PiToolCallHandler = ( event: PiToolCallEvent, context: PiContext, ) => PiToolCallResult | undefined | Promise; export interface PiCommandOptions { description?: string; handler(args: string, context: PiContext): Promise | void; } /** Fired once as the pi session tears down; the adapter aborts in-flight waiters here. */ export interface PiSessionEvent { type: "session_start" | "session_shutdown" | "session_switch" | "session_fork"; } export type PiSessionHandler = (event: PiSessionEvent) => void | Promise; /** * How an injected message reaches the live turn: "followUp" queues it for after * the current turn ends, "steer" interrupts the running turn. cueloop wakes with * "followUp" so a returning message never cuts off work the human is mid-request. */ export interface PiSendMessageOptions { deliverAs?: "followUp" | "steer"; expandPromptTemplates?: boolean; } export interface PiExtensionAPI { registerTool(tool: PiToolDefinition): void; registerCommand(name: string, options: PiCommandOptions): void; on(event: "tool_call", handler: PiToolCallHandler): void; on( event: "session_start" | "session_shutdown" | "session_switch" | "session_fork", handler: (event: PiSessionEvent, context: PiContext) => void | Promise, ): void; sendUserMessage(content: string, options?: PiSendMessageOptions): void; }