@assistant-ui/react 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -584,7 +584,7 @@ var useActionBarCopy = ({
584
584
  const hasCopyableContent = useCombinedStore(
585
585
  [useMessage, useEditComposer],
586
586
  (m, c) => {
587
- return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
587
+ return !c.isEditing && m.message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
588
588
  }
589
589
  );
590
590
  const callback = (0, import_react16.useCallback)(() => {
@@ -757,7 +757,7 @@ var useContentPartText = () => {
757
757
  throw new Error(
758
758
  "ContentPartText can only be used inside text content parts."
759
759
  );
760
- return c.part.text;
760
+ return c;
761
761
  });
762
762
  return text;
763
763
  };
@@ -933,6 +933,7 @@ var ActionBarPrimitiveEdit = createActionButton(
933
933
  // src/primitives/assistantModal/index.ts
934
934
  var assistantModal_exports = {};
935
935
  __export(assistantModal_exports, {
936
+ Anchor: () => AssistantModalPrimitiveAnchor,
936
937
  Content: () => AssistantModalPrimitiveContent,
937
938
  Root: () => AssistantModalPrimitiveRoot,
938
939
  Trigger: () => AssistantModalPrimitiveTrigger
@@ -1039,6 +1040,21 @@ var AssistantModalPrimitiveContent = (0, import_react30.forwardRef)(
1039
1040
  );
1040
1041
  AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
1041
1042
 
1043
+ // src/primitives/assistantModal/AssistantModalAnchor.tsx
1044
+ var import_react31 = require("react");
1045
+ var PopoverPrimitive5 = __toESM(require("@radix-ui/react-popover"));
1046
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1047
+ var AssistantModalPrimitiveAnchor = (0, import_react31.forwardRef)(
1048
+ ({
1049
+ __scopeAssistantModal,
1050
+ ...rest
1051
+ }, ref) => {
1052
+ const scope = usePopoverScope(__scopeAssistantModal);
1053
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PopoverPrimitive5.Anchor, { ...scope, ...rest, ref });
1054
+ }
1055
+ );
1056
+ AssistantModalPrimitiveAnchor.displayName = "AssistantModalPrimitive.Anchor";
1057
+
1042
1058
  // src/primitives/branchPicker/index.ts
1043
1059
  var branchPicker_exports = {};
1044
1060
  __export(branchPicker_exports, {
@@ -1062,24 +1078,24 @@ var BranchPickerPrevious = createActionButton(
1062
1078
  );
1063
1079
 
1064
1080
  // src/primitives/branchPicker/BranchPickerCount.tsx
1065
- var import_jsx_runtime9 = require("react/jsx-runtime");
1081
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1066
1082
  var BranchPickerPrimitiveCount = () => {
1067
1083
  const branchCount = useBranchPickerCount();
1068
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: branchCount });
1084
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: branchCount });
1069
1085
  };
1070
1086
  BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
1071
1087
 
1072
1088
  // src/primitives/branchPicker/BranchPickerNumber.tsx
1073
- var import_jsx_runtime10 = require("react/jsx-runtime");
1089
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1074
1090
  var BranchPickerPrimitiveNumber = () => {
1075
1091
  const branchNumber = useBranchPickerNumber();
1076
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: branchNumber });
1092
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: branchNumber });
1077
1093
  };
1078
1094
  BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
1079
1095
 
1080
1096
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1081
1097
  var import_react_primitive6 = require("@radix-ui/react-primitive");
1082
- var import_react37 = require("react");
1098
+ var import_react38 = require("react");
1083
1099
 
1084
1100
  // src/primitives/message/index.ts
1085
1101
  var message_exports = {};
@@ -1091,28 +1107,57 @@ __export(message_exports, {
1091
1107
  });
1092
1108
 
1093
1109
  // src/primitives/message/MessageRoot.tsx
1094
- var import_primitive4 = require("@radix-ui/primitive");
1095
1110
  var import_react_primitive3 = require("@radix-ui/react-primitive");
1096
- var import_react31 = require("react");
1097
- var import_jsx_runtime11 = require("react/jsx-runtime");
1098
- var MessagePrimitiveRoot = (0, import_react31.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
1111
+ var import_react33 = require("react");
1112
+
1113
+ // src/utils/hooks/useManagedRef.ts
1114
+ var import_react32 = require("react");
1115
+ var useManagedRef = (callback) => {
1116
+ const cleanupRef = (0, import_react32.useRef)();
1117
+ const ref = (0, import_react32.useCallback)(
1118
+ (el) => {
1119
+ if (cleanupRef.current) {
1120
+ cleanupRef.current();
1121
+ }
1122
+ if (el) {
1123
+ cleanupRef.current = callback(el);
1124
+ }
1125
+ },
1126
+ [callback]
1127
+ );
1128
+ return ref;
1129
+ };
1130
+
1131
+ // src/primitives/message/MessageRoot.tsx
1132
+ var import_react_compose_refs = require("@radix-ui/react-compose-refs");
1133
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1134
+ var useIsHoveringRef = () => {
1099
1135
  const { useMessageUtils } = useMessageContext();
1100
- const setIsHovering = useMessageUtils((s) => s.setIsHovering);
1101
- const handleMouseEnter = () => {
1102
- setIsHovering(true);
1103
- };
1104
- const handleMouseLeave = () => {
1105
- setIsHovering(false);
1106
- };
1107
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1108
- import_react_primitive3.Primitive.div,
1109
- {
1110
- ...rest,
1111
- ref,
1112
- onMouseEnter: (0, import_primitive4.composeEventHandlers)(onMouseEnter, handleMouseEnter),
1113
- onMouseLeave: (0, import_primitive4.composeEventHandlers)(onMouseLeave, handleMouseLeave)
1114
- }
1136
+ const callbackRef = (0, import_react33.useCallback)(
1137
+ (el) => {
1138
+ const setIsHovering = useMessageUtils.getState().setIsHovering;
1139
+ const handleMouseEnter = () => {
1140
+ setIsHovering(true);
1141
+ };
1142
+ const handleMouseLeave = () => {
1143
+ setIsHovering(false);
1144
+ };
1145
+ el.addEventListener("mouseenter", handleMouseEnter);
1146
+ el.addEventListener("mouseleave", handleMouseLeave);
1147
+ return () => {
1148
+ el.removeEventListener("mouseenter", handleMouseEnter);
1149
+ el.removeEventListener("mouseleave", handleMouseLeave);
1150
+ setIsHovering(false);
1151
+ };
1152
+ },
1153
+ [useMessageUtils]
1115
1154
  );
1155
+ return useManagedRef(callbackRef);
1156
+ };
1157
+ var MessagePrimitiveRoot = (0, import_react33.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef15) => {
1158
+ const isHoveringRef = useIsHoveringRef();
1159
+ const ref = (0, import_react_compose_refs.useComposedRefs)(forwardRef15, isHoveringRef);
1160
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_primitive3.Primitive.div, { ...rest, ref });
1116
1161
  });
1117
1162
  MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
1118
1163
 
@@ -1127,12 +1172,12 @@ var MessagePrimitiveIf = ({
1127
1172
  MessagePrimitiveIf.displayName = "MessagePrimitive.If";
1128
1173
 
1129
1174
  // src/primitives/message/MessageContent.tsx
1130
- var import_react35 = require("react");
1175
+ var import_react37 = require("react");
1131
1176
 
1132
1177
  // src/context/providers/ContentPartProvider.tsx
1133
- var import_react32 = require("react");
1178
+ var import_react34 = require("react");
1134
1179
  var import_zustand9 = require("zustand");
1135
- var import_jsx_runtime12 = require("react/jsx-runtime");
1180
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1136
1181
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
1137
1182
  const part = message.content[partIndex];
1138
1183
  if (!part) return;
@@ -1149,14 +1194,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
1149
1194
  };
1150
1195
  var useContentPartContext2 = (partIndex) => {
1151
1196
  const { useMessage } = useMessageContext();
1152
- const [context] = (0, import_react32.useState)(() => {
1197
+ const [context] = (0, import_react34.useState)(() => {
1153
1198
  const useContentPart = (0, import_zustand9.create)(
1154
1199
  () => ({})
1155
1200
  );
1156
1201
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
1157
1202
  return { useContentPart };
1158
1203
  });
1159
- (0, import_react32.useEffect)(() => {
1204
+ (0, import_react34.useEffect)(() => {
1160
1205
  syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
1161
1206
  return useMessage.subscribe((message) => {
1162
1207
  syncContentPart(message, context.useContentPart, partIndex);
@@ -1169,9 +1214,32 @@ var ContentPartProvider = ({
1169
1214
  children
1170
1215
  }) => {
1171
1216
  const context = useContentPartContext2(partIndex);
1172
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContentPartContext.Provider, { value: context, children });
1217
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ContentPartContext.Provider, { value: context, children });
1173
1218
  };
1174
1219
 
1220
+ // src/primitives/contentPart/ContentPartText.tsx
1221
+ var import_react_primitive4 = require("@radix-ui/react-primitive");
1222
+ var import_react35 = require("react");
1223
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1224
+ var ContentPartPrimitiveText = (0, import_react35.forwardRef)((props, forwardedRef) => {
1225
+ const {
1226
+ part: { text },
1227
+ status
1228
+ } = useContentPartText();
1229
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_primitive4.Primitive.span, { "data-status": status, ...props, ref: forwardedRef, children: text });
1230
+ });
1231
+ ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
1232
+
1233
+ // src/primitives/contentPart/ContentPartImage.tsx
1234
+ var import_react_primitive5 = require("@radix-ui/react-primitive");
1235
+ var import_react36 = require("react");
1236
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1237
+ var ContentPartPrimitiveImage = (0, import_react36.forwardRef)((props, forwardedRef) => {
1238
+ const image = useContentPartImage();
1239
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive5.Primitive.img, { src: image, ...props, ref: forwardedRef });
1240
+ });
1241
+ ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
1242
+
1175
1243
  // src/primitives/contentPart/ContentPartDisplay.tsx
1176
1244
  var ContentPartPrimitiveDisplay = () => {
1177
1245
  const display = useContentPartDisplay();
@@ -1179,54 +1247,24 @@ var ContentPartPrimitiveDisplay = () => {
1179
1247
  };
1180
1248
  ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
1181
1249
 
1182
- // src/utils/OutPortal.tsx
1183
- var import_react33 = require("react");
1184
- var import_jsx_runtime13 = require("react/jsx-runtime");
1185
- var OutPortal = ({ node }) => {
1186
- const parentRef = (0, import_react33.useRef)(null);
1187
- (0, import_react33.useLayoutEffect)(() => {
1188
- const parent = parentRef.current;
1189
- if (!parent || !node) return;
1190
- parent.appendChild(node);
1191
- return () => {
1192
- parent.removeChild(node);
1193
- };
1194
- }, [node]);
1195
- if (!node) return null;
1196
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { ref: parentRef });
1197
- };
1198
-
1199
- // src/primitives/contentPart/ContentPartInProgressIndicator.tsx
1200
- var import_jsx_runtime14 = require("react/jsx-runtime");
1201
- var ContentPartPrimitiveInProgressIndicator = () => {
1202
- const { useMessageUtils } = useMessageContext();
1250
+ // src/primitives/contentPart/ContentPartInProgress.tsx
1251
+ var ContentPartPrimitiveInProgress = ({
1252
+ children
1253
+ }) => {
1203
1254
  const { useContentPart } = useContentPartContext();
1204
- const indicator = useCombinedStore(
1205
- [useMessageUtils, useContentPart],
1206
- (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
1207
- );
1208
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(OutPortal, { node: indicator });
1255
+ const isInProgress = useContentPart((c) => c.status === "in_progress");
1256
+ return isInProgress ? children : null;
1209
1257
  };
1210
- ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
1211
-
1212
- // src/primitives/contentPart/ContentPartText.tsx
1213
- var import_react_primitive4 = require("@radix-ui/react-primitive");
1214
- var import_react34 = require("react");
1215
- var import_jsx_runtime15 = require("react/jsx-runtime");
1216
- var ContentPartPrimitiveText = (0, import_react34.forwardRef)((props, forwardedRef) => {
1217
- const text = useContentPartText();
1218
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive4.Primitive.span, { ...props, ref: forwardedRef, children: text });
1219
- });
1220
- ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
1258
+ ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
1221
1259
 
1222
1260
  // src/primitives/message/MessageContent.tsx
1223
1261
  var import_jsx_runtime16 = require("react/jsx-runtime");
1224
1262
  var defaultComponents = {
1225
1263
  Text: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("p", { style: { whiteSpace: "pre-line" }, children: [
1226
1264
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveText, {}),
1227
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveInProgressIndicator, {})
1265
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveInProgress, { children: " \u25CF" })
1228
1266
  ] }),
1229
- Image: () => null,
1267
+ Image: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveImage, {}),
1230
1268
  UI: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveDisplay, {}),
1231
1269
  tools: {
1232
1270
  Fallback: (props) => {
@@ -1272,7 +1310,7 @@ var MessageContentPartImpl = ({
1272
1310
  }) => {
1273
1311
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageContentPartComponent, { components }) });
1274
1312
  };
1275
- var MessageContentPart = (0, import_react35.memo)(
1313
+ var MessageContentPart = (0, import_react37.memo)(
1276
1314
  MessageContentPartImpl,
1277
1315
  (prev, next) => prev.partIndex === next.partIndex && prev.components?.Text === next.components?.Text && prev.components?.Image === next.components?.Image && prev.components?.UI === next.components?.UI && prev.components?.tools === next.components?.tools
1278
1316
  );
@@ -1296,21 +1334,15 @@ var MessagePrimitiveContent = ({
1296
1334
  MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
1297
1335
 
1298
1336
  // src/primitives/message/MessageInProgress.tsx
1299
- var import_react_dom = require("react-dom");
1300
- var import_react_primitive5 = require("@radix-ui/react-primitive");
1301
- var import_react36 = require("react");
1302
- var import_jsx_runtime17 = require("react/jsx-runtime");
1303
- var MessagePrimitiveInProgress = (0, import_react36.forwardRef)((props, ref) => {
1304
- const { useMessageUtils } = useMessageContext();
1305
- const portalNode = useMessageUtils((s) => s.inProgressIndicator);
1306
- return (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_primitive5.Primitive.span, { ...props, ref }), portalNode);
1307
- });
1337
+ var MessagePrimitiveInProgress = () => {
1338
+ return null;
1339
+ };
1308
1340
  MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
1309
1341
 
1310
1342
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1311
- var import_jsx_runtime18 = require("react/jsx-runtime");
1312
- var BranchPickerPrimitiveRoot = (0, import_react37.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
1313
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
1343
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1344
+ var BranchPickerPrimitiveRoot = (0, import_react38.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
1345
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
1314
1346
  });
1315
1347
  BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
1316
1348
 
@@ -1325,37 +1357,37 @@ __export(composer_exports, {
1325
1357
  });
1326
1358
 
1327
1359
  // src/primitives/composer/ComposerRoot.tsx
1328
- var import_primitive5 = require("@radix-ui/primitive");
1360
+ var import_primitive4 = require("@radix-ui/primitive");
1329
1361
  var import_react_primitive7 = require("@radix-ui/react-primitive");
1330
- var import_react38 = require("react");
1331
- var import_jsx_runtime19 = require("react/jsx-runtime");
1332
- var ComposerPrimitiveRoot = (0, import_react38.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
1362
+ var import_react39 = require("react");
1363
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1364
+ var ComposerPrimitiveRoot = (0, import_react39.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
1333
1365
  const send = useComposerSend();
1334
1366
  const handleSubmit = (e) => {
1335
1367
  e.preventDefault();
1336
1368
  if (!send) return;
1337
1369
  send();
1338
1370
  };
1339
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1371
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1340
1372
  import_react_primitive7.Primitive.form,
1341
1373
  {
1342
1374
  ...rest,
1343
1375
  ref: forwardedRef,
1344
- onSubmit: (0, import_primitive5.composeEventHandlers)(onSubmit, handleSubmit)
1376
+ onSubmit: (0, import_primitive4.composeEventHandlers)(onSubmit, handleSubmit)
1345
1377
  }
1346
1378
  );
1347
1379
  });
1348
1380
  ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
1349
1381
 
1350
1382
  // src/primitives/composer/ComposerInput.tsx
1351
- var import_primitive6 = require("@radix-ui/primitive");
1352
- var import_react_compose_refs = require("@radix-ui/react-compose-refs");
1383
+ var import_primitive5 = require("@radix-ui/primitive");
1384
+ var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
1353
1385
  var import_react_slot = require("@radix-ui/react-slot");
1354
- var import_react39 = require("react");
1386
+ var import_react40 = require("react");
1355
1387
  var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
1356
1388
  var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
1357
- var import_jsx_runtime20 = require("react/jsx-runtime");
1358
- var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1389
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1390
+ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
1359
1391
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
1360
1392
  const { useThread } = useThreadContext();
1361
1393
  const { useComposer, type } = useComposerContext();
@@ -1364,8 +1396,8 @@ var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1364
1396
  return c.value;
1365
1397
  });
1366
1398
  const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
1367
- const textareaRef = (0, import_react39.useRef)(null);
1368
- const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, textareaRef);
1399
+ const textareaRef = (0, import_react40.useRef)(null);
1400
+ const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, textareaRef);
1369
1401
  (0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
1370
1402
  const composer = useComposer.getState();
1371
1403
  if (composer.cancel()) {
@@ -1383,7 +1415,7 @@ var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1383
1415
  }
1384
1416
  };
1385
1417
  const autoFocusEnabled = autoFocus && !disabled;
1386
- const focus = (0, import_react39.useCallback)(() => {
1418
+ const focus = (0, import_react40.useCallback)(() => {
1387
1419
  const textarea = textareaRef.current;
1388
1420
  if (!textarea || !autoFocusEnabled) return;
1389
1421
  textarea.focus({ preventScroll: true });
@@ -1392,25 +1424,26 @@ var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1392
1424
  textareaRef.current.value.length
1393
1425
  );
1394
1426
  }, [autoFocusEnabled]);
1395
- (0, import_react39.useEffect)(() => focus(), [focus]);
1427
+ (0, import_react40.useEffect)(() => focus(), [focus]);
1396
1428
  useOnComposerFocus(() => {
1397
1429
  if (type === "new") {
1398
1430
  focus();
1399
1431
  }
1400
1432
  });
1401
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1433
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1402
1434
  Component,
1403
1435
  {
1436
+ name: "input",
1404
1437
  value,
1405
1438
  ...rest,
1406
1439
  ref,
1407
1440
  disabled,
1408
- onChange: (0, import_primitive6.composeEventHandlers)(onChange, (e) => {
1441
+ onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
1409
1442
  const composerState = useComposer.getState();
1410
1443
  if (!composerState.isEditing) return;
1411
1444
  return composerState.setValue(e.target.value);
1412
1445
  }),
1413
- onKeyDown: (0, import_primitive6.composeEventHandlers)(onKeyDown, handleKeyPress)
1446
+ onKeyDown: (0, import_primitive5.composeEventHandlers)(onKeyDown, handleKeyPress)
1414
1447
  }
1415
1448
  );
1416
1449
  }
@@ -1418,13 +1451,13 @@ var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1418
1451
  ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
1419
1452
 
1420
1453
  // src/primitives/composer/ComposerSend.tsx
1421
- var import_react40 = require("react");
1454
+ var import_react41 = require("react");
1422
1455
  var import_react_primitive8 = require("@radix-ui/react-primitive");
1423
- var import_jsx_runtime21 = require("react/jsx-runtime");
1424
- var ComposerPrimitiveSend = (0, import_react40.forwardRef)(({ disabled, ...rest }, ref) => {
1456
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1457
+ var ComposerPrimitiveSend = (0, import_react41.forwardRef)(({ disabled, ...rest }, ref) => {
1425
1458
  const { useComposer } = useComposerContext();
1426
1459
  const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1427
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1460
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1428
1461
  import_react_primitive8.Primitive.button,
1429
1462
  {
1430
1463
  type: "submit",
@@ -1457,20 +1490,10 @@ var contentPart_exports = {};
1457
1490
  __export(contentPart_exports, {
1458
1491
  Display: () => ContentPartPrimitiveDisplay,
1459
1492
  Image: () => ContentPartPrimitiveImage,
1460
- InProgressIndicator: () => ContentPartPrimitiveInProgressIndicator,
1493
+ InProgress: () => ContentPartPrimitiveInProgress,
1461
1494
  Text: () => ContentPartPrimitiveText
1462
1495
  });
1463
1496
 
1464
- // src/primitives/contentPart/ContentPartImage.tsx
1465
- var import_react_primitive9 = require("@radix-ui/react-primitive");
1466
- var import_react41 = require("react");
1467
- var import_jsx_runtime22 = require("react/jsx-runtime");
1468
- var ContentPartPrimitiveImage = (0, import_react41.forwardRef)((props, forwardedRef) => {
1469
- const image = useContentPartImage();
1470
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
1471
- });
1472
- ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
1473
-
1474
1497
  // src/primitives/thread/index.ts
1475
1498
  var thread_exports = {};
1476
1499
  __export(thread_exports, {
@@ -1484,11 +1507,11 @@ __export(thread_exports, {
1484
1507
  });
1485
1508
 
1486
1509
  // src/primitives/thread/ThreadRoot.tsx
1487
- var import_react_primitive10 = require("@radix-ui/react-primitive");
1510
+ var import_react_primitive9 = require("@radix-ui/react-primitive");
1488
1511
  var import_react42 = require("react");
1489
- var import_jsx_runtime23 = require("react/jsx-runtime");
1512
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1490
1513
  var ThreadPrimitiveRoot = (0, import_react42.forwardRef)((props, ref) => {
1491
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react_primitive10.Primitive.div, { ...props, ref });
1514
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react_primitive9.Primitive.div, { ...props, ref });
1492
1515
  });
1493
1516
  ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
1494
1517
 
@@ -1512,40 +1535,20 @@ var ThreadPrimitiveIf = ({
1512
1535
  ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
1513
1536
 
1514
1537
  // src/primitives/thread/ThreadViewport.tsx
1515
- var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
1516
- var import_react_primitive11 = require("@radix-ui/react-primitive");
1517
- var import_react47 = require("react");
1538
+ var import_react_compose_refs4 = require("@radix-ui/react-compose-refs");
1539
+ var import_react_primitive10 = require("@radix-ui/react-primitive");
1540
+ var import_react46 = require("react");
1518
1541
 
1519
1542
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
1520
- var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
1521
- var import_react46 = require("react");
1543
+ var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
1544
+ var import_react45 = require("react");
1522
1545
 
1523
1546
  // src/utils/hooks/useOnResizeContent.tsx
1524
1547
  var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
1525
- var import_react44 = require("react");
1526
-
1527
- // src/utils/hooks/useManagedRef.ts
1528
1548
  var import_react43 = require("react");
1529
- var useManagedRef = (callback) => {
1530
- const cleanupRef = (0, import_react43.useRef)();
1531
- const ref = (0, import_react43.useCallback)(
1532
- (el) => {
1533
- if (cleanupRef.current) {
1534
- cleanupRef.current();
1535
- }
1536
- if (el) {
1537
- cleanupRef.current = callback(el);
1538
- }
1539
- },
1540
- [callback]
1541
- );
1542
- return ref;
1543
- };
1544
-
1545
- // src/utils/hooks/useOnResizeContent.tsx
1546
1549
  var useOnResizeContent = (callback) => {
1547
1550
  const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
1548
- const refCallback = (0, import_react44.useCallback)(
1551
+ const refCallback = (0, import_react43.useCallback)(
1549
1552
  (el) => {
1550
1553
  const resizeObserver = new ResizeObserver(() => {
1551
1554
  callbackRef();
@@ -1582,11 +1585,11 @@ var useOnResizeContent = (callback) => {
1582
1585
 
1583
1586
  // src/utils/hooks/useOnScrollToBottom.tsx
1584
1587
  var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
1585
- var import_react45 = require("react");
1588
+ var import_react44 = require("react");
1586
1589
  var useOnScrollToBottom = (callback) => {
1587
1590
  const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
1588
1591
  const { useViewport } = useThreadContext();
1589
- (0, import_react45.useEffect)(() => {
1592
+ (0, import_react44.useEffect)(() => {
1590
1593
  return useViewport.getState().onScrollToBottom(() => {
1591
1594
  callbackRef();
1592
1595
  });
@@ -1597,11 +1600,11 @@ var useOnScrollToBottom = (callback) => {
1597
1600
  var useThreadViewportAutoScroll = ({
1598
1601
  autoScroll = true
1599
1602
  }) => {
1600
- const divRef = (0, import_react46.useRef)(null);
1603
+ const divRef = (0, import_react45.useRef)(null);
1601
1604
  const { useViewport } = useThreadContext();
1602
- const firstRenderRef = (0, import_react46.useRef)(true);
1603
- const lastScrollTop = (0, import_react46.useRef)(0);
1604
- const isScrollingToBottomRef = (0, import_react46.useRef)(false);
1605
+ const firstRenderRef = (0, import_react45.useRef)(true);
1606
+ const lastScrollTop = (0, import_react45.useRef)(0);
1607
+ const isScrollingToBottomRef = (0, import_react45.useRef)(false);
1605
1608
  const scrollToBottom = () => {
1606
1609
  const div = divRef.current;
1607
1610
  if (!div || !autoScroll) return;
@@ -1639,7 +1642,7 @@ var useThreadViewportAutoScroll = ({
1639
1642
  el.removeEventListener("scroll", handleScroll);
1640
1643
  };
1641
1644
  });
1642
- const autoScrollRef = (0, import_react_compose_refs2.useComposedRefs)(resizeRef, scrollRef, divRef);
1645
+ const autoScrollRef = (0, import_react_compose_refs3.useComposedRefs)(resizeRef, scrollRef, divRef);
1643
1646
  useOnScrollToBottom(() => {
1644
1647
  scrollToBottom();
1645
1648
  });
@@ -1647,21 +1650,21 @@ var useThreadViewportAutoScroll = ({
1647
1650
  };
1648
1651
 
1649
1652
  // src/primitives/thread/ThreadViewport.tsx
1650
- var import_jsx_runtime24 = require("react/jsx-runtime");
1651
- var ThreadPrimitiveViewport = (0, import_react47.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1653
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1654
+ var ThreadPrimitiveViewport = (0, import_react46.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1652
1655
  const autoScrollRef = useThreadViewportAutoScroll({
1653
1656
  autoScroll
1654
1657
  });
1655
- const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, autoScrollRef);
1656
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react_primitive11.Primitive.div, { ...rest, ref, children });
1658
+ const ref = (0, import_react_compose_refs4.useComposedRefs)(forwardedRef, autoScrollRef);
1659
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive10.Primitive.div, { ...rest, ref, children });
1657
1660
  });
1658
1661
  ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
1659
1662
 
1660
1663
  // src/primitives/thread/ThreadMessages.tsx
1661
- var import_react49 = require("react");
1664
+ var import_react48 = require("react");
1662
1665
 
1663
1666
  // src/context/providers/MessageProvider.tsx
1664
- var import_react48 = require("react");
1667
+ var import_react47 = require("react");
1665
1668
  var import_zustand12 = require("zustand");
1666
1669
 
1667
1670
  // src/context/stores/EditComposer.ts
@@ -1691,7 +1694,6 @@ var makeEditComposerStore = ({
1691
1694
  // src/context/stores/MessageUtils.ts
1692
1695
  var import_zustand11 = require("zustand");
1693
1696
  var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
1694
- inProgressIndicator: document.createElement("span"),
1695
1697
  isCopied: false,
1696
1698
  setIsCopied: (value) => {
1697
1699
  set({ isCopied: value });
@@ -1703,7 +1705,7 @@ var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
1703
1705
  }));
1704
1706
 
1705
1707
  // src/context/providers/MessageProvider.tsx
1706
- var import_jsx_runtime25 = require("react/jsx-runtime");
1708
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1707
1709
  var getIsLast = (messages, message) => {
1708
1710
  return messages[messages.length - 1]?.id === message.id;
1709
1711
  };
@@ -1725,7 +1727,7 @@ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
1725
1727
  };
1726
1728
  var useMessageContext2 = (messageIndex) => {
1727
1729
  const { useThreadMessages, useThreadActions } = useThreadContext();
1728
- const [context] = (0, import_react48.useState)(() => {
1730
+ const [context] = (0, import_react47.useState)(() => {
1729
1731
  const useMessage = (0, import_zustand12.create)(() => ({}));
1730
1732
  const useMessageUtils = makeMessageUtilsStore();
1731
1733
  const useEditComposer = makeEditComposerStore({
@@ -1762,7 +1764,7 @@ var useMessageContext2 = (messageIndex) => {
1762
1764
  );
1763
1765
  return { useMessage, useMessageUtils, useEditComposer };
1764
1766
  });
1765
- (0, import_react48.useEffect)(() => {
1767
+ (0, import_react47.useEffect)(() => {
1766
1768
  return useThreadMessages.subscribe((thread) => {
1767
1769
  syncMessage(
1768
1770
  thread,
@@ -1779,11 +1781,11 @@ var MessageProvider = ({
1779
1781
  children
1780
1782
  }) => {
1781
1783
  const context = useMessageContext2(messageIndex);
1782
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(MessageContext.Provider, { value: context, children });
1784
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(MessageContext.Provider, { value: context, children });
1783
1785
  };
1784
1786
 
1785
1787
  // src/primitives/thread/ThreadMessages.tsx
1786
- var import_jsx_runtime26 = require("react/jsx-runtime");
1788
+ var import_jsx_runtime24 = require("react/jsx-runtime");
1787
1789
  var getComponents = (components) => {
1788
1790
  return {
1789
1791
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
@@ -1796,15 +1798,15 @@ var ThreadMessageImpl = ({
1796
1798
  components
1797
1799
  }) => {
1798
1800
  const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1799
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(MessageProvider, { messageIndex, children: [
1800
- /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(MessagePrimitiveIf, { user: true, children: [
1801
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(UserMessage, {}) }),
1802
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(EditComposer, {}) })
1801
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessageProvider, { messageIndex, children: [
1802
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessagePrimitiveIf, { user: true, children: [
1803
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(UserMessage, {}) }),
1804
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(EditComposer, {}) })
1803
1805
  ] }),
1804
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(AssistantMessage, {}) })
1806
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
1805
1807
  ] });
1806
1808
  };
1807
- var ThreadMessage = (0, import_react49.memo)(
1809
+ var ThreadMessage = (0, import_react48.memo)(
1808
1810
  ThreadMessageImpl,
1809
1811
  (prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
1810
1812
  );
@@ -1816,7 +1818,7 @@ var ThreadPrimitiveMessages = ({
1816
1818
  if (messagesLength === 0) return null;
1817
1819
  return new Array(messagesLength).fill(null).map((_, idx) => {
1818
1820
  const messageIndex = idx;
1819
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1821
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1820
1822
  ThreadMessage,
1821
1823
  {
1822
1824
  messageIndex,
@@ -1841,7 +1843,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
1841
1843
  );
1842
1844
 
1843
1845
  // src/runtime/local/useLocalRuntime.tsx
1844
- var import_react50 = require("react");
1846
+ var import_react49 = require("react");
1845
1847
 
1846
1848
  // src/runtime/utils/idUtils.tsx
1847
1849
  var import_non_secure = require("nanoid/non-secure");
@@ -2173,8 +2175,8 @@ var LocalThreadRuntime = class {
2173
2175
 
2174
2176
  // src/runtime/local/useLocalRuntime.tsx
2175
2177
  var useLocalRuntime = (adapter) => {
2176
- const [runtime] = (0, import_react50.useState)(() => new LocalRuntime(adapter));
2177
- (0, import_react50.useInsertionEffect)(() => {
2178
+ const [runtime] = (0, import_react49.useState)(() => new LocalRuntime(adapter));
2179
+ (0, import_react49.useInsertionEffect)(() => {
2178
2180
  runtime.adapter = adapter;
2179
2181
  });
2180
2182
  return runtime;