199
200
const session = await toolRouter.create(userId);
201
202
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
203
- user_id: userId,
204
- toolkits: undefined,
205
- auth_configs: undefined,
206
- connected_accounts: undefined,
207
- tools: undefined,
208
- tags: undefined,
209
- manage_connections: createExpectedManageConnections(),
210
- workbench: undefined,
211
- });
202
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
203
+ {
204
+ user_id: userId,
205
+ toolkits: undefined,
206
+ auth_configs: undefined,
207
+ connected_accounts: undefined,
208
+ tools: undefined,
209
+ tags: undefined,
210
+ manage_connections: createExpectedManageConnections(),
211
+ workbench: undefined,
212
+ },
213
+ undefined
214
+ );
215
216
expect(session).toHaveProperty('sessionId', 'session_123');
217
expect(session).toHaveProperty('mcp');
232
233
const session = await toolRouter.create(userId, {});
234
232
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
233
- user_id: userId,
234
- toolkits: undefined,
235
- auth_configs: undefined,
236
- connected_accounts: undefined,
237
- tools: undefined,
238
- tags: undefined,
239
- manage_connections: createExpectedManageConnections(),
240
- workbench: undefined,
241
- });
235
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
236
+ {
237
+ user_id: userId,
238
+ toolkits: undefined,
239
+ auth_configs: undefined,
240
+ connected_accounts: undefined,
241
+ tools: undefined,
242
+ tags: undefined,
243
+ manage_connections: createExpectedManageConnections(),
244
+ workbench: undefined,
245
+ },
246
+ undefined
247
+ );
248
249
expect(session.sessionId).toBe('session_123');
250
expect(session.preload.tools).toEqual([]);
265
preload: { tools: ['GMAIL_FETCH_EMAILS'] },
266
});
267
262
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
263
- user_id: userId,
264
- toolkits: {
265
- enable: ['gmail'],
266
- },
267
- auth_configs: undefined,
268
- connected_accounts: undefined,
269
- tools: undefined,
270
- tags: undefined,
271
- manage_connections: createExpectedManageConnections(),
272
- workbench: undefined,
273
- preload: { tools: ['GMAIL_FETCH_EMAILS'] },
274
- });
268
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
269
+ {
270
+ user_id: userId,
271
+ toolkits: {
272
+ enable: ['gmail'],
273
+ },
274
+ auth_configs: undefined,
275
+ connected_accounts: undefined,
276
+ tools: undefined,
277
+ tags: undefined,
278
+ manage_connections: createExpectedManageConnections(),
279
+ workbench: undefined,
280
+ preload: { tools: ['GMAIL_FETCH_EMAILS'] },
281
+ },
282
+ undefined
283
+ );
284
285
expect(session.preload.tools).toEqual(['GMAIL_FETCH_EMAILS']);
286
expect(session.configVersion).toBe(2);
300
preload: { tools: 'all' },
301
});
302
294
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
295
- user_id: userId,
296
- toolkits: {
297
- enable: ['github'],
298
- },
299
- auth_configs: undefined,
300
- connected_accounts: undefined,
301
- tools: undefined,
302
- tags: undefined,
303
- manage_connections: createExpectedManageConnections(),
304
- workbench: undefined,
305
- preload: { tools: 'all' },
306
- });
303
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
304
+ {
305
+ user_id: userId,
306
+ toolkits: {
307
+ enable: ['github'],
308
+ },
309
+ auth_configs: undefined,
310
+ connected_accounts: undefined,
311
+ tools: undefined,
312
+ tags: undefined,
313
+ manage_connections: createExpectedManageConnections(),
314
+ workbench: undefined,
315
+ preload: { tools: 'all' },
316
+ },
317
+ undefined
318
+ );
319
320
expect(session.preload.tools).toBe('all');
321
});
350
toolkits: ['github'],
351
});
352
341
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
342
- user_id: userId,
343
- toolkits: {
344
- enable: ['github'],
345
- },
346
- auth_configs: undefined,
347
- connected_accounts: undefined,
348
- tools: undefined,
349
- tags: undefined,
350
- manage_connections: { enable: false },
351
- workbench: { enable: false },
352
- multi_account: undefined,
353
- preload: { tools: 'all' },
354
- search: { enable: false },
355
- execute: { enable_multi_execute: false },
356
- experimental: undefined,
357
- });
353
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
354
+ {
355
+ user_id: userId,
356
+ toolkits: {
357
+ enable: ['github'],
358
+ },
359
+ auth_configs: undefined,
360
+ connected_accounts: undefined,
361
+ tools: undefined,
362
+ tags: undefined,
363
+ manage_connections: { enable: false },
364
+ workbench: { enable: false },
365
+ multi_account: undefined,
366
+ preload: { tools: 'all' },
367
+ search: { enable: false },
368
+ execute: { enable_multi_execute: false },
369
+ experimental: undefined,
370
+ },
371
+ undefined
372
+ );
373
expect(session.preload.tools).toBe('all');
374
});
375
389
preload: { tools: ['GITHUB_CREATE_ISSUE'] },
390
});
391
377
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
378
- user_id: userId,
379
- toolkits: {
380
- enable: ['github'],
392
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
393
+ {
394
+ user_id: userId,
395
+ toolkits: {
396
+ enable: ['github'],
397
+ },
398
+ auth_configs: undefined,
399
+ connected_accounts: undefined,
400
+ tools: undefined,
401
+ tags: undefined,
402
+ manage_connections: { enable: true },
403
+ workbench: { enable: true },
404
+ multi_account: undefined,
405
+ preload: { tools: ['GITHUB_CREATE_ISSUE'] },
406
+ search: { enable: false },
407
+ execute: { enable_multi_execute: false },
408
+ experimental: undefined,
409
},
382
- auth_configs: undefined,
383
- connected_accounts: undefined,
384
- tools: undefined,
385
- tags: undefined,
386
- manage_connections: { enable: true },
387
- workbench: { enable: true },
388
- multi_account: undefined,
389
- preload: { tools: ['GITHUB_CREATE_ISSUE'] },
390
- search: { enable: false },
391
- execute: { enable_multi_execute: false },
392
- experimental: undefined,
393
- });
410
+ undefined
411
+ );
412
expect(session.preload.tools).toEqual(['GITHUB_CREATE_ISSUE']);
413
});
414
468
469
await toolRouter.create(userId, config);
470
453
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
454
- user_id: userId,
455
- toolkits: {
456
- enable: ['gmail', 'slack', 'github'],
457
- },
458
- auth_configs: undefined,
459
- connected_accounts: undefined,
460
- tools: undefined,
461
- tags: undefined,
462
- manage_connections: createExpectedManageConnections(),
463
- workbench: undefined,
464
- });
471
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
472
+ {
473
+ user_id: userId,
474
+ toolkits: {
475
+ enable: ['gmail', 'slack', 'github'],
476
+ },
477
+ auth_configs: undefined,
478
+ connected_accounts: undefined,
479
+ tools: undefined,
480
+ tags: undefined,
481
+ manage_connections: createExpectedManageConnections(),
482
+ workbench: undefined,
483
+ },
484
+ undefined
485
+ );
486
});
487
488
it('should create a session with enable toolkits configuration', async () => {
496
497
await toolRouter.create(userId, config);
498
478
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
479
- user_id: userId,
480
- toolkits: {
481
- enable: ['gmail', 'slack'],
482
- },
483
- auth_configs: undefined,
484
- connected_accounts: undefined,
485
- tools: undefined,
486
- tags: undefined,
487
- manage_connections: createExpectedManageConnections(),
488
- workbench: undefined,
489
- });
499
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
500
+ {
501
+ user_id: userId,
502
+ toolkits: {
503
+ enable: ['gmail', 'slack'],
504
+ },
505
+ auth_configs: undefined,
506
+ connected_accounts: undefined,
507
+ tools: undefined,
508
+ tags: undefined,
509
+ manage_connections: createExpectedManageConnections(),
510
+ workbench: undefined,
511
+ },
512
+ undefined
513
+ );
514
});
515
516
it('should create a session with disable toolkits configuration', async () => {
524
525
await toolRouter.create(userId, config);
526
503
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
504
- user_id: userId,
505
- toolkits: {
506
- disable: ['notion', 'trello'],
507
- },
508
- auth_configs: undefined,
509
- connected_accounts: undefined,
510
- tools: undefined,
511
- tags: undefined,
512
- manage_connections: createExpectedManageConnections(),
513
- workbench: undefined,
514
- });
527
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
528
+ {
529
+ user_id: userId,
530
+ toolkits: {
531
+ disable: ['notion', 'trello'],
532
+ },
533
+ auth_configs: undefined,
534
+ connected_accounts: undefined,
535
+ tools: undefined,
536
+ tags: undefined,
537
+ manage_connections: createExpectedManageConnections(),
538
+ workbench: undefined,
539
+ },
540
+ undefined
541
+ );
542
});
543
});
544
552
553
await toolRouter.create(userId, config);
554
528
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
529
- user_id: userId,
530
- toolkits: undefined,
531
- auth_configs: undefined,
532
- connected_accounts: undefined,
533
- tools: undefined,
534
- tags: {
535
- enable: ['readOnlyHint', 'idempotentHint'],
555
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
556
+ {
557
+ user_id: userId,
558
+ toolkits: undefined,
559
+ auth_configs: undefined,
560
+ connected_accounts: undefined,
561
+ tools: undefined,
562
+ tags: {
563
+ enable: ['readOnlyHint', 'idempotentHint'],
564
+ },
565
+ manage_connections: createExpectedManageConnections(),
566
+ workbench: undefined,
567
},
537
- manage_connections: createExpectedManageConnections(),
538
- workbench: undefined,
539
- });
568
+ undefined
569
+ );
570
});
571
572
it('should create a session with tags object with enable property', async () => {
580
581
await toolRouter.create(userId, config);
582
553
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
554
- user_id: userId,
555
- toolkits: undefined,
556
- auth_configs: undefined,
557
- connected_accounts: undefined,
558
- tools: undefined,
559
- tags: {
560
- enable: ['readOnlyHint', 'idempotentHint'],
583
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
584
+ {
585
+ user_id: userId,
586
+ toolkits: undefined,
587
+ auth_configs: undefined,
588
+ connected_accounts: undefined,
589
+ tools: undefined,
590
+ tags: {
591
+ enable: ['readOnlyHint', 'idempotentHint'],
592
+ },
593
+ manage_connections: createExpectedManageConnections(),
594
+ workbench: undefined,
595
},
562
- manage_connections: createExpectedManageConnections(),
563
- workbench: undefined,
564
- });
596
+ undefined
597
+ );
598
});
599
600
it('should create a session with tags object with disable property', async () => {
608
609
await toolRouter.create(userId, config);
610
578
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
579
- user_id: userId,
580
- toolkits: undefined,
581
- auth_configs: undefined,
582
- connected_accounts: undefined,
583
- tools: undefined,
584
- tags: {
585
- enable: undefined,
586
- disable: ['destructiveHint'],
611
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
612
+ {
613
+ user_id: userId,
614
+ toolkits: undefined,
615
+ auth_configs: undefined,
616
+ connected_accounts: undefined,
617
+ tools: undefined,
618
+ tags: {
619
+ enable: undefined,
620
+ disable: ['destructiveHint'],
621
+ },
622
+ manage_connections: createExpectedManageConnections(),
623
+ workbench: undefined,
624
},
588
- manage_connections: createExpectedManageConnections(),
589
- workbench: undefined,
590
- });
625
+ undefined
626
+ );
627
});
628
629
it('should create a session with tags object with both enable and disable properties', async () => {
638
639
await toolRouter.create(userId, config);
640
605
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
606
- user_id: userId,
607
- toolkits: undefined,
608
- auth_configs: undefined,
609
- connected_accounts: undefined,
610
- tools: undefined,
611
- tags: {
612
- enable: ['readOnlyHint', 'idempotentHint'],
613
- disable: ['destructiveHint'],
641
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
642
+ {
643
+ user_id: userId,
644
+ toolkits: undefined,
645
+ auth_configs: undefined,
646
+ connected_accounts: undefined,
647
+ tools: undefined,
648
+ tags: {
649
+ enable: ['readOnlyHint', 'idempotentHint'],
650
+ disable: ['destructiveHint'],
651
+ },
652
+ manage_connections: createExpectedManageConnections(),
653
+ workbench: undefined,
654
},
615
- manage_connections: createExpectedManageConnections(),
616
- workbench: undefined,
617
- });
655
+ undefined
656
+ );
657
});
658
659
it('should create a session with single tag in array', async () => {
665
666
await toolRouter.create(userId, config);
667
629
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
630
- user_id: userId,
631
- toolkits: undefined,
632
- auth_configs: undefined,
633
- connected_accounts: undefined,
634
- tools: undefined,
635
- tags: {
636
- enable: ['readOnlyHint'],
668
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
669
+ {
670
+ user_id: userId,
671
+ toolkits: undefined,
672
+ auth_configs: undefined,
673
+ connected_accounts: undefined,
674
+ tools: undefined,
675
+ tags: {
676
+ enable: ['readOnlyHint'],
677
+ },
678
+ manage_connections: createExpectedManageConnections(),
679
+ workbench: undefined,
680
},
638
- manage_connections: createExpectedManageConnections(),
639
- workbench: undefined,
640
- });
681
+ undefined
682
+ );
683
});
684
685
it('should create a session with all tag types', async () => {
691
692
await toolRouter.create(userId, config);
693
652
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
653
- user_id: userId,
654
- toolkits: undefined,
655
- auth_configs: undefined,
656
- connected_accounts: undefined,
657
- tools: undefined,
658
- tags: {
659
- enable: ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'],
694
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
695
+ {
696
+ user_id: userId,
697
+ toolkits: undefined,
698
+ auth_configs: undefined,
699
+ connected_accounts: undefined,
700
+ tools: undefined,
701
+ tags: {
702
+ enable: ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'],
703
+ },
704
+ manage_connections: createExpectedManageConnections(),
705
+ workbench: undefined,
706
},
661
- manage_connections: createExpectedManageConnections(),
662
- workbench: undefined,
663
- });
707
+ undefined
708
+ );
709
});
710
711
it('should create a session with tags combined with toolkits', async () => {
718
719
await toolRouter.create(userId, config);
720
676
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
677
- user_id: userId,
678
- toolkits: {
679
- enable: ['gmail', 'slack'],
680
- },
681
- auth_configs: undefined,
682
- connected_accounts: undefined,
683
- tools: undefined,
684
- tags: {
685
- enable: ['readOnlyHint'],
721
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
722
+ {
723
+ user_id: userId,
724
+ toolkits: {
725
+ enable: ['gmail', 'slack'],
726
+ },
727
+ auth_configs: undefined,
728
+ connected_accounts: undefined,
729
+ tools: undefined,
730
+ tags: {
731
+ enable: ['readOnlyHint'],
732
+ },
733
+ manage_connections: createExpectedManageConnections(),
734
+ workbench: undefined,
735
},
687
- manage_connections: createExpectedManageConnections(),
688
- workbench: undefined,
689
- });
736
+ undefined
737
+ );
738
});
739
});
740
952
953
await toolRouter.create(userId, config);
954
907
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
908
- user_id: userId,
909
- toolkits: undefined,
910
- auth_configs: undefined,
911
- connected_accounts: undefined,
912
- tools: undefined,
913
- tags: undefined,
914
- manage_connections: createExpectedManageConnections({ enable: true }),
915
- workbench: undefined,
916
- });
955
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
956
+ {
957
+ user_id: userId,
958
+ toolkits: undefined,
959
+ auth_configs: undefined,
960
+ connected_accounts: undefined,
961
+ tools: undefined,
962
+ tags: undefined,
963
+ manage_connections: createExpectedManageConnections({ enable: true }),
964
+ workbench: undefined,
965
+ },
966
+ undefined
967
+ );
968
});
969
970
it('should create a session with manageConnections as boolean (false)', async () => {
976
977
await toolRouter.create(userId, config);
978
928
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
929
- user_id: userId,
930
- toolkits: undefined,
931
- auth_configs: undefined,
932
- connected_accounts: undefined,
933
- tools: undefined,
934
- tags: undefined,
935
- manage_connections: createExpectedManageConnections({ enable: false }),
936
- workbench: undefined,
937
- });
979
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
980
+ {
981
+ user_id: userId,
982
+ toolkits: undefined,
983
+ auth_configs: undefined,
984
+ connected_accounts: undefined,
985
+ tools: undefined,
986
+ tags: undefined,
987
+ manage_connections: createExpectedManageConnections({ enable: false }),
988
+ workbench: undefined,
989
+ },
990
+ undefined
991
+ );
992
});
993
994
it('should create a session with manageConnections as object with enable', async () => {
1002
1003
await toolRouter.create(userId, config);
1004
951
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
952
- user_id: userId,
953
- toolkits: undefined,
954
- auth_configs: undefined,
955
- connected_accounts: undefined,
956
- tools: undefined,
957
- tags: undefined,
958
- manage_connections: createExpectedManageConnections({ enable: true }),
959
- workbench: undefined,
960
- });
1005
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1006
+ {
1007
+ user_id: userId,
1008
+ toolkits: undefined,
1009
+ auth_configs: undefined,
1010
+ connected_accounts: undefined,
1011
+ tools: undefined,
1012
+ tags: undefined,
1013
+ manage_connections: createExpectedManageConnections({ enable: true }),
1014
+ workbench: undefined,
1015
+ },
1016
+ undefined
1017
+ );
1018
});
1019
1020
it('should create a session with manageConnections object with callbackUrl', async () => {
1029
1030
await toolRouter.create(userId, config);
1031
975
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
976
- user_id: userId,
977
- toolkits: undefined,
978
- auth_configs: undefined,
979
- connected_accounts: undefined,
980
- tools: undefined,
981
- tags: undefined,
982
- manage_connections: createExpectedManageConnections({
983
- enable: true,
984
- callbackUrl: 'https://myapp.com/callback',
985
- }),
986
- workbench: undefined,
987
- });
1032
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1033
+ {
1034
+ user_id: userId,
1035
+ toolkits: undefined,
1036
+ auth_configs: undefined,
1037
+ connected_accounts: undefined,
1038
+ tools: undefined,
1039
+ tags: undefined,
1040
+ manage_connections: createExpectedManageConnections({
1041
+ enable: true,
1042
+ callbackUrl: 'https://myapp.com/callback',
1043
+ }),
1044
+ workbench: undefined,
1045
+ },
1046
+ undefined
1047
+ );
1048
});
1049
1050
it('should create a session with full manageConnections configuration', async () => {
1059
1060
await toolRouter.create(userId, config);
1061
1002
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1003
- user_id: userId,
1004
- toolkits: undefined,
1005
- auth_configs: undefined,
1006
- connected_accounts: undefined,
1007
- tools: undefined,
1008
- tags: undefined,
1009
- manage_connections: createExpectedManageConnections({
1010
- enable: true,
1011
- callbackUrl: 'https://myapp.com/callback',
1012
- }),
1013
- workbench: undefined,
1014
- });
1062
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1063
+ {
1064
+ user_id: userId,
1065
+ toolkits: undefined,
1066
+ auth_configs: undefined,
1067
+ connected_accounts: undefined,
1068
+ tools: undefined,
1069
+ tags: undefined,
1070
+ manage_connections: createExpectedManageConnections({
1071
+ enable: true,
1072
+ callbackUrl: 'https://myapp.com/callback',
1073
+ }),
1074
+ workbench: undefined,
1075
+ },
1076
+ undefined
1077
+ );
1078
});
1079
});
1080
1091
1092
await toolRouter.create(userId, config);
1093
1031
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1032
- user_id: userId,
1033
- toolkits: undefined,
1034
- auth_configs: {
1035
- gmail: 'auth_config_123',
1036
- slack: 'auth_config_456',
1094
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1095
+ {
1096
+ user_id: userId,
1097
+ toolkits: undefined,
1098
+ auth_configs: {
1099
+ gmail: 'auth_config_123',
1100
+ slack: 'auth_config_456',
1101
+ },
1102
+ connected_accounts: undefined,
1103
+ tools: undefined,
1104
+ tags: undefined,
1105
+ manage_connections: createExpectedManageConnections(),
1106
+ workbench: undefined,
1107
},
1038
- connected_accounts: undefined,
1039
- tools: undefined,
1040
- tags: undefined,
1041
- manage_connections: createExpectedManageConnections(),
1042
- workbench: undefined,
1043
- });
1108
+ undefined
1109
+ );
1110
});
1111
1112
it('should create a session with connectedAccounts (string coerced to array)', async () => {
1121
1122
await toolRouter.create(userId, config);
1123
1058
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1059
- user_id: userId,
1060
- toolkits: undefined,
1061
- auth_configs: undefined,
1062
- connected_accounts: {
1063
- gmail: ['conn_123'],
1064
- slack: ['conn_456'],
1124
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1125
+ {
1126
+ user_id: userId,
1127
+ toolkits: undefined,
1128
+ auth_configs: undefined,
1129
+ connected_accounts: {
1130
+ gmail: ['conn_123'],
1131
+ slack: ['conn_456'],
1132
+ },
1133
+ tools: undefined,
1134
+ tags: undefined,
1135
+ manage_connections: createExpectedManageConnections(),
1136
+ workbench: undefined,
1137
},
1066
- tools: undefined,
1067
- tags: undefined,
1068
- manage_connections: createExpectedManageConnections(),
1069
- workbench: undefined,
1070
- });
1138
+ undefined
1139
+ );
1140
});
1141
1142
it('should create a session with both authConfigs and connectedAccounts', async () => {
1153
1154
await toolRouter.create(userId, config);
1155
1087
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1088
- user_id: userId,
1089
- toolkits: undefined,
1090
- auth_configs: {
1091
- gmail: 'auth_config_123',
1092
- },
1093
- connected_accounts: {
1094
- slack: ['conn_456'],
1156
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1157
+ {
1158
+ user_id: userId,
1159
+ toolkits: undefined,
1160
+ auth_configs: {
1161
+ gmail: 'auth_config_123',
1162
+ },
1163
+ connected_accounts: {
1164
+ slack: ['conn_456'],
1165
+ },
1166
+ tools: undefined,
1167
+ tags: undefined,
1168
+ manage_connections: createExpectedManageConnections(),
1169
+ workbench: undefined,
1170
},
1096
- tools: undefined,
1097
- tags: undefined,
1098
- manage_connections: createExpectedManageConnections(),
1099
- workbench: undefined,
1100
- });
1171
+ undefined
1172
+ );
1173
});
1174
});
1175
1185
1186
await toolRouter.create(userId, config);
1187
1116
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1117
- user_id: userId,
1118
- toolkits: undefined,
1119
- auth_configs: undefined,
1120
- connected_accounts: undefined,
1121
- tools: undefined,
1122
- tags: undefined,
1123
- manage_connections: createExpectedManageConnections(),
1124
- workbench: {
1125
- enable: true,
1126
- enable_proxy_execution: true,
1127
- auto_offload_threshold: undefined,
1188
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1189
+ {
1190
+ user_id: userId,
1191
+ toolkits: undefined,
1192
+ auth_configs: undefined,
1193
+ connected_accounts: undefined,
1194
+ tools: undefined,
1195
+ tags: undefined,
1196
+ manage_connections: createExpectedManageConnections(),
1197
+ workbench: {
1198
+ enable: true,
1199
+ enable_proxy_execution: true,
1200
+ auto_offload_threshold: undefined,
1201
+ },
1202
},
1129
- });
1203
+ undefined
1204
+ );
1205
});
1206
1207
it('should create a session with autoOffloadThreshold only', async () => {
1215
1216
await toolRouter.create(userId, config);
1217
1143
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1144
- user_id: userId,
1145
- toolkits: undefined,
1146
- auth_configs: undefined,
1147
- connected_accounts: undefined,
1148
- tools: undefined,
1149
- tags: undefined,
1150
- manage_connections: createExpectedManageConnections(),
1151
- workbench: {
1152
- enable: true,
1153
- enable_proxy_execution: undefined,
1154
- auto_offload_threshold: 1000,
1218
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1219
+ {
1220
+ user_id: userId,
1221
+ toolkits: undefined,
1222
+ auth_configs: undefined,
1223
+ connected_accounts: undefined,
1224
+ tools: undefined,
1225
+ tags: undefined,
1226
+ manage_connections: createExpectedManageConnections(),
1227
+ workbench: {
1228
+ enable: true,
1229
+ enable_proxy_execution: undefined,
1230
+ auto_offload_threshold: 1000,
1231
+ },
1232
},
1156
- });
1233
+ undefined
1234
+ );
1235
});
1236
1237
it('should create a session with full workbench configuration', async () => {
1246
1247
await toolRouter.create(userId, config);
1248
1171
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1172
- user_id: userId,
1173
- toolkits: undefined,
1174
- auth_configs: undefined,
1175
- connected_accounts: undefined,
1176
- tools: undefined,
1177
- tags: undefined,
1178
- manage_connections: createExpectedManageConnections(),
1179
- workbench: {
1180
- enable: true,
1181
- enable_proxy_execution: true,
1182
- auto_offload_threshold: 500,
1249
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1250
+ {
1251
+ user_id: userId,
1252
+ toolkits: undefined,
1253
+ auth_configs: undefined,
1254
+ connected_accounts: undefined,
1255
+ tools: undefined,
1256
+ tags: undefined,
1257
+ manage_connections: createExpectedManageConnections(),
1258
+ workbench: {
1259
+ enable: true,
1260
+ enable_proxy_execution: true,
1261
+ auto_offload_threshold: 500,
1262
+ },
1263
},
1184
- });
1264
+ undefined
1265
+ );
1266
});
1267
1268
it('should create a session with workbench proxy and offload disabled', async () => {
1277
1278
await toolRouter.create(userId, config);
1279
1199
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1200
- user_id: userId,
1201
- toolkits: undefined,
1202
- auth_configs: undefined,
1203
- connected_accounts: undefined,
1204
- tools: undefined,
1205
- tags: undefined,
1206
- manage_connections: createExpectedManageConnections(),
1207
- workbench: {
1208
- enable: true,
1209
- enable_proxy_execution: false,
1210
- auto_offload_threshold: 0,
1280
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1281
+ {
1282
+ user_id: userId,
1283
+ toolkits: undefined,
1284
+ auth_configs: undefined,
1285
+ connected_accounts: undefined,
1286
+ tools: undefined,
1287
+ tags: undefined,
1288
+ manage_connections: createExpectedManageConnections(),
1289
+ workbench: {
1290
+ enable: true,
1291
+ enable_proxy_execution: false,
1292
+ auto_offload_threshold: 0,
1293
+ },
1294
},
1212
- });
1295
+ undefined
1296
+ );
1297
});
1298
1299
it('should create a session with workbench entirely disabled', async () => {
1307
1308
await toolRouter.create(userId, config);
1309
1226
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1227
- user_id: userId,
1228
- toolkits: undefined,
1229
- auth_configs: undefined,
1230
- connected_accounts: undefined,
1231
- tools: undefined,
1232
- tags: undefined,
1233
- manage_connections: createExpectedManageConnections(),
1234
- workbench: {
1235
- enable: false,
1236
- enable_proxy_execution: undefined,
1237
- auto_offload_threshold: undefined,
1310
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1311
+ {
1312
+ user_id: userId,
1313
+ toolkits: undefined,
1314
+ auth_configs: undefined,
1315
+ connected_accounts: undefined,
1316
+ tools: undefined,
1317
+ tags: undefined,
1318
+ manage_connections: createExpectedManageConnections(),
1319
+ workbench: {
1320
+ enable: false,
1321
+ enable_proxy_execution: undefined,
1322
+ auto_offload_threshold: undefined,
1323
+ },
1324
},
1239
- });
1325
+ undefined
1326
+ );
1327
});
1328
1329
it('should create a session with workbench explicitly enabled', async () => {
1339
1340
await toolRouter.create(userId, config);
1341
1255
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1256
- user_id: userId,
1257
- toolkits: undefined,
1258
- auth_configs: undefined,
1259
- connected_accounts: undefined,
1260
- tools: undefined,
1261
- tags: undefined,
1262
- manage_connections: createExpectedManageConnections(),
1263
- workbench: {
1264
- enable: true,
1265
- enable_proxy_execution: true,
1266
- auto_offload_threshold: 20000,
1342
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1343
+ {
1344
+ user_id: userId,
1345
+ toolkits: undefined,
1346
+ auth_configs: undefined,
1347
+ connected_accounts: undefined,
1348
+ tools: undefined,
1349
+ tags: undefined,
1350
+ manage_connections: createExpectedManageConnections(),
1351
+ workbench: {
1352
+ enable: true,
1353
+ enable_proxy_execution: true,
1354
+ auto_offload_threshold: 20000,
1355
+ },
1356
},
1268
- });
1357
+ undefined
1358
+ );
1359
});
1360
1361
it('forwards sandboxSize as snake_case sandbox_size on the wire', async () => {
1547
max_accounts_per_toolkit: undefined,
1548
require_explicit_selection: true,
1549
},
1460
- })
1550
+ }),
1551
+ undefined
1552
);
1553
});
1554
1573
max_accounts_per_toolkit: 3,
1574
require_explicit_selection: true,
1575
},
1485
- })
1576
+ }),
1577
+ undefined
1578
);
1579
});
1580
1609
max_accounts_per_toolkit: 5,
1610
require_explicit_selection: true,
1611
},
1520
- })
1612
+ }),
1613
+ undefined
1614
);
1615
});
1616
});
1629
1630
await toolRouter.create(userId, config);
1631
1539
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1540
- user_id: userId,
1541
- toolkits: undefined,
1542
- auth_configs: undefined,
1543
- connected_accounts: undefined,
1544
- tools: undefined,
1545
- tags: undefined,
1546
- manage_connections: createExpectedManageConnections(),
1547
- workbench: undefined,
1548
- experimental: {
1549
- assistive_prompt_config: {
1550
- user_timezone: 'America/New_York',
1632
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1633
+ {
1634
+ user_id: userId,
1635
+ toolkits: undefined,
1636
+ auth_configs: undefined,
1637
+ connected_accounts: undefined,
1638
+ tools: undefined,
1639
+ tags: undefined,
1640
+ manage_connections: createExpectedManageConnections(),
1641
+ workbench: undefined,
1642
+ experimental: {
1643
+ assistive_prompt_config: {
1644
+ user_timezone: 'America/New_York',
1645
+ },
1646
},
1647
},
1553
- });
1648
+ undefined
1649
+ );
1650
});
1651
1652
it('should not include experimental in payload when assistivePrompt is not provided', async () => {
1658
1659
await toolRouter.create(userId, config);
1660
1565
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1566
- user_id: userId,
1567
- toolkits: undefined,
1568
- auth_configs: undefined,
1569
- connected_accounts: undefined,
1570
- tools: undefined,
1571
- tags: undefined,
1572
- manage_connections: createExpectedManageConnections(),
1573
- workbench: undefined,
1574
- experimental: undefined,
1575
- });
1661
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1662
+ {
1663
+ user_id: userId,
1664
+ toolkits: undefined,
1665
+ auth_configs: undefined,
1666
+ connected_accounts: undefined,
1667
+ tools: undefined,
1668
+ tags: undefined,
1669
+ manage_connections: createExpectedManageConnections(),
1670
+ workbench: undefined,
1671
+ experimental: undefined,
1672
+ },
1673
+ undefined
1674
+ );
1675
});
1676
1677
it('should not include experimental in payload when userTimezone is not provided', async () => {
1685
1686
await toolRouter.create(userId, config);
1687
1589
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1590
- user_id: userId,
1591
- toolkits: undefined,
1592
- auth_configs: undefined,
1593
- connected_accounts: undefined,
1594
- tools: undefined,
1595
- tags: undefined,
1596
- manage_connections: createExpectedManageConnections(),
1597
- workbench: undefined,
1598
- experimental: undefined,
1599
- });
1688
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1689
+ {
1690
+ user_id: userId,
1691
+ toolkits: undefined,
1692
+ auth_configs: undefined,
1693
+ connected_accounts: undefined,
1694
+ tools: undefined,
1695
+ tags: undefined,
1696
+ manage_connections: createExpectedManageConnections(),
1697
+ workbench: undefined,
1698
+ experimental: undefined,
1699
+ },
1700
+ undefined
1701
+ );
1702
});
1703
1704
it('should create a session with experimental config combined with other options', async () => {
1715
1716
await toolRouter.create(userId, config);
1717
1616
- expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith({
1617
- user_id: userId,
1618
- toolkits: {
1619
- enable: ['gmail', 'slack'],
1620
- },
1621
- auth_configs: undefined,
1622
- connected_accounts: undefined,
1623
- tools: undefined,
1624
- tags: undefined,
1625
- manage_connections: createExpectedManageConnections(),
1626
- workbench: undefined,
1627
- experimental: {
1628
- assistive_prompt_config: {
1629
- user_timezone: 'Europe/London',
1718
+ expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1719
+ {
1720
+ user_id: userId,
1721
+ toolkits: {
1722
+ enable: ['gmail', 'slack'],
1723
+ },
1724
+ auth_configs: undefined,
1725
+ connected_accounts: undefined,
1726
+ tools: undefined,
1727
+ tags: undefined,
1728
+ manage_connections: createExpectedManageConnections(),
1729
+ workbench: undefined,
1730
+ experimental: {
1731
+ assistive_prompt_config: {
1732
+ user_timezone: 'Europe/London',
1733
+ },
1734
},
1735
},
1632
- });
1736
+ undefined
1737
+ );
1738
});
1739
1740
it('should transform experimental assistive_prompt from API response to SDK format', async () => {
1803
expect(mockClient.toolRouter.session.create).toHaveBeenCalledWith(
1804
expect.objectContaining({
1805
user_id: '',
1701
- })
1806
+ }),
1807
+ undefined
1808
);
1809
});
1810
});
1876
const session = await toolRouter.create(userId);
1877
const connectionRequest = await session.authorize(toolkit);
1878
1773
- expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {
1774
- toolkit,
1775
- });
1879
+ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(
1880
+ sessionId,
1881
+ {
1882
+ toolkit,
1883
+ },
1884
+ undefined
1885
+ );
1886
1887
expect(connectionRequest).toHaveProperty('id', 'conn_456');
1888
expect(connectionRequest).toHaveProperty('status', ConnectedAccountStatuses.INITIATED);
1897
callbackUrl: 'https://myapp.com/callback',
1898
});
1899
1790
- expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {
1791
- toolkit,
1792
- callback_url: 'https://myapp.com/callback',
1793
- });
1900
+ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(
1901
+ sessionId,
1902
+ {
1903
+ toolkit,
1904
+ callback_url: 'https://myapp.com/callback',
1905
+ },
1906
+ undefined
1907
+ );
1908
1909
expect(connectionRequest.id).toBe('conn_456');
1910
expect(connectionRequest.redirectUrl).toBe('https://composio.dev/auth/redirect');
1940
'Authorization failed: Invalid toolkit'
1941
);
1942
1829
- expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {
1830
- toolkit,
1831
- });
1943
+ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(
1944
+ sessionId,
1945
+ {
1946
+ toolkit,
1947
+ },
1948
+ undefined
1949
+ );
1950
});
1951
1952
it('should handle network errors during authorization', async () => {
1987
},
1988
});
1989
1872
- expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {
1873
- toolkit,
1874
- experimental: {
1875
- account_type: 'SHARED',
1876
- acl_config_for_shared: {
1877
- allow_all_users: true,
1878
- not_allowed_user_ids: ['user_bob'],
1990
+ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(
1991
+ sessionId,
1992
+ {
1993
+ toolkit,
1994
+ experimental: {
1995
+ account_type: 'SHARED',
1996
+ acl_config_for_shared: {
1997
+ allow_all_users: true,
1998
+ not_allowed_user_ids: ['user_bob'],
1999
+ },
2000
},
2001
},
1881
- });
2002
+ undefined
2003
+ );
2004
});
2005
2006
it('omits the experimental block entirely when not provided', async () => {
2075
const session = await toolRouter.create(userId);
2076
const result = await session.toolkits();
2077
1956
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
1957
- cursor: undefined,
1958
- limit: undefined,
1959
- toolkits: undefined,
1960
- is_connected: undefined,
1961
- });
2078
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2079
+ sessionId,
2080
+ {
2081
+ cursor: undefined,
2082
+ limit: undefined,
2083
+ toolkits: undefined,
2084
+ is_connected: undefined,
2085
+ },
2086
+ undefined
2087
+ );
2088
2089
expect(result).toHaveProperty('items');
2090
expect(result).toHaveProperty('cursor', 'cursor_789');
2101
cursor: 'cursor_abc',
2102
});
2103
1978
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
1979
- cursor: 'cursor_abc',
1980
- limit: 10,
1981
- toolkits: undefined,
1982
- is_connected: undefined,
1983
- });
2104
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2105
+ sessionId,
2106
+ {
2107
+ cursor: 'cursor_abc',
2108
+ limit: 10,
2109
+ toolkits: undefined,
2110
+ is_connected: undefined,
2111
+ },
2112
+ undefined
2113
+ );
2114
2115
expect(result.items).toHaveLength(3);
2116
});
2123
toolkits: ['gmail', 'slack'],
2124
});
2125
1996
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
1997
- cursor: undefined,
1998
- limit: undefined,
1999
- toolkits: ['gmail', 'slack'],
2000
- is_connected: undefined,
2001
- });
2126
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2127
+ sessionId,
2128
+ {
2129
+ cursor: undefined,
2130
+ limit: undefined,
2131
+ toolkits: ['gmail', 'slack'],
2132
+ is_connected: undefined,
2133
+ },
2134
+ undefined
2135
+ );
2136
2137
expect(result.items).toHaveLength(3);
2138
});
2145
isConnected: true,
2146
});
2147
2014
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
2015
- cursor: undefined,
2016
- limit: undefined,
2017
- toolkits: undefined,
2018
- is_connected: true,
2019
- });
2148
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2149
+ sessionId,
2150
+ {
2151
+ cursor: undefined,
2152
+ limit: undefined,
2153
+ toolkits: undefined,
2154
+ is_connected: true,
2155
+ },
2156
+ undefined
2157
+ );
2158
2159
expect(result.items).toHaveLength(3);
2160
});
2169
toolkits: ['github'],
2170
});
2171
2034
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
2035
- cursor: 'cursor_xyz',
2036
- limit: 5,
2037
- toolkits: ['github'],
2038
- is_connected: undefined,
2039
- });
2172
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2173
+ sessionId,
2174
+ {
2175
+ cursor: 'cursor_xyz',
2176
+ limit: 5,
2177
+ toolkits: ['github'],
2178
+ is_connected: undefined,
2179
+ },
2180
+ undefined
2181
+ );
2182
2183
expect(result.items).toHaveLength(3);
2184
});
2194
isConnected: false,
2195
});
2196
2055
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
2056
- cursor: 'cursor_xyz',
2057
- limit: 5,
2058
- toolkits: ['github', 'gmail'],
2059
- is_connected: false,
2060
- });
2197
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
2198
+ sessionId,
2199
+ {
2200
+ cursor: 'cursor_xyz',
2201
+ limit: 5,
2202
+ toolkits: ['github', 'gmail'],
2203
+ is_connected: false,
2204
+ },
2205
+ undefined
2206
+ );
2207
2208
expect(result.items).toHaveLength(3);
2209
});
2435
const session = await toolRouter.create(userId);
2436
const result = await session.search({ query: 'send emails' });
2437
2292
- expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(sessionId, {
2293
- queries: [{ use_case: 'send emails' }],
2294
- });
2438
+ expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(
2439
+ sessionId,
2440
+ {
2441
+ queries: [{ use_case: 'send emails' }],
2442
+ },
2443
+ undefined
2444
+ );
2445
expect(result.success).toBe(true);
2446
expect(result.results[0].useCase).toBe('send emails');
2447
expect(result.results[0].primaryToolSlugs).toEqual(['GMAIL_SEND_EMAIL']);
2458
const session = await toolRouter.create(userId);
2459
await session.search({ query: 'send emails', toolkits: ['gmail', 'slack'] });
2460
2311
- expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(sessionId, {
2312
- queries: [{ use_case: 'send emails' }],
2313
- toolkits: ['gmail', 'slack'],
2314
- });
2461
+ expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(
2462
+ sessionId,
2463
+ {
2464
+ queries: [{ use_case: 'send emails' }],
2465
+ toolkits: ['gmail', 'slack'],
2466
+ },
2467
+ undefined
2468
+ );
2469
});
2470
2471
it('should pass inline custom tools to search', async () => {
2495
});
2496
await session.search({ query: 'search local text' });
2497
2344
- expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(sessionId, {
2345
- queries: [{ use_case: 'search local text' }],
2346
- experimental: {
2347
- custom_tools: [
2348
- expect.objectContaining({
2349
- slug: 'GREP',
2350
- preload: true,
2351
- }),
2352
- ],
2498
+ expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(
2499
+ sessionId,
2500
+ {
2501
+ queries: [{ use_case: 'search local text' }],
2502
+ experimental: {
2503
+ custom_tools: [
2504
+ expect.objectContaining({
2505
+ slug: 'GREP',
2506
+ preload: true,
2507
+ }),
2508
+ ],
2509
+ },
2510
},
2354
- });
2511
+ undefined
2512
+ );
2513
});
2514
2515
it('should propagate search API errors', async () => {
2543
body: 'Hello',
2544
});
2545
2388
- expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
2389
- tool_slug: 'GMAIL_SEND_EMAIL',
2390
- arguments: { to: 'user@example.com', subject: 'Hi', body: 'Hello' },
2391
- });
2546
+ expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(
2547
+ sessionId,
2548
+ {
2549
+ tool_slug: 'GMAIL_SEND_EMAIL',
2550
+ arguments: { to: 'user@example.com', subject: 'Hi', body: 'Hello' },
2551
+ },
2552
+ undefined
2553
+ );
2554
expect(result.data).toEqual({ tool_slug: 'GMAIL_SEND_EMAIL', id: 'msg_123' });
2555
expect(result.error).toBeNull();
2556
expect(result.logId).toBe('log_abc');
2572
const session = await toolRouter.create(userId);
2573
await session.execute('HACKERNEWS_GET_USER');
2574
2413
- expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
2414
- tool_slug: 'HACKERNEWS_GET_USER',
2415
- arguments: {},
2416
- });
2575
+ expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(
2576
+ sessionId,
2577
+ {
2578
+ tool_slug: 'HACKERNEWS_GET_USER',
2579
+ arguments: {},
2580
+ },
2581
+ undefined
2582
+ );
2583
});
2584
2585
it('should pass account option to session execute', async () => {
2589
const session = await toolRouter.create(userId);
2590
await session.execute('GMAIL_SEND_EMAIL', { to: 'user@example.com' }, { account: 'work' });
2591
2426
- expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
2427
- tool_slug: 'GMAIL_SEND_EMAIL',
2428
- arguments: { to: 'user@example.com' },
2429
- account: 'work',
2430
- });
2592
+ expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(
2593
+ sessionId,
2594
+ {
2595
+ tool_slug: 'GMAIL_SEND_EMAIL',
2596
+ arguments: { to: 'user@example.com' },
2597
+ account: 'work',
2598
+ },
2599
+ undefined
2600
+ );
2601
});
2602
2603
it('should pass inline custom tools to remote execute when custom tools are bound', async () => {
2626
});
2627
await session.execute('GMAIL_SEND_EMAIL', { to: 'user@example.com' });
2628
2459
- expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
2460
- tool_slug: 'GMAIL_SEND_EMAIL',
2461
- arguments: { to: 'user@example.com' },
2462
- experimental: {
2463
- custom_tools: [expect.objectContaining({ slug: 'GREP' })],
2629
+ expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(
2630
+ sessionId,
2631
+ {
2632
+ tool_slug: 'GMAIL_SEND_EMAIL',
2633
+ arguments: { to: 'user@example.com' },
2634
+ experimental: {
2635
+ custom_tools: [expect.objectContaining({ slug: 'GREP' })],
2636
+ },
2637
},
2465
- });
2638
+ undefined
2639
+ );
2640
});
2641
});
2642
2670
});
2671
2672
const toolsInstance = (Tools as any).mock.results[0].value;
2499
- expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(sessionId, undefined);
2673
+ expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
2674
+ sessionId,
2675
+ undefined,
2676
+ undefined
2677
+ );
2678
expect(toolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
2679
sessionId,
2680
[{ slug: 'COMPOSIO_SEARCH_TOOLS' }],
2699
const tools = await session.tools(modifiers);
2700
2701
const toolsInstance = (Tools as any).mock.results[0].value;
2524
- expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(sessionId, {
2525
- modifySchema: modifiers.modifySchema,
2526
- });
2702
+ expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
2703
+ sessionId,
2704
+ { modifySchema: modifiers.modifySchema },
2705
+ undefined
2706
+ );
2707
expect(toolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
2708
sessionId,
2709
[{ slug: 'COMPOSIO_SEARCH_TOOLS' }],
3033
expect(Tools).toHaveBeenCalledTimes(2);
3034
3035
const firstToolsInstance = (Tools as any).mock.results[0].value;
2856
- expect(firstToolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(sessionId, {
2857
- modifySchema: modifier1.modifySchema,
2858
- });
3036
+ expect(firstToolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
3037
+ sessionId,
3038
+ { modifySchema: modifier1.modifySchema },
3039
+ undefined
3040
+ );
3041
expect(firstToolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
3042
sessionId,
3043
[{ slug: 'COMPOSIO_SEARCH_TOOLS' }],
3045
);
3046
3047
const secondToolsInstance = (Tools as any).mock.results[1].value;
2866
- expect(secondToolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(sessionId, {
2867
- modifySchema: modifier2.modifySchema,
2868
- });
3048
+ expect(secondToolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
3049
+ sessionId,
3050
+ { modifySchema: modifier2.modifySchema },
3051
+ undefined
3052
+ );
3053
expect(secondToolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
3054
sessionId,
3055
[{ slug: 'COMPOSIO_SEARCH_TOOLS' }],
3076
const toolsInstance = (Tools as any).mock.results[0].value;
3077
expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
3078
'custom_session_123',
3079
+ undefined,
3080
undefined
3081
);
3082
expect(toolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
3105
const toolsInstance = (Tools as any).mock.results[0].value;
3106
expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
3107
'empty_session_123',
3108
+ undefined,
3109
undefined
3110
);
3111
expect(toolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
3177
await session1.toolkits();
3178
await session2.toolkits();
3179
2994
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith('session_1', {
2995
- cursor: undefined,
2996
- limit: undefined,
2997
- toolkits: undefined,
2998
- is_connected: undefined,
2999
- });
3000
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith('session_2', {
3001
- cursor: undefined,
3002
- limit: undefined,
3003
- toolkits: undefined,
3004
- is_connected: undefined,
3005
- });
3180
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
3181
+ 'session_1',
3182
+ {
3183
+ cursor: undefined,
3184
+ limit: undefined,
3185
+ toolkits: undefined,
3186
+ is_connected: undefined,
3187
+ },
3188
+ undefined
3189
+ );
3190
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
3191
+ 'session_2',
3192
+ {
3193
+ cursor: undefined,
3194
+ limit: undefined,
3195
+ toolkits: undefined,
3196
+ is_connected: undefined,
3197
+ },
3198
+ undefined
3199
+ );
3200
});
3201
3202
it('should handle rapid successive calls', async () => {
3227
3228
const session = await toolRouter.use(sessionId);
3229
3036
- expect(mockClient.toolRouter.session.retrieve).toHaveBeenCalledWith(sessionId);
3230
+ expect(mockClient.toolRouter.session.retrieve).toHaveBeenCalledWith(sessionId, undefined);
3231
expect(mockClient.toolRouter.session.attach).not.toHaveBeenCalled();
3232
expect(mockClient.post).not.toHaveBeenCalled();
3233
expect(session).toHaveProperty('sessionId', 'session_123');
3269
3270
const session = await toolRouter.use(sessionId, { customTools: [grepTool] });
3271
3078
- expect(mockClient.toolRouter.session.attach).toHaveBeenCalledWith(sessionId, {
3079
- experimental: {
3080
- custom_tools: [expect.objectContaining({ slug: 'GREP' })],
3272
+ expect(mockClient.toolRouter.session.attach).toHaveBeenCalledWith(
3273
+ sessionId,
3274
+ {
3275
+ experimental: {
3276
+ custom_tools: [expect.objectContaining({ slug: 'GREP' })],
3277
+ },
3278
},
3082
- });
3279
+ undefined
3280
+ );
3281
expect(mockClient.toolRouter.session.attach.mock.calls[0][1].experimental).not.toHaveProperty(
3282
'custom_toolkits'
3283
);
3320
expect(Tools).toHaveBeenCalled();
3321
3322
const toolsInstance = (Tools as any).mock.results[0].value;
3125
- expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(sessionId, undefined);
3323
+ expect(toolsInstance.getRawToolRouterSessionTools).toHaveBeenCalledWith(
3324
+ sessionId,
3325
+ undefined,
3326
+ undefined
3327
+ );
3328
expect(toolsInstance.wrapToolsForToolRouter).toHaveBeenCalledWith(
3329
sessionId,
3330
[{ slug: 'COMPOSIO_SEARCH_TOOLS' }],
3340
3341
const connectionRequest = await session.authorize('github');
3342
3141
- expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {
3142
- toolkit: 'github',
3143
- });
3343
+ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(
3344
+ sessionId,
3345
+ {
3346
+ toolkit: 'github',
3347
+ },
3348
+ undefined
3349
+ );
3350
expect(connectionRequest).toHaveProperty('redirectUrl', 'https://composio.dev/auth/redirect');
3351
expect(connectionRequest).toHaveProperty('status', ConnectedAccountStatuses.INITIATED);
3352
});
3359
3360
const toolkitsResult = await session.toolkits();
3361
3156
- expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(sessionId, {
3157
- cursor: undefined,
3158
- limit: undefined,
3159
- toolkits: undefined,
3160
- is_connected: undefined,
3161
- });
3362
+ expect(mockClient.toolRouter.session.toolkits).toHaveBeenCalledWith(
3363
+ sessionId,
3364
+ {
3365
+ cursor: undefined,
3366
+ limit: undefined,
3367
+ toolkits: undefined,
3368
+ is_connected: undefined,
3369
+ },
3370
+ undefined
3371
+ );
3372
expect(toolkitsResult.items).toHaveLength(3);
3373
expect(toolkitsResult.items[0].slug).toBe('gmail');
3374
});
3399
const session = await toolRouter.use(sessionId, { customTools: [grepTool] });
3400
await session.tools();
3401
3192
- expect(mockClient.toolRouter.session.attach).toHaveBeenCalledWith(sessionId, {
3193
- experimental: {
3194
- custom_tools: [expect.objectContaining({ slug: 'GREP', preload: true })],
3402
+ expect(mockClient.toolRouter.session.attach).toHaveBeenCalledWith(
3403
+ sessionId,
3404
+ {
3405
+ experimental: {
3406
+ custom_tools: [expect.objectContaining({ slug: 'GREP', preload: true })],
3407
+ },
3408
},
3196
- });
3409
+ undefined
3410
+ );
3411
expect(mockClient.post).not.toHaveBeenCalled();
3412
expect(mockClient.toolRouter.session.retrieve).not.toHaveBeenCalled();
3413
const wrappedTools = mockProvider.wrapTools.mock.calls[0][0] as Array<{ slug: string }>;
3464
3465
const wrappedTools = mockProvider.wrapTools.mock.calls[0][0] as Array<{ slug: string }>;
3466
expect(wrappedTools.map(tool => tool.slug)).toEqual(['COMPOSIO_SEARCH_TOOLS', 'LOCAL_GREP']);
3253
- expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(sessionId, {
3254
- queries: [{ use_case: 'search local text' }],
3255
- experimental: {
3256
- custom_tools: [expect.objectContaining({ slug: 'GREP', preload: true })],
3467
+ expect(mockClient.toolRouter.session.search).toHaveBeenCalledWith(
3468
+ sessionId,
3469
+ {
3470
+ queries: [{ use_case: 'search local text' }],
3471
+ experimental: {
3472
+ custom_tools: [expect.objectContaining({ slug: 'GREP', preload: true })],
3473
+ },
3474
},
3258
- });
3475
+ undefined
3476
+ );
3477
});
3478
it('should handle different session IDs', async () => {
3479
const session1Response = {
3496
expect(session1.sessionId).toBe('session_1');
3497
expect(session2.sessionId).toBe('session_2');
3498
expect(mockClient.toolRouter.session.retrieve).toHaveBeenCalledTimes(2);
3281
- expect(mockClient.toolRouter.session.retrieve).toHaveBeenNthCalledWith(1, 'session_1');
3282
- expect(mockClient.toolRouter.session.retrieve).toHaveBeenNthCalledWith(2, 'session_2');
3499
+ expect(mockClient.toolRouter.session.retrieve).toHaveBeenNthCalledWith(
3500
+ 1,
3501
+ 'session_1',
3502
+ undefined
3503
+ );
3504
+ expect(mockClient.toolRouter.session.retrieve).toHaveBeenNthCalledWith(
3505
+ 2,
3506
+ 'session_2',
3507
+ undefined
3508
+ );
3509
expect(mockClient.post).not.toHaveBeenCalled();
3510
});
3511
3523
mockClient.toolRouter.session.retrieve.mockRejectedValueOnce(error);
3524
3525
await expect(toolRouter.use(sessionId)).rejects.toThrow('Session not found');
3300
- expect(mockClient.toolRouter.session.retrieve).toHaveBeenCalledWith(sessionId);
3526
+ expect(mockClient.toolRouter.session.retrieve).toHaveBeenCalledWith(sessionId, undefined);
3527
expect(mockClient.post).not.toHaveBeenCalled();
3528
});
3529