Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Inbox: one definition of waiting on the person, and every kind of card listed

milind-soni37d70192bdce
diff --git a/server/host/place-inbox.test.ts b/server/host/place-inbox.test.ts
index b619aa36e4..9738925672 100644
--- a/server/host/place-inbox.test.ts
+++ b/server/host/place-inbox.test.ts
@@ -4,6 +4,7 @@ import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import type { Notification } from "../../shared/notification.ts";
+import type { PersonWait } from "../../shared/person-wait.ts";
import type { OptionCardData } from "../../shared/wire.ts";
import type { RequestAuth } from "../request-auth.ts";
import { createPlaceInbox, PLACE_MESSAGES_HOURLY, placeInboxViewer, type InboxViewer, type OpenCardRow, type PlaceInboxDeps } from "./place-inbox.ts";
@@ -111,12 +112,44 @@ describe("the inbox of a place that is no team's", () => {
it("leaves out offers and receipts, and a card somebody already settled", () => {
const f = setup();
f.ask("eli-main", "offer", { quotaSwitch: {} as never });
- f.ask("eli-main", "sent", { outboundRequest: {} as never });
f.ask("eli-main", "auto", { autoApplied: true });
f.ask("eli-main", "answered", { answered: "allow" });
expect(f.inbox.view(OWNER).rows).toEqual([]);
});
+ it("lists a password, a sign-in and an app to connect the person's conversation rests on, each with the chat's own card", () => {
+ const waits: Array<PersonWait & { threadId: string }> = [];
+ const f = setup({ waiting: () => waits });
+ const secret = { target: "custom", label: "Stripe key", description: "", placeholder: "", helpUrl: "", requestKey: "k" };
+ const signIn = { url: "https://shop.test", site: "shop.test", place: "browser" };
+ const connector = { label: "Gmail", description: "Read mail", resumeKey: "r1" };
+ f.said.set("eli-pricing", [
+ { id: "pw", at: 10, role: "bot", kind: "secret", secret } as never,
+ { id: "si", at: 11, role: "bot", kind: "signin", signIn } as never,
+ { id: "co", at: 12, role: "bot", kind: "connector", connector } as never,
+ ]);
+ f.said.set("guest-chat", [{ id: "gpw", at: 13, role: "bot", kind: "secret", secret } as never]);
+ f.guests.set("guest-chat", "p_guest");
+ waits.push(
+ { kind: "password", messageId: "pw", at: 10, label: "Stripe key", threadId: "eli-pricing" },
+ { kind: "sign-in", messageId: "si", at: 11, label: "shop.test", threadId: "eli-pricing" },
+ { kind: "connect", messageId: "co", at: 12, label: "Gmail", threadId: "eli-pricing" },
+ { kind: "password", messageId: "gpw", at: 13, label: "Stripe key", threadId: "guest-chat" },
+ );
+ const rows = f.inbox.view(OWNER).rows;
+ expect(rows.map((row) => row.id)).toEqual(["co", "si", "pw"]);
+ expect(rows.find((row) => row.id === "pw")).toMatchObject({ kind: "ask", tab: "needs-you", text: "Stripe key", secret, origin: { threadId: "eli-pricing", title: "Pricing work", messageId: "pw" } });
+ expect(rows.find((row) => row.id === "si")).toMatchObject({ signIn });
+ expect(rows.find((row) => row.id === "co")).toMatchObject({ connector });
+ expect(f.inbox.count(OWNER)).toBe(3);
+ expect(f.inbox.view(GUEST).rows.map((row) => row.id), "a guest's own password is theirs alone").toEqual(["gpw"]);
+ expect(f.inbox.view(SHELL).rows).toEqual([]);
+ expect(f.inbox.markRead(OWNER, "pw")).toBe(true);
+ expect(f.inbox.view(OWNER).rows.find((row) => row.id === "pw")!.unread).toBe(false);
+ waits.splice(0, 1);
+ expect(f.inbox.view(OWNER).rows.map((row) => row.id), "gone once it no longer waits").toEqual(["co", "si"]);
+ });
+
it("says who a bot was working for, and which conversation an item came from", () => {
const f = setup();
f.handed.set("eli-pricing", "mira");
diff --git a/server/host/place-inbox.ts b/server/host/place-inbox.ts
index 99b4734a7f..23dea3fed3 100644
--- a/server/host/place-inbox.ts
+++ b/server/host/place-inbox.ts
@@ -8,10 +8,9 @@ import { readFileSync } from "node:fs";
import { join } from "node:path";
import { z } from "zod";
-import { isPersistentQuestionCard } from "../../shared/ask-question.ts";
import type { InboxItem, InboxRow, InboxView } from "../../shared/inbox.ts";
-import { liveCardKind } from "../../shared/live-approval.ts";
import type { Notification } from "../../shared/notification.ts";
+import { personWait, type PersonWait } from "../../shared/person-wait.ts";
import type { OptionCardData } from "../../shared/wire.ts";
import { ASK_NOTIFICATIONS } from "../ask-routing.ts";
import { writeFileAtomic } from "../atomic.ts";
@@ -72,15 +71,12 @@ export interface PlaceInboxDeps {
handedBy(threadId: string): string | null;
/** Sends a notification as it is. */
send(notification: Notification): void;
+ /** Conversations resting on the person for a card a running turn does not hold open: a password, a sign-in, an app to
+ * connect, or an ask left open after its turn ended. */
+ waiting?(): Array<PersonWait & { threadId: string }>;
now?: () => number;
}
-/** Cards that wait on the person: not an offer to switch engines, a receipt, or anything settled. */
-function waitsOnPerson(card: OptionCardData | null): card is OptionCardData {
- const kind = liveCardKind(card ?? undefined);
- if (!card || !kind || card.outboundRequest || card.quotaSwitch || card.teamMemoryRequest || card.autoApplied) return false;
- return kind === "review" || card.requestType === "permission" || Boolean(card.tool) || isPersistentQuestionCard(card);
-}
export function createPlaceInbox(deps: PlaceInboxDeps) {
const { store } = deps;
@@ -136,7 +132,7 @@ export function createPlaceInbox(deps: PlaceInboxDeps) {
for (const row of deps.openCards()) {
let card: OptionCardData | null = null;
try { card = row.card ? JSON.parse(row.card) as OptionCardData : null; } catch { continue; }
- if (!waitsOnPerson(card) || !deps.sees(auth, row.threadId) || !deps.mayAnswer(auth, row.threadId, card.requestId!)) continue;
+ if (!card || !personWait({ id: row.id, at: row.at, kind: "options", card }) || !deps.sees(auth, row.threadId) || !deps.mayAnswer(auth, row.threadId, card.requestId!)) continue;
const bot = (row.fromBotId ? store.bot(row.fromBotId) : undefined) ?? store.botByThread(row.threadId);
if (!bot) continue;
const group = store.groupByThread(row.threadId);
@@ -149,6 +145,26 @@ export function createPlaceInbox(deps: PlaceInboxDeps) {
text: clip(card.subtitle || card.title || "", ROW_TEXT_MAX), at: row.at, unread: !seenAsks.has(row.id), card,
});
}
+ const listed = new Set([...rows.values()].map((row) => row.id));
+ const viewer = deps.viewer(auth);
+ for (const wait of deps.waiting?.() ?? []) {
+ if (listed.has(wait.messageId) || !deps.sees(auth, wait.threadId)) continue;
+ const guest = deps.guestOf(wait.threadId);
+ if (viewer.kind === "guest" ? guest !== viewer.key : guest !== null) continue;
+ const said = store.messagesFor(wait.threadId).find((one) => one.id === wait.messageId);
+ const bot = (wait.botId ? store.bot(wait.botId) : undefined) ?? store.botByThread(wait.threadId);
+ if (!said || !bot) continue;
+ const card = said.kind === "options" ? said.card : undefined;
+ if (card && !(card.requestId && deps.mayAnswer(auth, wait.threadId, card.requestId))) continue;
+ const group = store.groupByThread(wait.threadId);
+ const handed = workingFor(wait.threadId);
+ rows.set(wait.messageId, {
+ id: wait.messageId, kind: "ask", tab: "needs-you", from: { name: bot.name, botId: bot.id }, ...(handed ? { workingFor: handed } : {}),
+ origin: { botId: bot.id, threadId: wait.threadId, title: titleOf(bot.id, wait.threadId), ...(group ? { groupId: group.id } : {}), messageId: wait.messageId },
+ text: clip(wait.label, ROW_TEXT_MAX), at: wait.at, unread: !seenAsks.has(wait.messageId),
+ ...(card ? { card } : {}), ...(said.secret ? { secret: said.secret } : {}), ...(said.signIn ? { signIn: said.signIn } : {}), ...(said.connector ? { connector: said.connector } : {}),
+ });
+ }
return [...rows.values()];
}
diff --git a/server/index.ts b/server/index.ts
index 1d4d1b5151..2025201513 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -2890,7 +2890,7 @@ const computerAsks = CLOUD_PERSONAL ? createComputerAsksHost({ store, notify, le
const { stopThreadForPerson, stopOnTypedCommand, restartForPerson, noteTeammatesLeftRunning } = createPersonStop({
store, routines: () => routines, handoffs: () => handoffs, interruptDirectThread, clearUnattended,
stopGoal: (threadId) => oneOnOneGoals.stop(threadId), markStopped: (threadId) => personStops.stop(threadId, liveTurns.running(threadId), directTurnDispatchClaims.has(threadId)),
-}); const teamMessages = createTeamMessages({ place: CLOUD_TEAM ? null : createPlaceInbox({ dataDir: DATA_DIR, store, openCards: openCardRows, send: (notification) => { broadcast({ kind: "notify", notification: logNotification(notification) }); }, sees: (auth, threadId) => visibleTo(viewerFor(auth)).thread(threadId), mayAnswer: (auth, threadId, requestId) => cardAnswerRefusal(auth, threadId, requestId, "allow") === null, viewer: (auth) => placeInboxViewer(auth, { personal: CLOUD_PERSONAL, owner: cloudOwnerSession, personOf: personKey }), guestOf: (threadId) => { if (!CLOUD_PERSONAL || !cloudGuestDriven(threadId)) return null; const person = [...cloudThreadStarters(threadId), threadPersonKey(threadId)].find((one) => one && one !== CLOUD_OUTSIDE_KEY && !cloudOwnerPerson(one)); return person ?? null; }, guestName: (threadId) => guestNameIn(store.messagesFor(threadId)), handedBy: (threadId) => { const from = delegatorOf(threadId); return from && from.threadId !== threadId ? from.botId ?? store.botByThread(from.threadId)?.id ?? null : null; } }), team: CLOUD_TEAM, dataDir: DATA_DIR, store, people: teamOwners.people, personName: teamHost.personName, audienceOf: teamHost.audienceOf, starters: threadStarters, notify, sees: (person) => visibleTo(person.role === "member" ? { kind: "member", email: person.email } : { kind: "all", email: person.email }), inbox: { askedPerson: teamOwners.routing.askedPerson, changed: (threadId) => { const bot = store.botByThread(threadId); if (bot) broadcast({ kind: "bot", bot: wireBot(bot) }); }, ensureOwnBot: (email) => { ensureDefaultBot(store, { dataDir: DATA_DIR, person: email, team: CLOUD_TEAM?.name ?? null }); }, handedFrom: (threadId) => { const from = delegatorOf(threadId); return from && from.threadId !== threadId ? from.threadId : null; }, continueTurn: relayedTurn({ store, startTurn, state: (botId, threadId) => ({ atCapacity: botAtThreadCapacity(botId, threadId), threadBusy: threadBusy(botId, threadId), groupTurn: roomTurnHolds(activeGroupTurnForBot(botId), threadId, false), parksBehindCoordination: parksBehindCoordination(botId, threadId) }) }), representative: { generate: async (botId, prompt) => (await sideJobs.text("representative", botId)?.generateText(prompt, { timeoutMs: 60_000 })) ?? null, busy: createPersonCalendar({ access: (person) => teamConnections.personApps().includes("googlecalendar") ? teamConnections.people.appsAccess(person) : null, connected: async (access) => (await composio.connectedServices(cfg, access)).googlecalendar?.connected === true, relay: (payload, session, signal, access) => composio.relayMcp(cfg, payload as never, session, undefined, signal, access) }).busy } } });
+}); const teamMessages = createTeamMessages({ place: CLOUD_TEAM ? null : createPlaceInbox({ dataDir: DATA_DIR, store, openCards: openCardRows, waiting: () => personWaits.waiting(), send: (notification) => { broadcast({ kind: "notify", notification: logNotification(notification) }); }, sees: (auth, threadId) => visibleTo(viewerFor(auth)).thread(threadId), mayAnswer: (auth, threadId, requestId) => cardAnswerRefusal(auth, threadId, requestId, "allow") === null, viewer: (auth) => placeInboxViewer(auth, { personal: CLOUD_PERSONAL, owner: cloudOwnerSession, personOf: personKey }), guestOf: (threadId) => { if (!CLOUD_PERSONAL || !cloudGuestDriven(threadId)) return null; const person = [...cloudThreadStarters(threadId), threadPersonKey(threadId)].find((one) => one && one !== CLOUD_OUTSIDE_KEY && !cloudOwnerPerson(one)); return person ?? null; }, guestName: (threadId) => guestNameIn(store.messagesFor(threadId)), handedBy: (threadId) => { const from = delegatorOf(threadId); return from && from.threadId !== threadId ? from.botId ?? store.botByThread(from.threadId)?.id ?? null : null; } }), team: CLOUD_TEAM, dataDir: DATA_DIR, store, people: teamOwners.people, personName: teamHost.personName, audienceOf: teamHost.audienceOf, starters: threadStarters, notify, sees: (person) => visibleTo(person.role === "member" ? { kind: "member", email: person.email } : { kind: "all", email: person.email }), inbox: { askedPerson: teamOwners.routing.askedPerson, changed: (threadId) => { const bot = store.botByThread(threadId); if (bot) broadcast({ kind: "bot", bot: wireBot(bot) }); }, ensureOwnBot: (email) => { ensureDefaultBot(store, { dataDir: DATA_DIR, person: email, team: CLOUD_TEAM?.name ?? null }); }, handedFrom: (threadId) => { const from = delegatorOf(threadId); return from && from.threadId !== threadId ? from.threadId : null; }, continueTurn: relayedTurn({ store, startTurn, state: (botId, threadId) => ({ atCapacity: botAtThreadCapacity(botId, threadId), threadBusy: threadBusy(botId, threadId), groupTurn: roomTurnHolds(activeGroupTurnForBot(botId), threadId, false), parksBehindCoordination: parksBehindCoordination(botId, threadId) }) }), representative: { generate: async (botId, prompt) => (await sideJobs.text("representative", botId)?.generateText(prompt, { timeoutMs: 60_000 })) ?? null, busy: createPersonCalendar({ access: (person) => teamConnections.personApps().includes("googlecalendar") ? teamConnections.people.appsAccess(person) : null, connected: async (access) => (await composio.connectedServices(cfg, access)).googlecalendar?.connected === true, relay: (payload, session, signal, access) => composio.relayMcp(cfg, payload as never, session, undefined, signal, access) }).busy } } });
const botNameClash = createBotNameClash({ store, people: () => teamMessages.people(), profileName: () => cfg.profile?.name });
const devsReports = createDevsReports({ dataDir: DATA_DIR, store, installId: ENVIRONMENT_ID, appVersion: serverVersion(), runsOn: CLOUD_TEAM ? "Team Cloud" : CLOUD_HOME ? "My Cloud" : DESKTOP_MANAGED ? "desktop app" : HOSTED_WORKSPACE ? "hosted server" : "self-hosted server", recentLog: captureRecentLog(), send: devsReportSender(bugReportEndpoint(process.env, CLOUD_HOME?.adminOrigin)), askStatus: devsStatusAsker(bugReportEndpoint(process.env, CLOUD_HOME?.adminOrigin), CLOUD_HOME), statusEveryMs: Number(process.env.OMB_DEVS_STATUS_MS) || undefined, tell: (threadId, text, person) => { const group = store.groupByThread(threadId), bot = group ? store.bot(group.memberIds[0] ?? "") : store.botByThread(threadId); if (bot) notify({ ...buildNoticeNotification(bot, threadId, text), ...(group ? { groupId: group.id } : {}), ...(CLOUD_TEAM && person ? { forPerson: person } : {}) }); }, working: (threadId) => { const group = store.groupByThread(threadId), bot = group ? null : store.botByThread(threadId); return group ? Boolean(group.busyBotId) || groupThreadIsWorking(group.id, threadId) : Boolean(bot && threadBusy(bot.id, threadId)); }, automated: (threadId) => Boolean(routines?.isActiveThread(threadId)), engine: (instanceId) => (registry.get(instanceId) ? { name: engineName(instanceId), snapshot: registry.lastSnapshot(instanceId) } : null), appsReady: () => composio.configured(cfg), sessions: () => sessions.list(), ownerKey: CLOUD_OWNER_KEY, team: Boolean(CLOUD_TEAM), profileEmail: () => cfg.profile?.email, language: appLanguage, lineLanguage: personLanguages.forLine });
const creditMoves = cloudCredit && createCreditMoves({ credit: cloudCredit, store, context: selectionContext, threadBusy, saveDefault: saveNewBotModel,
diff --git a/shared/inbox.ts b/shared/inbox.ts
index b19501385c..58f5e46c75 100644
--- a/shared/inbox.ts
+++ b/shared/inbox.ts
@@ -1,3 +1,4 @@
+import type { ConnectorCardData } from "./connector-card.ts";
import type { OptionCardData, SecretRequestCardData, SignInRequestCardData } from "./wire.ts";
/** On a Team Cloud, a line in a person's inbox: their own conversation with their own Chief of Staff (their own MausBot
@@ -62,6 +63,8 @@ export interface InboxRow {
secret?: SecretRequestCardData;
/** A sign-in the bot asked the person to do, answered with the chat's own card for it. */
signIn?: SignInRequestCardData;
+ /** An app the bot asked the person to connect, answered with the chat's own card for it. */
+ connector?: ConnectorCardData;
}
/** A person's inbox: where its lines live (none yet before the first arrives), and the line the inbox's card in that
diff --git a/src/components/inbox/InboxAnswer.tsx b/src/components/inbox/InboxAnswer.tsx
index ace30b8b7f..5681864041 100644
--- a/src/components/inbox/InboxAnswer.tsx
+++ b/src/components/inbox/InboxAnswer.tsx
@@ -3,25 +3,20 @@ import { Check, ExternalLink } from "lucide-react";
import type { InboxRow, InboxView } from "../../../shared/inbox";
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
-import type { Bot, Message } from "@/state/store";
+import type { Bot } from "@/state/store";
import { replyToInboxRow, settleInboxRow } from "@/state/inbox";
import { ASK_QUIET_ANSWER, AskReply } from "../AskCard";
import { ELEVATED_CARD } from "../elevated";
import { pendingApprovals, PendingApprovalActions, PendingApprovalPanel } from "../PendingApproval";
+import { ConnectorCard } from "../ConnectorCard";
import { QuestionCard } from "../QuestionCard";
import { SecretRequestCard } from "../SecretRequestCard";
import { SignInRequestCard } from "../SignInRequestCard";
-import { singleQuestion, type InboxAnswerKind } from "./inbox-answer";
+import { asMessage, singleQuestion, type InboxAnswerKind } from "./inbox-answer";
import { InboxQuestionAnswer } from "./InboxQuestionAnswer";
import { answerThread } from "./inbox-view";
import { useInboxActions } from "./use-inbox-actions";
-/** The line as the chat shows it, so an ask answers here with the very card it asks with in the chat. */
-export const asMessage = (row: InboxRow): Message => ({
- id: row.id, role: "bot", kind: row.secret ? "secret" : row.signIn ? "signin" : "options", text: row.text, at: row.at,
- ...(row.card ? { card: row.card } : {}), ...(row.secret ? { secret: row.secret } : {}), ...(row.signIn ? { signIn: row.signIn } : {}),
-} as Message);
-
interface AnswerProps { view: InboxView; row: InboxRow; threadId: string | null; asker?: Bot }
function QuestionAnswer({ view, row, threadId, asker }: AnswerProps) {
@@ -54,11 +49,16 @@ function ReviewAnswer({ view, row }: AnswerProps) {
);
}
-function SecretAnswer({ row, threadId, asker }: AnswerProps) {
+function PasswordAnswer({ row, threadId, asker }: AnswerProps) {
const botId = row.from.botId;
return botId && threadId ? <SecretRequestCard botId={botId} color={asker?.color} threadId={threadId} message={asMessage(row)} /> : null;
}
+function ConnectAnswer({ row, threadId, asker }: AnswerProps) {
+ const botId = row.from.botId;
+ return botId && threadId ? <ConnectorCard botId={botId} color={asker?.color} threadId={threadId} message={asMessage(row)} /> : null;
+}
+
function SignInAnswer({ row, threadId, asker }: AnswerProps) {
const botId = row.from.botId;
return botId && threadId ? <SignInRequestCard botId={botId} botName={asker?.name ?? row.from.name} color={asker?.color} threadId={threadId} message={asMessage(row)} /> : null;
@@ -97,8 +97,9 @@ const ANSWERS: Record<InboxAnswerKind, (props: AnswerProps) => ReactNode> = {
question: QuestionAnswer,
approval: ApprovalAnswer,
review: ReviewAnswer,
- secret: SecretAnswer,
- signIn: SignInAnswer,
+ password: PasswordAnswer,
+ "sign-in": SignInAnswer,
+ connect: ConnectAnswer,
reply: ReplyAnswer,
none: DoneButton,
};
diff --git a/src/components/inbox/InboxCard.tsx b/src/components/inbox/InboxCard.tsx
index 5358fc9934..c828ac1cae 100644
--- a/src/components/inbox/InboxCard.tsx
+++ b/src/components/inbox/InboxCard.tsx
@@ -12,7 +12,7 @@ import { pendingApprovals, PendingApprovalActions } from "../PendingApproval";
import { ASK_QUIET_ANSWER, ASK_QUIET_BUTTON, AskChoices, AskError } from "../AskCard";
import { ELEVATED_CARD } from "../elevated";
import { InboxRowItem } from "./InboxRow";
-import { asMessage } from "./InboxAnswer";
+import { asMessage } from "./inbox-answer";
import { askOf, CARD_ROWS, choiceResponse, choicesOf, rowsIn, tabCounts } from "./inbox-view";
import { accessRequestWords } from "../bot-access/access-card";
import { useInboxActions } from "./use-inbox-actions";
diff --git a/src/components/inbox/InboxReading.dom.test.ts b/src/components/inbox/InboxReading.dom.test.ts
index cdf9fdbb79..27e2b7709a 100644
--- a/src/components/inbox/InboxReading.dom.test.ts
+++ b/src/components/inbox/InboxReading.dom.test.ts
@@ -91,13 +91,17 @@ describe("the inbox's words", () => {
expect(nextAfter(["a"], "a")).toBeNull();
});
- it("keys a password and a sign-in by their own card kind, ahead of anything else the line says", () => {
+ it("keys a password, a sign-in and an app to connect by what the line waits on the person for", () => {
const secret: InboxRow = { ...news, kind: "ask", tab: "needs-you", secret: { target: "custom", label: "Stripe key", description: "", placeholder: "", helpUrl: "", requestKey: "k" } as InboxRow["secret"] };
const signIn: InboxRow = { ...news, kind: "ask", tab: "needs-you", signIn: { url: "https://shop.test", site: "shop.test", place: "browser" } as InboxRow["signIn"] };
- expect(answerKindOf(secret)).toBe("secret");
- expect(answerKindOf(signIn)).toBe("signIn");
+ const connect: InboxRow = { ...news, kind: "ask", tab: "needs-you", connector: { label: "Gmail", description: "Read mail", resumeKey: "r1" } as InboxRow["connector"] };
+ expect(answerKindOf(secret)).toBe("password");
+ expect(answerKindOf(signIn)).toBe("sign-in");
+ expect(answerKindOf(connect)).toBe("connect");
expect(answerKindOf({ ...signIn, signIn: { ...signIn.signIn!, done: true } })).toBe("none");
+ expect(answerKindOf({ ...secret, secret: { ...secret.secret!, provided: true } })).toBe("none");
expect(headlineOf(signIn)).toBe("Sign in to shop.test");
+ expect(headlineOf(connect)).toBe("Connect Gmail");
});
});
@@ -186,6 +190,23 @@ describe("a line read in full", () => {
expect(currentInboxPanel().reading).toBeNull();
});
+ it("answers a password, a sign-in and an app to connect with the chat's own card for each", async () => {
+ const base = { ...news, kind: "ask" as const, tab: "needs-you" as const };
+ const rows: InboxRow[] = [
+ { ...base, id: "pw", secret: { target: "custom", label: "Stripe key", description: "For the billing report", placeholder: "sk_live_…", helpUrl: "", requestKey: "k", reason: "To read invoices" } as InboxRow["secret"] },
+ { ...base, id: "si", signIn: { url: "https://shop.test", site: "shop.test", place: "browser", reason: "To see the order" } as InboxRow["signIn"] },
+ { ...base, id: "co", connector: { label: "Gmail", description: "Read mail", resumeKey: "r1", status: "required" } as InboxRow["connector"] },
+ ];
+ setInboxView(placeView(rows));
+ await mount();
+ for (const [id, kind, words] of [["pw", "password", "Stripe key"], ["si", "sign-in", "shop.test"], ["co", "connect", "Gmail"]] as const) {
+ await act(async () => { readInboxLine(id); });
+ const answer = document.querySelector<HTMLElement>(`[data-inbox-reading="${id}"] [data-inbox-answer-kind]`)!;
+ expect(answer.dataset.inboxAnswerKind).toBe(kind);
+ expect(answer.textContent, kind).toContain(words);
+ }
+ });
+
it("reads news with Done, which moves on to what is left", async () => {
await act(async () => { readInboxLine("n1"); });
await mount();
diff --git a/src/components/inbox/InboxReading.tsx b/src/components/inbox/InboxReading.tsx
index 01273a7a48..95c5a96429 100644
--- a/src/components/inbox/InboxReading.tsx
+++ b/src/components/inbox/InboxReading.tsx
@@ -28,7 +28,7 @@ function settledLabel(row: InboxRow): string {
/** What the line itself says, drawn after the bot's words before it: a question's question, news as it came. An approval,
* a password or a sign-in says it on its own card. */
function ownWords(row: InboxRow): string | null {
- if (row.secret || row.signIn) return null;
+ if (row.secret || row.signIn || row.connector) return null;
if (row.kind !== "ask") return textOf(row);
if (row.card?.tool) return null;
const question = singleQuestion(row);
diff --git a/src/components/inbox/inbox-answer.ts b/src/components/inbox/inbox-answer.ts
index a2e381b642..281a8bdad8 100644
--- a/src/components/inbox/inbox-answer.ts
+++ b/src/components/inbox/inbox-answer.ts
@@ -1,23 +1,28 @@
import type { AskQuestion } from "../../../shared/ask-question";
import type { InboxRow } from "../../../shared/inbox";
+import { personWait, type PersonWaitKind } from "../../../shared/person-wait";
+import type { Message } from "@/state/store";
import { t } from "@/lib/i18n";
import { cardQuestions } from "../QuestionCard";
import { accessRequestWords } from "../bot-access/access-card";
-import { askOf, senderLabel, subjectOf, textOf } from "./inbox-view";
+import { senderLabel, subjectOf, textOf } from "./inbox-view";
-/** How a line is answered: a question's choices, an approval's Allow and Deny, a proposal reviewed in its chat, a
- * password or a sign-in through the chat's own card for it, a reply to news that waits on one, or nothing but Done. */
-export type InboxAnswerKind = "question" | "approval" | "review" | "secret" | "signIn" | "reply" | "none";
+/** How a line is answered: by what it waits on the person for, else a reply to news that waits on one, or nothing but Done. */
+export type InboxAnswerKind = PersonWaitKind | "reply" | "none";
-const secretOpen = (row: InboxRow) => Boolean(row.secret && !row.secret.provided && !row.secret.dismissed && !row.secret.superseded && !row.secret.stopped);
-const signInOpen = (row: InboxRow) => Boolean(row.signIn && !row.signIn.done && !row.signIn.cancelled && !row.signIn.superseded && !row.signIn.stopped && !row.signIn.answeredInChat);
+/** The line as the chat shows it, so it answers here with the very card it asks with in the chat. */
+export const asMessage = (row: InboxRow): Message => ({
+ id: row.id, role: "bot", kind: row.secret ? "secret" : row.signIn ? "signin" : row.connector ? "connector" : "options", text: row.text, at: row.at,
+ ...(row.card ? { card: row.card } : {}), ...(row.secret ? { secret: row.secret } : {}), ...(row.signIn ? { signIn: row.signIn } : {}),
+ ...(row.connector ? { connector: row.connector } : {}),
+} as Message);
export function answerKindOf(row: InboxRow): InboxAnswerKind {
if (row.tab === "done") return "none";
- if (secretOpen(row)) return "secret";
- if (signInOpen(row)) return "signIn";
- const ask = askOf(row);
- if (ask) return ask;
+ if (row.kind === "ask") {
+ const wait = personWait(asMessage(row));
+ if (wait) return wait.kind;
+ }
return row.tab === "info" && row.replies === true ? "reply" : "none";
}
@@ -54,6 +59,7 @@ const firstLine = (text: string) => text.split("\n").map((line) => line.replace(
export function headlineOf(row: InboxRow): string {
if (row.secret) return row.secret.label;
if (row.signIn) return t("inbox.headline.signIn", { site: row.signIn.site });
+ if (row.connector) return t("inbox.headline.connect", { app: row.connector.label });
if (row.kind === "ask") {
const question = row.card && !row.card.tool ? singleQuestion(row) : null;
if (question) return question.header ?? firstLine(accessRequestWords(row.card)?.question ?? question.question);
diff --git a/src/locales/en.json b/src/locales/en.json
index 12f8d3d476..d4a93a68a1 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2080,6 +2080,7 @@
"inbox.note": "Add a note",
"inbox.you": "You",
"inbox.headline.signIn": "Sign in to {site}",
+ "inbox.headline.connect": "Connect {app}",
"inbox.youReplied": "You replied",
"sidebar.people.mention": "Write to {name}",
"orgChart.mode.departments": "Departments",