Skip to main content

beam_core/
session.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::ipc::{CliUsageLimitState, DisplayMode, ScreenStatus};
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(rename_all = "snake_case")]
8pub enum SessionScope {
9    Thread,
10    Chat,
11}
12
13#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(rename_all = "snake_case")]
15pub enum ChatMode {
16    Group,
17    Topic,
18    P2p,
19}
20
21impl From<&str> for ChatMode {
22    fn from(value: &str) -> Self {
23        match value {
24            "p2p" | "P2P" => ChatMode::P2p,
25            "topic" | "TOPIC" => ChatMode::Topic,
26            _ => ChatMode::Group,
27        }
28    }
29}
30
31impl Default for SessionScope {
32    fn default() -> Self {
33        Self::Thread
34    }
35}
36
37#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
38#[serde(rename_all = "snake_case")]
39pub enum SessionStatus {
40    Active,
41    Closed,
42}
43
44impl Default for SessionStatus {
45    fn default() -> Self {
46        Self::Active
47    }
48}
49
50#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
51#[serde(rename_all = "snake_case")]
52pub enum PendingResponseCardState {
53    Open,
54    Patched,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
58pub struct AdoptedFrom {
59    #[serde(default)]
60    pub tmux_target: Option<String>,
61    #[serde(default)]
62    pub zellij_session: Option<String>,
63    #[serde(default)]
64    pub zellij_pane_id: Option<String>,
65    pub original_cli_pid: i32,
66    #[serde(default)]
67    pub session_id: Option<String>,
68    #[serde(default)]
69    pub cli_id: Option<String>,
70    pub cwd: String,
71    #[serde(default)]
72    pub pane_cols: Option<u16>,
73    #[serde(default)]
74    pub pane_rows: Option<u16>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
78pub struct Session {
79    pub session_id: String,
80    pub title: String,
81    pub chat_id: String,
82    pub root_message_id: String,
83    #[serde(default)]
84    pub chat_type: Option<String>,
85    #[serde(default)]
86    pub quote_target_id: Option<String>,
87    #[serde(default)]
88    pub scope: SessionScope,
89    #[serde(default)]
90    pub status: SessionStatus,
91    pub created_at: DateTime<Utc>,
92    #[serde(default)]
93    pub closed_at: Option<DateTime<Utc>>,
94    #[serde(default)]
95    pub working_dir: Option<String>,
96    pub lark_app_id: String,
97    #[serde(default)]
98    pub owner_open_id: Option<String>,
99    #[serde(default)]
100    pub worker_pid: Option<u32>,
101    #[serde(default)]
102    pub cli_id: Option<String>,
103    #[serde(default)]
104    pub cli_bin: Option<String>,
105    #[serde(default)]
106    pub cli_args: Vec<String>,
107    #[serde(default)]
108    pub cli_session_id: Option<String>,
109    #[serde(default)]
110    pub last_cli_input: Option<String>,
111    #[serde(default)]
112    pub stream_card_id: Option<String>,
113    #[serde(default)]
114    pub stream_card_nonce: Option<String>,
115    #[serde(default)]
116    pub display_mode: Option<DisplayMode>,
117    #[serde(default)]
118    pub current_screen: Option<String>,
119    #[serde(default)]
120    pub last_screen_status: Option<ScreenStatus>,
121    #[serde(default)]
122    pub usage_limit: Option<CliUsageLimitState>,
123    #[serde(default)]
124    pub current_image_key: Option<String>,
125    #[serde(default)]
126    pub tui_prompt_card_id: Option<String>,
127    #[serde(default)]
128    pub tui_prompt_options: Vec<crate::ipc::TuiPromptOption>,
129    #[serde(default)]
130    pub tui_prompt_multi_select: Option<bool>,
131    #[serde(default)]
132    pub tui_toggled_indices: Vec<usize>,
133    #[serde(default)]
134    pub pending_response_card_id: Option<String>,
135    #[serde(default)]
136    pub pending_response_card_state: Option<PendingResponseCardState>,
137    #[serde(default)]
138    pub last_patched_response_card_id: Option<String>,
139    #[serde(default)]
140    pub terminal_url: Option<String>,
141    #[serde(default)]
142    pub last_final_output_turn_id: Option<String>,
143    #[serde(default)]
144    pub last_final_output: Option<String>,
145    #[serde(default)]
146    pub adopted_from: Option<AdoptedFrom>,
147    #[serde(default)]
148    pub model: Option<String>,
149    #[serde(default)]
150    pub locale: Option<String>,
151    #[serde(default)]
152    pub bot_name: Option<String>,
153    #[serde(default)]
154    pub bot_open_id: Option<String>,
155    #[serde(default)]
156    pub resume_session_id: Option<String>,
157    #[serde(default)]
158    pub disable_cli_bypass: bool,
159    #[serde(default)]
160    pub initial_prompt: Option<String>,
161    /// Feishu thread_id (omt_*), stable topic identifier.
162    /// Present for topic-group messages and p2p thread follow-ups that carry
163    /// thread metadata.  Used as the session-matching anchor for Thread-scoped
164    /// sessions.  For p2p, thread_id may be backfilled from a follow-up message
165    /// after the initial session is created (first p2p session starts with
166    /// thread_id=None and matches follow-ups via root_message_id).
167    #[serde(default)]
168    pub thread_id: Option<String>,
169}