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
1 change: 1 addition & 0 deletions docs/plugin-authoring-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Other grants (`mcp`, `managedFiles`, `publicImages`, `publicPages`, `agentHooks`
- Use the `ui` controls for buttons, fields, switches and dialogs. Use `className="ui-card"` for a card, `var(--space-panel-inset)` and `var(--space-2)` for spacing, and inline styles for layout. Plain `h1`–`h3`, `p` and `button` get host styling.
- Use host color tokens (`var(--...)`) so light and dark themes both work. Rely only on the `core` roles in `src/shared/design-system/tokens/registry.ts`; other custom properties, classes and `data-*` attributes are internal.
- Avoid fixed widths; pages can be narrow.
- For `ctx.agents.ui.Transcript`, set `endedAt` on a finished turn, or supply `outcome` if its end time is unknown. Use `at: 0` for an unknown item timestamp. Omit `completedAt` when a tool's start time is unknown.

## Common mistakes

Expand Down
20 changes: 13 additions & 7 deletions src/features/agents/ActivityTranscript.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,22 @@ it("shows no time for an entry with a zero, non-finite or invalid time", () => {
});

it.each([
["ended", 2000, undefined, "Completed"],
["working", undefined, undefined, "Working"],
["ended", 2000, "Command failed", "Failed"],
["unknown", undefined, undefined, "Status unknown"],
["ended", 2000, undefined, undefined, "Completed"],
["working", undefined, undefined, undefined, "Working"],
["working", undefined, "ended", undefined, "Completed"],
["working", undefined, "error", undefined, "Failed"],
["working", undefined, "stopped", undefined, "Stopped"],
["working", undefined, "unknown", undefined, "Status unknown"],
["ended", 2000, undefined, "Command failed", "Failed"],
["unknown", undefined, undefined, undefined, "Status unknown"],
] as const)(
"shows only the turn status for %s/%s/%s",
(state, endedAt, error, label) => {
"shows only the turn status for %s/%s/%s/%s",
(state, endedAt, outcome, error, label) => {
const turn = {
turnId: "status",
startedAt: 1000,
endedAt,
outcome,
error,
channelId: "channel",
threadRootId: "a".repeat(64),
Expand All @@ -444,10 +449,11 @@ it.each([
state={() => state}
/>,
);
if (state === "working") {
if (label === "Working") {
expect(container.querySelector("header")).toBeNull();
expect(screen.getAllByText("Working")).toHaveLength(1);
} else {
expect(screen.queryByText("Working")).not.toBeInTheDocument();
expect(container.querySelector("header")).toHaveTextContent(label);
expect(container.querySelector("header time") !== null).toBe(!!endedAt);
}
Expand Down
4 changes: 3 additions & 1 deletion src/features/agents/ActivityTranscript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ export function ActivityTranscript({
<Turn
turn={turn}
state={
turn.endedAt ? "ended" : (state(turn.turnId) ?? "unknown")
turn.endedAt || turn.outcome
? "ended"
: (state(turn.turnId) ?? "unknown")
}
agentName={agentName}
openConversation={openConversation}
Expand Down
92 changes: 85 additions & 7 deletions src/features/agents/TranscriptPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ afterEach(() => {
});

/** A read whose calls each settle when the test says. */
function reads() {
function reads<T = string>() {
const calls: {
key: string;
signal: AbortSignal;
resolve(value: string | undefined): void;
resolve(value: T | undefined): void;
reject(error: Error): void;
}[] = [];
const read = (key: string) => (signal: AbortSignal) =>
new Promise<string | undefined>((resolve, reject) =>
new Promise<T | undefined>((resolve, reject) =>
calls.push({ key, signal, resolve, reject }),
);
return { calls, read };
Expand Down Expand Up @@ -312,7 +312,11 @@ it("keeps the transcript while new read inputs are read, and ignores the read th
});
view.rerender({ key: "a", again: "s3", working: false });
await settle(nth(calls, 3), "second");
expect(view.result.current.shown).toEqual({ key: "a", transcript: "second" });
expect(view.result.current.shown).toEqual({
key: "a",
transcript: "second",
working: false,
});
});

it("shows a missing transcript as null", async () => {
Expand All @@ -321,6 +325,83 @@ it("shows a missing transcript as null", async () => {
expect(view.result.current.shown.transcript).toBeNull();
});

const agent = { key: "agent", name: "Agent" } as Parameters<
typeof TranscriptPanel
>[0]["agent"];

it.each([
{ result: "succeeds", late: false },
{ result: "fails", late: false },
{ result: "succeeds", late: true },
{ result: "fails", late: true },
])(
"shows the stop outcome when the read $result (past the hold: $late)",
async ({ result, late }) => {
const { read, calls } = reads<Transcript>();
const panel = (working: boolean) => (
<TranscriptPanel
agent={agent}
read={read("session")}
readKey="session"
working={working}
reading="Reading…"
missing="Missing"
failed="Could not read"
/>
);
const live: TranscriptTurn = {
turnId: "latest",
startedAt: 1000,
channelId: null,
threadRootId: null,
triggeringEventIds: [],
config: [],
newSession: false,
partial: false,
items: [],
};
const view = render(panel(true));
await act(async () => nth(calls, 0).resolve({ turns: [live] }));
expect(screen.getByText("Working")).toBeVisible();

view.rerender(panel(false));
const stop = nth(calls, 1);
expect(screen.getByText("Working")).toBeVisible();
expect(screen.queryByText("Status unknown")).toBeNull();
if (late) {
act(() => vi.advanceTimersByTime(9_999));
expect(screen.getByText("Working")).toBeVisible();
act(() => vi.advanceTimersByTime(1));
expect(screen.getByText("Status unknown")).toBeVisible();
expect(screen.queryByText("Working")).toBeNull();
}
if (result === "succeeds") {
await act(async () =>
stop.resolve({ turns: [{ ...live, endedAt: 2000 }] }),
);
expect(screen.getByText("Completed")).toBeVisible();
} else {
await act(async () => stop.reject(new Error("unavailable")));
expect(screen.getByRole("alert")).toHaveTextContent(
"Could not read: unavailable",
);
expect(screen.getByText("Status unknown")).toBeVisible();
}
expect(screen.queryByText("Working")).toBeNull();
act(() => vi.advanceTimersByTime(LIVE_READ_MS * 3));
expect(calls).toHaveLength(2);
if (late && result === "succeeds") {
view.rerender(panel(true));
await act(async () => nth(calls, 2).resolve({ turns: [live] }));
view.rerender(panel(false));
act(() => vi.advanceTimersByTime(9_999));
expect(screen.getByText("Working")).toBeVisible();
act(() => vi.advanceTimersByTime(1));
expect(screen.getByText("Status unknown")).toBeVisible();
}
},
);

it("keeps the shown transcript mounted while its sessions change", async () => {
const pending: {
resolve(value: Transcript): void;
Expand All @@ -330,9 +411,6 @@ it("keeps the shown transcript mounted while its sessions change", async () => {
new Promise<Transcript | undefined>((resolve, reject) =>
pending.push({ resolve, reject }),
);
const agent = { key: "agent", name: "Agent" } as Parameters<
typeof TranscriptPanel
>[0]["agent"];
const panel = (readAgain: string) => (
<div style={{ overflowY: "auto" }}>
<TranscriptPanel
Expand Down
17 changes: 14 additions & 3 deletions src/features/agents/TranscriptPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { AgentViewProps } from "./service";
export const LIVE_READ_MS = 2500;
/** How long after a read a step the agent reports reads again. */
export const STEP_READ_MS = 1000;
const STOP_STATUS_HOLD_MS = 10_000;
/** Turns a merged transcript holds at most. */
export const TURN_LIMIT = 50;

Expand Down Expand Up @@ -51,6 +52,7 @@ type Shown<T> = Readonly<{
key: string;
/** null: the agent type has no transcript for it. */
transcript?: T | null;
working?: boolean;
error?: string;
}>;
/** A full read, or one of only the latest turns. */
Expand Down Expand Up @@ -214,8 +216,8 @@ export function useLiveTranscript<T extends Transcript>({
const before = held.current;
held.current =
next.error !== undefined && before.key === key
? { ...before, error: next.error }
: { key, ...next };
? { ...before, working, error: next.error }
: { key, ...next, working };
setShown(held.current);
if (queued.current && request(true, queued.current)) return;
setLoading(false);
Expand Down Expand Up @@ -341,6 +343,15 @@ export function TranscriptPanel<T extends Transcript>({
refreshWhileWorking,
agentKey: agent.key,
});
const holding = !working && Boolean(shown.working);
const [holdExpired, setHoldExpired] = useState(false);
useEffect(() => {
setHoldExpired(false);
if (!holding) return;
const timer = setTimeout(() => setHoldExpired(true), STOP_STATUS_HOLD_MS);
return () => clearTimeout(timer);
}, [holding]);
const isWorking = shown.working && (working || !holdExpired);
const { transcript, error } = shown;
return (
<div className={activityStyles.transcript} data-transcript>
Expand Down Expand Up @@ -379,7 +390,7 @@ export function TranscriptPanel<T extends Transcript>({
agentKey={agent.key}
agentPicture={agent.picture}
community={agent.relay}
state={() => (working ? "working" : undefined)}
state={() => (isWorking ? "working" : undefined)}
before={notes?.(transcript)}
/>
) : (
Expand Down
Loading