@assistant-ui/react 0.1.10 → 0.1.11

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.mjs CHANGED
@@ -180,12 +180,15 @@ var useComposerIf = (props) => {
180
180
  // src/primitive-hooks/composer/useComposerSend.tsx
181
181
  import { useCallback as useCallback7 } from "react";
182
182
  var useComposerSend = () => {
183
+ const { useViewport } = useThreadContext();
183
184
  const { useComposer } = useComposerContext();
184
185
  const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
185
186
  const callback = useCallback7(() => {
186
- const { send } = useComposer.getState();
187
- send();
188
- }, [useComposer]);
187
+ const composerState = useComposer.getState();
188
+ if (!composerState.isEditing) return;
189
+ composerState.send();
190
+ useViewport.getState().scrollToBottom();
191
+ }, [useComposer, useViewport]);
189
192
  if (disabled) return null;
190
193
  return callback;
191
194
  };
@@ -330,132 +333,161 @@ var ThreadRoot = forwardRef(
330
333
  );
331
334
  ThreadRoot.displayName = "ThreadRoot";
332
335
 
336
+ // src/primitives/thread/ThreadEmpty.tsx
337
+ var ThreadEmpty = ({ children }) => {
338
+ const empty = useThreadEmpty();
339
+ return empty ? children : null;
340
+ };
341
+
333
342
  // src/primitives/thread/ThreadIf.tsx
334
343
  var ThreadIf = ({ children, ...query }) => {
335
344
  const result = useThreadIf(query);
336
345
  return result ? children : null;
337
346
  };
338
347
 
339
- // src/primitives/thread/ThreadEmpty.tsx
340
- import { jsx as jsx2 } from "react/jsx-runtime";
341
- var ThreadEmpty = ({ children }) => {
342
- return /* @__PURE__ */ jsx2(ThreadIf, { empty: true, children });
343
- };
344
-
345
348
  // src/primitives/thread/ThreadViewport.tsx
346
- import { composeEventHandlers } from "@radix-ui/primitive";
347
- import { useComposedRefs } from "@radix-ui/react-compose-refs";
349
+ import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
348
350
  import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
349
- import {
350
- forwardRef as forwardRef2,
351
- useRef
352
- } from "react";
351
+ import { forwardRef as forwardRef2 } from "react";
352
+
353
+ // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
354
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
355
+ import { useRef as useRef2 } from "react";
353
356
 
354
357
  // src/utils/hooks/useOnResizeContent.tsx
355
358
  import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
356
- import { useEffect } from "react";
357
- var useOnResizeContent = (ref, callback) => {
359
+ import { useCallback as useCallback11 } from "react";
360
+
361
+ // src/utils/hooks/useManagedRef.ts
362
+ import { useCallback as useCallback10, useRef } from "react";
363
+ var useManagedRef = (callback) => {
364
+ const cleanupRef = useRef();
365
+ const ref = useCallback10(
366
+ (el) => {
367
+ if (cleanupRef.current) {
368
+ cleanupRef.current();
369
+ }
370
+ if (el) {
371
+ cleanupRef.current = callback(el);
372
+ }
373
+ },
374
+ [callback]
375
+ );
376
+ return ref;
377
+ };
378
+
379
+ // src/utils/hooks/useOnResizeContent.tsx
380
+ var useOnResizeContent = (callback) => {
358
381
  const callbackRef = useCallbackRef(callback);
359
- useEffect(() => {
360
- const el = ref.current;
361
- if (!el) return;
362
- const resizeObserver = new ResizeObserver(() => {
363
- callbackRef();
364
- });
365
- const mutationObserver = new MutationObserver((mutations) => {
366
- for (const mutation of mutations) {
367
- for (const node of mutation.addedNodes) {
368
- if (node instanceof Element) {
369
- resizeObserver.observe(node);
382
+ const refCallback = useCallback11(
383
+ (el) => {
384
+ const resizeObserver = new ResizeObserver(() => {
385
+ callbackRef();
386
+ });
387
+ const mutationObserver = new MutationObserver((mutations) => {
388
+ for (const mutation of mutations) {
389
+ for (const node of mutation.addedNodes) {
390
+ if (node instanceof Element) {
391
+ resizeObserver.observe(node);
392
+ }
370
393
  }
371
- }
372
- for (const node of mutation.removedNodes) {
373
- if (node instanceof Element) {
374
- resizeObserver.unobserve(node);
394
+ for (const node of mutation.removedNodes) {
395
+ if (node instanceof Element) {
396
+ resizeObserver.unobserve(node);
397
+ }
375
398
  }
376
399
  }
400
+ callbackRef();
401
+ });
402
+ resizeObserver.observe(el);
403
+ mutationObserver.observe(el, { childList: true });
404
+ for (const child of el.children) {
405
+ resizeObserver.observe(child);
377
406
  }
378
- callbackRef();
379
- });
380
- resizeObserver.observe(el);
381
- mutationObserver.observe(el, { childList: true });
382
- for (const child of el.children) {
383
- resizeObserver.observe(child);
384
- }
385
- return () => {
386
- resizeObserver.disconnect();
387
- mutationObserver.disconnect();
388
- };
389
- }, [ref, callbackRef]);
407
+ return () => {
408
+ resizeObserver.disconnect();
409
+ mutationObserver.disconnect();
410
+ };
411
+ },
412
+ [callbackRef]
413
+ );
414
+ return useManagedRef(refCallback);
390
415
  };
391
416
 
392
417
  // src/utils/hooks/useOnScrollToBottom.tsx
393
418
  import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
394
- import { useEffect as useEffect2 } from "react";
419
+ import { useEffect } from "react";
395
420
  var useOnScrollToBottom = (callback) => {
396
421
  const callbackRef = useCallbackRef2(callback);
397
422
  const { useViewport } = useThreadContext();
398
- useEffect2(() => {
423
+ useEffect(() => {
399
424
  return useViewport.getState().onScrollToBottom(() => {
400
425
  callbackRef();
401
426
  });
402
427
  }, [useViewport, callbackRef]);
403
428
  };
404
429
 
405
- // src/primitives/thread/ThreadViewport.tsx
406
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
407
- var ThreadViewport = forwardRef2(({ autoScroll = true, onScroll, children, ...rest }, forwardedRef) => {
408
- const messagesEndRef = useRef(null);
409
- const divRef = useRef(null);
410
- const ref = useComposedRefs(forwardedRef, divRef);
430
+ // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
431
+ var useThreadViewportAutoScroll = ({
432
+ autoScroll = true
433
+ }) => {
434
+ const divRef = useRef2(null);
411
435
  const { useViewport } = useThreadContext();
412
- const firstRenderRef = useRef(true);
413
- const isScrollingToBottomRef = useRef(false);
414
- const lastScrollTop = useRef(0);
436
+ const firstRenderRef = useRef2(true);
437
+ const lastScrollTop = useRef2(0);
438
+ const isScrollingToBottomRef = useRef2(false);
415
439
  const scrollToBottom = () => {
416
- const div = messagesEndRef.current;
440
+ const div = divRef.current;
417
441
  if (!div || !autoScroll) return;
418
442
  const behavior = firstRenderRef.current ? "instant" : "auto";
419
443
  firstRenderRef.current = false;
420
444
  isScrollingToBottomRef.current = true;
421
- div.scrollIntoView({ behavior });
445
+ div.scrollTo({ top: div.scrollHeight, behavior });
422
446
  };
423
- useOnResizeContent(divRef, () => {
424
- if (!isScrollingToBottomRef.current && !useViewport.getState().isAtBottom) {
425
- handleScroll();
426
- } else {
427
- scrollToBottom();
428
- }
429
- });
430
- useOnScrollToBottom(() => {
431
- scrollToBottom();
432
- });
433
447
  const handleScroll = () => {
434
448
  const div = divRef.current;
435
449
  if (!div) return;
436
450
  const isAtBottom = useViewport.getState().isAtBottom;
437
451
  const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight;
438
452
  if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {
439
- } else if (newIsAtBottom !== isAtBottom) {
440
- isScrollingToBottomRef.current = false;
441
- useViewport.setState({
442
- isAtBottom: newIsAtBottom
443
- });
453
+ } else {
454
+ isScrollingToBottomRef.current = newIsAtBottom;
455
+ if (newIsAtBottom !== isAtBottom) {
456
+ useViewport.setState({
457
+ isAtBottom: newIsAtBottom
458
+ });
459
+ }
444
460
  }
445
461
  lastScrollTop.current = div.scrollTop;
446
462
  };
447
- return /* @__PURE__ */ jsxs(
448
- Primitive2.div,
449
- {
450
- ...rest,
451
- onScroll: composeEventHandlers(onScroll, handleScroll),
452
- ref,
453
- children: [
454
- children,
455
- /* @__PURE__ */ jsx3("div", { ref: messagesEndRef })
456
- ]
463
+ const resizeRef = useOnResizeContent(() => {
464
+ if (!isScrollingToBottomRef.current && !useViewport.getState().isAtBottom && !firstRenderRef.current) {
465
+ handleScroll();
466
+ } else {
467
+ scrollToBottom();
457
468
  }
458
- );
469
+ });
470
+ const scrollRef = useManagedRef((el) => {
471
+ el.addEventListener("scroll", handleScroll);
472
+ return () => {
473
+ el.removeEventListener("scroll", handleScroll);
474
+ };
475
+ });
476
+ const autoScrollRef = useComposedRefs(resizeRef, scrollRef, divRef);
477
+ useOnScrollToBottom(() => {
478
+ scrollToBottom();
479
+ });
480
+ return autoScrollRef;
481
+ };
482
+
483
+ // src/primitives/thread/ThreadViewport.tsx
484
+ import { jsx as jsx2 } from "react/jsx-runtime";
485
+ var ThreadViewport = forwardRef2(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
486
+ const autoScrollRef = useThreadViewportAutoScroll({
487
+ autoScroll
488
+ });
489
+ const ref = useComposedRefs2(forwardedRef, autoScrollRef);
490
+ return /* @__PURE__ */ jsx2(Primitive2.div, { ...rest, ref, children });
459
491
  });
460
492
  ThreadViewport.displayName = "ThreadViewport";
461
493
 
@@ -463,7 +495,7 @@ ThreadViewport.displayName = "ThreadViewport";
463
495
  import { memo } from "react";
464
496
 
465
497
  // src/context/providers/MessageProvider.tsx
466
- import { useEffect as useEffect3, useState } from "react";
498
+ import { useEffect as useEffect2, useState } from "react";
467
499
  import { create as create3 } from "zustand";
468
500
 
469
501
  // src/context/stores/EditComposer.ts
@@ -518,7 +550,7 @@ var makeMessageUtilsStore = () => create2((set) => ({
518
550
  }));
519
551
 
520
552
  // src/context/providers/MessageProvider.tsx
521
- import { jsx as jsx4 } from "react/jsx-runtime";
553
+ import { jsx as jsx3 } from "react/jsx-runtime";
522
554
  var getIsLast = (thread, message) => {
523
555
  return thread.messages[thread.messages.length - 1]?.id === message.id;
524
556
  };
@@ -564,6 +596,7 @@ var useMessageContext2 = (messageIndex) => {
564
596
  );
565
597
  useThreadActions.getState().append({
566
598
  parentId,
599
+ role: "user",
567
600
  content: [{ type: "text", text }, ...nonTextParts]
568
601
  });
569
602
  }
@@ -576,7 +609,7 @@ var useMessageContext2 = (messageIndex) => {
576
609
  );
577
610
  return { useMessage, useMessageUtils, useEditComposer };
578
611
  });
579
- useEffect3(() => {
612
+ useEffect2(() => {
580
613
  return useThread.subscribe((thread) => {
581
614
  syncMessage(
582
615
  thread,
@@ -593,7 +626,7 @@ var MessageProvider = ({
593
626
  children
594
627
  }) => {
595
628
  const context = useMessageContext2(messageIndex);
596
- return /* @__PURE__ */ jsx4(MessageContext.Provider, { value: context, children });
629
+ return /* @__PURE__ */ jsx3(MessageContext.Provider, { value: context, children });
597
630
  };
598
631
 
599
632
  // src/primitives/composer/ComposerIf.tsx
@@ -609,7 +642,7 @@ var MessageIf = ({ children, ...query }) => {
609
642
  };
610
643
 
611
644
  // src/primitives/thread/ThreadMessages.tsx
612
- import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
645
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
613
646
  var getComponents = (components) => {
614
647
  return {
615
648
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
@@ -622,12 +655,12 @@ var ThreadMessageImpl = ({
622
655
  components
623
656
  }) => {
624
657
  const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
625
- return /* @__PURE__ */ jsxs2(MessageProvider, { messageIndex, children: [
626
- /* @__PURE__ */ jsxs2(MessageIf, { user: true, children: [
627
- /* @__PURE__ */ jsx5(ComposerIf, { editing: false, children: /* @__PURE__ */ jsx5(UserMessage, {}) }),
628
- /* @__PURE__ */ jsx5(ComposerIf, { editing: true, children: /* @__PURE__ */ jsx5(EditComposer, {}) })
658
+ return /* @__PURE__ */ jsxs(MessageProvider, { messageIndex, children: [
659
+ /* @__PURE__ */ jsxs(MessageIf, { user: true, children: [
660
+ /* @__PURE__ */ jsx4(ComposerIf, { editing: false, children: /* @__PURE__ */ jsx4(UserMessage, {}) }),
661
+ /* @__PURE__ */ jsx4(ComposerIf, { editing: true, children: /* @__PURE__ */ jsx4(EditComposer, {}) })
629
662
  ] }),
630
- /* @__PURE__ */ jsx5(MessageIf, { assistant: true, children: /* @__PURE__ */ jsx5(AssistantMessage, {}) })
663
+ /* @__PURE__ */ jsx4(MessageIf, { assistant: true, children: /* @__PURE__ */ jsx4(AssistantMessage, {}) })
631
664
  ] });
632
665
  };
633
666
  var ThreadMessage = memo(
@@ -640,7 +673,7 @@ var ThreadMessages = ({ components }) => {
640
673
  if (messagesLength === 0) return null;
641
674
  return new Array(messagesLength).fill(null).map((_, idx) => {
642
675
  const messageIndex = idx;
643
- return /* @__PURE__ */ jsx5(
676
+ return /* @__PURE__ */ jsx4(
644
677
  ThreadMessage,
645
678
  {
646
679
  messageIndex,
@@ -652,21 +685,21 @@ var ThreadMessages = ({ components }) => {
652
685
  };
653
686
 
654
687
  // src/utils/createActionButton.tsx
655
- import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
688
+ import { composeEventHandlers } from "@radix-ui/primitive";
656
689
  import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
657
690
  import { forwardRef as forwardRef3 } from "react";
658
- import { jsx as jsx6 } from "react/jsx-runtime";
691
+ import { jsx as jsx5 } from "react/jsx-runtime";
659
692
  var createActionButton = (displayName, useActionButton) => {
660
693
  const ActionButton = forwardRef3((props, forwardedRef) => {
661
694
  const callback = useActionButton(props);
662
- return /* @__PURE__ */ jsx6(
695
+ return /* @__PURE__ */ jsx5(
663
696
  Primitive3.button,
664
697
  {
665
698
  type: "button",
666
699
  disabled: !callback,
667
700
  ...props,
668
701
  ref: forwardedRef,
669
- onClick: composeEventHandlers2(props.onClick, () => {
702
+ onClick: composeEventHandlers(props.onClick, () => {
670
703
  callback?.();
671
704
  })
672
705
  }
@@ -699,33 +732,26 @@ __export(composer_exports, {
699
732
  });
700
733
 
701
734
  // src/primitives/composer/ComposerRoot.tsx
702
- import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
703
- import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
735
+ import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
704
736
  import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
705
737
  import {
706
- forwardRef as forwardRef4,
707
- useRef as useRef2
738
+ forwardRef as forwardRef4
708
739
  } from "react";
709
- import { jsx as jsx7 } from "react/jsx-runtime";
740
+ import { jsx as jsx6 } from "react/jsx-runtime";
710
741
  var ComposerRoot = forwardRef4(
711
742
  ({ onSubmit, ...rest }, forwardedRef) => {
712
- const { useViewport } = useThreadContext();
713
- const { useComposer } = useComposerContext();
714
- const formRef = useRef2(null);
715
- const ref = useComposedRefs2(forwardedRef, formRef);
743
+ const send = useComposerSend();
716
744
  const handleSubmit = (e) => {
717
- const composerState = useComposer.getState();
718
- if (!composerState.isEditing) return;
745
+ if (!send) return;
719
746
  e.preventDefault();
720
- composerState.send();
721
- useViewport.getState().scrollToBottom();
747
+ send();
722
748
  };
723
- return /* @__PURE__ */ jsx7(
749
+ return /* @__PURE__ */ jsx6(
724
750
  Primitive4.form,
725
751
  {
726
752
  ...rest,
727
- ref,
728
- onSubmit: composeEventHandlers3(onSubmit, handleSubmit)
753
+ ref: forwardedRef,
754
+ onSubmit: composeEventHandlers2(onSubmit, handleSubmit)
729
755
  }
730
756
  );
731
757
  }
@@ -733,17 +759,18 @@ var ComposerRoot = forwardRef4(
733
759
  ComposerRoot.displayName = "ComposerRoot";
734
760
 
735
761
  // src/primitives/composer/ComposerInput.tsx
736
- import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
762
+ import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
737
763
  import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
738
764
  import { Slot } from "@radix-ui/react-slot";
739
765
  import {
740
766
  forwardRef as forwardRef5,
741
- useCallback as useCallback10,
742
- useEffect as useEffect4,
767
+ useCallback as useCallback12,
768
+ useEffect as useEffect3,
743
769
  useRef as useRef3
744
770
  } from "react";
745
771
  import TextareaAutosize from "react-textarea-autosize";
746
- import { jsx as jsx8 } from "react/jsx-runtime";
772
+ import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
773
+ import { jsx as jsx7 } from "react/jsx-runtime";
747
774
  var ComposerInput = forwardRef5(
748
775
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
749
776
  const { useThread } = useThreadContext();
@@ -755,14 +782,15 @@ var ComposerInput = forwardRef5(
755
782
  const Component = asChild ? Slot : TextareaAutosize;
756
783
  const textareaRef = useRef3(null);
757
784
  const ref = useComposedRefs3(forwardedRef, textareaRef);
785
+ useEscapeKeydown((e) => {
786
+ const composer = useComposer.getState();
787
+ if (composer.cancel()) {
788
+ e.preventDefault();
789
+ }
790
+ });
758
791
  const handleKeyPress = (e) => {
759
792
  if (disabled) return;
760
- if (e.key === "Escape") {
761
- const composer = useComposer.getState();
762
- if (composer.cancel()) {
763
- e.preventDefault();
764
- }
765
- } else if (e.key === "Enter" && e.shiftKey === false) {
793
+ if (e.key === "Enter" && e.shiftKey === false) {
766
794
  const isRunning = useThread.getState().isRunning;
767
795
  if (!isRunning) {
768
796
  e.preventDefault();
@@ -771,7 +799,7 @@ var ComposerInput = forwardRef5(
771
799
  }
772
800
  };
773
801
  const autoFocusEnabled = autoFocus && !disabled;
774
- const focus = useCallback10(() => {
802
+ const focus = useCallback12(() => {
775
803
  const textarea = textareaRef.current;
776
804
  if (!textarea || !autoFocusEnabled) return;
777
805
  textarea.focus();
@@ -780,13 +808,13 @@ var ComposerInput = forwardRef5(
780
808
  textareaRef.current.value.length
781
809
  );
782
810
  }, [autoFocusEnabled]);
783
- useEffect4(() => focus(), [focus]);
811
+ useEffect3(() => focus(), [focus]);
784
812
  useOnScrollToBottom(() => {
785
813
  if (type === "new") {
786
814
  focus();
787
815
  }
788
816
  });
789
- return /* @__PURE__ */ jsx8(
817
+ return /* @__PURE__ */ jsx7(
790
818
  Component,
791
819
  {
792
820
  value,
@@ -794,12 +822,12 @@ var ComposerInput = forwardRef5(
794
822
  ref,
795
823
  autoFocus,
796
824
  disabled,
797
- onChange: composeEventHandlers4(onChange, (e) => {
825
+ onChange: composeEventHandlers3(onChange, (e) => {
798
826
  const composerState = useComposer.getState();
799
827
  if (!composerState.isEditing) return;
800
828
  return composerState.setValue(e.target.value);
801
829
  }),
802
- onKeyDown: composeEventHandlers4(onKeyDown, handleKeyPress)
830
+ onKeyDown: composeEventHandlers3(onKeyDown, handleKeyPress)
803
831
  }
804
832
  );
805
833
  }
@@ -807,7 +835,25 @@ var ComposerInput = forwardRef5(
807
835
  ComposerInput.displayName = "ComposerInput";
808
836
 
809
837
  // src/primitives/composer/ComposerSend.tsx
810
- var ComposerSend = createActionButton("ComposerSend", useComposerSend);
838
+ import { forwardRef as forwardRef6 } from "react";
839
+ import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
840
+ import { jsx as jsx8 } from "react/jsx-runtime";
841
+ var ComposerSend = forwardRef6(
842
+ ({ disabled, ...rest }, ref) => {
843
+ const { useComposer } = useComposerContext();
844
+ const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
845
+ return /* @__PURE__ */ jsx8(
846
+ Primitive5.button,
847
+ {
848
+ type: "submit",
849
+ ...rest,
850
+ ref,
851
+ disabled: disabled || !hasValue
852
+ }
853
+ );
854
+ }
855
+ );
856
+ ComposerSend.displayName = "ComposerSend";
811
857
 
812
858
  // src/primitives/composer/ComposerCancel.tsx
813
859
  var ComposerCancel = createActionButton(
@@ -825,11 +871,11 @@ __export(message_exports, {
825
871
  });
826
872
 
827
873
  // src/primitives/message/MessageRoot.tsx
828
- import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
829
- import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
830
- import { forwardRef as forwardRef6 } from "react";
874
+ import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
875
+ import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
876
+ import { forwardRef as forwardRef7 } from "react";
831
877
  import { jsx as jsx9 } from "react/jsx-runtime";
832
- var MessageRoot = forwardRef6(
878
+ var MessageRoot = forwardRef7(
833
879
  ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
834
880
  const { useMessageUtils } = useMessageContext();
835
881
  const setIsHovering = useMessageUtils((s) => s.setIsHovering);
@@ -840,12 +886,12 @@ var MessageRoot = forwardRef6(
840
886
  setIsHovering(false);
841
887
  };
842
888
  return /* @__PURE__ */ jsx9(
843
- Primitive5.div,
889
+ Primitive6.div,
844
890
  {
845
891
  ...rest,
846
892
  ref,
847
- onMouseEnter: composeEventHandlers5(onMouseEnter, handleMouseEnter),
848
- onMouseLeave: composeEventHandlers5(onMouseLeave, handleMouseLeave)
893
+ onMouseEnter: composeEventHandlers4(onMouseEnter, handleMouseEnter),
894
+ onMouseLeave: composeEventHandlers4(onMouseLeave, handleMouseLeave)
849
895
  }
850
896
  );
851
897
  }
@@ -856,7 +902,7 @@ MessageRoot.displayName = "MessageRoot";
856
902
  import { memo as memo2 } from "react";
857
903
 
858
904
  // src/context/providers/ContentPartProvider.tsx
859
- import { useEffect as useEffect5, useState as useState2 } from "react";
905
+ import { useEffect as useEffect4, useState as useState2 } from "react";
860
906
  import { create as create4 } from "zustand";
861
907
  import { jsx as jsx10 } from "react/jsx-runtime";
862
908
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
@@ -882,7 +928,7 @@ var useContentPartContext2 = (partIndex) => {
882
928
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
883
929
  return { useContentPart };
884
930
  });
885
- useEffect5(() => {
931
+ useEffect4(() => {
886
932
  syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
887
933
  return useMessage.subscribe((message) => {
888
934
  syncContentPart(message, context.useContentPart, partIndex);
@@ -911,19 +957,19 @@ var ContentPartInProgressIndicator = () => {
911
957
  };
912
958
 
913
959
  // src/primitives/contentPart/ContentPartText.tsx
914
- import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
915
- import { forwardRef as forwardRef7 } from "react";
960
+ import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
961
+ import { forwardRef as forwardRef8 } from "react";
916
962
  import { jsx as jsx11 } from "react/jsx-runtime";
917
- var ContentPartText = forwardRef7((props, forwardedRef) => {
963
+ var ContentPartText = forwardRef8((props, forwardedRef) => {
918
964
  const text = useContentPartText();
919
- return /* @__PURE__ */ jsx11(Primitive6.span, { ...props, ref: forwardedRef, children: text });
965
+ return /* @__PURE__ */ jsx11(Primitive7.span, { ...props, ref: forwardedRef, children: text });
920
966
  });
921
967
  ContentPartText.displayName = "ContentPartText";
922
968
 
923
969
  // src/primitives/message/MessageContent.tsx
924
- import { Fragment, jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
970
+ import { Fragment, jsx as jsx12, jsxs as jsxs2 } from "react/jsx-runtime";
925
971
  var defaultComponents = {
926
- Text: () => /* @__PURE__ */ jsxs3(Fragment, { children: [
972
+ Text: () => /* @__PURE__ */ jsxs2(Fragment, { children: [
927
973
  /* @__PURE__ */ jsx12(ContentPartText, {}),
928
974
  /* @__PURE__ */ jsx12(ContentPartInProgressIndicator, {})
929
975
  ] }),
@@ -994,16 +1040,16 @@ var MessageContent = ({ components }) => {
994
1040
  };
995
1041
 
996
1042
  // src/primitives/message/MessageInProgress.tsx
997
- import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
1043
+ import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
998
1044
  import {
999
- forwardRef as forwardRef8,
1045
+ forwardRef as forwardRef9,
1000
1046
  useMemo as useMemo2
1001
1047
  } from "react";
1002
1048
  import { jsx as jsx13 } from "react/jsx-runtime";
1003
- var MessageInProgress = forwardRef8((props, ref) => {
1049
+ var MessageInProgress = forwardRef9((props, ref) => {
1004
1050
  const { useMessageUtils } = useMessageContext();
1005
1051
  useMemo2(() => {
1006
- useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ jsx13(Primitive7.span, { ...props, ref }));
1052
+ useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ jsx13(Primitive8.span, { ...props, ref }));
1007
1053
  }, [useMessageUtils, props, ref]);
1008
1054
  return null;
1009
1055
  });
@@ -1046,11 +1092,11 @@ var BranchPickerNumber = () => {
1046
1092
  };
1047
1093
 
1048
1094
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1049
- import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
1050
- import { forwardRef as forwardRef9 } from "react";
1095
+ import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
1096
+ import { forwardRef as forwardRef10 } from "react";
1051
1097
  import { jsx as jsx16 } from "react/jsx-runtime";
1052
- var BranchPickerRoot = forwardRef9(({ hideWhenSingleBranch, ...rest }, ref) => {
1053
- return /* @__PURE__ */ jsx16(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive8.div, { ...rest, ref }) });
1098
+ var BranchPickerRoot = forwardRef10(({ hideWhenSingleBranch, ...rest }, ref) => {
1099
+ return /* @__PURE__ */ jsx16(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive9.div, { ...rest, ref }) });
1054
1100
  });
1055
1101
  BranchPickerRoot.displayName = "BranchPickerRoot";
1056
1102
 
@@ -1064,8 +1110,8 @@ __export(actionBar_exports, {
1064
1110
  });
1065
1111
 
1066
1112
  // src/primitives/actionBar/ActionBarRoot.tsx
1067
- import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
1068
- import { forwardRef as forwardRef10 } from "react";
1113
+ import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
1114
+ import { forwardRef as forwardRef11 } from "react";
1069
1115
  import { jsx as jsx17 } from "react/jsx-runtime";
1070
1116
  var useActionBarFloatStatus = ({
1071
1117
  hideWhenRunning,
@@ -1087,7 +1133,7 @@ var useActionBarFloatStatus = ({
1087
1133
  }
1088
1134
  );
1089
1135
  };
1090
- var ActionBarRoot = forwardRef10(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
1136
+ var ActionBarRoot = forwardRef11(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
1091
1137
  const hideAndfloatStatus = useActionBarFloatStatus({
1092
1138
  hideWhenRunning,
1093
1139
  autohide,
@@ -1095,7 +1141,7 @@ var ActionBarRoot = forwardRef10(({ hideWhenRunning, autohide, autohideFloat, ..
1095
1141
  });
1096
1142
  if (hideAndfloatStatus === "hidden" /* Hidden */) return null;
1097
1143
  return /* @__PURE__ */ jsx17(
1098
- Primitive9.div,
1144
+ Primitive10.div,
1099
1145
  {
1100
1146
  ...hideAndfloatStatus === "floating" /* Floating */ ? { "data-floating": "true" } : null,
1101
1147
  ...rest,
@@ -1133,12 +1179,12 @@ __export(contentPart_exports, {
1133
1179
  });
1134
1180
 
1135
1181
  // src/primitives/contentPart/ContentPartImage.tsx
1136
- import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
1137
- import { forwardRef as forwardRef11 } from "react";
1182
+ import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
1183
+ import { forwardRef as forwardRef12 } from "react";
1138
1184
  import { jsx as jsx18 } from "react/jsx-runtime";
1139
- var ContentPartImage = forwardRef11((props, forwardedRef) => {
1185
+ var ContentPartImage = forwardRef12((props, forwardedRef) => {
1140
1186
  const image = useContentPartImage();
1141
- return /* @__PURE__ */ jsx18(Primitive10.img, { src: image, ...props, ref: forwardedRef });
1187
+ return /* @__PURE__ */ jsx18(Primitive11.img, { src: image, ...props, ref: forwardedRef });
1142
1188
  });
1143
1189
  ContentPartImage.displayName = "ContentPartImage";
1144
1190
 
@@ -1440,7 +1486,7 @@ var useLocalRuntime = (adapter) => {
1440
1486
  import { memo as memo3 } from "react";
1441
1487
 
1442
1488
  // src/context/providers/AssistantProvider.tsx
1443
- import { useEffect as useEffect7, useInsertionEffect as useInsertionEffect3, useRef as useRef5, useState as useState5 } from "react";
1489
+ import { useEffect as useEffect6, useInsertionEffect as useInsertionEffect3, useRef as useRef5, useState as useState5 } from "react";
1444
1490
 
1445
1491
  // src/context/stores/AssistantModelConfig.ts
1446
1492
  import { create as create5 } from "zustand";
@@ -1505,7 +1551,7 @@ var makeAssistantToolUIsStore = () => create6((set) => {
1505
1551
  });
1506
1552
 
1507
1553
  // src/context/providers/ThreadProvider.tsx
1508
- import { useEffect as useEffect6, useInsertionEffect as useInsertionEffect2, useRef as useRef4, useState as useState4 } from "react";
1554
+ import { useEffect as useEffect5, useInsertionEffect as useInsertionEffect2, useRef as useRef4, useState as useState4 } from "react";
1509
1555
 
1510
1556
  // src/context/stores/Composer.ts
1511
1557
  import { create as create7 } from "zustand";
@@ -1518,6 +1564,7 @@ var makeComposerStore = (useThread, useThreadActions) => create7()((set, get, st
1518
1564
  setValue("");
1519
1565
  useThreadActions.getState().append({
1520
1566
  parentId: useThread.getState().messages.at(-1)?.id ?? null,
1567
+ role: "user",
1521
1568
  content: [{ type: "text", text: value }]
1522
1569
  });
1523
1570
  },
@@ -1575,7 +1622,7 @@ var makeThreadActionStore = (runtimeRef) => {
1575
1622
  };
1576
1623
 
1577
1624
  // src/context/providers/ThreadProvider.tsx
1578
- import { jsx as jsx19, jsxs as jsxs4 } from "react/jsx-runtime";
1625
+ import { jsx as jsx19, jsxs as jsxs3 } from "react/jsx-runtime";
1579
1626
  var ThreadProvider = ({
1580
1627
  children,
1581
1628
  runtime
@@ -1596,7 +1643,7 @@ var ThreadProvider = ({
1596
1643
  useViewport
1597
1644
  };
1598
1645
  });
1599
- useEffect6(() => {
1646
+ useEffect5(() => {
1600
1647
  const onRuntimeUpdate = () => {
1601
1648
  context.useThread.setState(
1602
1649
  Object.freeze({
@@ -1610,7 +1657,7 @@ var ThreadProvider = ({
1610
1657
  return runtime.subscribe(onRuntimeUpdate);
1611
1658
  }, [context, runtime]);
1612
1659
  const RuntimeSynchronizer = runtime.unstable_synchronizer;
1613
- return /* @__PURE__ */ jsxs4(ThreadContext.Provider, { value: context, children: [
1660
+ return /* @__PURE__ */ jsxs3(ThreadContext.Provider, { value: context, children: [
1614
1661
  RuntimeSynchronizer && /* @__PURE__ */ jsx19(RuntimeSynchronizer, {}),
1615
1662
  children
1616
1663
  ] });
@@ -1629,7 +1676,7 @@ var AssistantProvider = ({ children, runtime }) => {
1629
1676
  return { useModelConfig, useToolUIs };
1630
1677
  });
1631
1678
  const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
1632
- useEffect7(() => {
1679
+ useEffect6(() => {
1633
1680
  return runtime.registerModelConfigProvider(getModelCOnfig);
1634
1681
  }, [runtime, getModelCOnfig]);
1635
1682
  return /* @__PURE__ */ jsx20(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx20(ThreadProvider, { runtime, children }) });