diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b3cbf700..2056a446 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -247,6 +247,7 @@ The bump level is derived from the catalog, not declared by hand: - a parameter removed from a model that still exists → **major** - any other catalog change → **patch** +- a change to the bundled `parameter-capabilities.json` → **npm patch** - nothing semantic changed → no release PR Each release PR carries a generated changelog of the models added, models removed, diff --git a/packages/modelparams/README.md b/packages/modelparams/README.md index 0cd2f3e3..bdc5841b 100644 --- a/packages/modelparams/README.md +++ b/packages/modelparams/README.md @@ -74,6 +74,18 @@ if (thinking?.type === "enum") { } ``` +### Verified configurable parameters by route + +The npm package also exports `modelparams/parameter-capabilities.json`. Each +entry in `routes` lists the exact `provider`, `authType`, `apiSurface`, and +`model` alongside provider-native parameter paths in `params`. A matching +entry records that the caller can configure that parameter on that route. +Start with the verified `generationConfig.topK` entry for Gemini 2.5 Flash-Lite +on the Gemini Developer API. An absent path means it has no verified entry. + +This lookup is for request construction. Existing catalog lookups and +validators continue to use the model's public parameter definitions. + ### Validate untrusted params at runtime `ParamsOf` is compile-time only — it can't help against a JSON request body. `parseParams` validates an untrusted object against the catalog (unknown keys, numeric ranges, enum values): diff --git a/packages/modelparams/package.json b/packages/modelparams/package.json index 49dd2dc4..225b439d 100644 --- a/packages/modelparams/package.json +++ b/packages/modelparams/package.json @@ -47,10 +47,12 @@ "types": "./dist/generated/model-ids.d.ts", "import": "./dist/generated/model-ids.js" }, + "./parameter-capabilities.json": "./parameter-capabilities.json", "./package.json": "./package.json" }, "files": [ "dist", + "parameter-capabilities.json", "README.md", "CHANGELOG.md", "LICENSE" diff --git a/packages/modelparams/parameter-capabilities.json b/packages/modelparams/parameter-capabilities.json new file mode 100644 index 00000000..c82df80b --- /dev/null +++ b/packages/modelparams/parameter-capabilities.json @@ -0,0 +1,11 @@ +{ + "routes": [ + { + "provider": "google", + "authType": "api_key", + "apiSurface": "google-generate-content", + "model": "gemini-2.5-flash-lite", + "params": ["generationConfig.topK"] + } + ] +} diff --git a/packages/modelparams/scripts/compute-version.ts b/packages/modelparams/scripts/compute-version.ts index 84543692..e5246bc9 100644 --- a/packages/modelparams/scripts/compute-version.ts +++ b/packages/modelparams/scripts/compute-version.ts @@ -5,7 +5,13 @@ import { fileURLToPath } from "node:url"; import { loadAllModels } from "../../../src/data/load.js"; import { loadModelsAtRef, refExists } from "../../../src/data/git-baseline.js"; import { findRemovedParams } from "../../../src/data/removals.js"; -import { canonicalCatalog, decideBump, bumpVersion, type BumpLevel } from "./lib/version.js"; +import { + bundledCapabilitiesChanged, + bumpVersion, + canonicalCatalog, + decideBump, + type BumpLevel, +} from "./lib/version.js"; const here = path.dirname(fileURLToPath(import.meta.url)); const PKG_DIR = path.resolve(here, ".."); @@ -73,7 +79,7 @@ function readForcedLevel(): BumpLevel | null { return null; } -/** Auto-detect the bump level from the catalog diff against the base ref. */ +/** Auto-detect the bump level from catalog and bundled capability changes. */ async function detectLevel( current: Awaited>["models"], ): Promise { @@ -84,11 +90,12 @@ async function detectLevel( } const base = await loadModelsAtRef(baseRef); const removals = findRemovedParams(base, current); - return decideBump({ + const catalogBump = decideBump({ baseCanon: canonicalCatalog(base), currentCanon: canonicalCatalog(current), hasRemovals: removals.length > 0, }); + return catalogBump ?? (bundledCapabilitiesChanged(baseRef) ? "patch" : null); } function emit(name: string, value: string): void { @@ -124,14 +131,16 @@ async function main(): Promise { // Subsequent releases bump from the latest published tag (the repo's // package.json is not written back, so tags are the source of truth). if (level === null) { - console.error(`No semantic catalog change since ${TAG_PREFIX}${latestTag} — skipping publish.`); + console.error( + `No catalog or parameter capability change since ${TAG_PREFIX}${latestTag} — skipping publish.`, + ); emit("level", ""); emit("next", ""); return; } const next = bumpVersion(latestTag, level); - console.error(`Catalog change: bump ${level} from ${latestTag} → ${next}.`); + console.error(`Detected release change: bump ${level} from ${latestTag} → ${next}.`); emit("level", level); emit("next", next); } diff --git a/packages/modelparams/scripts/lib/version.ts b/packages/modelparams/scripts/lib/version.ts index cf4b1b99..974ffdc1 100644 --- a/packages/modelparams/scripts/lib/version.ts +++ b/packages/modelparams/scripts/lib/version.ts @@ -1,7 +1,17 @@ +import { isDeepStrictEqual } from "node:util"; +import { git } from "../../../../src/data/git-baseline.js"; import { modelId, type Model } from "../../../../src/schema/model.js"; +import parameterCapabilities from "../../parameter-capabilities.json"; export type BumpLevel = "major" | "patch"; +export function bundledCapabilitiesChanged(baseRef: string): boolean { + const file = "packages/modelparams/parameter-capabilities.json"; + const existsInBase = git(["ls-tree", "--name-only", baseRef, "--", file]).trim() !== ""; + const base = existsInBase ? JSON.parse(git(["show", `${baseRef}:${file}`])) : null; + return !isDeepStrictEqual(base, parameterCapabilities); +} + /** * Canonicalize a catalog for value-equality comparison. We sort params by path * and drop nothing — any meaningful catalog edit (added/removed param, changed diff --git a/packages/modelparams/tests/parameter-capabilities.test.ts b/packages/modelparams/tests/parameter-capabilities.test.ts new file mode 100644 index 00000000..3741203d --- /dev/null +++ b/packages/modelparams/tests/parameter-capabilities.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from "vitest"; +import parameterCapabilities from "../parameter-capabilities.json"; +import { CATALOG } from "../src/generated/data.js"; +import { parseParams } from "../src/parse.js"; + +describe("bundled parameter capabilities", () => { + it("lists only configurable parameters on exact catalog routes", () => { + const identities = new Set(); + for (const route of parameterCapabilities.routes) { + const identity = JSON.stringify([ + route.provider, + route.authType, + route.apiSurface, + route.model, + ]); + expect(identities.has(identity)).toBe(false); + identities.add(identity); + const model = CATALOG.find( + (entry) => + entry.provider === route.provider && + entry.authType === route.authType && + entry.apiSurface === route.apiSurface && + entry.model === route.model, + ); + expect(model).toBeDefined(); + expect(model?.params.map((param) => param.path)).toEqual( + expect.arrayContaining(route.params), + ); + } + + expect(parameterCapabilities.routes).toContainEqual({ + provider: "google", + authType: "api_key", + apiSurface: "google-generate-content", + model: "gemini-2.5-flash-lite", + params: ["generationConfig.topK"], + }); + }); + + it("preserves validation of a previously saved parameter without a capability entry", () => { + const params = { "generationConfig.topK": 8 }; + expect(parseParams("google/gemini-3.6-flash", params)).toEqual({ + success: true, + value: params, + }); + }); +}); diff --git a/scripts/prepare-release.ts b/scripts/prepare-release.ts index 33bbcc91..95dfff84 100644 --- a/scripts/prepare-release.ts +++ b/scripts/prepare-release.ts @@ -19,6 +19,7 @@ import { fileURLToPath } from "node:url"; import { loadAllModels } from "../src/data/load.js"; import { loadModelsAtRef, refExists } from "../src/data/git-baseline.js"; import { diffCatalogs, renderCatalogChangelog } from "../src/data/catalog-diff.js"; +import { bundledCapabilitiesChanged } from "../packages/modelparams/scripts/lib/version.js"; import { insertChangelogEntry } from "./lib/changelog.js"; import { bumpPackageLockVersion } from "./lib/package-lock.js"; import { bumpUvLockVersion } from "./lib/uv-lock.js"; @@ -174,8 +175,13 @@ async function main(): Promise { } const tag = latestTag(spec.tagPrefix); - const base = tag && refExists(tag) ? await loadModelsAtRef(tag) : []; - const changelog = renderCatalogChangelog(diffCatalogs(base, current)); + const baseRef = tag && refExists(tag) ? tag : null; + const base = baseRef ? await loadModelsAtRef(baseRef) : []; + const catalogChangelog = renderCatalogChangelog(diffCatalogs(base, current)); + const changelog = + spec.key === "npm" && baseRef && bundledCapabilitiesChanged(baseRef) + ? `${catalogChangelog}\n\n- Updated verified route parameter capabilities in \`modelparams/parameter-capabilities.json\`.` + : catalogChangelog; const updated = spec.writeVersion(source, next); if (updated === source) {