Workspace views
The workspace pane sits beside the chat.
A plugin contributes a view to it: one entry in the pane's view strip, drawn
by the plugin's custom element. Things the view shows (a pinned preview, an
opened workbook) are items within the view, not views of their own.
Design background: codumentor-sandbox/workspace-shell/VIEW-CONTRIBUTIONS.md.
Working example: the workspace_files plugin (Files and Preview views).
Manifest
Add a widget with placement workspace-view to ui.widgets (declare it in
both manifest.json and the plugin's get_ui_manifest()):
{
"widget_id": "preview",
"title": "Preview",
"placement": "workspace-view",
"priority": 300,
"custom_element": "x-my-preview-view",
"icon": "preview",
"availability": "items",
"shortcut": false
}
| Field | Meaning |
|---|---|
priority | Strip order, highest first. |
icon | A host icon name (lowercase, e.g. files, preview); no SVG. |
availability | When the view is in the strip: always, conversation (default; needs an open conversation) or items (only while the view has open items). Decided from data, before the bundle loads. |
shortcut | true adds an "Open |
The strip entry is drawn from the manifest; the bundle is imported on the
view's first activation (workspace-view is a deferred placement in
ui/src/services/extensionPlacements.ts).
Replacing a header widget
If a chat-header widget of yours only opens what the view now shows, mark it
with superseded_by_view: "<view widget_id>". While the pane is on and that
view is available, the header does not draw the widget. The id must name a
workspace-view widget of the same plugin, or the manifest is rejected. Only
declare it when the view offers everything the widget does: workspace_files
marks its Files button, but not the Preview button, which also carries the
dev-server Start/Stop menu.
The element contract
The host keeps one element per conversation and view alive while the pane is
closed or another view is active, so state survives switching.
Inputs (set by the host):
| Input | Kind | Meaning |
|---|---|---|
plugin-id, widget-id | attribute | Who you are. |
conversation-id | attribute | The conversation; absent without one. |
locale | attribute | en, hu, … |
active | attribute | Present while the view is on screen; removed when hidden or detached. Pause polling without it. |
layout | attribute | split or mobile (one panel at a time). |
.items | property | The view's open items: {key, title, subtitle?, target}[]. |
.target | property | The selected item's target, or null. |
The host draws the item bar (picker and dismiss) itself; the element only
renders the selected target.
Outputs (from the element):
workspace-view-state(CustomEvent dispatched on the element): detail{badge?, busy?, title?}decorates the strip entry; an empty or absent field clears it.workspace-open(CustomEvent, bubbling, composed, cancelable; constantWORKSPACE_OPEN_EVENT): detail{view, key?}opens another view of the same plugin. The host cancels it when it opened the view; otherwise fall back.getAttachContext(): WorkspaceAttachContext | null(optional method): what the composer's+menu offers as "Attach
Items (backend)
Use the helpers in codumentor.plugins.workspace_items; never build the
events by hand.
from codumentor.plugins.workspace_items import (
conversation_emitter, publish_workspace_item, remove_workspace_item,
request_workspace_attention, request_workspace_reveal,
)
emit = conversation_emitter(conv_service, conversation_id) # or a turn's emitter
await publish_workspace_item(
emit, plugin_id="my_plugin", view="preview", key="app:repo:index.html",
title="index.html", target={"path": "index.html"}, attention=True,
)
await remove_workspace_item(emit, plugin_id="my_plugin", view="preview", key="app:repo:index.html")
publish_workspace_itemopens or updates the item(plugin_id, view, key)(storedworkspace.itemevent, folded into the snapshot).targetis opaque to the host and capped at 16 KB: keep it a pointer, not a payload. Settitleto a short content label andsubtitleto context that helps distinguish similar items. Upsert the same key when the label changes to preserve selection. If a singleton just represents the view itself, its title can match the view title: the host omits the redundant label.attention=Truealso badges it.remove_workspace_itemcloses it; removing a closed key is a no-op. Users dismiss from the view header for one item, or the picker for multiple items.request_workspace_attentionbadges the view (or item) and never moves focus.request_workspace_revealasks to show it: the host opens the pane only when it is closed and the user started the current turn, otherwise it becomes attention.
Opening the pane from a card or header widget
import { openWorkspace } from "@codumentor/plugin-sdk";
if (!openWorkspace({ pluginId: "my_plugin", view: "preview", key, conversationId })) {
openTheOldWay(); // flag off, no pane, view unavailable, or item not open
}
openWorkspace is for user actions: it may open the pane and move focus. It
returns true only when the host opened the view, so keep the old behaviour
as the fallback.