Agents
Every operable control is a UI SDK part, so an agent reads the page by accessible names and acts through the same parts a person uses.
How it works
- UI SDK registers each component as it mounts: its kind, label, state and the actions it accepts (
setValue,press,select…). agent.snapshot()lists them;agent.act()runs steps that name a component in the words of the task.- A control marked
data-agent-confirmasks yourallowcallback first, with the sentence the mark carries.
Every component page on this site has a Read the preview as an agent button that runs a real snapshot of its example. The landing page lets an agent archive a workspace while you approve.
Create one bridge
Render the approval as an AlertDialog with approval.controller. To publish the tools to the browser's agent, call registerTools from the same entry (WebMCP).
Mark what needs a person
- Destructive actions carry
data-agent-confirmwith a sentence that says what happens. ConfirmDialogwithtone="destructive"requiresagentConfirm;FormActions tone="destructive" confirmdoes the same for a form.data-agent-hiddenkeeps a region out of snapshots; password, card and one-time-code fields are redacted without a mark.
Behaviour UI SDK doesn't ship
Components like SearchField, NativeSelect, Sidebar and AgentTaskBoard are definePrimitive primitives with explicit agent.actions, rendered with createParts. A bare <button> or <select> is invisible to agents.
When an action can't run
UI SDK's bridge reports ok: true for any action that returns, so an Eskais component throws when an agent's action doesn't run. agent.act() resolves with ok: false and an error.message that says why, and stops there.
| Why | error.message |
|---|---|
Your callback called details.cancel() | start was refused by the app. [refused:start] |
| The state doesn't offer it | start isn't available while listening. [unavailable:start] |
| The component wasn't given the callback | reset isn't offered: there is no onResetRequest. |
A failed step keeps only the error's message: UI SDK's act result has error as { step, message }, with no code or cause, locally and over WebMCP. So a refusal's message ends with a tag, [refused:start] or [unavailable:start], and parseActionRefusal reads it back, from the step's error, its message or the error itself, as { action, kind, text }, where text is the sentence without the tag. Assert on it in a test instead of matching the words:
- A person's press that the app refuses does nothing and throws nothing. Only a call with no press behind it (an agent's step, a controller, your code) throws, an
ActionRefusedErrorfrom@/lib/action-refusalwithaction,kindandtext. - Actions that name an end state (
open,close,setCollapsed) succeed when it's already there; actions that move (start,next,undo) fail when there's nowhere to go. - UI SDK's own components keep UI SDK's rule: a cancelled
setValuereportsok: truewith no change, so read the step'schangesand the returnedvaluesthere. - When an app's callback rejects, like
onApproveoronCreate, the block's live alert shows a string or a React node as it is and anything else through its error text, which can be a function of the error.rejectionContent(error, fallback)from@/lib/rejection-contentdoes it, for your own blocks too.
Testing agent actions end to end
UI SDK's supported way to drive a page's agent from outside is WebMCP: registerTools publishes snapshot, query and act through document.modelContext, and the browser's agent, or your test, calls them. Nothing test-only goes in the app.
document.modelContext needs Chromium 158 or later: Chrome 158 and later have it with --enable-features=WebMCP. In Electron, the first major on Chromium 158 or later is Electron 46 (Chromium 160), whose stable release Electron's schedule puts on 5 January 2027 (tentative, checked on 20 November 2026); Electron 45 (Chromium 156) and older have no document.modelContext, so drive their pages through the stand-in below. Playwright lists the tools and calls them over the DevTools protocol, as a browser agent does (Playwright's protocol types don't list the WebMCP domain yet, so a TypeScript test casts the session):
On a browser without WebMCP, the test gives registerTools something to register into, and calls executeTool from inside the page. Check what the step did in the page too, not only result.ok.
The agent test
Test every interface the way an agent uses it: take a snapshot, act by label, and check that destructive steps wait for a person. The ui-sdk skill's references/agent-ready.md has the recipe.