Skip to content

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

List a bot's main thread first and set it from any thread's menu

luishron12346f85f206666
diff --git a/src/components/ChatMoreMenu.test.ts b/src/components/ChatMoreMenu.test.ts
index 33ea565a62..8e8ed68128 100644
--- a/src/components/ChatMoreMenu.test.ts
+++ b/src/components/ChatMoreMenu.test.ts
@@ -121,16 +121,16 @@ describe("ChatMoreMenu, the round ⋯ for the bot panel", () => {
expect(fixture.dispatch).toHaveBeenCalledWith({ type: "newTask", botId: "pepper" });
});
- it("lists the bot's threads newest first, without routine runs, marks the open one and opens another", () => {
+ it("lists the bot's main thread first, then newest first, without routine runs, marks the open one and opens another", () => {
const threads = menuOf(createElement(ChatMoreMenu, { bot })).items.find((item) => item.key === "threads")!;
expect(threads).toMatchObject({ label: "All threads", value: "3" });
expect(threads.submenu!.map((item) => [item.label, Boolean(item.active)])).toEqual([
+ ["Our chat", false],
["Trip plan", true],
["Untitled chat", false],
- ["Our chat", false],
]);
- expect(threads.submenu!.map((item) => renderToStaticMarkup(createElement("div", null, item.trailing)).includes('aria-label="Main thread"'))).toEqual([false, false, true]);
- threads.submenu![2].onSelect();
+ expect(threads.submenu!.map((item) => renderToStaticMarkup(createElement("div", null, item.trailing)).includes('aria-label="Main thread"'))).toEqual([true, false, false]);
+ threads.submenu![0].onSelect();
expect(fixture.dispatch).toHaveBeenCalledWith({ type: "switchTask", botId: "pepper", threadId: "main" });
});
diff --git a/src/components/ChatMoreMenu.tsx b/src/components/ChatMoreMenu.tsx
index fe229640a6..18bfc97d03 100644
--- a/src/components/ChatMoreMenu.tsx
+++ b/src/components/ChatMoreMenu.tsx
@@ -19,7 +19,7 @@ import { ELEVATED_CONTROL, ELEVATED_HOVER, ELEVATED_OPEN } from "./elevated";
import { ShortcutHint } from "./ShortcutHint";
import { SidebarPopoverMenu, type SidebarMenuItem } from "./SidebarPopoverMenu";
import { MainThreadMark } from "./SidebarRowMarkers";
-import { orderedThreadList } from "./SidebarThreadRow";
+import { mainThreadFirst, orderedThreadList } from "./SidebarThreadRow";
import { openBotSettings } from "./bot-panel/panel-link";
import { ShareBotButton, useTeamName } from "./bot-access/ShareBotButton";
import { UsageBars } from "./EngineUsage";
@@ -47,7 +47,7 @@ export function useChatMoreItems(profile: Bot, phoneHeader = false): { items: Si
const atFreshStart = messages.at(-1)?.compaction?.fresh === true;
const transcript = () => formatTranscriptMarkdown({ title: bot.name, messages, botName: bot.name, isGroup: false });
const side = useConversationSide(profile);
- const threads = showThreads ? [] : orderedThreadList((side ? tasksOfSide(profile, side) : profile.tasks ?? []).filter((task) => !task.routineRunId));
+ const threads = showThreads ? [] : mainThreadFirst(orderedThreadList((side ? tasksOfSide(profile, side) : profile.tasks ?? []).filter((task) => !task.routineRunId)), profile.mainThreadId);
const sharing = shareChoices(profile, profile.tasks?.find((task) => task.threadId === bot.threadId), Boolean(useTeamName()));
const shareItems: SidebarMenuItem[] = [
{ key: TEMPLATE_ITEM, label: t("template.shareAsTemplate"), icon: <LayoutTemplate size={16} />,
diff --git a/src/components/Sidebar.pinned-show-all.dom.test.ts b/src/components/Sidebar.pinned-show-all.dom.test.ts
index d670d8e70b..178d471c62 100644
--- a/src/components/Sidebar.pinned-show-all.dom.test.ts
+++ b/src/components/Sidebar.pinned-show-all.dom.test.ts
@@ -107,6 +107,28 @@ describe("a bot's main thread", () => {
await unmount();
});
+ it("leads the list, above folders and pinned threads, folded or showing all, and is listed once", async () => {
+ const rows = () => [...host.querySelectorAll("[data-sidebar-thread-row]")].map((row) => row.getAttribute("data-sidebar-thread-row"));
+ bot.mainThreadId = "loose-0";
+ await mount();
+ expect(rows().slice(0, 3)).toEqual(["loose-0", "filed-pinned", "filed-plain"]);
+ await click("Show all 11 threads");
+ expect(rows()[0]).toBe("loose-0");
+ expect(rows().filter((id) => id === "loose-0")).toHaveLength(1);
+ expect(rows()).toHaveLength(11);
+ await unmount();
+ forgetSidebarShowAllForTests();
+ localStorage.clear();
+ bot.mainThreadId = "filed-plain";
+ await mount();
+ expect(rows().slice(0, 2)).toEqual(["filed-plain", "filed-pinned"]);
+ expect(rows().filter((id) => id === "filed-plain")).toHaveLength(1);
+ await click("Collapse Taxes threads");
+ expect(rows().slice(0, 2)).toEqual(["filed-plain", "filed-pinned"]);
+ await unmount();
+ delete bot.mainThreadId;
+ });
+
it("is marked on a collapsed bot's row for it", () => {
const html = renderToStaticMarkup(createElement(SidebarBotActivity, {
bot: { ...bot, mainThreadId: "filed-pinned" }, rowThreadId: bot.threadId, density: "comfortable", pendingQueued: {}, dispatch: vi.fn(),
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 8b89ba4d9b..799e580d6a 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -481,8 +481,8 @@ export function BotThreadList({ bot, selected, drafting, query, pendingQueued, r
}, [selected, currentProjectId]);
useSnoozeExpiry(tasks);
const bulk = useBulkSelect();
- const { own: ownTasks, helpers } = bulk.active ? { own: tasks, helpers: [] } : partitionHelperThreads(tasks, bot.threadId, query, projects);
- const visibleTasks = orderedThreadList(visibleSidebarThreads(ownTasks, bot.threadId, query, projects, showAll || bulk.active, routineRuns, bot.mainThreadId));
+ const { own: ownTasks, helpers } = bulk.active ? { own: tasks, helpers: [] } : partitionHelperThreads(tasks, bot.threadId, query, projects, bot.mainThreadId);
+ const visibleTasks = orderedThreadList(visibleSidebarThreads(ownTasks, bot.threadId, query, projects, showAll || bulk.active, routineRuns, bot.mainThreadId)), mainTask = visibleTasks.find((task) => task.threadId === bot.mainThreadId);
const visibleProjectIndex = (projectId: string) => visibleTasks.findIndex((task) => task.projectId === projectId);
const folderRank = (projectId: string) => {
const index = visibleProjectIndex(projectId);
@@ -516,8 +516,8 @@ export function BotThreadList({ bot, selected, drafting, query, pendingQueued, r
activityLabel={task.threadId === bot.threadId ? activityLabel : undefined} now={stampClock(threadRecency(task), now)} locale={locale} {...actions}
selectMode={bulk.active} checked={selection.has(task.threadId)} onToggleSelect={bulk.toggle} />;
};
- const ungrouped = visibleTasks.filter((task) => !projects.some((project) => project.id === task.projectId));
- const shownRows = [...orderedProjects.filter((project) => query || bulk.active || !collapsed.has(project.id)).flatMap((project) => visibleTasks.filter((task) => task.projectId === project.id)), ...ungrouped]
+ const ungrouped = visibleTasks.filter((task) => task !== mainTask && !projects.some((project) => project.id === task.projectId));
+ const shownRows = [...(mainTask ? [mainTask] : []), ...orderedProjects.filter((project) => query || bulk.active || !collapsed.has(project.id)).flatMap((project) => visibleTasks.filter((task) => task !== mainTask && task.projectId === project.id)), ...ungrouped]
.map((task) => { const thread = currentTaskBot(bot, task.threadId); return { ...task, busy: thread.busy, activity: thread.activity }; });
const selection = bulk.forRows(shownRows);
const projectToEdit = projects.find((project) => project.id === editingProject);
@@ -547,11 +547,11 @@ export function BotThreadList({ bot, selected, drafting, query, pendingQueued, r
onDragOver={(event) => { if (event.dataTransfer.types.includes(FOLDER_DRAG_TYPE)) event.stopPropagation(); }}
onDrop={(event) => { if (event.dataTransfer.types.includes(FOLDER_DRAG_TYPE)) { event.preventDefault(); event.stopPropagation(); resetFolderDrag(); } }}>
{!hidden && <>
- {bulk.active && <BulkSelectFilters rows={shownRows} selected={selection} now={now} onChange={bulk.setSelected} onDone={bulk.finish} />}
+ {bulk.active && <BulkSelectFilters rows={shownRows} selected={selection} now={now} onChange={bulk.setSelected} onDone={bulk.finish} />}{mainTask && renderThread(mainTask)}
{orderedProjects.map((project) => {
const index = projects.indexOf(project);
- const projectTasks = tasks.filter((task) => task.projectId === project.id);
- const visible = visibleTasks.filter((task) => task.projectId === project.id);
+ const projectTasks = tasks.filter((task) => task.projectId === project.id && task.threadId !== bot.mainThreadId);
+ const visible = visibleTasks.filter((task) => task !== mainTask && task.projectId === project.id);
if (query && visible.length === 0 && !project.name.toLowerCase().includes(query.toLowerCase())) return null;
const open = Boolean(query) || bulk.active || !collapsed.has(project.id);
const waiting = projectTasks.some((task) => task.activity === "waiting-on-you");
diff --git a/src/components/SidebarThreadRow.test.ts b/src/components/SidebarThreadRow.test.ts
index 23725378d0..f5ed7ea098 100644
--- a/src/components/SidebarThreadRow.test.ts
+++ b/src/components/SidebarThreadRow.test.ts
@@ -2,7 +2,7 @@ import { createElement, type ComponentProps, type MemoExoticComponent, type Reac
import { renderToStaticMarkup } from "react-dom/server";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { setLocale } from "@/lib/i18n";
-import { formatUpdatedAt, nextSnoozeExpiry, orderedSidebarThreads, orderedThreadList, partitionHelperThreads, SidebarThreadRow, stampClock, threadRowActions, threadByline, threadOpenerLabel, threadUpdatedLabel, visibleSidebarThreads } from "./SidebarThreadRow";
+import { formatUpdatedAt, mainThreadFirst, nextSnoozeExpiry, orderedSidebarThreads, orderedThreadList, partitionHelperThreads, SidebarThreadRow, stampClock, threadRowActions, threadByline, threadOpenerLabel, threadUpdatedLabel, visibleSidebarThreads } from "./SidebarThreadRow";
type ThreadRowProps = ComponentProps<typeof SidebarThreadRow>;
@@ -409,6 +409,15 @@ describe("orderedThreadList", () => {
});
});
+describe("mainThreadFirst", () => {
+ it("leads with the bot's main thread, above a pinned one, and leaves a list without it as it is", () => {
+ const tasks = [{ threadId: "pinned", pinned: true }, { threadId: "new" }, { threadId: "main" }];
+ expect(mainThreadFirst(tasks, "main").map((task) => task.threadId)).toEqual(["main", "pinned", "new"]);
+ expect(mainThreadFirst(tasks, "gone")).toBe(tasks);
+ expect(mainThreadFirst(tasks)).toBe(tasks);
+ });
+});
+
describe("orderedSidebarThreads", () => {
const task = (threadId: string, over: Record<string, unknown> = {}) => ({
threadId,
@@ -740,6 +749,13 @@ describe("helper threads a bot opened", () => {
expect(helpers.map((task) => task.threadId)).toEqual(["email", "pricing"]);
});
+ it("never folds the bot's main thread away, whoever opened it", () => {
+ const tasks = [thread("mine"), thread("email", { openedBy: opener }), thread("pricing", { openedBy: opener })];
+ const { own, helpers } = partitionHelperThreads(tasks, "mine", "", [], "email");
+ expect(own.map((task) => task.threadId)).toEqual(["mine", "email"]);
+ expect(helpers.map((task) => task.threadId)).toEqual(["pricing"]);
+ });
+
it("keeps a helper thread in view while it needs the person or is doing something, as the phone lists it", () => {
const tasks = [
thread("open-now", { openedBy: opener }),
diff --git a/src/components/SidebarThreadRow.tsx b/src/components/SidebarThreadRow.tsx
index 5924b16b9c..a6dc11c49e 100644
--- a/src/components/SidebarThreadRow.tsx
+++ b/src/components/SidebarThreadRow.tsx
@@ -1,6 +1,6 @@
import { memo, useEffect, useRef, useState, type Dispatch, type ReactNode } from "react";
import { createPortal } from "react-dom";
-import { Archive, ArchiveRestore, BellOff, Brain, Check, ChevronRight, Clock, Clock3, FolderInput, Link2, Link2Off, Loader2, MoreHorizontal, Pencil, Pin, PinOff, RefreshCw, Trash2 } from "lucide-react";
+import { Archive, ArchiveRestore, BellOff, Brain, Check, ChevronRight, Clock, Clock3, FolderInput, Link2, Link2Off, Loader2, MoreHorizontal, Pencil, Pin, PinOff, RefreshCw, Star, Trash2 } from "lucide-react";
import type { Action, AppState, BotProject, Task } from "@/state/store";
import { api } from "@/state/store";
import type { RoutineRun } from "@/lib/routines";
@@ -10,6 +10,7 @@ import { useHeldMenuMotion } from "./MenuMotion";
import { intlLocale, t } from "@/lib/i18n";
import { nextRename } from "@/lib/rename";
import { imeComposing } from "@/lib/send-key";
+import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { isTickable, opensRowMenuFromKey } from "@/lib/bulk-select";
import { threadRefUrl, threadWebRefUrl } from "@/lib/thread-refs";
import { copyText } from "@/lib/copy-text";
@@ -27,7 +28,7 @@ import { ShareRowItems } from "./conversation-share/ShareRowItems";
export { isSnoozed, orderedThreadList };
-type ThreadRowTask = Pick<Task, "threadId" | "title" | "sharedChat" | "private" | "shared" | "sharedWith" | "projectId" | "busy" | "activity" | "unread" | "openedBy" | "closedBy" | "archivedAt" | "snoozedUntil" | "waitingForTeammates" | "link" | "turnStartedAt"> & {
+type ThreadRowTask = Pick<Task, "threadId" | "title" | "routineRunId" | "sharedChat" | "private" | "shared" | "sharedWith" | "projectId" | "busy" | "activity" | "unread" | "openedBy" | "closedBy" | "archivedAt" | "snoozedUntil" | "waitingForTeammates" | "link" | "turnStartedAt"> & {
queued?: boolean;
pinned?: boolean;
createdAt?: number;
@@ -101,13 +102,13 @@ const isWaitingOnTeammate = (task: Pick<Task, "waitingForTeammates">): boolean =
const demandsAttention = (task: ThreadRowTask, activeId: string) =>
task.threadId === activeId || task.activity === "waiting-on-you" || isWorking(task) || isWaitingOnTeammate(task) || Boolean(task.queued) || Boolean(task.unread);
-export function partitionHelperThreads<T extends ThreadRowTask>(tasks: T[], activeId: string, query = "", folders: BotProject[] = []): { own: T[]; helpers: T[] } {
+export function partitionHelperThreads<T extends ThreadRowTask>(tasks: T[], activeId: string, query = "", folders: BotProject[] = [], mainId?: string): { own: T[]; helpers: T[] } {
if (query.trim()) return { own: tasks, helpers: [] };
const own: T[] = [];
const helpers: T[] = [];
for (const task of tasks) {
const filed = folders.some((folder) => folder.id === task.projectId);
- const helper = Boolean(task.openedBy) && task.pinned !== true && !filed && !demandsAttention(task, activeId) &&
+ const helper = Boolean(task.openedBy) && task.threadId !== mainId && task.pinned !== true && !filed && !demandsAttention(task, activeId) &&
!task.closedBy && !isArchived(task) && !isSnoozed(task);
(helper ? helpers : own).push(task);
}
@@ -129,6 +130,12 @@ export function HelperThreadGroup<T>({ tasks, renderThread }: { tasks: T[]; rend
</div>;
}
+/** A bot's main thread leads every list of its threads, above pinned ones and whatever was written in last. */
+export function mainThreadFirst<T extends { threadId: string }>(tasks: T[], mainId?: string): T[] {
+ const main = tasks.find((task) => task.threadId === mainId);
+ return main ? [main, ...tasks.filter((task) => task !== main)] : tasks;
+}
+
/** Default list shows each routine's newest run only; older runs stay under "Show all". */
export function visibleSidebarThreads<T extends ThreadRowTask>(tasks: T[], activeId: string, query = "", folders: BotProject[] = [], showAll = false, routineRuns: readonly Pick<RoutineRun, "routineId" | "threadId" | "createdAt">[] = [], mainId?: string): T[] {
const needle = query.trim().toLowerCase();
@@ -223,6 +230,7 @@ export function threadRowActions(botId: string, dispatch: Dispatch<Action>) {
onMove: (task: { threadId: string }, projectId: string | null) => dispatch({ type: "updateTask", botId, threadId: task.threadId, patch: { projectId } }),
onArchive: (task: { threadId: string }, archivedAt: number | null) => dispatch({ type: "updateTask", botId, threadId: task.threadId, patch: { archivedAt } }),
onPin: (task: { threadId: string }, pinned: boolean) => dispatch({ type: "updateTask", botId, threadId: task.threadId, patch: { pinned } }),
+ onSetMain: (task: { threadId: string }) => dispatch({ type: "updateBot", botId, patch: { mainThreadChoice: task.threadId } }),
onSnooze: (task: { threadId: string }, snoozedUntil: number | null) => dispatch({ type: "updateTask", botId, threadId: task.threadId, patch: { snoozedUntil } }),
onLink: (task: { threadId: string }, link: string | null) => dispatch({ type: "updateTask", botId, threadId: task.threadId, patch: { link } }),
onMemory: () => openBotSettings(dispatch, "memory", { botId }),
@@ -244,6 +252,7 @@ type ThreadRowProps = {
onMove?: (task: ThreadRowTask, folderId: string | null) => void;
onArchive?: (task: ThreadRowTask, archivedAt: number | null) => void;
onPin?: (task: ThreadRowTask, pinned: boolean) => void;
+ onSetMain?: (task: ThreadRowTask) => void;
onSnooze?: (task: ThreadRowTask, snoozedUntil: number | null) => void;
onLink?: (task: ThreadRowTask, link: string | null) => void;
onRefreshPermissions?: (task: ThreadRowTask) => void;
@@ -268,10 +277,11 @@ const sameFields = <T extends object>(a: T, b: T): boolean => {
const sameThreadRow = ({ task: previousTask, ...previous }: ThreadRowProps, { task, ...next }: ThreadRowProps): boolean =>
sameFields(previousTask, task) && sameFields(previous, next);
-export const SidebarThreadRow = memo(function SidebarThreadRow({ task, ownerId, current, folders, onSelect, onRename, onRegenerateTitle, onDelete, onMove, onArchive, onPin, onSnooze, onLink, onRefreshPermissions, onMemory, activityLabel: liveActivity, now, selectMode = false, checked = false, onToggleSelect, panel = false, preview, main = false }: ThreadRowProps) {
+export const SidebarThreadRow = memo(function SidebarThreadRow({ task, ownerId, current, folders, onSelect, onRename, onRegenerateTitle, onDelete, onMove, onArchive, onPin, onSetMain, onSnooze, onLink, onRefreshPermissions, onMemory, activityLabel: liveActivity, now, selectMode = false, checked = false, onToggleSelect, panel = false, preview, main = false }: ThreadRowProps) {
const activityLabel = useHeldText(liveActivity);
// Simple mode's menu keeps what a person needs for a conversation; Advanced adds the rest.
const advanced = useAdvancedMode();
+ const admin = useOwnerOrAdmin();
const [menu, setMenu] = useState<{ left: number; top: number } | null>(null);
const [webLink, setWebLink] = useState<string | null>(null);
useEffect(() => {
@@ -408,6 +418,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow({ task, ownerId,
</Select>
</label>}
{onPin && <button type="button" onClick={() => { setMenu(null); onPin(task, task.pinned !== true); }} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover">{task.pinned === true ? <PinOff size={16} /> : <Pin size={16} />}{task.pinned === true ? t("sidebar.bot.unpin") : t("sidebar.bot.pin")}</button>}
+ {onSetMain && admin === true && window.ogb?.remoteClient?.active !== true && !task.routineRunId && !task.private && !archived && <button type="button" disabled={main} title={main ? t("sidebar.bot.simple.isMainThread") : undefined} onClick={() => { setMenu(null); onSetMain(task); }} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover disabled:opacity-40"><Star size={16} />{t("sidebar.bot.simple.setMainThread")}</button>}
{advanced && onLink && task.link && <button type="button" onClick={() => { setMenu(null); onLink(task, null); }} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover"><Link2Off size={16} />{t("task.removeLink")}</button>}
{onArchive && <button type="button" disabled={isWorking(task)} onClick={() => { setMenu(null); onArchive(task, isArchived(task) ? null : Date.now()); }} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover disabled:opacity-40">{archived ? <ArchiveRestore size={16} /> : <Archive size={16} />}{archived ? t("task.unarchive") : t("task.archive")}</button>}
{advanced && onSnooze && <div className="px-2 pt-1">
diff --git a/src/components/bot-panel/Conversations.dom.test.ts b/src/components/bot-panel/Conversations.dom.test.ts
index dd62219861..3d5ef50715 100644
--- a/src/components/bot-panel/Conversations.dom.test.ts
+++ b/src/components/bot-panel/Conversations.dom.test.ts
@@ -10,7 +10,9 @@ const fixture = vi.hoisted(() => ({
dispatch: vi.fn(),
wide: true,
api: vi.fn(),
+ admin: true as boolean | null,
}));
+vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => fixture.admin }));
vi.mock("@/state/store", async (importOriginal) => {
const original = await importOriginal<typeof import("@/state/store")>();
return {
@@ -150,9 +152,19 @@ describe("a bot's conversations in its panel", () => {
expect(more()!.textContent).toBe("Show 6 more");
});
- it("keeps the main thread listed, with its star, when it is older than the first three", () => {
+ it("lists the main thread first, above a pinned one, however old it is, folded or not", () => {
render(research({ mainThreadId: "gift" }));
- expect(listed()).toEqual(["hiring", "launch", "who", "gift"]);
+ expect(listed()).toEqual(["gift", "hiring", "launch", "who"]);
+ click(more());
+ expect(listed().slice(0, 3)).toEqual(["gift", "hiring", "launch"]);
+ expect(listed()).toHaveLength(10);
+ render(research({ mainThreadId: "hiring" }));
+ expect(listed().slice(0, 2)).toEqual(["hiring", "launch"]);
+ });
+
+ it("keeps the main thread listed, with its mark, when it is older than the first three", () => {
+ render(research({ mainThreadId: "gift" }));
+ expect(listed()).toEqual(["gift", "hiring", "launch", "who"]);
expect(row("gift").querySelector('[aria-label="Main thread"]')).not.toBeNull();
expect(more()!.textContent).toBe("Show 6 more");
});
@@ -294,6 +306,29 @@ describe("a bot's conversations in its panel", () => {
expect(fixture.dispatch.mock.calls).toEqual([[{ type: "updateTask", botId: "research", threadId: "launch", patch: { archivedAt: expect.any(Number) } }]]);
});
+ it("sets the row's own thread as the main one from its menu, and not the one that already is, an archived one, or for a member", () => {
+ const toggle = (title: string) => click(host.querySelector(`[aria-label="Actions for ${title}"]`));
+ const item = (title: string) => [...document.querySelector(`[data-thread-overlay][aria-label="Actions for ${title}"]`)!.querySelectorAll("button")]
+ .find((button) => button.textContent === "Set as main thread");
+ const archived = [...tasks, task("old", "Old notes", 11, { archivedAt: now })];
+ render(research({ mainThreadId: "launch", threadId: "old", tasks: archived }));
+ toggle("Who am I?");
+ click(item("Who am I?")!);
+ expect(fixture.dispatch.mock.calls).toEqual([[{ type: "updateBot", botId: "research", patch: { mainThreadChoice: "who" } }]]);
+ toggle("Translate the launch post");
+ const already = item("Translate the launch post")!;
+ expect([already.disabled, already.title]).toEqual([true, "This is already the main thread"]);
+ toggle("Translate the launch post");
+ toggle("Old notes");
+ expect(item("Old notes")).toBeUndefined();
+ toggle("Old notes");
+ fixture.admin = false;
+ render(research({ mainThreadId: "launch", threadId: "deck" }));
+ toggle("Who am I?");
+ expect(item("Who am I?")).toBeUndefined();
+ fixture.admin = true;
+ });
+
it("keeps the search open when archiving leaves one conversation listed", () => {
const two = [task("who", "Who am I?", 2), task("deck", "Summarise the board deck", 4)];
render(research({ tasks: two }));
diff --git a/src/components/bot-panel/Conversations.tsx b/src/components/bot-panel/Conversations.tsx
index c28451a509..80a4420b0b 100644
--- a/src/components/bot-panel/Conversations.tsx
+++ b/src/components/bot-panel/Conversations.tsx
@@ -6,7 +6,7 @@ import { activeLocale, t } from "@/lib/i18n";
import { SIDEBAR_INLINE, useMediaQuery } from "@/lib/use-media-query";
import { api, currentTaskBot, openBotThread, visibleMessages, type Bot, type Message } from "@/state/store";
import { lastLine } from "../sidebar-preview";
-import { isArchived, orderedThreadList, SidebarThreadRow, stampClock, threadRecency, threadRowActions, useRelativeNow } from "../SidebarThreadRow";
+import { isArchived, mainThreadFirst, orderedThreadList, SidebarThreadRow, stampClock, threadRecency, threadRowActions, useRelativeNow } from "../SidebarThreadRow";
import { filterTasks } from "../TaskPicker";
import { useConversationSide } from "../TeamSideSwitch";
import { tasksOfSide } from "@/state/team-side";
@@ -81,8 +81,8 @@ export function BotConversations({ bot }: { bot: Bot }) {
}, [bot.id]);
const [showArchived, setShowArchived] = useState(false);
const actions = useMemo(() => {
- const { onRename, onRegenerateTitle, onDelete, onMove, onPin, onArchive, onMemory } = threadRowActions(bot.id, dispatch);
- return { onRename, onRegenerateTitle, onDelete, onMove, onPin, onArchive, onMemory };
+ const { onRename, onRegenerateTitle, onDelete, onMove, onPin, onSetMain, onArchive, onMemory } = threadRowActions(bot.id, dispatch);
+ return { onRename, onRegenerateTitle, onDelete, onMove, onPin, onSetMain, onArchive, onMemory };
}, [bot.id, dispatch]);
const side = useConversationSide(bot);
@@ -96,7 +96,7 @@ export function BotConversations({ bot }: { bot: Bot }) {
turnStartedAt: thread.turnStartedAt ?? undefined, queued: Boolean(state.pendingQueued[task.threadId]?.length),
};
});
- const conversations = orderedThreadList(threads.filter((task) => !isArchived(task) || task.threadId === bot.threadId));
+ const conversations = mainThreadFirst(orderedThreadList(threads.filter((task) => !isArchived(task) || task.threadId === bot.threadId)), bot.mainThreadId);
const archived = orderedThreadList(threads.filter((task) => isArchived(task) && task.threadId !== bot.threadId));
const needle = query.trim();
const collapsed = conversations.filter((task, index) => index < CONVERSATIONS_SHOWN || task.threadId === bot.threadId || task.threadId === bot.mainThreadId);
diff --git a/src/components/sidebar-thread-labels.test.ts b/src/components/sidebar-thread-labels.test.ts
index b6210a59a2..91b4ac0e6c 100644
--- a/src/components/sidebar-thread-labels.test.ts
+++ b/src/components/sidebar-thread-labels.test.ts
@@ -32,10 +32,10 @@ describe("a bot's threads under its sidebar row", () => {
expect(open.more).toBe(3);
});
- it("unfolded, keeps the main thread listed however old it is, in place of the oldest active one", () => {
+ it("unfolded, lists the main thread first, however old it is, in place of the oldest active one", () => {
const tasks = [thread("main", 30), thread("a", 1), thread("b", 2), thread("c", 3), thread("d", 4), thread("e", 5)];
const labels = threadLabels({ ...bot(tasks, "e"), mainThreadId: "main" }, {}, { unfolded: true, current: "e", rowThreadId: "e", now: NOW });
- expect(ids(labels)).toEqual(["a", "b", "e", "main"]);
+ expect(ids(labels)).toEqual(["main", "a", "b", "e"]);
expect(labels.more).toBe(2);
});
diff --git a/src/components/sidebar-thread-labels.ts b/src/components/sidebar-thread-labels.ts
index 4ae97fccba..0ee33fd8b6 100644
--- a/src/components/sidebar-thread-labels.ts
+++ b/src/components/sidebar-thread-labels.ts
@@ -66,7 +66,7 @@ export function threadLabels(
const recent = (task: LabelTask) => now - threadRecency(task) < ACTIVE_DAYS * DAY_MS;
const anchored = (task: LabelTask) => task.threadId === current || task.threadId === bot.mainThreadId;
const active = own.filter((task) => anchored(task) || labelStatus(task) !== null || recent(task))
- .sort((a, b) => threadRecency(b) - threadRecency(a));
+ .sort((a, b) => Number(b.threadId === bot.mainThreadId) - Number(a.threadId === bot.mainThreadId) || threadRecency(b) - threadRecency(a));
const others = active.filter((task) => !anchored(task)).slice(0, Math.max(0, ACTIVE_LIMIT - active.filter(anchored).length));
const shown = active.filter((task) => anchored(task) || others.includes(task));
const listed = new Set(shown.map((task) => task.threadId));