mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-23 15:31:49 +00:00
Compare commits
1 Commits
fix/codeql
...
fix/20401-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0db645f617 |
@@ -119,6 +119,20 @@ export function isFlatTierId(id: string): boolean {
|
||||
return baseIdOf(id) !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog-aware variant check: an id is a flat effort variant only when
|
||||
* its base id is actually served. Product ids that merely end in an effort
|
||||
* word (`qwen3.8-max`, `gemini-3.8-flash-high` with no base row) stay
|
||||
* regular models. Without a catalog (`allIds` undefined) it falls back to
|
||||
* the lexical `isFlatTierId`. `allIds` holds lowercase raw ids.
|
||||
*/
|
||||
export function isFlatVariantOf(id: string, allIds?: ReadonlySet<string>): boolean {
|
||||
const base = baseIdOf(id);
|
||||
if (base === undefined) return false;
|
||||
if (allIds === undefined) return true;
|
||||
return allIds.has(base.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* The bare master auto router (`auto`, served as `owned_by: "combo"`).
|
||||
* It is a routing entry point, not a ranked model: it always publishes
|
||||
@@ -172,7 +186,8 @@ export function passesWhatServes(
|
||||
visibleFilter: ModelListFilter | undefined,
|
||||
nowMs: number = Date.now(),
|
||||
freshKept?: ReadonlySet<string>,
|
||||
windowMs: number = FRESHNESS_WINDOW_MS
|
||||
windowMs: number = FRESHNESS_WINDOW_MS,
|
||||
allIds?: ReadonlySet<string>
|
||||
): boolean {
|
||||
if (visibleFilter !== undefined) {
|
||||
if (matchesModelFilter(entry.id, visibleFilter)) return true;
|
||||
@@ -181,7 +196,7 @@ export function passesWhatServes(
|
||||
// not declare (it already flows through the fetcher untouched).
|
||||
if (readEntryStatus(entry) === "deprecated") return false;
|
||||
if (isMasterAutoRouter(entry)) return true;
|
||||
if (isFlatTierId(entry.id)) return false;
|
||||
if (isFlatVariantOf(entry.id, allIds)) return false;
|
||||
if (isFreshModel(entry, nowMs, windowMs)) {
|
||||
if (freshKept !== undefined) return freshKept.has(entry.id);
|
||||
return true;
|
||||
@@ -201,14 +216,15 @@ export function selectFreshKeptIds(
|
||||
perOwner: number = FRESH_PER_OWNER,
|
||||
nowMs: number = Date.now(),
|
||||
visibleFilter?: ModelListFilter,
|
||||
windowMs: number = FRESHNESS_WINDOW_MS
|
||||
windowMs: number = FRESHNESS_WINDOW_MS,
|
||||
allIds?: ReadonlySet<string>
|
||||
): Set<string> {
|
||||
const perOwnerCount = Number.isFinite(perOwner) && perOwner > 0 ? perOwner : FRESH_PER_OWNER;
|
||||
const groups = new Map<string, OmniRouteRawModelEntry[]>();
|
||||
for (const entry of entries) {
|
||||
if (!entry || typeof entry.id !== "string" || entry.id.length === 0) continue;
|
||||
if (readEntryStatus(entry) === "deprecated") continue;
|
||||
if (isFlatTierId(entry.id)) continue;
|
||||
if (isFlatVariantOf(entry.id, allIds)) continue;
|
||||
if (isMasterAutoRouter(entry)) continue;
|
||||
if (visibleFilter !== undefined) {
|
||||
if (matchesModelFilter(entry.id, visibleFilter)) continue;
|
||||
@@ -237,10 +253,11 @@ export function staysDropped(
|
||||
entry: OmniRouteRawModelEntry,
|
||||
freshKept: ReadonlySet<string>,
|
||||
nowMs: number = Date.now(),
|
||||
windowMs: number = FRESHNESS_WINDOW_MS
|
||||
windowMs: number = FRESHNESS_WINDOW_MS,
|
||||
allIds?: ReadonlySet<string>
|
||||
): boolean {
|
||||
if (readEntryStatus(entry) === "deprecated") return true;
|
||||
if (isFlatTierId(entry.id)) return true;
|
||||
if (isFlatVariantOf(entry.id, allIds)) return true;
|
||||
if (isFreshModel(entry, nowMs, windowMs) && !freshKept.has(entry.id)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import {
|
||||
SHOWCASE_PER_OWNER,
|
||||
baseIdOf,
|
||||
freshWindowDaysToMs,
|
||||
isFlatTierId,
|
||||
isFlatVariantOf,
|
||||
passesWhatServes,
|
||||
readEntryStatus,
|
||||
selectFreshKeptIds,
|
||||
@@ -78,6 +78,7 @@ export {
|
||||
compareByRecency,
|
||||
freshWindowDaysToMs,
|
||||
isFlatTierId,
|
||||
isFlatVariantOf,
|
||||
isFreshModel,
|
||||
ownerKeyOf,
|
||||
passesWhatServes,
|
||||
@@ -298,10 +299,14 @@ async function resolveUsageIds(
|
||||
* base entry: the base restores in place of its flat, never the flat
|
||||
* itself (flats stay excluded by the `restorable` filter above).
|
||||
*/
|
||||
function matchesUsage(id: string, used: ReadonlySet<string>): boolean {
|
||||
function matchesUsage(
|
||||
id: string,
|
||||
used: ReadonlySet<string>,
|
||||
allIds?: ReadonlySet<string>
|
||||
): boolean {
|
||||
const lower = id.toLowerCase();
|
||||
if (used.has(lower)) return true;
|
||||
if (isFlatTierId(id)) return false;
|
||||
if (isFlatVariantOf(id, allIds)) return false;
|
||||
for (const name of used) {
|
||||
if (baseIdOf(name) === lower) return true;
|
||||
}
|
||||
@@ -893,6 +898,8 @@ export async function collectCatalog(
|
||||
const presetPool = catalogAll
|
||||
? []
|
||||
: filterRawPoolByPreset(rawModels, enrichment, canonicalToAlias, presetFlags, isFreeInferred);
|
||||
// A flat effort id only counts as a variant when its base is served.
|
||||
const allRawIds = new Set(rawModels.map((e) => String(e.id ?? "").toLowerCase()));
|
||||
const showcasePool = catalogAll
|
||||
? []
|
||||
: presetPool.filter(
|
||||
@@ -903,7 +910,7 @@ export async function collectCatalog(
|
||||
passesModelAllowlist(entry.id, visibleFilter, hiddenFilter) &&
|
||||
passesProviderFilter(entry.id, providerFilter, providerResolve, providerAllUnknown) &&
|
||||
readEntryStatus(entry) !== "deprecated" &&
|
||||
!isFlatTierId(entry.id)
|
||||
!isFlatVariantOf(entry.id, allRawIds)
|
||||
);
|
||||
const showcased = catalogAll
|
||||
? new Set<string>()
|
||||
@@ -917,7 +924,8 @@ export async function collectCatalog(
|
||||
opts.freshPerOwner ?? FRESH_PER_OWNER,
|
||||
nowMs,
|
||||
visibleFilter,
|
||||
windowMs
|
||||
windowMs,
|
||||
allRawIds
|
||||
);
|
||||
const staticallyDropped: OmniRouteRawModelEntry[] = [];
|
||||
// Stage counters for the refresh summary line. Frozen at the end of the
|
||||
@@ -951,7 +959,7 @@ export async function collectCatalog(
|
||||
if (
|
||||
!catalogAll &&
|
||||
!servedCombo &&
|
||||
!passesWhatServes(entry, showcased, visibleFilter, nowMs, freshKept, windowMs)
|
||||
!passesWhatServes(entry, showcased, visibleFilter, nowMs, freshKept, windowMs, allRawIds)
|
||||
) {
|
||||
staticallyDropped.push(entry);
|
||||
continue;
|
||||
@@ -1005,10 +1013,10 @@ export async function collectCatalog(
|
||||
// entry, a flat effort-variant id or an id past the fresh cap is
|
||||
// never restored — filter before resolving.
|
||||
const restorable = staticallyDropped.filter(
|
||||
(entry) => !staysDropped(entry, freshKept, nowMs, windowMs)
|
||||
(entry) => !staysDropped(entry, freshKept, nowMs, windowMs, allRawIds)
|
||||
);
|
||||
const used = await resolveUsageIds(restorable, opts, fetchers, log);
|
||||
const toRestore = restorable.filter((entry) => matchesUsage(entry.id, used));
|
||||
const toRestore = restorable.filter((entry) => matchesUsage(entry.id, used, allRawIds));
|
||||
for (const entry of toRestore) {
|
||||
const mapped = mapRawModelToModelV2(entry, {
|
||||
providerId: X,
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { collectCatalog } from "../src/catalog.js";
|
||||
import { isFlatVariantOf } from "../src/catalog-freshness.js";
|
||||
import type { OmniRouteRawModelEntry } from "../src/shared/models-map.js";
|
||||
|
||||
const NOW = Date.parse("2026-11-17T12:00:00.000Z");
|
||||
const dated = (d: number) => new Date(NOW - d * 86400000).toISOString();
|
||||
|
||||
const baseOpts = {
|
||||
providerId: "omniroute",
|
||||
baseURL: "https://gw.example.com",
|
||||
apiKey: "k",
|
||||
timeoutMs: 1000,
|
||||
modelCacheTtlMs: 300000,
|
||||
usableOnly: false,
|
||||
enrichment: false as const,
|
||||
};
|
||||
|
||||
async function run(raw: OmniRouteRawModelEntry[]) {
|
||||
const realNow = Date.now;
|
||||
Date.now = () => NOW;
|
||||
try {
|
||||
return await collectCatalog(baseOpts, {
|
||||
fetcher: async () => raw,
|
||||
combosFetcher: async () => [],
|
||||
usageFetcher: async () => [],
|
||||
});
|
||||
} finally {
|
||||
Date.now = realNow;
|
||||
}
|
||||
}
|
||||
|
||||
const row = (id: string, owner: string): OmniRouteRawModelEntry =>
|
||||
({
|
||||
id,
|
||||
owned_by: owner,
|
||||
context_length: 1048576,
|
||||
release_date: dated(5),
|
||||
}) as OmniRouteRawModelEntry;
|
||||
|
||||
describe("#20401 product ids ending in an effort word are hidden", () => {
|
||||
it("publishes opencode-go/qwen3.8-max when no base qwen3.8 exists", async () => {
|
||||
const c = await run([row("opencode-go/qwen3.8-max", "opencode-go")]);
|
||||
assert.ok(c.entries.has("omniroute/opencode-go/qwen3.8-max"), "qwen3.8-max must be published");
|
||||
});
|
||||
|
||||
it("publishes antigravity gemini-3.8-flash-low/medium/high when no base exists", async () => {
|
||||
const c = await run(
|
||||
["low", "medium", "high"].map((t) => row(`antigravity/gemini-3.8-flash-${t}`, "antigravity"))
|
||||
);
|
||||
for (const t of ["low", "medium", "high"]) {
|
||||
assert.ok(
|
||||
c.entries.has(`omniroute/antigravity/gemini-3.8-flash-${t}`),
|
||||
`-${t} must be published`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("control: a real variant still hides when its base is present", async () => {
|
||||
const c = await run([row("o/m", "o"), row("o/m-high", "o")]);
|
||||
assert.ok(c.entries.has("omniroute/o/m"));
|
||||
assert.ok(!c.entries.has("omniroute/o/m-high"));
|
||||
});
|
||||
|
||||
it("isFlatVariantOf: base lookup is case-insensitive and legacy without a set", () => {
|
||||
assert.equal(isFlatVariantOf("o/M-high", new Set(["o/m"])), true);
|
||||
assert.equal(isFlatVariantOf("o/m-high", new Set()), false);
|
||||
assert.equal(isFlatVariantOf("o/m-high"), true);
|
||||
assert.equal(isFlatVariantOf("o/m"), false);
|
||||
});
|
||||
});
|
||||
1
changelog.d/fixes/20401-opencode-flat-tier-needs-base.md
Normal file
1
changelog.d/fixes/20401-opencode-flat-tier-needs-base.md
Normal file
@@ -0,0 +1 @@
|
||||
- fix(opencode-plugin): only hide a flat effort-variant id when its base model is served, so ids like `qwen3.8-max` and `gemini-3.8-flash-high` stay visible (#20401)
|
||||
Reference in New Issue
Block a user