@@ -68,85 +68,53 @@ export const CODEX_MODEL_MAP: Record<string, string> = {
6868
6969/**
7070 * Check if a model is an OpenAI model that can use Codex OAuth.
71- * Matches models in the CODEX_MODEL_MAP or with openai/ prefix.
71+ * Only returns true for models explicitly in the CODEX_MODEL_MAP.
72+ * This prevents unknown openai/* models from accidentally routing through Codex OAuth.
7273 */
7374export function isOpenAIModel ( model : string ) : boolean {
74- // Check if it's in the model map
75+ // Only return true for models explicitly in the model map
76+ // This is an allowlist approach - unknown models fall back to Codebuff backend
7577 if ( CODEX_MODEL_MAP [ model ] ) {
7678 return true
7779 }
78- // Check if it has openai/ prefix
79- if ( model . startsWith ( 'openai/' ) ) {
80- return true
80+ // Check without provider prefix
81+ if ( model . includes ( '/' ) ) {
82+ const modelId = model . split ( '/' ) . pop ( ) !
83+ if ( CODEX_MODEL_MAP [ modelId ] ) {
84+ return true
85+ }
8186 }
82- // Check if it's a known Codex model
83- const modelId = model . startsWith ( 'openai/' ) ? model . slice ( 7 ) : model
84- return ( CODEX_OAUTH_MODELS as readonly string [ ] ) . includes ( modelId )
87+ return false
8588}
8689
8790/**
8891 * Normalize a model ID to the Codex API format.
89- * Uses the model map for known models, with fallback pattern matching.
92+ * Uses the model map for known models. Returns null for unknown models
93+ * to signal that the model cannot be used with Codex OAuth.
9094 */
91- export function toCodexModelId ( model : string ) : string {
95+ export function toCodexModelId ( model : string ) : string | null {
9296 // Check the mapping table first
9397 const mapped = CODEX_MODEL_MAP [ model ]
9498 if ( mapped ) {
9599 return mapped
96100 }
97101
98- // Strip provider prefix if present
99- const modelId = model . includes ( '/' ) ? model . split ( '/' ) . pop ( ) ! : model
100-
101- // Check again without prefix
102- const mappedWithoutPrefix = CODEX_MODEL_MAP [ modelId ]
103- if ( mappedWithoutPrefix ) {
104- return mappedWithoutPrefix
105- }
106-
107- // Pattern-based fallback for unknown models
108- const normalized = modelId . toLowerCase ( )
109-
110- // GPT-5.2 Codex
111- if ( normalized . includes ( 'gpt-5.2-codex' ) || normalized . includes ( 'gpt 5.2 codex' ) ) {
112- return 'gpt-5.2-codex'
113- }
114- // GPT-5.2
115- if ( normalized . includes ( 'gpt-5.2' ) || normalized . includes ( 'gpt 5.2' ) ) {
116- return 'gpt-5.2'
117- }
118- // GPT-5.1 Codex Max
119- if ( normalized . includes ( 'gpt-5.1-codex-max' ) || normalized . includes ( 'codex-max' ) ) {
120- return 'gpt-5.1-codex-max'
121- }
122- // GPT-5.1 Codex Mini
123- if ( normalized . includes ( 'gpt-5.1-codex-mini' ) || normalized . includes ( 'codex-mini' ) ) {
124- return 'gpt-5.1-codex-mini'
125- }
126- // GPT-5.1 Codex
127- if ( normalized . includes ( 'gpt-5.1-codex' ) || normalized . includes ( 'gpt 5.1 codex' ) ) {
128- return 'gpt-5.1-codex'
129- }
130- // GPT-5.1
131- if ( normalized . includes ( 'gpt-5.1' ) || normalized . includes ( 'gpt 5.1' ) ) {
132- return 'gpt-5.1'
133- }
134- // Any codex model defaults to gpt-5.1-codex
135- if ( normalized . includes ( 'codex' ) ) {
136- return 'gpt-5.1-codex'
137- }
138- // GPT-5 family defaults to gpt-5.1
139- if ( normalized . includes ( 'gpt-5' ) || normalized . includes ( 'gpt 5' ) ) {
140- return 'gpt-5.1'
102+ // Strip provider prefix if present and check again
103+ if ( model . includes ( '/' ) ) {
104+ const modelId = model . split ( '/' ) . pop ( ) !
105+ const mappedWithoutPrefix = CODEX_MODEL_MAP [ modelId ]
106+ if ( mappedWithoutPrefix ) {
107+ return mappedWithoutPrefix
108+ }
141109 }
142110
143- // Default fallback
144- return 'gpt-5.1'
111+ // Unknown model - return null to signal fallback to Codebuff backend
112+ return null
145113}
146114
147115/**
148116 * @deprecated Use toCodexModelId instead
149117 */
150- export function toOpenAIModelId ( openrouterModel : string ) : string {
118+ export function toOpenAIModelId ( openrouterModel : string ) : string | null {
151119 return toCodexModelId ( openrouterModel )
152120}
0 commit comments