TodoMVC with a chat assistant that runs in the browser. Zod defines the tools, the todo context and the model's responses: each schema is the app's type, the JSON Schema the model reads, and the validation of what comes back. Everything runs client side and is served from GitHub Pages.
Live: https://gingur.github.io/zod-web-demo/ · Storybook: https://gingur.github.io/zod-web-demo/storybook/
src/todo/schema.tsdefines seven tools, one per TodoMVC action: add, edit, mark done or not, mark all, delete, clear completed, and filter. Marking sets a state rather than flipping it, so repeating a call is harmless. Each is a name, a description, and a Zod object for its arguments with a.describe()on every field. The assistant can do what the UI can do, and nothing else.- The UI's own controls dispatch those same tool calls through
src/todo/tools.ts, so a click and a model call are checked the same way. - The model runs in the browser through WebLLM in a Web Worker. It reads the tools as definitions generated from Zod, in the
<tools>format its chat template uses, and the todo context as JSON with its schema (src/copilot/prompt.ts). - Each turn, the model plans (
src/copilot/pipeline.ts): it returns{ intent, calls }, where intent ischange_list,about_listoroff_topic, with decoding constrained to that shape. Zod and the tools check what the decoder can't, such as an id that doesn't exist or an intent that disagrees with its calls. Calls are applied all or nothing, and failures go back to the model, up to 3 attempts (src/copilot/loop.ts). - The reply depends on the intent. A change is reported as the facts of what happened, written by code, so it is always true. An off-topic request gets a fixed decline. Only an
about_listrequest is answered in the model's own words, given the list and its counts.
The split is measured, not assumed: on the same 20 prompts with Qwen2.5 3B, a single pass that planned and replied in one go misreported changes it made or didn't make; planning with the model and reporting with code got 17–19 of 20 right with every reply true. Reading the full prompt the model receives (tools, examples, special tokens) found the rest: worked examples that skipped some tools, intent labels the model read by name, and a toggle tool that un-did already-finished todos.
Scripted mode replays the suggested prompts through the same pipeline without a model, for browsers without WebGPU. One of them deliberately guesses a wrong id first, so the rejection and retry show on stage.
The page also offers its tools to agents outside it, through the browser's WebMCP API (src/webmcp.ts). They are the same seven tools, from the same Zod schemas, with the same checks, plus get_todos to read the list. A change made this way flashes in the list like an assistant change, and is refused while the in-page assistant is running. A refused call returns the reason, so the agent can fix it.
To try it, open the page in Chrome or Edge. No flag is needed: the page's origin-trial tokens turn WebMCP on. Then, in DevTools on the page:
const tools = await document.modelContext.getTools();
const add = tools.find((t) => t.name === 'add_todo');
JSON.parse(await document.modelContext.executeTool(add, { title: 'Buy eggs' }));
// { ok: true, message: "Added 'Buy eggs'.", todos: [...], filter: 'all' }
// A refused call: { ok: false, error: '...' }If the tokens have expired, chrome://flags/#enable-experimental-we
6AC2
b-platform-features may turn it on instead (untested).
Give Claude in Chrome this prompt:
Open https://gingur.github.io/zod-web-demo/ in Chrome, list the tools with document.modelContext.getTools(), then call add_todo with document.modelContext.executeTool(tool, { title: 'Get Beers with Troy' }) and show the result.
The built-in browser in Claude Desktop has no WebMCP, even on sites with a token, so use Claude in Chrome.
Toolchain versions live in .nvmrc and packageManager; proto install sets them up.
pnpm install
pnpm dev # app at http://localhost:5173
pnpm storybook # stories at http://localhost:6006
pnpm test # unit tests
pnpm test:stories # story interaction tests in headless Chromium
pnpm build # app + Storybook into dist/Lint, format and git hooks come from @gingur/devkit: pnpm lint, pnpm fmt.
- Use a recent Chrome or Edge (WebGPU), in the same browser profile you'll present from.
- Load the model once beforehand so its weights are cached. Qwen2.5 3B is the default; use 1.5B if generation is slow.
- Run each suggested prompt and time it, then check the tab over your screen-share tool.
- Reload right before presenting and click Load; cached loads take seconds.
verify.yml: devkit'stoolchain.verifyon every PR (format, lint, typecheck, unit and story tests, build). Required formain.gh.pages.deploy.yml: builds and deploys to Pages on push tomain.infisical.secrets.scan.yml: devkit's secret scan on every PR.
The todo list's look is the official TodoMVC stylesheet, todomvc-app-css by Sindre Sorhus, licensed CC BY 4.0. It is used unmodified; src/index.css only adjusts the page around it.