mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(core): send unknown v1 openai-compatible model options in the request body (#54694)
This commit is contained in:
committed by
GitHub
Unverified
parent
5b7bad23b9
commit
5683367e27
@@ -120,7 +120,7 @@ function migrateStandardProvider(info: ConfigProviderV1.Info) {
|
||||
body: info.options && options.body,
|
||||
models:
|
||||
info.models &&
|
||||
Object.fromEntries(Object.entries(info.models).map(([name, model]) => [name, migrateModel(model)])),
|
||||
Object.fromEntries(Object.entries(info.models).map(([name, model]) => [name, migrateModel(model, info.npm)])),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ export function providerID(input: string) {
|
||||
return input
|
||||
}
|
||||
|
||||
function migrateModel(info: typeof ConfigProviderV1.Model.Type) {
|
||||
function migrateModel(info: typeof ConfigProviderV1.Model.Type, npm: string | undefined) {
|
||||
const disableThinkingBlockBinding =
|
||||
info.options?.thinking?.blockBinding === false || info.options?.reasoningConfig?.blockBinding === false
|
||||
const options = info.options && { ...info.options }
|
||||
@@ -185,7 +185,13 @@ function migrateModel(info: typeof ConfigProviderV1.Model.Type) {
|
||||
}
|
||||
}
|
||||
|
||||
const settings = options && ConfigProviderOptionsV1.model(options)
|
||||
const compatible = (info.provider?.npm ?? npm) === "@ai-sdk/openai-compatible"
|
||||
const split = (input: Record<string, unknown>) =>
|
||||
compatible
|
||||
? ConfigProviderOptionsV1.compatibleModel(input)
|
||||
: { settings: ConfigProviderOptionsV1.model(input), body: undefined }
|
||||
const migrated = options && split(options)
|
||||
const settings = migrated?.settings
|
||||
const compatibility = Model.compatibility(info.interleaved)
|
||||
const costs = info.cost && [
|
||||
{
|
||||
@@ -224,12 +230,10 @@ function migrateModel(info: typeof ConfigProviderV1.Model.Type) {
|
||||
settings: info.provider?.api ? { ...settings, baseURL: info.provider.api } : settings,
|
||||
capabilities,
|
||||
headers: info.headers,
|
||||
body: migrated?.body,
|
||||
variants:
|
||||
info.variants &&
|
||||
Object.entries(info.variants).map(([id, options]) => ({
|
||||
id,
|
||||
settings: ConfigProviderOptionsV1.model(options),
|
||||
})),
|
||||
Object.entries(info.variants).map(([id, options]) => ({ id, ...split(options) })),
|
||||
cost: costs,
|
||||
disabled: info.status === "deprecated" ? true : undefined,
|
||||
limit: info.limit && {
|
||||
|
||||
@@ -29,3 +29,30 @@ export function provider(options: Options): ProviderResult {
|
||||
export function model(options: Options) {
|
||||
return { ...options }
|
||||
}
|
||||
|
||||
// Model options read before the request is built; v1's `@ai-sdk/openai-compatible` sent every other one verbatim
|
||||
// in the request body.
|
||||
const COMPATIBLE_KEYS = new Set([
|
||||
"apiKey",
|
||||
"baseURL",
|
||||
"headers",
|
||||
"body",
|
||||
"extraBody",
|
||||
"timeout",
|
||||
"chunkTimeout",
|
||||
"headerTimeout",
|
||||
"disabled",
|
||||
"reasoningEffort",
|
||||
"textVerbosity",
|
||||
"user",
|
||||
"strictJsonSchema",
|
||||
])
|
||||
|
||||
export function compatibleModel(options: Options) {
|
||||
const entries = Object.entries(options)
|
||||
const body = Object.fromEntries(entries.filter(([key]) => !COMPATIBLE_KEYS.has(key)))
|
||||
return {
|
||||
settings: Object.fromEntries(entries.filter(([key]) => COMPATIBLE_KEYS.has(key))),
|
||||
body: Object.keys(body).length ? body : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1564,6 +1564,16 @@ describe("Config", () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
litellm: {
|
||||
npm: "@ai-sdk/openai-compatible",
|
||||
options: { baseURL: "https://litellm.example/v1" },
|
||||
models: {
|
||||
"glm-5.3-flashx": {
|
||||
options: { reasoningEffort: "high", allowed_openai_params: ["reasoning_effort"] },
|
||||
variants: { thinking: { chat_template_kwargs: { enable_thinking: true } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
compaction: { auto: true, tail_turns: 3, preserve_recent_tokens: 2000, reserved: 10000 },
|
||||
experimental: { mcp_timeout: 5000 },
|
||||
@@ -1641,6 +1651,11 @@ describe("Config", () => {
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(documents[0]?.info.providers?.litellm?.models?.["glm-5.3-flashx"]).toMatchObject({
|
||||
settings: { reasoningEffort: "high" },
|
||||
body: { allowed_openai_params: ["reasoning_effort"] },
|
||||
variants: [{ id: "thinking", settings: {}, body: { chat_template_kwargs: { enable_thinking: true } } }],
|
||||
})
|
||||
expect(documents[0]?.info.compaction).toEqual({
|
||||
auto: true,
|
||||
keep: { tokens: 2000 },
|
||||
|
||||
@@ -24,6 +24,27 @@ describe("ConfigProviderOptionsV1", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("moves openai-compatible options the package does not read into the body", () => {
|
||||
expect(
|
||||
ConfigProviderOptionsV1.compatibleModel({
|
||||
reasoningEffort: "high",
|
||||
timeout: 1000,
|
||||
allowed_openai_params: ["reasoning_effort"],
|
||||
chat_template_kwargs: { enable_thinking: true },
|
||||
}),
|
||||
).toEqual({
|
||||
settings: { reasoningEffort: "high", timeout: 1000 },
|
||||
body: {
|
||||
allowed_openai_params: ["reasoning_effort"],
|
||||
chat_template_kwargs: { enable_thinking: true },
|
||||
},
|
||||
})
|
||||
expect(ConfigProviderOptionsV1.compatibleModel({ reasoningEffort: "low" })).toEqual({
|
||||
settings: { reasoningEffort: "low" },
|
||||
body: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
test("keeps model and variant options unchanged", () => {
|
||||
expect(
|
||||
ConfigProviderOptionsV1.model({
|
||||
|
||||
Reference in New Issue
Block a user