@assistant-ui/react 0.7.23 → 0.7.25
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/AssistantRuntime.d.ts +1 -1
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +1 -1
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +1 -1
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/api/ComposerRuntime.d.ts +4 -2
- package/dist/api/ComposerRuntime.d.ts.map +1 -1
- package/dist/api/ComposerRuntime.js +6 -1
- package/dist/api/ComposerRuntime.js.map +1 -1
- package/dist/api/ComposerRuntime.mjs +6 -1
- package/dist/api/ComposerRuntime.mjs.map +1 -1
- package/dist/api/ThreadListItemRuntime.d.ts +3 -1
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/api/ThreadListRuntime.d.ts +8 -8
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +7 -5
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadListRuntime.mjs +7 -5
- package/dist/api/ThreadListRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +59 -32
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +2 -2
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +2 -2
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +8 -3
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +8 -3
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.js +2 -4
- package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.mjs +2 -4
- package/dist/primitives/threadList/ThreadListItems.mjs.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +6 -6
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +29 -20
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +29 -20
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +2 -3
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +2 -3
- package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.mjs +1 -1
- package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts +2 -0
- package/dist/runtimes/core/AssistantRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/AssistantRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts +2 -1
- package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +4 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.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/ExternalStoreThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +5 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +5 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/index.d.ts +5 -4
- package/dist/runtimes/index.d.ts.map +1 -1
- package/dist/runtimes/index.js +11 -9
- package/dist/runtimes/index.js.map +1 -1
- package/dist/runtimes/index.mjs +5 -4
- package/dist/runtimes/index.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +2 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +12 -8
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +12 -8
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/BaseSubscribable.d.ts +8 -0
- package/dist/runtimes/remote-thread-list/BaseSubscribable.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/BaseSubscribable.js +62 -0
- package/dist/runtimes/remote-thread-list/BaseSubscribable.js.map +1 -0
- package/dist/runtimes/remote-thread-list/BaseSubscribable.mjs +37 -0
- package/dist/runtimes/remote-thread-list/BaseSubscribable.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts +3 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +150 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs +125 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.d.ts +23 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.js +83 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.js.map +1 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.mjs +58 -0
- package/dist/runtimes/remote-thread-list/OptimisticState.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +75 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +127 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs +102 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +76 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +396 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +371 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.d.ts +7 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.js +39 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.mjs +14 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts +19 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js +79 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs +57 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts +20 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js +95 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs +69 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.d.ts +46 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.js +50 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.mjs +25 -0
- package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.d.ts +10 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.js +32 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.mjs +7 -0
- package/dist/runtimes/remote-thread-list/cloud/CloudContext.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/index.d.ts +4 -0
- package/dist/runtimes/remote-thread-list/cloud/index.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/index.js +37 -0
- package/dist/runtimes/remote-thread-list/cloud/index.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/index.mjs +10 -0
- package/dist/runtimes/remote-thread-list/cloud/index.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.d.ts +4 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.js +46 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.mjs +22 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts +14 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js +103 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js.map +1 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs +79 -0
- package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/index.d.ts +2 -0
- package/dist/runtimes/remote-thread-list/index.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/index.js +25 -0
- package/dist/runtimes/remote-thread-list/index.js.map +1 -0
- package/dist/runtimes/remote-thread-list/index.mjs +3 -0
- package/dist/runtimes/remote-thread-list/index.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +25 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/types.js +19 -0
- package/dist/runtimes/remote-thread-list/types.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.mjs +1 -0
- package/dist/runtimes/remote-thread-list/types.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts +3 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +51 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +26 -0
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -0
- package/dist/styles/index.css +2 -0
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/tailwindcss/thread.css +5 -1
- package/dist/styles/tailwindcss/thread.css.json +4 -1
- package/dist/ui/attachment-ui.d.ts.map +1 -1
- package/dist/ui/attachment-ui.js +12 -7
- package/dist/ui/attachment-ui.js.map +1 -1
- package/dist/ui/attachment-ui.mjs +12 -7
- package/dist/ui/attachment-ui.mjs.map +1 -1
- package/dist/utils/createActionButton.d.ts +2 -2
- package/dist/utils/createActionButton.d.ts.map +1 -1
- package/dist/utils/createActionButton.js +2 -4
- package/dist/utils/createActionButton.js.map +1 -1
- package/dist/utils/createActionButton.mjs +5 -5
- package/dist/utils/createActionButton.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/AssistantRuntime.ts +2 -6
- package/src/api/ComposerRuntime.ts +10 -2
- package/src/api/ThreadListItemRuntime.ts +3 -1
- package/src/api/ThreadListRuntime.ts +11 -9
- package/src/api/ThreadRuntime.ts +3 -3
- package/src/context/providers/AssistantRuntimeProvider.tsx +21 -6
- package/src/primitives/threadList/ThreadListItems.tsx +3 -5
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +43 -25
- package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +2 -3
- package/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx +1 -1
- package/src/runtimes/core/AssistantRuntimeCore.tsx +3 -0
- package/src/runtimes/core/ComposerRuntimeCore.tsx +2 -1
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +5 -2
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +1 -1
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +6 -1
- package/src/runtimes/index.ts +5 -4
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +14 -9
- package/src/runtimes/remote-thread-list/BaseSubscribable.tsx +38 -0
- package/src/runtimes/remote-thread-list/EMPTY_THREAD_CORE.tsx +158 -0
- package/src/runtimes/remote-thread-list/OptimisticState.ts +82 -0
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +132 -0
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +486 -0
- package/src/runtimes/remote-thread-list/cloud/AssistantCloud.tsx +11 -0
- package/src/runtimes/remote-thread-list/cloud/AssistantCloudAPI.tsx +81 -0
- package/src/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.tsx +95 -0
- package/src/runtimes/remote-thread-list/cloud/AssistantCloudThreads.tsx +72 -0
- package/src/runtimes/remote-thread-list/cloud/CloudContext.tsx +12 -0
- package/src/runtimes/remote-thread-list/cloud/index.ts +3 -0
- package/src/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.tsx +19 -0
- package/src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx +100 -0
- package/src/runtimes/remote-thread-list/index.ts +2 -0
- package/src/runtimes/remote-thread-list/types.tsx +34 -0
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +28 -0
- package/src/styles/tailwindcss/thread.css +5 -1
- package/src/ui/attachment-ui.tsx +20 -14
- package/src/utils/createActionButton.tsx +11 -6
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"conversational-ui",
|
|
30
30
|
"conversational-ai"
|
|
31
31
|
],
|
|
32
|
-
"version": "0.7.
|
|
32
|
+
"version": "0.7.25",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
@@ -120,9 +120,9 @@
|
|
|
120
120
|
"tailwindcss-animate": "^1.0.7",
|
|
121
121
|
"tsup": "8.3.5",
|
|
122
122
|
"tsx": "^4.19.2",
|
|
123
|
+
"@assistant-ui/tsbuildutils": "^0.0.1",
|
|
123
124
|
"@assistant-ui/tailwindcss-transformer": "0.1.0",
|
|
124
|
-
"@assistant-ui/tsconfig": "0.0.0"
|
|
125
|
-
"@assistant-ui/tsbuildutils": "^0.0.1"
|
|
125
|
+
"@assistant-ui/tsconfig": "0.0.0"
|
|
126
126
|
},
|
|
127
127
|
"publishConfig": {
|
|
128
128
|
"access": "public",
|
|
@@ -41,11 +41,7 @@ export type AssistantRuntime = {
|
|
|
41
41
|
registerModelConfigProvider(provider: ModelConfigProvider): Unsubscribe;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export class AssistantRuntimeImpl
|
|
45
|
-
implements
|
|
46
|
-
Omit<AssistantRuntimeCore, "thread" | "threadList">,
|
|
47
|
-
AssistantRuntime
|
|
48
|
-
{
|
|
44
|
+
export class AssistantRuntimeImpl implements AssistantRuntime {
|
|
49
45
|
public readonly threadList;
|
|
50
46
|
public readonly _thread: ThreadRuntime;
|
|
51
47
|
|
|
@@ -66,7 +62,7 @@ export class AssistantRuntimeImpl
|
|
|
66
62
|
getState: () => _core.threadList.getMainThreadRuntimeCore(),
|
|
67
63
|
subscribe: (callback) => _core.threadList.subscribe(callback),
|
|
68
64
|
}),
|
|
69
|
-
this.threadList.
|
|
65
|
+
this.threadList.mainItem, // TODO capture "main" threadListItem from context around useLocalRuntime / useExternalStoreRuntime
|
|
70
66
|
);
|
|
71
67
|
}
|
|
72
68
|
|
|
@@ -108,7 +108,9 @@ export type ComposerRuntime = {
|
|
|
108
108
|
setRole(role: MessageRole): void;
|
|
109
109
|
setRunConfig(runConfig: RunConfig): void;
|
|
110
110
|
|
|
111
|
-
reset(): void
|
|
111
|
+
reset(): Promise<void>;
|
|
112
|
+
clearAttachments(): Promise<void>;
|
|
113
|
+
|
|
112
114
|
send(): void;
|
|
113
115
|
cancel(): void;
|
|
114
116
|
subscribe(callback: () => void): Unsubscribe;
|
|
@@ -147,7 +149,13 @@ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
|
|
|
147
149
|
public reset() {
|
|
148
150
|
const core = this._core.getState();
|
|
149
151
|
if (!core) throw new Error("Composer is not available");
|
|
150
|
-
core.reset();
|
|
152
|
+
return core.reset();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public clearAttachments() {
|
|
156
|
+
const core = this._core.getState();
|
|
157
|
+
if (!core) throw new Error("Composer is not available");
|
|
158
|
+
return core.clearAttachments();
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
public send() {
|
|
@@ -9,13 +9,15 @@ export type ThreadListItemState = {
|
|
|
9
9
|
readonly isMain: boolean;
|
|
10
10
|
|
|
11
11
|
readonly id: string;
|
|
12
|
+
readonly remoteId: string | undefined;
|
|
13
|
+
readonly externalId: string | undefined;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @deprecated This field was renamed to `id`. This field will be removed in 0.8.0.
|
|
15
17
|
*/
|
|
16
18
|
readonly threadId: string;
|
|
17
19
|
|
|
18
|
-
readonly
|
|
20
|
+
readonly status: "archived" | "regular" | "new" | "deleted";
|
|
19
21
|
readonly title?: string | undefined;
|
|
20
22
|
};
|
|
21
23
|
|
|
@@ -21,10 +21,10 @@ export type ThreadListRuntime = {
|
|
|
21
21
|
|
|
22
22
|
subscribe(callback: () => void): Unsubscribe;
|
|
23
23
|
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
readonly mainItem: ThreadListItemRuntime;
|
|
25
|
+
getItemById(threadId: string): ThreadListItemRuntime;
|
|
26
|
+
getItemByIndex(idx: number): ThreadListItemRuntime;
|
|
27
|
+
getArchivedItemByIndex(idx: number): ThreadListItemRuntime;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const getThreadListState = (
|
|
@@ -49,8 +49,10 @@ const getThreadListItemState = (
|
|
|
49
49
|
return {
|
|
50
50
|
id: threadData.threadId,
|
|
51
51
|
threadId: threadData.threadId, // TODO remove in 0.8.0
|
|
52
|
+
remoteId: threadData.remoteId,
|
|
53
|
+
externalId: threadData.externalId,
|
|
52
54
|
title: threadData.title,
|
|
53
|
-
|
|
55
|
+
status: threadData.status,
|
|
54
56
|
isMain: threadData.threadId === threadList.mainThreadId,
|
|
55
57
|
};
|
|
56
58
|
};
|
|
@@ -93,11 +95,11 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
93
95
|
|
|
94
96
|
private _mainThreadListItemRuntime;
|
|
95
97
|
|
|
96
|
-
public get
|
|
98
|
+
public get mainItem() {
|
|
97
99
|
return this._mainThreadListItemRuntime;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
public
|
|
102
|
+
public getItemByIndex(idx: number) {
|
|
101
103
|
return new ThreadListItemRuntimeImpl(
|
|
102
104
|
new ShallowMemoizeSubject({
|
|
103
105
|
path: {
|
|
@@ -113,7 +115,7 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
113
115
|
);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
public
|
|
118
|
+
public getArchivedItemByIndex(idx: number) {
|
|
117
119
|
return new ThreadListItemRuntimeImpl(
|
|
118
120
|
new ShallowMemoizeSubject({
|
|
119
121
|
path: {
|
|
@@ -132,7 +134,7 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
132
134
|
);
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
public
|
|
137
|
+
public getItemById(threadId: string) {
|
|
136
138
|
return new ThreadListItemRuntimeImpl(
|
|
137
139
|
new ShallowMemoizeSubject({
|
|
138
140
|
path: {
|
package/src/api/ThreadRuntime.ts
CHANGED
|
@@ -215,11 +215,11 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
215
215
|
return this._threadBinding.path;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
public
|
|
219
|
-
return this._threadBinding
|
|
218
|
+
public get __internal_threadBinding() {
|
|
219
|
+
return this._threadBinding;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
private _threadBinding: ThreadRuntimeCoreBinding & {
|
|
222
|
+
private readonly _threadBinding: ThreadRuntimeCoreBinding & {
|
|
223
223
|
getStateState(): ThreadState;
|
|
224
224
|
};
|
|
225
225
|
|
|
@@ -8,6 +8,7 @@ import { ThreadRuntimeProvider } from "./ThreadRuntimeProvider";
|
|
|
8
8
|
import { AssistantRuntime } from "../../api/AssistantRuntime";
|
|
9
9
|
import { create } from "zustand";
|
|
10
10
|
import { writableStore } from "../ReadonlyStore";
|
|
11
|
+
import { AssistantRuntimeCore } from "../../runtimes/core/AssistantRuntimeCore";
|
|
11
12
|
|
|
12
13
|
export namespace AssistantRuntimeProvider {
|
|
13
14
|
export type Props = PropsWithChildren<{
|
|
@@ -45,6 +46,16 @@ const useThreadListStore = (runtime: AssistantRuntime) => {
|
|
|
45
46
|
return store;
|
|
46
47
|
};
|
|
47
48
|
|
|
49
|
+
const DEFAULT_RENDER_COMPONENT: FC<PropsWithChildren> = ({ children }) =>
|
|
50
|
+
children;
|
|
51
|
+
|
|
52
|
+
const getRenderComponent = (runtime: AssistantRuntime) => {
|
|
53
|
+
return (
|
|
54
|
+
(runtime as { _core?: AssistantRuntimeCore })._core
|
|
55
|
+
?.__internal_RenderComponent ?? DEFAULT_RENDER_COMPONENT
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
48
59
|
export const AssistantRuntimeProviderImpl: FC<
|
|
49
60
|
AssistantRuntimeProvider.Props
|
|
50
61
|
> = ({ children, runtime }) => {
|
|
@@ -59,14 +70,18 @@ export const AssistantRuntimeProviderImpl: FC<
|
|
|
59
70
|
};
|
|
60
71
|
}, [useAssistantRuntime, useToolUIs, useThreadList]);
|
|
61
72
|
|
|
73
|
+
const RenderComponent = getRenderComponent(runtime);
|
|
74
|
+
|
|
62
75
|
return (
|
|
63
76
|
<AssistantContext.Provider value={context}>
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
<RenderComponent>
|
|
78
|
+
<ThreadRuntimeProvider
|
|
79
|
+
runtime={runtime.thread}
|
|
80
|
+
listItemRuntime={runtime.threadList.mainItem}
|
|
81
|
+
>
|
|
82
|
+
{children}
|
|
83
|
+
</ThreadRuntimeProvider>
|
|
84
|
+
</RenderComponent>
|
|
70
85
|
</AssistantContext.Provider>
|
|
71
86
|
);
|
|
72
87
|
};
|
|
@@ -28,11 +28,9 @@ const ThreadListItemImpl: FC<ThreadListItemProps> = ({
|
|
|
28
28
|
const runtime = useMemo(
|
|
29
29
|
() =>
|
|
30
30
|
archived
|
|
31
|
-
? assistantRuntime.threadList.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
: assistantRuntime.threadList.getThreadListItemByIndex(partIndex),
|
|
35
|
-
[assistantRuntime, partIndex],
|
|
31
|
+
? assistantRuntime.threadList.getArchivedItemByIndex(partIndex)
|
|
32
|
+
: assistantRuntime.threadList.getItemByIndex(partIndex),
|
|
33
|
+
[assistantRuntime, partIndex, archived],
|
|
36
34
|
);
|
|
37
35
|
|
|
38
36
|
const ThreadListItemComponent = components.ThreadListItem;
|
|
@@ -3,18 +3,22 @@ import {
|
|
|
3
3
|
CompleteAttachment,
|
|
4
4
|
PendingAttachment,
|
|
5
5
|
} from "../../types/AttachmentTypes";
|
|
6
|
-
import { AppendMessage
|
|
6
|
+
import { AppendMessage } from "../../types";
|
|
7
7
|
import { AttachmentAdapter } from "../attachment";
|
|
8
8
|
import {
|
|
9
9
|
ComposerRuntimeCore,
|
|
10
10
|
ComposerRuntimeEventType,
|
|
11
11
|
} from "../core/ComposerRuntimeCore";
|
|
12
12
|
import { MessageRole, RunConfig } from "../../types/AssistantTypes";
|
|
13
|
+
import { BaseSubscribable } from "../remote-thread-list/BaseSubscribable";
|
|
13
14
|
|
|
14
15
|
const isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>
|
|
15
16
|
a.status.type === "complete";
|
|
16
17
|
|
|
17
|
-
export abstract class BaseComposerRuntimeCore
|
|
18
|
+
export abstract class BaseComposerRuntimeCore
|
|
19
|
+
extends BaseSubscribable
|
|
20
|
+
implements ComposerRuntimeCore
|
|
21
|
+
{
|
|
18
22
|
public readonly isEditing = true;
|
|
19
23
|
|
|
20
24
|
protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;
|
|
@@ -30,7 +34,7 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
|
30
34
|
|
|
31
35
|
protected setAttachments(value: readonly Attachment[]) {
|
|
32
36
|
this._attachments = value;
|
|
33
|
-
this.
|
|
37
|
+
this._notifySubscribers();
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
public abstract get canCancel(): boolean;
|
|
@@ -61,34 +65,59 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
|
61
65
|
if (this._text === value) return;
|
|
62
66
|
|
|
63
67
|
this._text = value;
|
|
64
|
-
this.
|
|
68
|
+
this._notifySubscribers();
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
public setRole(role: MessageRole) {
|
|
68
72
|
if (this._role === role) return;
|
|
69
73
|
|
|
70
74
|
this._role = role;
|
|
71
|
-
this.
|
|
75
|
+
this._notifySubscribers();
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
public setRunConfig(runConfig: RunConfig) {
|
|
75
79
|
if (this._runConfig === runConfig) return;
|
|
76
80
|
|
|
77
81
|
this._runConfig = runConfig;
|
|
78
|
-
this.
|
|
82
|
+
this._notifySubscribers();
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
private
|
|
82
|
-
// TODO attachmentAdapter.remove should be called here
|
|
85
|
+
private _emptyTextAndAttachments() {
|
|
83
86
|
this._attachments = [];
|
|
84
87
|
this._text = "";
|
|
88
|
+
this._notifySubscribers();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private async _onClearAttachments() {
|
|
92
|
+
const adapter = this.getAttachmentAdapter();
|
|
93
|
+
if (adapter) {
|
|
94
|
+
await Promise.all(this._attachments.map((a) => adapter.remove(a)));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async reset() {
|
|
99
|
+
if (
|
|
100
|
+
this._attachments.length === 0 &&
|
|
101
|
+
this._text === "" &&
|
|
102
|
+
this._role === "user" &&
|
|
103
|
+
Object.keys(this._runConfig).length === 0
|
|
104
|
+
) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
85
108
|
this._role = "user";
|
|
86
109
|
this._runConfig = {};
|
|
87
|
-
|
|
110
|
+
|
|
111
|
+
const task = this._onClearAttachments();
|
|
112
|
+
this._emptyTextAndAttachments();
|
|
113
|
+
await task;
|
|
88
114
|
}
|
|
89
115
|
|
|
90
|
-
public async
|
|
91
|
-
|
|
116
|
+
public async clearAttachments() {
|
|
117
|
+
const task = this._onClearAttachments();
|
|
118
|
+
this.setAttachments([]);
|
|
119
|
+
|
|
120
|
+
await task;
|
|
92
121
|
}
|
|
93
122
|
|
|
94
123
|
public async send() {
|
|
@@ -110,7 +139,7 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
|
110
139
|
attachments,
|
|
111
140
|
runConfig: this.runConfig,
|
|
112
141
|
};
|
|
113
|
-
this.
|
|
142
|
+
this._emptyTextAndAttachments();
|
|
114
143
|
|
|
115
144
|
this.handleSend(message);
|
|
116
145
|
this._notifyEventSubscribers("send");
|
|
@@ -130,7 +159,7 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
|
130
159
|
const attachment = await adapter.add({ file });
|
|
131
160
|
|
|
132
161
|
this._attachments = [...this._attachments, attachment as PendingAttachment];
|
|
133
|
-
this.
|
|
162
|
+
this._notifySubscribers();
|
|
134
163
|
}
|
|
135
164
|
|
|
136
165
|
async removeAttachment(attachmentId: string) {
|
|
@@ -144,18 +173,7 @@ export abstract class BaseComposerRuntimeCore implements ComposerRuntimeCore {
|
|
|
144
173
|
await adapter.remove(attachment);
|
|
145
174
|
|
|
146
175
|
this._attachments = this._attachments.toSpliced(index, 1);
|
|
147
|
-
this.
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private _subscriptions = new Set<() => void>();
|
|
151
|
-
|
|
152
|
-
protected notifySubscribers() {
|
|
153
|
-
for (const callback of this._subscriptions) callback();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public subscribe(callback: () => void): Unsubscribe {
|
|
157
|
-
this._subscriptions.add(callback);
|
|
158
|
-
return () => this._subscriptions.delete(callback);
|
|
176
|
+
this._notifySubscribers();
|
|
159
177
|
}
|
|
160
178
|
|
|
161
179
|
private _eventSubscribers = new Map<
|
|
@@ -46,12 +46,11 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
this.
|
|
50
|
-
this.notifySubscribers();
|
|
49
|
+
this.handleCancel();
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
public handleCancel() {
|
|
54
53
|
this.endEditCallback();
|
|
55
|
-
this.
|
|
54
|
+
this._notifySubscribers();
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -34,7 +34,7 @@ export class DefaultThreadComposerRuntimeCore
|
|
|
34
34
|
return this.runtime.subscribe(() => {
|
|
35
35
|
if (this.canCancel !== this.runtime.capabilities.cancel) {
|
|
36
36
|
this._canCancel = this.runtime.capabilities.cancel;
|
|
37
|
-
this.
|
|
37
|
+
this._notifySubscribers();
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
1
2
|
import type { ModelConfigProvider } from "../../types/ModelConfigTypes";
|
|
2
3
|
import type { Unsubscribe } from "../../types/Unsubscribe";
|
|
3
4
|
import { ThreadListRuntimeCore } from "./ThreadListRuntimeCore";
|
|
@@ -6,4 +7,6 @@ export type AssistantRuntimeCore = {
|
|
|
6
7
|
readonly threadList: ThreadListRuntimeCore;
|
|
7
8
|
|
|
8
9
|
registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
|
|
10
|
+
|
|
11
|
+
__internal_RenderComponent?: React.FC<PropsWithChildren>;
|
|
9
12
|
};
|
|
@@ -24,7 +24,8 @@ export type ComposerRuntimeCore = Readonly<{
|
|
|
24
24
|
runConfig: RunConfig;
|
|
25
25
|
setRunConfig: (runConfig: RunConfig) => void;
|
|
26
26
|
|
|
27
|
-
reset: () => void
|
|
27
|
+
reset: () => Promise<void>;
|
|
28
|
+
clearAttachments: () => Promise<void>;
|
|
28
29
|
|
|
29
30
|
send: () => void;
|
|
30
31
|
cancel: () => void;
|
|
@@ -3,7 +3,10 @@ import { ThreadRuntimeCore } from "./ThreadRuntimeCore";
|
|
|
3
3
|
|
|
4
4
|
type ThreadListItemCoreState = {
|
|
5
5
|
readonly threadId: string;
|
|
6
|
-
readonly
|
|
6
|
+
readonly remoteId?: string | undefined;
|
|
7
|
+
readonly externalId?: string | undefined;
|
|
8
|
+
|
|
9
|
+
readonly status: "archived" | "regular" | "new" | "deleted";
|
|
7
10
|
readonly title?: string | undefined;
|
|
8
11
|
|
|
9
12
|
readonly runtime?: ThreadRuntimeCore | undefined;
|
|
@@ -22,7 +25,7 @@ export type ThreadListRuntimeCore = {
|
|
|
22
25
|
switchToThread(threadId: string): Promise<void>;
|
|
23
26
|
switchToNewThread(): Promise<void>;
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
getLoadThreadsPromise(): Promise<void>;
|
|
26
29
|
// getLoadArchivedThreadsPromise(): Promise<void>;
|
|
27
30
|
|
|
28
31
|
rename(threadId: string, newTitle: string): Promise<void>;
|
|
@@ -10,7 +10,7 @@ import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
|
|
10
10
|
import { ThreadMessageLike } from "./ThreadMessageLike";
|
|
11
11
|
|
|
12
12
|
export type ExternalStoreThreadData<TState extends "regular" | "archived"> = {
|
|
13
|
-
|
|
13
|
+
status: TState;
|
|
14
14
|
threadId: string;
|
|
15
15
|
title?: string | undefined;
|
|
16
16
|
};
|
|
@@ -13,8 +13,9 @@ const DEFAULT_THREAD_ID = "DEFAULT_THREAD_ID";
|
|
|
13
13
|
const DEFAULT_THREADS = Object.freeze([DEFAULT_THREAD_ID]);
|
|
14
14
|
const DEFAULT_THREAD: ExternalStoreThreadData<"regular"> = Object.freeze({
|
|
15
15
|
threadId: DEFAULT_THREAD_ID,
|
|
16
|
-
|
|
16
|
+
status: "regular",
|
|
17
17
|
});
|
|
18
|
+
const RESOLVED_PROMISE = Promise.resolve();
|
|
18
19
|
|
|
19
20
|
export class ExternalStoreThreadListRuntimeCore
|
|
20
21
|
implements ThreadListRuntimeCore
|
|
@@ -35,6 +36,10 @@ export class ExternalStoreThreadListRuntimeCore
|
|
|
35
36
|
return this._archivedThreads;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
public getLoadThreadsPromise() {
|
|
40
|
+
return RESOLVED_PROMISE;
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
private _mainThread: ExternalStoreThreadRuntimeCore;
|
|
39
44
|
|
|
40
45
|
public get mainThreadId() {
|
package/src/runtimes/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export * from "./attachment";
|
|
1
2
|
export * from "./core";
|
|
2
|
-
export * from "./
|
|
3
|
+
export * from "./dangerous-in-browser";
|
|
3
4
|
export * from "./edge";
|
|
4
5
|
export * from "./external-store";
|
|
5
|
-
export * from "./dangerous-in-browser";
|
|
6
|
-
export * from "./speech";
|
|
7
|
-
export * from "./attachment";
|
|
8
6
|
export * from "./feedback";
|
|
7
|
+
export * from "./local";
|
|
8
|
+
export * from "./remote-thread-list";
|
|
9
|
+
export * from "./speech";
|
|
@@ -9,13 +9,14 @@ export type ThreadListAdapter = {
|
|
|
9
9
|
|
|
10
10
|
export type LocalThreadData = {
|
|
11
11
|
readonly runtime: LocalThreadRuntimeCore;
|
|
12
|
-
readonly
|
|
12
|
+
readonly status: "new" | "regular" | "archived";
|
|
13
13
|
readonly threadId: string;
|
|
14
14
|
readonly title?: string | undefined;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type LocalThreadFactory = () => LocalThreadRuntimeCore;
|
|
18
18
|
|
|
19
|
+
const RESOLVED_PROMISE = Promise.resolve();
|
|
19
20
|
export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
20
21
|
private _threadData = new Map<string, LocalThreadData>();
|
|
21
22
|
private _threadIds: readonly string[] = [];
|
|
@@ -51,6 +52,10 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
51
52
|
return result;
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
public getLoadThreadsPromise(): Promise<void> {
|
|
56
|
+
return RESOLVED_PROMISE;
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
public getItemById(threadId: string) {
|
|
55
60
|
return this._threadData.get(threadId);
|
|
56
61
|
}
|
|
@@ -61,7 +66,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
61
66
|
const data = this._threadData.get(threadId);
|
|
62
67
|
if (!data) throw new Error("Thread not found");
|
|
63
68
|
|
|
64
|
-
if (data.
|
|
69
|
+
if (data.status === "archived") await this.unarchive(threadId);
|
|
65
70
|
|
|
66
71
|
this._mainThreadId = data.threadId;
|
|
67
72
|
this._notifySubscribers();
|
|
@@ -84,7 +89,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
84
89
|
});
|
|
85
90
|
this._threadData.set(threadId, {
|
|
86
91
|
runtime,
|
|
87
|
-
|
|
92
|
+
status: "new",
|
|
88
93
|
threadId,
|
|
89
94
|
});
|
|
90
95
|
this._newThreadId = threadId;
|
|
@@ -101,7 +106,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
101
106
|
const data = this._threadData.get(threadId);
|
|
102
107
|
if (!data) throw new Error("Thread not found");
|
|
103
108
|
|
|
104
|
-
const {
|
|
109
|
+
const { status: lastState } = data;
|
|
105
110
|
if (lastState === newState) return;
|
|
106
111
|
|
|
107
112
|
// lastState
|
|
@@ -147,7 +152,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
147
152
|
if (newState !== "deleted") {
|
|
148
153
|
this._threadData.set(threadId, {
|
|
149
154
|
...data,
|
|
150
|
-
|
|
155
|
+
status: newState,
|
|
151
156
|
});
|
|
152
157
|
}
|
|
153
158
|
|
|
@@ -181,7 +186,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
181
186
|
public archive(threadId: string): Promise<void> {
|
|
182
187
|
const data = this._threadData.get(threadId);
|
|
183
188
|
if (!data) throw new Error("Thread not found");
|
|
184
|
-
if (data.
|
|
189
|
+
if (data.status !== "regular")
|
|
185
190
|
throw new Error("Thread is not yet initialized or already archived");
|
|
186
191
|
|
|
187
192
|
this._stateOp(threadId, "archived");
|
|
@@ -191,7 +196,7 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
191
196
|
public unarchive(threadId: string): Promise<void> {
|
|
192
197
|
const data = this._threadData.get(threadId);
|
|
193
198
|
if (!data) throw new Error("Thread not found");
|
|
194
|
-
if (data.
|
|
199
|
+
if (data.status !== "archived") throw new Error("Thread is not archived");
|
|
195
200
|
|
|
196
201
|
this._stateOp(threadId, "regular");
|
|
197
202
|
return Promise.resolve();
|
|
@@ -200,8 +205,8 @@ export class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
|
200
205
|
public delete(threadId: string): Promise<void> {
|
|
201
206
|
const data = this._threadData.get(threadId);
|
|
202
207
|
if (!data) throw new Error("Thread not found");
|
|
203
|
-
if (data.
|
|
204
|
-
throw new Error("Thread is not yet
|
|
208
|
+
if (data.status !== "regular" && data.status !== "archived")
|
|
209
|
+
throw new Error("Thread is not yet initialized");
|
|
205
210
|
|
|
206
211
|
this._stateOp(threadId, "deleted");
|
|
207
212
|
return Promise.resolve();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Unsubscribe } from "../../types";
|
|
2
|
+
|
|
3
|
+
export class BaseSubscribable {
|
|
4
|
+
private _subscribers = new Set<() => void>();
|
|
5
|
+
|
|
6
|
+
public subscribe(callback: () => void): Unsubscribe {
|
|
7
|
+
this._subscribers.add(callback);
|
|
8
|
+
return () => this._subscribers.delete(callback);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public waitForUpdate() {
|
|
12
|
+
return new Promise<void>((resolve) => {
|
|
13
|
+
const unsubscribe = this.subscribe(() => {
|
|
14
|
+
unsubscribe();
|
|
15
|
+
resolve();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected _notifySubscribers() {
|
|
21
|
+
const errors = [];
|
|
22
|
+
for (const callback of this._subscribers) {
|
|
23
|
+
try {
|
|
24
|
+
callback();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
errors.push(error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (errors.length > 0) {
|
|
31
|
+
if (errors.length === 1) {
|
|
32
|
+
throw errors[0];
|
|
33
|
+
} else {
|
|
34
|
+
throw new AggregateError(errors);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|