Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions src/api/providers/roo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ export async function activate(context: vscode.ExtensionContext) {
)
}
}

// Flush and reload Roo models cache on auth state change to ensure fresh token is used
try {
const { flushModels, getModels } = await import("./api/providers/fetchers/modelCache")
await flushModels("roo")

// Reload models with current 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 state: ${data.state}`)
} catch (error) {
cloudLogger(
`[authStateChangedHandler] Failed to reload Roo models cache: ${error instanceof Error ? error.message : String(error)}`,
)
}
}

settingsUpdatedHandler = async () => {
Expand Down