Skip to content
Open
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 @@ -96,6 +96,16 @@ then. Use compact icon buttons with an `aria-label` and `title`, and set
workspace with `registerWorkspace(component, { slots })` names the optional
props its component renders.

Check `ctx.conversation.workspaceSlots?.trailing === true` in the same way
before passing `trailing` to `ui.Workspace`. The Channels workspace shows that
content as a card over the
bottom of the channel timeline, in its own scroll layer: scrolling over the
card grows it, then slides it up. Render the whole card at rest too, since
growing scrolls it into view: let `expanded` change labels, not what the card
holds. Keep its controls in view with `position: sticky; bottom: 0` and an
opaque background, and draw its outline with a box shadow rather than a bottom
border.

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
3 changes: 3 additions & 0 deletions src/bundled/channels/ChannelBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import styles from "./Channels.module.css";
export const ChannelBody = memo(function ChannelBody({
cached,
intro,
trailing,
latestRequest,
viewer,
revealMessageId,
Expand All @@ -30,6 +31,7 @@ export const ChannelBody = memo(function ChannelBody({
onContentReady?(channelId: string): void;
cached: boolean;
intro?: ReactNode;
trailing?: ChannelTimelineProps["trailing"];
latestRequest?: AbortSignal | undefined;
viewer?: string | undefined;
navigation?: PageNavigation | undefined;
Expand Down Expand Up @@ -127,6 +129,7 @@ export const ChannelBody = memo(function ChannelBody({
<ConversationTimeline
continuityKey={continuityKey}
intro={intro}
trailing={trailing}
latestRequest={latestRequest}
viewer={viewer}
window={window}
Expand Down
25 changes: 25 additions & 0 deletions src/bundled/channels/ConversationTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ vi.mock("./ChannelBody", () => ({
inlineTarget,
marksRead,
onOpenThread,
trailing,
}: {
holding?: boolean;
inlineTarget?: { messageId: string };
marksRead?: boolean;
onOpenThread(id: string, root: string, intent?: "reply"): void;
trailing?: { content(state: object): import("react").ReactNode };
}) => {
threadOpeners.push(onOpenThread);
return (
Expand All @@ -79,6 +81,7 @@ vi.mock("./ChannelBody", () => ({
data-marks-read={marksRead}
>
Conversation content
{trailing?.content({ expanded: false, toggle() {} })}
</div>
);
},
Expand Down Expand Up @@ -641,6 +644,28 @@ it("a conversation tab opens a reply at its message as the thread", () => {
expect(screen.queryByText("Conversation content")).toBeNull();
});

it.each(["conversation", "thread"] as const)(
"only a channel timeline shows the workspace's trailing content (%s)",
(kind) => {
const c = openingAt([]);
render(
<ConversationTab
{...c.props}
tab={
kind === "thread"
? { id: "thread:beta", kind, channelId: "beta", messageId: "root" }
: { id: "conversation:beta", kind, channelId: "beta" }
}
trailing={{ restHeight: 100, content: () => <p>Decision card</p> }}
/>,
);
c.settle();
expect(screen.queryByText("Decision card") !== null).toBe(
kind === "conversation",
);
},
);

it("a thread tab asks its reader to reveal for each open at a message, not on restore", () => {
const c = openingAt([]);
const tab = {
Expand Down
9 changes: 8 additions & 1 deletion src/bundled/channels/ConversationTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
} from "react";
import type { ChannelSummary } from "../../features/relay/contracts";
import type { RelaySession } from "../../features/relay/session";
import type { ConversationExtensions } from "../../features/conversation/contracts";
import type {
ConversationExtensions,
ConversationWorkspaceProps,
} from "../../features/conversation/contracts";
import {
ConversationChannel,
ConversationComposer,
Expand All @@ -29,6 +32,8 @@ import styles from "./ChannelTabs.module.css";
type ConversationTabProps = {
tab: Tab;
intro?: ReactNode;
/** Only the channel timeline shows it, not a thread. */
trailing?: ConversationWorkspaceProps["trailing"];
subthreadId?: string | undefined;
latestRequest?: AbortSignal | undefined;
active: boolean;
Expand Down Expand Up @@ -57,6 +62,7 @@ type ConversationTabProps = {
export function ConversationTab({
tab,
intro,
trailing,
subthreadId,
latestRequest,
active,
Expand Down Expand Up @@ -208,6 +214,7 @@ export function ConversationTab({
<SoloColumn enabled={soloConversation}>
<ChannelBody
intro={intro}
trailing={trailing}
latestRequest={active ? latestRequest : undefined}
viewer={session.viewer}
cached={!!channel.cached}
Expand Down
20 changes: 20 additions & 0 deletions src/bundled/channels/PageTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ vi.mock("./ConversationTab", () => ({
onResolvedRoot,
parent,
intro,
trailing,
}: {
intro?: import("react").ReactNode;
trailing?: { content(state: object): import("react").ReactNode };
tab: Tab;
channel: { name: string };
visit: boolean;
Expand All @@ -52,6 +54,7 @@ vi.mock("./ConversationTab", () => ({
>
{intro}
{tab.kind} in {channel.name}
{trailing?.content({ expanded: false, toggle() {} })}
{!visit && " unvisited"}
{onResolvedRoot && (
<button type="button" onClick={() => onResolvedRoot("older")}>
Expand Down Expand Up @@ -492,6 +495,23 @@ it("a workspace owns its main reader, intro, menu, and no initial detail", async
expect(source).toHaveBeenCalledOnce();
});

it("a workspace gives its trailing content to its main reader", () => {
const f = fixture();
cleanup();
render(
<ConversationWorkspace
id="task"
session={f.session}
scope="origin:viewer"
target={{ channelId: "alpha" }}
label="Task"
host={f.host}
trailing={{ restHeight: 100, content: () => <p>Decision card</p> }}
/>,
);
expect(screen.getByText("Decision card")).toBeVisible();
});

it.each([false, true])(
"a workspace shows its header actions before the actions menu (menu=%s)",
(menu) => {
Expand Down
1 change: 1 addition & 0 deletions src/bundled/channels/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ export function PageTabs({
key={JSON.stringify(primaryTarget)}
tab={primaryTab}
intro={workspace.intro}
trailing={workspace.trailing}
subthreadId={primaryTarget?.subthreadId}
latestRequest={latestRequest}
active={
Expand Down
14 changes: 12 additions & 2 deletions src/bundled/channels/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ afterEach(() => {
document.body.innerHTML = "";
vi.restoreAllMocks();
});
function registered() {
function registered(
registerWorkspace: (...args: unknown[]) => void = () => {},
) {
const shortcuts = { register: vi.fn() };
apply({
reflect: { get: () => undefined },
shortcuts,
conversation: {
registerCompletion() {},
registerTabs() {},
registerWorkspace() {},
registerWorkspace,
registerMessageAction() {},
},
settingsCards: { register() {} },
Expand Down Expand Up @@ -56,6 +58,14 @@ it.each([
expect(shortcut.allowInModal).toBeUndefined();
});

it("declares the workspace slots that Channels renders", () => {
const registerWorkspace = vi.fn();
registered(registerWorkspace);
expect(registerWorkspace).toHaveBeenCalledWith(expect.any(Function), {
slots: { headerActions: true, trailing: true },
});
});

it("steps only while the sidebar renders rows, and not from a terminal", () => {
const next = registered().get("next-conversation");
expect(next.when()).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion src/bundled/channels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const apply: PluginModule["apply"] = (ctx) => {
(props) => (
<ConversationWorkspace {...props} host={ctx} extensions={extensions} />
),
{ slots: { headerActions: true } },
{ slots: { headerActions: true, trailing: true } },
);
const relay = ctx.relay;
const navigator = ctx.navigation;
Expand Down
10 changes: 10 additions & 0 deletions src/features/conversation/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ export type PageTabTarget = {
/** Optional `ConversationWorkspaceProps` a workspace provider renders. */
export type WorkspaceSlots = Readonly<{
headerActions?: true;
trailing?: true;
}>;
/** A page-owned conversation with the host's reader, composer, and side pane. */
export type ConversationWorkspaceProps = {
Expand All @@ -527,6 +528,15 @@ export type ConversationWorkspaceProps = {
intro?: ReactNode;
/** Controls in the main tab's toolbar, before the actions menu. */
headerActions?: ReactNode;
/** A card over the bottom of the channel timeline; a thread ignores it.
* At rest its first `restHeight` pixels show below the latest message.
* Scrolling over the card grows it, then slides it up; `expanded` is true
* once it has grown. `toggle()` grows it to near the view's top, or back.
* Render the whole card at rest too: growing scrolls it into view. */
trailing?: {
restHeight: number;
content(state: { expanded: boolean; toggle(): void }): 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
12 changes: 7 additions & 5 deletions src/features/messages/ChannelTimeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,14 @@ function setup({
});
}
key = scoped.key;
// The feed renders inside the list's message context menu host.
section = (
scoped.type as (
props: typeof scoped.props,
) => ReactElement<{ children: Section }>
// The feed renders inside the list's message context menu host, before
// the trailing sheet.
const [menus] = (
scoped.type as (props: typeof scoped.props) => ReactElement<{
children: [ReactElement<{ children: Section }>, unknown];
}>
)(scoped.props).props.children;
section = menus.props.children;
section.props.ref.current = element;
const edge = section.props.children[0] as ReactElement<{
ref: { current: unknown };
Expand Down
Loading
Loading