Skip to content

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

refactor: move the busy model menu out of ModelPicker.tsx

AdityaUmaledabf8aa2f0fe
diff --git a/src/components/ModelPicker.tsx b/src/components/ModelPicker.tsx
index b25f241b11..541b2157cd 100644
--- a/src/components/ModelPicker.tsx
+++ b/src/components/ModelPicker.tsx
@@ -3,7 +3,6 @@ import { createPortal } from "react-dom";
import { ChevronDown, ChevronLeft, ChevronRight, ChevronUp, KeyRound, Loader2, RefreshCw, X } from "lucide-react";
import { useStore, currentTaskBot, type Bot, type InstanceInfo, type ModelSelection } from "@/state/store";
import type { EffortLevel } from "../../shared/wire";
-import type { ModelVariantOption } from "../../shared/runtime-events";
import { filterCustomModels, partitionCustomModels, suggestedModels } from "@/lib/custom-models";
import { configuredModelInstances, isClaudeAccount, isCustomOnly, SIGN_IN_FAMILY_LABEL, signInFamily } from "@/lib/engine-rail";
import { modelName, simpleModelMenu } from "@/lib/simple-model-menu";
@@ -25,7 +24,8 @@ import { SimpleModelMenu, type SimpleThinking } from "./SimpleModelMenu";
import { apiKeysLabel, ClaudeAccountSelect, engineStatus, FollowBotModelRow, ModelEngineRail, ModelRow, ModelSearch } from "./ModelPickerFull";
import { MENU_LABEL, MENU_LINE, MENU_ROW, MENU_SEPARATOR, MENU_STROKE, MENU_TRAILING } from "./menu-recipe";
import { modelMenuKey, modelMenuPointerMove } from "./model-menu-keys";
-import { offersReasoning, useRefocusAfterPick, variantChoices } from "./model-picker-reasoning";
+import { lockedWhileBusy, offersReasoning, useRefocusAfterPick, variantChoices, variantLabel } from "./model-picker-reasoning";
+import { BusyModelMenu } from "./ModelPickerBusyMenu";
import { useAdvancedMode } from "@/lib/interface-mode";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
@@ -121,9 +121,6 @@ export function EffortRow({
);
}
-const variantLabel = (option: ModelVariantOption, driverKind?: string): string =>
- option.id === "default" && driverKind === "opencodeGo" ? t("model.variant.openCodeDefault") : option.label;
-
export function ModelVariantRow({ bot, threadId, updateBotDefault, className, label, compact = false, wide = false, quiet = false }: {
bot: Bot;
threadId?: string;
@@ -225,8 +222,7 @@ export function ModelPicker({
const { state, dispatch: storeDispatch, refreshInstances, refreshModels: refreshInstanceModels } = useStore();
const [open, setOpen] = useState(false);
const { bot, dispatch } = useAiSwitch({ bot: shown, threadId, contained, dispatch: storeDispatch, setOpen: (next) => (next ? openMenu() : setOpen(false)) });
- const busyInstance = bot.busy && !contained ? state.instances.find((instance) => instance.instanceId === bot.modelSelection.instanceId) : undefined;
- const locked = Boolean(bot.busy) && !(busyInstance && offersReasoning(state, busyInstance, bot.modelSelection, threadId ?? bot.threadId));
+ const locked = lockedWhileBusy(state, bot, contained, threadId);
const motion = useMenuMotion(open && !locked);
const [railId, setRailId] = useState<string | null>(null);
const [query, setQuery] = useState("");
@@ -972,25 +968,7 @@ export function ModelPicker({
} : { width: popoverWidth }}
className={cn("menu-surface z-[80] flex flex-col overflow-hidden", motion.className)}
>
- {bot.busy ? (
- <div data-model-busy className="flex flex-col py-1">
- <EffortRow
- compact
- bot={shown}
- threadId={threadId}
- updateBotDefault={busyUpdatesBotDefault}
- className="px-3.5 py-[5px]"
- label={<span className="text-[13px] leading-[18px] text-ink">{active?.capabilities?.modelVariants ? t("model.simple.reasoning") : t("model.section.effort")}</span>}
- />
- {threadId && (
- <p data-model-busy-scope className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">
- {t(busyUpdatesBotDefault ? "model.scope.botHelp" : "model.scope.threadHelp")}
- </p>
- )}
- <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t("model.reasoningNextTurn")}</p>
- <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t(threadId ? "model.threadBusy" : "model.busy")}</p>
- </div>
- ) : simpleMenu ? (
+ {bot.busy ? <BusyModelMenu bot={shown} threadId={threadId} updateBotDefault={busyUpdatesBotDefault} variants={Boolean(active?.capabilities?.modelVariants)} /> : simpleMenu ? (
<SimpleModelMenu
menu={simpleMenu}
query={query}
diff --git a/src/components/ModelPickerBusyMenu.tsx b/src/components/ModelPickerBusyMenu.tsx
new file mode 100644
index 0000000000..152f9a57c7
--- /dev/null
+++ b/src/components/ModelPickerBusyMenu.tsx
@@ -0,0 +1,26 @@
+import type { Bot } from "@/state/store";
+import { t } from "@/lib/i18n";
+import { EffortRow } from "./ModelPicker";
+
+/** The model menu while the bot works: only the reasoning level can change, for the next turn. */
+export function BusyModelMenu({ bot, threadId, updateBotDefault, variants }: { bot: Bot; threadId?: string; updateBotDefault: boolean; variants: boolean }) {
+ return (
+ <div data-model-busy className="flex flex-col py-1">
+ <EffortRow
+ compact
+ bot={bot}
+ threadId={threadId}
+ updateBotDefault={updateBotDefault}
+ className="px-3.5 py-[5px]"
+ label={<span className="text-[13px] leading-[18px] text-ink">{variants ? t("model.simple.reasoning") : t("model.section.effort")}</span>}
+ />
+ {threadId && (
+ <p data-model-busy-scope className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">
+ {t(updateBotDefault ? "model.scope.botHelp" : "model.scope.threadHelp")}
+ </p>
+ )}
+ <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t("model.reasoningNextTurn")}</p>
+ <p className="px-3.5 py-1 text-[12px] leading-4 text-ink-tertiary">{t(threadId ? "model.threadBusy" : "model.busy")}</p>
+ </div>
+ );
+}
diff --git a/src/components/model-picker-reasoning.ts b/src/components/model-picker-reasoning.ts
index a3847f3cea..ceec53fb67 100644
--- a/src/components/model-picker-reasoning.ts
+++ b/src/components/model-picker-reasoning.ts
@@ -1,5 +1,10 @@
import { useEffect, useRef, type RefObject } from "react";
-import type { AppState, InstanceInfo, ModelSelection } from "@/state/store";
+import type { AppState, Bot, InstanceInfo, ModelSelection } from "@/state/store";
+import type { ModelVariantOption } from "../../shared/runtime-events";
+import { t } from "@/lib/i18n";
+
+export const variantLabel = (option: ModelVariantOption, driverKind?: string): string =>
+ option.id === "default" && driverKind === "opencodeGo" ? t("model.variant.openCodeDefault") : option.label;
/** ACP variant ids are opaque; their model/session declares the available choices. */
export function variantChoices(state: Pick<AppState, "instances" | "modelVariantSessions">, selection: ModelSelection, threadId: string | undefined) {
@@ -19,6 +24,16 @@ export function offersReasoning(state: Pick<AppState, "instances" | "modelVarian
: Boolean(instance.capabilities?.effortLevels?.length);
}
+/**
+ * While a bot works its menu stays locked, unless it offers a reasoning row: the reasoning level is the one change
+ * allowed mid-turn, and it applies from the next turn.
+ */
+export function lockedWhileBusy(state: Pick<AppState, "instances" | "modelVariantSessions">, bot: Pick<Bot, "busy" | "modelSelection" | "threadId">, contained: boolean | undefined, threadId: string | undefined): boolean {
+ if (!bot.busy) return false;
+ const instance = contained ? undefined : state.instances.find((candidate) => candidate.instanceId === bot.modelSelection.instanceId);
+ return !(instance && offersReasoning(state, instance, bot.modelSelection, threadId ?? bot.threadId));
+}
+
/**
* Applying a pick, or clearing the search after one, can redraw or remove the focused row and drop focus out of
* the open menu. Call the returned function after either: focus comes back (to the thinking level when there is