Skip to content

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

Brief: number reply and dismiss labels when one sender has two emails (#7390)

Ooi Pin Jun9c546ae64bea
diff --git a/server/host/brief-cards.test.ts b/server/host/brief-cards.test.ts
index 012f406c6e..1087161747 100644
--- a/server/host/brief-cards.test.ts
+++ b/server/host/brief-cards.test.ts
@@ -2,9 +2,9 @@ import { describe, expect, it } from "vitest";
import englishCatalog from "../../src/locales/en.json" with { type: "json" };
import type { WidgetText, WidgetTextParam } from "../../shared/widget-text.ts";
-import { parseWidgetInput } from "../../shared/widget.ts";
+import { parseWidgetInput, widgetActions } from "../../shared/widget.ts";
import { WATCH_FAILURE } from "./brief.ts";
-import { briefCard, prepCard, reminderCard, type BriefFacts } from "./brief-cards.ts";
+import { briefCard, DISMISS_ACTION, DRAFT_ACTION, prepCard, reminderCard, type BriefFacts } from "./brief-cards.ts";
const english = englishCatalog as Record<string, string>;
const NOW = Date.UTC(2026, 9, 22, 13, 0);
@@ -26,6 +26,17 @@ function texts(node: unknown, found: WidgetText[] = []): WidgetText[] {
return found;
}
+function findButton(node: unknown, id: string): { i18n?: unknown } | undefined {
+ if (!node || typeof node !== "object") return undefined;
+ const record = node as { id?: string; type?: string; children?: unknown[]; i18n?: unknown };
+ if (record.type === "Button" && record.id === id) return record;
+ for (const child of record.children ?? []) {
+ const found = findButton(child, id);
+ if (found) return found;
+ }
+ return undefined;
+}
+
function nested(text: WidgetText): WidgetText[] {
return [text, ...Object.values(text.params ?? {}).flatMap((param: WidgetTextParam) => (typeof param === "object" && "key" in param ? nested(param) : []))];
}
@@ -53,6 +64,41 @@ describe("the brief's cards", () => {
}
});
+ it("gives two emails from one sender distinct reply and dismiss labels", () => {
+ const ada = (messageId: string, threadId: string, subject: string, needsReply: boolean) =>
+ ({ messageId, threadId, from: "Ada <[email protected]>", subject, needsReply });
+ const cases = [
+ [ada("m1", "t1", "Q3 numbers", true), ada("m2", "t2", "Friday agenda", false)],
+ [ada("m1", "t1", "Q3 numbers", true), ada("m2", "t2", "Q3 numbers", true)],
+ [ada("m1", "t1", "", false), ada("m2", "t2", "", false)],
+ [ada("m1", "t1", "Friday agenda", false), ada("m2", "t2", "Friday agenda", false)],
+ ];
+ for (const emails of cases) {
+ const card = briefCard({ now: NOW, timeZone: "UTC", intro: false, meetings: null, emails, needs: [], routines: [] }).card;
+ const parsed = parseWidgetInput(card);
+ expect(parsed.ok, parsed.ok ? "" : parsed.error).toBe(true);
+ if (!parsed.ok) continue;
+ const presses = widgetActions(parsed.value).filter((entry) => entry.action.type === DRAFT_ACTION || entry.action.type === DISMISS_ACTION);
+ expect(presses.map((entry) => [entry.label, entry.action.type, entry.action.payload])).toEqual([
+ ["1. Draft a reply to Ada", DRAFT_ACTION, { messageId: "m1" }],
+ ["1. Dismiss Ada's email", DISMISS_ACTION, { messageId: "m1" }],
+ ["2. Draft a reply to Ada", DRAFT_ACTION, { messageId: "m2" }],
+ ["2. Dismiss Ada's email", DISMISS_ACTION, { messageId: "m2" }],
+ ]);
+ const labels = presses.map((entry) => {
+ const button = findButton(parsed.value, entry.ref);
+ return button?.i18n && typeof button.i18n === "object" ? (button.i18n as { label?: WidgetText }).label : undefined;
+ });
+ expect(labels).toEqual([
+ { key: "brief.card.numberedEmailAction", params: { number: 1, action: { key: "brief.card.draftReply", params: { who: "Ada" } } } },
+ { key: "brief.card.numberedEmailAction", params: { number: 1, action: { key: "brief.card.dismissEmail", params: { who: "Ada" } } } },
+ { key: "brief.card.numberedEmailAction", params: { number: 2, action: { key: "brief.card.draftReply", params: { who: "Ada" } } } },
+ { key: "brief.card.numberedEmailAction", params: { number: 2, action: { key: "brief.card.dismissEmail", params: { who: "Ada" } } } },
+ ]);
+ }
+ expect(english["brief.card.numberedEmailAction"]).toBe("{number}. {action}");
+ });
+
it("name a routine's Open page button", () => {
const card = briefCard({ ...facts, routines: [{ text: "Digest", note: "Done", page: "https://pages.example.com/p/1" }] }).card;
const json = JSON.stringify(card);
diff --git a/server/host/brief-cards.ts b/server/host/brief-cards.ts
index f54ceefd81..e88efa38e4 100644
--- a/server/host/brief-cards.ts
+++ b/server/host/brief-cards.ts
@@ -190,16 +190,23 @@ function openEmailButton(email: BriefEmail, w: BriefWords): Node[] {
return gmail ? [button(w.openInGmail, gmail, false, words("brief.card.openGmail"))] : [];
}
-function emailRow(email: BriefEmail, w: BriefWords): Node {
+function numberedAction(label: string, said: WidgetText, position: number | undefined): { label: string; said: WidgetText } {
+ if (position === undefined) return { label, said };
+ return { label: `${position}. ${label}`, said: words("brief.card.numberedEmailAction", { number: position, action: said }) };
+}
+
+function emailRow(email: BriefEmail, w: BriefWords, position?: number): Node {
const who = sender(email, BRIEF_TEXT.label, w);
const note = email.needsReply ? (email.why ? `${w.waitingOnReply} · ${email.why}` : w.waitingOnReply) : email.why ?? w.important;
const whoWords = senderName(email.from).trim() ? who : words("brief.part.noSender");
const line = words("brief.card.emailLine", { sender: senderName(email.from).trim() ? sender(email, BRIEF_TEXT.sender, w) : words("brief.part.noSender"), subject: email.subject || words("brief.part.noSubject") });
const noteWords = inboxNoteWords(email.why, email.whyText, email.needsReply) ?? (email.needsReply ? (email.why ? words("brief.card.waitingReplyWhy", { why: email.why }) : words("brief.card.waitingReply")) : email.why ? undefined : words("brief.card.important"));
+ const reply = numberedAction(w.draftReply(who), words("brief.card.draftReply", { who: whoWords }), position);
+ const dismiss = numberedAction(w.dismiss(who), words("brief.card.dismissEmail", { who: whoWords }), position);
return rowUnder(`${sender(email, BRIEF_TEXT.sender, w)}: ${email.subject || w.noSubject}`, note, [
- button(w.draftReply(who), { type: DRAFT_ACTION, payload: { messageId: email.messageId } }, true, words("brief.card.draftReply", { who: whoWords })),
+ button(reply.label, { type: DRAFT_ACTION, payload: { messageId: email.messageId } }, true, reply.said),
...openEmailButton(email, w),
- button(w.dismiss(who), { type: DISMISS_ACTION, payload: { messageId: email.messageId } }, false, words("brief.card.dismissEmail", { who: whoWords })),
+ button(dismiss.label, { type: DISMISS_ACTION, payload: { messageId: email.messageId } }, false, dismiss.said),
], { text: line, ...(noteWords ? { note: noteWords } : {}) });
}
@@ -211,12 +218,13 @@ export function briefCard(facts: BriefFacts): BuiltCard {
const w = briefWords(language);
const replies = facts.emails.filter((email) => email.needsReply);
const important = facts.emails.filter((email) => !email.needsReply);
- const needRows = [...replies.map((email) => emailRow(email, w)), ...facts.needs.map((row) => rowBeside(row.text, row.note, openButton(row.open, w), row.said))];
+ const place = (index: number): number | undefined => (facts.emails.length > 1 ? index + 1 : undefined);
+ const needRows = [...replies.map((email, index) => emailRow(email, w, place(index))), ...facts.needs.map((row) => rowBeside(row.text, row.note, openButton(row.open, w), row.said))];
const meetings = [...(facts.meetings ?? [])].sort((a, b) => a.start - b.start);
const meetingRows = meetings.map((meeting) => rowBeside(`${clockTime(meeting.start, zone, language)} · ${meeting.title}`, "", joinButton(meeting, w.join),
{ text: words("brief.card.meetingLine", { time: moment(meeting.start, "clock", zone), title: meeting.title }) }));
const waiting = facts.waiting === true ? w.waitingMany : facts.waiting ? w.waitingCount(facts.waiting) : undefined;
- const importantRows = important.map((email) => emailRow(email, w));
+ const importantRows = important.map((email, index) => emailRow(email, w, place(replies.length + index)));
const waitingNotice = waiting ? [caption(waiting, facts.waiting === true ? words("brief.card.waitingMany") : words(facts.waiting === 1 ? "brief.card.waitingOne" : "brief.card.waitingOther", { count: facts.waiting || 0 }))] : [];
const routineRows = facts.routines.map((row) => rowBeside(row.text, row.note, [...pageButton(row.page, w), ...openButton(row.open, w)], row.said));
const ideaRows = (facts.ideas ?? []).map((row) => rowBeside(row.text, row.note, [], row.said));
diff --git a/src/locales/en.json b/src/locales/en.json
index 83749429f1..540a140f5e 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -8519,6 +8519,7 @@
"brief.card.openPage": "Open page",
"brief.card.draftReply": "Draft a reply to {who}",
"brief.card.dismissEmail": "Dismiss {who}'s email",
+ "brief.card.numberedEmailAction": "{number}. {action}",
"brief.card.emailLine": "{sender}: {subject}",
"brief.card.waitingReply": "Waiting on your reply",
"brief.card.waitingReplyWhy": "Waiting on your reply · {why}",