import type { RpcClient, RpcResponse } from "./rpc"; export type RpcSender = Pick; export type PromptOptions = { digest?: () => string; clearDigest?: () => void; }; export function sendPrompt( rpc: RpcSender, text: string, options: PromptOptions = {}, ): Promise { const digest = options.digest?.() ?? ""; if (!digest) return rpc.send({ type: "prompt", message: text }); options.clearDigest?.(); return rpc.send({ type: "prompt", message: `${digest}\n\nUser prompt:\n${text}`, }); } export function runSlashCommand( rpc: RpcSender, command: string, args = "", ): Promise { const suffix = args.trim() ? ` ${args.trim()}` : ""; return sendPrompt(rpc, `/${command}${suffix}`); } export function runBash( rpc: RpcSender, command: string, excludeFromContext: boolean, ): Promise { return rpc.send({ type: "bash", command, excludeFromContext }); } export function cycleModel(rpc: RpcSender): Promise { return rpc.send({ type: "cycle_model" }); } export function cycleThinking(rpc: RpcSender): Promise { return rpc.send({ type: "cycle_thinking_level" }); } export function compactSession(rpc: RpcSender): Promise { return rpc.send({ type: "compact" }); } export function abortCurrent(rpc: RpcSender): Promise { return rpc.send({ type: "abort" }); }