1#![deny(clippy::print_stdout)]
5#![deny(clippy::print_stderr)]
6
7use std::path::PathBuf;
8
9use serde::{Deserialize, Serialize};
10use serde_json::Value;
11
12pub mod agent_mail;
13pub mod agent_run;
14pub mod engine_owner;
15pub mod event_msg;
16pub mod fleet;
17pub mod ids;
18pub mod journal;
19pub mod op;
20pub mod runtime;
21pub mod workroom;
22
23pub trait Status {
29 fn is_terminal(&self) -> bool;
32
33 fn is_active(&self) -> bool;
36
37 fn is_paused(&self) -> bool;
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct MessageRecord {
48 pub id: i64,
50 pub thread_id: String,
52 pub role: String,
54 pub content: String,
56 pub item: Option<Value>,
58 pub created_at: i64,
60 pub parent_entry_id: Option<i64>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(deny_unknown_fields)]
67pub struct LegacyThreadHistory {
68 pub version: u32,
69 pub state_store_id: String,
70 pub thread_id: String,
71 pub current_leaf_id: Option<i64>,
72 pub messages: Vec<MessageRecord>,
73 #[serde(default, skip_serializing_if = "Option::is_none")]
75 pub goal: Option<ThreadGoal>,
76}
77
78pub const MAX_CANONICAL_HISTORY_ENTRIES: usize = 16_384;
79pub const MAX_CANONICAL_HISTORY_BYTES: usize = 8 * 1024 * 1024;
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(deny_unknown_fields)]
85pub struct CanonicalHistoryImportRequest {
86 pub version: u32,
87 pub operation_key: String,
88 pub expected_data_dir: PathBuf,
89 pub expected_execution_scope: String,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
93 pub target_runtime_thread_id: Option<String>,
94 pub workspace: PathBuf,
95 pub model: Option<String>,
96 pub history: LegacyThreadHistory,
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
103#[serde(deny_unknown_fields)]
104pub struct CanonicalThreadReceipt {
105 pub version: u32,
106 pub data_dir: PathBuf,
107 pub execution_scope: String,
108 pub operation_key: String,
109 pub request_digest: String,
110 pub history_digest: String,
111 pub runtime_thread_id: String,
112 pub session_id: String,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(deny_unknown_fields)]
120pub struct CanonicalThreadSnapshot {
121 pub version: u32,
122 pub data_dir: PathBuf,
123 pub execution_scope: String,
124 pub runtime_thread_id: String,
125 pub saved_session_id: Option<String>,
126 pub saved_document_digest: Option<String>,
127 pub document_digest: String,
128 pub session_goal_digest: String,
129 pub session: Value,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(deny_unknown_fields)]
136pub struct CanonicalThreadMutationRequest {
137 pub version: u32,
138 pub operation_key: String,
139 pub expected_data_dir: PathBuf,
140 pub expected_execution_scope: String,
141 pub workspace: PathBuf,
142 pub mutation: CanonicalThreadMutation,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(tag = "action", rename_all = "snake_case", deny_unknown_fields)]
147pub enum CanonicalThreadMutation {
148 Create { config: Value },
151 Resume {
152 source: CanonicalHistorySource,
153 #[serde(default)]
154 options: CanonicalHistoryOptions,
155 },
156 Fork {
157 source: CanonicalHistorySource,
158 #[serde(default)]
159 options: CanonicalHistoryOptions,
160 #[serde(default, skip_serializing_if = "Option::is_none")]
161 selected_entry_id: Option<String>,
162 },
163}
164
165#[derive(Debug, Clone, Default, Serialize, Deserialize)]
166#[serde(deny_unknown_fields)]
167pub struct CanonicalHistoryOptions {
168 #[serde(default, skip_serializing_if = "Vec::is_empty")]
169 pub offered_history: Vec<Value>,
170 #[serde(default, skip_serializing_if = "Value::is_null")]
171 pub overrides: Value,
172 #[serde(default, skip_serializing_if = "Option::is_none")]
173 pub source_path: Option<PathBuf>,
174 #[serde(default, skip_serializing_if = "Option::is_none")]
175 pub expected_session_goal_digest: Option<String>,
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize)]
179#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
180pub enum CanonicalHistorySource {
181 Thread {
182 runtime_thread_id: String,
183 expected_document_digest: String,
184 },
185 SavedSession {
188 session: Value,
189 expected_document_digest: String,
190 },
191}
192
193#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
194#[serde(rename_all = "snake_case")]
195pub enum CanonicalThreadOperationKind {
196 Create,
197 Resume,
198 Fork,
199}
200
201#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
202#[serde(deny_unknown_fields)]
203pub struct CanonicalThreadOperationAssociation {
204 pub kind: CanonicalThreadOperationKind,
205 pub source_runtime_thread_id: Option<String>,
206 pub source_session_id: Option<String>,
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(deny_unknown_fields)]
211pub struct CanonicalThreadOperationLookup {
212 pub version: u32,
213 pub operation_key: String,
214 pub expected_data_dir: PathBuf,
215 pub expected_execution_scope: String,
216 pub workspace: PathBuf,
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize)]
221#[serde(deny_unknown_fields)]
222pub struct CanonicalThreadOperationRecovery {
223 pub operation: CanonicalThreadOperationLookup,
224 pub association: CanonicalThreadOperationAssociation,
225}
226
227#[derive(Debug, Clone, Serialize, Deserialize)]
228#[serde(tag = "state", rename_all = "snake_case", deny_unknown_fields)]
229pub enum CanonicalThreadOperationStatus {
230 Absent,
231 Pending {
232 receipt: CanonicalThreadReceipt,
233 association: CanonicalThreadOperationAssociation,
234 },
235 Committed {
236 receipt: CanonicalThreadReceipt,
237 association: CanonicalThreadOperationAssociation,
238 },
239}
240
241#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
244#[serde(deny_unknown_fields)]
245pub struct RuntimeOwnerReceipt {
246 pub version: u32,
247 pub data_dir: PathBuf,
248 pub execution_scope: String,
249 pub lease_generation: String,
250 pub pid: u32,
251 pub process_start: String,
252 pub principal: String,
253 pub socket_path: PathBuf,
254 pub config_path: Option<PathBuf>,
255}
256
257#[derive(Debug, Clone, Serialize, Deserialize)]
258pub struct Envelope<T> {
259 pub request_id: String,
260 #[serde(skip_serializing_if = "Option::is_none")]
261 pub thread_id: Option<String>,
262 pub body: T,
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
266#[serde(rename_all = "snake_case")]
267pub enum ThreadStatus {
268 Running,
269 Idle,
270 Completed,
271 Failed,
272 Paused,
273 Archived,
274}
275
276impl Status for ThreadStatus {
277 fn is_terminal(&self) -> bool {
278 matches!(self, Self::Completed | Self::Failed | Self::Archived)
279 }
280 fn is_active(&self) -> bool {
281 matches!(self, Self::Running)
282 }
283 fn is_paused(&self) -> bool {
284 matches!(self, Self::Paused)
285 }
286}
287
288#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
289#[serde(rename_all = "snake_case")]
290pub enum SessionSource {
291 Interactive,
292 Resume,
293 Fork,
294 Api,
295 Unknown,
296}
297
298#[derive(Debug, Clone, Serialize, Deserialize)]
299pub struct Thread {
300 pub id: String,
301 pub preview: String,
302 pub ephemeral: bool,
303 pub model_provider: String,
304 pub created_at: i64,
305 pub updated_at: i64,
306 pub status: ThreadStatus,
307 #[serde(skip_serializing_if = "Option::is_none")]
308 pub path: Option<PathBuf>,
309 pub cwd: PathBuf,
310 pub cli_version: String,
311 pub source: SessionSource,
312 #[serde(skip_serializing_if = "Option::is_none")]
313 pub name: Option<String>,
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
317#[serde(rename_all = "snake_case")]
318pub enum ThreadGoalStatus {
319 Active,
320 Paused,
321 Blocked,
322 UsageLimited,
323 BudgetLimited,
324 Complete,
325}
326
327impl Status for ThreadGoalStatus {
328 fn is_terminal(&self) -> bool {
329 matches!(self, Self::Complete)
330 }
331 fn is_active(&self) -> bool {
332 matches!(self, Self::Active)
333 }
334 fn is_paused(&self) -> bool {
335 matches!(self, Self::Paused)
336 }
337}
338
339#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
340pub struct ThreadGoal {
341 pub thread_id: String,
342 pub goal_id: String,
343 pub objective: String,
344 pub status: ThreadGoalStatus,
345 #[serde(skip_serializing_if = "Option::is_none")]
346 pub token_budget: Option<i64>,
347 pub tokens_used: i64,
348 pub time_used_seconds: i64,
349 pub continuation_count: i64,
350 pub created_at: i64,
351 pub updated_at: i64,
352 #[serde(default, skip_serializing_if = "Option::is_none")]
353 pub last_gap_fingerprint: Option<String>,
354 #[serde(default)]
355 pub repeated_gap_count: u32,
356 #[serde(default, skip_serializing_if = "Option::is_none")]
357 pub last_gap_pass: Option<u32>,
358 #[serde(default, skip_serializing_if = "Option::is_none")]
359 pub pause_reason: Option<GoalPauseReason>,
360}
361
362#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
364#[serde(rename_all = "snake_case")]
365pub enum GoalPauseReason {
366 User,
367 Backoff,
368 NoProgress,
369 UsageLimit,
370 BudgetLimit,
371}
372
373impl GoalPauseReason {
374 #[must_use]
375 pub fn label(self) -> &'static str {
376 match self {
377 Self::User => "user",
378 Self::Backoff => "run limit",
379 Self::NoProgress => "no progress",
380 Self::UsageLimit => "usage limit",
381 Self::BudgetLimit => "budget limit",
382 }
383 }
384}
385
386pub const MAX_REPEATED_GAP_COUNT: u32 = 3;
389
390pub fn validate_goal_stall_state(
391 fingerprint: Option<&str>,
392 count: u32,
393 pass: Option<u32>,
394 continuation_count: u32,
395) -> Result<(), &'static str> {
396 match (fingerprint, count, pass) {
397 (None, 0, None) => Ok(()),
398 (Some(digest), 1..=MAX_REPEATED_GAP_COUNT, Some(pass))
399 if digest.len() == 64
400 && digest.bytes().all(|byte| byte.is_ascii_hexdigit())
401 && pass <= continuation_count
402 && count <= pass.saturating_add(1) =>
403 {
404 Ok(())
405 }
406 _ => Err("invalid persisted goal stall history"),
407 }
408}
409
410impl ThreadGoal {
411 pub fn validate_stall_state(&self) -> Result<(), &'static str> {
412 validate_goal_stall_state(
413 self.last_gap_fingerprint.as_deref(),
414 self.repeated_gap_count,
415 self.last_gap_pass,
416 u32::try_from(self.continuation_count.max(0)).unwrap_or(u32::MAX),
417 )
418 }
419
420 pub fn normalize_restored_stall_state(&mut self) -> bool {
426 if matches!(self.status, ThreadGoalStatus::Active)
427 && self.repeated_gap_count >= MAX_REPEATED_GAP_COUNT
428 {
429 self.status = ThreadGoalStatus::Paused;
430 self.pause_reason = Some(GoalPauseReason::NoProgress);
431 true
432 } else {
433 false
434 }
435 }
436}
437
438#[derive(Debug, Clone, Serialize, Deserialize)]
439pub struct ThreadStartParams {
440 #[serde(default, skip_serializing_if = "Option::is_none")]
442 pub operation_key: Option<String>,
443 #[serde(skip_serializing_if = "Option::is_none")]
444 pub model: Option<String>,
445 #[serde(skip_serializing_if = "Option::is_none")]
446 pub model_provider: Option<String>,
447 #[serde(skip_serializing_if = "Option::is_none")]
448 pub cwd: Option<PathBuf>,
449 #[serde(default)]
450 pub persist_extended_history: bool,
451}
452
453#[derive(Debug, Clone, Serialize, Deserialize)]
454pub struct ThreadResumeParams {
455 #[serde(default, skip_serializing_if = "Option::is_none")]
457 pub operation_key: Option<String>,
458 pub thread_id: String,
459 #[serde(skip_serializing_if = "Option::is_none")]
460 pub history: Option<Vec<Value>>,
461 #[serde(skip_serializing_if = "Option::is_none")]
462 pub path: Option<PathBuf>,
463 #[serde(skip_serializing_if = "Option::is_none")]
464 pub model: Option<String>,
465 #[serde(skip_serializing_if = "Option::is_none")]
466 pub model_provider: Option<String>,
467 #[serde(skip_serializing_if = "Option::is_none")]
468 pub cwd: Option<PathBuf>,
469 #[serde(skip_serializing_if = "Option::is_none")]
470 pub approval_policy: Option<String>,
471 #[serde(skip_serializing_if = "Option::is_none")]
472 pub sandbox: Option<String>,
473 #[serde(skip_serializing_if = "Option::is_none")]
474 pub config: Option<Value>,
475 #[serde(skip_serializing_if = "Option::is_none")]
476 pub base_instructions: Option<String>,
477 #[serde(skip_serializing_if = "Option::is_none")]
478 pub developer_instructions: Option<String>,
479 #[serde(skip_serializing_if = "Option::is_none")]
480 pub personality: Option<String>,
481 #[serde(default)]
482 pub persist_extended_history: bool,
483}
484
485#[derive(Debug, Clone, Serialize, Deserialize)]
486pub struct ThreadForkParams {
487 #[serde(default, skip_serializing_if = "Option::is_none")]
489 pub operation_key: Option<String>,
490 pub thread_id: String,
491 #[serde(skip_serializing_if = "Option::is_none")]
492 pub path: Option<PathBuf>,
493 #[serde(skip_serializing_if = "Option::is_none")]
494 pub model: Option<String>,
495 #[serde(skip_serializing_if = "Option::is_none")]
496 pub model_provider: Option<String>,
497 #[serde(skip_serializing_if = "Option::is_none")]
498 pub cwd: Option<PathBuf>,
499 #[serde(skip_serializing_if = "Option::is_none")]
500 pub approval_policy: Option<String>,
501 #[serde(skip_serializing_if = "Option::is_none")]
502 pub sandbox: Option<String>,
503 #[serde(skip_serializing_if = "Option::is_none")]
504 pub config: Option<Value>,
505 #[serde(skip_serializing_if = "Option::is_none")]
506 pub base_instructions: Option<String>,
507 #[serde(skip_serializing_if = "Option::is_none")]
508 pub developer_instructions: Option<String>,
509 #[serde(default)]
510 pub persist_extended_history: bool,
511}
512
513#[derive(Debug, Clone, Serialize, Deserialize)]
514pub struct ThreadListParams {
515 #[serde(default)]
516 pub include_archived: bool,
517 #[serde(skip_serializing_if = "Option::is_none")]
518 pub limit: Option<usize>,
519}
520
521#[derive(Debug, Clone, Serialize, Deserialize)]
522pub struct ThreadReadParams {
523 pub thread_id: String,
524}
525
526#[derive(Debug, Clone, Serialize, Deserialize)]
527pub struct ThreadSetNameParams {
528 pub thread_id: String,
529 pub name: String,
530}
531
532#[derive(Debug, Clone, Serialize, Deserialize)]
533pub struct ThreadGoalSetParams {
534 pub thread_id: String,
535 pub objective: String,
536 #[serde(skip_serializing_if = "Option::is_none")]
537 pub token_budget: Option<i64>,
538}
539
540#[derive(Debug, Clone, Serialize, Deserialize)]
541pub struct ThreadGoalGetParams {
542 pub thread_id: String,
543}
544
545#[derive(Debug, Clone, Serialize, Deserialize)]
546pub struct ThreadGoalClearParams {
547 pub thread_id: String,
548}
549
550#[derive(Debug, Clone, Serialize, Deserialize)]
551pub struct ThreadGoalProgressParams {
552 pub thread_id: String,
553 #[serde(default)]
554 pub token_delta: i64,
555 #[serde(default)]
556 pub time_delta_seconds: i64,
557 #[serde(default)]
558 pub record_continuation: bool,
559}
560
561#[derive(Debug, Clone, Serialize, Deserialize)]
562#[serde(tag = "kind", rename_all = "snake_case")]
563pub enum ThreadRequest {
564 Create {
565 #[serde(default)]
566 metadata: Value,
567 },
568 Start(ThreadStartParams),
569 Resume(ThreadResumeParams),
570 Fork(ThreadForkParams),
571 List(ThreadListParams),
572 Read(ThreadReadParams),
573 SetName(ThreadSetNameParams),
574 GoalSet(ThreadGoalSetParams),
575 GoalGet(ThreadGoalGetParams),
576 GoalClear(ThreadGoalClearParams),
577 GoalRecordProgress(ThreadGoalProgressParams),
578 Archive {
579 thread_id: String,
580 },
581 Unarchive {
582 thread_id: String,
583 },
584 Message {
585 thread_id: String,
586 input: String,
587 #[serde(default, skip_serializing_if = "Vec::is_empty")]
588 images: Vec<runtime::RuntimeImageInput>,
589 #[serde(
590 default,
591 rename = "maxOutputTokens",
592 alias = "max_output_tokens",
593 skip_serializing_if = "Option::is_none"
594 )]
595 max_output_tokens: Option<std::num::NonZeroU32>,
596 },
597}
598
599#[derive(Debug, Clone, Serialize, Deserialize)]
601pub struct ThreadResponse {
602 pub thread_id: String,
604 pub status: String,
606 #[serde(skip_serializing_if = "Option::is_none")]
608 pub thread: Option<Thread>,
609 #[serde(default)]
611 pub threads: Vec<Thread>,
612 #[serde(skip_serializing_if = "Option::is_none")]
614 pub goal: Option<ThreadGoal>,
615 #[serde(skip_serializing_if = "Option::is_none")]
617 pub model: Option<String>,
618 #[serde(skip_serializing_if = "Option::is_none")]
620 pub model_provider: Option<String>,
621 #[serde(skip_serializing_if = "Option::is_none")]
623 pub cwd: Option<PathBuf>,
624 #[serde(skip_serializing_if = "Option::is_none")]
626 pub approval_policy: Option<String>,
627 #[serde(skip_serializing_if = "Option::is_none")]
629 pub sandbox: Option<String>,
630 #[serde(default)]
632 pub events: Vec<EventFrame>,
633 #[serde(default)]
635 pub data: Value,
636}
637
638#[derive(Debug, Clone, Serialize, Deserialize)]
640#[serde(tag = "kind", rename_all = "snake_case")]
641pub enum AppRequest {
642 Capabilities,
644 ConfigGet { key: String },
646 ConfigSet { key: String, value: String },
648 ConfigUnset { key: String },
650 ConfigList,
652 ConfigReload,
665 Models,
667 ThreadLoadedList,
669 SubmitUserInput {
674 request_id: String,
675 answers: Vec<UserInputAnswerEvent>,
676 },
677}
678
679#[derive(Debug, Clone, Serialize, Deserialize)]
681pub struct AppResponse {
682 pub ok: bool,
684 pub data: Value,
686 #[serde(default)]
688 pub events: Vec<EventFrame>,
689}
690
691#[derive(Debug, Clone, Serialize, Deserialize)]
693pub struct PromptRequest {
694 #[serde(
695 default,
696 rename = "maxOutputTokens",
697 alias = "max_output_tokens",
698 skip_serializing_if = "Option::is_none"
699 )]
700 pub max_output_tokens: Option<std::num::NonZeroU32>,
701 #[serde(skip_serializing_if = "Option::is_none")]
703 pub thread_id: Option<String>,
704 pub prompt: String,
706 #[serde(default, skip_serializing_if = "Vec::is_empty")]
707 pub images: Vec<runtime::RuntimeImageInput>,
708 #[serde(skip_serializing_if = "Option::is_none")]
710 pub model: Option<String>,
711}
712
713#[derive(Debug, Clone, Serialize, Deserialize)]
715pub struct PromptResponse {
716 pub output: String,
718 pub model: String,
720 #[serde(default)]
722 pub events: Vec<EventFrame>,
723}
724
725#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
727#[serde(rename_all = "snake_case")]
728pub enum AskForApproval {
729 UnlessTrusted,
731 OnFailure,
733 OnRequest,
735 Reject {
737 sandbox_approval: bool,
738 rules: bool,
739 mcp_elicitations: bool,
740 },
741 Never,
743}
744
745#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
747#[serde(rename_all = "snake_case")]
748pub enum ToolKind {
749 Function,
751 Mcp,
753}
754
755#[derive(Debug, Clone, Serialize, Deserialize)]
757pub struct LocalShellParams {
758 pub command: String,
760 #[serde(skip_serializing_if = "Option::is_none")]
762 pub cwd: Option<String>,
763 #[serde(skip_serializing_if = "Option::is_none")]
765 pub timeout_ms: Option<u64>,
766}
767
768#[derive(Debug, Clone, Serialize, Deserialize)]
770#[serde(tag = "type", rename_all = "snake_case")]
771pub enum ToolPayload {
772 Function { arguments: String },
774 Custom { input: String },
776 LocalShell { params: LocalShellParams },
778 Mcp {
780 server: String,
781 tool: String,
782 raw_arguments: Value,
783 #[serde(skip_serializing_if = "Option::is_none")]
784 raw_tool_call_id: Option<String>,
785 },
786}
787
788#[derive(Debug, Clone, Serialize, Deserialize)]
790#[serde(tag = "type", rename_all = "snake_case")]
791pub enum ToolOutput {
792 Function {
794 #[serde(skip_serializing_if = "Option::is_none")]
796 body: Option<Value>,
797 success: bool,
799 },
800 Mcp {
802 result: Value,
804 },
805}
806
807impl ToolOutput {
808 pub fn success(&self) -> bool {
813 match self {
814 Self::Function { success, .. } => *success,
815 Self::Mcp { result } => {
816 matches!(result.get("isError"), None | Some(Value::Bool(false)))
817 }
818 }
819 }
820}
821
822#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
824#[serde(rename_all = "snake_case")]
825pub enum NetworkPolicyRuleAction {
826 Allow,
828 Deny,
830}
831
832#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
834pub struct NetworkPolicyAmendment {
835 pub host: String,
837 pub action: NetworkPolicyRuleAction,
839}
840
841#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
843#[serde(tag = "type", rename_all = "snake_case")]
844pub enum ReviewDecision {
845 Approved,
847 ApprovedExecpolicyAmendment,
849 ApprovedForSession,
851 NetworkPolicyAmendment {
853 host: String,
854 action: NetworkPolicyRuleAction,
855 },
856 Denied,
858 Abort,
860}
861
862#[derive(Debug, Clone, Serialize, Deserialize)]
864#[serde(rename_all = "snake_case")]
865pub enum McpStartupStatus {
866 Starting,
868 Ready,
870 Failed { error: String },
872 Cancelled,
874}
875
876#[derive(Debug, Clone, Serialize, Deserialize)]
878pub struct McpStartupUpdateEvent {
879 pub server_name: String,
881 pub status: McpStartupStatus,
883}
884
885#[derive(Debug, Clone, Serialize, Deserialize)]
887pub struct McpStartupFailure {
888 pub server_name: String,
890 pub error: String,
892}
893
894#[derive(Debug, Clone, Serialize, Deserialize)]
896pub struct McpStartupCompleteEvent {
897 pub ready: Vec<String>,
899 pub failed: Vec<McpStartupFailure>,
901 pub cancelled: Vec<String>,
903}
904
905#[derive(Debug, Clone, Serialize, Deserialize)]
907pub struct NetworkApprovalContext {
908 pub host: String,
910 pub protocol: String,
912}
913
914#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
921pub struct UserInputOptionEvent {
922 pub label: String,
924 pub description: String,
926}
927
928#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
930pub struct UserInputQuestionEvent {
931 pub header: String,
933 pub id: String,
935 pub question: String,
937 pub options: Vec<UserInputOptionEvent>,
939 #[serde(default)]
941 pub allow_free_text: bool,
942 #[serde(default)]
944 pub multi_select: bool,
945}
946
947#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
953pub struct UserInputRequestEvent {
954 pub call_id: String,
956 pub turn_id: String,
958 pub request_id: String,
960 pub questions: Vec<UserInputQuestionEvent>,
962}
963
964#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
966pub struct UserInputAnswerEvent {
967 pub id: String,
969 pub label: String,
971 pub value: String,
973}
974
975#[derive(Debug, Clone, Serialize, Deserialize)]
977pub struct ExecApprovalRequestEvent {
978 pub call_id: String,
980 pub approval_id: String,
982 pub turn_id: String,
984 pub command: String,
986 pub cwd: String,
988 pub reason: String,
990 #[serde(default, skip_serializing_if = "Option::is_none")]
992 pub matched_rule: Option<Box<str>>,
993 #[serde(skip_serializing_if = "Option::is_none")]
995 pub network_approval_context: Option<NetworkApprovalContext>,
996 #[serde(default)]
998 pub proposed_execpolicy_amendment: Vec<String>,
999 #[serde(default)]
1001 pub proposed_network_policy_amendments: Vec<NetworkPolicyAmendment>,
1002 #[serde(default)]
1004 pub additional_permissions: Vec<String>,
1005 #[serde(default)]
1007 pub available_decisions: Vec<ReviewDecision>,
1008}
1009
1010#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
1012#[serde(rename_all = "snake_case")]
1013pub enum ResponseChannel {
1014 #[default]
1016 Text,
1017 Reasoning,
1019}
1020
1021impl ResponseChannel {
1022 pub const fn is_text(&self) -> bool {
1024 matches!(self, ResponseChannel::Text)
1025 }
1026}
1027
1028#[derive(Debug, Clone, Serialize, Deserialize)]
1030pub struct ApprovalDecisionRequest {
1031 pub decision: String,
1033 #[serde(default)]
1035 pub remember: bool,
1036}
1037
1038#[derive(Debug, Clone, Serialize, Deserialize)]
1044#[serde(tag = "event", rename_all = "snake_case")]
1045pub enum EventFrame {
1046 ResponseStart { response_id: String },
1048 ResponseDelta {
1050 response_id: String,
1051 delta: String,
1052 #[serde(default, skip_serializing_if = "ResponseChannel::is_text")]
1053 channel: ResponseChannel,
1054 },
1055 ResponseEnd { response_id: String },
1057 ToolCallStart {
1059 response_id: String,
1060 tool_name: String,
1061 arguments: Value,
1062 },
1063 ToolCallResult {
1065 response_id: String,
1066 tool_name: String,
1067 output: Value,
1068 },
1069 McpStartupUpdate { update: McpStartupUpdateEvent },
1071 McpStartupComplete { summary: McpStartupCompleteEvent },
1073 McpToolCallBegin {
1075 server_name: String,
1076 tool_name: String,
1077 },
1078 McpToolCallEnd {
1080 server_name: String,
1081 tool_name: String,
1082 ok: bool,
1083 },
1084 ExecApprovalRequest { request: ExecApprovalRequestEvent },
1086 ApplyPatchApprovalRequest { request: ExecApprovalRequestEvent },
1088 UserInputRequest { request: UserInputRequestEvent },
1093 ElicitationRequest {
1095 server_name: String,
1096 request_id: String,
1097 prompt: String,
1098 },
1099 ExecCommandBegin { command: String, cwd: String },
1101 ExecCommandOutputDelta { command: String, delta: String },
1103 ExecCommandEnd { command: String, exit_code: i32 },
1105 PatchApplyBegin { path: String },
1107 PatchApplyEnd { path: String, ok: bool },
1109 TurnStarted { turn_id: String },
1111 TurnComplete { turn_id: String },
1113 TurnAborted { turn_id: String, reason: String },
1115 ThreadGoalUpdated { goal: ThreadGoal },
1117 ThreadGoalCleared { thread_id: String },
1119 Error {
1121 response_id: String,
1122 message: String,
1123 },
1124}
1125
1126pub mod request;
1127pub mod role;
1128
1129pub mod cloud_facts;
1131
1132pub mod display;