@@ -3348,9 +3348,19 @@ async function testTool(toolId) {
3348
3348
input . className =
3349
3349
"mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 text-gray-700 dark:text-gray-300 dark:border-gray-700 dark:focus:border-indigo-400 dark:focus:ring-indigo-400" ;
3350
3350
3351
- if ( prop . items ?. type === "number" ) {
3351
+ const itemTypes = Array . isArray ( prop . items ?. anyOf )
3352
+ ? prop . items . anyOf . map ( ( t ) => t . type )
3353
+ : [ prop . items ?. type ] ;
3354
+
3355
+ if (
3356
+ itemTypes . includes ( "number" ) ||
3357
+ itemTypes . includes ( "integer" )
3358
+ ) {
3352
3359
input . type = "number" ;
3353
- } else if ( prop . items ?. type === "boolean" ) {
3360
+ input . step = itemTypes . includes ( "integer" )
3361
+ ? "1"
3362
+ : "any" ;
3363
+ } else if ( itemTypes . includes ( "boolean" ) ) {
3354
3364
input . type = "checkbox" ;
3355
3365
input . value = "true" ;
3356
3366
input . checked = value === true || value === "true" ;
@@ -3390,9 +3400,16 @@ async function testTool(toolId) {
3390
3400
} ) ;
3391
3401
3392
3402
if ( Array . isArray ( prop . default ) ) {
3393
- prop . default . forEach ( ( val ) => {
3394
- arrayContainer . appendChild ( createArrayInput ( val ) ) ;
3395
- } ) ;
3403
+ if ( prop . default . length > 0 ) {
3404
+ prop . default . forEach ( ( val ) => {
3405
+ arrayContainer . appendChild (
3406
+ createArrayInput ( val ) ,
3407
+ ) ;
3408
+ } ) ;
3409
+ } else {
3410
+ // Create one empty input for empty default arrays
3411
+ arrayContainer . appendChild ( createArrayInput ( ) ) ;
3412
+ }
3396
3413
} else {
3397
3414
arrayContainer . appendChild ( createArrayInput ( ) ) ;
3398
3415
}
@@ -3535,49 +3552,48 @@ async function runToolTest() {
3535
3552
const inputValues = formData . getAll ( key ) ;
3536
3553
try {
3537
3554
// Convert values based on the items schema type
3538
- if ( prop . items && prop . items . type ) {
3539
- switch ( prop . items . type ) {
3540
- case "object" :
3541
- value = inputValues . map ( ( v ) => {
3542
- try {
3543
- const parsed = JSON . parse ( v ) ;
3544
- if (
3545
- typeof parsed !== "object" ||
3546
- Array . isArray ( parsed )
3547
- ) {
3548
- throw new Error (
3549
- `Value must be an object, got ${ typeof parsed } ` ,
3550
- ) ;
3551
- }
3552
- return parsed ;
3553
- } catch ( e ) {
3554
- console . error (
3555
- `Error parsing object for ${ key } :` ,
3556
- e ,
3557
- ) ;
3555
+ if ( prop . items ) {
3556
+ const itemType = Array . isArray ( prop . items . anyOf )
3557
+ ? prop . items . anyOf . map ( ( t ) => t . type )
3558
+ : [ prop . items . type ] ;
3559
+
3560
+ if (
3561
+ itemType . includes ( "number" ) ||
3562
+ itemType . includes ( "integer" )
3563
+ ) {
3564
+ value = inputValues . map ( ( v ) => {
3565
+ const num = Number ( v ) ;
3566
+ if ( isNaN ( num ) ) {
3567
+ throw new Error ( `Invalid number: ${ v } ` ) ;
3568
+ }
3569
+ return num ;
3570
+ } ) ;
3571
+ } else if ( itemType . includes ( "boolean" ) ) {
3572
+ value = inputValues . map (
3573
+ ( v ) => v === "true" || v === true ,
3574
+ ) ;
3575
+ } else if ( itemType . includes ( "object" ) ) {
3576
+ value = inputValues . map ( ( v ) => {
3577
+ try {
3578
+ const parsed = JSON . parse ( v ) ;
3579
+ if (
3580
+ typeof parsed !== "object" ||
3581
+ Array . isArray ( parsed )
3582
+ ) {
3558
3583
throw new Error (
3559
- `Invalid object format for ${ key } . Each item must be a valid JSON object.` ,
3584
+ "Value must be an object" ,
3560
3585
) ;
3561
3586
}
3562
- } ) ;
3563
- break ;
3564
- case "number" :
3565
- value = inputValues . map ( ( v ) =>
3566
- v === "" ? null : Number ( v ) ,
3567
- ) ;
3568
- break ;
3569
- case "boolean" :
3570
- value = inputValues . map (
3571
- ( v ) => v === "true" || v === true ,
3572
- ) ;
3573
- break ;
3574
- default :
3575
- // For other types (like strings), use raw values
3576
- value = inputValues ;
3587
+ return parsed ;
3588
+ } catch {
3589
+ throw new Error (
3590
+ `Invalid object format for ${ key } ` ,
3591
+ ) ;
3592
+ }
3593
+ } ) ;
3594
+ } else {
3595
+ value = inputValues ;
3577
3596
}
3578
- } else {
3579
- // If no items type specified, use raw values
3580
- value = inputValues ;
3581
3597
}
3582
3598
3583
3599
// Handle empty values
0 commit comments