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 SetTranscriptSource { cli_session_id: String },
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
137#[serde(tag = "type", rename_all = "snake_case")]
138pub enum WorkerToDaemon {
139 Ready {
140 zellij_session: String,
141 },
142 PromptReady,
143 ScreenUpdate {
144 content: String,
145 status: ScreenStatus,
146 #[serde(default)]
147 usage_limit: Option<CliUsageLimitState>,
148 },
149 ScreenshotUploaded {
150 image_key: String,
151 status: ScreenStatus,
152 #[serde(default)]
153 usage_limit: Option<CliUsageLimitState>,
154 },
155 CliSessionId {
156 cli_session_id: String,
157 },
158 CliExit {
159 code: Option<i32>,
160 signal: Option<String>,
161 },
162 TuiPrompt {
163 description: String,
164 options: Vec<TuiPromptOption>,
165 #[serde(default)]
166 multi_select: bool,
167 },
168 TuiPromptResolved {
169 #[serde(default)]
170 selected_text: Option<String>,
171 },
172 FinalOutput {
173 content: String,
174 turn_id: String,
175 #[serde(default)]
176 kind: Option<FinalOutputKind>,
177 #[serde(default)]
178 user_text: Option<String>,
179 },
180 AdoptPreamble {
181 user_text: String,
182 assistant_text: String,
183 },
184 UserNotify {
185 message: String,
186 },
187 TranscriptChoices {
188 candidates: Vec<TranscriptChoice>,
189 turn_id: String,
190 },
191 Error {
192 message: String,
193 },
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
198pub struct TranscriptChoice {
199 pub session_id: String,
200 pub label: String,
201}