mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-14 03:56:55 +03:00
refactor(core): slice model references at the first slash (#46467)
This commit is contained in:
committed by
GitHub
Unverified
parent
db768c4886
commit
e7d42f83e6
@@ -38,10 +38,10 @@ export function compatibility(input: unknown): Compatibility | undefined {
|
||||
}
|
||||
|
||||
export function parse(input: string): { providerID: Provider.ID; modelID: ID } {
|
||||
const [providerID, ...modelID] = input.split("/")
|
||||
const index = input.indexOf("/")
|
||||
return {
|
||||
providerID: Provider.ID.make(providerID),
|
||||
modelID: ID.make(modelID.join("/")),
|
||||
providerID: Provider.ID.make(index === -1 ? input : input.slice(0, index)),
|
||||
modelID: ID.make(index === -1 ? "" : input.slice(index + 1)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,23 @@ import { Provider } from "@opencode-ai/core/provider"
|
||||
|
||||
const decode = Schema.decodeUnknownSync(Model.Ref)
|
||||
|
||||
describe("Model.parse", () => {
|
||||
test.each([
|
||||
["vendor/model", "vendor", "model"],
|
||||
["vendor/team/model", "vendor", "team/model"],
|
||||
["vendor", "vendor", ""],
|
||||
["", "", ""],
|
||||
["/model", "", "model"],
|
||||
["vendor/", "vendor", ""],
|
||||
["vendor//model/", "vendor", "/model/"],
|
||||
])("parses %j at the first slash", (input, providerID, modelID) => {
|
||||
expect(Model.parse(input)).toEqual({
|
||||
providerID: Provider.ID.make(providerID),
|
||||
modelID: Model.ID.make(modelID),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("Model.Ref", () => {
|
||||
test("accepts a model selection without a variant", () => {
|
||||
expect(decode({ id: "claude-sonnet", providerID: "anthropic" })).toEqual({
|
||||
|
||||
Reference in New Issue
Block a user