2026-03-25 14:47:46 +01:00
|
|
|
import * as dataPath from "./data-path"
|
2026-04-03 19:36:56 +09:00
|
|
|
import { createJsonFileCacheStore } from "./json-file-cache-store"
|
2026-05-21 16:02:41 +09:00
|
|
|
import {
|
|
|
|
|
MODELS_DEV_SOURCE_URL,
|
|
|
|
|
buildModelCapabilitiesSnapshotFromModelsDev,
|
|
|
|
|
fetchModelCapabilitiesSnapshot,
|
|
|
|
|
} from "@oh-my-opencode/model-core"
|
|
|
|
|
import type { ModelCapabilitiesSnapshot } from "./model-capabilities"
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
MODELS_DEV_SOURCE_URL,
|
|
|
|
|
buildModelCapabilitiesSnapshotFromModelsDev,
|
|
|
|
|
fetchModelCapabilitiesSnapshot,
|
2026-03-25 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-21 16:02:41 +09:00
|
|
|
const MODEL_CAPABILITIES_CACHE_FILE = "model-capabilities.json"
|
2026-03-25 14:47:46 +01:00
|
|
|
|
|
|
|
|
export function createModelCapabilitiesCacheStore(
|
|
|
|
|
getCacheDir: () => string = dataPath.getOmoOpenCodeCacheDir,
|
|
|
|
|
) {
|
2026-04-03 19:36:56 +09:00
|
|
|
const snapshotCacheStore = createJsonFileCacheStore<ModelCapabilitiesSnapshot>({
|
|
|
|
|
getCacheDir,
|
|
|
|
|
filename: MODEL_CAPABILITIES_CACHE_FILE,
|
|
|
|
|
logPrefix: "model-capabilities-cache",
|
|
|
|
|
cacheLabel: "Cache",
|
|
|
|
|
describe: (snapshot) => ({
|
|
|
|
|
modelCount: Object.keys(snapshot.models).length,
|
|
|
|
|
generatedAt: snapshot.generatedAt,
|
|
|
|
|
}),
|
|
|
|
|
serialize: (snapshot) => `${JSON.stringify(snapshot, null, 2)}\n`,
|
|
|
|
|
})
|
2026-03-25 14:47:46 +01:00
|
|
|
|
|
|
|
|
function readModelCapabilitiesCache(): ModelCapabilitiesSnapshot | null {
|
2026-04-03 19:36:56 +09:00
|
|
|
return snapshotCacheStore.read()
|
2026-03-25 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasModelCapabilitiesCache(): boolean {
|
2026-04-03 19:36:56 +09:00
|
|
|
return snapshotCacheStore.has()
|
2026-03-25 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeModelCapabilitiesCache(snapshot: ModelCapabilitiesSnapshot): void {
|
2026-04-03 19:36:56 +09:00
|
|
|
snapshotCacheStore.write(snapshot)
|
2026-03-25 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshModelCapabilitiesCache(args: {
|
|
|
|
|
sourceUrl?: string
|
2026-05-21 16:02:41 +09:00
|
|
|
fetchImpl?: (input: string) => Promise<Response>
|
2026-03-25 14:47:46 +01:00
|
|
|
} = {}): Promise<ModelCapabilitiesSnapshot> {
|
|
|
|
|
const snapshot = await fetchModelCapabilitiesSnapshot(args)
|
|
|
|
|
writeModelCapabilitiesCache(snapshot)
|
|
|
|
|
return snapshot
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
readModelCapabilitiesCache,
|
|
|
|
|
hasModelCapabilitiesCache,
|
|
|
|
|
writeModelCapabilitiesCache,
|
|
|
|
|
refreshModelCapabilitiesCache,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultModelCapabilitiesCacheStore = createModelCapabilitiesCacheStore(
|
|
|
|
|
() => dataPath.getOmoOpenCodeCacheDir(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export const {
|
|
|
|
|
readModelCapabilitiesCache,
|
|
|
|
|
hasModelCapabilitiesCache,
|
|
|
|
|
writeModelCapabilitiesCache,
|
|
|
|
|
refreshModelCapabilitiesCache,
|
|
|
|
|
} = defaultModelCapabilitiesCacheStore
|