From 25ddcdeea30e945d783c2fd52a044fc24e1d2690 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Thu, 19 Nov 2026 23:47:44 -0600 Subject: [PATCH 1/3] feat(conversation): show a page's header actions in the workspace toolbar `ConversationWorkspaceProps.headerActions` renders in the main tab's toolbar, before the conversation actions menu, so a page can offer its own controls with pressed, expanded and badge states. Plugins detect the slot with `conversation.workspaceSlots.headerActions === true`; an older host ignores the prop. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- docs/plugin-authoring-guide.md | 6 +++ src/bundled/channels/PageTabs.test.tsx | 31 ++++++++++++ src/bundled/channels/PageTabs.tsx | 56 ++++++++++++---------- src/features/conversation/contracts.ts | 2 + src/features/conversation/service.test.tsx | 11 +++++ src/features/conversation/service.tsx | 8 ++++ 6 files changed, 90 insertions(+), 24 deletions(-) diff --git a/docs/plugin-authoring-guide.md b/docs/plugin-authoring-guide.md index 92770a3494..31950a40e0 100644 --- a/docs/plugin-authoring-guide.md +++ b/docs/plugin-authoring-guide.md @@ -86,6 +86,12 @@ entry has a unique `id`, a `label`, and an `onSelect` callback. heading. With `placement: "team-row"`, the channel group uses the native Team menu and ignores these entries. +Check `ctx.conversation.workspaceSlots?.headerActions === true` before passing +`headerActions` to `ui.Workspace`. The host renders those controls in the main +tab's toolbar, before the three-dot menu; an older host ignores them. Use +compact icon buttons with an `aria-label` and `title`, and set `aria-pressed` +or `aria-expanded` on a toggle. + For `ctx.agents.ui.Transcript`, give each turn a unique `turnId` that stays the same across reads. Return a new turn when it changes. Leave previously returned turns and their items untouched. ## Migration writes diff --git a/src/bundled/channels/PageTabs.test.tsx b/src/bundled/channels/PageTabs.test.tsx index 3454cb76a9..a3533157ba 100644 --- a/src/bundled/channels/PageTabs.test.tsx +++ b/src/bundled/channels/PageTabs.test.tsx @@ -452,6 +452,37 @@ it("a workspace owns its main reader, intro, menu, and no initial detail", async expect(source).toHaveBeenCalledOnce(); }); +it.each([false, true])( + "a workspace shows its header actions before the actions menu (menu=%s)", + (menu) => { + const f = fixture(); + cleanup(); + render( + Dashboard} + {...(menu && { actions: [{ label: "Archive", run() {} }] })} + />, + ); + const header = screen.getByRole("banner"); + expect( + within(header) + .getAllByRole("button") + .map( + (button) => button.getAttribute("aria-label") ?? button.textContent, + ) + .filter( + (name) => name === "Dashboard" || name === "Conversation actions", + ), + ).toEqual(menu ? ["Dashboard", "Conversation actions"] : ["Dashboard"]); + }, +); + it.each([false, true])( "a workspace requests composer focus unless another editor owns it (editing=%s)", (editing) => { diff --git a/src/bundled/channels/PageTabs.tsx b/src/bundled/channels/PageTabs.tsx index 92b75e9326..295a631adb 100644 --- a/src/bundled/channels/PageTabs.tsx +++ b/src/bundled/channels/PageTabs.tsx @@ -499,32 +499,40 @@ export function PageTabs({ id: "conversation", label, icon, - toolbar: !!workspace?.actions?.length && ( - - + )} + ), actions: workspace?.actions, content: workspace ? ( diff --git a/src/features/conversation/contracts.ts b/src/features/conversation/contracts.ts index a138de18fd..7b1ca0a638 100644 --- a/src/features/conversation/contracts.ts +++ b/src/features/conversation/contracts.ts @@ -517,6 +517,8 @@ export type ConversationWorkspaceProps = { label: string; /** Content at the start of history. It scrolls with the messages. */ intro?: ReactNode; + /** Controls in the main tab's toolbar, before the actions menu. */ + headerActions?: ReactNode; /** Actions in the pane's menu and the main tab's context menu. */ actions?: readonly { label: string; run(): void }[]; /** Select this panel on entry. Closing it keeps the main conversation. */ diff --git a/src/features/conversation/service.test.tsx b/src/features/conversation/service.test.tsx index 1bc6eb33f0..0d842e4882 100644 --- a/src/features/conversation/service.test.tsx +++ b/src/features/conversation/service.test.tsx @@ -103,6 +103,17 @@ it("provides ui.Tabs only while a plugin supplies the tab workspace", async () = h.runtime.reconcile([]); await vi.waitFor(() => expect(h.service.ui.Tabs).toBeUndefined()); }); +it("tells plugins that ui.Workspace renders header actions", async () => { + let slots: unknown; + const h = harness({ + inject: ["conversation"], + apply(ctx) { + slots = ctx.conversation.workspaceSlots; + }, + }); + h.runtime.reconcile([h.plugin]); + await vi.waitFor(() => expect(slots).toHaveProperty("headerActions", true)); +}); it("bundled Emoji really registers a picker and a renderer, including reaction metadata", async () => { const h = harness(emoji); h.runtime.reconcile([h.plugin]); diff --git a/src/features/conversation/service.tsx b/src/features/conversation/service.tsx index b74eddcc4e..2f376b4d2a 100644 --- a/src/features/conversation/service.tsx +++ b/src/features/conversation/service.tsx @@ -148,6 +148,11 @@ export type Conversation = { registerTabs(component: ComponentType): void; /** Provides `ui.Workspace` while the plugin runs; the first one wins. */ registerWorkspace(component: ComponentType): void; + /** The optional `ui.Workspace` props this host renders; check one before + * passing it. */ + readonly workspaceSlots: Readonly<{ + headerActions: true; + }>; /** Solo chat icons; the sidebar shows the first one. */ chatIcons: ContributionReader; /** Shows `component` as each Solo chat's sidebar icon while the providing @@ -232,6 +237,9 @@ export class ConversationService extends Service implements Conversation { readonly chatIcons; private readonly chatIconEntries; readonly ui: Conversation["ui"]; + readonly workspaceSlots: Conversation["workspaceSlots"] = Object.freeze({ + headerActions: true, + }); constructor(ctx: Context) { super(ctx, "conversation"); const attachments = createContributions(ctx); From 86733c2dd28522659b85a21c33e77a7cf61ae77c Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Fri, 20 Nov 2026 00:26:36 -0600 Subject: [PATCH 2/3] Address review feedback round 1 - Keep the main tab's toolbar empty, as before, when a workspace has neither header actions nor menu actions. - Recommend plain icon buttons with `aria-pressed` or `aria-expanded` for header toggles; the plugin `ui.Button` forwards neither. - Type `workspaceSlots` and its flag as optional, as other feature-detected capabilities are, so plugin code checks before use. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- src/bundled/channels/PageTabs.tsx | 7 ++++--- src/features/conversation/service.tsx | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bundled/channels/PageTabs.tsx b/src/bundled/channels/PageTabs.tsx index 295a631adb..1b7c0ae185 100644 --- a/src/bundled/channels/PageTabs.tsx +++ b/src/bundled/channels/PageTabs.tsx @@ -499,10 +499,11 @@ export function PageTabs({ id: "conversation", label, icon, - toolbar: workspace && ( + toolbar: (workspace?.headerActions || + !!workspace?.actions?.length) && ( <> - {workspace.headerActions} - {!!workspace.actions?.length && ( + {workspace?.headerActions} + {!!workspace?.actions?.length && ( ): void; /** Provides `ui.Workspace` while the plugin runs; the first one wins. */ registerWorkspace(component: ComponentType): void; - /** The optional `ui.Workspace` props this host renders; check one before - * passing it. */ - readonly workspaceSlots: Readonly<{ - headerActions: true; + /** The optional `ui.Workspace` props this host renders. An older host lacks + * a slot's flag, or the whole object, and ignores that prop. */ + readonly workspaceSlots?: Readonly<{ + headerActions?: true; }>; /** Solo chat icons; the sidebar shows the first one. */ chatIcons: ContributionReader; @@ -237,7 +237,7 @@ export class ConversationService extends Service implements Conversation { readonly chatIcons; private readonly chatIconEntries; readonly ui: Conversation["ui"]; - readonly workspaceSlots: Conversation["workspaceSlots"] = Object.freeze({ + readonly workspaceSlots = Object.freeze({ headerActions: true, }); constructor(ctx: Context) { From 8edc6fa4d761d0168ebb0697129251e5384f1886 Mon Sep 17 00:00:00 2001 From: Gil Birman Date: Mon, 23 Nov 2026 21:08:46 -0600 Subject: [PATCH 3/3] Let the workspace provider declare its slots workspaceSlots was a fixed host object, so it reported headerActions even when another plugin's registerWorkspace provider was active and ignored the prop. A caller that trusted the flag then dropped its fallback and lost its controls. registerWorkspace now takes { slots }, and workspaceSlots reflects the active provider, absent when it declares none. Channels declares headerActions. Other optional workspace props declare their keys the same way through WorkspaceSlots. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Gil Birman --- docs/plugin-authoring-guide.md | 14 +++++--- src/bundled/channels/index.tsx | 9 ++++-- src/features/conversation/contracts.ts | 4 +++ src/features/conversation/service.test.tsx | 27 +++++++++++++--- src/features/conversation/service.tsx | 37 +++++++++++++++------- src/plugins/author.ts | 1 + 6 files changed, 68 insertions(+), 24 deletions(-) diff --git a/docs/plugin-authoring-guide.md b/docs/plugin-authoring-guide.md index 31950a40e0..4fc02aa4c4 100644 --- a/docs/plugin-authoring-guide.md +++ b/docs/plugin-authoring-guide.md @@ -86,11 +86,15 @@ entry has a unique `id`, a `label`, and an `onSelect` callback. heading. With `placement: "team-row"`, the channel group uses the native Team menu and ignores these entries. -Check `ctx.conversation.workspaceSlots?.headerActions === true` before passing -`headerActions` to `ui.Workspace`. The host renders those controls in the main -tab's toolbar, before the three-dot menu; an older host ignores them. Use -compact icon buttons with an `aria-label` and `title`, and set `aria-pressed` -or `aria-expanded` on a toggle. +Check `ctx.conversation.workspaceSlots?.headerActions === true` when you +render, before passing `headerActions` to `ui.Workspace`. The Channels +workspace renders those controls in the main tab's toolbar, before the +three-dot menu. The flag is absent on an older host or when the active +workspace provider does not declare the slot; keep the controls in your page +then. Use compact icon buttons with an `aria-label` and `title`, and set +`aria-pressed` or `aria-expanded` on a toggle. A plugin that replaces the +workspace with `registerWorkspace(component, { slots })` names the optional +props its component renders. For `ctx.agents.ui.Transcript`, give each turn a unique `turnId` that stays the same across reads. Return a new turn when it changes. Leave previously returned turns and their items untouched. diff --git a/src/bundled/channels/index.tsx b/src/bundled/channels/index.tsx index bbd4599245..d1f0373d65 100644 --- a/src/bundled/channels/index.tsx +++ b/src/bundled/channels/index.tsx @@ -76,9 +76,12 @@ export const apply: PluginModule["apply"] = (ctx) => { extensions.registerTabs((props) => ( )); - extensions.registerWorkspace((props) => ( - - )); + extensions.registerWorkspace( + (props) => ( + + ), + { slots: { headerActions: true } }, + ); const relay = ctx.relay; const navigator = ctx.navigation; ctx.conversation.registerMessageAction({ diff --git a/src/features/conversation/contracts.ts b/src/features/conversation/contracts.ts index 7b1ca0a638..cceb6e135d 100644 --- a/src/features/conversation/contracts.ts +++ b/src/features/conversation/contracts.ts @@ -504,6 +504,10 @@ export type PageTabTarget = { messageId?: string; unreadSince?: number; }; +/** Optional `ConversationWorkspaceProps` a workspace provider renders. */ +export type WorkspaceSlots = Readonly<{ + headerActions?: true; +}>; /** A page-owned conversation with the host's reader, composer, and side pane. */ export type ConversationWorkspaceProps = { id: string; diff --git a/src/features/conversation/service.test.tsx b/src/features/conversation/service.test.tsx index 0d842e4882..34a3c0d983 100644 --- a/src/features/conversation/service.test.tsx +++ b/src/features/conversation/service.test.tsx @@ -103,16 +103,35 @@ it("provides ui.Tabs only while a plugin supplies the tab workspace", async () = h.runtime.reconcile([]); await vi.waitFor(() => expect(h.service.ui.Tabs).toBeUndefined()); }); -it("tells plugins that ui.Workspace renders header actions", async () => { - let slots: unknown; +it("reports the slots the active ui.Workspace provider declares", async () => { + const Workspace = () => null; const h = harness({ inject: ["conversation"], apply(ctx) { - slots = ctx.conversation.workspaceSlots; + ctx.conversation.registerWorkspace(Workspace, { + slots: { headerActions: true }, + }); + }, + }); + expect(h.service.workspaceSlots).toBeUndefined(); + h.runtime.reconcile([h.plugin]); + await vi.waitFor(() => + expect(h.service.workspaceSlots).toEqual({ headerActions: true }), + ); + h.runtime.reconcile([]); + await vi.waitFor(() => expect(h.service.workspaceSlots).toBeUndefined()); +}); +it("reports no slots for a ui.Workspace provider that declares none", async () => { + const Workspace = () => null; + const h = harness({ + inject: ["conversation"], + apply(ctx) { + ctx.conversation.registerWorkspace(Workspace); }, }); h.runtime.reconcile([h.plugin]); - await vi.waitFor(() => expect(slots).toHaveProperty("headerActions", true)); + await vi.waitFor(() => expect(h.service.ui.Workspace).toBeDefined()); + expect(h.service.workspaceSlots).toBeUndefined(); }); it("bundled Emoji really registers a picker and a renderer, including reaction metadata", async () => { const h = harness(emoji); diff --git a/src/features/conversation/service.tsx b/src/features/conversation/service.tsx index 3391e81ab1..7038cfa8bc 100644 --- a/src/features/conversation/service.tsx +++ b/src/features/conversation/service.tsx @@ -38,6 +38,7 @@ import type { PageTabsProps, ConversationWorkspaceProps, SendGate, + WorkspaceSlots, } from "./contracts"; import { PluginMarkdown, type MarkdownProps } from "../messages/PluginMarkdown"; import { @@ -146,13 +147,16 @@ export type Conversation = { }; /** Provides `ui.Tabs` while the providing plugin runs; the first one wins. */ registerTabs(component: ComponentType): void; - /** Provides `ui.Workspace` while the plugin runs; the first one wins. */ - registerWorkspace(component: ComponentType): void; - /** The optional `ui.Workspace` props this host renders. An older host lacks - * a slot's flag, or the whole object, and ignores that prop. */ - readonly workspaceSlots?: Readonly<{ - headerActions?: true; - }>; + /** Provides `ui.Workspace` while the plugin runs; the first one wins. + * `slots` names the optional props the component renders. */ + registerWorkspace( + component: ComponentType, + options?: Readonly<{ slots?: WorkspaceSlots }>, + ): void; + /** The optional props the active `ui.Workspace` provider renders. Absent + * when the provider declares none or the host predates slots; a caller + * then keeps the controls in its own page. */ + readonly workspaceSlots?: WorkspaceSlots | undefined; /** Solo chat icons; the sidebar shows the first one. */ chatIcons: ContributionReader; /** Shows `component` as each Solo chat's sidebar icon while the providing @@ -237,9 +241,6 @@ export class ConversationService extends Service implements Conversation { readonly chatIcons; private readonly chatIconEntries; readonly ui: Conversation["ui"]; - readonly workspaceSlots = Object.freeze({ - headerActions: true, - }); constructor(ctx: Context) { super(ctx, "conversation"); const attachments = createContributions(ctx); @@ -316,6 +317,7 @@ export class ConversationService extends Service implements Conversation { const workspaces = createContributions<{ id: string; component: ComponentType; + slots?: WorkspaceSlots | undefined; }>(ctx); this.workspaceEntries = workspaces; const chatMenus = createContributions(ctx); @@ -375,10 +377,21 @@ export class ConversationService extends Service implements Conversation { throw new Error("Page tabs need a component"); this.tabEntries.register(this.ctx, { id: "tabs", component }); } - registerWorkspace(component: ComponentType) { + registerWorkspace( + component: ComponentType, + options?: Readonly<{ slots?: WorkspaceSlots }>, + ) { if (typeof component !== "function") throw new Error("A conversation workspace needs a component"); - this.workspaceEntries.register(this.ctx, { id: "workspace", component }); + const slots = options?.slots && Object.freeze({ ...options.slots }); + this.workspaceEntries.register(this.ctx, { + id: "workspace", + component, + slots, + }); + } + get workspaceSlots() { + return this.workspaceEntries.snapshot()[0]?.slots; } registerChatMenu(component: ComponentType) { if (typeof component !== "function") diff --git a/src/plugins/author.ts b/src/plugins/author.ts index 8d70d0e3f4..b2d338bb28 100644 --- a/src/plugins/author.ts +++ b/src/plugins/author.ts @@ -89,6 +89,7 @@ export type { } from "../features/messages/DocumentEditor"; export type { ConversationWorkspaceProps, + WorkspaceSlots, PageTabTarget, PageTabOptions, PageTabsProps,