Skip to content

Commit d0db5b1

Browse files
committed
fix(provider): ModelsDev returns empty when disk empty and fetch disabled
1 parent ca8db31 commit d0db5b1

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/core/src/models-dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ export const layer = Layer.effect(
199199
const populate = Effect.gen(function* () {
200200
const fromDisk = yield* loadFromDisk
201201
if (fromDisk) return fromDisk
202+
if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}
202203
const snapshot = yield* loadSnapshot
203204
if (snapshot) return snapshot
204-
if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}
205205
// Flock is cross-process: concurrent opencode CLIs can race on this cache file.
206206
const text = yield* Effect.scoped(
207207
Effect.gen(function* () {

packages/opencode/src/provider/provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,13 @@ export const layer = Layer.effect(
15851585
(v) => omit(v, ["disabled"]),
15861586
)
15871587
}
1588+
1589+
const configLimit = configProvider?.models?.[modelID]?.limit
1590+
if (configLimit) {
1591+
if (configLimit.context) model.limit.context = configLimit.context
1592+
if (configLimit.input) model.limit.input = configLimit.input
1593+
if (configLimit.output) model.limit.output = configLimit.output
1594+
}
15881595
}
15891596

15901597
if (Object.keys(provider.models).length === 0) {

packages/opencode/test/provider/provider.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,31 @@ it.instance(
10981098
},
10991099
)
11001100

1101+
it.instance(
1102+
"config provider model limit overrides individual fields",
1103+
Effect.gen(function* () {
1104+
const providers = yield* list
1105+
const model = providers[ProviderV2.ID.make("limit-override")].models[ModelV2.ID.make("model")]
1106+
expect(model.limit.context).toBe(100000)
1107+
expect(model.limit.input).toBe(80000)
1108+
expect(model.limit.output).toBe(16000)
1109+
}),
1110+
{
1111+
config: {
1112+
provider: {
1113+
"limit-override": {
1114+
name: "Limit Override Provider",
1115+
npm: "@ai-sdk/openai-compatible",
1116+
env: [],
1117+
models: { model: { name: "Model", tool_call: true, limit: { context: 100000, input: 80000, output: 16000 } } },
1118+
options: { apiKey: "test" },
1119+
},
1120+
},
1121+
},
1122+
},
1123+
)
1124+
1125+
11011126
it.instance(
11021127
"provider options are deeply merged",
11031128
Effect.gen(function* () {

0 commit comments

Comments
 (0)