/** @file Shared Pi command adapter contracts for web commands. */ import type { ExtensionUIDialogOptions } from "@earendil-works/pi-coding-agent"; import type { Static, TSchema } from "typebox"; import type { PiToolShell } from "../types.ts"; export type CommandExecute = ( params: TParams, ctx?: CommandContext, ) => Promise | PiToolShell; /** Subset of ExtensionCommandContext used by web commands. */ export interface CommandContext { signal?: AbortSignal; hasUI?: boolean; ui?: { notify(message: string, type?: "info" | "warning" | "error"): void; select?( title: string, choices: readonly string[], options?: ExtensionUIDialogOptions, ): Promise; confirm?(title: string, message: string, options?: ExtensionUIDialogOptions): Promise; input?( title: string, placeholder?: string, options?: ExtensionUIDialogOptions, ): Promise; }; } export interface RegisteredCommandOptions { description?: string; handler(args: string, ctx: CommandContext): Promise; } export interface WebCommand { name: `web-${string}` | `scrape-${string}`; description: string; parameters: TParameters; parseArgs?: (args: string) => Static; execute: CommandExecute>; } export interface PiCommandRegistrar { registerCommand(name: string, options: RegisteredCommandOptions): void; registerFlag?(name: string, options: { description: string; type: string }): void; } export function defineWebCommand( command: WebCommand, ): WebCommand { return command; }