import { IChatMessage, ISlashCommand } from '../../components/widgets/ChatPane'; /** * A slash command as held in the shell store. Extends the presentational * {@link ISlashCommand} with the handler that runs when it is invoked. */ export interface ISlashCommandConfig extends ISlashCommand { /** Runs when the command is submitted. Receives the whitespace-split args. */ execute: (args: string[]) => void; } /** A reply being written, returned by {@link ChatReplyApi.stream}. */ export interface ChatStream { /** The message id. */ id: string; /** Append text as it arrives. */ append: (chunk: string) => void; /** Finish. `text` replaces the accumulated text when given. */ done: (text?: string) => void; /** Finish as failed, showing `message`. */ fail: (message: string) => void; } /** Helpers handed to a send handler for answering. */ export interface ChatReplyApi { /** Add a complete assistant reply. Returns its id. */ reply: (text: string, options?: { author?: string; }) => string; /** Start a streamed assistant reply, shown as typing until text arrives. */ stream: (options?: { author?: string; }) => ChatStream; } /** * What runs when the user sends a message that is not a slash command. * * Return a promise to have a rejection shown in the transcript as a failed * reply, rather than lost. * * @example * ```ts * chatPanel({ * onSend: async (text, chat) => { * const reply = chat.stream(); * for await (const chunk of llm.stream(text)) reply.append(chunk); * reply.done(); * }, * }); * ``` */ export type ChatSendHandler = (text: string, chat: ChatReplyApi) => void | Promise; interface ChatState { messages: IChatMessage[]; slashCommands: ISlashCommandConfig[]; /** * The app-wide send handler, used by any `ConnectedChatPane` not given its * own `onSend`. Set with `setSendHandler` or `initializeShell({ chat })`. */ sendHandler: ChatSendHandler | null; setSendHandler: (handler: ChatSendHandler | null) => void; setMessages: (messages: IChatMessage[]) => void; /** Append a message. Returns its id. */ addMessage: (message: Omit & { id?: string; }) => string; /** Change a message in place — mark it done, fix its text. */ updateMessage: (id: string, patch: Partial>) => void; /** Append text to a message, for streamed replies. */ appendToMessage: (id: string, chunk: string) => void; clearMessages: () => void; setSlashCommands: (commands: ISlashCommandConfig[]) => void; /** * Add a command, replacing any existing one with the same `command` word. * * Registering is idempotent so that a component registering in an effect is * safe to mount twice — which React does in StrictMode, and again on every * remount. Appending blindly would leave the same command listed two or three * times in the suggestion list. */ registerSlashCommand: (command: ISlashCommandConfig) => void; /** * Remove a command by its `command` word. Unknown words are ignored. * * The counterpart to {@link ChatState.registerSlashCommand}, so a component * that registers on mount can clean up on unmount and stop offering a command * whose handler is gone. */ unregisterSlashCommand: (command: string) => void; } /** * Shell-level store for the chat pane's transcript and slash commands. * Consumed by `ConnectedChatPane`; the presentational `ChatPane` does not read * it. */ export declare const useChatStore: import('zustand').UseBoundStore>; /** The {@link ChatReplyApi} bound to the shell's chat store. */ export declare const chatReplyApi: ChatReplyApi; export type { IChatMessage, ISlashCommand };