@assistant-ui/react 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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.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
|
760
|
+
return c;
|
761
761
|
});
|
762
762
|
return text;
|
763
763
|
};
|
@@ -1107,28 +1107,57 @@ __export(message_exports, {
|
|
1107
1107
|
});
|
1108
1108
|
|
1109
1109
|
// src/primitives/message/MessageRoot.tsx
|
1110
|
-
var import_primitive4 = require("@radix-ui/primitive");
|
1111
1110
|
var import_react_primitive3 = require("@radix-ui/react-primitive");
|
1111
|
+
var import_react33 = require("react");
|
1112
|
+
|
1113
|
+
// src/utils/hooks/useManagedRef.ts
|
1112
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");
|
1113
1133
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
1114
|
-
var
|
1134
|
+
var useIsHoveringRef = () => {
|
1115
1135
|
const { useMessageUtils } = useMessageContext();
|
1116
|
-
const
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
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]
|
1131
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 });
|
1132
1161
|
});
|
1133
1162
|
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
1134
1163
|
|
@@ -1143,10 +1172,10 @@ var MessagePrimitiveIf = ({
|
|
1143
1172
|
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
1144
1173
|
|
1145
1174
|
// src/primitives/message/MessageContent.tsx
|
1146
|
-
var
|
1175
|
+
var import_react37 = require("react");
|
1147
1176
|
|
1148
1177
|
// src/context/providers/ContentPartProvider.tsx
|
1149
|
-
var
|
1178
|
+
var import_react34 = require("react");
|
1150
1179
|
var import_zustand9 = require("zustand");
|
1151
1180
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
1152
1181
|
var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
@@ -1165,14 +1194,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
|
1165
1194
|
};
|
1166
1195
|
var useContentPartContext2 = (partIndex) => {
|
1167
1196
|
const { useMessage } = useMessageContext();
|
1168
|
-
const [context] = (0,
|
1197
|
+
const [context] = (0, import_react34.useState)(() => {
|
1169
1198
|
const useContentPart = (0, import_zustand9.create)(
|
1170
1199
|
() => ({})
|
1171
1200
|
);
|
1172
1201
|
syncContentPart(useMessage.getState(), useContentPart, partIndex);
|
1173
1202
|
return { useContentPart };
|
1174
1203
|
});
|
1175
|
-
(0,
|
1204
|
+
(0, import_react34.useEffect)(() => {
|
1176
1205
|
syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
|
1177
1206
|
return useMessage.subscribe((message) => {
|
1178
1207
|
syncContentPart(message, context.useContentPart, partIndex);
|
@@ -1188,6 +1217,29 @@ var ContentPartProvider = ({
|
|
1188
1217
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ContentPartContext.Provider, { value: context, children });
|
1189
1218
|
};
|
1190
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
|
+
|
1191
1243
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1192
1244
|
var ContentPartPrimitiveDisplay = () => {
|
1193
1245
|
const display = useContentPartDisplay();
|
@@ -1195,61 +1247,31 @@ var ContentPartPrimitiveDisplay = () => {
|
|
1195
1247
|
};
|
1196
1248
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
1197
1249
|
|
1198
|
-
// src/
|
1199
|
-
var
|
1200
|
-
|
1201
|
-
|
1202
|
-
const parentRef = (0, import_react34.useRef)(null);
|
1203
|
-
(0, import_react34.useLayoutEffect)(() => {
|
1204
|
-
const parent = parentRef.current;
|
1205
|
-
if (!parent || !node) return;
|
1206
|
-
parent.appendChild(node);
|
1207
|
-
return () => {
|
1208
|
-
parent.removeChild(node);
|
1209
|
-
};
|
1210
|
-
}, [node]);
|
1211
|
-
if (!node) return null;
|
1212
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { ref: parentRef });
|
1213
|
-
};
|
1214
|
-
|
1215
|
-
// src/primitives/contentPart/ContentPartInProgressIndicator.tsx
|
1216
|
-
var import_jsx_runtime15 = require("react/jsx-runtime");
|
1217
|
-
var ContentPartPrimitiveInProgressIndicator = () => {
|
1218
|
-
const { useMessageUtils } = useMessageContext();
|
1250
|
+
// src/primitives/contentPart/ContentPartInProgress.tsx
|
1251
|
+
var ContentPartPrimitiveInProgress = ({
|
1252
|
+
children
|
1253
|
+
}) => {
|
1219
1254
|
const { useContentPart } = useContentPartContext();
|
1220
|
-
const
|
1221
|
-
|
1222
|
-
(m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
|
1223
|
-
);
|
1224
|
-
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(OutPortal, { node: indicator });
|
1255
|
+
const isInProgress = useContentPart((c) => c.status === "in_progress");
|
1256
|
+
return isInProgress ? children : null;
|
1225
1257
|
};
|
1226
|
-
|
1227
|
-
|
1228
|
-
// src/primitives/contentPart/ContentPartText.tsx
|
1229
|
-
var import_react_primitive4 = require("@radix-ui/react-primitive");
|
1230
|
-
var import_react35 = require("react");
|
1231
|
-
var import_jsx_runtime16 = require("react/jsx-runtime");
|
1232
|
-
var ContentPartPrimitiveText = (0, import_react35.forwardRef)((props, forwardedRef) => {
|
1233
|
-
const text = useContentPartText();
|
1234
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive4.Primitive.span, { ...props, ref: forwardedRef, children: text });
|
1235
|
-
});
|
1236
|
-
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1258
|
+
ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
|
1237
1259
|
|
1238
1260
|
// src/primitives/message/MessageContent.tsx
|
1239
|
-
var
|
1261
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
1240
1262
|
var defaultComponents = {
|
1241
|
-
Text: () => /* @__PURE__ */ (0,
|
1242
|
-
/* @__PURE__ */ (0,
|
1243
|
-
/* @__PURE__ */ (0,
|
1263
|
+
Text: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("p", { style: { whiteSpace: "pre-line" }, children: [
|
1264
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveText, {}),
|
1265
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveInProgress, { children: " \u25CF" })
|
1244
1266
|
] }),
|
1245
|
-
Image: () =>
|
1246
|
-
UI: () => /* @__PURE__ */ (0,
|
1267
|
+
Image: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveImage, {}),
|
1268
|
+
UI: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveDisplay, {}),
|
1247
1269
|
tools: {
|
1248
1270
|
Fallback: (props) => {
|
1249
1271
|
const { useToolUIs } = useAssistantContext();
|
1250
1272
|
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
1251
1273
|
if (!Render) return null;
|
1252
|
-
return /* @__PURE__ */ (0,
|
1274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Render, { ...props });
|
1253
1275
|
}
|
1254
1276
|
}
|
1255
1277
|
};
|
@@ -1268,15 +1290,15 @@ var MessageContentPartComponent = ({
|
|
1268
1290
|
const type = part.type;
|
1269
1291
|
switch (type) {
|
1270
1292
|
case "text":
|
1271
|
-
return /* @__PURE__ */ (0,
|
1293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text, { part, status });
|
1272
1294
|
case "image":
|
1273
|
-
return /* @__PURE__ */ (0,
|
1295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Image, { part, status });
|
1274
1296
|
case "ui":
|
1275
|
-
return /* @__PURE__ */ (0,
|
1297
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(UI, { part, status });
|
1276
1298
|
case "tool-call": {
|
1277
1299
|
const Tool = by_name[part.toolName] || Fallback;
|
1278
1300
|
const addResult = (result) => addToolResult(part.toolCallId, result);
|
1279
|
-
return /* @__PURE__ */ (0,
|
1301
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Tool, { part, status, addResult });
|
1280
1302
|
}
|
1281
1303
|
default:
|
1282
1304
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -1286,9 +1308,9 @@ var MessageContentPartImpl = ({
|
|
1286
1308
|
partIndex,
|
1287
1309
|
components
|
1288
1310
|
}) => {
|
1289
|
-
return /* @__PURE__ */ (0,
|
1311
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageContentPartComponent, { components }) });
|
1290
1312
|
};
|
1291
|
-
var MessageContentPart = (0,
|
1313
|
+
var MessageContentPart = (0, import_react37.memo)(
|
1292
1314
|
MessageContentPartImpl,
|
1293
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
|
1294
1316
|
);
|
@@ -1299,7 +1321,7 @@ var MessagePrimitiveContent = ({
|
|
1299
1321
|
const contentLength = useMessage((s) => s.message.content.length);
|
1300
1322
|
return new Array(contentLength).fill(null).map((_, idx) => {
|
1301
1323
|
const partIndex = idx;
|
1302
|
-
return /* @__PURE__ */ (0,
|
1324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
1303
1325
|
MessageContentPart,
|
1304
1326
|
{
|
1305
1327
|
partIndex,
|
@@ -1312,21 +1334,15 @@ var MessagePrimitiveContent = ({
|
|
1312
1334
|
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
1313
1335
|
|
1314
1336
|
// src/primitives/message/MessageInProgress.tsx
|
1315
|
-
var
|
1316
|
-
|
1317
|
-
|
1318
|
-
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1319
|
-
var MessagePrimitiveInProgress = (0, import_react37.forwardRef)((props, ref) => {
|
1320
|
-
const { useMessageUtils } = useMessageContext();
|
1321
|
-
const portalNode = useMessageUtils((s) => s.inProgressIndicator);
|
1322
|
-
return (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_primitive5.Primitive.span, { ...props, ref }), portalNode);
|
1323
|
-
});
|
1337
|
+
var MessagePrimitiveInProgress = () => {
|
1338
|
+
return null;
|
1339
|
+
};
|
1324
1340
|
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
1325
1341
|
|
1326
1342
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1327
|
-
var
|
1343
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
1328
1344
|
var BranchPickerPrimitiveRoot = (0, import_react38.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1329
|
-
return /* @__PURE__ */ (0,
|
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 }) });
|
1330
1346
|
});
|
1331
1347
|
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
1332
1348
|
|
@@ -1341,10 +1357,10 @@ __export(composer_exports, {
|
|
1341
1357
|
});
|
1342
1358
|
|
1343
1359
|
// src/primitives/composer/ComposerRoot.tsx
|
1344
|
-
var
|
1360
|
+
var import_primitive4 = require("@radix-ui/primitive");
|
1345
1361
|
var import_react_primitive7 = require("@radix-ui/react-primitive");
|
1346
1362
|
var import_react39 = require("react");
|
1347
|
-
var
|
1363
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1348
1364
|
var ComposerPrimitiveRoot = (0, import_react39.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
|
1349
1365
|
const send = useComposerSend();
|
1350
1366
|
const handleSubmit = (e) => {
|
@@ -1352,25 +1368,25 @@ var ComposerPrimitiveRoot = (0, import_react39.forwardRef)(({ onSubmit, ...rest
|
|
1352
1368
|
if (!send) return;
|
1353
1369
|
send();
|
1354
1370
|
};
|
1355
|
-
return /* @__PURE__ */ (0,
|
1371
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
1356
1372
|
import_react_primitive7.Primitive.form,
|
1357
1373
|
{
|
1358
1374
|
...rest,
|
1359
1375
|
ref: forwardedRef,
|
1360
|
-
onSubmit: (0,
|
1376
|
+
onSubmit: (0, import_primitive4.composeEventHandlers)(onSubmit, handleSubmit)
|
1361
1377
|
}
|
1362
1378
|
);
|
1363
1379
|
});
|
1364
1380
|
ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
1365
1381
|
|
1366
1382
|
// src/primitives/composer/ComposerInput.tsx
|
1367
|
-
var
|
1368
|
-
var
|
1383
|
+
var import_primitive5 = require("@radix-ui/primitive");
|
1384
|
+
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
|
1369
1385
|
var import_react_slot = require("@radix-ui/react-slot");
|
1370
1386
|
var import_react40 = require("react");
|
1371
1387
|
var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
|
1372
1388
|
var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
|
1373
|
-
var
|
1389
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1374
1390
|
var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
1375
1391
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
1376
1392
|
const { useThread } = useThreadContext();
|
@@ -1381,7 +1397,7 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1381
1397
|
});
|
1382
1398
|
const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
|
1383
1399
|
const textareaRef = (0, import_react40.useRef)(null);
|
1384
|
-
const ref = (0,
|
1400
|
+
const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, textareaRef);
|
1385
1401
|
(0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
|
1386
1402
|
const composer = useComposer.getState();
|
1387
1403
|
if (composer.cancel()) {
|
@@ -1414,19 +1430,20 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1414
1430
|
focus();
|
1415
1431
|
}
|
1416
1432
|
});
|
1417
|
-
return /* @__PURE__ */ (0,
|
1433
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1418
1434
|
Component,
|
1419
1435
|
{
|
1436
|
+
name: "input",
|
1420
1437
|
value,
|
1421
1438
|
...rest,
|
1422
1439
|
ref,
|
1423
1440
|
disabled,
|
1424
|
-
onChange: (0,
|
1441
|
+
onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
|
1425
1442
|
const composerState = useComposer.getState();
|
1426
1443
|
if (!composerState.isEditing) return;
|
1427
1444
|
return composerState.setValue(e.target.value);
|
1428
1445
|
}),
|
1429
|
-
onKeyDown: (0,
|
1446
|
+
onKeyDown: (0, import_primitive5.composeEventHandlers)(onKeyDown, handleKeyPress)
|
1430
1447
|
}
|
1431
1448
|
);
|
1432
1449
|
}
|
@@ -1436,11 +1453,11 @@ ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
|
1436
1453
|
// src/primitives/composer/ComposerSend.tsx
|
1437
1454
|
var import_react41 = require("react");
|
1438
1455
|
var import_react_primitive8 = require("@radix-ui/react-primitive");
|
1439
|
-
var
|
1456
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
1440
1457
|
var ComposerPrimitiveSend = (0, import_react41.forwardRef)(({ disabled, ...rest }, ref) => {
|
1441
1458
|
const { useComposer } = useComposerContext();
|
1442
1459
|
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1443
|
-
return /* @__PURE__ */ (0,
|
1460
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
1444
1461
|
import_react_primitive8.Primitive.button,
|
1445
1462
|
{
|
1446
1463
|
type: "submit",
|
@@ -1473,20 +1490,10 @@ var contentPart_exports = {};
|
|
1473
1490
|
__export(contentPart_exports, {
|
1474
1491
|
Display: () => ContentPartPrimitiveDisplay,
|
1475
1492
|
Image: () => ContentPartPrimitiveImage,
|
1476
|
-
|
1493
|
+
InProgress: () => ContentPartPrimitiveInProgress,
|
1477
1494
|
Text: () => ContentPartPrimitiveText
|
1478
1495
|
});
|
1479
1496
|
|
1480
|
-
// src/primitives/contentPart/ContentPartImage.tsx
|
1481
|
-
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
1482
|
-
var import_react42 = require("react");
|
1483
|
-
var import_jsx_runtime23 = require("react/jsx-runtime");
|
1484
|
-
var ContentPartPrimitiveImage = (0, import_react42.forwardRef)((props, forwardedRef) => {
|
1485
|
-
const image = useContentPartImage();
|
1486
|
-
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
|
1487
|
-
});
|
1488
|
-
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1489
|
-
|
1490
1497
|
// src/primitives/thread/index.ts
|
1491
1498
|
var thread_exports = {};
|
1492
1499
|
__export(thread_exports, {
|
@@ -1500,11 +1507,11 @@ __export(thread_exports, {
|
|
1500
1507
|
});
|
1501
1508
|
|
1502
1509
|
// src/primitives/thread/ThreadRoot.tsx
|
1503
|
-
var
|
1504
|
-
var
|
1505
|
-
var
|
1506
|
-
var ThreadPrimitiveRoot = (0,
|
1507
|
-
return /* @__PURE__ */ (0,
|
1510
|
+
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
1511
|
+
var import_react42 = require("react");
|
1512
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1513
|
+
var ThreadPrimitiveRoot = (0, import_react42.forwardRef)((props, ref) => {
|
1514
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react_primitive9.Primitive.div, { ...props, ref });
|
1508
1515
|
});
|
1509
1516
|
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
1510
1517
|
|
@@ -1528,40 +1535,20 @@ var ThreadPrimitiveIf = ({
|
|
1528
1535
|
ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
1529
1536
|
|
1530
1537
|
// src/primitives/thread/ThreadViewport.tsx
|
1531
|
-
var
|
1532
|
-
var
|
1533
|
-
var
|
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");
|
1534
1541
|
|
1535
1542
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
1536
|
-
var
|
1537
|
-
var import_react47 = require("react");
|
1538
|
-
|
1539
|
-
// src/utils/hooks/useOnResizeContent.tsx
|
1540
|
-
var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
|
1543
|
+
var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
|
1541
1544
|
var import_react45 = require("react");
|
1542
1545
|
|
1543
|
-
// src/utils/hooks/useManagedRef.ts
|
1544
|
-
var import_react44 = require("react");
|
1545
|
-
var useManagedRef = (callback) => {
|
1546
|
-
const cleanupRef = (0, import_react44.useRef)();
|
1547
|
-
const ref = (0, import_react44.useCallback)(
|
1548
|
-
(el) => {
|
1549
|
-
if (cleanupRef.current) {
|
1550
|
-
cleanupRef.current();
|
1551
|
-
}
|
1552
|
-
if (el) {
|
1553
|
-
cleanupRef.current = callback(el);
|
1554
|
-
}
|
1555
|
-
},
|
1556
|
-
[callback]
|
1557
|
-
);
|
1558
|
-
return ref;
|
1559
|
-
};
|
1560
|
-
|
1561
1546
|
// src/utils/hooks/useOnResizeContent.tsx
|
1547
|
+
var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
|
1548
|
+
var import_react43 = require("react");
|
1562
1549
|
var useOnResizeContent = (callback) => {
|
1563
1550
|
const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
|
1564
|
-
const refCallback = (0,
|
1551
|
+
const refCallback = (0, import_react43.useCallback)(
|
1565
1552
|
(el) => {
|
1566
1553
|
const resizeObserver = new ResizeObserver(() => {
|
1567
1554
|
callbackRef();
|
@@ -1598,11 +1585,11 @@ var useOnResizeContent = (callback) => {
|
|
1598
1585
|
|
1599
1586
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
1600
1587
|
var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
|
1601
|
-
var
|
1588
|
+
var import_react44 = require("react");
|
1602
1589
|
var useOnScrollToBottom = (callback) => {
|
1603
1590
|
const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
|
1604
1591
|
const { useViewport } = useThreadContext();
|
1605
|
-
(0,
|
1592
|
+
(0, import_react44.useEffect)(() => {
|
1606
1593
|
return useViewport.getState().onScrollToBottom(() => {
|
1607
1594
|
callbackRef();
|
1608
1595
|
});
|
@@ -1613,11 +1600,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1613
1600
|
var useThreadViewportAutoScroll = ({
|
1614
1601
|
autoScroll = true
|
1615
1602
|
}) => {
|
1616
|
-
const divRef = (0,
|
1603
|
+
const divRef = (0, import_react45.useRef)(null);
|
1617
1604
|
const { useViewport } = useThreadContext();
|
1618
|
-
const firstRenderRef = (0,
|
1619
|
-
const lastScrollTop = (0,
|
1620
|
-
const isScrollingToBottomRef = (0,
|
1605
|
+
const firstRenderRef = (0, import_react45.useRef)(true);
|
1606
|
+
const lastScrollTop = (0, import_react45.useRef)(0);
|
1607
|
+
const isScrollingToBottomRef = (0, import_react45.useRef)(false);
|
1621
1608
|
const scrollToBottom = () => {
|
1622
1609
|
const div = divRef.current;
|
1623
1610
|
if (!div || !autoScroll) return;
|
@@ -1655,7 +1642,7 @@ var useThreadViewportAutoScroll = ({
|
|
1655
1642
|
el.removeEventListener("scroll", handleScroll);
|
1656
1643
|
};
|
1657
1644
|
});
|
1658
|
-
const autoScrollRef = (0,
|
1645
|
+
const autoScrollRef = (0, import_react_compose_refs3.useComposedRefs)(resizeRef, scrollRef, divRef);
|
1659
1646
|
useOnScrollToBottom(() => {
|
1660
1647
|
scrollToBottom();
|
1661
1648
|
});
|
@@ -1663,21 +1650,21 @@ var useThreadViewportAutoScroll = ({
|
|
1663
1650
|
};
|
1664
1651
|
|
1665
1652
|
// src/primitives/thread/ThreadViewport.tsx
|
1666
|
-
var
|
1667
|
-
var ThreadPrimitiveViewport = (0,
|
1653
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1654
|
+
var ThreadPrimitiveViewport = (0, import_react46.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1668
1655
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1669
1656
|
autoScroll
|
1670
1657
|
});
|
1671
|
-
const ref = (0,
|
1672
|
-
return /* @__PURE__ */ (0,
|
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 });
|
1673
1660
|
});
|
1674
1661
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1675
1662
|
|
1676
1663
|
// src/primitives/thread/ThreadMessages.tsx
|
1677
|
-
var
|
1664
|
+
var import_react48 = require("react");
|
1678
1665
|
|
1679
1666
|
// src/context/providers/MessageProvider.tsx
|
1680
|
-
var
|
1667
|
+
var import_react47 = require("react");
|
1681
1668
|
var import_zustand12 = require("zustand");
|
1682
1669
|
|
1683
1670
|
// src/context/stores/EditComposer.ts
|
@@ -1707,7 +1694,6 @@ var makeEditComposerStore = ({
|
|
1707
1694
|
// src/context/stores/MessageUtils.ts
|
1708
1695
|
var import_zustand11 = require("zustand");
|
1709
1696
|
var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
|
1710
|
-
inProgressIndicator: document.createElement("span"),
|
1711
1697
|
isCopied: false,
|
1712
1698
|
setIsCopied: (value) => {
|
1713
1699
|
set({ isCopied: value });
|
@@ -1719,7 +1705,7 @@ var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
|
|
1719
1705
|
}));
|
1720
1706
|
|
1721
1707
|
// src/context/providers/MessageProvider.tsx
|
1722
|
-
var
|
1708
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
1723
1709
|
var getIsLast = (messages, message) => {
|
1724
1710
|
return messages[messages.length - 1]?.id === message.id;
|
1725
1711
|
};
|
@@ -1741,7 +1727,7 @@ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
|
|
1741
1727
|
};
|
1742
1728
|
var useMessageContext2 = (messageIndex) => {
|
1743
1729
|
const { useThreadMessages, useThreadActions } = useThreadContext();
|
1744
|
-
const [context] = (0,
|
1730
|
+
const [context] = (0, import_react47.useState)(() => {
|
1745
1731
|
const useMessage = (0, import_zustand12.create)(() => ({}));
|
1746
1732
|
const useMessageUtils = makeMessageUtilsStore();
|
1747
1733
|
const useEditComposer = makeEditComposerStore({
|
@@ -1778,7 +1764,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1778
1764
|
);
|
1779
1765
|
return { useMessage, useMessageUtils, useEditComposer };
|
1780
1766
|
});
|
1781
|
-
(0,
|
1767
|
+
(0, import_react47.useEffect)(() => {
|
1782
1768
|
return useThreadMessages.subscribe((thread) => {
|
1783
1769
|
syncMessage(
|
1784
1770
|
thread,
|
@@ -1795,11 +1781,11 @@ var MessageProvider = ({
|
|
1795
1781
|
children
|
1796
1782
|
}) => {
|
1797
1783
|
const context = useMessageContext2(messageIndex);
|
1798
|
-
return /* @__PURE__ */ (0,
|
1784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(MessageContext.Provider, { value: context, children });
|
1799
1785
|
};
|
1800
1786
|
|
1801
1787
|
// src/primitives/thread/ThreadMessages.tsx
|
1802
|
-
var
|
1788
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
1803
1789
|
var getComponents = (components) => {
|
1804
1790
|
return {
|
1805
1791
|
EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
|
@@ -1812,15 +1798,15 @@ var ThreadMessageImpl = ({
|
|
1812
1798
|
components
|
1813
1799
|
}) => {
|
1814
1800
|
const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
|
1815
|
-
return /* @__PURE__ */ (0,
|
1816
|
-
/* @__PURE__ */ (0,
|
1817
|
-
/* @__PURE__ */ (0,
|
1818
|
-
/* @__PURE__ */ (0,
|
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, {}) })
|
1819
1805
|
] }),
|
1820
|
-
/* @__PURE__ */ (0,
|
1806
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
|
1821
1807
|
] });
|
1822
1808
|
};
|
1823
|
-
var ThreadMessage = (0,
|
1809
|
+
var ThreadMessage = (0, import_react48.memo)(
|
1824
1810
|
ThreadMessageImpl,
|
1825
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
|
1826
1812
|
);
|
@@ -1832,7 +1818,7 @@ var ThreadPrimitiveMessages = ({
|
|
1832
1818
|
if (messagesLength === 0) return null;
|
1833
1819
|
return new Array(messagesLength).fill(null).map((_, idx) => {
|
1834
1820
|
const messageIndex = idx;
|
1835
|
-
return /* @__PURE__ */ (0,
|
1821
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1836
1822
|
ThreadMessage,
|
1837
1823
|
{
|
1838
1824
|
messageIndex,
|
@@ -1857,7 +1843,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
|
|
1857
1843
|
);
|
1858
1844
|
|
1859
1845
|
// src/runtime/local/useLocalRuntime.tsx
|
1860
|
-
var
|
1846
|
+
var import_react49 = require("react");
|
1861
1847
|
|
1862
1848
|
// src/runtime/utils/idUtils.tsx
|
1863
1849
|
var import_non_secure = require("nanoid/non-secure");
|
@@ -2189,8 +2175,8 @@ var LocalThreadRuntime = class {
|
|
2189
2175
|
|
2190
2176
|
// src/runtime/local/useLocalRuntime.tsx
|
2191
2177
|
var useLocalRuntime = (adapter) => {
|
2192
|
-
const [runtime] = (0,
|
2193
|
-
(0,
|
2178
|
+
const [runtime] = (0, import_react49.useState)(() => new LocalRuntime(adapter));
|
2179
|
+
(0, import_react49.useInsertionEffect)(() => {
|
2194
2180
|
runtime.adapter = adapter;
|
2195
2181
|
});
|
2196
2182
|
return runtime;
|