A desktop coding agent with free access to frontier models.
TypeScript
feat: switch models within one provider in a chat
Samrat Talukdar4842ffe0168c
diff --git a/apps/app/src/app/lib/omnirush-server.ts b/apps/app/src/app/lib/omnirush-server.tsindex b2b2f4b9..ef778f57 100644--- a/apps/app/src/app/lib/omnirush-server.ts+++ b/apps/app/src/app/lib/omnirush-server.ts@@ -611,7 +611,7 @@ export type OmniRushSubagentModelState = {/** Whether an omnirush.ai account is signed in (its models can run). */signedIn: boolean;/** The account's model catalog, in the backend's order. */- models: Array<{ id: string; name: string; family: string | null; default: boolean; efforts: string[]; modes?: Array<"native" | "box"> }>;+ models: Array<{ id: string; name: string; family: string | null; default: boolean; efforts: string[]; modes?: Array<"native" | "box">; switch_group?: string }>;};export type OmniRushDesktopCloudSyncChange = {diff --git a/apps/app/src/react-app/domains/session/surface/claude-models.ts b/apps/app/src/react-app/domains/session/surface/claude-models.tsindex 81c41e2e..ec05f566 100644--- a/apps/app/src/react-app/domains/session/surface/claude-models.ts+++ b/apps/app/src/react-app/domains/session/surface/claude-models.ts@@ -69,19 +69,20 @@ export type ModelPick =/*** What picking `next` does. `current` is the chat's model and `started` says it- * already ran (its model is fixed: one model per chat). An unavailable Claude- * model is explained first, wherever it is picked; a different model in a- * started chat offers a new chat; in a fresh chat a Claude model opens Claude+ * already ran (its provider is fixed). An unavailable Claude model is explained+ * first, wherever it is picked; a model of another provider in a started chat+ * offers a new chat, one of its provider (`switchable`, model-modes.ts+ * switchableModel) is switched to; in a fresh chat a Claude model opens Claude* and any other model is simply switched to.*/-export function decideModelPick(input: { next: ModelRef; current: ModelRef | null; started: boolean; claude: ClaudeModelsState }): ModelPick {- const { next, current, started, claude } = input;+export function decideModelPick(input: { next: ModelRef; current: ModelRef | null; started: boolean; claude: ClaudeModelsState; switchable?: (current: ModelRef, next: ModelRef) => boolean }): ModelPick {+ const { next, current, started, claude, switchable } = input;const same = Boolean(current && current.providerID === next.providerID && current.modelID === next.modelID);if (same) return { kind: "same" };if (isClaudeModel(next) && !claude.models.includes(next.modelID)) {return { kind: "unavailable", message: claudeUnavailableMessage(claudeModelName(claude, next.modelID), claude.reason) };}- if (started && current) return { kind: "new_chat" };+ if (started && current && !(switchable?.(current, next) ?? false)) return { kind: "new_chat" };return isClaudeModel(next) ? { kind: "claude" } : { kind: "switch" };}diff --git a/apps/app/src/react-app/domains/session/surface/model-modes.ts b/apps/app/src/react-app/domains/session/surface/model-modes.tsindex 8dbed3df..1696fbca 100644--- a/apps/app/src/react-app/domains/session/surface/model-modes.ts+++ b/apps/app/src/react-app/domains/session/surface/model-modes.ts@@ -51,6 +51,19 @@ export function modeSwitchNote(models: CatalogModels | undefined, mode: Mode, frreturn `${name(from)} isn't available ${mode === "box" ? "in sandbox projects" : "outside the sandbox"}. Using ${name(to)} here.`;}+/**+ * Whether a started chat on `current` may go on with `next`: two catalog+ * models of one provider (`switch_group`, the server's grouping). A model with+ * no group (Claude, an older server) is a new chat. Mirrors+ * apps/server/src/model-modes/strict-sessions.mjs switchableModels.+ */+export function switchableModel(models: CatalogModels | undefined, current: ModelRef, next: ModelRef): boolean {+ if (current.providerID !== "omnirush" || next.providerID !== "omnirush") return false;+ const group = (id: string) => models?.find((entry) => entry.id === id)?.switch_group ?? null;+ const first = group(current.modelID);+ return first !== null && first === group(next.modelID);+}+/** "This chat runs on Kimi K3.1 Pro. Start a new chat to use GPT 6 Astra." */export function fixedModelNote(models: CatalogModels | undefined, current: ModelRef, wanted: ModelRef): string {const name = (ref: ModelRef) => models?.find((entry) => entry.id === ref.modelID)?.name ?? ref.modelID;@@ -112,6 +125,8 @@ export function useProjectModelModes(fallback: (model: ModelRef | null | undefined) => modeFallbackModel(models, mode, model),note: (from: ModelRef, to: ModelRef) => modeSwitchNote(models, mode ?? "native", from, to),fixedNote: (current: ModelRef, wanted: ModelRef) => fixedModelNote(models, current, wanted),+ /** A started chat may go on with `next` (same provider). */+ switchable: (current: ModelRef, next: ModelRef) => switchableModel(models, current, next),chatNote: (model: ModelRef) => chatModeNote(models, mode ?? "native", model),}), [mode, models]);useEffect(() => {diff --git a/apps/app/src/react-app/shell/session-route.tsx b/apps/app/src/react-app/shell/session-route.tsxindex ea084720..88f53857 100644--- a/apps/app/src/react-app/shell/session-route.tsx+++ b/apps/app/src/react-app/shell/session-route.tsx@@ -2865,7 +2865,7 @@ export function SessionRoute() {};const handleModelPick = (next: ModelRef, sessionId: string | null): boolean => {const current = sessionId ? getSessionModelSelection(sessionId)?.model ?? null : null;- const pick = decideModelPick({ next, current, started: Boolean(sessionId && chatStarted(sessionId)), claude: useClaudeModels.getState() });+ const pick = decideModelPick({ next, current, started: Boolean(sessionId && chatStarted(sessionId)), claude: useClaudeModels.getState(), switchable: modelModesRef.current.switchable });if (pick.kind === "unavailable") toast(pick.message, { id: `claude-unavailable:${next.modelID}` });else if (pick.kind === "new_chat" && current) setNewChatOffer({ next, current });else if (pick.kind === "claude") openClaudeChat(next);@@ -2897,7 +2897,7 @@ export function SessionRoute() {behavior?: { value: string | null },) => {const explicitBehavior = behavior !== undefined;- // One model per chat (a started chat offers a new one), and Claude opens its own chat.+ // One provider per chat (a started chat offers a new one for another provider), and Claude opens its own chat.if (modelPickRef.current(next, targetSessionId)) return;useModelCollectionsStore.getState().recordRecent(next);if (targetSessionId) {diff --git a/apps/app/tests/claude-models.test.ts b/apps/app/tests/claude-models.test.tsindex 70a50b15..356361e3 100644--- a/apps/app/tests/claude-models.test.ts+++ b/apps/app/tests/claude-models.test.ts@@ -10,6 +10,8 @@ import {setUpClaudeSandbox,type ClaudeModelsState,} from "../src/react-app/domains/session/surface/claude-models";+import { switchableModel } from "../src/react-app/domains/session/surface/model-modes";+import { switchableModels as sharedSwitchable } from "../../server/src/model-modes/strict-sessions.mjs";const opus = { providerID: "omnirush", modelID: "claude-opus-5-5" };const sonnet = { providerID: "omnirush", modelID: "claude-sonnet-5-5" };@@ -57,6 +59,30 @@ describe("popup decision", () => {expect(decideModelPick({ next: astra, current: astra, started: true, claude: allowed })).toEqual({ kind: "same" });});+ test("a started chat switches within its provider without the popup; another provider or no group offers a new chat", () => {+ const models = [+ { id: "gpt-6-astra", name: "GPT 6 Astra", family: "OpenAI", default: true, efforts: [], switch_group: "openai" },+ { id: "gpt-6.1-sol", name: "GPT 6.1 Sol", family: "OpenAI", default: false, efforts: [], switch_group: "openai" },+ { id: "gpt-6-sol", name: "GPT 6 Sol", family: "OpenAI", default: false, efforts: [], switch_group: "openai" },+ { id: "kimi-k3.1-pro", name: "Kimi K3.1 Pro", family: "Kimi", default: false, efforts: [], switch_group: "kimi" },+ { id: "gpt-old", name: "Old", family: "OpenAI", default: false, efforts: [] },+ ];+ const switchable = (current: typeof astra, next: typeof astra) => switchableModel(models, current, next);+ const sol6 = { providerID: "omnirush", modelID: "gpt-6-sol" };+ for (const [current, next] of [[astra, sol], [sol, sol6], [sol6, astra]]) {+ expect(decideModelPick({ next, current, started: true, claude: allowed, switchable })).toEqual({ kind: "switch" });+ }+ for (const next of [{ providerID: "omnirush", modelID: "kimi-k3.1-pro" }, { providerID: "omnirush", modelID: "gpt-old" }, sonnet, { providerID: "openai", modelID: "gpt-6.1-sol" }]) {+ expect(decideModelPick({ next, current: astra, started: true, claude: allowed, switchable })).toEqual({ kind: "new_chat" });+ }+ // The same rule as the shared module's (apps/server/src/model-modes/strict-sessions.mjs).+ for (const a of models) for (const b of models) {+ expect(switchableModel(models, { providerID: "omnirush", modelID: a.id }, { providerID: "omnirush", modelID: b.id }) || a.id === b.id).toBe(sharedSwitchable(models, a.id, b.id));+ }+ // No group known (an older server): a new chat.+ expect(decideModelPick({ next: sol, current: astra, started: true, claude: allowed, switchable: (c, n) => switchableModel(undefined, c, n) })).toEqual({ kind: "new_chat" });+ });+test("an account without Claude is told plainly, wherever it picks, with no switch", () => {for (const started of [false, true]) {expect(decideModelPick({ next: sonnet, current: astra, started, claude: denied }))diff --git a/apps/server/src/model-modes/PARITY.sha256 b/apps/server/src/model-modes/PARITY.sha256index b8386d41..3aa903f8 100644--- a/apps/server/src/model-modes/PARITY.sha256+++ b/apps/server/src/model-modes/PARITY.sha256@@ -2,5 +2,5 @@# A change to one must be ported to the other and this list updated in both.609bbc9cb508b4f79295e0b2f1f4707bd1facbee83835d5db7eac02fa088f43b model-modes.mjsef8a96d1e71ea3f5f3ab7a96796d042c009d90cc2896e7132b8dfc4486540699 model-modes.d.mts-41d945bb9aab9be941dd1840a61384982a37b986e7d2e7306c57d32ffc2b6e2c strict-sessions.mjs-7c98a499302e9d32799998f6960f0f5f3b4ff47b85fe24c5cc54bbfa084df54d strict-sessions.d.mts+8daa858a3791a3413a9356ff0668668ef13a2e905e6b6123efc81c93dc0f0a96 strict-sessions.mjs+dea5a6cadd25adfea5419ad1c9b877485cbdaaa20313e4838d49f5e91a4f7393 strict-sessions.d.mtsdiff --git a/apps/server/src/model-modes/model-modes.test.ts b/apps/server/src/model-modes/model-modes.test.tsindex f3b2ac6d..7b9572aa 100644--- a/apps/server/src/model-modes/model-modes.test.ts+++ b/apps/server/src/model-modes/model-modes.test.ts@@ -11,6 +11,7 @@ import path from "node:path";import { OmniRushGatewayBroker } from "../omnirush-gateway-broker.js";import { sanitizeOmniRushModelCatalog } from "../omnirush-model-catalog.js";import { modelAllowedIn, modelForMode, modelModes, notInModeMessage, projectMode } from "./model-modes.mjs";+import { bindingConflictMessage, switchableModels } from "./strict-sessions.mjs";const CATALOG = sanitizeOmniRushModelCatalog({data: [@@ -122,6 +123,39 @@ describe("model modes", () => {expect(calls.map((c) => c.model)).toEqual(["kimi-k3.1-pro", "kimi-k3.1-pro", "kimi-k3.1-pro", "gpt-6-astra"]);});+ test("broker: a chat switches between the models of one provider; another provider or no group is refused", async () => {+ const catalog = sanitizeOmniRushModelCatalog({ data: [+ { id: "gpt-6-astra", default: true, switch_group: "openai" }, { id: "gpt-6.1-sol", switch_group: "openai" }, { id: "gpt-6-sol", switch_group: "openai" },+ { id: "kimi-k3.1-pro", switch_group: "kimi" }, { id: "gpt-old" },+ ] })!;+ expect(catalog.find((m) => m.id === "gpt-6.1-sol")?.switch_group).toBe("openai");+ expect(catalog.find((m) => m.id === "gpt-old")?.switch_group).toBeUndefined();+ expect(switchableModels(catalog, "gpt-6-astra", "gpt-6.1-sol") && switchableModels(catalog, "gpt-6.1-sol", "gpt-6-sol")).toBe(true);+ for (const other of ["kimi-k3.1-pro", "gpt-old", "claude-opus-5-5"]) expect(switchableModels(catalog, "gpt-6-astra", other)).toBe(false);+ expect(switchableModels(null, "gpt-6-astra", "gpt-6.1-sol")).toBe(false);+ expect(bindingConflictMessage({ model: "gpt-6-astra", mode: "box" }, "gpt-6.1-sol", "native")).toBe("This chat runs in the sandbox. Start a new chat to run outside it.");+ const calls: Call[] = [];+ const b = new OmniRushGatewayBroker({+ credentials: { gatewayUrl: "https://gateway.example/omnirush/v1", accessToken: "access-token", refreshToken: "refresh-token" },+ engineToken: "local-engine-token",+ switchable: async (bound, asked) => switchableModels(catalog, bound, asked),+ fetch: async (input, init) => {+ const raw = init?.body;+ calls.push({ model: JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw as ArrayBuffer)).model, box: null, path: new URL(String(input)).pathname });+ return Response.json({ output: [] });+ },+ });+ // Each request goes up on the model it named, a sub-agent's too.+ for (const model of ["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol", "gpt-6-astra"]) expect((await b.handle(request({ model }, { "x-omnirush-session-id": "ses_sw" }), "responses")).status).toBe(200);+ expect((await b.handle(request({ model: "gpt-6.1-sol" }, { "x-omnirush-session-id": "ses_kid", "x-parent-session-id": "ses_sw" }), "responses")).status).toBe(200);+ for (const model of ["kimi-k3.1-pro", "gpt-old"]) {+ const refused = await b.handle(request({ model }, { "x-omnirush-session-id": "ses_sw" }), "responses");+ expect(refused.status).toBe(400);+ expect(((await refused.json()) as { error: { code: string; message: string } }).error).toMatchObject({ code: "session_model_fixed", message: `This chat runs on gpt-6-astra. Start a new chat to use ${model}.` });+ }+ expect(calls.map((c) => c.model)).toEqual(["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol", "gpt-6-astra", "gpt-6.1-sol"]);+ });+test("broker: a new process keeps saved model pins and refuses corrupt pins", async () => {const dir = mkdtempSync(path.join(tmpdir(), "model-pins-"));const file = path.join(dir, "chat-models.json");diff --git a/apps/server/src/model-modes/strict-sessions.d.mts b/apps/server/src/model-modes/strict-sessions.d.mtsindex f6349777..5e557e2c 100644--- a/apps/server/src/model-modes/strict-sessions.d.mts+++ b/apps/server/src/model-modes/strict-sessions.d.mts@@ -23,6 +23,8 @@ export type StrictSessions = { mode: "observe" | "enforce"; path: string; headerexport type BindPost = (path: string, body: Record<string, unknown>, signal: AbortSignal) => Promise<{ status: number; body: unknown }>;export function strictSessions(capabilities: unknown): StrictSessions | null;-export function bindingConflictMessage(binding: unknown, model: string): string;+export function switchGroup(entry: unknown): string | null;+export function switchableModels(catalog: unknown, bound: string, asked: string): boolean;+export function bindingConflictMessage(binding: unknown, model: string, mode?: string | null): string;export function modelUsedMessage(modelsUsed: unknown, model: string): string;export function sessionBinder(post: BindPost, options?: { timeoutMs?: number }): ((chat: BindChat) => Promise<BindOutcome>) & { forget(id: string): void };diff --git a/apps/server/src/model-modes/strict-sessions.mjs b/apps/server/src/model-modes/strict-sessions.mjsindex 92b8c414..2b6e48ab 100644--- a/apps/server/src/model-modes/strict-sessions.mjs+++ b/apps/server/src/model-modes/strict-sessions.mjs@@ -18,6 +18,11 @@// 1, so the gateway can bind it on the spot when the explicit bind failed.// No `strict_sessions` (an older server): no bind, no header.//+// A chat may switch between the models of one provider (GET /omnirush/v1/models+// `switch_group`, the server's grouping): the server binds the chat to its+// first model and serves each request on the model it names. A model with no+// group (Claude, an older server) is a new chat (`switchableModels`).+//// The same file ships in omnirush-cli (src/model-modes/) and omnirush-gui// (apps/server/src/model-modes/); PARITY.sha256 lists it in both. No imports.@@ -55,10 +60,37 @@ export function strictSessions(capabilities) {};}-/** The plain refusal of a request on another model or mode than the chat's binding. */-export function bindingConflictMessage(binding, model) {+const GROUP = /^[a-z0-9][a-z0-9_-]{0,31}$/;++/** A catalog entry's `switch_group` (the provider a chat may switch within), else null. */+export function switchGroup(entry) {+ const group = entry && typeof entry === "object" ? entry.switch_group : null;+ return typeof group === "string" && GROUP.test(group) ? group : null;+}++/**+ * Whether a chat on `bound` may go on with `asked` (catalog ids): the same+ * model, or two entries of `catalog` with one `switch_group`. An id not in+ * the catalog, or one without a group, is only itself.+ */+export function switchableModels(catalog, bound, asked) {+ if (bound === asked) return true;+ const list = Array.isArray(catalog) ? catalog : [];+ const group = (id) => switchGroup(list.find((entry) => entry && entry.id === id));+ const first = group(bound);+ return first !== null && first === group(asked);+}++/**+ * The plain refusal of a request on another model or mode than the chat's+ * binding. Given the chat's `mode`, a binding in another mode is the mode's+ * refusal: the server allows a model of the binding's provider, so the mode is+ * what it refused then.+ */+export function bindingConflictMessage(binding, model, mode = null) {const bound = binding && typeof binding === "object" ? binding : {};- if (typeof bound.model === "string" && bound.model && bound.model !== model) return `This chat runs on ${bound.model}. Start a new chat to use ${model}.`;+ const modeOff = typeof mode === "string" && typeof bound.mode === "string" && bound.mode !== mode;+ if (typeof bound.model === "string" && bound.model && bound.model !== model && !modeOff) return `This chat runs on ${bound.model}. Start a new chat to use ${model}.`;if (bound.mode === "box") return "This chat runs in the sandbox. Start a new chat to run outside it.";if (bound.mode === "native") return "This chat runs outside the sandbox. Start a new chat to run in it.";return "This chat runs on another model. Start a new chat to use this one.";@@ -123,7 +155,7 @@ export function sessionBinder(post, { timeoutMs = BIND_TIMEOUT_MS } = {}) {const status = answer ? answer.status : 0;const detail = detailOf(answer);if (detail === SESSION_BINDING_CONFLICT) {- return { refused: { code: SESSION_BINDING_CONFLICT, message: bindingConflictMessage(answer.body.binding, chat.model), retry: false } };+ return { refused: { code: SESSION_BINDING_CONFLICT, message: bindingConflictMessage(answer.body.binding, chat.model, chat.mode), retry: false } };}if (detail === SESSION_MODEL_USED) {return { refused: { code: SESSION_MODEL_USED, message: modelUsedMessage(answer.body.models_used, chat.model), retry: false } };diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex 13e411b3..179d2f0b 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -89,6 +89,12 @@ type BrokerOptions = {* is never sent. Unset: every model goes to the gateway, which judges.*/modelInMode?: (model: string, box: boolean) => boolean | Promise<boolean>;+ /**+ * Whether a chat on `bound` may go on with `asked`: two catalog models of+ * one provider (the catalog's switch_group, model-modes/strict-sessions.mjs).+ * Unset: only the same model.+ */+ switchable?: (bound: string, asked: string) => boolean | Promise<boolean>;/** The pause before a busy picked model is tried once more; tests shrink it. */subagentRetryDelayMs?: number;/** Whether a picked sub-agent model is in its refusal cooldown (sent straight to the main model). */@@ -1302,6 +1308,7 @@ export class OmniRushGatewayBroker {private readonly subagentRetryDelayMs: number;private readonly subagentModelRefused?: (model: string) => boolean;private readonly modelInMode?: BrokerOptions["modelInMode"];+ private readonly switchable: NonNullable<BrokerOptions["switchable"]>;/*** Chats seen with X-OmniRush-Box (the box engine plugin marks a box chat's* requests): a later request of one without the mark (a compaction, a side@@ -1391,6 +1398,7 @@ export class OmniRushGatewayBroker {this.subagentRetryDelayMs = options.subagentRetryDelayMs ?? SUBAGENT_RETRY_DELAY_MS;this.subagentModelRefused = options.subagentModelRefused;this.modelInMode = options.modelInMode;+ this.switchable = options.switchable ?? ((bound, asked) => bound === asked);this.onUpdateSignal = options.onUpdateSignal;this.chatPin = options.chatPin;this.bindSession = this.makeBinder(options.bindTimeoutMs);@@ -2090,7 +2098,7 @@ export class OmniRushGatewayBroker {}}// One model per chat: a main chat's agent request on another model than its first is refused here.- const fixed = this.fixedModelRefusal(request, path, body);+ const fixed = await this.fixedModelRefusal(request, path, body);if (fixed) return fixed;// The last capabilities answer's switch (this server's, kept on disk until it answers): a model request never waits for one.// The switch not known yet (capabilities failed, nothing kept): asked again, bounded, before this request.@@ -2174,10 +2182,12 @@ export class OmniRushGatewayBroker {}/**- * Every context-bearing request keeps the chat's model, including summaries,- * compaction and children. A different model never reaches the gateway.+ * Every context-bearing request keeps the chat's provider, including+ * summaries, compaction and children: a model of another provider never+ * reaches the gateway. One of the same provider (`switchable`) goes as asked;+ * the chat's pin keeps its first model.*/- private fixedModelRefusal(request: Request, path: string, body: ArrayBuffer | string | undefined): Response | null {+ private async fixedModelRefusal(request: Request, path: string, body: ArrayBuffer | string | undefined): Promise<Response | null> {if (body === undefined || (path !== "responses" && path !== "responses/compact")) return null;const session = request.headers.get("x-omnirush-session-id");if (!session) return request.headers.has(PARENT_SESSION_HEADER) || request.headers.has(SUBAGENT_ROOT_SESSION_HEADER)@@ -2193,7 +2203,8 @@ export class OmniRushGatewayBroker {const model = parsed.model.replace(/^omnirush\//, "");const parents = [request.headers.get(SUBAGENT_ROOT_SESSION_HEADER), request.headers.get(PARENT_SESSION_HEADER)].filter((id): id is string => Boolean(id));const pins = [session, ...parents].map(id => this.sessionModels.get(id)).filter((pin): pin is string => Boolean(pin));- const first = pins.find(pin => pin !== model);+ let first: string | undefined;+ for (const pin of pins) if (!(await this.switchable(pin, model))) { first = pin; break; }if (!first && !parents.some(id => !this.sessionModels.has(id))) {if (this.sessionModels.has(session)) return null;if (this.sessionModelsFile) {@@ -2205,7 +2216,7 @@ export class OmniRushGatewayBroker {this.sessionModels.set(session, model);return null;}- this.log?.("info", "omnirush.ai chat model change refused (one model per chat)", { first, model });+ this.log?.("info", "omnirush.ai chat model change refused (another provider)", { first, model });return Response.json({ detail: SESSION_MODEL_FIXED, error: { type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: first ? `This chat runs on ${first}. Start a new chat to use ${model}.` : "Resume the parent chat before continuing this sub-agent; its fixed model is unavailable." } }, { status: 400, headers: { "x-should-retry": "false" } });}diff --git a/apps/server/src/omnirush-model-catalog.ts b/apps/server/src/omnirush-model-catalog.tsindex f4ed14a9..7f8f4af9 100644--- a/apps/server/src/omnirush-model-catalog.ts+++ b/apps/server/src/omnirush-model-catalog.ts@@ -22,6 +22,7 @@ import type { ServerConfig } from "./types.js";import { writeFileAtomic } from "./atomic-write.js";import { modelHasWebSearch, type WebSearchSwitch } from "./web-search.js";import { modelModes, type ModelMode } from "./model-modes/model-modes.mjs";+import { switchGroup } from "./model-modes/strict-sessions.mjs";/** Every effort a catalog model may list, lowest first. */export const OMNIRUSH_MODEL_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const;@@ -52,6 +53,8 @@ export type OmniRushCatalogModel = {};/** Where the model may run (model-modes/); absent means both. Kept only when the backend lists it. */modes?: ModelMode[];+ /** The provider a chat may switch within (model-modes/strict-sessions.mjs); absent: none, a new chat. */+ switch_group?: string;};/** Models in the backend's order, default first. Never empty. */@@ -160,6 +163,7 @@ function sanitizeModel(raw: unknown): OmniRushCatalogModel | null {file_input: flag("file_input"),},...(Array.isArray(raw.modes) ? { modes: modelModes(raw) } : {}),+ ...(switchGroup(raw) ? { switch_group: switchGroup(raw)! } : {}),};}diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex df32ddae..6e73c810 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -214,6 +214,7 @@ import { isOmniRushUiMcpRegistryEntry } from "./omnirush-ui-mcp-command.js";import { describeIgnored, type McpAllowEntry } from "./mcp-allow/mcp-allow.mjs";import { omnirushModelWantsReasoningSummary, readOmniRushModelCatalog } from "./omnirush-model-catalog.js";import { modelAllowedIn, modelModes, projectMode, serverModelStart } from "./model-modes/model-modes.mjs";+import { switchableModels } from "./model-modes/strict-sessions.mjs";import { serverLocalBox } from "./box/launch.js";import {SUBAGENT_MODEL_FALLBACK_TRACE,@@ -1290,6 +1291,8 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {const entry = (await readOmniRushModelCatalog(config)).find((candidate) => candidate.id === model);return !entry || modelAllowedIn(entry, projectMode(box));},+ // A chat may switch between the models of one provider (the catalog's switch_group).+ switchable: async (bound, asked) => switchableModels(await readOmniRushModelCatalog(config), bound, asked),// Strict sessions: a chat's bind names the box revision it started under.chatPin: (sessionId) => boxServiceFor(config).chatPin(sessionId),// The capture policy the server stored for a chat: its pin and its uploads keep that one.@@ -4624,6 +4627,8 @@ function createRoutes(efforts: model.reasoning_levels,// Where the model may run: "native" (projects without the sandbox), "box" (sandbox projects).modes: modelModes(model),+ // The provider a chat may switch within (model-modes/strict-sessions.mjs); none: a new chat.+ ...(model.switch_group ? { switch_group: model.switch_group } : {}),})),});});