skip to content
$worker

canvas

v0.1.12

Create, edit and render diagrams in the console — stored as editable source, drawn live in chat and on a canvas page.

iiiverified
19 installs1 in 7d0 today
install
$iii trigger compose::add worker=canvas@0.1.12
  • macOS: arm64
  • Linux: arm64 · armv7 · x64
  • Windows: arm64 · x64

exact versions are immutable; binary and bundle artifacts are digest-pinned.

functions

13

canvas::create

function

Create a new canvas from mermaid text or an excalidraw scene JSON. Returns the stored record, including the minted stable id and, for mermaid, the diagram family derived from the source.

request
  • formatany of

    Diagram format: `mermaid` or `freeform`. Defaults to `mermaid`.

    any of (2)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
    variant 2
    valuenull
  • namestring

    Human-readable canvas name. Omit for a name derived from the detected diagram family (`Untitled flowchart`, `Untitled whiteboard`, …).

  • sourcestringrequired

    The editable source: mermaid text for `mermaid`, an excalidraw scene JSON string for `freeform`.

response
  • created_atinteger· int64required

    Creation time, unix seconds.

  • familystring

    Mermaid diagram family (`flowchart`, `sequenceDiagram`, …), derived from the source. `null` for a freeform canvas.

  • formatall ofrequired

    Diagram format: `mermaid` or `freeform`.

    all of (1)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
  • idstringrequired

    Stable 8-character slug identifying this canvas. Never changes across updates.

  • namestringrequired

    Human-readable canvas name.

  • sourcestringrequired

    The editable source of truth: mermaid text for `mermaid`, the excalidraw scene JSON for `freeform`.

  • updated_atinteger· int64required

    Last update time, unix seconds.

canvas::delete

function

Delete a stored canvas by its stable 8-character id. Deleting an unknown id is not an error: the response reports deleted=false instead.

request
  • idstringrequired

    Stable 8-character canvas id.

response
  • deletedbooleanrequired

    `true` when a record existed and was removed; `false` for an unknown id.

  • idstringrequired

    The id the call asked to delete.

canvas::element::add

function

Add elements to a freeform canvas, one call per drawing step. Each element is an excalidraw-style object ({type, x, y, width?, height?, text?, label?, start?, end?, ...}); skeleton shorthand is accepted and converted at render time. Elements without an id get a stable generated one. The open console canvas streams every call, so shapes appear as they are added. Returns the assigned ids and the new element count.

request
  • elementsunknown[]required

    Elements to append, in z-order. Objects with at least a `type` string; unknown fields pass through to the scene untouched.

  • idstringrequired

    Stable 8-character canvas id (format must be freeform).

response
  • element_countinteger· uintrequiredmin 0

    Total elements in the scene after the add.

  • element_idsstring[]required

    Assigned element ids, in the order the elements were given.

  • idstringrequired

    The canvas the elements were added to.

canvas::element::delete

function

Remove elements from a freeform canvas by element id. Unknown ids are ignored; the response reports how many were actually removed. The open console canvas streams the change live.

request
  • element_idsstring[]required

    Element ids to remove.

  • idstringrequired

    Stable 8-character canvas id (format must be freeform).

response
  • element_countinteger· uintrequiredmin 0

    Total elements left in the scene.

  • idstringrequired
  • removedinteger· uintrequiredmin 0

    How many of the given ids existed and were removed.

canvas::element::list

function

List the elements of a freeform canvas: id, type, position and size per element — the map an agent reads before updating or connecting shapes. Full element bodies are in the record source via canvas::get.

request
  • idstringrequired

    Stable 8-character canvas id (format must be freeform).

response
  • elementsobject[]required
    • heightnumber· double
    • idstringrequired
    • textstring

      The element's own `text`, or its `label.text` shorthand.

    • typestringrequired

      Element type (`rectangle`, `ellipse`, `arrow`, `text`, ...).

    • widthnumber· double
    • xnumber· double
    • ynumber· double
  • idstringrequired

canvas::element::update

function

Update one element of a freeform canvas by element id: move it, recolor it, change its text. Properties are merged; unknown ids error and name the canvas. The open canvas streams the change live.

request
  • element_idstringrequired

    Element id to update (from element::add or element::list).

  • idstringrequired

    Stable 8-character canvas id (format must be freeform).

  • propsobjectrequired

    Properties to merge into the element. `null` values remove the key.

response
  • elementunknownrequired

    The element after the merge.

  • element_idstringrequired
  • idstringrequired

canvas::get

function

Read one canvas by its stable 8-character id. Returns the full stored record, including the editable source. Errors when the id is unknown.

request
  • idstringrequired

    Stable 8-character canvas id, as returned by `canvas::create` and `canvas::list`.

response
  • created_atinteger· int64required

    Creation time, unix seconds.

  • familystring

    Mermaid diagram family (`flowchart`, `sequenceDiagram`, …), derived from the source. `null` for a freeform canvas.

  • formatall ofrequired

    Diagram format: `mermaid` or `freeform`.

    all of (1)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
  • idstringrequired

    Stable 8-character slug identifying this canvas. Never changes across updates.

  • namestringrequired

    Human-readable canvas name.

  • sourcestringrequired

    The editable source of truth: mermaid text for `mermaid`, the excalidraw scene JSON for `freeform`.

  • updated_atinteger· int64required

    Last update time, unix seconds.

canvas::list

function

List stored canvases, newest first, optionally filtered by format. Each entry is the full record including its source; the response is capped by the configured max_list.

request
  • formatany of

    Only return canvases of this format. Omit for every canvas.

    any of (2)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
    variant 2
    valuenull
response
  • canvasesobject[]required

    The stored records, newest first.

    • created_atinteger· int64required

      Creation time, unix seconds.

    • familystring

      Mermaid diagram family (`flowchart`, `sequenceDiagram`, …), derived from the source. `null` for a freeform canvas.

    • formatall ofrequired

      Diagram format: `mermaid` or `freeform`.

      all of (1)
      variant 1
      one of (2)
      variant 1
      valuestringenum: mermaid
      variant 2
      valuestringenum: freeform
    • idstringrequired

      Stable 8-character slug identifying this canvas. Never changes across updates.

    • namestringrequired

      Human-readable canvas name.

    • sourcestringrequired

      The editable source of truth: mermaid text for `mermaid`, the excalidraw scene JSON for `freeform`.

    • updated_atinteger· int64required

      Last update time, unix seconds.

  • countinteger· uintrequiredmin 0

    How many records this response carries.

canvas::on-config-change

function

Internal: hot-reload the canvas worker from the authoritative configuration when it changes, swapping the per-call snapshot.

request
  • idstring

    Configuration id that changed (advisory; the handler re-fetches).

response
  • okbooleanrequired

canvas::syntax

function

Look up how to write mermaid diagram syntax. Every supported family with a short summary and a working example, or, narrowed to one family, a compact primer. Call this before writing mermaid source.

request
  • familystring

    Diagram family to return (`flowchart`, `sequenceDiagram`, …; aliases like `graph` accepted); omit for the overview of every family.

response
  • familiesobject[]required

    The reference entries — every family for the overview, exactly one when the request named a family.

    • examplestringrequired

      A minimal, valid mermaid example of this family.

    • familystringrequired

      Canonical family name (`flowchart`, `sequenceDiagram`, …) — the same string `canvas::validate` reports and `canvas::create` stores.

    • summarystringrequired

      One-line description of what this family is for.

  • syntaxstringrequired

    The reference as readable text: one line per family for the overview, or the named family's syntax primer with its example.

canvas::ui-content

function

Serve the canvas worker's injected console UI assets (content function for its console:script / console:style triggers).

request
  • pathstringrequired

    The asset path from the trigger config (e.g. `state/page.js`).

response
  • contentstringrequired

    The asset source, verbatim.

  • content_typestringrequired

    MIME type the console should serve the asset with.

canvas::update

function

Update a stored canvas's name and/or source by id. The id never changes; updated_at is stamped and, for mermaid, the diagram family is re-derived from the new source. Returns the full updated record.

request
  • idstringrequired

    Stable 8-character canvas id.

  • namestring

    New canvas name. Omit to keep the current one.

  • sourcestring

    New source (mermaid text or excalidraw scene JSON, matching the canvas's format). Omit to keep the current one.

response
  • created_atinteger· int64required

    Creation time, unix seconds.

  • familystring

    Mermaid diagram family (`flowchart`, `sequenceDiagram`, …), derived from the source. `null` for a freeform canvas.

  • formatall ofrequired

    Diagram format: `mermaid` or `freeform`.

    all of (1)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
  • idstringrequired

    Stable 8-character slug identifying this canvas. Never changes across updates.

  • namestringrequired

    Human-readable canvas name.

  • sourcestringrequired

    The editable source of truth: mermaid text for `mermaid`, the excalidraw scene JSON for `freeform`.

  • updated_atinteger· int64required

    Last update time, unix seconds.

canvas::validate

function

Check canvas source for errors without storing it. Detects the mermaid diagram family, the size cap, balanced fences and per-family lints, or an excalidraw scene JSON's shape — a cheap pre-flight; full parsing happens at render time in the console.

request
  • formatany of

    Source format, `mermaid` or `freeform`; omit to auto-detect (a source starting with `{` is an excalidraw scene, anything else mermaid).

    any of (2)
    variant 1
    one of (2)
    variant 1
    valuestringenum: mermaid
    variant 2
    valuestringenum: freeform
    variant 2
    valuenull
  • sourcestringrequired

    The source to validate: mermaid text, or an excalidraw scene JSON string.

response
  • familystring

    The mermaid diagram family derived from the source (`flowchart`, `sequenceDiagram`, …). `null` for freeform or when the first meaningful line names no supported family.

  • issuesobject[]required

    Every issue found; empty when `valid` is `true`.

    • lineinteger· uint32min 0

      1-indexed source line the issue points at, when known.

    • messagestringrequired

      Human-readable description of the issue.

  • validbooleanrequired

    `true` when every cheap check passed. This is a pre-flight verdict, not a render guarantee — full parsing happens in the console.

triggers

0
no triggers registered