Codumentor logo Codumentor Enterprise

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
}
FieldMeaning
priorityStrip order, highest first.
iconA host icon name (lowercase, e.g. files, preview); no SVG.
availabilityWhen 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.
shortcuttrue adds an "Open " entry to the chat header's overflow menu.</td></tr> </tbody> </table> <p>The strip entry is drawn from the manifest; the bundle is imported on the<br> view's first activation (<code>workspace-view</code> is a deferred placement in<br> <code>ui/src/services/extensionPlacements.ts</code>).</p> <h3 id="replacing-a-header-widget">Replacing a header widget</h3> <p>If a <code>chat-header</code> widget of yours only opens what the view now shows, mark it<br> with <code>superseded_by_view: "<view widget_id>"</code>. While the pane is on and that<br> view is available, the header does not draw the widget. The id must name a<br> <code>workspace-view</code> widget of the same plugin, or the manifest is rejected. Only<br> declare it when the view offers everything the widget does: workspace_files<br> marks its Files button, but not the Preview button, which also carries the<br> dev-server Start/Stop menu.</p> <h2 id="the-element-contract">The element contract</h2> <p>The host keeps one element per conversation and view alive while the pane is<br> closed or another view is active, so state survives switching.</p> <p><strong>Inputs</strong> (set by the host):</p> <table> <thead> <tr><th>Input</th><th>Kind</th><th>Meaning</th></tr> </thead> <tbody> <tr><td><code>plugin-id</code>, <code>widget-id</code></td><td>attribute</td><td>Who you are.</td></tr> <tr><td><code>conversation-id</code></td><td>attribute</td><td>The conversation; absent without one.</td></tr> <tr><td><code>locale</code></td><td>attribute</td><td><code>en</code>, <code>hu</code>, …</td></tr> <tr><td><code>active</code></td><td>attribute</td><td>Present while the view is on screen; removed when hidden or detached. Pause polling without it.</td></tr> <tr><td><code>layout</code></td><td>attribute</td><td><code>split</code> or <code>mobile</code> (one panel at a time).</td></tr> <tr><td><code>.items</code></td><td>property</td><td>The view's open items: <code>{key, title, subtitle?, target}[]</code>.</td></tr> <tr><td><code>.target</code></td><td>property</td><td>The selected item's <code>target</code>, or <code>null</code>.</td></tr> </tbody> </table> <p>The host draws the item bar (picker and dismiss) itself; the element only<br> renders the selected <code>target</code>.</p> <p><strong>Outputs</strong> (from the element):</p> <ul> <li><code>workspace-view-state</code> (CustomEvent dispatched on the element): detail <code>{badge?, busy?, title?}</code> decorates the strip entry; an empty or absent field clears it.</li> <li><code>workspace-open</code> (CustomEvent, bubbling, composed, cancelable; constant <code>WORKSPACE_OPEN_EVENT</code>): detail <code>{view, key?}</code> opens another view of the same plugin. The host cancels it when it opened the view; otherwise fall back.</li> <li><code>getAttachContext(): WorkspaceAttachContext | null</code> (optional method): what the composer's <code>+</code> menu offers as "Attach <label>", e.g. the file on screen as an @-reference <code>{label, ref}</code>. Asked only when the menu opens. <code>repoPathReference(repo, path, kind)</code> builds a repository <code>ref</code>.</li> </ul> <h2 id="items-backend">Items (backend)</h2> <p>Use the helpers in <code>codumentor.plugins.workspace_items</code>; never build the<br> events by hand.</p> <pre><code class="language-python">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")</code></pre> <ul> <li><code>publish_workspace_item</code> opens or updates the item <code>(plugin_id, view, key)</code> (stored <code>workspace.item</code> event, folded into the snapshot). <code>target</code> is opaque to the host and capped at 16 KB: keep it a pointer, not a payload. Set <code>title</code> to a short content label and <code>subtitle</code> to 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. <code>attention=True</code> also badges it.</li> <li><code>remove_workspace_item</code> closes it; removing a closed key is a no-op. Users dismiss from the view header for one item, or the picker for multiple items.</li> <li><code>request_workspace_attention</code> badges the view (or item) and never moves focus. <code>request_workspace_reveal</code> asks to show it: the host opens the pane only when it is closed and the user started the current turn, otherwise it becomes attention.</li> </ul> <h2 id="opening-the-pane-from-a-card-or-header-widget">Opening the pane from a card or header widget</h2> <pre><code class="language-typescript">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 }</code></pre> <p><code>openWorkspace</code> is for user actions: it may open the pane and move focus. It<br> returns <code>true</code> only when the host opened the view, so keep the old behaviour<br> as the fallback.</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>