@assistant-ui/react 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -55,8 +55,18 @@ declare const ThreadScrollToBottom: react.ForwardRefExoticComponent<Pick<Omit<re
55
55
  asChild?: boolean;
56
56
  }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
57
57
 
58
+ declare const ThreadSuggestion: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
59
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
60
+ } & {
61
+ asChild?: boolean;
62
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & {
63
+ prompt: string;
64
+ method: "replace";
65
+ autoSend?: boolean;
66
+ } & react.RefAttributes<HTMLButtonElement>>;
67
+
58
68
  declare namespace index$4 {
59
- export { ThreadEmpty as Empty, ThreadIf as If, ThreadMessages as Messages, ThreadRoot as Root, ThreadScrollToBottom as ScrollToBottom, ThreadViewport as Viewport };
69
+ export { ThreadEmpty as Empty, ThreadIf as If, ThreadMessages as Messages, ThreadRoot as Root, ThreadScrollToBottom as ScrollToBottom, ThreadSuggestion as Suggestion, ThreadViewport as Viewport };
60
70
  }
61
71
 
62
72
  declare const ComposerRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
package/dist/index.d.ts CHANGED
@@ -55,8 +55,18 @@ declare const ThreadScrollToBottom: react.ForwardRefExoticComponent<Pick<Omit<re
55
55
  asChild?: boolean;
56
56
  }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & react.RefAttributes<HTMLButtonElement>>;
57
57
 
58
+ declare const ThreadSuggestion: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
59
+ ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
60
+ } & {
61
+ asChild?: boolean;
62
+ }, "key" | "asChild" | keyof react.ButtonHTMLAttributes<HTMLButtonElement>> & {
63
+ prompt: string;
64
+ method: "replace";
65
+ autoSend?: boolean;
66
+ } & react.RefAttributes<HTMLButtonElement>>;
67
+
58
68
  declare namespace index$4 {
59
- export { ThreadEmpty as Empty, ThreadIf as If, ThreadMessages as Messages, ThreadRoot as Root, ThreadScrollToBottom as ScrollToBottom, ThreadViewport as Viewport };
69
+ export { ThreadEmpty as Empty, ThreadIf as If, ThreadMessages as Messages, ThreadRoot as Root, ThreadScrollToBottom as ScrollToBottom, ThreadSuggestion as Suggestion, ThreadViewport as Viewport };
60
70
  }
61
71
 
62
72
  declare const ComposerRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ __export(thread_exports, {
54
54
  Messages: () => ThreadMessages,
55
55
  Root: () => ThreadRoot,
56
56
  ScrollToBottom: () => ThreadScrollToBottom,
57
+ Suggestion: () => ThreadSuggestion,
57
58
  Viewport: () => ThreadViewport
58
59
  });
59
60
 
@@ -528,6 +529,33 @@ var ThreadScrollToBottom = (0, import_react10.forwardRef)(({ onClick, ...rest },
528
529
  );
529
530
  });
530
531
 
532
+ // src/primitives/thread/ThreadSuggestion.tsx
533
+ var import_primitive4 = require("@radix-ui/primitive");
534
+ var import_react_primitive5 = require("@radix-ui/react-primitive");
535
+ var import_react11 = require("react");
536
+ var import_jsx_runtime9 = require("react/jsx-runtime");
537
+ var ThreadSuggestion = (0, import_react11.forwardRef)(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {
538
+ const { useThread, useComposer } = useAssistantContext();
539
+ const isDisabled = useThread((t) => t.isRunning);
540
+ const handleApplySuggestion = () => {
541
+ const thread = useThread.getState();
542
+ const composer = useComposer.getState();
543
+ composer.setValue(prompt);
544
+ if (send && !thread.isRunning) {
545
+ composer.send();
546
+ }
547
+ };
548
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
549
+ import_react_primitive5.Primitive.button,
550
+ {
551
+ ...rest,
552
+ disabled: isDisabled,
553
+ ref,
554
+ onClick: (0, import_primitive4.composeEventHandlers)(onClick, handleApplySuggestion)
555
+ }
556
+ );
557
+ });
558
+
531
559
  // src/primitives/composer/index.ts
532
560
  var composer_exports = {};
533
561
  __export(composer_exports, {
@@ -539,16 +567,16 @@ __export(composer_exports, {
539
567
  });
540
568
 
541
569
  // src/primitives/composer/ComposerRoot.tsx
542
- var import_primitive4 = require("@radix-ui/primitive");
570
+ var import_primitive5 = require("@radix-ui/primitive");
543
571
  var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
544
- var import_react_primitive5 = require("@radix-ui/react-primitive");
545
- var import_react11 = require("react");
546
- var import_jsx_runtime9 = require("react/jsx-runtime");
547
- var ComposerRoot = (0, import_react11.forwardRef)(
572
+ var import_react_primitive6 = require("@radix-ui/react-primitive");
573
+ var import_react12 = require("react");
574
+ var import_jsx_runtime10 = require("react/jsx-runtime");
575
+ var ComposerRoot = (0, import_react12.forwardRef)(
548
576
  ({ onSubmit, ...rest }, forwardedRef) => {
549
577
  const { useViewport } = useAssistantContext();
550
578
  const { useComposer } = useComposerContext();
551
- const formRef = (0, import_react11.useRef)(null);
579
+ const formRef = (0, import_react12.useRef)(null);
552
580
  const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, formRef);
553
581
  const handleSubmit = (e) => {
554
582
  const composerState = useComposer.getState();
@@ -558,25 +586,25 @@ var ComposerRoot = (0, import_react11.forwardRef)(
558
586
  composerState.send();
559
587
  useViewport.getState().scrollToBottom();
560
588
  };
561
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
562
- import_react_primitive5.Primitive.form,
589
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
590
+ import_react_primitive6.Primitive.form,
563
591
  {
564
592
  ...rest,
565
593
  ref,
566
- onSubmit: (0, import_primitive4.composeEventHandlers)(onSubmit, handleSubmit)
594
+ onSubmit: (0, import_primitive5.composeEventHandlers)(onSubmit, handleSubmit)
567
595
  }
568
596
  );
569
597
  }
570
598
  );
571
599
 
572
600
  // src/primitives/composer/ComposerInput.tsx
573
- var import_primitive5 = require("@radix-ui/primitive");
601
+ var import_primitive6 = require("@radix-ui/primitive");
574
602
  var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
575
603
  var import_react_slot = require("@radix-ui/react-slot");
576
- var import_react12 = require("react");
604
+ var import_react13 = require("react");
577
605
  var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
578
- var import_jsx_runtime10 = require("react/jsx-runtime");
579
- var ComposerInput = (0, import_react12.forwardRef)(
606
+ var import_jsx_runtime11 = require("react/jsx-runtime");
607
+ var ComposerInput = (0, import_react13.forwardRef)(
580
608
  ({ autoFocus, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
581
609
  const { useThread, useViewport } = useAssistantContext();
582
610
  const { useComposer, type } = useComposerContext();
@@ -603,10 +631,10 @@ var ComposerInput = (0, import_react12.forwardRef)(
603
631
  }
604
632
  }
605
633
  };
606
- const textareaRef = (0, import_react12.useRef)(null);
634
+ const textareaRef = (0, import_react13.useRef)(null);
607
635
  const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, textareaRef);
608
636
  const autoFocusEnabled = autoFocus !== false && !disabled;
609
- const focus = (0, import_react12.useCallback)(() => {
637
+ const focus = (0, import_react13.useCallback)(() => {
610
638
  const textarea = textareaRef.current;
611
639
  if (!textarea || !autoFocusEnabled)
612
640
  return;
@@ -616,41 +644,41 @@ var ComposerInput = (0, import_react12.forwardRef)(
616
644
  textareaRef.current.value.length
617
645
  );
618
646
  }, [autoFocusEnabled]);
619
- (0, import_react12.useEffect)(() => focus(), [focus]);
647
+ (0, import_react13.useEffect)(() => focus(), [focus]);
620
648
  useOnScrollToBottom(() => {
621
649
  if (type === "assistant") {
622
650
  focus();
623
651
  }
624
652
  });
625
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
653
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
626
654
  Component,
627
655
  {
628
656
  value,
629
657
  ...rest,
630
658
  ref,
631
659
  disabled,
632
- onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
660
+ onChange: (0, import_primitive6.composeEventHandlers)(onChange, (e) => {
633
661
  const composerState = useComposer.getState();
634
662
  if (!composerState.isEditing)
635
663
  return;
636
664
  return composerState.setValue(e.target.value);
637
665
  }),
638
- onKeyDown: (0, import_primitive5.composeEventHandlers)(onKeyDown, handleKeyPress)
666
+ onKeyDown: (0, import_primitive6.composeEventHandlers)(onKeyDown, handleKeyPress)
639
667
  }
640
668
  );
641
669
  }
642
670
  );
643
671
 
644
672
  // src/primitives/composer/ComposerSend.tsx
645
- var import_react_primitive6 = require("@radix-ui/react-primitive");
646
- var import_react13 = require("react");
647
- var import_jsx_runtime11 = require("react/jsx-runtime");
648
- var ComposerSend = (0, import_react13.forwardRef)(
673
+ var import_react_primitive7 = require("@radix-ui/react-primitive");
674
+ var import_react14 = require("react");
675
+ var import_jsx_runtime12 = require("react/jsx-runtime");
676
+ var ComposerSend = (0, import_react14.forwardRef)(
649
677
  ({ disabled, ...rest }, ref) => {
650
678
  const { useComposer } = useComposerContext();
651
679
  const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
652
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
653
- import_react_primitive6.Primitive.button,
680
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
681
+ import_react_primitive7.Primitive.button,
654
682
  {
655
683
  type: "submit",
656
684
  ...rest,
@@ -662,22 +690,22 @@ var ComposerSend = (0, import_react13.forwardRef)(
662
690
  );
663
691
 
664
692
  // src/primitives/composer/ComposerCancel.tsx
665
- var import_primitive6 = require("@radix-ui/primitive");
666
- var import_react_primitive7 = require("@radix-ui/react-primitive");
667
- var import_react14 = require("react");
668
- var import_jsx_runtime12 = require("react/jsx-runtime");
669
- var ComposerCancel = (0, import_react14.forwardRef)(({ onClick, ...rest }, ref) => {
693
+ var import_primitive7 = require("@radix-ui/primitive");
694
+ var import_react_primitive8 = require("@radix-ui/react-primitive");
695
+ var import_react15 = require("react");
696
+ var import_jsx_runtime13 = require("react/jsx-runtime");
697
+ var ComposerCancel = (0, import_react15.forwardRef)(({ onClick, ...rest }, ref) => {
670
698
  const { useComposer } = useComposerContext();
671
699
  const handleCancel = () => {
672
700
  useComposer.getState().cancel();
673
701
  };
674
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
675
- import_react_primitive7.Primitive.button,
702
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
703
+ import_react_primitive8.Primitive.button,
676
704
  {
677
705
  type: "button",
678
706
  ...rest,
679
707
  ref,
680
- onClick: (0, import_primitive6.composeEventHandlers)(onClick, handleCancel)
708
+ onClick: (0, import_primitive7.composeEventHandlers)(onClick, handleCancel)
681
709
  }
682
710
  );
683
711
  });
@@ -693,10 +721,10 @@ __export(branchPicker_exports, {
693
721
  });
694
722
 
695
723
  // src/utils/context/combined/useCombinedStore.ts
696
- var import_react16 = require("react");
724
+ var import_react17 = require("react");
697
725
 
698
726
  // src/utils/context/combined/createCombinedStore.ts
699
- var import_react15 = require("react");
727
+ var import_react16 = require("react");
700
728
  var createCombinedStore = (stores) => {
701
729
  const subscribe = (callback) => {
702
730
  const unsubscribes = stores.map((store) => store.subscribe(callback));
@@ -708,13 +736,13 @@ var createCombinedStore = (stores) => {
708
736
  };
709
737
  return (selector) => {
710
738
  const getSnapshot = () => selector(...stores.map((store) => store.getState()));
711
- return (0, import_react15.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
739
+ return (0, import_react16.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
712
740
  };
713
741
  };
714
742
 
715
743
  // src/utils/context/combined/useCombinedStore.ts
716
744
  var useCombinedStore = (stores, selector) => {
717
- const useCombined = (0, import_react16.useMemo)(() => createCombinedStore(stores), stores);
745
+ const useCombined = (0, import_react17.useMemo)(() => createCombinedStore(stores), stores);
718
746
  return useCombined(selector);
719
747
  };
720
748
 
@@ -735,22 +763,22 @@ var useGoToNextBranch = () => {
735
763
  };
736
764
 
737
765
  // src/utils/createActionButton.tsx
738
- var import_primitive7 = require("@radix-ui/primitive");
739
- var import_react_primitive8 = require("@radix-ui/react-primitive");
740
- var import_react17 = require("react");
741
- var import_jsx_runtime13 = require("react/jsx-runtime");
766
+ var import_primitive8 = require("@radix-ui/primitive");
767
+ var import_react_primitive9 = require("@radix-ui/react-primitive");
768
+ var import_react18 = require("react");
769
+ var import_jsx_runtime14 = require("react/jsx-runtime");
742
770
  var createActionButton = (useActionButton) => {
743
- return (0, import_react17.forwardRef)(
771
+ return (0, import_react18.forwardRef)(
744
772
  (props, forwardedRef) => {
745
773
  const onClick = useActionButton(props);
746
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
747
- import_react_primitive8.Primitive.button,
774
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
775
+ import_react_primitive9.Primitive.button,
748
776
  {
749
777
  type: "button",
750
778
  disabled: !onClick,
751
779
  ...props,
752
780
  ref: forwardedRef,
753
- onClick: (0, import_primitive7.composeEventHandlers)(props.onClick, onClick ?? void 0)
781
+ onClick: (0, import_primitive8.composeEventHandlers)(props.onClick, onClick ?? void 0)
754
782
  }
755
783
  );
756
784
  }
@@ -783,27 +811,27 @@ var useGoToPreviousBranch = () => {
783
811
  var BranchPickerPrevious = createActionButton(useGoToPreviousBranch);
784
812
 
785
813
  // src/primitives/branchPicker/BranchPickerCount.tsx
786
- var import_jsx_runtime14 = require("react/jsx-runtime");
814
+ var import_jsx_runtime15 = require("react/jsx-runtime");
787
815
  var BranchPickerCount = () => {
788
816
  const { useMessage } = useMessageContext();
789
817
  const branchCount = useMessage((s) => s.branches.length);
790
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: branchCount });
818
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: branchCount });
791
819
  };
792
820
 
793
821
  // src/primitives/branchPicker/BranchPickerNumber.tsx
794
- var import_jsx_runtime15 = require("react/jsx-runtime");
822
+ var import_jsx_runtime16 = require("react/jsx-runtime");
795
823
  var BranchPickerNumber = () => {
796
824
  const { useMessage } = useMessageContext();
797
825
  const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
798
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: branchIdx + 1 });
826
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: branchIdx + 1 });
799
827
  };
800
828
 
801
829
  // src/primitives/branchPicker/BranchPickerRoot.tsx
802
- var import_react_primitive9 = require("@radix-ui/react-primitive");
803
- var import_react18 = require("react");
804
- var import_jsx_runtime16 = require("react/jsx-runtime");
805
- var BranchPickerRoot = (0, import_react18.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
806
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive9.Primitive.div, { ...rest, ref }) });
830
+ var import_react_primitive10 = require("@radix-ui/react-primitive");
831
+ var import_react19 = require("react");
832
+ var import_jsx_runtime17 = require("react/jsx-runtime");
833
+ var BranchPickerRoot = (0, import_react19.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
834
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_primitive10.Primitive.div, { ...rest, ref }) });
807
835
  });
808
836
 
809
837
  // src/primitives/actionBar/index.ts
@@ -816,10 +844,10 @@ __export(actionBar_exports, {
816
844
  });
817
845
 
818
846
  // src/primitives/actionBar/ActionBarRoot.tsx
819
- var import_react_primitive10 = require("@radix-ui/react-primitive");
820
- var import_react19 = require("react");
821
- var import_jsx_runtime17 = require("react/jsx-runtime");
822
- var ActionBarRoot = (0, import_react19.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
847
+ var import_react_primitive11 = require("@radix-ui/react-primitive");
848
+ var import_react20 = require("react");
849
+ var import_jsx_runtime18 = require("react/jsx-runtime");
850
+ var ActionBarRoot = (0, import_react20.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
823
851
  const { useThread } = useAssistantContext();
824
852
  const { useMessage } = useMessageContext();
825
853
  const hideAndfloatStatus = useCombinedStore(
@@ -839,8 +867,8 @@ var ActionBarRoot = (0, import_react19.forwardRef)(({ hideWhenRunning, autohide,
839
867
  );
840
868
  if (hideAndfloatStatus === "hidden" /* Hidden */)
841
869
  return null;
842
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
843
- import_react_primitive10.Primitive.div,
870
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
871
+ import_react_primitive11.Primitive.div,
844
872
  {
845
873
  "data-floating": hideAndfloatStatus === "floating" /* Floating */,
846
874
  ...rest,
@@ -909,10 +937,10 @@ var useBeginMessageEdit = () => {
909
937
  var ActionBarEdit = createActionButton(useBeginMessageEdit);
910
938
 
911
939
  // src/adapters/vercel/VercelAIAssistantProvider.tsx
912
- var import_react22 = require("react");
940
+ var import_react23 = require("react");
913
941
 
914
942
  // src/adapters/vercel/useDummyAIAssistantContext.tsx
915
- var import_react20 = require("react");
943
+ var import_react21 = require("react");
916
944
  var import_zustand4 = require("zustand");
917
945
 
918
946
  // src/utils/context/stores/ViewportStore.tsx
@@ -958,7 +986,7 @@ var makeDummyThreadStore = () => {
958
986
  }));
959
987
  };
960
988
  var useDummyAIAssistantContext = () => {
961
- const [context] = (0, import_react20.useState)(() => {
989
+ const [context] = (0, import_react21.useState)(() => {
962
990
  const useThread = makeDummyThreadStore();
963
991
  const useViewport = makeViewportStore();
964
992
  const useComposer = makeThreadComposerStore(useThread);
@@ -968,7 +996,7 @@ var useDummyAIAssistantContext = () => {
968
996
  };
969
997
 
970
998
  // src/adapters/vercel/useVercelAIBranches.tsx
971
- var import_react21 = require("react");
999
+ var import_react22 = require("react");
972
1000
 
973
1001
  // src/adapters/MessageRepository.tsx
974
1002
  var import_non_secure = require("nanoid/non-secure");
@@ -1128,10 +1156,10 @@ var hasUpcomingMessage = (isRunning, messages) => {
1128
1156
  return isRunning && messages[messages.length - 1]?.role !== "assistant";
1129
1157
  };
1130
1158
  var useVercelAIBranches = (chat, messages) => {
1131
- const [data] = (0, import_react21.useState)(() => new MessageRepository());
1159
+ const [data] = (0, import_react22.useState)(() => new MessageRepository());
1132
1160
  const isRunning = "isLoading" in chat ? chat.isLoading : chat.status === "in_progress";
1133
- const assistantOptimisticIdRef = (0, import_react21.useRef)(null);
1134
- const messagesEx = (0, import_react21.useMemo)(() => {
1161
+ const assistantOptimisticIdRef = (0, import_react22.useRef)(null);
1162
+ const messagesEx = (0, import_react22.useMemo)(() => {
1135
1163
  for (const message of messages) {
1136
1164
  data.addOrUpdateMessage(message);
1137
1165
  }
@@ -1149,13 +1177,13 @@ var useVercelAIBranches = (chat, messages) => {
1149
1177
  );
1150
1178
  return data.getMessages();
1151
1179
  }, [data, isRunning, messages]);
1152
- const getBranches = (0, import_react21.useCallback)(
1180
+ const getBranches = (0, import_react22.useCallback)(
1153
1181
  (messageId) => {
1154
1182
  return data.getBranches(messageId);
1155
1183
  },
1156
1184
  [data]
1157
1185
  );
1158
- const switchToBranch = (0, import_react21.useCallback)(
1186
+ const switchToBranch = (0, import_react22.useCallback)(
1159
1187
  (messageId) => {
1160
1188
  data.switchToBranch(messageId);
1161
1189
  chat.setMessages(
@@ -1165,7 +1193,7 @@ var useVercelAIBranches = (chat, messages) => {
1165
1193
  [data, chat.setMessages]
1166
1194
  );
1167
1195
  const reloadMaybe = "reload" in chat ? chat.reload : void 0;
1168
- const startRun = (0, import_react21.useCallback)(
1196
+ const startRun = (0, import_react22.useCallback)(
1169
1197
  async (parentId) => {
1170
1198
  if (!reloadMaybe)
1171
1199
  throw new Error("Reload not supported by Vercel AI SDK's useAssistant");
@@ -1175,7 +1203,7 @@ var useVercelAIBranches = (chat, messages) => {
1175
1203
  },
1176
1204
  [chat.messages, chat.setMessages, reloadMaybe]
1177
1205
  );
1178
- const append = (0, import_react21.useCallback)(
1206
+ const append = (0, import_react22.useCallback)(
1179
1207
  async (message) => {
1180
1208
  if (message.content.length !== 1 || message.content[0]?.type !== "text")
1181
1209
  throw new Error("Only text content is supported by Vercel AI SDK");
@@ -1188,7 +1216,7 @@ var useVercelAIBranches = (chat, messages) => {
1188
1216
  },
1189
1217
  [chat.messages, chat.setMessages, chat.append]
1190
1218
  );
1191
- return (0, import_react21.useMemo)(
1219
+ return (0, import_react22.useMemo)(
1192
1220
  () => ({
1193
1221
  messages: messagesEx,
1194
1222
  getBranches,
@@ -1201,7 +1229,7 @@ var useVercelAIBranches = (chat, messages) => {
1201
1229
  };
1202
1230
 
1203
1231
  // src/adapters/vercel/VercelAIAssistantProvider.tsx
1204
- var import_jsx_runtime18 = require("react/jsx-runtime");
1232
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1205
1233
  var ThreadMessageCache = /* @__PURE__ */ new WeakMap();
1206
1234
  var vercelToThreadMessage = (message, parentId) => {
1207
1235
  if (message.role !== "user" && message.role !== "assistant")
@@ -1232,11 +1260,11 @@ var VercelAIAssistantProvider = ({
1232
1260
  }) => {
1233
1261
  const context = useDummyAIAssistantContext();
1234
1262
  const vercel = "chat" in rest ? rest.chat : rest.assistant;
1235
- const messages = (0, import_react22.useMemo)(() => {
1263
+ const messages = (0, import_react23.useMemo)(() => {
1236
1264
  return vercelToCachedThreadMessages(vercel.messages);
1237
1265
  }, [vercel.messages]);
1238
1266
  const branches = useVercelAIBranches(vercel, messages);
1239
- const cancelRun = (0, import_react22.useCallback)(() => {
1267
+ const cancelRun = (0, import_react23.useCallback)(() => {
1240
1268
  const lastMessage = vercel.messages.at(-1);
1241
1269
  vercel.stop();
1242
1270
  if (lastMessage?.role === "user") {
@@ -1244,7 +1272,7 @@ var VercelAIAssistantProvider = ({
1244
1272
  }
1245
1273
  }, [vercel.messages, vercel.stop, vercel.setInput]);
1246
1274
  const isRunning = "isLoading" in vercel ? vercel.isLoading : vercel.status === "in_progress";
1247
- (0, import_react22.useMemo)(() => {
1275
+ (0, import_react23.useMemo)(() => {
1248
1276
  context.useThread.setState(
1249
1277
  {
1250
1278
  messages: branches.messages,
@@ -1258,18 +1286,18 @@ var VercelAIAssistantProvider = ({
1258
1286
  true
1259
1287
  );
1260
1288
  }, [context, isRunning, cancelRun, branches]);
1261
- (0, import_react22.useMemo)(() => {
1289
+ (0, import_react23.useMemo)(() => {
1262
1290
  context.useComposer.setState({
1263
1291
  value: vercel.input,
1264
1292
  setValue: vercel.setInput
1265
1293
  });
1266
1294
  }, [context, vercel.input, vercel.setInput]);
1267
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(AssistantContext.Provider, { value: context, children });
1295
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AssistantContext.Provider, { value: context, children });
1268
1296
  };
1269
1297
 
1270
1298
  // src/adapters/vercel/VercelRSCAssistantProvider.tsx
1271
- var import_react23 = require("react");
1272
- var import_jsx_runtime19 = require("react/jsx-runtime");
1299
+ var import_react24 = require("react");
1300
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1273
1301
  var ThreadMessageCache2 = /* @__PURE__ */ new WeakMap();
1274
1302
  var vercelToThreadMessage2 = (parentId, message) => {
1275
1303
  if (message.role !== "user" && message.role !== "assistant")
@@ -1295,10 +1323,10 @@ var vercelToCachedThreadMessages2 = (messages) => {
1295
1323
  };
1296
1324
  var VercelRSCAssistantProvider = ({ children, messages: vercelMessages, append: vercelAppend }) => {
1297
1325
  const context = useDummyAIAssistantContext();
1298
- const messages = (0, import_react23.useMemo)(() => {
1326
+ const messages = (0, import_react24.useMemo)(() => {
1299
1327
  return vercelToCachedThreadMessages2(vercelMessages);
1300
1328
  }, [vercelMessages]);
1301
- const append = (0, import_react23.useCallback)(
1329
+ const append = (0, import_react24.useCallback)(
1302
1330
  async (message) => {
1303
1331
  if (message.parentId !== (context.useThread.getState().messages.at(-1)?.id ?? null))
1304
1332
  throw new Error("Unexpected: Message editing is not supported");
@@ -1309,13 +1337,13 @@ var VercelRSCAssistantProvider = ({ children, messages: vercelMessages, append:
1309
1337
  },
1310
1338
  [context, vercelAppend]
1311
1339
  );
1312
- (0, import_react23.useMemo)(() => {
1340
+ (0, import_react24.useMemo)(() => {
1313
1341
  context.useThread.setState({
1314
1342
  messages,
1315
1343
  append
1316
1344
  });
1317
1345
  }, [context, messages, append]);
1318
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(AssistantContext.Provider, { value: context, children });
1346
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(AssistantContext.Provider, { value: context, children });
1319
1347
  };
1320
1348
  // Annotate the CommonJS export names for ESM import in node:
1321
1349
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -12,6 +12,7 @@ __export(thread_exports, {
12
12
  Messages: () => ThreadMessages,
13
13
  Root: () => ThreadRoot,
14
14
  ScrollToBottom: () => ThreadScrollToBottom,
15
+ Suggestion: () => ThreadSuggestion,
15
16
  Viewport: () => ThreadViewport
16
17
  });
17
18
 
@@ -496,6 +497,35 @@ var ThreadScrollToBottom = forwardRef4(({ onClick, ...rest }, ref) => {
496
497
  );
497
498
  });
498
499
 
500
+ // src/primitives/thread/ThreadSuggestion.tsx
501
+ import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
502
+ import {
503
+ Primitive as Primitive5
504
+ } from "@radix-ui/react-primitive";
505
+ import { forwardRef as forwardRef5 } from "react";
506
+ import { jsx as jsx9 } from "react/jsx-runtime";
507
+ var ThreadSuggestion = forwardRef5(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {
508
+ const { useThread, useComposer } = useAssistantContext();
509
+ const isDisabled = useThread((t) => t.isRunning);
510
+ const handleApplySuggestion = () => {
511
+ const thread = useThread.getState();
512
+ const composer = useComposer.getState();
513
+ composer.setValue(prompt);
514
+ if (send && !thread.isRunning) {
515
+ composer.send();
516
+ }
517
+ };
518
+ return /* @__PURE__ */ jsx9(
519
+ Primitive5.button,
520
+ {
521
+ ...rest,
522
+ disabled: isDisabled,
523
+ ref,
524
+ onClick: composeEventHandlers4(onClick, handleApplySuggestion)
525
+ }
526
+ );
527
+ });
528
+
499
529
  // src/primitives/composer/index.ts
500
530
  var composer_exports = {};
501
531
  __export(composer_exports, {
@@ -507,14 +537,14 @@ __export(composer_exports, {
507
537
  });
508
538
 
509
539
  // src/primitives/composer/ComposerRoot.tsx
510
- import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
540
+ import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
511
541
  import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
512
542
  import {
513
- Primitive as Primitive5
543
+ Primitive as Primitive6
514
544
  } from "@radix-ui/react-primitive";
515
- import { forwardRef as forwardRef5, useRef as useRef4 } from "react";
516
- import { jsx as jsx9 } from "react/jsx-runtime";
517
- var ComposerRoot = forwardRef5(
545
+ import { forwardRef as forwardRef6, useRef as useRef4 } from "react";
546
+ import { jsx as jsx10 } from "react/jsx-runtime";
547
+ var ComposerRoot = forwardRef6(
518
548
  ({ onSubmit, ...rest }, forwardedRef) => {
519
549
  const { useViewport } = useAssistantContext();
520
550
  const { useComposer } = useComposerContext();
@@ -528,30 +558,30 @@ var ComposerRoot = forwardRef5(
528
558
  composerState.send();
529
559
  useViewport.getState().scrollToBottom();
530
560
  };
531
- return /* @__PURE__ */ jsx9(
532
- Primitive5.form,
561
+ return /* @__PURE__ */ jsx10(
562
+ Primitive6.form,
533
563
  {
534
564
  ...rest,
535
565
  ref,
536
- onSubmit: composeEventHandlers4(onSubmit, handleSubmit)
566
+ onSubmit: composeEventHandlers5(onSubmit, handleSubmit)
537
567
  }
538
568
  );
539
569
  }
540
570
  );
541
571
 
542
572
  // src/primitives/composer/ComposerInput.tsx
543
- import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
573
+ import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primitive";
544
574
  import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
545
575
  import { Slot } from "@radix-ui/react-slot";
546
576
  import {
547
- forwardRef as forwardRef6,
577
+ forwardRef as forwardRef7,
548
578
  useCallback,
549
579
  useEffect as useEffect2,
550
580
  useRef as useRef5
551
581
  } from "react";
552
582
  import TextareaAutosize from "react-textarea-autosize";
553
- import { jsx as jsx10 } from "react/jsx-runtime";
554
- var ComposerInput = forwardRef6(
583
+ import { jsx as jsx11 } from "react/jsx-runtime";
584
+ var ComposerInput = forwardRef7(
555
585
  ({ autoFocus, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
556
586
  const { useThread, useViewport } = useAssistantContext();
557
587
  const { useComposer, type } = useComposerContext();
@@ -597,20 +627,20 @@ var ComposerInput = forwardRef6(
597
627
  focus();
598
628
  }
599
629
  });
600
- return /* @__PURE__ */ jsx10(
630
+ return /* @__PURE__ */ jsx11(
601
631
  Component,
602
632
  {
603
633
  value,
604
634
  ...rest,
605
635
  ref,
606
636
  disabled,
607
- onChange: composeEventHandlers5(onChange, (e) => {
637
+ onChange: composeEventHandlers6(onChange, (e) => {
608
638
  const composerState = useComposer.getState();
609
639
  if (!composerState.isEditing)
610
640
  return;
611
641
  return composerState.setValue(e.target.value);
612
642
  }),
613
- onKeyDown: composeEventHandlers5(onKeyDown, handleKeyPress)
643
+ onKeyDown: composeEventHandlers6(onKeyDown, handleKeyPress)
614
644
  }
615
645
  );
616
646
  }
@@ -618,16 +648,16 @@ var ComposerInput = forwardRef6(
618
648
 
619
649
  // src/primitives/composer/ComposerSend.tsx
620
650
  import {
621
- Primitive as Primitive6
651
+ Primitive as Primitive7
622
652
  } from "@radix-ui/react-primitive";
623
- import { forwardRef as forwardRef7 } from "react";
624
- import { jsx as jsx11 } from "react/jsx-runtime";
625
- var ComposerSend = forwardRef7(
653
+ import { forwardRef as forwardRef8 } from "react";
654
+ import { jsx as jsx12 } from "react/jsx-runtime";
655
+ var ComposerSend = forwardRef8(
626
656
  ({ disabled, ...rest }, ref) => {
627
657
  const { useComposer } = useComposerContext();
628
658
  const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
629
- return /* @__PURE__ */ jsx11(
630
- Primitive6.button,
659
+ return /* @__PURE__ */ jsx12(
660
+ Primitive7.button,
631
661
  {
632
662
  type: "submit",
633
663
  ...rest,
@@ -639,24 +669,24 @@ var ComposerSend = forwardRef7(
639
669
  );
640
670
 
641
671
  // src/primitives/composer/ComposerCancel.tsx
642
- import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primitive";
672
+ import { composeEventHandlers as composeEventHandlers7 } from "@radix-ui/primitive";
643
673
  import {
644
- Primitive as Primitive7
674
+ Primitive as Primitive8
645
675
  } from "@radix-ui/react-primitive";
646
- import { forwardRef as forwardRef8 } from "react";
647
- import { jsx as jsx12 } from "react/jsx-runtime";
648
- var ComposerCancel = forwardRef8(({ onClick, ...rest }, ref) => {
676
+ import { forwardRef as forwardRef9 } from "react";
677
+ import { jsx as jsx13 } from "react/jsx-runtime";
678
+ var ComposerCancel = forwardRef9(({ onClick, ...rest }, ref) => {
649
679
  const { useComposer } = useComposerContext();
650
680
  const handleCancel = () => {
651
681
  useComposer.getState().cancel();
652
682
  };
653
- return /* @__PURE__ */ jsx12(
654
- Primitive7.button,
683
+ return /* @__PURE__ */ jsx13(
684
+ Primitive8.button,
655
685
  {
656
686
  type: "button",
657
687
  ...rest,
658
688
  ref,
659
- onClick: composeEventHandlers6(onClick, handleCancel)
689
+ onClick: composeEventHandlers7(onClick, handleCancel)
660
690
  }
661
691
  );
662
692
  });
@@ -714,24 +744,24 @@ var useGoToNextBranch = () => {
714
744
  };
715
745
 
716
746
  // src/utils/createActionButton.tsx
717
- import { composeEventHandlers as composeEventHandlers7 } from "@radix-ui/primitive";
747
+ import { composeEventHandlers as composeEventHandlers8 } from "@radix-ui/primitive";
718
748
  import {
719
- Primitive as Primitive8
749
+ Primitive as Primitive9
720
750
  } from "@radix-ui/react-primitive";
721
- import { forwardRef as forwardRef9 } from "react";
722
- import { jsx as jsx13 } from "react/jsx-runtime";
751
+ import { forwardRef as forwardRef10 } from "react";
752
+ import { jsx as jsx14 } from "react/jsx-runtime";
723
753
  var createActionButton = (useActionButton) => {
724
- return forwardRef9(
754
+ return forwardRef10(
725
755
  (props, forwardedRef) => {
726
756
  const onClick = useActionButton(props);
727
- return /* @__PURE__ */ jsx13(
728
- Primitive8.button,
757
+ return /* @__PURE__ */ jsx14(
758
+ Primitive9.button,
729
759
  {
730
760
  type: "button",
731
761
  disabled: !onClick,
732
762
  ...props,
733
763
  ref: forwardedRef,
734
- onClick: composeEventHandlers7(props.onClick, onClick ?? void 0)
764
+ onClick: composeEventHandlers8(props.onClick, onClick ?? void 0)
735
765
  }
736
766
  );
737
767
  }
@@ -764,29 +794,29 @@ var useGoToPreviousBranch = () => {
764
794
  var BranchPickerPrevious = createActionButton(useGoToPreviousBranch);
765
795
 
766
796
  // src/primitives/branchPicker/BranchPickerCount.tsx
767
- import { Fragment as Fragment3, jsx as jsx14 } from "react/jsx-runtime";
797
+ import { Fragment as Fragment3, jsx as jsx15 } from "react/jsx-runtime";
768
798
  var BranchPickerCount = () => {
769
799
  const { useMessage } = useMessageContext();
770
800
  const branchCount = useMessage((s) => s.branches.length);
771
- return /* @__PURE__ */ jsx14(Fragment3, { children: branchCount });
801
+ return /* @__PURE__ */ jsx15(Fragment3, { children: branchCount });
772
802
  };
773
803
 
774
804
  // src/primitives/branchPicker/BranchPickerNumber.tsx
775
- import { Fragment as Fragment4, jsx as jsx15 } from "react/jsx-runtime";
805
+ import { Fragment as Fragment4, jsx as jsx16 } from "react/jsx-runtime";
776
806
  var BranchPickerNumber = () => {
777
807
  const { useMessage } = useMessageContext();
778
808
  const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
779
- return /* @__PURE__ */ jsx15(Fragment4, { children: branchIdx + 1 });
809
+ return /* @__PURE__ */ jsx16(Fragment4, { children: branchIdx + 1 });
780
810
  };
781
811
 
782
812
  // src/primitives/branchPicker/BranchPickerRoot.tsx
783
813
  import {
784
- Primitive as Primitive9
814
+ Primitive as Primitive10
785
815
  } from "@radix-ui/react-primitive";
786
- import { forwardRef as forwardRef10 } from "react";
787
- import { jsx as jsx16 } from "react/jsx-runtime";
788
- var BranchPickerRoot = forwardRef10(({ hideWhenSingleBranch, ...rest }, ref) => {
789
- return /* @__PURE__ */ jsx16(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive9.div, { ...rest, ref }) });
816
+ import { forwardRef as forwardRef11 } from "react";
817
+ import { jsx as jsx17 } from "react/jsx-runtime";
818
+ var BranchPickerRoot = forwardRef11(({ hideWhenSingleBranch, ...rest }, ref) => {
819
+ return /* @__PURE__ */ jsx17(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx17(Primitive10.div, { ...rest, ref }) });
790
820
  });
791
821
 
792
822
  // src/primitives/actionBar/index.ts
@@ -800,11 +830,11 @@ __export(actionBar_exports, {
800
830
 
801
831
  // src/primitives/actionBar/ActionBarRoot.tsx
802
832
  import {
803
- Primitive as Primitive10
833
+ Primitive as Primitive11
804
834
  } from "@radix-ui/react-primitive";
805
- import { forwardRef as forwardRef11 } from "react";
806
- import { jsx as jsx17 } from "react/jsx-runtime";
807
- var ActionBarRoot = forwardRef11(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
835
+ import { forwardRef as forwardRef12 } from "react";
836
+ import { jsx as jsx18 } from "react/jsx-runtime";
837
+ var ActionBarRoot = forwardRef12(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
808
838
  const { useThread } = useAssistantContext();
809
839
  const { useMessage } = useMessageContext();
810
840
  const hideAndfloatStatus = useCombinedStore(
@@ -824,8 +854,8 @@ var ActionBarRoot = forwardRef11(({ hideWhenRunning, autohide, autohideFloat, ..
824
854
  );
825
855
  if (hideAndfloatStatus === "hidden" /* Hidden */)
826
856
  return null;
827
- return /* @__PURE__ */ jsx17(
828
- Primitive10.div,
857
+ return /* @__PURE__ */ jsx18(
858
+ Primitive11.div,
829
859
  {
830
860
  "data-floating": hideAndfloatStatus === "floating" /* Floating */,
831
861
  ...rest,
@@ -1186,7 +1216,7 @@ var useVercelAIBranches = (chat, messages) => {
1186
1216
  };
1187
1217
 
1188
1218
  // src/adapters/vercel/VercelAIAssistantProvider.tsx
1189
- import { jsx as jsx18 } from "react/jsx-runtime";
1219
+ import { jsx as jsx19 } from "react/jsx-runtime";
1190
1220
  var ThreadMessageCache = /* @__PURE__ */ new WeakMap();
1191
1221
  var vercelToThreadMessage = (message, parentId) => {
1192
1222
  if (message.role !== "user" && message.role !== "assistant")
@@ -1249,7 +1279,7 @@ var VercelAIAssistantProvider = ({
1249
1279
  setValue: vercel.setInput
1250
1280
  });
1251
1281
  }, [context, vercel.input, vercel.setInput]);
1252
- return /* @__PURE__ */ jsx18(AssistantContext.Provider, { value: context, children });
1282
+ return /* @__PURE__ */ jsx19(AssistantContext.Provider, { value: context, children });
1253
1283
  };
1254
1284
 
1255
1285
  // src/adapters/vercel/VercelRSCAssistantProvider.tsx
@@ -1257,7 +1287,7 @@ import {
1257
1287
  useCallback as useCallback4,
1258
1288
  useMemo as useMemo5
1259
1289
  } from "react";
1260
- import { jsx as jsx19 } from "react/jsx-runtime";
1290
+ import { jsx as jsx20 } from "react/jsx-runtime";
1261
1291
  var ThreadMessageCache2 = /* @__PURE__ */ new WeakMap();
1262
1292
  var vercelToThreadMessage2 = (parentId, message) => {
1263
1293
  if (message.role !== "user" && message.role !== "assistant")
@@ -1303,7 +1333,7 @@ var VercelRSCAssistantProvider = ({ children, messages: vercelMessages, append:
1303
1333
  append
1304
1334
  });
1305
1335
  }, [context, messages, append]);
1306
- return /* @__PURE__ */ jsx19(AssistantContext.Provider, { value: context, children });
1336
+ return /* @__PURE__ */ jsx20(AssistantContext.Provider, { value: context, children });
1307
1337
  };
1308
1338
  export {
1309
1339
  actionBar_exports as ActionBarPrimitive,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {