Skip to content

Commit a52ae30

Browse files
committed
fix: preserve Copilot catalog variants
1 parent abaabdc commit a52ae30

2 files changed

Lines changed: 102 additions & 2 deletions

File tree

packages/opencode/src/plugin/github-copilot/models.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ function build(key: string, remote: Item, url: string, prev?: Model): Model {
147147
}
148148
}
149149
}
150-
if (Object.keys(variants).length > 0) {
151-
model.variants = variants
150+
const mergedVariants = !isMsgApi ? { ...prev?.variants, ...variants } : variants
151+
if (Object.keys(mergedVariants).length > 0) {
152+
model.variants = mergedVariants
152153
}
153154

154155
return model

packages/opencode/test/plugin/github-copilot-models.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,105 @@ test("clears existing variants so refreshed models calculate provider-specific v
215215
expect(models["claude-opus-4.7"].variants).toBeUndefined()
216216
})
217217

218+
test("keeps catalog variants missing from the Copilot models endpoint", async () => {
219+
globalThis.fetch = mock(() =>
220+
Promise.resolve(
221+
new Response(
222+
JSON.stringify({
223+
data: [
224+
{
225+
model_picker_enabled: true,
226+
id: "gpt-5.2",
227+
name: "GPT-5.2",
228+
version: "gpt-5.2-2026-02-01",
229+
capabilities: {
230+
family: "gpt",
231+
limits: {
232+
max_context_window_tokens: 400000,
233+
max_output_tokens: 128000,
234+
max_prompt_tokens: 400000,
235+
},
236+
supports: {
237+
reasoning_effort: ["low", "medium", "high"],
238+
streaming: true,
239+
tool_calls: true,
240+
},
241+
},
242+
},
243+
],
244+
}),
245+
{ status: 200 },
246+
),
247+
),
248+
) as unknown as typeof fetch
249+
250+
const models = await CopilotModels.get(
251+
"https://api.githubcopilot.com",
252+
{},
253+
{
254+
"gpt-5.2": {
255+
id: "gpt-5.2",
256+
providerID: "github-copilot",
257+
api: {
258+
id: "gpt-5.2",
259+
url: "https://api.githubcopilot.com",
260+
npm: "@ai-sdk/github-copilot",
261+
},
262+
name: "GPT-5.2",
263+
family: "gpt",
264+
capabilities: {
265+
temperature: true,
266+
reasoning: true,
267+
attachment: true,
268+
toolcall: true,
269+
input: {
270+
text: true,
271+
audio: false,
272+
image: true,
273+
video: false,
274+
pdf: false,
275+
},
276+
output: {
277+
text: true,
278+
audio: false,
279+
image: false,
280+
video: false,
281+
pdf: false,
282+
},
283+
interleaved: false,
284+
},
285+
cost: {
286+
input: 0,
287+
output: 0,
288+
cache: {
289+
read: 0,
290+
write: 0,
291+
},
292+
},
293+
limit: {
294+
context: 400000,
295+
input: 400000,
296+
output: 128000,
297+
},
298+
options: {},
299+
headers: {},
300+
release_date: "2026-02-01",
301+
variants: {
302+
xhigh: {
303+
reasoningEffort: "xhigh",
304+
reasoningSummary: "auto",
305+
include: ["reasoning.encrypted_content"],
306+
},
307+
},
308+
status: "active",
309+
},
310+
},
311+
)
312+
313+
expect(models["gpt-5.2"].variants?.xhigh?.reasoningEffort).toBe("xhigh")
314+
expect(models["gpt-5.2"].variants?.low?.reasoningEffort).toBe("low")
315+
})
316+
218317
test("remaps fallback oauth model urls to the enterprise host", async () => {
219318
globalThis.fetch = mock(() => Promise.reject(new Error("timeout"))) as unknown as typeof fetch
220319

0 commit comments

Comments
 (0)