From 85f1d78d1129b1df5789984a95081e9f6fde09a5 Mon Sep 17 00:00:00 2001 From: hppsc1215 <34004905+hppsc1215@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:24:45 +0200 Subject: [PATCH] fix(ghe-copilot): route OpenAI-native models via Responses API (#8835) * fix(ghe-copilot): route OpenAI-native models via Responses API - Add targetFormat: 'openai-responses' to gpt-5.4-mini, gpt-5.3-codex, gpt-5-mini, mai-code-1-flash, and oswe-vscode-prime in ghe-copilot registry. - Register gpt-5.6-sol, gpt-5.6-terra, and gpt-5.6-luna with openai-responses targetFormat. - Update GheCopilotExecutor.buildUrl() to route openai-responses and codex models to /responses while keeping Claude and Gemini on /chat/completions. - Add unit tests verifying targetFormat parity and buildUrl endpoint routing. * docs(changelog): add fragment for #8835 Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: Alex Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --- .../8835-ghe-copilot-responses-routing.md | 1 + .../providers/registry/ghe-copilot/index.ts | 9 +++ open-sse/executors/ghe-copilot.ts | 37 +++++++-- .../ghe-copilot-targetformat-parity.test.ts | 79 +++++++++++++++++++ tests/unit/ghe-copilot.test.ts | 28 ++++++- 5 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 changelog.d/fixes/8835-ghe-copilot-responses-routing.md create mode 100644 tests/unit/ghe-copilot-targetformat-parity.test.ts diff --git a/changelog.d/fixes/8835-ghe-copilot-responses-routing.md b/changelog.d/fixes/8835-ghe-copilot-responses-routing.md new file mode 100644 index 00000000000..68489b4649b --- /dev/null +++ b/changelog.d/fixes/8835-ghe-copilot-responses-routing.md @@ -0,0 +1 @@ +- **GHE Copilot**: OpenAI-native models now route to `/responses` instead of failing with `model "..." is not accessible via the /chat/completions endpoint` — `gpt-5.4-mini`, `gpt-5.3-codex`, `mai-code-1-flash` and `oswe-vscode-prime` carry `targetFormat: "openai-responses"`, and `gpt-5.6-sol`/`terra`/`luna` are registered. Claude and Gemini models under `ghe-copilot` keep using `/chat/completions` diff --git a/open-sse/config/providers/registry/ghe-copilot/index.ts b/open-sse/config/providers/registry/ghe-copilot/index.ts index 5e88116d69a..483aefa369c 100644 --- a/open-sse/config/providers/registry/ghe-copilot/index.ts +++ b/open-sse/config/providers/registry/ghe-copilot/index.ts @@ -102,10 +102,14 @@ export const gheCopilotProvider: RegistryEntry = { contextLength: 1000000, maxOutputTokens: 64000, }, + { id: "gpt-5.6-sol", name: "GPT-5.6 Sol", targetFormat: "openai-responses", maxOutputTokens: 128000 }, + { id: "gpt-5.6-terra", name: "GPT-5.6 Terra", targetFormat: "openai-responses", maxOutputTokens: 128000 }, + { id: "gpt-5.6-luna", name: "GPT-5.6 Luna", targetFormat: "openai-responses", maxOutputTokens: 128000 }, { id: "gpt-5.5", name: "GPT-5.5", ...GPT_5_5_CODEX_CAPABILITIES, maxOutputTokens: 128000 }, { id: "gpt-5.4", name: "GPT-5.4", + targetFormat: "openai-responses", supportsXHighEffort: true, contextLength: 1050000, maxOutputTokens: 128000, @@ -113,18 +117,21 @@ export const gheCopilotProvider: RegistryEntry = { { id: "gpt-5.4-mini", name: "GPT-5.4 mini", + targetFormat: "openai-responses", contextLength: 400000, maxOutputTokens: 128000, }, { id: "gpt-5.3-codex", name: "GPT-5.3-Codex", + targetFormat: "openai-responses", contextLength: 400000, maxOutputTokens: 128000, }, { id: "gpt-5-mini", name: "GPT-5 mini", + targetFormat: "openai-responses", contextLength: 264000, maxOutputTokens: 64000, }, @@ -150,12 +157,14 @@ export const gheCopilotProvider: RegistryEntry = { { id: "mai-code-1-flash", name: "MAI-Code-1-Flash", + targetFormat: "openai-responses", contextLength: 256000, maxOutputTokens: 128000, }, { id: "oswe-vscode-prime", name: "Raptor mini", + targetFormat: "openai-responses", contextLength: 264000, maxOutputTokens: 64000, }, diff --git a/open-sse/executors/ghe-copilot.ts b/open-sse/executors/ghe-copilot.ts index 694f51fede6..0ab8665ceee 100644 --- a/open-sse/executors/ghe-copilot.ts +++ b/open-sse/executors/ghe-copilot.ts @@ -38,17 +38,38 @@ export class GheCopilotExecutor extends GithubExecutor { (typeof psd?.copilotApiUrl === "string" ? psd.copilotApiUrl : undefined) || (typeof psd?.copilotProxyUrl === "string" ? psd.copilotProxyUrl : undefined); if (apiOrProxy) { - const base = apiOrProxy.replace(/\/+$/, ""); + const base = apiOrProxy.replace(/\/chat\/completions\/?$/, "").replace(/\/responses\/?$/, "").replace(/\/+$/, ""); return base.endsWith("/chat/completions") ? base : `${base}/chat/completions`; } const gheUrl = psd?.gheUrl as string | undefined; if (!gheUrl) { throw new Error("GHE Copilot executor requires gheUrl in providerSpecificData"); } - const base = gheUrl.replace(/\/$/, ""); + const base = gheUrl.replace(/\/chat\/completions\/?$/, "").replace(/\/responses\/?$/, "").replace(/\/+$/, ""); return base.endsWith("/chat/completions") ? base : `${base}/chat/completions`; } + /** + * Derive the base URL for /responses from gheUrl in providerSpecificData. + * Appends /responses if not already present. + */ + private getResponsesBase(credentials: ProviderCredentials | null): string { + const psd = credentials?.providerSpecificData; + const apiOrProxy = + (typeof psd?.copilotApiUrl === "string" ? psd.copilotApiUrl : undefined) || + (typeof psd?.copilotProxyUrl === "string" ? psd.copilotProxyUrl : undefined); + if (apiOrProxy) { + const base = apiOrProxy.replace(/\/chat\/completions\/?$/, "").replace(/\/responses\/?$/, "").replace(/\/+$/, ""); + return `${base}/responses`; + } + const gheUrl = psd?.gheUrl as string | undefined; + if (!gheUrl) { + throw new Error("GHE Copilot executor requires gheUrl in providerSpecificData"); + } + const base = gheUrl.replace(/\/chat\/completions\/?$/, "").replace(/\/responses\/?$/, "").replace(/\/+$/, ""); + return `${base}/responses`; + } + /** * Strip the `ghe-copilot/` provider prefix from a model id so the upstream * GHE Copilot proxy receives the bare id (e.g. `gpt-5-mini`). @@ -60,10 +81,14 @@ export class GheCopilotExecutor extends GithubExecutor { } override buildUrl(model: string, stream: boolean, urlIndex = 0, credentials: ProviderCredentials | null = null): string { - // GHE Copilot proxy only reliably serves /chat/completions. Route every - // model there (including ones flagged openai-responses) and let the - // Responses→Chat transformer handle the format. Going to /responses on the - // GHE proxy returns a bare 404 ("404 page not found"). + const bareModel = this.stripPrefix(model); + const targetFormat = getModelTargetFormat("ghe-copilot", bareModel); + if ( + (targetFormat === "openai-responses" || /codex/i.test(bareModel)) && + this.supportsResponsesEndpoint(bareModel) + ) { + return this.getResponsesBase(credentials); + } return this.getChatCompletionsBase(credentials); } diff --git a/tests/unit/ghe-copilot-targetformat-parity.test.ts b/tests/unit/ghe-copilot-targetformat-parity.test.ts new file mode 100644 index 00000000000..505a26edf44 --- /dev/null +++ b/tests/unit/ghe-copilot-targetformat-parity.test.ts @@ -0,0 +1,79 @@ +/** + * Parity test for GHE Copilot targetFormat routing. + * + * Ensures that OpenAI-native models (gpt-5.4-mini, gpt-5.6-*, gpt-5.3-codex, etc.) + * under `ghe-copilot` carry `targetFormat: "openai-responses"`, while Claude and + * Gemini models do NOT. + */ +import test from "node:test"; +import assert from "node:assert/strict"; + +const { gheCopilotProvider } = await import("../../open-sse/config/providers/registry/ghe-copilot/index.ts"); +const { getModelsByProviderId } = await import("../../open-sse/config/providerModels.ts"); + +type ModelEntry = { id: string; targetFormat?: string; [k: string]: unknown }; + +function gheModel(id: string): ModelEntry | undefined { + return gheCopilotProvider.models.find((m) => m.id === id); +} + +// Claude/Gemini models that must NOT route through the Responses API. +const MUST_NOT_BE_RESPONSES = [ + "claude-fable-5", + "claude-opus-5", + "claude-opus-4.7", + "claude-opus-4.8", + "claude-opus-4.8-fast", + "claude-opus-4.5", + "claude-sonnet-4.6", + "claude-sonnet-5", + "claude-sonnet-4.5", + "claude-haiku-4.5", + "gemini-3.1-pro-preview", + "gemini-3.5-flash", +]; + +for (const id of MUST_NOT_BE_RESPONSES) { + test(`ghe-copilot/${id} must not use openai-responses targetFormat`, () => { + const model = gheModel(id); + assert.ok(model, `${id} must be registered under ghe-copilot`); + assert.notEqual( + model.targetFormat, + "openai-responses", + `ghe-copilot/${id} must route via chat/completions (Copilot Responses API rejects it)` + ); + }); +} + +// OpenAI-native models that MUST use openai-responses targetFormat under ghe-copilot +const MUST_BE_RESPONSES = [ + "gpt-5.6-sol", + "gpt-5.6-terra", + "gpt-5.6-luna", + "gpt-5.4", + "gpt-5.4-mini", + "gpt-5.3-codex", + "gpt-5-mini", + "mai-code-1-flash", + "oswe-vscode-prime", +]; + +for (const id of MUST_BE_RESPONSES) { + test(`ghe-copilot/${id} (OpenAI-native) uses openai-responses`, () => { + const model = gheModel(id); + assert.ok(model, `${id} must be registered under ghe-copilot`); + assert.equal( + model.targetFormat, + "openai-responses", + `ghe-copilot/${id} is OpenAI-native and must use the Responses API` + ); + }); +} + +// Lookup-by-id helper resolves the same entries. +test("getModelsByProviderId(ghe-copilot) reflects the targetFormat settings", () => { + const models = getModelsByProviderId("ghe-copilot") as ModelEntry[]; + const gpt54mini = models.find((m) => m.id === "gpt-5.4-mini"); + assert.ok(gpt54mini, "gpt-5.4-mini resolvable via getModelsByProviderId"); + assert.equal(gpt54mini.targetFormat, "openai-responses"); +}); diff --git a/tests/unit/ghe-copilot.test.ts b/tests/unit/ghe-copilot.test.ts index aed9f933ed3..e11975d532e 100644 --- a/tests/unit/ghe-copilot.test.ts +++ b/tests/unit/ghe-copilot.test.ts @@ -49,7 +49,33 @@ test("buildUrl uses gheUrl for responses endpoint with codex model", () => { providerSpecificData: { gheUrl: "https://ghe.company.com" }, }; const url = executor.buildUrl("gpt-4o-codex", true, 0, credentials); - assert.strictEqual(url, "https://ghe.company.com/chat/completions"); + assert.strictEqual(url, "https://ghe.company.com/responses"); +}); + +test("buildUrl uses responses endpoint for gpt-5.4-mini and gpt-5.6-sol", () => { + const executor = new GheCopilotExecutor({ + gheUrl: "https://ghe.company.com", + clientId: "test-client", + clientSecret: "test-secret", + }); + const credentials: ProviderCredentials = { + providerSpecificData: { gheUrl: "https://ghe.company.com" }, + }; + assert.strictEqual(executor.buildUrl("gpt-5.4-mini", true, 0, credentials), "https://ghe.company.com/responses"); + assert.strictEqual(executor.buildUrl("ghe-copilot/gpt-5.6-sol", true, 0, credentials), "https://ghe.company.com/responses"); +}); + +test("buildUrl uses chat/completions endpoint for claude and gemini models", () => { + const executor = new GheCopilotExecutor({ + gheUrl: "https://ghe.company.com", + clientId: "test-client", + clientSecret: "test-secret", + }); + const credentials: ProviderCredentials = { + providerSpecificData: { gheUrl: "https://ghe.company.com" }, + }; + assert.strictEqual(executor.buildUrl("claude-opus-5", true, 0, credentials), "https://ghe.company.com/chat/completions"); + assert.strictEqual(executor.buildUrl("gemini-3.5-flash", true, 0, credentials), "https://ghe.company.com/chat/completions"); }); test("buildUrl handles gheUrl with trailing slash", () => {