@assistant-ui/react 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -3
- package/dist/index.d.mts +97 -90
- package/dist/index.d.ts +97 -90
- package/dist/index.js +202 -244
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -220
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -9
package/dist/index.js
CHANGED
@@ -41,7 +41,7 @@ __export(src_exports, {
|
|
41
41
|
VercelRSCAssistantProvider: () => VercelRSCAssistantProvider,
|
42
42
|
getVercelAIMessage: () => getVercelAIMessage,
|
43
43
|
getVercelRSCMessage: () => getVercelRSCMessage,
|
44
|
-
|
44
|
+
unstable_MessageRepository: () => MessageRepository,
|
45
45
|
unstable_useComposerContext: () => useComposerContext,
|
46
46
|
unstable_useContentPartContext: () => useContentPartContext,
|
47
47
|
unstable_useLocalRuntime: () => useLocalRuntime,
|
@@ -1041,16 +1041,16 @@ __export(contentPart_exports, {
|
|
1041
1041
|
InProgressIndicator: () => ContentPartInProgressIndicator
|
1042
1042
|
});
|
1043
1043
|
|
1044
|
-
//
|
1044
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx
|
1045
1045
|
var import_react30 = require("react");
|
1046
1046
|
|
1047
|
-
//
|
1047
|
+
// ../react-ai-sdk/src/rsc/VercelRSCRuntime.tsx
|
1048
1048
|
var import_zustand4 = require("zustand");
|
1049
1049
|
|
1050
|
-
//
|
1050
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCSync.tsx
|
1051
1051
|
var import_react29 = require("react");
|
1052
1052
|
|
1053
|
-
//
|
1053
|
+
// ../react-ai-sdk/src/utils/ThreadMessageConverter.ts
|
1054
1054
|
var ThreadMessageConverter = class {
|
1055
1055
|
cache = /* @__PURE__ */ new WeakMap();
|
1056
1056
|
convertMessages(messages, converter, keyMapper = (key) => key) {
|
@@ -1064,13 +1064,13 @@ var ThreadMessageConverter = class {
|
|
1064
1064
|
}
|
1065
1065
|
};
|
1066
1066
|
|
1067
|
-
//
|
1067
|
+
// ../react-ai-sdk/src/rsc/getVercelRSCMessage.tsx
|
1068
1068
|
var symbolInnerRSCMessage = Symbol("innerVercelRSCMessage");
|
1069
1069
|
var getVercelRSCMessage = (message) => {
|
1070
1070
|
return message[symbolInnerRSCMessage];
|
1071
1071
|
};
|
1072
1072
|
|
1073
|
-
//
|
1073
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCSync.tsx
|
1074
1074
|
var vercelToThreadMessage = (converter, rawMessage) => {
|
1075
1075
|
const message = converter(rawMessage);
|
1076
1076
|
return {
|
@@ -1096,7 +1096,7 @@ var useVercelRSCSync = (adapter, updateData) => {
|
|
1096
1096
|
}, [updateData, converter, convertCallback, adapter.messages]);
|
1097
1097
|
};
|
1098
1098
|
|
1099
|
-
//
|
1099
|
+
// ../react-ai-sdk/src/rsc/VercelRSCRuntime.tsx
|
1100
1100
|
var EMPTY_BRANCHES = Object.freeze([]);
|
1101
1101
|
var VercelRSCRuntime = class {
|
1102
1102
|
constructor(adapter) {
|
@@ -1168,7 +1168,7 @@ var VercelRSCRuntime = class {
|
|
1168
1168
|
};
|
1169
1169
|
};
|
1170
1170
|
|
1171
|
-
//
|
1171
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx
|
1172
1172
|
var useVercelRSCRuntime = (adapter) => {
|
1173
1173
|
const [runtime] = (0, import_react30.useState)(() => new VercelRSCRuntime(adapter));
|
1174
1174
|
(0, import_react30.useInsertionEffect)(() => {
|
@@ -1180,179 +1180,19 @@ var useVercelRSCRuntime = (adapter) => {
|
|
1180
1180
|
return runtime;
|
1181
1181
|
};
|
1182
1182
|
|
1183
|
-
//
|
1184
|
-
var
|
1183
|
+
// ../react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx
|
1184
|
+
var import_react35 = require("react");
|
1185
1185
|
|
1186
|
-
//
|
1186
|
+
// ../react-ai-sdk/src/ui/VercelAIRuntime.tsx
|
1187
1187
|
var import_zustand5 = require("zustand");
|
1188
1188
|
|
1189
|
-
// src/
|
1190
|
-
var import_non_secure = require("nanoid/non-secure");
|
1191
|
-
var generateId = (0, import_non_secure.customAlphabet)(
|
1192
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
1193
|
-
7
|
1194
|
-
);
|
1195
|
-
var optimisticPrefix = "__optimistic__";
|
1196
|
-
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1197
|
-
|
1198
|
-
// src/runtime/utils/MessageRepository.tsx
|
1199
|
-
var findHead = (message) => {
|
1200
|
-
if (message.next) return findHead(message.next);
|
1201
|
-
return message;
|
1202
|
-
};
|
1203
|
-
var MessageRepository = class {
|
1204
|
-
messages = /* @__PURE__ */ new Map();
|
1205
|
-
// message_id -> item
|
1206
|
-
head = null;
|
1207
|
-
root = {
|
1208
|
-
children: []
|
1209
|
-
};
|
1210
|
-
performOp(newParent, child, operation) {
|
1211
|
-
const parentOrRoot = child.prev ?? this.root;
|
1212
|
-
const newParentOrRoot = newParent ?? this.root;
|
1213
|
-
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1214
|
-
if (operation !== "link") {
|
1215
|
-
parentOrRoot.children = parentOrRoot.children.filter(
|
1216
|
-
(m) => m !== child.current.id
|
1217
|
-
);
|
1218
|
-
if (child.prev?.next === child) {
|
1219
|
-
const fallbackId = child.prev.children.at(-1);
|
1220
|
-
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1221
|
-
if (fallback === void 0) {
|
1222
|
-
throw new Error(
|
1223
|
-
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1224
|
-
);
|
1225
|
-
}
|
1226
|
-
child.prev.next = fallback;
|
1227
|
-
}
|
1228
|
-
}
|
1229
|
-
if (operation !== "cut") {
|
1230
|
-
newParentOrRoot.children = [
|
1231
|
-
...newParentOrRoot.children,
|
1232
|
-
child.current.id
|
1233
|
-
];
|
1234
|
-
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1235
|
-
newParent.next = child;
|
1236
|
-
}
|
1237
|
-
child.prev = newParent;
|
1238
|
-
}
|
1239
|
-
}
|
1240
|
-
getMessages() {
|
1241
|
-
const messages = new Array(this.head?.level ?? 0);
|
1242
|
-
for (let current = this.head; current; current = current.prev) {
|
1243
|
-
messages[current.level] = current.current;
|
1244
|
-
}
|
1245
|
-
return messages;
|
1246
|
-
}
|
1247
|
-
addOrUpdateMessage(parentId, message) {
|
1248
|
-
const existingItem = this.messages.get(message.id);
|
1249
|
-
const prev = parentId ? this.messages.get(parentId) : null;
|
1250
|
-
if (prev === void 0)
|
1251
|
-
throw new Error(
|
1252
|
-
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1253
|
-
);
|
1254
|
-
if (existingItem) {
|
1255
|
-
existingItem.current = message;
|
1256
|
-
this.performOp(prev, existingItem, "relink");
|
1257
|
-
return;
|
1258
|
-
}
|
1259
|
-
const newItem = {
|
1260
|
-
prev,
|
1261
|
-
current: message,
|
1262
|
-
next: null,
|
1263
|
-
children: [],
|
1264
|
-
level: prev ? prev.level + 1 : 0
|
1265
|
-
};
|
1266
|
-
this.messages.set(message.id, newItem);
|
1267
|
-
this.performOp(prev, newItem, "link");
|
1268
|
-
if (this.head === prev) {
|
1269
|
-
this.head = newItem;
|
1270
|
-
}
|
1271
|
-
}
|
1272
|
-
appendOptimisticMessage(parentId, message) {
|
1273
|
-
let optimisticId;
|
1274
|
-
do {
|
1275
|
-
optimisticId = generateOptimisticId();
|
1276
|
-
} while (this.messages.has(optimisticId));
|
1277
|
-
this.addOrUpdateMessage(parentId, {
|
1278
|
-
...message,
|
1279
|
-
id: optimisticId,
|
1280
|
-
createdAt: /* @__PURE__ */ new Date(),
|
1281
|
-
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1282
|
-
});
|
1283
|
-
return optimisticId;
|
1284
|
-
}
|
1285
|
-
deleteMessage(messageId, replacementId) {
|
1286
|
-
const message = this.messages.get(messageId);
|
1287
|
-
if (!message)
|
1288
|
-
throw new Error(
|
1289
|
-
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1290
|
-
);
|
1291
|
-
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1292
|
-
if (replacement === void 0)
|
1293
|
-
throw new Error(
|
1294
|
-
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1295
|
-
);
|
1296
|
-
for (const child of message.children) {
|
1297
|
-
const childMessage = this.messages.get(child);
|
1298
|
-
if (!childMessage)
|
1299
|
-
throw new Error(
|
1300
|
-
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1301
|
-
);
|
1302
|
-
this.performOp(replacement, childMessage, "relink");
|
1303
|
-
}
|
1304
|
-
this.performOp(null, message, "cut");
|
1305
|
-
this.messages.delete(messageId);
|
1306
|
-
if (this.head === message) {
|
1307
|
-
this.head = replacement ? findHead(replacement) : null;
|
1308
|
-
}
|
1309
|
-
}
|
1310
|
-
getBranches(messageId) {
|
1311
|
-
const message = this.messages.get(messageId);
|
1312
|
-
if (!message)
|
1313
|
-
throw new Error(
|
1314
|
-
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1315
|
-
);
|
1316
|
-
const { children } = message.prev ?? this.root;
|
1317
|
-
return children;
|
1318
|
-
}
|
1319
|
-
switchToBranch(messageId) {
|
1320
|
-
const message = this.messages.get(messageId);
|
1321
|
-
if (!message)
|
1322
|
-
throw new Error(
|
1323
|
-
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1324
|
-
);
|
1325
|
-
if (message.prev) {
|
1326
|
-
message.prev.next = message;
|
1327
|
-
}
|
1328
|
-
this.head = findHead(message);
|
1329
|
-
}
|
1330
|
-
resetHead(messageId) {
|
1331
|
-
if (messageId === null) {
|
1332
|
-
this.head = null;
|
1333
|
-
return;
|
1334
|
-
}
|
1335
|
-
const message = this.messages.get(messageId);
|
1336
|
-
if (!message)
|
1337
|
-
throw new Error(
|
1338
|
-
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1339
|
-
);
|
1340
|
-
this.head = message;
|
1341
|
-
for (let current = message; current; current = current.prev) {
|
1342
|
-
if (current.prev) {
|
1343
|
-
current.prev.next = current;
|
1344
|
-
}
|
1345
|
-
}
|
1346
|
-
}
|
1347
|
-
};
|
1348
|
-
|
1349
|
-
// src/runtime/vercel-ai/ui/getVercelAIMessage.tsx
|
1189
|
+
// ../react-ai-sdk/src/ui/getVercelAIMessage.tsx
|
1350
1190
|
var symbolInnerAIMessage = Symbol("innerVercelAIUIMessage");
|
1351
1191
|
var getVercelAIMessage = (message) => {
|
1352
1192
|
return message[symbolInnerAIMessage];
|
1353
1193
|
};
|
1354
1194
|
|
1355
|
-
//
|
1195
|
+
// ../react-ai-sdk/src/ui/utils/sliceMessagesUntil.tsx
|
1356
1196
|
var sliceMessagesUntil = (messages, messageId) => {
|
1357
1197
|
if (messageId == null) return [];
|
1358
1198
|
let messageIdx = messages.findIndex((m) => m.id === messageId);
|
@@ -1366,11 +1206,11 @@ var sliceMessagesUntil = (messages, messageId) => {
|
|
1366
1206
|
return messages.slice(0, messageIdx + 1);
|
1367
1207
|
};
|
1368
1208
|
|
1369
|
-
//
|
1370
|
-
var
|
1209
|
+
// ../react-ai-sdk/src/ui/utils/useVercelAIComposerSync.tsx
|
1210
|
+
var import_react32 = require("react");
|
1371
1211
|
var useVercelAIComposerSync = (vercel) => {
|
1372
1212
|
const { useComposer } = useThreadContext();
|
1373
|
-
(0,
|
1213
|
+
(0, import_react32.useEffect)(() => {
|
1374
1214
|
useComposer.setState({
|
1375
1215
|
value: vercel.input,
|
1376
1216
|
setValue: vercel.setInput
|
@@ -1378,8 +1218,8 @@ var useVercelAIComposerSync = (vercel) => {
|
|
1378
1218
|
}, [useComposer, vercel.input, vercel.setInput]);
|
1379
1219
|
};
|
1380
1220
|
|
1381
|
-
//
|
1382
|
-
var
|
1221
|
+
// ../react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx
|
1222
|
+
var import_react33 = require("react");
|
1383
1223
|
var getIsRunning = (vercel) => {
|
1384
1224
|
if ("isLoading" in vercel) return vercel.isLoading;
|
1385
1225
|
return vercel.status === "in_progress";
|
@@ -1456,8 +1296,8 @@ var shallowArrayEqual = (a, b) => {
|
|
1456
1296
|
};
|
1457
1297
|
var useVercelAIThreadSync = (vercel, updateData) => {
|
1458
1298
|
const isRunning = getIsRunning(vercel);
|
1459
|
-
const converter = (0,
|
1460
|
-
(0,
|
1299
|
+
const converter = (0, import_react33.useMemo)(() => new ThreadMessageConverter(), []);
|
1300
|
+
(0, import_react33.useEffect)(() => {
|
1461
1301
|
const lastMessageId = vercel.messages.at(-1)?.id;
|
1462
1302
|
const convertCallback = (messages2, cache) => {
|
1463
1303
|
const status = lastMessageId === messages2[0].id && isRunning ? "in_progress" : "done";
|
@@ -1474,7 +1314,7 @@ var useVercelAIThreadSync = (vercel, updateData) => {
|
|
1474
1314
|
}, [updateData, isRunning, vercel.messages, converter]);
|
1475
1315
|
};
|
1476
1316
|
|
1477
|
-
//
|
1317
|
+
// ../react-ai-sdk/src/ui/VercelAIRuntime.tsx
|
1478
1318
|
var hasUpcomingMessage = (isRunning, messages) => {
|
1479
1319
|
return isRunning && messages[messages.length - 1]?.role !== "assistant";
|
1480
1320
|
};
|
@@ -1586,36 +1426,196 @@ var VercelAIRuntime = class {
|
|
1586
1426
|
};
|
1587
1427
|
};
|
1588
1428
|
|
1589
|
-
//
|
1429
|
+
// ../react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx
|
1590
1430
|
var useVercelUseChatRuntime = (chatHelpers) => {
|
1591
|
-
const [runtime] = (0,
|
1592
|
-
(0,
|
1431
|
+
const [runtime] = (0, import_react35.useState)(() => new VercelAIRuntime(chatHelpers));
|
1432
|
+
(0, import_react35.useInsertionEffect)(() => {
|
1593
1433
|
runtime.vercel = chatHelpers;
|
1594
1434
|
});
|
1595
|
-
(0,
|
1435
|
+
(0, import_react35.useEffect)(() => {
|
1596
1436
|
runtime.onVercelUpdated();
|
1597
1437
|
});
|
1598
1438
|
return runtime;
|
1599
1439
|
};
|
1600
1440
|
|
1601
|
-
//
|
1602
|
-
var
|
1441
|
+
// ../react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx
|
1442
|
+
var import_react36 = require("react");
|
1603
1443
|
var useVercelUseAssistantRuntime = (assistantHelpers) => {
|
1604
|
-
const [runtime] = (0,
|
1605
|
-
(0,
|
1444
|
+
const [runtime] = (0, import_react36.useState)(() => new VercelAIRuntime(assistantHelpers));
|
1445
|
+
(0, import_react36.useInsertionEffect)(() => {
|
1606
1446
|
runtime.vercel = assistantHelpers;
|
1607
1447
|
});
|
1608
|
-
(0,
|
1448
|
+
(0, import_react36.useEffect)(() => {
|
1609
1449
|
runtime.onVercelUpdated();
|
1610
1450
|
});
|
1611
1451
|
return runtime;
|
1612
1452
|
};
|
1613
1453
|
|
1454
|
+
// src/runtime/utils/idUtils.tsx
|
1455
|
+
var import_non_secure = require("nanoid/non-secure");
|
1456
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
1457
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
1458
|
+
7
|
1459
|
+
);
|
1460
|
+
var optimisticPrefix = "__optimistic__";
|
1461
|
+
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1462
|
+
|
1463
|
+
// src/runtime/utils/MessageRepository.tsx
|
1464
|
+
var findHead = (message) => {
|
1465
|
+
if (message.next) return findHead(message.next);
|
1466
|
+
return message;
|
1467
|
+
};
|
1468
|
+
var MessageRepository = class {
|
1469
|
+
messages = /* @__PURE__ */ new Map();
|
1470
|
+
// message_id -> item
|
1471
|
+
head = null;
|
1472
|
+
root = {
|
1473
|
+
children: []
|
1474
|
+
};
|
1475
|
+
performOp(newParent, child, operation) {
|
1476
|
+
const parentOrRoot = child.prev ?? this.root;
|
1477
|
+
const newParentOrRoot = newParent ?? this.root;
|
1478
|
+
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1479
|
+
if (operation !== "link") {
|
1480
|
+
parentOrRoot.children = parentOrRoot.children.filter(
|
1481
|
+
(m) => m !== child.current.id
|
1482
|
+
);
|
1483
|
+
if (child.prev?.next === child) {
|
1484
|
+
const fallbackId = child.prev.children.at(-1);
|
1485
|
+
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1486
|
+
if (fallback === void 0) {
|
1487
|
+
throw new Error(
|
1488
|
+
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1489
|
+
);
|
1490
|
+
}
|
1491
|
+
child.prev.next = fallback;
|
1492
|
+
}
|
1493
|
+
}
|
1494
|
+
if (operation !== "cut") {
|
1495
|
+
newParentOrRoot.children = [
|
1496
|
+
...newParentOrRoot.children,
|
1497
|
+
child.current.id
|
1498
|
+
];
|
1499
|
+
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1500
|
+
newParent.next = child;
|
1501
|
+
}
|
1502
|
+
child.prev = newParent;
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
getMessages() {
|
1506
|
+
const messages = new Array(this.head?.level ?? 0);
|
1507
|
+
for (let current = this.head; current; current = current.prev) {
|
1508
|
+
messages[current.level] = current.current;
|
1509
|
+
}
|
1510
|
+
return messages;
|
1511
|
+
}
|
1512
|
+
addOrUpdateMessage(parentId, message) {
|
1513
|
+
const existingItem = this.messages.get(message.id);
|
1514
|
+
const prev = parentId ? this.messages.get(parentId) : null;
|
1515
|
+
if (prev === void 0)
|
1516
|
+
throw new Error(
|
1517
|
+
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1518
|
+
);
|
1519
|
+
if (existingItem) {
|
1520
|
+
existingItem.current = message;
|
1521
|
+
this.performOp(prev, existingItem, "relink");
|
1522
|
+
return;
|
1523
|
+
}
|
1524
|
+
const newItem = {
|
1525
|
+
prev,
|
1526
|
+
current: message,
|
1527
|
+
next: null,
|
1528
|
+
children: [],
|
1529
|
+
level: prev ? prev.level + 1 : 0
|
1530
|
+
};
|
1531
|
+
this.messages.set(message.id, newItem);
|
1532
|
+
this.performOp(prev, newItem, "link");
|
1533
|
+
if (this.head === prev) {
|
1534
|
+
this.head = newItem;
|
1535
|
+
}
|
1536
|
+
}
|
1537
|
+
appendOptimisticMessage(parentId, message) {
|
1538
|
+
let optimisticId;
|
1539
|
+
do {
|
1540
|
+
optimisticId = generateOptimisticId();
|
1541
|
+
} while (this.messages.has(optimisticId));
|
1542
|
+
this.addOrUpdateMessage(parentId, {
|
1543
|
+
...message,
|
1544
|
+
id: optimisticId,
|
1545
|
+
createdAt: /* @__PURE__ */ new Date(),
|
1546
|
+
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1547
|
+
});
|
1548
|
+
return optimisticId;
|
1549
|
+
}
|
1550
|
+
deleteMessage(messageId, replacementId) {
|
1551
|
+
const message = this.messages.get(messageId);
|
1552
|
+
if (!message)
|
1553
|
+
throw new Error(
|
1554
|
+
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1555
|
+
);
|
1556
|
+
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1557
|
+
if (replacement === void 0)
|
1558
|
+
throw new Error(
|
1559
|
+
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1560
|
+
);
|
1561
|
+
for (const child of message.children) {
|
1562
|
+
const childMessage = this.messages.get(child);
|
1563
|
+
if (!childMessage)
|
1564
|
+
throw new Error(
|
1565
|
+
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1566
|
+
);
|
1567
|
+
this.performOp(replacement, childMessage, "relink");
|
1568
|
+
}
|
1569
|
+
this.performOp(null, message, "cut");
|
1570
|
+
this.messages.delete(messageId);
|
1571
|
+
if (this.head === message) {
|
1572
|
+
this.head = replacement ? findHead(replacement) : null;
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
getBranches(messageId) {
|
1576
|
+
const message = this.messages.get(messageId);
|
1577
|
+
if (!message)
|
1578
|
+
throw new Error(
|
1579
|
+
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1580
|
+
);
|
1581
|
+
const { children } = message.prev ?? this.root;
|
1582
|
+
return children;
|
1583
|
+
}
|
1584
|
+
switchToBranch(messageId) {
|
1585
|
+
const message = this.messages.get(messageId);
|
1586
|
+
if (!message)
|
1587
|
+
throw new Error(
|
1588
|
+
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1589
|
+
);
|
1590
|
+
if (message.prev) {
|
1591
|
+
message.prev.next = message;
|
1592
|
+
}
|
1593
|
+
this.head = findHead(message);
|
1594
|
+
}
|
1595
|
+
resetHead(messageId) {
|
1596
|
+
if (messageId === null) {
|
1597
|
+
this.head = null;
|
1598
|
+
return;
|
1599
|
+
}
|
1600
|
+
const message = this.messages.get(messageId);
|
1601
|
+
if (!message)
|
1602
|
+
throw new Error(
|
1603
|
+
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1604
|
+
);
|
1605
|
+
this.head = message;
|
1606
|
+
for (let current = message; current; current = current.prev) {
|
1607
|
+
if (current.prev) {
|
1608
|
+
current.prev.next = current;
|
1609
|
+
}
|
1610
|
+
}
|
1611
|
+
}
|
1612
|
+
};
|
1613
|
+
|
1614
1614
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
1615
|
-
var
|
1615
|
+
var import_react38 = require("react");
|
1616
1616
|
|
1617
1617
|
// src/context/providers/ThreadProvider.tsx
|
1618
|
-
var
|
1618
|
+
var import_react37 = require("react");
|
1619
1619
|
|
1620
1620
|
// src/context/stores/Composer.ts
|
1621
1621
|
var import_zustand6 = require("zustand");
|
@@ -1690,11 +1690,11 @@ var ThreadProvider = ({
|
|
1690
1690
|
children,
|
1691
1691
|
runtime
|
1692
1692
|
}) => {
|
1693
|
-
const runtimeRef = (0,
|
1694
|
-
(0,
|
1693
|
+
const runtimeRef = (0, import_react37.useRef)(runtime);
|
1694
|
+
(0, import_react37.useInsertionEffect)(() => {
|
1695
1695
|
runtimeRef.current = runtime;
|
1696
1696
|
});
|
1697
|
-
const [{ context, onRuntimeUpdate }] = (0,
|
1697
|
+
const [{ context, onRuntimeUpdate }] = (0, import_react37.useState)(() => {
|
1698
1698
|
const { useThread, onRuntimeUpdate: onRuntimeUpdate2 } = makeThreadStore(runtimeRef);
|
1699
1699
|
const useViewport = makeThreadViewportStore();
|
1700
1700
|
const useComposer = makeComposerStore(useThread);
|
@@ -1707,7 +1707,7 @@ var ThreadProvider = ({
|
|
1707
1707
|
onRuntimeUpdate: onRuntimeUpdate2
|
1708
1708
|
};
|
1709
1709
|
});
|
1710
|
-
(0,
|
1710
|
+
(0, import_react37.useEffect)(() => {
|
1711
1711
|
onRuntimeUpdate();
|
1712
1712
|
return runtime.subscribe(onRuntimeUpdate);
|
1713
1713
|
}, [onRuntimeUpdate, runtime]);
|
@@ -1723,7 +1723,7 @@ var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
1723
1723
|
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
1724
1724
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ThreadProvider, { runtime, children });
|
1725
1725
|
};
|
1726
|
-
var AssistantRuntimeProvider = (0,
|
1726
|
+
var AssistantRuntimeProvider = (0, import_react38.memo)(AssistantRuntimeProviderImpl);
|
1727
1727
|
|
1728
1728
|
// src/runtime/vercel-deprecated/VercelAIAssistantProvider.tsx
|
1729
1729
|
var import_jsx_runtime23 = require("react/jsx-runtime");
|
@@ -1762,7 +1762,7 @@ var VercelRSCAssistantProvider = ({
|
|
1762
1762
|
};
|
1763
1763
|
|
1764
1764
|
// src/runtime/local/useLocalRuntime.tsx
|
1765
|
-
var
|
1765
|
+
var import_react39 = require("react");
|
1766
1766
|
|
1767
1767
|
// src/runtime/local/LocalRuntime.tsx
|
1768
1768
|
var LocalRuntime = class {
|
@@ -1851,54 +1851,12 @@ var LocalRuntime = class {
|
|
1851
1851
|
|
1852
1852
|
// src/runtime/local/useLocalRuntime.tsx
|
1853
1853
|
var useLocalRuntime = (adapter) => {
|
1854
|
-
const [runtime] = (0,
|
1855
|
-
(0,
|
1854
|
+
const [runtime] = (0, import_react39.useState)(() => new LocalRuntime(adapter));
|
1855
|
+
(0, import_react39.useInsertionEffect)(() => {
|
1856
1856
|
runtime.adapter = adapter;
|
1857
1857
|
});
|
1858
1858
|
return runtime;
|
1859
1859
|
};
|
1860
|
-
|
1861
|
-
// src/runtime/local/vercel/VercelModelAdapter.tsx
|
1862
|
-
var import_ai = require("ai");
|
1863
|
-
var VercelModelAdapter = class {
|
1864
|
-
constructor(model) {
|
1865
|
-
this.model = model;
|
1866
|
-
}
|
1867
|
-
async run({ messages, abortSignal, onUpdate }) {
|
1868
|
-
const { fullStream } = await (0, import_ai.streamText)({
|
1869
|
-
model: this.model,
|
1870
|
-
abortSignal,
|
1871
|
-
messages: messages.map((m) => ({
|
1872
|
-
role: m.role,
|
1873
|
-
content: m.content.filter((c) => c.type !== "ui")
|
1874
|
-
}))
|
1875
|
-
});
|
1876
|
-
const content = [];
|
1877
|
-
for await (const aiPart of fullStream) {
|
1878
|
-
switch (aiPart.type) {
|
1879
|
-
case "text-delta": {
|
1880
|
-
let part = content.at(-1);
|
1881
|
-
if (!part || part.type !== "text") {
|
1882
|
-
part = { type: "text", text: "" };
|
1883
|
-
content.push(part);
|
1884
|
-
}
|
1885
|
-
part.text += aiPart.textDelta;
|
1886
|
-
break;
|
1887
|
-
}
|
1888
|
-
case "tool-call": {
|
1889
|
-
content.push({
|
1890
|
-
type: "tool-call",
|
1891
|
-
name: aiPart.toolName,
|
1892
|
-
args: aiPart.args
|
1893
|
-
});
|
1894
|
-
break;
|
1895
|
-
}
|
1896
|
-
}
|
1897
|
-
onUpdate({ content });
|
1898
|
-
}
|
1899
|
-
return { content };
|
1900
|
-
}
|
1901
|
-
};
|
1902
1860
|
// Annotate the CommonJS export names for ESM import in node:
|
1903
1861
|
0 && (module.exports = {
|
1904
1862
|
ActionBarPrimitive,
|
@@ -1912,7 +1870,7 @@ var VercelModelAdapter = class {
|
|
1912
1870
|
VercelRSCAssistantProvider,
|
1913
1871
|
getVercelAIMessage,
|
1914
1872
|
getVercelRSCMessage,
|
1915
|
-
|
1873
|
+
unstable_MessageRepository,
|
1916
1874
|
unstable_useComposerContext,
|
1917
1875
|
unstable_useContentPartContext,
|
1918
1876
|
unstable_useLocalRuntime,
|