@superinterface/react 2.20.2 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2491,6 +2491,95 @@ var threadRunStepCompleted = function(param) {
2491
2491
  });
2492
2492
  });
2493
2493
  };
2494
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/threadRunRequiresAction.ts
2495
+ import { map } from "radash";
2496
+ var threadRunRequiresAction = function() {
2497
+ var _ref = _async_to_generator(function(param) {
2498
+ var value, queryClient, messagesQueryKey, superinterfaceContext, toolCalls, toolOutputs;
2499
+ return _ts_generator(this, function(_state) {
2500
+ switch(_state.label){
2501
+ case 0:
2502
+ value = param.value, queryClient = param.queryClient, messagesQueryKey = param.messagesQueryKey, superinterfaceContext = param.superinterfaceContext;
2503
+ if (!(value.data.required_action.type === "submit_client_tool_outputs")) return [
2504
+ 3,
2505
+ 2
2506
+ ];
2507
+ toolCalls = value.data.required_action.submit_client_tool_outputs.tool_calls;
2508
+ return [
2509
+ 4,
2510
+ map(toolCalls, function() {
2511
+ var _ref = _async_to_generator(function(toolCall) {
2512
+ var fn, args, parsedArgs, output;
2513
+ return _ts_generator(this, function(_state) {
2514
+ switch(_state.label){
2515
+ case 0:
2516
+ if (toolCall.type !== "function") {
2517
+ return [
2518
+ 2,
2519
+ {
2520
+ toolCallId: toolCall.id,
2521
+ output: "Error: client tool type ".concat(toolCall.type, " is not supported.")
2522
+ }
2523
+ ];
2524
+ }
2525
+ fn = window[toolCall.function.name];
2526
+ if (!fn) {
2527
+ return [
2528
+ 2,
2529
+ {
2530
+ toolCallId: toolCall.id,
2531
+ output: "Error: client function ".concat(toolCall.function.name, " is not defined.")
2532
+ }
2533
+ ];
2534
+ }
2535
+ args = toolCall.function.arguments;
2536
+ parsedArgs = JSON.parse(args);
2537
+ return [
2538
+ 4,
2539
+ fn(parsedArgs)
2540
+ ];
2541
+ case 1:
2542
+ output = _state.sent();
2543
+ return [
2544
+ 2,
2545
+ {
2546
+ toolCallId: toolCall.id,
2547
+ output: output
2548
+ }
2549
+ ];
2550
+ }
2551
+ });
2552
+ });
2553
+ return function(toolCall) {
2554
+ return _ref.apply(this, arguments);
2555
+ };
2556
+ }())
2557
+ ];
2558
+ case 1:
2559
+ toolOutputs = _state.sent();
2560
+ return [
2561
+ 2,
2562
+ fetch("".concat(superinterfaceContext.baseUrl, "/threads/runs/submit-client-tool-outputs"), {
2563
+ method: "POST",
2564
+ headers: {
2565
+ "Content-Type": "application/json"
2566
+ },
2567
+ body: JSON.stringify(_object_spread({
2568
+ toolOutputs: toolOutputs
2569
+ }, superinterfaceContext.variables))
2570
+ })
2571
+ ];
2572
+ case 2:
2573
+ return [
2574
+ 2
2575
+ ];
2576
+ }
2577
+ });
2578
+ });
2579
+ return function threadRunRequiresAction(_) {
2580
+ return _ref.apply(this, arguments);
2581
+ };
2582
+ }();
2494
2583
  // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/index.ts
2495
2584
  var handlers = {
2496
2585
  "thread.created": threadCreated,
@@ -2500,7 +2589,8 @@ var handlers = {
2500
2589
  "thread.run.created": threadRunCreated,
2501
2590
  "thread.run.step.created": threadRunStepCreated,
2502
2591
  "thread.run.step.delta": threadRunStepDelta,
2503
- "thread.run.step.completed": threadRunStepCompleted
2592
+ "thread.run.step.completed": threadRunStepCompleted,
2593
+ "thread.run.requires_action": threadRunRequiresAction
2504
2594
  };
2505
2595
  // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/index.ts
2506
2596
  var handleResponse = function(param) {
@@ -2538,7 +2628,7 @@ var mutationFn = function(param) {
2538
2628
  var superinterfaceContext = param.superinterfaceContext, queryClient = param.queryClient, threadContext = param.threadContext;
2539
2629
  return function() {
2540
2630
  var _ref = _async_to_generator(function(variables) {
2541
- var abortController, response, parser, reader, messagesQueryKey, _ref, done, value;
2631
+ var abortController, response, errorResponse, error, parser, reader, messagesQueryKey, _ref, done, value;
2542
2632
  return _ts_generator(this, function(_state) {
2543
2633
  switch(_state.label){
2544
2634
  case 0:
@@ -2557,6 +2647,29 @@ var mutationFn = function(param) {
2557
2647
  ];
2558
2648
  case 1:
2559
2649
  response = _state.sent();
2650
+ if (!(response.status !== 200)) return [
2651
+ 3,
2652
+ 5
2653
+ ];
2654
+ _state.label = 2;
2655
+ case 2:
2656
+ _state.trys.push([
2657
+ 2,
2658
+ 4,
2659
+ ,
2660
+ 5
2661
+ ]);
2662
+ return [
2663
+ 4,
2664
+ response.json()
2665
+ ];
2666
+ case 3:
2667
+ errorResponse = _state.sent();
2668
+ throw new Error(errorResponse.error);
2669
+ case 4:
2670
+ error = _state.sent();
2671
+ throw new Error("There was a problem sending your message. Please try again.");
2672
+ case 5:
2560
2673
  if (response.body == null) {
2561
2674
  throw new Error("The response body is empty.");
2562
2675
  }
@@ -2572,21 +2685,21 @@ var mutationFn = function(param) {
2572
2685
  "messages",
2573
2686
  threadContext.variables
2574
2687
  ];
2575
- _state.label = 2;
2576
- case 2:
2688
+ _state.label = 6;
2689
+ case 6:
2577
2690
  if (!true) return [
2578
2691
  3,
2579
- 4
2692
+ 8
2580
2693
  ];
2581
2694
  return [
2582
2695
  4,
2583
2696
  reader.read()
2584
2697
  ];
2585
- case 3:
2698
+ case 7:
2586
2699
  _ref = _state.sent(), done = _ref.done, value = _ref.value;
2587
2700
  if (done) return [
2588
2701
  3,
2589
- 4
2702
+ 8
2590
2703
  ];
2591
2704
  handleResponse({
2592
2705
  value: value,
@@ -2596,9 +2709,9 @@ var mutationFn = function(param) {
2596
2709
  });
2597
2710
  return [
2598
2711
  3,
2599
- 2
2712
+ 6
2600
2713
  ];
2601
- case 4:
2714
+ case 8:
2602
2715
  return [
2603
2716
  2
2604
2717
  ];
@@ -3342,34 +3455,118 @@ MessageForm.Root = Root4;
3342
3455
  MessageForm.Field = Field;
3343
3456
  MessageForm.Submit = Submit;
3344
3457
  // src/components/threads/Thread/Root/index.tsx
3345
- import { Flex as Flex21 } from "@radix-ui/themes";
3458
+ import { Flex as Flex22 } from "@radix-ui/themes";
3346
3459
  // src/components/threads/Thread/Provider/index.tsx
3347
3460
  var Provider2 = SuperinterfaceProvider;
3461
+ // src/components/toasts/ToastsProvider/index.tsx
3462
+ import { useState as useState2, useCallback as useCallback3 } from "react";
3463
+ import * as Toast2 from "@radix-ui/react-toast";
3464
+ // src/components/toasts/ToastsProvider/CustomToast.tsx
3465
+ import * as Toast from "@radix-ui/react-toast";
3466
+ import { Card as Card2, Text as Text7, Flex as Flex21 } from "@radix-ui/themes";
3467
+ import { CheckCircledIcon as CheckCircledIcon2, CrossCircledIcon } from "@radix-ui/react-icons";
3468
+ import { jsx as jsx58, jsxs as jsxs21 } from "react/jsx-runtime";
3469
+ var CustomToast = function(param) {
3470
+ var toast = param.toast;
3471
+ return /* @__PURE__ */ jsx58(Toast.Root, {
3472
+ children: /* @__PURE__ */ jsx58(Card2, {
3473
+ children: /* @__PURE__ */ jsx58(Toast.Title, {
3474
+ children: /* @__PURE__ */ jsxs21(Flex21, {
3475
+ children: [
3476
+ /* @__PURE__ */ jsx58(Flex21, {
3477
+ pr: "2",
3478
+ height: "14px",
3479
+ align: "center",
3480
+ children: toast.type === "success" ? /* @__PURE__ */ jsx58(CheckCircledIcon2, {
3481
+ color: "var(--accent-9)"
3482
+ }) : /* @__PURE__ */ jsx58(CrossCircledIcon, {
3483
+ color: "var(--red-9)"
3484
+ })
3485
+ }),
3486
+ /* @__PURE__ */ jsx58(Text7, {
3487
+ weight: "medium",
3488
+ size: "1",
3489
+ children: toast.message
3490
+ })
3491
+ ]
3492
+ })
3493
+ })
3494
+ })
3495
+ });
3496
+ };
3497
+ // src/components/toasts/ToastsProvider/index.tsx
3498
+ import { jsx as jsx59, jsxs as jsxs22 } from "react/jsx-runtime";
3499
+ var ToastsProvider = function(param) {
3500
+ var children = param.children;
3501
+ var _useState2 = _sliced_to_array(useState2([]), 2), toasts = _useState2[0], setToasts = _useState2[1];
3502
+ var addToast = useCallback3(function(toast) {
3503
+ return setToasts(function(prevToasts) {
3504
+ return _to_consumable_array(prevToasts).concat([
3505
+ toast
3506
+ ]);
3507
+ });
3508
+ }, []);
3509
+ return /* @__PURE__ */ jsx59(ToastsContext.Provider, {
3510
+ value: {
3511
+ toasts: toasts,
3512
+ addToast: addToast
3513
+ },
3514
+ children: /* @__PURE__ */ jsxs22(Toast2.Provider, {
3515
+ children: [
3516
+ children,
3517
+ Array.from(toasts).map(function(toast, index) {
3518
+ return /* @__PURE__ */ jsx59(CustomToast, {
3519
+ toast: toast
3520
+ }, index);
3521
+ }),
3522
+ /* @__PURE__ */ jsx59(Toast2.Viewport, {
3523
+ style: {
3524
+ position: "absolute",
3525
+ bottom: "var(--space-9)",
3526
+ right: 0,
3527
+ display: "flex",
3528
+ flexDirection: "column",
3529
+ padding: "var(--space-5)",
3530
+ gap: "var(--space-3)",
3531
+ width: "390px",
3532
+ maxWidth: "100vw",
3533
+ margin: 0,
3534
+ listStyle: "none",
3535
+ zIndex: 99999999999999,
3536
+ outline: "none"
3537
+ }
3538
+ })
3539
+ ]
3540
+ })
3541
+ });
3542
+ };
3348
3543
  // src/components/threads/Thread/Root/index.tsx
3349
- import { jsx as jsx58 } from "react/jsx-runtime";
3350
- var Root7 = function(_param) {
3544
+ import { jsx as jsx60 } from "react/jsx-runtime";
3545
+ var Root8 = function(_param) {
3351
3546
  var children = _param.children, rest = _object_without_properties(_param, [
3352
3547
  "children"
3353
3548
  ]);
3354
- return /* @__PURE__ */ jsx58(Provider2, _object_spread_props(_object_spread({}, rest), {
3355
- children: /* @__PURE__ */ jsx58(Flex21, {
3356
- direction: "column",
3357
- flexGrow: "1",
3358
- children: children
3359
- })
3360
- }));
3549
+ return /* @__PURE__ */ jsx60(ToastsProvider, {
3550
+ children: /* @__PURE__ */ jsx60(Provider2, _object_spread_props(_object_spread({}, rest), {
3551
+ children: /* @__PURE__ */ jsx60(Flex22, {
3552
+ direction: "column",
3553
+ flexGrow: "1",
3554
+ children: children
3555
+ })
3556
+ }))
3557
+ });
3361
3558
  };
3362
3559
  // src/components/threads/Thread/index.tsx
3363
- import { jsx as jsx59, jsxs as jsxs21 } from "react/jsx-runtime";
3560
+ import { jsx as jsx61, jsxs as jsxs23 } from "react/jsx-runtime";
3364
3561
  var Thread = function(props) {
3365
- return /* @__PURE__ */ jsxs21(Root7, _object_spread_props(_object_spread({}, props), {
3562
+ return /* @__PURE__ */ jsxs23(Root8, _object_spread_props(_object_spread({}, props), {
3366
3563
  children: [
3367
- /* @__PURE__ */ jsx59(Messages, {}),
3368
- /* @__PURE__ */ jsx59(MessageForm, {})
3564
+ /* @__PURE__ */ jsx61(Messages, {}),
3565
+ /* @__PURE__ */ jsx61(MessageForm, {})
3369
3566
  ]
3370
3567
  }));
3371
3568
  };
3372
- Thread.Root = Root7;
3569
+ Thread.Root = Root8;
3373
3570
  Thread.Messages = Messages;
3374
3571
  Thread.MessageForm = MessageForm;
3375
3572
  // src/hooks/messages/useMessageContext/index.ts
@@ -3476,7 +3673,7 @@ var useAssistant = function(param) {
3476
3673
  ]);
3477
3674
  };
3478
3675
  // src/components/threads/ThreadDialog/Provider/index.tsx
3479
- import { useState as useState2 } from "react";
3676
+ import { useState as useState3 } from "react";
3480
3677
  // src/contexts/threads/ThreadDialogContext/index.ts
3481
3678
  import { createContext as createContext11 } from "react";
3482
3679
  var ThreadDialogContext = createContext11({
@@ -3489,12 +3686,12 @@ var useThreadDialogContext = function() {
3489
3686
  return useContext13(ThreadDialogContext);
3490
3687
  };
3491
3688
  // src/components/threads/ThreadDialog/Provider/index.tsx
3492
- import { jsx as jsx60 } from "react/jsx-runtime";
3493
- var Provider3 = function(param) {
3689
+ import { jsx as jsx62 } from "react/jsx-runtime";
3690
+ var Provider4 = function(param) {
3494
3691
  var children = param.children;
3495
3692
  var threadDialogContext = useThreadDialogContext();
3496
- var _useState2 = _sliced_to_array(useState2(threadDialogContext.isOpen), 2), isOpen = _useState2[0], setIsOpen = _useState2[1];
3497
- return /* @__PURE__ */ jsx60(ThreadDialogContext.Provider, {
3693
+ var _useState3 = _sliced_to_array(useState3(threadDialogContext.isOpen), 2), isOpen = _useState3[0], setIsOpen = _useState3[1];
3694
+ return /* @__PURE__ */ jsx62(ThreadDialogContext.Provider, {
3498
3695
  value: {
3499
3696
  isOpen: isOpen,
3500
3697
  setIsOpen: setIsOpen
@@ -3502,96 +3699,12 @@ var Provider3 = function(param) {
3502
3699
  children: children
3503
3700
  });
3504
3701
  };
3505
- // src/components/toasts/ToastsProvider/index.tsx
3506
- import { useState as useState3, useCallback as useCallback3 } from "react";
3507
- import * as Toast2 from "@radix-ui/react-toast";
3508
- // src/components/toasts/ToastsProvider/CustomToast.tsx
3509
- import * as Toast from "@radix-ui/react-toast";
3510
- import { Card as Card2, Text as Text7, Flex as Flex22 } from "@radix-ui/themes";
3511
- import { CheckCircledIcon as CheckCircledIcon2, CrossCircledIcon } from "@radix-ui/react-icons";
3512
- import { jsx as jsx61, jsxs as jsxs22 } from "react/jsx-runtime";
3513
- var CustomToast = function(param) {
3514
- var toast = param.toast;
3515
- return /* @__PURE__ */ jsx61(Toast.Root, {
3516
- children: /* @__PURE__ */ jsx61(Card2, {
3517
- children: /* @__PURE__ */ jsx61(Toast.Title, {
3518
- children: /* @__PURE__ */ jsxs22(Flex22, {
3519
- children: [
3520
- /* @__PURE__ */ jsx61(Flex22, {
3521
- pr: "2",
3522
- height: "14px",
3523
- align: "center",
3524
- children: toast.type === "success" ? /* @__PURE__ */ jsx61(CheckCircledIcon2, {
3525
- color: "var(--accent-9)"
3526
- }) : /* @__PURE__ */ jsx61(CrossCircledIcon, {
3527
- color: "var(--red-9)"
3528
- })
3529
- }),
3530
- /* @__PURE__ */ jsx61(Text7, {
3531
- weight: "medium",
3532
- size: "1",
3533
- children: toast.message
3534
- })
3535
- ]
3536
- })
3537
- })
3538
- })
3539
- });
3540
- };
3541
- // src/components/toasts/ToastsProvider/index.tsx
3542
- import { jsx as jsx62, jsxs as jsxs23 } from "react/jsx-runtime";
3543
- var ToastsProvider = function(param) {
3544
- var children = param.children;
3545
- var _useState3 = _sliced_to_array(useState3([]), 2), toasts = _useState3[0], setToasts = _useState3[1];
3546
- var addToast = useCallback3(function(toast) {
3547
- return setToasts(function(prevToasts) {
3548
- return _to_consumable_array(prevToasts).concat([
3549
- toast
3550
- ]);
3551
- });
3552
- }, []);
3553
- return /* @__PURE__ */ jsx62(ToastsContext.Provider, {
3554
- value: {
3555
- toasts: toasts,
3556
- addToast: addToast
3557
- },
3558
- children: /* @__PURE__ */ jsxs23(Toast2.Provider, {
3559
- children: [
3560
- children,
3561
- Array.from(toasts).map(function(toast, index) {
3562
- return /* @__PURE__ */ jsx62(CustomToast, {
3563
- toast: toast
3564
- }, index);
3565
- }),
3566
- /* @__PURE__ */ jsx62(Toast2.Viewport, {
3567
- style: {
3568
- position: "absolute",
3569
- bottom: 0,
3570
- right: 0,
3571
- display: "flex",
3572
- flexDirection: "column",
3573
- padding: "var(--space-5)",
3574
- gap: "var(--space-3)",
3575
- width: "390px",
3576
- maxWidth: "100vw",
3577
- margin: 0,
3578
- listStyle: "none",
3579
- zIndex: 99999999999999,
3580
- outline: "none"
3581
- }
3582
- })
3583
- ]
3584
- })
3585
- });
3586
- };
3587
3702
  // src/components/threads/ThreadDialog/Root/index.tsx
3588
3703
  import { jsx as jsx63 } from "react/jsx-runtime";
3589
3704
  var Root9 = function(param) {
3590
3705
  var children = param.children;
3591
- return /* @__PURE__ */ jsx63(ToastsProvider, {
3592
- children: /* @__PURE__ */ jsx63(Provider3, {
3593
- children: children
3594
- })
3706
+ return /* @__PURE__ */ jsx63(Provider4, {
3707
+ children: children
3595
3708
  });
3596
3709
  };
3597
3710
  // src/components/threads/ThreadDialog/Trigger/index.tsx