/** * [WHO]: RpcCommand, RpcResponse, RpcSessionState, RpcSlashCommand types * [FROM]: Depends on agent-core, ai, core/runtime, core/platform/exec/bash-executor, core/session/compaction * [TO]: Consumed by modes/index.ts, modes/rpc/rpc-client.ts, modes/rpc/rpc-mode.ts * [HERE]: modes/rpc/rpc-types.ts - RPC protocol type definitions */ import type { AgentLoopFramework, AgentMessage, AgentRunResult, ThinkingLevel } from "@catui/agent-core"; import type { ImageContent, Model } from "@catui/ai/types"; import type { SessionStats } from "../../core/runtime/agent-session.js"; import type { BashResult } from "../../core/platform/exec/bash-executor.js"; import type { CompactionResult } from "../../core/session/compaction/index.js"; import type { SlashCommandCategory } from "../../core/slash-commands.js"; type AgentLoopFrameworkInput = AgentLoopFramework | "high-intelligence" | "low-intelligence" | "structured-adaptive"; export type RpcCommand = { id?: string; type: "prompt"; message: string; images?: ImageContent[]; streamingBehavior?: "steer" | "followUp"; } | { id?: string; type: "steer"; message: string; images?: ImageContent[]; } | { id?: string; type: "follow_up"; message: string; images?: ImageContent[]; } | { id?: string; type: "abort"; } | { id?: string; type: "new_session"; parentSession?: string; } | { id?: string; type: "get_state"; } | { id?: string; type: "set_model"; provider: string; modelId: string; } | { id?: string; type: "cycle_model"; } | { id?: string; type: "get_available_models"; } | { id?: string; type: "set_thinking_level"; level: ThinkingLevel; } | { id?: string; type: "cycle_thinking_level"; } | { id?: string; type: "set_agent_loop_framework"; framework: AgentLoopFrameworkInput | null; } | { id?: string; type: "set_loop_policy"; policy: RpcLoopPolicyOptions; } | { id?: string; type: "set_steering_mode"; mode: "all" | "one-at-a-time"; } | { id?: string; type: "set_follow_up_mode"; mode: "all" | "one-at-a-time"; } | { id?: string; type: "compact"; customInstructions?: string; } | { id?: string; type: "set_auto_compaction"; enabled: boolean; } | { id?: string; type: "set_auto_retry"; enabled: boolean; } | { id?: string; type: "abort_retry"; } | { id?: string; type: "bash"; command: string; } | { id?: string; type: "abort_bash"; } | { id?: string; type: "get_session_stats"; } | { id?: string; type: "export_html"; outputPath?: string; } | { id?: string; type: "switch_session"; sessionPath: string; } | { id?: string; type: "fork"; entryId: string; } | { id?: string; type: "get_fork_messages"; } | { id?: string; type: "get_last_assistant_text"; } | { id?: string; type: "set_session_name"; name: string; } | { id?: string; type: "get_messages"; } | { id?: string; type: "get_commands"; }; /** A command available for invocation via prompt */ export interface RpcSlashCommand { /** Command name (without leading slash) */ name: string; /** Human-readable description */ description?: string; /** What kind of command this is */ source: "extension" | "prompt" | "skill"; /** Human-facing command category for grouping and filtering */ category?: SlashCommandCategory; /** Where the command was loaded from (undefined for extensions) */ location?: "user" | "project" | "path"; /** File path to the command source */ path?: string; } export interface RpcSessionState { model?: Model; thinkingLevel: ThinkingLevel; agentLoopFramework: AgentLoopFramework; isStreaming: boolean; isCompacting: boolean; steeringMode: "all" | "one-at-a-time"; followUpMode: "all" | "one-at-a-time"; lastResult?: AgentRunResult; sessionFile?: string; sessionId: string; sessionName?: string; autoCompactionEnabled: boolean; messageCount: number; pendingMessageCount: number; } export interface RpcOutputTokenBudget { targetTokens: number; thresholdPct?: number; maxContinuations?: number; } export interface RpcLoopPolicyOptions { maxToolResultBatchSizeChars?: number | null; maxModelErrorRecoveryAttempts?: number | null; maxOutputTokenRecoveryAttempts?: number | null; outputTokenBudget?: RpcOutputTokenBudget | null; maxStopHookContinuations?: number | null; maxToolConcurrency?: number | null; maxTurnsPerPrompt?: number | null; maxToolCallsPerPrompt?: number | null; } export type RpcResponse = { id?: string; type: "response"; command: "prompt"; success: true; } | { id?: string; type: "response"; command: "steer"; success: true; } | { id?: string; type: "response"; command: "follow_up"; success: true; } | { id?: string; type: "response"; command: "abort"; success: true; } | { id?: string; type: "response"; command: "new_session"; success: true; data: { cancelled: boolean; }; } | { id?: string; type: "response"; command: "get_state"; success: true; data: RpcSessionState; } | { id?: string; type: "response"; command: "set_model"; success: true; data: Model; } | { id?: string; type: "response"; command: "cycle_model"; success: true; data: { model: Model; thinkingLevel: ThinkingLevel; isScoped: boolean; } | null; } | { id?: string; type: "response"; command: "get_available_models"; success: true; data: { models: Model[]; }; } | { id?: string; type: "response"; command: "set_thinking_level"; success: true; } | { id?: string; type: "response"; command: "cycle_thinking_level"; success: true; data: { level: ThinkingLevel; } | null; } | { id?: string; type: "response"; command: "set_agent_loop_framework"; success: true; } | { id?: string; type: "response"; command: "set_steering_mode"; success: true; } | { id?: string; type: "response"; command: "set_follow_up_mode"; success: true; } | { id?: string; type: "response"; command: "compact"; success: true; data: CompactionResult; } | { id?: string; type: "response"; command: "set_auto_compaction"; success: true; } | { id?: string; type: "response"; command: "set_auto_retry"; success: true; } | { id?: string; type: "response"; command: "abort_retry"; success: true; } | { id?: string; type: "response"; command: "bash"; success: true; data: BashResult; } | { id?: string; type: "response"; command: "abort_bash"; success: true; } | { id?: string; type: "response"; command: "get_session_stats"; success: true; data: SessionStats; } | { id?: string; type: "response"; command: "export_html"; success: true; data: { path: string; }; } | { id?: string; type: "response"; command: "switch_session"; success: true; data: { cancelled: boolean; }; } | { id?: string; type: "response"; command: "fork"; success: true; data: { text: string; cancelled: boolean; }; } | { id?: string; type: "response"; command: "get_fork_messages"; success: true; data: { messages: Array<{ entryId: string; text: string; }>; }; } | { id?: string; type: "response"; command: "get_last_assistant_text"; success: true; data: { text: string | null; }; } | { id?: string; type: "response"; command: "set_session_name"; success: true; } | { id?: string; type: "response"; command: "get_messages"; success: true; data: { messages: AgentMessage[]; }; } | { id?: string; type: "response"; command: "get_commands"; success: true; data: { commands: RpcSlashCommand[]; }; } | { id?: string; type: "response"; command: string; success: false; error: string; }; /** Emitted when an extension needs user input */ export type RpcExtensionUIRequest = { type: "extension_ui_request"; id: string; method: "select"; title: string; options: string[]; timeout?: number; } | { type: "extension_ui_request"; id: string; method: "confirm"; title: string; message: string; timeout?: number; } | { type: "extension_ui_request"; id: string; method: "input"; title: string; placeholder?: string; timeout?: number; } | { type: "extension_ui_request"; id: string; method: "editor"; title: string; prefill?: string; } | { type: "extension_ui_request"; id: string; method: "openExternalEditor"; title?: string; filePath: string; } | { type: "extension_ui_request"; id: string; method: "notify"; message: string; notifyType?: "info" | "warning" | "error"; } | { type: "extension_ui_request"; id: string; method: "setStatus"; statusKey: string; statusText: string | undefined; } | { type: "extension_ui_request"; id: string; method: "setWidget"; widgetKey: string; widgetLines: string[] | undefined; widgetPlacement?: "aboveEditor" | "belowEditor"; } | { type: "extension_ui_request"; id: string; method: "setTitle"; title: string; } | { type: "extension_ui_request"; id: string; method: "set_editor_text"; text: string; }; /** Response to an extension UI request */ export type RpcExtensionUIResponse = { type: "extension_ui_response"; id: string; value: string; } | { type: "extension_ui_response"; id: string; confirmed: boolean; } | { type: "extension_ui_response"; id: string; cancelled: true; }; export type RpcCommandType = RpcCommand["type"]; export {};