@assistant-ui/react 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{ModelConfigTypes-CzmXY3sn.d.mts → Thread-By2aBNAG.d.mts} +14 -2
- package/dist/{ModelConfigTypes-CzmXY3sn.d.ts → Thread-By2aBNAG.d.ts} +14 -2
- package/dist/{chunk-CY4TTHR7.mjs → chunk-SCWPIDP6.mjs} +8 -1
- package/dist/{chunk-CY4TTHR7.mjs.map → chunk-SCWPIDP6.mjs.map} +1 -1
- package/dist/experimental.d.mts +2 -3
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.mjs +1 -2
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +31 -4
- package/dist/index.d.ts +31 -4
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -15
- package/dist/AssistantRuntime-BM_jVV3g.d.mts +0 -23
- package/dist/AssistantRuntime-CBMSAJqH.d.mts +0 -23
- package/dist/AssistantRuntime-C_BvM7ZT.d.ts +0 -23
- package/dist/AssistantRuntime-DELpXWfG.d.ts +0 -23
- package/dist/ModelConfigTypes-B9UY4zxv.d.mts +0 -55
- package/dist/ModelConfigTypes-B9UY4zxv.d.ts +0 -55
- package/dist/ModelConfigTypes-BF5HxVrH.d.mts +0 -55
- package/dist/ModelConfigTypes-BF5HxVrH.d.ts +0 -55
- package/dist/ModelConfigTypes-Cf3yjaDu.d.mts +0 -55
- package/dist/ModelConfigTypes-Cf3yjaDu.d.ts +0 -55
- package/dist/Thread-BMASJT4a.d.ts +0 -15
- package/dist/Thread-UEVsUmvl.d.mts +0 -15
- package/dist/chunk-3XZUKECF.mjs +0 -207
- package/dist/chunk-3XZUKECF.mjs.map +0 -1
- package/dist/chunk-4DQ2CIAD.mjs +0 -69
- package/dist/chunk-4DQ2CIAD.mjs.map +0 -1
- package/dist/chunk-5YONSDN4.mjs +0 -200
- package/dist/chunk-5YONSDN4.mjs.map +0 -1
- package/dist/chunk-DKAWDNW5.mjs +0 -22
- package/dist/chunk-DKAWDNW5.mjs.map +0 -1
- package/dist/chunk-GQKH2ADD.mjs +0 -165
- package/dist/chunk-GQKH2ADD.mjs.map +0 -1
- package/dist/chunk-J5LGTIGS.mjs +0 -10
- package/dist/chunk-J5LGTIGS.mjs.map +0 -1
- package/dist/chunk-NSBOH42A.mjs +0 -200
- package/dist/chunk-NSBOH42A.mjs.map +0 -1
- package/dist/chunk-X4HBDEFP.mjs +0 -30
- package/dist/chunk-X4HBDEFP.mjs.map +0 -1
- package/dist/internal-dlLjX30u.d.mts +0 -75
- package/dist/internal-dlLjX30u.d.ts +0 -75
- package/dist/internal.d.mts +0 -25
- package/dist/internal.d.ts +0 -25
- package/dist/internal.js +0 -225
- package/dist/internal.js.map +0 -1
- package/dist/internal.mjs +0 -10
- package/dist/internal.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -1,22 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
MessageRepository,
|
3
|
-
ProxyConfigProvider,
|
4
|
-
generateId,
|
5
|
-
mergeModelConfigs
|
6
|
-
} from "./chunk-NSBOH42A.mjs";
|
7
1
|
import {
|
8
2
|
AssistantContext,
|
9
3
|
ContentPartContext,
|
10
4
|
MessageContext,
|
11
5
|
ThreadContext,
|
6
|
+
__export,
|
12
7
|
useComposerContext,
|
13
8
|
useContentPartContext,
|
14
9
|
useMessageContext,
|
15
10
|
useThreadContext
|
16
|
-
} from "./chunk-
|
17
|
-
import {
|
18
|
-
__export
|
19
|
-
} from "./chunk-J5LGTIGS.mjs";
|
11
|
+
} from "./chunk-SCWPIDP6.mjs";
|
20
12
|
|
21
13
|
// src/actions/useCopyMessage.tsx
|
22
14
|
import { useCallback } from "react";
|
@@ -979,6 +971,185 @@ __export(contentPart_exports, {
|
|
979
971
|
// src/runtime/local/useLocalRuntime.tsx
|
980
972
|
import { useInsertionEffect, useState as useState3 } from "react";
|
981
973
|
|
974
|
+
// src/utils/ModelConfigTypes.ts
|
975
|
+
var mergeModelConfigs = (configs) => {
|
976
|
+
return configs.reduce((acc, config) => {
|
977
|
+
if (config.system) {
|
978
|
+
if (acc.system) {
|
979
|
+
acc.system += `
|
980
|
+
|
981
|
+
${config.system}`;
|
982
|
+
} else {
|
983
|
+
acc.system = config.system;
|
984
|
+
}
|
985
|
+
}
|
986
|
+
if (config.tools) {
|
987
|
+
acc.tools = { ...acc.tools, ...config.tools };
|
988
|
+
}
|
989
|
+
return acc;
|
990
|
+
}, {});
|
991
|
+
};
|
992
|
+
|
993
|
+
// src/runtime/utils/idUtils.tsx
|
994
|
+
import { customAlphabet } from "nanoid/non-secure";
|
995
|
+
var generateId = customAlphabet(
|
996
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
997
|
+
7
|
998
|
+
);
|
999
|
+
var optimisticPrefix = "__optimistic__";
|
1000
|
+
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1001
|
+
|
1002
|
+
// src/runtime/utils/MessageRepository.tsx
|
1003
|
+
var findHead = (message) => {
|
1004
|
+
if (message.next) return findHead(message.next);
|
1005
|
+
return message;
|
1006
|
+
};
|
1007
|
+
var MessageRepository = class {
|
1008
|
+
messages = /* @__PURE__ */ new Map();
|
1009
|
+
// message_id -> item
|
1010
|
+
head = null;
|
1011
|
+
root = {
|
1012
|
+
children: []
|
1013
|
+
};
|
1014
|
+
performOp(newParent, child, operation) {
|
1015
|
+
const parentOrRoot = child.prev ?? this.root;
|
1016
|
+
const newParentOrRoot = newParent ?? this.root;
|
1017
|
+
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1018
|
+
if (operation !== "link") {
|
1019
|
+
parentOrRoot.children = parentOrRoot.children.filter(
|
1020
|
+
(m) => m !== child.current.id
|
1021
|
+
);
|
1022
|
+
if (child.prev?.next === child) {
|
1023
|
+
const fallbackId = child.prev.children.at(-1);
|
1024
|
+
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1025
|
+
if (fallback === void 0) {
|
1026
|
+
throw new Error(
|
1027
|
+
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1028
|
+
);
|
1029
|
+
}
|
1030
|
+
child.prev.next = fallback;
|
1031
|
+
}
|
1032
|
+
}
|
1033
|
+
if (operation !== "cut") {
|
1034
|
+
newParentOrRoot.children = [
|
1035
|
+
...newParentOrRoot.children,
|
1036
|
+
child.current.id
|
1037
|
+
];
|
1038
|
+
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1039
|
+
newParent.next = child;
|
1040
|
+
}
|
1041
|
+
child.prev = newParent;
|
1042
|
+
}
|
1043
|
+
}
|
1044
|
+
getMessages() {
|
1045
|
+
const messages = new Array(this.head?.level ?? 0);
|
1046
|
+
for (let current = this.head; current; current = current.prev) {
|
1047
|
+
messages[current.level] = current.current;
|
1048
|
+
}
|
1049
|
+
return messages;
|
1050
|
+
}
|
1051
|
+
addOrUpdateMessage(parentId, message) {
|
1052
|
+
const existingItem = this.messages.get(message.id);
|
1053
|
+
const prev = parentId ? this.messages.get(parentId) : null;
|
1054
|
+
if (prev === void 0)
|
1055
|
+
throw new Error(
|
1056
|
+
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1057
|
+
);
|
1058
|
+
if (existingItem) {
|
1059
|
+
existingItem.current = message;
|
1060
|
+
this.performOp(prev, existingItem, "relink");
|
1061
|
+
return;
|
1062
|
+
}
|
1063
|
+
const newItem = {
|
1064
|
+
prev,
|
1065
|
+
current: message,
|
1066
|
+
next: null,
|
1067
|
+
children: [],
|
1068
|
+
level: prev ? prev.level + 1 : 0
|
1069
|
+
};
|
1070
|
+
this.messages.set(message.id, newItem);
|
1071
|
+
this.performOp(prev, newItem, "link");
|
1072
|
+
if (this.head === prev) {
|
1073
|
+
this.head = newItem;
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
appendOptimisticMessage(parentId, message) {
|
1077
|
+
let optimisticId;
|
1078
|
+
do {
|
1079
|
+
optimisticId = generateOptimisticId();
|
1080
|
+
} while (this.messages.has(optimisticId));
|
1081
|
+
this.addOrUpdateMessage(parentId, {
|
1082
|
+
...message,
|
1083
|
+
id: optimisticId,
|
1084
|
+
createdAt: /* @__PURE__ */ new Date(),
|
1085
|
+
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1086
|
+
});
|
1087
|
+
return optimisticId;
|
1088
|
+
}
|
1089
|
+
deleteMessage(messageId, replacementId) {
|
1090
|
+
const message = this.messages.get(messageId);
|
1091
|
+
if (!message)
|
1092
|
+
throw new Error(
|
1093
|
+
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1094
|
+
);
|
1095
|
+
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1096
|
+
if (replacement === void 0)
|
1097
|
+
throw new Error(
|
1098
|
+
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1099
|
+
);
|
1100
|
+
for (const child of message.children) {
|
1101
|
+
const childMessage = this.messages.get(child);
|
1102
|
+
if (!childMessage)
|
1103
|
+
throw new Error(
|
1104
|
+
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1105
|
+
);
|
1106
|
+
this.performOp(replacement, childMessage, "relink");
|
1107
|
+
}
|
1108
|
+
this.performOp(null, message, "cut");
|
1109
|
+
this.messages.delete(messageId);
|
1110
|
+
if (this.head === message) {
|
1111
|
+
this.head = replacement ? findHead(replacement) : null;
|
1112
|
+
}
|
1113
|
+
}
|
1114
|
+
getBranches(messageId) {
|
1115
|
+
const message = this.messages.get(messageId);
|
1116
|
+
if (!message)
|
1117
|
+
throw new Error(
|
1118
|
+
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1119
|
+
);
|
1120
|
+
const { children } = message.prev ?? this.root;
|
1121
|
+
return children;
|
1122
|
+
}
|
1123
|
+
switchToBranch(messageId) {
|
1124
|
+
const message = this.messages.get(messageId);
|
1125
|
+
if (!message)
|
1126
|
+
throw new Error(
|
1127
|
+
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1128
|
+
);
|
1129
|
+
if (message.prev) {
|
1130
|
+
message.prev.next = message;
|
1131
|
+
}
|
1132
|
+
this.head = findHead(message);
|
1133
|
+
}
|
1134
|
+
resetHead(messageId) {
|
1135
|
+
if (messageId === null) {
|
1136
|
+
this.head = null;
|
1137
|
+
return;
|
1138
|
+
}
|
1139
|
+
const message = this.messages.get(messageId);
|
1140
|
+
if (!message)
|
1141
|
+
throw new Error(
|
1142
|
+
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1143
|
+
);
|
1144
|
+
this.head = message;
|
1145
|
+
for (let current = message; current; current = current.prev) {
|
1146
|
+
if (current.prev) {
|
1147
|
+
current.prev.next = current;
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
};
|
1152
|
+
|
982
1153
|
// src/runtime/local/LocalRuntime.tsx
|
983
1154
|
var LocalRuntime = class {
|
984
1155
|
constructor(adapter) {
|
@@ -1087,6 +1258,22 @@ import { useEffect as useEffect7, useInsertionEffect as useInsertionEffect3, use
|
|
1087
1258
|
|
1088
1259
|
// src/context/stores/AssistantModelConfig.ts
|
1089
1260
|
import { create as create4 } from "zustand";
|
1261
|
+
|
1262
|
+
// src/utils/ProxyConfigProvider.ts
|
1263
|
+
var ProxyConfigProvider = class {
|
1264
|
+
_providers = /* @__PURE__ */ new Set();
|
1265
|
+
getModelConfig() {
|
1266
|
+
return mergeModelConfigs([...this._providers].map((p) => p()));
|
1267
|
+
}
|
1268
|
+
registerModelConfigProvider(provider) {
|
1269
|
+
this._providers.add(provider);
|
1270
|
+
return () => {
|
1271
|
+
this._providers.delete(provider);
|
1272
|
+
};
|
1273
|
+
}
|
1274
|
+
};
|
1275
|
+
|
1276
|
+
// src/context/stores/AssistantModelConfig.ts
|
1090
1277
|
var makeAssistantModelConfigStore = () => create4(() => {
|
1091
1278
|
const proxy = new ProxyConfigProvider();
|
1092
1279
|
return {
|
@@ -1227,12 +1414,20 @@ var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
|
1227
1414
|
return /* @__PURE__ */ jsx23(AssistantProvider, { runtime, children });
|
1228
1415
|
};
|
1229
1416
|
var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
1417
|
+
|
1418
|
+
// src/internal.ts
|
1419
|
+
var internal_exports = {};
|
1420
|
+
__export(internal_exports, {
|
1421
|
+
MessageRepository: () => MessageRepository,
|
1422
|
+
ProxyConfigProvider: () => ProxyConfigProvider
|
1423
|
+
});
|
1230
1424
|
export {
|
1231
1425
|
actionBar_exports as ActionBarPrimitive,
|
1232
1426
|
AssistantRuntimeProvider,
|
1233
1427
|
branchPicker_exports as BranchPickerPrimitive,
|
1234
1428
|
composer_exports as ComposerPrimitive,
|
1235
1429
|
contentPart_exports as ContentPartPrimitive,
|
1430
|
+
internal_exports as INTERNAL,
|
1236
1431
|
message_exports as MessagePrimitive,
|
1237
1432
|
thread_exports as ThreadPrimitive,
|
1238
1433
|
useBeginMessageEdit,
|