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
  <gheUrl>/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 <sefias_methue@hotmail.de>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
hppsc1215
2026-07-28 15:24:45 +02:00
committed by GitHub
parent 0809c73430
commit 85f1d78d11
5 changed files with 147 additions and 7 deletions

View File

@@ -0,0 +1 @@
- **GHE Copilot**: OpenAI-native models now route to `<gheUrl>/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`

View File

@@ -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,
},

View File

@@ -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);
}

View File

@@ -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");
});

View File

@@ -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", () => {