fix(copilot): ensure available variants sync from api (#24734)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Aiden Cline
2026-04-28 14:58:51 -05:00
committed by GitHub
parent 276d162044
commit 0acac216ae
5 changed files with 176 additions and 11 deletions

View File

@@ -58,7 +58,7 @@ function build(key: string, remote: Item, url: string, prev?: Model): Model {
const isMsgApi = remote.supported_endpoints?.includes("/v1/messages")
return {
const model: Model = {
id: key,
providerID: "github-copilot",
api: {
@@ -107,8 +107,50 @@ function build(key: string, remote: Item, url: string, prev?: Model): Model {
release_date:
prev?.release_date ??
(remote.version.startsWith(`${remote.id}-`) ? remote.version.slice(remote.id.length + 1) : remote.version),
variants: prev?.variants ?? {},
}
const efforts = remote.capabilities.supports.reasoning_effort
const variants: NonNullable<Model["variants"]> = {}
if (!isMsgApi && efforts?.length) {
efforts.forEach((effort) => {
variants[effort] = {
reasoningEffort: effort,
reasoningSummary: "auto",
include: ["reasoning.encrypted_content"],
}
})
} else {
if (efforts?.length && remote.capabilities.supports.adaptive_thinking) {
efforts.forEach((effort) => {
variants[effort] = {
thinking: {
type: "adaptive",
...(model.api.id.includes("opus-4.7") ? { display: "summarized" } : {}),
},
effort,
}
})
} else if (remote.capabilities.supports.max_thinking_budget) {
const max = remote.capabilities.supports.max_thinking_budget
variants["max"] = {
thinking: {
type: "enabled",
budgetTokens: max - 1,
},
}
variants["high"] = {
thinking: {
type: "enabled",
budgetTokens: Math.floor(max / 2),
},
}
}
}
if (Object.keys(variants).length > 0) {
model.variants = variants
}
return model
}
export async function get(

View File

@@ -1358,7 +1358,9 @@ const layer: Layer.Layer<
)
delete provider.models[modelID]
model.variants = mapValues(ProviderTransform.variants(model), (v) => v)
if (!model.variants || Object.keys(model.variants).length === 0) {
model.variants = mapValues(ProviderTransform.variants(model), (v) => v)
}
const configVariants = configProvider?.models?.[modelID]?.variants
if (configVariants && model.variants) {

View File

@@ -630,16 +630,17 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/anthropic
case "@ai-sdk/google-vertex/anthropic":
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex#anthropic-provider
if (model.providerID === "github-copilot") {
if (model.api.id.includes("opus-4.7")) {
return Object.fromEntries(["medium"].map((effort) => [effort, { reasoningEffort: effort }]))
}
}
if (adaptiveEfforts) {
let efforts = [...adaptiveEfforts]
if (model.providerID === "github-copilot") {
if (model.api.id.includes("opus-4.7")) {
efforts = ["medium"]
}
// Efforts currently supported are: low, medium, high
efforts = efforts.filter((v) => v !== "max" && v !== "xhigh")
}
return Object.fromEntries(
adaptiveEfforts.map((effort) => [
efforts.map((effort) => [
effort,
{
thinking: {