|
| 1 | +import { MODEL_ADAPTER_OVERRIDE_ALLOWED } from "../types"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Built-in per-model wire defaults for providers whose catalog is mixed-wire. |
| 5 | + * |
| 6 | + * Distinct from the hard pins in `types.ts`: a pin means the upstream speaks exactly |
| 7 | + * one wire and a user override must not apply. These are defaults — the provider-wide |
| 8 | + * `adapter` is still the right answer for most of the catalog, and an explicit |
| 9 | + * `modelAdapters` entry always wins, including one that names the provider-wide |
| 10 | + * adapter to opt a model back out. |
| 11 | + * |
| 12 | + * Only OpenAI-shaped wires belong here; see MODEL_ADAPTER_OVERRIDE_ALLOWED. |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * GitHub Copilot fronts an OpenAI-compatible catalog that is not uniformly served by |
| 17 | + * `/chat/completions`. The preset adapter is `openai-chat` because that is correct for |
| 18 | + * the Claude, Gemini, GPT-3.5/4 and GPT-5-mini entries, but the newer OpenAI models are |
| 19 | + * Responses-only and fail on chat completions with either |
| 20 | + * |
| 21 | + * model "<id>" is not accessible via the /chat/completions endpoint |
| 22 | + * |
| 23 | + * or, for `gpt-5.4`, only once a real Codex request supplies function tools plus a |
| 24 | + * reasoning effort: |
| 25 | + * |
| 26 | + * Function tools with reasoning_effort are not supported for gpt-5.4 in |
| 27 | + * /v1/chat/completions. To use function tools, use /v1/responses [...] |
| 28 | + * |
| 29 | + * Verified 2026-07-30 against a live 37-entry Copilot catalog with real `codex exec` |
| 30 | + * runs, not minimal text-only probes — presence in `GET /models` does not prove a model |
| 31 | + * works on `/chat/completions`, and a text-only success does not prove it survives |
| 32 | + * function tools plus `reasoning_effort`. |
| 33 | + * |
| 34 | + * Recheck when Copilot adds or changes models. |
| 35 | + */ |
| 36 | +const GITHUB_COPILOT_RESPONSES_MODELS: ReadonlySet<string> = new Set([ |
| 37 | + "gpt-5.3-codex", |
| 38 | + "gpt-5.4", |
| 39 | + "gpt-5.4-mini", |
| 40 | + "gpt-5.5", |
| 41 | + "gpt-5.6-luna", |
| 42 | + "gpt-5.6-sol", |
| 43 | + "gpt-5.6-terra", |
| 44 | +]); |
| 45 | + |
| 46 | +const MODEL_WIRE_DEFAULTS: Record<string, ReadonlyMap<string, string>> = { |
| 47 | + "github-copilot": new Map( |
| 48 | + [...GITHUB_COPILOT_RESPONSES_MODELS].map(id => [id, "openai-responses"] as const), |
| 49 | + ), |
| 50 | +}; |
| 51 | + |
| 52 | +/** Copilot publishes dated snapshots of a family (`gpt-4o-2024-05-13`), so match those too. */ |
| 53 | +const DATED_SNAPSHOT_SUFFIX = /-\d{4}-\d{2}-\d{2}$/; |
| 54 | + |
| 55 | +/** |
| 56 | + * The wire a model should use when the user has configured nothing for it, or undefined |
| 57 | + * when the provider-wide adapter already applies. |
| 58 | + * |
| 59 | + * `currentAdapter` is the provider's configured adapter: a default only ever nudges a |
| 60 | + * provider between OpenAI-shaped wires, so a provider reconfigured onto some other |
| 61 | + * adapter keeps whatever the user chose. |
| 62 | + */ |
| 63 | +export function builtinModelWireDefault( |
| 64 | + providerName: string, |
| 65 | + modelId: string, |
| 66 | + currentAdapter: string, |
| 67 | +): string | undefined { |
| 68 | + if (!MODEL_ADAPTER_OVERRIDE_ALLOWED.has(currentAdapter)) return undefined; |
| 69 | + const table = MODEL_WIRE_DEFAULTS[providerName]; |
| 70 | + if (!table) return undefined; |
| 71 | + const id = modelId.trim().toLowerCase(); |
| 72 | + return table.get(id) ?? table.get(id.replace(DATED_SNAPSHOT_SUFFIX, "")); |
| 73 | +} |
| 74 | + |
| 75 | +/** The built-in default map for a provider, for surfacing in docs/diagnostics. */ |
| 76 | +export function builtinModelWireDefaultsFor(providerName: string): Readonly<Record<string, string>> { |
| 77 | + const table = MODEL_WIRE_DEFAULTS[providerName]; |
| 78 | + return table ? Object.fromEntries(table) : {}; |
| 79 | +} |
0 commit comments