Skip to main content

adk_surface/
lib.rs

1//! # adk-surface
2//!
3//! Agent surfaces for ADK-Rust (spec 3.3): one engine under every window a person opens onto
4//! their agents — the web home, the terminal, chat, the phone, the desktop tray, voice.
5//! Nothing lives in a surface: a decision is made once, from anywhere, and every other window
6//! shows who made it.
7//!
8//! ## The engine
9//!
10//! [`SurfaceEngine`] is always compiled. It reads a [`Source`] — an in-process kernel,
11//! harness or runner ([`LocalSource`]), or a kernel's control plane ([`ControlSource`]) — and
12//! gives every surface the same three things (spec 3.3 §6):
13//!
14//! | Part | What | Where |
15//! |---|---|---|
16//! | Feed | A session's events numbered by their position in the session store, as a snapshot then a live tail, resumable after the last `seq` seen | [`SurfaceEngine::feed`], [`SurfaceEngine::thread`] |
17//! | Projection | Decision cards (§7.1), thread items, agent rows, the status line and the "While you were away" briefing, in the words of §8 | [`model`], [`words`] |
18//! | Commands | Decide at the version seen, send, queue, stop all, resume all, change the mode — each with its caller's subject and [`Origin`], audited | [`SurfaceEngine::execute`], [`Command`] |
19//!
20//! What each surface may decide (§7.2) and the rules on every surface (§7.4) are enforced by
21//! the engine in [`rules`], not left to renderers.
22//!
23//! The live camera surface (spec 3.7 §8.2) is [`camera`]: a camera source's facts, the hub that
24//! drops every frame of a camera switched off or paused by Stop all, and the view model; its
25//! routes are served with `web` once the engine is built with [`SurfaceEngineBuilder::cameras`],
26//! and with `vision-camera` its cameras run on adk-vision's frame pipeline.
27//!
28//! ## Surfaces
29//!
30//! | Feature | Surface | Stability |
31//! |---|---|---|
32//! | `web` | The web home: its HTTP API under `/api/surface`, mounted with `ServerBuilder::add_api_routes`, with its OpenAPI document, and its page at `/ui/`, mounted with `ServerBuilder::add_root_routes` | Beta |
33//! | `tui` | The terminal (spec 3.3 §5.2): full screen, inline and JSON lines on the engine, decisions answered by key, light and dark; the `adk-rust` binary's `tui` feature | Beta |
34//! | `channels` | Chat: the Telegram adapter over the kernel's channel contract, `channels::TelegramAdapter` (spec 3.3 §5.3) | Beta |
35//! | `whatsapp`, `slack`, `discord`, `matrix`, `teams` | Chat on WhatsApp, Slack, Discord, Matrix and Microsoft Teams over the same contract, `channels::WhatsAppAdapter`, `SlackAdapter`, `DiscordAdapter`, `MatrixAdapter`, `TeamsAdapter` (spec 3.5 §10 X12); each implies `channels` | Experimental |
36//! | `mobile` | The phone: the web home installed on a phone, Web Push from the person's own kernel, pairing QR codes and "Confirm it's you", `mobile::router` (spec 3.3 §5.4); implies `web` | Beta |
37//! | `voice` | Voice and video: spoken "allow once" and "deny" through the engine with a cancel window, the camera and the screen as input while their switches are on; with `web`, the voice view's socket (`voice::router`, `voice::socket_routes`) (spec 3.3 §5.6) | Beta |
38//! | `voice-live` | `voice` with Gemini Live and the OpenAI Realtime API compiled in, for the live voice test and the `voice_home` example; a host passes its own provider models | Beta |
39//! | `computer-use` | Screen plans on decision cards (spec 3.7 Q8): a previewed plan of desktop actions parks as one card, decided with one answer through the harness's computer-use pack (`Harness::decide_held_screen_plan`), with the plan's binding on every step | Experimental |
40//! | `vision-camera` | The live camera surface on adk-vision's frame pipeline (spec 3.7 §7.13, §8.2): `camera::PipelineCameras` runs each camera through `StreamPipeline` and reports what it measured; the voice screen's camera through `SurfaceCameraSource` | Experimental |
41//! | `website` | The website's views on the web home (spec 3.5 §8.2): the web editor, onboarding, the charter cards, the site view and the weekly review over `adk-website`'s desk, `web::website::router`; implies `web` | Experimental |
42//! | `verb-ui` | Screen actions people and agents share (spec 3.3 §2 item 7, §6.1): snoozing something in Coming up from the home, the terminal, voice and an agent, always through the governed path, `verbs::VerbRegistry`; with `web`, `web::verbs::router` | Experimental |
43//! | `workflow` | The workflow observer (spec 3.3 §12 developer track): a graph agent's runs, steps and forks, card hints for its governed nodes, `workflow::Workflows`; with `web`, the Runs tab's routes, `web::workflow::router` | Beta |
44//! | `genui` | Agent-drawn UI (spec 3.3 §6.1, §7.4 rule 5): the A2UI v0.9.1 model, the `forms` 1.0 catalog, the validator that keeps approval controls and secrets out of drawings, the render tools agents draw with (`genui::DrawToolset`), drawings in the thread and a drawn form's Send, which asks the person first (`Command::SubmitDrawn`), and with `web` the capabilities route (`web::genui::router`) | Beta |
45//! | `genui-apps` | Apps from MCP servers in a thread (spec 3.3 §6.1): framed sandboxed on their own origin, their tool calls held for the person, never able to approve anything, `genui::McpAppsHost`; implies `genui` and `web` | Beta |
46//!
47//! ## Example
48//!
49//! ```rust
50//! use std::sync::Arc;
51//! use adk_core::{InMemoryApprovalStore, StoreApprovalService};
52//! use adk_session::InMemorySessionService;
53//! use adk_surface::{Caller, LocalSource, Origin, SurfaceEngine, SurfaceKind};
54//!
55//! # #[tokio::main(flavor = "current_thread")]
56//! # async fn main() -> adk_surface::Result<()> {
57//! let source = LocalSource::builder("adk-rust")
58//!     .sessions(Arc::new(InMemorySessionService::new()))
59//!     .approvals(Arc::new(StoreApprovalService::new(Arc::new(InMemoryApprovalStore::new()))))
60//!     .build()?;
61//! let engine = SurfaceEngine::builder(Arc::new(source)).build();
62//!
63//! let me = Caller::human("ana", SurfaceKind::Phone, Origin::Touch);
64//! let status = engine.status(&me, None).await?;
65//! assert_eq!(status.decisions, 0);
66//! # Ok(())
67//! # }
68//! ```
69//!
70//! ## Stability
71//!
72//! Beta — new in 3.0.0; `verb-ui` and the WhatsApp, Slack, Discord, Matrix and Teams adapters are
73//! Experimental. See [STABILITY.md](https://github.com/zavora-ai/adk-rust/blob/main/STABILITY.md).
74
75#![warn(missing_docs)]
76
77mod agents;
78pub mod answers;
79pub mod camera;
80#[cfg(feature = "channels")]
81pub mod channels;
82mod control;
83mod engine;
84pub mod error;
85mod evidence;
86pub mod genui;
87mod hints;
88pub mod images;
89mod inbox;
90mod local;
91#[cfg(feature = "mobile")]
92pub mod mobile;
93pub mod model;
94mod origin;
95mod project;
96pub mod rules;
97mod source;
98pub mod suggest;
99#[cfg(feature = "tui")]
100pub mod tui;
101#[cfg(feature = "verb-ui")]
102pub mod verbs;
103pub mod viewer;
104#[cfg(any(feature = "voice", feature = "web"))]
105pub mod voice;
106#[cfg(feature = "web")]
107pub mod web;
108pub mod words;
109#[cfg(feature = "workflow")]
110pub mod workflow;
111
112pub use agents::GrantedUse;
113pub use agents::{
114    AgentCardView, AgentChoices, AgentColor, AgentDetail, AgentDraft, AgentLife, AgentPreview,
115    AgentPreviewRequest, AgentThreads, AreaChoice, CardLine, ColorChoice, EndedWork, FileUse,
116    ModelView, RemovedAgent, RemovedThread, ShellUse, ThreadSummary, UsesDraft, WebUse,
117};
118pub use answers::{
119    AnswerLog, AnswerRecord, AnswerSummary, AuditAnswerLog, InMemoryAnswerLog, RECORD_LINES,
120    RecordAnswerLog, SURFACE_AUDIT_DECIDE, SurfaceCount,
121};
122pub use control::ControlSource;
123pub use engine::SURFACE_AUDIT_ANSWER;
124pub use engine::SURFACE_AUDIT_IMAGE_CHANGE;
125pub use engine::SURFACE_AUDIT_VISION_EXAMPLE;
126pub use engine::{
127    Command, CommandOutcome, DEFAULT_POLL_INTERVAL, FeedFrame, SURFACE_AUDIT_RESUME_ALL,
128    SURFACE_AUDIT_SEND, SURFACE_AUDIT_SET_MODE, SURFACE_AUDIT_STEER, SURFACE_AUDIT_STOP_ALL,
129    SURFACE_AUDIT_STOP_TURN, SurfaceEngine, SurfaceEngineBuilder,
130};
131pub use engine::{
132    SURFACE_AUDIT_APP_CALL_AUTO_APPROVED, SURFACE_AUDIT_DRAWN_SEALED, SURFACE_AUDIT_DRAWN_SUBMITTED,
133};
134pub use error::{Result, SurfaceError};
135pub use evidence::{
136    CardMedia, CoverClass, CoveredLine, EVIDENCE_RETENTION_DAYS, EvidenceBytes, EvidenceImage,
137    EvidenceKept, EvidenceRegion, GoesTo, ImageChange, ImageChanged, ImageFacts, MediaFacts,
138    MediaNotice, MediaNoticeKind, PurgedView, short_digest,
139};
140pub use hints::{CardHint, CardHints};
141pub use images::{MAX_IMAGE_BYTES, MAX_IMAGES, MessageImage};
142pub use local::{LocalSource, LocalSourceBuilder};
143pub use model::CardDetail;
144pub use model::{
145    AgentRef, AgentRow, AgentStatus, Avatar, Briefing, BriefingLine, CallView, CardStatus, Decided,
146    DecidedAnswer, DecisionCard, ElicitationView, ElicitedField, ElicitedKind, ElicitedOption,
147    FeedEntry, Mode, ModeView, ParkedView, Pill, QuietView, Reversibility, ScreenPlanStepView,
148    ScreenPlanView, Served, Speaker, SpendView, StatusLine, ThreadItem, TimelineStep,
149};
150pub use model::{CommandRun, ImageData, OutputLine, RunStop, ShellPlace, ShellView};
151pub use origin::{Caller, Origin, SurfaceKind, Via};
152pub use project::RUN_LINES;
153pub use project::{CALL_TEXT_LIMIT, Place};
154pub use rules::{Allowed, Answer, AnswerOption, Risk};
155pub use source::{
156    AgentState, AlwaysAllowOffer, HeldPlan, RuleCommit, Source, SpendToday, Steered, Steering,
157    TurnFailure,
158};