adk_surface/model.rs
1//! The projection types every surface draws from (spec 3.3 §6, §7.1, §8).
2//!
3//! Each type carries the words to show (from [`words`](crate::words)) beside the data they
4//! were made from, so a renderer never composes on-screen text of its own. Identifiers such as
5//! [`DecisionCard::id`] and [`DecisionCard::version`] are for commands and are never shown
6//! (spec 3.3 §8: no internal identifiers). Every string that came from a model, a tool or a
7//! file is data: renderers escape it before display (§11 S-I9).
8//!
9//! All payloads serialize in `camelCase`.
10
11use chrono::{DateTime, Utc};
12use schemars::JsonSchema;
13use serde::{Deserialize, Serialize};
14use serde_json::Value;
15
16use crate::origin::Via;
17use crate::rules::{Allowed, Risk};
18
19/// An agent's avatar: a rounded monogram in the agent's own colour (spec 3.3 §9).
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
21#[serde(rename_all = "camelCase")]
22pub struct Avatar {
23 /// One or two letters.
24 pub monogram: String,
25 /// The agent's colour, `#RRGGBB`.
26 pub color: String,
27}
28
29/// An agent as a decision or a thread names it.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
31#[serde(rename_all = "camelCase")]
32pub struct AgentRef {
33 /// The agent's name in the runtime.
34 pub name: String,
35 /// The name to show, such as "Finance".
36 pub display_name: String,
37 /// The avatar.
38 pub avatar: Avatar,
39}
40
41/// What an agent is doing (spec 3.3 §8.1).
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
43#[serde(rename_all = "camelCase")]
44pub enum AgentStatus {
45 /// "Working": `RunState::Running`, or queued to run.
46 Working,
47 /// "Waiting for you": waiting with a held call.
48 WaitingForYou,
49 /// "Asleep until 07:00": waiting with a wake set, or parked by a stop.
50 Asleep,
51 /// "Done": completed, or cancelled.
52 Done,
53 /// "Failed".
54 Failed,
55 /// "Ready": an agent the person added that has not run yet (spec 3.3 §5.7, §8.1).
56 Ready,
57 /// "Paused": an agent paused by hand (spec 3.3 §5.7, §8.1).
58 Paused,
59 /// "Can't start": an agent the kernel cannot build (spec 3.3 §5.7, §8.1).
60 CantStart,
61}
62
63/// One agent in the roster (spec 3.3 §5.1, §8.1).
64#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
65#[serde(rename_all = "camelCase")]
66pub struct AgentRow {
67 /// The agent.
68 pub agent: AgentRef,
69 /// What it is doing.
70 pub status: AgentStatus,
71 /// The status word: "Working", "Waiting for you", "Asleep until 07:00", "Done", "Failed".
72 pub status_text: String,
73 /// When it wakes, while asleep with a wake time.
74 #[serde(default, skip_serializing_if = "Option::is_none")]
75 pub wake_at: Option<DateTime<Utc>>,
76 /// The session of its latest work, to open its thread.
77 #[serde(default, skip_serializing_if = "Option::is_none")]
78 pub session_id: Option<String>,
79 /// Its area, for an agent the person added (spec 3.3 §5.7).
80 #[serde(default, skip_serializing_if = "Option::is_none")]
81 pub area: Option<String>,
82 /// How much it asks first, for an agent the person added (spec 3.3 §5.7).
83 #[serde(default, skip_serializing_if = "Option::is_none")]
84 pub mode: Option<ModeView>,
85 /// An agent the person added: it has settings beyond its mode and rules (spec 3.3 §5.7).
86 /// Absent when false.
87 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
88 pub added: bool,
89 /// The caller may change it here (spec 3.3 §7.2). Absent when false.
90 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
91 pub can_change: bool,
92 /// Where its commands run, when it has a shell and its source says (spec 3.3 §5.7).
93 #[serde(default, skip_serializing_if = "Option::is_none")]
94 pub shell: Option<ShellView>,
95}
96
97/// How much agents act on their own (spec 3.3 §8.1).
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
99#[serde(rename_all = "camelCase")]
100pub enum Mode {
101 /// "Just look": `HarnessMode::ReadOnly`.
102 JustLook,
103 /// "Suggest": `HarnessMode::Plan`.
104 Suggest,
105 /// "Ask first": `HarnessMode::Ask`.
106 AskFirst,
107 /// "Go ahead": `HarnessMode::Auto`.
108 GoAhead,
109}
110
111/// The mode with its words.
112#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
113#[serde(rename_all = "camelCase")]
114pub struct ModeView {
115 /// The mode.
116 pub mode: Mode,
117 /// The setting's name: "Ask first".
118 pub label: String,
119 /// As a status: "Asks first".
120 pub status: String,
121}
122
123/// Today's spend against the daily limit (spec 3.3 §8.1).
124#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
125#[serde(rename_all = "camelCase")]
126pub struct SpendView {
127 /// Spent today, micro-USD.
128 pub spent_micro_usd: u64,
129 /// The daily spending limit, micro-USD, when set.
130 #[serde(default, skip_serializing_if = "Option::is_none")]
131 pub limit_micro_usd: Option<u64>,
132 /// "$1.84 of $5.00 today", or "$1.84 today" with no limit.
133 pub text: String,
134}
135
136/// Quiet time (spec 3.3 §8.1).
137#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
138#[serde(rename_all = "camelCase")]
139pub struct QuietView {
140 /// Quiet time holds now.
141 pub active: bool,
142 /// Local start, `HH:MM`.
143 pub start: String,
144 /// Local end, `HH:MM`.
145 pub end: String,
146 /// "Quiet from 22:00", or "Quiet until 07:00" while it holds.
147 pub text: String,
148}
149
150/// The status line every surface shows (spec 3.3 §5.1, §6): the mode word, spend against the
151/// daily limit, quiet time and the count of decisions.
152#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
153#[serde(rename_all = "camelCase")]
154pub struct StatusLine {
155 /// The mode, when the source runs a harness.
156 #[serde(default, skip_serializing_if = "Option::is_none")]
157 pub mode: Option<ModeView>,
158 /// Spend, when the source knows it.
159 #[serde(default, skip_serializing_if = "Option::is_none")]
160 pub spend: Option<SpendView>,
161 /// Quiet time, when set.
162 #[serde(default, skip_serializing_if = "Option::is_none")]
163 pub quiet: Option<QuietView>,
164 /// Decisions waiting for the caller: the filled badge.
165 pub decisions: u32,
166 /// Everything is stopped.
167 pub stopped: bool,
168 /// "All agents stopped", while stopped.
169 #[serde(default, skip_serializing_if = "Option::is_none")]
170 pub stopped_text: Option<String>,
171 /// Minutes east of UTC of the server's time zone now: the kernel reads a quiet window that
172 /// carries no offset of its own there, so a page in another zone reads it there too
173 /// (spec 3.3 §5.1).
174 #[serde(default, skip_serializing_if = "Option::is_none")]
175 pub host_utc_offset_minutes: Option<i32>,
176 /// The parts of the home this server serves beside the engine's own routes, in order: the
177 /// web home reads no route of a part it leaves out, so a server built or mounted without
178 /// one answers no request for it. Absent only from a server older than this field.
179 #[serde(default)]
180 pub serves: Vec<Served>,
181}
182
183/// A part of the web home a server serves beside the engine's own routes (spec 3.3 §6.1),
184/// listed in [`StatusLine::serves`].
185///
186/// adk-surface's routers name their part as they are built: `web::verbs::router` (feature
187/// `verb-ui`), `web::workflow::router` (`workflow`), `voice::router` (`voice`) and
188/// `mobile::router` (`mobile`). The engine names [`Cameras`](Self::Cameras) when it has a camera hub and
189/// [`Kernel`](Self::Kernel) when its source's kernel built its control-plane routes. A host
190/// names a part mounted from elsewhere with [`SurfaceEngine::serve`](crate::SurfaceEngine::serve),
191/// such as the website's desk.
192#[derive(
193 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
194)]
195#[serde(rename_all = "camelCase")]
196pub enum Served {
197 /// The kernel's control plane under `/api/kernel`: processes, the agenda, "While you were
198 /// away", settings, devices, memory and the record.
199 Kernel,
200 /// The live camera surface under `/api/surface/cameras`.
201 Cameras,
202 /// Screen actions under `/api/surface/verbs` (`verb-ui`).
203 Verbs,
204 /// Voice under `/api/surface/voice` (`voice`).
205 Voice,
206 /// The website's views under `/api/surface/website` (`website`).
207 Website,
208 /// The workflow observer under `/api/surface/workflow` (`workflow`).
209 Workflow,
210 /// The phone's routes under `/api/surface/phone` (`mobile`).
211 Phone,
212}
213
214/// The exact call a decision is about (spec 3.3 §7.1).
215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
216#[serde(rename_all = "camelCase")]
217pub struct CallView {
218 /// The tool.
219 pub tool: String,
220 /// Its arguments in full, as the inbox shows them to approvers (secrets removed).
221 pub args: Value,
222 /// The call as text, `send_email(to: "…", subject: "…")`, cut short when long.
223 pub text: String,
224 /// `text` is cut short: the call must be expanded before it can be approved.
225 pub truncated: bool,
226}
227
228/// Whether a call can be taken back (spec 3.3 §7.1).
229#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
230#[serde(rename_all = "camelCase")]
231pub enum Reversibility {
232 /// "Can't be unsent": a message, once sent.
233 CantBeUnsent,
234 /// "Can't be undone".
235 CantBeUndone,
236 /// "You can remove it later": an agent a person adds (spec 3.3 §5.7).
237 CanBeRemoved,
238 /// "You can change it back": a change a person can make again the other way, such as a
239 /// time moved on their screens, which a feature's [`CardHint`](crate::CardHint) says
240 /// (spec 3.3 §7.1).
241 CanBeChangedBack,
242}
243
244/// A line under a decision's details that a feature adds through a
245/// [`CardHint`](crate::CardHint): where the call comes from, with an optional link into the
246/// home, such as "From the invoice-run workflow · Open in Runs" (spec 3.3 §7.1). Never on a
247/// chat card (S-I5).
248///
249/// # Example
250///
251/// ```rust
252/// use adk_surface::CardDetail;
253///
254/// let detail = CardDetail::new("From the invoice-run workflow").with_link("Open in Runs", "/ui/runs/r-1");
255/// assert_eq!(detail.href.as_deref(), Some("/ui/runs/r-1"));
256/// ```
257#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
258#[serde(rename_all = "camelCase")]
259pub struct CardDetail {
260 /// The line, in plain words: "From the invoice-run workflow".
261 pub text: String,
262 /// The words of the link after the line: "Open in Runs".
263 #[serde(default, skip_serializing_if = "Option::is_none")]
264 pub link_text: Option<String>,
265 /// Where the link goes: a path in the home, such as `/ui/runs/r-1`. A renderer follows only
266 /// a path on its own server.
267 #[serde(default, skip_serializing_if = "Option::is_none")]
268 pub href: Option<String>,
269}
270
271impl CardDetail {
272 /// The line `text`, with no link.
273 pub fn new(text: impl Into<String>) -> Self {
274 Self { text: text.into(), link_text: None, href: None }
275 }
276
277 /// Adds the link `link_text` to `href`, a path in the home.
278 #[must_use]
279 pub fn with_link(mut self, link_text: impl Into<String>, href: impl Into<String>) -> Self {
280 self.link_text = Some(link_text.into());
281 self.href = Some(href.into());
282 self
283 }
284}
285
286/// One step of how a decision got here (spec 3.3 §7.1).
287#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
288#[serde(rename_all = "camelCase")]
289pub struct TimelineStep {
290 /// "Asked at 18:00", "Waited through quiet time", "Waiting for you".
291 pub text: String,
292 /// The step the decision is at now.
293 pub current: bool,
294}
295
296/// How a decision ended.
297#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
298#[serde(rename_all = "camelCase")]
299pub enum DecidedAnswer {
300 /// Allowed.
301 Yes,
302 /// Refused.
303 No,
304 /// Allowed with changed arguments.
305 Edited,
306 /// Answered with a message instead.
307 Replied,
308 /// Cancelled or expired without an answer.
309 Ended,
310 /// Answered, but the source does not say how.
311 Unknown,
312}
313
314/// A decision answered, here or elsewhere (spec 3.3 §8.1 "Decided", §11 S-I2): who answered,
315/// where and how, and when.
316#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
317#[serde(rename_all = "camelCase")]
318pub struct Decided {
319 /// Who answered: "You" for the caller, else the approver's name; empty when nobody did.
320 pub by: String,
321 /// The caller answered.
322 pub by_you: bool,
323 /// Where and how, when the answer came through a surface.
324 #[serde(default, skip_serializing_if = "Option::is_none")]
325 pub via: Option<Via>,
326 /// When.
327 pub at: DateTime<Utc>,
328 /// Local `HH:MM`.
329 pub at_text: String,
330 /// The answer.
331 pub answer: DecidedAnswer,
332 /// "You said yes in Telegram at 07:31".
333 pub text: String,
334 /// How far the answer reaches, shown after the text: "done once" for allow once, the
335 /// standing rule's label for always allow (spec 3.3 §5.4); `None` when no surface
336 /// recorded the answer.
337 #[serde(default, skip_serializing_if = "Option::is_none")]
338 pub scope_text: Option<String>,
339}
340
341/// Where a decision is in its life.
342#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
343#[serde(rename_all = "camelCase")]
344pub enum CardStatus {
345 /// Waiting for an answer.
346 Waiting,
347 /// Answered, or ended.
348 Decided,
349}
350
351/// A decision, drawn the same way on every surface from its inbox entry, never from agent
352/// output (spec 3.3 §7.1, §11 S-I1).
353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
354#[serde(rename_all = "camelCase")]
355pub struct DecisionCard {
356 /// The inbox entry: what a command answers. Never shown.
357 pub id: String,
358 /// The version the surface saw, which its answer carries (S-I2). Never shown.
359 pub version: u64,
360 /// The session the call belongs to.
361 pub session_id: String,
362 /// Who asks.
363 pub agent: AgentRef,
364 /// Since when it waits.
365 pub waiting_since: DateTime<Utc>,
366 /// "since 18:00".
367 pub since_text: String,
368 /// Waiting or decided.
369 pub status: CardStatus,
370 /// The pill: "Waiting for you" or "Decided".
371 pub status_text: String,
372 /// What will happen, in plain words.
373 pub heading: String,
374 /// What the heading alone does not say, in plain words, for a decision the kernel itself
375 /// asks: who suggests the work and when it runs once allowed, such as "Finance suggests
376 /// this. Once you say yes, it runs every 5 minutes." (spec 3.3 §7.1, §8.1). Never on a
377 /// chat card (S-I5).
378 #[serde(default, skip_serializing_if = "Option::is_none")]
379 pub summary: Option<String>,
380 /// The exact call: the details under the plain words.
381 pub call: CallView,
382 /// How it got here.
383 pub timeline: Vec<TimelineStep>,
384 /// The answers this surface may give; empty once decided.
385 pub allowed: Allowed,
386 /// The risk.
387 pub risk: Risk,
388 /// "Medium risk".
389 pub risk_text: String,
390 /// Whether it can be taken back.
391 pub reversibility: Reversibility,
392 /// "Can't be unsent".
393 pub reversibility_text: String,
394 /// The call spends money.
395 pub money: bool,
396 /// "Also on your phone and in Telegram".
397 #[serde(default, skip_serializing_if = "Option::is_none")]
398 pub also_shown: Option<String>,
399 /// The answer, once decided.
400 #[serde(default, skip_serializing_if = "Option::is_none")]
401 pub decided: Option<Decided>,
402 /// The agent a suggestion would add, shown in place of the call (spec 3.3 §5.7, S-I13).
403 #[serde(default, skip_serializing_if = "Option::is_none")]
404 pub adds_agent: Option<crate::agents::AgentCardView>,
405 /// A line under the details from a feature's [`CardHint`](crate::CardHint), such as
406 /// "From the invoice-run workflow · Open in Runs" (spec 3.3 §7.1). Never on a chat card
407 /// (S-I5).
408 #[serde(default, skip_serializing_if = "Option::is_none")]
409 pub detail: Option<CardDetail>,
410 /// What an MCP server asks the person, drawn in the home's own controls in place of the
411 /// call's arguments (MCP elicitation; spec 3.3 §7.2). Never on a chat card (S-I5).
412 #[serde(default, skip_serializing_if = "Option::is_none")]
413 pub elicitation: Option<ElicitationView>,
414 /// The images the call would send, keep or act on, after redaction, with what was
415 /// covered, where they go and what they cost (spec 3.7 §8.2, X11). Never on a chat card,
416 /// which carries the image itself or a link (S-I5).
417 #[serde(default, skip_serializing_if = "Option::is_none")]
418 pub media: Option<crate::evidence::CardMedia>,
419 /// The run that waited on this decision ended while it still waits: the answer is kept
420 /// and used when the agent picks the thread up again (spec 3.7 §8.2, board choice A12).
421 #[serde(default, skip_serializing_if = "Option::is_none")]
422 pub parked: Option<ParkedView>,
423 /// The screen plan the card decides with one answer (spec 3.7 Q8): its window and every
424 /// step with its target and the screenshot the target was found on. `None` for a card that
425 /// decides one call.
426 #[serde(default, skip_serializing_if = "Option::is_none")]
427 pub plan: Option<ScreenPlanView>,
428}
429
430/// A previewed screen plan a decision card decides with one answer (spec 3.7 Q8): up to N
431/// desktop actions in one window. **Allow** runs the steps once each, in order, each checked
432/// against its preview on a fresh screenshot before it runs; a step whose target moved is asked
433/// again on a card of its own. Never a standing rule.
434///
435/// # Example
436///
437/// ```rust
438/// use adk_surface::{ScreenPlanStepView, ScreenPlanView};
439///
440/// let plan = ScreenPlanView {
441/// digest: "sha256:ab12".into(),
442/// window: "app.forms, window \"Customer form\"".into(),
443/// steps: vec![ScreenPlanStepView {
444/// operation: "left_click".into(),
445/// target: Some("(100, 300)-(190, 340) pt".into()),
446/// screenshot: Some("sha256:screen".into()),
447/// proposed: serde_json::json!({ "operation": "left_click", "label": "Name" }),
448/// }],
449/// };
450/// assert_eq!(plan.steps.len(), 1);
451/// ```
452#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
453#[serde(rename_all = "camelCase")]
454pub struct ScreenPlanView {
455 /// The plan's fingerprint, `sha256:…`, over its window, steps and targets: the answer binds
456 /// it.
457 pub digest: String,
458 /// The window every step acts in: the application, then the window.
459 pub window: String,
460 /// The steps, in the order they run.
461 pub steps: Vec<ScreenPlanStepView>,
462}
463
464/// One step of a [`ScreenPlanView`].
465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
466#[serde(rename_all = "camelCase")]
467pub struct ScreenPlanStepView {
468 /// What the step does: `left_click`, `type`, ….
469 pub operation: String,
470 /// Where on the screen, in points: `(100, 300)-(190, 340) pt`. `None` for a step that acts
471 /// where the step before it put the focus, such as typing.
472 #[serde(default, skip_serializing_if = "Option::is_none")]
473 pub target: Option<String>,
474 /// The digest of the screenshot the target was found on, when the runtime gave one.
475 #[serde(default, skip_serializing_if = "Option::is_none")]
476 pub screenshot: Option<String>,
477 /// The action as the agent proposed it.
478 pub proposed: Value,
479}
480
481/// What an MCP server asks the person while the agent's call waits (MCP elicitation), drawn
482/// by the home in its own controls, never by the server: a form whose answer is sent as the
483/// decision's edit and checked against the server's schema, or a page the person opens
484/// themselves, shown in full and never opened by the home (spec 3.3 §7.2).
485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
486#[serde(rename_all = "camelCase", tag = "mode")]
487pub enum ElicitationView {
488 /// Fields to fill in: **Answer** sends them.
489 #[serde(rename_all = "camelCase")]
490 Form {
491 /// The server that asks.
492 server: String,
493 /// What it asks, in its words.
494 message: String,
495 /// The fields, in the schema's order.
496 fields: Vec<ElicitedField>,
497 },
498 /// A page the server asks the person to open.
499 #[serde(rename_all = "camelCase")]
500 Url {
501 /// The server that asks.
502 server: String,
503 /// Why, in its words.
504 message: String,
505 /// The whole address, as sent.
506 url: String,
507 /// Its host, shown on its own so a look-alike stands out.
508 host: String,
509 /// Why to look twice, when there is a reason: look-alike characters, a name hidden
510 /// before an `@`, no encryption.
511 #[serde(default, skip_serializing_if = "Option::is_none")]
512 warning: Option<String>,
513 },
514}
515
516/// One field of an elicitation form.
517#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
518#[serde(rename_all = "camelCase")]
519pub struct ElicitedField {
520 /// Its key in the answer.
521 pub name: String,
522 /// What the field is called: the schema's `title`, else its key.
523 pub label: String,
524 /// The schema's description.
525 #[serde(default, skip_serializing_if = "Option::is_none")]
526 pub description: Option<String>,
527 /// What it takes.
528 pub kind: ElicitedKind,
529 /// The answer is refused without it.
530 pub required: bool,
531 /// The value it starts with.
532 #[serde(default, skip_serializing_if = "Option::is_none")]
533 pub default: Option<Value>,
534 /// A choice's options.
535 #[serde(default, skip_serializing_if = "Vec::is_empty")]
536 pub options: Vec<ElicitedOption>,
537 /// A number's bounds.
538 #[serde(default, skip_serializing_if = "Option::is_none")]
539 pub minimum: Option<f64>,
540 /// A number's bounds.
541 #[serde(default, skip_serializing_if = "Option::is_none")]
542 pub maximum: Option<f64>,
543 /// A text's length bounds, in characters.
544 #[serde(default, skip_serializing_if = "Option::is_none")]
545 pub min_length: Option<u64>,
546 /// A text's length bounds, in characters.
547 #[serde(default, skip_serializing_if = "Option::is_none")]
548 pub max_length: Option<u64>,
549}
550
551/// What an elicitation field takes.
552#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
553#[serde(rename_all = "camelCase")]
554pub enum ElicitedKind {
555 /// A line of text.
556 Text,
557 /// An email address.
558 Email,
559 /// A web address, shown as text and never opened.
560 Url,
561 /// A date.
562 Date,
563 /// A date and time.
564 DateTime,
565 /// A number.
566 Number,
567 /// A whole number.
568 Integer,
569 /// Yes or no.
570 Boolean,
571 /// One of the options.
572 Choice,
573}
574
575/// One option of a choice.
576#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
577#[serde(rename_all = "camelCase")]
578pub struct ElicitedOption {
579 /// What the answer carries.
580 pub value: String,
581 /// What the person reads.
582 pub label: String,
583}
584
585/// An image of a person's message (spec 3.3 §5.1): PNG, JPEG, WebP or GIF, base64. A
586/// command carries at most [`MAX_IMAGES`](crate::MAX_IMAGES), each at most
587/// [`MAX_IMAGE_BYTES`](crate::MAX_IMAGE_BYTES) once decoded; the engine checks each image's
588/// bytes, not only its declared type.
589#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
590#[serde(rename_all = "camelCase")]
591pub struct ImageData {
592 /// `image/png`, `image/jpeg`, `image/webp` or `image/gif`.
593 pub mime_type: String,
594 /// The image, base64 (standard alphabet, padded).
595 pub data: String,
596}
597
598/// A command or code an agent ran (spec 3.3 §5.1), from its tool's result: the last lines it
599/// wrote, how it exited and for how long. Every string is data.
600#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
601#[serde(rename_all = "camelCase")]
602pub struct CommandRun {
603 /// The command line, when the tool's result repeats it; otherwise the call's own
604 /// activity line says what ran.
605 #[serde(default, skip_serializing_if = "Option::is_none")]
606 pub command: Option<String>,
607 /// The language of code the sandbox ran: `python`, `javascript`, `command`, ….
608 #[serde(default, skip_serializing_if = "Option::is_none")]
609 pub language: Option<String>,
610 /// How it exited, when it did.
611 #[serde(default, skip_serializing_if = "Option::is_none")]
612 pub exit_code: Option<i32>,
613 /// How long it ran, when the tool says.
614 #[serde(default, skip_serializing_if = "Option::is_none")]
615 pub duration_ms: Option<u64>,
616 /// The last lines it wrote, at most [`RUN_LINES`](crate::RUN_LINES).
617 pub output: Vec<OutputLine>,
618 /// How many lines the result holds in all.
619 pub lines: u32,
620 /// The tool cut what it wrote; the agent can read the whole of it.
621 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
622 pub truncated: bool,
623 /// Why it stopped short, when it did.
624 #[serde(default, skip_serializing_if = "Option::is_none")]
625 pub stopped: Option<RunStop>,
626}
627
628/// A line a run wrote.
629#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
630#[serde(rename_all = "camelCase")]
631pub struct OutputLine {
632 /// The line, as data.
633 pub text: String,
634 /// It went to standard error. Absent when false.
635 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
636 pub stderr: bool,
637}
638
639/// Why a run stopped short.
640#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
641#[serde(rename_all = "camelCase")]
642pub enum RunStop {
643 /// It ran out of time.
644 Timeout,
645 /// It ran out of memory.
646 MemoryExceeded,
647 /// The sandbox refused what it tried.
648 PolicyViolation,
649 /// It could not run.
650 Error,
651}
652
653/// Where an agent's commands run (spec 3.3 §5.7), as its harness reports it.
654#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
655#[serde(tag = "kind", rename_all = "camelCase")]
656pub enum ShellPlace {
657 /// On this computer, with no sandbox.
658 Host,
659 /// In the OS sandbox.
660 #[serde(rename_all = "camelCase")]
661 Sandbox {
662 /// The enforcer: `seatbelt`, `bubblewrap`; absent when the source does not say.
663 #[serde(default, skip_serializing_if = "Option::is_none")]
664 enforcer: Option<String>,
665 },
666 /// In a container.
667 #[serde(rename_all = "camelCase")]
668 Container {
669 /// The image.
670 image: String,
671 },
672 /// In an environment from a sandbox provider.
673 #[serde(rename_all = "camelCase")]
674 Remote {
675 /// The provider: `e2b`, `daytona`, `modal`, ….
676 provider: String,
677 /// It runs off this computer, so commands cannot reach its files.
678 off_host: bool,
679 },
680 /// A sandbox was asked for and is unavailable, so commands run on this computer.
681 #[serde(rename_all = "camelCase")]
682 Degraded {
683 /// The sandbox asked for.
684 requested: String,
685 /// Why it is unavailable.
686 reason: String,
687 },
688}
689
690impl ShellPlace {
691 /// Commands run apart from this computer's files and network: a sandbox, a container
692 /// or a remote environment.
693 pub fn isolated(&self) -> bool {
694 matches!(self, Self::Sandbox { .. } | Self::Container { .. } | Self::Remote { .. })
695 }
696}
697
698/// Where an agent's commands run, and the words that say so.
699#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
700#[serde(rename_all = "camelCase")]
701pub struct ShellView {
702 /// Where.
703 pub place: ShellPlace,
704 /// "Commands run in the sandbox (Seatbelt)".
705 pub text: String,
706}
707
708/// A decision whose run stopped waiting for it (spec 3.7 §8.2, board choice A12).
709///
710/// # Example
711///
712/// ```rust
713/// use adk_surface::ParkedView;
714///
715/// let parked = ParkedView {
716/// at: chrono::Utc::now(),
717/// at_text: "10:24".into(),
718/// text: adk_surface::words::stopped_waiting("Document desk", "10:24"),
719/// };
720/// assert!(parked.text.contains("picks this thread up again"));
721/// ```
722#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
723#[serde(rename_all = "camelCase")]
724pub struct ParkedView {
725 /// When the run ended.
726 pub at: DateTime<Utc>,
727 /// Local `HH:MM`.
728 pub at_text: String,
729 /// "Document desk stopped waiting at 10:24 and finished its run without this. …".
730 pub text: String,
731}
732
733/// Who wrote a message in a thread.
734#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
735#[serde(rename_all = "camelCase")]
736pub enum Speaker {
737 /// The person.
738 You,
739 /// An agent.
740 Agent,
741}
742
743/// One thing in a thread (spec 3.3 §5.1): a message, something an agent did, or a decision,
744/// which links to its inbox entry and is drawn from the card (§11 S-I1).
745#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
746#[serde(tag = "kind", rename_all = "camelCase")]
747pub enum ThreadItem {
748 /// A message.
749 #[serde(rename_all = "camelCase")]
750 Message {
751 /// The person or an agent.
752 from: Speaker,
753 /// The author's name: the agent's display name, or "You".
754 author: String,
755 /// The text, as data.
756 text: String,
757 /// The images the person sent with it (spec 3.3 §5.1). Absent when none.
758 #[serde(default, skip_serializing_if = "Vec::is_empty")]
759 images: Vec<ImageData>,
760 },
761 /// An agent used a tool.
762 #[serde(rename_all = "camelCase")]
763 Activity {
764 /// The tool.
765 tool: String,
766 /// "Read file timesheet-october.csv".
767 text: String,
768 /// The call, to match its result.
769 #[serde(default, skip_serializing_if = "Option::is_none")]
770 call_id: Option<String>,
771 },
772 /// A tool's result.
773 #[serde(rename_all = "camelCase")]
774 Result {
775 /// The tool.
776 tool: String,
777 /// The call it answers.
778 #[serde(default, skip_serializing_if = "Option::is_none")]
779 call_id: Option<String>,
780 /// It succeeded.
781 ok: bool,
782 /// "Done" or "Failed".
783 text: String,
784 /// The image a vision tool answered about, by digest: the thread links the call to
785 /// the annotated viewer (spec 3.7 §8.2, board choice V1).
786 #[serde(default, skip_serializing_if = "Option::is_none")]
787 image: Option<String>,
788 },
789 /// A command or code an agent ran, and what it wrote: the shell's `bash` or the sandbox's
790 /// `sandbox_exec` (spec 3.3 §5.1). It stands for that call's [`Result`](Self::Result).
791 #[serde(rename_all = "camelCase")]
792 Run {
793 /// The tool.
794 tool: String,
795 /// The call it answers.
796 #[serde(default, skip_serializing_if = "Option::is_none")]
797 call_id: Option<String>,
798 /// It succeeded: it exited with 0.
799 ok: bool,
800 /// "Done" or "Failed".
801 text: String,
802 /// The run.
803 run: CommandRun,
804 },
805 /// Replies the agent suggests the person might send next (spec 3.3 §5.1): tapping one fills
806 /// the message box, and the person still sends it.
807 #[serde(rename_all = "camelCase")]
808 Suggestions {
809 /// The replies, checked: one to four short lines, as data.
810 replies: Vec<String>,
811 /// The call that offered them.
812 #[serde(default, skip_serializing_if = "Option::is_none")]
813 call_id: Option<String>,
814 },
815 /// An agent asked first: a held call. Its card comes from the inbox entry.
816 #[serde(rename_all = "camelCase")]
817 Decision {
818 /// The inbox entry, when the call reached the inbox.
819 #[serde(default, skip_serializing_if = "Option::is_none")]
820 decision_id: Option<String>,
821 /// The tool.
822 tool: String,
823 /// "Waiting for you".
824 text: String,
825 },
826 /// Something an agent drew (spec 3.3 §6.1 `genui`, §7.4 rule 5): a form, card, table or
827 /// screen on the normal card background, never a decision. Only a render tool's result
828 /// with the reserved state key and the drawing's digest makes one.
829 #[serde(rename_all = "camelCase")]
830 Drawn {
831 /// The drawing, its strings resolved on the server.
832 surface: Box<crate::genui::DrawnSurface>,
833 },
834 /// A drawing that was not shown: a plain notice (spec 3.3 §7.4 rule 5).
835 #[serde(rename_all = "camelCase")]
836 DrawnRefused {
837 /// What the thread says, and the reason the developer panel shows.
838 refusal: crate::genui::RefusedDrawing,
839 },
840 /// A person sent a drawn form: the call they asked for, held as the drawing agent for
841 /// their decision, or refused by its rules (spec 3.3 §7.4 rule 5). The decision's own
842 /// `Decision` item follows it in the same entry.
843 #[serde(rename_all = "camelCase")]
844 DrawnSent {
845 /// The call and the form it came from.
846 sent: crate::genui::DrawnSent,
847 },
848 /// An app an MCP server's tool showed (spec 3.3 §6.1 `genui-apps`): on the normal card
849 /// background, labelled as unable to approve anything, framed sandboxed by the web home
850 /// and shown as its text result elsewhere. Only the event of the MCP tool's own call, which
851 /// carries its `adk.mcp.app` record, makes one.
852 #[serde(rename_all = "camelCase")]
853 App {
854 /// The app.
855 app: Box<crate::genui::AppView>,
856 },
857 /// The turn ended in an error, where the agent's reply would have been: a failed model
858 /// call leaves no event of its own, so the source's record of the turn says it
859 /// ([`Source::turn_failures`](crate::Source::turn_failures)). It follows the last event of
860 /// the session before the turn ended.
861 #[serde(rename_all = "camelCase")]
862 TurnFailed {
863 /// "Claims Desk couldn't answer".
864 text: String,
865 /// Why, as the runtime said it: "no recorded answer for turn 3". Absent when the
866 /// runtime recorded no reason.
867 #[serde(default, skip_serializing_if = "Option::is_none")]
868 reason: Option<String>,
869 /// The error's code, for a developer: `model.internal`.
870 #[serde(default, skip_serializing_if = "Option::is_none")]
871 code: Option<String>,
872 },
873}
874
875/// One event of a session's store, numbered by its position there (spec 3.3 §6).
876#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
877#[serde(rename_all = "camelCase")]
878pub struct FeedEntry {
879 /// The event's position in the session store, from 1: the `Last-Event-ID` a surface
880 /// resumes from.
881 pub seq: u64,
882 /// When.
883 pub at: DateTime<Utc>,
884 /// Local `HH:MM`.
885 pub at_text: String,
886 /// What it shows; empty for events with nothing to show.
887 pub items: Vec<ThreadItem>,
888}
889
890/// A pill on a briefing line (spec 3.3 §5.1 Today).
891#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
892#[serde(rename_all = "camelCase")]
893pub enum Pill {
894 /// "Done".
895 Done,
896 /// "Failed".
897 Failed,
898 /// "Waiting for you".
899 WaitingForYou,
900 /// "You decided".
901 YouDecided,
902 /// "Suggestion".
903 Suggestion,
904 /// "Question".
905 Question,
906}
907
908/// One line of "While you were away", from one `/proc` ledger row (spec 3.3 §5.1, §8.1).
909#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
910#[serde(rename_all = "camelCase")]
911pub struct BriefingLine {
912 /// The ledger row it came from: its record.
913 pub seq: u64,
914 /// When.
915 pub at: DateTime<Utc>,
916 /// Local `HH:MM`.
917 pub at_text: String,
918 /// The agent.
919 pub agent: String,
920 /// The pill, when the line has one.
921 #[serde(default, skip_serializing_if = "Option::is_none")]
922 pub pill: Option<Pill>,
923 /// The pill's words.
924 #[serde(default, skip_serializing_if = "Option::is_none")]
925 pub pill_text: Option<String>,
926 /// The sentence.
927 pub text: String,
928}
929
930/// "While you were away" (spec 3.3 §5.1, §8.1).
931#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
932#[serde(rename_all = "camelCase")]
933pub struct Briefing {
934 /// "While you were away".
935 pub title: String,
936 /// Since when.
937 pub since: DateTime<Utc>,
938 /// "Since 22:04".
939 pub since_text: String,
940 /// What was spent today.
941 #[serde(default, skip_serializing_if = "Option::is_none")]
942 pub spend: Option<SpendView>,
943 /// Decisions waiting.
944 pub waiting: u32,
945 /// One line per event, oldest first.
946 pub lines: Vec<BriefingLine>,
947 /// The source keeps an activity record. Without one, `lines` is empty whatever ran, so a
948 /// surface says nothing is recorded rather than that nothing happened.
949 #[serde(default = "kept")]
950 pub recorded: bool,
951}
952
953fn kept() -> bool {
954 true
955}