Commit 2662aed
authored
🤖 fix: align GitHub Copilot model routing (#3104)
## Summary
This PR aligns GitHub Copilot model routing with the account's model
catalog. All non-Codex models use chat completions. Codex models use a
custom Responses language model that handles Copilot's SSE stream
format. Copilot can now route Anthropic and Google models (with
dot-vs-dash ID normalization). Catalog entries are hidden from the
selector.
## Background
Copilot auth persisted the signed-in user's model list, but routing
ignored it and only routed OpenAI models. Non-OpenAI Copilot models
(Claude, Gemini) were unreachable. Codex models were stuck:
`/chat/completions` rejects them, and the standard AI SDK Responses
parser can't handle Copilot's SSE stream format. Additionally, Copilot's
catalog uses dot-form Claude IDs (`claude-opus-4.6`) while Mux's
built-in models use dashes (`claude-opus-4-6`).
## Implementation
- add a custom `CopilotResponsesLanguageModel` that handles Copilot's
Responses API SSE stream directly, bypassing the AI SDK's broken parser
(following opencode's approach)
- route Codex models through the custom Responses model, all other
Copilot models through chat completions
- expand Copilot gateway routes to include `anthropic` and `google`
- normalize Claude model IDs (dot-vs-dash: `4.6` matches `4-6`) so
Copilot catalog entries match built-in models
- hide `github-copilot:*` entries from the model selector while keeping
the catalog for route gating
- check credentials before catalog availability for correct error
messages
- classify initiator from pre-normalization body for correct billing
headers
- treat malformed catalog entries as absent for self-healing
## Validation
- `make static-check`
- `bun test src/common/utils/copilot/modelRouting.test.ts
src/node/services/providerModelFactory.test.ts
src/node/services/copilot/copilotResponsesLanguageModel.test.ts
src/browser/hooks/useRouting.test.ts
src/browser/hooks/useModelsFromSettings.test.ts
src/common/routing/resolve.test.ts
src/browser/utils/compaction/suggestion.test.ts
src/common/utils/providers/gatewayModelCatalog.test.ts`
## Risks
Medium. The custom `CopilotResponsesLanguageModel` is a new language
model implementation that directly parses Copilot's SSE stream. It's
scoped to Codex-family models only to minimize blast radius. Tool call
streaming is not yet covered (text-only). Adding Anthropic/Google to
Copilot routes means users with both Copilot and direct API keys will
route through Copilot when it's prioritized (the priority system is
user-controlled and defaults to `["direct"]`).
---
_Generated with `mux` • Model: `openai:gpt-5.4` • Thinking: `xhigh` •
Cost: `$23.81`_
<!-- mux-attribution: model=openai:gpt-5.4 thinking=xhigh costs=23.81
-->1 parent fb25a63 commit 2662aed
26 files changed
Lines changed: 2999 additions & 200 deletions
File tree
- src
- browser
- hooks
- utils/compaction
- common
- constants
- orpc/schemas
- routing
- types
- utils
- copilot
- errors
- messages
- providers
- node/services
- copilot
- utils
- tests/ipc/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
435 | 551 | | |
436 | 552 | | |
437 | 553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
155 | 163 | | |
156 | 164 | | |
157 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
158 | 190 | | |
159 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
160 | 194 | | |
161 | | - | |
| 195 | + | |
162 | 196 | | |
163 | 197 | | |
164 | 198 | | |
| |||
179 | 213 | | |
180 | 214 | | |
181 | 215 | | |
182 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
183 | 229 | | |
184 | 230 | | |
185 | 231 | | |
| |||
205 | 251 | | |
206 | 252 | | |
207 | 253 | | |
| 254 | + | |
| 255 | + | |
208 | 256 | | |
209 | 257 | | |
210 | 258 | | |
| |||
224 | 272 | | |
225 | 273 | | |
226 | 274 | | |
227 | | - | |
228 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
229 | 285 | | |
230 | 286 | | |
231 | 287 | | |
| |||
263 | 319 | | |
264 | 320 | | |
265 | 321 | | |
| 322 | + | |
| 323 | + | |
266 | 324 | | |
267 | 325 | | |
268 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments