Skip to main content

adk_surface/genui/
drawn.rs

1//! What a thread shows of agent-drawn UI (spec 3.3 §6.1 `genui`, §7.4 rule 5).
2//!
3//! | Thread item | Projected from | Shows |
4//! |---|---|---|
5//! | [`DrawnSurface`] | A render tool's result whose event writes `adk.surface.drawn` with the digest of the result's drawing, checked again by the validator | The drawing, every string resolved on the server; a field carries only the value the person types |
6//! | [`RefusedDrawing`] | A render tool's refusal whose event writes `adk.surface.refused` | A plain notice; the technical reason for the developer panel and the terminal |
7//! | [`DrawnSent`] | The events an agent writes for a call a person asked for (`adk.requested`) | "Sent at 10:03", or why the agent cannot use the tool |
8//!
9//! A tool of the same name without the state key — an MCP server's `render_form`, say — is
10//! shown as an ordinary tool result. Only the latest version of a surface is live; a
11//! drawing's status ([`FormState`]) comes from its decision and its call's result, never from
12//! the click.
13//!
14//! These are wire types of every `web` build, whatever the features, so the page is the same
15//! for every server; a server built without `genui` never projects them.
16
17use chrono::{DateTime, Utc};
18use schemars::JsonSchema;
19use serde::{Deserialize, Serialize};
20use serde_json::Value;
21
22use super::scene::{DrawnDepth, DrawnScene};
23use crate::model::AgentRef;
24
25/// What a drawing is: a form a person fills in and sends, a card or table to read, or a
26/// screen of catalog components.
27///
28/// # Example
29///
30/// ```rust
31/// use adk_surface::genui::DrawnKind;
32///
33/// assert_eq!(serde_json::to_value(DrawnKind::Form).unwrap(), "form");
34/// ```
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
36#[serde(rename_all = "camelCase")]
37pub enum DrawnKind {
38    /// Fields and actions.
39    Form,
40    /// Label and value rows; no buttons.
41    Card,
42    /// Columns and rows; no buttons.
43    Table,
44    /// Any catalog components, with declared actions.
45    Screen,
46}
47
48/// Why a drawing was refused, in a person's terms (spec 3.3 §7.4 rule 5).
49///
50/// # Example
51///
52/// ```rust
53/// use adk_surface::genui::RefusalKind;
54///
55/// assert_eq!(serde_json::to_value(RefusalKind::AsksForSecret).unwrap(), "asksForSecret");
56/// ```
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
58#[serde(rename_all = "camelCase")]
59pub enum RefusalKind {
60    /// It shows a decision's words or controls.
61    LooksLikeDecision,
62    /// It asks for a password or another secret.
63    AsksForSecret,
64    /// It uses something this home does not show: a component outside the catalog, a link,
65    /// a function, or a malformed tree.
66    CannotShow,
67}
68
69/// A drawing in a thread (spec 3.3 §6.1 `genui`): drawn on the normal card background,
70/// never the decision's, with its strings already resolved on the server.
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
72#[serde(rename_all = "camelCase")]
73pub struct DrawnSurface {
74    /// The surface; a later drawing of it is its next version.
75    pub surface_id: String,
76    /// This version. Only the latest version of a surface is live.
77    pub version: u64,
78    /// What it is.
79    pub kind: DrawnKind,
80    /// The catalog it was checked against, such as `forms 1.0`.
81    pub catalog: String,
82    /// The agent that drew it.
83    pub agent: AgentRef,
84    /// When it was drawn.
85    pub drawn_at: DateTime<Utc>,
86    /// Local `HH:MM` it was drawn at.
87    pub at_text: String,
88    /// "Drawn by Finance · 10:02".
89    pub drawn_text: String,
90    /// What a newer version says above itself: "Finance changed this form at 10:05", or
91    /// "Finance removed this at 10:06" for a removal.
92    pub changed_text: String,
93    /// What this version says once a newer one replaces it: "Earlier version · 10:02".
94    pub earlier_text: String,
95    /// The title, agent text checked by rule 5.
96    #[serde(default, skip_serializing_if = "Option::is_none")]
97    pub title: Option<String>,
98    /// What it shows; `None` for a removal.
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub root: Option<DrawnNode>,
101    /// What its buttons ask for.
102    #[serde(default, skip_serializing_if = "Vec::is_empty")]
103    pub actions: Vec<DrawnActionView>,
104    /// This version removes the surface.
105    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
106    pub deleted: bool,
107    /// The render tool's call.
108    #[serde(default, skip_serializing_if = "Option::is_none")]
109    pub call_id: Option<String>,
110}
111
112/// One component of a drawing, resolved for a renderer: templates expanded, every string a
113/// person reads already in place (spec 3.3 §7.4 rule 5).
114///
115/// | Component | `text` | `variant` | Other |
116/// |---|---|---|---|
117/// | `Text` | The text | `h1`–`h5`, `caption`, `body` | — |
118/// | `Row`, `Column`, `List` | — | `justify` (Row, Column) or `direction` (List) | `children`; a long `List` has `showAllText` |
119/// | `Card` | — | — | `children` |
120/// | `Tabs` | — | — | `tabs` titles and one child per tab |
121/// | `Divider` | — | `axis` | — |
122/// | `Button` | Its label | `primary`, `default`, `borderless` | `action` |
123/// | `TextField`, `DateTimeInput`, `CheckBox`, `ChoicePicker`, `Slider` | The label | the catalog's variant | `field` |
124/// | `Chart` | — | — | `chart`: a chart an extension component's home view draws |
125/// | `Scene` | — | — | `scene`: a 3D scene an extension component's home view draws; its children are its panels, then its text view |
126/// | `Depth` | — | — | `depth`: the children an extension component's home view holds, presented with CSS 3D |
127/// | An extension component, such as `Metric` | — | — | `extension`, and one child: what the home shows for it |
128#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
129#[serde(rename_all = "camelCase")]
130pub struct DrawnNode {
131    /// Unique within the drawing: the component's id, and for a template's copy the list
132    /// item it was drawn for, `cell-0@/rows/3`.
133    pub key: String,
134    /// The catalog component.
135    pub component: String,
136    /// What it reads, or its label.
137    #[serde(default, skip_serializing_if = "Option::is_none")]
138    pub text: Option<String>,
139    /// A style hint from the catalog.
140    #[serde(default, skip_serializing_if = "Option::is_none")]
141    pub variant: Option<String>,
142    /// A field the person fills in.
143    #[serde(default, skip_serializing_if = "Option::is_none")]
144    pub field: Option<DrawnField>,
145    /// The declared action a button asks for.
146    #[serde(default, skip_serializing_if = "Option::is_none")]
147    pub action: Option<String>,
148    /// The titles of a `Tabs`' tabs, one per child.
149    #[serde(default, skip_serializing_if = "Vec::is_empty")]
150    pub tabs: Vec<String>,
151    /// A long list's "Show all 42", when a renderer cuts it.
152    #[serde(default, skip_serializing_if = "Option::is_none")]
153    pub show_all_text: Option<String>,
154    /// Its children, in order.
155    #[serde(default, skip_serializing_if = "Vec::is_empty")]
156    pub children: Vec<DrawnNode>,
157    /// A chart the home draws natively, from an extension component's home view.
158    #[serde(default, skip_serializing_if = "Option::is_none")]
159    pub chart: Option<DrawnChart>,
160    /// A 3D scene the home draws natively, from an extension component's home view.
161    #[serde(default, skip_serializing_if = "Option::is_none")]
162    pub scene: Option<DrawnScene>,
163    /// How the home presents this node's children in depth, from an extension component's
164    /// home view.
165    #[serde(default, skip_serializing_if = "Option::is_none")]
166    pub depth: Option<DrawnDepth>,
167    /// The extension component this node draws, for a host that draws it with its own
168    /// renderer; every other surface draws its one child, what the home shows for it.
169    #[serde(default, skip_serializing_if = "Option::is_none")]
170    pub extension: Option<DrawnExtension>,
171    /// What assistive technology reads for it (A2UI 1.0 `@accessibility`), resolved and
172    /// checked by rule 5.
173    #[serde(default, skip_serializing_if = "Option::is_none")]
174    pub accessibility: Option<DrawnAccessibility>,
175}
176
177/// What assistive technology reads for a drawn node (A2UI 1.0 `AccessibilityAttributes`): its
178/// label and description resolved and checked like any shown text, how its changes are
179/// announced, and whether it is hidden from screen readers (never a field or a button).
180#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
181#[serde(rename_all = "camelCase")]
182pub struct DrawnAccessibility {
183    /// A short name, read instead of its visible text.
184    #[serde(default, skip_serializing_if = "Option::is_none")]
185    pub label: Option<String>,
186    /// More it reads after the name: instructions, a format, a result.
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub description: Option<String>,
189    /// How its changes are announced: `polite` or `assertive`; absent is `off`.
190    #[serde(default, skip_serializing_if = "Option::is_none")]
191    pub live: Option<String>,
192    /// Hidden from screen readers.
193    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
194    pub hidden: bool,
195}
196
197/// A component of an extension catalog as a host renderer reads it (spec 3.3 §6.1 `genui`,
198/// extension catalogs): its properties with every binding and text function resolved and
199/// every string already checked by rule 5. A renderer draws it from these and nothing else,
200/// and draws no control: the component only shows.
201#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
202#[serde(rename_all = "camelCase")]
203pub struct DrawnExtension {
204    /// The catalog's id.
205    pub catalog: String,
206    /// The component's type, such as `Metric`.
207    pub component: String,
208    /// Its properties, resolved and checked.
209    pub props: Value,
210    /// The keys of the nodes its slots hold, in slot order: each is in the subtree of the
211    /// node's child.
212    #[serde(default, skip_serializing_if = "Vec::is_empty")]
213    pub children: Vec<String>,
214}
215
216/// A chart a component of an extension catalog shows in the home (spec 3.3 §6.1 `genui`,
217/// extension catalogs): numbers and words the server already checked by rule 5, never
218/// colours, links or markup. The home draws it in its own chart colours.
219///
220/// # Example
221///
222/// ```rust
223/// use adk_surface::genui::{ChartAxis, ChartKind, ChartSeries, DrawnChart};
224///
225/// let chart = DrawnChart {
226///     kind: ChartKind::Bar,
227///     x: ChartAxis::Category { labels: vec!["Q1".into(), "Q2".into()] },
228///     x_label: None,
229///     y_label: Some("Revenue".into()),
230///     ticks: Vec::new(),
231///     series: vec![ChartSeries { name: "2026".into(), x: Vec::new(), y: vec![4.into(), 7.into()] }],
232///     summary: String::new(),
233/// };
234/// let wire = serde_json::to_value(&chart).unwrap();
235/// assert_eq!(wire["x"]["type"], "category");
236/// assert_eq!(wire["series"][0]["y"][1], 7);
237/// ```
238#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
239#[serde(rename_all = "camelCase")]
240pub struct DrawnChart {
241    /// How it is drawn.
242    pub kind: ChartKind,
243    /// What the horizontal axis holds.
244    pub x: ChartAxis,
245    /// The horizontal axis's name.
246    #[serde(default, skip_serializing_if = "Option::is_none")]
247    pub x_label: Option<String>,
248    /// The vertical axis's name.
249    #[serde(default, skip_serializing_if = "Option::is_none")]
250    pub y_label: Option<String>,
251    /// Labelled points on a number or time axis, such as "10:00" at its epoch milliseconds.
252    #[serde(default, skip_serializing_if = "Vec::is_empty")]
253    pub ticks: Vec<ChartTick>,
254    /// The series, at most eight: one per chart colour.
255    pub series: Vec<ChartSeries>,
256    /// One sentence that says what the chart shows, for screen readers and the terminal,
257    /// written by the server: "Line chart of Revenue, 12 points, from 3100 to 9800".
258    #[serde(default)]
259    pub summary: String,
260}
261
262/// How a chart is drawn.
263#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
264#[serde(rename_all = "camelCase")]
265pub enum ChartKind {
266    /// Points joined by lines.
267    Line,
268    /// Lines with the area under them filled.
269    Area,
270    /// Bars side by side.
271    Bar,
272    /// Points only.
273    Scatter,
274    /// Slices of one whole: one series of at most eight values, none negative.
275    Pie,
276    /// One small line, no axes.
277    Sparkline,
278}
279
280/// What a chart's horizontal axis holds.
281#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
282#[serde(tag = "type", rename_all = "camelCase")]
283pub enum ChartAxis {
284    /// Named categories, one value per category in every series.
285    Category {
286        /// The categories' names, in order.
287        labels: Vec<String>,
288    },
289    /// Numbers: every series carries its `x` values.
290    Number,
291    /// Times as epoch milliseconds: every series carries its `x` values.
292    Time,
293}
294
295/// One series of a chart.
296#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
297#[serde(rename_all = "camelCase")]
298pub struct ChartSeries {
299    /// Its name, in the legend.
300    pub name: String,
301    /// Its horizontal values on a number or time axis; empty on a category axis.
302    #[serde(default, skip_serializing_if = "Vec::is_empty")]
303    pub x: Vec<serde_json::Number>,
304    /// Its values.
305    pub y: Vec<serde_json::Number>,
306}
307
308/// A labelled point on a number or time axis.
309#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
310#[serde(rename_all = "camelCase")]
311pub struct ChartTick {
312    /// Where, in the axis's values.
313    pub at: serde_json::Number,
314    /// What it reads.
315    pub text: String,
316}
317
318/// The kind of value a drawn field takes.
319#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
320#[serde(rename_all = "camelCase")]
321pub enum DrawnInput {
322    /// One line of text.
323    ShortText,
324    /// Several lines of text.
325    LongText,
326    /// A number.
327    Number,
328    /// A date, `2026-11-15`.
329    Date,
330    /// A time, `10:30`.
331    Time,
332    /// A date and a time, ISO 8601.
333    DateTime,
334    /// Yes or no.
335    Checkbox,
336    /// One of the options.
337    Choice,
338    /// Any of the options.
339    Choices,
340    /// A number between `min` and `max`.
341    Slider,
342}
343
344/// A field of a drawing: where its value goes, what it takes and what it checks.
345#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
346#[serde(rename_all = "camelCase")]
347pub struct DrawnField {
348    /// The data model path its value is at, such as `/to`: the key of its value when the
349    /// form is sent.
350    pub path: String,
351    /// What it takes.
352    pub input: DrawnInput,
353    /// The value it starts with.
354    pub value: Value,
355    /// The options of a choice.
356    #[serde(default, skip_serializing_if = "Vec::is_empty")]
357    pub options: Vec<DrawnOption>,
358    /// The lowest value of a slider, or the earliest date.
359    #[serde(default, skip_serializing_if = "Option::is_none")]
360    pub min: Option<Value>,
361    /// The highest value of a slider, or the latest date.
362    #[serde(default, skip_serializing_if = "Option::is_none")]
363    pub max: Option<Value>,
364    /// What it checks before the form is sent, in order.
365    #[serde(default, skip_serializing_if = "Vec::is_empty")]
366    pub checks: Vec<DrawnCheck>,
367}
368
369/// One option of a drawn choice.
370#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
371#[serde(rename_all = "camelCase")]
372pub struct DrawnOption {
373    /// What the person reads.
374    pub label: String,
375    /// The value sent.
376    pub value: String,
377}
378
379/// A check a drawn field makes: the catalog's `required`, `regex`, `length`, `numeric`,
380/// `email`, `and`, `or` and `not` functions, and the message shown when it fails.
381#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
382#[serde(rename_all = "camelCase")]
383pub struct DrawnCheck {
384    /// The A2UI function call that must be true, its bindings at data model paths.
385    pub condition: Value,
386    /// "Enter an email address".
387    pub message: String,
388}
389
390/// A declared action of a drawing, as its button shows it.
391#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
392#[serde(rename_all = "camelCase")]
393pub struct DrawnActionView {
394    /// The action's id.
395    pub id: String,
396    /// The button's label, agent text checked by rule 5.
397    pub label: String,
398    /// The tool sending runs.
399    pub tool: String,
400    /// The engine's line under the button: "Sending runs send_invoice and asks you first".
401    pub note: String,
402    /// The call's arguments: a field's value, or a constant the drawing fixed.
403    #[serde(default, skip_serializing_if = "Vec::is_empty")]
404    pub args: Vec<DrawnArg>,
405}
406
407/// One argument of a drawn action's call, as a preview of the call shows it.
408#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
409#[serde(rename_all = "camelCase")]
410pub struct DrawnArg {
411    /// The argument's name.
412    pub name: String,
413    /// The field whose value it takes, by data path.
414    #[serde(default, skip_serializing_if = "Option::is_none")]
415    pub path: Option<String>,
416    /// The constant it takes, when it takes no field's value.
417    #[serde(default, skip_serializing_if = "Option::is_none")]
418    pub value: Option<Value>,
419}
420
421/// A drawing that was not shown (spec 3.3 §7.4 rule 5): a plain notice in the thread; the
422/// technical reason only in the developer panel and the terminal.
423#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
424#[serde(rename_all = "camelCase")]
425pub struct RefusedDrawing {
426    /// The agent that tried to draw it.
427    pub agent: AgentRef,
428    /// Why, in a person's terms.
429    pub kind: RefusalKind,
430    /// "Finance tried to show something that looks like a decision. It wasn't shown."
431    pub text: String,
432    /// The technical reason: "catalog forms 1.0 · component c7 Button · label matches
433    /// reserved word \"Allow once\" after normalisation".
434    pub reason: String,
435    /// The component at fault, when one is.
436    #[serde(default, skip_serializing_if = "Option::is_none")]
437    pub component: Option<String>,
438    /// When.
439    pub at: DateTime<Utc>,
440    /// Local `HH:MM:SS`.
441    pub at_text: String,
442    /// The render tool.
443    pub tool: String,
444    /// The render tool's call.
445    #[serde(default, skip_serializing_if = "Option::is_none")]
446    pub call_id: Option<String>,
447}
448
449/// A person sent a drawn form: the call they asked for, held as the drawing agent for their
450/// decision, or refused by its rules before it was held (spec 3.3 §7.4 rule 5).
451#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
452#[serde(rename_all = "camelCase")]
453pub struct DrawnSent {
454    /// The surface sent.
455    pub surface_id: String,
456    /// The version sent.
457    pub version: u64,
458    /// The action used.
459    pub action_id: String,
460    /// The tool asked for.
461    pub tool: String,
462    /// The call's id: its result names it.
463    pub call_id: String,
464    /// The decision it waits on, once held.
465    #[serde(default, skip_serializing_if = "Option::is_none")]
466    pub decision_id: Option<String>,
467    /// Held for a decision; `false` when the agent's rules refused the call first.
468    pub held: bool,
469    /// When.
470    pub at: DateTime<Utc>,
471    /// "Sent at 10:03", "The app asked · 10:06", or "Finance can't use send_invoice here".
472    pub text: String,
473    /// What asked for it: a form the person sent, or an app from an MCP server (spec 3.3 §6.1
474    /// `genui-apps`).
475    #[serde(default)]
476    pub via: SentVia,
477}
478
479/// What asked for a [`DrawnSent`] call (spec 3.3 §6.1 `genui`, `genui-apps`).
480#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
481#[serde(rename_all = "camelCase")]
482pub enum SentVia {
483    /// The person pressed Send on a form an agent drew.
484    #[default]
485    Form,
486    /// An app from an MCP server asked, as its `tools/call`.
487    App,
488}
489
490/// Where a drawn form is after it was sent, from its decision and its call's result
491/// (spec 3.3 §7.4 rule 5).
492#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
493#[serde(rename_all = "camelCase")]
494pub enum FormStatus {
495    /// Sent, and the call is held: its decision is not answered here yet.
496    Waiting,
497    /// Sent and answered yes; the call has not finished yet.
498    Sent,
499    /// The call ran.
500    Done,
501    /// The person said no.
502    SaidNo,
503    /// The call ran and failed.
504    Failed,
505    /// Allowed, then refused when it resumed because a rule changed.
506    NotRun,
507    /// The drawing agent's rules refused the call before it was held; the form can be
508    /// changed and sent again.
509    Refused,
510    /// The decision ended without an answer.
511    Ended,
512}
513
514/// A drawn form's state after it was sent (spec 3.3 §7.4 rule 5).
515#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
516#[serde(rename_all = "camelCase")]
517pub struct FormState {
518    /// The surface.
519    pub surface_id: String,
520    /// The version sent.
521    pub version: u64,
522    /// Where it is.
523    pub status: FormStatus,
524    /// "Sent at 10:03 · waiting for you", "Sent · done at 10:04", …
525    pub text: String,
526    /// Its fields can no longer be changed: it was sent and the call was not refused.
527    pub locked: bool,
528    /// The decision it waits on or waited on.
529    #[serde(default, skip_serializing_if = "Option::is_none")]
530    pub decision_id: Option<String>,
531}