> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blobhub.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Widgets

> A workflow blob's own playground widgets: web projects deployed with the CLI, on origins of their own.

A workflow blob carries its own playground widgets. Each is authored as an ordinary web project, built into one
JavaScript module, and deployed into a revision by `blobhub workflow deploy` as a definition of the `widget` category,
beside workflow, playground and listener definitions. A widget versions with its revision and travels with a branch, as
the revision's workflows do. Mission Control, the screen of the [Missions](https://docs.blobhub.io/general/apps.md#mission-control) app, is one:
the custom widget `mission-control`, which the app deploys with its workflows.

A custom widget is code from a blob, running in the browser of whoever opens the playground. It runs walled off, in a
frame on an origin of its own, and is handed no credential of any kind. It reaches its playground only through a bridge
the page holds, and through it reads and changes nothing outside its own playground's revision and selected session,
with two exceptions: it may read a person's display name and avatar (`people.get`), and it may start a workflow defined
elsewhere, one it lists and the viewer can run, which runs in the selected session. It can do no more than it declares
and no more than the viewer may. Whoever installs it confirms what it declares, including what it does outside the
page, such as copying to the clipboard or opening a link, and the playground's details pane shows it ([Trust at
install](#trust-at-install)). The [Security Model](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-security.md) states each
rule the platform enforces and the risks that remain.

## On a playground

The playground's library pane lists the revision's widgets beside the built-in ones, under each widget's `group`
(default `Custom`). A widget whose `group` is a built-in group's name, such as `Data`, is listed in that group, after
its built-in widgets, and any other group comes after the built-in groups. A widget created and never uploaded is listed
with its alias as its name and marked `Install incomplete`. Listing and placing a widget downloads none of its code: the
pane reads the revision's widget rows (see [What is stored](#what-is-stored)). A placed widget is an ordinary component
of the [playground definition](https://docs.blobhub.io/blob-types/workflow/playgrounds/definition-format.md) whose `type` is the widget
definition's alias alone: the widget `order-board` is placed as `order-board`. Every built-in type holds a dot, as
`widget.thread` does, and an alias cannot hold one: it matches `^[a-z0-9_-]{6,42}$`. A type without a dot is therefore
this blob's own widget, a widget definition in the playground's own revision. A form for placing a widget shared from
another blob may come later.

The host draws the widget's header itself: its name, its alias chip, its actions as icon buttons, its type and, for a
viewer who can edit the revision, Remove. The widget may set the alias chip's text and the actions with
[`ui.header`](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge#interface); the type is the alias the widget is
deployed under, which the widget cannot change. When the header runs out of room, the alias chip gives way first, then
the name, and the type last, so the widget's own text never pushes out its type; the actions and Remove never shrink,
and the details pane's Type always shows the type in full. Below the header is a frame on an origin of the widget's own,
`https://<label>.widgets.playground.blobhub.io/`, where `<label>` is derived from the blob and the widget's alias: one
origin per widget of every blob, the same for every revision and every viewer. With no session selected, the frame stays
live and the widget draws what it likes, a session picker of its own included when it declares `sessions: select` (see
[When the session changes](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#when-the-session-changes)). A click on
the header selects the widget, since a click inside its frame never reaches the page. A press on one of its
actions, with a click, Enter or Space, only pushes `ui.action` to the widget and does not select it; Space also
presses it on a [free-form layout](https://docs.blobhub.io/blob-types/workflow/playgrounds/definition-format.md#free-form-layout)'s
canvas. Its ports are edited in the details pane like any built-in widget's, and the pane's **Permissions**
section shows, read-only, the line each of its permissions is shown as ([Permissions](#permissions)), the same
lines as an open row of the [Widgets tab](#the-widgets-tab).

```mermaid theme={null}
flowchart LR
  subgraph page["The viewer's page on blobhub.io"]
    direction TB
    host["Host<br/>header · details pane<br/>API calls as the viewer"]
  end
  subgraph frame["A frame on its own origin"]
    direction TB
    widget["Widget<br/>#lt;label#gt;.widgets.<br/>playground.blobhub.io"]
  end
  api["BlobHub API<br/>api.blobhub.io"]
  widget <-->|"bridge (MessagePort)"| host
  host --> api
```

Everything a widget shows or changes travels over the bridge, a `MessagePort` the frame's bootstrap relays to the host:
the widget's requests, the host's replies, and the events the host pushes. The host makes every API call itself, inside
the page, with the viewer's own login, and hands back data only: nothing the frame receives is a token, key, cookie or
API address. Every call is pinned by the host to the playground's revision and its selected session at the moment of the
call, and the host takes neither from what the widget sends. The [Bridge
Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md) lists every call, event and refusal.

A form does not submit inside a widget: the frame's `sandbox` attribute lacks `allow-forms`, so the browser stops a
submission before its `submit` event fires. A `<form>`'s submit handler (React's `onSubmit` included) never runs, and a
submit button does nothing beyond its own `click` handler. Send on the click of a `type="button"` button, and on Enter
in a single-line field with a `keydown` handler.
[The frame](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-security.md#the-frame) says why.

A component naming an alias the revision does not hold shows `This revision has no widget named <alias>.`, never an
empty cell. Any other type the playground has no widget for, such as a retired built-in's, shows
`This playground has no widget of type <type>.`, and a component with no `type`, or a `type` of `""`, shows
`This widget has no type.` In each case a save keeps the component as stored, its type included.

## `widget.yaml`

A widget's project carries a `widget.yaml` (JSON works too) that describes the widget. It holds exactly these keys; any
other key is refused:

| Key | Required | Becomes |
| - | - | - |
| `label` | yes | `label` |
| `entry` | yes | `entry`; a file in the build directory ending `.js` or `.mjs` |
| `description` | no | `description`, omitted when absent |
| `group` | no | `group`, default `Custom` |
| `icon` | no | `icon`, omitted when absent |
| `ports` | no | `ports`, default `[]` |
| `permissions` | no | `permissions`, default `{}`; see [Permissions](#permissions) |
| `libraries` | no | `libraries`, default `{}`; see [Libraries and Theme](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md) |

The CLI writes the rest of the definition itself: `type`, `version`, `bridge`, `files` and `content_hash`
(see [The definition](#the-definition)). An Order Board, which shows the orders in the selected session and approves
one at a click:

```yaml theme={null}
label: Order Board
description: Orders in the selected session, and a button that approves one.
group: Operations
icon: LuClipboardList
entry: index.js
ports:
  - {category: data_input, route: orders, value: {type: component_alias}}
  - {category: data_input, route: width, value: {type: integer, default: 700, range: {from: 100, to: 2000, step: 50}}}
  - {category: data_input, route: height, value: {type: integer, default: 500, range: {from: 100, to: 2000, step: 50}}}
permissions:
  objects: read
  sessions: read
  executions:
    - {definition: approve-order}
libraries:
  react: 18.3.1
  react-dom: 18.3.1
```

* **`icon`** names the widget's icon: a react-icons export name as react-icons 5.3.0 spells it, such as `LuLineChart` or
  `GoGraph`. The playground's library pane draws it beside the widget. The server and the CLI check only its shape, a
  capital letter, then 1 to 63 ASCII letters or digits, never whether the icon exists. A widget without an `icon`, or
  with a name the page cannot find, such as `LuChartLine`, which react-icons 5.3.0 does not have, draws the default
  icon, `LuPuzzle`, and nothing is refused. The CLI refuses an `icon` key with no value; leave it out instead.
* **`ports`** use the built-in widgets' port shape, `{category, route, value: {type, ...}}`, and their value types
  (`component_alias`, `workflow_alias`, `choice`, `integer`, `text`, `message` and the rest), so the details pane edits
  them with the editors it already has. Here `orders` names the component whose output the board shows. Width and
  height are ports the widget declares itself, as every built-in does; these two take `widget.html`'s default and range.
* **`permissions`** lets the board read the selected session's objects, list the revision's sessions, and start
  `approve-order`, a workflow of its own revision, when the viewer clicks its button.
* **`libraries`** loads React and react-dom from the platform's library catalog at exactly these versions; anything else
  the widget imports must be bundled into its own files.

## The definition

`blobhub workflow build` packs `widget.yaml` and the build directory into one JSON document and writes it to the
manifest entry's `source`. That document is the widget definition `blobhub workflow deploy` uploads. For the Order
Board, with the code shortened:

```json theme={null}
{
  "type": "widget_definition",
  "version": "1.0.0",
  "label": "Order Board",
  "description": "Orders in the selected session, and a button that approves one.",
  "group": "Operations",
  "icon": "LuClipboardList",
  "ports": [
    {"category": "data_input", "route": "orders", "value": {"type": "component_alias"}},
    {"category": "data_input", "route": "width",
     "value": {"type": "integer", "default": 700, "range": {"from": 100, "to": 2000, "step": 50}}},
    {"category": "data_input", "route": "height",
     "value": {"type": "integer", "default": 500, "range": {"from": 100, "to": 2000, "step": 50}}}
  ],
  "permissions": {"objects": "read", "sessions": "read", "executions": [{"definition": "approve-order"}]},
  "libraries": {"react": "18.3.1", "react-dom": "18.3.1"},
  "bridge": 1,
  "entry": "index.js",
  "files": {
    "index.js": {"type": "text/javascript", "text": "…"},
    "index.css": {"type": "text/css", "text": "…"}
  },
  "content_hash": "sha256:…"
}
```

* **`type`**, **`version`** and **`bridge`** are fixed; `bridge` is the major version of the bridge protocol the
  widget was built for.
* **`files`** is the build output, each relative path mapped to `{type, text}` for a text file or `{type, base64}` for
  a binary one. **`entry`** names the ES module the frame imports. The build stands alone: one module with its own
  dynamic imports inlined, plus stylesheets with their assets inlined, since the frame loads the files from `blob:`
  URLs, which cannot resolve a relative import.
* **`content_hash`** identifies the build: the CLI computes it, the server recomputes it, and the viewer's page caches
  the code by it.

### The rules

The server checks a widget definition when it is uploaded, in this order, and the first failure is the answer. Each
rule refuses with `400 invalid_widget` unless it names another code:

1. **Keys:** `type`, `version`, `label`, `bridge`, `entry`, `files` and `content_hash` are required; `description`,
   `group`, `icon`, `ports`, `permissions` and `libraries` are optional; any other key is refused.
2. **`type`, `version`, `bridge`:** `"widget_definition"`, `"1.0.0"`, and the integer `1` (not a boolean, not `1.0`).
3. **`label`, `group`:** strings of 1 to 64 characters. **`description`:** a string of at most 500 characters.
   **`icon`:** a string matching `[A-Z][A-Za-z0-9]{1,63}` in full, ASCII only.
4. **`ports`:** a list; each an object with a string `category`, a string `route`, and a `value` object whose `type` is
   a string; routes unique; other port keys allowed. The category and value-type vocabularies are not checked.
5. **`permissions`:** an object with only the keys and values of [Permissions](#permissions): `objects`, `graph` and
   `files` with `read` or `write`; `threads` with `read` or `post`; `sessions` with `read` or `select`; `clipboard` with
   `write`; `notifications` with `show`; `executions`, a list, each entry a workflow reference of one of its three
   shapes; and `links`, either exactly `["*"]` or a list of at most 16 hosts, none repeated and none `"*"`. Each host is
   at most 253 characters, `*.` included, and matches in full, ASCII only,
   `(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]([a-z0-9-]{0,61}[a-z0-9])?`: two or more lowercase labels, the
   last starting with a letter, and `*.` only as the whole first label.
6. **`libraries`:** an object of non-empty names to versions matching `[0-9]+\.[0-9]+\.[0-9]+` in full. The server
   checks only the shape; `deploy` and `diff` check the names and versions against the library catalog, and `build` does
   against a catalog given with `--library-catalog`.
7. **`files`:** a non-empty object. Each path matches `[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*` in full and has no `..`
   segment. Each value is `{type, text}` or `{type, base64}`: exactly one of `text` and `base64`, no other key, `type`
   a non-empty string, `text` a string, `base64` a string that decodes as standard base64.
8. **`entry`:** a key of `files` whose `type` is `text/javascript`.
9. **Size:** the canonical form of the whole document, `content_hash` included, is at most
   [`workflow.widget_definition_bytes`](https://docs.blobhub.io/general/limits#workflow); refused with `400 widget_definition_too_large` and
   a `limit` object.
10. **Hash:** `content_hash` equals the hash computed below; refused with `400 widget_hash_mismatch`.
11. **Listing row:** the canonical form of the widget's listing row (see [What is stored](#what-is-stored)) is at most
    262,144 bytes (256 KiB).

A refusal's message names the field at fault, such as `permissions.objects`, `files["a/b.js"].base64` or
`ports[2].route`, and nothing is stored. `invalid_widget` means the document needs fixing; `widget_hash_mismatch`
means it needs rebuilding, since only `blobhub workflow build` recomputes the hash. `blobhub workflow deploy` checks the
same rules before it uploads anything, and is stricter, never looser: for example, it refuses `..` anywhere in a path.

### The canonical form and the hash

The canonical form of a document is `json.dumps(doc, sort_keys=True, separators=(",", ":"), ensure_ascii=False)`
encoded as UTF-8. `content_hash` is `"sha256:"` followed by the lowercase hex SHA-256 of the canonical form of the
document without `content_hash`. The byte size checked against the limit is the length of the canonical form of the
whole document, `content_hash` included. In Python, for a document `doc`:

```python theme={null}
import hashlib
import json


def canonical(doc):
    return json.dumps(doc, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")


unhashed = {key: value for key, value in doc.items() if key != "content_hash"}
content_hash = "sha256:" + hashlib.sha256(canonical(unhashed)).hexdigest()
byte_size = len(canonical({**unhashed, "content_hash": content_hash}))
```

### What is stored

The revision keeps the uploaded document's canonical form byte for byte, with no defaults filled, so the stored
document hashes to its own `content_hash`. [Download Definition](https://docs.blobhub.io/blob-types/workflow/operations/download-definition.md)
returns it as `definition_object`.

[List Definitions](https://docs.blobhub.io/blob-types/workflow/operations/list-definitions.md) with `category: widget` serves each widget's
listing row: the document without `files`, with its defaults filled. The row holds `label`, `description` and `icon`
(each only when the document has one), `group` (default `Custom`), `ports` (default `[]`), `permissions` (default `{}`),
`libraries` (default `{}`), `bridge`, `entry`, `content_hash`, and `byte_size`, the length of the document's canonical
form. It is everything the library pane and the details pane need; no listing carries `files`. Each upload replaces the
row's copy of the document, so an upload without `description` or `icon` removes it from the row.

[Create Definition](https://docs.blobhub.io/blob-types/workflow/operations/create-definition.md) writes a stub,
`{"type": "widget_definition", "version": "1.0.0"}`, which is not yet a widget. A widget row without `content_hash` was
created and never uploaded: it is not deployed, and a placed widget naming it shows
`Install incomplete: the widget <alias> was never uploaded.` When the revision's widget rows cannot be listed, every
custom widget on the playground shows `This widget could not be loaded.`, as does a widget whose stored document
cannot be downloaded.

A widget's row also carries `created_at` and `updated_at`, both ISO 8601 times. Create Definition writes the same time
to both. Each accepted upload sets `updated_at` to its own time and leaves `created_at`, so `updated_at` moves with
every deploy that uploads the widget. `blobhub workflow deploy` uploads a widget only when its hash differs from the
stored one, so a deploy that leaves the widget unchanged leaves its `updated_at` too. A refused upload writes nothing,
and a rename ([Update Definition](https://docs.blobhub.io/blob-types/workflow/operations/update-definition.md)) leaves `updated_at` as it was.

## Permissions

`permissions` is a widget's whole reach. A key left out grants nothing, and so does a definition with no
`permissions`.

| Key | Values | Grants | Calls | Shown as |
| - | - | - | - | - |
| `objects` | `read` · `write` | listing and reading the selected session's objects; writing and deleting them | `read`: `objects.rows`, `objects.read`, `objects.watch`, `objects.unwatch`, `objects.watch_rows`, `objects.unwatch_rows`; `write`: `objects.write`, `objects.delete` | `Reads session objects` · `Reads and writes session objects as you` |
| `threads` | `read` · `post` | reading thread items; posting them, as the viewer | `read`: `threads.list`, `threads.get`, `threads.watch`, `threads.unwatch`; `post`: `threads.post` | `Reads threads` · `Reads threads and posts to them as you` |
| `graph` | `read` · `write` | reading session graphs; mutating them | `read`: `graph.list`, `graph.get`, `graph.neighbors`, `graph.query`, `graph.watch`, `graph.unwatch`; `write`: `graph.mutate` | `Reads session graphs` · `Reads and changes session graphs as you` |
| `files` | `read` · `write` | downloading session files; uploading them | `read`: `files.read`, `files.save`; `write`: `files.upload` | `Reads session files` · `Reads and uploads session files as you` |
| `sessions` | `read` · `select` | listing the revision's sessions; asking the host to switch to one | `read`: `sessions.list`; `select`: `session.select` | `Lists sessions` · `Lists sessions and switches the playground's session` |
| `executions` | a list of workflow references | starting those workflows in the selected session, as the viewer | `executions.start` | `Starts these workflows as you:`, then each workflow in its [path form](https://docs.blobhub.io/blob-types/workflow/workflows/workflow-reference.md#the-path-form) |
| `clipboard` | `write` | copying text to the viewer's clipboard | `ui.copy` | `Copies to your clipboard` |
| `notifications` | `show` | showing the viewer a desktop notification | `ui.notify` | `Shows desktop notifications` |
| `links` | a list of hosts, or `["*"]` alone | opening a new tab at an `https` address on one of those hosts, or on any host for `["*"]` | `ui.open` with a `{url}` | `Opens links to these hosts:`, then each host · `Opens links to any website` |

**Shown as** is the line the permission draws, word for word, wherever a widget's permissions are shown: the output of
[`blobhub workflow deploy`](https://docs.blobhub.io/cli/workflow/commands/deploy#confirming-what-a-widget-may-do) and `push`, the playground's
details pane, and an open row of the [Widgets tab](#the-widgets-tab). A widget that declares no permissions reads
`This widget asks for no permissions.`

`write` implies `read`, `post` implies `read`, and `select` implies `read`. `hello`, `session.get`, `session.follow`,
`people.get` and `ui.header` need no permission, and neither does `ui.open` to a named route, `debugger` or `profile`,
since the host builds that link itself. Each call is described under
[Calls](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#calls).

Each `executions` entry is a [workflow reference](https://docs.blobhub.io/blob-types/workflow/workflows/workflow-reference.md#the-three-shapes) in
one of its three shapes: `{definition}`, a definition in the playground's own revision; `{blob, revision, definition}`;
or `{org, blob, revision, definition}`. A widget starts only the workflows this list names, and only an entry that is a
well-formed workflow reference counts: BlobHub neither starts nor shows any other entry of a stored document. A
`workflow_alias` port adds none: a workflow one of the widget's ports names starts only when the list names it too.

`links` is either `["*"]` alone, which allows any `https` host, or a list of hosts, such as `docs.example.com`. `*.` may
stand only as a host's whole first label, as in `*.example.com`; quote such a host, and `"*"`, in `widget.yaml`, since a
bare `*` starts a YAML alias. Rule 5 of [The rules](#the-rules) gives a host's exact form. `ui.open` takes only an
`https` URL with no user or password that reads the same with and without a base, so `https:a.com/x` is refused with
`invalid_params`, and it opens exactly the URL it checked. A URL whose host `links` does not name is refused with
`forbidden` and `{permission: ["links"]}`. Matching reads the host alone, so any port passes, and since no entry is an
IP address, a URL whose host is one opens only under `["*"]`. The [Bridge
Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#interface) gives the details.

```yaml theme={null}
permissions:
  objects: write
  executions:
    - {definition: approve-order}
    - {org: my-company, blob: fulfilment, revision: default, definition: ship-order}
  clipboard: write
  notifications: show
  links: [docs.example.com, "*.example.com"]
```

A call is answered only when the widget declared the permission it needs **and** the viewer could make the call
themselves. The host refuses with `forbidden` a call whose permission the widget did not declare, and a write by a
viewer who cannot write in the session. A write's refusal carries the selected session's status in its `data`
([Refusals](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#refusals)), which tells a reader apart from a session
that closed under the call. The API, called with the viewer's own login, enforces the viewer's rights, and a
call it refuses answers `api_error`, whose `data` carries the API's `status`, and its `error` code and `reasons` when
the API names them (see [Refusals](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#refusals)). So a reader's
widget can only read, whatever it declared.

The bridge has no call that reads or changes anything in other blobs, other revisions or other organizations, account or
organization settings, definitions, listeners, schedules, or a session's lifecycle (creating, closing or deleting one),
so these are out of a widget's reach by construction rather than by policy. Two calls are the exception:
`executions.start` may start a workflow the widget lists under `executions`, defined in another blob or organization,
which starts only if the viewer can run it and runs in the selected session; and `people.get` answers a person's
display name and avatar, and nothing more of them.

Nor is there a permission for the network. The frame's headers allow connections only to its own origin, so data reaches
a widget only through the bridge; a browser still leaves two ways out that no header closes, a frame navigating itself
and WebRTC, which the [Security Model](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-security.md) names.

## Trust at install

What a widget may do is settled before it runs: declared in its `widget.yaml`, confirmed by whoever installs it, and
shown to every viewer on the playground and in the blob's Widgets tab.

```mermaid theme={null}
flowchart LR
  deploy["blobhub workflow deploy or push<br/>refuses changed grants<br/>without --yes"]
  yaml["widget.yaml<br/>declares every capability"] --> deploy
  deploy --> definition["The revision's<br/>widget definition"]
  upload["Upload Definition Content<br/>called directly"] -.->|"no confirmation"| definition
  definition --> shown["Details pane<br/>and Widgets tab<br/>the same lines"]
  definition --> host["The host, at each call<br/>declared? viewer allowed?<br/>under its rate budget?"]
```

* **Declared.** `widget.yaml`'s `permissions` names everything the widget may do, including what reaches past the
  frame: copying to the clipboard, showing a notification and opening a link to an outside address
  ([Permissions](#permissions)). The host refuses a call whose permission the widget did not declare with `forbidden`,
  and its `data` names the `permission` the call needs.
* **Confirmed at install.** When a widget's granted permissions differ from the deployed definition's, [`blobhub
  workflow deploy`](/cli/workflow/commands/deploy#confirming-what-a-widget-may-do) and [`blobhub workflow
  push`](https://docs.blobhub.io/cli/workflow/commands/push#widgets-whose-permissions-changed) print its lines and refuse before any write with
  `WIDGET_NOT_CONFIRMED`, naming `--yes`; with `--yes` they print the same lines and install it. They compare grants,
  not text, so a removed permission counts, and a new widget asking for none is not listed. Neither waits on input, so a
  terminal and a script behave the same. Installing takes the right to edit the revision, so the confirmation is the
  installer's. A direct call to [Upload Definition Content](https://docs.blobhub.io/blob-types/workflow/operations/upload-definition.md) installs
  a widget without it, and `--yes` passed by a script installs one without anyone reading the lines; the [Security
  Model](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-security.md#residual-risks) names this.
* **Shown.** Every viewer sees the same lines, word for word, the **Shown as** column of [Permissions](#permissions):
  the details pane's **Permissions** section and an open row of the [Widgets tab](#the-widgets-tab) show what the widget
  reads, what it writes as the viewer, which workflows it starts as the viewer, and what it does outside the page.
* **Checked at each call.** Besides a call's params and its session, the host checks only the declaration, the viewer's
  own rights and the placed widget's [rate budgets](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#calls): a
  reader's widget still only reads, and the API enforces the rest of the viewer's rights. A write, a workflow start, a
  copy, an opened link or a notification happens when the widget calls, on load or on a timer as well as after a click;
  the host asks for no click and draws no dialog. A press on one of the widget's header actions, Space on a free-form
  canvas included, only sends `ui.action` to it. The browser's own rules still apply: it may refuse a new tab, a
  clipboard write or a notification prompt that no click preceded. That is a result, not an error: `ui.open` answers
  `{opened: false}`, `ui.copy` `{copied: false}` and `ui.notify` `{shown: false}`. The browser is asked for notification
  permission only by a `ui.notify` made while the page holds its activation from a click or key press
  ([`ui.notify`](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge#interface)).

## Deploying

A widget is a definition entry in the workflow blob's [manifest](https://docs.blobhub.io/cli/workflow/manifest.md):

```yaml theme={null}
definitions:
  - alias: order-board
    category: widget
    source: definitions/order_board.json
    widget:
      source: widgets/order_board/widget.yaml
      build: widgets/order_board/dist
```

* **`source`** is the packed definition document, which `build` writes and `deploy` uploads. Commit it: an install
  then needs no Node and no build directory.
* **`widget.source`** names the `widget.yaml`, and **`widget.build`** the directory the widget project's own build
  wrote. Both resolve against the manifest's directory.
* An entry with `category: widget` and no `widget:` binding deploys its committed `source` as it stands.

```sh theme={null}
npm run build                                          # in the widget's own project
blobhub workflow build -f manifest.yaml                # pack widget.yaml and the build directory into `source`
blobhub workflow deploy -f manifest.yaml               # upload the document at `source`
```

The CLI runs no Node: the widget project's own build writes the directory `build` packs.
[Libraries and Theme](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md) says how to build one module that
loads.

* **[`build`](https://docs.blobhub.io/cli/workflow/commands/build)** packs every entry with a `widget:` binding. It reads `widget.yaml`, walks
  the build directory in sorted order (skipping any path with a segment that begins with `.`, refusing symlinks), types
  each file from a fixed table of extensions, assembles the document, computes `content_hash`, checks it, and writes it
  to `source`, reporting `built widget/<alias> (<bytes> bytes, <content_hash>)`. It makes no API call, so it reports the
  size without a verdict. It checks libraries only against a catalog given with `--library-catalog`, a file or an
  `http(s)` URL; a catalog named by URL is fetched, the one request `build` can make. Without a catalog, a widget that
  declares libraries draws `WIDGET_LIBRARIES_UNVERIFIED`.
* **[`deploy`](https://docs.blobhub.io/cli/workflow/commands/deploy)** uploads the document at `source` as it stands and never packs. Before
  any write it checks every widget: the rules above, its libraries against `https://blobhub.io/libs/catalog.json` (or
  `--library-catalog`) when it declares any, its entry's imports, and its size against the blob's
  `workflow.widget_definition_bytes`. It deploys widgets after workflows and before playgrounds and listeners, and
  uploads a widget only when its hash differs from the stored one. When the build directory still exists and packs to
  a different document, `deploy` warns that the build is stale (`WIDGET_SOURCE_STALE`, and `stale` with `--json`) and
  uploads the source regardless; a build directory that exists but cannot be packed stops the deploy before any write.
  When a widget's granted permissions differ from the deployed definition's, `deploy` prints its lines and refuses with
  `WIDGET_NOT_CONFIRMED` unless given `--yes` ([Trust at install](#trust-at-install)).
* **[`diff`](https://docs.blobhub.io/cli/workflow/commands/diff)** compares hashes without downloading a widget. It reports `deployed`,
  `body_changed` when the local hash differs from the stored one, `build_stale` when the build directory packs to a
  different hash, `compile_error` when it cannot be packed, and `validation_error` from the same checks as `deploy`.
* **[`ls`](https://docs.blobhub.io/cli/workflow/commands/ls)** marks a widget created but never uploaded `(not deployed)` (`deployed: false`
  with `--json`), the one the [Widgets tab](#the-widgets-tab) shows as `Install incomplete`.
* **[`pull`](https://docs.blobhub.io/cli/workflow/commands/pull)** writes each deployed widget's document to its `source`, and skips one not
  deployed, leaving its local source as it is (`not_deployed` with `--json`).

[`push`](https://docs.blobhub.io/cli/workflow/commands/push) uploads a widget's document as it stands, without `deploy`'s offline checks of
anything but its `permissions`, and confirms a widget whose permissions changed as `deploy` does: it prints the widget's
lines and refuses with `WIDGET_NOT_CONFIRMED` unless given `--yes`. [`prune`](https://docs.blobhub.io/cli/workflow/commands/prune) deletes a
widget no manifest entry claims, as for any other definition; [`check`](https://docs.blobhub.io/cli/workflow/commands/check) and
[`eject`](https://docs.blobhub.io/cli/workflow/commands/eject) skip widgets.

Before it uploads anything, `deploy` refuses a widget that breaks the rules, asks for a permission outside the
vocabulary, is larger than the blob's `workflow.widget_definition_bytes`, names a library or version the catalog lacks,
or whose entry imports a relative path, a URL, or a bare name no declared library answers to. Only the entry module is
read, and a computed `import(expr)` draws the advisory `WIDGET_IMPORT_UNVERIFIED`. [Error codes](https://docs.blobhub.io/cli/error-codes.md) lists
the `WIDGET_*` codes.

There is no local runner. A widget is developed by deploying it to a real playground, and a deploy is what a viewer's
page picks up; a playground already open gets it at its next load. The page downloads a widget's code once per
`content_hash`, keeps the code of up to 32 builds, dropping the oldest, and loads every later view of a kept build from
there, so a new build reaches a viewer with its new hash. Where the browser offers no Cache Storage, the page downloads
the code on every view.

### The Widgets tab

A workflow blob's **Widgets** tab, after **Playgrounds**, lists the selected revision's widgets, one row each; a
revision with none reads `No widgets in this revision. Install one with blobhub workflow deploy --yes.` Its columns are
**Alias**; **Label**, a link that opens the row in place; **Group**; **Permissions**, what the widget declares in short,
in the order of [Permissions](#permissions): `key: level`, a list's count as its lines count it, and `links: *` for any
site, as in `objects: write · executions: 2 · links: *`, or a muted `None` for a widget that declares none; and
**Updated**, when the widget was last uploaded, or created if it never was (see [What is stored](#what-is-stored)). A
widget created and never uploaded reads `Install incomplete` in the grid.

A selected row opens in place. It shows the widget's description, its properties with its icon among them, its
permissions in the lines of the **Shown as** column of [Permissions](#permissions), one line per permission and a list's
items beneath it, and the row's JSON. The details pane's **Permissions** section shows the same lines. A widget created
and never uploaded reads `Install incomplete` in both, since its permissions are not known: its open row's properties
are only its alias, label and group, with `Install incomplete` where its permissions go, beside the row's JSON.

A person who can edit the revision can delete the widget there. Delete asks
`Are you sure that you would like to delete widget <alias>?` and, once confirmed, removes the widget's definition from
the revision; a playground that places the widget shows `This revision has no widget named <alias>.` when it next loads.
The tab only reads and deletes: a widget is installed and updated with `blobhub workflow deploy`.

## Limits

* [`workflow.widgets_per_revision`](https://docs.blobhub.io/general/limits#workflow): how many widget definitions one revision may hold.
  Creating one more is refused with `limit_exceeded`.
* [`workflow.widget_definition_bytes`](https://docs.blobhub.io/general/limits#workflow): the size of one widget definition's canonical form.
  A larger upload is refused with `widget_definition_too_large` and a `limit` object, and `deploy` refuses it before
  uploading (`WIDGET_TOO_LARGE`).

Large dependencies belong in the [library catalog](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md), not in a
definition: a library a widget loads from the catalog adds nothing to its definition. A definition near the size limit
may fail its upload or download with a transport error rather than a named refusal: it crosses the API JSON-escaped and
grows on the way, and one made mostly of quotes or non-ASCII text grows the most.

## The kit

BlobHub builds its own widgets, Mission Control among them, with a kit: React hooks over the bridge, the shared
components BlobHub's widgets are made of, the theme and a build preset. The kit is not yet public, so a widget is built
against the bridge protocol these pages document, in plain JavaScript or with any framework that builds to one ES
module.

## See also

* [Bridge Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md): the entry, the wire format, every call,
  event and refusal, and a widget written without the kit.
* [Libraries and Theme](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md): the library catalog, the import map,
  building one module, and BlobHub's light and dark look.
* [Security Model](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-security.md): the frame and its origin, the rules the
  platform enforces, and the risks that remain.
* [Widgets](https://docs.blobhub.io/blob-types/workflow/playgrounds/widgets.md): the built-in widgets.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.