fix: fail on dropped manifest catalog rows

This commit is contained in:
Shakker
2026-04-28 03:53:57 +01:00
parent 4168575b88
commit a3ad2723cc
2 changed files with 35 additions and 0 deletions

View File

@@ -217,4 +217,27 @@ describe("provider-catalog-shared manifest provider configs", () => {
}),
).toThrow("unsupported runtime input document");
});
it("rejects manifest catalogs when normalization drops a model row", () => {
expect(() =>
buildManifestModelProviderConfig({
providerId: "example",
catalog: {
baseUrl: "https://api.example.test/v1",
models: [
{
id: "valid",
contextWindow: 1024,
maxTokens: 1024,
},
{
id: "",
contextWindow: 1024,
maxTokens: 1024,
},
],
},
}),
).toThrow("providers.example.models");
});
});

View File

@@ -32,6 +32,14 @@ export type ConfiguredProviderCatalogEntry = {
input?: Array<"text" | "image" | "audio" | "video" | "document">;
};
function countRawManifestCatalogModels(catalog: unknown): number | undefined {
if (!catalog || typeof catalog !== "object") {
return undefined;
}
const models = (catalog as { models?: unknown }).models;
return Array.isArray(models) ? models.length : undefined;
}
function cloneManifestCatalogTieredCost(
tier: ModelCatalogTieredCost,
): NonNullable<ModelDefinitionConfig["cost"]["tieredPricing"]>[number] {
@@ -102,6 +110,10 @@ export function buildManifestModelProviderConfig(params: {
if (!catalog.baseUrl) {
throw new Error(`Missing modelCatalog.providers.${params.providerId}.baseUrl`);
}
const rawModelCount = countRawManifestCatalogModels(params.catalog);
if (rawModelCount !== undefined && rawModelCount !== catalog.models.length) {
throw new Error(`Invalid modelCatalog.providers.${params.providerId}.models`);
}
return {
baseUrl: catalog.baseUrl,
...(catalog.api ? { api: catalog.api } : {}),