oh-my-opencode/src/shared/migration/model-versions.ts
YeonGyu-Kim 67c2cfddf4 fix(migration): remove non-existent gpt-5.3-codex from MODEL_VERSION_MAP
Fixes #1804, fixes #1962

The migration entry 'gpt-5.2-codex → gpt-5.3-codex' caused the plugin to silently overwrite user configs on every startup with a model that doesn't exist in the OpenAI API. Users explicitly setting gpt-5.2-codex (the correct current model) were forced to revert their config manually every session.
2026-02-21 04:08:44 +09:00

50 lines
1.7 KiB
TypeScript

/**
* Model version migration map: old full model strings → new full model strings.
* Used to auto-upgrade hardcoded model versions in user configs when the plugin
* bumps to newer model versions.
*
* Keys are full "provider/model" strings. Only openai and anthropic entries needed.
*/
export const MODEL_VERSION_MAP: Record<string, string> = {
"anthropic/claude-opus-4-5": "anthropic/claude-opus-4-6",
"anthropic/claude-sonnet-4-5": "anthropic/claude-sonnet-4-6",
}
function migrationKey(oldModel: string, newModel: string): string {
return `model-version:${oldModel}->${newModel}`
}
export function migrateModelVersions(
configs: Record<string, unknown>,
appliedMigrations?: Set<string>
): { migrated: Record<string, unknown>; changed: boolean; newMigrations: string[] } {
const migrated: Record<string, unknown> = {}
let changed = false
const newMigrations: string[] = []
for (const [key, value] of Object.entries(configs)) {
if (value && typeof value === "object" && !Array.isArray(value)) {
const config = value as Record<string, unknown>
if (typeof config.model === "string" && MODEL_VERSION_MAP[config.model]) {
const oldModel = config.model
const newModel = MODEL_VERSION_MAP[oldModel]
const mKey = migrationKey(oldModel, newModel)
// Skip if this migration was already applied (user may have reverted)
if (appliedMigrations?.has(mKey)) {
migrated[key] = value
continue
}
migrated[key] = { ...config, model: newModel }
changed = true
newMigrations.push(mKey)
continue
}
}
migrated[key] = value
}
return { migrated, changed, newMigrations }
}