@@ -338,6 +338,227 @@ describe("BaseProvider", () => {
338338 expect ( result ?. [ 0 ] . function . parameters . required ) . toEqual ( [ "path" ] )
339339 } )
340340
341+ it ( "removes unsupported constraints from the reported follow-up schema" , ( ) => {
342+ const tools = [
343+ {
344+ type : "function" ,
345+ function : {
346+ name : "ask_followup_question" ,
347+ description : "Ask a question" ,
348+ parameters : {
349+ type : "object" ,
350+ properties : {
351+ follow_up : {
352+ type : "array" ,
353+ description : "Required list of 2-4 suggested responses" ,
354+ items : { type : "object" , properties : { text : { type : "string" } } } ,
355+ minItems : 1 ,
356+ maxItems : 4 ,
357+ } ,
358+ } ,
359+ } ,
360+ } ,
361+ } ,
362+ ]
363+
364+ const result = provider . testConvertToolsForOpenAI ( tools )
365+ const followUp = result ?. [ 0 ] . function . parameters . properties . follow_up
366+
367+ expect ( result ?. [ 0 ] . function . strict ) . toBe ( true )
368+ expect ( followUp . minItems ) . toBe ( 1 )
369+ expect ( followUp . maxItems ) . toBeUndefined ( )
370+ expect ( followUp . description ) . toBe ( 'Required list of 2-4 suggested responses\n\nConstraints: {"maxItems":4}' )
371+ } )
372+
373+ it ( "removes unsupported constraints recursively while keeping supported keywords" , ( ) => {
374+ const tools = [
375+ {
376+ type : "function" ,
377+ function : {
378+ name : "constraint_tool" ,
379+ parameters : {
380+ type : "object" ,
381+ properties : {
382+ count : { type : "number" , minimum : 1 , maximum : 9 , multipleOf : 1 } ,
383+ name : {
384+ type : "string" ,
385+ minLength : 1 ,
386+ maxLength : 5 ,
387+ pattern : "^a" ,
388+ format : "email" ,
389+ } ,
390+ unsupportedFormat : { type : "string" , format : "phone" } ,
391+ list : {
392+ type : "array" ,
393+ items : { type : "integer" , exclusiveMinimum : 0 } ,
394+ minItems : 2 ,
395+ uniqueItems : true ,
396+ contains : { type : "integer" , minimum : 1 } ,
397+ } ,
398+ choice : { anyOf : [ { type : "string" , maxLength : 3 } , { type : "null" } ] } ,
399+ } ,
400+ $defs : { bounded : { type : "integer" , maximum : 3 } } ,
401+ } ,
402+ } ,
403+ } ,
404+ ]
405+
406+ const result = provider . testConvertToolsForOpenAI ( tools )
407+ const parameters = result ?. [ 0 ] . function . parameters
408+
409+ expect ( parameters . properties . count ) . toEqual ( {
410+ type : "number" ,
411+ description : 'Constraints: {"minimum":1,"maximum":9,"multipleOf":1}' ,
412+ } )
413+ expect ( parameters . properties . name ) . toMatchObject ( { type : "string" , pattern : "^a" , format : "email" } )
414+ expect ( parameters . properties . unsupportedFormat . format ) . toBeUndefined ( )
415+ expect ( parameters . properties . list . minItems ) . toBeUndefined ( )
416+ expect ( parameters . properties . list . uniqueItems ) . toBeUndefined ( )
417+ expect ( parameters . properties . list . contains ) . toBeUndefined ( )
418+ expect ( parameters . properties . list . items . exclusiveMinimum ) . toBeUndefined ( )
419+ expect ( parameters . properties . choice . anyOf [ 0 ] . maxLength ) . toBeUndefined ( )
420+ expect ( parameters . $defs . bounded . maximum ) . toBeUndefined ( )
421+ } )
422+
423+ it . each ( [ 0 , 1 ] ) ( "keeps supported minItems value %s" , ( minItems ) => {
424+ const tools = [
425+ {
426+ type : "function" ,
427+ function : {
428+ name : "list_tool" ,
429+ parameters : {
430+ type : "object" ,
431+ properties : { values : { type : "array" , items : { type : "string" } , minItems } } ,
432+ } ,
433+ } ,
434+ } ,
435+ ]
436+
437+ const result = provider . testConvertToolsForOpenAI ( tools )
438+
439+ expect ( result ?. [ 0 ] . function . parameters . properties . values . minItems ) . toBe ( minItems )
440+ } )
441+
442+ it ( "processes tuple items and nested schema keywords" , ( ) => {
443+ const tools = [
444+ {
445+ type : "function" ,
446+ function : {
447+ name : "nested_schema_tool" ,
448+ parameters : {
449+ type : "object" ,
450+ properties : {
451+ values : {
452+ type : "array" ,
453+ items : [
454+ { type : "string" , maxLength : 2 } ,
455+ { type : "integer" , minimum : 0 } ,
456+ ] ,
457+ } ,
458+ } ,
459+ additionalProperties : { type : "string" , minLength : 1 } ,
460+ not : { type : "number" , maximum : 10 } ,
461+ if : { type : "number" , minimum : 1 } ,
462+ then : { type : "string" , maxLength : 5 } ,
463+ else : { type : "string" , minLength : 2 } ,
464+ } ,
465+ } ,
466+ } ,
467+ ]
468+
469+ const result = provider . testConvertToolsForOpenAI ( tools )
470+ const parameters = result ?. [ 0 ] . function . parameters
471+
472+ expect ( parameters . properties . values . items [ 0 ] . maxLength ) . toBeUndefined ( )
473+ expect ( parameters . properties . values . items [ 1 ] . minimum ) . toBeUndefined ( )
474+ expect ( parameters . additionalProperties ) . toBe ( false )
475+ expect ( parameters . not . maximum ) . toBeUndefined ( )
476+ expect ( parameters . if . minimum ) . toBeUndefined ( )
477+ expect ( parameters . then . maxLength ) . toBeUndefined ( )
478+ expect ( parameters . else . minLength ) . toBeUndefined ( )
479+ } )
480+
481+ it ( "replaces additionalProperties values other than false in nested schemas" , ( ) => {
482+ const tools = [
483+ {
484+ type : "function" ,
485+ function : {
486+ name : "composed_object_tool" ,
487+ parameters : {
488+ type : "object" ,
489+ properties : {
490+ options : {
491+ anyOf : [
492+ { type : "object" , properties : { } , additionalProperties : true } ,
493+ { type : "object" , properties : { } , additionalProperties : { type : "string" } } ,
494+ ] ,
495+ } ,
496+ } ,
497+ } ,
498+ } ,
499+ } ,
500+ ]
501+
502+ const result = provider . testConvertToolsForOpenAI ( tools )
503+ const variants = result ?. [ 0 ] . function . parameters . properties . options . anyOf
504+
505+ expect ( variants [ 0 ] . additionalProperties ) . toBe ( false )
506+ expect ( variants [ 1 ] . additionalProperties ) . toBe ( false )
507+ expect ( variants [ 0 ] . description ) . toBe ( 'Constraints: {"additionalProperties":true}' )
508+ expect ( variants [ 1 ] . description ) . toBe ( 'Constraints: {"additionalProperties":{"type":"string"}}' )
509+ } )
510+
511+ it ( "keeps properties whose names match unsupported keywords" , ( ) => {
512+ const tools = [
513+ {
514+ type : "function" ,
515+ function : {
516+ name : "keyword_property_tool" ,
517+ parameters : {
518+ type : "object" ,
519+ properties : {
520+ maxItems : { type : "integer" } ,
521+ minimum : { type : "number" } ,
522+ } ,
523+ } ,
524+ } ,
525+ } ,
526+ ]
527+
528+ const result = provider . testConvertToolsForOpenAI ( tools )
529+
530+ expect ( result ?. [ 0 ] . function . parameters . properties ) . toHaveProperty ( "maxItems" )
531+ expect ( result ?. [ 0 ] . function . parameters . properties ) . toHaveProperty ( "minimum" )
532+ } )
533+
534+ it ( "normalizes nullable object properties before stripping constraints" , ( ) => {
535+ const tools = [
536+ {
537+ type : "function" ,
538+ function : {
539+ name : "nullable_object_tool" ,
540+ parameters : {
541+ type : "object" ,
542+ properties : {
543+ options : {
544+ type : [ "object" , "null" ] ,
545+ properties : { limit : { type : "integer" , minimum : 1 } } ,
546+ } ,
547+ } ,
548+ } ,
549+ } ,
550+ } ,
551+ ]
552+
553+ const result = provider . testConvertToolsForOpenAI ( tools )
554+ const options = result ?. [ 0 ] . function . parameters . properties . options
555+
556+ expect ( options . type ) . toBe ( "object" )
557+ expect ( options . required ) . toEqual ( [ "limit" ] )
558+ expect ( options . additionalProperties ) . toBe ( false )
559+ expect ( options . properties . limit . minimum ) . toBeUndefined ( )
560+ } )
561+
341562 it ( "should not apply schema conversion to MCP tools in base-provider" , ( ) => {
342563 // Note: In base-provider, MCP tools are passed through unchanged
343564 // The openai-native provider has its own handling for MCP tools
@@ -350,8 +571,9 @@ describe("BaseProvider", () => {
350571 parameters : {
351572 type : "object" ,
352573 properties : {
353- token : { type : "string" } ,
574+ token : { type : "string" , maxLength : 20 } ,
354575 } ,
576+ maxItems : 4 ,
355577 required : [ "token" ] ,
356578 } ,
357579 } ,
@@ -362,6 +584,8 @@ describe("BaseProvider", () => {
362584
363585 // MCP tools pass through original parameters in base-provider
364586 expect ( result ?. [ 0 ] . function . parameters . additionalProperties ) . toBeUndefined ( )
587+ expect ( result ?. [ 0 ] . function . parameters . maxItems ) . toBe ( 4 )
588+ expect ( result ?. [ 0 ] . function . parameters . properties . token . maxLength ) . toBe ( 20 )
365589 } )
366590
367591 it ( "should sanitize lone UTF-16 surrogates in name, description, and parameters (#461)" , ( ) => {
@@ -453,9 +677,10 @@ describe("BaseProvider", () => {
453677 type : "object" ,
454678 properties : {
455679 path : { type : "string" } ,
456- offset : { type : "integer" } ,
680+ offset : { type : "integer" , minimum : 1 } ,
457681 } ,
458682 required : [ "path" ] ,
683+ maxItems : 4 ,
459684 } ,
460685 } ,
461686 } ,
@@ -478,7 +703,7 @@ describe("BaseProvider", () => {
478703 parameters : {
479704 type : "object" ,
480705 properties : {
481- path : { type : [ "string" , "null" ] } ,
706+ path : { type : [ "string" , "null" ] , maxLength : 20 } ,
482707 } ,
483708 required : [ "path" ] ,
484709 } ,
@@ -488,10 +713,12 @@ describe("BaseProvider", () => {
488713
489714 const strictResult = provider . testConvertToolsForOpenAI ( tools , true )
490715 expect ( strictResult ?. [ 0 ] . function . parameters . properties . path . type ) . toBe ( "string" )
716+ expect ( strictResult ?. [ 0 ] . function . parameters . properties . path . maxLength ) . toBeUndefined ( )
491717
492718 // Caller-owned schema is untouched, so a later non-strict request
493719 // can still send the original nullable type.
494720 expect ( tools [ 0 ] . function . parameters . properties . path . type ) . toEqual ( [ "string" , "null" ] )
721+ expect ( tools [ 0 ] . function . parameters . properties . path . maxLength ) . toBe ( 20 )
495722
496723 const nonStrictResult = provider . testConvertToolsForOpenAI ( tools , false )
497724 expect ( nonStrictResult ?. [ 0 ] . function . parameters ) . toEqual ( tools [ 0 ] . function . parameters )
0 commit comments