edaa95fec0
Move three pure helpers from src/shared/ into @oh-my-opencode/model-core so the package can stand alone without depending on plugin internals:
- buildModelCapabilitiesSnapshotFromModelsDev + fetchModelCapabilitiesSnapshot (models.dev normalization)
- parseModelSuggestion (cross-provider ProviderModelNotFoundError suggestion extraction)
- resolveActualContextLimit (Anthropic GA 1M context override)
Split provider-model-id-transform into two variants exposed by model-core:
- transformModelForProvider keeps the runtime dash to dot Anthropic rewrite used by the SDK
- transformModelForProviderDisplay preserves hyphenated Anthropic IDs so the installer writes registry-compatible model strings, fixing the ProviderModelNotFoundError fresh installs hit when the dotted form leaks into the config
src/shared/* and src/cli/provider-model-id-transform.ts collapse to re-export shims that point at the new core modules. Stale src/shared/{known-variants,model-capability-aliases,model-capability-guardrails,model-capability-heuristics}.ts re-export files plus the duplicated context-limit-resolver test are removed in favor of the canonical model-core copies.
Tests: bun test packages/model-core src/shared/model-capabilities-cache.test.ts src/cli/provider-model-id-transform.test.ts
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import * as dataPath from "./data-path"
|
|
import { createJsonFileCacheStore } from "./json-file-cache-store"
|
|
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,
|
|
}
|
|
|
|
const MODEL_CAPABILITIES_CACHE_FILE = "model-capabilities.json"
|
|
|
|
export function createModelCapabilitiesCacheStore(
|
|
getCacheDir: () => string = dataPath.getOmoOpenCodeCacheDir,
|
|
) {
|
|
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`,
|
|
})
|
|
|
|
function readModelCapabilitiesCache(): ModelCapabilitiesSnapshot | null {
|
|
return snapshotCacheStore.read()
|
|
}
|
|
|
|
function hasModelCapabilitiesCache(): boolean {
|
|
return snapshotCacheStore.has()
|
|
}
|
|
|
|
function writeModelCapabilitiesCache(snapshot: ModelCapabilitiesSnapshot): void {
|
|
snapshotCacheStore.write(snapshot)
|
|
}
|
|
|
|
async function refreshModelCapabilitiesCache(args: {
|
|
sourceUrl?: string
|
|
fetchImpl?: (input: string) => Promise<Response>
|
|
} = {}): 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
|