@@ -213,13 +213,14 @@ const normalizeCodexToolChoice = (value: unknown): unknown => {
213213 const topLevelName = getString ( value . name ) ;
214214 const fn = isRecord ( value . function ) ? value . function : null ;
215215
216- // If no function field and no top-level name, nothing to normalize
217- if ( ! fn && ! topLevelName ) return value ;
216+ // If no function field and no valid top-level name, nothing to normalize
217+ const hasValidTopName = topLevelName && topLevelName . trim ( ) ;
218+ if ( ! fn && ! hasValidTopName ) return value ;
218219
219220 // Determine the name to use: prefer non-empty top-level name, fallback to function.name
220221 const functionName = fn ? getString ( fn . name ) : null ;
221- const name = ( topLevelName && topLevelName . trim ( ) ) ? topLevelName : functionName ;
222- if ( ! name ) return value ;
222+ const name = hasValidTopName ? topLevelName : functionName ;
223+ if ( ! name || ! name . trim ( ) ) return value ;
223224
224225 const normalized : Record < string , unknown > = { ...value , name } ;
225226 delete normalized . function ;
@@ -235,13 +236,14 @@ const normalizeCodexTools = (value: unknown): unknown => {
235236 if ( ! nestedFunction ) return tool ;
236237
237238 const nestedName = getString ( nestedFunction . name ) ;
238- if ( ! nestedName ) return tool ;
239+ if ( ! nestedName || ! nestedName . trim ( ) ) return tool ;
239240
240241 const normalized : Record < string , unknown > = { ...tool } ;
241242
242- // Prefer existing top-level name if present and non-empty ; otherwise use nested function name.
243+ // Prefer existing non-empty top-level name; otherwise use nested function name.
243244 const existingName = getString ( normalized . name ) ;
244- if ( ! existingName ) normalized . name = nestedName ;
245+ const hasValidExistingName = existingName && existingName . trim ( ) ;
246+ if ( ! hasValidExistingName ) normalized . name = nestedName ;
245247
246248 if ( ! ( "description" in normalized ) && nestedFunction . description !== undefined ) {
247249 normalized . description = nestedFunction . description ;
0 commit comments