Skip to content

Commit a697f53

Browse files
authored
feat(core): let custom models in config set a model type (anomalyco#59388)
1 parent 804a7f3 commit a697f53

7 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core/src/config/plugin/provider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ function overlay(
217217
if (item.package !== undefined) model.package = undefined
218218
if (item.settings?.baseURL !== undefined && model.settings) delete model.settings.baseURL
219219
}
220+
if (config.type !== undefined) model.type = config.type
220221
if (config.family !== undefined) model.family = config.family
221222
if (config.name) model.name = config.name
222223
if (config.modelID !== undefined) model.modelID = config.modelID

‎packages/core/src/plugin/provider/opencode-legacy.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const register = Effect.fn("OpencodeLegacy.register")(function* (
9797
const base = source?.models.get(config.modelID ?? modelID) ?? source?.models.get(modelID)
9898
providers.models.update(providerID, modelID, (model) => {
9999
Object.assign(model, structuredClone(base ?? model))
100+
if (config.type !== undefined) model.type = config.type
100101
if (config.family !== undefined) model.family = config.family
101102
if (config.name !== undefined) model.name = config.name
102103
if (config.modelID !== undefined) model.modelID = config.modelID

‎packages/core/test/config/provider.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,68 @@ describe("ConfigProviderPlugin.Plugin", () => {
397397
}),
398398
)
399399

400+
it.effect("lists a custom model by its configured type and an untyped one as chat", () =>
401+
Effect.gen(function* () {
402+
const models = yield* Model.Service
403+
const entries = [
404+
new Document({
405+
type: "document",
406+
info: decode({
407+
providers: {
408+
custom: {
409+
package: "aisdk:@ai-sdk/openai-compatible",
410+
models: { chat: {}, painter: { type: "image" } },
411+
},
412+
},
413+
}),
414+
}),
415+
]
416+
417+
yield* addPlugin(entries)
418+
419+
expect((yield* models.available()).map((model) => model.id)).toEqual([Model.ID.make("chat")])
420+
expect((yield* models.available(["image"])).map((model) => model.id)).toEqual([Model.ID.make("painter")])
421+
expect(yield* models.get(Provider.ID.make("custom"), Model.ID.make("painter"))).toBeUndefined()
422+
}),
423+
)
424+
425+
it.effect("lets config change a catalog model's type and keeps it when unset", () =>
426+
Effect.gen(function* () {
427+
const providers = yield* Provider.Service
428+
const models = yield* Model.Service
429+
const providerID = Provider.ID.make("custom")
430+
const retypedID = Model.ID.make("retyped")
431+
const keptID = Model.ID.make("kept")
432+
yield* providers.transform((editor) => {
433+
editor.models.update(providerID, retypedID, () => {})
434+
editor.models.update(providerID, keptID, (model) => {
435+
model.type = "decision"
436+
})
437+
})
438+
const entries = [
439+
new Document({
440+
type: "document",
441+
info: decode({
442+
providers: {
443+
custom: {
444+
package: "aisdk:@ai-sdk/openai-compatible",
445+
models: { retyped: { type: "image" }, kept: { name: "Kept" } },
446+
},
447+
},
448+
}),
449+
}),
450+
]
451+
452+
yield* addPlugin(entries)
453+
454+
expect(yield* models.available()).toEqual([])
455+
expect((yield* models.available(["image"])).map((model) => model.id)).toEqual([retypedID])
456+
expect((yield* models.available(["decision"])).map((model) => [model.id, model.name])).toEqual([
457+
[keptID, "Kept"],
458+
])
459+
}),
460+
)
461+
400462
it.effect("preserves catalog capabilities unless config overrides them", () =>
401463
Effect.gen(function* () {
402464
const providers = yield* Provider.Service

‎packages/protocol/openapi.json‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/schema/src/config/provider.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * as ConfigProvider from "./provider.js"
22

33
import { Schema } from "effect"
44
import { Money } from "../money.js"
5-
import { Capabilities, Compatibility, Family, ID, Model, VariantID } from "../model.js"
5+
import { Capabilities, Compatibility, Family, ID, Model, Type, VariantID } from "../model.js"
66
import { ProviderCompatibility } from "../model-compatibility.js"
77
import { Provider } from "../provider.js"
88
import { optional } from "../schema.js"
@@ -74,6 +74,7 @@ export type Reasoning = typeof Reasoning.Type
7474

7575
class ModelConfig extends Schema.Class<ModelConfig>("Config.Model")({
7676
modelID: ID.pipe(optional),
77+
type: Type.pipe(optional),
7778
family: Family.pipe(optional),
7879
name: Schema.String.pipe(optional),
7980
releaseDate: Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}(-\d{2})?$/u))

‎services/www/src/docs/content/providers.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ ID sent to the provider.
293293
| `modelID` | Model or deployment ID sent to the provider. |
294294
| `name` | Display name. |
295295
| `family` | Model family used for grouping related models. |
296+
| `type` | What the model produces, such as `chat`, `image` or `decision`. Defaults to `chat`; only chat models are offered for sessions. |
296297
| `releaseDate` | Release date as `YYYY-MM-DD` or `YYYY-MM`. |
297298
| `package` | Runtime override for this model. |
298299
| `settings` | Model-level OpenCode controls and package-specific JSON settings. |

0 commit comments

Comments
 (0)