@assistant-ui/react 0.2.2 → 0.2.4
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 +46 -44
- package/dist/index.d.ts +46 -44
- package/dist/index.js +194 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +179 -148
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -3
package/dist/index.js
CHANGED
@@ -60,7 +60,6 @@ __export(src_exports, {
|
|
60
60
|
useContentPartContext: () => useContentPartContext,
|
61
61
|
useContentPartDisplay: () => useContentPartDisplay,
|
62
62
|
useContentPartImage: () => useContentPartImage,
|
63
|
-
useContentPartInProgressIndicator: () => useContentPartInProgressIndicator,
|
64
63
|
useContentPartText: () => useContentPartText,
|
65
64
|
useLocalRuntime: () => useLocalRuntime,
|
66
65
|
useMessageContext: () => useMessageContext,
|
@@ -211,7 +210,7 @@ var makeBaseComposer = (set) => ({
|
|
211
210
|
});
|
212
211
|
|
213
212
|
// src/context/stores/Composer.ts
|
214
|
-
var makeComposerStore = (useThread, useThreadActions) => {
|
213
|
+
var makeComposerStore = (useThread, useThreadMessages, useThreadActions) => {
|
215
214
|
const focusListeners = /* @__PURE__ */ new Set();
|
216
215
|
return (0, import_zustand3.create)()((set, get, store) => {
|
217
216
|
return {
|
@@ -221,7 +220,7 @@ var makeComposerStore = (useThread, useThreadActions) => {
|
|
221
220
|
const { setValue, value } = get();
|
222
221
|
setValue("");
|
223
222
|
useThreadActions.getState().append({
|
224
|
-
parentId:
|
223
|
+
parentId: useThreadMessages.getState().at(-1)?.id ?? null,
|
225
224
|
role: "user",
|
226
225
|
content: [{ type: "text", text: value }]
|
227
226
|
});
|
@@ -251,7 +250,6 @@ var makeComposerStore = (useThread, useThreadActions) => {
|
|
251
250
|
var import_zustand4 = require("zustand");
|
252
251
|
var makeThreadStore = (runtimeRef) => {
|
253
252
|
return (0, import_zustand4.create)(() => ({
|
254
|
-
messages: runtimeRef.current.messages,
|
255
253
|
isRunning: runtimeRef.current.isRunning
|
256
254
|
}));
|
257
255
|
};
|
@@ -291,6 +289,12 @@ var makeThreadActionStore = (runtimeRef) => {
|
|
291
289
|
);
|
292
290
|
};
|
293
291
|
|
292
|
+
// src/context/stores/ThreadMessages.ts
|
293
|
+
var import_zustand7 = require("zustand");
|
294
|
+
var makeThreadMessagesStore = (runtimeRef) => {
|
295
|
+
return (0, import_zustand7.create)(() => runtimeRef.current.messages);
|
296
|
+
};
|
297
|
+
|
294
298
|
// src/context/providers/ThreadProvider.tsx
|
295
299
|
var import_jsx_runtime = require("react/jsx-runtime");
|
296
300
|
var ThreadProvider = ({
|
@@ -303,11 +307,17 @@ var ThreadProvider = ({
|
|
303
307
|
});
|
304
308
|
const [context] = (0, import_react3.useState)(() => {
|
305
309
|
const useThread = makeThreadStore(runtimeRef);
|
310
|
+
const useThreadMessages = makeThreadMessagesStore(runtimeRef);
|
306
311
|
const useThreadActions = makeThreadActionStore(runtimeRef);
|
307
312
|
const useViewport = makeThreadViewportStore();
|
308
|
-
const useComposer = makeComposerStore(
|
313
|
+
const useComposer = makeComposerStore(
|
314
|
+
useThread,
|
315
|
+
useThreadMessages,
|
316
|
+
useThreadActions
|
317
|
+
);
|
309
318
|
return {
|
310
319
|
useThread,
|
320
|
+
useThreadMessages,
|
311
321
|
useThreadActions,
|
312
322
|
useComposer,
|
313
323
|
useViewport
|
@@ -317,11 +327,11 @@ var ThreadProvider = ({
|
|
317
327
|
const onRuntimeUpdate = () => {
|
318
328
|
context.useThread.setState(
|
319
329
|
Object.freeze({
|
320
|
-
messages: runtimeRef.current.messages,
|
321
330
|
isRunning: runtimeRef.current.isRunning
|
322
331
|
}),
|
323
332
|
true
|
324
333
|
);
|
334
|
+
context.useThreadMessages.setState(Object.freeze(runtimeRef.current.messages), true);
|
325
335
|
};
|
326
336
|
onRuntimeUpdate();
|
327
337
|
return runtime.subscribe(onRuntimeUpdate);
|
@@ -342,8 +352,8 @@ var ThreadProvider = ({
|
|
342
352
|
};
|
343
353
|
|
344
354
|
// src/context/stores/AssistantActions.tsx
|
345
|
-
var
|
346
|
-
var makeAssistantActionsStore = (runtimeRef) => (0,
|
355
|
+
var import_zustand8 = require("zustand");
|
356
|
+
var makeAssistantActionsStore = (runtimeRef) => (0, import_zustand8.create)(
|
347
357
|
() => Object.freeze({
|
348
358
|
switchToThread: () => runtimeRef.current.switchToThread(null)
|
349
359
|
})
|
@@ -420,30 +430,30 @@ var useContentPartContext = () => {
|
|
420
430
|
|
421
431
|
// src/hooks/useAppendMessage.tsx
|
422
432
|
var import_react9 = require("react");
|
423
|
-
var toAppendMessage = (
|
433
|
+
var toAppendMessage = (useThreadMessages, message) => {
|
424
434
|
if (typeof message === "string") {
|
425
435
|
return {
|
426
|
-
parentId:
|
436
|
+
parentId: useThreadMessages.getState().at(-1)?.id ?? null,
|
427
437
|
role: "user",
|
428
438
|
content: [{ type: "text", text: message }]
|
429
439
|
};
|
430
440
|
}
|
431
441
|
return {
|
432
|
-
parentId: message.parentId ??
|
442
|
+
parentId: message.parentId ?? useThreadMessages.getState().at(-1)?.id ?? null,
|
433
443
|
role: message.role ?? "user",
|
434
444
|
content: message.content
|
435
445
|
};
|
436
446
|
};
|
437
447
|
var useAppendMessage = () => {
|
438
|
-
const {
|
448
|
+
const { useThreadMessages, useThreadActions, useViewport, useComposer } = useThreadContext();
|
439
449
|
const append = (0, import_react9.useCallback)(
|
440
450
|
(message) => {
|
441
|
-
const appendMessage = toAppendMessage(
|
451
|
+
const appendMessage = toAppendMessage(useThreadMessages, message);
|
442
452
|
useThreadActions.getState().append(appendMessage);
|
443
453
|
useViewport.getState().scrollToBottom();
|
444
454
|
useComposer.getState().focus();
|
445
455
|
},
|
446
|
-
[
|
456
|
+
[useThreadMessages, useThreadActions, useViewport, useComposer]
|
447
457
|
);
|
448
458
|
return append;
|
449
459
|
};
|
@@ -739,17 +749,6 @@ var useContentPartImage = () => {
|
|
739
749
|
return image;
|
740
750
|
};
|
741
751
|
|
742
|
-
// src/primitive-hooks/contentPart/useContentPartInProgressIndicator.tsx
|
743
|
-
var useContentPartInProgressIndicator = () => {
|
744
|
-
const { useMessageUtils } = useMessageContext();
|
745
|
-
const { useContentPart } = useContentPartContext();
|
746
|
-
const indicator = useCombinedStore(
|
747
|
-
[useMessageUtils, useContentPart],
|
748
|
-
(m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
|
749
|
-
);
|
750
|
-
return indicator;
|
751
|
-
};
|
752
|
-
|
753
752
|
// src/primitive-hooks/contentPart/useContentPartText.tsx
|
754
753
|
var useContentPartText = () => {
|
755
754
|
const { useContentPart } = useContentPartContext();
|
@@ -782,14 +781,17 @@ var useMessageIf = (props) => {
|
|
782
781
|
|
783
782
|
// src/primitive-hooks/thread/useThreadIf.tsx
|
784
783
|
var useThreadIf = (props) => {
|
785
|
-
const { useThread } = useThreadContext();
|
786
|
-
return
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
784
|
+
const { useThread, useThreadMessages } = useThreadContext();
|
785
|
+
return useCombinedStore(
|
786
|
+
[useThread, useThreadMessages],
|
787
|
+
(thread, messages) => {
|
788
|
+
if (props.empty === true && messages.length !== 0) return false;
|
789
|
+
if (props.empty === false && messages.length === 0) return false;
|
790
|
+
if (props.running === true && !thread.isRunning) return false;
|
791
|
+
if (props.running === false && thread.isRunning) return false;
|
792
|
+
return true;
|
793
|
+
}
|
794
|
+
);
|
793
795
|
};
|
794
796
|
|
795
797
|
// src/primitive-hooks/thread/useThreadEmpty.tsx
|
@@ -931,6 +933,7 @@ var ActionBarPrimitiveEdit = createActionButton(
|
|
931
933
|
// src/primitives/assistantModal/index.ts
|
932
934
|
var assistantModal_exports = {};
|
933
935
|
__export(assistantModal_exports, {
|
936
|
+
Anchor: () => AssistantModalPrimitiveAnchor,
|
934
937
|
Content: () => AssistantModalPrimitiveContent,
|
935
938
|
Root: () => AssistantModalPrimitiveRoot,
|
936
939
|
Trigger: () => AssistantModalPrimitiveTrigger
|
@@ -1037,6 +1040,21 @@ var AssistantModalPrimitiveContent = (0, import_react30.forwardRef)(
|
|
1037
1040
|
);
|
1038
1041
|
AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
|
1039
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
|
+
|
1040
1058
|
// src/primitives/branchPicker/index.ts
|
1041
1059
|
var branchPicker_exports = {};
|
1042
1060
|
__export(branchPicker_exports, {
|
@@ -1060,24 +1078,24 @@ var BranchPickerPrevious = createActionButton(
|
|
1060
1078
|
);
|
1061
1079
|
|
1062
1080
|
// src/primitives/branchPicker/BranchPickerCount.tsx
|
1063
|
-
var
|
1081
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
1064
1082
|
var BranchPickerPrimitiveCount = () => {
|
1065
1083
|
const branchCount = useBranchPickerCount();
|
1066
|
-
return /* @__PURE__ */ (0,
|
1084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: branchCount });
|
1067
1085
|
};
|
1068
1086
|
BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
|
1069
1087
|
|
1070
1088
|
// src/primitives/branchPicker/BranchPickerNumber.tsx
|
1071
|
-
var
|
1089
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
1072
1090
|
var BranchPickerPrimitiveNumber = () => {
|
1073
1091
|
const branchNumber = useBranchPickerNumber();
|
1074
|
-
return /* @__PURE__ */ (0,
|
1092
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: branchNumber });
|
1075
1093
|
};
|
1076
1094
|
BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
|
1077
1095
|
|
1078
1096
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1079
1097
|
var import_react_primitive6 = require("@radix-ui/react-primitive");
|
1080
|
-
var
|
1098
|
+
var import_react38 = require("react");
|
1081
1099
|
|
1082
1100
|
// src/primitives/message/index.ts
|
1083
1101
|
var message_exports = {};
|
@@ -1091,9 +1109,9 @@ __export(message_exports, {
|
|
1091
1109
|
// src/primitives/message/MessageRoot.tsx
|
1092
1110
|
var import_primitive4 = require("@radix-ui/primitive");
|
1093
1111
|
var import_react_primitive3 = require("@radix-ui/react-primitive");
|
1094
|
-
var
|
1095
|
-
var
|
1096
|
-
var MessagePrimitiveRoot = (0,
|
1112
|
+
var import_react32 = require("react");
|
1113
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
1114
|
+
var MessagePrimitiveRoot = (0, import_react32.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
|
1097
1115
|
const { useMessageUtils } = useMessageContext();
|
1098
1116
|
const setIsHovering = useMessageUtils((s) => s.setIsHovering);
|
1099
1117
|
const handleMouseEnter = () => {
|
@@ -1102,7 +1120,7 @@ var MessagePrimitiveRoot = (0, import_react31.forwardRef)(({ onMouseEnter, onMou
|
|
1102
1120
|
const handleMouseLeave = () => {
|
1103
1121
|
setIsHovering(false);
|
1104
1122
|
};
|
1105
|
-
return /* @__PURE__ */ (0,
|
1123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
1106
1124
|
import_react_primitive3.Primitive.div,
|
1107
1125
|
{
|
1108
1126
|
...rest,
|
@@ -1125,12 +1143,12 @@ var MessagePrimitiveIf = ({
|
|
1125
1143
|
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
1126
1144
|
|
1127
1145
|
// src/primitives/message/MessageContent.tsx
|
1128
|
-
var
|
1146
|
+
var import_react36 = require("react");
|
1129
1147
|
|
1130
1148
|
// src/context/providers/ContentPartProvider.tsx
|
1131
|
-
var
|
1132
|
-
var
|
1133
|
-
var
|
1149
|
+
var import_react33 = require("react");
|
1150
|
+
var import_zustand9 = require("zustand");
|
1151
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
1134
1152
|
var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
1135
1153
|
const part = message.content[partIndex];
|
1136
1154
|
if (!part) return;
|
@@ -1147,14 +1165,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
|
1147
1165
|
};
|
1148
1166
|
var useContentPartContext2 = (partIndex) => {
|
1149
1167
|
const { useMessage } = useMessageContext();
|
1150
|
-
const [context] = (0,
|
1151
|
-
const useContentPart = (0,
|
1168
|
+
const [context] = (0, import_react33.useState)(() => {
|
1169
|
+
const useContentPart = (0, import_zustand9.create)(
|
1152
1170
|
() => ({})
|
1153
1171
|
);
|
1154
1172
|
syncContentPart(useMessage.getState(), useContentPart, partIndex);
|
1155
1173
|
return { useContentPart };
|
1156
1174
|
});
|
1157
|
-
(0,
|
1175
|
+
(0, import_react33.useEffect)(() => {
|
1158
1176
|
syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
|
1159
1177
|
return useMessage.subscribe((message) => {
|
1160
1178
|
syncContentPart(message, context.useContentPart, partIndex);
|
@@ -1167,7 +1185,7 @@ var ContentPartProvider = ({
|
|
1167
1185
|
children
|
1168
1186
|
}) => {
|
1169
1187
|
const context = useContentPartContext2(partIndex);
|
1170
|
-
return /* @__PURE__ */ (0,
|
1188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ContentPartContext.Provider, { value: context, children });
|
1171
1189
|
};
|
1172
1190
|
|
1173
1191
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
@@ -1177,38 +1195,61 @@ var ContentPartPrimitiveDisplay = () => {
|
|
1177
1195
|
};
|
1178
1196
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
1179
1197
|
|
1198
|
+
// src/utils/OutPortal.tsx
|
1199
|
+
var import_react34 = require("react");
|
1200
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
1201
|
+
var OutPortal = ({ node }) => {
|
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
|
+
|
1180
1215
|
// src/primitives/contentPart/ContentPartInProgressIndicator.tsx
|
1216
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
1181
1217
|
var ContentPartPrimitiveInProgressIndicator = () => {
|
1182
|
-
const
|
1183
|
-
|
1218
|
+
const { useMessageUtils } = useMessageContext();
|
1219
|
+
const { useContentPart } = useContentPartContext();
|
1220
|
+
const indicator = useCombinedStore(
|
1221
|
+
[useMessageUtils, useContentPart],
|
1222
|
+
(m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
|
1223
|
+
);
|
1224
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(OutPortal, { node: indicator });
|
1184
1225
|
};
|
1185
1226
|
ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
|
1186
1227
|
|
1187
1228
|
// src/primitives/contentPart/ContentPartText.tsx
|
1188
1229
|
var import_react_primitive4 = require("@radix-ui/react-primitive");
|
1189
|
-
var
|
1190
|
-
var
|
1191
|
-
var ContentPartPrimitiveText = (0,
|
1230
|
+
var import_react35 = require("react");
|
1231
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
1232
|
+
var ContentPartPrimitiveText = (0, import_react35.forwardRef)((props, forwardedRef) => {
|
1192
1233
|
const text = useContentPartText();
|
1193
|
-
return /* @__PURE__ */ (0,
|
1234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive4.Primitive.span, { ...props, ref: forwardedRef, children: text });
|
1194
1235
|
});
|
1195
1236
|
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1196
1237
|
|
1197
1238
|
// src/primitives/message/MessageContent.tsx
|
1198
|
-
var
|
1239
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
1199
1240
|
var defaultComponents = {
|
1200
|
-
Text: () => /* @__PURE__ */ (0,
|
1201
|
-
/* @__PURE__ */ (0,
|
1202
|
-
/* @__PURE__ */ (0,
|
1241
|
+
Text: () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("p", { style: { whiteSpace: "pre-line" }, children: [
|
1242
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ContentPartPrimitiveText, {}),
|
1243
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ContentPartPrimitiveInProgressIndicator, {})
|
1203
1244
|
] }),
|
1204
1245
|
Image: () => null,
|
1205
|
-
UI: () => /* @__PURE__ */ (0,
|
1246
|
+
UI: () => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ContentPartPrimitiveDisplay, {}),
|
1206
1247
|
tools: {
|
1207
1248
|
Fallback: (props) => {
|
1208
1249
|
const { useToolUIs } = useAssistantContext();
|
1209
1250
|
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
1210
1251
|
if (!Render) return null;
|
1211
|
-
return /* @__PURE__ */ (0,
|
1252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Render, { ...props });
|
1212
1253
|
}
|
1213
1254
|
}
|
1214
1255
|
};
|
@@ -1227,15 +1268,15 @@ var MessageContentPartComponent = ({
|
|
1227
1268
|
const type = part.type;
|
1228
1269
|
switch (type) {
|
1229
1270
|
case "text":
|
1230
|
-
return /* @__PURE__ */ (0,
|
1271
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Text, { part, status });
|
1231
1272
|
case "image":
|
1232
|
-
return /* @__PURE__ */ (0,
|
1273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Image, { part, status });
|
1233
1274
|
case "ui":
|
1234
|
-
return /* @__PURE__ */ (0,
|
1275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(UI, { part, status });
|
1235
1276
|
case "tool-call": {
|
1236
1277
|
const Tool = by_name[part.toolName] || Fallback;
|
1237
1278
|
const addResult = (result) => addToolResult(part.toolCallId, result);
|
1238
|
-
return /* @__PURE__ */ (0,
|
1279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Tool, { part, status, addResult });
|
1239
1280
|
}
|
1240
1281
|
default:
|
1241
1282
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -1245,9 +1286,9 @@ var MessageContentPartImpl = ({
|
|
1245
1286
|
partIndex,
|
1246
1287
|
components
|
1247
1288
|
}) => {
|
1248
|
-
return /* @__PURE__ */ (0,
|
1289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessageContentPartComponent, { components }) });
|
1249
1290
|
};
|
1250
|
-
var MessageContentPart = (0,
|
1291
|
+
var MessageContentPart = (0, import_react36.memo)(
|
1251
1292
|
MessageContentPartImpl,
|
1252
1293
|
(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
|
1253
1294
|
);
|
@@ -1258,7 +1299,7 @@ var MessagePrimitiveContent = ({
|
|
1258
1299
|
const contentLength = useMessage((s) => s.message.content.length);
|
1259
1300
|
return new Array(contentLength).fill(null).map((_, idx) => {
|
1260
1301
|
const partIndex = idx;
|
1261
|
-
return /* @__PURE__ */ (0,
|
1302
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
1262
1303
|
MessageContentPart,
|
1263
1304
|
{
|
1264
1305
|
partIndex,
|
@@ -1271,25 +1312,21 @@ var MessagePrimitiveContent = ({
|
|
1271
1312
|
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
1272
1313
|
|
1273
1314
|
// src/primitives/message/MessageInProgress.tsx
|
1315
|
+
var import_react_dom = require("react-dom");
|
1274
1316
|
var import_react_primitive5 = require("@radix-ui/react-primitive");
|
1275
|
-
var
|
1276
|
-
var
|
1277
|
-
var MessagePrimitiveInProgress = (0,
|
1317
|
+
var import_react37 = require("react");
|
1318
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1319
|
+
var MessagePrimitiveInProgress = (0, import_react37.forwardRef)((props, ref) => {
|
1278
1320
|
const { useMessageUtils } = useMessageContext();
|
1279
|
-
|
1280
|
-
|
1281
|
-
return () => {
|
1282
|
-
useMessageUtils.getState().setInProgressIndicator(null);
|
1283
|
-
};
|
1284
|
-
}, [useMessageUtils, props, ref]);
|
1285
|
-
return null;
|
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);
|
1286
1323
|
});
|
1287
1324
|
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
1288
1325
|
|
1289
1326
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1290
|
-
var
|
1291
|
-
var BranchPickerPrimitiveRoot = (0,
|
1292
|
-
return /* @__PURE__ */ (0,
|
1327
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1328
|
+
var BranchPickerPrimitiveRoot = (0, import_react38.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1329
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
|
1293
1330
|
});
|
1294
1331
|
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
1295
1332
|
|
@@ -1306,16 +1343,16 @@ __export(composer_exports, {
|
|
1306
1343
|
// src/primitives/composer/ComposerRoot.tsx
|
1307
1344
|
var import_primitive5 = require("@radix-ui/primitive");
|
1308
1345
|
var import_react_primitive7 = require("@radix-ui/react-primitive");
|
1309
|
-
var
|
1310
|
-
var
|
1311
|
-
var ComposerPrimitiveRoot = (0,
|
1346
|
+
var import_react39 = require("react");
|
1347
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
1348
|
+
var ComposerPrimitiveRoot = (0, import_react39.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
|
1312
1349
|
const send = useComposerSend();
|
1313
1350
|
const handleSubmit = (e) => {
|
1314
1351
|
e.preventDefault();
|
1315
1352
|
if (!send) return;
|
1316
1353
|
send();
|
1317
1354
|
};
|
1318
|
-
return /* @__PURE__ */ (0,
|
1355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
1319
1356
|
import_react_primitive7.Primitive.form,
|
1320
1357
|
{
|
1321
1358
|
...rest,
|
@@ -1330,11 +1367,11 @@ ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
|
1330
1367
|
var import_primitive6 = require("@radix-ui/primitive");
|
1331
1368
|
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
|
1332
1369
|
var import_react_slot = require("@radix-ui/react-slot");
|
1333
|
-
var
|
1370
|
+
var import_react40 = require("react");
|
1334
1371
|
var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
|
1335
1372
|
var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
|
1336
|
-
var
|
1337
|
-
var ComposerPrimitiveInput = (0,
|
1373
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1374
|
+
var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
1338
1375
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
1339
1376
|
const { useThread } = useThreadContext();
|
1340
1377
|
const { useComposer, type } = useComposerContext();
|
@@ -1343,7 +1380,7 @@ var ComposerPrimitiveInput = (0, import_react38.forwardRef)(
|
|
1343
1380
|
return c.value;
|
1344
1381
|
});
|
1345
1382
|
const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
|
1346
|
-
const textareaRef = (0,
|
1383
|
+
const textareaRef = (0, import_react40.useRef)(null);
|
1347
1384
|
const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, textareaRef);
|
1348
1385
|
(0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
|
1349
1386
|
const composer = useComposer.getState();
|
@@ -1362,7 +1399,7 @@ var ComposerPrimitiveInput = (0, import_react38.forwardRef)(
|
|
1362
1399
|
}
|
1363
1400
|
};
|
1364
1401
|
const autoFocusEnabled = autoFocus && !disabled;
|
1365
|
-
const focus = (0,
|
1402
|
+
const focus = (0, import_react40.useCallback)(() => {
|
1366
1403
|
const textarea = textareaRef.current;
|
1367
1404
|
if (!textarea || !autoFocusEnabled) return;
|
1368
1405
|
textarea.focus({ preventScroll: true });
|
@@ -1371,13 +1408,13 @@ var ComposerPrimitiveInput = (0, import_react38.forwardRef)(
|
|
1371
1408
|
textareaRef.current.value.length
|
1372
1409
|
);
|
1373
1410
|
}, [autoFocusEnabled]);
|
1374
|
-
(0,
|
1411
|
+
(0, import_react40.useEffect)(() => focus(), [focus]);
|
1375
1412
|
useOnComposerFocus(() => {
|
1376
1413
|
if (type === "new") {
|
1377
1414
|
focus();
|
1378
1415
|
}
|
1379
1416
|
});
|
1380
|
-
return /* @__PURE__ */ (0,
|
1417
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
1381
1418
|
Component,
|
1382
1419
|
{
|
1383
1420
|
value,
|
@@ -1397,13 +1434,13 @@ var ComposerPrimitiveInput = (0, import_react38.forwardRef)(
|
|
1397
1434
|
ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
1398
1435
|
|
1399
1436
|
// src/primitives/composer/ComposerSend.tsx
|
1400
|
-
var
|
1437
|
+
var import_react41 = require("react");
|
1401
1438
|
var import_react_primitive8 = require("@radix-ui/react-primitive");
|
1402
|
-
var
|
1403
|
-
var ComposerPrimitiveSend = (0,
|
1439
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1440
|
+
var ComposerPrimitiveSend = (0, import_react41.forwardRef)(({ disabled, ...rest }, ref) => {
|
1404
1441
|
const { useComposer } = useComposerContext();
|
1405
1442
|
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1406
|
-
return /* @__PURE__ */ (0,
|
1443
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
1407
1444
|
import_react_primitive8.Primitive.button,
|
1408
1445
|
{
|
1409
1446
|
type: "submit",
|
@@ -1442,11 +1479,11 @@ __export(contentPart_exports, {
|
|
1442
1479
|
|
1443
1480
|
// src/primitives/contentPart/ContentPartImage.tsx
|
1444
1481
|
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
1445
|
-
var
|
1446
|
-
var
|
1447
|
-
var ContentPartPrimitiveImage = (0,
|
1482
|
+
var import_react42 = require("react");
|
1483
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
1484
|
+
var ContentPartPrimitiveImage = (0, import_react42.forwardRef)((props, forwardedRef) => {
|
1448
1485
|
const image = useContentPartImage();
|
1449
|
-
return /* @__PURE__ */ (0,
|
1486
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
|
1450
1487
|
});
|
1451
1488
|
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1452
1489
|
|
@@ -1464,10 +1501,10 @@ __export(thread_exports, {
|
|
1464
1501
|
|
1465
1502
|
// src/primitives/thread/ThreadRoot.tsx
|
1466
1503
|
var import_react_primitive10 = require("@radix-ui/react-primitive");
|
1467
|
-
var
|
1468
|
-
var
|
1469
|
-
var ThreadPrimitiveRoot = (0,
|
1470
|
-
return /* @__PURE__ */ (0,
|
1504
|
+
var import_react43 = require("react");
|
1505
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
1506
|
+
var ThreadPrimitiveRoot = (0, import_react43.forwardRef)((props, ref) => {
|
1507
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react_primitive10.Primitive.div, { ...props, ref });
|
1471
1508
|
});
|
1472
1509
|
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
1473
1510
|
|
@@ -1493,21 +1530,21 @@ ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
|
1493
1530
|
// src/primitives/thread/ThreadViewport.tsx
|
1494
1531
|
var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
|
1495
1532
|
var import_react_primitive11 = require("@radix-ui/react-primitive");
|
1496
|
-
var
|
1533
|
+
var import_react48 = require("react");
|
1497
1534
|
|
1498
1535
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
1499
1536
|
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
|
1500
|
-
var
|
1537
|
+
var import_react47 = require("react");
|
1501
1538
|
|
1502
1539
|
// src/utils/hooks/useOnResizeContent.tsx
|
1503
1540
|
var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
|
1504
|
-
var
|
1541
|
+
var import_react45 = require("react");
|
1505
1542
|
|
1506
1543
|
// src/utils/hooks/useManagedRef.ts
|
1507
|
-
var
|
1544
|
+
var import_react44 = require("react");
|
1508
1545
|
var useManagedRef = (callback) => {
|
1509
|
-
const cleanupRef = (0,
|
1510
|
-
const ref = (0,
|
1546
|
+
const cleanupRef = (0, import_react44.useRef)();
|
1547
|
+
const ref = (0, import_react44.useCallback)(
|
1511
1548
|
(el) => {
|
1512
1549
|
if (cleanupRef.current) {
|
1513
1550
|
cleanupRef.current();
|
@@ -1524,7 +1561,7 @@ var useManagedRef = (callback) => {
|
|
1524
1561
|
// src/utils/hooks/useOnResizeContent.tsx
|
1525
1562
|
var useOnResizeContent = (callback) => {
|
1526
1563
|
const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
|
1527
|
-
const refCallback = (0,
|
1564
|
+
const refCallback = (0, import_react45.useCallback)(
|
1528
1565
|
(el) => {
|
1529
1566
|
const resizeObserver = new ResizeObserver(() => {
|
1530
1567
|
callbackRef();
|
@@ -1561,11 +1598,11 @@ var useOnResizeContent = (callback) => {
|
|
1561
1598
|
|
1562
1599
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
1563
1600
|
var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
|
1564
|
-
var
|
1601
|
+
var import_react46 = require("react");
|
1565
1602
|
var useOnScrollToBottom = (callback) => {
|
1566
1603
|
const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
|
1567
1604
|
const { useViewport } = useThreadContext();
|
1568
|
-
(0,
|
1605
|
+
(0, import_react46.useEffect)(() => {
|
1569
1606
|
return useViewport.getState().onScrollToBottom(() => {
|
1570
1607
|
callbackRef();
|
1571
1608
|
});
|
@@ -1576,11 +1613,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1576
1613
|
var useThreadViewportAutoScroll = ({
|
1577
1614
|
autoScroll = true
|
1578
1615
|
}) => {
|
1579
|
-
const divRef = (0,
|
1616
|
+
const divRef = (0, import_react47.useRef)(null);
|
1580
1617
|
const { useViewport } = useThreadContext();
|
1581
|
-
const firstRenderRef = (0,
|
1582
|
-
const lastScrollTop = (0,
|
1583
|
-
const isScrollingToBottomRef = (0,
|
1618
|
+
const firstRenderRef = (0, import_react47.useRef)(true);
|
1619
|
+
const lastScrollTop = (0, import_react47.useRef)(0);
|
1620
|
+
const isScrollingToBottomRef = (0, import_react47.useRef)(false);
|
1584
1621
|
const scrollToBottom = () => {
|
1585
1622
|
const div = divRef.current;
|
1586
1623
|
if (!div || !autoScroll) return;
|
@@ -1626,29 +1663,29 @@ var useThreadViewportAutoScroll = ({
|
|
1626
1663
|
};
|
1627
1664
|
|
1628
1665
|
// src/primitives/thread/ThreadViewport.tsx
|
1629
|
-
var
|
1630
|
-
var ThreadPrimitiveViewport = (0,
|
1666
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
1667
|
+
var ThreadPrimitiveViewport = (0, import_react48.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1631
1668
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1632
1669
|
autoScroll
|
1633
1670
|
});
|
1634
1671
|
const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, autoScrollRef);
|
1635
|
-
return /* @__PURE__ */ (0,
|
1672
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react_primitive11.Primitive.div, { ...rest, ref, children });
|
1636
1673
|
});
|
1637
1674
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1638
1675
|
|
1639
1676
|
// src/primitives/thread/ThreadMessages.tsx
|
1640
|
-
var
|
1677
|
+
var import_react50 = require("react");
|
1641
1678
|
|
1642
1679
|
// src/context/providers/MessageProvider.tsx
|
1643
|
-
var
|
1644
|
-
var
|
1680
|
+
var import_react49 = require("react");
|
1681
|
+
var import_zustand12 = require("zustand");
|
1645
1682
|
|
1646
1683
|
// src/context/stores/EditComposer.ts
|
1647
|
-
var
|
1684
|
+
var import_zustand10 = require("zustand");
|
1648
1685
|
var makeEditComposerStore = ({
|
1649
1686
|
onEdit,
|
1650
1687
|
onSend
|
1651
|
-
}) => (0,
|
1688
|
+
}) => (0, import_zustand10.create)()((set, get, store) => ({
|
1652
1689
|
...makeBaseComposer(set, get, store),
|
1653
1690
|
isEditing: false,
|
1654
1691
|
edit: () => {
|
@@ -1668,12 +1705,9 @@ var makeEditComposerStore = ({
|
|
1668
1705
|
}));
|
1669
1706
|
|
1670
1707
|
// src/context/stores/MessageUtils.ts
|
1671
|
-
var
|
1672
|
-
var makeMessageUtilsStore = () => (0,
|
1673
|
-
inProgressIndicator:
|
1674
|
-
setInProgressIndicator: (value) => {
|
1675
|
-
set({ inProgressIndicator: value });
|
1676
|
-
},
|
1708
|
+
var import_zustand11 = require("zustand");
|
1709
|
+
var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
|
1710
|
+
inProgressIndicator: document.createElement("span"),
|
1677
1711
|
isCopied: false,
|
1678
1712
|
setIsCopied: (value) => {
|
1679
1713
|
set({ isCopied: value });
|
@@ -1685,15 +1719,15 @@ var makeMessageUtilsStore = () => (0, import_zustand10.create)((set) => ({
|
|
1685
1719
|
}));
|
1686
1720
|
|
1687
1721
|
// src/context/providers/MessageProvider.tsx
|
1688
|
-
var
|
1689
|
-
var getIsLast = (
|
1690
|
-
return
|
1722
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
1723
|
+
var getIsLast = (messages, message) => {
|
1724
|
+
return messages[messages.length - 1]?.id === message.id;
|
1691
1725
|
};
|
1692
|
-
var syncMessage = (
|
1693
|
-
const parentId =
|
1694
|
-
const message =
|
1726
|
+
var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
|
1727
|
+
const parentId = messages[messageIndex - 1]?.id ?? null;
|
1728
|
+
const message = messages[messageIndex];
|
1695
1729
|
if (!message) return;
|
1696
|
-
const isLast = getIsLast(
|
1730
|
+
const isLast = getIsLast(messages, message);
|
1697
1731
|
const branches = getBranches(message.id);
|
1698
1732
|
const currentState = useMessage.getState();
|
1699
1733
|
if (currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
|
@@ -1706,9 +1740,9 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
|
|
1706
1740
|
});
|
1707
1741
|
};
|
1708
1742
|
var useMessageContext2 = (messageIndex) => {
|
1709
|
-
const {
|
1710
|
-
const [context] = (0,
|
1711
|
-
const useMessage = (0,
|
1743
|
+
const { useThreadMessages, useThreadActions } = useThreadContext();
|
1744
|
+
const [context] = (0, import_react49.useState)(() => {
|
1745
|
+
const useMessage = (0, import_zustand12.create)(() => ({}));
|
1712
1746
|
const useMessageUtils = makeMessageUtilsStore();
|
1713
1747
|
const useEditComposer = makeEditComposerStore({
|
1714
1748
|
onEdit: () => {
|
@@ -1737,15 +1771,15 @@ var useMessageContext2 = (messageIndex) => {
|
|
1737
1771
|
}
|
1738
1772
|
});
|
1739
1773
|
syncMessage(
|
1740
|
-
|
1774
|
+
useThreadMessages.getState(),
|
1741
1775
|
useThreadActions.getState().getBranches,
|
1742
1776
|
useMessage,
|
1743
1777
|
messageIndex
|
1744
1778
|
);
|
1745
1779
|
return { useMessage, useMessageUtils, useEditComposer };
|
1746
1780
|
});
|
1747
|
-
(0,
|
1748
|
-
return
|
1781
|
+
(0, import_react49.useEffect)(() => {
|
1782
|
+
return useThreadMessages.subscribe((thread) => {
|
1749
1783
|
syncMessage(
|
1750
1784
|
thread,
|
1751
1785
|
useThreadActions.getState().getBranches,
|
@@ -1753,7 +1787,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1753
1787
|
messageIndex
|
1754
1788
|
);
|
1755
1789
|
});
|
1756
|
-
}, [
|
1790
|
+
}, [useThreadMessages, useThreadActions, context, messageIndex]);
|
1757
1791
|
return context;
|
1758
1792
|
};
|
1759
1793
|
var MessageProvider = ({
|
@@ -1761,11 +1795,11 @@ var MessageProvider = ({
|
|
1761
1795
|
children
|
1762
1796
|
}) => {
|
1763
1797
|
const context = useMessageContext2(messageIndex);
|
1764
|
-
return /* @__PURE__ */ (0,
|
1798
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(MessageContext.Provider, { value: context, children });
|
1765
1799
|
};
|
1766
1800
|
|
1767
1801
|
// src/primitives/thread/ThreadMessages.tsx
|
1768
|
-
var
|
1802
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
1769
1803
|
var getComponents = (components) => {
|
1770
1804
|
return {
|
1771
1805
|
EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
|
@@ -1778,27 +1812,27 @@ var ThreadMessageImpl = ({
|
|
1778
1812
|
components
|
1779
1813
|
}) => {
|
1780
1814
|
const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
|
1781
|
-
return /* @__PURE__ */ (0,
|
1782
|
-
/* @__PURE__ */ (0,
|
1783
|
-
/* @__PURE__ */ (0,
|
1784
|
-
/* @__PURE__ */ (0,
|
1815
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(MessageProvider, { messageIndex, children: [
|
1816
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(MessagePrimitiveIf, { user: true, children: [
|
1817
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(UserMessage, {}) }),
|
1818
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(EditComposer, {}) })
|
1785
1819
|
] }),
|
1786
|
-
/* @__PURE__ */ (0,
|
1820
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(AssistantMessage, {}) })
|
1787
1821
|
] });
|
1788
1822
|
};
|
1789
|
-
var ThreadMessage = (0,
|
1823
|
+
var ThreadMessage = (0, import_react50.memo)(
|
1790
1824
|
ThreadMessageImpl,
|
1791
1825
|
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1792
1826
|
);
|
1793
1827
|
var ThreadPrimitiveMessages = ({
|
1794
1828
|
components
|
1795
1829
|
}) => {
|
1796
|
-
const {
|
1797
|
-
const messagesLength =
|
1830
|
+
const { useThreadMessages } = useThreadContext();
|
1831
|
+
const messagesLength = useThreadMessages((t) => t.length);
|
1798
1832
|
if (messagesLength === 0) return null;
|
1799
1833
|
return new Array(messagesLength).fill(null).map((_, idx) => {
|
1800
1834
|
const messageIndex = idx;
|
1801
|
-
return /* @__PURE__ */ (0,
|
1835
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
1802
1836
|
ThreadMessage,
|
1803
1837
|
{
|
1804
1838
|
messageIndex,
|
@@ -1823,7 +1857,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
|
|
1823
1857
|
);
|
1824
1858
|
|
1825
1859
|
// src/runtime/local/useLocalRuntime.tsx
|
1826
|
-
var
|
1860
|
+
var import_react51 = require("react");
|
1827
1861
|
|
1828
1862
|
// src/runtime/utils/idUtils.tsx
|
1829
1863
|
var import_non_secure = require("nanoid/non-secure");
|
@@ -2155,8 +2189,8 @@ var LocalThreadRuntime = class {
|
|
2155
2189
|
|
2156
2190
|
// src/runtime/local/useLocalRuntime.tsx
|
2157
2191
|
var useLocalRuntime = (adapter) => {
|
2158
|
-
const [runtime] = (0,
|
2159
|
-
(0,
|
2192
|
+
const [runtime] = (0, import_react51.useState)(() => new LocalRuntime(adapter));
|
2193
|
+
(0, import_react51.useInsertionEffect)(() => {
|
2160
2194
|
runtime.adapter = adapter;
|
2161
2195
|
});
|
2162
2196
|
return runtime;
|
@@ -2201,7 +2235,6 @@ __export(internal_exports, {
|
|
2201
2235
|
useContentPartContext,
|
2202
2236
|
useContentPartDisplay,
|
2203
2237
|
useContentPartImage,
|
2204
|
-
useContentPartInProgressIndicator,
|
2205
2238
|
useContentPartText,
|
2206
2239
|
useLocalRuntime,
|
2207
2240
|
useMessageContext,
|