@@ -126,7 +126,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ |
126 | 126 | ) |
127 | 127 |
|
128 | 128 | const [ephemeral, setEphemeral] = createStore<{ |
129 | | - model: Record<string, ModelKey> |
| 129 | + model: Record<string, ModelKey | undefined> |
130 | 130 | }>({ |
131 | 131 | model: {}, |
132 | 132 | }) |
@@ -182,7 +182,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ |
182 | 182 |
|
183 | 183 | const find = (key: ModelKey) => list().find((m) => m.id === key?.modelID && m.provider.id === key.providerID) |
184 | 184 |
|
185 | | - const fallbackModel = createMemo(() => { |
| 185 | + const fallbackModel = createMemo<ModelKey | undefined>(() => { |
186 | 186 | if (sync.data.config.model) { |
187 | 187 | const [providerID, modelID] = sync.data.config.model.split("/") |
188 | 188 | if (isModelValid({ providerID, modelID })) { |
@@ -199,16 +199,21 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ |
199 | 199 | } |
200 | 200 | } |
201 | 201 |
|
| 202 | + const defaults = providers.default() |
202 | 203 | 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 |
208 | 208 | } |
| 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 |
209 | 214 | } |
210 | 215 |
|
211 | | - throw new Error("No default model found") |
| 216 | + return undefined |
212 | 217 | }) |
213 | 218 |
|
214 | 219 | const current = createMemo(() => { |
@@ -266,7 +271,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({ |
266 | 271 | set(model: ModelKey | undefined, options?: { recent?: boolean }) { |
267 | 272 | batch(() => { |
268 | 273 | 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) |
270 | 276 | if (model) updateVisibility(model, "show") |
271 | 277 | if (options?.recent && model) { |
272 | 278 | const uniq = uniqueBy([model, ...store.recent], (x) => x.providerID + x.modelID) |
|