Veya Runtime Protocol 0.1
Every participant in Veya speaks this protocol: an instrumented app reports through it, the hub stores and joins it, the MCP tools project it, and the agent reads it. The zod definitions in packages/protocol/src/ are the source of truth; this document is checked against them in packages/protocol/src/docs.test.ts.
Envelope
Every event is one envelope.
| Field | Type | Meaning |
|---|---|---|
id | string | Event identity, unique inside a session. |
seq | integer | Monotonic order inside a session, starting at 0. |
sessionId | string | The session the event belongs to. |
traceId | string | The user action this event descends from. |
spanId | string | The work unit that emitted the event. |
parentSpanId | string? | The span that caused this one. |
t | integer | Epoch milliseconds. |
source | runtime | browser | hub | Which channel observed it. |
type | event type | One of the types below. |
payload | JSON object | Type specific fields. |
A trace is every envelope sharing a traceId, ordered by seq. That is the causal chain an agent reads when it asks why the product did something.
Sessions
A session is one instrumented page.
| Field | Meaning |
|---|---|
id | Session identity. |
url | Page URL at hello. |
route | Page route at hello. |
title | Page title, when known. |
mode | human, agent or managed. |
channel | Runtime and CDP status. |
viewport | Page viewport at hello. |
startedAt | Epoch milliseconds. |
The desktop app opens a human product window and an agent product window with its own persistent profile. The preload reports the window kind; the runtime writes it into session.mode.
A page load creates a session. A newer session for the same url and mode replaces the previous one: the hub marks the old session replacedBy and emits session.replaced into the new one. Human and agent sessions for the same URL coexist and do not replace each other.
Event types
| Type | Source | Payload |
|---|---|---|
session.hello | runtime | route, viewport, framework, channel |
session.replaced | hub | reason, previousSessionId |
interaction.started | runtime | kind (click, input, submit, key), target, label |
interaction.completed | runtime | durationMs, outcome (ok, blocked) |
state.changed | runtime | id, path, previous, current |
network.request.started | runtime | browser | requestId, method, url, resourceType |
network.request.completed | runtime | browser | requestId, status, durationMs, size |
network.request.failed | runtime | browser | requestId, message, durationMs |
component.mounted | runtime | componentId, type, source |
component.unmounted | runtime | componentId |
error.uncaught | runtime | browser | message, stack, componentId |
error.console | runtime | browser | level, message |
navigation.committed | browser | from, to |
human.feedback | runtime | target, note, artifactId |
signal.raised | hub | signalId, rule, severity |
cdp.detached | hub | reason |
Components
A component node is what the app says about itself, not what the DOM looks like.
| Field | Meaning |
|---|---|
id | Semantic identity, from <AgentComponent id>. |
type | Component name, from the compiled marker or the React boundary. |
purpose | Why the component exists, from <AgentComponent purpose>. |
role | primary-action, navigation, content, status or form. |
status, visible, disabled, loading | Runtime state at capture time. |
dataStatus | idle, loading, ready or error. |
source | { file, line, column? } from the build, or null when unknown. |
children | Nested components, in render order. |
source: null is a fact, not a gap to fill in. Rule R008 reports components the build never annotated.
Snapshot
inspect returns a snapshot: protocol version, session, capture time, URL and route, viewport, the component tree, the business state keyed by state id, diagnostics, and the channel status ({ runtime, cdp }).
Diagnostics carry the errors seen, a console error count, failed and slow requests, the pending request count, and the web performance entries the runtime measured.
Context document
veya_context returns a ContextDocument, a projection over the session's snapshot history and event stream. It is not an event and adds no event types.
A baseline (baseline: true) is returned without since; a diff (baseline: false) is returned with a cursor from a previous response. Both carry signals as current failing findings, not a delta.
| Field | Baseline | Diff | Meaning |
|---|---|---|---|
cursor | yes | yes | Cursor for the next call. |
generatedAt | yes | yes | Compilation time. |
baselineReason | optional | no | cursor_unavailable when the supplied cursor was not found. |
since | no | yes | The cursor passed by the caller. |
budget | yes | yes | maxBytes, exact UTF-8 usedBytes and truncated. |
page | yes | yes | Snapshot time, URL, route, title, mode, viewport, channel and last probe viewport. |
signals | yes | yes | Current failing signals with evidence. |
components | yes | no | Flat pre-order component outlines with parentId and source. |
state | yes | no | Business state packed by top-level state id. |
diagnostics | yes | no | Counters, failed and slow requests, errors and performance. |
events | yes | no | Recent event summaries. |
changes.components | no | yes | added, removed and changed. |
changes.state | no | yes | path, previous and current. |
changes.events | no | yes | Event summaries after since. |
omitted | yes | yes | Omitted candidate counts by section. |
next | yes | yes | Tool calls that return the omitted material. |
A cursor is opaque and session-scoped. It points at a snapshot in a bounded history, 32 points by default. An unknown, expired or other-session cursor returns a baseline with baselineReason: "cursor_unavailable"; it is not an error.
The budget is UTF-8 bytes of compact JSON. usedBytes is exact, truncated says whether anything was left out, and the brief is packed by priority: failing signals, problem components, state, diagnostics, navigation components, recent events and the remaining components.
components omits bounds, props and children; source: null is preserved as a fact. events are summaries with seq, t, type, traceId and summary, not event payloads. The brief never probes: layout signals reuse the last probe, and page.probe reports its viewport when one exists.
The document is additive in protocol 0.1. No event type and no PROTOCOL_VERSION changed.
Signals
A signal is a deterministic finding with evidence. status is pass or fail; severity is critical, high, medium or low; evidence points at the trace, component, source file, request or artefact that proves it.
| Rule | Title | Severity |
|---|---|---|
R001 | Uncaught error | critical |
R002 | Console error | medium |
R003 | Failed request | high |
R004 | Stuck loading | high |
R005 | Horizontal overflow | medium |
R006 | Interactive control without a name | medium |
R007 | Low text contrast | low |
R008 | Component without source mapping | low |
Commands
A command is one of navigate, click, resize, screenshot or perform, optionally with target, value, steps and timeoutMs.
perform runs an ordered step list. A step is either { "kind": "click", "target" } or { "kind": "expect", "expect": { "events", "state" } }. The list starts with a click, contains at least one expect and holds at most 12 steps. An expect step waits for event types in the most recent click's trace and for current dotted state paths to match. The first unmet expectation stops the list.
A command result reports ok, the action, the traceId the last click produced, the events observed while verifying, the state changes among them, per-step outcomes, any evidence artefacts, and an error with a stable code and the failing stepIndex. perform answers ok: true only when every expectation held; a click that lands is not a product behaviour that works. timeoutMs is the wait budget for each expect step, not the whole list.
Compatibility
PROTOCOL_VERSION is 0.1. The hub accepts a session whose protocol major matches and records a mismatch in the session channel instead of dropping evidence.