Codumentor logo Codumentor Enterprise

UI Components

UI plugins are TypeScript projects that produce Web Components (Custom Elements) for the Codumentor interface. This guide covers directory structure, the Plugin SDK, widget development, and building.

See also: Backend Hooks, User Gates (per-user blocking modals), Best Practices, Plugin SDK README


Directory Structure

ui/plugins/my_plugin/
├── manifest.json       # Plugin metadata
├── package.json        # NPM dependencies and build script
├── tsconfig.json       # TypeScript configuration
├── index.js            # Built bundle (generated)
└── src/
    ├── index.ts        # Entry point - registers custom elements
    ├── types.ts        # Data interfaces
    ├── styles.ts       # Component CSS
    └── components/     # Component files (optional organization)
        └── my-card.ts

Quick Start

  1. Copy the template:

``bash
cp -r ui/plugins/_template ui/plugins/my_plugin
``

  1. Update manifest.json:

``json
{
"plugin_id": "my_plugin",
"name": "My Plugin",
"version": "1.0.0",
"description": "What this plugin does",
"event_types": ["plugin.my_plugin.completed"],
"transcript_events": {
"*": { "role": "card", "element": "x-my-plugin-card" }
},
"ui": {
"bundle": "index.js",
"sdk_version": "1.0",
"custom_elements": ["x-my-plugin-card"],
"placements": ["transcript-card"]
}
}
``

transcript_events (top level, not under ui) declares what each event
means to the conversation and which element draws it — see
Transcript events.

The file's JSON Schema ships with the SDK
(@codumentor/plugin-sdk/manifest.schema.json; plugin new copies it to
ui/types/manifest.schema.json). Add "$schema": "<path to it>" for editor
completion — the host ignores the key — and codumentor plugin validate
checks the manifest against it.

Supported ui.placements values (the ExtensionPlacement union in
ui/src/types/api.ts):

| Placement | Where it renders |
|---|---|
| transcript-card | Plugin events in the transcript — as a line, card or receipt chip by the event's role (see Transcript events) |
| message-actions | Controls in the assistant turn action row (next to copy) |
| chat-header | Small components in the chat header (see Chat Header Widgets) |
| message-list-header | An in-flow row above the transcript's scroll viewport |
| composer-intent | Left of the composer textarea: what this turn does (see Composer Controls) |
| composer-input | Right of the composer textarea: how I am entering this message |
| composer-tray | The state row above the composer textarea (see the tray) |
| activity-panel | Deprecated, not rendered. The activity side panel was removed; manifests declaring it still validate, but the widget never mounts. Background work now shows in the strip above the composer. |
| permission-card | A whole card for a plugin-owned pending permission; see Permission cards. |
| workspace-view | A view in the chat's workspace pane. Widget fields: icon (a host icon name, e.g. files), availability (always \| conversation \| items, default conversation), shortcut (adds an "Open " header-menu entry). Loaded on first activation; the host sets <code>plugin-id</code>, <code>widget-id</code>, <code>conversation-id</code>, <code>locale</code>, <code>active</code>, <code>layout</code> (<code>split</code> \| <code>mobile</code>) and <code>.target</code> / <code>.items</code>; the element may dispatch <code>workspace-view-state</code> <code>{badge?, busy?, title?}</code>. Guide: <a href="workspace-views.html">workspace-views.md</a> |<br> | <code>welcome-widget</code>, <code>welcome-repos</code> | Welcome page widget surfaces (see <a href="#welcome-page-widgets">Welcome Page Widgets</a>) |<br> | <code>sidebar-panel</code> | Plugin-driven sidebar surface |<br> | <code>admin-panel</code> | Panels on the admin hub page (see <a href="#admin-panels">Admin Panels</a>) |<br> | <code>ingestion-panel</code> | Panels inside the Ingestion page (see <a href="#ingestion-panels">Ingestion Panels</a>) |</p> <p> The type is <code>… | string</code>, so a plugin may declare a custom slot; it renders<br> only where some host component mounts that placement.</p> <ol> <li><strong>Update <code>package.json</code>:</strong></li> </ol> <p> ``<code>json<br> {<br> "name": "@codumentor/plugin-my-plugin",<br> "version": "1.0.0",<br> "type": "module",<br> "scripts": {<br> "build": "node ../../scripts/plugin-esbuild.js",<br> "build:watch": "node ../../scripts/plugin-esbuild.js --watch",<br> "typecheck": "tsc --noEmit"<br> },<br> "devDependencies": {<br> "@codumentor/plugin-sdk": "file:../../../sdk/web",<br> "typescript": "^5.3.0"<br> }<br> }<br> </code>``</p> <p> The build itself is the SDK's (<code>sdk/web/scripts/plugin-build.js</code>, the code<br> behind the <code>codumentor-plugin build</code> bin an out-of-tree plugin uses);<br> <code>ui/scripts/plugin-esbuild.js</code> runs it for in-tree plugins, so no<br> package.json spells out esbuild flags. Two things it does matter to you:</p> <ul> <li>Bundles ship minified.</li> <li>The SDK is <strong>external</strong>. <code>@codumentor/plugin-sdk</code> (and its <code>/styles</code> and <code>/utils</code> subpaths) is rewritten to <code>/ui/extensions/sdk/index.js</code>, the one shared SDK bundle the browser loads once, rather than inlined into your bundle. Which is why your bundle is a few KB rather than 110 KB, and why <code>sdk/web/dist/bundle/index.js</code> has to be built before yours — the orchestrator (<code>npm run build:plugins</code>) does that for you.</li> </ul> <ol> <li><strong>Create your component in <code>src/index.ts</code>:</strong></li> </ol> <p> ```typescript<br> import {<br> BasePluginElement,<br> bindExpandClick,<br> getBaseStyles,<br> escapeHtml,<br> formatMs,<br> } from "@codumentor/plugin-sdk";</p> <p> interface MyPluginData {<br> message: string;<br> duration_ms?: number;<br> }</p> <p> class MyPluginCard extends BasePluginElement<MyPluginData> {<br> render(): void {<br> const { message, duration_ms } = this._data;</p> <p> // Declared as a card, the host draws the frame, status edge and status<br> // glyph: <code>CARD_STYLES</code> unframes <code>.card</code> and <code>getStatusIcon()</code> returns ""<br> // then, so this markup is the body only.<br> this._shadowRoot.innerHTML = <code><br> <style>${getBaseStyles()}</style><br> <div class="card ${this._status}"><br> <div class="header"><br> <span class="icon">${this.getStatusIcon()}</span><br> <span class="title">My Plugin</span><br> ${duration_ms ? </code><span class="badge">${formatMs(duration_ms)}</span><code> : ""}<br> </div><br> <p>${escapeHtml(message)}</p><br> </div><br> </code>;<br> }<br> }</p> <p> // Register custom element - tag MUST match manifest.json<br> if (!customElements.get("x-my-plugin-card")) {<br> customElements.define("x-my-plugin-card", MyPluginCard);<br> }</p> <p> export { MyPluginCard };<br> ```</p> <ol> <li><strong>Build:</strong></li> </ol> <p> ``<code>bash<br> cd ui && npm run build:plugins<br> </code>``</p> <hr> <h2 id="permission-cards">Permission cards</h2> <p>Declare a card at the <strong>top level</strong>, not as a widget. The key is the exact<br> permission type: use <code><plugin_id>.<type></code> for new types. The existing<br> <code>browse_handoff</code> wire type belongs to <code>browse</code>.</p> <pre><code class="language-json">"permission_cards": { "browse_handoff": { "element": "x-browse-handoff-card", "workspace_view": "handoff" } }</code></pre> <p>List the card in <code>ui.custom_elements</code> and <code>permission-card</code> in <code>ui.placements</code>.<br> For a workspace offer, also declare <code>workspace-view</code> and a widget of that<br> placement with the referenced <code>widget_id</code>, <code>availability: "items"</code>, a title<br> and its own declared custom element. Define <strong>both</strong> tags in the bundle. The<br> workspace element is a readiness marker for this route: the host renders the<br> card directly in the active tab panel. It needs no second stream or state.</p> <p>The host sets the SDK's <code>PermissionCardElement</code> properties before connecting:<br> <code>.permission</code> (<code>requestId</code>, <code>toolCallId</code>, <code>toolName</code>, <code>permissionType</code>, <code>details</code>),<br> <code>.locale</code>, <code>.onDecision("allow" | "deny")</code>, <code>.isSubmitting</code>, and <code>.active</code>.<br> A localized <code>.cardTitle</code> getter names the host frame. Disable decision controls<br> while submitting; release streams and input listeners on disconnect. Opening,<br> closing, or hiding a view <strong>never</strong> answers a request.</p> <p>By default the host frame is a header, a scrolling body holding the card, and a<br> host footer with Cancel. A card that needs the whole frame (a live view, say)<br> sets a <code>.ownsLayout</code> getter to <code>true</code>: the host then draws no footer, and its<br> body becomes a non-scrolling flex column that fills the height it has (the<br> workspace pane, or the modal's <code>min(90dvh, 100%)</code>), with the element stretched<br> to it; lay the card out as a flex column and scroll inside it where needed.<br> The host reads <code>ownsLayout</code> with <code>cardTitle</code>, after it sets the inputs. Such a<br> card must offer its own Cancel (<code>onDecision("deny")</code>) and keep it usable while the rest of the card is busy. If the bundle fails to load, the<br> host frame and its Cancel return as usual.</p> <p>Only the first pending permission is offered. A workspace offer never changes<br> focus or selection. It lasts only as long as that pending request: don't<br> publish a <code>workspace.item</code> or emit a separate handoff event. With the pane off,<br> a withheld/unavailable widget, or a missing workspace element, the same card<br> appears in a host modal. If the card cannot load the host offers Cancel only.<br> Unless the card sets <code>ownsLayout</code>, the host's Cancel remains available even if<br> the renderer stops responding.</p> <h2 id="transcript-events-roles-and-presentations">Transcript events: roles and presentations</h2> <p>Every plugin event that reaches the transcript has a <strong>role</strong>, and the host<br> turns the role into placement, frame, spacing, disclosure and focus-mode<br> behaviour — on the web and in the TUI alike. Your element draws content only.<br> Design and rationale:<br> plugin-activity-presentation.md.</p> <h3 id="the-four-roles">The four roles</h3> <p>Decide an event's role by asking, in order:</p> <ol> <li>Does it mark a change to the <strong>conversation itself</strong>, true from this point on? → <strong><code>line</code></strong></li> <li>Is it <strong>output, live work, or something the user must act on</strong>? → <strong><code>card</code></strong></li> <li>Otherwise it is <strong>bookkeeping about the turn it belongs to</strong> → <strong><code>receipt</code></strong></li> </ol> <table> <thead> <tr><th>Role</th><th>Where it renders</th><th>Examples</th></tr> </thead> <tbody> <tr><td><code>line</code></td><td>A quiet rule across the column with a sentence in it, at the event's position. May open a document below the rule.</td><td>model/effort seam, compaction, push marker, topic shift</td></tr> <tr><td><code>card</code></td><td>A host-framed card at the leading (left) edge, at the event's position — like a tool card. Opening it grows it in place.</td><td>file written, process with Kill, server with Start/Retry, scheduled run, an error to fix</td></tr> <tr><td><code>receipt</code></td><td>A chip in the turn's single <strong>receipt strip</strong>, under the answer. One chip's panel open at a time, full column width.</td><td>timings, metrics, memories recalled/stored, skill loaded, context state</td></tr> <tr><td><code>none</code></td><td>Nothing.</td><td>a terminal outcome that should disappear (below)</td></tr> </tbody> </table> <p>A receipt is attached to the turn named by its event's <code>turn_id</code> (below), and<br> the strip sits above the turn's action row; while the turn runs it sits at the<br> live bottom edge, so a pending "Recalling…" chip is visible before the answer<br> streams in above it. A receipt with no turn (before the first user message, or<br> inside a subagent's nested transcript) renders as a card.</p> <p>In <strong>focus mode</strong> lines stay visible, the receipt strip stays under the<br> answer, and cards fold into the work chip unless the event sets<br> <code>data.focus_visible: true</code> (see focus-mode.md<br> §"Plugin event visibility").</p> <h3 id="declaring-roles-transcript_events">Declaring roles: <code>transcript_events</code></h3> <p>Declare role and element per event subtype in <code>ui_manifest()</code>, at the **top<br> level** of the manifest — beside <code>event_types</code>, not inside <code>ui</code>. The role is<br> surface-agnostic (the TUI resolves it too), so a plugin without a web bundle<br> declares it as well. A static <code>manifest.json</code> carries the same top-level key.</p> <pre><code class="language-python">def ui_manifest(self) -> dict: return { "plugin_id": "my_plugin", "event_types": [ "plugin.my_plugin.turn_complete", "plugin.my_plugin.rdc_started", "plugin.my_plugin.rdc_retrieved", "plugin.my_plugin.file_written", ], "transcript_events": { "turn_complete": {"role": "receipt", "element": "x-my-metrics"}, "rdc_*": {"role": "receipt", "element": "x-my-recall"}, "*": {"role": "card", "element": "x-my-plugin-card"}, }, "ui": { "bundle_url": "/ui/extensions/plugins/my_plugin/index.js", "custom_elements": ["x-my-metrics", "x-my-recall", "x-my-plugin-card"], "placements": ["transcript-card"], }, }</code></pre> <ul> <li><strong>Keys</strong> match the event subtype (the part after <code>plugin.<id>.</code>): an exact key wins, then the longest <code>prefix<em></code> key, then <code>"</em>"</code> (the plugin default).</li> <li><strong>Field by field</strong>: a key that declares only an <code>element</code> leaves the role to a broader key, and an <code>element</code> your bundle did not register does not count (a broader key's element is used instead).</li> <li><strong><code>role</code></strong> is one of <code>line</code>, <code>card</code>, <code>receipt</code>, <code>none</code>. An unknown value is dropped with a warning (the rest of the manifest survives) and ignored.</li> <li><strong><code>element</code></strong> is the custom element that renders the subtype. It wins over the plugin-wide <code>ui.transcript_card</code> and over subtype guessing.</li> <li>A group whose pending and terminal subtypes map to different elements remounts the element on the update; host-held expansion survives.</li> </ul> <p>An event your manifest does not declare falls back to a default:<br> <code>data.align == "full"</code> → line (your element still draws its own rule), anything<br> else → a left card. Declare every subtype you emit.</p> <h3 id="per-event-override-datarole">Per-event override: <code>data.role</code></h3> <p><code>data.role</code> (<code>"line" | "card" | "receipt" | "none"</code>) overrides the manifest for<br> one event or group update; unknown values are ignored. Its main use is<br> <code>"none"</code> on a terminal update: a producer whose outcome turned out to be<br> empty sends the terminal update with <code>role: "none"</code>, the lifecycle update is<br> applied first, then the chip (or card) is removed — live and after reload.<br> Do not use <code>_hidden</code> for that: materializers drop <code>_hidden</code> events before the<br> group update, which strands the pending chip.</p> <pre><code class="language-python">await emit("plugin.my_plugin.rdc_retrieved", { "status": "success", "event_group_id": run_id, "role": "none", # nothing recalled: no chip at all }, turn_id)</code></pre> <h3 id="whole-state-group-updates-datasupersedes_group">Whole-state group updates: <code>data.supersedes_group</code></h3> <p>A group update is a <em>patch</em>: the materializers merge <code>{<strong>old, </strong>new}</code>, so every<br> event of the group is kept in the store. A producer whose every update carries<br> the group's <strong>complete</strong> state — a live card refreshed several times a turn —<br> can set <code>supersedes_group: true</code>. The event store then deletes the group's<br> earlier events of the same type once the new one is written, so the group<br> costs one stored row however often it updated. Live clients see no difference;<br> a reload finds only the newest row, so a key that only an earlier update<br> carried is gone — do not set the flag on partial updates.</p> <pre><code class="language-python">await emit("plugin.my_plugin.snapshot", { **whole_state, "event_group_id": f"my_plugin:{turn_id}", "supersedes_group": True, }, turn_id)</code></pre> <h3 id="element-presentations">Element presentations</h3> <p>The host mounts your element with a <code>presentation</code> property (reflected as an<br> attribute, so your stylesheet can key off <code>:host([presentation="chip"])</code>):</p> <table> <thead> <tr><th><code>presentation</code></th><th>Mounted for</th><th>Your element renders</th></tr> </thead> <tbody> <tr><td><code>"line"</code></td><td>a line</td><td>the glyph and text <em>inside</em> the host's rule — never the rule</td></tr> <tr><td><code>"panel"</code> (line)</td><td>below a line's rule, only when the <code>line</code> instance's <code>hasPanel</code> is true</td><td>a closed one-line preview, and the document while <code>expanded</code></td></tr> <tr><td><code>"card"</code></td><td>a card (and a receipt with no strip)</td><td>the card <strong>body</strong> — no outer frame, no status edge, no status glyph</td></tr> <tr><td><code>"chip"</code></td><td>a receipt's chip in the strip</td><td>glyph, short label, optional value (~24 characters) — use <code>chipHtml()</code> + <code>RECEIPT_STYLES</code></td></tr> <tr><td><code>"panel"</code> (receipt)</td><td>below the strip while the chip is open</td><td>the whole panel, actions included, with no frame or header (the chip is the header)</td></tr> </tbody> </table> <p><strong>Declaring support.</strong> List the presentations your element draws in a static<br> <code>presentations</code> on its class; the host reads it off <code>customElements.get(tag)</code><br> before mounting. The default is <code>["card"]</code>. Listing <code>"chip"</code> implies the<br> receipt <code>"panel"</code>. Lines need no declaration.</p> <pre><code class="language-typescript">import { BasePluginElement, chipHtml, RECEIPT_STYLES, getBaseStyles, formatMs } from "@codumentor/plugin-sdk"; class MyMetrics extends BasePluginElement<{ elapsed_ms: number }> { static presentations = ["card", "chip"] as const; get hasPanel() { return true; } render() { if (this.presentation === "chip") { this._shadowRoot.innerHTML = `<style>${RECEIPT_STYLES}</style>` + chipHtml({ glyph: "⏲", label: "Turn", value: formatMs(this._data.elapsed_ms) }); return; } // "panel" and "card": the body only — the host draws frame and status. this._shadowRoot.innerHTML = `<style>${getBaseStyles()}</style><div class="card">…</div>`; } }</code></pre> <p>A receipt element that does <strong>not</strong> list <code>"chip"</code> gets a host-drawn chip from<br> <code>data.chip_label</code>, else <code>data.summary</code>, else the plugin and action names, and<br> its card presentation inside the open panel. So the cheapest good receipt is a<br> short <code>chip_label</code> in the event data. Plugins without a web bundle get the same<br> three presentations from the generic fields (<code>summary</code>, <code>chip_label</code>,<br> <code>details_lines</code>, <code>details_markdown</code>) through the host fallback renderer.</p> <p><strong>What the host reads off your element</strong> after every event and whenever you<br> call <code>notifyHost()</code> (which dispatches <code>PLUGIN_ELEMENT_CHANGED_EVENT</code>):</p> <table> <thead> <tr><th>Member</th><th>Instance</th><th>Meaning</th></tr> </thead> <tbody> <tr><td><code>hasPanel</code></td><td><code>line</code>, <code>chip</code></td><td>false → no disclosure (a plain line, a chip that is text, not a button)</td></tr> <tr><td><code>chipAction</code></td><td><code>chip</code></td><td><code>{label, ariaLabel?, busy?}</code> or null — the one inline control for <em>queued or running</em> work (cancel). The host renders it as its own button beside the chip and calls <code>runChipAction()</code>. All other actions belong in the panel.</td></tr> <tr><td><code>cardStatus</code></td><td><code>card</code></td><td>the status the frame shows when it differs from the event's — a card that tracks live state itself (polling a server it started), or a waiting prompt sent as <code>pending</code> that is really a warning. Null = the event's status.</td></tr> <tr><td><code>hidden</code> (attribute)</td><td><code>card</code></td><td>set it on yourself when there is nothing to show (an event you only render on error, a dismissed card); the host hides the frame too</td></tr> </tbody> </table> <h3 id="the-host-owns-the-frame">The host owns the frame</h3> <p>For any host-set presentation (<code>hostFramed</code> is true) the host draws the card<br> frame (<code>--color-bg-inset</code> surface, hairline border, <code>max-width: 90%</code>), the<br> <strong>status edge</strong> (pending → <code>--accent-live</code>, success → muted green, warning,<br> error), and the <strong>status glyph</strong> on the body's first line (spinner while<br> pending, <code>⚠</code> / <code>✗</code> with accessible names; success is quiet). On chips it draws<br> the button, the same glyphs and the error colour. So:</p> <ul> <li><code>getStatusIcon()</code> returns <code>""</code> when host-framed, and <code>CARD_STYLES</code> unframes <code>.card</code> under <code>:host([presentation="card"])</code> — an element written against the SDK styles needs no change.</li> <li>Do not draw your own status edge, status glyph, outer border or expand arrow in <code>card</code> / <code>chip</code> / <code>panel</code>. Content glyphs (🧠, 📦) are yours.</li> <li>Gate any custom framing on <code>hostFramed</code>, so an undeclared mount — which has no <code>presentation</code> attribute and gets no host frame — still looks right.</li> </ul> <p>See visual-language.md §4.10 for the<br> exact tokens.</p> <h3 id="status-contract">Status contract</h3> <ul> <li><strong>Every visible event carries <code>status</code></strong>: <code>"pending"</code>, <code>"success"</code>, <code>"warning"</code> or <code>"error"</code>. Anything else is logged as invalid and treated as <code>pending</code> — a card with a spinner that never stops.</li> <li><strong>Every pending event gets a terminal update</strong> in the same <code>event_group_id</code>: success, warning, error, or <code>role: "none"</code> — including on exceptions, timeouts, cancellation and background completion. A turn ending is not proof your background work ended. Emit the terminal update from a <code>finally</code> path.</li> <li>Group updates are merged before the role is resolved, so a terminal update may change the subtype (and with it the declared role or element).</li> <li>Missing counts mean <em>unknown</em>, not zero: send the outcome you know.</li> </ul> <h3 id="turn_id-which-turn-a-receipt-belongs-to"><code>turn_id</code>: which turn a receipt belongs to</h3> <p><code>ui_event_emitter(event_type, data, turn_id=None)</code> stamps the event with the<br> current turn when you pass none. Work that finishes later — memory storage<br> completing after the next turn started — must keep its receipt under the turn<br> that caused it: emit the pending event inside that turn (or pass its<br> <code>turn_id</code>), and keep the <code>event_group_id</code>. The envelope's turn id is kept from<br> a group's <strong>first</strong> event, live and in the snapshot, so the terminal chip lands<br> in the original turn's strip. An event with no turn id is attached to the turn<br> it arrives in.</p> <h3 id="tui">TUI</h3> <p>The same resolver runs in Python (<code>api/ui/services/transcript_role.py</code>), fed<br> by the same top-level <code>transcript_events</code>. <code>PluginCard</code> (TUI SDK) is mounted<br> with <code>presentation</code> = <code>card</code> | <code>line</code> | <code>chip</code> | <code>panel</code> and exposes hooks<br> that default to the generic fields — <code>_build_line_content()</code>,<br> <code>_has_line_document()</code> / <code>_build_line_document()</code> / <code>_build_line_preview()</code><br> for lines, <code>chip_text()</code> for the strip (no status glyph: the strip draws it),<br> and <code>_build_details_text()</code> for the panel. Cards sit at the left edge with the<br> host status edge. See <a href="distribution.html#tui-widget-support">distribution.md</a> and<br> <code>src/codumentor/plugins/tui_sdk/plugin_card.py</code>.</p> <hr> <h2 id="plugin-sdk-reference">Plugin SDK Reference</h2> <p>The SDK (<code>@codumentor/plugin-sdk</code>) provides types, utilities, and base classes.</p> <h3 id="types">Types</h3> <pre><code class="language-typescript">import type { PluginEvent, // Full event object passed to components PluginEventStatus, // "pending" | "success" | "warning" | "error" PluginPresentation, // "card" | "line" | "chip" | "panel" PluginChipAction, // { label, ariaLabel?, busy? } PluginElement, // Interface for custom elements PluginManifest, // manifest.json structure } from "@codumentor/plugin-sdk";</code></pre> <h3 id="base-class">Base Class</h3> <p><code>BasePluginElement<TData></code> provides:</p> <table> <thead> <tr><th>Property/Method</th><th>Description</th></tr> </thead> <tbody> <tr><td><code>_shadowRoot</code></td><td>Shadow DOM root</td></tr> <tr><td><code>_event</code></td><td>Full event object</td></tr> <tr><td><code>_data</code></td><td>Event data (typed as <code>TData</code>)</td></tr> <tr><td><code>_status</code></td><td>Current status</td></tr> <tr><td><code>_expanded</code></td><td>Expansion state for collapsible cards</td></tr> <tr><td><code>escapeHtml(text)</code></td><td>HTML escape utility</td></tr> <tr><td><code>getStatusIcon()</code></td><td>Status emoji — <code>""</code> when <code>hostFramed</code></td></tr> <tr><td><code>static presentations</code></td><td>Presentations the element draws (default <code>["card"]</code>; add <code>"chip"</code> for receipts)</td></tr> <tr><td><code>presentation</code></td><td>How the host mounted this instance: <code>card</code> / <code>line</code> / <code>chip</code> / <code>panel</code> (reflected as an attribute)</td></tr> <tr><td><code>hostFramed</code></td><td>True when the host set a presentation — it draws frame, status edge and glyph</td></tr> <tr><td><code>hasPanel</code></td><td>Override: whether a <code>line</code> / <code>chip</code> opens a panel</td></tr> <tr><td><code>chipAction</code> / <code>runChipAction()</code></td><td>Override: the one inline control on a chip for queued/running work</td></tr> <tr><td><code>cardStatus</code></td><td>Override: status for the host frame when it differs from the event's</td></tr> <tr><td><code>notifyHost()</code></td><td>Ask the host to re-read <code>hasPanel</code> / <code>chipAction</code> / <code>cardStatus</code></td></tr> <tr><td><code>toggleExpanded()</code></td><td>Toggle expansion state (call this from your click handler)</td></tr> <tr><td><code>setExpanded(value)</code></td><td>Set expansion state directly (same channel as above)</td></tr> <tr><td><code>expanded</code></td><td>Property the <strong>host</strong> sets to restore expansion; also readable</td></tr> <tr><td><code>render()</code></td><td><strong>Abstract</strong> — you must implement this</td></tr> </tbody> </table> <p>Both expansion setters reflect an <code>expanded</code> attribute onto your element. The<br> app's stylesheet cannot see inside your shadow root, so that attribute is how<br> the transcript learns a card grew. Nothing beside a card reflows when it opens:<br> cards stack, they never share a row.</p> <p>The host sets the <code>event</code> property, which triggers <code>render()</code> automatically.</p> <h4 id="expansion-is-held-by-the-host-not-by-your-element">Expansion is held by the host, not by your element</h4> <p>Your element does not outlive the transcript's layout decisions. It is<br> rebuilt on re-materialization, when focus mode moves it between renderers, when<br> a receipt's chip and panel instances are mounted, and when a group update<br> switches its element. Each of those destroys the element and the host builds<br> a new one — taking <code>_expanded</code> with it.</p> <p>So the state lives above the card, keyed by the plugin event id, and the two<br> halves of <code>BasePluginElement</code> keep it in sync:</p> <ul> <li><code>setExpanded</code> / <code>toggleExpanded</code> — <strong>you</strong> call these, from a click handler. Besides re-rendering and reflecting the attribute, they dispatch a bubbling <code>PLUGIN_CARD_EXPANDED_EVENT</code> (<code>"codumentor:plugin-card-expanded"</code>, detail <code>{ expanded }</code>) that tells the host the user opened or closed this card.</li> <li><code>expanded</code> — the <strong>host</strong> sets this property, on a freshly built element, to whatever it remembers. It applies the state silently: it does <em>not</em> dispatch the event, so state coming down can never echo back up.</li> </ul> <p>None of that needs anything from your card beyond routing every toggle through<br> <code>setExpanded</code>/<code>toggleExpanded</code> — which <code>bindExpandClick</code> already does. Do not<br> assign <code>this._expanded</code> directly: the host would never hear about it, and the<br> next re-parenting would undo it.</p> <h3 id="utilities">Utilities</h3> <pre><code class="language-typescript">import { escapeHtml, // Escape HTML special characters formatMs, // Format milliseconds (e.g., "1.2s", "500ms") formatBytes, // Format bytes (e.g., "1.5 KB") formatNumber, // Format numbers with locale formatPercent, // Format percentages truncate, // Truncate text with ellipsis } from "@codumentor/plugin-sdk";</code></pre> <p>To hand the user off to the chat, <code>startNewChat({ prefill })</code> opens a new,<br> empty conversation with <code>prefill</code> in its composer — never sent, so the user<br> reviews it first. It works from a full page too (the host navigates to the<br> chat). See the SDK README, "Starting a new chat".</p> <p>To open a host route such as a conversation (<code>/c/<id></code>) without a page load,<br> call <code>navigateInApp(url)</code>: it pushes the URL and fires the <code>popstate</code> the<br> host's router listens for.</p> <p>A header widget that must know whether the conversation it shows has a turn<br> in flight (to hold back an action until it is idle) listens for<br> <code>TURN_STATUS_EVENT</code> and keeps a <code>TurnActivity</code>: <code>record(event)</code> on every<br> event, <code>isActive(conversationId)</code> when rendering. It is keyed by<br> conversation because the host keeps one widget instance for the session and<br> the event only reports the open conversation's stream.</p> <h3 id="styles">Styles</h3> <p>The SDK provides CSS that integrates with the host's dark mode:</p> <pre><code class="language-typescript">import { // All base styles combined getBaseStyles, // Individual style modules CSS_TOKENS, // CSS custom properties (--color-*, --radius-*, etc.) CARD_STYLES, // .card, .header, .details BADGE_STYLES, // .badge STATUS_STYLES, // .success, .error, .pending CODE_STYLES, // code, pre LOADING_STYLES, // .loading, .loading-spinner // Component styles BUTTON_STYLES, // .btn, .btn-primary TABLE_STYLES, // table, th, td LIST_STYLES, // ul, li styles INPUT_STYLES, // input, textarea } from "@codumentor/plugin-sdk";</code></pre> <p><strong>Always use CSS custom properties</strong> for colors to support dark mode:</p> <pre><code class="language-css">.my-element { background: var(--color-bg-inset); /* NOT #f5f5f5 */ color: var(--color-text); /* NOT #111 */ border: 1px solid var(--color-border); /* NOT #e0e0e0 */ }</code></pre> <h3 id="role-tokens-and-edge-not-fill">Role tokens and "edge, not fill"</h3> <p>The host app's colors are not decorative — each accent has exactly one job.<br> <code>doc/core-dev/design/visual-language.md</code><br> is the source of truth; the short version for plugin authors:</p> <ul> <li><strong><code>--accent-live</code></strong> — interactive or in-flight. Only for something clickable right now or actively working/streaming.</li> <li><strong><code>--accent-user</code></strong> — the human's voice. Not available to plugin content; don't use it for emphasis or status.</li> <li><strong><code>--accent-inner</code></strong> — the agent's inner work (thinking/subagent-shaped content). Recessed only — a low-alpha tint, never full strength.</li> <li><strong><code>--color-success</code> / <code>--color-warning</code> / <code>--color-error</code></strong> (plus their <code>-text</code> variants) — outcome only: done, needs attention, or failed.</li> </ul> <p><strong>Plugin cards read as neutral with a colored edge, not a colored fill.</strong> For a<br> declared card the host draws that edge from the event status (or your<br> <code>cardStatus</code>) — don't draw one yourself. The SDK's own<br> <code>sdk-card-info|success|warning|error</code> classes, for an undeclared mount<br> that frames itself, put the status color on the left border only<br> (<code>plugin-sdk.css</code>); the surface stays <code>--color-bg-inset</code>. A status color<br> filling the whole card is the mistake to avoid, inside a host frame or not.</p> <h3 id="expandcollapse-helper">Expand/Collapse Helper</h3> <pre><code class="language-typescript">import { bindExpandClick } from "@codumentor/plugin-sdk"; class MyCard extends BasePluginElement<MyData> { render() { this._shadowRoot.innerHTML = `...`; // Add click handler for expandable header bindExpandClick(this._shadowRoot, ".header", () => this.toggleExpanded()); } }</code></pre> <h3 id="events-that-open-into-a-document">Events that open into a document</h3> <p>An event whose open state is a <em>document</em> — a summary, a report — is usually a<br> <strong>line</strong> with a panel: the <code>line</code> instance renders the sentence, returns<br> <code>hasPanel = true</code>, and the <code>panel</code> instance renders a closed one-line preview<br> and, while <code>expanded</code>, the document. The host holds the document to a reading<br> measure (two thirds of the transcript column from 700px, the whole column<br> below); your wrapper should not cap its own width. A receipt's panel and a<br> card that opens are sized by the host the same way.</p> <p>To render markdown inside such a document, use the SDK's renderer with<br> <code>escapeRawHtml</code> whenever the text is model output or comes from repository or<br> conversation content — <code>marked</code> passes embedded HTML straight through, and the<br> result goes into your shadow root via <code>innerHTML</code>:</p> <pre><code class="language-typescript">import { renderMarkdownHtml, MARKDOWN_PREVIEW_STYLES } from "@codumentor/plugin-sdk"; const html = renderMarkdownHtml(text, { escapeRawHtml: true });</code></pre> <p><code>MARKDOWN_PREVIEW_STYLES</code> carries the matching block styles (it targets<br> <code>.markdown-content</code>) and follows the host theme.</p> <h4 id="offering-open-these-cards-by-default">Offering "open these cards by default"</h4> <p>A card whose open state is worth reading every time can offer the reader a<br> setting for it, without any front-end change. Declare a boolean in your<br> <code>settings_schema</code> and mark it <code>"opens_cards": True</code>:</p> <pre><code class="language-python">def ui_manifest(self) -> dict: return { "settings_schema": { "properties": { "open_summary_cards": { "type": "boolean", "title": "Open summary cards by default", "default": False, "opens_cards": True, }, }, }, }</code></pre> <p>The transcript resolves the flag generically (<code>ui/src/state/hiddenPluginCards.ts</code>)<br> and every card of that plugin mounts with <code>expanded</code> already set. Notes:</p> <ul> <li>It is the mirror of <code>"hides_cards": True</code>, the flag that lets a boolean switch your cards <em>off</em>. A plugin may declare both; they are independent.</li> <li>An unset value falls back to the declared <code>default</code>, so the toggle reads the same in the settings panel as the transcript behaves. Prefer <code>False</code>: a default-open document at every event is a lot of transcript to scroll past.</li> <li>It is a default, not a lock. The reader closing such a card is remembered for the rest of the conversation, and that decision beats the setting.</li> <li>Nothing in your plugin reads the value back — the host does. That is also why the "every declared setting must be read by something" tripwire (<code>tests/test_plugin_settings_read_sites.py</code>) accepts the flag as the answer.</li> </ul> <hr> <h2 id="using-other-frameworks">Using Other Frameworks</h2> <p>The build contract is <strong>framework-agnostic</strong>. Your plugin just needs to:</p> <ol> <li>Have a <code>build</code> script in <code>package.json</code></li> <li>Output an ES module that registers custom elements</li> <li>Custom elements accept an <code>event</code> property</li> </ol> <p>You can use:</p> <table> <thead> <tr><th>Framework</th><th>Approach</th></tr> </thead> <tbody> <tr><td><strong>Vanilla TS</strong></td><td>Extend <code>BasePluginElement</code> or raw <code>HTMLElement</code></td></tr> <tr><td><strong>Lit</strong></td><td>Use <code>@customElement</code> decorator</td></tr> <tr><td><strong>Svelte</strong></td><td>Compile with <code>customElement: true</code></td></tr> <tr><td><strong>Preact/React</strong></td><td>Wrap with <code>@preact/custom-element</code> or similar</td></tr> <tr><td><strong>Vue</strong></td><td>Use <code>defineCustomElement()</code></td></tr> </tbody> </table> <h3 id="example-with-lit">Example with Lit</h3> <pre><code class="language-typescript">import { LitElement, html, css } from "lit"; import { customElement, property } from "lit/decorators.js"; import type { PluginEvent } from "@codumentor/plugin-sdk"; @customElement("x-my-plugin-card") export class MyPluginCard extends LitElement { @property({ type: Object }) event?: PluginEvent<MyData>; render() { const data = this.event?.data; return html`<div class="card">${data?.message}</div>`; } }</code></pre> <hr> <h2 id="welcome-page-widgets">Welcome Page Widgets</h2> <p>Plugins can contribute widgets to the welcome page by adding a <code>widgets</code> array to the manifest:</p> <pre><code class="language-json">{ "ui": { "widgets": [{ "id": "status_widget", "element": "x-my-status-widget", "title": "My Status", "placement": "welcome-sidebar" }] } }</code></pre> <h3 id="widget-implementation-with-api-fetching">Widget Implementation with API Fetching</h3> <pre><code class="language-typescript">class MyStatusWidget extends HTMLElement { private _shadowRoot: ShadowRoot; private _config: { refresh_interval_seconds?: number } = {}; constructor() { super(); this._shadowRoot = this.attachShadow({ mode: "open" }); } set config(value: { refresh_interval_seconds?: number }) { this._config = value || {}; if (value?.refresh_interval_seconds) { setInterval(() => this.fetchData(), value.refresh_interval_seconds * 1000); } } connectedCallback() { this.fetchData(); } async fetchData() { const response = await fetch("/ui/plugins/my_plugin/status/summary"); const data = await response.json(); this.render(data); } render(data: any) { this._shadowRoot.innerHTML = ` <style>${getBaseStyles()}${WIDGET_STYLES}</style> <div class="widget"> <div class="widget-header">${data.title}</div> <div class="widget-content">${data.count} items</div> </div> `; } } customElements.define("x-my-status-widget", MyStatusWidget);</code></pre> <h3 id="two-tier-loading-pattern">Two-Tier Loading Pattern</h3> <p>For optimal performance, implement two API endpoints — a fast summary for initial render and a full dataset for expanded views:</p> <pre><code class="language-python"># Backend API routes @router.get("/status/summary") async def get_summary(request: Request): # Fast endpoint for initial render (< 100ms) return {"count": 5, "top_items": [...], "has_more": True} @router.get("/status") async def get_full(request: Request): # Full data when user expands return {"items": [...]}</code></pre> <hr> <h2 id="building-plugins">Building Plugins</h2> <h3 id="build-commands">Build Commands</h3> <p>From the <code>ui/</code> directory:</p> <pre><code class="language-bash"># Build everything (plugins + main UI) npm run build # Build only plugins npm run build:plugins # Build with verbose output npm run build:plugins:verbose # Build a specific plugin node scripts/build-plugins.js --plugin=telemetry # Watch mode (in plugin directory) cd plugins/my_plugin && npm run build:watch</code></pre> <h3 id="build-contract">Build Contract</h3> <p>The build system (<code>ui/scripts/build-plugins.js</code>) expects:</p> <ol> <li><strong><code>package.json</code></strong> with a <code>build</code> script</li> <li><strong><code>manifest.json</code></strong> with plugin metadata and <code>ui.bundle</code> path</li> <li>After <code>npm run build</code>, the file at <code>manifest.ui.bundle</code> must exist</li> </ol> <p>The orchestrator:</p> <ol> <li>Builds the SDK first (<code>sdk/web</code>)</li> <li>Installs dependencies for each plugin if needed</li> <li>Runs <code>npm run build</code> for each plugin</li> <li>Copies bundles to <code>ui/dist/plugins/{plugin_id}/</code></li> </ol> <p><strong>Code splitting (opt-in).</strong> If your bundle is eager (a chat-header or welcome<br> widget) but also carries a heavy page app, set<br> <code>"pluginBuild": { "splitting": true }</code> in <code>package.json</code> and <code>import()</code> the<br> app lazily from its element. The build then emits <code>chunk-<hash>.js</code> files flat<br> beside <code>index.js</code>; they are served, packaged and git-ignored like it. The entry<br> must still define every declared custom element. Example: <code>ui/plugins/goals</code>.</p> <h3 id="extra-plugin-folders">Extra plugin folders</h3> <p><code>ui/plugins/</code> is always searched. Further source folders (for example an<br> overlay repository's own plugins) are named by <code>CODUMENTOR_UI_PLUGIN_DIRS</code>,<br> separated by the OS path separator (<code>:</code> on Linux/macOS, <code>;</code> on Windows);<br> relative entries resolve against the repository root, not the current<br> directory. One variable drives every consumer:</p> <ul> <li><code>build-plugins.js</code> and <code>watch-plugins.js</code> build/watch those plugins too (bundles are built in place, and copied to <code>ui/dist/plugins/<id>/</code> like the built-in ones). The shared discovery lives in <code>ui/scripts/plugin-dirs.js</code>.</li> <li><code>vite.config.ts</code> serves <code>/ui/extensions/plugins/<id>/</code> from the folder that has the plugin and runs its <code>src/<em>*/</em>.test.ts(x)</code> under <code>npm run test:unit</code>.</li> <li>The backend (<code>ui_plugins_dirs()</code> in <code>src/codumentor/utils/bundle.py</code>) looks a plugin id up in <code>ui/plugins/</code> first, then in each extra folder.</li> <li><code>scripts/build.spec</code> and <code>scripts/build_nuitka.py</code> stage every folder's bundles into the package's single <code>ui/plugins/</code>; a packaged binary ignores the variable at runtime. The container build (<code>deploy/Dockerfile.backend</code>) only copies <code>ui/plugins/</code>, so an overlay must add its folder there itself.</li> </ul> <p>A plugin id must be unique across all folders: the build (and <code>vite</code>) refuse<br> an id that two folders both offer. Plugins outside <code>ui/plugins/</code> cannot use the<br> in-tree <code>node ../../scripts/plugin-esbuild.js</code> build script; use the SDK's<br> <code>codumentor-plugin build</code> / <code>codumentor-plugin watch</code> instead.</p> <h3 id="development-workflow">Development Workflow</h3> <ol> <li><strong>Start the dev server:</strong></li> </ol> <p> ``<code>bash<br> cd ui && npm run dev<br> </code>``</p> <ol> <li><strong>Build plugins when you make changes:</strong></li> </ol> <p> ``<code>bash<br> npm run build:plugins<br> # Or use watch mode in the plugin directory<br> </code>``</p> <ol> <li><strong>Refresh the browser</strong> to see changes (or use the plugin's watch mode + browser refresh)</li> </ol> <hr> <h2 id="settings-panes">Settings panes</h2> <p>A plugin's per-user settings appear as its row under <strong>Settings → Extensions</strong>.<br> <code>ui_manifest()</code> declares what the row renders: a <code>settings_schema</code> (the host<br> builds a form), a <code>settings_widget</code> (your own custom element, with<br> <code>"web_component": "x-…"</code> and the tag in <code>ui.custom_elements</code> with the<br> <code>settings-panel</code> placement), an <code>oauth_connection</code>, or several of them. In the<br> TUI the row mounts the Textual widget your plugin returns from<br> <code>tui_settings_widget(user_id)</code>.</p> <p>A plugin may instead put those same settings in a pane at the root of the<br> Settings sidebar by declaring <code>settings_pane</code>.</p> <blockquote><p><strong>Most plugins should not declare a <code>settings_pane</code>.</strong> Use <code>settings_schema</code><br> or <code>settings_widget</code>: they appear under Settings → Extensions, which is where<br> users look for a plugin's options. A root pane lengthens the Settings sidebar<br> for every user of every deployment that loads your plugin.</p> <p>A root pane is for a plugin that meets all three of these:</p> <ul> <li>it owns a product-level concern that most users visit, such as the models a conversation runs on;</li> <li>without it, the concern would have to be a core section;</li> <li>its pane stands on its own rather than listing options.</li> </ul> <p>If you are unsure, it does not qualify. Raise it in review before adding one.</p></blockquote> <pre><code class="language-python">def ui_manifest(self): return { # … existing keys, including what the pane renders: "settings_widget": {"web_component": "x-my-plugin-settings"}, "settings_pane": { "id": "models", # slug, unique per process "title": {"en": "Models", "hu": "Modellek"}, "icon": "model", # host icon token "order": 10, # among plugin panes # "access_feature": "<plugin>.<feature>", # optional }, }</code></pre> <table> <thead> <tr><th>Field</th><th>Required</th><th>Meaning</th></tr> </thead> <tbody> <tr><td><code>id</code></td><td>Yes</td><td>A slug (<code>[a-z][a-z0-9_-]*</code>, at most 40 characters), unique per process. The web section id is <code>plugin:<id></code>.</td></tr> <tr><td><code>title</code></td><td>Yes</td><td>The nav label by locale. <code>en</code> is required; other locales fall back to it.</td></tr> <tr><td><code>icon</code></td><td>No</td><td>A token from the host set: <code>model</code>, <code>key</code>, <code>link</code>, <code>user</code>, <code>chart</code>, <code>database</code>, <code>globe</code>. Anything else, or none, renders a generic glyph. You cannot supply your own SVG.</td></tr> <tr><td><code>order</code></td><td>No</td><td>Position among plugin panes (default <code>100</code>); ties sort by <code>id</code>.</td></tr> <tr><td><code>access_feature</code></td><td>No</td><td>The <a href="backend-hooks.html#declaring-what-a-hook-reaches">access feature</a> the pane belongs to.</td></tr> </tbody> </table> <p>What the host does with it:</p> <ul> <li><strong>Position is banded.</strong> The sidebar is General, Tool Approvals, Shared, the plugin panes (by <code>order</code>, then <code>id</code>), Extensions, About. A plugin cannot reorder, replace or sit between core items.</li> <li><strong>One rendering path.</strong> The pane's body is exactly what your Extensions row would have rendered — schema form, <code>settings_widget</code>, <code>oauth_connection</code> — under the pane's localized title. A plugin with a pane has <strong>no</strong> Extensions row. A pane with nothing to render is not shown.</li> <li><strong>One pane per plugin, first come first served.</strong> A duplicate <code>id</code> goes to the plugin loaded first (priority order, which is deterministic). The other plugin's pane is refused with an error log naming both, and that plugin keeps its Extensions row. Ownership is decided over every loaded plugin's declaration before any access check, so it is the same for every user: a pane withheld from one user does not pass its <code>id</code> to the next plugin. An invalid declaration (no <code>en</code> title, an <code>id</code> that is not a slug) is refused the same way.</li> <li><strong>Gating.</strong> <code>access_feature</code> on <code>settings_pane</code> withholds the pane from a principal without the feature — and your settings with it: they do <strong>not</strong> fall back to an Extensions row. <code>access_feature</code> on <code>settings_widget</code> withholds just the widget. An edition that excludes your plugin sends no manifest, so no pane.</li> <li><strong>Deep links.</strong> <code>openSettings("plugin:<id>")</code> opens the pane. An older <code>openSettings("extensions", { pluginId })</code> for a plugin that now owns a pane is redirected to the pane, so existing links keep working; a link to a pane that is not there falls back to the plugin's Extensions row, then General.</li> <li><strong>TUI.</strong> The pane gets its own entry in the Settings sidebar, before Plugin Settings, mounting your <code>tui_settings_widget</code> (and your schema form, if you have one) — also when your plugin has no web settings at all. The Plugin Settings accordion skips your plugin. There is no new TUI hook.</li> <li><strong>Operators can see it.</strong> Startup logs one line listing the plugin panes in force (<code>Settings panes from plugins: models (thinking_modes)</code>), so an operator can see what lengthened their sidebar.</li> </ul> <p>The in-tree users are <code>thinking_modes</code>, whose pane is <strong>Settings → Models</strong><br> (<a href="catalog/thinking_modes.html">catalog</a>), and the <code>agent_instructions</code> builtin,<br> whose pane is <strong>Settings → Custom instructions</strong><br> (<a href="catalog/agent_instructions.html">catalog</a>).</p> <hr> <h2 id="admin-panels">Admin Panels</h2> <p>Plugins can contribute panels to the <code>/admin</code> hub page by declaring <code>admin-panel</code> as a placement and adding a widget with <code>placement: "admin-panel"</code>.</p> <h3 id="manifest-configuration">Manifest Configuration</h3> <pre><code class="language-json">{ "plugin_id": "my_plugin", "name": "My Plugin", "version": "1.0.0", "event_types": ["plugin.my_plugin.completed"], "ui": { "bundle": "index.js", "sdk_version": "1.0", "custom_elements": ["x-my-plugin-admin"], "placements": ["admin-panel"], "widgets": [{ "id": "my_admin_panel", "element": "x-my-plugin-admin", "title": "My Plugin Settings", "placement": "admin-panel", "priority": 100 }] } }</code></pre> <h3 id="admin-panel-custom-element">Admin Panel Custom Element</h3> <p>Admin panel elements receive a <code>config</code> property (same pattern as welcome widgets) with optional endpoint and refresh configuration:</p> <pre><code class="language-typescript">class MyPluginAdmin extends HTMLElement { private _shadowRoot: ShadowRoot; constructor() { super(); this._shadowRoot = this.attachShadow({ mode: "open" }); } set config(value: { refresh_interval_seconds?: number; summary_endpoint?: string; detail_endpoint?: string }) { // Use config for API endpoints or refresh intervals } connectedCallback() { this.render(); } render() { this._shadowRoot.innerHTML = ` <style>${getBaseStyles()}</style> <div class="admin-panel"> <p>Plugin admin content here</p> </div> `; } } if (!customElements.get("x-my-plugin-admin")) { customElements.define("x-my-plugin-admin", MyPluginAdmin); }</code></pre> <p>The admin hub automatically wraps each admin panel widget in a <code><section></code> with the widget's <code>title</code> as a heading. Widgets are sorted by <code>priority</code> (lower values appear first).</p> <hr> <h2 id="ingestion-panels">Ingestion Panels</h2> <p>Plugins can contribute panels <em>inside</em> the Ingestion page (<code>/admin/ingest</code>) — below the built-in full-ingestion and per-repo sections — by declaring <code>ingestion-panel</code> as a placement and adding a widget with <code>placement: "ingestion-panel"</code>. Use this (instead of <code>admin-panel</code>) when your panel is conceptually part of ingestion/indexing and belongs next to those controls rather than on the standalone admin hub.</p> <h3 id="manifest-configuration-1">Manifest Configuration</h3> <p>Identical to an admin panel, only the placement string differs:</p> <pre><code class="language-json">{ "ui": { "custom_elements": ["x-my-plugin-ingestion"], "placements": ["ingestion-panel"], "widgets": [{ "id": "my_ingestion_panel", "element": "x-my-plugin-ingestion", "title": "My Plugin Indexing", "placement": "ingestion-panel", "priority": 100 }] } }</code></pre> <h3 id="custom-element">Custom Element</h3> <p>Authoring is the same as an <a href="#admin-panels">admin panel</a>: the element receives the same <code>config</code> property (<code>refresh_interval_seconds</code>, <code>summary_endpoint</code>, <code>detail_endpoint</code>), and the host wraps each widget in a titled <code><section></code>, sorted by <code>priority</code>.</p> <p>Both placements are rendered by the same reusable host — <code><PluginPanelHost placement=… /></code> backed by the <code>usePluginPanels(placement)</code> hook (<code>ui/src/components/PluginPanelHost.tsx</code>, <code>ui/src/hooks/usePluginPanels.ts</code>). <code>AdminPage</code> mounts <code>placement="admin-panel"</code>; <code>IngestPage</code> mounts <code>placement="ingestion-panel"</code>. Adding a host to a new core page is just <code><PluginPanelHost placement="…" /></code> plus a new value in <code>ExtensionPlacement</code> (<code>ui/src/types/api.ts</code>).</p> <h3 id="gating">Gating</h3> <p>The Ingestion page is already an admin-only route, so an <code>ingestion-panel</code> section is only visible to admins. This is <strong>visibility only</strong> — keep enforcing permissions on your plugin's own endpoints server-side (e.g. <code>require_permission("admin:*")</code>); the placement does not gate API calls.</p> <p>The <code>branch_switching</code> plugin's branch-overlay panel is the canonical example (<code>plugins/branch_switching/plugin.py</code> <code>ui_manifest</code>; design rationale in <code>doc/features/branch-overlay-admin-design.md</code> §5, "Option C").</p> <hr> <h2 id="full-pages">Full Pages</h2> <p>A widget lives inside someone else's layout. When your plugin needs a whole<br> screen — a browser, a dashboard, a management console — declare a <strong>page</strong><br> instead. Each entry in <code>ui.pages</code> mounts your custom element at its own SPA<br> route:</p> <pre><code class="language-python">"ui": { "bundle_url": "/ui/extensions/plugins/my_plugin/index.js", "custom_elements": ["x-my-plugin-browser"], "pages": [ { "page_id": "browser", "path": "browser", # relative, no leading slash "title": "Browser", # shown as the page heading "custom_element": "x-my-plugin-browser", }, ], }</code></pre> <table> <thead> <tr><th>Field</th><th>Description</th></tr> </thead> <tbody> <tr><td><code>page_id</code></td><td>Stable identifier for the page within your plugin</td></tr> <tr><td><code>path</code></td><td>Route segment, <strong>relative</strong> — the host mounts it under <code>/plugins/<plugin_id>/</code></td></tr> <tr><td><code>title</code></td><td>Human-readable page title</td></tr> <tr><td><code>custom_element</code></td><td>Tag from your bundle to mount as the page body</td></tr> </tbody> </table> <p>The example above is reachable at <code>/plugins/my_plugin/browser</code>. Routing goes<br> through <code>App.tsx</code>'s <code>/plugins/:pluginId/*</code> entry, so you add no React code and<br> touch no core routing.</p> <p><strong>Carry page state in the URL hash</strong>, not in component state, so deep links from<br> a transcript card restore the full view:</p> <pre><code>/plugins/workspace_files/repos#?repo=alpha&path=docs/report.md</code></pre> <p><code>workspace_files</code> (repo browser), <code>agentic_memory</code>, <code>log_collection</code><br> and <code>user_feedback</code> all ship pages this way.</p> <p><strong>Several pages, one element.</strong> When several <code>ui.pages</code> entries name the same<br> <code>custom_element</code>, the host keeps that one instance while the user moves between<br> them and only updates its <code>page-id</code> attribute; a different element remounts.<br> So a plugin can run its own in-app router: <code>history.pushState</code> plus a<br> dispatched <code>popstate</code> changes the URL, the host re-matches the page, and your<br> element keeps its state. <code>goals</code> does this (<code>ui/plugins/goals/src/paths.ts</code>).</p> <blockquote><p>Pages are <strong>not</strong> gated for you. The route renders for any authenticated user;<br> enforce authorization on the plugin API endpoints the page calls, exactly as<br> with <a href="#gating">admin panels</a>.</p></blockquote> <hr> <h2 id="chat-header-widgets">Chat Header Widgets</h2> <p>Plugins can contribute small components to the chat header. The header is a single responsive action bar: every item — native actions and plugin widgets alike — is placed by the same priority-ordered overflow pass, which keeps as many items inline as fit the available width and collapses the rest into the overflow (⋮) menu.</p> <p>Each <code>chat-header</code> widget declares two layout fields:</p> <ul> <li><strong><code>priority</code></strong> — higher = more important. Items are laid out left-to-right by descending priority, and when space runs out the <em>lowest</em>-priority <code>auto</code> items are the first to collapse into the menu. Defaults to <code>100</code>. The core inline band is spaced by <code>100</code> so a new action can slot in without reshuffling the rest: trial badge <code>1000</code> (pinned, leftmost), then Preview <code>900</code> (only with a pinned app or a configured dev server), Push <code>800</code>, Workspace <code>750</code>, Focus <code>700</code>, Control Room <code>600</code>, Share <code>500</code>, Repos <code>300</code>, Goals <code>200</code>, Settings <code>50</code> (inline actions); admin <code>-200</code> (menu item). A widget that omits <code>priority</code> takes the default <code>100</code>, which lands in the reserved gap between Goals (<code>200</code>) and Settings (<code>50</code>).</li> <li><strong><code>collapse</code></strong> — the collapse intent:</li> <li><code>"pinned"</code>: always inline, never collapsed (e.g. the trial badge)</li> <li><code>"menu"</code>: always in the overflow menu</li> <li><code>"auto"</code> (default): inline while there is room, otherwise overflows into the menu</li> </ul> <p><strong>Ordering inside the menu.</strong> <code>priority</code> is a <em>single</em> axis shared by the inline row and the menu — there is no separate "menu priority". The menu is one list that merges always-<code>"menu"</code> items with any <code>auto</code> items that happened to overflow for lack of space, then sorts the whole thing by descending priority (highest at the top). So a <code>"menu"</code> widget left at the default <code>100</code> will interleave with — and <em>race against</em> — whatever <code>auto</code> items got pushed out of the inline row on a given viewport. <strong>For a <code>"menu"</code> widget, prefer a negative <code>priority</code></strong> so it settles near the bottom of the menu, below the space-driven overflow and in a stable spot. Use a high positive priority only when you deliberately want it near the <em>top</em> of the menu, accepting that it will sit among the overflowed <code>auto</code> items. Native items bracket the range: the user button anchors the top at <code>10000</code>, logout the bottom at <code>-10000</code>.</p> <h3 id="manifest-configuration-2">Manifest Configuration</h3> <p>Add a widget with <code>placement: "chat-header"</code> in <code>ui.widgets</code>. (Declaring <code>"chat-header"</code> in <code>ui.placements</code> is optional and purely informational — discovery is driven by <code>ui.widgets[]</code>.)</p> <pre><code class="language-json">{ "plugin_id": "my_plugin", "name": "My Plugin", "version": "1.0.0", "event_types": ["plugin.my_plugin.completed"], "ui": { "bundle": "index.js", "sdk_version": "1.0", "custom_elements": ["x-my-header-status"], "placements": ["chat-header"], "widgets": [{ "id": "header_status", "element": "x-my-header-status", "title": "Status Indicator", "placement": "chat-header", "priority": 100, "collapse": "auto" }] } }</code></pre> <p>A widget that a workspace view of the same plugin replaces may declare <code>superseded_by_view: "<view widget_id>"</code>: while the workspace pane is on and that view is available, the host does not draw it. See <a href="workspace-views.html#replacing-a-header-widget">workspace-views.md</a>.</p> <p>When a widget is relocated between the inline row and the menu, the host sets a <code>display-mode</code> attribute (<code>"inline"</code> or <code>"menu"</code>) on the custom element so it can adapt its rendering (e.g. show a label next to the icon in the menu).</p> <h3 id="custom-element-properties">Custom Element Properties</h3> <p>The host sets the following properties on the custom element:</p> <table> <thead> <tr><th>Property</th><th>Type</th><th>Description</th></tr> </thead> <tbody> <tr><td><code>conversationId</code></td><td>string</td><td>Current conversation ID</td></tr> <tr><td><code>locale</code></td><td>string</td><td>Current UI locale (e.g., <code>"en"</code>, <code>"hu"</code>)</td></tr> <tr><td><code>widgetId</code></td><td>string</td><td>Widget ID from the manifest</td></tr> <tr><td><code>pluginId</code></td><td>string</td><td>Plugin ID</td></tr> </tbody> </table> <h3 id="example-implementation">Example Implementation</h3> <pre><code class="language-typescript">class MyHeaderStatus extends HTMLElement { private _shadowRoot: ShadowRoot; private _conversationId?: string; constructor() { super(); this._shadowRoot = this.attachShadow({ mode: "open" }); } set conversationId(value: string | undefined) { this._conversationId = value; this.render(); } connectedCallback() { this.render(); } render() { this._shadowRoot.innerHTML = ` <style> :host { display: inline-flex; align-items: center; } .badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; background: var(--color-bg-inset); border: 1px solid var(--color-border); font-size: 12px; color: var(--color-text-secondary); } .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-primary); } </style> <div class="badge"> <span class="dot"></span> Connected </div> `; } } if (!customElements.get("x-my-header-status")) { customElements.define("x-my-header-status", MyHeaderStatus); }</code></pre> <p>Multiple plugins can contribute to the header slot. They are laid out side by<br> side in <strong>descending</strong> <code>priority</code> — the highest-priority item sits leftmost, and<br> the lowest-priority <code>auto</code> items are the first to collapse into the ⋮ menu when<br> space runs out (<code>ui/src/components/headerOverflow.ts</code>).</p> <blockquote><p><strong>Note:</strong> this is the opposite of <code>admin-panel</code> / <code>ingestion-panel</code>, where<br> panels sort by <em>ascending</em> priority (lower value first). The chat header sorts<br> descending because there <code>priority</code> expresses importance — what survives<br> inline when the bar is tight — not just position.</p></blockquote> <hr> <h2 id="message-actions">Message Actions</h2> <p>A <code>message-actions</code> widget renders in the small row under an assistant answer,<br> next to copy (<code>ui/src/components/MessageActions.tsx</code>). The row appears after<br> every completed answer, in normal and focus mode alike, so one element is<br> mounted per answer. Widgets sort by ascending <code>priority</code>.</p> <h3 id="element-context">Element context</h3> <p>The host sets <code>context</code> (a <code>MessageActionsContext</code> from<br> <code>@codumentor/plugin-sdk</code>) and also each field as a property of the same name,<br> plus <code>widgetId</code>, <code>pluginId</code> and <code>locale</code>:</p> <table> <thead> <tr><th>Field</th><th>Type</th><th>Attribute</th><th>Meaning</th></tr> </thead> <tbody> <tr><td><code>conversationId</code></td><td>string?</td><td><code>conversation-id</code></td><td>The conversation</td></tr> <tr><td><code>turnId</code></td><td>string?</td><td><code>turn-id</code></td><td>Root turn id (the user message id), when known</td></tr> <tr><td><code>assistantMessageId</code></td><td>string?</td><td><code>assistant-message-id</code></td><td>The answer's message id</td></tr> <tr><td><code>assistantContent</code></td><td>string</td><td>—</td><td>The turn's final assistant text</td></tr> <tr><td><code>isLatestTurn</code></td><td>boolean</td><td><code>latest-turn</code> (present when true)</td><td>This row is under the conversation's latest answer</td></tr> <tr><td><code>turnOutcome</code></td><td>`"completed" \</td><td>"cancelled" \</td><td>"error"`</td></tr> <tr><td><code>canSend</code></td><td>boolean</td><td><code>can-send</code> (present when true)</td><td>The viewer can send into this conversation from here</td></tr> </tbody> </table> <ul> <li><strong>Latest and responding.</strong> At most one row is the latest, and only while nothing is in flight: the latest row is not rendered while the conversation is responding or a send is pending. When a turn starts, that element is removed (normal mode) or every row is removed (focus mode), so a widget that shows only on the latest row needs no separate "responding" signal. A trailing turn with no answer (cancelled before any text) has no row, and the answer above it is not the latest either.</li> <li><strong>Outcome.</strong> <code>cancelled</code> when the turn carries a cancel notice; <code>error</code> when it is the latest turn and ended with <code>turn.failed</code>. An earlier failed turn reports <code>completed</code>, because only the latest turn's failure is known. A turn waiting on an approval is still in flight, so it has no latest row.</li> <li><strong>Can send.</strong> False in the admin chat viewer and in a conversation from another folder (the composer is blocked there). Share views and subagent transcripts do not render this row at all.</li> <li><code>isLatestTurn</code>, <code>turnOutcome</code> and <code>canSend</code> can change while the element is mounted. The host updates the properties and attributes in place and assigns a new <code>context</code> object, so a <code>context</code> setter (or <code>attributeChangedCallback</code> on the attributes) sees each change. The other fields remount the element.</li> </ul> <p>To send a user turn from a widget, dispatch the window event<br> <code>codumentor:send-chat-message</code> with <code>{ conversation_id, text }</code>. By default the<br> composer is cleared, as when the user presses Send; add <code>preserve_draft: true</code><br> to leave a half-typed draft alone.</p> <hr> <h2 id="composer-controls">Composer Controls</h2> <p>The composer row — the one with the textarea and the send button — is two<br> placements, not one, split by what a control <em>is</em> rather than where it happens<br> to sit:</p> <table> <thead> <tr><th>Placement</th><th>Side</th><th>It answers</th><th>Overflow</th></tr> </thead> <tbody> <tr><td><code>composer-intent</code></td><td>left of the textarea</td><td><em>what this turn does</em></td><td>into the <code>+</code> menu</td></tr> <tr><td><code>composer-input</code></td><td>right of the textarea</td><td><em>how I am entering this message</em></td><td>icon-only, then gone</td></tr> </tbody> </table> <p>The split exists because one overflow policy cannot serve both. A mode picker<br> works fine as a dropdown row: you open it, you choose, you close. A<br> press-and-hold microphone does not — so the input cluster is never put in a<br> menu. Which side a new control belongs on therefore stops being a judgement<br> call.</p> <p>Both clusters go through <strong>one</strong> measured pass over their union, so the globally<br> least important control on the row collapses first regardless of side; only what<br> <em>happens</em> to it comes from its own placement.</p> <h3 id="layout-fields">Layout fields</h3> <ul> <li><strong><code>priority</code></strong> — higher = more important, exactly as <code>chat-header</code>: laid out furthest from the textarea, and last to collapse. Defaults to <code>50</code>. Reference points among the native controls: thinking chip <code>60</code>, speak-replies <code>40</code> (intent); push-to-talk <code>50</code>, voice conversation <code>30</code>, native dictation <code>20</code> (input). On the <em>input</em> side the highest priority renders <strong>nearest the send button</strong>, in the thumb zone, so the visual order there is the reverse of the priority order.</li> <li><strong><code>collapse</code></strong> — what happens when the row runs out of room:</li> <li><code>"pinned"</code>: always on the row. It guarantees <em>presence</em>, never a label — a pinned control still degrades to icon-only when the budget is tight.</li> <li><code>"menu"</code>: always in the <code>+</code> menu. <code>composer-intent</code> only; an input control that declares it is simply absent, since that cluster has no menu.</li> <li><code>"auto"</code> (default): on the row while there is room, then icon-only, then demoted — into the menu for <code>composer-intent</code>, out of sight for <code>composer-input</code>.</li> <li><code>"hide"</code>: like <code>auto</code>, but with no menu fallback. For a control that is a redundant convenience (native dictation is one) rather than the only way to reach something.</li> <li><strong><code>group</code></strong> (<code>composer-input</code> only) — an optional merge group. Accepted today so a manifest can declare it; a single merged trigger for the group is not implemented yet.</li> </ul> <h3 id="the-three-display-modes">The three display modes</h3> <p>There is no way for a widget to demand a label. Instead the host sets<br> <code>display-mode</code> on the custom element and the widget <strong>must</strong> render sanely in<br> all three:</p> <table> <thead> <tr><th><code>display-mode</code></th><th>What the host is asking for</th></tr> </thead> <tbody> <tr><td><code>"inline"</code></td><td>The full trigger — icon and label</td></tr> <tr><td><code>"compact"</code></td><td>Icon only. Presence beats labels when the row is tight</td></tr> <tr><td><code>"menu"</code></td><td>A labelled row inside the <code>+</code> dropdown</td></tr> </tbody> </table> <p>Presence comes first: the host places every control compact, sees who fits, then<br> hands labels back from the highest priority down. A control that renders nothing<br> at <code>"compact"</code> will simply vanish at a width where it could have stayed.</p> <h3 id="the-element-is-moved-never-re-created">The element is moved, never re-created</h3> <p>A composer widget is instantiated <strong>once</strong> and <em>relocated</em> between the row and<br> the menu — and it stays alive, detached, while the menu is shut. That is what<br> lets a demoted widget go on tracking the state it will show when the user<br> finally opens the <code>+</code>.</p> <blockquote><p><strong>Subscribe in the <code>constructor</code>, not <code>connectedCallback</code>.</strong> A widget demoted<br> into a closed menu has no DOM at all, so <code>connectedCallback</code> has not run and<br> will not run again until the menu opens. This is the same rule<br> <a href="#chat-header-widgets">chat-header widgets</a> follow, and for the same reason.</p></blockquote> <h3 id="menu-behaviour">Menu behaviour</h3> <p>Rows in the <code>+</code> close the menu when clicked, which is what an entry that acts<br> once and is done wants. A widget that owns a toggle, a stepper, or anything with<br> more than one hit target opts out by putting <code>data-keep-open</code> on itself — the<br> host reads it at click time, so a widget may change its mind — and then closes<br> the menu itself when it is finished.</p> <p>The dropdown is a <code>role="menu"</code> whose native rows are <code>role="menuitem"</code>, walked<br> with the arrow keys. A plugin's row is <strong>not</strong> given that role: the host cannot<br> activate a control that lives inside your shadow root, so keyboard access is<br> yours to provide — render a focusable element (a <code><button></code>) in an open shadow<br> root and it is reachable by <kbd>Tab</kbd>.</p> <h3 id="the-tray-and-the-state-a-control-publishes">The tray, and the state a control publishes</h3> <p>Demotion would otherwise be lossy: a control pushed into a shut <code>+</code> takes its<br> state with it, and the user has to open a menu to find out that replies are<br> being read aloud or which mode this turn runs at. The <strong>composer tray</strong> — an<br> in-flow, wrapping row directly above the textarea — is where that state goes on<br> being readable with nothing opened.</p> <p><strong>The host draws the chip, never the widget.</strong> A widget is one element and<br> cannot be in two DOM places at once, so drawing its own chip would cost it the<br> "moved, never re-created" guarantee above. Instead it <em>declares</em> its state, and<br> the host renders it — which also means every plugin's chip is styled the same.</p> <p>Publish in either spelling. Both carry the same fields:</p> <table> <thead> <tr><th>Field</th><th>Attribute</th><th>Meaning</th></tr> </thead> <tbody> <tr><td>label</td><td><code>data-state-label</code></td><td>Short text, glyph included if you want one (<code>◐ Slow · High</code>). No label ⇒ nothing published.</td></tr> <tr><td>tone</td><td><code>data-state-tone</code></td><td><code>default</code> (the host stays quiet) \</td></tr> <tr><td>count</td><td><code>data-state-count</code></td><td>A badge, rendered only above 1.</td></tr> <tr><td>actionable</td><td><code>data-state-actionable</code></td><td>Optional chip activation opt-in: only boolean <code>true</code> in event detail or the exact attribute value <code>"true"</code> enables it. Omitted or false stays passive.</td></tr> <tr><td>progress</td><td><code>data-state-progress</code></td><td>Activity: <code>0..1</code>, drawn as a thin bar along the chip's bottom edge. Omitted ⇒ no bar (indeterminate). Values are clamped to <code>0..1</code>; a non-numeric value counts as omitted.</td></tr> <tr><td>detail</td><td><code>data-state-detail</code></td><td>Activity: one line of figures (<code>12/80 · 34/120 MB · ~2 min</code>), shown beside the label where there is room and at the top of the popover.</td></tr> <tr><td>actions</td><td><code>data-state-actions</code></td><td>Activity: a JSON array of <code>{id, label?, disabled?}</code> (bare strings are accepted as ids). The host draws the buttons in the popover.</td></tr> <tr><td>compact label</td><td><code>data-state-compact-label</code></td><td>The label on narrow (mobile) widths, e.g. <code>📁 · 42%</code>. Falls back to <code>label</code>.</td></tr> </tbody> </table> <pre><code class="language-typescript">// Attributes — read the moment the host creates your element, so this is the // spelling that carries *initial* state. this.setAttribute("data-state-label", "3 folders"); this.setAttribute("data-state-tone", "active"); this.setAttribute("data-state-count", "3"); // Or an event on yourself, for an update you already have in hand. this.dispatchEvent(new CustomEvent("codumentor:composer-state", { detail: { label: "3 folders", tone: "active", count: 3 }, }));</code></pre> <p>Two rules follow from the contract:</p> <ul> <li><strong><code>default</code> is silence.</strong> A chip appears only for a <em>non-default</em> state, which is what lets the tray cost exactly zero pixels on a conversation with nothing to say. Publish <code>default</code> (or no label) when you are sitting at the value the user would have got anyway.</li> <li><strong>A chip is drawn only while your control is off the row.</strong> On the row your own trigger is showing; a chip beside it would be the same string twice.</li> </ul> <h4 id="opting-in-to-chip-activation">Opting in to chip activation</h4> <p>Chips are <strong>informational and passive by default</strong>. A plugin that can handle<br> activation opts in with <code>data-state-actionable="true"</code> or <code>actionable: true</code> in<br> its <code>codumentor:composer-state</code> detail. String <code>"true"</code> in event detail, an empty<br> attribute, and other truthy values do not opt in.</p> <p>When the user activates an actionable chip, the host first opens the overflow<br> (<code>+</code>) menu, then dispatches <code>COMPOSER_ACTIVATE_EVENT</code><br> (<code>"codumentor:composer-activate"</code>) <strong>directly on the existing plugin element</strong><br> with detail <code>{ source: "chip" }</code>. The element is not recreated. Listen on the<br> element itself and open or focus your own control; the host does not synthesize<br> a click inside your shadow root.</p> <pre><code class="language-typescript">import { COMPOSER_ACTIVATE_EVENT } from "@codumentor/plugin-sdk"; // Install once, for example in your element's constructor. this.addEventListener(COMPOSER_ACTIVATE_EVENT, (event) => { const { source } = (event as CustomEvent<{ source: "chip" }>).detail; if (source === "chip") { this.shadowRoot?.querySelector<HTMLButtonElement>("button")?.focus(); } }); this.setAttribute("data-state-actionable", "true");</code></pre> <p>Removing the attribute or publishing state without <code>actionable: true</code> makes the<br> chip passive again. Attribute and event updates remain last-writer-wins.</p> <p>A control that needs a genuine custom in-flow row rather than a chip — something<br> <code>InputAttachments</code>-shaped — declares <code>placement: "composer-tray"</code> and renders<br> into the row itself.</p> <h4 id="activity-chips-tray-widgets-that-publish-state">Activity chips: tray widgets that publish state</h4> <p>A <code>composer-tray</code> widget that publishes a label gets a <strong>host-drawn chip</strong> in<br> the tray, for as long as the label is there. This is how long-running work<br> shows (design <code>client-fs-transfers</code> §3.5, D8): a copy, an upload, a save-back.<br> The host draws every such chip the same way: label, tone, the progress bar and<br> the detail.</p> <ul> <li><strong>Passive chip (the default): clicking opens a popover.</strong> The popover shows the detail, the action buttons, and <strong>your element itself</strong> as the popover content. The host keeps the element in a stable node and only hides and shows it, so render whatever the user should see on click (names, file lists, your own buttons) into your shadow root. To close the popover from inside, dispatch <code>codumentor:composer-popover-close</code> on yourself.</li> <li><strong>Action buttons</strong> dispatch <code>COMPOSER_ACTIVATE_EVENT</code> on your element with <code>{ source: "action", action: id }</code>, synchronously inside the click.</li> <li><strong>Actionable chip:</strong> with <code>data-state-actionable="true"</code> the chip is a button with no popover. A click dispatches <code>{ source: "chip" }</code>, still inside the user gesture, so calls such as <code>requestPermission()</code> or a file picker work from the handler.</li> <li><strong>No label means no chip.</strong> The element then renders in the row as before.</li> </ul> <pre><code class="language-typescript">this.setAttribute("data-state-tone", "active"); this.setAttribute("data-state-progress", "0.42"); this.setAttribute("data-state-detail", "12/80 · 34/120 MB · ~2 min"); this.setAttribute("data-state-actions", JSON.stringify([{ id: "cancel", label: "Cancel" }])); this.setAttribute("data-state-compact-label", "📁 · 42%"); this.setAttribute("data-state-label", "📁 Project · copying"); // last: the label makes the chip this.addEventListener(COMPOSER_ACTIVATE_EVENT, (e) => { const d = (e as CustomEvent).detail; if (d.source === "action" && d.action === "cancel") void cancelJob(); });</code></pre> <p>The first producer is the <code>client_fs</code> folder chip<br> (<code>ui/plugins/client_fs/src/folder-chip.ts</code>).</p> <h3 id="what-the-says-on-your-behalf">What the <code>+</code> says on your behalf</h3> <p>The tray carries the <em>label</em>; the <code>+</code> carries the fact that your control is in<br> there. When the row runs out of space and pushes controls into the menu, the<br> trigger grows a dot — a count once it is holding more than one, and the same<br> number in its accessible name, since a dot is invisible to a screen reader. Your<br> published <code>tone</code> colours it: the loudest one among everything demoted wins.</p> <p>Two consequences worth knowing:</p> <ul> <li><strong>A <code>collapse: "menu"</code> widget never marks the trigger.</strong> It declared the menu its home, so nothing was lost by it being there, and a dot that is always present would say nothing. Only controls the row <em>had to give up</em> are counted.</li> <li><strong>The dot appears even when you published nothing.</strong> That is the case it exists for: <code>default</code> is silence in the tray, so without it a control could be demoted with no trace at all. You do not have to publish state to stay discoverable — publishing is what upgrades the dot to a readable chip.</li> </ul> <blockquote><p><strong>The tray sorts by <em>ascending</em> priority</strong> (left to right, like panels), the<br> opposite of the two row clusters beside it. The clusters sort descending<br> because there <code>priority</code> expresses importance, which is what decides who<br> survives when the row is tight; the tray never collapses, so there it is only<br> position.</p></blockquote> <h3 id="manifest-configuration-3">Manifest configuration</h3> <pre><code class="language-json">{ "widgets": [{ "widget_id": "turn_scope", "title": "Turn scope", "placement": "composer-intent", "priority": 45, "collapse": "auto", "custom_element": "x-my-turn-scope" }] }</code></pre> <p>The custom element receives the same properties as a header widget<br> (<code>conversationId</code>, <code>locale</code>, <code>widgetId</code>, <code>pluginId</code>) plus the <code>display-mode</code><br> attribute above.</p> <h2 id="ui-component-guidelines">UI Component Guidelines</h2> <ol> <li><strong>Always escape user content:</strong> Use <code>escapeHtml()</code> for any dynamic text</li> <li><strong>Support dark mode:</strong> Use CSS custom properties, not hardcoded colors</li> <li><strong>Use Shadow DOM:</strong> Provides style isolation from the host</li> <li><strong>Handle all states:</strong> Render appropriately for <code>pending</code>, <code>success</code>, <code>error</code></li> <li><strong>Keep bundles small:</strong> The SDK is ~15KB; aim for <50KB total per plugin</li> </ol> <h2 id="settings-action-widgets">Settings action widgets</h2> <p>Plugins may declare <code>ui.widgets[]</code> entries with <code>placement: "settings-panel"</code><br> to add actions to the Settings sidebar, before About. These are distinct from<br> <code>settings_widget</code> forms and root <code>settings_pane</code> sections. The host loads each<br> custom element on demand when Settings opens, ordered by descending <code>priority</code><br> then plugin/widget ID, and supplies <code>locale</code>, <code>plugin-id</code>, <code>widget-id</code>, and the<br> active <code>conversation-id</code> (omitted without a conversation). The bug-report plugin<br> uses this surface to open its report dialog without a main-menu entry.</p> </div> </div> <script> (function() { var toggle = document.getElementById('menuToggle'); var sidebar = document.getElementById('sidebar'); var overlay = document.getElementById('sidebarOverlay'); function close() { sidebar.classList.remove('open'); overlay.classList.remove('open'); } toggle.addEventListener('click', function() { sidebar.classList.toggle('open'); overlay.classList.toggle('open'); }); overlay.addEventListener('click', close); })(); </script> </body> </html>