mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 06:42:12 +03:00
fix(sse): guard model-less registry entries in getUnsupportedParams (mimocode) (#4015)
Real bugfix: guard model-less registry entries (mimocode) in getUnsupportedParams so handleChatCore no longer throws 'entry.models is not iterable' / reports 'All models failed' for unrelated requests. Includes a regression test. Fast QG green.
This commit is contained in:
committed by
GitHub
parent
33493586b4
commit
599c10b048
@@ -189,7 +189,8 @@ function ensureUnsupportedParamsPopulated(): void {
|
||||
if (_unsupportedParamsPopulated) return;
|
||||
_unsupportedParamsPopulated = true;
|
||||
for (const entry of Object.values(REGISTRY)) {
|
||||
for (const model of entry.models) {
|
||||
// Some entries (e.g. the `mimocode` proxy) legitimately have no model catalogue.
|
||||
for (const model of entry.models ?? []) {
|
||||
if (model.unsupportedParams && !_unsupportedParamsMap.has(model.id)) {
|
||||
_unsupportedParamsMap.set(model.id, model.unsupportedParams);
|
||||
}
|
||||
@@ -207,7 +208,7 @@ export function getUnsupportedParams(provider: string, modelId: string): readonl
|
||||
ensureUnsupportedParamsPopulated();
|
||||
// 1. Check current provider's registry (exact match)
|
||||
const entry = getRegistryEntry(provider);
|
||||
const modelEntry = entry?.models.find((m) => m.id === modelId);
|
||||
const modelEntry = entry?.models?.find((m) => m.id === modelId);
|
||||
if (modelEntry?.unsupportedParams) return modelEntry.unsupportedParams;
|
||||
|
||||
// 2. O(1) lookup in precomputed map (handles cross-provider routing)
|
||||
|
||||
23
tests/unit/provider-registry-models-guard.test.ts
Normal file
23
tests/unit/provider-registry-models-guard.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { getUnsupportedParams } from "../../open-sse/config/providerRegistry.ts";
|
||||
|
||||
// Regression guard for `TypeError: entry.models is not iterable`.
|
||||
//
|
||||
// A registry entry can legitimately have no static model catalogue — e.g. the
|
||||
// `mimocode` proxy provider, whose `models` is `undefined`. The byModelId map
|
||||
// builder already tolerates this (`if (entry.models && entry.models.length > 0)`),
|
||||
// but `getUnsupportedParams` had two unguarded accesses:
|
||||
// - `ensureUnsupportedParamsPopulated()` iterated `entry.models` for EVERY entry,
|
||||
// - the per-provider lookup did `entry?.models.find(...)`.
|
||||
// Either one threw on the first call once a model-less entry existed, which made
|
||||
// `handleChatCore` report "All models failed" for unrelated requests.
|
||||
|
||||
test("getUnsupportedParams does not throw when a registry entry has no models (mimocode regression)", () => {
|
||||
// This call triggers ensureUnsupportedParamsPopulated() which walks ALL entries.
|
||||
assert.doesNotThrow(() => getUnsupportedParams("openai", "gpt-4o"));
|
||||
});
|
||||
|
||||
test("getUnsupportedParams returns [] for a model-less proxy provider", () => {
|
||||
assert.deepEqual(getUnsupportedParams("mimocode", "anything"), []);
|
||||
});
|
||||
Reference in New Issue
Block a user