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.
When to use it
Section titled “When to use it”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).
What the agent receives
Section titled “What the agent receives”| The template calls | The agent gets | When |
|---|---|---|
canvas.setState({ rows }) | Canvas state | 600 ms after the user stops editing. Only the keys that changed: rows, selected, skipped. |
canvas.setState({ selected }) | Canvas state | When the user selects rows, so “fix these” in the chat means those rows. |
canvas.setState({ committed }) | Canvas state | After actions.commit() succeeds. The canvas switches to READ_MODE. |
displayed() | FUNCTION_TOOL_DISPLAYED | Mobile summary card: as soon as it shows. |
States
Section titled “States”Besides its data, the template draws these as itself, with mountState(). Pick one on the preview with State.
| State | When it shows |
|---|---|
| Loading | While execute reads the file and your app checks the rows. The skeleton has the grid’s shape, so nothing jumps when the rows arrive. |
| Empty | The file had no rows your app could read. The agent says why and what to try. |
| Error | execute 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.
TableCanvasState
Section titled “TableCanvasState”| Field | Type | Notes |
|---|---|---|
canvasTitle (optional) | string | The canvas header (setTitle, up to 80 characters). Default: title. |
title | string | Above the table, e.g. “Review imported contacts”. |
intro (optional) | string | One line under the title: where the rows came from. |
columns | TableCanvasColumn[] | |
rows | TableCanvasRow[] | 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) | string | The commit button. {n} is the number of rows that go. Default: “Import {n} rows”. |
committed (optional) | TableCanvasReceipt | Set by the canvas after actions.commit succeeds. A reopened canvas shows the receipt. |
TableCanvasColumn
Section titled “TableCanvasColumn”| Field | Type | Notes |
|---|---|---|
id | string | The key of this column in each row. |
label | string | Header text. |
type (optional) | "text" | "email" | "tel" | "url" | "number" | "select" | How a cell is edited and checked. Default: text. |
required (optional) | boolean | An empty cell needs a fix. |
unique (optional) | boolean | Two 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) | number | Width in px. Default: by type, 110 to 230. |
icon (optional) | IconName | The header icon. Default: by type. |
TableCanvasRow
Section titled “TableCanvasRow”| Field | Type | Notes |
|---|---|---|
id | string | Stable id. The agent keeps it, so the canvas can mark the cells it changed. |
TableCanvasActions
Section titled “TableCanvasActions”| Field | Type | Notes |
|---|---|---|
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) => void | Called each time the table is shared with the agent (debounced). Keep a draft in your app here. |
finish() (optional) | () => void | The receipt’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
- table-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.