@assistant-ui/react 0.5.16 → 0.5.18
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +25 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -18
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
@@ -186,10 +186,13 @@ type ChatModelRunOptions = {
|
|
186
186
|
messages: ThreadMessage[];
|
187
187
|
abortSignal: AbortSignal;
|
188
188
|
config: ModelConfig;
|
189
|
+
/**
|
190
|
+
* @deprecated Declare the run function as an AsyncGenerator instead. This method will be removed in v0.6
|
191
|
+
*/
|
189
192
|
onUpdate: (result: ChatModelRunUpdate) => void;
|
190
193
|
};
|
191
194
|
type ChatModelAdapter = {
|
192
|
-
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
|
195
|
+
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>;
|
193
196
|
};
|
194
197
|
|
195
198
|
declare abstract class BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> implements AssistantRuntime {
|
@@ -296,7 +299,7 @@ type EdgeChatAdapterOptions = {
|
|
296
299
|
declare class EdgeChatAdapter implements ChatModelAdapter {
|
297
300
|
private options;
|
298
301
|
constructor(options: EdgeChatAdapterOptions);
|
299
|
-
run({ messages, abortSignal, config
|
302
|
+
run({ messages, abortSignal, config }: ChatModelRunOptions): AsyncGenerator<ChatModelRunResult, void, unknown>;
|
300
303
|
}
|
301
304
|
|
302
305
|
type EdgeRuntimeOptions = EdgeChatAdapterOptions & LocalRuntimeOptions;
|
@@ -658,7 +661,7 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
658
661
|
cancel: boolean;
|
659
662
|
copy: boolean;
|
660
663
|
};
|
661
|
-
messages:
|
664
|
+
messages: ThreadMessage[];
|
662
665
|
isDisabled: boolean;
|
663
666
|
isRunning: boolean;
|
664
667
|
constructor(store: ExternalStoreAdapter<any>);
|
package/dist/index.d.ts
CHANGED
@@ -186,10 +186,13 @@ type ChatModelRunOptions = {
|
|
186
186
|
messages: ThreadMessage[];
|
187
187
|
abortSignal: AbortSignal;
|
188
188
|
config: ModelConfig;
|
189
|
+
/**
|
190
|
+
* @deprecated Declare the run function as an AsyncGenerator instead. This method will be removed in v0.6
|
191
|
+
*/
|
189
192
|
onUpdate: (result: ChatModelRunUpdate) => void;
|
190
193
|
};
|
191
194
|
type ChatModelAdapter = {
|
192
|
-
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
|
195
|
+
run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult> | AsyncGenerator<ChatModelRunResult, void>;
|
193
196
|
};
|
194
197
|
|
195
198
|
declare abstract class BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> implements AssistantRuntime {
|
@@ -296,7 +299,7 @@ type EdgeChatAdapterOptions = {
|
|
296
299
|
declare class EdgeChatAdapter implements ChatModelAdapter {
|
297
300
|
private options;
|
298
301
|
constructor(options: EdgeChatAdapterOptions);
|
299
|
-
run({ messages, abortSignal, config
|
302
|
+
run({ messages, abortSignal, config }: ChatModelRunOptions): AsyncGenerator<ChatModelRunResult, void, unknown>;
|
300
303
|
}
|
301
304
|
|
302
305
|
type EdgeRuntimeOptions = EdgeChatAdapterOptions & LocalRuntimeOptions;
|
@@ -658,7 +661,7 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
658
661
|
cancel: boolean;
|
659
662
|
copy: boolean;
|
660
663
|
};
|
661
|
-
messages:
|
664
|
+
messages: ThreadMessage[];
|
662
665
|
isDisabled: boolean;
|
663
666
|
isRunning: boolean;
|
664
667
|
constructor(store: ExternalStoreAdapter<any>);
|
package/dist/index.js
CHANGED
@@ -3428,7 +3428,7 @@ var EdgeChatAdapter = class {
|
|
3428
3428
|
constructor(options) {
|
3429
3429
|
this.options = options;
|
3430
3430
|
}
|
3431
|
-
async run({ messages, abortSignal, config
|
3431
|
+
async *run({ messages, abortSignal, config }) {
|
3432
3432
|
const result = await fetch(this.options.api, {
|
3433
3433
|
method: "POST",
|
3434
3434
|
headers: {
|
@@ -3449,11 +3449,10 @@ var EdgeChatAdapter = class {
|
|
3449
3449
|
const stream = result.body.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(assistantDecoderStream()).pipeThrough(toolResultStream(config.tools)).pipeThrough(runResultStream());
|
3450
3450
|
let update;
|
3451
3451
|
for await (update of asAsyncIterable(stream)) {
|
3452
|
-
|
3452
|
+
yield update;
|
3453
3453
|
}
|
3454
3454
|
if (update === void 0)
|
3455
3455
|
throw new Error("No data received from Edge Runtime");
|
3456
|
-
return update;
|
3457
3456
|
}
|
3458
3457
|
};
|
3459
3458
|
|
@@ -3572,21 +3571,27 @@ var LocalThreadRuntime = class {
|
|
3572
3571
|
});
|
3573
3572
|
}
|
3574
3573
|
try {
|
3575
|
-
const
|
3574
|
+
const promiseOrGenerator = this.adapter.run({
|
3576
3575
|
messages,
|
3577
3576
|
abortSignal: this.abortController.signal,
|
3578
3577
|
config: this.configProvider.getModelConfig(),
|
3579
3578
|
onUpdate: updateMessage
|
3580
3579
|
});
|
3581
|
-
if (
|
3582
|
-
|
3583
|
-
|
3584
|
-
|
3580
|
+
if (Symbol.asyncIterator in promiseOrGenerator) {
|
3581
|
+
for await (const r of promiseOrGenerator) {
|
3582
|
+
updateMessage(r);
|
3583
|
+
}
|
3584
|
+
} else {
|
3585
|
+
updateMessage(await promiseOrGenerator);
|
3586
|
+
}
|
3585
3587
|
this.abortController = null;
|
3586
|
-
|
3587
|
-
|
3588
|
-
|
3589
|
-
|
3588
|
+
if (message.status.type === "running") {
|
3589
|
+
updateMessage({
|
3590
|
+
status: { type: "complete", reason: "unknown" }
|
3591
|
+
});
|
3592
|
+
} else {
|
3593
|
+
this.notifySubscribers();
|
3594
|
+
}
|
3590
3595
|
} catch (e) {
|
3591
3596
|
this.abortController = null;
|
3592
3597
|
if (e instanceof Error && e.name === "AbortError") {
|
@@ -3827,9 +3832,11 @@ var hasUpcomingMessage = (isRunning, messages) => {
|
|
3827
3832
|
var ExternalStoreThreadRuntime = class {
|
3828
3833
|
constructor(store) {
|
3829
3834
|
this.store = store;
|
3830
|
-
this.
|
3831
|
-
|
3832
|
-
|
3835
|
+
this.updateData(
|
3836
|
+
store.isDisabled ?? false,
|
3837
|
+
store.isRunning ?? false,
|
3838
|
+
store.messages
|
3839
|
+
);
|
3833
3840
|
this.useStore = (0, import_zustand14.create)(() => ({
|
3834
3841
|
store
|
3835
3842
|
}));
|
@@ -3847,9 +3854,9 @@ var ExternalStoreThreadRuntime = class {
|
|
3847
3854
|
copy: this.store.onCopy !== null
|
3848
3855
|
};
|
3849
3856
|
}
|
3850
|
-
messages;
|
3851
|
-
isDisabled;
|
3852
|
-
isRunning;
|
3857
|
+
messages = [];
|
3858
|
+
isDisabled = false;
|
3859
|
+
isRunning = false;
|
3853
3860
|
getBranches(messageId) {
|
3854
3861
|
return this.repository.getBranches(messageId);
|
3855
3862
|
}
|