fix: handled unknown model limits as null to avoid artificial token caps

- Replaced unknown model contextWindow/maxTokens sentinels with nullable values across types and catalog data.
- Mapped request token calculations to treat null maxTokens as unlimited output caps.
- Updated remote compaction and context checks to ignore unknown limits by using Infinity/0 fallbacks.
- Adjusted CLI/model registry flows to skip cap enforcement for null limits and render unknown values as '-'.
This commit is contained in:
can1357
2026-06-13 15:35:40 +02:00
parent 2a7e10cc44
commit f0c6a54f51
43 changed files with 3014 additions and 2798 deletions
+7 -10
View File
@@ -34,8 +34,6 @@ import {
MODELS_DEV_PROVIDER_DESCRIPTORS,
mapModelsDevToModels,
stripFireworksDeepSeekThinkingToggle,
UNK_CONTEXT_WINDOW,
UNK_MAX_TOKENS,
} from "../src/provider-models/openai-compat";
import type { ModelSpec } from "../src/types";
import { cleanModelName } from "../src/utils";
@@ -158,21 +156,20 @@ function createGlobalModelsDevReferenceMap(modelsDevModels: readonly ModelSpec[]
references.set(model.id, model);
continue;
}
if (model.contextWindow > existing.contextWindow) {
if ((model.contextWindow ?? 0) > (existing.contextWindow ?? 0)) {
references.set(model.id, model);
continue;
}
if (model.contextWindow === existing.contextWindow && model.maxTokens > existing.maxTokens) {
if (
(model.contextWindow ?? 0) === (existing.contextWindow ?? 0) &&
(model.maxTokens ?? 0) > (existing.maxTokens ?? 0)
) {
references.set(model.id, model);
}
}
return references;
}
function inheritModelsDevLimit(value: number, referenceValue: number, unspecifiedValue: number): number {
return value === unspecifiedValue ? referenceValue : value;
}
function applyGlobalModelsDevFallback(
models: readonly ModelSpec[],
modelsDevModels: readonly ModelSpec[],
@@ -194,8 +191,8 @@ function applyGlobalModelsDevFallback(
input: reference.input,
// Fill unknown endpoint limits from same-id models.dev references, but keep
// provider-specific values when discovery returned them explicitly.
contextWindow: inheritModelsDevLimit(model.contextWindow, reference.contextWindow, UNK_CONTEXT_WINDOW),
maxTokens: inheritModelsDevLimit(model.maxTokens, reference.maxTokens, UNK_MAX_TOKENS),
contextWindow: model.contextWindow ?? reference.contextWindow,
maxTokens: model.maxTokens ?? reference.maxTokens,
};
});
}