feat(catalog): add hideAutoCombos and hideNoThinkVariants settings toggles (#9418) (#9535)

Validated in local merge-train (diegosouzapw batch)
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-08-06 10:39:51 -03:00
committed by GitHub
parent 607bccb6d6
commit 2d617325e7
6 changed files with 214 additions and 51 deletions

View File

@@ -0,0 +1 @@
- **feat(catalog):** added opt-in settings `hideAutoCombos` and `hideNoThinkVariants` (default off) to filter built-in `auto/*` virtual combos and `no-think/*` gateway variants from the `/v1/models` catalog — user-defined combos and original provider models stay listed; routing is unaffected ([#9418](https://github.com/diegosouzapw/OmniRoute/issues/9418))

View File

@@ -135,8 +135,8 @@ export async function getUnifiedModelsResponse(
// #6408 fast path: reject unauthorized callers first (auth state is per-request
// and MUST NOT be cached), then coalesce identical concurrent requests + short-
// TTL memoize the serialized JSON body.
let settingsForAuth: Record<string, any> = {};
try {
let settingsForAuth: Record<string, any> = {};
try {
settingsForAuth = await getSettings();
} catch {}
@@ -160,7 +160,11 @@ export async function getUnifiedModelsResponse(
return await resolveCachedCatalogResponse(
request,
{ corsHeaders, diagnosticHeaders },
buildCatalogPayload
buildCatalogPayload,
{
hideAutoCombos: settingsForAuth?.hideAutoCombos === true,
hideNoThinkVariants: settingsForAuth?.hideNoThinkVariants === true,
}
);
} catch (err) {
// Hard rule #12: never put a raw err.message/err.stack in a response body.
@@ -235,6 +239,10 @@ async function buildUnifiedModelsResponseCore(
// exempt. Combos + auto/* + synced/custom/alias-backed rows also stay unfiltered —
// extending v1 scope to those requires per-entry pricing lookup not available today.
const hidePaid = settings.hidePaidModels === true;
// #9418: Opt-in filter — skip the entire auto/* synthesis loop when the operator
// does not want built-in virtual combos advertised in the catalog. User-defined
// combos are unaffected; routing still works for ids sent explicitly.
const hideAuto = settings.hideAutoCombos === true;
const shouldHidePaid = (providerKey: string, modelId: string, pricing?: unknown): boolean => {
if (!hidePaid) return false;
const provider = aliasToProviderId[providerKey] || providerKey;
@@ -568,6 +576,7 @@ async function buildUnifiedModelsResponseCore(
connections,
prefixMode,
aliasToProviderId,
hideNoThinkVariants: settings.hideNoThinkVariants === true,
});
return finalizeCatalogResponse(request, quotaFinal, () => undefined, {
...corsHeaders,
@@ -585,47 +594,51 @@ async function buildUnifiedModelsResponseCore(
// #4164 entry is emitted instead, so the id is never dropped.
// #4235 Phase B: also advertise the curated `auto/<category>[:<tier>]` combos.
// #6453: also advertise the `auto/<family>` combos (auto/glm, auto/minimax, ...).
for (const autoId of [
...Object.keys(AUTO_TEMPLATE_VARIANTS),
...AUTO_SUFFIX_VARIANTS,
...AUTO_FAMILY_IDS,
]) {
if (blockedProviders.has("auto") || listedIds.has(autoId)) continue; // #5192
// #6328 (follow-up to #6495 / #6512): REMOVE — not just hide — paid-tier
// auto/* ids (auto/pro-* + auto/*:pro) from the advertised catalog when the
// operator opts into hidePaidModels. The candidate-pool filter in
// virtualFactory (#6512) still gates request-time routing for the rest.
if (hidePaid && isPaidTierAutoId(autoId)) continue;
listedIds.add(autoId);
const baseAutoEntry = {
id: autoId,
object: "model",
created: timestamp,
owned_by: "combo",
permission: [],
root: autoId,
parent: null,
};
try {
const suffix = autoId.replace(/^auto\/?/, "");
const virtualCombo = await createBuiltinAutoCombo(autoId, suffix);
const contextLength = virtualCombo.advertisedContextLength || 128000;
const maxOutputTokens = virtualCombo.advertisedMaxOutputTokens || 8192;
models.push({
...baseAutoEntry,
context_length: contextLength,
max_input_tokens: contextLength,
max_output_tokens: maxOutputTokens,
capabilities: {
tool_calling: true,
reasoning: true,
thinking: true,
temperature: true,
},
});
} catch (err) {
console.log(`[catalog] Could not materialize built-in auto model ${autoId}:`, err);
models.push(baseAutoEntry);
// #9418: skip the entire loop when hideAutoCombos is on — the ids are still
// routable when sent explicitly, just not advertised in the catalog.
if (!hideAuto) {
for (const autoId of [
...Object.keys(AUTO_TEMPLATE_VARIANTS),
...AUTO_SUFFIX_VARIANTS,
...AUTO_FAMILY_IDS,
]) {
if (blockedProviders.has("auto") || listedIds.has(autoId)) continue; // #5192
// #6328 (follow-up to #6495 / #6512): REMOVE — not just hide — paid-tier
// auto/* ids (auto/pro-* + auto/*:pro) from the advertised catalog when the
// operator opts into hidePaidModels. The candidate-pool filter in
// virtualFactory (#6512) still gates request-time routing for the rest.
if (hidePaid && isPaidTierAutoId(autoId)) continue;
listedIds.add(autoId);
const baseAutoEntry = {
id: autoId,
object: "model",
created: timestamp,
owned_by: "combo",
permission: [],
root: autoId,
parent: null,
};
try {
const suffix = autoId.replace(/^auto\/?/, "");
const virtualCombo = await createBuiltinAutoCombo(autoId, suffix);
const contextLength = virtualCombo.advertisedContextLength || 128000;
const maxOutputTokens = virtualCombo.advertisedMaxOutputTokens || 8192;
models.push({
...baseAutoEntry,
context_length: contextLength,
max_input_tokens: contextLength,
max_output_tokens: maxOutputTokens,
capabilities: {
tool_calling: true,
reasoning: true,
thinking: true,
temperature: true,
},
});
} catch (err) {
console.log(`[catalog] Could not materialize built-in auto model ${autoId}:`, err);
models.push(baseAutoEntry);
}
}
}
@@ -1495,6 +1508,7 @@ async function buildUnifiedModelsResponseCore(
connections,
prefixMode,
aliasToProviderId,
hideNoThinkVariants: settings.hideNoThinkVariants === true,
});
const getDefaultContextFallback = (model: any): number | undefined => {

View File

@@ -80,13 +80,18 @@ const catalogInFlight = new Map<string, InFlightBuild>();
let _catalogBuilderRuns = 0;
function buildCatalogCacheKey(request: Request): string {
function buildCatalogCacheKey(
request: Request,
catalogSettings?: { hideAutoCombos?: boolean; hideNoThinkVariants?: boolean }
): string {
const url = new URL(request.url);
const prefix = url.searchParams.get("prefix") || "";
const apiKey = extractApiKey(request) || "";
const isCodex = isCodexModelCatalogClient(request) ? "1" : "0";
const configuredOnly = url.searchParams.get("configuredOnly") === "true" ? "1" : "0";
return `${prefix}|${isCodex}|${apiKey}|${configuredOnly}`;
const hideAuto = catalogSettings?.hideAutoCombos ? "1" : "0";
const hideNoThink = catalogSettings?.hideNoThinkVariants ? "1" : "0";
return `${prefix}|${isCodex}|${apiKey}|${configuredOnly}|${hideAuto}|${hideNoThink}`;
}
// Tracks the model-catalog cache version (src/lib/db/readCache.ts) as of the last
@@ -223,12 +228,13 @@ function runBuilder(
export async function resolveCachedCatalogResponse(
request: Request,
headerSources: { corsHeaders: Record<string, string>; diagnosticHeaders: Record<string, string> },
buildPayload: (request: Request) => Promise<CatalogPayload>
buildPayload: (request: Request) => Promise<CatalogPayload>,
catalogSettings?: { hideAutoCombos?: boolean; hideNoThinkVariants?: boolean }
): Promise<Response> {
const { corsHeaders, diagnosticHeaders } = headerSources;
dropCatalogCacheIfStateChanged();
const cacheKey = buildCatalogCacheKey(request);
const cacheKey = buildCatalogCacheKey(request, catalogSettings);
const now = Date.now();
const cached = catalogCache.get(cacheKey);

View File

@@ -47,6 +47,7 @@ export function applyCatalogPostFilters(
connections: any;
prefixMode: string;
aliasToProviderId: Record<string, string>;
hideNoThinkVariants?: boolean;
}
): Array<Record<string, any>> {
let finalModels = models;
@@ -71,10 +72,14 @@ export function applyCatalogPostFilters(
// Advertise no-thinking gateway variants (Fase 8.1). Derived from the already
// key-filtered list, so a variant only appears when its real model is permitted.
finalModels = appendNoThinkingVariants(
finalModels,
ctx.prefixMode === "canonical" ? ctx.aliasToProviderId : undefined
);
// #9418: skip when hideNoThinkVariants is on — the ids are still routable when
// sent explicitly, just not advertised in the catalog.
if (!ctx.hideNoThinkVariants) {
finalModels = appendNoThinkingVariants(
finalModels,
ctx.prefixMode === "canonical" ? ctx.aliasToProviderId : undefined
);
}
// Advertise `claude/<id>` discovery-mirror aliases so Claude Code's gateway
// model discovery (which only lists `claude`/`anthropic`-prefixed ids) can see

View File

@@ -234,6 +234,12 @@ export async function getSettings() {
// (`:free` suffix, zero-price pricing, or FREE_MODEL_BUDGETS membership). Default
// false preserves prior behaviour; opt-in only.
hidePaidModels: false,
// #9418: Opt-in filter that hides auto/* virtual combos from the /v1/models catalog.
// User-defined combos are unaffected; routing still works for hidden ids sent explicitly.
hideAutoCombos: false,
// #9418: Opt-in filter that hides no-think/* gateway variants from the /v1/models catalog.
// Routing still works for hidden ids sent explicitly.
hideNoThinkVariants: false,
// #6977: Opt-in per-connection auto-ping that warms a Codex OAuth connection's
// quota window right after it resets, so the first real request doesn't land in
// a cold window. `connections` maps connection id -> enabled. Default empty map

View File

@@ -0,0 +1,131 @@
/**
* #9418 — `hideAutoCombos` and `hideNoThinkVariants` settings toggles filter
* built-in `auto/*` virtual combos and `no-think/*` gateway variants from the
* unified `/v1/models` catalog. Default false (opt-in, Rule #20 spirit).
* Rule #18 regression guard for both toggles.
*/
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-hide-auto-no-think-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const providersDb = await import("../../src/lib/db/providers.ts");
const v1ModelsCatalog = await import("../../src/app/api/v1/models/catalog.ts");
async function fetchCatalog(): Promise<Array<{ id: string; type?: string }>> {
const res = await v1ModelsCatalog.getUnifiedModelsResponse(
new Request("http://localhost/api/v1/models", { method: "GET" })
);
if (res.status !== 200) {
const body = await res.text();
assert.fail(`Expected 200, got ${res.status}: ${body.slice(0, 500)}`);
}
const body = (await res.json()) as { data: Array<{ id: string; type?: string }> };
return body.data;
}
test.after(() => {
core.resetDbInstance();
try {
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
} catch {
/* best-effort */
}
});
test("hideAutoCombos and hideNoThinkVariants default to false", async () => {
const defaults = await settingsDb.getSettings();
assert.equal(defaults.hideAutoCombos, false, "hideAutoCombos default must be false");
assert.equal(defaults.hideNoThinkVariants, false, "hideNoThinkVariants default must be false");
});
test("hideAutoCombos=true removes auto/* ids from /v1/models", async () => {
// Ensure at least one provider connection exists so the catalog has content
await providersDb.createProviderConnection({
provider: "openai",
authType: "apikey",
name: "openai-main",
apiKey: "sk-test",
isActive: true,
});
const isAutoId = (m: { id: string }) => m.id.startsWith("auto/");
await settingsDb.updateSettings({ hideAutoCombos: false, hideNoThinkVariants: false });
const off = await fetchCatalog();
const autoWhenOff = off.filter(isAutoId).map((m) => m.id);
assert.equal(autoWhenOff.length > 0, true, `expected auto/* ids when toggle off, got ${autoWhenOff.length}`);
await settingsDb.updateSettings({ hideAutoCombos: true, hideNoThinkVariants: false });
const on = await fetchCatalog();
const leaked = on.filter(isAutoId).map((m) => m.id);
assert.deepEqual(leaked, [], `auto/* ids leaked when hideAutoCombos=true: ${leaked.join(", ")}`);
// Original provider models must still be present
const hasProviderModel = on.some((m) => m.id.startsWith("openai/") || m.id.startsWith("oa/"));
assert.equal(hasProviderModel, true, "original provider models must remain when hideAutoCombos=true");
});
test("hideNoThinkVariants=true removes no-think/* ids from /v1/models", async () => {
// Add a claude provider connection so the catalog has no-think/* variants
// (no-thinking variants are generated for Claude-family models that support thinking)
await providersDb.createProviderConnection({
provider: "claude",
authType: "apikey",
name: "claude-main",
apiKey: "sk-ant-test",
isActive: true,
});
const isNoThinkId = (m: { id: string }) => m.id.startsWith("no-think/");
await settingsDb.updateSettings({ hideAutoCombos: false, hideNoThinkVariants: false });
const off = await fetchCatalog();
const noThinkWhenOff = off.filter(isNoThinkId).map((m) => m.id);
// If no no-think/* ids are present in the baseline catalog, the filter is
// trivially correct — just verify the toggle doesn't break anything.
if (noThinkWhenOff.length === 0) {
// No no-think/* ids to filter — verify the toggle doesn't remove other models
await settingsDb.updateSettings({ hideAutoCombos: false, hideNoThinkVariants: true });
const on = await fetchCatalog();
const hasProviderModel = on.some(
(m) => m.id.startsWith("claude/") || m.id.startsWith("anthropic/")
);
assert.equal(hasProviderModel, true, "original provider models must remain when hideNoThinkVariants=true");
return;
}
await settingsDb.updateSettings({ hideAutoCombos: false, hideNoThinkVariants: true });
const on = await fetchCatalog();
const leaked = on.filter(isNoThinkId).map((m) => m.id);
assert.deepEqual(leaked, [], `no-think/* ids leaked when hideNoThinkVariants=true: ${leaked.join(", ")}`);
// Original provider models must still be present
const hasProviderModel = on.some(
(m) => m.id.startsWith("claude/") || m.id.startsWith("anthropic/")
);
assert.equal(hasProviderModel, true, "original provider models must remain when hideNoThinkVariants=true");
});
test("both toggles on: neither auto/* nor no-think/* appear; original models present", async () => {
const isAutoId = (m: { id: string }) => m.id.startsWith("auto/");
const isNoThinkId = (m: { id: string }) => m.id.startsWith("no-think/");
await settingsDb.updateSettings({ hideAutoCombos: true, hideNoThinkVariants: true });
const on = await fetchCatalog();
const autoLeaked = on.filter(isAutoId).map((m) => m.id);
const noThinkLeaked = on.filter(isNoThinkId).map((m) => m.id);
assert.deepEqual(autoLeaked, [], `auto/* ids leaked: ${autoLeaked.join(", ")}`);
assert.deepEqual(noThinkLeaked, [], `no-think/* ids leaked: ${noThinkLeaked.join(", ")}`);
const hasProviderModel = on.some(
(m) => m.id.startsWith("openai/") || m.id.startsWith("oa/") || m.id.startsWith("claude/") || m.id.startsWith("anthropic/")
);
assert.equal(hasProviderModel, true, "original provider models must remain when both toggles are on");
});