Skip to content

Commit c31a4ce

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 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 d1ef198 commit c31a4ce

55 files changed

Lines changed: 2164 additions & 39220 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
@@ -565,7 +565,6 @@ AICTRL_DISABLE_AUTOCOMPACT
565565
AICTRL_DISABLE_AUTOUPDATE
566566
AICTRL_DISABLE_DEFAULT_PLUGINS
567567
AICTRL_DISABLE_FILETIME_CHECK
568-
AICTRL_DISABLE_MODELS_FETCH
569568
AICTRL_DISABLE_PRUNE
570569
AICTRL_ENABLE_EXA
571570
AICTRL_ENABLE_EXPERIMENTAL_MODELS
@@ -577,7 +576,6 @@ AICTRL_EXPERIMENTAL_OXFMT
577576
AICTRL_FAKE_VCS
578577
AICTRL_GIT_BASH_PATH
579578
AICTRL_MODEL
580-
AICTRL_MODELS_URL
581579
AICTRL_PERMISSION
582580
AICTRL_PORT
583581
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
@@ -18,28 +18,6 @@ const singleFlag = process.argv.includes("--single") || process.env.AICTRL_BUILD
1818
const baselineFlag = process.argv.includes("--baseline")
1919
const liteFlag = process.argv.includes("--lite")
2020

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

‎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)

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Filesystem } from "../../util/filesystem"
1717
import { createAictrlClient } from "@aictrl/sdk"
1818
import type { ToolPart } from "@aictrl/sdk/v2"
1919
import { Provider } from "../../provider/provider"
20-
import { ModelsDev } from "../../provider/models"
20+
import { lazy } from "../../util/lazy"
2121
import { Agent } from "../../agent/agent"
2222
import { PermissionNext } from "../../permission/next"
2323
import { Session } from "../../session"
@@ -120,9 +120,12 @@ export function buildContextWindow(
120120
export async function attachedContextLimit(
121121
providerID: string,
122122
modelID: string,
123-
providers = ModelsDev.get(),
123+
providers: Promise<Provider.Info[]>,
124124
): Promise<number | null> {
125-
return providers.then((providers) => providers[providerID]?.models[modelID]?.limit.context ?? null).catch(() => null)
125+
return providers
126+
.then((providers) => providers.find((provider) => provider.id === providerID))
127+
.then((provider) => provider?.models[modelID]?.limit.context ?? null)
128+
.catch(() => null)
126129
}
127130

128131
type TerminalUsageInfo = Pick<MessageV2.Assistant, "finish" | "usageStatus" | "tokens">
@@ -542,6 +545,11 @@ export const RunCommand = cmd({
542545
let promptResult: Promise<any> = Promise.resolve()
543546

544547
async function execute(sdk: any) {
548+
// An attached server resolves models from its own provider registry, so ask it once per run.
549+
const attachedProviders = lazy(
550+
(): Promise<Provider.Info[]> => sdk.config.providers().then((res: any) => res.data?.providers ?? []),
551+
)
552+
545553
function tool(part: ToolPart) {
546554
try {
547555
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
@@ -697,10 +705,10 @@ export const RunCommand = cmd({
697705
// part of the prompt sent to the model and count against the context
698706
// window, just billed at the cache-write rate. Excluding them
699707
// undercounts utilization on the first turn of a conversation.
700-
// limit comes from the model registry (models.dev). On lookup failure
701-
// (or limit===0 for custom models) buildContextWindow returns null.
708+
// limit comes from the provider registry (the built-in catalog plus config).
709+
// On lookup failure (or limit===0 for custom models) buildContextWindow returns null.
702710
const contextLimit = await (args.attach
703-
? attachedContextLimit(info.providerID, info.modelID)
711+
? attachedContextLimit(info.providerID, info.modelID, attachedProviders())
704712
: Provider.getModel(info.providerID, info.modelID)
705713
.then((m) => m.limit.context)
706714
.catch((e) => {

0 commit comments

Comments
 (0)