@assistant-ui/react 0.7.56 → 0.7.58
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/runtimes/core/BaseThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +3 -3
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +3 -3
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts +3 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js +10 -2
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs +10 -2
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.d.ts +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.d.ts.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.js.map +1 -1
- package/dist/runtimes/edge/createEdgeRuntimeAPI.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageConverter.d.ts +1 -1
- package/dist/runtimes/external-store/ThreadMessageConverter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageConverter.js.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageConverter.mjs.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +17 -17
- package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.d.ts +2 -1
- package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js +25 -1
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.mjs +25 -1
- package/dist/runtimes/utils/MessageRepository.mjs.map +1 -1
- package/package.json +1 -1
- package/src/runtimes/edge/EdgeChatAdapter.ts +3 -3
- package/src/runtimes/edge/converters/toLanguageModelMessages.ts +12 -1
- package/src/runtimes/edge/createEdgeRuntimeAPI.ts +1 -1
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +1 -1
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +5 -4
- package/src/runtimes/external-store/ThreadMessageConverter.ts +1 -1
- package/src/runtimes/local/ChatModelAdapter.tsx +18 -18
- package/src/runtimes/utils/MessageRepository.tsx +33 -1
|
@@ -10,41 +10,41 @@ import type {
|
|
|
10
10
|
import type { ModelContext } from "../../model-context/ModelContextTypes";
|
|
11
11
|
|
|
12
12
|
export type ChatModelRunUpdate = {
|
|
13
|
-
content: ThreadAssistantContentPart[];
|
|
14
|
-
metadata?: Record<string, unknown>;
|
|
13
|
+
readonly content: readonly ThreadAssistantContentPart[];
|
|
14
|
+
readonly metadata?: Record<string, unknown>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type ChatModelRunResult = {
|
|
18
|
-
content?: ThreadAssistantContentPart[] | undefined;
|
|
19
|
-
status?: MessageStatus | undefined;
|
|
20
|
-
metadata?: {
|
|
21
|
-
unstable_annotations?: unknown[] | undefined;
|
|
22
|
-
unstable_data?: unknown[] | undefined;
|
|
23
|
-
steps?: ThreadStep[] | undefined;
|
|
24
|
-
custom?: Record<string, unknown> | undefined;
|
|
18
|
+
readonly content?: readonly ThreadAssistantContentPart[] | undefined;
|
|
19
|
+
readonly status?: MessageStatus | undefined;
|
|
20
|
+
readonly metadata?: {
|
|
21
|
+
readonly unstable_annotations?: readonly unknown[] | undefined;
|
|
22
|
+
readonly unstable_data?: readonly unknown[] | undefined;
|
|
23
|
+
readonly steps?: readonly ThreadStep[] | undefined;
|
|
24
|
+
readonly custom?: Record<string, unknown> | undefined;
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export type CoreChatModelRunResult = Omit<ChatModelRunResult, "content"> & {
|
|
29
|
-
content: (TextContentPart | ToolCallContentPart)[];
|
|
29
|
+
readonly content: readonly (TextContentPart | ToolCallContentPart)[];
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export type ChatModelRunOptions = {
|
|
33
|
-
messages: ThreadMessage[];
|
|
34
|
-
runConfig: RunConfig;
|
|
35
|
-
abortSignal: AbortSignal;
|
|
36
|
-
context: ModelContext;
|
|
33
|
+
readonly messages: readonly ThreadMessage[];
|
|
34
|
+
readonly runConfig: RunConfig;
|
|
35
|
+
readonly abortSignal: AbortSignal;
|
|
36
|
+
readonly context: ModelContext;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated This field was renamed to `context`.
|
|
40
40
|
*/
|
|
41
|
-
config: ModelContext;
|
|
41
|
+
readonly config: ModelContext;
|
|
42
42
|
|
|
43
|
-
unstable_assistantMessageId?: string;
|
|
43
|
+
readonly unstable_assistantMessageId?: string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export type ChatModelAdapter = {
|
|
47
|
-
run
|
|
47
|
+
run(
|
|
48
48
|
options: ChatModelRunOptions,
|
|
49
|
-
)
|
|
49
|
+
): Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>;
|
|
50
50
|
};
|
|
@@ -34,6 +34,23 @@ const findHead = (
|
|
|
34
34
|
return null;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
class CachedValue<T> {
|
|
38
|
+
private _value: T | null = null;
|
|
39
|
+
|
|
40
|
+
constructor(private func: () => T) {}
|
|
41
|
+
|
|
42
|
+
get value() {
|
|
43
|
+
if (this._value === null) {
|
|
44
|
+
this._value = this.func();
|
|
45
|
+
}
|
|
46
|
+
return this._value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dirty() {
|
|
50
|
+
this._value = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
export class MessageRepository {
|
|
38
55
|
private messages = new Map<string, RepositoryMessage>(); // message_id -> item
|
|
39
56
|
private head: RepositoryMessage | null = null;
|
|
@@ -101,12 +118,17 @@ export class MessageRepository {
|
|
|
101
118
|
child.prev = newParent;
|
|
102
119
|
}
|
|
103
120
|
}
|
|
104
|
-
|
|
121
|
+
|
|
122
|
+
private _messages = new CachedValue<readonly ThreadMessage[]>(() => {
|
|
105
123
|
const messages = new Array<ThreadMessage>(this.head?.level ?? 0);
|
|
106
124
|
for (let current = this.head; current; current = current.prev) {
|
|
107
125
|
messages[current.level] = current.current;
|
|
108
126
|
}
|
|
109
127
|
return messages;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
getMessages() {
|
|
131
|
+
return this._messages.value;
|
|
110
132
|
}
|
|
111
133
|
|
|
112
134
|
addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {
|
|
@@ -121,6 +143,7 @@ export class MessageRepository {
|
|
|
121
143
|
if (existingItem) {
|
|
122
144
|
existingItem.current = message;
|
|
123
145
|
this.performOp(prev, existingItem, "relink");
|
|
146
|
+
this._messages.dirty();
|
|
124
147
|
return;
|
|
125
148
|
}
|
|
126
149
|
|
|
@@ -139,6 +162,8 @@ export class MessageRepository {
|
|
|
139
162
|
if (this.head === prev) {
|
|
140
163
|
this.head = newItem;
|
|
141
164
|
}
|
|
165
|
+
|
|
166
|
+
this._messages.dirty();
|
|
142
167
|
}
|
|
143
168
|
|
|
144
169
|
getMessage(messageId: string) {
|
|
@@ -205,6 +230,8 @@ export class MessageRepository {
|
|
|
205
230
|
if (this.head === message) {
|
|
206
231
|
this.head = findHead(replacement ?? this.root);
|
|
207
232
|
}
|
|
233
|
+
|
|
234
|
+
this._messages.dirty();
|
|
208
235
|
}
|
|
209
236
|
|
|
210
237
|
getBranches(messageId: string) {
|
|
@@ -229,11 +256,14 @@ export class MessageRepository {
|
|
|
229
256
|
prevOrRoot.next = message;
|
|
230
257
|
|
|
231
258
|
this.head = findHead(message);
|
|
259
|
+
|
|
260
|
+
this._messages.dirty();
|
|
232
261
|
}
|
|
233
262
|
|
|
234
263
|
resetHead(messageId: string | null) {
|
|
235
264
|
if (messageId === null) {
|
|
236
265
|
this.head = null;
|
|
266
|
+
this._messages.dirty();
|
|
237
267
|
return;
|
|
238
268
|
}
|
|
239
269
|
|
|
@@ -253,6 +283,8 @@ export class MessageRepository {
|
|
|
253
283
|
current.prev.next = current;
|
|
254
284
|
}
|
|
255
285
|
}
|
|
286
|
+
|
|
287
|
+
this._messages.dirty();
|
|
256
288
|
}
|
|
257
289
|
|
|
258
290
|
export(): ExportedMessageRepository {
|