Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/v1/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ function migrateModel(info: typeof ConfigProviderV1.Model.Type, npm: string | un
cost: costs,
disabled: info.status === "deprecated" ? true : undefined,
limit: info.limit && {
context: int(info.limit.context),
context: info.limit.context === undefined ? undefined : int(info.limit.context),
input: info.limit.input === undefined ? undefined : int(info.limit.input),
output: int(info.limit.output),
output: info.limit.output === undefined ? undefined : int(info.limit.output),
},
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/v1/config/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ export const Model = Schema.Struct({
}),
),
limit: Schema.optional(
// Every field optional: V2 lets an operator override just one dimension (commonly
// `{ output: 16000 }`), and requiring `context` here made that config fail V1 decoding,
// which drops the ENTIRE provider rather than the one model. See normalize.migrateProviders.
Schema.Struct({
context: Schema.Finite,
context: Schema.optional(Schema.Finite),
input: Schema.optional(Schema.Finite),
output: Schema.Finite,
output: Schema.optional(Schema.Finite),
}),
),
modalities: Schema.optional(
Expand Down
24 changes: 24 additions & 0 deletions packages/core/test/config/normalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,27 @@ describe("ConfigNormalize", () => {
expect(result.encoded.share).toBeUndefined()
})
})

describe("legacy provider decoding", () => {
// Regression: a V2-style partial limit ({ output: 16000 }) failed the V1 schema, and because
// migrateProviders decodes a whole provider atomically, ONE such model dropped the entire
// provider — every other model in it silently disappeared.
test("keeps a provider whose model overrides only limit.output", () => {
const result = normalized({
provider: {
custom: {
npm: "@ai-sdk/openai-compatible",
models: {
"some/model": { limit: { output: 16000 } },
"other/model": { limit: { context: 200000, output: 8000 } },
},
},
},
})
const providers = (result.encoded as Record<string, any>).providers ?? {}
expect(Object.keys(providers)).toContain("custom")
const models = providers.custom?.models ?? {}
expect(Object.keys(models)).toEqual(expect.arrayContaining(["some/model", "other/model"]))
expect(models["some/model"].limit).toEqual({ output: 16000 })
})
})
Loading