From df5456f441f878ac36c7d81336eb09a8442ea5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aykut=20G=C3=BCney?= <50778230+KeuqS@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:29:50 +0300 Subject: [PATCH] docs: document widget data and CSP handling --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 6074a49..c1ea808 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,57 @@ from nitrostack import WidgetOptions, WidgetCsp, widget `nitrostack-py init` copies `widgets/out/{route}.html` for every `@widget`. Widget HTML is generated in Python from the tool's `structuredContent` (one iframe, N cards). +#### Custom widget HTML: data and host bridge + +The tool result is passed to the widget as a JSON-compatible object. The shared host bridge +normalizes the following sources, in order: + +1. `window.openai.toolOutput.structuredContent` (or `toolResult`). +2. A JSON `application/json` content block, or a JSON object in a `text/plain` content block. +3. The `#nitrostack-tool-data` embedded JSON script used by Python-rendered pages. + +The normalized object is passed to `window.__nitroWidgetRender(data)`. Keep the tool return +shape stable and render from that object. `NITROSTACK_APP_MODE` changes the advertised +metadata and resource MIME type, not this data shape: + +- `openai` uses OpenAI output-template metadata and the OpenAI host data channel. +- `mcp-app` uses MCP Apps `_meta.ui` metadata; tool-result notifications are normalized by the bridge. +- `universal` (the default) publishes both forms. + +A hand-written file found at `widgets/out/{route}.html` is loaded as-is. The loader does +not inject the host bridge into that file. The built-in route templates created by `init` +do include the bridge, so custom HTML must include the equivalent bridge/render hook itself. +The generated files under `examples/widgets/out/` are the reference implementation. + +Minimal render hook (used after the bridge has been included): + +```html +