@superinterface/react 2.22.0 → 2.22.2

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
@@ -2354,6 +2354,11 @@ var threadRunCreated = function(param) {
2354
2354
  });
2355
2355
  });
2356
2356
  };
2357
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/threadRunFailed.ts
2358
+ var threadRunFailed = function(param) {
2359
+ var value = param.value, queryClient = param.queryClient, messagesQueryKey = param.messagesQueryKey;
2360
+ throw new Error("There was a problem sending your message. Please try again.");
2361
+ };
2357
2362
  // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/threadRunStepCreated.ts
2358
2363
  var threadRunStepCreated = function(param) {
2359
2364
  var value = param.value, queryClient = param.queryClient, messagesQueryKey = param.messagesQueryKey;
@@ -2587,6 +2592,7 @@ var handlers = {
2587
2592
  "thread.message.delta": threadMessageDelta,
2588
2593
  "thread.message.completed": threadMessageCompleted,
2589
2594
  "thread.run.created": threadRunCreated,
2595
+ "thread.run.failed": threadRunFailed,
2590
2596
  "thread.run.step.created": threadRunStepCreated,
2591
2597
  "thread.run.step.delta": threadRunStepDelta,
2592
2598
  "thread.run.step.completed": threadRunStepCompleted,
@@ -2773,6 +2779,32 @@ var formOptions = {
2773
2779
  };
2774
2780
  // src/components/threads/Thread/MessageForm/Root/index.tsx
2775
2781
  import { partob as partob2 } from "radash";
2782
+ // src/lib/errors/createMessageDefaultOnError.ts
2783
+ var createMessageDefaultOnError = function(param) {
2784
+ var queryClient = param.queryClient, addToast = param.addToast, threadContext = param.threadContext;
2785
+ return function(error) {
2786
+ if (error.name === "AbortError") {
2787
+ queryClient.invalidateQueries({
2788
+ queryKey: [
2789
+ "messages",
2790
+ threadContext.variables
2791
+ ]
2792
+ });
2793
+ queryClient.invalidateQueries({
2794
+ queryKey: [
2795
+ "runs",
2796
+ threadContext.variables
2797
+ ]
2798
+ });
2799
+ return;
2800
+ }
2801
+ addToast({
2802
+ type: "error",
2803
+ message: error.message
2804
+ });
2805
+ };
2806
+ };
2807
+ // src/components/threads/Thread/MessageForm/Root/index.tsx
2776
2808
  import { jsx as jsx51 } from "react/jsx-runtime";
2777
2809
  var Root4 = function(param) {
2778
2810
  var children = param.children, onSubmitArg = param.onSubmit, isDisabledArg = param.isDisabled;
@@ -2783,27 +2815,11 @@ var Root4 = function(param) {
2783
2815
  var queryClient = useQueryClient4();
2784
2816
  var threadContext = useSuperinterfaceContext();
2785
2817
  var createMessage = useCreateMessage({
2786
- onError: function(error) {
2787
- if (error.name === "AbortError") {
2788
- queryClient.invalidateQueries({
2789
- queryKey: [
2790
- "messages",
2791
- threadContext.variables
2792
- ]
2793
- });
2794
- queryClient.invalidateQueries({
2795
- queryKey: [
2796
- "runs",
2797
- threadContext.variables
2798
- ]
2799
- });
2800
- return;
2801
- }
2802
- addToast({
2803
- type: "error",
2804
- message: error.message
2805
- });
2806
- }
2818
+ onError: createMessageDefaultOnError({
2819
+ queryClient: queryClient,
2820
+ addToast: addToast,
2821
+ threadContext: threadContext
2822
+ })
2807
2823
  }).createMessage;
2808
2824
  var isMutatingMessage = useIsMutatingMessage();
2809
2825
  var isFileLoading = useMemo8(function() {
@@ -3497,7 +3513,7 @@ var CustomToast = function(param) {
3497
3513
  // src/components/toasts/ToastsProvider/index.tsx
3498
3514
  import { jsx as jsx59, jsxs as jsxs22 } from "react/jsx-runtime";
3499
3515
  var ToastsProvider = function(param) {
3500
- var children = param.children;
3516
+ var children = param.children, _param_bottom = param.bottom, bottom = _param_bottom === void 0 ? 0 : _param_bottom;
3501
3517
  var _useState2 = _sliced_to_array(useState2([]), 2), toasts = _useState2[0], setToasts = _useState2[1];
3502
3518
  var addToast = useCallback3(function(toast) {
3503
3519
  return setToasts(function(prevToasts) {
@@ -3522,7 +3538,7 @@ var ToastsProvider = function(param) {
3522
3538
  /* @__PURE__ */ jsx59(Toast2.Viewport, {
3523
3539
  style: {
3524
3540
  position: "absolute",
3525
- bottom: "var(--space-9)",
3541
+ bottom: bottom,
3526
3542
  right: 0,
3527
3543
  display: "flex",
3528
3544
  flexDirection: "column",
@@ -3547,6 +3563,7 @@ var Root8 = function(_param) {
3547
3563
  "children"
3548
3564
  ]);
3549
3565
  return /* @__PURE__ */ jsx60(ToastsProvider, {
3566
+ bottom: "var(--space-9)",
3550
3567
  children: /* @__PURE__ */ jsx60(Provider2, _object_spread_props(_object_spread({}, rest), {
3551
3568
  children: /* @__PURE__ */ jsx60(Flex22, {
3552
3569
  direction: "column",
@@ -4409,10 +4426,23 @@ var useMessageAudio = function(param) {
4409
4426
  });
4410
4427
  };
4411
4428
  // src/components/threads/AudioThread/Root/index.tsx
4429
+ import { useQueryClient as useQueryClient6 } from "@tanstack/react-query";
4412
4430
  import { jsx as jsx69 } from "react/jsx-runtime";
4413
- var Root12 = function(param) {
4431
+ var Content6 = function(param) {
4414
4432
  var children = param.children;
4415
- var createMessageProps = useCreateMessage();
4433
+ var addToast = useToasts().addToast;
4434
+ var queryClient = useQueryClient6();
4435
+ var threadContext = useSuperinterfaceContext();
4436
+ var createMessageProps = useCreateMessage({
4437
+ onError: function(error) {
4438
+ createMessageDefaultOnError({
4439
+ queryClient: queryClient,
4440
+ addToast: addToast,
4441
+ threadContext: threadContext
4442
+ })(error);
4443
+ recorderProps.start();
4444
+ }
4445
+ });
4416
4446
  var recorderProps = useRecorder({
4417
4447
  isStopOnSilence: true,
4418
4448
  onStart: /*#__PURE__*/ _async_to_generator(function() {
@@ -4481,6 +4511,14 @@ var Root12 = function(param) {
4481
4511
  })
4482
4512
  });
4483
4513
  };
4514
+ var Root12 = function(param) {
4515
+ var children = param.children;
4516
+ return /* @__PURE__ */ jsx69(ToastsProvider, {
4517
+ children: /* @__PURE__ */ jsx69(Content6, {
4518
+ children: children
4519
+ })
4520
+ });
4521
+ };
4484
4522
  // src/components/threads/AudioThread/Visualization/index.tsx
4485
4523
  import { useContext as useContext15, useState as useState8, useCallback as useCallback6, useEffect as useEffect10 } from "react";
4486
4524
  import _9 from "lodash";
@@ -4869,11 +4907,21 @@ import { Flex as Flex32 } from "@radix-ui/themes";
4869
4907
  // src/components/suggestions/Suggestions/Item.tsx
4870
4908
  import { ArrowUpIcon as ArrowUpIcon3 } from "@radix-ui/react-icons";
4871
4909
  import { Text as Text9, Button as Button4, Spinner as Spinner2 } from "@radix-ui/themes";
4910
+ import { useQueryClient as useQueryClient7 } from "@tanstack/react-query";
4872
4911
  import { jsx as jsx79, jsxs as jsxs32 } from "react/jsx-runtime";
4873
4912
  var Item = function(param) {
4874
4913
  var suggestion = param.suggestion, isDisabled = param.isDisabled;
4875
- var _useCreateMessage = useCreateMessage(), createMessage = _useCreateMessage.createMessage, isPending = _useCreateMessage.isPending;
4876
- return /* @__PURE__ */ jsx79(Content6, {
4914
+ var addToast = useToasts().addToast;
4915
+ var queryClient = useQueryClient7();
4916
+ var threadContext = useSuperinterfaceContext();
4917
+ var _useCreateMessage = useCreateMessage({
4918
+ onError: createMessageDefaultOnError({
4919
+ queryClient: queryClient,
4920
+ addToast: addToast,
4921
+ threadContext: threadContext
4922
+ })
4923
+ }), createMessage = _useCreateMessage.createMessage, isPending = _useCreateMessage.isPending;
4924
+ return /* @__PURE__ */ jsx79(Content7, {
4877
4925
  onClick: function() {
4878
4926
  createMessage({
4879
4927
  // @ts-ignore-next-line
@@ -4885,7 +4933,7 @@ var Item = function(param) {
4885
4933
  children: suggestion
4886
4934
  });
4887
4935
  };
4888
- var Content6 = function(param) {
4936
+ var Content7 = function(param) {
4889
4937
  var onClick = param.onClick, isDisabled = param.isDisabled, isPending = param.isPending, children = param.children;
4890
4938
  return /* @__PURE__ */ jsxs32(Button4, {
4891
4939
  variant: "soft",
@@ -4913,10 +4961,10 @@ var Content6 = function(param) {
4913
4961
  ]
4914
4962
  });
4915
4963
  };
4916
- Item.Content = Content6;
4964
+ Item.Content = Content7;
4917
4965
  // src/components/suggestions/Suggestions/Content.tsx
4918
4966
  import { jsx as jsx80 } from "react/jsx-runtime";
4919
- var Content7 = function(param) {
4967
+ var Content8 = function(param) {
4920
4968
  var children = param.children;
4921
4969
  var isMutatingMessage = useIsMutatingMessage();
4922
4970
  var suggestions = useMemo14(function() {
@@ -4955,7 +5003,7 @@ var Suggestions = function(param) {
4955
5003
  ]);
4956
5004
  if (latestMessageProps.isLoading) return null;
4957
5005
  if (isDisabled) return null;
4958
- return /* @__PURE__ */ jsx81(Content7, {
5006
+ return /* @__PURE__ */ jsx81(Content8, {
4959
5007
  children: children
4960
5008
  });
4961
5009
  };