fix(core): keep explicit native package api through catalog merge

The catalog treated any native model api with empty settings and no url as
a placeholder inheriting the provider api, which stomped plugin-assigned
native packages (ChatGPT codex retargeting) back to aisdk. A native api
carrying a package is explicitly targeted and now survives projection.
This commit is contained in:
Kit Langton 2026-07-03 14:35:48 -04:00
commit 781165c884
2 changed files with 40 additions and 1 deletions

View file

@ -77,7 +77,12 @@ const layer = Layer.effect(
const projectModel = (model: ModelV2.Info, provider: ProviderV2.Info) => {
const api =
model.api.type === "native" && !model.api.url && Object.keys(model.api.settings).length === 0
// A native api with a package is explicitly targeted; only package-less,
// settings-less native apis are placeholders that inherit the provider api.
model.api.type === "native" &&
model.api.package === undefined &&
!model.api.url &&
Object.keys(model.api.settings).length === 0
? { ...provider.api, id: model.api.id }
: model.api.type === "aisdk" && provider.api.type === "aisdk" && !model.api.url
? { ...model.api, url: provider.api.url, settings: { ...provider.api.settings, ...model.api.settings } }

View file

@ -213,6 +213,40 @@ describe("CatalogV2", () => {
}),
)
it.effect("keeps an explicit native package api over the provider api", () =>
Effect.gen(function* () {
const catalog = yield* Catalog.Service
const providerID = ProviderV2.ID.make("test")
const modelID = ModelV2.ID.make("model")
yield* catalog.transform((catalog) => {
catalog.provider.update(providerID, (provider) => {
provider.api = {
type: "aisdk",
package: "@ai-sdk/openai",
}
})
catalog.model.update(providerID, modelID, (model) => {
// Plugins retarget models at explicit native packages (e.g. ChatGPT
// subscription models at the codex package); empty settings must not
// demote the api back to the provider placeholder rule.
model.api = {
type: "native",
id: model.api.id,
package: "@opencode-ai/llm/providers/openai/codex",
settings: {},
}
})
})
expect(required(yield* catalog.model.get(providerID, modelID)).api).toEqual({
id: modelID,
type: "native",
package: "@opencode-ai/llm/providers/openai/codex",
settings: {},
})
}),
)
it.effect("resolves provider and model request merges", () =>
Effect.gen(function* () {
const catalog = yield* Catalog.Service