@assistant-ui/react 0.7.23 → 0.7.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. package/dist/api/AssistantRuntime.d.ts +1 -1
  2. package/dist/api/AssistantRuntime.d.ts.map +1 -1
  3. package/dist/api/AssistantRuntime.js +1 -1
  4. package/dist/api/AssistantRuntime.js.map +1 -1
  5. package/dist/api/AssistantRuntime.mjs +1 -1
  6. package/dist/api/AssistantRuntime.mjs.map +1 -1
  7. package/dist/api/ComposerRuntime.d.ts +4 -2
  8. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  9. package/dist/api/ComposerRuntime.js +6 -1
  10. package/dist/api/ComposerRuntime.js.map +1 -1
  11. package/dist/api/ComposerRuntime.mjs +6 -1
  12. package/dist/api/ComposerRuntime.mjs.map +1 -1
  13. package/dist/api/ThreadListItemRuntime.d.ts +3 -1
  14. package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
  15. package/dist/api/ThreadListItemRuntime.js.map +1 -1
  16. package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
  17. package/dist/api/ThreadListRuntime.d.ts +8 -8
  18. package/dist/api/ThreadListRuntime.d.ts.map +1 -1
  19. package/dist/api/ThreadListRuntime.js +7 -5
  20. package/dist/api/ThreadListRuntime.js.map +1 -1
  21. package/dist/api/ThreadListRuntime.mjs +7 -5
  22. package/dist/api/ThreadListRuntime.mjs.map +1 -1
  23. package/dist/api/ThreadRuntime.d.ts +59 -32
  24. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  25. package/dist/api/ThreadRuntime.js +2 -2
  26. package/dist/api/ThreadRuntime.js.map +1 -1
  27. package/dist/api/ThreadRuntime.mjs +2 -2
  28. package/dist/api/ThreadRuntime.mjs.map +1 -1
  29. package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
  30. package/dist/context/providers/AssistantRuntimeProvider.js +8 -3
  31. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  32. package/dist/context/providers/AssistantRuntimeProvider.mjs +8 -3
  33. package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
  34. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  35. package/dist/primitives/threadList/ThreadListItems.js +2 -4
  36. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  37. package/dist/primitives/threadList/ThreadListItems.mjs +2 -4
  38. package/dist/primitives/threadList/ThreadListItems.mjs.map +1 -1
  39. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +6 -6
  40. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  41. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +29 -20
  42. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  43. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +29 -20
  44. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  45. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
  46. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +2 -3
  47. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
  48. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +2 -3
  49. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
  50. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js +1 -1
  51. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js.map +1 -1
  52. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.mjs +1 -1
  53. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.mjs.map +1 -1
  54. package/dist/runtimes/core/AssistantRuntimeCore.d.ts +2 -0
  55. package/dist/runtimes/core/AssistantRuntimeCore.d.ts.map +1 -1
  56. package/dist/runtimes/core/AssistantRuntimeCore.js.map +1 -1
  57. package/dist/runtimes/core/ComposerRuntimeCore.d.ts +2 -1
  58. package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
  59. package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
  60. package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +4 -1
  61. package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
  62. package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
  63. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +1 -1
  64. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
  65. package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
  66. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +1 -0
  67. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
  68. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +5 -1
  69. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
  70. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +5 -1
  71. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
  72. package/dist/runtimes/index.d.ts +5 -4
  73. package/dist/runtimes/index.d.ts.map +1 -1
  74. package/dist/runtimes/index.js +11 -9
  75. package/dist/runtimes/index.js.map +1 -1
  76. package/dist/runtimes/index.mjs +5 -4
  77. package/dist/runtimes/index.mjs.map +1 -1
  78. package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +2 -1
  79. package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
  80. package/dist/runtimes/local/LocalThreadListRuntimeCore.js +12 -8
  81. package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
  82. package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +12 -8
  83. package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
  84. package/dist/runtimes/remote-thread-list/BaseSubscribable.d.ts +8 -0
  85. package/dist/runtimes/remote-thread-list/BaseSubscribable.d.ts.map +1 -0
  86. package/dist/runtimes/remote-thread-list/BaseSubscribable.js +62 -0
  87. package/dist/runtimes/remote-thread-list/BaseSubscribable.js.map +1 -0
  88. package/dist/runtimes/remote-thread-list/BaseSubscribable.mjs +37 -0
  89. package/dist/runtimes/remote-thread-list/BaseSubscribable.mjs.map +1 -0
  90. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts +3 -0
  91. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -0
  92. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +150 -0
  93. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -0
  94. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs +125 -0
  95. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs.map +1 -0
  96. package/dist/runtimes/remote-thread-list/OptimisticState.d.ts +23 -0
  97. package/dist/runtimes/remote-thread-list/OptimisticState.d.ts.map +1 -0
  98. package/dist/runtimes/remote-thread-list/OptimisticState.js +83 -0
  99. package/dist/runtimes/remote-thread-list/OptimisticState.js.map +1 -0
  100. package/dist/runtimes/remote-thread-list/OptimisticState.mjs +58 -0
  101. package/dist/runtimes/remote-thread-list/OptimisticState.mjs.map +1 -0
  102. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +75 -0
  103. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -0
  104. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +127 -0
  105. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -0
  106. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs +102 -0
  107. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs.map +1 -0
  108. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +76 -0
  109. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -0
  110. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +396 -0
  111. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -0
  112. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +371 -0
  113. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -0
  114. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.d.ts +7 -0
  115. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.d.ts.map +1 -0
  116. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.js +39 -0
  117. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.js.map +1 -0
  118. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.mjs +14 -0
  119. package/dist/runtimes/remote-thread-list/cloud/AssistantCloud.mjs.map +1 -0
  120. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts +19 -0
  121. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.d.ts.map +1 -0
  122. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js +79 -0
  123. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.js.map +1 -0
  124. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs +57 -0
  125. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAPI.mjs.map +1 -0
  126. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts +20 -0
  127. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.d.ts.map +1 -0
  128. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js +95 -0
  129. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.js.map +1 -0
  130. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs +69 -0
  131. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.mjs.map +1 -0
  132. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.d.ts +46 -0
  133. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.d.ts.map +1 -0
  134. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.js +50 -0
  135. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.js.map +1 -0
  136. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.mjs +25 -0
  137. package/dist/runtimes/remote-thread-list/cloud/AssistantCloudThreads.mjs.map +1 -0
  138. package/dist/runtimes/remote-thread-list/cloud/CloudContext.d.ts +10 -0
  139. package/dist/runtimes/remote-thread-list/cloud/CloudContext.d.ts.map +1 -0
  140. package/dist/runtimes/remote-thread-list/cloud/CloudContext.js +32 -0
  141. package/dist/runtimes/remote-thread-list/cloud/CloudContext.js.map +1 -0
  142. package/dist/runtimes/remote-thread-list/cloud/CloudContext.mjs +7 -0
  143. package/dist/runtimes/remote-thread-list/cloud/CloudContext.mjs.map +1 -0
  144. package/dist/runtimes/remote-thread-list/cloud/index.d.ts +4 -0
  145. package/dist/runtimes/remote-thread-list/cloud/index.d.ts.map +1 -0
  146. package/dist/runtimes/remote-thread-list/cloud/index.js +37 -0
  147. package/dist/runtimes/remote-thread-list/cloud/index.js.map +1 -0
  148. package/dist/runtimes/remote-thread-list/cloud/index.mjs +10 -0
  149. package/dist/runtimes/remote-thread-list/cloud/index.mjs.map +1 -0
  150. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.d.ts +4 -0
  151. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.d.ts.map +1 -0
  152. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.js +46 -0
  153. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.js.map +1 -0
  154. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.mjs +22 -0
  155. package/dist/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.mjs.map +1 -0
  156. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts +14 -0
  157. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.d.ts.map +1 -0
  158. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js +103 -0
  159. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.js.map +1 -0
  160. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs +79 -0
  161. package/dist/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.mjs.map +1 -0
  162. package/dist/runtimes/remote-thread-list/index.d.ts +2 -0
  163. package/dist/runtimes/remote-thread-list/index.d.ts.map +1 -0
  164. package/dist/runtimes/remote-thread-list/index.js +25 -0
  165. package/dist/runtimes/remote-thread-list/index.js.map +1 -0
  166. package/dist/runtimes/remote-thread-list/index.mjs +3 -0
  167. package/dist/runtimes/remote-thread-list/index.mjs.map +1 -0
  168. package/dist/runtimes/remote-thread-list/types.d.ts +25 -0
  169. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -0
  170. package/dist/runtimes/remote-thread-list/types.js +19 -0
  171. package/dist/runtimes/remote-thread-list/types.js.map +1 -0
  172. package/dist/runtimes/remote-thread-list/types.mjs +1 -0
  173. package/dist/runtimes/remote-thread-list/types.mjs.map +1 -0
  174. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts +3 -0
  175. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -0
  176. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +51 -0
  177. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -0
  178. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +26 -0
  179. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -0
  180. package/dist/styles/index.css +2 -0
  181. package/dist/styles/index.css.map +1 -1
  182. package/dist/styles/tailwindcss/thread.css +5 -1
  183. package/dist/styles/tailwindcss/thread.css.json +4 -1
  184. package/dist/ui/attachment-ui.d.ts.map +1 -1
  185. package/dist/ui/attachment-ui.js +12 -7
  186. package/dist/ui/attachment-ui.js.map +1 -1
  187. package/dist/ui/attachment-ui.mjs +12 -7
  188. package/dist/ui/attachment-ui.mjs.map +1 -1
  189. package/dist/utils/createActionButton.d.ts +2 -2
  190. package/dist/utils/createActionButton.d.ts.map +1 -1
  191. package/dist/utils/createActionButton.js +2 -4
  192. package/dist/utils/createActionButton.js.map +1 -1
  193. package/dist/utils/createActionButton.mjs +5 -5
  194. package/dist/utils/createActionButton.mjs.map +1 -1
  195. package/package.json +3 -3
  196. package/src/api/AssistantRuntime.ts +2 -6
  197. package/src/api/ComposerRuntime.ts +10 -2
  198. package/src/api/ThreadListItemRuntime.ts +3 -1
  199. package/src/api/ThreadListRuntime.ts +11 -9
  200. package/src/api/ThreadRuntime.ts +3 -3
  201. package/src/context/providers/AssistantRuntimeProvider.tsx +21 -6
  202. package/src/primitives/threadList/ThreadListItems.tsx +3 -5
  203. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +43 -25
  204. package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +2 -3
  205. package/src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx +1 -1
  206. package/src/runtimes/core/AssistantRuntimeCore.tsx +3 -0
  207. package/src/runtimes/core/ComposerRuntimeCore.tsx +2 -1
  208. package/src/runtimes/core/ThreadListRuntimeCore.tsx +5 -2
  209. package/src/runtimes/external-store/ExternalStoreAdapter.tsx +1 -1
  210. package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +6 -1
  211. package/src/runtimes/index.ts +5 -4
  212. package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +14 -9
  213. package/src/runtimes/remote-thread-list/BaseSubscribable.tsx +38 -0
  214. package/src/runtimes/remote-thread-list/EMPTY_THREAD_CORE.tsx +158 -0
  215. package/src/runtimes/remote-thread-list/OptimisticState.ts +82 -0
  216. package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +132 -0
  217. package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +486 -0
  218. package/src/runtimes/remote-thread-list/cloud/AssistantCloud.tsx +11 -0
  219. package/src/runtimes/remote-thread-list/cloud/AssistantCloudAPI.tsx +81 -0
  220. package/src/runtimes/remote-thread-list/cloud/AssistantCloudAuthStrategy.tsx +95 -0
  221. package/src/runtimes/remote-thread-list/cloud/AssistantCloudThreads.tsx +72 -0
  222. package/src/runtimes/remote-thread-list/cloud/CloudContext.tsx +12 -0
  223. package/src/runtimes/remote-thread-list/cloud/index.ts +3 -0
  224. package/src/runtimes/remote-thread-list/cloud/useCloudGetOrCreateThread.tsx +19 -0
  225. package/src/runtimes/remote-thread-list/cloud/useCloudThreadListRuntime.tsx +100 -0
  226. package/src/runtimes/remote-thread-list/index.ts +2 -0
  227. package/src/runtimes/remote-thread-list/types.tsx +34 -0
  228. package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +28 -0
  229. package/src/styles/tailwindcss/thread.css +5 -1
  230. package/src/ui/attachment-ui.tsx +20 -14
  231. 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.23",
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.mainThreadListItem, // TODO capture "main" threadListItem from context around useLocalRuntime / useExternalStoreRuntime
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 state: "archived" | "regular" | "new" | "deleted";
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 mainThreadListItem: ThreadListItemRuntime;
25
- getThreadListItemById(threadId: string): ThreadListItemRuntime;
26
- getThreadListItemByIndex(idx: number): ThreadListItemRuntime;
27
- getThreadListArchivedItemByIndex(idx: number): ThreadListItemRuntime;
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
- state: threadData.state,
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 mainThreadListItem() {
98
+ public get mainItem() {
97
99
  return this._mainThreadListItemRuntime;
98
100
  }
99
101
 
100
- public getThreadListItemByIndex(idx: number) {
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 getThreadListArchivedItemByIndex(idx: number) {
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 getThreadListItemById(threadId: string) {
137
+ public getItemById(threadId: string) {
136
138
  return new ThreadListItemRuntimeImpl(
137
139
  new ShallowMemoizeSubject({
138
140
  path: {
@@ -215,11 +215,11 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
215
215
  return this._threadBinding.path;
216
216
  }
217
217
 
218
- public unstable_getCore() {
219
- return this._threadBinding.getState();
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
- <ThreadRuntimeProvider
65
- runtime={runtime.thread}
66
- listItemRuntime={runtime.threadList.mainThreadListItem}
67
- >
68
- {children}
69
- </ThreadRuntimeProvider>
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.getThreadListArchivedItemByIndex(
32
- partIndex,
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, Unsubscribe } from "../../types";
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 implements ComposerRuntimeCore {
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.notifySubscribers();
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.notifySubscribers();
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.notifySubscribers();
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.notifySubscribers();
82
+ this._notifySubscribers();
79
83
  }
80
84
 
81
- private _resetInternal() {
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
- this.notifySubscribers();
110
+
111
+ const task = this._onClearAttachments();
112
+ this._emptyTextAndAttachments();
113
+ await task;
88
114
  }
89
115
 
90
- public async reset() {
91
- return this._resetInternal();
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._resetInternal();
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.notifySubscribers();
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.notifySubscribers();
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.endEditCallback();
50
- this.notifySubscribers();
49
+ this.handleCancel();
51
50
  }
52
51
 
53
52
  public handleCancel() {
54
53
  this.endEditCallback();
55
- this.notifySubscribers();
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.notifySubscribers();
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 state: "archived" | "regular" | "new" | "deleted";
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
- // getLoadThreadsPromise(): Promise<void>;
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
- state: TState;
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
- state: "regular",
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() {
@@ -1,8 +1,9 @@
1
+ export * from "./attachment";
1
2
  export * from "./core";
2
- export * from "./local";
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 state: "new" | "regular" | "archived";
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.state === "archived") await this.unarchive(threadId);
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
- state: "new",
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 { state: lastState } = data;
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
- state: newState,
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.state !== "regular")
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.state !== "archived") throw new Error("Thread is not archived");
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.state !== "regular" && data.state !== "archived")
204
- throw new Error("Thread is not yet initalized");
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
+ }