Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Inbox: show each bot's picture on the Pinned, Active and Finished rows
AdityaUmaled2f932264f67
diff --git a/src/components/SidebarBotActivity.tsx b/src/components/SidebarBotActivity.tsxindex e61955bfa4..2df1a1eb63 100644--- a/src/components/SidebarBotActivity.tsx+++ b/src/components/SidebarBotActivity.tsx@@ -1,4 +1,4 @@-import { BellDot, CircleAlert, Clock3, Loader2, Pin, type LucideIcon } from "lucide-react";+import { BellDot, CircleAlert, Clock3, Loader2, Pin, Users, type LucideIcon } from "lucide-react";import type { Dispatch } from "react";import type { Action, AppState, Bot, Group, Task } from "@/state/store";import { cn } from "@/lib/cn";@@ -11,6 +11,7 @@ import { localizedTaskTitle } from "@/lib/task-title";import { endedOnFailure } from "@/lib/mascot";import { MainThreadMark, rowSelectedSurface } from "./SidebarRowMarkers";import { handoffStatusText } from "./HandoffStatusChip";+import { BotAvatar, type BotAvatarProps } from "./Avatar";export function sidebarBotActivityTasks(bot: Bot, queued: Record<string, unknown[]>, archivedApprovals = false): Array<Task & { queued: boolean }> {const tasks = bot.tasks ?? [{@@ -197,8 +198,35 @@ export function crossBotPinnedThreads(bots: Bot[], groups: Group[], queued: Reco: { kind: "bot", botId: botId!, botName: botName!, task });}-export function AttentionThreadRows({ entries, onJump, inset = false, unreadDot = false, current }: {+/** What a bot's picture is drawn from, and nothing else, so a list of faces re-renders when a picture changes, not on+ * every message. */+export type BotFace = BotAvatarProps["bot"] & { id: string };++export function botFaces(bots: readonly Bot[]): BotFace[] {+ return bots.map(({ id, name, color, avatarUrl, avatarCrop, avatarZoom, avatarFocusX, avatarFocusY, mascotBody, mascotFaceColor, mascotBodyColor, mascotMaterial }) =>+ ({ id, name, color, avatarUrl, avatarCrop, avatarZoom, avatarFocusX, avatarFocusY, mascotBody, mascotFaceColor, mascotBodyColor, mascotMaterial }));+}++/** Whose conversation a row is, at a glance: the bot's own picture, or the room mark for a room, with the row's status+ * icon on its corner. */+export function AttentionFace({ entry, faces, Icon, iconClass }: { entry: AttentionThread; faces: readonly BotFace[]; Icon: LucideIcon; iconClass?: string }) {+ const bot = entry.kind === "bot" ? faces.find((face) => face.id === entry.botId) : undefined;+ return (+ <span data-attention-face={entry.kind} className="relative flex size-5 shrink-0">+ {entry.kind === "bot"+ ? <BotAvatar bot={bot ?? { name: entry.botName, color: "blue" }} state="happy" size={20} motion="none" motionKey={0} animated={false} />+ : <span className="flex size-5 items-center justify-center rounded-full bg-raised"><Users size={12} aria-hidden="true" className="text-ink-secondary" /></span>}+ <span className="absolute -bottom-1 -right-1 flex size-3.5 items-center justify-center rounded-full bg-panel">+ <Icon size={10} aria-hidden="true" className={cn("shrink-0", iconClass)} />+ </span>+ </span>+ );+}++export function AttentionThreadRows({ entries, onJump, inset = false, unreadDot = false, current, faces }: {entries: AttentionThread[]; onJump: (entry: AttentionThread) => void; inset?: boolean;+ /** Lead each row with its bot's picture; without them the status icon leads the row. */+ faces?: readonly BotFace[];/** Mark an unread conversation with a dot and a heavier title, the way the Inbox's own rows are marked. */unreadDot?: boolean;/** The conversation the chat window has open, marked like a selected sidebar row. */@@ -215,7 +243,9 @@ export function AttentionThreadRows({ entries, onJump, inset = false, unreadDotaria-current={open ? "page" : undefined} data-open-thread={open || undefined}onClick={() => onJump(entry)}className={cn("flex w-full items-center gap-2.5 text-left text-[13px] text-ink hover:bg-menu-hover", inset ? "rounded-md px-2 py-1.5" : "px-3.5 py-2", open && openThreadRow)}>- <Icon size={inset ? 16 : 15} aria-hidden="true" className={cn("shrink-0", colorClass)} />+ {faces+ ? <AttentionFace entry={entry} faces={faces} Icon={Icon} iconClass={colorClass} />+ : <Icon size={inset ? 16 : 15} aria-hidden="true" className={cn("shrink-0", colorClass)} />}<span className="min-w-0 flex-1"><span className={cn("block truncate", unread && "font-medium text-ink")}>{entry.task.title}</span><span className="block truncate text-[12px] leading-4 text-ink-secondary">{name} · {status}</span>diff --git a/src/components/inbox/FinishedThreads.tsx b/src/components/inbox/FinishedThreads.tsxindex 8a496cb86e..085a80a676 100644--- a/src/components/inbox/FinishedThreads.tsx+++ b/src/components/inbox/FinishedThreads.tsx@@ -6,7 +6,7 @@ import type { Bot, Group, Task } from "@/state/store";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";import { roomThreadSpeakerId, roomThreadWorking } from "@/lib/room-threads";-import { attentionOwnerName, isOpenThread, openThreadRow, type AttentionThread, type OpenThread } from "../SidebarBotActivity";+import { AttentionFace, attentionOwnerName, isOpenThread, openThreadRow, type AttentionThread, type BotFace, type OpenThread } from "../SidebarBotActivity";import { formatUpdatedAt, threadRecency, threadUpdatedLabel } from "../SidebarThreadRow";export const FINISHED_LIMIT = 10;@@ -54,9 +54,11 @@ export function finishedThreads(bots: readonly Bot[], groups: readonly Group[] =return found.sort((a, b) => b.at - a.at).slice(0, limit).map(({ at: _at, ...row }) => row);}-export function FinishedThreads({ rows, now, current, onOpen }: {+export function FinishedThreads({ rows, faces, now, current, onOpen }: {/** From finishedThreads: the read conversations, without the ones the pinned section at the top already shows. */rows: readonly FinishedThread[];+ /** The bots' pictures, from botFaces: each row leads with its own. */+ faces: readonly BotFace[];/** The clock the row's last-activity label is relative to. */now: number;/** The conversation the chat window has open, marked like a selected sidebar row. */@@ -78,7 +80,7 @@ export function FinishedThreads({ rows, now, current, onOpen }: {<button key={`${row.kind}-${row.kind === "bot" ? row.botId : row.groupId}-${row.task.threadId}`} type="button" aria-label={label} title={label}aria-current={open ? "page" : undefined} data-open-thread={open || undefined} onClick={() => onOpen(row)}className={cn("flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[13px] text-ink hover:bg-menu-hover", open && openThreadRow)}>- <CheckCircle2 size={16} aria-hidden="true" className="shrink-0 text-ink-tertiary" />+ <AttentionFace entry={row} faces={faces} Icon={CheckCircle2} iconClass="text-ink-tertiary" /><span className="min-w-0 flex-1"><span className="block truncate">{row.task.title}</span><span className="block truncate text-[11px] text-ink-secondary">diff --git a/src/components/inbox/InboxActive.tsx b/src/components/inbox/InboxActive.tsxindex 39d8c6956a..77322e0357 100644--- a/src/components/inbox/InboxActive.tsx+++ b/src/components/inbox/InboxActive.tsx@@ -9,7 +9,7 @@ import { type AppState } from "@/state/store";import { sameJson } from "@/state/same-json";import { useStoreSelector } from "@/state/store-select";import { useTeamPeople } from "@/state/team-people";-import { AttentionThreadRows, crossBotAttentionThreads, type AttentionThread, type OpenThread } from "../SidebarBotActivity";+import { AttentionThreadRows, crossBotAttentionThreads, type AttentionThread, type BotFace, type OpenThread } from "../SidebarBotActivity";import { NeedsYouLine } from "../TeamOwner";import { setAttentionPinned, useAttentionPinned } from "./attention-pinned";import { closeInbox } from "@/state/inbox";@@ -65,8 +65,10 @@ 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, faces }: {view: InboxView | null; current?: OpenThread;+ /** The bots' pictures, from botFaces: each row leads with its own. */+ faces: readonly BotFace[];/** Conversations the pinned section at the top already shows: these lists leave them out so none appears twice. */exclude?: ReadonlySet<string>;}) {@@ -91,7 +93,7 @@ export function InboxActive({ view, current, exclude }: {{pinned ? <PinOff size={14} aria-hidden="true" /> : <Pin size={14} aria-hidden="true" />}</button></div>- <AttentionThreadRows inset entries={entries} unreadDot current={current} onJump={jump} />+ <AttentionThreadRows inset entries={entries} faces={faces} unreadDot current={current} onJump={jump} /></section>)}</>diff --git a/src/components/inbox/InboxPanel.tsx b/src/components/inbox/InboxPanel.tsxindex 749022140e..e99371e288 100644--- a/src/components/inbox/InboxPanel.tsx+++ b/src/components/inbox/InboxPanel.tsx@@ -11,7 +11,7 @@ import { sameJson } from "@/state/same-json";import { useStoreDispatch, useStoreSelector } from "@/state/store-select";import { useActiveLocale } from "@/lib/use-active-locale";import { InboxActive, inboxAttentionEntries, inboxOpenThread, readNewsThreads, unreadConversations } from "./InboxActive";-import { attentionUnpinAction } from "../SidebarBotActivity";+import { attentionUnpinAction, botFaces } from "../SidebarBotActivity";import { InboxReading } from "./InboxReading";import { InboxRowItem } from "./InboxRow";import { FinishedThreads, finishedThreads } from "./FinishedThreads";@@ -77,6 +77,7 @@ export const InboxPanel = memo(function InboxPanel() {const row = rows[at + by];if (row) open(row);};+ const faces = useStoreSelector((state) => botFaces(state.bots), sameJson);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);@@ -114,7 +115,7 @@ export const InboxPanel = memo(function InboxPanel() {<><div className="min-h-0 flex-1 overflow-y-auto">{/* The conversations each bot and room pinned, at the top of the list. */}- {!query.trim() && <PinnedThreads rows={pinnedRows} now={now} current={openThread} onOpen={jump} onUnpin={(row) => dispatch(attentionUnpinAction(row))} />}+ {!query.trim() && <PinnedThreads rows={pinnedRows} faces={faces} now={now} current={openThread} onOpen={jump} onUnpin={(row) => dispatch(attentionUnpinAction(row))} />}{listed.length > 0 && <label className="mx-[13px] my-2.5 flex h-8 items-center gap-2 rounded-lg bg-ink/[0.045] px-2.5 ring-[0.5px] ring-ink/[0.12] focus-within:ring-ink/30"><Search size={14} aria-hidden="true" className="shrink-0 text-ink-tertiary" /><input type="search" value={query} onChange={(event) => setQuery(event.target.value)} placeholder={t("inbox.search")} aria-label={t("inbox.search")}@@ -133,9 +134,9 @@ 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() && <InboxActive view={view} current={openThread} exclude={pinnedThreads} faces={faces} />}{/* The finished, already-read conversations. */}- {!query.trim() && <FinishedThreads rows={finishedRows} now={now} current={openThread} onOpen={jump} />}+ {!query.trim() && <FinishedThreads rows={finishedRows} faces={faces} 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/PinnedThreads.tsx b/src/components/inbox/PinnedThreads.tsxindex a9e6a4db99..0f01ae2184 100644--- a/src/components/inbox/PinnedThreads.tsx+++ b/src/components/inbox/PinnedThreads.tsx@@ -6,8 +6,8 @@ import type { Bot, Group } from "@/state/store";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";import {- attentionOwnerName, attentionRowStatus, crossBotPinnedThreads, isOpenThread, openThreadRow,- type AttentionThread, type OpenThread,+ AttentionFace, attentionOwnerName, attentionRowStatus, crossBotPinnedThreads, isOpenThread, openThreadRow,+ type AttentionThread, type BotFace, type OpenThread,} from "../SidebarBotActivity";import { formatUpdatedAt, threadRecency, threadUpdatedLabel } from "../SidebarThreadRow";@@ -18,8 +18,10 @@ export function pinnedThreadRows(bots: readonly Bot[], groups: readonly Group[],.sort((a, b) => threadRecency(b.task) - threadRecency(a.task));}-export function PinnedThreads({ rows, now, current, onOpen, onUnpin }: {+export function PinnedThreads({ rows, faces, now, current, onOpen, onUnpin }: {rows: readonly AttentionThread[];+ /** The bots' pictures, from botFaces: each row leads with its own. */+ faces: readonly BotFace[];/** The clock each row's last-activity label is relative to. */now: number;/** The conversation the chat window has open, marked like a selected sidebar row. */@@ -48,9 +50,7 @@ export function PinnedThreads({ rows, now, current, onOpen, onUnpin }: {aria-current={open ? "page" : undefined} data-open-thread={open || undefined}onClick={() => onOpen(row)}className={cn("flex min-w-0 flex-1 items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[13px] text-ink hover:bg-menu-hover", open && openThreadRow)}>- {active- ? <Icon size={16} aria-hidden="true" className={cn("shrink-0", colorClass)} />- : <Pin size={16} aria-hidden="true" className="shrink-0 text-ink-tertiary" />}+ <AttentionFace entry={row} faces={faces} Icon={active ? Icon : Pin} iconClass={active ? colorClass : "text-ink-tertiary"} /><span className="min-w-0 flex-1"><span className="block truncate" data-pinned-title>{row.task.title}</span><span className="block truncate text-[11px] text-ink-secondary">diff --git a/src/components/inbox/finished.dom.test.ts b/src/components/inbox/finished.dom.test.tsindex 5cd8eb015f..08baad24d0 100644--- a/src/components/inbox/finished.dom.test.ts+++ b/src/components/inbox/finished.dom.test.ts@@ -5,6 +5,7 @@ import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { Bot, Group, Task } from "@/state/store";import { t } from "@/lib/i18n";+import { botFaces } from "../SidebarBotActivity";import { FinishedThreads, finishedThreads } from "./FinishedThreads";(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;@@ -15,7 +16,7 @@ const bot = (id: string, tasks: Task[]): Bot => ({ id, name: id, tasks } as unknlet root: Root;const mount = (bots: Bot[], groups: Group[] = [], current?: { kind: "bot"; botId: string; threadId: string }) => act(async () => {- root.render(createElement(FinishedThreads, { rows: finishedThreads(bots, groups, {}), now: NOW, current, onOpen: vi.fn() }));+ root.render(createElement(FinishedThreads, { rows: finishedThreads(bots, groups, {}), faces: botFaces(bots), now: NOW, current, onOpen: vi.fn() }));});beforeEach(() => {diff --git a/src/components/inbox/pinned.dom.test.ts b/src/components/inbox/pinned.dom.test.tsindex e11acf24a2..8160212b31 100644--- a/src/components/inbox/pinned.dom.test.ts+++ b/src/components/inbox/pinned.dom.test.ts@@ -5,7 +5,7 @@ import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { Bot, Group, GroupTask, Task } from "@/state/store";import { t } from "@/lib/i18n";-import type { AttentionThread } from "../SidebarBotActivity";+import { botFaces, type AttentionThread } from "../SidebarBotActivity";import { PinnedThreads, pinnedThreadRows } from "./PinnedThreads";(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;@@ -20,7 +20,7 @@ let root: Root;const onOpen = vi.fn();const onUnpin = vi.fn();const mount = (bots: Bot[], groups: Group[] = [], current?: { kind: "bot"; botId: string; threadId: string }) => act(async () => {- root.render(createElement(PinnedThreads, { rows: pinnedThreadRows(bots, groups, {}), now: NOW, current, onOpen, onUnpin }));+ root.render(createElement(PinnedThreads, { rows: pinnedThreadRows(bots, groups, {}), faces: botFaces(bots), now: NOW, current, onOpen, onUnpin }));});const rowTitles = () => [...document.querySelectorAll<HTMLElement>("[data-pinned-row]")].map((row) => row.querySelector("[data-pinned-title]")?.textContent);diff --git a/src/components/inbox/thread-faces.dom.test.ts b/src/components/inbox/thread-faces.dom.test.tsnew file mode 100644index 0000000000..679c213603--- /dev/null+++ b/src/components/inbox/thread-faces.dom.test.ts@@ -0,0 +1,67 @@+// @vitest-environment happy-dom+// Every conversation row in the Inbox leads with whose it is: the bot's own picture, or the room mark for a room,+// with the row's status on the picture's corner.+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { Bot, Group, GroupTask, Task } from "@/state/store";+import { AttentionThreadRows, botFaces, type AttentionThread } from "../SidebarBotActivity";+import { FinishedThreads, finishedThreads } from "./FinishedThreads";+import { PinnedThreads, pinnedThreadRows } from "./PinnedThreads";++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++const NOW = Date.parse("2026-11-25T08:00:00Z");+const PICTURE = "/api/attachments/eli-face.png";+const task = (threadId: string, patch: Partial<Task> = {}): Task => ({ threadId, title: threadId, createdAt: 0, updatedAt: NOW, ...patch });+const eli = (tasks: Task[]): Bot => ({ id: "eli", name: "Eli", color: "blue", avatarUrl: PICTURE, avatarCrop: "circle", tasks } as unknown as Bot);+const room = (tasks: GroupTask[]): Group =>+ ({ id: "room", threadId: "room-main", name: "Room", memberIds: [], unread: false, createdAt: 0, tasks } as unknown as Group);+const roomTask = (patch: Partial<GroupTask> = {}): GroupTask => ({ threadId: "room-main", title: "room chat", createdAt: 0, updatedAt: NOW - 60_000, ...patch });+const working = (botId: string, botName: string): AttentionThread =>+ ({ kind: "bot", botId, botName, task: { ...task("working", { busy: true }), queued: false } });++let root: Root;+const render = (element: ReturnType<typeof createElement>) => act(async () => { root.render(element); });+const faces = (rowSelector: string) => [...document.querySelectorAll<HTMLElement>(`${rowSelector} [data-attention-face]`)];+const pictureOf = (face: HTMLElement) => face.querySelector("img")?.getAttribute("src");++beforeEach(() => { root = createRoot(document.body.appendChild(document.createElement("div"))); });+afterEach(() => { act(() => root.unmount()); document.body.innerHTML = ""; });++describe("faces on the Inbox's conversation rows", () => {+ it("leads each pinned row with the bot's picture, and a room's with the room mark", async () => {+ const bots = [eli([task("pinned", { pinned: true })])];+ const groups = [room([roomTask({ pinned: true })])];+ await render(createElement(PinnedThreads, { rows: pinnedThreadRows(bots, groups, {}), faces: botFaces(bots), now: NOW, onOpen: vi.fn(), onUnpin: vi.fn() }));+ const shown = faces("[data-pinned-row]");+ expect(shown.map((face) => face.dataset.attentionFace)).toEqual(["bot", "group"]);+ expect(pictureOf(shown[0]!)).toBe(PICTURE);+ });++ it("leads each finished row with the bot's picture, and a room's with the room mark", async () => {+ const bots = [eli([task("done", { lastReadMessageId: "m1" })])];+ const groups = [room([roomTask({ lastReadMessageId: "m2" })])];+ await render(createElement(FinishedThreads, { rows: finishedThreads(bots, groups, {}), faces: botFaces(bots), now: NOW, onOpen: vi.fn() }));+ const shown = faces("[data-inbox-finished] button");+ expect(shown.map((face) => face.dataset.attentionFace)).toEqual(["bot", "group"]);+ expect(pictureOf(shown[0]!)).toBe(PICTURE);+ });++ it("leads each at-work row with the bot's picture when the list is given faces", async () => {+ await render(createElement(AttentionThreadRows, { entries: [working("eli", "Eli")], faces: botFaces([eli([])]), inset: true, onJump: vi.fn() }));+ const shown = faces("button");+ expect(shown).toHaveLength(1);+ expect(pictureOf(shown[0]!)).toBe(PICTURE);+ });++ it("keeps the sidebar's rows as they were: no faces unless asked for", async () => {+ await render(createElement(AttentionThreadRows, { entries: [working("eli", "Eli")], inset: true, onJump: vi.fn() }));+ expect(faces("button")).toHaveLength(0);+ });++ it("still draws a face for a bot it has no picture details for", async () => {+ await render(createElement(AttentionThreadRows, { entries: [working("gone", "Gone")], faces: [], inset: true, onJump: vi.fn() }));+ expect(faces("button")).toHaveLength(1);+ });+});