Skip to content

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

fix(sidebar): let the person open a running automation's thread (#4235)

Aditya Umalea72d920d1556
diff --git a/src/components/Sidebar.simple-mode.test.ts b/src/components/Sidebar.simple-mode.test.ts
index f0214ecdb7..549698c57b 100644
--- a/src/components/Sidebar.simple-mode.test.ts
+++ b/src/components/Sidebar.simple-mode.test.ts
@@ -545,6 +545,23 @@ describe("activity-only escape hatch", () => {
expect(markup).toContain('data-sidebar-activity-row="unread"');
});
+ it("offers a running routine's thread under its bot in both modes, also beside an open thread tree, and drops it once the run ends", () => {
+ const runner: Bot = { ...bot, unread: false, threadId: "main", tasks: [
+ { threadId: "main", title: "Main chat", createdAt: 1 },
+ { threadId: "run", title: "Morning report", createdAt: 2, routineRunId: "run-1", busy: true, activity: "working" },
+ ] };
+ const ended: Bot = { ...runner, tasks: runner.tasks!.map((task) => task.routineRunId ? { ...task, busy: false, activity: "idle" as const, unread: true } : task) };
+ // Searching "Main" opens the thread tree, which itself keeps routine runs out: the row is the only way in.
+ const rows = (candidate: Bot, query = "") => renderToStaticMarkup(createElement(BotListItem, rowProps("comfortable", candidate, query))).split('data-sidebar-activity-row="run"').length - 1;
+ for (const showThreads of [false, true]) for (const advanced of [false, true]) {
+ fixture.showThreads = showThreads;
+ fixture.advanced = advanced;
+ expect(rows(runner)).toBe(1);
+ expect(rows(ended)).toBe(0);
+ if (showThreads) expect(rows(runner, "Main")).toBe(1);
+ }
+ });
+
it("lists a reply in the thread a bot was left on, since its row opens the main thread", () => {
const left: Bot = { ...bot, threadId: "left-behind", mainThreadId: "main-chat", tasks: [
{ threadId: "left-behind", title: "Routine report", createdAt: 1, unread: true },
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 4e412e1fb3..e7c91a7c2f 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -84,7 +84,7 @@ import { isSidebarToggle } from "@/lib/keyboard-shortcuts";
import { SidebarRailSeparator, SimpleRailFooter } from "./SidebarSimpleRail";
import { useShowThreads } from "@/lib/thread-preferences";
import { useBotUnread } from "./unread-notice";
-import { attentionHasRunningWork, attentionJumpAction, attentionTriggerLabel, attentionUnpinAction, AttentionThreadRows, crossBotAttentionThreads, crossBotPinnedThreads, SidebarBotActivity, sidebarBotActivityTasks, sidebarBotStatus } from "./SidebarBotActivity";
+import { attentionHasRunningWork, attentionJumpAction, attentionTriggerLabel, attentionUnpinAction, AttentionThreadRows, crossBotAttentionThreads, crossBotPinnedThreads, runningRoutineRun, SidebarBotActivity, sidebarBotActivityTasks, sidebarBotStatus } from "./SidebarBotActivity";
import { SidebarNoBots, SidebarTileGrid } from "./SidebarTiles";
import { BotContextMenu } from "./SidebarBotMenu";
export { BotContextMenu };
@@ -913,7 +913,7 @@ export const BotListItem = memo(function BotListItem(props: BotRowProps) {
{advanced && !iconOnly && threadsOpen && hasThreadList && <BotThreadList {...props} hidden={!showThreads}
activityLabel={liveActivityLabel(last)}
query={bot.name.toLowerCase().includes(query.toLowerCase()) || bot.title.toLowerCase().includes(query.toLowerCase()) ? "" : query} />}
- {(advanced || (!iconOnly && (waiting || unread))) && !expanded && <SidebarBotActivity bot={bot} rowThreadId={selected ? bot.threadId : botOpensTo(bot, showThreads)} density={density} pendingQueued={pendingQueued} dispatch={dispatch} waitingOnly={!advanced} />}
+ {(advanced || (!iconOnly && (waiting || unread || bot.tasks?.some(runningRoutineRun)))) && <SidebarBotActivity bot={bot} rowThreadId={selected ? bot.threadId : botOpensTo(bot, showThreads)} density={density} pendingQueued={pendingQueued} dispatch={dispatch} waitingOnly={!advanced} runsOnly={expanded} />}
{showThreads && creatingProject && <BotProjectDialog bot={bot} onClose={() => setCreatingProject(false)} />}
</>
);
diff --git a/src/components/SidebarBotActivity.tsx b/src/components/SidebarBotActivity.tsx
index a97e2f4e9c..11fed5b1d1 100644
--- a/src/components/SidebarBotActivity.tsx
+++ b/src/components/SidebarBotActivity.tsx
@@ -20,6 +20,15 @@ export function sidebarBotActivityTasks(bot: Bot, queued: Record<string, unknown
.filter((task) => task.activity === "waiting-on-you" || task.activity === "working" || task.busy || task.waitingForTeammates === true || task.queued || task.unread);
}
+/** A routine run's thread stays out of the thread tree, but gets an activity row while it runs, so the person can open it and watch. */
+export function runningRoutineRun(task: Task): boolean {
+ return Boolean(task.routineRunId) && !isArchived(task) && (task.busy === true || task.activity === "working");
+}
+
+export function runningRoutineRuns(bot: Bot): Array<Task & { queued: boolean }> {
+ return orderedThreadList((bot.tasks ?? []).filter(runningRoutineRun).map((task) => ({ ...task, queued: false })));
+}
+
export function sidebarBotStatus(bot: Bot, queued: Record<string, unknown[]>) {
const tasks = sidebarBotActivityTasks(bot, queued);
const waiting = bot.activity === "waiting-on-you" || tasks.some((task) => task.activity === "waiting-on-you");
@@ -196,8 +205,10 @@ export function PinnedThreadRows({ entries, now, onJump, onUnpin }: { entries: A
</>;
}
-export function SidebarBotActivity({ bot, rowThreadId, density, pendingQueued, dispatch, waitingOnly = false }: { bot: Bot; rowThreadId: string; density: SidebarDensity; pendingQueued: AppState["pendingQueued"]; dispatch: Dispatch<Action>; waitingOnly?: boolean }) {
- const tasks = (waitingOnly ? threadsWaitingOnPerson : threadsWhenTreeHidden)(bot, pendingQueued).filter((task) => task.threadId !== rowThreadId);
+/** runsOnly: the open thread tree already lists the rest, so only a running routine's row is added. */
+export function SidebarBotActivity({ bot, rowThreadId, density, pendingQueued, dispatch, waitingOnly = false, runsOnly = false }: { bot: Bot; rowThreadId: string; density: SidebarDensity; pendingQueued: AppState["pendingQueued"]; dispatch: Dispatch<Action>; waitingOnly?: boolean; runsOnly?: boolean }) {
+ const others = runsOnly ? [] : (waitingOnly ? threadsWaitingOnPerson : threadsWhenTreeHidden)(bot, pendingQueued);
+ const tasks = [...others, ...runningRoutineRuns(bot)].filter((task) => task.threadId !== rowThreadId);
if (!tasks.length) return null;
const iconOnly = density === "icons";
return <div data-sidebar-bot-activity={bot.id} className={cn("mb-1 space-y-0.5", !iconOnly && "ml-6")}>