@assistant-ui/react 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +43 -48
- package/dist/index.d.ts +43 -48
- package/dist/index.js +156 -170
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -155
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
@@ -522,7 +522,7 @@ var useActionBarCopy = ({
|
|
522
522
|
const hasCopyableContent = useCombinedStore(
|
523
523
|
[useMessage, useEditComposer],
|
524
524
|
(m, c) => {
|
525
|
-
return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
|
525
|
+
return !c.isEditing && m.message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
526
526
|
}
|
527
527
|
);
|
528
528
|
const callback = useCallback4(() => {
|
@@ -695,7 +695,7 @@ var useContentPartText = () => {
|
|
695
695
|
throw new Error(
|
696
696
|
"ContentPartText can only be used inside text content parts."
|
697
697
|
);
|
698
|
-
return c
|
698
|
+
return c;
|
699
699
|
});
|
700
700
|
return text;
|
701
701
|
};
|
@@ -1045,28 +1045,60 @@ __export(message_exports, {
|
|
1045
1045
|
});
|
1046
1046
|
|
1047
1047
|
// src/primitives/message/MessageRoot.tsx
|
1048
|
-
import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
|
1049
1048
|
import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
|
1050
|
-
import {
|
1049
|
+
import {
|
1050
|
+
forwardRef as forwardRef6,
|
1051
|
+
useCallback as useCallback14
|
1052
|
+
} from "react";
|
1053
|
+
|
1054
|
+
// src/utils/hooks/useManagedRef.ts
|
1055
|
+
import { useCallback as useCallback13, useRef as useRef3 } from "react";
|
1056
|
+
var useManagedRef = (callback) => {
|
1057
|
+
const cleanupRef = useRef3();
|
1058
|
+
const ref = useCallback13(
|
1059
|
+
(el) => {
|
1060
|
+
if (cleanupRef.current) {
|
1061
|
+
cleanupRef.current();
|
1062
|
+
}
|
1063
|
+
if (el) {
|
1064
|
+
cleanupRef.current = callback(el);
|
1065
|
+
}
|
1066
|
+
},
|
1067
|
+
[callback]
|
1068
|
+
);
|
1069
|
+
return ref;
|
1070
|
+
};
|
1071
|
+
|
1072
|
+
// src/primitives/message/MessageRoot.tsx
|
1073
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
1051
1074
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
1052
|
-
var
|
1075
|
+
var useIsHoveringRef = () => {
|
1053
1076
|
const { useMessageUtils } = useMessageContext();
|
1054
|
-
const
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1077
|
+
const callbackRef = useCallback14(
|
1078
|
+
(el) => {
|
1079
|
+
const setIsHovering = useMessageUtils.getState().setIsHovering;
|
1080
|
+
const handleMouseEnter = () => {
|
1081
|
+
setIsHovering(true);
|
1082
|
+
};
|
1083
|
+
const handleMouseLeave = () => {
|
1084
|
+
setIsHovering(false);
|
1085
|
+
};
|
1086
|
+
el.addEventListener("mouseenter", handleMouseEnter);
|
1087
|
+
el.addEventListener("mouseleave", handleMouseLeave);
|
1088
|
+
return () => {
|
1089
|
+
el.removeEventListener("mouseenter", handleMouseEnter);
|
1090
|
+
el.removeEventListener("mouseleave", handleMouseLeave);
|
1091
|
+
setIsHovering(false);
|
1092
|
+
};
|
1093
|
+
},
|
1094
|
+
[useMessageUtils]
|
1069
1095
|
);
|
1096
|
+
return useManagedRef(callbackRef);
|
1097
|
+
};
|
1098
|
+
var MessagePrimitiveRoot = forwardRef6(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef15) => {
|
1099
|
+
const isHoveringRef = useIsHoveringRef();
|
1100
|
+
const ref = useComposedRefs(forwardRef15, isHoveringRef);
|
1101
|
+
return /* @__PURE__ */ jsx12(Primitive3.div, { ...rest, ref });
|
1070
1102
|
});
|
1071
1103
|
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
1072
1104
|
|
@@ -1126,6 +1158,29 @@ var ContentPartProvider = ({
|
|
1126
1158
|
return /* @__PURE__ */ jsx13(ContentPartContext.Provider, { value: context, children });
|
1127
1159
|
};
|
1128
1160
|
|
1161
|
+
// src/primitives/contentPart/ContentPartText.tsx
|
1162
|
+
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
1163
|
+
import { forwardRef as forwardRef7 } from "react";
|
1164
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
1165
|
+
var ContentPartPrimitiveText = forwardRef7((props, forwardedRef) => {
|
1166
|
+
const {
|
1167
|
+
part: { text },
|
1168
|
+
status
|
1169
|
+
} = useContentPartText();
|
1170
|
+
return /* @__PURE__ */ jsx14(Primitive4.span, { "data-status": status, ...props, ref: forwardedRef, children: text });
|
1171
|
+
});
|
1172
|
+
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1173
|
+
|
1174
|
+
// src/primitives/contentPart/ContentPartImage.tsx
|
1175
|
+
import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
|
1176
|
+
import { forwardRef as forwardRef8 } from "react";
|
1177
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
1178
|
+
var ContentPartPrimitiveImage = forwardRef8((props, forwardedRef) => {
|
1179
|
+
const image = useContentPartImage();
|
1180
|
+
return /* @__PURE__ */ jsx15(Primitive5.img, { src: image, ...props, ref: forwardedRef });
|
1181
|
+
});
|
1182
|
+
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1183
|
+
|
1129
1184
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1130
1185
|
var ContentPartPrimitiveDisplay = () => {
|
1131
1186
|
const display = useContentPartDisplay();
|
@@ -1133,61 +1188,31 @@ var ContentPartPrimitiveDisplay = () => {
|
|
1133
1188
|
};
|
1134
1189
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
1135
1190
|
|
1136
|
-
// src/
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
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
|
-
|
1153
|
-
// src/primitives/contentPart/ContentPartInProgressIndicator.tsx
|
1154
|
-
import { jsx as jsx15 } from "react/jsx-runtime";
|
1155
|
-
var ContentPartPrimitiveInProgressIndicator = () => {
|
1156
|
-
const { useMessageUtils } = useMessageContext();
|
1191
|
+
// src/primitives/contentPart/ContentPartInProgress.tsx
|
1192
|
+
var ContentPartPrimitiveInProgress = ({
|
1193
|
+
children
|
1194
|
+
}) => {
|
1157
1195
|
const { useContentPart } = useContentPartContext();
|
1158
|
-
const
|
1159
|
-
|
1160
|
-
(m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
|
1161
|
-
);
|
1162
|
-
return /* @__PURE__ */ jsx15(OutPortal, { node: indicator });
|
1196
|
+
const isInProgress = useContentPart((c) => c.status === "in_progress");
|
1197
|
+
return isInProgress ? children : null;
|
1163
1198
|
};
|
1164
|
-
|
1165
|
-
|
1166
|
-
// src/primitives/contentPart/ContentPartText.tsx
|
1167
|
-
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
1168
|
-
import { forwardRef as forwardRef7 } from "react";
|
1169
|
-
import { jsx as jsx16 } from "react/jsx-runtime";
|
1170
|
-
var ContentPartPrimitiveText = forwardRef7((props, forwardedRef) => {
|
1171
|
-
const text = useContentPartText();
|
1172
|
-
return /* @__PURE__ */ jsx16(Primitive4.span, { ...props, ref: forwardedRef, children: text });
|
1173
|
-
});
|
1174
|
-
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1199
|
+
ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
|
1175
1200
|
|
1176
1201
|
// src/primitives/message/MessageContent.tsx
|
1177
|
-
import { jsx as
|
1202
|
+
import { jsx as jsx16, jsxs as jsxs2 } from "react/jsx-runtime";
|
1178
1203
|
var defaultComponents = {
|
1179
1204
|
Text: () => /* @__PURE__ */ jsxs2("p", { style: { whiteSpace: "pre-line" }, children: [
|
1180
|
-
/* @__PURE__ */
|
1181
|
-
/* @__PURE__ */
|
1205
|
+
/* @__PURE__ */ jsx16(ContentPartPrimitiveText, {}),
|
1206
|
+
/* @__PURE__ */ jsx16(ContentPartPrimitiveInProgress, { children: " \u25CF" })
|
1182
1207
|
] }),
|
1183
|
-
Image: () =>
|
1184
|
-
UI: () => /* @__PURE__ */
|
1208
|
+
Image: () => /* @__PURE__ */ jsx16(ContentPartPrimitiveImage, {}),
|
1209
|
+
UI: () => /* @__PURE__ */ jsx16(ContentPartPrimitiveDisplay, {}),
|
1185
1210
|
tools: {
|
1186
1211
|
Fallback: (props) => {
|
1187
1212
|
const { useToolUIs } = useAssistantContext();
|
1188
1213
|
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
1189
1214
|
if (!Render) return null;
|
1190
|
-
return /* @__PURE__ */
|
1215
|
+
return /* @__PURE__ */ jsx16(Render, { ...props });
|
1191
1216
|
}
|
1192
1217
|
}
|
1193
1218
|
};
|
@@ -1206,15 +1231,15 @@ var MessageContentPartComponent = ({
|
|
1206
1231
|
const type = part.type;
|
1207
1232
|
switch (type) {
|
1208
1233
|
case "text":
|
1209
|
-
return /* @__PURE__ */
|
1234
|
+
return /* @__PURE__ */ jsx16(Text, { part, status });
|
1210
1235
|
case "image":
|
1211
|
-
return /* @__PURE__ */
|
1236
|
+
return /* @__PURE__ */ jsx16(Image, { part, status });
|
1212
1237
|
case "ui":
|
1213
|
-
return /* @__PURE__ */
|
1238
|
+
return /* @__PURE__ */ jsx16(UI, { part, status });
|
1214
1239
|
case "tool-call": {
|
1215
1240
|
const Tool = by_name[part.toolName] || Fallback;
|
1216
1241
|
const addResult = (result) => addToolResult(part.toolCallId, result);
|
1217
|
-
return /* @__PURE__ */
|
1242
|
+
return /* @__PURE__ */ jsx16(Tool, { part, status, addResult });
|
1218
1243
|
}
|
1219
1244
|
default:
|
1220
1245
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -1224,7 +1249,7 @@ var MessageContentPartImpl = ({
|
|
1224
1249
|
partIndex,
|
1225
1250
|
components
|
1226
1251
|
}) => {
|
1227
|
-
return /* @__PURE__ */
|
1252
|
+
return /* @__PURE__ */ jsx16(ContentPartProvider, { partIndex, children: /* @__PURE__ */ jsx16(MessageContentPartComponent, { components }) });
|
1228
1253
|
};
|
1229
1254
|
var MessageContentPart = memo2(
|
1230
1255
|
MessageContentPartImpl,
|
@@ -1237,7 +1262,7 @@ var MessagePrimitiveContent = ({
|
|
1237
1262
|
const contentLength = useMessage((s) => s.message.content.length);
|
1238
1263
|
return new Array(contentLength).fill(null).map((_, idx) => {
|
1239
1264
|
const partIndex = idx;
|
1240
|
-
return /* @__PURE__ */
|
1265
|
+
return /* @__PURE__ */ jsx16(
|
1241
1266
|
MessageContentPart,
|
1242
1267
|
{
|
1243
1268
|
partIndex,
|
@@ -1250,21 +1275,15 @@ var MessagePrimitiveContent = ({
|
|
1250
1275
|
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
1251
1276
|
|
1252
1277
|
// src/primitives/message/MessageInProgress.tsx
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
import { jsx as jsx18 } from "react/jsx-runtime";
|
1257
|
-
var MessagePrimitiveInProgress = forwardRef8((props, ref) => {
|
1258
|
-
const { useMessageUtils } = useMessageContext();
|
1259
|
-
const portalNode = useMessageUtils((s) => s.inProgressIndicator);
|
1260
|
-
return createPortal(/* @__PURE__ */ jsx18(Primitive5.span, { ...props, ref }), portalNode);
|
1261
|
-
});
|
1278
|
+
var MessagePrimitiveInProgress = () => {
|
1279
|
+
return null;
|
1280
|
+
};
|
1262
1281
|
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
1263
1282
|
|
1264
1283
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1265
|
-
import { jsx as
|
1284
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
1266
1285
|
var BranchPickerPrimitiveRoot = forwardRef9(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1267
|
-
return /* @__PURE__ */
|
1286
|
+
return /* @__PURE__ */ jsx17(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx17(Primitive6.div, { ...rest, ref }) });
|
1268
1287
|
});
|
1269
1288
|
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
1270
1289
|
|
@@ -1279,12 +1298,12 @@ __export(composer_exports, {
|
|
1279
1298
|
});
|
1280
1299
|
|
1281
1300
|
// src/primitives/composer/ComposerRoot.tsx
|
1282
|
-
import { composeEventHandlers as
|
1301
|
+
import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
|
1283
1302
|
import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
|
1284
1303
|
import {
|
1285
1304
|
forwardRef as forwardRef10
|
1286
1305
|
} from "react";
|
1287
|
-
import { jsx as
|
1306
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
1288
1307
|
var ComposerPrimitiveRoot = forwardRef10(({ onSubmit, ...rest }, forwardedRef) => {
|
1289
1308
|
const send = useComposerSend();
|
1290
1309
|
const handleSubmit = (e) => {
|
@@ -1292,30 +1311,30 @@ var ComposerPrimitiveRoot = forwardRef10(({ onSubmit, ...rest }, forwardedRef) =
|
|
1292
1311
|
if (!send) return;
|
1293
1312
|
send();
|
1294
1313
|
};
|
1295
|
-
return /* @__PURE__ */
|
1314
|
+
return /* @__PURE__ */ jsx18(
|
1296
1315
|
Primitive7.form,
|
1297
1316
|
{
|
1298
1317
|
...rest,
|
1299
1318
|
ref: forwardedRef,
|
1300
|
-
onSubmit:
|
1319
|
+
onSubmit: composeEventHandlers4(onSubmit, handleSubmit)
|
1301
1320
|
}
|
1302
1321
|
);
|
1303
1322
|
});
|
1304
1323
|
ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
1305
1324
|
|
1306
1325
|
// src/primitives/composer/ComposerInput.tsx
|
1307
|
-
import { composeEventHandlers as
|
1308
|
-
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
1326
|
+
import { composeEventHandlers as composeEventHandlers5 } from "@radix-ui/primitive";
|
1327
|
+
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
|
1309
1328
|
import { Slot } from "@radix-ui/react-slot";
|
1310
1329
|
import {
|
1311
1330
|
forwardRef as forwardRef11,
|
1312
|
-
useCallback as
|
1331
|
+
useCallback as useCallback15,
|
1313
1332
|
useEffect as useEffect8,
|
1314
1333
|
useRef as useRef4
|
1315
1334
|
} from "react";
|
1316
1335
|
import TextareaAutosize from "react-textarea-autosize";
|
1317
1336
|
import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
|
1318
|
-
import { jsx as
|
1337
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
1319
1338
|
var ComposerPrimitiveInput = forwardRef11(
|
1320
1339
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
1321
1340
|
const { useThread } = useThreadContext();
|
@@ -1326,7 +1345,7 @@ var ComposerPrimitiveInput = forwardRef11(
|
|
1326
1345
|
});
|
1327
1346
|
const Component = asChild ? Slot : TextareaAutosize;
|
1328
1347
|
const textareaRef = useRef4(null);
|
1329
|
-
const ref =
|
1348
|
+
const ref = useComposedRefs2(forwardedRef, textareaRef);
|
1330
1349
|
useEscapeKeydown((e) => {
|
1331
1350
|
const composer = useComposer.getState();
|
1332
1351
|
if (composer.cancel()) {
|
@@ -1344,7 +1363,7 @@ var ComposerPrimitiveInput = forwardRef11(
|
|
1344
1363
|
}
|
1345
1364
|
};
|
1346
1365
|
const autoFocusEnabled = autoFocus && !disabled;
|
1347
|
-
const focus =
|
1366
|
+
const focus = useCallback15(() => {
|
1348
1367
|
const textarea = textareaRef.current;
|
1349
1368
|
if (!textarea || !autoFocusEnabled) return;
|
1350
1369
|
textarea.focus({ preventScroll: true });
|
@@ -1359,19 +1378,20 @@ var ComposerPrimitiveInput = forwardRef11(
|
|
1359
1378
|
focus();
|
1360
1379
|
}
|
1361
1380
|
});
|
1362
|
-
return /* @__PURE__ */
|
1381
|
+
return /* @__PURE__ */ jsx19(
|
1363
1382
|
Component,
|
1364
1383
|
{
|
1384
|
+
name: "input",
|
1365
1385
|
value,
|
1366
1386
|
...rest,
|
1367
1387
|
ref,
|
1368
1388
|
disabled,
|
1369
|
-
onChange:
|
1389
|
+
onChange: composeEventHandlers5(onChange, (e) => {
|
1370
1390
|
const composerState = useComposer.getState();
|
1371
1391
|
if (!composerState.isEditing) return;
|
1372
1392
|
return composerState.setValue(e.target.value);
|
1373
1393
|
}),
|
1374
|
-
onKeyDown:
|
1394
|
+
onKeyDown: composeEventHandlers5(onKeyDown, handleKeyPress)
|
1375
1395
|
}
|
1376
1396
|
);
|
1377
1397
|
}
|
@@ -1381,11 +1401,11 @@ ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
|
1381
1401
|
// src/primitives/composer/ComposerSend.tsx
|
1382
1402
|
import { forwardRef as forwardRef12 } from "react";
|
1383
1403
|
import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
|
1384
|
-
import { jsx as
|
1404
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
1385
1405
|
var ComposerPrimitiveSend = forwardRef12(({ disabled, ...rest }, ref) => {
|
1386
1406
|
const { useComposer } = useComposerContext();
|
1387
1407
|
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1388
|
-
return /* @__PURE__ */
|
1408
|
+
return /* @__PURE__ */ jsx20(
|
1389
1409
|
Primitive8.button,
|
1390
1410
|
{
|
1391
1411
|
type: "submit",
|
@@ -1418,20 +1438,10 @@ var contentPart_exports = {};
|
|
1418
1438
|
__export(contentPart_exports, {
|
1419
1439
|
Display: () => ContentPartPrimitiveDisplay,
|
1420
1440
|
Image: () => ContentPartPrimitiveImage,
|
1421
|
-
|
1441
|
+
InProgress: () => ContentPartPrimitiveInProgress,
|
1422
1442
|
Text: () => ContentPartPrimitiveText
|
1423
1443
|
});
|
1424
1444
|
|
1425
|
-
// src/primitives/contentPart/ContentPartImage.tsx
|
1426
|
-
import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
|
1427
|
-
import { forwardRef as forwardRef13 } from "react";
|
1428
|
-
import { jsx as jsx23 } from "react/jsx-runtime";
|
1429
|
-
var ContentPartPrimitiveImage = forwardRef13((props, forwardedRef) => {
|
1430
|
-
const image = useContentPartImage();
|
1431
|
-
return /* @__PURE__ */ jsx23(Primitive9.img, { src: image, ...props, ref: forwardedRef });
|
1432
|
-
});
|
1433
|
-
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1434
|
-
|
1435
1445
|
// src/primitives/thread/index.ts
|
1436
1446
|
var thread_exports = {};
|
1437
1447
|
__export(thread_exports, {
|
@@ -1445,11 +1455,11 @@ __export(thread_exports, {
|
|
1445
1455
|
});
|
1446
1456
|
|
1447
1457
|
// src/primitives/thread/ThreadRoot.tsx
|
1448
|
-
import { Primitive as
|
1449
|
-
import { forwardRef as
|
1450
|
-
import { jsx as
|
1451
|
-
var ThreadPrimitiveRoot =
|
1452
|
-
return /* @__PURE__ */
|
1458
|
+
import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
|
1459
|
+
import { forwardRef as forwardRef13 } from "react";
|
1460
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
1461
|
+
var ThreadPrimitiveRoot = forwardRef13((props, ref) => {
|
1462
|
+
return /* @__PURE__ */ jsx21(Primitive9.div, { ...props, ref });
|
1453
1463
|
});
|
1454
1464
|
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
1455
1465
|
|
@@ -1473,40 +1483,20 @@ var ThreadPrimitiveIf = ({
|
|
1473
1483
|
ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
1474
1484
|
|
1475
1485
|
// src/primitives/thread/ThreadViewport.tsx
|
1476
|
-
import { useComposedRefs as
|
1477
|
-
import { Primitive as
|
1478
|
-
import { forwardRef as
|
1486
|
+
import { useComposedRefs as useComposedRefs4 } from "@radix-ui/react-compose-refs";
|
1487
|
+
import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
|
1488
|
+
import { forwardRef as forwardRef14 } from "react";
|
1479
1489
|
|
1480
1490
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
1481
|
-
import { useComposedRefs as
|
1482
|
-
import { useRef as
|
1491
|
+
import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
|
1492
|
+
import { useRef as useRef5 } from "react";
|
1483
1493
|
|
1484
1494
|
// src/utils/hooks/useOnResizeContent.tsx
|
1485
1495
|
import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
|
1486
|
-
import { useCallback as
|
1487
|
-
|
1488
|
-
// src/utils/hooks/useManagedRef.ts
|
1489
|
-
import { useCallback as useCallback14, useRef as useRef5 } from "react";
|
1490
|
-
var useManagedRef = (callback) => {
|
1491
|
-
const cleanupRef = useRef5();
|
1492
|
-
const ref = useCallback14(
|
1493
|
-
(el) => {
|
1494
|
-
if (cleanupRef.current) {
|
1495
|
-
cleanupRef.current();
|
1496
|
-
}
|
1497
|
-
if (el) {
|
1498
|
-
cleanupRef.current = callback(el);
|
1499
|
-
}
|
1500
|
-
},
|
1501
|
-
[callback]
|
1502
|
-
);
|
1503
|
-
return ref;
|
1504
|
-
};
|
1505
|
-
|
1506
|
-
// src/utils/hooks/useOnResizeContent.tsx
|
1496
|
+
import { useCallback as useCallback16 } from "react";
|
1507
1497
|
var useOnResizeContent = (callback) => {
|
1508
1498
|
const callbackRef = useCallbackRef2(callback);
|
1509
|
-
const refCallback =
|
1499
|
+
const refCallback = useCallback16(
|
1510
1500
|
(el) => {
|
1511
1501
|
const resizeObserver = new ResizeObserver(() => {
|
1512
1502
|
callbackRef();
|
@@ -1558,11 +1548,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1558
1548
|
var useThreadViewportAutoScroll = ({
|
1559
1549
|
autoScroll = true
|
1560
1550
|
}) => {
|
1561
|
-
const divRef =
|
1551
|
+
const divRef = useRef5(null);
|
1562
1552
|
const { useViewport } = useThreadContext();
|
1563
|
-
const firstRenderRef =
|
1564
|
-
const lastScrollTop =
|
1565
|
-
const isScrollingToBottomRef =
|
1553
|
+
const firstRenderRef = useRef5(true);
|
1554
|
+
const lastScrollTop = useRef5(0);
|
1555
|
+
const isScrollingToBottomRef = useRef5(false);
|
1566
1556
|
const scrollToBottom = () => {
|
1567
1557
|
const div = divRef.current;
|
1568
1558
|
if (!div || !autoScroll) return;
|
@@ -1600,7 +1590,7 @@ var useThreadViewportAutoScroll = ({
|
|
1600
1590
|
el.removeEventListener("scroll", handleScroll);
|
1601
1591
|
};
|
1602
1592
|
});
|
1603
|
-
const autoScrollRef =
|
1593
|
+
const autoScrollRef = useComposedRefs3(resizeRef, scrollRef, divRef);
|
1604
1594
|
useOnScrollToBottom(() => {
|
1605
1595
|
scrollToBottom();
|
1606
1596
|
});
|
@@ -1608,13 +1598,13 @@ var useThreadViewportAutoScroll = ({
|
|
1608
1598
|
};
|
1609
1599
|
|
1610
1600
|
// src/primitives/thread/ThreadViewport.tsx
|
1611
|
-
import { jsx as
|
1612
|
-
var ThreadPrimitiveViewport =
|
1601
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
1602
|
+
var ThreadPrimitiveViewport = forwardRef14(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1613
1603
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1614
1604
|
autoScroll
|
1615
1605
|
});
|
1616
|
-
const ref =
|
1617
|
-
return /* @__PURE__ */
|
1606
|
+
const ref = useComposedRefs4(forwardedRef, autoScrollRef);
|
1607
|
+
return /* @__PURE__ */ jsx22(Primitive10.div, { ...rest, ref, children });
|
1618
1608
|
});
|
1619
1609
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1620
1610
|
|
@@ -1652,7 +1642,6 @@ var makeEditComposerStore = ({
|
|
1652
1642
|
// src/context/stores/MessageUtils.ts
|
1653
1643
|
import { create as create11 } from "zustand";
|
1654
1644
|
var makeMessageUtilsStore = () => create11((set) => ({
|
1655
|
-
inProgressIndicator: document.createElement("span"),
|
1656
1645
|
isCopied: false,
|
1657
1646
|
setIsCopied: (value) => {
|
1658
1647
|
set({ isCopied: value });
|
@@ -1664,7 +1653,7 @@ var makeMessageUtilsStore = () => create11((set) => ({
|
|
1664
1653
|
}));
|
1665
1654
|
|
1666
1655
|
// src/context/providers/MessageProvider.tsx
|
1667
|
-
import { jsx as
|
1656
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
1668
1657
|
var getIsLast = (messages, message) => {
|
1669
1658
|
return messages[messages.length - 1]?.id === message.id;
|
1670
1659
|
};
|
@@ -1740,11 +1729,11 @@ var MessageProvider = ({
|
|
1740
1729
|
children
|
1741
1730
|
}) => {
|
1742
1731
|
const context = useMessageContext2(messageIndex);
|
1743
|
-
return /* @__PURE__ */
|
1732
|
+
return /* @__PURE__ */ jsx23(MessageContext.Provider, { value: context, children });
|
1744
1733
|
};
|
1745
1734
|
|
1746
1735
|
// src/primitives/thread/ThreadMessages.tsx
|
1747
|
-
import { jsx as
|
1736
|
+
import { jsx as jsx24, jsxs as jsxs3 } from "react/jsx-runtime";
|
1748
1737
|
var getComponents = (components) => {
|
1749
1738
|
return {
|
1750
1739
|
EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
|
@@ -1759,10 +1748,10 @@ var ThreadMessageImpl = ({
|
|
1759
1748
|
const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
|
1760
1749
|
return /* @__PURE__ */ jsxs3(MessageProvider, { messageIndex, children: [
|
1761
1750
|
/* @__PURE__ */ jsxs3(MessagePrimitiveIf, { user: true, children: [
|
1762
|
-
/* @__PURE__ */
|
1763
|
-
/* @__PURE__ */
|
1751
|
+
/* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
|
1752
|
+
/* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
|
1764
1753
|
] }),
|
1765
|
-
/* @__PURE__ */
|
1754
|
+
/* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
|
1766
1755
|
] });
|
1767
1756
|
};
|
1768
1757
|
var ThreadMessage = memo3(
|
@@ -1777,7 +1766,7 @@ var ThreadPrimitiveMessages = ({
|
|
1777
1766
|
if (messagesLength === 0) return null;
|
1778
1767
|
return new Array(messagesLength).fill(null).map((_, idx) => {
|
1779
1768
|
const messageIndex = idx;
|
1780
|
-
return /* @__PURE__ */
|
1769
|
+
return /* @__PURE__ */ jsx24(
|
1781
1770
|
ThreadMessage,
|
1782
1771
|
{
|
1783
1772
|
messageIndex,
|