Skip to content

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

fix(list_models): name models the engine has but won't run, with why

AdityaUmale3dc9daf76894
diff --git a/server/routes/internal-models.test.ts b/server/routes/internal-models.test.ts
index af2126bf71..685dc1264c 100644
--- a/server/routes/internal-models.test.ts
+++ b/server/routes/internal-models.test.ts
@@ -24,7 +24,7 @@ describe("modelMenu", () => {
expect(JSON.stringify(menu).length).toBeLessThan(400);
});
- it("lists a small catalog whole, without what the organization turned off, with efforts and only the labels that add something", () => {
+ it("lists a small catalog whole, with efforts and only the labels that add something, and says what the organization turned off", () => {
const claude = engine("claude", [], {
models: { default: "claude-sonnet-5", options: [
{ id: "claude-sonnet-5", label: "Claude Sonnet 5" },
@@ -36,9 +36,26 @@ describe("modelMenu", () => {
});
expect(modelMenu({ engines: [claude], current, pinned: [], refusal: opens })).toEqual({ current, engines: [{
instanceId: "claude", name: "Claude", models: ["claude-sonnet-5", "claude-opus-5", { id: "default", label: "Default (recommended)" }], efforts: ["low", "high", "max"],
+ blocked: [{ id: "claude-haiku-5", why: "turned off by this account's organization" }],
}] });
});
+ it("names a model the installed CLI is too old for, with the version it needs, instead of dropping it (Fable 5.2 'gone' after an update)", () => {
+ const claude = engine("claude", [], {
+ models: { default: "claude-sonnet-5", options: [
+ { id: "claude-sonnet-5", label: "Claude Sonnet 5" },
+ { id: "claude-fable-5-2", label: "Claude Fable 5.2", needsCliUpdate: "2.1.321" },
+ ] },
+ });
+ const why = "needs Claude CLI 2.1.321 or newer: update it";
+ expect(modelMenu({ engines: [claude], current, pinned: [], refusal: opens }).engines).toEqual([{
+ instanceId: "claude", name: "Claude", models: ["claude-sonnet-5"], blocked: [{ id: "claude-fable-5-2", why }],
+ }]);
+ expect(modelMenu({ engines: [claude], current, pinned: [], refusal: opens, search: "fable 5.2" }).engines).toEqual([{
+ instanceId: "claude", name: "Claude", blocked: [{ id: "claude-fable-5-2", why }],
+ }]);
+ });
+
it("marks an engine unusable with start_thread's own reason after a few refusals, without checking the rest of a big catalog", () => {
const grok = engine("grok", Array.from({ length: 500 }, (_, i) => `grok-${i}`));
const refusal = vi.fn((selection: ModelSelection) => selection.instanceId === "grok" ? "Grok · grok-0 can't run now: it is signed out." : null);
diff --git a/server/routes/internal-models.ts b/server/routes/internal-models.ts
index a0ca92e2e7..9a926f73f9 100644
--- a/server/routes/internal-models.ts
+++ b/server/routes/internal-models.ts
@@ -32,6 +32,8 @@ export interface MenuRow {
efforts?: readonly string[];
/** Why no thread can run on this engine now; it then lists no models. */
unusable?: string;
+ /** Models the engine has but won't run until something changes, with what: the bot can say so instead of calling them gone. */
+ blocked?: Array<{ id: string; why: string }>;
}
export interface ModelMenu {
@@ -62,13 +64,16 @@ export function modelMenu(input: {
const labels = new Map(engine.models.options.filter((option) => !option.orgBlocked && !option.needsCliUpdate).map((option) => [option.id, option.label]));
const ids = [...new Set([...[input.current, ...input.pinned].filter((pin) => pin.instanceId === instanceId).map((pin) => pin.model), engine.models.default, ...labels.keys()])]
.filter(Boolean);
- const matching = terms.length ? ids.filter((id) => terms.every((term) => `${name} ${id} ${labels.get(id) ?? ""}`.toLowerCase().includes(term))) : ids;
- if (!matching.length && !(terms.length && terms.every((term) => name.toLowerCase().includes(term)))) continue;
+ const matches = (id: string, label = "") => terms.every((term) => `${name} ${id} ${label}`.toLowerCase().includes(term));
+ const matching = ids.filter((id) => matches(id, labels.get(id)));
+ const blocked = engine.models.options.filter((option) => (option.orgBlocked || option.needsCliUpdate) && matches(option.id, option.label)).slice(0, MENU_SHORT)
+ .map((option) => ({ id: option.id, why: option.orgBlocked ? "turned off by this account's organization" : `needs ${name} CLI ${option.needsCliUpdate} or newer: update it` }));
+ if (!matching.length && !blocked.length && !(terms.length && terms.every((term) => name.toLowerCase().includes(term)))) continue;
if (input.down(engine)) {
unavailable.push(name);
continue;
}
- if (!matching.length) continue;
+ if (!matching.length && !blocked.length) continue;
const cap = terms.length ? room : matching.length <= MENU_WHOLE ? matching.length : MENU_SHORT;
const listed: string[] = [];
let examined = 0, refusedInRow = 0, why: string | null = null;
@@ -99,6 +104,7 @@ export function modelMenu(input: {
}) } : {}),
...(more > 0 ? { more } : {}),
...(efforts.length ? { efforts } : {}),
+ ...(blocked.length ? { blocked } : {}),
});
}
return { current: input.current, engines, ...(unavailable.length ? { unavailable } : {}) };