@anvia/react-ui 0.7.1 → 1.0.0-rc.10

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.
Files changed (72) hide show
  1. package/README.md +52 -39
  2. package/dist/attachment/index.d.ts +5 -5
  3. package/dist/attachment/index.js +4 -4
  4. package/dist/{attachment-BP597fV3.d.ts → attachment-mbjsroli.d.ts} +1 -1
  5. package/dist/chat/index.d.ts +13 -12
  6. package/dist/chat/index.js +11 -9
  7. package/dist/chat-tfA570mg.d.ts +86 -0
  8. package/dist/{chunk-7RMRM7W3.js → chunk-647LAYRV.js} +90 -65
  9. package/dist/chunk-647LAYRV.js.map +1 -0
  10. package/dist/chunk-6XOJFLX4.js +22 -0
  11. package/dist/chunk-6XOJFLX4.js.map +1 -0
  12. package/dist/chunk-CKA4CE26.js +25 -0
  13. package/dist/chunk-CKA4CE26.js.map +1 -0
  14. package/dist/{chunk-JWZDNM5D.js → chunk-CRXNFZRW.js} +145 -125
  15. package/dist/chunk-CRXNFZRW.js.map +1 -0
  16. package/dist/{chunk-7HR34SOF.js → chunk-CVXLQCDI.js} +13 -21
  17. package/dist/chunk-CVXLQCDI.js.map +1 -0
  18. package/dist/{chunk-ULGJLLZE.js → chunk-F6AKBUO3.js} +12 -12
  19. package/dist/chunk-F6AKBUO3.js.map +1 -0
  20. package/dist/{chunk-FABSIZZ7.js → chunk-HWJIMLHC.js} +97 -90
  21. package/dist/chunk-HWJIMLHC.js.map +1 -0
  22. package/dist/{chunk-SBYUKODG.js → chunk-MISX4WUT.js} +10 -15
  23. package/dist/chunk-MISX4WUT.js.map +1 -0
  24. package/dist/{chunk-R3NA6BWW.js → chunk-OQE6SHZE.js} +54 -56
  25. package/dist/chunk-OQE6SHZE.js.map +1 -0
  26. package/dist/{chunk-VEYJNQVW.js → chunk-S4XLE2RN.js} +11 -16
  27. package/dist/chunk-S4XLE2RN.js.map +1 -0
  28. package/dist/{chunk-43U2XQP2.js → chunk-SOG2GVE4.js} +69 -25
  29. package/dist/chunk-SOG2GVE4.js.map +1 -0
  30. package/dist/{chunk-56CV6S76.js → chunk-UCBAG42A.js} +9 -21
  31. package/dist/chunk-UCBAG42A.js.map +1 -0
  32. package/dist/completion/index.d.ts +4 -3
  33. package/dist/completion/index.js +4 -4
  34. package/dist/completion-input-DHlwrhxB.d.ts +24 -0
  35. package/dist/{composer-CzsbDFPt.d.ts → composer-CigccTLT.d.ts} +19 -7
  36. package/dist/human-input/index.d.ts +10 -8
  37. package/dist/human-input/index.js +5 -4
  38. package/dist/human-input-D7jgYsfM.d.ts +27 -0
  39. package/dist/image/index.d.ts +6 -6
  40. package/dist/image/index.js +4 -4
  41. package/dist/{image-DanUxcl2.d.ts → image-VZv6Ddsn.d.ts} +1 -1
  42. package/dist/index.d.ts +19 -18
  43. package/dist/index.js +59 -63
  44. package/dist/index.js.map +1 -1
  45. package/dist/message/index.d.ts +12 -11
  46. package/dist/message/index.js +8 -6
  47. package/dist/{message-CkEnKhAn.d.ts → message-CNRnZQwU.d.ts} +1 -1
  48. package/dist/selection-toolbar/index.d.ts +2 -2
  49. package/dist/selection-toolbar/index.js +5 -4
  50. package/dist/shared.d.ts +9 -8
  51. package/dist/shared.js +1 -1
  52. package/dist/stream/index.d.ts +2 -0
  53. package/dist/stream/index.js +1 -1
  54. package/dist/{thread-uEm8hH0s.d.ts → thread-Bz6-1zaJ.d.ts} +1 -0
  55. package/dist/thread-list/index.d.ts +3 -3
  56. package/dist/thread-list/index.js +6 -6
  57. package/package.json +18 -18
  58. package/dist/chat-B3kucz1w.d.ts +0 -13
  59. package/dist/chunk-43U2XQP2.js.map +0 -1
  60. package/dist/chunk-56CV6S76.js.map +0 -1
  61. package/dist/chunk-7HR34SOF.js.map +0 -1
  62. package/dist/chunk-7RMRM7W3.js.map +0 -1
  63. package/dist/chunk-FABSIZZ7.js.map +0 -1
  64. package/dist/chunk-JWZDNM5D.js.map +0 -1
  65. package/dist/chunk-R3NA6BWW.js.map +0 -1
  66. package/dist/chunk-SBYUKODG.js.map +0 -1
  67. package/dist/chunk-ULGJLLZE.js.map +0 -1
  68. package/dist/chunk-VEYJNQVW.js.map +0 -1
  69. package/dist/completion-input-WjK6kUyG.d.ts +0 -23
  70. package/dist/human-input-CydeYm_7.d.ts +0 -20
  71. package/dist/stream/styles.css +0 -17
  72. package/dist/styles.css +0 -130
@@ -1,10 +1,11 @@
1
1
  import {
2
- Message,
2
+ MessagePrimitive,
3
+ isComposerEntityData,
3
4
  shiftComposerEntityRanges
4
- } from "./chunk-JWZDNM5D.js";
5
+ } from "./chunk-CRXNFZRW.js";
5
6
  import {
6
- Attachment
7
- } from "./chunk-SBYUKODG.js";
7
+ AttachmentPrimitive
8
+ } from "./chunk-MISX4WUT.js";
8
9
  import {
9
10
  composeRefs,
10
11
  renderPrimitive
@@ -17,7 +18,7 @@ import {
17
18
  useChatContext,
18
19
  useComposer,
19
20
  useThread
20
- } from "./chunk-43U2XQP2.js";
21
+ } from "./chunk-SOG2GVE4.js";
21
22
 
22
23
  // src/chat/composer.tsx
23
24
  import { mergeAttributes } from "@tiptap/core";
@@ -89,8 +90,9 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
89
90
  const entitiesControlled = entitiesProp !== void 0;
90
91
  const quoteControlled = quoteProp !== void 0;
91
92
  const hasMessageContent = input.trim().length > 0 || attachments.length > 0 || entities.length > 0 || quote !== void 0;
92
- const canSubmit = hasMessageContent && chat.status !== "streaming";
93
- const canStop = chat.status === "streaming";
93
+ const active = chat.status === "submitted" || chat.status === "streaming";
94
+ const canSubmit = hasMessageContent && !active;
95
+ const canStop = active;
94
96
  const setInput = useCallback(
95
97
  (nextInput) => {
96
98
  if (!inputControlled) {
@@ -160,9 +162,10 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
160
162
  }, [clearQuote, setAttachments, setEntities, setInput]);
161
163
  const submit = useCallback(async () => {
162
164
  const prompt = input;
163
- if (prompt.trim().length === 0 && attachments.length === 0 && entities.length === 0 && quote === void 0 || chat.status === "streaming") {
165
+ if (prompt.trim().length === 0 && attachments.length === 0 && entities.length === 0 && quote === void 0 || chat.status === "submitted" || chat.status === "streaming") {
164
166
  return;
165
167
  }
168
+ assertComposerEntitiesData(entities);
166
169
  if (submitMessage !== void 0) {
167
170
  await submitMessage({
168
171
  input: prompt,
@@ -188,7 +191,7 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
188
191
  const metadata = composerSubmitMetadata(submittedQuote, submittedEntities);
189
192
  let payload;
190
193
  if (submittedAttachments.length === 0) {
191
- payload = metadata === void 0 ? prompt : { text: submittedText, metadata };
194
+ payload = metadata === void 0 ? { text: submittedText } : { text: submittedText, metadata };
192
195
  } else {
193
196
  const attachmentPayload = {
194
197
  text: submittedText,
@@ -271,7 +274,6 @@ var ComposerRoot = forwardRef(function ComposerRoot2({
271
274
  {
272
275
  ...props,
273
276
  onSubmit: handleSubmit,
274
- "data-anvia-composer": "",
275
277
  "data-state": chat.status
276
278
  },
277
279
  ref
@@ -289,9 +291,7 @@ var ComposerQuotePreview = forwardRef(
289
291
  "blockquote",
290
292
  {
291
293
  ...props,
292
- children: renderedChildren,
293
- "data-anvia-composer-quote": "",
294
- "data-message-id": quote.messageId
294
+ children: renderedChildren
295
295
  },
296
296
  ref
297
297
  );
@@ -319,7 +319,6 @@ var ComposerClearQuote = forwardRef(
319
319
  disabled,
320
320
  onClick: handleClick,
321
321
  type: props.type ?? "button",
322
- "data-anvia-clear-quote": "",
323
322
  "data-state": disabled ? "disabled" : "enabled"
324
323
  },
325
324
  ref
@@ -356,12 +355,11 @@ var ComposerInput = forwardRef(function ComposerInput2({
356
355
  {
357
356
  extensions,
358
357
  content: plainTextToComposerContent(composer.input),
359
- editable: composer.status !== "streaming",
358
+ editable: composer.status !== "submitted" && composer.status !== "streaming",
360
359
  editorProps: {
361
360
  attributes: {
362
361
  "aria-label": props["aria-label"] ?? "Message",
363
362
  "aria-multiline": "true",
364
- "data-anvia-composer-editor": "",
365
363
  role: "textbox"
366
364
  },
367
365
  handleKeyDown: (_view, event) => submitComposerFromEditorKeyDown(event, composerRef)
@@ -383,7 +381,7 @@ var ComposerInput = forwardRef(function ComposerInput2({
383
381
  [extensions]
384
382
  );
385
383
  const ariaDisabled = props["aria-disabled"] === true || props["aria-disabled"] === "true";
386
- const composerDisabled = disabled === true || ariaDisabled || composer.status === "streaming";
384
+ const composerDisabled = disabled === true || ariaDisabled || composer.status === "submitted" || composer.status === "streaming";
387
385
  const inputStyle = useMemo(() => {
388
386
  if (!autoResize) {
389
387
  return style;
@@ -445,9 +443,8 @@ var ComposerInput = forwardRef(function ComposerInput2({
445
443
  ...props,
446
444
  children: /* @__PURE__ */ jsx(EditorContent, { editor }),
447
445
  "aria-disabled": composerDisabled ? true : props["aria-disabled"],
448
- "data-anvia-composer-input": "",
446
+ "data-role": "editor",
449
447
  "data-state": composerDisabled ? "disabled" : "enabled",
450
- "data-auto-resize": autoResize ? "" : void 0,
451
448
  onKeyDown: handleKeyDown,
452
449
  style: inputStyle
453
450
  },
@@ -510,13 +507,11 @@ var ComposerTextareaInput = forwardRef(
510
507
  {
511
508
  ...props,
512
509
  "aria-label": props["aria-label"] ?? "Message",
513
- disabled: props.disabled ?? composer.status === "streaming",
510
+ disabled: props.disabled ?? (composer.status === "submitted" || composer.status === "streaming"),
514
511
  onChange: handleChange,
515
512
  onKeyDown: handleKeyDown,
516
513
  rows: autoResize ? minRows : rows,
517
- value: composer.input,
518
- "data-anvia-composer-input": "",
519
- "data-anvia-composer-textarea-input": ""
514
+ value: composer.input
520
515
  },
521
516
  composedInputRef
522
517
  );
@@ -556,9 +551,15 @@ var ComposerEntityExtension = Mention.extend({
556
551
  renderHTML: (attributes) => attributes.text === void 0 || attributes.text === null ? {} : { "data-text": String(attributes.text) }
557
552
  },
558
553
  data: {
559
- default: null,
554
+ default: void 0,
560
555
  parseHTML: (element) => dataFromAttribute(element.getAttribute("data-entity-data")),
561
- renderHTML: (attributes) => attributes.data === void 0 || attributes.data === null ? {} : { "data-entity-data": JSON.stringify(attributes.data) }
556
+ renderHTML: (attributes) => {
557
+ if (attributes.data === void 0) return {};
558
+ if (!isComposerEntityData(attributes.data)) {
559
+ throw new TypeError("Composer entity data must be a JSON value.");
560
+ }
561
+ return { "data-entity-data": JSON.stringify(attributes.data) };
562
+ }
562
563
  }
563
564
  };
564
565
  }
@@ -575,16 +576,12 @@ function composerInputExtensions({
575
576
  HardBreak,
576
577
  Placeholder.configure(placeholder === void 0 ? {} : { placeholder }),
577
578
  ComposerEntityExtension.configure({
578
- HTMLAttributes: {
579
- "data-anvia-composer-entity": ""
580
- },
579
+ HTMLAttributes: {},
581
580
  deleteTriggerWithBackspace: true,
582
581
  renderText: ({ node }) => composerEntityText(node.attrs),
583
582
  renderHTML: ({ node, options }) => [
584
583
  "span",
585
- mergeAttributes(options.HTMLAttributes, {
586
- "data-anvia-composer-entity": ""
587
- }),
584
+ mergeAttributes(options.HTMLAttributes, {}),
588
585
  composerEntityText(node.attrs)
589
586
  ],
590
587
  suggestions: triggers.map((trigger) => composerSuggestion(trigger, composerRef))
@@ -729,6 +726,9 @@ function handleComposerTriggerKeyDown(trigger, { event }, composerRef) {
729
726
  return false;
730
727
  }
731
728
  function triggerItemToEntityAttrs(trigger, item) {
729
+ if (item.data !== void 0 && !isComposerEntityData(item.data)) {
730
+ throw new TypeError("Composer trigger item data must be a JSON value.");
731
+ }
732
732
  return {
733
733
  id: item.id,
734
734
  label: item.label,
@@ -829,7 +829,7 @@ function composerEntityFromAttrs(attrs, from, previousEntities, triggers) {
829
829
  const previous = previousEntities.find(
830
830
  (entity2) => entity2.id === id && entity2.triggerId === triggerId && entity2.trigger === trigger
831
831
  );
832
- const data = attrs?.data ?? previous?.data;
832
+ const data = attrs?.data === void 0 ? previous?.data : attrs.data;
833
833
  const entity = {
834
834
  id,
835
835
  triggerId,
@@ -857,12 +857,13 @@ function stringAttr(value) {
857
857
  }
858
858
  function dataFromAttribute(value) {
859
859
  if (value === null) {
860
- return null;
860
+ return void 0;
861
861
  }
862
862
  try {
863
- return JSON.parse(value);
863
+ const parsed = JSON.parse(value);
864
+ return isComposerEntityData(parsed) ? parsed : void 0;
864
865
  } catch {
865
- return null;
866
+ return void 0;
866
867
  }
867
868
  }
868
869
  function resizeComposerInput(input, { maxRows, minRows }) {
@@ -930,7 +931,30 @@ function composerSubmitMetadata(quote, entities) {
930
931
  }
931
932
  const metadata = {};
932
933
  if (quote !== void 0) metadata.quote = quote;
933
- if (entities.length > 0) metadata.composer = { entities };
934
+ if (entities.length > 0) {
935
+ metadata.composer = { entities: entities.map(composerEntityMetadata) };
936
+ }
937
+ return metadata;
938
+ }
939
+ function assertComposerEntitiesData(entities) {
940
+ for (const entity of entities) {
941
+ if (entity.data !== void 0 && !isComposerEntityData(entity.data)) {
942
+ throw new TypeError("Composer entity data must be a JSON value.");
943
+ }
944
+ }
945
+ }
946
+ function composerEntityMetadata(entity) {
947
+ const metadata = {
948
+ id: entity.id,
949
+ triggerId: entity.triggerId,
950
+ trigger: entity.trigger,
951
+ label: entity.label,
952
+ text: entity.text,
953
+ range: { from: entity.range.from, to: entity.range.to }
954
+ };
955
+ if (entity.data !== void 0) {
956
+ metadata.data = entity.data;
957
+ }
934
958
  return metadata;
935
959
  }
936
960
  var ComposerSubmit = forwardRef(
@@ -944,7 +968,6 @@ var ComposerSubmit = forwardRef(
944
968
  children: props.children ?? "Send",
945
969
  disabled,
946
970
  type: props.type ?? "submit",
947
- "data-anvia-submit": "",
948
971
  "data-state": disabled ? "disabled" : "enabled"
949
972
  },
950
973
  ref
@@ -972,7 +995,6 @@ var ComposerStop = forwardRef(function ComposerStop2({ onClick, ...props }, ref)
972
995
  disabled,
973
996
  onClick: handleClick,
974
997
  type: props.type ?? "button",
975
- "data-anvia-stop": "",
976
998
  "data-state": disabled ? "disabled" : "enabled"
977
999
  },
978
1000
  ref
@@ -1000,11 +1022,7 @@ var ComposerTriggerMenu = forwardRef(
1000
1022
  children: renderedChildren,
1001
1023
  role: props.role ?? "listbox",
1002
1024
  style: menuStyle,
1003
- "data-anvia-composer-trigger-menu": "",
1004
- "data-empty": empty ? "" : void 0,
1005
- "data-loading": activeTrigger?.loading ? "" : void 0,
1006
- "data-trigger": activeTrigger?.trigger.char,
1007
- "data-trigger-id": activeTrigger?.trigger.id
1025
+ "data-state": activeTrigger === void 0 ? "closed" : activeTrigger.loading ? "loading" : empty ? "empty" : "open"
1008
1026
  },
1009
1027
  ref
1010
1028
  );
@@ -1045,12 +1063,7 @@ var ComposerTriggerItem = forwardRef(
1045
1063
  role: props.role ?? "option",
1046
1064
  type: props.type ?? "button",
1047
1065
  "aria-selected": selected,
1048
- "data-anvia-composer-trigger-item": "",
1049
- "data-disabled": disabled ? "" : void 0,
1050
- "data-item-id": item.id,
1051
- "data-selected": selected ? "" : void 0,
1052
- "data-trigger": activeTrigger.trigger.char,
1053
- "data-trigger-id": activeTrigger.trigger.id
1066
+ "data-state": disabled ? "disabled" : selected ? "selected" : "idle"
1054
1067
  },
1055
1068
  ref
1056
1069
  );
@@ -1076,12 +1089,12 @@ var ComposerAttachments = forwardRef(
1076
1089
  composer.removeAttachment(attachment.id);
1077
1090
  }
1078
1091
  },
1079
- children: typeof children === "function" ? children(attachment) : children ?? /* @__PURE__ */ jsx(Attachment.Root, {})
1092
+ children: typeof children === "function" ? children(attachment) : children ?? /* @__PURE__ */ jsx(AttachmentPrimitive.Root, {})
1080
1093
  },
1081
1094
  attachment.id
1082
1095
  )),
1083
- "data-anvia-composer-attachments": "",
1084
- "data-empty": empty ? "" : void 0
1096
+ "data-role": "attachments",
1097
+ "data-state": empty ? "empty" : "populated"
1085
1098
  },
1086
1099
  ref
1087
1100
  );
@@ -1090,7 +1103,7 @@ var ComposerAttachments = forwardRef(
1090
1103
  var ComposerAttachmentInput = forwardRef(
1091
1104
  function ComposerAttachmentInput2({ onChange, ...props }, ref) {
1092
1105
  const composer = useComposer();
1093
- const disabled = props.disabled ?? composer.status === "streaming";
1106
+ const disabled = props.disabled ?? (composer.status === "submitted" || composer.status === "streaming");
1094
1107
  const handleChange = useCallback(
1095
1108
  async (event) => {
1096
1109
  onChange?.(event);
@@ -1114,7 +1127,6 @@ var ComposerAttachmentInput = forwardRef(
1114
1127
  void handleChange(event);
1115
1128
  },
1116
1129
  type: "file",
1117
- "data-anvia-attachment-input": "",
1118
1130
  "data-state": disabled ? "disabled" : "enabled"
1119
1131
  },
1120
1132
  ref
@@ -1125,7 +1137,7 @@ var ComposerAddAttachment = forwardRef(
1125
1137
  function ComposerAddAttachment2({ accept, multiple = false, onClick, ...props }, ref) {
1126
1138
  const composer = useComposer();
1127
1139
  const inputRef = useRef(null);
1128
- const disabled = props.disabled ?? composer.status === "streaming";
1140
+ const disabled = props.disabled ?? (composer.status === "submitted" || composer.status === "streaming");
1129
1141
  const handleClick = useCallback(
1130
1142
  (event) => {
1131
1143
  onClick?.(event);
@@ -1145,7 +1157,6 @@ var ComposerAddAttachment = forwardRef(
1145
1157
  disabled,
1146
1158
  onClick: handleClick,
1147
1159
  type: props.type ?? "button",
1148
- "data-anvia-add-attachment": "",
1149
1160
  "data-state": disabled ? "disabled" : "enabled"
1150
1161
  },
1151
1162
  ref
@@ -1168,7 +1179,7 @@ var ComposerAttachmentDropzone = forwardRef(
1168
1179
  function ComposerAttachmentDropzone2({ disabled: disabledProp = false, onDragLeave, onDragOver, onDrop, ...props }, ref) {
1169
1180
  const composer = useComposer();
1170
1181
  const [dragging, setDragging] = useState(false);
1171
- const disabled = disabledProp || composer.status === "streaming";
1182
+ const disabled = disabledProp || composer.status === "submitted" || composer.status === "streaming";
1172
1183
  const handleDragOver = useCallback(
1173
1184
  (event) => {
1174
1185
  onDragOver?.(event);
@@ -1209,9 +1220,7 @@ var ComposerAttachmentDropzone = forwardRef(
1209
1220
  onDragLeave: handleDragLeave,
1210
1221
  onDragOver: handleDragOver,
1211
1222
  onDrop: handleDrop,
1212
- "data-anvia-attachment-dropzone": "",
1213
- "data-dragging": dragging ? "" : void 0,
1214
- "data-state": disabled ? "disabled" : "enabled"
1223
+ "data-state": disabled ? "disabled" : dragging ? "dragging" : "enabled"
1215
1224
  },
1216
1225
  ref
1217
1226
  );
@@ -1257,7 +1266,7 @@ function createAttachmentId() {
1257
1266
  nextAttachmentId += 1;
1258
1267
  return `attachment_${nextAttachmentId.toString(36)}`;
1259
1268
  }
1260
- var Composer = {
1269
+ var ComposerPrimitive = {
1261
1270
  Root: ComposerRoot,
1262
1271
  Quote: ComposerQuotePreview,
1263
1272
  ClearQuote: ComposerClearQuote,
@@ -1288,6 +1297,7 @@ var ThreadRoot = forwardRef2(
1288
1297
  function ThreadRoot2(props, ref) {
1289
1298
  const chat = useChatContext();
1290
1299
  const viewportRef = useRef2(null);
1300
+ const messagesRef = useRef2(null);
1291
1301
  const [atBottom, setAtBottom] = useState2(true);
1292
1302
  const scrollToBottom = useCallback2((behavior = "smooth") => {
1293
1303
  const viewport = viewportRef.current;
@@ -1297,14 +1307,13 @@ var ThreadRoot = forwardRef2(
1297
1307
  viewport.scrollTo({ top: viewport.scrollHeight, behavior });
1298
1308
  }, []);
1299
1309
  const thread = useMemo2(
1300
- () => ({ viewportRef, atBottom, setAtBottom, scrollToBottom }),
1310
+ () => ({ viewportRef, messagesRef, atBottom, setAtBottom, scrollToBottom }),
1301
1311
  [atBottom, scrollToBottom]
1302
1312
  );
1303
1313
  return /* @__PURE__ */ jsx2(InternalThreadProvider, { value: thread, children: renderPrimitive(
1304
1314
  "div",
1305
1315
  {
1306
1316
  ...props,
1307
- "data-anvia-thread": "",
1308
1317
  "data-state": chat.status
1309
1318
  },
1310
1319
  ref
@@ -1332,7 +1341,7 @@ var ThreadViewport = forwardRef2(function ThreadViewport2({ autoScroll = true, o
1332
1341
  if (viewport === null || !autoScroll || typeof ResizeObserver !== "function") {
1333
1342
  return;
1334
1343
  }
1335
- const content = viewport.querySelector("[data-anvia-thread-messages]");
1344
+ const content = thread.messagesRef.current;
1336
1345
  if (content === null) {
1337
1346
  return;
1338
1347
  }
@@ -1359,7 +1368,6 @@ var ThreadViewport = forwardRef2(function ThreadViewport2({ autoScroll = true, o
1359
1368
  {
1360
1369
  ...props,
1361
1370
  onScroll: handleScroll,
1362
- "data-anvia-thread-viewport": "",
1363
1371
  "data-state": thread.atBottom ? "bottom" : "away"
1364
1372
  },
1365
1373
  composedRef
@@ -1370,8 +1378,7 @@ var ThreadViewportFooter = forwardRef2(
1370
1378
  return renderPrimitive(
1371
1379
  "div",
1372
1380
  {
1373
- ...props,
1374
- "data-anvia-thread-viewport-footer": ""
1381
+ ...props
1375
1382
  },
1376
1383
  ref
1377
1384
  );
@@ -1386,8 +1393,7 @@ var ThreadEmpty = forwardRef2(
1386
1393
  return renderPrimitive(
1387
1394
  "div",
1388
1395
  {
1389
- ...props,
1390
- "data-anvia-thread-empty": ""
1396
+ ...props
1391
1397
  },
1392
1398
  ref
1393
1399
  );
@@ -1401,7 +1407,6 @@ var ThreadStatus = forwardRef2(function ThreadStatus2({ children, ...props }, re
1401
1407
  {
1402
1408
  ...props,
1403
1409
  children: renderedChildren ?? chat.status,
1404
- "data-anvia-thread-status": "",
1405
1410
  "data-state": chat.status
1406
1411
  },
1407
1412
  ref
@@ -1410,15 +1415,14 @@ var ThreadStatus = forwardRef2(function ThreadStatus2({ children, ...props }, re
1410
1415
  var ThreadLoading = forwardRef2(
1411
1416
  function ThreadLoading2(props, ref) {
1412
1417
  const chat = useChatContext();
1413
- if (chat.status !== "streaming") {
1418
+ if (chat.status !== "submitted" && chat.status !== "streaming") {
1414
1419
  return null;
1415
1420
  }
1416
1421
  return renderPrimitive(
1417
1422
  "div",
1418
1423
  {
1419
1424
  ...props,
1420
- children: props.children ?? "Loading",
1421
- "data-anvia-thread-loading": ""
1425
+ children: props.children ?? "Loading"
1422
1426
  },
1423
1427
  ref
1424
1428
  );
@@ -1435,7 +1439,6 @@ var ThreadError = forwardRef2(function ThreadError2({ children, ...props }, ref)
1435
1439
  {
1436
1440
  ...props,
1437
1441
  children: renderedChildren ?? errorMessage(chat.error),
1438
- "data-anvia-thread-error": "",
1439
1442
  role: props.role ?? "alert"
1440
1443
  },
1441
1444
  ref
@@ -1443,6 +1446,13 @@ var ThreadError = forwardRef2(function ThreadError2({ children, ...props }, ref)
1443
1446
  });
1444
1447
  var ThreadMessages = forwardRef2(function ThreadMessages2({ children, keepMounted = true, ...props }, ref) {
1445
1448
  const chat = useChatContext();
1449
+ const thread = useThread();
1450
+ const composedRef = useMemo2(
1451
+ () => composeRefs(ref, (node) => {
1452
+ thread.messagesRef.current = node;
1453
+ }),
1454
+ [ref, thread.messagesRef]
1455
+ );
1446
1456
  const empty = chat.messages.length === 0;
1447
1457
  if (empty && !keepMounted) {
1448
1458
  return null;
@@ -1452,10 +1462,9 @@ var ThreadMessages = forwardRef2(function ThreadMessages2({ children, keepMounte
1452
1462
  {
1453
1463
  ...props,
1454
1464
  children: chat.messages.map((message) => /* @__PURE__ */ jsx2(InternalMessageProvider, { message, children: typeof children === "function" ? children(message) : children ?? defaultMessage() }, message.id)),
1455
- "data-anvia-thread-messages": "",
1456
- "data-empty": empty ? "" : void 0
1465
+ "data-state": empty ? "empty" : "populated"
1457
1466
  },
1458
- ref
1467
+ composedRef
1459
1468
  );
1460
1469
  });
1461
1470
  var ThreadSuggestions = forwardRef2(
@@ -1473,8 +1482,8 @@ var ThreadSuggestions = forwardRef2(
1473
1482
  children: suggestions.map(
1474
1483
  (suggestion) => typeof children === "function" ? /* @__PURE__ */ jsx2(Fragment2, { children: children(suggestion) }, suggestion.id) : /* @__PURE__ */ jsx2(ThreadSuggestion, { suggestion, children }, suggestion.id)
1475
1484
  ),
1476
- "data-anvia-thread-suggestions": "",
1477
- "data-empty": empty ? "" : void 0
1485
+ "data-role": "suggestions",
1486
+ "data-state": empty ? "empty" : "populated"
1478
1487
  },
1479
1488
  ref
1480
1489
  );
@@ -1484,14 +1493,14 @@ var ThreadSuggestion = forwardRef2(
1484
1493
  function ThreadSuggestion2({ onClick, prompt, suggestion, ...props }, ref) {
1485
1494
  const chat = useChatContext();
1486
1495
  const suggestionPrompt = prompt ?? suggestion?.prompt ?? "";
1487
- const disabled = props.disabled ?? (suggestionPrompt.length === 0 || chat.status === "streaming");
1496
+ const disabled = props.disabled ?? (suggestionPrompt.length === 0 || chat.status === "submitted" || chat.status === "streaming");
1488
1497
  const handleClick = useCallback2(
1489
1498
  (event) => {
1490
1499
  onClick?.(event);
1491
1500
  if (event.defaultPrevented || disabled) {
1492
1501
  return;
1493
1502
  }
1494
- void chat.sendMessage(suggestionPrompt);
1503
+ void chat.sendMessage({ text: suggestionPrompt });
1495
1504
  },
1496
1505
  [chat, disabled, onClick, suggestionPrompt]
1497
1506
  );
@@ -1503,7 +1512,6 @@ var ThreadSuggestion = forwardRef2(
1503
1512
  disabled,
1504
1513
  onClick: handleClick,
1505
1514
  type: props.type ?? "button",
1506
- "data-anvia-thread-suggestion": "",
1507
1515
  "data-state": disabled ? "disabled" : "enabled"
1508
1516
  },
1509
1517
  ref
@@ -1532,7 +1540,6 @@ var ThreadScrollToBottom = forwardRef2(
1532
1540
  disabled,
1533
1541
  onClick: handleClick,
1534
1542
  type: props.type ?? "button",
1535
- "data-anvia-scroll-to-bottom": "",
1536
1543
  "data-state": thread.atBottom ? "bottom" : "away"
1537
1544
  },
1538
1545
  ref
@@ -1540,9 +1547,9 @@ var ThreadScrollToBottom = forwardRef2(
1540
1547
  }
1541
1548
  );
1542
1549
  function defaultMessage() {
1543
- return /* @__PURE__ */ jsxs2(Message.Root, { children: [
1544
- /* @__PURE__ */ jsx2(Message.Content, { children: /* @__PURE__ */ jsx2(Message.Parts, {}) }),
1545
- /* @__PURE__ */ jsx2(Message.Actions, {})
1550
+ return /* @__PURE__ */ jsxs2(MessagePrimitive.Root, { children: [
1551
+ /* @__PURE__ */ jsx2(MessagePrimitive.Content, { children: /* @__PURE__ */ jsx2(MessagePrimitive.Parts, {}) }),
1552
+ /* @__PURE__ */ jsx2(MessagePrimitive.Actions, {})
1546
1553
  ] });
1547
1554
  }
1548
1555
  function errorMessage(error) {
@@ -1554,7 +1561,7 @@ function errorMessage(error) {
1554
1561
  }
1555
1562
  return "Something went wrong.";
1556
1563
  }
1557
- var Thread = {
1564
+ var ThreadPrimitive = {
1558
1565
  Root: ThreadRoot,
1559
1566
  Viewport: ThreadViewport,
1560
1567
  ViewportFooter: ThreadViewportFooter,
@@ -1569,7 +1576,7 @@ var Thread = {
1569
1576
  };
1570
1577
 
1571
1578
  export {
1572
- Composer,
1573
- Thread
1579
+ ComposerPrimitive,
1580
+ ThreadPrimitive
1574
1581
  };
1575
- //# sourceMappingURL=chunk-FABSIZZ7.js.map
1582
+ //# sourceMappingURL=chunk-HWJIMLHC.js.map