diff --git a/packages/ai/test/provider/github-copilot.test.ts b/packages/ai/test/provider/github-copilot.test.ts new file mode 100644 index 00000000000..7b194ca7909 --- /dev/null +++ b/packages/ai/test/provider/github-copilot.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, test } from "bun:test" +import { shouldUseResponsesApi } from "@opencode-ai/ai/providers/github-copilot" + +describe("GitHub Copilot", () => { + test("selects the endpoint from explicit metadata before the model ID fallback", () => { + expect(shouldUseResponsesApi("mai-code-1-flash-picker", "responses")).toBe(true) + expect(shouldUseResponsesApi("gpt-5", "chat")).toBe(false) + expect(shouldUseResponsesApi("gpt-5")).toBe(true) + expect(shouldUseResponsesApi("gpt-5.1-codex")).toBe(true) + expect(shouldUseResponsesApi("gpt-4o")).toBe(false) + expect(shouldUseResponsesApi("gpt-5-mini")).toBe(false) + expect(shouldUseResponsesApi("gpt-5-mini-2025-08-07")).toBe(false) + }) +}) diff --git a/packages/core/src/plugin/provider/github-copilot.ts b/packages/core/src/plugin/provider/github-copilot.ts index c8aff68697c..e7d27f4cca8 100644 --- a/packages/core/src/plugin/provider/github-copilot.ts +++ b/packages/core/src/plugin/provider/github-copilot.ts @@ -1,4 +1,5 @@ import type { IntegrationOAuthMethodRegistration } from "@opencode-ai/plugin/effect/integration" +import { shouldUseResponsesApi } from "@opencode-ai/ai/providers/github-copilot" import { Effect, Option, Schema, Semaphore, Stream } from "effect" import { Catalog } from "../../catalog" import { Credential } from "../../credential" @@ -140,14 +141,6 @@ const oauth = (app: App.Info) => ({ }), }) satisfies IntegrationOAuthMethodRegistration -function shouldUseResponses(modelID: string) { - // Copilot supports Responses for GPT-5 class models, except mini variants - // which still need the chat-completions endpoint. - const match = /^gpt-(\d+)/.exec(modelID) - if (!match) return false - return Number(match[1]) >= 5 && !modelID.startsWith("gpt-5-mini") -} - export const GithubCopilotPlugin = define({ id: "opencode.provider.github-copilot", effect: Effect.fn(function* (ctx) { @@ -269,7 +262,7 @@ export const GithubCopilotPlugin = define({ return } const id = evt.model.modelID ?? evt.model.id - evt.language = shouldUseResponses(id) ? evt.sdk.responses(id) : evt.sdk.chat(id) + evt.language = shouldUseResponsesApi(id) ? evt.sdk.responses(id) : evt.sdk.chat(id) }), ) }),