fix: tighten model catalog manifest normalization

This commit is contained in:
Shakker
2026-04-25 02:50:34 +01:00
committed by Shakker
parent a5d46c4567
commit 1f4dab2c37
2 changed files with 30 additions and 11 deletions

View File

@@ -505,6 +505,20 @@ describe("loadPluginManifestRegistry", () => {
output: 2.5,
cacheRead: 0.15,
tieredPricing: [
{
input: 0.6,
output: 2.5,
cacheRead: 0.15,
cacheWrite: 0.6,
range: [0, "bad"],
},
{
input: 0.6,
output: 2.5,
cacheRead: 0.15,
cacheWrite: 0.6,
range: [0, -1],
},
{
input: 0.6,
output: 2.5,
@@ -516,6 +530,7 @@ describe("loadPluginManifestRegistry", () => {
},
compat: {
supportsTools: true,
supportedReasoningEfforts: ["low", "medium"],
supportsStore: "yes",
unknownFlag: true,
},
@@ -592,6 +607,7 @@ describe("loadPluginManifestRegistry", () => {
},
compat: {
supportsTools: true,
supportedReasoningEfforts: ["low", "medium"],
},
status: "available",
tags: ["default"],

View File

@@ -50,8 +50,8 @@ export type PluginManifestModelCatalogStatus = "available" | "preview" | "deprec
export type PluginManifestModelCatalogTieredCost = {
input: number;
output: number;
cacheRead?: number;
cacheWrite?: number;
cacheRead: number;
cacheWrite: number;
range: [number, number] | [number];
};
@@ -432,9 +432,9 @@ function normalizeStringMap(value: unknown): Record<string, string> | undefined
const normalized: Record<string, string> = {};
for (const [rawKey, rawValue] of Object.entries(value)) {
const key = normalizeSafeRecordKey(rawKey);
const value = normalizeOptionalString(rawValue) ?? "";
if (key && value) {
normalized[key] = value;
const strValue = normalizeOptionalString(rawValue) ?? "";
if (key && strValue) {
normalized[key] = strValue;
}
}
return Object.keys(normalized).length > 0 ? normalized : undefined;
@@ -728,15 +728,17 @@ function normalizeModelCatalogTieredCost(
) {
continue;
}
const rangeValues = entry.range
.map((rangeValue) => normalizeModelCatalogNumber(rangeValue))
.filter((rangeValue): rangeValue is number => rangeValue !== undefined);
if (entry.range.length < 1 || entry.range.length > 2) {
continue;
}
const rangeValues = entry.range.map((rangeValue) => normalizeModelCatalogNumber(rangeValue));
if (rangeValues.some((rangeValue) => rangeValue === undefined)) {
continue;
}
const range =
rangeValues.length === 1
? ([rangeValues[0]] as [number])
: rangeValues.length >= 2
? ([rangeValues[0], rangeValues[1]] as [number, number])
: undefined;
: ([rangeValues[0], rangeValues[1]] as [number, number]);
if (!range) {
continue;
}
@@ -807,6 +809,7 @@ function normalizeModelCatalogCompat(value: unknown): ModelCompatConfig | undefi
const stringListFields = [
"visibleReasoningDetailTypes",
"supportedReasoningEfforts",
"unsupportedToolSchemaKeywords",
] as const;
for (const field of stringListFields) {