@superinterface/react 2.21.0 → 2.22.1

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
@@ -2628,7 +2628,7 @@ var mutationFn = function(param) {
2628
2628
  var superinterfaceContext = param.superinterfaceContext, queryClient = param.queryClient, threadContext = param.threadContext;
2629
2629
  return function() {
2630
2630
  var _ref = _async_to_generator(function(variables) {
2631
- var abortController, response, parser, reader, messagesQueryKey, _ref, done, value;
2631
+ var abortController, response, errorResponse, error, parser, reader, messagesQueryKey, _ref, done, value;
2632
2632
  return _ts_generator(this, function(_state) {
2633
2633
  switch(_state.label){
2634
2634
  case 0:
@@ -2647,6 +2647,29 @@ var mutationFn = function(param) {
2647
2647
  ];
2648
2648
  case 1:
2649
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:
2650
2673
  if (response.body == null) {
2651
2674
  throw new Error("The response body is empty.");
2652
2675
  }
@@ -2662,21 +2685,21 @@ var mutationFn = function(param) {
2662
2685
  "messages",
2663
2686
  threadContext.variables
2664
2687
  ];
2665
- _state.label = 2;
2666
- case 2:
2688
+ _state.label = 6;
2689
+ case 6:
2667
2690
  if (!true) return [
2668
2691
  3,
2669
- 4
2692
+ 8
2670
2693
  ];
2671
2694
  return [
2672
2695
  4,
2673
2696
  reader.read()
2674
2697
  ];
2675
- case 3:
2698
+ case 7:
2676
2699
  _ref = _state.sent(), done = _ref.done, value = _ref.value;
2677
2700
  if (done) return [
2678
2701
  3,
2679
- 4
2702
+ 8
2680
2703
  ];
2681
2704
  handleResponse({
2682
2705
  value: value,
@@ -2686,9 +2709,9 @@ var mutationFn = function(param) {
2686
2709
  });
2687
2710
  return [
2688
2711
  3,
2689
- 2
2712
+ 6
2690
2713
  ];
2691
- case 4:
2714
+ case 8:
2692
2715
  return [
2693
2716
  2
2694
2717
  ];
@@ -2750,6 +2773,32 @@ var formOptions = {
2750
2773
  };
2751
2774
  // src/components/threads/Thread/MessageForm/Root/index.tsx
2752
2775
  import { partob as partob2 } from "radash";
2776
+ // src/lib/errors/createMessageDefaultOnError.ts
2777
+ var createMessageDefaultOnError = function(param) {
2778
+ var queryClient = param.queryClient, addToast = param.addToast, threadContext = param.threadContext;
2779
+ return function(error) {
2780
+ if (error.name === "AbortError") {
2781
+ queryClient.invalidateQueries({
2782
+ queryKey: [
2783
+ "messages",
2784
+ threadContext.variables
2785
+ ]
2786
+ });
2787
+ queryClient.invalidateQueries({
2788
+ queryKey: [
2789
+ "runs",
2790
+ threadContext.variables
2791
+ ]
2792
+ });
2793
+ return;
2794
+ }
2795
+ addToast({
2796
+ type: "error",
2797
+ message: error.message
2798
+ });
2799
+ };
2800
+ };
2801
+ // src/components/threads/Thread/MessageForm/Root/index.tsx
2753
2802
  import { jsx as jsx51 } from "react/jsx-runtime";
2754
2803
  var Root4 = function(param) {
2755
2804
  var children = param.children, onSubmitArg = param.onSubmit, isDisabledArg = param.isDisabled;
@@ -2760,27 +2809,11 @@ var Root4 = function(param) {
2760
2809
  var queryClient = useQueryClient4();
2761
2810
  var threadContext = useSuperinterfaceContext();
2762
2811
  var createMessage = useCreateMessage({
2763
- onError: function(error) {
2764
- if (error.name === "AbortError") {
2765
- queryClient.invalidateQueries({
2766
- queryKey: [
2767
- "messages",
2768
- threadContext.variables
2769
- ]
2770
- });
2771
- queryClient.invalidateQueries({
2772
- queryKey: [
2773
- "runs",
2774
- threadContext.variables
2775
- ]
2776
- });
2777
- return;
2778
- }
2779
- addToast({
2780
- type: "error",
2781
- message: error.message
2782
- });
2783
- }
2812
+ onError: createMessageDefaultOnError({
2813
+ queryClient: queryClient,
2814
+ addToast: addToast,
2815
+ threadContext: threadContext
2816
+ })
2784
2817
  }).createMessage;
2785
2818
  var isMutatingMessage = useIsMutatingMessage();
2786
2819
  var isFileLoading = useMemo8(function() {
@@ -3432,34 +3465,119 @@ MessageForm.Root = Root4;
3432
3465
  MessageForm.Field = Field;
3433
3466
  MessageForm.Submit = Submit;
3434
3467
  // src/components/threads/Thread/Root/index.tsx
3435
- import { Flex as Flex21 } from "@radix-ui/themes";
3468
+ import { Flex as Flex22 } from "@radix-ui/themes";
3436
3469
  // src/components/threads/Thread/Provider/index.tsx
3437
3470
  var Provider2 = SuperinterfaceProvider;
3471
+ // src/components/toasts/ToastsProvider/index.tsx
3472
+ import { useState as useState2, useCallback as useCallback3 } from "react";
3473
+ import * as Toast2 from "@radix-ui/react-toast";
3474
+ // src/components/toasts/ToastsProvider/CustomToast.tsx
3475
+ import * as Toast from "@radix-ui/react-toast";
3476
+ import { Card as Card2, Text as Text7, Flex as Flex21 } from "@radix-ui/themes";
3477
+ import { CheckCircledIcon as CheckCircledIcon2, CrossCircledIcon } from "@radix-ui/react-icons";
3478
+ import { jsx as jsx58, jsxs as jsxs21 } from "react/jsx-runtime";
3479
+ var CustomToast = function(param) {
3480
+ var toast = param.toast;
3481
+ return /* @__PURE__ */ jsx58(Toast.Root, {
3482
+ children: /* @__PURE__ */ jsx58(Card2, {
3483
+ children: /* @__PURE__ */ jsx58(Toast.Title, {
3484
+ children: /* @__PURE__ */ jsxs21(Flex21, {
3485
+ children: [
3486
+ /* @__PURE__ */ jsx58(Flex21, {
3487
+ pr: "2",
3488
+ height: "14px",
3489
+ align: "center",
3490
+ children: toast.type === "success" ? /* @__PURE__ */ jsx58(CheckCircledIcon2, {
3491
+ color: "var(--accent-9)"
3492
+ }) : /* @__PURE__ */ jsx58(CrossCircledIcon, {
3493
+ color: "var(--red-9)"
3494
+ })
3495
+ }),
3496
+ /* @__PURE__ */ jsx58(Text7, {
3497
+ weight: "medium",
3498
+ size: "1",
3499
+ children: toast.message
3500
+ })
3501
+ ]
3502
+ })
3503
+ })
3504
+ })
3505
+ });
3506
+ };
3507
+ // src/components/toasts/ToastsProvider/index.tsx
3508
+ import { jsx as jsx59, jsxs as jsxs22 } from "react/jsx-runtime";
3509
+ var ToastsProvider = function(param) {
3510
+ var children = param.children, _param_bottom = param.bottom, bottom = _param_bottom === void 0 ? 0 : _param_bottom;
3511
+ var _useState2 = _sliced_to_array(useState2([]), 2), toasts = _useState2[0], setToasts = _useState2[1];
3512
+ var addToast = useCallback3(function(toast) {
3513
+ return setToasts(function(prevToasts) {
3514
+ return _to_consumable_array(prevToasts).concat([
3515
+ toast
3516
+ ]);
3517
+ });
3518
+ }, []);
3519
+ return /* @__PURE__ */ jsx59(ToastsContext.Provider, {
3520
+ value: {
3521
+ toasts: toasts,
3522
+ addToast: addToast
3523
+ },
3524
+ children: /* @__PURE__ */ jsxs22(Toast2.Provider, {
3525
+ children: [
3526
+ children,
3527
+ Array.from(toasts).map(function(toast, index) {
3528
+ return /* @__PURE__ */ jsx59(CustomToast, {
3529
+ toast: toast
3530
+ }, index);
3531
+ }),
3532
+ /* @__PURE__ */ jsx59(Toast2.Viewport, {
3533
+ style: {
3534
+ position: "absolute",
3535
+ bottom: bottom,
3536
+ right: 0,
3537
+ display: "flex",
3538
+ flexDirection: "column",
3539
+ padding: "var(--space-5)",
3540
+ gap: "var(--space-3)",
3541
+ width: "390px",
3542
+ maxWidth: "100vw",
3543
+ margin: 0,
3544
+ listStyle: "none",
3545
+ zIndex: 99999999999999,
3546
+ outline: "none"
3547
+ }
3548
+ })
3549
+ ]
3550
+ })
3551
+ });
3552
+ };
3438
3553
  // src/components/threads/Thread/Root/index.tsx
3439
- import { jsx as jsx58 } from "react/jsx-runtime";
3440
- var Root7 = function(_param) {
3554
+ import { jsx as jsx60 } from "react/jsx-runtime";
3555
+ var Root8 = function(_param) {
3441
3556
  var children = _param.children, rest = _object_without_properties(_param, [
3442
3557
  "children"
3443
3558
  ]);
3444
- return /* @__PURE__ */ jsx58(Provider2, _object_spread_props(_object_spread({}, rest), {
3445
- children: /* @__PURE__ */ jsx58(Flex21, {
3446
- direction: "column",
3447
- flexGrow: "1",
3448
- children: children
3449
- })
3450
- }));
3559
+ return /* @__PURE__ */ jsx60(ToastsProvider, {
3560
+ bottom: "var(--space-9)",
3561
+ children: /* @__PURE__ */ jsx60(Provider2, _object_spread_props(_object_spread({}, rest), {
3562
+ children: /* @__PURE__ */ jsx60(Flex22, {
3563
+ direction: "column",
3564
+ flexGrow: "1",
3565
+ children: children
3566
+ })
3567
+ }))
3568
+ });
3451
3569
  };
3452
3570
  // src/components/threads/Thread/index.tsx
3453
- import { jsx as jsx59, jsxs as jsxs21 } from "react/jsx-runtime";
3571
+ import { jsx as jsx61, jsxs as jsxs23 } from "react/jsx-runtime";
3454
3572
  var Thread = function(props) {
3455
- return /* @__PURE__ */ jsxs21(Root7, _object_spread_props(_object_spread({}, props), {
3573
+ return /* @__PURE__ */ jsxs23(Root8, _object_spread_props(_object_spread({}, props), {
3456
3574
  children: [
3457
- /* @__PURE__ */ jsx59(Messages, {}),
3458
- /* @__PURE__ */ jsx59(MessageForm, {})
3575
+ /* @__PURE__ */ jsx61(Messages, {}),
3576
+ /* @__PURE__ */ jsx61(MessageForm, {})
3459
3577
  ]
3460
3578
  }));
3461
3579
  };
3462
- Thread.Root = Root7;
3580
+ Thread.Root = Root8;
3463
3581
  Thread.Messages = Messages;
3464
3582
  Thread.MessageForm = MessageForm;
3465
3583
  // src/hooks/messages/useMessageContext/index.ts
@@ -3566,7 +3684,7 @@ var useAssistant = function(param) {
3566
3684
  ]);
3567
3685
  };
3568
3686
  // src/components/threads/ThreadDialog/Provider/index.tsx
3569
- import { useState as useState2 } from "react";
3687
+ import { useState as useState3 } from "react";
3570
3688
  // src/contexts/threads/ThreadDialogContext/index.ts
3571
3689
  import { createContext as createContext11 } from "react";
3572
3690
  var ThreadDialogContext = createContext11({
@@ -3579,12 +3697,12 @@ var useThreadDialogContext = function() {
3579
3697
  return useContext13(ThreadDialogContext);
3580
3698
  };
3581
3699
  // src/components/threads/ThreadDialog/Provider/index.tsx
3582
- import { jsx as jsx60 } from "react/jsx-runtime";
3583
- var Provider3 = function(param) {
3700
+ import { jsx as jsx62 } from "react/jsx-runtime";
3701
+ var Provider4 = function(param) {
3584
3702
  var children = param.children;
3585
3703
  var threadDialogContext = useThreadDialogContext();
3586
- var _useState2 = _sliced_to_array(useState2(threadDialogContext.isOpen), 2), isOpen = _useState2[0], setIsOpen = _useState2[1];
3587
- return /* @__PURE__ */ jsx60(ThreadDialogContext.Provider, {
3704
+ var _useState3 = _sliced_to_array(useState3(threadDialogContext.isOpen), 2), isOpen = _useState3[0], setIsOpen = _useState3[1];
3705
+ return /* @__PURE__ */ jsx62(ThreadDialogContext.Provider, {
3588
3706
  value: {
3589
3707
  isOpen: isOpen,
3590
3708
  setIsOpen: setIsOpen
@@ -3592,96 +3710,12 @@ var Provider3 = function(param) {
3592
3710
  children: children
3593
3711
  });
3594
3712
  };
3595
- // src/components/toasts/ToastsProvider/index.tsx
3596
- import { useState as useState3, useCallback as useCallback3 } from "react";
3597
- import * as Toast2 from "@radix-ui/react-toast";
3598
- // src/components/toasts/ToastsProvider/CustomToast.tsx
3599
- import * as Toast from "@radix-ui/react-toast";
3600
- import { Card as Card2, Text as Text7, Flex as Flex22 } from "@radix-ui/themes";
3601
- import { CheckCircledIcon as CheckCircledIcon2, CrossCircledIcon } from "@radix-ui/react-icons";
3602
- import { jsx as jsx61, jsxs as jsxs22 } from "react/jsx-runtime";
3603
- var CustomToast = function(param) {
3604
- var toast = param.toast;
3605
- return /* @__PURE__ */ jsx61(Toast.Root, {
3606
- children: /* @__PURE__ */ jsx61(Card2, {
3607
- children: /* @__PURE__ */ jsx61(Toast.Title, {
3608
- children: /* @__PURE__ */ jsxs22(Flex22, {
3609
- children: [
3610
- /* @__PURE__ */ jsx61(Flex22, {
3611
- pr: "2",
3612
- height: "14px",
3613
- align: "center",
3614
- children: toast.type === "success" ? /* @__PURE__ */ jsx61(CheckCircledIcon2, {
3615
- color: "var(--accent-9)"
3616
- }) : /* @__PURE__ */ jsx61(CrossCircledIcon, {
3617
- color: "var(--red-9)"
3618
- })
3619
- }),
3620
- /* @__PURE__ */ jsx61(Text7, {
3621
- weight: "medium",
3622
- size: "1",
3623
- children: toast.message
3624
- })
3625
- ]
3626
- })
3627
- })
3628
- })
3629
- });
3630
- };
3631
- // src/components/toasts/ToastsProvider/index.tsx
3632
- import { jsx as jsx62, jsxs as jsxs23 } from "react/jsx-runtime";
3633
- var ToastsProvider = function(param) {
3634
- var children = param.children;
3635
- var _useState3 = _sliced_to_array(useState3([]), 2), toasts = _useState3[0], setToasts = _useState3[1];
3636
- var addToast = useCallback3(function(toast) {
3637
- return setToasts(function(prevToasts) {
3638
- return _to_consumable_array(prevToasts).concat([
3639
- toast
3640
- ]);
3641
- });
3642
- }, []);
3643
- return /* @__PURE__ */ jsx62(ToastsContext.Provider, {
3644
- value: {
3645
- toasts: toasts,
3646
- addToast: addToast
3647
- },
3648
- children: /* @__PURE__ */ jsxs23(Toast2.Provider, {
3649
- children: [
3650
- children,
3651
- Array.from(toasts).map(function(toast, index) {
3652
- return /* @__PURE__ */ jsx62(CustomToast, {
3653
- toast: toast
3654
- }, index);
3655
- }),
3656
- /* @__PURE__ */ jsx62(Toast2.Viewport, {
3657
- style: {
3658
- position: "absolute",
3659
- bottom: 0,
3660
- right: 0,
3661
- display: "flex",
3662
- flexDirection: "column",
3663
- padding: "var(--space-5)",
3664
- gap: "var(--space-3)",
3665
- width: "390px",
3666
- maxWidth: "100vw",
3667
- margin: 0,
3668
- listStyle: "none",
3669
- zIndex: 99999999999999,
3670
- outline: "none"
3671
- }
3672
- })
3673
- ]
3674
- })
3675
- });
3676
- };
3677
3713
  // src/components/threads/ThreadDialog/Root/index.tsx
3678
3714
  import { jsx as jsx63 } from "react/jsx-runtime";
3679
3715
  var Root9 = function(param) {
3680
3716
  var children = param.children;
3681
- return /* @__PURE__ */ jsx63(ToastsProvider, {
3682
- children: /* @__PURE__ */ jsx63(Provider3, {
3683
- children: children
3684
- })
3717
+ return /* @__PURE__ */ jsx63(Provider4, {
3718
+ children: children
3685
3719
  });
3686
3720
  };
3687
3721
  // src/components/threads/ThreadDialog/Trigger/index.tsx
@@ -4386,10 +4420,23 @@ var useMessageAudio = function(param) {
4386
4420
  });
4387
4421
  };
4388
4422
  // src/components/threads/AudioThread/Root/index.tsx
4423
+ import { useQueryClient as useQueryClient6 } from "@tanstack/react-query";
4389
4424
  import { jsx as jsx69 } from "react/jsx-runtime";
4390
- var Root12 = function(param) {
4425
+ var Content6 = function(param) {
4391
4426
  var children = param.children;
4392
- var createMessageProps = useCreateMessage();
4427
+ var addToast = useToasts().addToast;
4428
+ var queryClient = useQueryClient6();
4429
+ var threadContext = useSuperinterfaceContext();
4430
+ var createMessageProps = useCreateMessage({
4431
+ onError: function(error) {
4432
+ createMessageDefaultOnError({
4433
+ queryClient: queryClient,
4434
+ addToast: addToast,
4435
+ threadContext: threadContext
4436
+ })(error);
4437
+ recorderProps.start();
4438
+ }
4439
+ });
4393
4440
  var recorderProps = useRecorder({
4394
4441
  isStopOnSilence: true,
4395
4442
  onStart: /*#__PURE__*/ _async_to_generator(function() {
@@ -4458,6 +4505,14 @@ var Root12 = function(param) {
4458
4505
  })
4459
4506
  });
4460
4507
  };
4508
+ var Root12 = function(param) {
4509
+ var children = param.children;
4510
+ return /* @__PURE__ */ jsx69(ToastsProvider, {
4511
+ children: /* @__PURE__ */ jsx69(Content6, {
4512
+ children: children
4513
+ })
4514
+ });
4515
+ };
4461
4516
  // src/components/threads/AudioThread/Visualization/index.tsx
4462
4517
  import { useContext as useContext15, useState as useState8, useCallback as useCallback6, useEffect as useEffect10 } from "react";
4463
4518
  import _9 from "lodash";
@@ -4846,11 +4901,21 @@ import { Flex as Flex32 } from "@radix-ui/themes";
4846
4901
  // src/components/suggestions/Suggestions/Item.tsx
4847
4902
  import { ArrowUpIcon as ArrowUpIcon3 } from "@radix-ui/react-icons";
4848
4903
  import { Text as Text9, Button as Button4, Spinner as Spinner2 } from "@radix-ui/themes";
4904
+ import { useQueryClient as useQueryClient7 } from "@tanstack/react-query";
4849
4905
  import { jsx as jsx79, jsxs as jsxs32 } from "react/jsx-runtime";
4850
4906
  var Item = function(param) {
4851
4907
  var suggestion = param.suggestion, isDisabled = param.isDisabled;
4852
- var _useCreateMessage = useCreateMessage(), createMessage = _useCreateMessage.createMessage, isPending = _useCreateMessage.isPending;
4853
- return /* @__PURE__ */ jsx79(Content6, {
4908
+ var addToast = useToasts().addToast;
4909
+ var queryClient = useQueryClient7();
4910
+ var threadContext = useSuperinterfaceContext();
4911
+ var _useCreateMessage = useCreateMessage({
4912
+ onError: createMessageDefaultOnError({
4913
+ queryClient: queryClient,
4914
+ addToast: addToast,
4915
+ threadContext: threadContext
4916
+ })
4917
+ }), createMessage = _useCreateMessage.createMessage, isPending = _useCreateMessage.isPending;
4918
+ return /* @__PURE__ */ jsx79(Content7, {
4854
4919
  onClick: function() {
4855
4920
  createMessage({
4856
4921
  // @ts-ignore-next-line
@@ -4862,7 +4927,7 @@ var Item = function(param) {
4862
4927
  children: suggestion
4863
4928
  });
4864
4929
  };
4865
- var Content6 = function(param) {
4930
+ var Content7 = function(param) {
4866
4931
  var onClick = param.onClick, isDisabled = param.isDisabled, isPending = param.isPending, children = param.children;
4867
4932
  return /* @__PURE__ */ jsxs32(Button4, {
4868
4933
  variant: "soft",
@@ -4890,10 +4955,10 @@ var Content6 = function(param) {
4890
4955
  ]
4891
4956
  });
4892
4957
  };
4893
- Item.Content = Content6;
4958
+ Item.Content = Content7;
4894
4959
  // src/components/suggestions/Suggestions/Content.tsx
4895
4960
  import { jsx as jsx80 } from "react/jsx-runtime";
4896
- var Content7 = function(param) {
4961
+ var Content8 = function(param) {
4897
4962
  var children = param.children;
4898
4963
  var isMutatingMessage = useIsMutatingMessage();
4899
4964
  var suggestions = useMemo14(function() {
@@ -4932,7 +4997,7 @@ var Suggestions = function(param) {
4932
4997
  ]);
4933
4998
  if (latestMessageProps.isLoading) return null;
4934
4999
  if (isDisabled) return null;
4935
- return /* @__PURE__ */ jsx81(Content7, {
5000
+ return /* @__PURE__ */ jsx81(Content8, {
4936
5001
  children: children
4937
5002
  });
4938
5003
  };