fix(models): store cache in agent directory
Resolve the Command Code model cache through the host's getAgentDir helper so pi, OMP, and PI_CODING_AGENT_DIR use their own agent state directory instead of the official Command Code client directory.
This commit is contained in:
+4
-9
@@ -1,6 +1,5 @@
|
||||
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"
|
||||
import { homedir } from "node:os"
|
||||
import { dirname, join } from "node:path"
|
||||
import { dirname } from "node:path"
|
||||
|
||||
export const DEFAULT_MODELS_URL = "https://api.commandcode.ai/provider/v1/models"
|
||||
|
||||
@@ -27,7 +26,7 @@ interface FetchCommandCodeModelsOptions {
|
||||
}
|
||||
|
||||
interface LoadCommandCodeModelsOptions extends FetchCommandCodeModelsOptions {
|
||||
cachePath?: string
|
||||
cachePath: string
|
||||
}
|
||||
|
||||
export interface LoadCommandCodeModelsResult {
|
||||
@@ -93,10 +92,6 @@ function errorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
|
||||
export function defaultCommandCodeModelsCachePath(): string {
|
||||
return join(homedir(), ".commandcode", "pi-models.json")
|
||||
}
|
||||
|
||||
export function commandCodeModelsFromApiResponse(value: unknown): readonly CommandCodeModel[] {
|
||||
if (!isRecord(value)) throw new Error("Expected models response to be an object")
|
||||
if (value.object !== "list") throw new Error("Expected models response object to be 'list'")
|
||||
@@ -174,9 +169,9 @@ async function writeCommandCodeModelsCache(
|
||||
}
|
||||
|
||||
export async function loadCommandCodeModels(
|
||||
options: LoadCommandCodeModelsOptions = {},
|
||||
options: LoadCommandCodeModelsOptions,
|
||||
): Promise<LoadCommandCodeModelsResult> {
|
||||
const cachePath = options.cachePath ?? defaultCommandCodeModelsCachePath()
|
||||
const cachePath = options.cachePath
|
||||
|
||||
try {
|
||||
const models = await fetchCommandCodeModels(options)
|
||||
|
||||
Reference in New Issue
Block a user