evOo-local/apps/web/src/lib/main-inbox.test.ts
Claude 408db28330
feat(inbox): show what specialists need from the user in the main conversation
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
2026-10-02 23:01:33 +00:00

41 lines
1.6 KiB
TypeScript

import type { InboxItem } from "@rakazo/contracts";
import { describe, expect, it } from "vitest";
import { inboxItemKey, inboxRefreshSignal } from "./main-inbox";
const bot = { id: "bot-scout", name: "Scout", color: "#3B82F6" };
const base = { bot, target: { botId: bot.id }, createdAt: "2026-10-02T09:00:00.000Z" };
const ask = { kind: "ask", text: "Which city?", status: "pending" } as const;
describe("inboxItemKey", () => {
it("keys asks by message, takeovers by run, and unread threads by bot", () => {
const items: InboxItem[] = [
{ ...base, kind: "ask", runId: "run-1", messageId: "msg-1", ask },
{ ...base, kind: "approval", runId: "run-2", messageId: "msg-2", ask },
{ ...base, kind: "takeover", runId: "run-3", messageId: null, text: "" },
{ ...base, kind: "unread", messageId: "msg-4", text: "hi" },
];
expect(items.map(inboxItemKey)).toEqual([
"ask:msg-1",
"ask:msg-2",
"takeover:run-3",
`unread:${bot.id}`,
]);
});
});
describe("inboxRefreshSignal", () => {
const idle = { id: bot.id, status: "idle", unread: false, preview: "done" };
it("stays the same while nothing the inbox shows has changed", () => {
expect(inboxRefreshSignal([idle])).toBe(inboxRefreshSignal([{ ...idle }]));
});
it("changes with run status, unread state, or a new message", () => {
const signal = inboxRefreshSignal([idle]);
expect(inboxRefreshSignal([{ ...idle, status: "waiting_input" }])).not.toBe(signal);
expect(inboxRefreshSignal([{ ...idle, unread: true }])).not.toBe(signal);
expect(inboxRefreshSignal([{ ...idle, preview: "Which city?" }])).not.toBe(signal);
});
});