Skip to content

Commit 68d6b94

Browse files
HXYerrorclaude
andcommitted
fix(routing): undefined model guard, codex regex, capabilities type narrowing (#5)
- getModelMode: return "chat" early when modelId is falsy — prevents TypeError crash on requests missing the model field - isResponsesOnlyModel: anchor codex check with word boundaries (/(?:^|-)codex(?:-|$)/) to avoid false-positives on future codex-mini - ModelCapabilities.type: narrow to "chat"|"responses"|(string & {}) so routing logic is type-checked against known upstream values Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 394203a commit 68d6b94

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/lib/model-routing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export type ModelMode = "chat" | "responses"
2626
* "responses" = must use /responses; "chat" = use /chat/completions (or native Anthropic).
2727
*/
2828
export function getModelMode(modelId: string): ModelMode {
29+
// Guard: treat missing/empty model as "chat" — upstream will reject with a proper error
30+
if (!modelId) return "chat"
31+
2932
// 1. Check state.models capabilities if available (future-proof)
3033
if (state.models?.data) {
3134
const entry = state.models.data.find((m) => m.id === modelId)
@@ -43,7 +46,8 @@ export function getModelMode(modelId: string): ModelMode {
4346
*/
4447
export function isResponsesOnlyModel(modelId: string): boolean {
4548
// codex family: gpt-5-codex, gpt-5.1-codex, gpt-5.1-codex-max, gpt-5.3-codex, etc.
46-
if (modelId.includes("codex")) return true
49+
// Anchored to word boundaries to avoid matching hypothetical future "codex-mini" chat models.
50+
if (/(?:^|-)codex(?:-|$)/.test(modelId)) return true
4751
// o-pro family: o1-pro, o3-pro, o1-pro-2025-04-09, o3-pro-2025-01-10, etc.
4852
// Covers: o\d+-pro(?:-\d{4}-\d{2}-\d{2})? — requires string to end after "pro" or date
4953
if (/^o\d+-pro(?:-\d{4}-\d{2}-\d{2})?$/.test(modelId)) return true

src/services/copilot/get-models.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ interface ModelCapabilities {
3636
object: string
3737
supports: ModelSupports
3838
tokenizer: string
39-
type: string
39+
/** Known values: "chat" | "responses". Open string for forward-compat. */
40+
type: "chat" | "responses" | (string & {})
4041
}
4142

4243
export interface Model {

0 commit comments

Comments
 (0)