Skip to main content

agentmux_srv/server/agent_handlers/
endpoint.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `undoagentendpoint`: the Undo on the notice for a changed model server (`backend/endpoint_notice.rs`).
5//! It puts the agent's environment back as it was, while the notice's window is open and the environment is
6//! unchanged since (`app_api::agent_env::undo_endpoint`).
7
8use std::sync::Arc;
9
10use crate::backend::rpc::engine::WshRpcEngine;
11use crate::backend::rpc_types::{CommandUndoAgentEndpointData, UndoAgentEndpointResult, COMMAND_UNDO_AGENT_ENDPOINT};
12
13use super::super::AppState;
14
15pub fn register(engine: &Arc<WshRpcEngine>, state: &AppState) {
16    let state = state.clone();
17    engine.register_typed(COMMAND_UNDO_AGENT_ENDPOINT, move |cmd: CommandUndoAgentEndpointData, _ctx| {
18        let state = state.clone();
19        async move {
20            let result = tokio::task::spawn_blocking(move || crate::server::app_api::agent_env::undo_endpoint(&state, &cmd.notice_id, "you"))
21                .await
22                .map_err(|e| format!("undoagentendpoint: {e}"))?;
23            Ok(match result {
24                Ok(()) => UndoAgentEndpointResult { restored: true, reason: None },
25                Err(why) => UndoAgentEndpointResult { restored: false, reason: Some(why) },
26            })
27        }
28    });
29}