Skip to content
Talk to an engineer

Canvas

Table

Rows the user and the agent clean up together beside the chat, before your app saves them. Every cell is checked as it changes, the agent’s edits are marked cell by cell, and only the user imports.

KindCanvas · TABLE · EDIT_MODEAgent waitsNoMobileNo canvas: a summary card

Use it when: Rows the user reviews and fixes in bulk before your app saves them: imported contacts, invoice lines, a price list (10 to 40 rows, 3 to 7 columns). The agent fixes the cells the user asks about, and the user imports from the canvas.

Use something else when: A few rows to read (data table card). One record (form canvas). More rows than fit in about 3 KB of state: page them in your app. Mobile: the canvas isn’t available; use the summary card (mountMobile).

The template callsThe agent getsWhen
canvas.setState({ rows })Canvas state600 ms after the user stops editing. Only the keys that changed: rows, selected, skipped.
canvas.setState({ selected })Canvas stateWhen the user selects rows, so “fix these” in the chat means those rows.
canvas.setState({ committed })Canvas stateAfter actions.commit() succeeds. The canvas switches to READ_MODE.
displayed()FUNCTION_TOOL_DISPLAYEDMobile summary card: as soon as it shows.

Besides its data, the template draws these as itself, with mountState(). Pick one on the preview with State.

StateWhen it shows
LoadingWhile execute reads the file and your app checks the rows. The skeleton has the grid’s shape, so nothing jumps when the rows arrive.
EmptyThe file had no rows your app could read. The agent says why and what to try.
Errorexecute couldn’t read the rows. Nothing was imported; Try again reads the file again in place.
mountState({ 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.

FieldTypeNotes
canvasTitle (optional)stringThe canvas header (setTitle, up to 80 characters). Default: title.
titlestringAbove the table, e.g. “Review imported contacts”.
intro (optional)stringOne line under the title: where the rows came from.
columnsTableCanvasColumn[]
rowsTableCanvasRow[]The rows. The agent changes only the cells it’s asked to, and adds or removes rows only when asked.
selected (optional)string[]Row ids the user selected. The agent reads them as “these rows”.
skipped (optional)string[]Row ids the user excluded. They aren’t saved and don’t need a fix.
noun (optional)[string, string]What a row is, singular and plural. Default: [“row”, “rows”].
commitLabel (optional)stringThe commit button. {n} is the number of rows that go. Default: “Import {n} rows”.
committed (optional)TableCanvasReceiptSet by the canvas after actions.commit succeeds. A reopened canvas shows the receipt.
FieldTypeNotes
idstringThe key of this column in each row.
labelstringHeader text.
type (optional)"text" | "email" | "tel" | "url" | "number" | "select"How a cell is edited and checked. Default: text.
required (optional)booleanAn empty cell needs a fix.
unique (optional)booleanTwo rows with the same value (case ignored) both need a fix, as for email.
options (optional)string[]The choices of a select column. Any other value needs a fix.
width (optional)numberWidth in px. Default: by type, 110 to 230.
icon (optional)IconNameThe header icon. Default: by type.
FieldTypeNotes
idstringStable id. The agent keeps it, so the canvas can mark the cells it changed.
FieldTypeNotes
commit() (optional)(rows: TableCanvasRow[]) => Promise<{ id?: string; url?: string } | void>Saves the rows through your app: every row except the excluded ones, all valid. Throw to keep the table and show why.
onChange() (optional)(state: TableCanvasState) => voidCalled each time the table is shared with the agent (debounced). Keep a draft in your app here.
finish() (optional)() => voidThe receipt’s button. Default: close the canvas.

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.

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.