feat(models): add refresh-model-catalog skill
Add an agent skill that walks through a full model catalog refresh: drift detection, catalog sync, manually reviewed pricing updates, fixture refresh, and test updates. Its helper scripts run on Windows and Linux: one snapshots the live model-id list into the test fixture, the other regenerates the pricing fixture from MODEL_COSTS through prettier so format:check stays green. Typecheck now covers the skill scripts.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
// Refreshes tests/fixtures/commandcode-model-ids.json from the live Command Code
|
||||
// models API. Run from the repository root:
|
||||
// node .agents/skills/refresh-model-catalog/scripts/refresh-model-ids.mjs
|
||||
import { writeFile } from "node:fs/promises"
|
||||
|
||||
import { format, resolveConfig } from "prettier"
|
||||
|
||||
const MODELS_URL = "https://api.commandcode.ai/provider/v1/models"
|
||||
const FIXTURE_PATH = new URL(
|
||||
"../../../../tests/fixtures/commandcode-model-ids.json",
|
||||
import.meta.url,
|
||||
)
|
||||
|
||||
const response = await fetch(MODELS_URL)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch Command Code models: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
const body = await response.json()
|
||||
if (body?.object !== "list" || !Array.isArray(body.data)) {
|
||||
throw new Error("Expected a Command Code models list response")
|
||||
}
|
||||
|
||||
const modelIds = body.data.map((model) => {
|
||||
if (typeof model?.id !== "string" || model.id.length === 0) {
|
||||
throw new Error("Expected each model entry to have a non-empty id")
|
||||
}
|
||||
return model.id
|
||||
})
|
||||
if (modelIds.length === 0) throw new Error("Command Code returned an empty model catalog")
|
||||
|
||||
const fixture = { fetchedAt: new Date().toISOString(), source: MODELS_URL, modelIds }
|
||||
const options = await resolveConfig(new URL("../../../../.prettierrc.json", import.meta.url))
|
||||
const contents = await format(JSON.stringify(fixture), {
|
||||
...options,
|
||||
filepath: "commandcode-model-ids.json",
|
||||
})
|
||||
await writeFile(FIXTURE_PATH, contents, "utf-8")
|
||||
console.log(`Wrote ${modelIds.length} model ids to tests/fixtures/commandcode-model-ids.json`)
|
||||
@@ -0,0 +1,43 @@
|
||||
// Regenerates tests/fixtures/commandcode-pricing.json from src/pricing.ts so the
|
||||
// snapshot always matches MODEL_COSTS. Run from the repository root:
|
||||
// npx tsx .agents/skills/refresh-model-catalog/scripts/sync-pricing-fixture.ts
|
||||
import { writeFile } from "node:fs/promises"
|
||||
|
||||
import { format, resolveConfig } from "prettier"
|
||||
|
||||
import { MODEL_COSTS, PRICING_LAST_VERIFIED, PRICING_SOURCE_URL } from "../../../../src/pricing.ts"
|
||||
|
||||
const FIXTURE_PATH = new URL("../../../../tests/fixtures/commandcode-pricing.json", import.meta.url)
|
||||
|
||||
const costs: Record<string, [number, number, number, number]> = {}
|
||||
const tiers: Record<string, [number, number, number, number, number][]> = {}
|
||||
for (const [modelId, cost] of Object.entries(MODEL_COSTS)) {
|
||||
costs[modelId] = [cost.input, cost.output, cost.cacheRead, cost.cacheWrite]
|
||||
if (cost.tiers) {
|
||||
tiers[modelId] = cost.tiers.map((tier) => [
|
||||
tier.inputTokensAbove,
|
||||
tier.input,
|
||||
tier.output,
|
||||
tier.cacheRead,
|
||||
tier.cacheWrite,
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
const fixture = {
|
||||
verifiedAt: PRICING_LAST_VERIFIED,
|
||||
source: PRICING_SOURCE_URL,
|
||||
tierPolicy:
|
||||
"Use request-wide input tiers; the highest threshold exceeded by input plus cache tokens applies to the full request.",
|
||||
tiers,
|
||||
costs,
|
||||
}
|
||||
const options = await resolveConfig(new URL("../../../../.prettierrc.json", import.meta.url))
|
||||
const contents = await format(JSON.stringify(fixture), {
|
||||
...options,
|
||||
filepath: "commandcode-pricing.json",
|
||||
})
|
||||
await writeFile(FIXTURE_PATH, contents, "utf-8")
|
||||
console.log(
|
||||
`Wrote ${Object.keys(costs).length} model prices to tests/fixtures/commandcode-pricing.json`,
|
||||
)
|
||||
Reference in New Issue
Block a user