Skip to content

Commit 536137e

Browse files
committed
roo provider: update session token on every request
1 parent ed45d1c commit 536137e

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/api/providers/roo.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ type RooChatCompletionParams = OpenAI.Chat.ChatCompletionCreateParamsStreaming &
2828
reasoning?: RooReasoningParams
2929
}
3030

31+
function getSessionToken(): string {
32+
const token = CloudService.hasInstance() ? CloudService.instance.authService?.getSessionToken() : undefined
33+
return token ?? "unauthenticated"
34+
}
35+
3136
export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
32-
private authStateListener?: (state: { state: AuthState }) => void
3337
private fetcherBaseURL: string
3438

3539
constructor(options: ApiHandlerOptions) {
@@ -52,7 +56,7 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
5256
...options,
5357
providerName: "Roo Code Cloud",
5458
baseURL, // Already has /v1 suffix
55-
apiKey: sessionToken || "unauthenticated", // Use a placeholder if no token.
59+
apiKey: getSessionToken(),
5660
defaultProviderModelId: rooDefaultModelId,
5761
providerModels: {},
5862
defaultTemperature: 0.7,
@@ -63,29 +67,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
6367
this.loadDynamicModels(this.fetcherBaseURL, sessionToken).catch((error) => {
6468
console.error("[RooHandler] Failed to load dynamic models:", error)
6569
})
66-
67-
if (CloudService.hasInstance()) {
68-
const cloudService = CloudService.instance
69-
70-
this.authStateListener = (state: { state: AuthState }) => {
71-
// Update OpenAI client with current auth token
72-
// Note: Model cache flush/reload is handled by extension.ts authStateChangedHandler
73-
const newToken = cloudService.authService?.getSessionToken()
74-
this.client = new OpenAI({
75-
baseURL: this.baseURL,
76-
apiKey: newToken ?? "unauthenticated",
77-
defaultHeaders: DEFAULT_HEADERS,
78-
})
79-
}
80-
81-
cloudService.on("auth-state-changed", this.authStateListener)
82-
}
83-
}
84-
85-
dispose() {
86-
if (this.authStateListener && CloudService.hasInstance()) {
87-
CloudService.instance.off("auth-state-changed", this.authStateListener)
88-
}
8970
}
9071

9172
protected override createStream(
@@ -127,6 +108,7 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
127108
}
128109

129110
try {
111+
this.client.apiKey = getSessionToken()
130112
return this.client.chat.completions.create(rooParams, requestOptions)
131113
} catch (error) {
132114
throw handleOpenAIError(error, this.providerName)

0 commit comments

Comments
 (0)