DRYs up read model from cache logic

This commit is contained in:
Vignesh Subbiah 2025-02-08 18:44:32 +05:30
parent a8f764983f
commit c049436101

View file

@ -1775,16 +1775,20 @@ export class ClineProvider implements vscode.WebviewViewProvider {
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome
}
async readGlamaModels(): Promise<Record<string, ModelInfo> | undefined> {
const glamaModelsFilePath = path.join(await this.ensureCacheDirectoryExists(), GlobalFileNames.glamaModels)
const fileExists = await fileExistsAtPath(glamaModelsFilePath)
private async readModelsFromCache(filename: string): Promise<Record<string, ModelInfo> | undefined> {
const filePath = path.join(await this.ensureCacheDirectoryExists(), filename)
const fileExists = await fileExistsAtPath(filePath)
if (fileExists) {
const fileContents = await fs.readFile(glamaModelsFilePath, "utf8")
const fileContents = await fs.readFile(filePath, "utf8")
return JSON.parse(fileContents)
}
return undefined
}
async readGlamaModels(): Promise<Record<string, ModelInfo> | undefined> {
return this.readModelsFromCache(GlobalFileNames.glamaModels)
}
async refreshGlamaModels() {
const glamaModelsFilePath = path.join(await this.ensureCacheDirectoryExists(), GlobalFileNames.glamaModels)
@ -1860,16 +1864,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
}
async readOpenRouterModels(): Promise<Record<string, ModelInfo> | undefined> {
const openRouterModelsFilePath = path.join(
await this.ensureCacheDirectoryExists(),
GlobalFileNames.openRouterModels,
)
const fileExists = await fileExistsAtPath(openRouterModelsFilePath)
if (fileExists) {
const fileContents = await fs.readFile(openRouterModelsFilePath, "utf8")
return JSON.parse(fileContents)
}
return undefined
return this.readModelsFromCache(GlobalFileNames.openRouterModels)
}
async refreshOpenRouterModels() {
@ -1985,13 +1980,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
}
async readUnboundModels(): Promise<Record<string, ModelInfo> | undefined> {
const unboundModelsFilePath = path.join(await this.ensureCacheDirectoryExists(), GlobalFileNames.unboundModels)
const fileExists = await fileExistsAtPath(unboundModelsFilePath)
if (fileExists) {
const fileContents = await fs.readFile(unboundModelsFilePath, "utf8")
return JSON.parse(fileContents)
}
return undefined
return this.readModelsFromCache(GlobalFileNames.unboundModels)
}
async refreshUnboundModels() {