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 placement;
21pub mod runtime;
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 {
189 session: Value,
190 expected_document_digest: String,
191 },
192}
193
194#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
195#[serde(rename_all = "snake_case")]
196pub enum CanonicalThreadOperationKind {
197 Create,
198 Resume,
199 Fork,
200}
201
202#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
203#[serde(deny_unknown_fields)]
204pub struct CanonicalThreadOperationAssociation {
205 pub kind: CanonicalThreadOperationKind,
206 pub source_runtime_thread_id: Option<String>,
207 pub source_session_id: Option<String>,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize)]
211#[serde(deny_unknown_fields)]
212pub struct CanonicalThreadOperationLookup {
213 pub version: u32,
214 pub operation_key: String,
215 pub expected_data_dir: PathBuf,
216 pub expected_execution_scope: String,
217 pub workspace: PathBuf,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(deny_unknown_fields)]
223pub struct CanonicalThreadOperationRecovery {
224 pub operation: CanonicalThreadOperationLookup,
225 pub association: CanonicalThreadOperationAssociation,
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize)]
229#[serde(tag = "state", rename_all = "snake_case", deny_unknown_fields)]
230pub enum CanonicalThreadOperationStatus {
231 Absent,
232 Pending {
233 receipt: CanonicalThreadReceipt,
234 association: CanonicalThreadOperationAssociation,
235 },
236 Committed {
237 receipt: CanonicalThreadReceipt,
238 association: CanonicalThreadOperationAssociation,
239 },
240}
241
242#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
245#[serde(deny_unknown_fields)]
246pub struct RuntimeOwnerReceipt {
247 pub version: u32,
248 pub data_dir: PathBuf,
249 pub execution_scope: String,
250 pub lease_generation: String,
251 pub pid: u32,
252 pub process_start: String,
253 pub principal: String,
254 pub socket_path: PathBuf,
255 pub config_path: Option<PathBuf>,
256}
257
258#[derive(Debug, Clone, Serialize, Deserialize)]
259pub struct Envelope<T> {
260 pub request_id: String,
261 #[serde(skip_serializing_if = "Option::is_none")]
262 pub thread_id: Option<String>,
263 pub body: T,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
267#[serde(rename_all = "snake_case")]
268pub enum ThreadStatus {
269 Running,
270 Idle,
271 Completed,
272 Failed,
273 Paused,
274 Archived,
275}
276
277impl Status for ThreadStatus {
278 fn is_terminal(&self) -> bool {
279 matches!(self, Self::Completed | Self::Failed | Self::Archived)
280 }
281 fn is_active(&self) -> bool {
282 matches!(self, Self::Running)
283 }
284 fn is_paused(&self) -> bool {
285 matches!(self, Self::Paused)
286 }
287}
288
289#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
290#[serde(rename_all = "snake_case")]
291pub enum SessionSource {
292 Interactive,
293 Resume,
294 Fork,
295 Api,
296 Unknown,
297}
298
299#[derive(Debug, Clone, Serialize, Deserialize)]
300pub struct Thread {
301 pub id: String,
302 pub preview: String,
303 pub ephemeral: bool,
304 pub model_provider: String,
305 pub created_at: i64,
306 pub updated_at: i64,
307 pub status: ThreadStatus,
308 #[serde(skip_serializing_if = "Option::is_none")]
309 pub path: Option<PathBuf>,
310 pub cwd: PathBuf,
311 pub cli_version: String,
312 pub source: SessionSource,
313 #[serde(skip_serializing_if = "Option::is_none")]
314 pub name: Option<String>,
315}
316
317#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
318#[serde(rename_all = "snake_case")]
319pub enum ThreadGoalStatus {
320 Active,
321 Paused,
322 Blocked,
323 UsageLimited,
324 BudgetLimited,
325 Complete,
326}
327
328impl Status for ThreadGoalStatus {
329 fn is_terminal(&self) -> bool {
330 matches!(self, Self::Complete)
331 }
332 fn is_active(&self) -> bool {
333 matches!(self, Self::Active)
334 }
335 fn is_paused(&self) -> bool {
336 matches!(self, Self::Paused)
337 }
338}
339
340#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
341pub struct ThreadGoal {
342 pub thread_id: String,
343 pub goal_id: String,
344 pub objective: String,
345 pub status: ThreadGoalStatus,
346 #[serde(skip_serializing_if = "Option::is_none")]
347 pub token_budget: Option<i64>,
348 pub tokens_used: i64,
349 pub time_used_seconds: i64,
350 pub continuation_count: i64,
351 pub created_at: i64,
352 pub updated_at: i64,
353 #[serde(default, skip_serializing_if = "Option::is_none")]
354 pub last_gap_fingerprint: Option<String>,
355 #[serde(default)]
356 pub repeated_gap_count: u32,
357 #[serde(default, skip_serializing_if = "Option::is_none")]
358 pub last_gap_pass: Option<u32>,
359 #[serde(default, skip_serializing_if = "Option::is_none")]
360 pub pause_reason: Option<GoalPauseReason>,
361}
362
363#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
365#[serde(rename_all = "snake_case")]
366pub enum GoalPauseReason {
367 User,
368 Backoff,
369 NoProgress,
370 UsageLimit,
371 BudgetLimit,
372 Yielded,
377 #[serde(other)]
382 Unrecognized,
383}
384
385impl GoalPauseReason {
386 #[must_use]
387 pub fn label(self) -> &'static str {
388 match self {
389 Self::User => "user",
390 Self::Backoff => "run limit",
391 Self::NoProgress => "no progress",
392 Self::UsageLimit => "usage limit",
393 Self::BudgetLimit => "budget limit",
394 Self::Yielded => "handed back",
395 Self::Unrecognized => "unrecognized",
396 }
397 }
398}
399
400pub const MAX_REPEATED_GAP_COUNT: u32 = 3;
403
404pub fn validate_goal_stall_state(
405 fingerprint: Option<&str>,
406 count: u32,
407 pass: Option<u32>,
408 continuation_count: u32,
409) -> Result<(), &'static str> {
410 match (fingerprint, count, pass) {
411 (None, 0, None) => Ok(()),
412 (Some(digest), 1..=MAX_REPEATED_GAP_COUNT, Some(pass))
413 if digest.len() == 64
414 && digest.bytes().all(|byte| byte.is_ascii_hexdigit())
415 && pass <= continuation_count
416 && count <= pass.saturating_add(1) =>
417 {
418 Ok(())
419 }
420 _ => Err("invalid persisted goal stall history"),
421 }
422}
423
424impl ThreadGoal {
425 pub fn validate_stall_state(&self) -> Result<(), &'static str> {
426 validate_goal_stall_state(
427 self.last_gap_fingerprint.as_deref(),
428 self.repeated_gap_count,
429 self.last_gap_pass,
430 u32::try_from(self.continuation_count.max(0)).unwrap_or(u32::MAX),
431 )
432 }
433
434 pub fn normalize_restored_stall_state(&mut self) -> bool {
440 if matches!(self.status, ThreadGoalStatus::Active)
441 && self.repeated_gap_count >= MAX_REPEATED_GAP_COUNT
442 {
443 self.status = ThreadGoalStatus::Paused;
444 self.pause_reason = Some(GoalPauseReason::NoProgress);
445 true
446 } else {
447 false
448 }
449 }
450}
451
452#[derive(Debug, Clone, Serialize, Deserialize)]
453pub struct ThreadStartParams {
454 #[serde(default, skip_serializing_if = "Option::is_none")]
456 pub operation_key: Option<String>,
457 #[serde(skip_serializing_if = "Option::is_none")]
458 pub model: Option<String>,
459 #[serde(skip_serializing_if = "Option::is_none")]
460 pub model_provider: Option<String>,
461 #[serde(skip_serializing_if = "Option::is_none")]
462 pub cwd: Option<PathBuf>,
463 #[serde(default)]
464 pub persist_extended_history: bool,
465}
466
467#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct ThreadResumeParams {
469 #[serde(default, skip_serializing_if = "Option::is_none")]
471 pub operation_key: Option<String>,
472 pub thread_id: String,
473 #[serde(skip_serializing_if = "Option::is_none")]
474 pub history: Option<Vec<Value>>,
475 #[serde(skip_serializing_if = "Option::is_none")]
476 pub path: Option<PathBuf>,
477 #[serde(skip_serializing_if = "Option::is_none")]
478 pub model: Option<String>,
479 #[serde(skip_serializing_if = "Option::is_none")]
480 pub model_provider: Option<String>,
481 #[serde(skip_serializing_if = "Option::is_none")]
482 pub cwd: Option<PathBuf>,
483 #[serde(skip_serializing_if = "Option::is_none")]
484 pub approval_policy: Option<String>,
485 #[serde(skip_serializing_if = "Option::is_none")]
486 pub sandbox: Option<String>,
487 #[serde(skip_serializing_if = "Option::is_none")]
488 pub config: Option<Value>,
489 #[serde(skip_serializing_if = "Option::is_none")]
490 pub base_instructions: Option<String>,
491 #[serde(skip_serializing_if = "Option::is_none")]
492 pub developer_instructions: Option<String>,
493 #[serde(skip_serializing_if = "Option::is_none")]
494 pub personality: Option<String>,
495 #[serde(default)]
496 pub persist_extended_history: bool,
497}
498
499#[derive(Debug, Clone, Serialize, Deserialize)]
500pub struct ThreadForkParams {
501 #[serde(default, skip_serializing_if = "Option::is_none")]
503 pub operation_key: Option<String>,
504 pub thread_id: String,
505 #[serde(skip_serializing_if = "Option::is_none")]
506 pub path: Option<PathBuf>,
507 #[serde(skip_serializing_if = "Option::is_none")]
508 pub model: Option<String>,
509 #[serde(skip_serializing_if = "Option::is_none")]
510 pub model_provider: Option<String>,
511 #[serde(skip_serializing_if = "Option::is_none")]
512 pub cwd: Option<PathBuf>,
513 #[serde(skip_serializing_if = "Option::is_none")]
514 pub approval_policy: Option<String>,
515 #[serde(skip_serializing_if = "Option::is_none")]
516 pub sandbox: Option<String>,
517 #[serde(skip_serializing_if = "Option::is_none")]
518 pub config: Option<Value>,
519 #[serde(skip_serializing_if = "Option::is_none")]
520 pub base_instructions: Option<String>,
521 #[serde(skip_serializing_if = "Option::is_none")]
522 pub developer_instructions: Option<String>,
523 #[serde(default)]
524 pub persist_extended_history: bool,
525}
526
527#[derive(Debug, Clone, Serialize, Deserialize)]
528pub struct ThreadListParams {
529 #[serde(default)]
530 pub include_archived: bool,
531 #[serde(skip_serializing_if = "Option::is_none")]
532 pub limit: Option<usize>,
533}
534
535#[derive(Debug, Clone, Serialize, Deserialize)]
536pub struct ThreadReadParams {
537 pub thread_id: String,
538}
539
540#[derive(Debug, Clone, Serialize, Deserialize)]
541pub struct ThreadSetNameParams {
542 pub thread_id: String,
543 pub name: String,
544}
545
546#[derive(Debug, Clone, Serialize, Deserialize)]
547pub struct ThreadGoalSetParams {
548 pub thread_id: String,
549 pub objective: String,
550 #[serde(skip_serializing_if = "Option::is_none")]
551 pub token_budget: Option<i64>,
552}
553
554#[derive(Debug, Clone, Serialize, Deserialize)]
555pub struct ThreadGoalGetParams {
556 pub thread_id: String,
557}
558
559#[derive(Debug, Clone, Serialize, Deserialize)]
560pub struct ThreadGoalClearParams {
561 pub thread_id: String,
562}
563
564#[derive(Debug, Clone, Serialize, Deserialize)]
565pub struct ThreadGoalProgressParams {
566 pub thread_id: String,
567 #[serde(default)]
568 pub token_delta: i64,
569 #[serde(default)]
570 pub time_delta_seconds: i64,
571 #[serde(default)]
572 pub record_continuation: bool,
573}
574
575#[derive(Debug, Clone, Serialize, Deserialize)]
576#[serde(tag = "kind", rename_all = "snake_case")]
577pub enum ThreadRequest {
578 Create {
579 #[serde(default)]
580 metadata: Value,
581 },
582 Start(ThreadStartParams),
583 Resume(ThreadResumeParams),
584 Fork(ThreadForkParams),
585 List(ThreadListParams),
586 Read(ThreadReadParams),
587 SetName(ThreadSetNameParams),
588 GoalSet(ThreadGoalSetParams),
589 GoalGet(ThreadGoalGetParams),
590 GoalClear(ThreadGoalClearParams),
591 GoalRecordProgress(ThreadGoalProgressParams),
592 Archive {
593 thread_id: String,
594 },
595 Unarchive {
596 thread_id: String,
597 },
598 Message {
599 thread_id: String,
600 input: String,
601 #[serde(default, skip_serializing_if = "Option::is_none")]
602 allowed_tools: Option<Vec<String>>,
603 #[serde(default, skip_serializing_if = "Vec::is_empty")]
604 images: Vec<runtime::RuntimeImageInput>,
605 #[serde(
606 default,
607 rename = "maxOutputTokens",
608 alias = "max_output_tokens",
609 skip_serializing_if = "Option::is_none"
610 )]
611 max_output_tokens: Option<std::num::NonZeroU32>,
612 },
613}
614
615#[derive(Debug, Clone, Serialize, Deserialize)]
617pub struct ThreadResponse {
618 pub thread_id: String,
620 pub status: String,
622 #[serde(skip_serializing_if = "Option::is_none")]
624 pub thread: Option<Thread>,
625 #[serde(default)]
627 pub threads: Vec<Thread>,
628 #[serde(skip_serializing_if = "Option::is_none")]
630 pub goal: Option<ThreadGoal>,
631 #[serde(skip_serializing_if = "Option::is_none")]
633 pub model: Option<String>,
634 #[serde(skip_serializing_if = "Option::is_none")]
636 pub model_provider: Option<String>,
637 #[serde(skip_serializing_if = "Option::is_none")]
639 pub cwd: Option<PathBuf>,
640 #[serde(skip_serializing_if = "Option::is_none")]
642 pub approval_policy: Option<String>,
643 #[serde(skip_serializing_if = "Option::is_none")]
645 pub sandbox: Option<String>,
646 #[serde(default)]
648 pub events: Vec<EventFrame>,
649 #[serde(default)]
651 pub data: Value,
652}
653
654#[derive(Debug, Clone, Serialize, Deserialize)]
656#[serde(tag = "kind", rename_all = "snake_case")]
657pub enum AppRequest {
658 Capabilities,
660 ConfigGet { key: String },
662 ConfigSet { key: String, value: String },
664 ConfigUnset { key: String },
666 ConfigList,
668 ConfigReload,
681 Models,
683 ThreadLoadedList,
685 SubmitUserInput {
690 request_id: String,
691 answers: Vec<UserInputAnswerEvent>,
692 },
693}
694
695#[derive(Debug, Clone, Serialize, Deserialize)]
697pub struct AppResponse {
698 pub ok: bool,
700 pub data: Value,
702 #[serde(default)]
704 pub events: Vec<EventFrame>,
705}
706
707#[derive(Debug, Clone, Serialize, Deserialize)]
709pub struct PromptRequest {
710 #[serde(default, skip_serializing_if = "Option::is_none")]
711 pub allowed_tools: Option<Vec<String>>,
712 #[serde(
713 default,
714 rename = "maxOutputTokens",
715 alias = "max_output_tokens",
716 skip_serializing_if = "Option::is_none"
717 )]
718 pub max_output_tokens: Option<std::num::NonZeroU32>,
719 #[serde(skip_serializing_if = "Option::is_none")]
721 pub thread_id: Option<String>,
722 pub prompt: String,
724 #[serde(default, skip_serializing_if = "Vec::is_empty")]
725 pub images: Vec<runtime::RuntimeImageInput>,
726 #[serde(skip_serializing_if = "Option::is_none")]
728 pub model: Option<String>,
729}
730
731#[derive(Debug, Clone, Serialize, Deserialize)]
733pub struct PromptResponse {
734 pub output: String,
736 pub model: String,
738 #[serde(default)]
740 pub events: Vec<EventFrame>,
741}
742
743#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
745#[serde(rename_all = "snake_case")]
746pub enum AskForApproval {
747 UnlessTrusted,
749 OnFailure,
751 OnRequest,
753 Reject {
755 sandbox_approval: bool,
756 rules: bool,
757 mcp_elicitations: bool,
758 },
759 Never,
761}
762
763#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
765#[serde(rename_all = "snake_case")]
766pub enum ToolKind {
767 Function,
769 Mcp,
771}
772
773#[derive(Debug, Clone, Serialize, Deserialize)]
775pub struct LocalShellParams {
776 pub command: String,
778 #[serde(skip_serializing_if = "Option::is_none")]
780 pub cwd: Option<String>,
781 #[serde(skip_serializing_if = "Option::is_none")]
783 pub timeout_ms: Option<u64>,
784}
785
786#[derive(Debug, Clone, Serialize, Deserialize)]
788#[serde(tag = "type", rename_all = "snake_case")]
789pub enum ToolPayload {
790 Function { arguments: String },
792 Custom { input: String },
794 LocalShell { params: LocalShellParams },
796 Mcp {
798 server: String,
799 tool: String,
800 raw_arguments: Value,
801 #[serde(skip_serializing_if = "Option::is_none")]
802 raw_tool_call_id: Option<String>,
803 },
804}
805
806#[derive(Debug, Clone, Serialize, Deserialize)]
808#[serde(tag = "type", rename_all = "snake_case")]
809pub enum ToolOutput {
810 Function {
812 #[serde(skip_serializing_if = "Option::is_none")]
814 body: Option<Value>,
815 success: bool,
817 },
818 Mcp {
820 result: Value,
822 },
823}
824
825impl ToolOutput {
826 pub fn success(&self) -> bool {
831 match self {
832 Self::Function { success, .. } => *success,
833 Self::Mcp { result } => {
834 matches!(result.get("isError"), None | Some(Value::Bool(false)))
835 }
836 }
837 }
838}
839
840#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
842#[serde(rename_all = "snake_case")]
843pub enum NetworkPolicyRuleAction {
844 Allow,
846 Deny,
848}
849
850#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
852pub struct NetworkPolicyAmendment {
853 pub host: String,
855 pub action: NetworkPolicyRuleAction,
857}
858
859#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
861#[serde(tag = "type", rename_all = "snake_case")]
862pub enum ReviewDecision {
863 Approved,
865 ApprovedExecpolicyAmendment,
867 ApprovedForSession,
869 NetworkPolicyAmendment {
871 host: String,
872 action: NetworkPolicyRuleAction,
873 },
874 Denied,
876 Abort,
878}
879
880#[derive(Debug, Clone, Serialize, Deserialize)]
882#[serde(rename_all = "snake_case")]
883pub enum McpStartupStatus {
884 Starting,
886 Ready,
888 Failed { error: String },
890 Cancelled,
892}
893
894#[derive(Debug, Clone, Serialize, Deserialize)]
896pub struct McpStartupUpdateEvent {
897 pub server_name: String,
899 pub status: McpStartupStatus,
901}
902
903#[derive(Debug, Clone, Serialize, Deserialize)]
905pub struct McpStartupFailure {
906 pub server_name: String,
908 pub error: String,
910}
911
912#[derive(Debug, Clone, Serialize, Deserialize)]
914pub struct McpStartupCompleteEvent {
915 pub ready: Vec<String>,
917 pub failed: Vec<McpStartupFailure>,
919 pub cancelled: Vec<String>,
921}
922
923#[derive(Debug, Clone, Serialize, Deserialize)]
925pub struct NetworkApprovalContext {
926 pub host: String,
928 pub protocol: String,
930}
931
932#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
939pub struct UserInputOptionEvent {
940 pub label: String,
942 pub description: String,
944}
945
946#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
948pub struct UserInputQuestionEvent {
949 pub header: String,
951 pub id: String,
953 pub question: String,
955 pub options: Vec<UserInputOptionEvent>,
957 #[serde(default)]
959 pub allow_free_text: bool,
960 #[serde(default)]
962 pub multi_select: bool,
963}
964
965#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
971pub struct UserInputRequestEvent {
972 pub call_id: String,
974 pub turn_id: String,
976 pub request_id: String,
978 pub questions: Vec<UserInputQuestionEvent>,
980}
981
982#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
984pub struct UserInputAnswerEvent {
985 pub id: String,
987 pub label: String,
989 pub value: String,
991}
992
993#[derive(Debug, Clone, Serialize, Deserialize)]
995pub struct ExecApprovalRequestEvent {
996 pub call_id: String,
998 pub approval_id: String,
1000 pub turn_id: String,
1002 pub command: String,
1004 pub cwd: String,
1006 pub reason: String,
1008 #[serde(default, skip_serializing_if = "Option::is_none")]
1010 pub matched_rule: Option<Box<str>>,
1011 #[serde(skip_serializing_if = "Option::is_none")]
1013 pub network_approval_context: Option<NetworkApprovalContext>,
1014 #[serde(default)]
1016 pub proposed_execpolicy_amendment: Vec<String>,
1017 #[serde(default)]
1019 pub proposed_network_policy_amendments: Vec<NetworkPolicyAmendment>,
1020 #[serde(default)]
1022 pub additional_permissions: Vec<String>,
1023 #[serde(default)]
1025 pub available_decisions: Vec<ReviewDecision>,
1026}
1027
1028#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
1030#[serde(rename_all = "snake_case")]
1031pub enum ResponseChannel {
1032 #[default]
1034 Text,
1035 Reasoning,
1037}
1038
1039impl ResponseChannel {
1040 pub const fn is_text(&self) -> bool {
1042 matches!(self, ResponseChannel::Text)
1043 }
1044}
1045
1046#[derive(Debug, Clone, Serialize, Deserialize)]
1048pub struct ApprovalDecisionRequest {
1049 pub decision: String,
1051 #[serde(default)]
1053 pub remember: bool,
1054}
1055
1056#[derive(Debug, Clone, Serialize, Deserialize)]
1062#[serde(tag = "event", rename_all = "snake_case")]
1063pub enum EventFrame {
1064 ResponseStart { response_id: String },
1066 ResponseDelta {
1068 response_id: String,
1069 delta: String,
1070 #[serde(default, skip_serializing_if = "ResponseChannel::is_text")]
1071 channel: ResponseChannel,
1072 },
1073 ResponseEnd { response_id: String },
1075 ToolCallStart {
1077 response_id: String,
1078 tool_name: String,
1079 arguments: Value,
1080 },
1081 ToolCallResult {
1083 response_id: String,
1084 tool_name: String,
1085 output: Value,
1086 },
1087 McpStartupUpdate { update: McpStartupUpdateEvent },
1089 McpStartupComplete { summary: McpStartupCompleteEvent },
1091 McpToolCallBegin {
1093 server_name: String,
1094 tool_name: String,
1095 },
1096 McpToolCallEnd {
1098 server_name: String,
1099 tool_name: String,
1100 ok: bool,
1101 },
1102 ExecApprovalRequest { request: ExecApprovalRequestEvent },
1104 ApplyPatchApprovalRequest { request: ExecApprovalRequestEvent },
1106 UserInputRequest { request: UserInputRequestEvent },
1111 ElicitationRequest {
1113 server_name: String,
1114 request_id: String,
1115 prompt: String,
1116 },
1117 ExecCommandBegin { command: String, cwd: String },
1119 ExecCommandOutputDelta { command: String, delta: String },
1121 ExecCommandEnd { command: String, exit_code: i32 },
1123 PatchApplyBegin { path: String },
1125 PatchApplyEnd { path: String, ok: bool },
1127 TurnStarted { turn_id: String },
1129 TurnComplete { turn_id: String },
1131 TurnAborted { turn_id: String, reason: String },
1133 ThreadGoalUpdated { goal: ThreadGoal },
1135 ThreadGoalCleared { thread_id: String },
1137 Error {
1139 response_id: String,
1140 message: String,
1141 },
1142}
1143
1144pub mod request;
1145pub mod role;
1146
1147pub mod cloud_facts;
1149
1150pub mod display;