1use serde::{Deserialize, Serialize};
2
3use crate::{config::ScreenAnalyzerConfig, session::AdoptedFrom};
4
5#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "snake_case")]
7pub enum DisplayMode {
8 Hidden,
9 Screenshot,
10}
11
12#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
13#[serde(rename_all = "snake_case")]
14pub enum ScreenStatus {
15 Starting,
16 Working,
17 Idle,
18 Analyzing,
19 Limited,
20}
21
22#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
23#[serde(rename_all = "snake_case")]
24pub enum CliUsageLimitKind {
25 Usage,
26 Rate,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
30#[serde(rename_all = "camelCase")]
31pub struct CliUsageLimitState {
32 pub limited: bool,
33 pub kind: CliUsageLimitKind,
34 pub retry_at_ms: u64,
35 pub retry_label: String,
36 pub retry_ready: bool,
37}
38
39#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
40#[serde(rename_all = "snake_case")]
41pub enum TermActionKey {
42 Esc,
43 CtrlC,
44 Tab,
45 Enter,
46 Space,
47 Up,
48 Down,
49 Left,
50 Right,
51 HalfPageUp,
52 HalfPageDown,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
56pub struct TuiPromptOption {
57 #[serde(default)]
58 pub label: Option<String>,
59 pub text: String,
60 pub selected: bool,
61 #[serde(rename = "type", default)]
62 pub option_type: Option<String>,
63 #[serde(default)]
64 pub keys: Vec<String>,
65}
66
67#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
68#[serde(rename_all = "snake_case")]
69pub enum FinalOutputKind {
70 Bridge,
71 LocalTurn,
72 LocalTurnHeadless,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
76pub struct InitConfig {
77 pub session_id: String,
78 pub title: String,
79 pub chat_id: String,
80 pub root_message_id: String,
81 pub working_dir: String,
82 pub cli_id: String,
83 pub cli_bin: String,
84 #[serde(default)]
85 pub cli_args: Vec<String>,
86 pub prompt: String,
87 #[serde(default)]
88 pub resume: bool,
89 #[serde(default)]
90 pub cli_session_id: Option<String>,
91 pub lark_app_id: String,
92 pub lark_app_secret: String,
93 #[serde(default)]
94 pub prompt_turn_id: Option<String>,
95 #[serde(default)]
96 pub owner_open_id: Option<String>,
97 #[serde(default)]
98 pub adopted_from: Option<AdoptedFrom>,
99 #[serde(default)]
100 pub adopt_restored_from_metadata: bool,
101 #[serde(default)]
102 pub screen_analyzer: ScreenAnalyzerConfig,
103 #[serde(default)]
104 pub initial_prompt: Option<String>,
105 #[serde(default)]
106 pub model: Option<String>,
107 #[serde(default)]
108 pub locale: Option<String>,
109 #[serde(default)]
110 pub bot_name: Option<String>,
111 #[serde(default)]
112 pub bot_open_id: Option<String>,
113 #[serde(default)]
114 pub resume_session_id: Option<String>,
115 #[serde(default)]
116 pub disable_cli_bypass: bool,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
120#[serde(tag = "type", rename_all = "snake_case")]
121pub enum DaemonToWorker {
122 Init(InitConfig),
123 Message { content: String, turn_id: String },
124 RawInput { content: String, turn_id: String },
125 Close,
126 Restart,
127 SetDisplayMode { mode: DisplayMode },
128 TermAction { key: TermActionKey },
129 SpecialKeys { keys: Vec<String> },
130 TuiKeys { keys: Vec<String>, is_final: bool },
131 TuiTextInput { keys: Vec<String>, text: String },
132 RefreshScreen,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
136#[serde(tag = "type", rename_all = "snake_case")]
137pub enum WorkerToDaemon {
138 Ready {
139 zellij_session: String,
140 },
141 PromptReady,
142 ScreenUpdate {
143 content: String,
144 status: ScreenStatus,
145 #[serde(default)]
146 usage_limit: Option<CliUsageLimitState>,
147 },
148 ScreenshotUploaded {
149 image_key: String,
150 status: ScreenStatus,
151 #[serde(default)]
152 usage_limit: Option<CliUsageLimitState>,
153 },
154 CliSessionId {
155 cli_session_id: String,
156 },
157 CliExit {
158 code: Option<i32>,
159 signal: Option<String>,
160 },
161 TuiPrompt {
162 description: String,
163 options: Vec<TuiPromptOption>,
164 #[serde(default)]
165 multi_select: bool,
166 },
167 TuiPromptResolved {
168 #[serde(default)]
169 selected_text: Option<String>,
170 },
171 FinalOutput {
172 content: String,
173 turn_id: String,
174 #[serde(default)]
175 kind: Option<FinalOutputKind>,
176 #[serde(default)]
177 user_text: Option<String>,
178 },
179 AdoptPreamble {
180 user_text: String,
181 assistant_text: String,
182 },
183 UserNotify {
184 message: String,
185 },
186 Error {
187 message: String,
188 },
189}