Canvas
Article editor
An article the user and the agent write together beside the chat: a help article, a blog post, release notes. Headings, lists, callouts and links, with a format toolbar and markdown shortcuts. The agent rewrites the parts the user asks for, in place, and marks what it changed.
When to use it
Section titled “When to use it”Use it when: The user and the agent write one article together over several turns: a help article, a blog post, release notes, an announcement. The user writes and formats in the canvas, and asks the agent to draft, shorten or rewrite parts of it.
Use something else when: A one-line reply or a short answer (the chat). Structured fields with rules (form canvas). Text the agent writes once and the user never edits (a chat card). Mobile: the canvas isn’t available; use the preview card (mountMobile).
What the agent receives
Section titled “What the agent receives”| The template calls | The agent gets | When |
|---|---|---|
canvas.setState(patch) | Canvas state | 600 ms after the user stops writing, and on blur. Only the fields that changed (title, subtitle, blocks), and publishedAt and url after Publish. |
canvas.setTitle(title) | Canvas title | When the title changes: “Help article: <title>”. |
displayed() | FUNCTION_TOOL_DISPLAYED | Mobile preview 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 with only a title while the agent writes the first draft into its state. The editor takes over when the draft arrives. |
| Error | A saved article didn’t load when the canvas reopened. Try again loads it in place; the article itself is still saved. |
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.
ContentState
Section titled “ContentState”| Field | Type | Notes |
|---|---|---|
canvasTitle (optional) | string | The canvas header (setTitle, up to 80 characters). Default: “<kind>: <title>”. |
kind (optional) | string | What is being written, on the badge: “Help article”, “Blog post”. |
collection (optional) | string | Where it lives, as a breadcrumb: “Help center / Reports”. Display only. |
title | string | The headline. |
subtitle (optional) | string | One or two sentences under the headline: the summary readers see in search and lists. |
author (optional) | string | The byline. Display only. |
tags (optional) | string[] | Shown under the byline. Display only: the user asks the agent to change them. |
blocks | ContentBlock[] | |
publishedAt (optional) | string | When the user last published it (ISO time). The editor sets it, so the agent knows. |
url (optional) | string | The published article’s address, from your app’s publish(). |
ContentBlock
Section titled “ContentBlock”| Field | Type | Notes |
|---|---|---|
id | string | Stable id. The agent keeps it when it rewrites a block, so the editor can show what it changed. |
type | ContentBlockType | p (paragraph), h2 (heading), h3 (subheading), ul or ol (lists), quote or callout. |
text (optional) | string | The text of every type but lists. Inline markdown: bold, italic, code, label. |
items (optional) | string[] | A list’s items (ul, ol), each with the same inline markdown. |
ContentActions
Section titled “ContentActions”| Field | Type | Notes |
|---|---|---|
onChange() (optional) | (state: ContentState) => void | Called each time the draft is shared with the agent (debounced). Keep a copy in your app here if you need one. |
publish() (optional) | (state: ContentState) => Promise<{ url?: string } | void> | Publishes (or updates) the article in your app. With it the toolbar shows Publish. Resolve with its address; throw to show the error. |
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
- content-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.