fix(ai): forward Anthropic provider options (#38694)
This commit is contained in:
parent
c5680a206e
commit
c06186a9d9
3 changed files with 20 additions and 2 deletions
|
|
@ -3,7 +3,7 @@ import { AnthropicMessages } from "../protocols/anthropic-messages"
|
||||||
import { Auth } from "../route/auth"
|
import { Auth } from "../route/auth"
|
||||||
import type { ProviderAuthOption } from "../route/auth-options"
|
import type { ProviderAuthOption } from "../route/auth-options"
|
||||||
import type { RouteDefaultsInput } from "../route/client"
|
import type { RouteDefaultsInput } from "../route/client"
|
||||||
import { ProviderID, type ModelID } from "../schema"
|
import { ProviderID, type ModelID, type ProviderOptions } from "../schema"
|
||||||
|
|
||||||
export const id = ProviderID.make("anthropic-compatible")
|
export const id = ProviderID.make("anthropic-compatible")
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ export type Settings = ProviderPackage.Settings &
|
||||||
) & {
|
) & {
|
||||||
readonly baseURL: string
|
readonly baseURL: string
|
||||||
readonly provider?: string
|
readonly provider?: string
|
||||||
|
readonly providerOptions?: ProviderOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
export const routes = [AnthropicMessages.route]
|
export const routes = [AnthropicMessages.route]
|
||||||
|
|
@ -61,6 +62,7 @@ export const model: ProviderPackage.Definition<Settings>["model"] = (modelID, se
|
||||||
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
||||||
limits: settings.limits,
|
limits: settings.limits,
|
||||||
provider: settings.provider,
|
provider: settings.provider,
|
||||||
|
providerOptions: settings.providerOptions,
|
||||||
}).model(modelID)
|
}).model(modelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import type { RouteDefaultsInput } from "../route/client"
|
||||||
import { Auth } from "../route/auth"
|
import { Auth } from "../route/auth"
|
||||||
import type { ProviderAuthOption } from "../route/auth-options"
|
import type { ProviderAuthOption } from "../route/auth-options"
|
||||||
import type { ProviderPackage } from "../provider-package"
|
import type { ProviderPackage } from "../provider-package"
|
||||||
import { ProviderID, type ModelID } from "../schema"
|
import { ProviderID, type ModelID, type ProviderOptions } from "../schema"
|
||||||
import { AnthropicMessages } from "../protocols/anthropic-messages"
|
import { AnthropicMessages } from "../protocols/anthropic-messages"
|
||||||
import { AnthropicCompatible } from "./anthropic-compatible"
|
import { AnthropicCompatible } from "./anthropic-compatible"
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ export type Settings = ProviderPackage.Settings &
|
||||||
| { readonly apiKey?: never; readonly authToken?: string }
|
| { readonly apiKey?: never; readonly authToken?: string }
|
||||||
) & {
|
) & {
|
||||||
readonly baseURL?: string
|
readonly baseURL?: string
|
||||||
|
readonly providerOptions?: ProviderOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
const auth = (options: ProviderAuthOption<"optional">) => {
|
const auth = (options: ProviderAuthOption<"optional">) => {
|
||||||
|
|
@ -52,5 +53,6 @@ export const model: ProviderPackage.Definition<Settings>["model"] = (modelID, se
|
||||||
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
||||||
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
||||||
limits: settings.limits,
|
limits: settings.limits,
|
||||||
|
providerOptions: settings.providerOptions,
|
||||||
}).model(modelID)
|
}).model(modelID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ describe("provider package entrypoints", () => {
|
||||||
headers: { "x-application": "opencode" },
|
headers: { "x-application": "opencode" },
|
||||||
body: { metadata: { user_id: "user_1" } },
|
body: { metadata: { user_id: "user_1" } },
|
||||||
limits: { context: 200_000, output: 64_000 },
|
limits: { context: 200_000, output: 64_000 },
|
||||||
|
providerOptions: { anthropic: { effort: "low" } },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(String(selected.provider)).toBe("example")
|
expect(String(selected.provider)).toBe("example")
|
||||||
|
|
@ -96,6 +97,19 @@ describe("provider package entrypoints", () => {
|
||||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||||
expect(selected.route.defaults.http?.body).toEqual({ metadata: { user_id: "user_1" } })
|
expect(selected.route.defaults.http?.body).toEqual({ metadata: { user_id: "user_1" } })
|
||||||
expect(selected.route.defaults.limits).toEqual({ context: 200_000, output: 64_000 })
|
expect(selected.route.defaults.limits).toEqual({ context: 200_000, output: 64_000 })
|
||||||
|
expect(selected.route.defaults.providerOptions).toEqual({ anthropic: { effort: "low" } })
|
||||||
|
})
|
||||||
|
|
||||||
|
test("maps Anthropic provider options onto the executable model", async () => {
|
||||||
|
const Anthropic = await import("@opencode-ai/ai/providers/anthropic")
|
||||||
|
const selected = Anthropic.model("claude-sonnet-4-6", {
|
||||||
|
apiKey: "fixture",
|
||||||
|
providerOptions: { anthropic: { thinking: { type: "adaptive" } } },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(selected.route.defaults.providerOptions).toEqual({
|
||||||
|
anthropic: { thinking: { type: "adaptive" } },
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("requires an Anthropic-compatible base URL at runtime", async () => {
|
test("requires an Anthropic-compatible base URL at runtime", async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue