Skip to content

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

Show recently active conversations above sidebar departments

vincentdefe7413ae7b
diff --git a/screenshots/issue-6929/after-1440-daylight.png b/screenshots/issue-6929/after-1440-daylight.png
new file mode 100644
index 0000000000..27c7edef39
Binary files /dev/null and b/screenshots/issue-6929/after-1440-daylight.png differ
diff --git a/screenshots/issue-6929/after-1440-midnight.png b/screenshots/issue-6929/after-1440-midnight.png
new file mode 100644
index 0000000000..03785174f5
Binary files /dev/null and b/screenshots/issue-6929/after-1440-midnight.png differ
diff --git a/screenshots/issue-6929/after-390-daylight.png b/screenshots/issue-6929/after-390-daylight.png
new file mode 100644
index 0000000000..7fd484fb19
Binary files /dev/null and b/screenshots/issue-6929/after-390-daylight.png differ
diff --git a/screenshots/issue-6929/after-390-midnight.png b/screenshots/issue-6929/after-390-midnight.png
new file mode 100644
index 0000000000..9cc7647a85
Binary files /dev/null and b/screenshots/issue-6929/after-390-midnight.png differ
diff --git a/screenshots/issue-6929/before-1440-daylight.png b/screenshots/issue-6929/before-1440-daylight.png
new file mode 100644
index 0000000000..4ad6a4893e
Binary files /dev/null and b/screenshots/issue-6929/before-1440-daylight.png differ
diff --git a/screenshots/issue-6929/before-1440-midnight.png b/screenshots/issue-6929/before-1440-midnight.png
new file mode 100644
index 0000000000..7afdafd13e
Binary files /dev/null and b/screenshots/issue-6929/before-1440-midnight.png differ
diff --git a/screenshots/issue-6929/before-390-daylight.png b/screenshots/issue-6929/before-390-daylight.png
new file mode 100644
index 0000000000..ce218789a9
Binary files /dev/null and b/screenshots/issue-6929/before-390-daylight.png differ
diff --git a/screenshots/issue-6929/before-390-midnight.png b/screenshots/issue-6929/before-390-midnight.png
new file mode 100644
index 0000000000..d3da273d4f
Binary files /dev/null and b/screenshots/issue-6929/before-390-midnight.png differ
diff --git a/src/components/Sidebar.recent-conversations.dom.test.ts b/src/components/Sidebar.recent-conversations.dom.test.ts
new file mode 100644
index 0000000000..16ec00618e
--- /dev/null
+++ b/src/components/Sidebar.recent-conversations.dom.test.ts
@@ -0,0 +1,102 @@
+// @vitest-environment happy-dom
+import { act, createElement } from "react";
+import { createRoot } from "react-dom/client";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { PHONE_LAYOUT } from "@/lib/use-media-query";
+import { setLocale } from "@/lib/i18n";
+import { BotEditorStore, initialState, type Bot, type Group } from "@/state/store";
+import { Sidebar } from "./Sidebar";
+
+vi.mock("./DesktopCapabilities", async (original) => ({
+ ...await original<typeof import("./DesktopCapabilities")>(),
+ useDesktopCapabilities: () => ({ capabilities: { dictation: { available: false }, host: { packaged: false, platform: "other" }, localComputer: { available: false } }, ready: true }),
+}));
+
+const bot = (id: string, section: string, activityAt: number): Bot => ({
+ id, name: id, section, threadId: `${id}-main`, title: "", description: "", color: "green", unread: false,
+ notifications: true, messages: [], modelSelection: { instanceId: "test", model: "test" },
+ tasks: [{ threadId: `${id}-main`, title: `${id} main`, createdAt: 1, lastThreadOrderAt: activityAt }],
+});
+const room: Group = {
+ id: "room", name: "Launch room", memberIds: [], defaultResponder: { kind: "auto" }, bulletin: "", unread: false,
+ threadId: "room-main", section: "Launch", createdAt: 1, messages: [],
+ tasks: [{ threadId: "launch-plan", title: "Launch plan", createdAt: 2, updatedAt: 20 }],
+};
+const dispatch = vi.fn();
+const onClose = vi.fn();
+let host: HTMLDivElement;
+let root: ReturnType<typeof createRoot>;
+
+beforeEach(() => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ vi.stubGlobal("fetch", () => new Promise(() => {}));
+ localStorage.clear();
+ setLocale("en");
+ dispatch.mockClear();
+ onClose.mockClear();
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+});
+afterEach(async () => {
+ await act(async () => root.unmount());
+ host.remove();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+async function render(bots: Bot[]) {
+ await act(async () => root.render(createElement(BotEditorStore, {
+ value: {
+ state: { ...initialState, connected: true, bots, groups: [room], selectedId: "Scout", activeView: "chat" },
+ dispatch, flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {},
+ },
+ children: createElement(Sidebar, { open: true, onClose }),
+ })));
+}
+const rows = () => [...host.querySelectorAll<HTMLButtonElement>("button[data-sidebar-recent-thread]")];
+const order = () => rows().map((row) => row.dataset.sidebarRecentThread);
+const departmentOrder = () => [...host.querySelectorAll<HTMLElement>("[data-sidebar-section-id]")].map((section) => section.dataset.sidebarSectionId);
+
+it.each([false, true])("shows cross-department activity and opens the exact conversation (phone=%s)", async (phone) => {
+ const matchMedia = window.matchMedia.bind(window);
+ vi.spyOn(window, "matchMedia").mockImplementation((query) => {
+ const match = matchMedia(query);
+ Object.defineProperty(match, "matches", { value: phone && query === PHONE_LAYOUT });
+ return match;
+ });
+ const scout = bot("Scout", "Research", 10);
+ const builder = bot("Builder", "Engineering", 30);
+ builder.tasks!.push(
+ { threadId: "archived", title: "Archived", createdAt: 100, archivedAt: 0 },
+ { threadId: "routine", title: "Routine", createdAt: 100, routineRunId: "run" },
+ );
+ const hidden = { ...bot("Hidden", "Operations", 100), hidden: true };
+ await render([scout, builder, hidden]);
+
+ expect(order()).toEqual(["Builder-main", "launch-plan", "Scout-main"]);
+ expect(rows()[2]?.getAttribute("aria-current")).toBe("page");
+ const firstDepartment = host.querySelector("[data-sidebar-section-id]")!;
+ expect(rows()[0]!.compareDocumentPosition(firstDepartment) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ const sections = departmentOrder();
+ expect(sections).toContain("section:Research");
+ expect(sections).toContain("section:Engineering");
+
+ const activeScout = { ...scout, tasks: [{ ...scout.tasks![0]!, lastThreadOrderAt: 40 }] };
+ await render([activeScout, builder, hidden]);
+ expect(order()).toEqual(["Scout-main", "Builder-main", "launch-plan"]);
+ expect(departmentOrder()).toEqual(sections);
+
+ await act(async () => rows()[1]!.click());
+ expect(dispatch).toHaveBeenCalledWith({ type: "switchTask", botId: "Builder", threadId: "Builder-main" });
+ await act(async () => rows()[2]!.click());
+ expect(dispatch).toHaveBeenCalledWith({ type: "switchGroupTask", groupId: "room", threadId: "launch-plan" });
+ expect(onClose).toHaveBeenCalledTimes(phone ? 2 : 0);
+
+ const toggle = host.querySelector<HTMLButtonElement>("[data-sidebar-recent] button[aria-expanded]")!;
+ await act(async () => toggle.click());
+ expect(toggle.getAttribute("aria-expanded")).toBe("false");
+ expect(order()).toEqual([]);
+ await act(async () => toggle.click());
+ expect(order()).toEqual(["Scout-main", "Builder-main", "launch-plan"]);
+});
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 2476992cb3..5a872d7317 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -92,8 +92,7 @@ import { SidebarNoBots, SidebarTileGrid } from "./SidebarTiles";
import { BotContextMenu } from "./SidebarBotMenu";
export { BotContextMenu };
import { AvatarActivityDot, AvatarCornerDot, RowDot, RowStatusText, rowSelectedSurface, rowSurface } from "./SidebarRowMarkers";
-
-
+import { SidebarRecentConversations } from "./SidebarRecentConversations";
import { SidebarAttentionPanel } from "./SidebarAttentionPanel";
import { useLiveMedia } from "@/lib/live-call-media";
import { LiveCallPill, liveBadgeFor } from "./LiveCallPill";
@@ -1026,7 +1025,6 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
return () => window.clearTimeout(timer);
}, [teamFeedback]);
-
const requestArchive = (bot: Bot) => {
const current = currentArchivableBot(state.bots, bot.id);
if (current) setConfirm({ kind: "archive", bot: current });
@@ -1088,7 +1086,8 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
);
const visibleGroups = sideLists.groups.filter((g) => !q || g.name.toLowerCase().includes(q) || g.tasks?.some((task) => task.title.toLowerCase().includes(q)));
const viewerEmail = useViewerEmail(), placed = useOtherPlaceBots(q), placeHere = useOneListHere(), oneList = useOneList(matchingBots, placed, state.sections ?? NO_SECTIONS, dispatch, state.hydrated === true);
- const parts = partitionSidebarBots(botDrag.preview(oneList?.bots ?? matchingBots), { universalPins, viewerEmail, welcoming: useWelcomingBot(), searching: Boolean(q) });
+ const welcoming = useWelcomingBot();
+ const parts = partitionSidebarBots(botDrag.preview(oneList?.bots ?? matchingBots), { universalPins, viewerEmail, welcoming, searching: Boolean(q) });
const saved = simpleDesk ? withPrimaryTile(parts, myDefaultBot(state.bots, viewerEmail)?.id) : { ...parts, primary: null };
// Rows keep their place while the app is in use: unread, work and a wait on the person show as marks on the row, never
// as a move to the top or into an Unread list. Only a pin, a drag, Alt+Up/Down or a move to a department moves a row.
@@ -1353,6 +1352,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
<BotListItem {...botRow(unsectionedChief)} />
</div>
))}
+ {!q && density !== "icons" && <SidebarRecentConversations bots={sideLists.bots} groups={sideLists.groups} routineRuns={state.routineRuns} viewerEmail={viewerEmail} welcoming={welcoming} selectedId={state.activeView === "chat" ? state.selectedId : null} onOpen={(target) => { if (openThread(dispatch, target, state, showThreads) && phone) onClose(); }} />}
{sectionIds.map((id, index) => {
const sectionName = userSectionName(id), editable = oneList?.mirror ? null : sectionName;
const sectionChiefItems = sectionName
diff --git a/src/components/SidebarRecentConversations.tsx b/src/components/SidebarRecentConversations.tsx
new file mode 100644
index 0000000000..b3b3f8a9d5
--- /dev/null
+++ b/src/components/SidebarRecentConversations.tsx
@@ -0,0 +1,59 @@
+import { useMemo, useState } from "react";
+import { ChevronRight } from "lucide-react";
+import { cn } from "@/lib/cn";
+import { hiddenFromSidebar } from "@/lib/default-bot";
+import { t } from "@/lib/i18n";
+import { isPlaceId } from "@/lib/place-chat";
+import { localizedTaskTitle } from "@/lib/task-title";
+import type { AppState, Bot, Group } from "@/state/store";
+import type { ThreadTarget } from "@/state/thread-navigation";
+import { rowSelectedSurface } from "./SidebarRowMarkers";
+import { isArchived, threadRecency } from "./SidebarThreadRow";
+
+const ROW_CLASS = "flex min-h-8 w-full items-center gap-1.5 rounded-md px-2 text-left leading-[18px] hover:bg-ink/[0.06] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-focus max-md:min-h-11";
+
+export function SidebarRecentConversations({ bots, groups, routineRuns, viewerEmail, welcoming, selectedId, onOpen }: {
+ bots: Bot[];
+ groups: Group[];
+ routineRuns: AppState["routineRuns"];
+ viewerEmail: string | null | undefined;
+ welcoming: string | null;
+ selectedId: string | null;
+ onOpen: (target: ThreadTarget) => void;
+}) {
+ const [expanded, setExpanded] = useState(true);
+ const entries = useMemo(() => {
+ const runThreads = new Set(routineRuns?.map((run) => run.threadId));
+ const botEntries = bots.filter((bot) => !bot.hidden && !isPlaceId(bot.id) && bot.id !== welcoming && !hiddenFromSidebar(bot, viewerEmail))
+ .flatMap((owner) => (owner.tasks ?? [{ threadId: owner.threadId, title: owner.title, createdAt: 0, updatedAt: owner.messages.at(-1)?.at }])
+ .filter((task) => !task.routineRunId).map((task) => ({ owner, task })));
+ const roomEntries = groups.flatMap((owner) => (owner.tasks ?? [{ threadId: owner.threadId, title: owner.name, createdAt: owner.createdAt, updatedAt: owner.messages.at(-1)?.at }])
+ .map((task) => ({ owner, task })));
+ return [...botEntries, ...roomEntries]
+ .filter(({ task }) => !isArchived(task) && !runThreads.has(task.threadId))
+ .map((entry) => ({ ...entry, at: entry.task.lastThreadOrderAt ?? threadRecency(entry.task) }))
+ .sort((a, b) => b.at - a.at)
+ .slice(0, 6);
+ }, [bots, groups, routineRuns, viewerEmail, welcoming]);
+ if (!entries.length) return null;
+
+ const label = t("sidebar.section.recentConversations");
+ return <section aria-label={label} data-sidebar-recent="" className="mb-1">
+ <button type="button" aria-expanded={expanded} onClick={() => setExpanded((open) => !open)}
+ className={cn(ROW_CLASS, "text-[13px] text-ink-secondary hover:text-ink")}>
+ <ChevronRight size={12} aria-hidden="true" className={cn("shrink-0 transition-transform motion-reduce:transition-none", expanded && "rotate-90")} />
+ <span className="truncate">{label}</span>
+ </button>
+ {expanded && entries.map(({ owner, task }) => {
+ const current = selectedId === owner.id && task.threadId === owner.threadId;
+ const title = task.title ? localizedTaskTitle(task.title) : t("task.untitledChat");
+ return <button key={`${owner.id}:${task.threadId}`} type="button" data-sidebar-recent-thread={task.threadId}
+ aria-current={current ? "page" : undefined} title={`${title} · ${owner.name}`}
+ onClick={() => onOpen({ botId: owner.id, threadId: task.threadId })}
+ className={cn(ROW_CLASS, "ps-6 text-[13px] text-ink", current && rowSelectedSurface)}>
+ <span className="min-w-0 flex-1 truncate">{title}</span>
+ <span className="max-w-[40%] truncate text-[12px] text-ink-secondary">{owner.name}</span>
+ </button>;
+ })}
+ </section>;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index cf38252006..b3b5eadbe4 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2353,6 +2353,7 @@
"sidebar.preview.you": "You: {text}",
"sidebar.section.pinned": "Pinned",
"sidebar.section.unread": "Unread",
+ "sidebar.section.recentConversations": "Recent conversations",
"sidebar.section.channels": "Group chats",
"sidebar.section.botChats": "Bot threads",
"sidebar.section.bots": "Bots",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 0dd3959498..67e435384e 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2158,6 +2158,7 @@
"sidebar.section.channels": "Chats em grupo",
"sidebar.section.botChats": "Conversas dos bots",
"sidebar.section.bots": "Bots",
+ "sidebar.section.recentConversations": "Conversas recentes",
"sidebar.section.moved": "{name} foi para a posição {position} de {count}",
"sidebar.section.moveToContext": "Mover para equipe",
"sidebar.section.newContext": "Nova equipe…",