Skip to main content

beam_core/
ipc.rs

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        #[serde(default)]
155        turn_id: Option<String>,
156    },
157    CliSessionId {
158        cli_session_id: String,
159    },
160    CliExit {
161        code: Option<i32>,
162        signal: Option<String>,
163    },
164    TuiPrompt {
165        description: String,
166        options: Vec<TuiPromptOption>,
167        #[serde(default)]
168        multi_select: bool,
169    },
170    TuiPromptResolved {
171        #[serde(default)]
172        selected_text: Option<String>,
173    },
174    FinalOutput {
175        content: String,
176        turn_id: String,
177        #[serde(default)]
178        kind: Option<FinalOutputKind>,
179        #[serde(default)]
180        user_text: Option<String>,
181    },
182    AdoptPreamble {
183        user_text: String,
184        assistant_text: String,
185    },
186    UserNotify {
187        message: String,
188    },
189    TranscriptChoices {
190        candidates: Vec<TranscriptChoice>,
191        turn_id: String,
192    },
193    Error {
194        message: String,
195    },
196}
197
198/// A single transcript source candidate for disambiguation.
199#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
200pub struct TranscriptChoice {
201    pub session_id: String,
202    pub label: String,
203}