agentmux_srv\reducer/
window.rs1use agentmux_common::ipc::{ErrorCode, Event};
5
6use crate::state::State;
7
8
9use crate::state::WindowRecord;
10
11pub(super) fn handle_create_window(
17 state: &mut State,
18 window_id: String,
19 workspace_id: String,
20) -> Vec<Event> {
21 if !state.workspaces.contains_key(&workspace_id) {
22 let v = state.bump_version();
23 return vec![Event::Error {
24 code: ErrorCode::InvalidCommand,
25 message: format!("CreateWindow: workspace not found: {}", workspace_id),
26 fatal: false,
27 version: v,
28 }];
29 }
30 if let Some(existing) = state.windows.get(&window_id) {
31 if existing.workspace_id == workspace_id {
32 return Vec::new();
33 }
34 }
35 state.windows.insert(
36 window_id.clone(),
37 WindowRecord {
38 window_id: window_id.clone(),
39 workspace_id: workspace_id.clone(),
40 },
41 );
42 let v = state.bump_version();
43 vec![Event::SrvWindowOpened {
44 window_id,
45 workspace_id,
46 version: v,
47 }]
48}
49
50pub(super) fn handle_close_window_internal(state: &mut State, window_id: String) -> Vec<Event> {
53 if state.windows.remove(&window_id).is_none() {
54 return Vec::new();
55 }
56 let v = state.bump_version();
57 vec![Event::SrvWindowClosed {
58 window_id,
59 version: v,
60 }]
61}
62
63pub(super) fn handle_switch_workspace(
67 state: &mut State,
68 window_id: String,
69 workspace_id: String,
70) -> Vec<Event> {
71 if !state.workspaces.contains_key(&workspace_id) {
72 let v = state.bump_version();
73 return vec![Event::Error {
74 code: ErrorCode::InvalidCommand,
75 message: format!(
76 "SwitchWorkspace: destination workspace not found: {}",
77 workspace_id
78 ),
79 fatal: false,
80 version: v,
81 }];
82 }
83 let Some(window) = state.windows.get_mut(&window_id) else {
84 let v = state.bump_version();
85 return vec![Event::Error {
86 code: ErrorCode::InvalidCommand,
87 message: format!("SwitchWorkspace: window not found: {}", window_id),
88 fatal: false,
89 version: v,
90 }];
91 };
92 if window.workspace_id == workspace_id {
93 return Vec::new();
94 }
95 window.workspace_id = workspace_id.clone();
96 let v = state.bump_version();
97 vec![Event::SrvWindowWorkspaceChanged {
98 window_id,
99 workspace_id,
100 version: v,
101 }]
102}
103
104pub(super) fn handle_update_window_meta(
121 state: &mut State,
122 window_id: String,
123 meta_patch: serde_json::Value,
124) -> Vec<Event> {
125 let v = state.bump_version();
126 vec![Event::WindowMetaUpdated {
127 window_id,
128 meta_patch,
129 version: v,
130 }]
131}