Skip to content
Closed
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
12 changes: 12 additions & 0 deletions packages/opencode/src/cli/cmd/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Argv } from "yargs"
import { Instance } from "../../project/instance"
import { Provider } from "../../provider/provider"
import { ModelsDev } from "../../provider/models"
import { Config } from "../../config/config"
import { cmd } from "./cmd"
import { UI } from "../ui"
import { EOL } from "os"
Expand Down Expand Up @@ -34,6 +35,17 @@ export const ModelsCommand = cmd({
await Instance.provide({
directory: process.cwd(),
async fn() {
// Check for skip_models_fetch setting after instance context is established
if (!args.refresh) {
const config = await Config.get()
if (config.experimental?.skip_models_fetch) {
UI.println(
UI.Style.TEXT_DIM +
"Automatic models fetch is disabled via experimental.skip_models_fetch" +
UI.Style.TEXT_NORMAL,
)
}
}
const providers = await Provider.list()

function printModels(providerID: string, verbose?: boolean) {
Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ export namespace Config {
chatMaxRetries: z.number().optional().describe("Number of retries for chat completions on failure"),
disable_paste_summary: z.boolean().optional(),
batch_tool: z.boolean().optional().describe("Enable the batch tool"),
skip_models_fetch: z
.boolean()
.optional()
.describe("Skip automatic fetching of models from models.dev on startup"),
})
.optional(),
})
Expand Down
16 changes: 14 additions & 2 deletions packages/opencode/src/provider/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "path"
import z from "zod"
import { data } from "./models-macro" with { type: "macro" }
import { Installation } from "../installation"
import { Config } from "../config/config"

export namespace ModelsDev {
const log = Log.create({ service: "models.dev" })
Expand Down Expand Up @@ -69,7 +70,10 @@ export namespace ModelsDev {
export type Provider = z.infer<typeof Provider>

export async function get() {
refresh()
const config = await Config.get()
if (!config.experimental?.skip_models_fetch) {
refresh()
}
const file = Bun.file(filepath)
const result = await file.json().catch(() => {})
if (result) return result as Record<string, Provider>
Expand All @@ -96,4 +100,12 @@ export namespace ModelsDev {
}
}

setInterval(() => ModelsDev.refresh(), 60 * 1000 * 60).unref()
setInterval(
async () => {
const config = await Config.get()
if (!config.experimental?.skip_models_fetch) {
ModelsDev.refresh()
}
},
60 * 1000 * 60,
).unref()
Loading