@assistant-ui/react 0.0.11 → 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"> & {
@@ -256,24 +266,24 @@ declare namespace index {
256
266
  export { ActionBarCopy as Copy, ActionBarEdit as Edit, ActionBarReload as Reload, ActionBarRoot as Root };
257
267
  }
258
268
 
259
- type VercelAIAssistantProviderProps$1 = PropsWithChildren<{
269
+ type VercelAIAssistantProviderProps = PropsWithChildren<{
260
270
  chat: UseChatHelpers;
261
271
  } | {
262
272
  assistant: UseAssistantHelpers;
263
273
  }>;
264
- declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps$1>;
274
+ declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
265
275
 
266
- type RSCMessage = {
276
+ type VercelRSCMessage = {
267
277
  id: string;
268
278
  role: "user" | "assistant";
269
279
  display: ReactNode;
270
280
  createdAt?: Date;
271
281
  };
272
- type VercelAIAssistantProviderProps = PropsWithChildren<{
273
- messages: RSCMessage[];
282
+ type VercelRSCAssistantProviderProps = PropsWithChildren<{
283
+ messages: VercelRSCMessage[];
274
284
  append: (message: CreateThreadMessage) => Promise<void>;
275
285
  }>;
276
- declare const VercelRSCAssistantProvider: FC<VercelAIAssistantProviderProps>;
286
+ declare const VercelRSCAssistantProvider: FC<VercelRSCAssistantProviderProps>;
277
287
 
278
288
  type MessageState = {
279
289
  message: ThreadMessage;
@@ -303,4 +313,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
303
313
 
304
314
  declare const useGoToPreviousBranch: () => (() => void) | null;
305
315
 
306
- export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, index$2 as MessagePrimitive, index$4 as ThreadPrimitive, VercelAIAssistantProvider, VercelRSCAssistantProvider as unstable_VercelRSCAssistantProvider, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
316
+ export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type CreateThreadMessage, type CreateThreadUserMessageContent, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type ThreadMessageImagePart, type ThreadMessageTextPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
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"> & {
@@ -256,24 +266,24 @@ declare namespace index {
256
266
  export { ActionBarCopy as Copy, ActionBarEdit as Edit, ActionBarReload as Reload, ActionBarRoot as Root };
257
267
  }
258
268
 
259
- type VercelAIAssistantProviderProps$1 = PropsWithChildren<{
269
+ type VercelAIAssistantProviderProps = PropsWithChildren<{
260
270
  chat: UseChatHelpers;
261
271
  } | {
262
272
  assistant: UseAssistantHelpers;
263
273
  }>;
264
- declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps$1>;
274
+ declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
265
275
 
266
- type RSCMessage = {
276
+ type VercelRSCMessage = {
267
277
  id: string;
268
278
  role: "user" | "assistant";
269
279
  display: ReactNode;
270
280
  createdAt?: Date;
271
281
  };
272
- type VercelAIAssistantProviderProps = PropsWithChildren<{
273
- messages: RSCMessage[];
282
+ type VercelRSCAssistantProviderProps = PropsWithChildren<{
283
+ messages: VercelRSCMessage[];
274
284
  append: (message: CreateThreadMessage) => Promise<void>;
275
285
  }>;
276
- declare const VercelRSCAssistantProvider: FC<VercelAIAssistantProviderProps>;
286
+ declare const VercelRSCAssistantProvider: FC<VercelRSCAssistantProviderProps>;
277
287
 
278
288
  type MessageState = {
279
289
  message: ThreadMessage;
@@ -303,4 +313,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
303
313
 
304
314
  declare const useGoToPreviousBranch: () => (() => void) | null;
305
315
 
306
- export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, index$2 as MessagePrimitive, index$4 as ThreadPrimitive, VercelAIAssistantProvider, VercelRSCAssistantProvider as unstable_VercelRSCAssistantProvider, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
316
+ export { index as ActionBarPrimitive, index$1 as BranchPickerPrimitive, index$3 as ComposerPrimitive, type CreateThreadMessage, type CreateThreadUserMessageContent, index$2 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type ThreadMessageImagePart, type ThreadMessageTextPart, index$4 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ __export(src_exports, {
36
36
  MessagePrimitive: () => message_exports,
37
37
  ThreadPrimitive: () => thread_exports,
38
38
  VercelAIAssistantProvider: () => VercelAIAssistantProvider,
39
- unstable_VercelRSCAssistantProvider: () => VercelRSCAssistantProvider,
39
+ VercelRSCAssistantProvider: () => VercelRSCAssistantProvider,
40
40
  unstable_useMessageContext: () => useMessageContext,
41
41
  useBeginMessageEdit: () => useBeginMessageEdit,
42
42
  useCopyMessage: () => useCopyMessage,
@@ -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,22 +996,11 @@ var useDummyAIAssistantContext = () => {
968
996
  };
969
997
 
970
998
  // src/adapters/vercel/useVercelAIBranches.tsx
971
- var import_react21 = require("react");
972
-
973
- // ../../node_modules/nanoid/non-secure/index.js
974
- var customAlphabet = (alphabet, defaultSize = 21) => {
975
- return (size = defaultSize) => {
976
- let id = "";
977
- let i = size;
978
- while (i--) {
979
- id += alphabet[Math.random() * alphabet.length | 0];
980
- }
981
- return id;
982
- };
983
- };
999
+ var import_react22 = require("react");
984
1000
 
985
1001
  // src/adapters/MessageRepository.tsx
986
- var generateId = customAlphabet(
1002
+ var import_non_secure = require("nanoid/non-secure");
1003
+ var generateId = (0, import_non_secure.customAlphabet)(
987
1004
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
988
1005
  7
989
1006
  );
@@ -1139,10 +1156,10 @@ var hasUpcomingMessage = (isRunning, messages) => {
1139
1156
  return isRunning && messages[messages.length - 1]?.role !== "assistant";
1140
1157
  };
1141
1158
  var useVercelAIBranches = (chat, messages) => {
1142
- const [data] = (0, import_react21.useState)(() => new MessageRepository());
1159
+ const [data] = (0, import_react22.useState)(() => new MessageRepository());
1143
1160
  const isRunning = "isLoading" in chat ? chat.isLoading : chat.status === "in_progress";
1144
- const assistantOptimisticIdRef = (0, import_react21.useRef)(null);
1145
- const messagesEx = (0, import_react21.useMemo)(() => {
1161
+ const assistantOptimisticIdRef = (0, import_react22.useRef)(null);
1162
+ const messagesEx = (0, import_react22.useMemo)(() => {
1146
1163
  for (const message of messages) {
1147
1164
  data.addOrUpdateMessage(message);
1148
1165
  }
@@ -1160,13 +1177,13 @@ var useVercelAIBranches = (chat, messages) => {
1160
1177
  );
1161
1178
  return data.getMessages();
1162
1179
  }, [data, isRunning, messages]);
1163
- const getBranches = (0, import_react21.useCallback)(
1180
+ const getBranches = (0, import_react22.useCallback)(
1164
1181
  (messageId) => {
1165
1182
  return data.getBranches(messageId);
1166
1183
  },
1167
1184
  [data]
1168
1185
  );
1169
- const switchToBranch = (0, import_react21.useCallback)(
1186
+ const switchToBranch = (0, import_react22.useCallback)(
1170
1187
  (messageId) => {
1171
1188
  data.switchToBranch(messageId);
1172
1189
  chat.setMessages(
@@ -1176,7 +1193,7 @@ var useVercelAIBranches = (chat, messages) => {
1176
1193
  [data, chat.setMessages]
1177
1194
  );
1178
1195
  const reloadMaybe = "reload" in chat ? chat.reload : void 0;
1179
- const startRun = (0, import_react21.useCallback)(
1196
+ const startRun = (0, import_react22.useCallback)(
1180
1197
  async (parentId) => {
1181
1198
  if (!reloadMaybe)
1182
1199
  throw new Error("Reload not supported by Vercel AI SDK's useAssistant");
@@ -1186,7 +1203,7 @@ var useVercelAIBranches = (chat, messages) => {
1186
1203
  },
1187
1204
  [chat.messages, chat.setMessages, reloadMaybe]
1188
1205
  );
1189
- const append = (0, import_react21.useCallback)(
1206
+ const append = (0, import_react22.useCallback)(
1190
1207
  async (message) => {
1191
1208
  if (message.content.length !== 1 || message.content[0]?.type !== "text")
1192
1209
  throw new Error("Only text content is supported by Vercel AI SDK");
@@ -1199,7 +1216,7 @@ var useVercelAIBranches = (chat, messages) => {
1199
1216
  },
1200
1217
  [chat.messages, chat.setMessages, chat.append]
1201
1218
  );
1202
- return (0, import_react21.useMemo)(
1219
+ return (0, import_react22.useMemo)(
1203
1220
  () => ({
1204
1221
  messages: messagesEx,
1205
1222
  getBranches,
@@ -1212,7 +1229,7 @@ var useVercelAIBranches = (chat, messages) => {
1212
1229
  };
1213
1230
 
1214
1231
  // src/adapters/vercel/VercelAIAssistantProvider.tsx
1215
- var import_jsx_runtime18 = require("react/jsx-runtime");
1232
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1216
1233
  var ThreadMessageCache = /* @__PURE__ */ new WeakMap();
1217
1234
  var vercelToThreadMessage = (message, parentId) => {
1218
1235
  if (message.role !== "user" && message.role !== "assistant")
@@ -1243,11 +1260,11 @@ var VercelAIAssistantProvider = ({
1243
1260
  }) => {
1244
1261
  const context = useDummyAIAssistantContext();
1245
1262
  const vercel = "chat" in rest ? rest.chat : rest.assistant;
1246
- const messages = (0, import_react22.useMemo)(() => {
1263
+ const messages = (0, import_react23.useMemo)(() => {
1247
1264
  return vercelToCachedThreadMessages(vercel.messages);
1248
1265
  }, [vercel.messages]);
1249
1266
  const branches = useVercelAIBranches(vercel, messages);
1250
- const cancelRun = (0, import_react22.useCallback)(() => {
1267
+ const cancelRun = (0, import_react23.useCallback)(() => {
1251
1268
  const lastMessage = vercel.messages.at(-1);
1252
1269
  vercel.stop();
1253
1270
  if (lastMessage?.role === "user") {
@@ -1255,7 +1272,7 @@ var VercelAIAssistantProvider = ({
1255
1272
  }
1256
1273
  }, [vercel.messages, vercel.stop, vercel.setInput]);
1257
1274
  const isRunning = "isLoading" in vercel ? vercel.isLoading : vercel.status === "in_progress";
1258
- (0, import_react22.useMemo)(() => {
1275
+ (0, import_react23.useMemo)(() => {
1259
1276
  context.useThread.setState(
1260
1277
  {
1261
1278
  messages: branches.messages,
@@ -1269,18 +1286,18 @@ var VercelAIAssistantProvider = ({
1269
1286
  true
1270
1287
  );
1271
1288
  }, [context, isRunning, cancelRun, branches]);
1272
- (0, import_react22.useMemo)(() => {
1289
+ (0, import_react23.useMemo)(() => {
1273
1290
  context.useComposer.setState({
1274
1291
  value: vercel.input,
1275
1292
  setValue: vercel.setInput
1276
1293
  });
1277
1294
  }, [context, vercel.input, vercel.setInput]);
1278
- 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 });
1279
1296
  };
1280
1297
 
1281
1298
  // src/adapters/vercel/VercelRSCAssistantProvider.tsx
1282
- var import_react23 = require("react");
1283
- var import_jsx_runtime19 = require("react/jsx-runtime");
1299
+ var import_react24 = require("react");
1300
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1284
1301
  var ThreadMessageCache2 = /* @__PURE__ */ new WeakMap();
1285
1302
  var vercelToThreadMessage2 = (parentId, message) => {
1286
1303
  if (message.role !== "user" && message.role !== "assistant")
@@ -1304,16 +1321,12 @@ var vercelToCachedThreadMessages2 = (messages) => {
1304
1321
  return newMessage;
1305
1322
  });
1306
1323
  };
1307
- var VercelRSCAssistantProvider = ({
1308
- children,
1309
- messages: vercelMessages,
1310
- append: vercelAppend
1311
- }) => {
1324
+ var VercelRSCAssistantProvider = ({ children, messages: vercelMessages, append: vercelAppend }) => {
1312
1325
  const context = useDummyAIAssistantContext();
1313
- const messages = (0, import_react23.useMemo)(() => {
1326
+ const messages = (0, import_react24.useMemo)(() => {
1314
1327
  return vercelToCachedThreadMessages2(vercelMessages);
1315
1328
  }, [vercelMessages]);
1316
- const append = (0, import_react23.useCallback)(
1329
+ const append = (0, import_react24.useCallback)(
1317
1330
  async (message) => {
1318
1331
  if (message.parentId !== (context.useThread.getState().messages.at(-1)?.id ?? null))
1319
1332
  throw new Error("Unexpected: Message editing is not supported");
@@ -1324,13 +1337,13 @@ var VercelRSCAssistantProvider = ({
1324
1337
  },
1325
1338
  [context, vercelAppend]
1326
1339
  );
1327
- (0, import_react23.useMemo)(() => {
1340
+ (0, import_react24.useMemo)(() => {
1328
1341
  context.useThread.setState({
1329
1342
  messages,
1330
1343
  append
1331
1344
  });
1332
1345
  }, [context, messages, append]);
1333
- 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 });
1334
1347
  };
1335
1348
  // Annotate the CommonJS export names for ESM import in node:
1336
1349
  0 && (module.exports = {
@@ -1340,7 +1353,7 @@ var VercelRSCAssistantProvider = ({
1340
1353
  MessagePrimitive,
1341
1354
  ThreadPrimitive,
1342
1355
  VercelAIAssistantProvider,
1343
- unstable_VercelRSCAssistantProvider,
1356
+ VercelRSCAssistantProvider,
1344
1357
  unstable_useMessageContext,
1345
1358
  useBeginMessageEdit,
1346
1359
  useCopyMessage,
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,
@@ -955,19 +985,8 @@ var useDummyAIAssistantContext = () => {
955
985
  // src/adapters/vercel/useVercelAIBranches.tsx
956
986
  import { useCallback as useCallback2, useMemo as useMemo3, useRef as useRef6, useState as useState3 } from "react";
957
987
 
958
- // ../../node_modules/nanoid/non-secure/index.js
959
- var customAlphabet = (alphabet, defaultSize = 21) => {
960
- return (size = defaultSize) => {
961
- let id = "";
962
- let i = size;
963
- while (i--) {
964
- id += alphabet[Math.random() * alphabet.length | 0];
965
- }
966
- return id;
967
- };
968
- };
969
-
970
988
  // src/adapters/MessageRepository.tsx
989
+ import { customAlphabet } from "nanoid/non-secure";
971
990
  var generateId = customAlphabet(
972
991
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
973
992
  7
@@ -1197,7 +1216,7 @@ var useVercelAIBranches = (chat, messages) => {
1197
1216
  };
1198
1217
 
1199
1218
  // src/adapters/vercel/VercelAIAssistantProvider.tsx
1200
- import { jsx as jsx18 } from "react/jsx-runtime";
1219
+ import { jsx as jsx19 } from "react/jsx-runtime";
1201
1220
  var ThreadMessageCache = /* @__PURE__ */ new WeakMap();
1202
1221
  var vercelToThreadMessage = (message, parentId) => {
1203
1222
  if (message.role !== "user" && message.role !== "assistant")
@@ -1260,7 +1279,7 @@ var VercelAIAssistantProvider = ({
1260
1279
  setValue: vercel.setInput
1261
1280
  });
1262
1281
  }, [context, vercel.input, vercel.setInput]);
1263
- return /* @__PURE__ */ jsx18(AssistantContext.Provider, { value: context, children });
1282
+ return /* @__PURE__ */ jsx19(AssistantContext.Provider, { value: context, children });
1264
1283
  };
1265
1284
 
1266
1285
  // src/adapters/vercel/VercelRSCAssistantProvider.tsx
@@ -1268,7 +1287,7 @@ import {
1268
1287
  useCallback as useCallback4,
1269
1288
  useMemo as useMemo5
1270
1289
  } from "react";
1271
- import { jsx as jsx19 } from "react/jsx-runtime";
1290
+ import { jsx as jsx20 } from "react/jsx-runtime";
1272
1291
  var ThreadMessageCache2 = /* @__PURE__ */ new WeakMap();
1273
1292
  var vercelToThreadMessage2 = (parentId, message) => {
1274
1293
  if (message.role !== "user" && message.role !== "assistant")
@@ -1292,11 +1311,7 @@ var vercelToCachedThreadMessages2 = (messages) => {
1292
1311
  return newMessage;
1293
1312
  });
1294
1313
  };
1295
- var VercelRSCAssistantProvider = ({
1296
- children,
1297
- messages: vercelMessages,
1298
- append: vercelAppend
1299
- }) => {
1314
+ var VercelRSCAssistantProvider = ({ children, messages: vercelMessages, append: vercelAppend }) => {
1300
1315
  const context = useDummyAIAssistantContext();
1301
1316
  const messages = useMemo5(() => {
1302
1317
  return vercelToCachedThreadMessages2(vercelMessages);
@@ -1318,7 +1333,7 @@ var VercelRSCAssistantProvider = ({
1318
1333
  append
1319
1334
  });
1320
1335
  }, [context, messages, append]);
1321
- return /* @__PURE__ */ jsx19(AssistantContext.Provider, { value: context, children });
1336
+ return /* @__PURE__ */ jsx20(AssistantContext.Provider, { value: context, children });
1322
1337
  };
1323
1338
  export {
1324
1339
  actionBar_exports as ActionBarPrimitive,
@@ -1327,7 +1342,7 @@ export {
1327
1342
  message_exports as MessagePrimitive,
1328
1343
  thread_exports as ThreadPrimitive,
1329
1344
  VercelAIAssistantProvider,
1330
- VercelRSCAssistantProvider as unstable_VercelRSCAssistantProvider,
1345
+ VercelRSCAssistantProvider,
1331
1346
  useMessageContext as unstable_useMessageContext,
1332
1347
  useBeginMessageEdit,
1333
1348
  useCopyMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -18,7 +18,10 @@
18
18
  "main": "./dist/index.js",
19
19
  "module": "./dist/index.mjs",
20
20
  "types": "./dist/index.d.ts",
21
- "files": ["dist", "README.md"],
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
22
25
  "sideEffects": false,
23
26
  "scripts": {
24
27
  "build": "tsup src/index.ts --format cjs,esm --dts"
@@ -28,7 +31,8 @@
28
31
  "@radix-ui/react-compose-refs": "^1.0.1",
29
32
  "@radix-ui/react-primitive": "^1.0.3",
30
33
  "@radix-ui/react-slot": "^1.0.2",
31
- "ai": "^3.1.15",
34
+ "ai": "^3.1.22",
35
+ "nanoid": "^5.0.7",
32
36
  "react-textarea-autosize": "^8.5.3",
33
37
  "zustand": "^4.5.2"
34
38
  },