Skip to content
Eskais UI

Get started

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

  1. UI SDK registers each component as it mounts: its kind, label, state and the actions it accepts (setValue, press, select…).
  2. agent.snapshot() lists them; agent.act() runs steps that name a component in the words of the task.
  3. A control marked data-agent-confirm asks your allow callback 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

agent.ts
import { createConfirm } from "@ui-sdk/react/alert-dialog"import { createAgent } from "@ui-sdk/react/agent"
// The approval is its own top-layer dialog: a modal the agent opened makes the rest of the page inert.export const approval = createConfirm<{ sentence: string }>()
export const agent = createAgent({  allow: (step, { signal }) => {    if (!step.confirm) return true    signal.addEventListener("abort", () => approval.controller.close(), { once: true })    return approval({ sentence: step.confirm })  },})

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).

const result = await agent.act({  steps: [    { ref: "Project name", action: "setValue", args: ["Atlas"] },    { ref: "Delete project", action: "press", args: ["Delete forever"] },  ],})

Mark what needs a person

  • Destructive actions carry data-agent-confirm with a sentence that says what happens.
  • ConfirmDialog with tone="destructive" requires agentConfirm; FormActions tone="destructive" confirm does the same for a form.
  • data-agent-hidden keeps a region out of snapshots; password, card and one-time-code fields are redacted without a mark.
<ConfirmDialog  trigger="Delete project"  title="Delete Apollo?"  confirmLabel="Delete forever"  tone="destructive"  agentConfirm="Deletes the Apollo project and its files"  onConfirm={deleteProject}/>

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.

Whyerror.message
Your callback called details.cancel()start was refused by the app. [refused:start]
The state doesn't offer itstart isn't available while listening. [unavailable:start]
The component wasn't given the callbackreset isn't offered: there is no onResetRequest.
<VoiceInput  state={state}  onStart={(details) => {    // People can dictate; an agent's start fails with "start was refused by the app."    if (details.source === "agent") return details.cancel()    startListening()  }}/>

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:

import { parseActionRefusal } from "@/lib/action-refusal"
const result = await agent.act({ steps: [{ ref: "Voice input", action: "start" }] })expect(result.ok).toBe(false)expect(parseActionRefusal(result.error)).toMatchObject({ action: "start", kind: "refused" })// A failure of any other kind (no such component, a bad argument, a plain Error) parses to null.
  • 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 ActionRefusedError from @/lib/action-refusal with action, kind and text.
  • 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 setValue reports ok: true with no change, so read the step's changes and the returned values there.
  • When an app's callback rejects, like onApprove or onCreate, 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-content does 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.

agent.ts
import { createAgent, registerTools } from "@ui-sdk/react/agent"
export const agent = createAgent({ allow })
// For a real browser agent in production, or only in dev and test builds:if (import.meta.env.DEV || import.meta.env.MODE === "test") {  registerTools(agent, { allow: (step) => !step.confirm })}

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):

dictation.spec.ts
import { chromium, expect, test } from "@playwright/test"import { parseActionRefusal } from "@/lib/action-refusal"
test("an agent can't start dictation the app keeps for people", async () => {  const browser = await chromium.launch({ channel: "chrome", args: ["--enable-features=WebMCP"] })  const page = await browser.newPage()  const cdp = await page.context().newCDPSession(page)  const tools = new Map()  const responses = new Map()  cdp.on("WebMCP.toolsAdded", ({ tools: added }) => added.forEach((tool) => tools.set(tool.name, tool)))  cdp.on("WebMCP.toolResponded", ({ invocationId, output }) => responses.get(invocationId)?.(output))  await cdp.send("WebMCP.enable")  await page.goto("http://localhost:5173/dictation")  await expect.poll(() => tools.has("act")).toBe(true)
  const call = async (toolName, input) => {    const { frameId } = tools.get(toolName)    const { invocationId } = await cdp.send("WebMCP.invokeTool", { frameId, toolName, input })    const output = await new Promise((resolve) => responses.set(invocationId, resolve))    return typeof output === "string" ? JSON.parse(output) : output  }
  const result = await call("act", { steps: [{ ref: "Voice input", action: "start" }] })  expect(result.ok).toBe(false)  expect(parseActionRefusal(result.error)).toMatchObject({ action: "start", kind: "refused" })  await expect(page.getByRole("group", { name: "Voice input" })).toHaveAttribute("data-state", "idle")  await browser.close()})

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.

// Before the page loads, in the test only: what registerTools needs from document.modelContext.await page.addInitScript(() => {  if (document.modelContext) return  const tools = new Map()  Object.defineProperty(document, "modelContext", {    value: {      registerTool: async (tool) => void tools.set(tool.name, tool),      getTools: async () => [...tools.values()],      executeTool: async (tool, input) => JSON.stringify(await tools.get(tool.name).execute(input, {})),    },  })})
const result = await page.evaluate(async () => {  const act = (await document.modelContext.getTools()).find((tool) => tool.name === "act")  const steps = [{ ref: "Voice input", action: "start" }]  return JSON.parse(await document.modelContext.executeTool(act, { steps }))})

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.