mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-07 02:58:15 +00:00
Fix provider model loading race conditions (#8836)
This commit is contained in:
parent
8870348bd3
commit
f5d7ba1959
2 changed files with 37 additions and 28 deletions
|
|
@ -58,34 +58,14 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
const cloudService = CloudService.instance
|
||||
|
||||
this.authStateListener = (state: { state: AuthState }) => {
|
||||
if (state.state === "active-session") {
|
||||
const newToken = cloudService.authService?.getSessionToken()
|
||||
this.client = new OpenAI({
|
||||
baseURL: this.baseURL,
|
||||
apiKey: newToken ?? "unauthenticated",
|
||||
defaultHeaders: DEFAULT_HEADERS,
|
||||
})
|
||||
|
||||
// Flush cache and reload models with the new auth token
|
||||
flushModels("roo")
|
||||
.then(() => {
|
||||
return this.loadDynamicModels(this.fetcherBaseURL, newToken)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("[RooHandler] Failed to reload models after auth:", error)
|
||||
})
|
||||
} else if (state.state === "logged-out") {
|
||||
this.client = new OpenAI({
|
||||
baseURL: this.baseURL,
|
||||
apiKey: "unauthenticated",
|
||||
defaultHeaders: DEFAULT_HEADERS,
|
||||
})
|
||||
|
||||
// Flush cache when logged out
|
||||
flushModels("roo").catch((error) => {
|
||||
console.error("[RooHandler] Failed to flush models on logout:", error)
|
||||
})
|
||||
}
|
||||
// Update OpenAI client with current auth token
|
||||
// Note: Model cache flush/reload is handled by extension.ts authStateChangedHandler
|
||||
const newToken = cloudService.authService?.getSessionToken()
|
||||
this.client = new OpenAI({
|
||||
baseURL: this.baseURL,
|
||||
apiKey: newToken ?? "unauthenticated",
|
||||
defaultHeaders: DEFAULT_HEADERS,
|
||||
})
|
||||
}
|
||||
|
||||
cloudService.on("auth-state-changed", this.authStateListener)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import {
|
|||
CodeActionProvider,
|
||||
} from "./activate"
|
||||
import { initializeI18n } from "./i18n"
|
||||
import { flushModels, getModels } from "./api/providers/fetchers/modelCache"
|
||||
|
||||
/**
|
||||
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
|
||||
|
|
@ -140,6 +141,34 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Roo models cache based on auth state
|
||||
const handleRooModelsCache = async () => {
|
||||
try {
|
||||
await flushModels("roo")
|
||||
|
||||
if (data.state === "active-session") {
|
||||
// Reload models with the new auth token
|
||||
const sessionToken = cloudService?.authService?.getSessionToken()
|
||||
await getModels({
|
||||
provider: "roo",
|
||||
baseUrl: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy",
|
||||
apiKey: sessionToken,
|
||||
})
|
||||
cloudLogger(`[authStateChangedHandler] Reloaded Roo models cache for active session`)
|
||||
} else {
|
||||
cloudLogger(`[authStateChangedHandler] Flushed Roo models cache on logout`)
|
||||
}
|
||||
} catch (error) {
|
||||
cloudLogger(
|
||||
`[authStateChangedHandler] Failed to handle Roo models cache: ${error instanceof Error ? error.message : String(error)}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (data.state === "active-session" || data.state === "logged-out") {
|
||||
await handleRooModelsCache()
|
||||
}
|
||||
}
|
||||
|
||||
settingsUpdatedHandler = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue