@assistant-ui/react 0.5.98 → 0.5.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (273) hide show
  1. package/dist/api/AssistantRuntime.d.ts +4 -4
  2. package/dist/api/AssistantRuntime.d.ts.map +1 -1
  3. package/dist/api/AssistantRuntime.js +7 -7
  4. package/dist/api/AssistantRuntime.js.map +1 -1
  5. package/dist/api/AssistantRuntime.mjs +7 -9
  6. package/dist/api/AssistantRuntime.mjs.map +1 -1
  7. package/dist/api/ComposerRuntime.d.ts +7 -0
  8. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  9. package/dist/api/ComposerRuntime.js +13 -0
  10. package/dist/api/ComposerRuntime.js.map +1 -1
  11. package/dist/api/ComposerRuntime.mjs +13 -0
  12. package/dist/api/ComposerRuntime.mjs.map +1 -1
  13. package/dist/api/MessageRuntime.d.ts.map +1 -1
  14. package/dist/api/MessageRuntime.js +0 -5
  15. package/dist/api/MessageRuntime.js.map +1 -1
  16. package/dist/api/MessageRuntime.mjs +0 -5
  17. package/dist/api/MessageRuntime.mjs.map +1 -1
  18. package/dist/api/RuntimePathTypes.d.ts +16 -1
  19. package/dist/api/RuntimePathTypes.d.ts.map +1 -1
  20. package/dist/api/RuntimePathTypes.js.map +1 -1
  21. package/dist/api/ThreadListItemRuntime.d.ts +29 -0
  22. package/dist/api/ThreadListItemRuntime.d.ts.map +1 -0
  23. package/dist/api/ThreadListItemRuntime.js +61 -0
  24. package/dist/api/ThreadListItemRuntime.js.map +1 -0
  25. package/dist/api/ThreadListItemRuntime.mjs +36 -0
  26. package/dist/api/ThreadListItemRuntime.mjs.map +1 -0
  27. package/dist/api/ThreadListRuntime.d.ts +51 -0
  28. package/dist/api/ThreadListRuntime.d.ts.map +1 -0
  29. package/dist/api/ThreadListRuntime.js +128 -0
  30. package/dist/api/ThreadListRuntime.js.map +1 -0
  31. package/dist/api/ThreadListRuntime.mjs +105 -0
  32. package/dist/api/ThreadListRuntime.mjs.map +1 -0
  33. package/dist/api/ThreadRuntime.d.ts +3 -0
  34. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  35. package/dist/api/ThreadRuntime.js +1 -1
  36. package/dist/api/ThreadRuntime.js.map +1 -1
  37. package/dist/api/ThreadRuntime.mjs +1 -1
  38. package/dist/api/ThreadRuntime.mjs.map +1 -1
  39. package/dist/api/index.d.ts +1 -1
  40. package/dist/api/index.d.ts.map +1 -1
  41. package/dist/api/index.js.map +1 -1
  42. package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
  43. package/dist/context/providers/AssistantRuntimeProvider.js +7 -9
  44. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  45. package/dist/context/providers/AssistantRuntimeProvider.mjs +7 -9
  46. package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
  47. package/dist/context/providers/AttachmentRuntimeProvider.d.ts +6 -5
  48. package/dist/context/providers/AttachmentRuntimeProvider.d.ts.map +1 -1
  49. package/dist/context/providers/AttachmentRuntimeProvider.js.map +1 -1
  50. package/dist/context/providers/AttachmentRuntimeProvider.mjs.map +1 -1
  51. package/dist/context/providers/ContentPartRuntimeProvider.d.ts +6 -5
  52. package/dist/context/providers/ContentPartRuntimeProvider.d.ts.map +1 -1
  53. package/dist/context/providers/ContentPartRuntimeProvider.js +1 -4
  54. package/dist/context/providers/ContentPartRuntimeProvider.js.map +1 -1
  55. package/dist/context/providers/ContentPartRuntimeProvider.mjs +1 -4
  56. package/dist/context/providers/ContentPartRuntimeProvider.mjs.map +1 -1
  57. package/dist/context/providers/MessageRuntimeProvider.d.ts +6 -5
  58. package/dist/context/providers/MessageRuntimeProvider.d.ts.map +1 -1
  59. package/dist/context/providers/MessageRuntimeProvider.js.map +1 -1
  60. package/dist/context/providers/MessageRuntimeProvider.mjs.map +1 -1
  61. package/dist/context/providers/TextContentPartProvider.d.ts +7 -6
  62. package/dist/context/providers/TextContentPartProvider.d.ts.map +1 -1
  63. package/dist/context/providers/TextContentPartProvider.js +5 -1
  64. package/dist/context/providers/TextContentPartProvider.js.map +1 -1
  65. package/dist/context/providers/TextContentPartProvider.mjs +5 -1
  66. package/dist/context/providers/TextContentPartProvider.mjs.map +1 -1
  67. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts +13 -0
  68. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -0
  69. package/dist/context/providers/ThreadListItemRuntimeProvider.js +62 -0
  70. package/dist/context/providers/ThreadListItemRuntimeProvider.js.map +1 -0
  71. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs +39 -0
  72. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs.map +1 -0
  73. package/dist/context/react/AssistantContext.d.ts +35 -11
  74. package/dist/context/react/AssistantContext.d.ts.map +1 -1
  75. package/dist/context/react/AssistantContext.js +4 -4
  76. package/dist/context/react/AssistantContext.js.map +1 -1
  77. package/dist/context/react/AssistantContext.mjs +3 -3
  78. package/dist/context/react/AssistantContext.mjs.map +1 -1
  79. package/dist/context/react/ThreadListItemContext.d.ts +58 -0
  80. package/dist/context/react/ThreadListItemContext.d.ts.map +1 -0
  81. package/dist/context/react/ThreadListItemContext.js +53 -0
  82. package/dist/context/react/ThreadListItemContext.js.map +1 -0
  83. package/dist/context/react/ThreadListItemContext.mjs +25 -0
  84. package/dist/context/react/ThreadListItemContext.mjs.map +1 -0
  85. package/dist/context/react/index.d.ts +1 -1
  86. package/dist/context/react/index.d.ts.map +1 -1
  87. package/dist/context/react/index.js +2 -2
  88. package/dist/context/react/index.js.map +1 -1
  89. package/dist/context/react/index.mjs +2 -2
  90. package/dist/context/react/index.mjs.map +1 -1
  91. package/dist/internal.d.ts +1 -1
  92. package/dist/internal.d.ts.map +1 -1
  93. package/dist/internal.js.map +1 -1
  94. package/dist/internal.mjs.map +1 -1
  95. package/dist/primitives/index.d.ts +2 -0
  96. package/dist/primitives/index.d.ts.map +1 -1
  97. package/dist/primitives/index.js +6 -0
  98. package/dist/primitives/index.js.map +1 -1
  99. package/dist/primitives/index.mjs +4 -0
  100. package/dist/primitives/index.mjs.map +1 -1
  101. package/dist/primitives/threadList/ThreadListItems.d.ts +11 -0
  102. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -0
  103. package/dist/primitives/threadList/ThreadListItems.js +72 -0
  104. package/dist/primitives/threadList/ThreadListItems.js.map +1 -0
  105. package/dist/primitives/threadList/ThreadListItems.mjs +48 -0
  106. package/dist/primitives/threadList/ThreadListItems.mjs.map +1 -0
  107. package/dist/primitives/threadList/ThreadListNew.d.ts +13 -0
  108. package/dist/primitives/threadList/ThreadListNew.d.ts.map +1 -0
  109. package/dist/primitives/threadList/ThreadListNew.js +43 -0
  110. package/dist/primitives/threadList/ThreadListNew.js.map +1 -0
  111. package/dist/primitives/threadList/ThreadListNew.mjs +21 -0
  112. package/dist/primitives/threadList/ThreadListNew.mjs.map +1 -0
  113. package/dist/primitives/threadList/index.d.ts +3 -0
  114. package/dist/primitives/threadList/index.d.ts.map +1 -0
  115. package/dist/primitives/threadList/index.js +34 -0
  116. package/dist/primitives/threadList/index.js.map +1 -0
  117. package/dist/primitives/threadList/index.mjs +8 -0
  118. package/dist/primitives/threadList/index.mjs.map +1 -0
  119. package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts +13 -0
  120. package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts.map +1 -0
  121. package/dist/primitives/threadListItem/ThreadListItemArchive.js +43 -0
  122. package/dist/primitives/threadListItem/ThreadListItemArchive.js.map +1 -0
  123. package/dist/primitives/threadListItem/ThreadListItemArchive.mjs +21 -0
  124. package/dist/primitives/threadListItem/ThreadListItemArchive.mjs.map +1 -0
  125. package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts +13 -0
  126. package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts.map +1 -0
  127. package/dist/primitives/threadListItem/ThreadListItemDelete.js +43 -0
  128. package/dist/primitives/threadListItem/ThreadListItemDelete.js.map +1 -0
  129. package/dist/primitives/threadListItem/ThreadListItemDelete.mjs +21 -0
  130. package/dist/primitives/threadListItem/ThreadListItemDelete.mjs.map +1 -0
  131. package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts +13 -0
  132. package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts.map +1 -0
  133. package/dist/primitives/threadListItem/ThreadListItemUnarchive.js +43 -0
  134. package/dist/primitives/threadListItem/ThreadListItemUnarchive.js.map +1 -0
  135. package/dist/primitives/threadListItem/ThreadListItemUnarchive.mjs +21 -0
  136. package/dist/primitives/threadListItem/ThreadListItemUnarchive.mjs.map +1 -0
  137. package/dist/primitives/threadListItem/index.d.ts +4 -0
  138. package/dist/primitives/threadListItem/index.d.ts.map +1 -0
  139. package/dist/primitives/threadListItem/index.js +37 -0
  140. package/dist/primitives/threadListItem/index.js.map +1 -0
  141. package/dist/primitives/threadListItem/index.mjs +10 -0
  142. package/dist/primitives/threadListItem/index.mjs.map +1 -0
  143. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +5 -1
  144. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  145. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +14 -5
  146. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  147. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +14 -5
  148. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  149. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
  150. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +2 -1
  151. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
  152. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs +2 -1
  153. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.mjs.map +1 -1
  154. package/dist/runtimes/core/AssistantRuntimeCore.d.ts +2 -2
  155. package/dist/runtimes/core/AssistantRuntimeCore.d.ts.map +1 -1
  156. package/dist/runtimes/core/AssistantRuntimeCore.js.map +1 -1
  157. package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts +2 -2
  158. package/dist/runtimes/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
  159. package/dist/runtimes/core/BaseAssistantRuntimeCore.js.map +1 -1
  160. package/dist/runtimes/core/BaseAssistantRuntimeCore.mjs.map +1 -1
  161. package/dist/runtimes/core/ComposerRuntimeCore.d.ts +3 -0
  162. package/dist/runtimes/core/ComposerRuntimeCore.d.ts.map +1 -1
  163. package/dist/runtimes/core/ComposerRuntimeCore.js.map +1 -1
  164. package/dist/runtimes/core/{ThreadManagerRuntimeCore.d.ts → ThreadListRuntimeCore.d.ts} +7 -6
  165. package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -0
  166. package/dist/runtimes/core/{ThreadManagerRuntimeCore.js → ThreadListRuntimeCore.js} +4 -4
  167. package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -0
  168. package/dist/runtimes/core/ThreadListRuntimeCore.mjs +1 -0
  169. package/dist/runtimes/core/subscribeToMainThread.js +2 -2
  170. package/dist/runtimes/core/subscribeToMainThread.js.map +1 -1
  171. package/dist/runtimes/core/subscribeToMainThread.mjs +2 -2
  172. package/dist/runtimes/core/subscribeToMainThread.mjs.map +1 -1
  173. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +8 -8
  174. package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
  175. package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
  176. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts +2 -2
  177. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts.map +1 -1
  178. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +8 -8
  179. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
  180. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs +8 -8
  181. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs.map +1 -1
  182. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +35 -0
  183. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -0
  184. package/dist/runtimes/external-store/{ExternalStoreThreadManagementAdapter.js → ExternalStoreThreadListRuntimeCore.js} +21 -9
  185. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -0
  186. package/dist/runtimes/external-store/{ExternalStoreThreadManagementAdapter.mjs → ExternalStoreThreadListRuntimeCore.mjs} +17 -5
  187. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -0
  188. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +1 -1
  189. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  190. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +8 -3
  191. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  192. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +8 -3
  193. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
  194. package/dist/runtimes/local/LocalRuntimeCore.d.ts +2 -2
  195. package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
  196. package/dist/runtimes/local/LocalRuntimeCore.js +7 -7
  197. package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
  198. package/dist/runtimes/local/LocalRuntimeCore.mjs +7 -7
  199. package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
  200. package/dist/runtimes/local/{LocalThreadManagerRuntimeCore.d.ts → LocalThreadListRuntimeCore.d.ts} +16 -6
  201. package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -0
  202. package/dist/runtimes/local/{LocalThreadManagerRuntimeCore.js → LocalThreadListRuntimeCore.js} +11 -8
  203. package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -0
  204. package/dist/runtimes/local/{LocalThreadManagerRuntimeCore.mjs → LocalThreadListRuntimeCore.mjs} +7 -4
  205. package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -0
  206. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  207. package/dist/runtimes/local/LocalThreadRuntimeCore.js +2 -1
  208. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  209. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +2 -1
  210. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
  211. package/dist/types/AssistantTypes.d.ts +2 -0
  212. package/dist/types/AssistantTypes.d.ts.map +1 -1
  213. package/dist/types/AssistantTypes.js.map +1 -1
  214. package/package.json +7 -7
  215. package/src/api/AssistantRuntime.ts +9 -12
  216. package/src/api/ComposerRuntime.ts +17 -0
  217. package/src/api/MessageRuntime.ts +0 -9
  218. package/src/api/RuntimePathTypes.ts +10 -1
  219. package/src/api/ThreadListItemRuntime.ts +67 -0
  220. package/src/api/ThreadListRuntime.ts +159 -0
  221. package/src/api/ThreadRuntime.ts +2 -1
  222. package/src/api/index.ts +1 -4
  223. package/src/context/providers/AssistantRuntimeProvider.tsx +7 -9
  224. package/src/context/providers/AttachmentRuntimeProvider.tsx +6 -4
  225. package/src/context/providers/ContentPartRuntimeProvider.tsx +8 -7
  226. package/src/context/providers/MessageRuntimeProvider.tsx +6 -4
  227. package/src/context/providers/TextContentPartProvider.tsx +11 -7
  228. package/src/context/providers/ThreadListItemRuntimeProvider.tsx +54 -0
  229. package/src/context/react/AssistantContext.ts +4 -4
  230. package/src/context/react/ThreadListItemContext.ts +39 -0
  231. package/src/context/react/index.ts +2 -2
  232. package/src/internal.ts +1 -1
  233. package/src/primitives/index.ts +2 -0
  234. package/src/primitives/threadList/ThreadListItems.tsx +73 -0
  235. package/src/primitives/threadList/ThreadListNew.ts +25 -0
  236. package/src/primitives/threadList/index.ts +2 -0
  237. package/src/primitives/threadListItem/ThreadListItemArchive.ts +25 -0
  238. package/src/primitives/threadListItem/ThreadListItemDelete.ts +25 -0
  239. package/src/primitives/threadListItem/ThreadListItemUnarchive.ts +25 -0
  240. package/src/primitives/threadListItem/index.ts +3 -0
  241. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +19 -5
  242. package/src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx +3 -2
  243. package/src/runtimes/core/AssistantRuntimeCore.tsx +2 -2
  244. package/src/runtimes/core/BaseAssistantRuntimeCore.tsx +2 -2
  245. package/src/runtimes/core/ComposerRuntimeCore.tsx +4 -0
  246. package/src/runtimes/core/{ThreadManagerRuntimeCore.tsx → ThreadListRuntimeCore.tsx} +7 -5
  247. package/src/runtimes/core/subscribeToMainThread.ts +2 -2
  248. package/src/runtimes/external-store/ExternalStoreAdapter.tsx +8 -8
  249. package/src/runtimes/external-store/ExternalStoreRuntimeCore.tsx +8 -8
  250. package/src/runtimes/external-store/{ExternalStoreThreadManagementAdapter.tsx → ExternalStoreThreadListRuntimeCore.tsx} +24 -9
  251. package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +8 -3
  252. package/src/runtimes/local/LocalRuntimeCore.tsx +7 -7
  253. package/src/runtimes/local/{LocalThreadManagerRuntimeCore.tsx → LocalThreadListRuntimeCore.tsx} +11 -7
  254. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +2 -1
  255. package/src/types/AssistantTypes.ts +3 -0
  256. package/dist/api/ThreadManagerRuntime.d.ts +0 -32
  257. package/dist/api/ThreadManagerRuntime.d.ts.map +0 -1
  258. package/dist/api/ThreadManagerRuntime.js +0 -73
  259. package/dist/api/ThreadManagerRuntime.js.map +0 -1
  260. package/dist/api/ThreadManagerRuntime.mjs +0 -48
  261. package/dist/api/ThreadManagerRuntime.mjs.map +0 -1
  262. package/dist/runtimes/core/ThreadManagerRuntimeCore.d.ts.map +0 -1
  263. package/dist/runtimes/core/ThreadManagerRuntimeCore.js.map +0 -1
  264. package/dist/runtimes/core/ThreadManagerRuntimeCore.mjs +0 -1
  265. package/dist/runtimes/external-store/ExternalStoreThreadManagementAdapter.d.ts +0 -25
  266. package/dist/runtimes/external-store/ExternalStoreThreadManagementAdapter.d.ts.map +0 -1
  267. package/dist/runtimes/external-store/ExternalStoreThreadManagementAdapter.js.map +0 -1
  268. package/dist/runtimes/external-store/ExternalStoreThreadManagementAdapter.mjs.map +0 -1
  269. package/dist/runtimes/local/LocalThreadManagerRuntimeCore.d.ts.map +0 -1
  270. package/dist/runtimes/local/LocalThreadManagerRuntimeCore.js.map +0 -1
  271. package/dist/runtimes/local/LocalThreadManagerRuntimeCore.mjs.map +0 -1
  272. package/src/api/ThreadManagerRuntime.ts +0 -80
  273. /package/dist/runtimes/core/{ThreadManagerRuntimeCore.mjs.map → ThreadListRuntimeCore.mjs.map} +0 -0
@@ -0,0 +1,105 @@
1
+ // src/api/ThreadListRuntime.ts
2
+ import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject.mjs";
3
+ import {
4
+ ThreadListItemRuntimeImpl
5
+ } from "./ThreadListItemRuntime.mjs";
6
+ import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE.mjs";
7
+ var getThreadListState = (threadList) => {
8
+ return {
9
+ threads: threadList.threads,
10
+ archivedThreads: threadList.archivedThreads
11
+ };
12
+ };
13
+ var THREAD_MANAGER_PATH = {
14
+ ref: "ThreadList"
15
+ };
16
+ var ThreadListRuntimeImpl = class {
17
+ constructor(_core) {
18
+ this._core = _core;
19
+ const stateBinding = new LazyMemoizeSubject({
20
+ path: THREAD_MANAGER_PATH,
21
+ getState: () => getThreadListState(_core),
22
+ subscribe: (callback) => _core.subscribe(callback)
23
+ });
24
+ this._getState = stateBinding.getState.bind(stateBinding);
25
+ }
26
+ get path() {
27
+ return THREAD_MANAGER_PATH;
28
+ }
29
+ _getState;
30
+ getState() {
31
+ return this._getState();
32
+ }
33
+ rename(threadId, newTitle) {
34
+ return this._core.rename(threadId, newTitle);
35
+ }
36
+ archive(threadId) {
37
+ return this._core.archive(threadId);
38
+ }
39
+ unarchive(threadId) {
40
+ return this._core.unarchive(threadId);
41
+ }
42
+ delete(threadId) {
43
+ return this._core.delete(threadId);
44
+ }
45
+ subscribe(callback) {
46
+ return this._core.subscribe(callback);
47
+ }
48
+ getThreadListItemByIndex(idx) {
49
+ return new ThreadListItemRuntimeImpl(
50
+ new LazyMemoizeSubject({
51
+ path: {
52
+ ref: this.path.ref + `${this.path.ref}.threadItems[${idx}]`,
53
+ threadSelector: { type: "index", index: idx }
54
+ },
55
+ getState: () => {
56
+ const threads = this._core.threads;
57
+ const thread = threads[idx];
58
+ if (!thread) return SKIP_UPDATE;
59
+ return thread;
60
+ },
61
+ subscribe: (callback) => this._core.subscribe(callback)
62
+ }),
63
+ this._core
64
+ );
65
+ }
66
+ getThreadListArchivedItemByIndex(idx) {
67
+ return new ThreadListItemRuntimeImpl(
68
+ new LazyMemoizeSubject({
69
+ path: {
70
+ ref: this.path.ref + `${this.path.ref}.archivedThreadItems[${idx}]`,
71
+ threadSelector: { type: "archiveIndex", index: idx }
72
+ },
73
+ getState: () => {
74
+ const threads = this._core.archivedThreads;
75
+ const thread = threads[idx];
76
+ if (!thread) return SKIP_UPDATE;
77
+ return thread;
78
+ },
79
+ subscribe: (callback) => this._core.subscribe(callback)
80
+ }),
81
+ this._core
82
+ );
83
+ }
84
+ getThreadListItemById(threadId) {
85
+ return new ThreadListItemRuntimeImpl(
86
+ new LazyMemoizeSubject({
87
+ path: {
88
+ ref: this.path.ref + `${this.path.ref}.threadItems[threadId=${threadId}]`,
89
+ threadSelector: { type: "threadId", threadId }
90
+ },
91
+ getState: () => {
92
+ const threadItem = this._core.getThreadMetadataById(threadId);
93
+ if (!threadItem) return SKIP_UPDATE;
94
+ return threadItem;
95
+ },
96
+ subscribe: (callback) => this._core.subscribe(callback)
97
+ }),
98
+ this._core
99
+ );
100
+ }
101
+ };
102
+ export {
103
+ ThreadListRuntimeImpl
104
+ };
105
+ //# sourceMappingURL=ThreadListRuntime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/api/ThreadListRuntime.ts"],"sourcesContent":["import { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport {\n ThreadListMetadata,\n ThreadListRuntimeCore,\n} from \"../runtimes/core/ThreadListRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport { ThreadListRuntimePath } from \"./RuntimePathTypes\";\nimport {\n ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n} from \"./ThreadListItemRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\n\nexport type ThreadListState = Readonly<{\n threads: readonly ThreadListMetadata[];\n archivedThreads: readonly ThreadListMetadata[];\n}>;\n\nexport type ThreadListRuntime = Readonly<{\n path: ThreadListRuntimePath;\n getState(): ThreadListState;\n\n /**\n * @deprecated Use `getThreadListItemById(idx).rename(newTitle)` instead. This will be removed in 0.6.0.\n */\n rename(threadId: string, newTitle: string): Promise<void>;\n /**\n * @deprecated Use `getThreadListItemById(idx).archive()` instead. This will be removed in 0.6.0.\n */\n archive(threadId: string): Promise<void>;\n /**\n * @deprecated Use `getThreadListItemById(idx).unarchive()` instead. This will be removed in 0.6.0.\n */\n unarchive(threadId: string): Promise<void>;\n /**\n * @deprecated Use `getThreadListItemById(idx).delete()` instead. This will be removed in 0.6.0.\n */\n delete(threadId: string): Promise<void>;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getThreadListItemById(threadId: string): ThreadListItemRuntime;\n getThreadListItemByIndex(idx: number): ThreadListItemRuntime;\n getThreadListArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n}>;\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n threads: threadList.threads,\n archivedThreads: threadList.archivedThreads,\n };\n};\n\nconst THREAD_MANAGER_PATH = {\n ref: \"ThreadList\",\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n public get path() {\n return THREAD_MANAGER_PATH;\n }\n\n private _getState;\n constructor(private _core: ThreadListRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: THREAD_MANAGER_PATH,\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n return this._core.rename(threadId, newTitle);\n }\n\n public archive(threadId: string): Promise<void> {\n return this._core.archive(threadId);\n }\n\n public unarchive(threadId: string): Promise<void> {\n return this._core.unarchive(threadId);\n }\n\n public delete(threadId: string): Promise<void> {\n return this._core.delete(threadId);\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n public getThreadListItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new LazyMemoizeSubject({\n path: {\n ref: this.path.ref + `${this.path.ref}.threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const threads = this._core.threads;\n const thread = threads[idx];\n if (!thread) return SKIP_UPDATE;\n return thread;\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getThreadListArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new LazyMemoizeSubject({\n path: {\n ref: this.path.ref + `${this.path.ref}.archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n const threads = this._core.archivedThreads;\n const thread = threads[idx];\n if (!thread) return SKIP_UPDATE;\n return thread;\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getThreadListItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new LazyMemoizeSubject({\n path: {\n ref:\n this.path.ref +\n `${this.path.ref}.threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n const threadItem = this._core.getThreadMetadataById(threadId);\n if (!thre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;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
@@ -11,6 +11,7 @@ export type CreateAppendMessage = string | {
11
11
  role?: AppendMessage["role"] | undefined;
12
12
  content: AppendMessage["content"];
13
13
  attachments?: AppendMessage["attachments"] | undefined;
14
+ startRun?: boolean | undefined;
14
15
  };
15
16
  export type ThreadRuntimeCoreBinding = SubscribableWithState<ThreadRuntimeCore, ThreadRuntimePath> & {
16
17
  outerSubscribe(callback: () => void): Unsubscribe;
@@ -293,6 +294,8 @@ export declare class ThreadRuntimeImpl implements Omit<ThreadRuntimeCore, "getMe
293
294
  isEmpty: boolean;
294
295
  text: string;
295
296
  setText: (value: string) => void;
297
+ role: import("../types/AssistantTypes").MessageRole;
298
+ setRole: (role: import("../types/AssistantTypes").MessageRole) => void;
296
299
  reset: () => void;
297
300
  send: () => void;
298
301
  cancel: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ThreadRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EACd,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAEL,qBAAqB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAsB,iBAAiB,EAAE,MAAM,oBA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7Qf;;WAEG;kBACO,MAAM;QAChB;;WAEG;oBACS,OAAO;QAEnB;;WAEG;mBACQ,OAAO;QAElB;;WAEG;sBACW,mBAAmB;QAEjC;;WAEG;kBACO,SAAS,aAAa,EAAE;QAElC;;WAEG;qBACU,SAAS,gBAAgB,EAAE;QAExC;;WAEG;gBACK,OAAO;QAEf;;WAEG;gBACK,WAAW,GAAG,SAAS;;IA4OxB,MAAM,CAAC,OAAO,EAAE,mBAAmB;IAQnC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;IAIrC;;OAEG;IACI,WAAW,CAAC,SAAS,EAAE,MAAM;IAI7B,cAAc;IAKd,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIhC,SAAS;IAIhB;;OAEG;IACI,aAAa,CAAC,OAAO,EAAE,oBAAoB;IAIlD;;OAEG;IACI,cAAc,CAAC,QAAQ,EAAE,MAAM;IAItC;;OAEG;IACI,KAAK,CAAC,SAAS,EAAE,MAAM;IAIvB,YAAY;IAIZ,oBAAoB,CAAC,SAAS,EAAE,MAAM;;;IAI7C;;OAEG;IACI,cAAc,CAAC,OAAO,EAAE,qBAAqB;IAIpD;;OAEG;IACI,eAAe,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;IAIxC;;OAEG;IACI,SAAS,CAAC,SAAS,EAAE,MAAM;IAI3B,MAAM;IAIN,MAAM,CAAC,IAAI,EAAE,yBAAyB;IAItC,kBAAkB,CAAC,GAAG,EAAE,MAAM;IAqB9B,eAAe,CAAC,SAAS,EAAE,MAAM;IAaxC,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,iCAAiC,CAGrC;IAEG,WAAW,CAChB,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,MAAM,IAAI,GACnB,WAAW;CAef"}
@@ -43,9 +43,9 @@ var toAppendMessage = (messages, message) => {
43
43
  return message;
44
44
  }
45
45
  return {
46
+ ...message,
46
47
  parentId: message.parentId ?? messages.at(-1)?.id ?? null,
47
48
  role: message.role ?? "user",
48
- content: message.content,
49
49
  attachments: message.attachments ?? []
50
50
  };
51
51
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,4BAIO;AACP,uCAA0C;AAC1C,mCAAsC;AAKtC,6BAGO;AACP,gCAAmC;AACnC,yBAA4B;AAa5B,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAA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,QAAQ,EAAE;AAC9C,gBAAM,oBAAoB,OAAO,qBAAqB,QAAQ,EAAE;AAEhE,iBAAO;AAAA,YACL,GAAG;AAAA,YAEH;AAAA,YACA,QAAQ,SAAS,GAAG,EAAE,GAAG,OAAO,QAAQ;AAAA,YACxC;AAAA,YAEA;AAAA,YACA,cAAc,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAAA,YAC7C,aAAa,SAAS;AAAA,YAEtB,QACE,aAAa,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,oCAAoC,oBAAI,IAG9C;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,2DAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
1
+ {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n ...message,\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,4BAIO;AACP,uCAA0C;AAC1C,mCAAsC;AAKtC,6BAGO;AACP,gCAAmC;AACnC,yBAA4B;AAc5B,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,IACrD,MAAM,QAAQ,QAAQ;AAAA,IACtB,aAAa,QAAQ,eAAe,CAAC;AAAA,EACvC;AACF;AAkDO,IAAM,iBAAiB,CAAC,YAA4C;AACzE,QAAM,cAAc,QAAQ,SAAS,GAAG,EAAE;AAC1C,SAAO,OAAO,OAAO;AAAA,IACnB,UAAU,QAAQ;AAAA,IAClB,cAAc,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,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,oCAAoC,oBAAI,IAG9C;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,kCAAkC,IAAI,KAAK;AAC9D,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,2DAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
@@ -22,9 +22,9 @@ var toAppendMessage = (messages, message) => {
22
22
  return message;
23
23
  }
24
24
  return {
25
+ ...message,
25
26
  parentId: message.parentId ?? messages.at(-1)?.id ?? null,
26
27
  role: message.role ?? "user",
27
- content: message.content,
28
28
  attachments: message.attachments ?? []
29
29
  };
30
30
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAiBA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAKtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAa5B,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,MACzC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,aAAa;AAC3D,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,IACrD,MAAM,QAAQ,QAAQ;AAAA,IACtB,SAAS,QAAQ;AAAA,IACjB,aAAa,QAAQ,eAAe,CAAC;AAAA,EACvC;AACF;AAkDO,IAAM,iBAAiB,CAAC,YAA4C;AACzE,QAAM,cAAc,QAAQ,SAAS,GAAG,EAAE;AAC1C,SAAO,OAAO,OAAO;AAAA,IACnB,UAAU,QAAQ;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,YAAY,QAAQ;AAAA,IACpB,WACE,aAAa,SAAS,cAClB,QACA,YAAY,OAAO,SAAS;AAAA,IAClC,UAAU,QAAQ;AAAA,IAClB,aAAa,QAAQ;AAAA,IACrB,QAAQ,QAAQ;AAAA,IAChB,QAAQ,Q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AI,CAAC,SAAS;AACZ,gBAAU,IAAI,0BAA0B;AAAA,QACtC,MAAM,KAAK;AAAA,QACX,UAAU,OAAO;AAAA,UACf,WAAW,CAACA,cACV,KAAK,eAAe,SAAS,EAAE,YAAY,OAAOA,SAAQ;AAAA,QAC9D;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,eAAeA,SAAQ;AAAA,MACtE,CAAC;AACD,WAAK,kCAAkC,IAAI,OAAO,OAAO;AAAA,IAC3D;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
1
+ {"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n RuntimeCapabilities,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n SubmittedFeedback,\n ThreadRuntimeEventType,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport {\n AppendMessage,\n ModelConfig,\n ThreadMessage,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n Subscribable,\n SubscribableWithState,\n} from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimeCore } from \"../runtimes/core/ComposerRuntimeCore\";\nimport { MessageRuntimePath, ThreadRuntimePath } from \"./RuntimePathTypes\";\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: messages.at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n };\n }\n\n if (message.role && message.parentId && message.attachments) {\n return message as AppendMessage;\n }\n\n return {\n ...message,\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n attachments: message.attachments ?? [],\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadState = Readonly<{\n /**\n * The thread ID.\n */\n threadId: string;\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * Follow up message suggestions to show the user.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speech: SpeechState | undefined;\n}>;\n\nexport const getThreadState = (runtime: ThreadRuntimeCore): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: runtime.threadId,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = Readonly<{\n readonly path: ThreadRuntimePath;\n\n readonly composer: ThreadComposerRuntime;\n getState(): ThreadState;\n\n /**\n * @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.\n */\n unstable_getCore(): ThreadRuntimeCore;\n\n append(message: CreateAppendMessage): void;\n startRun(parentId: string | null): void;\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelConfig(): ModelConfig;\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n\n // Legacy methods with deprecations\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n capabilities: Readonly<RuntimeCapabilities>;\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n threadId: string;\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n isDisabled: boolean;\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n isRunning: boolean;\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n messages: readonly ThreadMessage[];\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n suggestions: readonly ThreadSuggestion[];\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n speech: SpeechState | undefined;\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n extras: unknown;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n getBranches: (messageId: string) => readonly string[];\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n switchToBranch: (branchId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n addToolResult: (options: AddToolResultOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n speak: (messageId: string) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).getState().submittedFeedback` instead. This will be removed in 0.6.0.\n */\n getSubmittedFeedback: (messageId: string) => SubmittedFeedback | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n submitFeedback: (feedback: SubmitFeedbackOptions) => void;\n\n /**\n * @deprecated Use `getMesssageById(id).composer` instead. This will be removed in 0.6.0.\n */\n getEditComposer: (messageId: string) => ComposerRuntimeCore | undefined;\n\n /**\n * @deprecated Use `getMesssageById(id).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n beginEdit: (messageId: string) => void;\n}>;\n\nexport class ThreadRuntimeImpl\n implements Omit<ThreadRuntimeCore, \"getMessageById\">, ThreadRuntime\n{\n public get path() {\n return this._threadBinding.path;\n }\n\n /**\n * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.\n */\n public get threadId() {\n return this.getState().threadId;\n }\n\n /**\n * @deprecated Use `getState().isDisabled` instead. This will be removed in 0.6.0.\n */\n public get isDisabled() {\n return this.getState().isDisabled;\n }\n\n /**\n * @deprecated Use `getState().isRunning` instead. This will be removed in 0.6.0.\n */\n public get isRunning() {\n return this.getState().isRunning;\n }\n\n /**\n * @deprecated Use `getState().capabilities` instead. This will be removed in 0.6.0.\n */\n public get capabilities() {\n return this.getState().capabilities;\n }\n\n /**\n * @deprecated Use `getState().extras` instead. This will be removed in 0.6.0.\n */\n public get extras() {\n return this._threadBinding.getState().extras;\n }\n\n /**\n * @deprecated Use `getState().followupSuggestions` instead. This will be removed in 0.6.0.\n */\n public get suggestions() {\n return this._threadBinding.getState().suggestions;\n }\n\n /**\n * @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.\n */\n public get messages() {\n return this._threadBinding.getState().messages;\n }\n\n /**\n * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.\n */\n public get speech() {\n return this._threadBinding.getState().speech;\n }\n\n public unstable_getCore() {\n return this._threadBinding.getState();\n }\n\n private _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(threadBinding: ThreadRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: threadBinding.path,\n getState: () => getThreadState(threadBinding.getState()),\n subscribe: (callback) => threadBinding.subscribe(callback),\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n /**\n * @derprecated Use `getMesssageById(id).getState().branchNumber` / `getMesssageById(id).getState().branchCount` instead. This will be removed in 0.6.0.\n */\n public getBranches(messageId: string) {\n return this._threadBinding.getState().getBranches(messageId);\n }\n\n public getModelConfig() {\n return this._threadBinding.getState().getModelConfig();\n }\n\n // TODO sometimes you want to continue when there is no child message\n public startRun(parentId: string | null) {\n return this._threadBinding.getState().startRun(parentId);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getContentPartByToolCallId(toolCallId).addToolResult({ result })` instead. This will be removed in 0.6.0.\n */\n public addToolResult(options: AddToolResultOptions) {\n this._threadBinding.getState().addToolResult(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).switchToBranch({ options })` instead. This will be removed in 0.6.0.\n */\n public switchToBranch(branchId: string) {\n return this._threadBinding.getState().switchToBranch(branchId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.\n */\n public speak(messageId: string) {\n return this._threadBinding.getState().speak(messageId);\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public getSubmittedFeedback(messageId: string) {\n return this._threadBinding.getState().getSubmittedFeedback(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.\n */\n public submitFeedback(options: SubmitFeedbackOptions) {\n return this._threadBinding.getState().submitFeedback(options);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.\n */\n public getEditComposer(messageId: string) {\n return this._threadBinding.getState().getEditComposer(messageId);\n }\n\n /**\n * @deprecated Use `getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.\n */\n public beginEdit(messageId: string) {\n return this._threadBinding.getState().beginEdit(messageId);\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n\n message,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branches,\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventListenerNestedSubscriptions = new Map<\n string,\n NestedSubscriptionSubject<Subscribable, ThreadRuntimePath>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventListenerNestedSubscriptions.get(event);\n if (!subject) {\n subject = new NestedSubscriptionSubject({\n path: this.path,\n getState: () => ({\n subscribe: (callback) =>\n this._threadBinding.getState().unstable_on(event, callback),\n }),\n subscribe: (callback) => this._threadBinding.outerSubscribe(callback),\n });\n this._eventListenerNestedSubscriptions.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAiBA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAKtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,mBAAm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untime, MessageState } from "./MessageRuntime";
4
4
  export type { ContentPartRuntime, ContentPartState, } from "./ContentPartRuntime";
5
5
  export type { ComposerRuntime, ThreadComposerRuntime, EditComposerRuntime, EditComposerState, ThreadComposerState, ComposerState, } from "./ComposerRuntime";
6
6
  export type { AttachmentRuntime, AttachmentState } from "./AttachmentRuntime";
7
- export type { ThreadManagerRuntime, ThreadManagerState, } from "./ThreadManagerRuntime";
7
+ export type { ThreadListRuntime, ThreadListState } from "./ThreadListRuntime";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrE,YAAY,EACV,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EACV,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrE,YAAY,EACV,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/index.ts"],"sourcesContent":["export type { AssistantRuntime } from \"./AssistantRuntime\";\nexport type { ThreadRuntime, ThreadState } from \"./ThreadRuntime\";\nexport type { MessageRuntime, MessageState } from \"./MessageRuntime\";\nexport type {\n ContentPartRuntime,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nexport type {\n ComposerRuntime,\n ThreadComposerRuntime,\n EditComposerRuntime,\n EditComposerState,\n ThreadComposerState,\n ComposerState,\n} from \"./ComposerRuntime\";\nexport type { AttachmentRuntime, AttachmentState } from \"./AttachmentRuntime\";\nexport type {\n ThreadManagerRuntime,\n ThreadManagerState,\n} from \"./ThreadManagerRuntime\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/api/index.ts"],"sourcesContent":["export type { AssistantRuntime } from \"./AssistantRuntime\";\nexport type { ThreadRuntime, ThreadState } from \"./ThreadRuntime\";\nexport type { MessageRuntime, MessageState } from \"./MessageRuntime\";\nexport type {\n ContentPartRuntime,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nexport type {\n ComposerRuntime,\n ThreadComposerRuntime,\n EditComposerRuntime,\n EditComposerState,\n ThreadComposerState,\n ComposerState,\n} from \"./ComposerRuntime\";\nexport type { AttachmentRuntime, AttachmentState } from \"./AttachmentRuntime\";\nexport type { ThreadListRuntime, ThreadListState } from \"./ThreadListRuntime\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AA+BD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,wBAAwB,CAAC,KAAK,CAqB/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,sEAAqC,CAAC"}
1
+ {"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AA6BD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,wBAAwB,CAAC,KAAK,CAqB/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,sEAAqC,CAAC"}
@@ -42,29 +42,27 @@ var useAssistantRuntimeStore = (runtime) => {
42
42
  var useAssistantToolUIsStore = () => {
43
43
  return (0, import_react.useMemo)(() => (0, import_AssistantToolUIs.makeAssistantToolUIsStore)(), []);
44
44
  };
45
- var useThreadManagerStore = (runtime) => {
46
- const [store] = (0, import_react.useState)(
47
- () => (0, import_zustand.create)(() => runtime.threadManager.getState())
48
- );
45
+ var useThreadListStore = (runtime) => {
46
+ const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime.threadList.getState()));
49
47
  (0, import_react.useEffect)(() => {
50
- const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.threadManager.getState(), true);
48
+ const updateState = () => (0, import_ReadonlyStore.writableStore)(store).setState(runtime.threadList.getState(), true);
51
49
  updateState();
52
- return runtime.threadManager.subscribe(updateState);
50
+ return runtime.threadList.subscribe(updateState);
53
51
  }, [runtime, store]);
54
52
  return store;
55
53
  };
56
54
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
57
55
  const useAssistantRuntime = useAssistantRuntimeStore(runtime);
58
56
  const useToolUIs = useAssistantToolUIsStore();
59
- const useThreadManager = useThreadManagerStore(runtime);
57
+ const useThreadList = useThreadListStore(runtime);
60
58
  const context = (0, import_react.useMemo)(() => {
61
59
  return {
62
60
  useToolUIs,
63
61
  useAssistantRuntime,
64
62
  useAssistantActions: useAssistantRuntime,
65
- useThreadManager
63
+ useThreadList
66
64
  };
67
- }, [useAssistantRuntime, useToolUIs, useThreadManager]);
65
+ }, [useAssistantRuntime, useToolUIs, useThreadList]);
68
66
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_AssistantContext.AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThreadRuntimeProvider.ThreadRuntimeProvider, { runtime: runtime.thread, children }) });
69
67
  };
70
68
  var AssistantRuntimeProvider = (0, import_react.memo)(AssistantRuntimeProviderImpl);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadManagerStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() =>\n create(() => runtime.threadManager.getState()),\n );\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadManager.getState(), true);\n updateState();\n return runtime.threadManager.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadManager = useThreadManagerStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useAssistantActions: useAssistantRuntime,\n useThreadManager,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadManager]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadRuntimeProvider runtime={runtime.thread}>\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAmD;AACnD,8BAAiC;AACjC,8BAA0C;AAC1C,mCAAsC;AAEtC,qBAAuB;AACvB,2BAA8B;AAyDxB;AA9CN,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,aAAO,sBAAQ,UAAM,mDAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,wBAAwB,CAAC,YAA8B;AAC3D,QAAM,CAAC,KAAK,QAAI;AAAA,IAAS,UACvB,uBAAO,MAAM,QAAQ,cAAc,SAAS,CAAC;AAAA,EAC/C;AAEA,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,cAAc,SAAS,GAAG,IAAI;AACtE,gBAAY;AACZ,WAAO,QAAQ,cAAc,UAAU,WAAW;AAAA,EACpD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,mBAAmB,sBAAsB,OAAO;AACtD,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,qBAAqB;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,gBAAgB,CAAC;AAEtD,SACE,4CAAC,yCAAiB,UAAjB,EAA0B,OAAO,SAChC,sDAAC,sDAAsB,SAAS,QAAQ,QACrC,UACH,GACF;AAEJ;AAEO,IAAM,+BAA2B,mBAAK,4BAA4B;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadListStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime.threadList.getState()));\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadList.getState(), true);\n updateState();\n return runtime.threadList.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadList = useThreadListStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useAssistantActions: useAssistantRuntime,\n useThreadList,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadList]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadRuntimeProvider runtime={runtime.thread}>\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAmD;AACnD,8BAAiC;AACjC,8BAA0C;AAC1C,mCAAsC;AAEtC,qBAAuB;AACvB,2BAA8B;AAuDxB;AA5CN,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,aAAO,sBAAQ,UAAM,mDAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,WAAW,SAAS,CAAC,CAAC;AAE1E,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,WAAW,SAAS,GAAG,IAAI;AACnE,gBAAY;AACZ,WAAO,QAAQ,WAAW,UAAU,WAAW;AAAA,EACjD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,qBAAqB;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,aAAa,CAAC;AAEnD,SACE,4CAAC,yCAAiB,UAAjB,EAA0B,OAAO,SAChC,sDAAC,sDAAsB,SAAS,QAAQ,QACrC,UACH,GACF;AAEJ;AAEO,IAAM,+BAA2B,mBAAK,4BAA4B;","names":[]}
@@ -18,29 +18,27 @@ var useAssistantRuntimeStore = (runtime) => {
18
18
  var useAssistantToolUIsStore = () => {
19
19
  return useMemo(() => makeAssistantToolUIsStore(), []);
20
20
  };
21
- var useThreadManagerStore = (runtime) => {
22
- const [store] = useState(
23
- () => create(() => runtime.threadManager.getState())
24
- );
21
+ var useThreadListStore = (runtime) => {
22
+ const [store] = useState(() => create(() => runtime.threadList.getState()));
25
23
  useEffect(() => {
26
- const updateState = () => writableStore(store).setState(runtime.threadManager.getState(), true);
24
+ const updateState = () => writableStore(store).setState(runtime.threadList.getState(), true);
27
25
  updateState();
28
- return runtime.threadManager.subscribe(updateState);
26
+ return runtime.threadList.subscribe(updateState);
29
27
  }, [runtime, store]);
30
28
  return store;
31
29
  };
32
30
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
33
31
  const useAssistantRuntime = useAssistantRuntimeStore(runtime);
34
32
  const useToolUIs = useAssistantToolUIsStore();
35
- const useThreadManager = useThreadManagerStore(runtime);
33
+ const useThreadList = useThreadListStore(runtime);
36
34
  const context = useMemo(() => {
37
35
  return {
38
36
  useToolUIs,
39
37
  useAssistantRuntime,
40
38
  useAssistantActions: useAssistantRuntime,
41
- useThreadManager
39
+ useThreadList
42
40
  };
43
- }, [useAssistantRuntime, useToolUIs, useThreadManager]);
41
+ }, [useAssistantRuntime, useToolUIs, useThreadList]);
44
42
  return /* @__PURE__ */ jsx(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx(ThreadRuntimeProvider, { runtime: runtime.thread, children }) });
45
43
  };
46
44
  var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadManagerStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() =>\n create(() => runtime.threadManager.getState()),\n );\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadManager.getState(), true);\n updateState();\n return runtime.threadManager.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadManager = useThreadManagerStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useAssistantActions: useAssistantRuntime,\n useThreadManager,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadManager]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadRuntimeProvider runtime={runtime.thread}>\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAGA,SAAS,MAAM,WAAW,SAAS,gBAAgB;AACnD,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAyDxB;AA9CN,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,SAAO,QAAQ,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,wBAAwB,CAAC,YAA8B;AAC3D,QAAM,CAAC,KAAK,IAAI;AAAA,IAAS,MACvB,OAAO,MAAM,QAAQ,cAAc,SAAS,CAAC;AAAA,EAC/C;AAEA,YAAU,MAAM;AACd,UAAM,cAAc,MAClB,cAAc,KAAK,EAAE,SAAS,QAAQ,cAAc,SAAS,GAAG,IAAI;AACtE,gBAAY;AACZ,WAAO,QAAQ,cAAc,UAAU,WAAW;AAAA,EACpD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,mBAAmB,sBAAsB,OAAO;AACtD,QAAM,UAAU,QAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,qBAAqB;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,gBAAgB,CAAC;AAEtD,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAChC,8BAAC,yBAAsB,SAAS,QAAQ,QACrC,UACH,GACF;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst useThreadListStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime.threadList.getState()));\n\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.threadList.getState(), true);\n updateState();\n return runtime.threadList.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const useThreadList = useThreadListStore(runtime);\n const context = useMemo(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n useAssistantActions: useAssistantRuntime,\n useThreadList,\n };\n }, [useAssistantRuntime, useToolUIs, useThreadList]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadRuntimeProvider runtime={runtime.thread}>\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAGA,SAAS,MAAM,WAAW,SAAS,gBAAgB;AACnD,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAuDxB;AA5CN,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,SAAO,QAAQ,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,QAAQ,WAAW,SAAS,CAAC,CAAC;AAE1E,YAAU,MAAM;AACd,UAAM,cAAc,MAClB,cAAc,KAAK,EAAE,SAAS,QAAQ,WAAW,SAAS,GAAG,IAAI;AACnE,gBAAY;AACZ,WAAO,QAAQ,WAAW,UAAU,WAAW;AAAA,EACjD,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,UAAU,QAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,qBAAqB;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,YAAY,aAAa,CAAC;AAEnD,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAChC,8BAAC,yBAAsB,SAAS,QAAQ,QACrC,UACH,GACF;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
@@ -1,8 +1,9 @@
1
1
  import { type FC, type PropsWithChildren } from "react";
2
2
  import { AttachmentRuntime } from "../../api/AttachmentRuntime";
3
- type AttachmentRuntimeProviderProps = PropsWithChildren<{
4
- runtime: AttachmentRuntime;
5
- }>;
6
- export declare const AttachmentRuntimeProvider: FC<AttachmentRuntimeProviderProps>;
7
- export {};
3
+ export declare namespace AttachmentRuntimeProvider {
4
+ type Props = PropsWithChildren<{
5
+ runtime: AttachmentRuntime;
6
+ }>;
7
+ }
8
+ export declare const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props>;
8
9
  //# sourceMappingURL=AttachmentRuntimeProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AttachmentRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EAAE,EACP,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,KAAK,8BAA8B,GAAG,iBAAiB,CAAC;IACtD,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC,CAAC;AAuBH,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,8BAA8B,CAoBxE,CAAC"}
1
+ {"version":3,"file":"AttachmentRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EAAE,EACP,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,yBAAiB,yBAAyB,CAAC;IACzC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC,OAAO,EAAE,iBAAiB,CAAC;KAC5B,CAAC,CAAC;CACJ;AAuBD,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,yBAAyB,CAAC,KAAK,CAoBzE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FC,\n type PropsWithChildren,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\n\ntype AttachmentRuntimeProviderProps = PropsWithChildren<{\n runtime: AttachmentRuntime;\n}>;\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\nconst useAttachmentStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProviderProps> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const useAttachment = useAttachmentStore(runtime);\n const source = useAttachment((s) => s.source);\n const context = useMemo(() => {\n return {\n source,\n useAttachmentRuntime,\n useAttachment,\n };\n }, [useAttachmentRuntime, useAttachment]);\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAMO;AACP,qBAAuB;AACvB,+BAAkC;AAClC,2BAA8B;AA4C1B;AArCJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AACA,IAAM,qBAAqB,CAAC,YAA+B;AACzD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAgE,CAAC;AAAA,EAC5E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,SAAS,cAAc,CAAC,MAAM,EAAE,MAAM;AAC5C,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,sBAAsB,aAAa,CAAC;AAExC,SACE,4CAAC,2CAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/providers/AttachmentRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FC,\n type PropsWithChildren,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { create } from \"zustand\";\nimport { AttachmentContext } from \"../react/AttachmentContext\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\n\nexport namespace AttachmentRuntimeProvider {\n export type Props = PropsWithChildren<{\n runtime: AttachmentRuntime;\n }>;\n}\n\nconst useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\nconst useAttachmentStore = (runtime: AttachmentRuntime) => {\n const [store] = useState(() => create(() => runtime.getState()));\n useEffect(() => {\n const updateState = () =>\n writableStore(store).setState(runtime.getState(), true);\n updateState();\n return runtime.subscribe(updateState);\n }, [runtime, store]);\n\n return store;\n};\n\nexport const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({\n runtime,\n children,\n}) => {\n const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);\n const useAttachment = useAttachmentStore(runtime);\n const source = useAttachment((s) => s.source);\n const context = useMemo(() => {\n return {\n source,\n useAttachmentRuntime,\n useAttachment,\n };\n }, [useAttachmentRuntime, useAttachment]);\n\n return (\n <AttachmentContext.Provider value={context}>\n {children}\n </AttachmentContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAMO;AACP,qBAAuB;AACvB,+BAAkC;AAClC,2BAA8B;AA8C1B;AArCJ,IAAM,4BAA4B,CAAC,YAA+B;AAChE,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AACA,IAAM,qBAAqB,CAAC,YAA+B;AACzD,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;AAC/D,8BAAU,MAAM;AACd,UAAM,cAAc,UAClB,oCAAc,KAAK,EAAE,SAAS,QAAQ,SAAS,GAAG,IAAI;AACxD,gBAAY;AACZ,WAAO,QAAQ,UAAU,WAAW;AAAA,EACtC,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEO,IAAM,4BAAiE,CAAC;AAAA,EAC7E;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAuB,0BAA0B,OAAO;AAC9D,QAAM,gBAAgB,mBAAmB,OAAO;AAChD,QAAM,SAAS,cAAc,CAAC,MAAM,EAAE,MAAM;AAC5C,QAAM,cAAU,sBAAQ,MAAM;AAC5B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,sBAAsB,aAAa,CAAC;AAExC,SACE,4CAAC,2CAAkB,UAAlB,EAA2B,OAAO,SAChC,UACH;AAEJ;","names":[]}