Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cea857a
feat(api): validate and render widget modules safely
maxsam4 Nov 19, 2026
0c7a807
feat: widget blocks with drafts, publishes and label carry-over
maxsam4 Nov 19, 2026
b7e372b
feat: widget drafts and publishes over REST and MCP
maxsam4 Nov 19, 2026
ee796dd
docs(plugin): widget vocabulary for agents
maxsam4 Nov 19, 2026
885f373
feat: checkpoints keep widgets and restore republishes them
maxsam4 Nov 19, 2026
570d122
fix(api): widget bundles and restores stay inside their own document
maxsam4 Nov 19, 2026
bdbe1f3
fix(api): widget output refuses external references; label words are …
maxsam4 Nov 19, 2026
4ae8cd2
chore: drop the widgets migration to regenerate it on the merged base
maxsam4 Nov 19, 2026
b26908e
Merge collab-m6-pages into collab-m8-widgets
maxsam4 Nov 19, 2026
674e50c
feat(api): widget labels by ops, comments on parts and points, charts…
maxsam4 Nov 19, 2026
c7e8977
feat(web): widgets in the live editor, with labels edited in place an…
maxsam4 Nov 19, 2026
a868f9d
fix(web): widget SVG is mounted as checked nodes, never as markup
maxsam4 Nov 19, 2026
4608bd7
fix: widget attribute values refuse every spelling of an outside refe…
maxsam4 Nov 19, 2026
59e6235
fix(web): one event stream per document, shared by every listener
maxsam4 Nov 19, 2026
6f005c9
fix: one positive value grammar per widget attribute, shared by serve…
maxsam4 Nov 19, 2026
a6c0dda
fix: widget transform values are read by a linear tokenizer, and ever…
maxsam4 Nov 19, 2026
e640b43
fix(web): widgets fill the column, and the comment box stays on screen
maxsam4 Nov 19, 2026
18be991
chore: changeset for widgets in the editor; drop a local check config
maxsam4 Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/widgets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@primer/api": minor
"@primer/web": minor
"@polygonlabs/primer-api-types": minor
"@polygonlabs/primer-mcp": minor
"@polygonlabs/plugin-primer": minor
---

Agents draw diagrams and charts (widgets) in live documents, and people edit their labels in place.

- **Widgets.** A widget is a `widget` block: an SVG drawing an agent writes as one JSX/SVG module (no imports, no fetch, no `style`, no `foreignObject`, colours from theme tokens only). Every typed label carries a literal `data-text-id`, named parts carry `data-anchor`, and marks drawn from rows carry `data-row`/`data-col`.
- **Safe rendering on the server.** Modules are validated (each error with its line and fix), run in QuickJS (WASM, 16 MB, 50 ms, 5,000 elements, no clock or random) and their output always passes a runtime SVG allowlist and bounds (512 KB, a 4096 viewBox). PNG previews come from resvg, drawn in Roboto, the face the page uses.
- **Draft, preview, publish.** `primer_widget_draft` returns light and dark PNG previews; `primer_widget_publish` publishes only that exact preview (`previewHash`); a draft with errors never replaces the live widget. `primer_widget_get` reads a widget with its labels as people see them. REST: `POST /api/documents/:docId/widgets/draft`, `POST /api/widgets/:widgetId/publish`, `GET /api/widgets/:widgetId`, `GET /api/widgets/:widgetId/image`.
- **In the editor.** A widget block draws its live SVG inline for the page's theme. People edit a label in place through the shared overlay (and comment on it there), and click a mark drawn from a row, or a named part, to comment on that data point or part; commented parts are marked and listed under the widget. The SVG is allowlisted on the server and checked again in the browser (one positive value grammar per attribute, shared in api-types as `isWidgetAttributeValue`) before it is mounted as nodes, never as markup.
- **Labels.** Each label's words live in the document (`widget/<blockId>/<textId>`), shaped like page text, so agents edit one with `primer_apply_ops` `update` by `{ tabId, blockId, textId }` and its version, and suggestions keep the `textId`. A republish keeps people's edits: unchanged labels carry them, and when the agent changed the same label the person's words stay and the agent is told.
- **Comments on parts and data points.** A `widget-part` or `data-point` thread is accepted only when the live publish draws that part, or has that row and column.
- **Records.** A draft can draw a records collection (`collection` instead of `rows`); the published widget redraws by itself on `data.changed`, keeping the last good publish if a redraw fails.
- **Checkpoints.** Bundles keep each widget as it looked (`widgets/<id>.light.svg`, `.dark.svg`, `.json`), static renderings and print draw them, restore republishes them, and purge deletes every file a bundle's manifest lists.
- An agent that may only suggest in a document doesn't draw there (a publish changes what people see at once). Comment listeners on a page share one event stream per document.
- **Skill.** `widgets.md` (also the MCP resource `primer://skills/widgets` on both MCP servers, linked from `authoring.md`) teaches the house style and gives copyable flows, trees, 2×2s, timelines, funnels, roadmaps and bar, line and area charts.
- api-types: `WidgetDraftRequest`, `WidgetDraftResponse`, `WidgetPublishResponse`, `WidgetDTO`, `WidgetLabelDTO`, `WidgetError`, `WidgetLabelOutcome`, `isWidgetAttributeValue`, and the refusal code `widget_invalid`.
- New dependencies: `quickjs-emscripten-core` and `@jitl/quickjs-wasmfile-release-sync` (MIT), `acorn` and `acorn-jsx` (MIT), `@resvg/resvg-js` (MPL-2.0), `roboto-fontface` (Apache-2.0, in the API and the web app).
21 changes: 21 additions & 0 deletions apps/api/drizzle/0023_widgets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE "widgets" (
"id" uuid PRIMARY KEY NOT NULL,
"document_id" uuid NOT NULL,
"block_id" text NOT NULL,
"draft_source" text,
"draft_rows" jsonb,
"draft_errors" jsonb,
"published_source" text,
"published_svg_light" text,
"published_svg_dark" text,
"published_hash" text,
"rows" jsonb,
"collection" text,
"draft_collection" text,
"updated_by" text NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "widgets" ADD CONSTRAINT "widgets_document_id_documents_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."documents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "widgets" ADD CONSTRAINT "widgets_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "widgets_document_id_idx" ON "widgets" USING btree ("document_id");
Loading
Loading