@assistant-ui/react 0.1.0 → 0.1.1
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/ModelConfigTypes-CzmXY3sn.d.mts +55 -0
- package/dist/ModelConfigTypes-CzmXY3sn.d.ts +55 -0
- package/dist/Thread-BMASJT4a.d.ts +15 -0
- package/dist/Thread-UEVsUmvl.d.mts +15 -0
- package/dist/chunk-NSBOH42A.mjs +200 -0
- package/dist/chunk-NSBOH42A.mjs.map +1 -0
- package/dist/experimental.d.mts +4 -38
- package/dist/experimental.d.ts +4 -38
- package/dist/experimental.js +17 -301
- package/dist/experimental.js.map +1 -1
- package/dist/experimental.mjs +1 -111
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +46 -5
- package/dist/index.d.ts +46 -5
- package/dist/index.js +288 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.mjs +3 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import * as react from 'react';
|
2
2
|
import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
|
3
3
|
import { TextareaAutosizeProps } from 'react-textarea-autosize';
|
4
|
-
import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart } from './ModelConfigTypes-
|
5
|
-
export {
|
6
|
-
import { T as
|
7
|
-
export { U as Unsubscribe } from './AssistantRuntime-CBMSAJqH.mjs';
|
4
|
+
import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart, M as ModelConfigProvider, b as ThreadMessage, c as ModelConfig, A as AssistantContentPart, d as AppendMessage } from './ModelConfigTypes-CzmXY3sn.mjs';
|
5
|
+
export { h as AppendContentPart, e as AssistantMessage, g as UserContentPart, f as UserMessage } from './ModelConfigTypes-CzmXY3sn.mjs';
|
6
|
+
import { T as ThreadState, U as Unsubscribe } from './Thread-UEVsUmvl.mjs';
|
8
7
|
import 'zod';
|
9
8
|
|
10
9
|
declare const useCopyMessage: ({ copiedDuration }: {
|
@@ -236,13 +235,55 @@ declare namespace index {
|
|
236
235
|
export { ContentPartInProgressIndicator as InProgressIndicator };
|
237
236
|
}
|
238
237
|
|
238
|
+
type ThreadRuntime = Readonly<ThreadState & {
|
239
|
+
subscribe: (callback: () => void) => Unsubscribe;
|
240
|
+
}>;
|
241
|
+
|
242
|
+
type AssistantRuntime = ThreadRuntime & {
|
243
|
+
registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
|
244
|
+
};
|
245
|
+
|
239
246
|
type ReactThreadRuntime = ThreadRuntime & {
|
240
247
|
unstable_synchronizer?: ComponentType;
|
241
248
|
};
|
242
249
|
|
250
|
+
type ChatModelRunResult = {
|
251
|
+
content: AssistantContentPart[];
|
252
|
+
};
|
253
|
+
type ChatModelRunOptions = {
|
254
|
+
messages: ThreadMessage[];
|
255
|
+
abortSignal: AbortSignal;
|
256
|
+
config: ModelConfig;
|
257
|
+
onUpdate: (result: ChatModelRunResult) => void;
|
258
|
+
};
|
259
|
+
type ChatModelAdapter = {
|
260
|
+
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
|
261
|
+
};
|
262
|
+
|
263
|
+
declare class LocalRuntime implements AssistantRuntime {
|
264
|
+
adapter: ChatModelAdapter;
|
265
|
+
private _subscriptions;
|
266
|
+
private _configProviders;
|
267
|
+
private abortController;
|
268
|
+
private repository;
|
269
|
+
get messages(): ThreadMessage[];
|
270
|
+
get isRunning(): boolean;
|
271
|
+
constructor(adapter: ChatModelAdapter);
|
272
|
+
getBranches(messageId: string): string[];
|
273
|
+
switchToBranch(branchId: string): void;
|
274
|
+
append(message: AppendMessage): Promise<void>;
|
275
|
+
startRun(parentId: string | null): Promise<void>;
|
276
|
+
cancelRun(): void;
|
277
|
+
private notifySubscribers;
|
278
|
+
subscribe(callback: () => void): Unsubscribe;
|
279
|
+
registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
|
280
|
+
}
|
281
|
+
|
282
|
+
declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
|
283
|
+
|
243
284
|
type AssistantRuntimeProviderProps = {
|
244
285
|
runtime: AssistantRuntime;
|
245
286
|
};
|
246
287
|
declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChildren<AssistantRuntimeProviderProps>>;
|
247
288
|
|
248
|
-
export { index$1 as ActionBarPrimitive, AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, index$5 as ThreadPrimitive, ThreadRuntime, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
|
289
|
+
export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
|
package/dist/index.d.ts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import * as react from 'react';
|
2
2
|
import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
|
3
3
|
import { TextareaAutosizeProps } from 'react-textarea-autosize';
|
4
|
-
import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart } from './ModelConfigTypes-
|
5
|
-
export {
|
6
|
-
import { T as
|
7
|
-
export { U as Unsubscribe } from './AssistantRuntime-C_BvM7ZT.js';
|
4
|
+
import { T as TextContentPart, I as ImageContentPart, U as UIContentPart, a as ToolCallContentPart, M as ModelConfigProvider, b as ThreadMessage, c as ModelConfig, A as AssistantContentPart, d as AppendMessage } from './ModelConfigTypes-CzmXY3sn.js';
|
5
|
+
export { h as AppendContentPart, e as AssistantMessage, g as UserContentPart, f as UserMessage } from './ModelConfigTypes-CzmXY3sn.js';
|
6
|
+
import { T as ThreadState, U as Unsubscribe } from './Thread-BMASJT4a.js';
|
8
7
|
import 'zod';
|
9
8
|
|
10
9
|
declare const useCopyMessage: ({ copiedDuration }: {
|
@@ -236,13 +235,55 @@ declare namespace index {
|
|
236
235
|
export { ContentPartInProgressIndicator as InProgressIndicator };
|
237
236
|
}
|
238
237
|
|
238
|
+
type ThreadRuntime = Readonly<ThreadState & {
|
239
|
+
subscribe: (callback: () => void) => Unsubscribe;
|
240
|
+
}>;
|
241
|
+
|
242
|
+
type AssistantRuntime = ThreadRuntime & {
|
243
|
+
registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
|
244
|
+
};
|
245
|
+
|
239
246
|
type ReactThreadRuntime = ThreadRuntime & {
|
240
247
|
unstable_synchronizer?: ComponentType;
|
241
248
|
};
|
242
249
|
|
250
|
+
type ChatModelRunResult = {
|
251
|
+
content: AssistantContentPart[];
|
252
|
+
};
|
253
|
+
type ChatModelRunOptions = {
|
254
|
+
messages: ThreadMessage[];
|
255
|
+
abortSignal: AbortSignal;
|
256
|
+
config: ModelConfig;
|
257
|
+
onUpdate: (result: ChatModelRunResult) => void;
|
258
|
+
};
|
259
|
+
type ChatModelAdapter = {
|
260
|
+
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
|
261
|
+
};
|
262
|
+
|
263
|
+
declare class LocalRuntime implements AssistantRuntime {
|
264
|
+
adapter: ChatModelAdapter;
|
265
|
+
private _subscriptions;
|
266
|
+
private _configProviders;
|
267
|
+
private abortController;
|
268
|
+
private repository;
|
269
|
+
get messages(): ThreadMessage[];
|
270
|
+
get isRunning(): boolean;
|
271
|
+
constructor(adapter: ChatModelAdapter);
|
272
|
+
getBranches(messageId: string): string[];
|
273
|
+
switchToBranch(branchId: string): void;
|
274
|
+
append(message: AppendMessage): Promise<void>;
|
275
|
+
startRun(parentId: string | null): Promise<void>;
|
276
|
+
cancelRun(): void;
|
277
|
+
private notifySubscribers;
|
278
|
+
subscribe(callback: () => void): Unsubscribe;
|
279
|
+
registerModelConfigProvider(provider: ModelConfigProvider): () => boolean;
|
280
|
+
}
|
281
|
+
|
282
|
+
declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
|
283
|
+
|
243
284
|
type AssistantRuntimeProviderProps = {
|
244
285
|
runtime: AssistantRuntime;
|
245
286
|
};
|
246
287
|
declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChildren<AssistantRuntimeProviderProps>>;
|
247
288
|
|
248
|
-
export { index$1 as ActionBarPrimitive, AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, index$5 as ThreadPrimitive, ThreadRuntime, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
|
289
|
+
export { index$1 as ActionBarPrimitive, AppendMessage, AssistantContentPart, type AssistantRuntime, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, type ChatModelAdapter, type ChatModelRunOptions, index$4 as ComposerPrimitive, index as ContentPartPrimitive, index$3 as MessagePrimitive, type ReactThreadRuntime, TextContentPart, ThreadMessage, index$5 as ThreadPrimitive, type ThreadRuntime, Unsubscribe, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useLocalRuntime, useReloadMessage };
|
package/dist/index.js
CHANGED
@@ -41,6 +41,7 @@ __export(src_exports, {
|
|
41
41
|
useCopyMessage: () => useCopyMessage,
|
42
42
|
useGoToNextBranch: () => useGoToNextBranch,
|
43
43
|
useGoToPreviousBranch: () => useGoToPreviousBranch,
|
44
|
+
useLocalRuntime: () => useLocalRuntime,
|
44
45
|
useReloadMessage: () => useReloadMessage
|
45
46
|
});
|
46
47
|
module.exports = __toCommonJS(src_exports);
|
@@ -1028,20 +1029,8 @@ __export(contentPart_exports, {
|
|
1028
1029
|
InProgressIndicator: () => ContentPartInProgressIndicator
|
1029
1030
|
});
|
1030
1031
|
|
1031
|
-
// src/
|
1032
|
-
var import_react32 = require("react");
|
1033
|
-
|
1034
|
-
// src/context/providers/AssistantProvider.tsx
|
1035
|
-
var import_react31 = require("react");
|
1036
|
-
|
1037
|
-
// src/context/AssistantContext.ts
|
1032
|
+
// src/runtime/local/useLocalRuntime.tsx
|
1038
1033
|
var import_react29 = require("react");
|
1039
|
-
var AssistantContext = (0, import_react29.createContext)(
|
1040
|
-
null
|
1041
|
-
);
|
1042
|
-
|
1043
|
-
// src/context/stores/AssistantModelConfig.ts
|
1044
|
-
var import_zustand4 = require("zustand");
|
1045
1034
|
|
1046
1035
|
// src/utils/ModelConfigTypes.ts
|
1047
1036
|
var mergeModelConfigs = (configs) => {
|
@@ -1062,6 +1051,281 @@ ${config.system}`;
|
|
1062
1051
|
}, {});
|
1063
1052
|
};
|
1064
1053
|
|
1054
|
+
// src/runtime/utils/idUtils.tsx
|
1055
|
+
var import_non_secure = require("nanoid/non-secure");
|
1056
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
1057
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
1058
|
+
7
|
1059
|
+
);
|
1060
|
+
var optimisticPrefix = "__optimistic__";
|
1061
|
+
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
1062
|
+
|
1063
|
+
// src/runtime/utils/MessageRepository.tsx
|
1064
|
+
var findHead = (message) => {
|
1065
|
+
if (message.next) return findHead(message.next);
|
1066
|
+
return message;
|
1067
|
+
};
|
1068
|
+
var MessageRepository = class {
|
1069
|
+
messages = /* @__PURE__ */ new Map();
|
1070
|
+
// message_id -> item
|
1071
|
+
head = null;
|
1072
|
+
root = {
|
1073
|
+
children: []
|
1074
|
+
};
|
1075
|
+
performOp(newParent, child, operation) {
|
1076
|
+
const parentOrRoot = child.prev ?? this.root;
|
1077
|
+
const newParentOrRoot = newParent ?? this.root;
|
1078
|
+
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
1079
|
+
if (operation !== "link") {
|
1080
|
+
parentOrRoot.children = parentOrRoot.children.filter(
|
1081
|
+
(m) => m !== child.current.id
|
1082
|
+
);
|
1083
|
+
if (child.prev?.next === child) {
|
1084
|
+
const fallbackId = child.prev.children.at(-1);
|
1085
|
+
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
1086
|
+
if (fallback === void 0) {
|
1087
|
+
throw new Error(
|
1088
|
+
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
1089
|
+
);
|
1090
|
+
}
|
1091
|
+
child.prev.next = fallback;
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
if (operation !== "cut") {
|
1095
|
+
newParentOrRoot.children = [
|
1096
|
+
...newParentOrRoot.children,
|
1097
|
+
child.current.id
|
1098
|
+
];
|
1099
|
+
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
1100
|
+
newParent.next = child;
|
1101
|
+
}
|
1102
|
+
child.prev = newParent;
|
1103
|
+
}
|
1104
|
+
}
|
1105
|
+
getMessages() {
|
1106
|
+
const messages = new Array(this.head?.level ?? 0);
|
1107
|
+
for (let current = this.head; current; current = current.prev) {
|
1108
|
+
messages[current.level] = current.current;
|
1109
|
+
}
|
1110
|
+
return messages;
|
1111
|
+
}
|
1112
|
+
addOrUpdateMessage(parentId, message) {
|
1113
|
+
const existingItem = this.messages.get(message.id);
|
1114
|
+
const prev = parentId ? this.messages.get(parentId) : null;
|
1115
|
+
if (prev === void 0)
|
1116
|
+
throw new Error(
|
1117
|
+
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
1118
|
+
);
|
1119
|
+
if (existingItem) {
|
1120
|
+
existingItem.current = message;
|
1121
|
+
this.performOp(prev, existingItem, "relink");
|
1122
|
+
return;
|
1123
|
+
}
|
1124
|
+
const newItem = {
|
1125
|
+
prev,
|
1126
|
+
current: message,
|
1127
|
+
next: null,
|
1128
|
+
children: [],
|
1129
|
+
level: prev ? prev.level + 1 : 0
|
1130
|
+
};
|
1131
|
+
this.messages.set(message.id, newItem);
|
1132
|
+
this.performOp(prev, newItem, "link");
|
1133
|
+
if (this.head === prev) {
|
1134
|
+
this.head = newItem;
|
1135
|
+
}
|
1136
|
+
}
|
1137
|
+
appendOptimisticMessage(parentId, message) {
|
1138
|
+
let optimisticId;
|
1139
|
+
do {
|
1140
|
+
optimisticId = generateOptimisticId();
|
1141
|
+
} while (this.messages.has(optimisticId));
|
1142
|
+
this.addOrUpdateMessage(parentId, {
|
1143
|
+
...message,
|
1144
|
+
id: optimisticId,
|
1145
|
+
createdAt: /* @__PURE__ */ new Date(),
|
1146
|
+
...message.role === "assistant" ? { status: "in_progress" } : void 0
|
1147
|
+
});
|
1148
|
+
return optimisticId;
|
1149
|
+
}
|
1150
|
+
deleteMessage(messageId, replacementId) {
|
1151
|
+
const message = this.messages.get(messageId);
|
1152
|
+
if (!message)
|
1153
|
+
throw new Error(
|
1154
|
+
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
1155
|
+
);
|
1156
|
+
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
1157
|
+
if (replacement === void 0)
|
1158
|
+
throw new Error(
|
1159
|
+
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
1160
|
+
);
|
1161
|
+
for (const child of message.children) {
|
1162
|
+
const childMessage = this.messages.get(child);
|
1163
|
+
if (!childMessage)
|
1164
|
+
throw new Error(
|
1165
|
+
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
1166
|
+
);
|
1167
|
+
this.performOp(replacement, childMessage, "relink");
|
1168
|
+
}
|
1169
|
+
this.performOp(null, message, "cut");
|
1170
|
+
this.messages.delete(messageId);
|
1171
|
+
if (this.head === message) {
|
1172
|
+
this.head = replacement ? findHead(replacement) : null;
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
getBranches(messageId) {
|
1176
|
+
const message = this.messages.get(messageId);
|
1177
|
+
if (!message)
|
1178
|
+
throw new Error(
|
1179
|
+
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
1180
|
+
);
|
1181
|
+
const { children } = message.prev ?? this.root;
|
1182
|
+
return children;
|
1183
|
+
}
|
1184
|
+
switchToBranch(messageId) {
|
1185
|
+
const message = this.messages.get(messageId);
|
1186
|
+
if (!message)
|
1187
|
+
throw new Error(
|
1188
|
+
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
1189
|
+
);
|
1190
|
+
if (message.prev) {
|
1191
|
+
message.prev.next = message;
|
1192
|
+
}
|
1193
|
+
this.head = findHead(message);
|
1194
|
+
}
|
1195
|
+
resetHead(messageId) {
|
1196
|
+
if (messageId === null) {
|
1197
|
+
this.head = null;
|
1198
|
+
return;
|
1199
|
+
}
|
1200
|
+
const message = this.messages.get(messageId);
|
1201
|
+
if (!message)
|
1202
|
+
throw new Error(
|
1203
|
+
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
1204
|
+
);
|
1205
|
+
this.head = message;
|
1206
|
+
for (let current = message; current; current = current.prev) {
|
1207
|
+
if (current.prev) {
|
1208
|
+
current.prev.next = current;
|
1209
|
+
}
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
};
|
1213
|
+
|
1214
|
+
// src/runtime/local/LocalRuntime.tsx
|
1215
|
+
var LocalRuntime = class {
|
1216
|
+
constructor(adapter) {
|
1217
|
+
this.adapter = adapter;
|
1218
|
+
}
|
1219
|
+
_subscriptions = /* @__PURE__ */ new Set();
|
1220
|
+
_configProviders = /* @__PURE__ */ new Set();
|
1221
|
+
abortController = null;
|
1222
|
+
repository = new MessageRepository();
|
1223
|
+
get messages() {
|
1224
|
+
return this.repository.getMessages();
|
1225
|
+
}
|
1226
|
+
get isRunning() {
|
1227
|
+
return this.abortController != null;
|
1228
|
+
}
|
1229
|
+
getBranches(messageId) {
|
1230
|
+
return this.repository.getBranches(messageId);
|
1231
|
+
}
|
1232
|
+
switchToBranch(branchId) {
|
1233
|
+
this.repository.switchToBranch(branchId);
|
1234
|
+
this.notifySubscribers();
|
1235
|
+
}
|
1236
|
+
async append(message) {
|
1237
|
+
const userMessageId = generateId();
|
1238
|
+
const userMessage = {
|
1239
|
+
id: userMessageId,
|
1240
|
+
role: "user",
|
1241
|
+
content: message.content,
|
1242
|
+
createdAt: /* @__PURE__ */ new Date()
|
1243
|
+
};
|
1244
|
+
this.repository.addOrUpdateMessage(message.parentId, userMessage);
|
1245
|
+
await this.startRun(userMessageId);
|
1246
|
+
}
|
1247
|
+
async startRun(parentId) {
|
1248
|
+
const id = generateId();
|
1249
|
+
this.repository.resetHead(parentId);
|
1250
|
+
const messages = this.repository.getMessages();
|
1251
|
+
const message = {
|
1252
|
+
id,
|
1253
|
+
role: "assistant",
|
1254
|
+
status: "in_progress",
|
1255
|
+
content: [{ type: "text", text: "" }],
|
1256
|
+
createdAt: /* @__PURE__ */ new Date()
|
1257
|
+
};
|
1258
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1259
|
+
this.abortController?.abort();
|
1260
|
+
this.abortController = new AbortController();
|
1261
|
+
this.notifySubscribers();
|
1262
|
+
try {
|
1263
|
+
const updateHandler = ({ content }) => {
|
1264
|
+
message.content = content;
|
1265
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1266
|
+
this.notifySubscribers();
|
1267
|
+
};
|
1268
|
+
const result = await this.adapter.run({
|
1269
|
+
messages,
|
1270
|
+
abortSignal: this.abortController.signal,
|
1271
|
+
config: mergeModelConfigs([...this._configProviders].map((p) => p())),
|
1272
|
+
onUpdate: updateHandler
|
1273
|
+
});
|
1274
|
+
updateHandler(result);
|
1275
|
+
message.status = "done";
|
1276
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1277
|
+
} catch (e) {
|
1278
|
+
message.status = "error";
|
1279
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1280
|
+
console.error(e);
|
1281
|
+
} finally {
|
1282
|
+
this.abortController = null;
|
1283
|
+
this.notifySubscribers();
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
cancelRun() {
|
1287
|
+
if (!this.abortController) return;
|
1288
|
+
this.abortController.abort();
|
1289
|
+
this.abortController = null;
|
1290
|
+
this.notifySubscribers();
|
1291
|
+
}
|
1292
|
+
notifySubscribers() {
|
1293
|
+
for (const callback of this._subscriptions) callback();
|
1294
|
+
}
|
1295
|
+
subscribe(callback) {
|
1296
|
+
this._subscriptions.add(callback);
|
1297
|
+
return () => this._subscriptions.delete(callback);
|
1298
|
+
}
|
1299
|
+
registerModelConfigProvider(provider) {
|
1300
|
+
this._configProviders.add(provider);
|
1301
|
+
return () => this._configProviders.delete(provider);
|
1302
|
+
}
|
1303
|
+
};
|
1304
|
+
|
1305
|
+
// src/runtime/local/useLocalRuntime.tsx
|
1306
|
+
var useLocalRuntime = (adapter) => {
|
1307
|
+
const [runtime] = (0, import_react29.useState)(() => new LocalRuntime(adapter));
|
1308
|
+
(0, import_react29.useInsertionEffect)(() => {
|
1309
|
+
runtime.adapter = adapter;
|
1310
|
+
});
|
1311
|
+
return runtime;
|
1312
|
+
};
|
1313
|
+
|
1314
|
+
// src/context/providers/AssistantRuntimeProvider.tsx
|
1315
|
+
var import_react33 = require("react");
|
1316
|
+
|
1317
|
+
// src/context/providers/AssistantProvider.tsx
|
1318
|
+
var import_react32 = require("react");
|
1319
|
+
|
1320
|
+
// src/context/AssistantContext.ts
|
1321
|
+
var import_react30 = require("react");
|
1322
|
+
var AssistantContext = (0, import_react30.createContext)(
|
1323
|
+
null
|
1324
|
+
);
|
1325
|
+
|
1326
|
+
// src/context/stores/AssistantModelConfig.ts
|
1327
|
+
var import_zustand4 = require("zustand");
|
1328
|
+
|
1065
1329
|
// src/utils/ProxyConfigProvider.ts
|
1066
1330
|
var ProxyConfigProvider = class {
|
1067
1331
|
_providers = /* @__PURE__ */ new Set();
|
@@ -1090,7 +1354,7 @@ var makeAssistantModelConfigStore = () => (0, import_zustand4.create)(() => {
|
|
1090
1354
|
});
|
1091
1355
|
|
1092
1356
|
// src/context/providers/ThreadProvider.tsx
|
1093
|
-
var
|
1357
|
+
var import_react31 = require("react");
|
1094
1358
|
|
1095
1359
|
// src/context/stores/Composer.ts
|
1096
1360
|
var import_zustand5 = require("zustand");
|
@@ -1165,11 +1429,11 @@ var ThreadProvider = ({
|
|
1165
1429
|
children,
|
1166
1430
|
runtime
|
1167
1431
|
}) => {
|
1168
|
-
const runtimeRef = (0,
|
1169
|
-
(0,
|
1432
|
+
const runtimeRef = (0, import_react31.useRef)(runtime);
|
1433
|
+
(0, import_react31.useInsertionEffect)(() => {
|
1170
1434
|
runtimeRef.current = runtime;
|
1171
1435
|
});
|
1172
|
-
const [{ context, onRuntimeUpdate }] = (0,
|
1436
|
+
const [{ context, onRuntimeUpdate }] = (0, import_react31.useState)(() => {
|
1173
1437
|
const { useThread, onRuntimeUpdate: onRuntimeUpdate2 } = makeThreadStore(runtimeRef);
|
1174
1438
|
const useViewport = makeThreadViewportStore();
|
1175
1439
|
const useComposer = makeComposerStore(useThread);
|
@@ -1182,7 +1446,7 @@ var ThreadProvider = ({
|
|
1182
1446
|
onRuntimeUpdate: onRuntimeUpdate2
|
1183
1447
|
};
|
1184
1448
|
});
|
1185
|
-
(0,
|
1449
|
+
(0, import_react31.useEffect)(() => {
|
1186
1450
|
onRuntimeUpdate();
|
1187
1451
|
return runtime.subscribe(onRuntimeUpdate);
|
1188
1452
|
}, [onRuntimeUpdate, runtime]);
|
@@ -1196,16 +1460,16 @@ var ThreadProvider = ({
|
|
1196
1460
|
// src/context/providers/AssistantProvider.tsx
|
1197
1461
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1198
1462
|
var AssistantProvider = ({ children, runtime }) => {
|
1199
|
-
const runtimeRef = (0,
|
1200
|
-
(0,
|
1463
|
+
const runtimeRef = (0, import_react32.useRef)(runtime);
|
1464
|
+
(0, import_react32.useInsertionEffect)(() => {
|
1201
1465
|
runtimeRef.current = runtime;
|
1202
1466
|
});
|
1203
|
-
const [context] = (0,
|
1467
|
+
const [context] = (0, import_react32.useState)(() => {
|
1204
1468
|
const useModelConfig = makeAssistantModelConfigStore();
|
1205
1469
|
return { useModelConfig };
|
1206
1470
|
});
|
1207
1471
|
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
1208
|
-
(0,
|
1472
|
+
(0, import_react32.useEffect)(() => {
|
1209
1473
|
return runtime.registerModelConfigProvider(getModelCOnfig);
|
1210
1474
|
}, [runtime, getModelCOnfig]);
|
1211
1475
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ThreadProvider, { runtime, children }) });
|
@@ -1216,7 +1480,7 @@ var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
1216
1480
|
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
1217
1481
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(AssistantProvider, { runtime, children });
|
1218
1482
|
};
|
1219
|
-
var AssistantRuntimeProvider = (0,
|
1483
|
+
var AssistantRuntimeProvider = (0, import_react33.memo)(AssistantRuntimeProviderImpl);
|
1220
1484
|
// Annotate the CommonJS export names for ESM import in node:
|
1221
1485
|
0 && (module.exports = {
|
1222
1486
|
ActionBarPrimitive,
|
@@ -1230,6 +1494,7 @@ var AssistantRuntimeProvider = (0, import_react32.memo)(AssistantRuntimeProvider
|
|
1230
1494
|
useCopyMessage,
|
1231
1495
|
useGoToNextBranch,
|
1232
1496
|
useGoToPreviousBranch,
|
1497
|
+
useLocalRuntime,
|
1233
1498
|
useReloadMessage
|
1234
1499
|
});
|
1235
1500
|
//# sourceMappingURL=index.js.map
|