Skip to content
Talk to an engineer

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.

KindCanvas · CONTENT_EDITOR · EDIT_MODEAgent waitsNoMobileNo canvas: a preview card

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).

The template callsThe agent getsWhen
canvas.setState(patch)Canvas state600 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 titleWhen the title changes: “Help article: <title>”.
displayed()FUNCTION_TOOL_DISPLAYEDMobile preview card: as soon as it shows.

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.

StateWhen it shows
LoadingThe canvas opens with only a title while the agent writes the first draft into its state. The editor takes over when the draft arrives.
ErrorA 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.

FieldTypeNotes
canvasTitle (optional)stringThe canvas header (setTitle, up to 80 characters). Default: “<kind>: <title>”.
kind (optional)stringWhat is being written, on the badge: “Help article”, “Blog post”.
collection (optional)stringWhere it lives, as a breadcrumb: “Help center / Reports”. Display only.
titlestringThe headline.
subtitle (optional)stringOne or two sentences under the headline: the summary readers see in search and lists.
author (optional)stringThe byline. Display only.
tags (optional)string[]Shown under the byline. Display only: the user asks the agent to change them.
blocksContentBlock[]
publishedAt (optional)stringWhen the user last published it (ISO time). The editor sets it, so the agent knows.
url (optional)stringThe published article’s address, from your app’s publish().
FieldTypeNotes
idstringStable id. The agent keeps it when it rewrites a block, so the editor can show what it changed.
typeContentBlockTypep (paragraph), h2 (heading), h3 (subheading), ul or ol (lists), quote or callout.
text (optional)stringThe 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.
FieldTypeNotes
onChange() (optional)(state: ContentState) => voidCalled 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.

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.