Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions packages/modelparams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Id>` 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):
Expand Down
2 changes: 2 additions & 0 deletions packages/modelparams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions packages/modelparams/parameter-capabilities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"routes": [
{
"provider": "google",
"authType": "api_key",
"apiSurface": "google-generate-content",
"model": "gemini-2.5-flash-lite",
"params": ["generationConfig.topK"]
}
]
}
19 changes: 14 additions & 5 deletions packages/modelparams/scripts/compute-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "..");
Expand Down Expand Up @@ -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<ReturnType<typeof loadAllModels>>["models"],
): Promise<BumpLevel | null> {
Expand All @@ -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 {
Expand Down Expand Up @@ -124,14 +131,16 @@ async function main(): Promise<void> {
// 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);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/modelparams/scripts/lib/version.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 47 additions & 0 deletions packages/modelparams/tests/parameter-capabilities.test.ts
Original file line number Diff line number Diff line change
@@ -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<string>();
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,
});
});
});
10 changes: 8 additions & 2 deletions scripts/prepare-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -174,8 +175,13 @@ async function main(): Promise<void> {
}

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) {
Expand Down
Loading