diff --git a/docs/plugin-authoring-guide.md b/docs/plugin-authoring-guide.md index 92770a3494..4fc02aa4c4 100644 --- a/docs/plugin-authoring-guide.md +++ b/docs/plugin-authoring-guide.md @@ -86,6 +86,16 @@ 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` 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. ## 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..1b7c0ae185 100644 --- a/src/bundled/channels/PageTabs.tsx +++ b/src/bundled/channels/PageTabs.tsx @@ -499,32 +499,41 @@ export function PageTabs({ id: "conversation", label, icon, - toolbar: !!workspace?.actions?.length && ( - - + )} + ), actions: workspace?.actions, content: workspace ? ( 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 a138de18fd..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; @@ -517,6 +521,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..34a3c0d983 100644 --- a/src/features/conversation/service.test.tsx +++ b/src/features/conversation/service.test.tsx @@ -103,6 +103,36 @@ 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("reports the slots the active ui.Workspace provider declares", async () => { + const Workspace = () => null; + const h = harness({ + inject: ["conversation"], + apply(ctx) { + 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(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); h.runtime.reconcile([h.plugin]); diff --git a/src/features/conversation/service.tsx b/src/features/conversation/service.tsx index b74eddcc4e..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,8 +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; + /** 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 @@ -308,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); @@ -367,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,