Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: keep the tray open when re-opening the shown thread or room thread; close it on a new chat
AdityaUmale6d8862fbb54a
diff --git a/src/state/store.test.ts b/src/state/store.test.tsindex 43fd5bc84c..278a743f45 100644--- a/src/state/store.test.ts+++ b/src/state/store.test.ts@@ -3177,9 +3177,18 @@ describe("notifications feed", () => {for (const action of switches) expect(reducer(pinned, action).notificationsOpen).toBe(true);});- it("re-selecting the open chat leaves the tray as it is", () => {- const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1" };+ it("re-selecting the open chat or its open thread leaves the tray as it is", () => {+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1",+ bots: [{ id: "bot-1", threadId: "t-1" }] as AppState["bots"], groups: [{ id: "room-1", threadId: "room-t" }] as AppState["groups"] };expect(reducer(open, { type: "select", id: "bot-1" }).notificationsOpen).toBe(true);+ expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-1" }).notificationsOpen).toBe(true);+ expect(reducer({ ...open, selectedId: "room-1" }, { type: "switchGroupTask", groupId: "room-1", threadId: "room-t" }).notificationsOpen).toBe(true);+ expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-2" }).notificationsOpen).toBe(false);+ });++ it("unpinned, starting a new chat closes it", () => {+ const open = reducer(initialState, { type: "toggleNotifications", open: true });+ expect(reducer(open, { type: "newTask", botId: "bot-1" }).notificationsOpen).toBe(false);});it("pinned, the feed survives Computer/Inspector/Activity/AppSettings opening", () => {diff --git a/src/state/store.tsx b/src/state/store.tsxindex 4ab897de8e..1463e5815d 100644--- a/src/state/store.tsx+++ b/src/state/store.tsx@@ -19,7 +19,7 @@ import { DATA_ROUTES, type DataSheet, type DataTable } from "../../shared/data-simport type { NotificationLogEntry } from "../../shared/notification";import { isNotificationFeedAction, reduceNotificationFeed, type NotificationFeedAction } from "./notification-feed";import { bumpThreadUpdatedAt, mergeTaskStamps, rewindThreadUpdatedAt } from "./thread-stamps";-import { botOpensTo, closeUnpinnedTray, openBot, openNotificationTarget, visibleNotificationThread, withRememberedTrayPin } from "./thread-navigation";+import { botOpensTo, closeTrayUnlessShown, closeUnpinnedTray, openBot, openNotificationTarget, visibleNotificationThread, withRememberedTrayPin } from "./thread-navigation";import { patchGroupTask } from "./thread-edits";import type { EngineInstall } from "./engine-install";import { optimisticMessageId, optimisticUserMessage, sendArrived, sendReconciled } from "./optimistic-send";@@ -1727,17 +1727,17 @@ export function reducer(state: AppState, action: Action): AppState {})), threadId, message.at, true);}case "switchGroupTask":- return closeUnpinnedTray(state);+ return closeTrayUnlessShown(state, action.groupId, action.threadId);case "deleteTask":case "newGroupTask":case "deleteGroupTask":case "regenerateTaskTitle":return state;case "newTask":- return action.cwd !== undefined ? state : { ...state, selectedId: action.botId, activeView: "chat" };+ return action.cwd !== undefined ? state : { ...closeUnpinnedTray(state), selectedId: action.botId, activeView: "chat" };case "switchTask": {const { [action.threadId]: _old, ...backgroundThreadEvents } = state.backgroundThreadEvents;- return updateBot({ ...closeUnpinnedTray(state), backgroundThreadEvents, selectedId: action.botId, activeView: "chat" }, action.botId, (bot) => ({ ...bot, switchingTo: action.threadId }));+ return updateBot({ ...closeTrayUnlessShown(state, action.botId, action.threadId), backgroundThreadEvents, selectedId: action.botId, activeView: "chat" }, action.botId, (bot) => ({ ...bot, switchingTo: action.threadId }));}case "switchTaskFailed":return updateBot(state, action.botId, (bot) => bot.switchingTo === action.threadId ? { ...bot, switchingTo: undefined } : bot);diff --git a/src/state/thread-navigation.ts b/src/state/thread-navigation.tsindex a7982d33ea..2b5f3c107a 100644--- a/src/state/thread-navigation.ts+++ b/src/state/thread-navigation.ts@@ -121,12 +121,16 @@ export function openThread(type NotificationTray = Pick<AppState, "notificationsOpen" | "notificationsPinned">;-/** Leaving a chat closes the notification tray unless the person pinned it. */export function closeUnpinnedTray<T extends NotificationTray>(state: T): T {return state.notificationsOpen && !state.notificationsPinned ? { ...state, notificationsOpen: false } : state;}-/** The tray pin is remembered per device, so it holds after a restart. */+/** Opening the chat already on screen is not leaving it. */+export function closeTrayUnlessShown(state: AppState, id: string, threadId: string): AppState {+ const shown = id === state.selectedId && [...state.bots, ...state.groups].find((chat) => chat.id === id)?.threadId === threadId;+ return shown ? state : closeUnpinnedTray(state);+}+export function withRememberedTrayPin<T extends NotificationTray>(state: T): T {return notificationTrayPinned() ? { ...state, notificationsPinned: true } : state;}