Skip to content

Commit e78aace

Browse files
committed
Better model reloading on auth state change
1 parent b941b65 commit e78aace

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,39 @@ export const webviewMessageHandler = async (
930930
}
931931
break
932932
}
933+
case "requestRooModels": {
934+
// Specific handler for Roo models only - flushes cache to ensure fresh auth token is used
935+
try {
936+
// Flush cache first to ensure fresh models with current auth state
937+
await flushModels("roo")
938+
939+
const rooModels = await getModels({
940+
provider: "roo",
941+
baseUrl: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy",
942+
apiKey: CloudService.hasInstance()
943+
? CloudService.instance.authService?.getSessionToken()
944+
: undefined,
945+
})
946+
947+
if (Object.keys(rooModels).length > 0) {
948+
provider.postMessageToWebview({
949+
type: "singleRouterModelFetchResponse",
950+
success: true,
951+
values: { provider: "roo", models: rooModels },
952+
})
953+
}
954+
} catch (error) {
955+
// Send error response
956+
const errorMessage = error instanceof Error ? error.message : String(error)
957+
provider.postMessageToWebview({
958+
type: "singleRouterModelFetchResponse",
959+
success: false,
960+
error: errorMessage,
961+
values: { provider: "roo" },
962+
})
963+
}
964+
break
965+
}
933966
case "requestOpenAiModels":
934967
if (message?.values?.baseUrl && message?.values?.apiKey) {
935968
const openAiModels = await getOpenAiModels(

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface WebviewMessage {
6969
| "requestOpenAiModels"
7070
| "requestOllamaModels"
7171
| "requestLmStudioModels"
72+
| "requestRooModels"
7273
| "requestVsCodeLmModels"
7374
| "requestHuggingFaceModels"
7475
| "openImage"

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
289289
global: {},
290290
})
291291
const [includeTaskHistoryInEnhance, setIncludeTaskHistoryInEnhance] = useState(true)
292+
const [prevCloudIsAuthenticated, setPrevCloudIsAuthenticated] = useState(false)
292293

293294
const setListApiConfigMeta = useCallback(
294295
(value: ProviderSettingsEntry[]) => setState((prevState) => ({ ...prevState, listApiConfigMeta: value })),
@@ -420,6 +421,16 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
420421
vscode.postMessage({ type: "webviewDidLaunch" })
421422
}, [])
422423

424+
// Watch for authentication state changes and refresh Roo models
425+
useEffect(() => {
426+
const currentAuth = state.cloudIsAuthenticated ?? false
427+
if (!prevCloudIsAuthenticated && currentAuth) {
428+
// User just authenticated - refresh Roo models with the new auth token
429+
vscode.postMessage({ type: "requestRooModels" })
430+
}
431+
setPrevCloudIsAuthenticated(currentAuth)
432+
}, [state.cloudIsAuthenticated, prevCloudIsAuthenticated])
433+
423434
const contextValue: ExtensionStateContextType = {
424435
...state,
425436
reasoningBlockCollapsed: state.reasoningBlockCollapsed ?? true,

0 commit comments

Comments
 (0)