React in a view

Every workflow becomes a scene: its data, its tools, the agent that runs it, and the history of everything it did. Everything in a scene is a cell, a value and a view that shows it. A view is one self-contained HTML document, which is enough to run React from a CDN with no build step. The value and the viewer's sign-in are already in the page when it loads, so a React view is usually shorter than the same component in an app of your own.

The page finds its value on window

The renderer puts these beside your HTML, so the document itself never holds data or credentials:

GlobalWhat it is
window.__DASLAB_WIDGET_DATA__The cell's value: what its formula last computed, or the literal written to it. Inlined, so the first render needs no request.
window.__DASLAB_WIDGET_META__When that value was computed, and whether it is stale or its last refresh failed.
window.daslabReadyResolves to the client factory. d.call('<tool>', input) runs a tool as the person viewing, with no token to pass.

The formula fetches the data and the view draws it

Compute in the formula, not in the page. The value then lives in the cell, where every viewer and the agent read the same thing, and the server keeps it fresh. Two calls make a forecast view. The first creates the view with the page further down:

daslab_add_cell {
  "type": "view",
  "name": "Forecast",
  "config": { "html": "<the page below>" }
}

The second gives it a formula that fetches the forecast and shapes it. The server runs it at once and again whenever the scene is read and the value is more than an hour old:

daslab_write_script {
  "cell_id": "<the view's id>",
  "ttl_seconds": 3600,
  "fn": [
    { "id": "fetch", "op": "http_request",
      "params": { "url": "https://api.open-meteo.com/v1/forecast?latitude=13.75&longitude=100.5&daily=temperature_2m_max,precipitation_probability_max&timezone=Asia/Bangkok" } },
    { "op": "core.transform",
      "params": { "over": "$fetch.json",
        "jq": "{ days: [range(0; .daily.time | length) as $i | { date: .daily.time[$i], max: .daily.temperature_2m_max[$i], rain: .daily.precipitation_probability_max[$i] }] }" } }
  ]
}

The page only draws what the formula left in the cell, and says how old it is:

<div id="root"></div>
<script type="module">
  import React from "https://esm.sh/react@19.1.0";
  import { createRoot } from "https://esm.sh/react-dom@19.1.0/client?deps=react@19.1.0";
  const h = React.createElement;

  function Forecast({ value, meta }) {
    if (!value) return h("p", null, "No forecast yet.");
    const asOf = meta.state === "failed"
      ? "Refresh failed, showing the last good forecast"
      : meta.computed_at ? `As of ${new Date(meta.computed_at).toLocaleTimeString()}` : "";
    return h("div", null,
      h("ul", null, value.days.map((d) =>
        h("li", { key: d.date }, `${d.date} · ${Math.round(d.max)}° · ${d.rain}% rain`))),
      h("small", null, asOf));
  }

  createRoot(document.getElementById("root")).render(
    h(Forecast, {
      value: window.__DASLAB_WIDGET_DATA__,
      meta: window.__DASLAB_WIDGET_META__ ?? {},
    }));
</script>
  • A failed refresh keeps serving the last good value, so a view that shows computed data should say when it is from. __DASLAB_WIDGET_META__ is how the viewer can tell.
  • Pin the version on every esm.sh URL and never use @latest, which is a redirect with no long cache and can change under you. ?deps=react@19.1.0 on ReactDOM makes it use the same copy of React the page imported.

A view can act as the person viewing it

d.call(tool, input) runs any tool in the scene as the signed-in viewer, the same tools a job calls, by the same names. Reading works straight away. A tool that needs approval, such as posting a message or creating a record, is refused at view time, because a page can't raise an approval prompt.

const d = (await window.daslabReady)();
await d.call("slack_post_message", { channel_id: "C0123ABC", text: "Forecast checked" });

Grant the view those tools once and its calls run unattended from then on:

daslab_grant_view_tools { "asset_id": "<the view's id>", "tools": ["slack_post_message"] }

The grant itself waits for your approval, covers only that view and those tools, and replaces the view's earlier grant. Irreversible tools can never be granted. A view opened without a session, such as a public snapshot, can't call tools at all: the first d.call throws a display-only error.

JSX belongs in your own toolchain

The example writes h(…) instead of JSX. In-browser Babel is the one transform that makes a view slow, so skip it. If you want JSX, build the component in your own toolchain and paste the built output: the globals are the same either way.

Updated 2026-11-14