@assistant-ui/react 0.7.65 → 0.7.66
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/api/ThreadListItemRuntime.d.ts +2 -0
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +5 -0
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +5 -0
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/cloud/AssistantCloudThreads.d.ts +1 -1
- package/dist/cloud/AssistantCloudThreads.d.ts.map +1 -1
- package/dist/cloud/AssistantCloudThreads.js.map +1 -1
- package/dist/cloud/AssistantCloudThreads.mjs.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.js +8 -83
- package/dist/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.mjs +8 -89
- package/dist/cloud/useCloudThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts +22 -3
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +44 -13
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +34 -13
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +3 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +3 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +1 -0
- package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts +4 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.js +2 -0
- package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.mjs +2 -0
- package/dist/runtimes/local/LocalRuntimeOptions.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +21 -31
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +43 -147
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +43 -147
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +4 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +4 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +10 -1
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +10 -1
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +4 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs +4 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +6 -6
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +25 -23
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +25 -23
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts +13 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.js +96 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs +76 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +12 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js +58 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.mjs +35 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/index.d.ts +2 -1
- package/dist/runtimes/remote-thread-list/index.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/index.js +3 -0
- package/dist/runtimes/remote-thread-list/index.js.map +1 -1
- package/dist/runtimes/remote-thread-list/index.mjs +2 -0
- package/dist/runtimes/remote-thread-list/index.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -6
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/types.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts +2 -2
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +7 -7
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +7 -7
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/ThreadListItemRuntime.ts +8 -0
- package/src/cloud/AssistantCloudThreads.tsx +1 -1
- package/src/cloud/useCloudThreadListRuntime.tsx +8 -110
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +1 -0
- package/src/runtimes/edge/EdgeChatAdapter.ts +90 -19
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -0
- package/src/runtimes/local/ChatModelAdapter.tsx +1 -0
- package/src/runtimes/local/LocalRuntimeOptions.tsx +4 -0
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +47 -190
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +3 -0
- package/src/runtimes/local/useLocalRuntime.tsx +15 -2
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +7 -0
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +27 -28
- package/src/runtimes/remote-thread-list/adapter/cloud.tsx +99 -0
- package/src/runtimes/remote-thread-list/adapter/in-memory.tsx +43 -0
- package/src/runtimes/remote-thread-list/index.ts +3 -4
- package/src/runtimes/remote-thread-list/types.tsx +10 -12
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +8 -8
|
@@ -4,7 +4,7 @@ import { ThreadListRuntimeCore } from "../core/ThreadListRuntimeCore";
|
|
|
4
4
|
import { generateId } from "../../internal";
|
|
5
5
|
import {
|
|
6
6
|
RemoteThreadInitializeResponse,
|
|
7
|
-
|
|
7
|
+
RemoteThreadListOptions,
|
|
8
8
|
} from "./types";
|
|
9
9
|
import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager";
|
|
10
10
|
import { BaseSubscribable } from "./BaseSubscribable";
|
|
@@ -12,7 +12,7 @@ import { EMPTY_THREAD_CORE } from "./EMPTY_THREAD_CORE";
|
|
|
12
12
|
import { OptimisticState } from "./OptimisticState";
|
|
13
13
|
import { FC, Fragment, useEffect, useId } from "react";
|
|
14
14
|
import { create } from "zustand";
|
|
15
|
-
import {
|
|
15
|
+
import { AssistantMessageStream } from "assistant-stream";
|
|
16
16
|
import { ModelContextProvider } from "../../model-context";
|
|
17
17
|
import { RuntimeAdapterProvider } from "../adapters/RuntimeAdapterProvider";
|
|
18
18
|
|
|
@@ -141,7 +141,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
141
141
|
extends BaseSubscribable
|
|
142
142
|
implements ThreadListRuntimeCore
|
|
143
143
|
{
|
|
144
|
-
private
|
|
144
|
+
private _options!: RemoteThreadListOptions;
|
|
145
145
|
private readonly _hookManager: RemoteThreadListHookInstanceManager;
|
|
146
146
|
|
|
147
147
|
private _loadThreadsPromise: Promise<void> | undefined;
|
|
@@ -161,7 +161,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
161
161
|
if (!this._loadThreadsPromise) {
|
|
162
162
|
this._loadThreadsPromise = this._state
|
|
163
163
|
.optimisticUpdate({
|
|
164
|
-
execute: () => this.
|
|
164
|
+
execute: () => this._options.adapter.list(),
|
|
165
165
|
loading: (state) => {
|
|
166
166
|
return {
|
|
167
167
|
...state,
|
|
@@ -228,43 +228,40 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
constructor(
|
|
231
|
-
|
|
231
|
+
options: RemoteThreadListOptions,
|
|
232
232
|
private readonly contextProvider: ModelContextProvider,
|
|
233
233
|
) {
|
|
234
234
|
super();
|
|
235
235
|
|
|
236
236
|
this._state.subscribe(() => this._notifySubscribers());
|
|
237
237
|
this._hookManager = new RemoteThreadListHookInstanceManager(
|
|
238
|
-
|
|
238
|
+
options.runtimeHook,
|
|
239
239
|
);
|
|
240
240
|
this.useProvider = create(() => ({
|
|
241
|
-
Provider: adapter.unstable_Provider ?? Fragment,
|
|
241
|
+
Provider: options.adapter.unstable_Provider ?? Fragment,
|
|
242
242
|
}));
|
|
243
|
-
this.
|
|
243
|
+
this.__internal_setOptions(options);
|
|
244
244
|
|
|
245
245
|
this.switchToNewThread();
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
private useProvider;
|
|
249
249
|
|
|
250
|
-
public
|
|
251
|
-
if (this.
|
|
250
|
+
public __internal_setOptions(options: RemoteThreadListOptions) {
|
|
251
|
+
if (this._options === options) return;
|
|
252
252
|
|
|
253
|
-
this.
|
|
253
|
+
this._options = options;
|
|
254
254
|
|
|
255
|
-
const Provider = adapter.unstable_Provider ?? Fragment;
|
|
255
|
+
const Provider = options.adapter.unstable_Provider ?? Fragment;
|
|
256
256
|
if (Provider !== this.useProvider.getState().Provider) {
|
|
257
257
|
this.useProvider.setState({ Provider }, true);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
this._hookManager.setRuntimeHook(
|
|
260
|
+
this._hookManager.setRuntimeHook(options.runtimeHook);
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
public
|
|
263
|
+
public __internal_load() {
|
|
264
264
|
this.getLoadThreadsPromise(); // begin loading on initial bind
|
|
265
|
-
return this._adapter.subscribe?.({
|
|
266
|
-
onGenerateTitle: this._onGenerateTitle,
|
|
267
|
-
});
|
|
268
265
|
}
|
|
269
266
|
|
|
270
267
|
public get threadIds() {
|
|
@@ -368,7 +365,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
368
365
|
|
|
369
366
|
return this._state.optimisticUpdate({
|
|
370
367
|
execute: () => {
|
|
371
|
-
return this.
|
|
368
|
+
return this._options.adapter.initialize(threadId);
|
|
372
369
|
},
|
|
373
370
|
optimistic: (state) => {
|
|
374
371
|
return updateStatusReducer(state, threadId, "regular");
|
|
@@ -411,15 +408,17 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
411
408
|
});
|
|
412
409
|
};
|
|
413
410
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
begin: () => Promise<AssistantStream>,
|
|
417
|
-
) => {
|
|
418
|
-
const data = this.getItemById(remoteId);
|
|
411
|
+
public generateTitle = async (threadId: string) => {
|
|
412
|
+
const data = this.getItemById(threadId);
|
|
419
413
|
if (!data) throw new Error("Thread not found");
|
|
420
414
|
if (data.status === "new") throw new Error("Thread is not yet initialized");
|
|
421
415
|
|
|
422
|
-
const
|
|
416
|
+
const { remoteId } = await data.initializeTask;
|
|
417
|
+
const messages = this.getThreadRuntimeCore(threadId).messages;
|
|
418
|
+
const stream = await this._options.adapter.generateTitle(
|
|
419
|
+
remoteId,
|
|
420
|
+
messages,
|
|
421
|
+
);
|
|
423
422
|
const messageStream = AssistantMessageStream.fromAssistantStream(stream);
|
|
424
423
|
for await (const result of messageStream) {
|
|
425
424
|
const newTitle =
|
|
@@ -447,7 +446,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
447
446
|
return this._state.optimisticUpdate({
|
|
448
447
|
execute: async () => {
|
|
449
448
|
const { remoteId } = await data.initializeTask;
|
|
450
|
-
return this.
|
|
449
|
+
return this._options.adapter.rename(remoteId, newTitle);
|
|
451
450
|
},
|
|
452
451
|
optimistic: (state) => {
|
|
453
452
|
const data = getThreadData(state, threadIdOrRemoteId);
|
|
@@ -484,7 +483,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
484
483
|
execute: async () => {
|
|
485
484
|
await this._ensureThreadIsNotMain(data.threadId);
|
|
486
485
|
const { remoteId } = await data.initializeTask;
|
|
487
|
-
return this.
|
|
486
|
+
return this._options.adapter.archive(remoteId);
|
|
488
487
|
},
|
|
489
488
|
optimistic: (state) => {
|
|
490
489
|
return updateStatusReducer(state, data.threadId, "archived");
|
|
@@ -501,7 +500,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
501
500
|
execute: async () => {
|
|
502
501
|
try {
|
|
503
502
|
const { remoteId } = await data.initializeTask;
|
|
504
|
-
return await this.
|
|
503
|
+
return await this._options.adapter.unarchive(remoteId);
|
|
505
504
|
} catch (error) {
|
|
506
505
|
await this._ensureThreadIsNotMain(data.threadId);
|
|
507
506
|
throw error;
|
|
@@ -523,7 +522,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
523
522
|
execute: async () => {
|
|
524
523
|
await this._ensureThreadIsNotMain(data.threadId);
|
|
525
524
|
const { remoteId } = await data.initializeTask;
|
|
526
|
-
return await this.
|
|
525
|
+
return await this._options.adapter.delete(remoteId);
|
|
527
526
|
},
|
|
528
527
|
optimistic: (state) => {
|
|
529
528
|
return updateStatusReducer(state, data.threadId, "deleted");
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FC,
|
|
3
|
+
PropsWithChildren,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { AssistantCloud } from "../../../cloud";
|
|
10
|
+
import { RemoteThreadListAdapter } from "../types";
|
|
11
|
+
import { useAssistantCloudThreadHistoryAdapter } from "../../../cloud/AssistantCloudThreadHistoryAdapter";
|
|
12
|
+
import { RuntimeAdapterProvider } from "../../adapters/RuntimeAdapterProvider";
|
|
13
|
+
import { toCoreMessages } from "../../edge";
|
|
14
|
+
import { InMemoryThreadListAdapter } from "./in-memory";
|
|
15
|
+
|
|
16
|
+
type ThreadData = {
|
|
17
|
+
externalId: string;
|
|
18
|
+
};
|
|
19
|
+
type CloudThreadListAdapterOptions = {
|
|
20
|
+
cloud?: AssistantCloud | undefined;
|
|
21
|
+
|
|
22
|
+
create?(): Promise<ThreadData>;
|
|
23
|
+
delete?(threadId: string): Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const useCloudThreadListAdapter = (
|
|
27
|
+
adapter: CloudThreadListAdapterOptions,
|
|
28
|
+
): RemoteThreadListAdapter => {
|
|
29
|
+
const adapterRef = useRef(adapter);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
adapterRef.current = adapter;
|
|
32
|
+
}, [adapter]);
|
|
33
|
+
|
|
34
|
+
const cloud = adapter.cloud;
|
|
35
|
+
if (!cloud) return new InMemoryThreadListAdapter();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
list: async () => {
|
|
39
|
+
const { threads } = await cloud.threads.list();
|
|
40
|
+
return {
|
|
41
|
+
threads: threads.map((t) => ({
|
|
42
|
+
status: t.is_archived ? "archived" : "regular",
|
|
43
|
+
remoteId: t.id,
|
|
44
|
+
title: t.title,
|
|
45
|
+
externalId: t.external_id ?? undefined,
|
|
46
|
+
})),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
initialize: async () => {
|
|
51
|
+
const createTask = adapter.create?.() ?? Promise.resolve();
|
|
52
|
+
const t = await createTask;
|
|
53
|
+
const external_id = t ? t.externalId : undefined;
|
|
54
|
+
const { thread_id: remoteId } = await cloud.threads.create({
|
|
55
|
+
last_message_at: new Date(),
|
|
56
|
+
external_id,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return { externalId: external_id, remoteId: remoteId };
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
rename: async (threadId, newTitle) => {
|
|
63
|
+
return cloud.threads.update(threadId, { title: newTitle });
|
|
64
|
+
},
|
|
65
|
+
archive: async (threadId) => {
|
|
66
|
+
return cloud.threads.update(threadId, { is_archived: true });
|
|
67
|
+
},
|
|
68
|
+
unarchive: async (threadId) => {
|
|
69
|
+
return cloud.threads.update(threadId, { is_archived: false });
|
|
70
|
+
},
|
|
71
|
+
delete: async (threadId) => {
|
|
72
|
+
await adapter.delete?.(threadId);
|
|
73
|
+
return cloud.threads.delete(threadId);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
generateTitle: async (threadId, messages) => {
|
|
77
|
+
return cloud.runs.stream({
|
|
78
|
+
thread_id: threadId,
|
|
79
|
+
assistant_id: "system/thread_title",
|
|
80
|
+
messages: toCoreMessages(messages),
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
unstable_Provider: useCallback<FC<PropsWithChildren>>(({ children }) => {
|
|
85
|
+
const history = useAssistantCloudThreadHistoryAdapter({
|
|
86
|
+
get current() {
|
|
87
|
+
return adapterRef.current.cloud!;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const adapters = useMemo(() => ({ history }), [history]);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<RuntimeAdapterProvider adapters={adapters}>
|
|
94
|
+
{children}
|
|
95
|
+
</RuntimeAdapterProvider>
|
|
96
|
+
);
|
|
97
|
+
}, []),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssistantStream,
|
|
3
|
+
AssistantStreamChunk,
|
|
4
|
+
} from "@assistant-ui/assistant-stream";
|
|
5
|
+
import {
|
|
6
|
+
RemoteThreadInitializeResponse,
|
|
7
|
+
RemoteThreadListAdapter,
|
|
8
|
+
RemoteThreadListResponse,
|
|
9
|
+
} from "../types";
|
|
10
|
+
|
|
11
|
+
export class InMemoryThreadListAdapter implements RemoteThreadListAdapter {
|
|
12
|
+
list(): Promise<RemoteThreadListResponse> {
|
|
13
|
+
return Promise.resolve({
|
|
14
|
+
threads: [],
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
rename(): Promise<void> {
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
archive(): Promise<void> {
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
unarchive(): Promise<void> {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
delete(): Promise<void> {
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
initialize(threadId: string): Promise<RemoteThreadInitializeResponse> {
|
|
35
|
+
return Promise.resolve({ remoteId: threadId, externalId: undefined });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
generateTitle(): Promise<AssistantStream> {
|
|
39
|
+
return Promise.resolve(
|
|
40
|
+
new AssistantStream(new ReadableStream<AssistantStreamChunk>()),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { useRemoteThreadListRuntime as unstable_useRemoteThreadListRuntime } from "./useRemoteThreadListRuntime";
|
|
2
|
-
export type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./types";
|
|
2
|
+
export type { RemoteThreadListAdapter as unstable_RemoteThreadListAdapter } from "./types";
|
|
3
|
+
|
|
4
|
+
export { InMemoryThreadListAdapter as unstable_InMemoryThreadListAdapter } from "./adapter/in-memory";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentType, PropsWithChildren } from "react";
|
|
2
2
|
import { AssistantRuntime } from "../../api";
|
|
3
|
-
import { Unsubscribe } from "../../types";
|
|
4
3
|
import { AssistantStream } from "assistant-stream";
|
|
4
|
+
import { ThreadMessage } from "../../types";
|
|
5
5
|
|
|
6
6
|
export type RemoteThreadInitializeResponse = {
|
|
7
7
|
remoteId: string;
|
|
@@ -19,16 +19,7 @@ export type RemoteThreadListResponse = {
|
|
|
19
19
|
threads: RemoteThreadMetadata[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type RemoteThreadListSubscriber = {
|
|
23
|
-
onGenerateTitle: (
|
|
24
|
-
threadId: string,
|
|
25
|
-
begin: () => Promise<AssistantStream>,
|
|
26
|
-
) => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
22
|
export type RemoteThreadListAdapter = {
|
|
30
|
-
runtimeHook: () => AssistantRuntime;
|
|
31
|
-
|
|
32
23
|
list(): Promise<RemoteThreadListResponse>;
|
|
33
24
|
|
|
34
25
|
rename(remoteId: string, newTitle: string): Promise<void>;
|
|
@@ -36,8 +27,15 @@ export type RemoteThreadListAdapter = {
|
|
|
36
27
|
unarchive(remoteId: string): Promise<void>;
|
|
37
28
|
delete(remoteId: string): Promise<void>;
|
|
38
29
|
initialize(threadId: string): Promise<RemoteThreadInitializeResponse>;
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
generateTitle(
|
|
31
|
+
remoteId: string,
|
|
32
|
+
unstable_messages: readonly ThreadMessage[],
|
|
33
|
+
): Promise<AssistantStream>;
|
|
41
34
|
|
|
42
35
|
unstable_Provider?: ComponentType<PropsWithChildren>;
|
|
43
36
|
};
|
|
37
|
+
|
|
38
|
+
export type RemoteThreadListOptions = {
|
|
39
|
+
runtimeHook: () => AssistantRuntime;
|
|
40
|
+
adapter: RemoteThreadListAdapter;
|
|
41
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useState, useEffect, useMemo } from "react";
|
|
4
4
|
import { BaseAssistantRuntimeCore } from "../core/BaseAssistantRuntimeCore";
|
|
5
5
|
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore";
|
|
6
|
-
import {
|
|
6
|
+
import { RemoteThreadListOptions } from "./types";
|
|
7
7
|
import { AssistantRuntimeImpl } from "../../internal";
|
|
8
8
|
import { AssistantRuntimeCore } from "../core/AssistantRuntimeCore";
|
|
9
9
|
|
|
@@ -13,10 +13,10 @@ class RemoteThreadListRuntimeCore
|
|
|
13
13
|
{
|
|
14
14
|
public readonly threads;
|
|
15
15
|
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(options: RemoteThreadListOptions) {
|
|
17
17
|
super();
|
|
18
18
|
this.threads = new RemoteThreadListThreadListRuntimeCore(
|
|
19
|
-
|
|
19
|
+
options,
|
|
20
20
|
this._contextProvider,
|
|
21
21
|
);
|
|
22
22
|
}
|
|
@@ -27,12 +27,12 @@ class RemoteThreadListRuntimeCore
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const useRemoteThreadListRuntime = (
|
|
30
|
-
|
|
30
|
+
options: RemoteThreadListOptions,
|
|
31
31
|
) => {
|
|
32
|
-
const [runtime] = useState(() => new RemoteThreadListRuntimeCore(
|
|
32
|
+
const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
|
|
33
33
|
useEffect(() => {
|
|
34
|
-
runtime.threads.
|
|
35
|
-
|
|
36
|
-
}, [runtime,
|
|
34
|
+
runtime.threads.__internal_setOptions(options);
|
|
35
|
+
runtime.threads.__internal_load();
|
|
36
|
+
}, [runtime, options]);
|
|
37
37
|
return useMemo(() => AssistantRuntimeImpl.create(runtime), [runtime]);
|
|
38
38
|
};
|