Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
#6416: take the click-through only; leave the read-work list change for the owner
milind-soni0984ae155bc5
diff --git a/server/host/person-inbox.test.ts b/server/host/person-inbox.test.tsindex 6934b6e60c..16a1b1ca36 100644--- a/server/host/person-inbox.test.ts+++ b/server/host/person-inbox.test.ts@@ -184,17 +184,6 @@ describe("asks routed to a person", () => {describe("finished work in a person's inbox", () => {const report = (): Notification => ({ kind: "done", botId: "scout", botName: "Scout", threadId: "ben-private", title: "Scout finished", body: "Daily digest: 3 new leads." });- it("takes a routine's report out of the inbox once the person has read it", () => {- const f = fixture();- f.team.route(report(), { routine: true });- const person = key(BEN.email);- const row = f.team.inbox.view(person)!.rows[0]!;- expect(row).toMatchObject({ kind: "result", tab: "info" });- f.team.inbox.markRead(person, row.id);- expect(f.team.inbox.view(person)!.rows[0]!.tab).toBe("done");- expect(f.team.inbox.view(person)!.rows.filter((one) => one.tab === "info"), "the inbox holds only what needs them").toEqual([]);- });-it("points the line at the message it came from, so a client can open the conversation there", () => {const f = fixture();const said = f.said("ben-private", "Can you look at the deck?", BEN);diff --git a/server/host/person-inbox.ts b/server/host/person-inbox.tsindex 770a360823..a23d0e064b 100644--- a/server/host/person-inbox.ts+++ b/server/host/person-inbox.ts@@ -250,11 +250,10 @@ export function createPersonInbox(deps: PersonInboxDeps) {const mark = (threadId: string) => { changedAt.set(threadId, Math.max(now(), (changedAt.get(threadId) ?? 0) + 1)); };const touch = (threadId: string) => { mark(threadId); deps.changed?.(threadId); };- /** The tab a line is listed in: an ask by its card where it was asked, anything else by its answer or the person's done.- * Finished work the person has read needs nothing more from them, so it leaves the inbox. */+ /** The tab a line is listed in: an ask by its card where it was asked, anything else by its answer or the person's done. */function tabOf(item: Item, copy?: Message): InboxTab {if (item.kind === "ask" && item.requestId) return askWaits(item, copy) ? "needs-you" : "done";- return item.done || settled(item) || (item.kind === "result" && item.seen === true) ? "done" : "info";+ return item.done || settled(item) ? "done" : "info";}/** How many asks in this inbox wait on its person: questions, approvals and work handed on, open here and where theydiff --git a/server/host/place-inbox.test.ts b/server/host/place-inbox.test.tsindex 5227401dbd..f94301242d 100644--- a/server/host/place-inbox.test.ts+++ b/server/host/place-inbox.test.ts@@ -113,16 +113,6 @@ describe("finished work reaches the inbox once", () => {expect(infoRows(reopened).map((row) => row.text).sort()).toEqual(["All three pages are live.", "It stopped in eli-pricing."]);});- it("takes finished work out of the inbox once the person has read it", () => {- const f = setup();- f.inbox.route(routine, { routine: true });- expect(infoRows(f)).toHaveLength(1);- f.inbox.markRead(OWNER, f.inbox.view(OWNER).rows[0]!.id);- expect(infoRows(f), "finished work the person has read leaves the inbox").toEqual([]);- expect(f.inbox.view(OWNER).rows[0]!.tab).toBe("done");- expect(f.inbox.count(OWNER), "nothing waits on the person any more").toBe(0);- });-it("keeps a message that waits for an answer listed after the person read it", () => {const f = setup();expect(f.inbox.message("eli", "eli-main", "Can you look at the deck?").status).toBe(200);diff --git a/server/host/place-inbox.ts b/server/host/place-inbox.tsindex 516b839660..9d2ae0b2a2 100644--- a/server/host/place-inbox.ts+++ b/server/host/place-inbox.ts@@ -128,9 +128,7 @@ export function createPlaceInbox(deps: PlaceInboxDeps) {return false;}- /** Finished work the person has read needs nothing more from them: it leaves the inbox. */- const readWork = (line: Line): boolean => line.kind === "result" && line.seen === true;- const lineTab = (line: Line): InboxRow["tab"] => (line.done || answeredThere(line) || readWork(line) ? "done" : "info");+ const lineTab = (line: Line): InboxRow["tab"] => (line.done || answeredThere(line) ? "done" : "info");const lineFor = (auth: RequestAuth, line: Line): boolean => {const viewer = deps.viewer(auth);if (viewer.kind === "nobody" || !deps.sees(auth, line.threadId)) return false;diff --git a/src/components/inbox/InboxPanel.dom.test.ts b/src/components/inbox/InboxPanel.dom.test.tsindex e2b2b5b236..ebb6ccada2 100644--- a/src/components/inbox/InboxPanel.dom.test.ts+++ b/src/components/inbox/InboxPanel.dom.test.ts@@ -3,16 +3,14 @@ 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; kind?: string; unread?: boolean }> } }));+const server = vi.hoisted(() => ({ calls: [] as Array<{ path: string; method: string; body?: unknown }>, view: null as null | { rows: Array<{ id: string; tab: string }> } }));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 && row.kind === "result"- ? { ...row, unread: false, tab: "done" }- : { ...row, unread: false })) };+ if (path === "/api/inbox/read-all" && server.view) server.view = { ...server.view, rows: server.view.rows.map((row) => ({ ...row, unread: false })) };return server.view;}),}));@@ -86,16 +84,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, reportRow.id]);+ expect(unreadIds()).toEqual([approvalRow.id, messageRow.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(), "the finished work leaves the list, the rest stays").toEqual([approvalRow.id, questionRow.id, messageRow.id]);+ expect(rowIds(), "every row is still listed").toEqual([approvalRow.id, questionRow.id, messageRow.id, reportRow.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(server.view!.rows.map((row) => [row.id, row.tab]));+ expect(currentInbox()!.rows.map((row) => [row.id, row.tab])).toEqual(inboxView().rows.map((row) => [row.id, row.tab]));expect(document.querySelector("[data-inbox-mark-all]"), "nothing is unread").toBeNull();});@@ -118,16 +116,6 @@ describe("the inbox panel", () => {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 6f48ee4a9b..a31c6e21c5 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 { Check, Inbox, Maximize2, Minimize2, Search, X } from "lucide-react";+import { 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, rowsIn, waitingCount } from "./inbox-view";+import { listedRows, waitingCount } from "./inbox-view";import { useInboxActions } from "./use-inbox-actions";import { roundButtonCls } from "../bot-panel/rows";@@ -25,7 +25,6 @@ export function InboxPanel() {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);@@ -45,7 +44,6 @@ export function InboxPanel() {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;@@ -65,7 +63,7 @@ export function InboxPanel() {const step = (by: -1 | 1) => {const row = rows[at + by];- if (row) open(row);+ if (row) { readInboxRow(row); readInboxLine(row.id); }};const count = waitingCount(view);const body = (@@ -116,17 +114,6 @@ 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/testing/inbox-fixture.ts b/src/testing/inbox-fixture.tsindex 456651ef8b..00fe56579b 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: true, at: INBOX_NOW - 3 * 60 * 60_000,+ id: "line-report", kind: "result", tab: "info", unread: false, 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 = {