Skip to main content

agentmux_srv_core/backend/
account_availability.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! What the account episodes (`server/account_episodes`) publish and the layers below the
5//! server read: the `accountavailability` event with the agents and tasks it names, and the
6//! question "does an episode speak for this pane's failure", which the notification router asks
7//! and the server answers once the episodes run.
8
9use std::sync::OnceLock;
10
11use serde::{Deserialize, Serialize};
12
13/// The event an episode's change is published as.
14pub const EVENT_ACCOUNT_AVAILABILITY: &str = "accountavailability";
15
16/// One agent of an episode.
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ts_rs::TS)]
18#[ts(export, export_to = "../../../frontend/types/rpc/")]
19pub struct AccountEpisodeAgent {
20    pub block_id: String,
21    /// Its definition id: the UID a Kanban task's holder carries.
22    pub agent_id: String,
23    pub agent_name: String,
24}
25
26/// A Kanban task an episode's agent holds (claimed, or blocked on a question).
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, ts_rs::TS)]
28#[ts(export, export_to = "../../../frontend/types/rpc/")]
29pub struct AccountEpisodeTask {
30    pub id: String,
31    #[ts(type = "number")]
32    pub number: i64,
33    /// How the task is named: `#12` on the default board, else `work#12`.
34    pub task_ref: String,
35    pub title: String,
36}
37
38/// `accountavailability` (spec §6.1): an episode opened, changed or closed
39/// (`ok`). A signal for the windows, which then read
40/// `identity.account.availability`: it carries no account label and no move
41/// candidates, since any connection can subscribe to an event.
42#[derive(Debug, Clone, PartialEq, Eq, Serialize, ts_rs::TS)]
43#[ts(export, export_to = "../../../frontend/types/rpc/")]
44pub struct AccountAvailabilityEvent {
45    pub account_id: String,
46    pub provider: String,
47    #[ts(type = r#""limited" | "signed_out" | "ok""#)]
48    pub state: String,
49    #[ts(type = "number | null")]
50    pub resets_at_ms: Option<u64>,
51    pub agents: Vec<AccountEpisodeAgent>,
52    pub tasks: Vec<AccountEpisodeTask>,
53}
54
55static COVERS_BLOCK: OnceLock<fn(&str) -> bool> = OnceLock::new();
56
57/// Sets the answer to [`covers_block`]; the server calls it once at startup.
58pub fn set_covers_block(f: fn(&str) -> bool) {
59    let _ = COVERS_BLOCK.set(f);
60}
61
62/// Whether an account episode speaks for this pane's failure, so its own `AgentCrashed` or
63/// "finished" toast is left out (spec §6.2). `false` until the episodes run.
64pub fn covers_block(block_id: &str) -> bool {
65    COVERS_BLOCK.get().is_some_and(|f| f(block_id))
66}