Skip to main content

kimi_wire/protocol/
method.rs

1use serde::{Deserialize, Serialize};
2
3use super::content::UserInput;
4
5// ============================================================================
6// Initialize
7// ============================================================================
8
9/// Initialize request parameters.
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
11pub struct InitializeParams {
12    /// Protocol version string (e.g. "1.7").
13    pub protocol_version: String,
14    /// Client identification.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub client: Option<ClientInfo>,
17    /// External tools the client wants to register.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub external_tools: Option<Vec<ExternalTool>>,
20    /// Client capabilities.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub capabilities: Option<ClientCapabilities>,
23    /// Hook subscriptions requested by the client.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub hooks: Option<Vec<WireHookSubscription>>,
26}
27
28/// Client identification info.
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
30pub struct ClientInfo {
31    /// Client name.
32    pub name: String,
33    /// Client version.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub version: Option<String>,
36}
37
38/// Capabilities advertised by the client.
39#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
40pub struct ClientCapabilities {
41    /// Whether the client supports interactive questions.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub supports_question: Option<bool>,
44    /// Whether the client supports plan mode.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub supports_plan_mode: Option<bool>,
47}
48
49/// A hook subscription.
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
51pub struct WireHookSubscription {
52    /// Subscription id.
53    pub id: String,
54    /// Event name to subscribe to.
55    pub event: String,
56    /// Optional regex matcher for event targets.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub matcher: Option<String>,
59    /// Timeout for client response in seconds, default 30.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub timeout: Option<u32>,
62}
63
64/// An external tool definition.
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
66pub struct ExternalTool {
67    /// Tool name.
68    pub name: String,
69    /// Tool description.
70    pub description: String,
71    /// Parameter definition in JSON Schema format.
72    pub parameters: serde_json::Value,
73}
74
75/// Initialize response result.
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
77pub struct InitializeResult {
78    /// Protocol version supported by the server.
79    pub protocol_version: String,
80    /// Server identification.
81    pub server: ServerInfo,
82    /// Available slash commands.
83    pub slash_commands: Vec<SlashCommandInfo>,
84    /// External tools accepted/rejected by the server.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub external_tools: Option<ExternalToolsResult>,
87    /// Server capabilities.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub capabilities: Option<ServerCapabilities>,
90    /// Hook info from the server.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub hooks: Option<HooksInfo>,
93}
94
95/// Server identification info.
96#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
97pub struct ServerInfo {
98    /// Server name.
99    pub name: String,
100    /// Server version.
101    pub version: String,
102}
103
104/// Information about a slash command.
105#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
106pub struct SlashCommandInfo {
107    /// Command name.
108    pub name: String,
109    /// Command description.
110    pub description: String,
111    /// Command aliases.
112    pub aliases: Vec<String>,
113}
114
115/// Result of registering external tools.
116#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
117pub struct ExternalToolsResult {
118    /// Accepted tool names.
119    pub accepted: Vec<String>,
120    /// Rejected tools with reasons.
121    pub rejected: Vec<RejectedExternalTool>,
122}
123
124/// A rejected external tool.
125#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
126pub struct RejectedExternalTool {
127    /// Tool name.
128    pub name: String,
129    /// Rejection reason.
130    pub reason: String,
131}
132
133/// Capabilities advertised by the server.
134#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
135pub struct ServerCapabilities {
136    /// Whether the server supports interactive questions.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub supports_question: Option<bool>,
139}
140
141/// Hook information returned by the server.
142#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
143pub struct HooksInfo {
144    /// Supported hook event names.
145    pub supported_events: Vec<String>,
146    /// Configured hooks: subscription id → timeout.
147    pub configured: std::collections::HashMap<String, u32>,
148}
149
150// ============================================================================
151// Prompt
152// ============================================================================
153
154/// Prompt request parameters.
155#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
156pub struct PromptParams {
157    /// User input for the prompt.
158    pub user_input: UserInput,
159}
160
161/// Prompt response result.
162#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
163pub struct PromptResult {
164    /// Turn completion status.
165    pub status: PromptStatus,
166    /// Number of steps taken, if known.
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub steps: Option<u64>,
169}
170
171/// Status of a completed turn.
172#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
173#[serde(rename_all = "snake_case")]
174pub enum PromptStatus {
175    /// Turn finished successfully.
176    Finished,
177    /// Turn was cancelled.
178    Cancelled,
179    /// Turn reached the step limit.
180    MaxStepsReached,
181    /// The turn is still pending (observed in some server implementations).
182    Pending,
183    /// An unexpected end-of-stream occurred.
184    UnexpectedEof,
185}
186
187// ============================================================================
188// Replay
189// ============================================================================
190
191/// Replay request parameters (empty).
192#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
193pub struct ReplayParams {}
194
195/// Replay response result.
196#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
197pub struct ReplayResult {
198    /// Replay completion status.
199    pub status: ReplayStatus,
200    /// Number of events replayed.
201    pub events: u64,
202    /// Number of requests replayed.
203    pub requests: u64,
204}
205
206/// Replay completion status.
207#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
208#[serde(rename_all = "snake_case")]
209pub enum ReplayStatus {
210    /// Replay finished successfully.
211    Finished,
212    /// Replay was cancelled.
213    Cancelled,
214}
215
216// ============================================================================
217// Steer
218// ============================================================================
219
220/// Steer request parameters.
221#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
222pub struct SteerParams {
223    /// Additional user input to steer the turn.
224    pub user_input: UserInput,
225}
226
227/// Steer response result.
228#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
229pub struct SteerResult {
230    /// Steering status.
231    pub status: SteerStatus,
232}
233
234/// Steer operation status.
235#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
236#[serde(rename_all = "snake_case")]
237pub enum SteerStatus {
238    /// Input was successfully steered.
239    Steered,
240}
241
242// ============================================================================
243// SetPlanMode
244// ============================================================================
245
246/// SetPlanMode request parameters.
247#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
248pub struct SetPlanModeParams {
249    /// Whether to enable plan mode.
250    pub enabled: bool,
251}
252
253/// SetPlanMode response result.
254#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
255pub struct SetPlanModeResult {
256    /// Operation status.
257    pub status: SetPlanModeStatus,
258    /// Whether plan mode is now active.
259    pub plan_mode: bool,
260}
261
262/// SetPlanMode operation status.
263#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
264#[serde(rename_all = "snake_case")]
265pub enum SetPlanModeStatus {
266    /// Operation succeeded.
267    Ok,
268}
269
270// ============================================================================
271// Cancel
272// ============================================================================
273
274/// Cancel request parameters (empty).
275#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
276pub struct CancelParams {}
277
278/// Cancel response result (empty).
279#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
280pub struct CancelResult {}