Bento Spaces docs

Bento Spaces documentation

Widgets

A widget fills a container. It never owns geometry. Two formats exist; the first is safe by construction and is the default.

The manifest

Every widget, in every format, ships a manifest. It is the only thing the editor needs to decide whether a widget fits a container.

{
  "id": "clock",
  "name": "Clock",
  "version": "1.2.0",
  "sizes": ["1x1", "2x1", "2x2", "4x2"],
  "defaultSize": "2x1",
  "fit": "exact",
  "role": "ambient",
  "refresh": null,
  "vars": [],
  "data": null,
  "permissions": { "network": [], "actions": [] }
}
FieldMeaning
sizesthe renderings the developer actually drew, in boxes
defaultSizewhat the picker inserts by default
fitexact (only listed sizes), nearest (closest size, letterboxed), stretch (any size)
roleambient (glanceable) or interactive (needs big hit areas)
refreshnull, "5s", "30s", "60s", "5m", "10m"; a data widget with no field defaults to "5m", explicit null disables polling
varsnames a widget may interpolate into its data URL
data.modeproxy: the host fetches; client is accepted as a legacy alias but still goes through the host
data.urlabsolute http(s) URL or a /path on this Bento Spaces host
data.pathoptional dot path into the JSON, used by {{data}}
data.cacheTtl0s, 5s, 30s, 60s, 5m, 10m
permissions.networkorigins the widget may read, or "self" for this host
permissions.actionsopen, refresh, setProps (modules only)
permissions.connectortrue lets the declared action post through an account connector

Fit rules in the editor. A widget can only be dropped into a container whose size is in sizes, or any size when fit is stretch. Illegal targets dim to 50% with a red border and refuse the drop. Containers are locked while filled, so a resize can never create a mismatch.

Built-ins

Twenty-one trusted modules live in web/src/widgets/builtin/. All but gree, http and ha are secret-free: they stay visible in shared views and in an HTML export. See 14 — Widget catalogue for the tier model.

WidgetSizesNotes
clock1×1, 2×1, 1×2, 2×2, 4×2ticks every second; optional second timezone
stat1×1, 2×1, 2×2, 4×2label + value + unit
noteanything (stretch)double-click to edit
links2×1, 2×2, 4×2, 4×4opens in a new tab
image ("Photo frame")anything (stretch)one or more URLs, cross-fade slideshow
progress2×1, 4×1, 2×2, 4×20..1 bar
countdown1×1, 2×1, 2×2ticks every second only while it has a target; optional yearly repeat
weather1×1, 2×1, 2×2, 4×2Open-Meteo; current, feels-like, 3-day forecast
feed2×1, 2×2, 4×1, 4×2, 2×4, 4×4RSS/Atom through /api/live/feed
markets2×1, 4×1, 2×2, 4×2, 2×4, 4×4CoinGecko coins + Frankfurter FX
qr1×1, 2×1, 2×2, 4×2local encoder (v1–10, L/M/Q/H), drawn as SVG
sun1×1, 2×1, 2×2, 4×2sunrise/sunset + moon phase; Open-Meteo daily
units1×1, 2×1, 2×2, 4×1, 4×2local unit conversion, no network
dice1×1, 2×1, 2×2, 4×2d2–d100, up to 12 dice, or a list picker
holidays1×1, 2×1, 2×2, 4×1, 4×2, 2×4, 4×4Nager.Date, next public holidays
crypto2×1, 2×2, 4×1, 4×2CoinGecko market chart + sparkline
air1×1, 2×1, 2×2, 4×2European AQI, PM2.5, PM10
gree2×1, 2×2, 4×2account connector to a local Gree bridge; power, temperatures, toggle
http ("HTTP card")1×1, 2×1, 2×2, 4×2one connector path mapped to dotted-path fields; templates and inferred fields
ha ("Home Assistant")1×1, 2×1, 2×2, 4×2one HA entity: state, unit, friendly name, toggle for lights/switches/fans
transit ("Departures")2×1, 2×2, 4×1, 4×2TfL or BVG departures for a stop, 60 s refresh

Where their data comes from. Either a direct fetch to a CSP-allowed public host, or the API-hosted /api/live/feed proxy for feeds (which do not send CORS headers). Widgets never hold a token, and a failed request paints a one-line message in the box.

Configuration. A widget that has settings declares config: { title, fields } — field types are text, number, boolean, select and textarea; a select lists strings or { value, label } pairs. In edit mode the shelf shows a gear on hover and opens one shared settings dialog for every widget. A widget with a custom action instead of fields exports configure(el, ctx) (Gree uses this to open the connector list). View-mode double-click is reserved for shortcuts and never opens a prompt.

Refresh is per placement. Every polling widget also has a Refresh… entry in the block menu: Default (which names the widget's own interval, e.g. Default (10 minutes) for weather), Off, 30 s, 1 min, 5 min, 10 min, 30 min or 1 hour. The choice is stored in that placement's props with its space, so one weather card can poll every minute and another every hour; Off loads once and stops. Widgets that do not poll (clock, countdown, note, …) do not offer it. The timer helper is shared, so a new polling widget gets the same behaviour by using startRefresh/stopRefresh from web/src/widgets/refresh.js.

Auditing the catalog. node scripts/audit-widgets.mjs compares the 21 built-ins with the marketplace releases: ids, names, manifest validity, hashes, sizes and functional overlap. node scripts/e2e/widget-sweep.e2e.mjs mounts every built-in at every declared size in a real browser and destroys it again. tests/widgets.test.js also fails if a .wg-* rule gives a font-size in px: widget text has to stay in em so the device zoom scales it.

Installed widgets and the in-app marketplace

The add-widget picker lists the account's library: the built-ins it has enabled plus the registry widgets it has installed. With a large catalog that stays small; adding a widget type to the library is an explicit act.

Declarative widgets (shipped in P4)

Beyond the built-ins, a widget can be a JSON manifest with no code. It is validated by one shared module (web/src/widgets/declarative.js), installed from a registry, and interpreted by the same renderer. Render types: stat, badge, text, list, image, progress, clock, link.

{
  "id": "deploy-status",
  "name": "Deploy status",
  "version": "1.0.0",
  "sizes": ["1x1", "2x1", "2x2"],
  "defaultSize": "2x1",
  "fit": "exact",
  "role": "ambient",
  "refresh": null,
  "vars": [],
  "data": null,
  "render": { "type": "stat", "label": "Deploy", "value": "ok", "unit": "" }
}

Data through the host proxy

A declarative widget reads JSON by declaring where it comes from. The browser calls POST /api/widgets/{id}/{version}/data; the host checks the installed manifest and fetches. The widget never talks to the network itself.

{
  "id": "site-status",
  "name": "Site status",
  "version": "1.0.0",
  "sizes": ["1x1", "2x1", "2x2"],
  "defaultSize": "2x1",
  "fit": "exact",
  "refresh": "30s",
  "data": {
    "mode": "proxy",
    "url": "/example-data/status.json",
    "path": "deploy",
    "cacheTtl": "30s"
  },
  "permissions": { "network": ["self"], "actions": [] },
  "render": { "type": "stat", "label": "Deploy", "value": "{{data}}" }
}

If the fetch fails the widget says Unavailable instead of showing stale or fake data.

Connector data

Instead of data.url, a widget can read through an account connector:

{
  "permissions": { "network": [], "connector": true },
  "data": { "mode": "connector", "connector": "/api/state", "path": "armed" },
  "render": { "type": "stat", "label": "Blocking", "value": "{{data}}" }
}

Actions (connectors)

A declarative widget can act on one account connector — a button, not a script. It has to ask for the permission and declare exactly one action:

{
  "permissions": { "network": [], "connector": true },
  "render": { "type": "stat", "label": "Blocking", "value": "Armed" },
  "action": {
    "label": "Disable blocking",
    "method": "POST",
    "path": "/api/blocking?disable=600",
    "body": { "note": "{{var:reason}}" }
  }
}

A bundled example registry lives at /registry-example.json (three widgets under /example-widgets/), so the whole flow can be tried without hosting anything.

Format B — sandboxed modules (shipped in P5)

A manifest can carry source instead of a render spec:

{
  "id": "pulse",
  "name": "Pulse",
  "version": "1.0.0",
  "sizes": ["2x2", "4x2"],
  "defaultSize": "2x2",
  "fit": "exact",
  "render": { "type": "module" },
  "module": {
    "source": "self.widget = { mount(el, ctx) { … } }",
    "assets": [
      { "name": "helper.js", "text": "self.helper = 1;" },
      { "name": "theme.css", "text": ".card { color: var(--accent); }" }
    ]
  }
}

The source is a classic script that defines self.widget with mount(el, ctx), update(el, ctx) and destroy(el). ctx exposes props, size, setProps(patch), emit(name, payload), request({ url }), asset(name), open(url) and refresh().

Assets. Up to five text files (1–32 KB each, 96 KB total) travel inside the immutable release. ctx.asset("helper.js") returns the text or null; the module decides how to use it (a <script>, a <style>, JSON). Nothing is fetched: the frame receives the map as window.__bentoAssets before the module runs, and assets may not contain </script.

Studio can author this format: the module source gets its own editor, Add asset files bundles text assets into the manifest, and the sandboxed preview uses the same CSP; everything ships inside the manifest. It runs in an iframe with sandbox="allow-scripts" and no allow-same-origin, so the origin is opaque: no cookies, no storage, no parent DOM. The frame document is served by the host at /api/widgets/{id}/{version}/frame with its own CSP (sandbox allow-scripts; default-src 'none'; …; connect-src 'none'), so the frame itself still cannot touch the network. Because an opaque-origin frame sends no cookies, the client first requests a 12-hour frame token and puts it in the URL.

ctx.request({ url }) posts to the parent, which calls the same proxy as declarative widgets. The URL must be inside permissions.network. ctx.open(url) opens a link (requires actions: ["open"] and a network origin), ctx.refresh() asks the shelf to call update, and ctx.setProps(patch) requires actions: ["setProps"]. Actions and origins are shown at install and enforced in the parent and on the server.

Source is capped at 64 KB and may not contain </script; asset rules are in the same validator. The frame's base font-size follows the bento zoom, so author module CSS in em/rem to scale with the board.

The harness at /harness.html renders modules too (with the same token flow).

Format A — declarative (reference)

No code runs. The host renders a small vocabulary from JSON, which means a widget can be reviewed by reading ten lines, and an AI can generate one safely.

{
  "id": "gpu-temp",
  "name": "GPU temperature",
  "version": "1.0.0",
  "sizes": ["1x1", "2x1", "2x2"],
  "defaultSize": "2x1",
  "fit": "stretch",
  "refresh": "30s",
  "data": {
    "mode": "proxy",
    "url": "https://api.example.com/gpu",
    "path": "temp",
    "cacheTtl": "30s"
  },
  "permissions": { "network": ["https://api.example.com"], "actions": [] },
  "render": { "type": "stat", "label": "GPU", "unit": "°C", "value": "{{data}}" }
}

Data: host-proxied GET, refresh, optional cacheTtl, a simple dot path, and {{data}} / {{data:path}} / {{var:name}} interpolation. Render: stat, text, list, image, progress, badge, clock, link. Actions: declarative widgets have none yet; actions belong to sandboxed modules.

Rules: no script, no eval, no remote CSS or fonts, https images only, text always escaped, prefers-reduced-motion respected, 44 px touch targets.

Where widgets live

data/users/{userId}/widgets/library.json            ← built-ins this account removed
data/users/{userId}/widgets/{widgetId}/{version}/   ← installed bundles, all that user's spaces
data/users/{userId}/widgets/settings/{widgetId}.json ← shared defaults (connector id only, today)
data/users/{userId}/spaces/widgets/{instanceId}.json ← one placement's values, no space
web/src/widgets/builtin/                            ← built-in modules, shipped with the client

The library is available in every space that user owns, never to anyone else. Containers reference { "type": "clock", "version": "1.2.0" }; the loader renders a built-in only while its id is enabled in the library, otherwise it uses the installed manifest. A disabled built-in is not deleted — its code is part of the client — so re-enabling it restores every placement.

Instance values sit outside any space, next to layout.json rather than inside it. That is what makes the block menu's Move to space… a two-layout edit: the widget and all its props change owner, and widgets/settings/{widgetId}.json is not touched. Copy to space… creates a new instance with cloned props; the two copies then evolve independently.

Common settings resolve as instance props > widgets/settings/{widgetId}.json > manifest defaults. Only gree ships a common file today (the connector id); deviceId stays per instance so two rooms never collide.

Uninstalling a type never deletes instance values, so reinstalling the same id restores every placement in every space. Remove from space is the placement action: it trashes the instance and removes the container, and the shelf undo puts both back. Trash is pruned after seven days.

Registries (federated)

A registry is a static registry.json that anyone can host — a company, a gallery on GitHub Pages, the Official source.

{
  "schema": 1,
  "name": "Bento Official",
  "suggested": ["clock", "weather"],
  "widgets": [{
    "id": "clock",
    "name": "Clock",
    "developer": "Bento",
    "tags": ["time"],
    "latest": "1.2.0",
    "versions": [
      { "version": "1.2.0", "notes": "Faster startup", "url": "https://…/clock/1.2.0.zip",
        "sha256": "…", "sizes": ["1x1","2x1"], "permissions": { "network": [], "actions": [] } }
    ]
  }]
}

Developer tooling

Caching and offline

AssetCache
widget files (id/version/…)max-age=31536000, immutable
registry.jsonno-store
widget data (/api/widgets/*/data)no-store unless the manifest sets cacheTtl
installed bundlesservice worker runtime cache
the app shellnetwork-first with a cache fallback; see 15 — PWA and offline
last widget readinglocalStorage snapshot, rendered stale when a refresh fails

While idle (see UI) widgets are unmounted and refresh stops; waking remounts and refetches.