@assistant-ui/react 0.7.21 → 0.7.23
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/ComposerRuntime.d.ts +9 -7
- package/dist/api/ComposerRuntime.d.ts.map +1 -1
- package/dist/api/ComposerRuntime.js +9 -4
- package/dist/api/ComposerRuntime.js.map +1 -1
- package/dist/api/ComposerRuntime.mjs +9 -4
- package/dist/api/ComposerRuntime.mjs.map +1 -1
- package/dist/api/MessageRuntime.d.ts +7 -3
- package/dist/api/MessageRuntime.d.ts.map +1 -1
- package/dist/api/MessageRuntime.js +5 -2
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +5 -2
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +5 -5
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +3 -2
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +3 -2
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +6 -3
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +19 -6
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +19 -6
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts +6 -4
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +6 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +2 -0
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +2 -0
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts +13 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js +3 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js.map +1 -1
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs +3 -0
- package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +2 -2
- 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 +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +2 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +3 -2
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +14 -5
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +14 -5
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/types/AssistantTypes.d.ts +5 -0
- package/dist/types/AssistantTypes.d.ts.map +1 -1
- package/dist/types/AssistantTypes.js.map +1 -1
- package/package.json +1 -1
- package/src/api/ComposerRuntime.ts +21 -12
- package/src/api/MessageRuntime.ts +11 -3
- package/src/api/ThreadRuntime.ts +9 -4
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +26 -6
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +2 -1
- package/src/runtimes/core/ComposerRuntimeCore.tsx +9 -6
- package/src/runtimes/core/ThreadRuntimeCore.tsx +7 -1
- package/src/runtimes/edge/EdgeChatAdapter.ts +2 -0
- package/src/runtimes/edge/EdgeRuntimeRequestOptions.ts +5 -0
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +4 -1
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -2
- package/src/runtimes/local/ChatModelAdapter.tsx +2 -0
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +17 -4
- package/src/types/AssistantTypes.ts +7 -0
@@ -53,6 +53,7 @@ export class EdgeChatAdapter implements ChatModelAdapter {
|
|
53
53
|
|
54
54
|
async *run({
|
55
55
|
messages,
|
56
|
+
runConfig,
|
56
57
|
abortSignal,
|
57
58
|
config,
|
58
59
|
unstable_assistantMessageId,
|
@@ -75,6 +76,7 @@ export class EdgeChatAdapter implements ChatModelAdapter {
|
|
75
76
|
}),
|
76
77
|
tools: config.tools ? toLanguageModelTools(config.tools) : [],
|
77
78
|
unstable_assistantMessageId,
|
79
|
+
runConfig,
|
78
80
|
...config.callSettings,
|
79
81
|
...config.config,
|
80
82
|
|
@@ -82,6 +82,11 @@ export const EdgeRuntimeRequestOptionsSchema = z
|
|
82
82
|
.object({
|
83
83
|
system: z.string().optional(),
|
84
84
|
messages: z.array(CoreMessageSchema).min(1),
|
85
|
+
runConfig: z
|
86
|
+
.object({
|
87
|
+
custom: z.record(z.unknown()).optional(),
|
88
|
+
})
|
89
|
+
.optional(),
|
85
90
|
tools: z.array(LanguageModelV1FunctionToolSchema).optional(),
|
86
91
|
unstable_assistantMessageId: z.string().optional(),
|
87
92
|
})
|
@@ -2,6 +2,7 @@ import { AppendMessage, ThreadMessage } from "../../types";
|
|
2
2
|
import { AttachmentAdapter } from "../attachment";
|
3
3
|
import {
|
4
4
|
AddToolResultOptions,
|
5
|
+
StartRunConfig,
|
5
6
|
ThreadSuggestion,
|
6
7
|
} from "../core/ThreadRuntimeCore";
|
7
8
|
import { FeedbackAdapter } from "../feedback/FeedbackAdapter";
|
@@ -57,7 +58,9 @@ type ExternalStoreAdapterBase<T> = {
|
|
57
58
|
setMessages?: ((messages: T[]) => void) | undefined;
|
58
59
|
onNew: (message: AppendMessage) => Promise<void>;
|
59
60
|
onEdit?: ((message: AppendMessage) => Promise<void>) | undefined;
|
60
|
-
onReload?:
|
61
|
+
onReload?: // TODO: remove parentId in 0.8.0
|
62
|
+
| ((parentId: string | null, config: StartRunConfig) => Promise<void>)
|
63
|
+
| undefined;
|
61
64
|
onCancel?: (() => Promise<void>) | undefined;
|
62
65
|
onAddToolResult?:
|
63
66
|
| ((options: AddToolResultOptions) => Promise<void> | void)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import {
|
2
2
|
AddToolResultOptions,
|
3
|
+
StartRunConfig,
|
3
4
|
ThreadSuggestion,
|
4
5
|
} from "../core/ThreadRuntimeCore";
|
5
6
|
|
@@ -192,11 +193,11 @@ export class ExternalStoreThreadRuntimeCore
|
|
192
193
|
}
|
193
194
|
}
|
194
195
|
|
195
|
-
public async startRun(
|
196
|
+
public async startRun(config: StartRunConfig): Promise<void> {
|
196
197
|
if (!this._store.onReload)
|
197
198
|
throw new Error("Runtime does not support reloading messages.");
|
198
199
|
|
199
|
-
await this._store.onReload(parentId);
|
200
|
+
await this._store.onReload(config.parentId, config);
|
200
201
|
}
|
201
202
|
|
202
203
|
public cancelRun(): void {
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
import type {
|
4
4
|
MessageStatus,
|
5
|
+
RunConfig,
|
5
6
|
ThreadAssistantContentPart,
|
6
7
|
ThreadMessage,
|
7
8
|
ThreadStep,
|
@@ -24,6 +25,7 @@ export type ChatModelRunResult = {
|
|
24
25
|
|
25
26
|
export type ChatModelRunOptions = {
|
26
27
|
messages: ThreadMessage[];
|
28
|
+
runConfig: RunConfig;
|
27
29
|
abortSignal: AbortSignal;
|
28
30
|
config: ModelConfig;
|
29
31
|
|
@@ -12,8 +12,10 @@ import {
|
|
12
12
|
AddToolResultOptions,
|
13
13
|
ThreadSuggestion,
|
14
14
|
ThreadRuntimeCore,
|
15
|
+
StartRunConfig,
|
15
16
|
} from "../core/ThreadRuntimeCore";
|
16
17
|
import { BaseThreadRuntimeCore } from "../core/BaseThreadRuntimeCore";
|
18
|
+
import { RunConfig } from "../../types/AssistantTypes";
|
17
19
|
|
18
20
|
export class LocalThreadRuntimeCore
|
19
21
|
extends BaseThreadRuntimeCore
|
@@ -49,6 +51,8 @@ export class LocalThreadRuntimeCore
|
|
49
51
|
|
50
52
|
private _options!: LocalRuntimeOptionsBase;
|
51
53
|
|
54
|
+
private _lastRunConfig: RunConfig = {};
|
55
|
+
|
52
56
|
public get extras() {
|
53
57
|
return undefined;
|
54
58
|
}
|
@@ -91,14 +95,20 @@ export class LocalThreadRuntimeCore
|
|
91
95
|
|
92
96
|
const startRun = message.startRun ?? message.role === "user";
|
93
97
|
if (startRun) {
|
94
|
-
await this.startRun(
|
98
|
+
await this.startRun({
|
99
|
+
parentId: newMessage.id,
|
100
|
+
runConfig: message.runConfig ?? {},
|
101
|
+
});
|
95
102
|
} else {
|
96
103
|
this.repository.resetHead(newMessage.id);
|
97
104
|
this._notifySubscribers();
|
98
105
|
}
|
99
106
|
}
|
100
107
|
|
101
|
-
public async startRun(
|
108
|
+
public async startRun({
|
109
|
+
parentId,
|
110
|
+
runConfig,
|
111
|
+
}: StartRunConfig): Promise<void> {
|
102
112
|
this.ensureInitialized();
|
103
113
|
|
104
114
|
this.repository.resetHead(parentId);
|
@@ -117,13 +127,14 @@ export class LocalThreadRuntimeCore
|
|
117
127
|
this._notifyEventSubscribers("run-start");
|
118
128
|
|
119
129
|
do {
|
120
|
-
message = await this.performRoundtrip(parentId, message);
|
130
|
+
message = await this.performRoundtrip(parentId, message, runConfig);
|
121
131
|
} while (shouldContinue(message));
|
122
132
|
}
|
123
133
|
|
124
134
|
private async performRoundtrip(
|
125
135
|
parentId: string | null,
|
126
136
|
message: ThreadAssistantMessage,
|
137
|
+
runConfig: RunConfig | undefined,
|
127
138
|
) {
|
128
139
|
const messages = this.repository.getMessages();
|
129
140
|
|
@@ -185,8 +196,10 @@ export class LocalThreadRuntimeCore
|
|
185
196
|
}
|
186
197
|
|
187
198
|
try {
|
199
|
+
this._lastRunConfig = runConfig ?? {};
|
188
200
|
const promiseOrGenerator = this.adapters.chatModel.run({
|
189
201
|
messages,
|
202
|
+
runConfig: this._lastRunConfig,
|
190
203
|
abortSignal: this.abortController.signal,
|
191
204
|
config: this.getModelConfig(),
|
192
205
|
unstable_assistantMessageId: message.id,
|
@@ -267,7 +280,7 @@ export class LocalThreadRuntimeCore
|
|
267
280
|
this.repository.addOrUpdateMessage(parentId, message);
|
268
281
|
|
269
282
|
if (added && shouldContinue(message)) {
|
270
|
-
this.performRoundtrip(parentId, message);
|
283
|
+
this.performRoundtrip(parentId, message, this._lastRunConfig);
|
271
284
|
}
|
272
285
|
}
|
273
286
|
}
|
@@ -146,10 +146,17 @@ export type ThreadAssistantMessage = MessageCommonProps & {
|
|
146
146
|
};
|
147
147
|
};
|
148
148
|
|
149
|
+
export type RunConfig = {
|
150
|
+
// TODO allow user customization via global type overrides
|
151
|
+
readonly custom?: Record<string, unknown>;
|
152
|
+
};
|
153
|
+
|
149
154
|
export type AppendMessage = CoreMessage & {
|
150
155
|
parentId: string | null;
|
151
156
|
attachments: readonly CompleteAttachment[];
|
152
157
|
startRun?: boolean | undefined;
|
158
|
+
/** TODO: make required in 0.8.0 */
|
159
|
+
runConfig?: RunConfig | undefined;
|
153
160
|
};
|
154
161
|
|
155
162
|
type BaseThreadMessage = {
|