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
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "bun:test"
|
|
|
|
import { parseModelSuggestion } from "./parse-model-suggestion"
|
|
|
|
describe("parseModelSuggestion", () => {
|
|
it("extracts suggestions from structured Anthropic ProviderModelNotFoundError", () => {
|
|
const error = {
|
|
name: "ProviderModelNotFoundError",
|
|
data: {
|
|
providerID: "anthropic",
|
|
modelID: "claude-sonet-4",
|
|
suggestions: ["claude-sonnet-4", "claude-sonnet-4-6"],
|
|
},
|
|
}
|
|
|
|
expect(parseModelSuggestion(error)).toEqual({
|
|
providerID: "anthropic",
|
|
modelID: "claude-sonet-4",
|
|
suggestion: "claude-sonnet-4",
|
|
})
|
|
})
|
|
|
|
it("extracts suggestions from nested OpenAI errors", () => {
|
|
const error = {
|
|
data: {
|
|
name: "ProviderModelNotFoundError",
|
|
data: {
|
|
providerID: "openai",
|
|
modelID: "gpt-5",
|
|
suggestions: ["gpt-5.4"],
|
|
},
|
|
},
|
|
}
|
|
|
|
expect(parseModelSuggestion(error)).toEqual({
|
|
providerID: "openai",
|
|
modelID: "gpt-5",
|
|
suggestion: "gpt-5.4",
|
|
})
|
|
})
|
|
|
|
it("extracts suggestions from Bedrock-style model-not-found messages", () => {
|
|
const error = new Error(
|
|
"Model not found: aws-bedrock-anthropic/claude-sonet-4. Did you mean: claude-sonnet-4, claude-sonnet-4-6?",
|
|
)
|
|
|
|
expect(parseModelSuggestion(error)).toEqual({
|
|
providerID: "aws-bedrock-anthropic",
|
|
modelID: "claude-sonet-4",
|
|
suggestion: "claude-sonnet-4",
|
|
})
|
|
})
|
|
|
|
it("extracts suggestions from plain string message payloads", () => {
|
|
const error = "Model not found: openai/gtp-5. Did you mean: gpt-5?"
|
|
|
|
expect(parseModelSuggestion(error)).toEqual({
|
|
providerID: "openai",
|
|
modelID: "gtp-5",
|
|
suggestion: "gpt-5",
|
|
})
|
|
})
|
|
|
|
it("returns null for unrelated errors", () => {
|
|
expect(parseModelSuggestion(new Error("Connection timeout"))).toBeNull()
|
|
expect(parseModelSuggestion(null)).toBeNull()
|
|
})
|
|
})
|