Skip to content

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

fix(routing): preserve configured route for continuations and unshared providers

Prit Patelc279806439dc
diff --git a/server/turn-route.test.ts b/server/turn-route.test.ts
index 04c119091f..be8c005525 100644
--- a/server/turn-route.test.ts
+++ b/server/turn-route.test.ts
@@ -40,6 +40,16 @@ describe("classifyTurn", () => {
expect(classifyTurn({ text: "and the other one?", attachments: 0, priorTurnUsedTools: true })).toBe("complex");
expect(classifyTurn({ text: "thanks!", attachments: 0, priorTurnUsedTools: true })).toBe("simple");
});
+
+ it.each([
+ "Продолжи",
+ "продолжай",
+ "Продолжайте, пожалуйста",
+ "давай дальше",
+ "дальше",
+ ])("a Russian continuation is complex: %s", (text) => {
+ expect(classifyTurn({ ...plain, text })).toBe("complex");
+ });
});
const claude: ModelCatalog = {
@@ -78,6 +88,41 @@ describe("fastModelFor", () => {
expect(fastModelFor(claude, "claude-haiku-4-5")).toBe("claude-haiku-4-5");
expect(fastModelFor(undefined, "claude-opus-5")).toBeUndefined();
});
+
+ it("does not treat two absent provider identities from different model families as compatible", () => {
+ const catalog: ModelCatalog = {
+ default: "gpt-6.1-sol",
+ options: [
+ { id: "gpt-6.1-sol", label: "GPT-6.1-Sol" },
+ { id: "glm-5.3-flash", label: "GLM-5.3-Flash" },
+ ],
+ };
+ expect(fastModelFor(catalog, "gpt-6.1-sol")).toBeUndefined();
+ });
+
+ it("does not guess a provider when the selected model is absent from the catalog", () => {
+ expect(fastModelFor(mixed, "unlisted-model")).toBeUndefined();
+ });
+
+ it("does not substitute a fast model for a custom model", () => {
+ expect(fastModelFor({
+ default: "custom-model",
+ options: [
+ { id: "custom-model", label: "Custom", provider: "openai", custom: true },
+ { id: "gpt-5.4-mini", label: "Mini", provider: "openai" },
+ ],
+ }, "custom-model")).toBeUndefined();
+ });
+
+ it("does not substitute an unqualified candidate for a provider-tagged model", () => {
+ expect(fastModelFor({
+ default: "gpt-6.1-sol",
+ options: [
+ { id: "gpt-6.1-sol", label: "GPT", provider: "openai" },
+ { id: "glm-5.3-flash", label: "GLM Flash" },
+ ],
+ }, "gpt-6.1-sol")).toBeUndefined();
+ });
});
describe("routeTurn", () => {
@@ -157,4 +202,27 @@ describe("routeDirectTurn", () => {
expect(routeDirectTurn(bot, { modelSelection: bot.modelSelection }, [], message, instance, false).tier).toBeNull();
expect(routeDirectTurn(bot, {}, [], message, instance, true).tier).toBeNull();
});
+
+ it.each(["Продолжи", "продолжай", "давай дальше", "дальше"])(
+ "keeps a Russian continuation on the configured model and effort: %s",
+ (text) => {
+ const codexBot = { replyStyle: "conversational" as const, modelSelection: { instanceId: "codex", model: "gpt-6.1-sol", effort: "high" as const } };
+ const codexInstance = {
+ models: {
+ default: "gpt-6.1-sol",
+ options: [
+ { id: "gpt-6.1-sol", label: "GPT-6.1-Sol" },
+ { id: "glm-5.3-flash", label: "GLM-5.3-Flash" },
+ ],
+ },
+ adapter: { capabilities: { effortLevels: ["low", "high"] as const } },
+ };
+ expect(routeDirectTurn(codexBot, {}, [{ role: "bot", kind: "compaction" }], { text, images: [] }, codexInstance, false)).toEqual({
+ tier: "complex",
+ model: "gpt-6.1-sol",
+ effort: "high",
+ variant: undefined,
+ });
+ },
+ );
});
diff --git a/server/turn-route.ts b/server/turn-route.ts
index 5b7de62130..a847bbd5f8 100644
--- a/server/turn-route.ts
+++ b/server/turn-route.ts
@@ -12,10 +12,9 @@ export interface TurnSignals {
priorTurnUsedTools: boolean;
}
-// English only: a message in another language falls back on the other signals.
const ACTION = /\b(build|fix|debug|implement|refactor|write|create|generate|deploy|install|run|test|search|find|look up|browse|open|edit|change|update|delete|remove|rename|move|migrate|analy[sz]e|review|compare|research|summari[sz]e|translate|draft|send|email|schedule|book|download|upload|scrape|clone|commit|push|merge|plan|design|calculate|convert)\b/i;
const CODE = /```|`[^`\n]+`|\b(function|const|let|class|import|def|SELECT|FROM)\b|[{};]\s*$|\w+\.(ts|tsx|js|py|go|rs|json|md|sh|yml|yaml|sql|css|html)\b|https?:\/\/|(^|\s)[~.]?\/[\w.-]+\//m;
-const CONTINUE = /^(yes|yep|yeah|ok(ay)?|sure|go( ahead| on)?|do it|continue|proceed|please do|sounds good|retry|try again)\b/i;
+const CONTINUE = /^(yes|yep|yeah|ok(ay)?|sure|go( ahead| on)?|do it|continue|proceed|please do|sounds good|retry|try again|продолж(?:и|ай|айте|ите|ить|им)|давай(?:те)?|дальше)(?=$|[^\p{L}\p{N}_])/iu;
const ACK = /^(thanks|thank you|thx|ty|cool|nice|great|perfect|awesome|got it|lol|haha)\b[\s!.]*$/i;
const SIMPLE_CHARS = 280;
const SIMPLE_LINES = 4;
@@ -36,13 +35,21 @@ export function classifyTurn(signals: TurnSignals): TurnTier {
const FAST = /(^|[-_/. ])(haiku|flash|mini|nano|lite|small|fast|instant|spark|turbo|air)(?=$|[-_/. \d])/i;
+const family = (id: string) => id.split(/[-_./+]/)[0]?.toLowerCase();
+
/** Same upstream provider only; among several, the first listed wins since engines list their newest first. */
export function fastModelFor(catalog: ModelCatalog | undefined, current: string, refused: ReadonlySet<string> = new Set()): string | undefined {
if (!catalog) return undefined;
+ const currentOption = catalog.options.find((option) => option.id === current);
+ if (!currentOption || currentOption.custom) return undefined;
if (FAST.test(current)) return current;
- const provider = catalog.options.find((option) => option.id === current)?.provider;
- const pick = catalog.options.find((option) => !option.custom && !refused.has(option.id) &&
- FAST.test(option.id) && (option.provider ?? undefined) === (provider ?? undefined));
+ const provider = currentOption.provider;
+ const pick = catalog.options.find((option) =>
+ !option.custom &&
+ !refused.has(option.id) &&
+ FAST.test(option.id) &&
+ (provider || option.provider ? option.provider === provider : family(option.id) === family(current)),
+ );
return pick?.id;
}