agentmux_srv/server/app_api/
agent_quit.rs1use super::*;
11use crate::sagas::self_quit::{self, QuitOrigin};
12
13pub(crate) const ENDING_AN_AGENT_IS_THE_PERSONS: &str =
15 "only the person shuts an agent down from its composer or menu: an agent stops another with Agents stop, which lets the person keep it running";
16
17fn summary_of(result: Result<self_quit::QuitSummary, String>) -> Result<serde_json::Value, String> {
18 result.map(|summary| serde_json::to_value(&summary).unwrap_or_default())
19}
20
21pub fn register(engine: &Arc<WshRpcEngine>, state: &AppState) {
22 let quit_state = state.clone();
23 engine.register_typed(COMMAND_AGENT_QUIT, move |cmd: CommandAgentQuitData, ctx| {
24 let state = quit_state.clone();
25 async move {
26 ctx.operator_only(ENDING_AN_AGENT_IS_THE_PERSONS)?;
27 summary_of(self_quit::run(&state, &cmd.blockid, QuitOrigin::UserSlash).await)
28 }
29 });
30 let shutdown_state = state.clone();
31 engine.register_typed(COMMAND_AGENT_SHUTDOWN, move |cmd: CommandAgentShutdownData, ctx| {
32 let state = shutdown_state.clone();
33 async move {
34 ctx.operator_only(ENDING_AN_AGENT_IS_THE_PERSONS)?;
35 let stop_background = cmd.stop_background.unwrap_or(false);
36 summary_of(self_quit::run_shutdown(&state, &cmd.blockid, QuitOrigin::UserMenu, stop_background).await)
37 }
38 });
39}