Skip to content

Commit a72aae3

Browse files
committed
Add optional chaining to prevent TypeError during provider transitions
Also fixes issue #9047 where switching providers after selecting a model causes TypeError when router models are undefined during transitions.
1 parent c693f1c commit a72aae3

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
@@ -137,7 +137,7 @@ function getSelectedModel({
137137
switch (provider) {
138138
case "openrouter": {
139139
const id = getValidatedModelId(apiConfiguration.openRouterModelId, routerModels.openrouter, defaultModelId)
140-
let info = routerModels.openrouter[id]
140+
let info = routerModels.openrouter?.[id]
141141
const specificProvider = apiConfiguration.openRouterSpecificProvider
142142

143143
if (specificProvider && openRouterModelProviders[specificProvider]) {
@@ -153,22 +153,22 @@ function getSelectedModel({
153153
}
154154
case "requesty": {
155155
const id = getValidatedModelId(apiConfiguration.requestyModelId, routerModels.requesty, defaultModelId)
156-
const info = routerModels.requesty[id]
156+
const info = routerModels.requesty?.[id]
157157
return { id, info }
158158
}
159159
case "glama": {
160160
const id = getValidatedModelId(apiConfiguration.glamaModelId, routerModels.glama, defaultModelId)
161-
const info = routerModels.glama[id]
161+
const info = routerModels.glama?.[id]
162162
return { id, info }
163163
}
164164
case "unbound": {
165165
const id = getValidatedModelId(apiConfiguration.unboundModelId, routerModels.unbound, defaultModelId)
166-
const info = routerModels.unbound[id]
166+
const info = routerModels.unbound?.[id]
167167
return { id, info }
168168
}
169169
case "litellm": {
170170
const id = getValidatedModelId(apiConfiguration.litellmModelId, routerModels.litellm, defaultModelId)
171-
const info = routerModels.litellm[id]
171+
const info = routerModels.litellm?.[id]
172172
return { id, info }
173173
}
174174
case "xai": {
@@ -193,7 +193,7 @@ function getSelectedModel({
193193
}
194194
case "chutes": {
195195
const id = getValidatedModelId(apiConfiguration.apiModelId, routerModels.chutes, defaultModelId)
196-
const info = routerModels.chutes[id]
196+
const info = routerModels.chutes?.[id]
197197
return { id, info }
198198
}
199199
case "bedrock": {
@@ -348,7 +348,7 @@ function getSelectedModel({
348348
}
349349
case "roo": {
350350
const id = getValidatedModelId(apiConfiguration.apiModelId, routerModels.roo, defaultModelId)
351-
const info = routerModels.roo[id]
351+
const info = routerModels.roo?.[id]
352352
return { id, info }
353353
}
354354
case "qwen-code": {

0 commit comments

Comments
 (0)