@assistant-ui/react 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -148,7 +148,7 @@ var makeBaseComposer = (set) => ({
148
148
  });
149
149
 
150
150
  // src/context/stores/Composer.ts
151
- var makeComposerStore = (useThread, useThreadActions) => {
151
+ var makeComposerStore = (useThread, useThreadMessages, useThreadActions) => {
152
152
  const focusListeners = /* @__PURE__ */ new Set();
153
153
  return create3()((set, get, store) => {
154
154
  return {
@@ -158,7 +158,7 @@ var makeComposerStore = (useThread, useThreadActions) => {
158
158
  const { setValue, value } = get();
159
159
  setValue("");
160
160
  useThreadActions.getState().append({
161
- parentId: useThread.getState().messages.at(-1)?.id ?? null,
161
+ parentId: useThreadMessages.getState().at(-1)?.id ?? null,
162
162
  role: "user",
163
163
  content: [{ type: "text", text: value }]
164
164
  });
@@ -188,7 +188,6 @@ var makeComposerStore = (useThread, useThreadActions) => {
188
188
  import { create as create4 } from "zustand";
189
189
  var makeThreadStore = (runtimeRef) => {
190
190
  return create4(() => ({
191
- messages: runtimeRef.current.messages,
192
191
  isRunning: runtimeRef.current.isRunning
193
192
  }));
194
193
  };
@@ -228,6 +227,12 @@ var makeThreadActionStore = (runtimeRef) => {
228
227
  );
229
228
  };
230
229
 
230
+ // src/context/stores/ThreadMessages.ts
231
+ import { create as create7 } from "zustand";
232
+ var makeThreadMessagesStore = (runtimeRef) => {
233
+ return create7(() => runtimeRef.current.messages);
234
+ };
235
+
231
236
  // src/context/providers/ThreadProvider.tsx
232
237
  import { jsx, jsxs } from "react/jsx-runtime";
233
238
  var ThreadProvider = ({
@@ -240,11 +245,17 @@ var ThreadProvider = ({
240
245
  });
241
246
  const [context] = useState(() => {
242
247
  const useThread = makeThreadStore(runtimeRef);
248
+ const useThreadMessages = makeThreadMessagesStore(runtimeRef);
243
249
  const useThreadActions = makeThreadActionStore(runtimeRef);
244
250
  const useViewport = makeThreadViewportStore();
245
- const useComposer = makeComposerStore(useThread, useThreadActions);
251
+ const useComposer = makeComposerStore(
252
+ useThread,
253
+ useThreadMessages,
254
+ useThreadActions
255
+ );
246
256
  return {
247
257
  useThread,
258
+ useThreadMessages,
248
259
  useThreadActions,
249
260
  useComposer,
250
261
  useViewport
@@ -254,11 +265,11 @@ var ThreadProvider = ({
254
265
  const onRuntimeUpdate = () => {
255
266
  context.useThread.setState(
256
267
  Object.freeze({
257
- messages: runtimeRef.current.messages,
258
268
  isRunning: runtimeRef.current.isRunning
259
269
  }),
260
270
  true
261
271
  );
272
+ context.useThreadMessages.setState(Object.freeze(runtimeRef.current.messages), true);
262
273
  };
263
274
  onRuntimeUpdate();
264
275
  return runtime.subscribe(onRuntimeUpdate);
@@ -279,8 +290,8 @@ var ThreadProvider = ({
279
290
  };
280
291
 
281
292
  // src/context/stores/AssistantActions.tsx
282
- import { create as create7 } from "zustand";
283
- var makeAssistantActionsStore = (runtimeRef) => create7(
293
+ import { create as create8 } from "zustand";
294
+ var makeAssistantActionsStore = (runtimeRef) => create8(
284
295
  () => Object.freeze({
285
296
  switchToThread: () => runtimeRef.current.switchToThread(null)
286
297
  })
@@ -357,30 +368,30 @@ var useContentPartContext = () => {
357
368
 
358
369
  // src/hooks/useAppendMessage.tsx
359
370
  import { useCallback as useCallback2 } from "react";
360
- var toAppendMessage = (useThread, message) => {
371
+ var toAppendMessage = (useThreadMessages, message) => {
361
372
  if (typeof message === "string") {
362
373
  return {
363
- parentId: useThread.getState().messages.at(-1)?.id ?? null,
374
+ parentId: useThreadMessages.getState().at(-1)?.id ?? null,
364
375
  role: "user",
365
376
  content: [{ type: "text", text: message }]
366
377
  };
367
378
  }
368
379
  return {
369
- parentId: message.parentId ?? useThread.getState().messages.at(-1)?.id ?? null,
380
+ parentId: message.parentId ?? useThreadMessages.getState().at(-1)?.id ?? null,
370
381
  role: message.role ?? "user",
371
382
  content: message.content
372
383
  };
373
384
  };
374
385
  var useAppendMessage = () => {
375
- const { useThread, useThreadActions, useViewport, useComposer } = useThreadContext();
386
+ const { useThreadMessages, useThreadActions, useViewport, useComposer } = useThreadContext();
376
387
  const append = useCallback2(
377
388
  (message) => {
378
- const appendMessage = toAppendMessage(useThread, message);
389
+ const appendMessage = toAppendMessage(useThreadMessages, message);
379
390
  useThreadActions.getState().append(appendMessage);
380
391
  useViewport.getState().scrollToBottom();
381
392
  useComposer.getState().focus();
382
393
  },
383
- [useThread, useThreadActions, useViewport, useComposer]
394
+ [useThreadMessages, useThreadActions, useViewport, useComposer]
384
395
  );
385
396
  return append;
386
397
  };
@@ -676,17 +687,6 @@ var useContentPartImage = () => {
676
687
  return image;
677
688
  };
678
689
 
679
- // src/primitive-hooks/contentPart/useContentPartInProgressIndicator.tsx
680
- var useContentPartInProgressIndicator = () => {
681
- const { useMessageUtils } = useMessageContext();
682
- const { useContentPart } = useContentPartContext();
683
- const indicator = useCombinedStore(
684
- [useMessageUtils, useContentPart],
685
- (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
686
- );
687
- return indicator;
688
- };
689
-
690
690
  // src/primitive-hooks/contentPart/useContentPartText.tsx
691
691
  var useContentPartText = () => {
692
692
  const { useContentPart } = useContentPartContext();
@@ -719,14 +719,17 @@ var useMessageIf = (props) => {
719
719
 
720
720
  // src/primitive-hooks/thread/useThreadIf.tsx
721
721
  var useThreadIf = (props) => {
722
- const { useThread } = useThreadContext();
723
- return useThread((thread) => {
724
- if (props.empty === true && thread.messages.length !== 0) return false;
725
- if (props.empty === false && thread.messages.length === 0) return false;
726
- if (props.running === true && !thread.isRunning) return false;
727
- if (props.running === false && thread.isRunning) return false;
728
- return true;
729
- });
722
+ const { useThread, useThreadMessages } = useThreadContext();
723
+ return useCombinedStore(
724
+ [useThread, useThreadMessages],
725
+ (thread, messages) => {
726
+ if (props.empty === true && messages.length !== 0) return false;
727
+ if (props.empty === false && messages.length === 0) return false;
728
+ if (props.running === true && !thread.isRunning) return false;
729
+ if (props.running === false && thread.isRunning) return false;
730
+ return true;
731
+ }
732
+ );
730
733
  };
731
734
 
732
735
  // src/primitive-hooks/thread/useThreadEmpty.tsx
@@ -868,6 +871,7 @@ var ActionBarPrimitiveEdit = createActionButton(
868
871
  // src/primitives/assistantModal/index.ts
869
872
  var assistantModal_exports = {};
870
873
  __export(assistantModal_exports, {
874
+ Anchor: () => AssistantModalPrimitiveAnchor,
871
875
  Content: () => AssistantModalPrimitiveContent,
872
876
  Root: () => AssistantModalPrimitiveRoot,
873
877
  Trigger: () => AssistantModalPrimitiveTrigger
@@ -974,6 +978,21 @@ var AssistantModalPrimitiveContent = forwardRef4(
974
978
  );
975
979
  AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
976
980
 
981
+ // src/primitives/assistantModal/AssistantModalAnchor.tsx
982
+ import { forwardRef as forwardRef5 } from "react";
983
+ import * as PopoverPrimitive5 from "@radix-ui/react-popover";
984
+ import { jsx as jsx9 } from "react/jsx-runtime";
985
+ var AssistantModalPrimitiveAnchor = forwardRef5(
986
+ ({
987
+ __scopeAssistantModal,
988
+ ...rest
989
+ }, ref) => {
990
+ const scope = usePopoverScope(__scopeAssistantModal);
991
+ return /* @__PURE__ */ jsx9(PopoverPrimitive5.Anchor, { ...scope, ...rest, ref });
992
+ }
993
+ );
994
+ AssistantModalPrimitiveAnchor.displayName = "AssistantModalPrimitive.Anchor";
995
+
977
996
  // src/primitives/branchPicker/index.ts
978
997
  var branchPicker_exports = {};
979
998
  __export(branchPicker_exports, {
@@ -997,24 +1016,24 @@ var BranchPickerPrevious = createActionButton(
997
1016
  );
998
1017
 
999
1018
  // src/primitives/branchPicker/BranchPickerCount.tsx
1000
- import { Fragment, jsx as jsx9 } from "react/jsx-runtime";
1019
+ import { Fragment, jsx as jsx10 } from "react/jsx-runtime";
1001
1020
  var BranchPickerPrimitiveCount = () => {
1002
1021
  const branchCount = useBranchPickerCount();
1003
- return /* @__PURE__ */ jsx9(Fragment, { children: branchCount });
1022
+ return /* @__PURE__ */ jsx10(Fragment, { children: branchCount });
1004
1023
  };
1005
1024
  BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
1006
1025
 
1007
1026
  // src/primitives/branchPicker/BranchPickerNumber.tsx
1008
- import { Fragment as Fragment2, jsx as jsx10 } from "react/jsx-runtime";
1027
+ import { Fragment as Fragment2, jsx as jsx11 } from "react/jsx-runtime";
1009
1028
  var BranchPickerPrimitiveNumber = () => {
1010
1029
  const branchNumber = useBranchPickerNumber();
1011
- return /* @__PURE__ */ jsx10(Fragment2, { children: branchNumber });
1030
+ return /* @__PURE__ */ jsx11(Fragment2, { children: branchNumber });
1012
1031
  };
1013
1032
  BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
1014
1033
 
1015
1034
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1016
1035
  import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
1017
- import { forwardRef as forwardRef8 } from "react";
1036
+ import { forwardRef as forwardRef9 } from "react";
1018
1037
 
1019
1038
  // src/primitives/message/index.ts
1020
1039
  var message_exports = {};
@@ -1028,9 +1047,9 @@ __export(message_exports, {
1028
1047
  // src/primitives/message/MessageRoot.tsx
1029
1048
  import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
1030
1049
  import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
1031
- import { forwardRef as forwardRef5 } from "react";
1032
- import { jsx as jsx11 } from "react/jsx-runtime";
1033
- var MessagePrimitiveRoot = forwardRef5(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
1050
+ import { forwardRef as forwardRef6 } from "react";
1051
+ import { jsx as jsx12 } from "react/jsx-runtime";
1052
+ var MessagePrimitiveRoot = forwardRef6(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
1034
1053
  const { useMessageUtils } = useMessageContext();
1035
1054
  const setIsHovering = useMessageUtils((s) => s.setIsHovering);
1036
1055
  const handleMouseEnter = () => {
@@ -1039,7 +1058,7 @@ var MessagePrimitiveRoot = forwardRef5(({ onMouseEnter, onMouseLeave, ...rest },
1039
1058
  const handleMouseLeave = () => {
1040
1059
  setIsHovering(false);
1041
1060
  };
1042
- return /* @__PURE__ */ jsx11(
1061
+ return /* @__PURE__ */ jsx12(
1043
1062
  Primitive3.div,
1044
1063
  {
1045
1064
  ...rest,
@@ -1066,8 +1085,8 @@ import { memo as memo2 } from "react";
1066
1085
 
1067
1086
  // src/context/providers/ContentPartProvider.tsx
1068
1087
  import { useEffect as useEffect7, useState as useState4 } from "react";
1069
- import { create as create8 } from "zustand";
1070
- import { jsx as jsx12 } from "react/jsx-runtime";
1088
+ import { create as create9 } from "zustand";
1089
+ import { jsx as jsx13 } from "react/jsx-runtime";
1071
1090
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
1072
1091
  const part = message.content[partIndex];
1073
1092
  if (!part) return;
@@ -1085,7 +1104,7 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
1085
1104
  var useContentPartContext2 = (partIndex) => {
1086
1105
  const { useMessage } = useMessageContext();
1087
1106
  const [context] = useState4(() => {
1088
- const useContentPart = create8(
1107
+ const useContentPart = create9(
1089
1108
  () => ({})
1090
1109
  );
1091
1110
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
@@ -1104,7 +1123,7 @@ var ContentPartProvider = ({
1104
1123
  children
1105
1124
  }) => {
1106
1125
  const context = useContentPartContext2(partIndex);
1107
- return /* @__PURE__ */ jsx12(ContentPartContext.Provider, { value: context, children });
1126
+ return /* @__PURE__ */ jsx13(ContentPartContext.Provider, { value: context, children });
1108
1127
  };
1109
1128
 
1110
1129
  // src/primitives/contentPart/ContentPartDisplay.tsx
@@ -1114,38 +1133,61 @@ var ContentPartPrimitiveDisplay = () => {
1114
1133
  };
1115
1134
  ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
1116
1135
 
1136
+ // src/utils/OutPortal.tsx
1137
+ import { useLayoutEffect, useRef as useRef3 } from "react";
1138
+ import { jsx as jsx14 } from "react/jsx-runtime";
1139
+ var OutPortal = ({ node }) => {
1140
+ const parentRef = useRef3(null);
1141
+ useLayoutEffect(() => {
1142
+ const parent = parentRef.current;
1143
+ if (!parent || !node) return;
1144
+ parent.appendChild(node);
1145
+ return () => {
1146
+ parent.removeChild(node);
1147
+ };
1148
+ }, [node]);
1149
+ if (!node) return null;
1150
+ return /* @__PURE__ */ jsx14("span", { ref: parentRef });
1151
+ };
1152
+
1117
1153
  // src/primitives/contentPart/ContentPartInProgressIndicator.tsx
1154
+ import { jsx as jsx15 } from "react/jsx-runtime";
1118
1155
  var ContentPartPrimitiveInProgressIndicator = () => {
1119
- const indicator = useContentPartInProgressIndicator();
1120
- return indicator;
1156
+ const { useMessageUtils } = useMessageContext();
1157
+ const { useContentPart } = useContentPartContext();
1158
+ const indicator = useCombinedStore(
1159
+ [useMessageUtils, useContentPart],
1160
+ (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
1161
+ );
1162
+ return /* @__PURE__ */ jsx15(OutPortal, { node: indicator });
1121
1163
  };
1122
1164
  ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
1123
1165
 
1124
1166
  // src/primitives/contentPart/ContentPartText.tsx
1125
1167
  import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
1126
- import { forwardRef as forwardRef6 } from "react";
1127
- import { jsx as jsx13 } from "react/jsx-runtime";
1128
- var ContentPartPrimitiveText = forwardRef6((props, forwardedRef) => {
1168
+ import { forwardRef as forwardRef7 } from "react";
1169
+ import { jsx as jsx16 } from "react/jsx-runtime";
1170
+ var ContentPartPrimitiveText = forwardRef7((props, forwardedRef) => {
1129
1171
  const text = useContentPartText();
1130
- return /* @__PURE__ */ jsx13(Primitive4.p, { ...props, ref: forwardedRef, children: text });
1172
+ return /* @__PURE__ */ jsx16(Primitive4.span, { ...props, ref: forwardedRef, children: text });
1131
1173
  });
1132
1174
  ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
1133
1175
 
1134
1176
  // src/primitives/message/MessageContent.tsx
1135
- import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs2 } from "react/jsx-runtime";
1177
+ import { jsx as jsx17, jsxs as jsxs2 } from "react/jsx-runtime";
1136
1178
  var defaultComponents = {
1137
- Text: () => /* @__PURE__ */ jsxs2(Fragment3, { children: [
1138
- /* @__PURE__ */ jsx14(ContentPartPrimitiveText, { style: { whiteSpace: "pre-line" } }),
1139
- /* @__PURE__ */ jsx14(ContentPartPrimitiveInProgressIndicator, {})
1179
+ Text: () => /* @__PURE__ */ jsxs2("p", { style: { whiteSpace: "pre-line" }, children: [
1180
+ /* @__PURE__ */ jsx17(ContentPartPrimitiveText, {}),
1181
+ /* @__PURE__ */ jsx17(ContentPartPrimitiveInProgressIndicator, {})
1140
1182
  ] }),
1141
1183
  Image: () => null,
1142
- UI: () => /* @__PURE__ */ jsx14(ContentPartPrimitiveDisplay, {}),
1184
+ UI: () => /* @__PURE__ */ jsx17(ContentPartPrimitiveDisplay, {}),
1143
1185
  tools: {
1144
1186
  Fallback: (props) => {
1145
1187
  const { useToolUIs } = useAssistantContext();
1146
1188
  const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
1147
1189
  if (!Render) return null;
1148
- return /* @__PURE__ */ jsx14(Render, { ...props });
1190
+ return /* @__PURE__ */ jsx17(Render, { ...props });
1149
1191
  }
1150
1192
  }
1151
1193
  };
@@ -1164,15 +1206,15 @@ var MessageContentPartComponent = ({
1164
1206
  const type = part.type;
1165
1207
  switch (type) {
1166
1208
  case "text":
1167
- return /* @__PURE__ */ jsx14(Text, { part, status });
1209
+ return /* @__PURE__ */ jsx17(Text, { part, status });
1168
1210
  case "image":
1169
- return /* @__PURE__ */ jsx14(Image, { part, status });
1211
+ return /* @__PURE__ */ jsx17(Image, { part, status });
1170
1212
  case "ui":
1171
- return /* @__PURE__ */ jsx14(UI, { part, status });
1213
+ return /* @__PURE__ */ jsx17(UI, { part, status });
1172
1214
  case "tool-call": {
1173
1215
  const Tool = by_name[part.toolName] || Fallback;
1174
1216
  const addResult = (result) => addToolResult(part.toolCallId, result);
1175
- return /* @__PURE__ */ jsx14(Tool, { part, status, addResult });
1217
+ return /* @__PURE__ */ jsx17(Tool, { part, status, addResult });
1176
1218
  }
1177
1219
  default:
1178
1220
  throw new Error(`Unknown content part type: ${type}`);
@@ -1182,7 +1224,7 @@ var MessageContentPartImpl = ({
1182
1224
  partIndex,
1183
1225
  components
1184
1226
  }) => {
1185
- return /* @__PURE__ */ jsx14(ContentPartProvider, { partIndex, children: /* @__PURE__ */ jsx14(MessageContentPartComponent, { components }) });
1227
+ return /* @__PURE__ */ jsx17(ContentPartProvider, { partIndex, children: /* @__PURE__ */ jsx17(MessageContentPartComponent, { components }) });
1186
1228
  };
1187
1229
  var MessageContentPart = memo2(
1188
1230
  MessageContentPartImpl,
@@ -1195,7 +1237,7 @@ var MessagePrimitiveContent = ({
1195
1237
  const contentLength = useMessage((s) => s.message.content.length);
1196
1238
  return new Array(contentLength).fill(null).map((_, idx) => {
1197
1239
  const partIndex = idx;
1198
- return /* @__PURE__ */ jsx14(
1240
+ return /* @__PURE__ */ jsx17(
1199
1241
  MessageContentPart,
1200
1242
  {
1201
1243
  partIndex,
@@ -1208,28 +1250,21 @@ var MessagePrimitiveContent = ({
1208
1250
  MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
1209
1251
 
1210
1252
  // src/primitives/message/MessageInProgress.tsx
1253
+ import { createPortal } from "react-dom";
1211
1254
  import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
1212
- import {
1213
- forwardRef as forwardRef7,
1214
- useEffect as useEffect8
1215
- } from "react";
1216
- import { jsx as jsx15 } from "react/jsx-runtime";
1217
- var MessagePrimitiveInProgress = forwardRef7((props, ref) => {
1255
+ import { forwardRef as forwardRef8 } from "react";
1256
+ import { jsx as jsx18 } from "react/jsx-runtime";
1257
+ var MessagePrimitiveInProgress = forwardRef8((props, ref) => {
1218
1258
  const { useMessageUtils } = useMessageContext();
1219
- useEffect8(() => {
1220
- useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ jsx15(Primitive5.span, { ...props, ref }));
1221
- return () => {
1222
- useMessageUtils.getState().setInProgressIndicator(null);
1223
- };
1224
- }, [useMessageUtils, props, ref]);
1225
- return null;
1259
+ const portalNode = useMessageUtils((s) => s.inProgressIndicator);
1260
+ return createPortal(/* @__PURE__ */ jsx18(Primitive5.span, { ...props, ref }), portalNode);
1226
1261
  });
1227
1262
  MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
1228
1263
 
1229
1264
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1230
- import { jsx as jsx16 } from "react/jsx-runtime";
1231
- var BranchPickerPrimitiveRoot = forwardRef8(({ hideWhenSingleBranch, ...rest }, ref) => {
1232
- return /* @__PURE__ */ jsx16(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive6.div, { ...rest, ref }) });
1265
+ import { jsx as jsx19 } from "react/jsx-runtime";
1266
+ var BranchPickerPrimitiveRoot = forwardRef9(({ hideWhenSingleBranch, ...rest }, ref) => {
1267
+ return /* @__PURE__ */ jsx19(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx19(Primitive6.div, { ...rest, ref }) });
1233
1268
  });
1234
1269
  BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
1235
1270
 
@@ -1247,17 +1282,17 @@ __export(composer_exports, {
1247
1282
  import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
1248
1283
  import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
1249
1284
  import {
1250
- forwardRef as forwardRef9
1285
+ forwardRef as forwardRef10
1251
1286
  } from "react";
1252
- import { jsx as jsx17 } from "react/jsx-runtime";
1253
- var ComposerPrimitiveRoot = forwardRef9(({ onSubmit, ...rest }, forwardedRef) => {
1287
+ import { jsx as jsx20 } from "react/jsx-runtime";
1288
+ var ComposerPrimitiveRoot = forwardRef10(({ onSubmit, ...rest }, forwardedRef) => {
1254
1289
  const send = useComposerSend();
1255
1290
  const handleSubmit = (e) => {
1256
1291
  e.preventDefault();
1257
1292
  if (!send) return;
1258
1293
  send();
1259
1294
  };
1260
- return /* @__PURE__ */ jsx17(
1295
+ return /* @__PURE__ */ jsx20(
1261
1296
  Primitive7.form,
1262
1297
  {
1263
1298
  ...rest,
@@ -1273,15 +1308,15 @@ import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primiti
1273
1308
  import { useComposedRefs } from "@radix-ui/react-compose-refs";
1274
1309
  import { Slot } from "@radix-ui/react-slot";
1275
1310
  import {
1276
- forwardRef as forwardRef10,
1311
+ forwardRef as forwardRef11,
1277
1312
  useCallback as useCallback13,
1278
- useEffect as useEffect9,
1279
- useRef as useRef3
1313
+ useEffect as useEffect8,
1314
+ useRef as useRef4
1280
1315
  } from "react";
1281
1316
  import TextareaAutosize from "react-textarea-autosize";
1282
1317
  import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
1283
- import { jsx as jsx18 } from "react/jsx-runtime";
1284
- var ComposerPrimitiveInput = forwardRef10(
1318
+ import { jsx as jsx21 } from "react/jsx-runtime";
1319
+ var ComposerPrimitiveInput = forwardRef11(
1285
1320
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
1286
1321
  const { useThread } = useThreadContext();
1287
1322
  const { useComposer, type } = useComposerContext();
@@ -1290,7 +1325,7 @@ var ComposerPrimitiveInput = forwardRef10(
1290
1325
  return c.value;
1291
1326
  });
1292
1327
  const Component = asChild ? Slot : TextareaAutosize;
1293
- const textareaRef = useRef3(null);
1328
+ const textareaRef = useRef4(null);
1294
1329
  const ref = useComposedRefs(forwardedRef, textareaRef);
1295
1330
  useEscapeKeydown((e) => {
1296
1331
  const composer = useComposer.getState();
@@ -1318,13 +1353,13 @@ var ComposerPrimitiveInput = forwardRef10(
1318
1353
  textareaRef.current.value.length
1319
1354
  );
1320
1355
  }, [autoFocusEnabled]);
1321
- useEffect9(() => focus(), [focus]);
1356
+ useEffect8(() => focus(), [focus]);
1322
1357
  useOnComposerFocus(() => {
1323
1358
  if (type === "new") {
1324
1359
  focus();
1325
1360
  }
1326
1361
  });
1327
- return /* @__PURE__ */ jsx18(
1362
+ return /* @__PURE__ */ jsx21(
1328
1363
  Component,
1329
1364
  {
1330
1365
  value,
@@ -1344,13 +1379,13 @@ var ComposerPrimitiveInput = forwardRef10(
1344
1379
  ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
1345
1380
 
1346
1381
  // src/primitives/composer/ComposerSend.tsx
1347
- import { forwardRef as forwardRef11 } from "react";
1382
+ import { forwardRef as forwardRef12 } from "react";
1348
1383
  import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
1349
- import { jsx as jsx19 } from "react/jsx-runtime";
1350
- var ComposerPrimitiveSend = forwardRef11(({ disabled, ...rest }, ref) => {
1384
+ import { jsx as jsx22 } from "react/jsx-runtime";
1385
+ var ComposerPrimitiveSend = forwardRef12(({ disabled, ...rest }, ref) => {
1351
1386
  const { useComposer } = useComposerContext();
1352
1387
  const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1353
- return /* @__PURE__ */ jsx19(
1388
+ return /* @__PURE__ */ jsx22(
1354
1389
  Primitive8.button,
1355
1390
  {
1356
1391
  type: "submit",
@@ -1389,11 +1424,11 @@ __export(contentPart_exports, {
1389
1424
 
1390
1425
  // src/primitives/contentPart/ContentPartImage.tsx
1391
1426
  import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
1392
- import { forwardRef as forwardRef12 } from "react";
1393
- import { jsx as jsx20 } from "react/jsx-runtime";
1394
- var ContentPartPrimitiveImage = forwardRef12((props, forwardedRef) => {
1427
+ import { forwardRef as forwardRef13 } from "react";
1428
+ import { jsx as jsx23 } from "react/jsx-runtime";
1429
+ var ContentPartPrimitiveImage = forwardRef13((props, forwardedRef) => {
1395
1430
  const image = useContentPartImage();
1396
- return /* @__PURE__ */ jsx20(Primitive9.img, { src: image, ...props, ref: forwardedRef });
1431
+ return /* @__PURE__ */ jsx23(Primitive9.img, { src: image, ...props, ref: forwardedRef });
1397
1432
  });
1398
1433
  ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
1399
1434
 
@@ -1411,10 +1446,10 @@ __export(thread_exports, {
1411
1446
 
1412
1447
  // src/primitives/thread/ThreadRoot.tsx
1413
1448
  import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
1414
- import { forwardRef as forwardRef13 } from "react";
1415
- import { jsx as jsx21 } from "react/jsx-runtime";
1416
- var ThreadPrimitiveRoot = forwardRef13((props, ref) => {
1417
- return /* @__PURE__ */ jsx21(Primitive10.div, { ...props, ref });
1449
+ import { forwardRef as forwardRef14 } from "react";
1450
+ import { jsx as jsx24 } from "react/jsx-runtime";
1451
+ var ThreadPrimitiveRoot = forwardRef14((props, ref) => {
1452
+ return /* @__PURE__ */ jsx24(Primitive10.div, { ...props, ref });
1418
1453
  });
1419
1454
  ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
1420
1455
 
@@ -1440,20 +1475,20 @@ ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
1440
1475
  // src/primitives/thread/ThreadViewport.tsx
1441
1476
  import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
1442
1477
  import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
1443
- import { forwardRef as forwardRef14 } from "react";
1478
+ import { forwardRef as forwardRef15 } from "react";
1444
1479
 
1445
1480
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
1446
1481
  import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
1447
- import { useRef as useRef5 } from "react";
1482
+ import { useRef as useRef6 } from "react";
1448
1483
 
1449
1484
  // src/utils/hooks/useOnResizeContent.tsx
1450
1485
  import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
1451
1486
  import { useCallback as useCallback15 } from "react";
1452
1487
 
1453
1488
  // src/utils/hooks/useManagedRef.ts
1454
- import { useCallback as useCallback14, useRef as useRef4 } from "react";
1489
+ import { useCallback as useCallback14, useRef as useRef5 } from "react";
1455
1490
  var useManagedRef = (callback) => {
1456
- const cleanupRef = useRef4();
1491
+ const cleanupRef = useRef5();
1457
1492
  const ref = useCallback14(
1458
1493
  (el) => {
1459
1494
  if (cleanupRef.current) {
@@ -1508,11 +1543,11 @@ var useOnResizeContent = (callback) => {
1508
1543
 
1509
1544
  // src/utils/hooks/useOnScrollToBottom.tsx
1510
1545
  import { useCallbackRef as useCallbackRef3 } from "@radix-ui/react-use-callback-ref";
1511
- import { useEffect as useEffect10 } from "react";
1546
+ import { useEffect as useEffect9 } from "react";
1512
1547
  var useOnScrollToBottom = (callback) => {
1513
1548
  const callbackRef = useCallbackRef3(callback);
1514
1549
  const { useViewport } = useThreadContext();
1515
- useEffect10(() => {
1550
+ useEffect9(() => {
1516
1551
  return useViewport.getState().onScrollToBottom(() => {
1517
1552
  callbackRef();
1518
1553
  });
@@ -1523,11 +1558,11 @@ var useOnScrollToBottom = (callback) => {
1523
1558
  var useThreadViewportAutoScroll = ({
1524
1559
  autoScroll = true
1525
1560
  }) => {
1526
- const divRef = useRef5(null);
1561
+ const divRef = useRef6(null);
1527
1562
  const { useViewport } = useThreadContext();
1528
- const firstRenderRef = useRef5(true);
1529
- const lastScrollTop = useRef5(0);
1530
- const isScrollingToBottomRef = useRef5(false);
1563
+ const firstRenderRef = useRef6(true);
1564
+ const lastScrollTop = useRef6(0);
1565
+ const isScrollingToBottomRef = useRef6(false);
1531
1566
  const scrollToBottom = () => {
1532
1567
  const div = divRef.current;
1533
1568
  if (!div || !autoScroll) return;
@@ -1573,13 +1608,13 @@ var useThreadViewportAutoScroll = ({
1573
1608
  };
1574
1609
 
1575
1610
  // src/primitives/thread/ThreadViewport.tsx
1576
- import { jsx as jsx22 } from "react/jsx-runtime";
1577
- var ThreadPrimitiveViewport = forwardRef14(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1611
+ import { jsx as jsx25 } from "react/jsx-runtime";
1612
+ var ThreadPrimitiveViewport = forwardRef15(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1578
1613
  const autoScrollRef = useThreadViewportAutoScroll({
1579
1614
  autoScroll
1580
1615
  });
1581
1616
  const ref = useComposedRefs3(forwardedRef, autoScrollRef);
1582
- return /* @__PURE__ */ jsx22(Primitive11.div, { ...rest, ref, children });
1617
+ return /* @__PURE__ */ jsx25(Primitive11.div, { ...rest, ref, children });
1583
1618
  });
1584
1619
  ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
1585
1620
 
@@ -1587,15 +1622,15 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
1587
1622
  import { memo as memo3 } from "react";
1588
1623
 
1589
1624
  // src/context/providers/MessageProvider.tsx
1590
- import { useEffect as useEffect11, useState as useState5 } from "react";
1591
- import { create as create11 } from "zustand";
1625
+ import { useEffect as useEffect10, useState as useState5 } from "react";
1626
+ import { create as create12 } from "zustand";
1592
1627
 
1593
1628
  // src/context/stores/EditComposer.ts
1594
- import { create as create9 } from "zustand";
1629
+ import { create as create10 } from "zustand";
1595
1630
  var makeEditComposerStore = ({
1596
1631
  onEdit,
1597
1632
  onSend
1598
- }) => create9()((set, get, store) => ({
1633
+ }) => create10()((set, get, store) => ({
1599
1634
  ...makeBaseComposer(set, get, store),
1600
1635
  isEditing: false,
1601
1636
  edit: () => {
@@ -1615,12 +1650,9 @@ var makeEditComposerStore = ({
1615
1650
  }));
1616
1651
 
1617
1652
  // src/context/stores/MessageUtils.ts
1618
- import { create as create10 } from "zustand";
1619
- var makeMessageUtilsStore = () => create10((set) => ({
1620
- inProgressIndicator: null,
1621
- setInProgressIndicator: (value) => {
1622
- set({ inProgressIndicator: value });
1623
- },
1653
+ import { create as create11 } from "zustand";
1654
+ var makeMessageUtilsStore = () => create11((set) => ({
1655
+ inProgressIndicator: document.createElement("span"),
1624
1656
  isCopied: false,
1625
1657
  setIsCopied: (value) => {
1626
1658
  set({ isCopied: value });
@@ -1632,15 +1664,15 @@ var makeMessageUtilsStore = () => create10((set) => ({
1632
1664
  }));
1633
1665
 
1634
1666
  // src/context/providers/MessageProvider.tsx
1635
- import { jsx as jsx23 } from "react/jsx-runtime";
1636
- var getIsLast = (thread, message) => {
1637
- return thread.messages[thread.messages.length - 1]?.id === message.id;
1667
+ import { jsx as jsx26 } from "react/jsx-runtime";
1668
+ var getIsLast = (messages, message) => {
1669
+ return messages[messages.length - 1]?.id === message.id;
1638
1670
  };
1639
- var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
1640
- const parentId = thread.messages[messageIndex - 1]?.id ?? null;
1641
- const message = thread.messages[messageIndex];
1671
+ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
1672
+ const parentId = messages[messageIndex - 1]?.id ?? null;
1673
+ const message = messages[messageIndex];
1642
1674
  if (!message) return;
1643
- const isLast = getIsLast(thread, message);
1675
+ const isLast = getIsLast(messages, message);
1644
1676
  const branches = getBranches(message.id);
1645
1677
  const currentState = useMessage.getState();
1646
1678
  if (currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
@@ -1653,9 +1685,9 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
1653
1685
  });
1654
1686
  };
1655
1687
  var useMessageContext2 = (messageIndex) => {
1656
- const { useThread, useThreadActions } = useThreadContext();
1688
+ const { useThreadMessages, useThreadActions } = useThreadContext();
1657
1689
  const [context] = useState5(() => {
1658
- const useMessage = create11(() => ({}));
1690
+ const useMessage = create12(() => ({}));
1659
1691
  const useMessageUtils = makeMessageUtilsStore();
1660
1692
  const useEditComposer = makeEditComposerStore({
1661
1693
  onEdit: () => {
@@ -1684,15 +1716,15 @@ var useMessageContext2 = (messageIndex) => {
1684
1716
  }
1685
1717
  });
1686
1718
  syncMessage(
1687
- useThread.getState(),
1719
+ useThreadMessages.getState(),
1688
1720
  useThreadActions.getState().getBranches,
1689
1721
  useMessage,
1690
1722
  messageIndex
1691
1723
  );
1692
1724
  return { useMessage, useMessageUtils, useEditComposer };
1693
1725
  });
1694
- useEffect11(() => {
1695
- return useThread.subscribe((thread) => {
1726
+ useEffect10(() => {
1727
+ return useThreadMessages.subscribe((thread) => {
1696
1728
  syncMessage(
1697
1729
  thread,
1698
1730
  useThreadActions.getState().getBranches,
@@ -1700,7 +1732,7 @@ var useMessageContext2 = (messageIndex) => {
1700
1732
  messageIndex
1701
1733
  );
1702
1734
  });
1703
- }, [useThread, useThreadActions, context, messageIndex]);
1735
+ }, [useThreadMessages, useThreadActions, context, messageIndex]);
1704
1736
  return context;
1705
1737
  };
1706
1738
  var MessageProvider = ({
@@ -1708,11 +1740,11 @@ var MessageProvider = ({
1708
1740
  children
1709
1741
  }) => {
1710
1742
  const context = useMessageContext2(messageIndex);
1711
- return /* @__PURE__ */ jsx23(MessageContext.Provider, { value: context, children });
1743
+ return /* @__PURE__ */ jsx26(MessageContext.Provider, { value: context, children });
1712
1744
  };
1713
1745
 
1714
1746
  // src/primitives/thread/ThreadMessages.tsx
1715
- import { jsx as jsx24, jsxs as jsxs3 } from "react/jsx-runtime";
1747
+ import { jsx as jsx27, jsxs as jsxs3 } from "react/jsx-runtime";
1716
1748
  var getComponents = (components) => {
1717
1749
  return {
1718
1750
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
@@ -1727,10 +1759,10 @@ var ThreadMessageImpl = ({
1727
1759
  const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1728
1760
  return /* @__PURE__ */ jsxs3(MessageProvider, { messageIndex, children: [
1729
1761
  /* @__PURE__ */ jsxs3(MessagePrimitiveIf, { user: true, children: [
1730
- /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
1731
- /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
1762
+ /* @__PURE__ */ jsx27(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx27(UserMessage, {}) }),
1763
+ /* @__PURE__ */ jsx27(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx27(EditComposer, {}) })
1732
1764
  ] }),
1733
- /* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
1765
+ /* @__PURE__ */ jsx27(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx27(AssistantMessage, {}) })
1734
1766
  ] });
1735
1767
  };
1736
1768
  var ThreadMessage = memo3(
@@ -1740,12 +1772,12 @@ var ThreadMessage = memo3(
1740
1772
  var ThreadPrimitiveMessages = ({
1741
1773
  components
1742
1774
  }) => {
1743
- const { useThread } = useThreadContext();
1744
- const messagesLength = useThread((t) => t.messages.length);
1775
+ const { useThreadMessages } = useThreadContext();
1776
+ const messagesLength = useThreadMessages((t) => t.length);
1745
1777
  if (messagesLength === 0) return null;
1746
1778
  return new Array(messagesLength).fill(null).map((_, idx) => {
1747
1779
  const messageIndex = idx;
1748
- return /* @__PURE__ */ jsx24(
1780
+ return /* @__PURE__ */ jsx27(
1749
1781
  ThreadMessage,
1750
1782
  {
1751
1783
  messageIndex,
@@ -2147,7 +2179,6 @@ export {
2147
2179
  useContentPartContext,
2148
2180
  useContentPartDisplay,
2149
2181
  useContentPartImage,
2150
- useContentPartInProgressIndicator,
2151
2182
  useContentPartText,
2152
2183
  useLocalRuntime,
2153
2184
  useMessageContext,