Specialists ask questions, request approvals and the computer screen in their own threads, and the user only finds out by opening each thread. With the main conversation as the single entry point, those requests have to reach the user there, with the specialist as the visible sender. - inbox.list returns, for the current space and the user's own bots, pending asks and approvals (bot messages with a pending ask block whose run waits for input), takeover requests, and unread specialist threads. Asks already in the main conversation are left out; takeovers stay because their controls live in the bot's own thread. Each item carries the bot, the thread target, run and message ids, and the ask block for asks and approvals. - The main conversation shows the items above the composer. Asks and approvals are answered in place through threads.answer with the source thread target; takeovers and unread threads open the bot's thread. The list refreshes when the bots' status, unread state or newest message changes, every 15 seconds, and after an answer. - The inbox shrinks and scrolls so it never pushes the composer out of view. The transcript now clips its scroller: with no room left in the column, the scroller's padding used to spill over whatever sat below it. - The ask block schema is extracted from MessageBlock so the inbox contract reuses it, and AskCard accepts a className. Tests: unit tests for the item builder and the component, a Postgres suite for the query (added to the harness list), inbox cases in the authorization suite, and an E2E spec in which a specialist asks in its own thread and the user answers from the main conversation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
86 lines
3.8 KiB
TypeScript
86 lines
3.8 KiB
TypeScript
import { expect, type Page, test } from "@playwright/test";
|
|
import type { Group } from "@rakazo/contracts";
|
|
import { captureScreenshot, routePatchRpc, rpc, signup, waitForChatComposer } from "./helpers";
|
|
|
|
test("answers a specialist's question from the main conversation", async ({ page }, testInfo) => {
|
|
const stamp = Date.now();
|
|
await signup(page, `inbox-${stamp}@rakazo.test`, "password12", "Inbox");
|
|
// Bots come from RPC: this spec is about the inbox, not the onboarding flow.
|
|
await page.waitForURL(/\/(onboarding|app)/, { timeout: 30_000 });
|
|
const researcher = await createBot(page, "Researcher");
|
|
|
|
await rpc(page, "threads/send", { botId: researcher.id, text: "ask me which city to use" });
|
|
await expect
|
|
.poll(async () => (await activeRun(page, researcher.id))?.status ?? null, { timeout: 60_000 })
|
|
.toBe("waiting_input");
|
|
|
|
await openMainConversation(page, researcher.id);
|
|
const inbox = page.getByRole("region", { name: "Needs you" });
|
|
const ask = inbox.locator("[data-kind='ask']");
|
|
await expect(ask).toBeVisible({ timeout: 30_000 });
|
|
await expect(ask).toContainText("Researcher");
|
|
await expect(ask).toContainText("Which city should I use?");
|
|
await expect(page.getByRole("combobox", { name: "Message" })).toBeInViewport();
|
|
await captureScreenshot(page, testInfo, "inbox-ask");
|
|
|
|
await ask.getByRole("button", { name: "Edit first" }).click();
|
|
await ask.getByRole("textbox", { name: "Answer" }).fill("Paris");
|
|
await ask.getByRole("button", { name: "Send answer" }).click();
|
|
await expect(ask).toHaveCount(0);
|
|
await expect.poll(async () => activeRun(page, researcher.id), { timeout: 60_000 }).toBeNull();
|
|
|
|
// The answer resumed the specialist in its own thread; its reply arrives as unread.
|
|
const reply = inbox.locator("[data-kind='unread']").filter({ hasText: "Researcher" });
|
|
await expect(reply).toContainText("Paris", { timeout: 30_000 });
|
|
await captureScreenshot(page, testInfo, "inbox-unread-reply");
|
|
|
|
await reply.getByRole("button").click();
|
|
await page.waitForURL(new RegExp(`/app/${researcher.id}$`));
|
|
await expect(page.getByText("Answered: Paris", { exact: true })).toBeVisible({ timeout: 30_000 });
|
|
});
|
|
|
|
async function createBot(page: Page, name: string) {
|
|
return rpc<{ id: string }>(page, "bots/create", {
|
|
name,
|
|
title: "",
|
|
description: "",
|
|
notifyOnFinish: true,
|
|
computerMode: "team",
|
|
});
|
|
}
|
|
|
|
async function activeRun(page: Page, botId: string) {
|
|
const snapshot = await rpc<{ run?: { status: string } | null }>(page, "threads/get", { botId });
|
|
return snapshot.run ?? null;
|
|
}
|
|
|
|
/**
|
|
* Opens the user's main conversation. Until the app sets one up, a group with the specialist
|
|
* stands in for it and is reported to the client as the main conversation.
|
|
*/
|
|
async function openMainConversation(page: Page, specialistId: string) {
|
|
// The shell's first load is where the app sets up the main conversation.
|
|
await rpc(page, "bootstrap", {});
|
|
const groups = await rpc<Group[]>(page, "groups/list", {});
|
|
let main = groups.find((group) => group.kind === "main");
|
|
if (!main) {
|
|
const lead = await createBot(page, "Lead");
|
|
const stand = await rpc<Group>(page, "groups/create", {
|
|
name: "Main",
|
|
botIds: [lead.id, specialistId],
|
|
});
|
|
const asMain = (list: unknown) =>
|
|
Array.isArray(list)
|
|
? list.map((group) => (group?.id === stand.id ? { ...group, kind: "main" } : group))
|
|
: list;
|
|
await routePatchRpc(page, "bootstrap", (json) => ({ ...json, groups: asMain(json.groups) }));
|
|
await routePatchRpc(page, "spaces/list", (json) => {
|
|
const current = json.current as { groups?: unknown } | undefined;
|
|
return current ? { ...json, current: { ...current, groups: asMain(current.groups) } } : json;
|
|
});
|
|
main = stand;
|
|
}
|
|
await page.goto(`/app/g/${main.id}`, { waitUntil: "domcontentloaded" });
|
|
await waitForChatComposer(page);
|
|
}
|