Skip to main content

agentmux_srv/server/prep/
meta.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The pane meta a pending change shows through. The composer's chip reads it live, and it
5//! outlives a window reload, as the queued account switch's own meta does.
6
7use serde_json::{json, Value};
8
9use crate::backend::blockcontroller;
10use crate::backend::obj;
11use crate::server::AppState;
12
13/// Set each `(key, value)` on every pane in `block_ids` (a `null` value clears the key) and tell the
14/// windows. One pane failing doesn't stop the rest.
15pub(crate) fn set_block_meta(state: &AppState, block_ids: &[&str], updates: &[(&str, Value)]) {
16    let mut update = obj::MetaMapType::new();
17    for (key, value) in updates {
18        update.insert((*key).to_string(), value.clone());
19    }
20    for oid in block_ids {
21        match crate::server::service::update_object_meta(&state.mstore, &format!("block:{oid}"), &update) {
22            Ok(()) => blockcontroller::core::broadcast_block_update(&state.mstore, &state.event_bus, oid),
23            Err(e) => tracing::warn!(block_id = %oid, error = %e, "prep: the pane's meta was not updated"),
24        }
25    }
26}
27
28/// `agent:prep` for a window that is open until `until_ms`.
29pub(super) fn prep_value(id: &str, action: &str, until_ms: u64, extended: bool, why: Option<&str>) -> Value {
30    json!({ "id": id, "action": action, "until_ms": until_ms, "extended": extended, "why": why })
31}