Skip to content

Commit da12437

Browse files
authored
fix: update the model list when the client requests a refresh (RooCodeInc#3882)
* update the model list when the client refreshes * Refactor and use the grpc response instead of a webview message
1 parent fb3012f commit da12437

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

.changeset/lovely-zoos-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
update the openrouter model list when refreshing

webview-ui/src/components/settings/OpenRouterModelPicker.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useMount } from "react-use"
66
import styled from "styled-components"
77
import { openRouterDefaultModelId } from "@shared/api"
88
import { useExtensionState } from "@/context/ExtensionStateContext"
9-
import { ModelsServiceClient, StateServiceClient } from "@/services/grpc-client"
9+
import { StateServiceClient } from "@/services/grpc-client"
1010
import { highlight } from "../history/HistoryView"
1111
import { ModelInfoView, normalizeApiConfiguration } from "./ApiOptions"
1212
import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
@@ -58,7 +58,7 @@ const featuredModels = [
5858
]
5959

6060
const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup }) => {
61-
const { apiConfiguration, setApiConfiguration, openRouterModels } = useExtensionState()
61+
const { apiConfiguration, setApiConfiguration, openRouterModels, refreshOpenRouterModels } = useExtensionState()
6262
const [searchTerm, setSearchTerm] = useState(apiConfiguration?.openRouterModelId || openRouterDefaultModelId)
6363
const [isDropdownVisible, setIsDropdownVisible] = useState(false)
6464
const [selectedIndex, setSelectedIndex] = useState(-1)
@@ -83,11 +83,7 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup }
8383
return normalizeApiConfiguration(apiConfiguration)
8484
}, [apiConfiguration])
8585

86-
useMount(() => {
87-
ModelsServiceClient.refreshOpenRouterModels({}).catch((error: Error) =>
88-
console.error("Failed to refresh OpenRouter models:", error),
89-
)
90-
})
86+
useMount(refreshOpenRouterModels)
9187

9288
useEffect(() => {
9389
const handleClickOutside = (event: MouseEvent) => {

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { createContext, useCallback, useContext, useEffect, useState, useRef } from "react"
22
import { useEvent } from "react-use"
3-
import { StateServiceClient } from "../services/grpc-client"
4-
import { EmptyRequest } from "@shared/proto/common"
3+
import { ModelsServiceClient, StateServiceClient } from "../services/grpc-client"
54
import { DEFAULT_AUTO_APPROVAL_SETTINGS } from "@shared/AutoApprovalSettings"
65
import { ExtensionMessage, ExtensionState, DEFAULT_PLATFORM } from "@shared/ExtensionMessage"
76
import {
@@ -61,6 +60,9 @@ interface ExtensionStateContextType extends ExtensionState {
6160
setMcpMarketplaceCatalog: (value: McpMarketplaceCatalog) => void
6261
setTotalTasksSize: (value: number | null) => void
6362

63+
// Refresh functions
64+
refreshOpenRouterModels: () => void
65+
6466
// Navigation state setters
6567
setShowMcp: (value: boolean) => void
6668
setMcpTab: (tab?: McpViewTab) => void
@@ -358,6 +360,17 @@ export const ExtensionStateContextProvider: React.FC<{
358360
}
359361
}, [])
360362

363+
const refreshOpenRouterModels = useCallback(() => {
364+
ModelsServiceClient.refreshOpenRouterModels({})
365+
.then((res) => {
366+
setOpenRouterModels({
367+
[openRouterDefaultModelId]: openRouterDefaultModelInfo, // in case the extension sent a model list without the default model
368+
...res.models,
369+
})
370+
})
371+
.catch((error: Error) => console.error("Failed to refresh OpenRouter models:", error))
372+
}, [])
373+
361374
const contextValue: ExtensionStateContextType = {
362375
...state,
363376
didHydrateState,
@@ -489,6 +502,7 @@ export const ExtensionStateContextProvider: React.FC<{
489502
})),
490503
setMcpTab,
491504
setTotalTasksSize,
505+
refreshOpenRouterModels,
492506
}
493507

494508
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>

0 commit comments

Comments
 (0)