Skip to main content

agentmux_srv_core/backend/
prompt_events.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The events that put a countdown or a question in front of the person (a sensitive request's countdown, an
5//! agent's start notice, a pane's question), and the names they go out under. They live in the core so
6//! `backend/mps_events.rs` names them without reaching up into `sagas/`; the sagas re-export them under their
7//! old paths. The wire shape is pinned by `sagas/prompt_events_tests.rs`.
8
9use serde::Serialize;
10
11pub const EVENT_SENSITIVE_PENDING: &str = "sensitive:pending";
12pub const EVENT_SENSITIVE_CLEARED: &str = "sensitive:cleared";
13pub const EVENT_AGENT_NOTICE: &str = "agent:notice";
14pub const EVENT_AGENT_GRANTS: &str = "agent:grants";
15pub const EVENT_PANE_CONFIRM: &str = "pane:confirm";
16
17/// A countdown as the person's banner shows it.
18#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
19#[ts(export, export_to = "../../../frontend/types/rpc/")]
20pub struct SensitiveView {
21    pub request_id: String,
22    pub op: String,
23    /// What will happen, built by AgentMux from the request's facts.
24    pub summary: String,
25    /// The words of its two buttons: the cancel and the do-it-now (`OpSpec`).
26    pub cancel_label: String,
27    pub now_label: String,
28    /// The agent that asked.
29    pub requester: String,
30    /// The super agent that approved it; absent when none reviewed it.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    #[ts(optional)]
33    pub approver: Option<String>,
34    #[ts(type = "number")]
35    pub deadline_ms: i64,
36    /// When the countdown began. A window that connects later is replayed the countdowns still
37    /// running; this is what tells those from a new one.
38    #[ts(type = "number")]
39    pub opened_ms: i64,
40    /// `pending` → `vetoed` or `cancelled`, or `proceeding` → `done` / `failed`.
41    #[ts(type = r#""pending" | "vetoed" | "cancelled" | "proceeding" | "done" | "failed""#)]
42    pub status: &'static str,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[ts(optional)]
45    pub error: Option<String>,
46}
47
48/// `sensitive:cleared`: the countdown ended, and how.
49#[derive(Clone, Debug, Serialize, ts_rs::TS)]
50#[ts(export, export_to = "../../../frontend/types/rpc/")]
51pub struct SensitiveClearedEvent {
52    pub request_id: String,
53    pub outcome: String,
54}
55
56/// A notice as the pane draws it: a one-line `line`, a `pending` card with a countdown, or the end
57/// of a card (`cleared`, with its `outcome`).
58#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
59#[ts(export, export_to = "../../../frontend/types/rpc/")]
60pub struct NoticeView {
61    pub id: String,
62    /// `github` and `aws` are a container agent refused a credential (`sagas::credential_notice`): a line with
63    /// no countdown and no buttons, kept until the credential works again.
64    #[ts(type = r#""spawn" | "ssh" | "google" | "memory" | "github" | "aws""#)]
65    pub kind: &'static str,
66    pub block_id: String,
67    pub agent: String,
68    pub headline: String,
69    pub body: String,
70    /// The agent's own words, for the quote.
71    pub quote: String,
72    /// The Always button's words; empty when there is none.
73    pub always_label: String,
74    /// When the countdown ends; 0 for a line.
75    #[ts(type = "number")]
76    pub deadline_ms: i64,
77    #[ts(type = "number")]
78    pub opened_ms: i64,
79    #[ts(type = r#""pending" | "line" | "cleared""#)]
80    pub status: &'static str,
81    /// For `cleared`: `stopped`, `now`, `always`, `deadline` or `gone`.
82    pub outcome: String,
83}
84
85/// `agent:grants`: the agents with an "Always" for `topic`, after a change.
86#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
87#[ts(export, export_to = "../../../frontend/types/rpc/")]
88pub struct GrantsEvent {
89    #[ts(type = r#""spawn" | "google" | "memory""#)]
90    pub topic: &'static str,
91    pub agents: Vec<String>,
92}
93
94/// A question as the pane draws it: `pending`, or its end (`cleared`).
95#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
96#[ts(export, export_to = "../../../frontend/types/rpc/")]
97pub struct PaneConfirmView {
98    pub id: String,
99    pub block_id: String,
100    pub title: String,
101    pub message: String,
102    pub ok_label: String,
103    pub cancel_label: String,
104    pub destructive: bool,
105    /// The tick box's words; empty when there is none.
106    pub checkbox: String,
107    /// When srv stops waiting for the answer.
108    #[ts(type = "number")]
109    pub deadline_ms: i64,
110    #[ts(type = r#""pending" | "cleared""#)]
111    pub status: &'static str,
112}