Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(inbox): finished work the person has read leaves the inbox
subfocusxaa3fc1f0b25a
diff --git a/server/host/person-inbox.test.ts b/server/host/person-inbox.test.tsindex f6b0a80da4..6934b6e60c 100644--- a/server/host/person-inbox.test.ts+++ b/server/host/person-inbox.test.ts@@ -181,6 +181,28 @@ 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);+ f.team.route(report(), { routine: true });+ expect(f.team.inbox.view(key(BEN.email))!.rows[0]!.origin?.messageId).toBe(said.id);+ });+});+describe("what still waits on the person", () => {const question = (requestId: string) => ({ title: "Your bot has a question", subtitle: "Which landing page?", options: ["Home", "Pricing"], requestId, requestType: "question" as const });const asked = (f: ReturnType<typeof fixture>, threadId: string, requestId: string, made: ReturnType<typeof card | typeof question> = card(requestId)) => {diff --git a/server/host/person-inbox.ts b/server/host/person-inbox.tsindex 03d2b87ac8..770a360823 100644--- a/server/host/person-inbox.ts+++ b/server/host/person-inbox.ts@@ -215,6 +215,13 @@ export function createPersonInbox(deps: PersonInboxDeps) {const line = (item: Item) => store.messagesFor(item.threadId).find((message) => message.id === item.id);+ /** The message a line points at in the conversation it came from: the newest one there, so a client can put the person+ * at it when they open the line. */+ const focusOf = (threadId: string): { messageId?: string } => {+ const newest = store.messagesFor(threadId).at(-1)?.id;+ return newest ? { messageId: newest } : {};+ };+/** The card that asked, in the conversation it was asked in; undefined once that conversation is gone. An ask that* came from no conversation (someone asking for access to a bot) is its own card. */const asking = (item: Item) => !item.requestId ? undefined : item.origin@@ -243,10 +250,11 @@ 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. */+ /** 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. */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) ? "done" : "info";+ return item.done || settled(item) || (item.kind === "result" && item.seen === true) ? "done" : "info";}/** How many asks in this inbox wait on its person: questions, approvals and work handed on, open here and where they@@ -287,7 +295,10 @@ export function createPersonInbox(deps: PersonInboxDeps) {}const wire: InboxItem = {kind: delivery.kind, from: delivery.from, ...(delivery.via ? { via: delivery.via } : {}),- ...(origin && deps.sees(to, origin.threadId) ? { origin: { ...origin, title: titleOf(origin) } } : {}),+ ...(origin && deps.sees(to, origin.threadId)+ // The message it points at: the newest one in the conversation it came from, so a client can put the person there.+ ? { origin: { ...origin, title: titleOf(origin), ...(origin.messageId ? {} : focusOf(origin.threadId)) } }+ : {}),...(delivery.to ? { replies: true as const } : {}),...(delivery.assistant ? { assistant: true as const } : {}),};diff --git a/server/host/place-inbox.test.ts b/server/host/place-inbox.test.tsindex 2281792f13..5227401dbd 100644--- a/server/host/place-inbox.test.ts+++ b/server/host/place-inbox.test.ts@@ -112,6 +112,32 @@ describe("finished work reaches the inbox once", () => {const reopened = setup({}, f.dataDir);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);+ const row = f.inbox.view(OWNER).rows[0]!;+ expect(row.kind).toBe("message");+ f.inbox.markRead(OWNER, row.id);+ expect(f.inbox.view(OWNER).rows[0]!.tab, "it still waits for a reply").toBe("info");+ });++ it("points a line at the message it came from, so a client can open the conversation there", () => {+ const f = setup();+ const posted = f.store.appendMessage("eli-main", { role: "bot", text: "All three pages are live." });+ f.inbox.route(summary, { summary: true });+ expect(f.inbox.view(OWNER).rows[0]!.origin?.messageId).toBe(posted.id);+ });});describe("who is asking for the inbox", () => {diff --git a/server/host/place-inbox.ts b/server/host/place-inbox.tsindex a9eb904bf0..516b839660 100644--- a/server/host/place-inbox.ts+++ b/server/host/place-inbox.ts@@ -128,7 +128,9 @@ export function createPlaceInbox(deps: PlaceInboxDeps) {return false;}- const lineTab = (line: Line): InboxRow["tab"] => (line.done || answeredThere(line) ? "done" : "info");+ /** 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 lineFor = (auth: RequestAuth, line: Line): boolean => {const viewer = deps.viewer(auth);if (viewer.kind === "nobody" || !deps.sees(auth, line.threadId)) return false;@@ -184,11 +186,18 @@ export function createPlaceInbox(deps: PlaceInboxDeps) {return [...rows.values()];}- const lineRow = (line: Line): InboxRow => ({- id: line.id, kind: line.kind, tab: lineTab(line), from: { name: line.from, botId: line.botId }, ...(line.workingFor ? { workingFor: line.workingFor } : {}),- origin: { botId: line.botId, threadId: line.threadId, title: titleOf(line.botId, line.threadId), ...(line.groupId ? { groupId: line.groupId } : {}), messageId: line.id },- text: clip(line.text, ROW_TEXT_MAX), at: line.at, unread: !line.seen, ...(line.kind === "message" ? { replies: true as const } : {}),- });+ /** The message a line points at: its own message, or the newest one in the conversation it came from, so a client+ * can put the person at it. */+ const focusOf = (line: Line): string | undefined => line.kind === "message" ? line.id : store.messagesFor(line.threadId).at(-1)?.id;++ const lineRow = (line: Line): InboxRow => {+ const focus = focusOf(line);+ return {+ id: line.id, kind: line.kind, tab: lineTab(line), from: { name: line.from, botId: line.botId }, ...(line.workingFor ? { workingFor: line.workingFor } : {}),+ origin: { botId: line.botId, threadId: line.threadId, title: titleOf(line.botId, line.threadId), ...(line.groupId ? { groupId: line.groupId } : {}), ...(focus ? { messageId: focus } : {}) },+ text: clip(line.text, ROW_TEXT_MAX), at: line.at, unread: !line.seen, ...(line.kind === "message" ? { replies: true as const } : {}),+ };+ };function view(auth: RequestAuth): InboxView {const rows = [...askRows(auth), ...lines.filter((line) => lineFor(auth, line)).map(lineRow)].sort((a, b) => b.at - a.at).slice(0, VIEW_ROWS);