Skip to content

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

fix(start-fresh): refuse while a thread switch is pending

VNATdev-ops5943a84aff06
diff --git a/src/App.start-fresh.test.ts b/src/App.start-fresh.test.ts
index 64f597ebea..32ff3f19bb 100644
--- a/src/App.start-fresh.test.ts
+++ b/src/App.start-fresh.test.ts
@@ -73,6 +73,7 @@ it("leaves the shortcut alone while busy, empty, already fresh, read-only or wit
{ bots: [{ ...bot, messages: [] }] },
{ bots: [{ ...bot, messages: [text, fresh], activeLeafId: "m2" }] },
{ bots: [{ ...bot, yourAccess: "view" as const }] },
+ { bots: [{ ...bot, switchingTo: "other" }] },
{ activeView: "routines" as const },
{ shortcutsOpen: true },
]) {
diff --git a/src/App.tsx b/src/App.tsx
index 9747ebd98d..67ce524bcc 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -265,7 +265,7 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {
const selected = state.bots.find((bot) => bot.id === state.selectedId && !bot.hidden);
if (
!e.repeat && selected && chatBot && state.activeView === "chat"
- && selected.yourAccess !== "view" && startFreshRefusal(chatBot) === null
+ && selected.yourAccess !== "view" && !chatBot.switchingTo && startFreshRefusal(chatBot) === null
&& !freshPending.current.has(selected.id)
) {
e.preventDefault();
diff --git a/src/components/ChatMoreMenu.test.ts b/src/components/ChatMoreMenu.test.ts
index 3048d17e43..1acc5923b7 100644
--- a/src/components/ChatMoreMenu.test.ts
+++ b/src/components/ChatMoreMenu.test.ts
@@ -115,6 +115,11 @@ describe("ChatMoreMenu, the round ⋯ for the bot panel", () => {
expect(menuOf(createElement(ChatMoreMenu, { bot: fresh })).items.find((one) => one.key === "start-fresh")!.disabled).toBe(true);
});
+ it("does not start fresh while a thread switch is pending", () => {
+ const item = menuOf(createElement(ChatMoreMenu, { bot: { ...bot, switchingTo: "other" } })).items.find((one) => one.key === "start-fresh")!;
+ expect(item.disabled).toBe(true);
+ });
+
it("starts a new thread with the bot and displays the platform shortcut hint", () => {
const win = globalThis.window as { ogb?: { platform?: string } };
try {
diff --git a/src/components/ChatMoreMenu.tsx b/src/components/ChatMoreMenu.tsx
index e2018d7b01..17ba53ab38 100644
--- a/src/components/ChatMoreMenu.tsx
+++ b/src/components/ChatMoreMenu.tsx
@@ -127,7 +127,7 @@ export function useChatMoreItems(profile: Bot, phoneHeader = false): { items: Si
key: "start-fresh",
label: t("chat.startFresh"),
icon: <RotateCcw size={16} />,
- disabled: bot.busy || contextAction.pending || !hasMessages || atFreshStart,
+ disabled: bot.busy || contextAction.pending || !hasMessages || atFreshStart || Boolean(bot.switchingTo),
title: t(bot.busy ? "contextWarning.busy" : "chat.startFresh.hint"),
trailing: <ShortcutHint id="start-fresh" />,
onSelect: () => contextAction.run(`/api/bots/${profile.id}/start-fresh`, { threadId: bot.threadId }),
diff --git a/src/components/ComposerContextMenu.test.ts b/src/components/ComposerContextMenu.test.ts
index 304168c7f3..e56979f62e 100644
--- a/src/components/ComposerContextMenu.test.ts
+++ b/src/components/ComposerContextMenu.test.ts
@@ -124,6 +124,12 @@ describe("the composer's context button", () => {
expect(panel()!.querySelector<HTMLButtonElement>("[data-context-fresh]")!.disabled).toBe(false);
});
+ it("offers neither action while a thread switch is pending", async () => {
+ await render({ bot: chat({ tokens: 136_000, window: 200_000 }, { switchingTo: "t2" }) });
+ await press(trigger());
+ expect([...panel()!.querySelectorAll("button")].map((button) => button.disabled)).toEqual([true, true]);
+ });
+
it("takes the focus when it opens, on no action yet, and gives it back to the button on Escape", async () => {
await render({ bot: chat({ tokens: 136_000, window: 200_000 }) });
trigger().focus();
diff --git a/src/components/ComposerContextMenu.tsx b/src/components/ComposerContextMenu.tsx
index cbf04b85a5..b6e798d02c 100644
--- a/src/components/ComposerContextMenu.tsx
+++ b/src/components/ComposerContextMenu.tsx
@@ -147,7 +147,7 @@ function ChatContext({ bot, reading, breakdown, detailed, onDone }: { bot: Bot;
const messages = visibleMessages(bot);
const rows = contextRows(breakdown);
const atFreshStart = messages.at(-1)?.compaction?.fresh === true;
- const idle = !bot.busy && !compact.pending && !fresh.pending && messages.length > 0 && !atFreshStart;
+ const idle = !bot.busy && !compact.pending && !fresh.pending && messages.length > 0 && !atFreshStart && !bot.switchingTo;
return (
<>
<div className={MENU_LABEL}>{t("contextMenu.title")}</div>