import type { KeyboardEvent } from "react"; import type { CommandContext, SlashCommand } from "../commands/types.js"; /** * Context the composer supplies for command execution and visibility. The * composer owns the UI affordances (notice/openHelp/clearView/confirm), so they * are NOT part of this slice — the hook closes over them via `handlers`. */ export type SlashCommandContext = Pick; /** * UI affordances the composer supplies. `confirm` differs from the registry- * facing {@link CommandContext.confirm} (which takes no args): the composer's * confirm receives the command being run so the confirm bar renders from that * exact command's identity. The hook bridges the two in {@link buildContext}. */ export type SlashCommandHandlers = Pick & { confirm: (command: SlashCommand) => Promise; }; export type ConfirmState = { command: SlashCommand; /** Resolve the pending confirm() promise. */ resolve: (confirmed: boolean) => void; } | null; export type UseSlashCommandsOptions = { commands: readonly SlashCommand[]; context: SlashCommandContext | undefined; handlers: SlashCommandHandlers; /** The current composer draft. */ value: string; /** Replace the composer draft (autocomplete writes through this). */ setValue: (value: string) => void; }; export type UseSlashCommandsResult = { /** Whether the palette is open (a command token is being typed). */ open: boolean; /** * Whether the draft is a slash-command attempt (matches a registered command) * — true even after Escape dismisses the popover. The composer blocks its send * path while this holds so a command can't be delivered to the agent as chat. */ isCommandDraft: boolean; /** Commands shown for the current token + context, in display order. */ items: SlashCommand[]; /** Index into `items` of the highlighted row. */ highlight: number; setHighlight: (index: number) => void; /** The matched command once the name is closed by a space (arg-hint mode). */ activeCommand: SlashCommand | null; /** The arg hint string for the active command (footer), or "". */ activeArgHint: string; /** * Key handler for the textarea. Returns true when it consumed the event * (the composer must then NOT run its send path). Only consumes while open. */ onKeyDown: (event: KeyboardEvent) => boolean; /** Run the highlighted command (or the active command in arg-hint mode). */ runHighlighted: () => Promise; /** * Run the command at an explicitly chosen index (a pointer click on a row). * Bypasses the exact-match token heuristic that runHighlighted uses for * keyboard Enter, so an explicit click always runs the clicked command. */ runAt: (index: number) => Promise; /** Autocomplete the highlighted command name + a trailing space. */ autocompleteHighlighted: () => void; }; export declare function useSlashCommands(options: UseSlashCommandsOptions): UseSlashCommandsResult;