Skip to content

Commit 423b6d9

Browse files
byapparovclaude
andcommitted
feat(provider)!: replace models.dev with a static model catalog (#40)
Built-in providers and models now come from a git-tracked catalog (src/provider/catalog.json, one model per line in the Provider.Model shape). Nothing is fetched, cached or snapshotted at build or run time. The catalog covers the 18 providers with custom loaders. Any other provider is defined under `provider` in aictrl.json. The dead `aictrl` provider (a renamed upstream gateway that never resolved) is removed with its loader, picker hints, small-model fallback, ACP default and gateway-only headers and transforms. BREAKING CHANGE: providers outside the catalog no longer load from an env var alone; define them in config. AICTRL_MODELS_URL, AICTRL_MODELS_PATH, AICTRL_DISABLE_MODELS_FETCH and `models --refresh` are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 27bc92f commit 423b6d9

57 files changed

Lines changed: 2165 additions & 39236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.opencode/agent/translator.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ AICTRL_DISABLE_AUTOCOMPACT
566566
AICTRL_DISABLE_AUTOUPDATE
567567
AICTRL_DISABLE_DEFAULT_PLUGINS
568568
AICTRL_DISABLE_FILETIME_CHECK
569-
AICTRL_DISABLE_MODELS_FETCH
570569
AICTRL_DISABLE_PRUNE
571570
AICTRL_ENABLE_EXA
572571
AICTRL_ENABLE_EXPERIMENTAL_MODELS
@@ -578,7 +577,6 @@ AICTRL_EXPERIMENTAL_OXFMT
578577
AICTRL_FAKE_VCS
579578
AICTRL_GIT_BASH_PATH
580579
AICTRL_MODEL
581-
AICTRL_MODELS_URL
582580
AICTRL_PERMISSION
583581
AICTRL_PORT
584582
PROJECT_ROOT

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sst-env.d.ts
22
packages/desktop/src/bindings.ts
3+
packages/cli/src/provider/catalog.json

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ Want to take on an issue? Leave a comment and a maintainer may assign it to you
2626

2727
## Adding New Providers
2828

29-
New providers shouldn't require many if ANY code changes, but if you want to add support for a new provider first make a PR to:
30-
https://github.com/anomalyco/models.dev
29+
Built-in providers and models live in the static catalog at `packages/cli/src/provider/catalog.json` (one model per line, in the `Provider.Model` shape). To add or update a built-in model, edit that file; providers that need custom loading also need an entry in `CUSTOM_LOADERS` in `packages/cli/src/provider/provider.ts`.
30+
31+
Any other OpenAI-compatible provider does not need a code change: users define it under `provider` in `aictrl.json`.
3132

3233
## Developing Aictrl
3334

‎EVENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ For compatibility with sessions written before usage provenance was persisted, a
268268
**`context`** (context-window utilization):
269269

270270
- `used` (number) — tokens occupying the model's context window this turn: `input + cache.read + cache.write`.
271-
- `limit` (number) — the model's total context-window size in tokens, sourced from the models.dev registry (`model.limit.context`).
271+
- `limit` (number) — the model's total context-window size in tokens, sourced from the provider registry: the built-in model catalog plus `provider` config (`model.limit.context`).
272272
- `ratio` (number) — `used / limit` (≥0; may exceed 1 if usage exceeds the model's registered limit). A value approaching or exceeding 1 signals context-exhaustion risk.
273273
- `null` — emitted when the model's context limit is not known (e.g. unregistered custom endpoint), or usage is missing.
274274

‎nix/opencode.nix‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
bun,
66
sysctl,
77
makeBinaryWrapper,
8-
models-dev,
98
ripgrep,
109
installShellFiles,
1110
versionCheckHook,
@@ -21,7 +20,6 @@ stdenvNoCC.mkDerivation (finalAttrs: {
2120
bun
2221
installShellFiles
2322
makeBinaryWrapper
24-
models-dev
2523
writableTmpDirAsHomeHook
2624
];
2725

@@ -33,8 +31,6 @@ stdenvNoCC.mkDerivation (finalAttrs: {
3331
runHook postConfigure
3432
'';
3533

36-
env.MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json";
37-
env.AICTRL_DISABLE_MODELS_FETCH = true;
3834
env.AICTRL_VERSION = finalAttrs.version;
3935
env.AICTRL_CHANNEL = "local";
4036

@@ -80,7 +76,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
8076
writableTmpDirAsHomeHook
8177
];
8278
doInstallCheck = true;
83-
versionCheckKeepEnvironment = [ "HOME" "AICTRL_DISABLE_MODELS_FETCH" ];
79+
versionCheckKeepEnvironment = [ "HOME" ];
8480
versionCheckProgramArg = "--version";
8581

8682
passthru = {

‎packages/cli/.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ research
22
dist
33
gen
44
app.log
5-
src/provider/models-snapshot.ts

‎packages/cli/script/build.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,6 @@ const baselineFlag = process.argv.includes("--baseline")
1919
const skipInstall = process.argv.includes("--skip-install")
2020
const liteFlag = process.argv.includes("--lite")
2121

22-
const modelsUrl = process.env.AICTRL_MODELS_URL || "https://models.dev"
23-
// Fetch and generate models.dev snapshot
24-
let modelsData = process.env.MODELS_DEV_API_JSON
25-
? await Bun.file(process.env.MODELS_DEV_API_JSON).text()
26-
: await fetch(`${modelsUrl}/api.json`).then((x) => x.text())
27-
28-
if (liteFlag) {
29-
const allModels = JSON.parse(modelsData)
30-
const liteProviders = ["anthropic", "openai", "google", "google-vertex", "openrouter", "zai", "aictrl"]
31-
const filtered: Record<string, any> = {}
32-
for (const key of liteProviders) {
33-
if (allModels[key]) filtered[key] = allModels[key]
34-
}
35-
modelsData = JSON.stringify(filtered)
36-
}
37-
38-
await Bun.write(
39-
path.join(dir, "src/provider/models-snapshot.ts"),
40-
`// Auto-generated by build.ts - do not edit\nexport const snapshot = ${modelsData} as const\n`,
41-
)
42-
console.log("Generated models-snapshot.ts")
43-
4422
// Load migrations from migration directories
4523
const migrationDirs = (
4624
await fs.promises.readdir(path.join(dir, "migration"), {

‎packages/cli/src/acp/agent.ts‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,20 +1563,6 @@ export namespace ACP {
15631563

15641564
if (specified && !providers.length) return specified
15651565

1566-
const aictrlProvider = providers.find((p) => p.id === "aictrl")
1567-
if (aictrlProvider) {
1568-
if (aictrlProvider.models["big-pickle"]) {
1569-
return { providerID: "aictrl", modelID: "big-pickle" }
1570-
}
1571-
const [best] = Provider.sort(Object.values(aictrlProvider.models))
1572-
if (best) {
1573-
return {
1574-
providerID: best.providerID,
1575-
modelID: best.id,
1576-
}
1577-
}
1578-
}
1579-
15801566
const models = providers.flatMap((p) => Object.values(p.models))
15811567
const [best] = Provider.sort(models)
15821568
if (best) {
@@ -1588,7 +1574,7 @@ export namespace ACP {
15881574

15891575
if (specified) return specified
15901576

1591-
return { providerID: "aictrl", modelID: "big-pickle" }
1577+
throw new Error("no providers found")
15921578
}
15931579

15941580
function parseUri(

‎packages/cli/src/cli/cmd/auth.ts‎

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Auth } from "../../auth"
22
import { cmd } from "./cmd"
33
import * as prompts from "@clack/prompts"
44
import { UI } from "../ui"
5-
import { ModelsDev } from "../../provider/models"
6-
import { map, pipe, sortBy, values } from "remeda"
5+
import { ModelCatalog } from "../../provider/catalog"
6+
import { map, pickBy, pipe, sortBy, values } from "remeda"
77
import path from "path"
88
import os from "os"
99
import { Config } from "../../config/config"
@@ -163,7 +163,7 @@ async function handlePluginAuth(plugin: { auth: PluginAuth }, provider: string):
163163

164164
/**
165165
* Build a deduplicated list of plugin-registered auth providers that are not
166-
* already present in models.dev, respecting enabled/disabled provider lists.
166+
* already built into the model catalog, respecting enabled/disabled provider lists.
167167
* Pure function with no side effects; safe to test without mocking.
168168
*/
169169
export function resolvePluginProviders(input: {
@@ -212,7 +212,7 @@ export const AuthListCommand = cmd({
212212
const displayPath = authPath.startsWith(homedir) ? authPath.replace(homedir, "~") : authPath
213213
prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
214214
const results = Object.entries(await Auth.all())
215-
const database = await ModelsDev.get()
215+
const database = ModelCatalog.providers()
216216

217217
for (const [providerID, result] of results) {
218218
const name = database[providerID]?.name || providerID
@@ -288,30 +288,21 @@ export const AuthLoginCommand = cmd({
288288
prompts.outro("Done")
289289
return
290290
}
291-
await ModelsDev.refresh().catch(() => {})
292-
293291
const config = await Config.get()
294292

295293
const disabled = new Set(config.disabled_providers ?? [])
296294
const enabled = config.enabled_providers ? new Set(config.enabled_providers) : undefined
297295

298-
const providers = await ModelsDev.get().then((x) => {
299-
const filtered: Record<string, (typeof x)[string]> = {}
300-
for (const [key, value] of Object.entries(x)) {
301-
if ((enabled ? enabled.has(key) : true) && !disabled.has(key)) {
302-
filtered[key] = value
303-
}
304-
}
305-
return filtered
306-
})
296+
const providers = pickBy(
297+
ModelCatalog.providers(),
298+
(_, id) => (enabled ? enabled.has(id) : true) && !disabled.has(id),
299+
)
307300

308301
const priority: Record<string, number> = {
309-
aictrl: 0,
310-
anthropic: 1,
311-
openai: 2,
312-
google: 3,
313-
openrouter: 4,
314-
vercel: 5,
302+
anthropic: 0,
303+
openai: 1,
304+
openrouter: 2,
305+
vercel: 3,
315306
}
316307
const pluginProviders = resolvePluginProviders({
317308
hooks: await Plugin.list(),
@@ -335,7 +326,6 @@ export const AuthLoginCommand = cmd({
335326
label: x.name,
336327
value: x.id,
337328
hint: {
338-
aictrl: "recommended",
339329
anthropic: "Claude Max or API key",
340330
openai: "ChatGPT Plus/Pro or API key",
341331
}[x.id],
@@ -392,10 +382,6 @@ export const AuthLoginCommand = cmd({
392382
)
393383
}
394384

395-
if (provider === "aictrl") {
396-
prompts.log.info("Create an api key at https://aictrl.ai/auth")
397-
}
398-
399385
if (provider === "vercel") {
400386
prompts.log.info("You can create an api key at https://vercel.link/ai-gateway-token")
401387
}
@@ -433,7 +419,7 @@ export const AuthLogoutCommand = cmd({
433419
prompts.log.error("No credentials found")
434420
return
435421
}
436-
const database = await ModelsDev.get()
422+
const database = ModelCatalog.providers()
437423
const providerID = await prompts.select({
438424
message: "Select provider",
439425
options: credentials.map(([key, value]) => ({

‎packages/cli/src/cli/cmd/models.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Argv } from "yargs"
22
import { Instance } from "../../project/instance"
33
import { Provider } from "../../provider/provider"
4-
import { ModelsDev } from "../../provider/models"
54
import { cmd } from "./cmd"
65
import { UI } from "../ui"
76
import { EOL } from "os"
@@ -20,17 +19,8 @@ export const ModelsCommand = cmd({
2019
describe: "use more verbose model output (includes metadata like costs)",
2120
type: "boolean",
2221
})
23-
.option("refresh", {
24-
describe: "refresh the models cache from models.dev",
25-
type: "boolean",
26-
})
2722
},
2823
handler: async (args) => {
29-
if (args.refresh) {
30-
await ModelsDev.refresh()
31-
UI.println(UI.Style.TEXT_SUCCESS_BOLD + "Models cache refreshed" + UI.Style.TEXT_NORMAL)
32-
}
33-
3424
await Instance.provide({
3525
directory: process.cwd(),
3626
async fn() {
@@ -60,13 +50,7 @@ export const ModelsCommand = cmd({
6050
return
6151
}
6252

63-
const providerIDs = Object.keys(providers).sort((a, b) => {
64-
const aIsOpencode = a.startsWith("aictrl")
65-
const bIsOpencode = b.startsWith("aictrl")
66-
if (aIsOpencode && !bIsOpencode) return -1
67-
if (!aIsOpencode && bIsOpencode) return 1
68-
return a.localeCompare(b)
69-
})
53+
const providerIDs = Object.keys(providers).sort((a, b) => a.localeCompare(b))
7054

7155
for (const providerID of providerIDs) {
7256
printModels(providerID, args.verbose)

0 commit comments

Comments
 (0)