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
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 for corporate proxy environments"),
})
.optional(),
})
Expand Down
22 changes: 20 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 @@ -78,6 +82,12 @@ export namespace ModelsDev {
}

export async function refresh() {
const config = await Config.get()
if (config.experimental?.skip_models_fetch) {
log.debug("models.dev fetch skipped by configuration")
return
}

const file = Bun.file(filepath)
log.info("refreshing", {
file,
Expand All @@ -96,4 +106,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()
25 changes: 25 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,28 @@ test("deduplicates duplicate plugins from global and local configs", async () =>
},
})
})

test("handles experimental.skip_models_fetch field", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
await Bun.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
experimental: {
skip_models_fetch: true,
batch_tool: false,
},
}),
)
},
})
await Instance.provide({
directory: tmp.path,
fn: async () => {
const config = await Config.get()
expect(config.experimental?.skip_models_fetch).toBe(true)
expect(config.experimental?.batch_tool).toBe(false)
},
})
})
2 changes: 2 additions & 0 deletions packages/sdk/go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ func (r configCommandJSON) RawJSON() string {

type ConfigExperimental struct {
DisablePasteSummary bool `json:"disable_paste_summary"`
SkipModelsFetch bool `json:"skip_models_fetch"`
Hook ConfigExperimentalHook `json:"hook"`
JSON configExperimentalJSON `json:"-"`
}
Expand All @@ -712,6 +713,7 @@ type ConfigExperimental struct {
// [ConfigExperimental]
type configExperimentalJSON struct {
DisablePasteSummary apijson.Field
SkipModelsFetch apijson.Field
Hook apijson.Field
raw string
ExtraFields map[string]apijson.Field
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/js/src/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,10 @@ export type Config = {
* Enable the batch tool
*/
batch_tool?: boolean
/**
* Skip automatic fetching of models from models.dev for corporate proxy environments
*/
skip_models_fetch?: boolean
}
}

Expand Down
Loading