1pub use crate::protocol_generated::types::*;
23
24pub mod methods {
29 pub const INITIALIZE: &str = "initialize";
31 pub const INITIALIZED: &str = "initialized";
32 pub const THREAD_START: &str = "thread/start";
33 pub const THREAD_ARCHIVE: &str = "thread/archive";
34 pub const THREAD_DELETE: &str = "thread/delete";
35 pub const TURN_START: &str = "turn/start";
36 pub const TURN_INTERRUPT: &str = "turn/interrupt";
37 pub const TURN_STEER: &str = "turn/steer";
38 pub const THREAD_RESUME: &str = "thread/resume";
39 pub const THREAD_FORK: &str = "thread/fork";
40 pub const THREAD_UNSUBSCRIBE: &str = "thread/unsubscribe";
41 pub const THREAD_NAME_SET: &str = "thread/name/set";
42 pub const THREAD_METADATA_UPDATE: &str = "thread/metadata/update";
43 pub const THREAD_ATTACHMENT_ADD: &str = "thread/attachment/add";
44 pub const THREAD_ATTACHMENT_LIST: &str = "thread/attachment/list";
45 pub const THREAD_ATTACHMENT_REMOVE: &str = "thread/attachment/remove";
46 pub const THREAD_ATTACHMENT_OWNER_LIST: &str = "thread/attachmentOwner/list";
47 pub const THREAD_UNARCHIVE: &str = "thread/unarchive";
48 pub const THREAD_COMPACT_START: &str = "thread/compact/start";
49 pub const THREAD_SHELLCOMMAND: &str = "thread/shellCommand";
50 pub const THREAD_APPROVEGUARDIANDENIEDACTION: &str = "thread/approveGuardianDeniedAction";
51 pub const THREAD_LIST: &str = "thread/list";
52 pub const THREAD_LOADED_LIST: &str = "thread/loaded/list";
53 pub const THREAD_READ: &str = "thread/read";
54 pub const THREAD_INJECT_ITEMS: &str = "thread/inject_items";
55 pub const THREAD_ITEMS_LIST: &str = "thread/items/list";
56 pub const THREAD_TURNS_LIST: &str = "thread/turns/list";
57 pub const THREAD_REVERT: &str = "thread/revert";
58 pub const SKILLS_LIST: &str = "skills/list";
59 pub const HOOKS_LIST: &str = "hooks/list";
60 pub const MARKETPLACE_ADD: &str = "marketplace/add";
61 pub const MARKETPLACE_REMOVE: &str = "marketplace/remove";
62 pub const MARKETPLACE_UPGRADE: &str = "marketplace/upgrade";
63 pub const PLUGIN_LIST: &str = "plugin/list";
64 pub const PLUGIN_READ: &str = "plugin/read";
65 pub const PLUGIN_SKILL_READ: &str = "plugin/skill/read";
66 pub const PLUGIN_SHARE_SAVE: &str = "plugin/share/save";
67 pub const PLUGIN_SHARE_UPDATETARGETS: &str = "plugin/share/updateTargets";
68 pub const PLUGIN_SHARE_LIST: &str = "plugin/share/list";
69 pub const PLUGIN_SHARE_CHECKOUT: &str = "plugin/share/checkout";
70 pub const PLUGIN_SHARE_DELETE: &str = "plugin/share/delete";
71 pub const APP_LIST: &str = "app/list";
72 pub const APP_READ: &str = "app/read";
73 pub const APP_INSTALLED: &str = "app/installed";
74 pub const FS_READFILE: &str = "fs/readFile";
75 pub const FS_WRITEFILE: &str = "fs/writeFile";
76 pub const FS_CREATEDIRECTORY: &str = "fs/createDirectory";
77 pub const FS_GETMETADATA: &str = "fs/getMetadata";
78 pub const FS_READDIRECTORY: &str = "fs/readDirectory";
79 pub const FS_REMOVE: &str = "fs/remove";
80 pub const FS_COPY: &str = "fs/copy";
81 pub const FS_WATCH: &str = "fs/watch";
82 pub const FS_UNWATCH: &str = "fs/unwatch";
83 pub const SKILLS_CONFIG_WRITE: &str = "skills/config/write";
84 pub const PLUGIN_INSTALL: &str = "plugin/install";
85 pub const PLUGIN_UNINSTALL: &str = "plugin/uninstall";
86 pub const REVIEW_START: &str = "review/start";
87 pub const MODEL_LIST: &str = "model/list";
88 pub const ACCOUNT_GATEWAYOAUTH_READ: &str = "account/gatewayOAuth/read";
89 pub const ACCOUNT_GATEWAYOAUTH_LOGIN: &str = "account/gatewayOAuth/login";
90 pub const ACCOUNT_GATEWAYOAUTH_CANCEL: &str = "account/gatewayOAuth/cancel";
91 pub const MODELPROVIDER_CAPABILITIES_READ: &str = "modelProvider/capabilities/read";
92 pub const EXPERIMENTALFEATURE_LIST: &str = "experimentalFeature/list";
93 pub const EXPERIMENTALFEATURE_ENABLEMENT_SET: &str = "experimentalFeature/enablement/set";
94 pub const MCPSERVER_OAUTH_LOGIN: &str = "mcpServer/oauth/login";
95 pub const CONFIG_MCPSERVER_RELOAD: &str = "config/mcpServer/reload";
96 pub const MCPSERVERSTATUS_LIST: &str = "mcpServerStatus/list";
97 pub const MCPSERVER_RESOURCE_READ: &str = "mcpServer/resource/read";
98 pub const MCPSERVER_TOOL_CALL: &str = "mcpServer/tool/call";
99 pub const WINDOWSSANDBOX_SETUPSTART: &str = "windowsSandbox/setupStart";
100 pub const WINDOWSSANDBOX_READINESS: &str = "windowsSandbox/readiness";
101 pub const ACCOUNT_LOGIN_START: &str = "account/login/start";
102 pub const ACCOUNT_LOGIN_CANCEL: &str = "account/login/cancel";
103 pub const ACCOUNT_LOGOUT: &str = "account/logout";
104 pub const ACCOUNT_RATELIMITS_READ: &str = "account/rateLimits/read";
105 pub const ACCOUNT_SENDADDCREDITSNUDGEEMAIL: &str = "account/sendAddCreditsNudgeEmail";
106 pub const FEEDBACK_UPLOAD: &str = "feedback/upload";
107 pub const FEEDBACK_SAVE: &str = "feedback/save";
108 pub const COMMAND_EXEC: &str = "command/exec";
109 pub const COMMAND_EXEC_WRITE: &str = "command/exec/write";
110 pub const COMMAND_EXEC_TERMINATE: &str = "command/exec/terminate";
111 pub const COMMAND_EXEC_RESIZE: &str = "command/exec/resize";
112 pub const CONFIG_READ: &str = "config/read";
113 pub const EXTERNALAGENTCONFIG_DETECT: &str = "externalAgentConfig/detect";
114 pub const EXTERNALAGENTCONFIG_IMPORT: &str = "externalAgentConfig/import";
115 pub const CONFIG_VALUE_WRITE: &str = "config/value/write";
116 pub const CONFIG_BATCHWRITE: &str = "config/batchWrite";
117 pub const CONFIGREQUIREMENTS_READ: &str = "configRequirements/read";
118 pub const ACCOUNT_READ: &str = "account/read";
119 pub const FUZZYFILESEARCH: &str = "fuzzyFileSearch";
120 pub const ACCOUNT_USAGE_READ: &str = "account/usage/read";
121 pub const PERMISSION_PROFILE_LIST: &str = "permissionProfile/list";
122 pub const PLUGIN_INSTALLED: &str = "plugin/installed";
123 pub const PLUGIN_RECONCILE: &str = "plugin/reconcile";
124 pub const SKILLS_EXTRA_ROOTS_SET: &str = "skills/extraRoots/set";
125 pub const THREAD_GOAL_GET: &str = "thread/goal/get";
126 pub const THREAD_GOAL_SET: &str = "thread/goal/set";
127 pub const THREAD_GOAL_CLEAR: &str = "thread/goal/clear";
128 pub const THREADSECTION_LIST: &str = "threadSection/list";
129 pub const THREADSECTION_CREATE: &str = "threadSection/create";
130 pub const THREADSECTION_UPDATE: &str = "threadSection/update";
131 pub const THREADSECTION_DELETE: &str = "threadSection/delete";
132 pub const THREAD_SECTION_MOVE: &str = "thread/section/move";
133 pub const ACCOUNT_RATELIMITRESETCREDIT_CONSUME: &str = "account/rateLimitResetCredit/consume";
134 pub const ACCOUNT_WORKSPACEMESSAGES_READ: &str = "account/workspaceMessages/read";
135 pub const EXTERNALAGENTCONFIG_IMPORT_READHISTORIES: &str =
136 "externalAgentConfig/import/readHistories";
137 pub const EXTERNALAGENTCONFIG_IMPORT_RECORDHISTORY: &str =
138 "externalAgentConfig/import/recordHistory";
139
140 pub const THREAD_STARTED: &str = "thread/started";
142 pub const STRICT_REVIEW_REQUIRED: &str = "autoApprovalReview/strictReviewRequired";
143 pub const PROJECT_CHANGED: &str = "project/changed";
144 pub const THREAD_PROJECT_UPDATED: &str = "thread/project/updated";
145 pub const THREAD_QUEUE_CHANGED: &str = "thread/queue/changed";
146 pub const THREAD_REVERTED: &str = "thread/reverted";
147 pub const THREAD_PREDICTION_UPDATED: &str = "thread/prediction/updated";
148 pub const MCP_SERVER_EVENT_STREAM: &str = "mcpServer/event/stream/notification";
149 pub const THREAD_STATUS_CHANGED: &str = "thread/status/changed";
150 pub const THREAD_READ_STATE_CHANGED: &str = "thread/readState/changed";
151 pub const THREAD_TOKEN_USAGE_UPDATED: &str = "thread/tokenUsage/updated";
152 pub const TURN_STARTED: &str = "turn/started";
153 pub const TURN_COMPLETED: &str = "turn/completed";
154 pub const ITEM_STARTED: &str = "item/started";
155 pub const ITEM_COMPLETED: &str = "item/completed";
156 pub const AGENT_MESSAGE_DELTA: &str = "item/agentMessage/delta";
157 pub const CMD_OUTPUT_DELTA: &str = "item/commandExecution/outputDelta";
158 pub const FILE_CHANGE_OUTPUT_DELTA: &str = "item/fileChange/outputDelta";
159 pub const REASONING_DELTA: &str = "item/reasoning/summaryTextDelta";
160 pub const ERROR: &str = "error";
161 pub const ACCOUNT_RATE_LIMITS_UPDATED: &str = "account/rateLimits/updated";
162 pub const MCP_SERVER_STARTUP_STATUS_UPDATED: &str = "mcpServer/startupStatus/updated";
163 pub const MCP_SERVER_OAUTH_LOGIN_COMPLETED: &str = "mcpServer/oauthLogin/completed";
164 pub const REMOTE_CONTROL_STATUS_CHANGED: &str = "remoteControl/status/changed";
165 pub const FILE_CHANGE_PATCH_UPDATED: &str = "item/fileChange/patchUpdated";
166 pub const PLAN_DELTA: &str = "item/plan/delta";
167 pub const TURN_PLAN_UPDATED: &str = "turn/plan/updated";
168 pub const TURN_DIFF_UPDATED: &str = "turn/diff/updated";
169 pub const REASONING_SUMMARY_PART_ADDED: &str = "item/reasoning/summaryPartAdded";
170 pub const REASONING_TEXT_DELTA: &str = "item/reasoning/textDelta";
171 pub const ACCOUNT_LOGIN_COMPLETED: &str = "account/login/completed";
172 pub const DEPRECATION_NOTICE: &str = "deprecationNotice";
173 pub const GUARDIAN_WARNING: &str = "guardianWarning";
174 pub const WARNING: &str = "warning";
175 pub const THREAD_ARCHIVED: &str = "thread/archived";
176 pub const THREAD_CLOSED: &str = "thread/closed";
177 pub const THREAD_DELETED: &str = "thread/deleted";
178 pub const THREAD_UNARCHIVED: &str = "thread/unarchived";
179 pub const THREAD_GOAL_CLEARED: &str = "thread/goal/cleared";
180 pub const THREAD_NAME_UPDATED: &str = "thread/name/updated";
181 pub const THREAD_ATTACHMENT_UPDATED: &str = "thread/attachment/updated";
182 pub const SKILLS_CHANGED: &str = "skills/changed";
183 pub const FS_CHANGED: &str = "fs/changed";
184 pub const CONFIG_WARNING: &str = "configWarning";
185 pub const ACCOUNT_UPDATED: &str = "account/updated";
186 pub const ACCOUNT_GATEWAY_OAUTH_CHANGED: &str = "account/gatewayOAuth/changed";
187 pub const APP_LIST_UPDATED: &str = "app/list/updated";
188 pub const COMMAND_EXEC_OUTPUT_DELTA: &str = "command/exec/outputDelta";
189 pub const EXTERNAL_AGENT_CONFIG_IMPORT_COMPLETED: &str = "externalAgentConfig/import/completed";
190 pub const FUZZY_FILE_SEARCH_SESSION_COMPLETED: &str = "fuzzyFileSearch/sessionCompleted";
191 pub const FUZZY_FILE_SEARCH_SESSION_UPDATED: &str = "fuzzyFileSearch/sessionUpdated";
192 pub const HOOK_COMPLETED: &str = "hook/completed";
193 pub const HOOK_STARTED: &str = "hook/started";
194 pub const ITEM_AUTO_APPROVAL_REVIEW_COMPLETED: &str = "item/autoApprovalReview/completed";
195 pub const ITEM_AUTO_APPROVAL_REVIEW_STARTED: &str = "item/autoApprovalReview/started";
196 pub const ITEM_COMMAND_EXEC_TERMINAL_INTERACTION: &str =
197 "item/commandExecution/terminalInteraction";
198 pub const ITEM_MCP_TOOL_CALL_PROGRESS: &str = "item/mcpToolCall/progress";
199 pub const MODEL_REROUTED: &str = "model/rerouted";
200 pub const MODEL_VERIFICATION: &str = "model/verification";
201 pub const PROCESS_EXITED: &str = "process/exited";
202 pub const PROCESS_OUTPUT_DELTA: &str = "process/outputDelta";
203 pub const SERVER_REQUEST_RESOLVED: &str = "serverRequest/resolved";
204 pub const THREAD_COMPACTED: &str = "thread/compacted";
205 pub const THREAD_GOAL_UPDATED: &str = "thread/goal/updated";
206 pub const THREAD_REALTIME_CLOSED: &str = "thread/realtime/closed";
207 pub const THREAD_REALTIME_ERROR: &str = "thread/realtime/error";
208 pub const THREAD_REALTIME_ITEM_ADDED: &str = "thread/realtime/itemAdded";
209 pub const THREAD_REALTIME_OUTPUT_AUDIO_DELTA: &str = "thread/realtime/outputAudio/delta";
210 pub const THREAD_REALTIME_SDP: &str = "thread/realtime/sdp";
211 pub const THREAD_REALTIME_STARTED: &str = "thread/realtime/started";
212 pub const THREAD_REALTIME_TRANSCRIPT_DELTA: &str = "thread/realtime/transcript/delta";
213 pub const THREAD_REALTIME_TRANSCRIPT_DONE: &str = "thread/realtime/transcript/done";
214 pub const THREAD_REALTIME_ITEM_STARTED: &str = "thread/realtime/item/started";
215 pub const THREAD_REALTIME_ITEM_COMPLETED: &str = "thread/realtime/item/completed";
216 pub const THREAD_REALTIME_ITEM_TRANSCRIPT_DELTA: &str = "thread/realtime/item/transcript/delta";
217 pub const MODEL_PROVIDER_AUTH_RECOVERY_STARTED: &str = "modelProvider/authRecoveryStarted";
218 pub const MODEL_PROVIDER_AUTH_RECOVERY_COMPLETED: &str = "modelProvider/authRecoveryCompleted";
219 pub const WINDOWS_WORLD_WRITABLE_WARNING: &str = "windows/worldWritableWarning";
220 pub const WINDOWS_SANDBOX_SETUP_COMPLETED: &str = "windowsSandbox/setupCompleted";
221 pub const THREAD_SETTINGS_UPDATED: &str = "thread/settings/updated";
222 pub const TURN_MODERATION_METADATA: &str = "turn/moderationMetadata";
223 pub const EXTERNAL_AGENT_CONFIG_IMPORT_PROGRESS: &str = "externalAgentConfig/import/progress";
224 pub const MODEL_SAFETY_BUFFERING_UPDATED: &str = "model/safetyBuffering/updated";
225 pub const THREAD_ENVIRONMENT_CONNECTED: &str = "thread/environment/connected";
226 pub const THREAD_ENVIRONMENT_DISCONNECTED: &str = "thread/environment/disconnected";
227
228 pub const CMD_EXEC_APPROVAL: &str = "item/commandExecution/requestApproval";
230 pub const FILE_CHANGE_APPROVAL: &str = "item/fileChange/requestApproval";
231 pub const TOOL_REQUEST_USER_INPUT: &str = "item/tool/requestUserInput";
232 pub const MCP_SERVER_ELICITATION_REQUEST: &str = "mcpServer/elicitation/request";
233 pub const PERMISSIONS_REQUEST_APPROVAL: &str = "item/permissions/requestApproval";
234 pub const ITEM_TOOL_CALL: &str = "item/tool/call";
235 pub const CHATGPT_AUTH_TOKENS_REFRESH: &str = "account/chatgptAuthTokens/refresh";
236 pub const ATTESTATION_GENERATE: &str = "attestation/generate";
237 pub const APPLY_PATCH_APPROVAL: &str = "applyPatchApproval";
238 pub const EXEC_COMMAND_APPROVAL: &str = "execCommandApproval";
239}
240
241impl FileChangeRequestApprovalResponse {
255 pub fn accept() -> Self {
257 Self {
258 decision: FileChangeApprovalDecision::Accept,
259 }
260 }
261
262 pub fn accept_for_session() -> Self {
264 Self {
265 decision: FileChangeApprovalDecision::AcceptForSession,
266 }
267 }
268
269 pub fn decline() -> Self {
271 Self {
272 decision: FileChangeApprovalDecision::Decline,
273 }
274 }
275
276 pub fn cancel() -> Self {
278 Self {
279 decision: FileChangeApprovalDecision::Cancel,
280 }
281 }
282}
283
284impl CommandExecutionRequestApprovalResponse {
285 pub fn accept() -> Self {
287 Self {
288 decision: CommandExecutionApprovalDecision::Accept,
289 }
290 }
291
292 pub fn accept_for_session() -> Self {
294 Self {
295 decision: CommandExecutionApprovalDecision::AcceptForSession,
296 }
297 }
298
299 pub fn decline() -> Self {
301 Self {
302 decision: CommandExecutionApprovalDecision::Decline,
303 }
304 }
305
306 pub fn cancel() -> Self {
308 Self {
309 decision: CommandExecutionApprovalDecision::Cancel,
310 }
311 }
312}
313
314impl ExecCommandApprovalResponse {
315 pub fn approved() -> Self {
317 Self {
318 decision: ReviewDecision::Approved,
319 }
320 }
321
322 pub fn approved_for_session() -> Self {
324 Self {
325 decision: ReviewDecision::ApprovedForSession,
326 }
327 }
328
329 pub fn denied(rejection: impl Into<String>) -> Self {
331 Self {
332 decision: ReviewDecision::Denied {
333 rejection: rejection.into(),
334 },
335 }
336 }
337
338 pub fn abort() -> Self {
340 Self {
341 decision: ReviewDecision::Abort,
342 }
343 }
344}
345
346impl ApplyPatchApprovalResponse {
347 pub fn approved() -> Self {
349 Self {
350 decision: ReviewDecision::Approved,
351 }
352 }
353
354 pub fn approved_for_session() -> Self {
356 Self {
357 decision: ReviewDecision::ApprovedForSession,
358 }
359 }
360
361 pub fn denied(rejection: impl Into<String>) -> Self {
363 Self {
364 decision: ReviewDecision::Denied {
365 rejection: rejection.into(),
366 },
367 }
368 }
369
370 pub fn abort() -> Self {
372 Self {
373 decision: ReviewDecision::Abort,
374 }
375 }
376}
377
378#[cfg(test)]
379mod tests {
380 use super::*;
381
382 #[test]
383 fn thread_start_params_default_is_empty_object() {
384 let p = ThreadStartParams::default();
385 assert_eq!(serde_json::to_value(&p).unwrap(), serde_json::json!({}));
386 }
387
388 #[test]
389 fn turn_start_params_default_round_trips() {
390 let p = TurnStartParams::default();
391 let v = serde_json::to_value(&p).unwrap();
392 assert_eq!(v["threadId"], "");
394 assert_eq!(v["input"], serde_json::json!([]));
395 }
396
397 #[test]
398 fn thread_resume_and_fork_params_default() {
399 let _ = ThreadResumeParams::default();
400 let _ = ThreadForkParams::default();
401 }
402
403 #[test]
404 fn file_change_approval_response_wire_shape() {
405 assert_eq!(
406 serde_json::to_value(FileChangeRequestApprovalResponse::accept()).unwrap(),
407 serde_json::json!({"decision": "accept"})
408 );
409 assert_eq!(
410 serde_json::to_value(FileChangeRequestApprovalResponse::decline()).unwrap(),
411 serde_json::json!({"decision": "decline"})
412 );
413 }
414
415 #[test]
416 fn command_execution_approval_response_wire_shape() {
417 assert_eq!(
418 serde_json::to_value(CommandExecutionRequestApprovalResponse::accept()).unwrap(),
419 serde_json::json!({"decision": "accept"})
420 );
421 assert_eq!(
422 serde_json::to_value(CommandExecutionRequestApprovalResponse::cancel()).unwrap(),
423 serde_json::json!({"decision": "cancel"})
424 );
425 }
426
427 #[test]
428 fn exec_and_apply_patch_approval_response_wire_shape() {
429 assert_eq!(
430 serde_json::to_value(ExecCommandApprovalResponse::approved()).unwrap(),
431 serde_json::json!({"decision": "approved"})
432 );
433 assert_eq!(
434 serde_json::to_value(ApplyPatchApprovalResponse::denied("keep the original file"))
435 .unwrap(),
436 serde_json::json!({"decision": {"denied": {"rejection": "keep the original file"}}})
437 );
438 }
439
440 #[test]
441 fn hook_event_name_model_request_round_trips() {
442 for (event, wire) in [
443 (HookEventName::PreModelRequest, "preModelRequest"),
444 (HookEventName::PostModelRequest, "postModelRequest"),
445 ] {
446 assert_eq!(serde_json::to_value(&event).unwrap(), wire);
447 assert_eq!(
448 serde_json::from_value::<HookEventName>(serde_json::json!(wire)).unwrap(),
449 event
450 );
451 }
452 }
453
454 #[test]
455 fn gcp_account_round_trips() {
456 let wire = serde_json::json!({"type": "gcp"});
457 assert_eq!(serde_json::to_value(Account::Gcp).unwrap(), wire);
458 assert_eq!(
459 serde_json::from_value::<Account>(wire).unwrap(),
460 Account::Gcp
461 );
462 let response: GetAccountResponse = serde_json::from_value(serde_json::json!({
463 "account": {"type": "gcp"},
464 "requiresOpenaiAuth": false
465 }))
466 .unwrap();
467 assert_eq!(response.account, Some(Account::Gcp));
468 }
469}