Skip to content

Commit fd6c987

Browse files
committed
fix: add optional chaining to router model accesses to prevent TypeError when switching providers
Fixes #9047 - When switching providers after selecting a model, the router models for the new provider may not be loaded yet, causing a TypeError when trying to access properties on undefined. Added optional chaining to safely handle these cases.
1 parent 6965e5c commit fd6c987

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function getSelectedModel({
146146
switch (provider) {
147147
case "openrouter": {
148148
const id = apiConfiguration.openRouterModelId ?? openRouterDefaultModelId
149-
let info = routerModels.openrouter[id]
149+
let info = routerModels.openrouter?.[id]
150150
const specificProvider = apiConfiguration.openRouterSpecificProvider
151151

152152
if (specificProvider && openRouterModelProviders[specificProvider]) {
@@ -162,22 +162,22 @@ function getSelectedModel({
162162
}
163163
case "requesty": {
164164
const id = apiConfiguration.requestyModelId ?? requestyDefaultModelId
165-
const info = routerModels.requesty[id]
165+
const info = routerModels.requesty?.[id]
166166
return { id, info }
167167
}
168168
case "glama": {
169169
const id = apiConfiguration.glamaModelId ?? glamaDefaultModelId
170-
const info = routerModels.glama[id]
170+
const info = routerModels.glama?.[id]
171171
return { id, info }
172172
}
173173
case "unbound": {
174174
const id = apiConfiguration.unboundModelId ?? unboundDefaultModelId
175-
const info = routerModels.unbound[id]
175+
const info = routerModels.unbound?.[id]
176176
return { id, info }
177177
}
178178
case "litellm": {
179179
const id = apiConfiguration.litellmModelId ?? litellmDefaultModelId
180-
const info = routerModels.litellm[id]
180+
const info = routerModels.litellm?.[id]
181181
return { id, info }
182182
}
183183
case "xai": {
@@ -202,7 +202,7 @@ function getSelectedModel({
202202
}
203203
case "chutes": {
204204
const id = apiConfiguration.apiModelId ?? chutesDefaultModelId
205-
const info = routerModels.chutes[id]
205+
const info = routerModels.chutes?.[id]
206206
return { id, info }
207207
}
208208
case "bedrock": {
@@ -354,7 +354,7 @@ function getSelectedModel({
354354
case "roo": {
355355
// Roo is a dynamic provider - models are loaded from API
356356
const id = apiConfiguration.apiModelId ?? rooDefaultModelId
357-
const info = routerModels.roo[id]
357+
const info = routerModels.roo?.[id]
358358
return { id, info }
359359
}
360360
case "qwen-code": {

0 commit comments

Comments
 (0)