GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): no default model crash · bpd1069/opencode@f7a4cdc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app/src/context
    • local.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/context/local.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/context/local.tsx
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
126126
)
127127

128128
const [ephemeral, setEphemeral] = createStore<{
129-
model: Record<string, ModelKey>
129+
model: Record<string, ModelKey | undefined>
130130
}>({
131131
model: {},
132132
})
@@ -182,7 +182,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
182182

183183
const find = (key: ModelKey) => list().find((m) => m.id === key?.modelID && m.provider.id === key.providerID)
184184

185-
const fallbackModel = createMemo(() => {
185+
const fallbackModel = createMemo<ModelKey | undefined>(() => {
186186
if (sync.data.config.model) {
187187
const [providerID, modelID] = sync.data.config.model.split("/")
188188
if (isModelValid({ providerID, modelID })) {
@@ -199,16 +199,21 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
199199
}
200200
}
201201

202+
const defaults = providers.default()
202203
for (const p of providers.connected()) {
203-
if (p.id in providers.default()) {
204-
return {
205-
providerID: p.id,
206-
modelID: providers.default()[p.id],
207-
}
204+
const configured = defaults[p.id]
205+
if (configured) {
206+
const key = { providerID: p.id, modelID: configured }
207+
if (isModelValid(key)) return key
208208
}
209+
210+
const first = Object.values(p.models)[0]
211+
if (!first) continue
212+
const key = { providerID: p.id, modelID: first.id }
213+
if (isModelValid(key)) return key
209214
}
210215

211-
throw new Error("No default model found")
216+
return undefined
212217
})
213218

214219
const current = createMemo(() => {
@@ -266,7 +271,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
266271
set(model: ModelKey | undefined, options?: { recent?: boolean }) {
267272
batch(() => {
268273
const currentAgent = agent.current()
269-
if (currentAgent) setEphemeral("model", currentAgent.name, model ?? fallbackModel())
274+
const next = model ?? fallbackModel()
275+
if (currentAgent) setEphemeral("model", currentAgent.name, next)
270276
if (model) updateVisibility(model, "show")
271277
if (options?.recent && model) {
272278
const uniq = uniqueBy([model, ...store.recent], (x) => x.providerID + x.modelID)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.