Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(inbox): clicking a notice opens the conversation it came from
subfocusxe0be142288e8
diff --git a/src/components/inbox/InboxPanel.dom.test.ts b/src/components/inbox/InboxPanel.dom.test.tsindex 88a2d4eb87..e2b2b5b236 100644--- a/src/components/inbox/InboxPanel.dom.test.ts+++ b/src/components/inbox/InboxPanel.dom.test.ts@@ -3,14 +3,16 @@ import { act, createElement, type ReactElement } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-const server = vi.hoisted(() => ({ calls: [] as Array<{ path: string; method: string; body?: unknown }>, view: null as null | { rows: Array<{ id: string; tab: string }> } }));+const server = vi.hoisted(() => ({ calls: [] as Array<{ path: string; method: string; body?: unknown }>, view: null as null | { rows: Array<{ id: string; tab: string; kind?: string; unread?: boolean }> } }));vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => true }));vi.mock("../../state/api", () => ({api: vi.fn(async (path: string, init?: RequestInit) => {server.calls.push({ path, method: init?.method ?? "GET", ...(init?.body ? { body: JSON.parse(String(init.body)) } : {}) });const done = /^\/api\/inbox\/([\w-]+)\/done$/.exec(path);if (done && server.view) server.view = { ...server.view, rows: server.view.rows.map((row) => (row.id === done[1] ? { ...row, tab: "done", unread: false } : row)) };- if (path === "/api/inbox/read-all" && server.view) server.view = { ...server.view, rows: server.view.rows.map((row) => ({ ...row, unread: false })) };+ if (path === "/api/inbox/read-all" && server.view) server.view = { ...server.view, rows: server.view.rows.map((row) => (row.unread && row.kind === "result"+ ? { ...row, unread: false, tab: "done" }+ : { ...row, unread: false })) };return server.view;}),}));@@ -19,7 +21,7 @@ import { initialState, StoreContext, type AppState, type Bot } from "@/state/stoimport { BOT_BUTTON, botButtonTone } from "@/lib/bot-button";import { closeInbox, currentInbox, currentInboxPanel, inboxVersion, openInbox, setInboxView, useInboxLoader } from "@/state/inbox";import { approvalRow, inboxView, messageRow, questionRow, reportRow, settledRow } from "@/testing/inbox-fixture";-import type { InboxView } from "../../../shared/inbox";+import type { InboxRow, InboxView } from "../../../shared/inbox";import { InboxCardSlot } from "./InboxCard";import { InboxPanel } from "./InboxPanel";@@ -84,16 +86,16 @@ describe("the inbox panel", () => {await mount(createElement(InboxPanel));const rowIds = () => [...document.querySelectorAll<HTMLElement>("[data-inbox-row]")].map((row) => row.dataset.inboxRow);const unreadIds = () => [...document.querySelectorAll<HTMLElement>("[data-inbox-row][data-unread]")].map((row) => row.dataset.inboxRow);- expect(unreadIds()).toEqual([approvalRow.id, messageRow.id]);+ expect(unreadIds()).toEqual([approvalRow.id, messageRow.id, reportRow.id]);expect(document.querySelector("[data-inbox-mark-all]")!.textContent).toBe("Mark all as read");await click("[data-inbox-mark-all]");expect(server.calls).toContainEqual({ path: "/api/inbox/read-all", method: "POST" });expect(unreadIds()).toEqual([]);- expect(rowIds(), "every row is still listed").toEqual([approvalRow.id, questionRow.id, messageRow.id, reportRow.id]);+ expect(rowIds(), "the finished work leaves the list, the rest stays").toEqual([approvalRow.id, questionRow.id, messageRow.id]);expect(document.querySelector(`[data-inbox-row="${approvalRow.id}"] [data-inbox-action="allow"]`), "the ask still waits on its answer").not.toBeNull();expect(dispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: "decideRequest" }));expect(server.calls.filter((call) => /\/(done)$/.test(call.path))).toEqual([]);- expect(currentInbox()!.rows.map((row) => [row.id, row.tab])).toEqual(inboxView().rows.map((row) => [row.id, row.tab]));+ expect(currentInbox()!.rows.map((row) => [row.id, row.tab])).toEqual(server.view!.rows.map((row) => [row.id, row.tab]));expect(document.querySelector("[data-inbox-mark-all]"), "nothing is unread").toBeNull();});@@ -105,6 +107,27 @@ describe("the inbox panel", () => {expect(document.querySelector("[data-inbox-mark-all]")).toBeNull();});+ it("opens the conversation a finished notice came from when the person clicks it", async () => {+ const notice: InboxRow = { ...reportRow, id: "line-notice", origin: { botId: "reporter", threadId: "rep-daily", title: "Daily digest", messageId: "m-report" } };+ shown(inboxView([notice]));+ openInbox();+ await mount(createElement(InboxPanel), [{ id: "reporter", name: "Reporter", color: "orange" } as Bot]);+ await click(`[data-inbox-row="${notice.id}"] button`);+ expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({ type: "revealThread", threadId: "rep-daily" }));+ expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({ type: "focusMessage", threadId: "rep-daily", messageId: "m-report" }));+ expect(document.querySelector(`[data-inbox-reading="${notice.id}"]`), "it is not read in the panel").toBeNull();+ });++ it("keeps what it took out of the list where the person can find it again", async () => {+ shown(inboxView([approvalRow, { ...reportRow, tab: "done" }]));+ openInbox();+ await mount(createElement(InboxPanel));+ const listed = () => [...document.querySelectorAll<HTMLElement>("[data-inbox-row]")].map((row) => row.dataset.inboxRow);+ expect(listed(), "a settled line is not listed again").toEqual([approvalRow.id]);+ await click("[data-inbox-done-toggle]");+ expect(listed()).toEqual([approvalRow.id, reportRow.id]);+ });+it("is a sheet at phone width", async () => {vi.stubGlobal("matchMedia", (query: string) => ({ matches: query.includes("max-width"), addEventListener() {}, removeEventListener() {} }));openInbox();diff --git a/src/components/inbox/InboxPanel.tsx b/src/components/inbox/InboxPanel.tsxindex 76f042dd95..6f48ee4a9b 100644--- a/src/components/inbox/InboxPanel.tsx+++ b/src/components/inbox/InboxPanel.tsx@@ -1,6 +1,6 @@import { useEffect, useRef, useState, type KeyboardEvent } from "react";import { createPortal } from "react-dom";-import { Inbox, Maximize2, Minimize2, Search, X } from "lucide-react";+import { Check, Inbox, Maximize2, Minimize2, Search, X } from "lucide-react";import type { InboxRow } from "../../../shared/inbox";import { cn } from "@/lib/cn";import { useAdvancedMode } from "@/lib/interface-mode";@@ -11,7 +11,7 @@ import { InboxActive } from "./InboxActive";import { InboxReading } from "./InboxReading";import { InboxRowItem } from "./InboxRow";import { matchesSearch, nextAfter } from "./inbox-answer";-import { listedRows, waitingCount } from "./inbox-view";+import { listedRows, rowsIn, waitingCount } from "./inbox-view";import { useInboxActions } from "./use-inbox-actions";import { roundButtonCls } from "../bot-panel/rows";@@ -22,9 +22,10 @@ export function InboxPanel() {const markingAll = useInboxMarkingAll();const phone = useMediaQuery(PHONE_LAYOUT);const simple = !useAdvancedMode();- const { run } = useInboxActions(view);+ const { run, openInChat } = useInboxActions(view);const [now, setNow] = useState(() => Date.now());const [query, setQuery] = useState("");+ const [showDone, setShowDone] = useState(false);useEffect(() => {const timer = setInterval(() => setNow(Date.now()), 30_000);return () => clearInterval(timer);@@ -36,8 +37,15 @@ export function InboxPanel() {else closeInbox();};const reading = panel.reading ? view?.rows.find((row) => row.id === panel.reading) : undefined;- const open = (row: InboxRow) => { readInboxRow(row); readInboxLine(row.id); };+ /** An ask waits for an answer here and a message waits for a reply, so those open in the panel; finished work opens+ * the conversation it came from, at the message it is about. */+ const open = (row: InboxRow) => {+ readInboxRow(row);+ if (row.tab === "needs-you" || row.replies) { readInboxLine(row.id); return; }+ openInChat(row);+ };const rows = listedRows(view).filter((row) => matchesSearch(row, query));+ const done = rowsIn(view, "done").filter((row) => matchesSearch(row, query)).sort((a, b) => b.at - a.at);const ids = rows.map((row) => row.id);const at = reading ? ids.indexOf(reading.id) : -1;@@ -108,6 +116,17 @@ export function InboxPanel() {): rows.map((row) => <InboxRowItem key={row.id} row={row} now={now} onOpen={open} onAction={run} />)}</div>+ {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)}+ className="flex w-full items-center gap-1.5 rounded-lg px-2 py-1.5 text-[12px] text-ink-tertiary hover:bg-raised/70 hover:text-ink-secondary">+ <Check size={13} aria-hidden="true" className="shrink-0" />+ <span className="font-medium">{t("common.done")}</span>+ <span className="tabular-nums">{done.length}</span>+ </button>+ {showDone && done.map((row) => <InboxRowItem key={row.id} row={row} now={now} onOpen={open} onAction={run} />)}+ </section>+ )}{!query.trim() && <InboxActive view={view} />}</div></>diff --git a/src/components/inbox/use-inbox-actions.ts b/src/components/inbox/use-inbox-actions.tsindex 3f7683a415..31b927b400 100644--- a/src/components/inbox/use-inbox-actions.ts+++ b/src/components/inbox/use-inbox-actions.ts@@ -1,8 +1,9 @@import { useCallback } from "react";import type { InboxRow, InboxView } from "../../../shared/inbox";import { useShowThreads } from "@/lib/thread-preferences";+import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";import { openThread, useStore } from "@/state/store";-import { doneInboxRow, openInbox, readInboxRow, refreshInbox } from "@/state/inbox";+import { closeInbox, doneInboxRow, openInbox, readInboxRow, refreshInbox } from "@/state/inbox";import type { CardResponse } from "@/lib/card-answer";import { answerThread, closeResponse, type QuickAction } from "./inbox-view";@@ -11,6 +12,7 @@ import { answerThread, closeResponse, type QuickAction } from "./inbox-view";export function useInboxActions(view: InboxView | null) {const { state, dispatch } = useStore();const showThreads = useShowThreads();+ const phone = useMediaQuery(PHONE_LAYOUT);const answer = useCallback((row: InboxRow, response: CardResponse, failed?: () => void) => {const threadId = answerThread(view, row);@@ -27,7 +29,9 @@ export function useInboxActions(view: InboxView | null) {if (!target) return;openThread(dispatch, { botId: target.botId, threadId: target.threadId }, state, showThreads);if (target.messageId) dispatch({ type: "focusMessage", threadId: target.threadId, messageId: target.messageId });- }, [view, state, dispatch, showThreads]);+ // The conversation is in the main window; on a phone the inbox is a sheet over it.+ if (phone) closeInbox();+ }, [view, state, dispatch, showThreads, phone]);const run = useCallback((row: InboxRow, action: QuickAction) => {if (action === "allow" || action === "deny") answer(row, { behavior: action });diff --git a/src/testing/inbox-fixture.ts b/src/testing/inbox-fixture.tsindex 00fe56579b..456651ef8b 100644--- a/src/testing/inbox-fixture.ts+++ b/src/testing/inbox-fixture.ts@@ -18,7 +18,7 @@ export const messageRow: InboxRow = {from: { name: "Cleo", email: "[email protected]" }, via: { botId: "scout", name: "Scout" }, text: "The launch moved to Friday. Can you check the numbers before then?",};export const reportRow: InboxRow = {- id: "line-report", kind: "result", tab: "info", unread: false, at: INBOX_NOW - 3 * 60 * 60_000,+ id: "line-report", kind: "result", tab: "info", unread: true, at: INBOX_NOW - 3 * 60 * 60_000,from: { name: "Reporter", botId: "reporter" }, origin: { botId: "reporter", threadId: "rep-daily", title: "Daily digest" }, text: "Daily digest: 3 new leads, 1 reply waiting.",};export const settledRow: InboxRow = {