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