Canvas
Custom canvas
A plain starting point for a canvas no typed one fits: a plan, a brief or a runbook built from headings, text, key values, checklists and callouts. The user and the agent edit the same blocks, the agent’s changes are marked, and your footer buttons act on the result.
When to use it
Section titled “When to use it”Use it when: None of the typed canvases fits: a plan, a brief, a runbook or a review the user and the agent shape together from headings, text, key values, checklists and callouts. The SDK adds no rule for OTHER, so your action’s own prompt must say what the agent may change and what it must leave alone.
Use something else when: The content is a form, a table, a document, code or a report: use that canvas, whose type tells the agent how to behave. A one-off answer (a chat card). Mobile: the canvas isn’t available; use the card (mountMobile).
What the agent receives
Section titled “What the agent receives”| The template calls | The agent gets | When |
|---|---|---|
canvas.setState({ blocks }) | Canvas state | 600 ms after the user stops editing, and when a field loses focus. The agent edits the same blocks by id. |
actions.onAction(id, state) | Your app | A footer button. The patch it returns (a new status, say) is drawn and shared. |
displayed() | FUNCTION_TOOL_DISPLAYED | Mobile 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 what the plan starts from. The skeleton has the canvas’s shape: a title, key values, text and a checklist. |
| Empty | There’s nothing to build the canvas from, for example a workspace that’s already in the target region. Say why, and what the user can do. |
| Error | execute couldn’t read what the canvas needs. Nothing changed; Try again loads it 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.
CustomCanvasState
Section titled “CustomCanvasState”| Field | Type | Notes |
|---|---|---|
canvasTitle (optional) | string | The canvas header (setTitle, up to 80 characters). Default: title. |
eyebrow (optional) | string | A small label above the title, e.g. “Migration plan”. |
title | string | |
subtitle (optional) | string | One or two lines under the title. |
status (optional) | CustomCanvasStatus | A status pill beside the eyebrow. |
blocks | CustomCanvasBlock[] | The body, top to bottom. Each block keeps its id when the agent edits it, so the canvas can mark the change. |
buttons (optional) | CustomCanvasButton[] | Footer buttons. Their clicks go to actions.onAction(id); the last primary one is the main action. |
footnote (optional) | string | A line in the footer, e.g. who decides what. |
CustomCanvasBlock
Section titled “CustomCanvasBlock”| Field | Type | Notes |
|---|---|---|
id | string | Stable id. |
type | "heading" | "text" | "keyValue" | "checklist" | "callout" | heading, text (paragraphs), keyValue (label and value rows), checklist (items the user ticks), callout (a note with a tone). |
text (optional) | string | heading, text and callout: the text. A blank line starts a paragraph. |
items (optional) | CustomCanvasItem[] | keyValue and checklist: the rows. |
tone (optional) | "info" | "success" | "warning" | "error" | callout: info (default), success, warning or error. |
editable (optional) | boolean | text and keyValue: the user can edit it in place. Checklists are always tickable. |
CustomCanvasItem
Section titled “CustomCanvasItem”| Field | Type | Notes |
|---|---|---|
id | string | Stable id. |
label | string | |
value (optional) | string | keyValue: the value. |
done (optional) | boolean | checklist: ticked. |
hint (optional) | string | A muted line under the label or value. |
CustomCanvasButton
Section titled “CustomCanvasButton”| Field | Type | Notes |
|---|---|---|
id | string | What actions.onAction receives. |
label | string | |
primary (optional) | boolean | The filled button. Default: outlined. |
CustomCanvasActions
Section titled “CustomCanvasActions”| Field | Type | Notes |
|---|---|---|
onAction() (optional) | (id: string, state: CustomCanvasState) => Promise<Partial<CustomCanvasState> | void> | Partial<CustomCanvasState> | void | A footer button was clicked. Return a state patch to apply and share (e.g. a new status). Throw to show why it failed. |
onChange() (optional) | (state: CustomCanvasState) => void | Called each time the state is shared with the agent (debounced). |
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
- custom-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.