@@ -3507,19 +3507,78 @@ async function runToolTest() {
3507
3507
}
3508
3508
let value ;
3509
3509
if ( prop . type === "array" ) {
3510
- value = formData . getAll ( key ) ;
3511
- if ( prop . items && prop . items . type === "number" ) {
3512
- value = value . map ( ( v ) => ( v === "" ? null : Number ( v ) ) ) ;
3513
- } else if ( prop . items && prop . items . type === "boolean" ) {
3514
- value = value . map ( ( v ) => v === "true" || v === true ) ;
3515
- }
3516
- if (
3517
- value . length === 0 ||
3518
- ( value . length === 1 && value [ 0 ] === "" )
3519
- ) {
3520
- continue ;
3510
+ const inputValues = formData . getAll ( key ) ;
3511
+ try {
3512
+ // Convert values based on the items schema type
3513
+ if ( prop . items && prop . items . type ) {
3514
+ switch ( prop . items . type ) {
3515
+ case "object" :
3516
+ value = inputValues . map ( ( v ) => {
3517
+ try {
3518
+ const parsed = JSON . parse ( v ) ;
3519
+ if (
3520
+ typeof parsed !== "object" ||
3521
+ Array . isArray ( parsed )
3522
+ ) {
3523
+ throw new Error (
3524
+ `Value must be an object, got ${ typeof parsed } ` ,
3525
+ ) ;
3526
+ }
3527
+ return parsed ;
3528
+ } catch ( e ) {
3529
+ console . error (
3530
+ `Error parsing object for ${ key } :` ,
3531
+ e ,
3532
+ ) ;
3533
+ throw new Error (
3534
+ `Invalid object format for ${ key } . Each item must be a valid JSON object.` ,
3535
+ ) ;
3536
+ }
3537
+ } ) ;
3538
+ break ;
3539
+ case "number" :
3540
+ value = inputValues . map ( ( v ) =>
3541
+ v === "" ? null : Number ( v ) ,
3542
+ ) ;
3543
+ break ;
3544
+ case "boolean" :
3545
+ value = inputValues . map (
3546
+ ( v ) => v === "true" || v === true ,
3547
+ ) ;
3548
+ break ;
3549
+ default :
3550
+ // For other types (like strings), use raw values
3551
+ value = inputValues ;
3552
+ }
3553
+ } else {
3554
+ // If no items type specified, use raw values
3555
+ value = inputValues ;
3556
+ }
3557
+
3558
+ // Handle empty values
3559
+ if (
3560
+ value . length === 0 ||
3561
+ ( value . length === 1 && value [ 0 ] === "" )
3562
+ ) {
3563
+ if (
3564
+ schema . required &&
3565
+ schema . required . includes ( key )
3566
+ ) {
3567
+ params [ keyValidation . value ] = [ ] ;
3568
+ }
3569
+ continue ;
3570
+ }
3571
+ params [ keyValidation . value ] = value ;
3572
+ } catch ( error ) {
3573
+ console . error (
3574
+ `Error parsing array values for ${ key } :` ,
3575
+ error ,
3576
+ ) ;
3577
+ showErrorMessage (
3578
+ `Invalid input format for ${ key } . Please check the values are in correct format.` ,
3579
+ ) ;
3580
+ throw error ;
3521
3581
}
3522
- params [ keyValidation . value ] = value ;
3523
3582
} else {
3524
3583
value = formData . get ( key ) ;
3525
3584
if ( value === null || value === undefined || value === "" ) {
0 commit comments