@assistant-ui/react 0.0.25 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -3
- package/dist/index.d.mts +97 -90
- package/dist/index.d.ts +97 -90
- package/dist/index.js +210 -250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -226
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -9
package/dist/index.mjs
CHANGED
@@ -1016,16 +1016,16 @@ __export(contentPart_exports, {
|
|
1016
1016
|
InProgressIndicator: () => ContentPartInProgressIndicator
|
1017
1017
|
});
|
1018
1018
|
|
1019
|
-
//
|
1019
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx
|
1020
1020
|
import { useEffect as useEffect7, useInsertionEffect, useState as useState3 } from "react";
|
1021
1021
|
|
1022
|
-
//
|
1022
|
+
// ../react-ai-sdk/src/rsc/VercelRSCRuntime.tsx
|
1023
1023
|
import { create as create4 } from "zustand";
|
1024
1024
|
|
1025
|
-
//
|
1025
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCSync.tsx
|
1026
1026
|
import { useEffect as useEffect6, useMemo as useMemo4 } from "react";
|
1027
1027
|
|
1028
|
-
//
|
1028
|
+
// ../react-ai-sdk/src/utils/ThreadMessageConverter.ts
|
1029
1029
|
var ThreadMessageConverter = class {
|
1030
1030
|
cache = /* @__PURE__ */ new WeakMap();
|
1031
1031
|
convertMessages(messages, converter, keyMapper = (key) => key) {
|
@@ -1039,13 +1039,13 @@ var ThreadMessageConverter = class {
|
|
1039
1039
|
}
|
1040
1040
|
};
|
1041
1041
|
|
1042
|
-
//
|
1042
|
+
// ../react-ai-sdk/src/rsc/getVercelRSCMessage.tsx
|
1043
1043
|
var symbolInnerRSCMessage = Symbol("innerVercelRSCMessage");
|
1044
1044
|
var getVercelRSCMessage = (message) => {
|
1045
1045
|
return message[symbolInnerRSCMessage];
|
1046
1046
|
};
|
1047
1047
|
|
1048
|
-
//
|
1048
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCSync.tsx
|
1049
1049
|
var vercelToThreadMessage = (converter, rawMessage) => {
|
1050
1050
|
const message = converter(rawMessage);
|
1051
1051
|
return {
|
@@ -1071,7 +1071,7 @@ var useVercelRSCSync = (adapter, updateData) => {
|
|
1071
1071
|
}, [updateData, converter, convertCallback, adapter.messages]);
|
1072
1072
|
};
|
1073
1073
|
|
1074
|
-
//
|
1074
|
+
// ../react-ai-sdk/src/rsc/VercelRSCRuntime.tsx
|
1075
1075
|
var EMPTY_BRANCHES = Object.freeze([]);
|
1076
1076
|
var VercelRSCRuntime = class {
|
1077
1077
|
constructor(adapter) {
|
@@ -1143,7 +1143,7 @@ var VercelRSCRuntime = class {
|
|
1143
1143
|
};
|
1144
1144
|
};
|
1145
1145
|
|
1146
|
-
//
|
1146
|
+
// ../react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx
|
1147
1147
|
var useVercelRSCRuntime = (adapter) => {
|
1148
1148
|
const [runtime] = useState3(() => new VercelRSCRuntime(adapter));
|
1149
1149
|
useInsertionEffect(() => {
|
@@ -1155,179 +1155,19 @@ var useVercelRSCRuntime = (adapter) => {
|
|
1155
1155
|
return runtime;
|
1156
1156
|
};
|
1157
1157
|
|
1158
|
-
//
|
1158
|
+
// ../react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx
|
1159
1159
|
import { useEffect as useEffect10, useInsertionEffect as useInsertionEffect2, useState as useState4 } from "react";
|
1160
1160
|
|
1161
|
-
//
|
1161
|
+
// ../react-ai-sdk/src/ui/VercelAIRuntime.tsx
|
1162
1162
|
import { create as create5 } from "zustand";
|
1163
1163
|
|
1164
|
-
// src/
|
1165
|
-
import { customAlphabet } from "nanoid/non-secure";
|
1166
|
-
var generateId = customAlphabet(
|
1167
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
1168
|
-
7
|
1169
|
-
);
|
1170
|
-
var optimisticPrefix = "__optimistic__";
|
1171
|
-
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1172
|
-
|
1173
|
-
// src/runtime/utils/MessageRepository.tsx
|
1174
|
-
var findHead = (message) => {
|
1175
|
-
if (message.next) return findHead(message.next);
|
1176
|
-
return message;
|
1177
|
-
};
|
1178
|
-
var MessageRepository = class {
|
1179
|
-
messages = /* @__PURE__ */ new Map();
|
1180
|
-
// message_id -> item
|
1181
|
-
head = null;
|
1182
|
-
root = {
|
1183
|
-
children: []
|
1184
|
-
};
|
1185
|
-
performOp(newParent, child, operation) {
|
1186
|
-
const parentOrRoot = child.prev ?? this.root;
|
1187
|
-
const newParentOrRoot = newParent ?? this.root;
|
1188
|
-
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1189
|
-
if (operation !== "link") {
|
1190
|
-
parentOrRoot.children = parentOrRoot.children.filter(
|
1191
|
-
(m) => m !== child.current.id
|
1192
|
-
);
|
1193
|
-
if (child.prev?.next === child) {
|
1194
|
-
const fallbackId = child.prev.children.at(-1);
|
1195
|
-
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1196
|
-
if (fallback === void 0) {
|
1197
|
-
throw new Error(
|
1198
|
-
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1199
|
-
);
|
1200
|
-
}
|
1201
|
-
child.prev.next = fallback;
|
1202
|
-
}
|
1203
|
-
}
|
1204
|
-
if (operation !== "cut") {
|
1205
|
-
newParentOrRoot.children = [
|
1206
|
-
...newParentOrRoot.children,
|
1207
|
-
child.current.id
|
1208
|
-
];
|
1209
|
-
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1210
|
-
newParent.next = child;
|
1211
|
-
}
|
1212
|
-
child.prev = newParent;
|
1213
|
-
}
|
1214
|
-
}
|
1215
|
-
getMessages() {
|
1216
|
-
const messages = new Array(this.head?.level ?? 0);
|
1217
|
-
for (let current = this.head; current; current = current.prev) {
|
1218
|
-
messages[current.level] = current.current;
|
1219
|
-
}
|
1220
|
-
return messages;
|
1221
|
-
}
|
1222
|
-
addOrUpdateMessage(parentId, message) {
|
1223
|
-
const existingItem = this.messages.get(message.id);
|
1224
|
-
const prev = parentId ? this.messages.get(parentId) : null;
|
1225
|
-
if (prev === void 0)
|
1226
|
-
throw new Error(
|
1227
|
-
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1228
|
-
);
|
1229
|
-
if (existingItem) {
|
1230
|
-
existingItem.current = message;
|
1231
|
-
this.performOp(prev, existingItem, "relink");
|
1232
|
-
return;
|
1233
|
-
}
|
1234
|
-
const newItem = {
|
1235
|
-
prev,
|
1236
|
-
current: message,
|
1237
|
-
next: null,
|
1238
|
-
children: [],
|
1239
|
-
level: prev ? prev.level + 1 : 0
|
1240
|
-
};
|
1241
|
-
this.messages.set(message.id, newItem);
|
1242
|
-
this.performOp(prev, newItem, "link");
|
1243
|
-
if (this.head === prev) {
|
1244
|
-
this.head = newItem;
|
1245
|
-
}
|
1246
|
-
}
|
1247
|
-
appendOptimisticMessage(parentId, message) {
|
1248
|
-
let optimisticId;
|
1249
|
-
do {
|
1250
|
-
optimisticId = generateOptimisticId();
|
1251
|
-
} while (this.messages.has(optimisticId));
|
1252
|
-
this.addOrUpdateMessage(parentId, {
|
1253
|
-
...message,
|
1254
|
-
id: optimisticId,
|
1255
|
-
createdAt: /* @__PURE__ */ new Date(),
|
1256
|
-
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1257
|
-
});
|
1258
|
-
return optimisticId;
|
1259
|
-
}
|
1260
|
-
deleteMessage(messageId, replacementId) {
|
1261
|
-
const message = this.messages.get(messageId);
|
1262
|
-
if (!message)
|
1263
|
-
throw new Error(
|
1264
|
-
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1265
|
-
);
|
1266
|
-
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1267
|
-
if (replacement === void 0)
|
1268
|
-
throw new Error(
|
1269
|
-
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1270
|
-
);
|
1271
|
-
for (const child of message.children) {
|
1272
|
-
const childMessage = this.messages.get(child);
|
1273
|
-
if (!childMessage)
|
1274
|
-
throw new Error(
|
1275
|
-
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1276
|
-
);
|
1277
|
-
this.performOp(replacement, childMessage, "relink");
|
1278
|
-
}
|
1279
|
-
this.performOp(null, message, "cut");
|
1280
|
-
this.messages.delete(messageId);
|
1281
|
-
if (this.head === message) {
|
1282
|
-
this.head = replacement ? findHead(replacement) : null;
|
1283
|
-
}
|
1284
|
-
}
|
1285
|
-
getBranches(messageId) {
|
1286
|
-
const message = this.messages.get(messageId);
|
1287
|
-
if (!message)
|
1288
|
-
throw new Error(
|
1289
|
-
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1290
|
-
);
|
1291
|
-
const { children } = message.prev ?? this.root;
|
1292
|
-
return children;
|
1293
|
-
}
|
1294
|
-
switchToBranch(messageId) {
|
1295
|
-
const message = this.messages.get(messageId);
|
1296
|
-
if (!message)
|
1297
|
-
throw new Error(
|
1298
|
-
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1299
|
-
);
|
1300
|
-
if (message.prev) {
|
1301
|
-
message.prev.next = message;
|
1302
|
-
}
|
1303
|
-
this.head = findHead(message);
|
1304
|
-
}
|
1305
|
-
resetHead(messageId) {
|
1306
|
-
if (messageId === null) {
|
1307
|
-
this.head = null;
|
1308
|
-
return;
|
1309
|
-
}
|
1310
|
-
const message = this.messages.get(messageId);
|
1311
|
-
if (!message)
|
1312
|
-
throw new Error(
|
1313
|
-
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1314
|
-
);
|
1315
|
-
this.head = message;
|
1316
|
-
for (let current = message; current; current = current.prev) {
|
1317
|
-
if (current.prev) {
|
1318
|
-
current.prev.next = current;
|
1319
|
-
}
|
1320
|
-
}
|
1321
|
-
}
|
1322
|
-
};
|
1323
|
-
|
1324
|
-
// src/runtime/vercel-ai/ui/getVercelAIMessage.tsx
|
1164
|
+
// ../react-ai-sdk/src/ui/getVercelAIMessage.tsx
|
1325
1165
|
var symbolInnerAIMessage = Symbol("innerVercelAIUIMessage");
|
1326
1166
|
var getVercelAIMessage = (message) => {
|
1327
1167
|
return message[symbolInnerAIMessage];
|
1328
1168
|
};
|
1329
1169
|
|
1330
|
-
//
|
1170
|
+
// ../react-ai-sdk/src/ui/utils/sliceMessagesUntil.tsx
|
1331
1171
|
var sliceMessagesUntil = (messages, messageId) => {
|
1332
1172
|
if (messageId == null) return [];
|
1333
1173
|
let messageIdx = messages.findIndex((m) => m.id === messageId);
|
@@ -1341,7 +1181,7 @@ var sliceMessagesUntil = (messages, messageId) => {
|
|
1341
1181
|
return messages.slice(0, messageIdx + 1);
|
1342
1182
|
};
|
1343
1183
|
|
1344
|
-
//
|
1184
|
+
// ../react-ai-sdk/src/ui/utils/useVercelAIComposerSync.tsx
|
1345
1185
|
import { useEffect as useEffect8 } from "react";
|
1346
1186
|
var useVercelAIComposerSync = (vercel) => {
|
1347
1187
|
const { useComposer } = useThreadContext();
|
@@ -1353,7 +1193,7 @@ var useVercelAIComposerSync = (vercel) => {
|
|
1353
1193
|
}, [useComposer, vercel.input, vercel.setInput]);
|
1354
1194
|
};
|
1355
1195
|
|
1356
|
-
//
|
1196
|
+
// ../react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx
|
1357
1197
|
import { useEffect as useEffect9, useMemo as useMemo5 } from "react";
|
1358
1198
|
var getIsRunning = (vercel) => {
|
1359
1199
|
if ("isLoading" in vercel) return vercel.isLoading;
|
@@ -1449,7 +1289,7 @@ var useVercelAIThreadSync = (vercel, updateData) => {
|
|
1449
1289
|
}, [updateData, isRunning, vercel.messages, converter]);
|
1450
1290
|
};
|
1451
1291
|
|
1452
|
-
//
|
1292
|
+
// ../react-ai-sdk/src/ui/VercelAIRuntime.tsx
|
1453
1293
|
var hasUpcomingMessage = (isRunning, messages) => {
|
1454
1294
|
return isRunning && messages[messages.length - 1]?.role !== "assistant";
|
1455
1295
|
};
|
@@ -1561,7 +1401,7 @@ var VercelAIRuntime = class {
|
|
1561
1401
|
};
|
1562
1402
|
};
|
1563
1403
|
|
1564
|
-
//
|
1404
|
+
// ../react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx
|
1565
1405
|
var useVercelUseChatRuntime = (chatHelpers) => {
|
1566
1406
|
const [runtime] = useState4(() => new VercelAIRuntime(chatHelpers));
|
1567
1407
|
useInsertionEffect2(() => {
|
@@ -1573,7 +1413,7 @@ var useVercelUseChatRuntime = (chatHelpers) => {
|
|
1573
1413
|
return runtime;
|
1574
1414
|
};
|
1575
1415
|
|
1576
|
-
//
|
1416
|
+
// ../react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx
|
1577
1417
|
import { useEffect as useEffect11, useInsertionEffect as useInsertionEffect3, useState as useState5 } from "react";
|
1578
1418
|
var useVercelUseAssistantRuntime = (assistantHelpers) => {
|
1579
1419
|
const [runtime] = useState5(() => new VercelAIRuntime(assistantHelpers));
|
@@ -1586,6 +1426,166 @@ var useVercelUseAssistantRuntime = (assistantHelpers) => {
|
|
1586
1426
|
return runtime;
|
1587
1427
|
};
|
1588
1428
|
|
1429
|
+
// src/runtime/utils/idUtils.tsx
|
1430
|
+
import { customAlphabet } from "nanoid/non-secure";
|
1431
|
+
var generateId = customAlphabet(
|
1432
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
1433
|
+
7
|
1434
|
+
);
|
1435
|
+
var optimisticPrefix = "__optimistic__";
|
1436
|
+
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1437
|
+
|
1438
|
+
// src/runtime/utils/MessageRepository.tsx
|
1439
|
+
var findHead = (message) => {
|
1440
|
+
if (message.next) return findHead(message.next);
|
1441
|
+
return message;
|
1442
|
+
};
|
1443
|
+
var MessageRepository = class {
|
1444
|
+
messages = /* @__PURE__ */ new Map();
|
1445
|
+
// message_id -> item
|
1446
|
+
head = null;
|
1447
|
+
root = {
|
1448
|
+
children: []
|
1449
|
+
};
|
1450
|
+
performOp(newParent, child, operation) {
|
1451
|
+
const parentOrRoot = child.prev ?? this.root;
|
1452
|
+
const newParentOrRoot = newParent ?? this.root;
|
1453
|
+
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1454
|
+
if (operation !== "link") {
|
1455
|
+
parentOrRoot.children = parentOrRoot.children.filter(
|
1456
|
+
(m) => m !== child.current.id
|
1457
|
+
);
|
1458
|
+
if (child.prev?.next === child) {
|
1459
|
+
const fallbackId = child.prev.children.at(-1);
|
1460
|
+
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1461
|
+
if (fallback === void 0) {
|
1462
|
+
throw new Error(
|
1463
|
+
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1464
|
+
);
|
1465
|
+
}
|
1466
|
+
child.prev.next = fallback;
|
1467
|
+
}
|
1468
|
+
}
|
1469
|
+
if (operation !== "cut") {
|
1470
|
+
newParentOrRoot.children = [
|
1471
|
+
...newParentOrRoot.children,
|
1472
|
+
child.current.id
|
1473
|
+
];
|
1474
|
+
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1475
|
+
newParent.next = child;
|
1476
|
+
}
|
1477
|
+
child.prev = newParent;
|
1478
|
+
}
|
1479
|
+
}
|
1480
|
+
getMessages() {
|
1481
|
+
const messages = new Array(this.head?.level ?? 0);
|
1482
|
+
for (let current = this.head; current; current = current.prev) {
|
1483
|
+
messages[current.level] = current.current;
|
1484
|
+
}
|
1485
|
+
return messages;
|
1486
|
+
}
|
1487
|
+
addOrUpdateMessage(parentId, message) {
|
1488
|
+
const existingItem = this.messages.get(message.id);
|
1489
|
+
const prev = parentId ? this.messages.get(parentId) : null;
|
1490
|
+
if (prev === void 0)
|
1491
|
+
throw new Error(
|
1492
|
+
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1493
|
+
);
|
1494
|
+
if (existingItem) {
|
1495
|
+
existingItem.current = message;
|
1496
|
+
this.performOp(prev, existingItem, "relink");
|
1497
|
+
return;
|
1498
|
+
}
|
1499
|
+
const newItem = {
|
1500
|
+
prev,
|
1501
|
+
current: message,
|
1502
|
+
next: null,
|
1503
|
+
children: [],
|
1504
|
+
level: prev ? prev.level + 1 : 0
|
1505
|
+
};
|
1506
|
+
this.messages.set(message.id, newItem);
|
1507
|
+
this.performOp(prev, newItem, "link");
|
1508
|
+
if (this.head === prev) {
|
1509
|
+
this.head = newItem;
|
1510
|
+
}
|
1511
|
+
}
|
1512
|
+
appendOptimisticMessage(parentId, message) {
|
1513
|
+
let optimisticId;
|
1514
|
+
do {
|
1515
|
+
optimisticId = generateOptimisticId();
|
1516
|
+
} while (this.messages.has(optimisticId));
|
1517
|
+
this.addOrUpdateMessage(parentId, {
|
1518
|
+
...message,
|
1519
|
+
id: optimisticId,
|
1520
|
+
createdAt: /* @__PURE__ */ new Date(),
|
1521
|
+
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1522
|
+
});
|
1523
|
+
return optimisticId;
|
1524
|
+
}
|
1525
|
+
deleteMessage(messageId, replacementId) {
|
1526
|
+
const message = this.messages.get(messageId);
|
1527
|
+
if (!message)
|
1528
|
+
throw new Error(
|
1529
|
+
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1530
|
+
);
|
1531
|
+
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1532
|
+
if (replacement === void 0)
|
1533
|
+
throw new Error(
|
1534
|
+
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1535
|
+
);
|
1536
|
+
for (const child of message.children) {
|
1537
|
+
const childMessage = this.messages.get(child);
|
1538
|
+
if (!childMessage)
|
1539
|
+
throw new Error(
|
1540
|
+
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1541
|
+
);
|
1542
|
+
this.performOp(replacement, childMessage, "relink");
|
1543
|
+
}
|
1544
|
+
this.performOp(null, message, "cut");
|
1545
|
+
this.messages.delete(messageId);
|
1546
|
+
if (this.head === message) {
|
1547
|
+
this.head = replacement ? findHead(replacement) : null;
|
1548
|
+
}
|
1549
|
+
}
|
1550
|
+
getBranches(messageId) {
|
1551
|
+
const message = this.messages.get(messageId);
|
1552
|
+
if (!message)
|
1553
|
+
throw new Error(
|
1554
|
+
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1555
|
+
);
|
1556
|
+
const { children } = message.prev ?? this.root;
|
1557
|
+
return children;
|
1558
|
+
}
|
1559
|
+
switchToBranch(messageId) {
|
1560
|
+
const message = this.messages.get(messageId);
|
1561
|
+
if (!message)
|
1562
|
+
throw new Error(
|
1563
|
+
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1564
|
+
);
|
1565
|
+
if (message.prev) {
|
1566
|
+
message.prev.next = message;
|
1567
|
+
}
|
1568
|
+
this.head = findHead(message);
|
1569
|
+
}
|
1570
|
+
resetHead(messageId) {
|
1571
|
+
if (messageId === null) {
|
1572
|
+
this.head = null;
|
1573
|
+
return;
|
1574
|
+
}
|
1575
|
+
const message = this.messages.get(messageId);
|
1576
|
+
if (!message)
|
1577
|
+
throw new Error(
|
1578
|
+
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1579
|
+
);
|
1580
|
+
this.head = message;
|
1581
|
+
for (let current = message; current; current = current.prev) {
|
1582
|
+
if (current.prev) {
|
1583
|
+
current.prev.next = current;
|
1584
|
+
}
|
1585
|
+
}
|
1586
|
+
}
|
1587
|
+
};
|
1588
|
+
|
1589
1589
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
1590
1590
|
import { memo } from "react";
|
1591
1591
|
|
@@ -1787,15 +1787,17 @@ var LocalRuntime = class {
|
|
1787
1787
|
this.abortController = new AbortController();
|
1788
1788
|
this.notifySubscribers();
|
1789
1789
|
try {
|
1790
|
-
|
1790
|
+
const updateHandler = ({ content }) => {
|
1791
|
+
message.content = content;
|
1792
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1793
|
+
this.notifySubscribers();
|
1794
|
+
};
|
1795
|
+
const result = await this.adapter.run({
|
1791
1796
|
messages,
|
1792
1797
|
abortSignal: this.abortController.signal,
|
1793
|
-
onUpdate:
|
1794
|
-
message.content = content;
|
1795
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1796
|
-
this.notifySubscribers();
|
1797
|
-
}
|
1798
|
+
onUpdate: updateHandler
|
1798
1799
|
});
|
1800
|
+
updateHandler(result);
|
1799
1801
|
message.status = "done";
|
1800
1802
|
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1801
1803
|
} catch (e) {
|
@@ -1830,48 +1832,6 @@ var useLocalRuntime = (adapter) => {
|
|
1830
1832
|
});
|
1831
1833
|
return runtime;
|
1832
1834
|
};
|
1833
|
-
|
1834
|
-
// src/runtime/local/vercel/VercelModelAdapter.tsx
|
1835
|
-
import { streamText } from "ai";
|
1836
|
-
var VercelModelAdapter = class {
|
1837
|
-
constructor(model) {
|
1838
|
-
this.model = model;
|
1839
|
-
}
|
1840
|
-
async run({ messages, abortSignal, onUpdate }) {
|
1841
|
-
const { fullStream } = await streamText({
|
1842
|
-
model: this.model,
|
1843
|
-
abortSignal,
|
1844
|
-
messages: messages.map((m) => ({
|
1845
|
-
role: m.role,
|
1846
|
-
content: m.content.filter((c) => c.type !== "ui")
|
1847
|
-
}))
|
1848
|
-
});
|
1849
|
-
const content = [];
|
1850
|
-
for await (const aiPart of fullStream) {
|
1851
|
-
switch (aiPart.type) {
|
1852
|
-
case "text-delta": {
|
1853
|
-
let part = content.at(-1);
|
1854
|
-
if (!part || part.type !== "text") {
|
1855
|
-
part = { type: "text", text: "" };
|
1856
|
-
content.push(part);
|
1857
|
-
}
|
1858
|
-
part.text += aiPart.textDelta;
|
1859
|
-
break;
|
1860
|
-
}
|
1861
|
-
case "tool-call": {
|
1862
|
-
content.push({
|
1863
|
-
type: "tool-call",
|
1864
|
-
name: aiPart.toolName,
|
1865
|
-
args: aiPart.args
|
1866
|
-
});
|
1867
|
-
break;
|
1868
|
-
}
|
1869
|
-
}
|
1870
|
-
onUpdate({ content });
|
1871
|
-
}
|
1872
|
-
return { content };
|
1873
|
-
}
|
1874
|
-
};
|
1875
1835
|
export {
|
1876
1836
|
actionBar_exports as ActionBarPrimitive,
|
1877
1837
|
AssistantRuntimeProvider,
|
@@ -1884,7 +1844,7 @@ export {
|
|
1884
1844
|
VercelRSCAssistantProvider,
|
1885
1845
|
getVercelAIMessage,
|
1886
1846
|
getVercelRSCMessage,
|
1887
|
-
|
1847
|
+
MessageRepository as unstable_MessageRepository,
|
1888
1848
|
useComposerContext as unstable_useComposerContext,
|
1889
1849
|
useContentPartContext as unstable_useContentPartContext,
|
1890
1850
|
useLocalRuntime as unstable_useLocalRuntime,
|