Skip to main content

agentmux_srv/server/remote_ops/
google_ops.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `google.status` and `google.grant` (docs/specs/SPEC_GOOGLE_PHASE_B_AGENTMUXS_OWN_CLIENT_2026_11_01.md ยง7):
5//! which Google accounts are connected here and who holds what, and turning a service of one on or off
6//! for an agent on this machine. Both run the code the `Google` tool's `status` and `grant` run; a grant
7//! is recorded as the remote agent, `slug@machine`, in the account's log and the window notice. `connect`
8//! has no remote form: the sign-in is a person's, at the machine that holds the account.
9
10use serde_json::Value;
11
12use super::{AppState, RemoteCaller, RemoteRefusal, RemoteResult};
13use crate::server::google_handlers::{grant_as, status_for, GrantBody};
14
15/// The connected accounts, what each supports and who holds what. A remote caller has no agent here, so
16/// there is no `yours`.
17pub(super) async fn status(state: &AppState, _caller: &RemoteCaller, _params: Value) -> RemoteResult {
18    status_for(state, None).map_err(RemoteRefusal::failed)
19}
20
21/// Turn a service of an account on (`level` read or write) or off (`off`) for an agent here. A state
22/// change: the transport has already required a certificate from a trusted install for it.
23pub(super) async fn grant(state: &AppState, caller: &RemoteCaller, params: Value) -> RemoteResult {
24    let names_an_agent = params.get("agent").and_then(Value::as_str).is_some_and(|a| !a.trim().is_empty());
25    if !names_an_agent {
26        return Err(RemoteRefusal::new("bad_params", "google.grant: name the agent on this machine (agent): there is no \"yourself\" across machines"));
27    }
28    let body: GrantBody = serde_json::from_value(params).map_err(|e| RemoteRefusal::new("bad_params", format!("google.grant: {e}")))?;
29    let actor = caller.actor();
30    let done = grant_as(state, &actor, &actor, None, &body).map_err(RemoteRefusal::failed)?;
31    tracing::info!(actor = %actor, "remote google.grant: a grant was set");
32    Ok(done)
33}
34
35#[cfg(test)]
36#[path = "google_ops_tests.rs"]
37mod tests;