Skip to content

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

Inbox: filter Active Threads and Finished by bot and status

AdityaUmale6228eda955fb
diff --git a/src/components/inbox/InboxActive.tsx b/src/components/inbox/InboxActive.tsx
index 39d8c6956a..02cb00ce36 100644
--- a/src/components/inbox/InboxActive.tsx
+++ b/src/components/inbox/InboxActive.tsx
@@ -15,6 +15,7 @@ import { setAttentionPinned, useAttentionPinned } from "./attention-pinned";
import { closeInbox } from "@/state/inbox";
import { inboxFixes } from "./inbox-view";
import { useInboxJump } from "./use-inbox-actions";
+import { matchesThreadFilter, type ThreadFilter } from "./thread-filter";
/** The conversations this list shows: the work in progress — at work, waiting on a teammate or on the person, or
* finished but still unread. A conversation the person has read leaves for the finished list below, so the two lists
@@ -65,15 +66,18 @@ export function unreadConversations(entries: readonly AttentionThread[], view?:
return entries.filter((entry) => entry.task.unread === true && !lined.has(entry.task.threadId)).length;
}
-export function InboxActive({ view, current, exclude }: {
+export function InboxActive({ view, current, exclude, filter = {} }: {
view: InboxView | null; current?: OpenThread;
/** Conversations the pinned section at the top already shows: these lists leave them out so none appears twice. */
exclude?: ReadonlySet<string>;
+ /** The bot and status the person picked above the lists. */
+ filter?: ThreadFilter;
}) {
const jump = useInboxJump();
const team = useTeamPeople();
const pinned = useAttentionPinned();
- const entries = useStoreSelector((state) => inboxAttentionEntries(state, view).filter((entry) => !exclude?.has(entry.task.threadId)), sameJson);
+ const entries = useStoreSelector((state) => inboxAttentionEntries(state, view)
+ .filter((entry) => !exclude?.has(entry.task.threadId) && matchesThreadFilter(entry, filter)), sameJson);
const fixes = inboxFixes(team?.needsYou, view);
return (
<>
diff --git a/src/components/inbox/InboxPanel.dom.test.ts b/src/components/inbox/InboxPanel.dom.test.ts
index bf2df1bc18..fa13d527e0 100644
--- a/src/components/inbox/InboxPanel.dom.test.ts
+++ b/src/components/inbox/InboxPanel.dom.test.ts
@@ -244,3 +244,61 @@ describe("keeping the list live", () => {
expect(reads()).toBe(2);
});
});
+
+describe("the inbox's bot and status filters", () => {
+ const minutes = (count: number) => INBOX_NOW - count * 60_000;
+ const ada = {
+ id: "ada", name: "Ada", threadId: "ada-main", tasks: [
+ { threadId: "ada-run", title: "Ada running", createdAt: 0, updatedAt: minutes(1), busy: true },
+ { threadId: "ada-ask", title: "Ada asking", createdAt: 0, updatedAt: minutes(2), activity: "waiting-on-you" },
+ { threadId: "ada-done", title: "Ada finished", createdAt: 0, updatedAt: minutes(500) },
+ ],
+ } as unknown as Bot;
+ const ben = {
+ id: "ben", name: "Ben", threadId: "ben-main",
+ tasks: Array.from({ length: 10 }, (_, index) => ({ threadId: `ben-${index}`, title: `Ben finished ${index}`, createdAt: 0, updatedAt: minutes(10 + index) })),
+ } as unknown as Bot;
+ const titles = (section: string) => [...document.querySelectorAll<HTMLElement>(`[${section}] button[title]:not([data-inbox-pin])`)].map((row) => row.querySelector("span span")?.textContent ?? row.textContent);
+ const choose = (selector: string, value: string) => act(async () => {
+ const select = document.querySelector<HTMLSelectElement>(selector)!;
+ select.value = value;
+ select.dispatchEvent(new Event("change", { bubbles: true }));
+ });
+
+ it("lists every bot that has a conversation, and keeps the lists whole until the person picks", async () => {
+ openInbox();
+ await mount(createElement(InboxPanel), [ada, ben]);
+ const owners = [...document.querySelectorAll<HTMLOptionElement>("[data-inbox-filter-owner] option")].map((option) => option.textContent);
+ expect(owners).toEqual(["All bots and rooms", "Ada", "Ben"]);
+ expect(titles("data-inbox-active")).toEqual(["Ada asking", "Ada running"]);
+ expect(titles("data-inbox-finished"), "the newest ten").toEqual(Array.from({ length: 10 }, (_, index) => `Ben finished ${index}`));
+ });
+
+ it("shows one bot's conversations, including a finished one older than the newest ten", async () => {
+ openInbox();
+ await mount(createElement(InboxPanel), [ada, ben]);
+ await choose("[data-inbox-filter-owner]", "bot:ada");
+ expect(titles("data-inbox-active")).toEqual(["Ada asking", "Ada running"]);
+ expect(titles("data-inbox-finished")).toEqual(["Ada finished"]);
+ await choose("[data-inbox-filter-status]", "waiting");
+ expect(titles("data-inbox-active")).toEqual(["Ada asking"]);
+ expect(document.querySelector("[data-inbox-finished]"), "finished conversations are not waiting").toBeNull();
+ await choose("[data-inbox-filter-status]", "finished");
+ expect(document.querySelector("[data-inbox-active] button[title]")).toBeNull();
+ expect(titles("data-inbox-finished")).toEqual(["Ada finished"]);
+ });
+
+ it("says when nothing matches, and clears both pickers from there", async () => {
+ openInbox();
+ await mount(createElement(InboxPanel), [ada, ben]);
+ await choose("[data-inbox-filter-owner]", "bot:ben");
+ await choose("[data-inbox-filter-status]", "working");
+ expect(document.querySelector("[data-inbox-filter-empty]")?.textContent).toContain("No conversations match these filters.");
+ expect(document.querySelector<HTMLSelectElement>("[data-inbox-filter-owner]")!.value, "the picker shows the choice in force").toBe("bot:ben");
+ await click("[data-inbox-filter-empty] button");
+ expect(document.querySelector("[data-inbox-filter-empty]")).toBeNull();
+ expect(document.querySelector<HTMLSelectElement>("[data-inbox-filter-owner]")!.value).toBe("");
+ expect(document.querySelector<HTMLSelectElement>("[data-inbox-filter-status]")!.value).toBe("");
+ expect(titles("data-inbox-active")).toEqual(["Ada asking", "Ada running"]);
+ });
+});
diff --git a/src/components/inbox/InboxPanel.tsx b/src/components/inbox/InboxPanel.tsx
index 749022140e..190e1a4c46 100644
--- a/src/components/inbox/InboxPanel.tsx
+++ b/src/components/inbox/InboxPanel.tsx
@@ -14,12 +14,14 @@ import { InboxActive, inboxAttentionEntries, inboxOpenThread, readNewsThreads, u
import { attentionUnpinAction } from "../SidebarBotActivity";
import { InboxReading } from "./InboxReading";
import { InboxRowItem } from "./InboxRow";
-import { FinishedThreads, finishedThreads } from "./FinishedThreads";
+import { FINISHED_LIMIT, FinishedThreads, finishedThreads } from "./FinishedThreads";
import { PinnedThreads, pinnedThreadRows } from "./PinnedThreads";
import { matchesSearch, nextAfter } from "./inbox-answer";
import { listedRows, rowsIn, waitingCount } from "./inbox-view";
import { useInboxActions, useInboxJump } from "./use-inbox-actions";
import { roundButtonCls } from "../bot-panel/rows";
+import { matchesThreadFilter, threadFilterOn, threadOwners, type ThreadFilter } from "./thread-filter";
+import { ThreadFilterBar } from "./ThreadFilterBar";
export const InboxPanel = memo(function InboxPanel() {
@@ -34,6 +36,7 @@ export const InboxPanel = memo(function InboxPanel() {
const [now, setNow] = useState(() => Date.now());
const [query, setQuery] = useState("");
const [showDone, setShowDone] = useState(false);
+ const [filter, setFilter] = useState<ThreadFilter>({});
useEffect(() => {
const timer = setInterval(() => setNow(Date.now()), 30_000);
return () => clearInterval(timer);
@@ -79,9 +82,18 @@ export const InboxPanel = memo(function InboxPanel() {
};
const pinnedRows = useStoreSelector((state) => pinnedThreadRows(state.bots, state.groups, state.pendingQueued), sameJson);
const pinnedThreads = useMemo(() => new Set(pinnedRows.map((row) => row.task.threadId)), [pinnedRows]);
- const finishedRows = useStoreSelector((state) => finishedThreads(state.bots, state.groups, state.pendingQueued, undefined, readNewsThreads(view), pinnedThreads), sameJson);
- const unread = useStoreSelector((state) => unreadConversations(inboxAttentionEntries(state, view), view));
- const count = waitingCount(view) + unread;
+ // The filter picks from every finished conversation before the list keeps its newest ten.
+ const threads = useStoreSelector((state) => {
+ const entries = inboxAttentionEntries(state, view);
+ const active = entries.filter((entry) => !pinnedThreads.has(entry.task.threadId));
+ const finished = finishedThreads(state.bots, state.groups, state.pendingQueued, Infinity, readNewsThreads(view), pinnedThreads);
+ const finishedRows = finished.filter((row) => matchesThreadFilter(row, filter)).slice(0, FINISHED_LIMIT);
+ return {
+ owners: threadOwners([...active, ...finished], filter.owner), finishedRows, unread: unreadConversations(entries, view),
+ any: finishedRows.length > 0 || active.some((entry) => matchesThreadFilter(entry, filter)),
+ };
+ }, sameJson);
+ const count = waitingCount(view) + threads.unread;
const openThread = useStoreSelector((state) => inboxOpenThread(state), sameJson);
const body = (
<>
@@ -133,9 +145,16 @@ export const InboxPanel = memo(function InboxPanel() {
)
: rows.map((row) => <InboxRowItem key={row.id} row={row} now={now} onOpen={open} onAction={run} />)}
</div>
- {!query.trim() && <InboxActive view={view} current={openThread} exclude={pinnedThreads} />}
+ {!query.trim() && threads.owners.length > 0 && <ThreadFilterBar owners={threads.owners} filter={filter} onChange={setFilter} />}
+ {!query.trim() && threadFilterOn(filter) && !threads.any && (
+ <div data-inbox-filter-empty className="flex flex-col items-center gap-1 px-4 py-6 text-center">
+ <p className="text-[13px] text-ink-secondary">{t("inbox.filter.noMatch")}</p>
+ <button type="button" onClick={() => setFilter({})} className="text-[12px] text-accent hover:underline">{t("inbox.filter.clear")}</button>
+ </div>
+ )}
+ {!query.trim() && <InboxActive view={view} current={openThread} exclude={pinnedThreads} filter={filter} />}
{/* The finished, already-read conversations. */}
- {!query.trim() && <FinishedThreads rows={finishedRows} now={now} current={openThread} onOpen={jump} />}
+ {!query.trim() && <FinishedThreads rows={threads.finishedRows} now={now} current={openThread} onOpen={jump} />}
{done.length > 0 && (
<section data-inbox-done className="px-1.5 pb-1.5">
<button type="button" data-inbox-done-toggle aria-expanded={showDone} onClick={() => setShowDone(!showDone)}
diff --git a/src/components/inbox/ThreadFilterBar.tsx b/src/components/inbox/ThreadFilterBar.tsx
new file mode 100644
index 0000000000..72bb5df95a
--- /dev/null
+++ b/src/components/inbox/ThreadFilterBar.tsx
@@ -0,0 +1,30 @@
+import { t } from "@/lib/i18n";
+import type { LocaleKey } from "@/locales";
+import { Select } from "../Select";
+import type { ThreadFilter, ThreadOwner, ThreadStatus } from "./thread-filter";
+
+const STATUSES: ReadonlyArray<{ status: ThreadStatus; label: LocaleKey }> = [
+ { status: "working", label: "inbox.filter.working" },
+ { status: "waiting", label: "inbox.filter.waiting" },
+ { status: "finished", label: "inbox.filter.finished" },
+];
+
+/** Two pickers above the Inbox's conversation lists: whose conversations, and in what state. */
+export function ThreadFilterBar({ owners, filter, onChange }: {
+ owners: readonly ThreadOwner[]; filter: ThreadFilter; onChange(filter: ThreadFilter): void;
+}) {
+ return (
+ <div data-inbox-thread-filter className="flex items-center gap-2 border-t border-hairline/40 px-[13px] py-2">
+ <Select variant="quiet" size="sm" className="min-w-0 flex-[3]" data-inbox-filter-owner aria-label={t("inbox.filter.owner")}
+ value={filter.owner?.key ?? ""} onChange={(event) => onChange({ ...filter, owner: owners.find((owner) => owner.key === event.target.value) })}>
+ <option value="">{t("inbox.filter.allOwners")}</option>
+ {owners.map((owner) => <option key={owner.key} value={owner.key}>{owner.name}</option>)}
+ </Select>
+ <Select variant="quiet" size="sm" className="min-w-0 flex-[2]" data-inbox-filter-status aria-label={t("inbox.filter.status")}
+ value={filter.status ?? ""} onChange={(event) => onChange({ ...filter, status: STATUSES.find((one) => one.status === event.target.value)?.status })}>
+ <option value="">{t("inbox.filter.allStatus")}</option>
+ {STATUSES.map((one) => <option key={one.status} value={one.status}>{t(one.label)}</option>)}
+ </Select>
+ </div>
+ );
+}
diff --git a/src/components/inbox/thread-filter.test.ts b/src/components/inbox/thread-filter.test.ts
new file mode 100644
index 0000000000..d1ad52f32a
--- /dev/null
+++ b/src/components/inbox/thread-filter.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import type { AttentionThread } from "../SidebarBotActivity";
+import { matchesThreadFilter, threadFilterOn, threadOwners, threadStatus } from "./thread-filter";
+
+const row = (botId: string, task: Partial<AttentionThread["task"]> = {}): AttentionThread =>
+ ({ kind: "bot", botId, botName: botId.toUpperCase(), task: { threadId: `${botId}-t`, title: "t", queued: false, ...task } } as AttentionThread);
+const room = (groupId: string): AttentionThread =>
+ ({ kind: "group", groupId, groupName: `Room ${groupId}`, groupThreadId: "main", task: { threadId: "main", title: "t", queued: false } } as AttentionThread);
+
+describe("the inbox's thread filters", () => {
+ it("sorts a conversation the way its own status line does: waiting before working", () => {
+ expect(threadStatus(row("a", { activity: "waiting-on-you", busy: true }).task)).toBe("waiting");
+ expect(threadStatus(row("a", { waitingForTeammates: true, busy: true }).task)).toBe("waiting");
+ expect(threadStatus(row("a", { busy: true }).task)).toBe("working");
+ expect(threadStatus(row("a", { queued: true }).task)).toBe("working");
+ expect(threadStatus(row("a", { unread: true }).task)).toBe("finished");
+ });
+
+ it("matches on bot or room and on status together, and matches everything with nothing picked", () => {
+ const busy = row("a", { busy: true });
+ expect(threadFilterOn({})).toBe(false);
+ expect(matchesThreadFilter(busy, {})).toBe(true);
+ expect(matchesThreadFilter(busy, { owner: { key: "bot:a", name: "A" }, status: "working" })).toBe(true);
+ expect(matchesThreadFilter(busy, { owner: { key: "bot:b", name: "B" } })).toBe(false);
+ expect(matchesThreadFilter(busy, { status: "finished" })).toBe(false);
+ expect(matchesThreadFilter(room("r"), { owner: { key: "group:r", name: "Room r" } })).toBe(true);
+ });
+
+ it("lists each owner once by name, and keeps the picked one when it has nothing left", () => {
+ expect(threadOwners([row("b"), row("a"), row("b"), room("r")])).toEqual([
+ { key: "bot:a", name: "A" }, { key: "bot:b", name: "B" }, { key: "group:r", name: "Room r" },
+ ]);
+ expect(threadOwners([row("a")], { key: "bot:z", name: "Zed" }).map((owner) => owner.name)).toEqual(["A", "Zed"]);
+ });
+});
diff --git a/src/components/inbox/thread-filter.ts b/src/components/inbox/thread-filter.ts
new file mode 100644
index 0000000000..c9fa4770f6
--- /dev/null
+++ b/src/components/inbox/thread-filter.ts
@@ -0,0 +1,40 @@
+// The Inbox's bot and status filters for its conversation lists (Active Threads and Finished). Nothing is stored: the
+// choice lasts while the panel is open.
+import { attentionOwnerName, type AttentionThread } from "../SidebarBotActivity";
+
+export type ThreadStatus = "working" | "waiting" | "finished";
+
+export type ThreadOwner = { key: string; name: string };
+
+/** No owner keeps every bot and room; no status keeps every status. */
+export type ThreadFilter = { owner?: ThreadOwner; status?: ThreadStatus };
+
+export function threadFilterOn(filter: ThreadFilter): boolean {
+ return Boolean(filter.owner || filter.status);
+}
+
+export function threadOwnerKey(row: AttentionThread): string {
+ return row.kind === "bot" ? `bot:${row.botId}` : `group:${row.groupId}`;
+}
+
+/** The same order the row's own status line uses (attentionRowStatus): waiting on the person or a teammate first, then
+ * working or queued; anything else is finished, read or not. */
+export function threadStatus(task: AttentionThread["task"]): ThreadStatus {
+ if (task.activity === "waiting-on-you" || task.waitingForTeammates === true) return "waiting";
+ if (task.busy === true || task.activity === "working" || task.queued === true) return "working";
+ return "finished";
+}
+
+export function matchesThreadFilter(row: AttentionThread, filter: ThreadFilter): boolean {
+ return (!filter.owner || threadOwnerKey(row) === filter.owner.key)
+ && (!filter.status || threadStatus(row.task) === filter.status);
+}
+
+/** The bots and rooms that own any of these conversations, by name, plus the chosen one when none of its conversations
+ * is left, so the picker always shows the choice in force. */
+export function threadOwners(rows: readonly AttentionThread[], chosen?: ThreadOwner): ThreadOwner[] {
+ const owners = new Map<string, string>();
+ for (const row of rows) owners.set(threadOwnerKey(row), attentionOwnerName(row));
+ if (chosen && !owners.has(chosen.key)) owners.set(chosen.key, chosen.name);
+ return [...owners].map(([key, name]) => ({ key, name })).sort((a, b) => a.name.localeCompare(b.name));
+}
diff --git a/src/locales/de.json b/src/locales/de.json
index f1e269695b..338c785121 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -4259,6 +4259,15 @@
"geminiServer.key": "Gemini-API-Schlüssel",
"geminiServer.add": "Google AI Studio hinzufügen",
"inbox.settled.title": "Erledigt",
+ "inbox.filter.owner": "Bot oder Raum",
+ "inbox.filter.allOwners": "Alle Bots und Räume",
+ "inbox.filter.status": "Status",
+ "inbox.filter.allStatus": "Jeder Status",
+ "inbox.filter.working": "In Arbeit",
+ "inbox.filter.waiting": "Wartet",
+ "inbox.filter.finished": "Erledigt",
+ "inbox.filter.noMatch": "Keine Unterhaltungen passen zu diesen Filtern.",
+ "inbox.filter.clear": "Filter zurücksetzen",
"inbox.settled.read": "Gelesen",
"settings.logins.source.bitwardenSecrets": "Aus Bitwarden Secrets Manager",
"settings.vault.bitwardenSecrets.title": "Bitwarden Secrets Manager",
diff --git a/src/locales/en.json b/src/locales/en.json
index c86657d93e..682cf24a1c 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -11662,6 +11662,15 @@
"alwaysOn.windowClosedLinux": "Keeps running when its window is closed. Open {app} again to bring the window back; to quit, press Alt and choose File → Quit.",
"alwaysOn.status.noWay": "Home is on · no phone or computer can reach it yet",
"inbox.settled.title": "Finished",
+ "inbox.filter.owner": "Bot or room",
+ "inbox.filter.allOwners": "All bots and rooms",
+ "inbox.filter.status": "Status",
+ "inbox.filter.allStatus": "Any status",
+ "inbox.filter.working": "Working",
+ "inbox.filter.waiting": "Waiting",
+ "inbox.filter.finished": "Finished",
+ "inbox.filter.noMatch": "No conversations match these filters.",
+ "inbox.filter.clear": "Clear filters",
"chat.unreadContext.title": "Previous message",
"chat.unreadContext.images": "Image",
"chat.unreadContext.files": "File",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 0840202a50..6827e64c7a 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -8217,6 +8217,15 @@
"inbox.action.closeQuestion": "Fechar sem responder",
"inbox.markAllRead": "Marcar tudo como lido",
"inbox.settled.title": "Concluído",
+ "inbox.filter.owner": "Bot ou sala",
+ "inbox.filter.allOwners": "Todos os bots e salas",
+ "inbox.filter.status": "Status",
+ "inbox.filter.allStatus": "Qualquer status",
+ "inbox.filter.working": "Trabalhando",
+ "inbox.filter.waiting": "Aguardando",
+ "inbox.filter.finished": "Concluído",
+ "inbox.filter.noMatch": "Nenhuma conversa corresponde a estes filtros.",
+ "inbox.filter.clear": "Limpar filtros",
"inbox.settled.read": "Lido",
"chat.unreadContext.title": "Mensagem anterior",
"chat.unreadContext.images": "Imagem",