mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
feat(core): let custom models in config set a model type (#59388)
This commit is contained in:
committed by
GitHub
Unverified
parent
804a7f3c01
commit
a697f53611
@@ -217,6 +217,7 @@ function overlay(
|
||||
if (item.package !== undefined) model.package = undefined
|
||||
if (item.settings?.baseURL !== undefined && model.settings) delete model.settings.baseURL
|
||||
}
|
||||
if (config.type !== undefined) model.type = config.type
|
||||
if (config.family !== undefined) model.family = config.family
|
||||
if (config.name) model.name = config.name
|
||||
if (config.modelID !== undefined) model.modelID = config.modelID
|
||||
|
||||
@@ -97,6 +97,7 @@ export const register = Effect.fn("OpencodeLegacy.register")(function* (
|
||||
const base = source?.models.get(config.modelID ?? modelID) ?? source?.models.get(modelID)
|
||||
providers.models.update(providerID, modelID, (model) => {
|
||||
Object.assign(model, structuredClone(base ?? model))
|
||||
if (config.type !== undefined) model.type = config.type
|
||||
if (config.family !== undefined) model.family = config.family
|
||||
if (config.name !== undefined) model.name = config.name
|
||||
if (config.modelID !== undefined) model.modelID = config.modelID
|
||||
|
||||
@@ -397,6 +397,68 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("lists a custom model by its configured type and an untyped one as chat", () =>
|
||||
Effect.gen(function* () {
|
||||
const models = yield* Model.Service
|
||||
const entries = [
|
||||
new Document({
|
||||
type: "document",
|
||||
info: decode({
|
||||
providers: {
|
||||
custom: {
|
||||
package: "aisdk:@ai-sdk/openai-compatible",
|
||||
models: { chat: {}, painter: { type: "image" } },
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
]
|
||||
|
||||
yield* addPlugin(entries)
|
||||
|
||||
expect((yield* models.available()).map((model) => model.id)).toEqual([Model.ID.make("chat")])
|
||||
expect((yield* models.available(["image"])).map((model) => model.id)).toEqual([Model.ID.make("painter")])
|
||||
expect(yield* models.get(Provider.ID.make("custom"), Model.ID.make("painter"))).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("lets config change a catalog model's type and keeps it when unset", () =>
|
||||
Effect.gen(function* () {
|
||||
const providers = yield* Provider.Service
|
||||
const models = yield* Model.Service
|
||||
const providerID = Provider.ID.make("custom")
|
||||
const retypedID = Model.ID.make("retyped")
|
||||
const keptID = Model.ID.make("kept")
|
||||
yield* providers.transform((editor) => {
|
||||
editor.models.update(providerID, retypedID, () => {})
|
||||
editor.models.update(providerID, keptID, (model) => {
|
||||
model.type = "decision"
|
||||
})
|
||||
})
|
||||
const entries = [
|
||||
new Document({
|
||||
type: "document",
|
||||
info: decode({
|
||||
providers: {
|
||||
custom: {
|
||||
package: "aisdk:@ai-sdk/openai-compatible",
|
||||
models: { retyped: { type: "image" }, kept: { name: "Kept" } },
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
]
|
||||
|
||||
yield* addPlugin(entries)
|
||||
|
||||
expect(yield* models.available()).toEqual([])
|
||||
expect((yield* models.available(["image"])).map((model) => model.id)).toEqual([retypedID])
|
||||
expect((yield* models.available(["decision"])).map((model) => [model.id, model.name])).toEqual([
|
||||
[keptID, "Kept"],
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("preserves catalog capabilities unless config overrides them", () =>
|
||||
Effect.gen(function* () {
|
||||
const providers = yield* Provider.Service
|
||||
|
||||
Reference in New Issue
Block a user