fix(oauth): reach Copilot models served only over the Responses API

Merged
FE
2mo ago
+394-76

Fixes #778.

copilot() built its model with createOpenAICompatible(...).chatModel(modelId) for every id, so a model the Copilot plan serves only over its Responses API (gpt-6-luna, gpt-5.3-codex, grok-4.5, mai-code-1.1-flash) could not be called: /chat/completions answers 400 unsupported_api_for_model, while /responses succeeds. #767 marked those models in the listing and scoped the invocation as a follow-up; this is that follow-up.

What changed

  • copilot(modelId) stays synchronous and makes no network call while constructing. It returns a delegate that settles the protocol on the first doGenerate / doStream from the plan's GET /models, then hands the call to @ai-sdk/openai-compatible's chat model or @ai-sdk/openai's Responses model (wrapped with store: false, as chatgpt() is).
  • The protocol comes from the model's supported_endpoints only, as in vscode-copilot-chat. No endpoints or /chat/completions named means chat; /responses without chat means Responses; anything else stays on chat and the vendor's error explains it. Plan policy plays no part: grok-4.5 and gpt-5.3-codex carry no policy yet work over Responses, and a disabled model fails identically on both endpoints.
  • Only a listing that was read is remembered. An error status, non-JSON body, network failure, or the listing's own 10s timeout sends that call over chat and the next call asks again, so one blip does not pin a Responses-only model to chat for the whole run.
  • One lookup serves concurrent calls under its own timeout; a caller that aborts stops waiting without failing the others.
  • A revoked login fails on the listing with the sign-in command instead of being read as "no listing" and retried on chat.
  • @ai-sdk/openai is imported lazily, only when a Responses model is called. Without it, the call fails with MISCONFIGURED naming the package. e2e init now adds it for the Copilot gateway.
  • sendCopilotRequest reads the initiator and vision flag from Responses bodies too (input[], input_image); before, every Responses turn was labelled x-initiator: agent with no vision header.
  • withoutServerStorage moved to src/oauth/responses.ts, shared by chatgpt() and copilot().
  • e2e models github-copilot marks uncallable models no chat or responses (was no chat completions); a disabled Responses model now reads not enabled only.

Verified

  • pnpm check passes; e2e unit tests: 165 files, 2370 passed.
  • Live, through copilot() against a real Copilot plan (tests/live/oauth.ts: image + forced tool call):
ModelEndpoints listedRouted toResult
gpt-6-luna/responsesresponsestool call ok
gpt-5.3-codex/responses, no policyresponsestool call ok
grok-4.5/responses, no policyresponsesok with a 256px image; xAI rejects the 8x8 test PNG on either path
claude-sonnet-5chat + messageschattool call ok
gpt-5.4chat + responseschattool call ok
  • A 4-step reasoning tool loop over Responses with store: false completes on gpt-6-luna, gpt-5.3-codex, grok-4.5, mai-code-1.1-flash.

Open

  • When a model lists both endpoints (gpt-5.4, gpt-5-mini), chat wins so working models do not move. vscode-copilot-chat prefers Responses there.
  • @ai-sdk/openai decides "reasoning model" by name, so grok-* / mai-* get no include: reasoning.encrypted_content. forceReasoning from the listing's reasoning_effort works live but showed no measurable gain; left as follow-up.