Skip to content

Commit 3a687ba

Browse files
committed
fix: add explicit fallback model and prevent direct opencode provider calls
- Add fallbackModel parameter to getSmallModel() to provide explicit fallback - Check opencode provider availability before using gpt-5-nano model - Update callers in prompt.ts and summary.ts to use current model as fallback - Prevent errors when opencode provider is disabled
1 parent 7d11986 commit 3a687ba

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

packages/opencode/src/provider/provider.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ export namespace Provider {
654654
}
655655
}
656656

657-
export async function getSmallModel(providerID: string) {
657+
export async function getSmallModel(providerID: string, fallbackModel?: { providerID: string; modelID: string }) {
658658
const cfg = await Config.get()
659659

660660
if (cfg.small_model) {
@@ -685,7 +685,20 @@ export namespace Provider {
685685
}
686686
}
687687
}
688-
return getModel("opencode", "gpt-5-nano")
688+
689+
// Check if opencode provider is available before using it
690+
const opencodeProvider = await state().then((state) => state.providers["opencode"])
691+
if (opencodeProvider && opencodeProvider.info.models["gpt-5-nano"]) {
692+
return getModel("opencode", "gpt-5-nano")
693+
}
694+
695+
// Use fallback model if provided
696+
if (fallbackModel) {
697+
return getModel(fallbackModel.providerID, fallbackModel.modelID)
698+
}
699+
700+
// No fallback available
701+
throw new Error("No small model available")
689702
}
690703

691704
const priority = ["gpt-5", "claude-sonnet-4", "big-pickle", "gemini-3-pro"]

packages/opencode/src/session/prompt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,10 @@ export namespace SessionPrompt {
14081408
input.history.filter((m) => m.info.role === "user" && !m.parts.every((p) => "synthetic" in p && p.synthetic))
14091409
.length === 1
14101410
if (!isFirst) return
1411-
const small = await Provider.getSmallModel(input.providerID)
1411+
const small = await Provider.getSmallModel(input.providerID, {
1412+
providerID: input.providerID,
1413+
modelID: input.modelID,
1414+
})
14121415
const options = pipe(
14131416
{},
14141417
mergeDeep(ProviderTransform.options(small.providerID, small.modelID, small.npm ?? "", input.session.id)),

packages/opencode/src/session/summary.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export namespace SessionSummary {
7373
await Session.updateMessage(userMsg)
7474

7575
const assistantMsg = messages.find((m) => m.info.role === "assistant")!.info as MessageV2.Assistant
76-
const small = await Provider.getSmallModel(assistantMsg.providerID)
76+
const small = await Provider.getSmallModel(assistantMsg.providerID, {
77+
providerID: assistantMsg.providerID,
78+
modelID: assistantMsg.modelID,
79+
})
7780
const options = pipe(
7881
{},
7982
mergeDeep(ProviderTransform.options(small.providerID, small.modelID, small.npm ?? "", assistantMsg.sessionID)),

0 commit comments

Comments
 (0)