Skip to content

Commit d442484

Browse files
committed
PR feedback
1 parent 18aeb4f commit d442484

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/api/providers/roo.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import { ApiStream } from "../transform/stream"
1010
import type { ApiHandlerCreateMessageMetadata } from "../index"
1111
import { DEFAULT_HEADERS } from "./constants"
1212
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
13-
import { getModels, flushModels } from "../providers/fetchers/modelCache"
13+
import { getModels, flushModels, getModelsFromCache } from "../providers/fetchers/modelCache"
1414

1515
export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
1616
private authStateListener?: (state: { state: AuthState }) => void
17-
private mergedModels: Record<string, ModelInfo> = {}
18-
private modelsLoaded = false
1917
private fetcherBaseURL: string
2018

2119
constructor(options: ApiHandlerOptions) {
@@ -77,12 +75,10 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
7775
defaultHeaders: DEFAULT_HEADERS,
7876
})
7977

80-
// Flush cache and clear models when logged out
78+
// Flush cache when logged out
8179
flushModels("roo").catch((error) => {
8280
console.error("[RooHandler] Failed to flush models on logout:", error)
8381
})
84-
this.mergedModels = {}
85-
this.modelsLoaded = false
8682
}
8783
}
8884

@@ -139,26 +135,23 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
139135

140136
private async loadDynamicModels(baseURL: string, apiKey?: string): Promise<void> {
141137
try {
142-
const dynamicModels = await getModels({
138+
// Fetch models and cache them in the shared cache
139+
await getModels({
143140
provider: "roo",
144141
baseUrl: baseURL,
145142
apiKey,
146143
})
147-
this.modelsLoaded = true
148-
149-
this.mergedModels = dynamicModels as Record<string, ModelInfo>
150144
} catch (error) {
151145
console.error("[RooHandler] Error loading dynamic models:", error)
152-
// Models will remain empty until successfully loaded
153-
this.modelsLoaded = false
154146
}
155147
}
156148

157149
override getModel() {
158150
const modelId = this.options.apiModelId || rooDefaultModelId
159151

160-
// Try to find the model in the dynamically loaded models
161-
const modelInfo = this.mergedModels[modelId]
152+
// Get models from shared cache
153+
const models = getModelsFromCache("roo") || {}
154+
const modelInfo = models[modelId]
162155

163156
if (modelInfo) {
164157
return { id: modelId, info: modelInfo }

0 commit comments

Comments
 (0)