Canvas
Form
A long form beside the chat. The agent fills in what it knows and answers questions about the rest; its fields stay marked until the user checks them. Only the user sends it.
When to use it
Section titled “When to use it”Use it when: A long form (3–4 sections, 10–16 fields) the user fills in over a few turns, with the agent filling what it can find and answering questions about the rest. The user sends it from the canvas.
Use something else when: Up to ~8 fields the agent can draft in one go (form with approval card). Steps that depend on earlier answers (wizard). Mobile: the canvas isn’t available; use the progress card (mountMobile).
What the agent receives
Section titled “What the agent receives”| The template calls | The agent gets | When |
|---|---|---|
canvas.setState({ values, suggested }) | Canvas state | 600 ms after the user stops typing, and when a field loses focus. The agent sees it with the user’s next message. |
canvas.setState({ submitted }) | Canvas state | After actions.submit() succeeds. The canvas switches to READ_MODE. |
displayed() | FUNCTION_TOOL_DISPLAYED | Mobile progress card: as soon as it shows. |
States
Section titled “States”Besides its data, the template draws these as itself: mountState() on the canvas, mountMobileState() in the mobile card. Pick one on the preview with State.
| State | When it shows |
|---|---|
| Loading | The canvas opens while your app loads the form’s sections and options, and again after Try again. It stays in READ_MODE until the fields show. |
| Error | The form didn’t load, or your app refused a submit outright (no permission). A submit worth retrying keeps its inline message instead. |
mountState({ root, head, title: "…", state: { kind: "error", text: "…", retry } });mountMobileState({ root, head, title: "…", state: { kind: "error", text: "…", retry } });The hosted action and the in-page handler below show each case. The state types are LoadingState, EmptyState and ErrorState in fs-kit.
FormCanvasState
Section titled “FormCanvasState”| Field | Type | Notes |
|---|---|---|
title | string | |
intro (optional) | string | |
canvasTitle (optional) | string | The canvas header (setTitle, up to 80 characters). Default: title. |
sections | FormCanvasSection[] | |
values | Record<string, string> | Field id to value, as text. The user and the agent both write here. A key the agent leaves out keeps its value. |
suggested (optional) | string[] | Fields the agent filled that the user hasn’t changed yet. The form keeps this list. |
submitLabel (optional) | string | |
busyLabel (optional) | string | |
doneTitle (optional) | string | |
doneText (optional) | string | |
receiptFields (optional) | string[] | Field ids listed on the success screen. Default: the first three required fields. |
submitted (optional) | FormCanvasReceipt | Set by the form after a successful submit. A reopened canvas shows the success screen. |
FormCanvasSection
Section titled “FormCanvasSection”| Field | Type | Notes |
|---|---|---|
id | string | |
title | string | |
description (optional) | string | |
icon (optional) | IconName | The section card’s icon. Default: doc. |
fields | FormCanvasField[] |
FormCanvasField
Section titled “FormCanvasField”| Field | Type | Notes |
|---|---|---|
id | string | |
label | string | |
type (optional) | "text" | "email" | "tel" | "url" | "number" | "date" | "select" | "textarea" | |
required (optional) | boolean | |
wide (optional) | boolean | Full row in the two-column layout (textareas always are). |
options (optional) | (string | { value: string; label: string })[] | |
placeholder (optional) | string | |
hint (optional) | string | |
prefix (optional) | string | Shown inside the input, e.g. ”$”. |
rows (optional) | number | |
format (optional) | NumberFormat | How a number shows on the success screen. |
FormCanvasActions
Section titled “FormCanvasActions”| Field | Type | Notes |
|---|---|---|
submit() (optional) | (values: FormCanvasValues) => Promise<{ id?: string; url?: string } | void> | Sends the form through your app. Throw to show the error and keep the draft. Return { id, url } to link the record. |
finish() (optional) | () => void | The success screen’s button. Default: close the canvas. |
Install
Section titled “Install”Copy the template and the shared kit into your code: agent/ui/ in an agent repo, or anywhere in your app. The template imports only ./fs-kit.js. Then wire it up from the hosted action or the in-page handler.
- Hosted action: TypeScript, JavaScript
- In-page handler: TypeScript, JavaScript
- form-canvas: TypeScript, JavaScript
- fs-kit: TypeScript, JavaScript
The hosted action needs an agent repo with one folder per action (agent/actions/<action_key>/index.ts). If your repo keeps its actions in agent/actions/index.ts, use the in-page handler: it runs the same template in your app.
All templates in machine-readable form: /ui-catalog/catalog.json.