Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/plugin-authoring-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/bundled/channels/PageTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ConversationWorkspace
id="task"
session={f.session}
scope="origin:viewer"
target={{ channelId: "alpha" }}
label="Task"
host={f.host}
headerActions={<button type="button">Dashboard</button>}
{...(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) => {
Expand Down
57 changes: 33 additions & 24 deletions src/bundled/channels/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,32 +499,41 @@ export function PageTabs({
id: "conversation",
label,
icon,
toolbar: !!workspace?.actions?.length && (
<MenuRoot>
<MenuTrigger
render={
<IconButton
hint="familiar"
size="sm"
aria-label="Conversation actions"
title="Conversation actions"
icon={
<DotsThreeIcon size="1rem" aria-hidden="true" />
toolbar: (workspace?.headerActions ||
!!workspace?.actions?.length) && (
<>
{workspace?.headerActions}
{!!workspace?.actions?.length && (
<MenuRoot>
<MenuTrigger
render={
<IconButton
hint="familiar"
size="sm"
aria-label="Conversation actions"
title="Conversation actions"
icon={
<DotsThreeIcon
size="1rem"
aria-hidden="true"
/>
}
/>
}
/>
}
/>
<MenuPopup align="end">
{workspace.actions.map((action) => (
<MenuItem
key={action.label}
onClick={() => action.run()}
>
{action.label}
</MenuItem>
))}
</MenuPopup>
</MenuRoot>
<MenuPopup align="end">
{workspace.actions.map((action) => (
<MenuItem
key={action.label}
onClick={() => action.run()}
>
{action.label}
</MenuItem>
))}
</MenuPopup>
</MenuRoot>
)}
</>
),
actions: workspace?.actions,
content: workspace ? (
Expand Down
9 changes: 6 additions & 3 deletions src/bundled/channels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ export const apply: PluginModule["apply"] = (ctx) => {
extensions.registerTabs((props) => (
<PageTabs {...props} host={ctx} extensions={extensions} />
));
extensions.registerWorkspace((props) => (
<ConversationWorkspace {...props} host={ctx} extensions={extensions} />
));
extensions.registerWorkspace(
(props) => (
<ConversationWorkspace {...props} host={ctx} extensions={extensions} />
),
{ slots: { headerActions: true } },
);
const relay = ctx.relay;
const navigator = ctx.navigation;
ctx.conversation.registerMessageAction({
Expand Down
6 changes: 6 additions & 0 deletions src/features/conversation/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. */
Expand Down
30 changes: 30 additions & 0 deletions src/features/conversation/service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
29 changes: 25 additions & 4 deletions src/features/conversation/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
PageTabsProps,
ConversationWorkspaceProps,
SendGate,
WorkspaceSlots,
} from "./contracts";
import { PluginMarkdown, type MarkdownProps } from "../messages/PluginMarkdown";
import {
Expand Down Expand Up @@ -146,8 +147,16 @@ export type Conversation = {
};
/** Provides `ui.Tabs` while the providing plugin runs; the first one wins. */
registerTabs(component: ComponentType<PageTabsProps>): void;
/** Provides `ui.Workspace` while the plugin runs; the first one wins. */
registerWorkspace(component: ComponentType<ConversationWorkspaceProps>): void;
/** Provides `ui.Workspace` while the plugin runs; the first one wins.
* `slots` names the optional props the component renders. */
registerWorkspace(
component: ComponentType<ConversationWorkspaceProps>,
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<ChatIcon>;
/** Shows `component` as each Solo chat's sidebar icon while the providing
Expand Down Expand Up @@ -308,6 +317,7 @@ export class ConversationService extends Service implements Conversation {
const workspaces = createContributions<{
id: string;
component: ComponentType<ConversationWorkspaceProps>;
slots?: WorkspaceSlots | undefined;
}>(ctx);
this.workspaceEntries = workspaces;
const chatMenus = createContributions<ChatMenu>(ctx);
Expand Down Expand Up @@ -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<ConversationWorkspaceProps>) {
registerWorkspace(
component: ComponentType<ConversationWorkspaceProps>,
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<ChatMenuProps>) {
if (typeof component !== "function")
Expand Down
1 change: 1 addition & 0 deletions src/plugins/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export type {
} from "../features/messages/DocumentEditor";
export type {
ConversationWorkspaceProps,
WorkspaceSlots,
PageTabTarget,
PageTabOptions,
PageTabsProps,
Expand Down
Loading