@assistant-ui/core 0.3.13 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/dist/adapters/speech.d.ts.map +1 -1
  2. package/dist/adapters/speech.js +9 -15
  3. package/dist/adapters/speech.js.map +1 -1
  4. package/dist/adapters/thread-history.d.ts +2 -0
  5. package/dist/adapters/thread-history.d.ts.map +1 -1
  6. package/dist/adapters/voice.d.ts.map +1 -1
  7. package/dist/adapters/voice.js +38 -15
  8. package/dist/adapters/voice.js.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/internal.d.ts +3 -2
  13. package/dist/internal.js +8 -7
  14. package/dist/model-context/frame/host.d.ts +1 -1
  15. package/dist/model-context/frame/host.d.ts.map +1 -1
  16. package/dist/model-context/frame/host.js +19 -4
  17. package/dist/model-context/frame/host.js.map +1 -1
  18. package/dist/model-context/frame/provider.d.ts +4 -0
  19. package/dist/model-context/frame/provider.d.ts.map +1 -1
  20. package/dist/model-context/frame/provider.js +50 -3
  21. package/dist/model-context/frame/provider.js.map +1 -1
  22. package/dist/model-context/frame/types.d.ts +4 -1
  23. package/dist/model-context/frame/types.d.ts.map +1 -1
  24. package/dist/model-context/frame/types.js.map +1 -1
  25. package/dist/model-context/registry.d.ts.map +1 -1
  26. package/dist/model-context/registry.js +16 -4
  27. package/dist/model-context/registry.js.map +1 -1
  28. package/dist/react/RuntimeAdapter.d.ts +8 -1
  29. package/dist/react/RuntimeAdapter.d.ts.map +1 -1
  30. package/dist/react/RuntimeAdapter.js +23 -18
  31. package/dist/react/RuntimeAdapter.js.map +1 -1
  32. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  33. package/dist/react/adapters/LocalStorageThreadListAdapter.js +28 -12
  34. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  35. package/dist/react/client/AdaptedRemoteThread.d.ts +11 -0
  36. package/dist/react/client/AdaptedRemoteThread.d.ts.map +1 -0
  37. package/dist/react/client/AdaptedRemoteThread.js +27 -0
  38. package/dist/react/client/AdaptedRemoteThread.js.map +1 -0
  39. package/dist/react/client/InMemoryThreadList.d.ts +19 -0
  40. package/dist/react/client/InMemoryThreadList.d.ts.map +1 -0
  41. package/dist/react/client/InMemoryThreadList.js +418 -0
  42. package/dist/react/client/InMemoryThreadList.js.map +1 -0
  43. package/dist/react/client/Interactables.d.ts.map +1 -1
  44. package/dist/react/client/Interactables.js +159 -102
  45. package/dist/react/client/Interactables.js.map +1 -1
  46. package/dist/react/client/RemoteThreadList.d.ts +34 -0
  47. package/dist/react/client/RemoteThreadList.d.ts.map +1 -0
  48. package/dist/react/client/RemoteThreadList.js +898 -0
  49. package/dist/react/client/RemoteThreadList.js.map +1 -0
  50. package/dist/react/client/Tools.d.ts.map +1 -1
  51. package/dist/react/client/Tools.js +38 -27
  52. package/dist/react/client/Tools.js.map +1 -1
  53. package/dist/react/index.d.ts +7 -2
  54. package/dist/react/index.js +5 -2
  55. package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
  56. package/dist/react/interactables-legacy/Interactables.js +145 -110
  57. package/dist/react/interactables-legacy/Interactables.js.map +1 -1
  58. package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -1
  59. package/dist/react/primitive-hooks/useActionBarCopy.js +20 -19
  60. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  61. package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -1
  62. package/dist/react/primitive-hooks/useActionBarEdit.js +2 -4
  63. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  64. package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -1
  65. package/dist/react/primitive-hooks/useActionBarReload.js +2 -4
  66. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  67. package/dist/react/primitive-hooks/useBranchPickerNext.d.ts.map +1 -1
  68. package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -6
  69. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  70. package/dist/react/primitive-hooks/useBranchPickerPrevious.d.ts.map +1 -1
  71. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -6
  72. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  73. package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -1
  74. package/dist/react/primitive-hooks/useComposerCancel.js +2 -4
  75. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  76. package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
  77. package/dist/react/primitive-hooks/useComposerSend.js +2 -4
  78. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  79. package/dist/react/primitive-hooks/useSuggestionTrigger.d.ts.map +1 -1
  80. package/dist/react/primitive-hooks/useSuggestionTrigger.js +6 -2
  81. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  82. package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts +3 -0
  83. package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -1
  84. package/dist/react/primitive-hooks/useThreadIsEmpty.js +3 -0
  85. package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
  86. package/dist/react/primitive-hooks/useThreadIsRunning.d.ts +3 -0
  87. package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -1
  88. package/dist/react/primitive-hooks/useThreadIsRunning.js +3 -0
  89. package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
  90. package/dist/react/primitives/message/MessageParts.d.ts +13 -0
  91. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  92. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  93. package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
  94. package/dist/react/primitives/thread/ThreadMessages.js +1 -1
  95. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  96. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +24 -10
  97. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  98. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +115 -71
  99. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  100. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +14 -2
  101. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  102. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +232 -63
  103. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  104. package/dist/react/runtimes/RemoteThreadResource.d.ts +30 -0
  105. package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -0
  106. package/dist/react/runtimes/RemoteThreadResource.js +136 -0
  107. package/dist/react/runtimes/RemoteThreadResource.js.map +1 -0
  108. package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +3 -10
  109. package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -1
  110. package/dist/react/runtimes/RuntimeAdapterProvider.js +3 -6
  111. package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
  112. package/dist/react/runtimes/assistant-transport/commandQueue.d.ts +17 -0
  113. package/dist/react/runtimes/assistant-transport/commandQueue.d.ts.map +1 -0
  114. package/dist/react/runtimes/assistant-transport/commandQueue.js +55 -0
  115. package/dist/react/runtimes/assistant-transport/commandQueue.js.map +1 -0
  116. package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts +11 -0
  117. package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts.map +1 -0
  118. package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js +165 -0
  119. package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js.map +1 -0
  120. package/dist/react/runtimes/assistant-transport/runManager.d.ts +15 -0
  121. package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -0
  122. package/dist/react/runtimes/assistant-transport/runManager.js +86 -0
  123. package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -0
  124. package/dist/react/runtimes/assistant-transport/types.d.ts +130 -0
  125. package/dist/react/runtimes/assistant-transport/types.d.ts.map +1 -0
  126. package/dist/react/runtimes/assistant-transport/types.js +0 -0
  127. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts +14 -0
  128. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -0
  129. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js +296 -0
  130. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js.map +1 -0
  131. package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts +7 -0
  132. package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts.map +1 -0
  133. package/dist/react/runtimes/assistant-transport/useConvertedState.js +25 -0
  134. package/dist/react/runtimes/assistant-transport/useConvertedState.js.map +1 -0
  135. package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts +7 -0
  136. package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts.map +1 -0
  137. package/dist/react/runtimes/assistant-transport/useLatestRef.js +27 -0
  138. package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -0
  139. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  140. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +39 -13
  141. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  142. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +2 -1
  143. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  144. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -3
  145. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  146. package/dist/react/runtimes/cloud/auiV0.d.ts +4 -0
  147. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  148. package/dist/react/runtimes/cloud/auiV0.js +7 -0
  149. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  150. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  151. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +60 -17
  152. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  153. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts +16 -0
  154. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts.map +1 -0
  155. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js +36 -0
  156. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -0
  157. package/dist/react/runtimes/external-message-converter.js +14 -14
  158. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  159. package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -1
  160. package/dist/react/runtimes/useExternalStoreRuntime.js +44 -28
  161. package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
  162. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  163. package/dist/react/runtimes/useLocalRuntime.js +1 -1
  164. package/dist/react/runtimes/useRuntimeAdapters.d.ts +9 -0
  165. package/dist/react/runtimes/useRuntimeAdapters.d.ts.map +1 -0
  166. package/dist/react/runtimes/useRuntimeAdapters.js +20 -0
  167. package/dist/react/runtimes/useRuntimeAdapters.js.map +1 -0
  168. package/dist/runtime/api/composer-runtime.d.ts +5 -0
  169. package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
  170. package/dist/runtime/api/composer-runtime.js.map +1 -1
  171. package/dist/runtime/api/message-runtime.js +1 -1
  172. package/dist/runtime/api/thread-list-runtime.d.ts +1 -0
  173. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  174. package/dist/runtime/api/thread-list-runtime.js +4 -2
  175. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  176. package/dist/runtime/api/thread-runtime.d.ts +12 -2
  177. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  178. package/dist/runtime/api/thread-runtime.js +8 -2
  179. package/dist/runtime/api/thread-runtime.js.map +1 -1
  180. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  181. package/dist/runtime/base/base-composer-runtime-core.js +8 -7
  182. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  183. package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
  184. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  185. package/dist/runtime/base/base-thread-runtime-core.js +3 -3
  186. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  187. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +0 -1
  188. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  189. package/dist/runtime/base/default-thread-composer-runtime-core.js +10 -4
  190. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  191. package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
  192. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  193. package/dist/runtime/internal.js +5 -5
  194. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  195. package/dist/runtime/queue/message-queue.js +2 -1
  196. package/dist/runtime/queue/message-queue.js.map +1 -1
  197. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  198. package/dist/runtime/utils/message-repository.js +27 -18
  199. package/dist/runtime/utils/message-repository.js.map +1 -1
  200. package/dist/runtime/utils/thread-runtime-lifecycle.d.ts +8 -0
  201. package/dist/runtime/utils/thread-runtime-lifecycle.d.ts.map +1 -0
  202. package/dist/runtime/utils/thread-runtime-lifecycle.js +11 -0
  203. package/dist/runtime/utils/thread-runtime-lifecycle.js.map +1 -0
  204. package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
  205. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  206. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +4 -1
  207. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  208. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +8 -0
  209. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  210. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +37 -13
  211. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  212. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +102 -0
  213. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -0
  214. package/dist/runtimes/inert/InertThreadRuntimeCore.js +156 -0
  215. package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -0
  216. package/dist/runtimes/internal.d.ts +1 -1
  217. package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
  218. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  219. package/dist/runtimes/local/local-thread-runtime-core.js +78 -19
  220. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  221. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +12 -59
  222. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  223. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +10 -142
  224. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  225. package/dist/runtimes/remote-thread-list/adapter-changed.d.ts +9 -0
  226. package/dist/runtimes/remote-thread-list/adapter-changed.d.ts.map +1 -0
  227. package/dist/runtimes/remote-thread-list/adapter-changed.js +13 -0
  228. package/dist/runtimes/remote-thread-list/adapter-changed.js.map +1 -0
  229. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
  230. package/dist/runtimes/remote-thread-list/empty-thread-core.js +16 -152
  231. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  232. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +2 -0
  233. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
  234. package/dist/runtimes/remote-thread-list/optimistic-state.js +11 -0
  235. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  236. package/dist/runtimes/remote-thread-list/types.d.ts +32 -1
  237. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  238. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +1 -12
  239. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  240. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +67 -38
  241. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  242. package/dist/store/clients/external-thread.js +1 -1
  243. package/dist/store/clients/external-thread.js.map +1 -1
  244. package/dist/store/clients/suggestions.js +2 -2
  245. package/dist/store/clients/suggestions.js.map +1 -1
  246. package/dist/store/clients/thread-selection-events.d.ts +10 -0
  247. package/dist/store/clients/thread-selection-events.d.ts.map +1 -0
  248. package/dist/store/clients/thread-selection-events.js +40 -0
  249. package/dist/store/clients/thread-selection-events.js.map +1 -0
  250. package/dist/store/env.d.ts +5 -0
  251. package/dist/store/env.d.ts.map +1 -0
  252. package/dist/store/env.js +12 -0
  253. package/dist/store/env.js.map +1 -0
  254. package/dist/store/index.d.ts +5 -3
  255. package/dist/store/index.js +4 -2
  256. package/dist/store/internal.d.ts +4 -1
  257. package/dist/store/internal.js +4 -1
  258. package/dist/store/primitive-predicates.d.ts +19 -0
  259. package/dist/store/primitive-predicates.d.ts.map +1 -0
  260. package/dist/store/primitive-predicates.js +19 -0
  261. package/dist/store/primitive-predicates.js.map +1 -0
  262. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  263. package/dist/store/runtime-clients/attachment-runtime-client.js +18 -11
  264. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
  265. package/dist/store/runtime-clients/handle-runtime-action.d.ts +5 -0
  266. package/dist/store/runtime-clients/handle-runtime-action.d.ts.map +1 -0
  267. package/dist/store/runtime-clients/handle-runtime-action.js +14 -0
  268. package/dist/store/runtime-clients/handle-runtime-action.js.map +1 -0
  269. package/dist/store/runtime-clients/handle-thread-list-action.d.ts +5 -0
  270. package/dist/store/runtime-clients/handle-thread-list-action.d.ts.map +1 -0
  271. package/dist/store/runtime-clients/handle-thread-list-action.js +7 -0
  272. package/dist/store/runtime-clients/handle-thread-list-action.js.map +1 -0
  273. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  274. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +62 -29
  275. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  276. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  277. package/dist/store/runtime-clients/thread-list-runtime-client.js +5 -6
  278. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  279. package/dist/store/scopes/composer.d.ts +9 -4
  280. package/dist/store/scopes/composer.d.ts.map +1 -1
  281. package/dist/store/scopes/thread-list-item.d.ts +7 -6
  282. package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
  283. package/dist/store/scopes/thread.d.ts +8 -7
  284. package/dist/store/scopes/thread.d.ts.map +1 -1
  285. package/dist/store/scopes/threads.d.ts +17 -1
  286. package/dist/store/scopes/threads.d.ts.map +1 -1
  287. package/dist/subscribable/subscribable.d.ts +2 -1
  288. package/dist/subscribable/subscribable.d.ts.map +1 -1
  289. package/dist/subscribable/subscribable.js +23 -18
  290. package/dist/subscribable/subscribable.js.map +1 -1
  291. package/dist/types/message.d.ts +1 -1
  292. package/dist/types/message.js.map +1 -1
  293. package/dist/utils/composite-context-provider.d.ts +1 -0
  294. package/dist/utils/composite-context-provider.d.ts.map +1 -1
  295. package/dist/utils/composite-context-provider.js +25 -9
  296. package/dist/utils/composite-context-provider.js.map +1 -1
  297. package/dist/utils/notify-event-listeners.d.ts +2 -2
  298. package/dist/utils/notify-event-listeners.d.ts.map +1 -1
  299. package/dist/utils/notify-event-listeners.js +2 -2
  300. package/dist/utils/notify-event-listeners.js.map +1 -1
  301. package/dist/utils/silent-runtime-action.d.ts +6 -0
  302. package/dist/utils/silent-runtime-action.d.ts.map +1 -0
  303. package/dist/utils/silent-runtime-action.js +7 -0
  304. package/dist/utils/silent-runtime-action.js.map +1 -0
  305. package/package.json +8 -8
  306. package/src/adapters/speech.test.ts +118 -1
  307. package/src/adapters/speech.ts +21 -22
  308. package/src/adapters/thread-history.ts +2 -0
  309. package/src/adapters/voice.test.ts +134 -0
  310. package/src/adapters/voice.ts +35 -27
  311. package/src/index.ts +1 -0
  312. package/src/internal.ts +1 -0
  313. package/src/model-context/frame/host.test.ts +87 -5
  314. package/src/model-context/frame/host.ts +18 -4
  315. package/src/model-context/frame/provider.test.ts +347 -20
  316. package/src/model-context/frame/provider.ts +58 -2
  317. package/src/model-context/frame/types.ts +5 -0
  318. package/src/model-context/registry.test.ts +131 -0
  319. package/src/model-context/registry.ts +16 -6
  320. package/src/react/RuntimeAdapter.test.ts +2 -0
  321. package/src/react/RuntimeAdapter.ts +20 -8
  322. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +34 -17
  323. package/src/react/client/AdaptedRemoteThread.ts +41 -0
  324. package/src/react/client/InMemoryThreadList.test.tsx +148 -0
  325. package/src/react/client/InMemoryThreadList.ts +290 -0
  326. package/src/react/client/Interactables.test.ts +326 -2
  327. package/src/react/client/Interactables.ts +227 -110
  328. package/src/react/client/RemoteThreadList.test.ts +1222 -0
  329. package/src/react/client/RemoteThreadList.ts +1136 -0
  330. package/src/react/client/Tools.ts +36 -29
  331. package/src/react/index.ts +13 -0
  332. package/src/react/interactables-legacy/Interactables.test.ts +317 -0
  333. package/src/react/interactables-legacy/Interactables.ts +204 -128
  334. package/src/react/primitive-hooks/useActionBarCopy.test.ts +15 -0
  335. package/src/react/primitive-hooks/useActionBarCopy.ts +15 -10
  336. package/src/react/primitive-hooks/useActionBarEdit.ts +2 -1
  337. package/src/react/primitive-hooks/useActionBarReload.ts +2 -6
  338. package/src/react/primitive-hooks/useBranchPickerNext.ts +2 -7
  339. package/src/react/primitive-hooks/useBranchPickerPrevious.ts +2 -7
  340. package/src/react/primitive-hooks/useComposerCancel.ts +2 -1
  341. package/src/react/primitive-hooks/useComposerSend.ts +2 -5
  342. package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +11 -0
  343. package/src/react/primitive-hooks/useSuggestionTrigger.ts +4 -5
  344. package/src/react/primitive-hooks/useThreadIsEmpty.ts +3 -0
  345. package/src/react/primitive-hooks/useThreadIsRunning.ts +3 -0
  346. package/src/react/primitives/message/MessageParts.tsx +0 -1
  347. package/src/react/primitives/thread/ThreadMessages.tsx +2 -1
  348. package/src/react/runtimes/RemoteThreadListHookInstanceManager.retry.test.tsx +116 -0
  349. package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +1 -1
  350. package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +57 -6
  351. package/src/react/runtimes/RemoteThreadListHookInstanceManager.title.test.tsx +272 -0
  352. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +171 -124
  353. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.republish.test.ts +87 -0
  354. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +327 -83
  355. package/src/react/runtimes/RemoteThreadResource.test.ts +141 -0
  356. package/src/react/runtimes/RemoteThreadResource.ts +233 -0
  357. package/src/react/runtimes/RuntimeAdapterProvider.tsx +8 -20
  358. package/src/react/runtimes/assistant-transport/commandQueue.ts +68 -0
  359. package/src/react/runtimes/assistant-transport/replayBoundaryStream.test.ts +455 -0
  360. package/src/react/runtimes/assistant-transport/replayBoundaryStream.ts +172 -0
  361. package/src/react/runtimes/assistant-transport/runManager.ts +124 -0
  362. package/src/react/runtimes/assistant-transport/transport-delivery.test.tsx +79 -0
  363. package/src/react/runtimes/assistant-transport/transport-parentid.test.tsx +97 -0
  364. package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +414 -0
  365. package/src/react/runtimes/assistant-transport/types.ts +170 -0
  366. package/src/react/runtimes/assistant-transport/useAssistantTransport.spec.md +141 -0
  367. package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.test.tsx +683 -0
  368. package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.ts +483 -0
  369. package/src/react/runtimes/assistant-transport/useConvertedState.ts +20 -0
  370. package/src/react/runtimes/assistant-transport/useLatestRef.ts +9 -0
  371. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +131 -6
  372. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +61 -15
  373. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +6 -4
  374. package/src/react/runtimes/cloud/auiV0.ts +17 -1
  375. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +98 -3
  376. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +104 -27
  377. package/src/react/runtimes/cloud/useCloudThreadListRuntime.test.tsx +56 -0
  378. package/src/react/runtimes/cloud/useCloudThreadListRuntime.ts +31 -0
  379. package/src/react/runtimes/external-message-converter.test.ts +143 -0
  380. package/src/react/runtimes/external-message-converter.ts +41 -41
  381. package/src/react/runtimes/remote-thread-hook-on-tap.test.ts +58 -0
  382. package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +83 -0
  383. package/src/react/runtimes/useExternalStoreRuntime.suggestions.test.tsx +13 -3
  384. package/src/react/runtimes/useExternalStoreRuntime.ts +7 -0
  385. package/src/react/runtimes/useExternalStoreSharedOptions.ts +3 -1
  386. package/src/react/runtimes/useLocalRuntime.test.tsx +134 -8
  387. package/src/react/runtimes/useRuntimeAdapters.test.tsx +62 -0
  388. package/src/react/runtimes/useRuntimeAdapters.ts +28 -0
  389. package/src/runtime/api/composer-runtime.ts +5 -0
  390. package/src/runtime/api/thread-list-runtime.ts +3 -1
  391. package/src/runtime/api/thread-runtime.ts +20 -2
  392. package/src/runtime/base/base-composer-runtime-core.ts +6 -5
  393. package/src/runtime/base/base-thread-runtime-core.test.ts +191 -0
  394. package/src/runtime/base/base-thread-runtime-core.ts +11 -2
  395. package/src/runtime/base/default-thread-composer-runtime-core.ts +12 -4
  396. package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
  397. package/src/runtime/queue/message-queue.ts +2 -1
  398. package/src/runtime/utils/message-repository.ts +26 -18
  399. package/src/runtime/utils/thread-runtime-lifecycle.ts +18 -0
  400. package/src/runtimes/external-store/external-store-shared-options.ts +3 -1
  401. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
  402. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +103 -34
  403. package/src/runtimes/inert/InertThreadRuntimeCore.test.ts +253 -0
  404. package/src/runtimes/inert/InertThreadRuntimeCore.ts +232 -0
  405. package/src/runtimes/local/local-thread-runtime-core.test.ts +692 -4
  406. package/src/runtimes/local/local-thread-runtime-core.ts +117 -22
  407. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +17 -205
  408. package/src/runtimes/remote-thread-list/adapter-changed.ts +10 -0
  409. package/src/runtimes/remote-thread-list/empty-thread-core.ts +28 -217
  410. package/src/runtimes/remote-thread-list/optimistic-state.test.ts +18 -0
  411. package/src/runtimes/remote-thread-list/optimistic-state.ts +13 -0
  412. package/src/runtimes/remote-thread-list/types.ts +34 -0
  413. package/src/runtimes/tool-invocations/EDGE_CASES.md +17 -6
  414. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +243 -0
  415. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +127 -61
  416. package/src/store/clients/external-thread.ts +1 -1
  417. package/src/store/clients/model-context-client.test.ts +16 -8
  418. package/src/store/clients/suggestions.ts +2 -2
  419. package/src/store/clients/thread-selection-events.ts +21 -0
  420. package/src/store/env.ts +11 -0
  421. package/src/store/index.ts +14 -1
  422. package/src/store/internal.ts +13 -0
  423. package/src/store/primitive-predicates.test.ts +184 -0
  424. package/src/store/primitive-predicates.ts +43 -0
  425. package/src/store/runtime-clients/attachment-runtime-client.test.ts +41 -0
  426. package/src/store/runtime-clients/attachment-runtime-client.ts +2 -1
  427. package/src/store/runtime-clients/handle-runtime-action.test.ts +40 -0
  428. package/src/store/runtime-clients/handle-runtime-action.ts +14 -0
  429. package/src/store/runtime-clients/handle-thread-list-action.test.ts +69 -0
  430. package/src/store/runtime-clients/handle-thread-list-action.ts +6 -0
  431. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +15 -7
  432. package/src/store/runtime-clients/thread-list-runtime-client.ts +9 -6
  433. package/src/store/scopes/composer.ts +9 -4
  434. package/src/store/scopes/thread-list-item.ts +7 -6
  435. package/src/store/scopes/thread.ts +8 -7
  436. package/src/store/scopes/threads.ts +14 -0
  437. package/src/subscribable/subscribable.test.ts +77 -1
  438. package/src/subscribable/subscribable.ts +38 -23
  439. package/src/tests/MessageRepository.test.ts +48 -0
  440. package/src/tests/RemoteThreadListThreadListRuntimeCore-errors.test.ts +2 -2
  441. package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +8 -6
  442. package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-unarchive.test.ts +25 -0
  443. package/src/tests/auiV0Encode.test.ts +66 -0
  444. package/src/tests/base-composer-runtime-core-send.test.ts +30 -0
  445. package/src/tests/base-composer-runtime-core.test.ts +28 -0
  446. package/src/tests/composer-can-cancel.test.ts +101 -0
  447. package/src/tests/empty-thread-core.test.ts +6 -0
  448. package/src/tests/external-store-thread-list-runtime-core.test.ts +101 -0
  449. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +211 -1
  450. package/src/tests/external-store-thread-runtime-core.test.ts +124 -0
  451. package/src/tests/external-thread-isEmpty.test.tsx +100 -0
  452. package/src/tests/interactables-toolui-migration.test.tsx +66 -0
  453. package/src/tests/message-queue.test.ts +28 -0
  454. package/src/tests/remote-thread-list-adapter-switch.test.ts +383 -0
  455. package/src/tests/session-reset-notification.test.ts +145 -0
  456. package/src/tests/thread-switch-events.test.tsx +99 -1
  457. package/src/tests/tools-scope-migration.test.tsx +58 -0
  458. package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +67 -0
  459. package/src/types/message.ts +1 -1
  460. package/src/utils/composite-context-provider.test.ts +139 -0
  461. package/src/utils/composite-context-provider.ts +26 -8
  462. package/src/utils/notify-event-listeners.ts +10 -5
  463. package/src/utils/silent-runtime-action.ts +6 -0
@@ -0,0 +1,898 @@
1
+ import { generateId } from "../../utils/id.js";
2
+ import { OptimisticState } from "../../runtimes/remote-thread-list/optimistic-state.js";
3
+ import { classifyThreads, createThreadMappingId, getThreadData, normalizeCursor, updateStatusReducer } from "../../runtimes/remote-thread-list/remote-thread-state.js";
4
+ import { handleThreadListAction } from "../../store/runtime-clients/handle-thread-list-action.js";
5
+ import { useThreadSelectionEvents } from "../../store/clients/thread-selection-events.js";
6
+ import { isDevelopment } from "../../store/env.js";
7
+ import { inMemoryThreadListTransformScopes } from "./InMemoryThreadList.js";
8
+ import { ThreadListAdapterChangedError } from "../../runtimes/remote-thread-list/adapter-changed.js";
9
+ import { AdaptedRemoteThread } from "./AdaptedRemoteThread.js";
10
+ import { AssistantMessageStream } from "assistant-stream";
11
+ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
12
+ import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "@assistant-ui/tap/react-shim";
13
+ import { resource, withKey } from "@assistant-ui/tap";
14
+ import { attachTransformScopes, useClientLookup, useClientResource } from "@assistant-ui/store/client";
15
+ //#region src/react/client/RemoteThreadList.ts
16
+ const RESOLVED_PROMISE = Promise.resolve();
17
+ const EMPTY_LIST = {
18
+ isLoading: true,
19
+ isLoadingMore: false,
20
+ cursor: void 0,
21
+ newThreadId: void 0,
22
+ threadIds: [],
23
+ archivedThreadIds: [],
24
+ threadIdMap: {},
25
+ threadData: {}
26
+ };
27
+ const threadNotFoundError = (threadIdOrRemoteId, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" was not found while ${action}.`);
28
+ const threadStatusError = (threadIdOrRemoteId, status, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`);
29
+ const toInitializeResult = (result) => ({
30
+ remoteId: result.remoteId,
31
+ externalId: result.externalId
32
+ });
33
+ const applyTitleStream = async (stream, onTitle) => {
34
+ const messageStream = AssistantMessageStream.fromAssistantStream(stream);
35
+ for await (const result of messageStream) onTitle(result.parts.filter((part) => part.type === "text")[0]?.text);
36
+ };
37
+ const seedNewThread = (state) => {
38
+ let id;
39
+ do
40
+ id = `__LOCALID_${generateId()}`;
41
+ while (state.threadIdMap[id]);
42
+ const mappingId = createThreadMappingId(id);
43
+ return {
44
+ id,
45
+ state: {
46
+ ...state,
47
+ newThreadId: id,
48
+ threadIdMap: {
49
+ ...state.threadIdMap,
50
+ [id]: mappingId
51
+ },
52
+ threadData: {
53
+ ...state.threadData,
54
+ [mappingId]: {
55
+ status: "new",
56
+ id,
57
+ remoteId: void 0,
58
+ externalId: void 0,
59
+ title: void 0,
60
+ custom: void 0
61
+ }
62
+ }
63
+ }
64
+ };
65
+ };
66
+ const useThreadListItemClient = (props) => {
67
+ const $ = c(22);
68
+ const { data, isRunning, onSwitchTo, onRename, onUpdateCustom, onArchive, onUnarchive, onDelete, onGenerateTitle, onInitialize, onDetach } = props;
69
+ const t0 = "lastMessageAt" in data ? data.lastMessageAt : void 0;
70
+ let t1;
71
+ if ($[0] !== data.custom || $[1] !== data.externalId || $[2] !== data.id || $[3] !== data.remoteId || $[4] !== data.status || $[5] !== data.title || $[6] !== isRunning || $[7] !== t0) {
72
+ t1 = {
73
+ id: data.id,
74
+ remoteId: data.remoteId,
75
+ externalId: data.externalId,
76
+ title: data.title,
77
+ lastMessageAt: t0,
78
+ status: data.status,
79
+ custom: data.custom,
80
+ isRunning
81
+ };
82
+ $[0] = data.custom;
83
+ $[1] = data.externalId;
84
+ $[2] = data.id;
85
+ $[3] = data.remoteId;
86
+ $[4] = data.status;
87
+ $[5] = data.title;
88
+ $[6] = isRunning;
89
+ $[7] = t0;
90
+ $[8] = t1;
91
+ } else t1 = $[8];
92
+ const state = t1;
93
+ let t2;
94
+ if ($[9] !== state) {
95
+ t2 = () => state;
96
+ $[9] = state;
97
+ $[10] = t2;
98
+ } else t2 = $[10];
99
+ let t3;
100
+ if ($[11] !== onArchive || $[12] !== onDelete || $[13] !== onDetach || $[14] !== onGenerateTitle || $[15] !== onInitialize || $[16] !== onRename || $[17] !== onSwitchTo || $[18] !== onUnarchive || $[19] !== onUpdateCustom || $[20] !== t2) {
101
+ t3 = {
102
+ getState: t2,
103
+ switchTo: onSwitchTo,
104
+ rename: onRename,
105
+ updateCustom: onUpdateCustom,
106
+ archive: onArchive,
107
+ unarchive: onUnarchive,
108
+ delete: onDelete,
109
+ generateTitle: onGenerateTitle,
110
+ initialize: onInitialize,
111
+ detach: onDetach
112
+ };
113
+ $[11] = onArchive;
114
+ $[12] = onDelete;
115
+ $[13] = onDetach;
116
+ $[14] = onGenerateTitle;
117
+ $[15] = onInitialize;
118
+ $[16] = onRename;
119
+ $[17] = onSwitchTo;
120
+ $[18] = onUnarchive;
121
+ $[19] = onUpdateCustom;
122
+ $[20] = t2;
123
+ $[21] = t3;
124
+ } else t3 = $[21];
125
+ return t3;
126
+ };
127
+ const ThreadListItemClient = resource(useThreadListItemClient);
128
+ const collectItemOrder = (listState, mainThreadId) => {
129
+ const ids = [
130
+ listState.newThreadId,
131
+ ...listState.threadIds,
132
+ ...listState.archivedThreadIds,
133
+ mainThreadId
134
+ ].filter((id) => id !== void 0);
135
+ const seenIds = /* @__PURE__ */ new Set();
136
+ const seenRemoteIds = /* @__PURE__ */ new Set();
137
+ const items = [];
138
+ for (const id of ids) {
139
+ const data = getThreadData(listState, id);
140
+ if (!data || seenIds.has(data.id)) continue;
141
+ if (data.remoteId !== void 0 && seenRemoteIds.has(data.remoteId)) continue;
142
+ seenIds.add(data.id);
143
+ if (data.remoteId !== void 0) seenRemoteIds.add(data.remoteId);
144
+ items.push(data);
145
+ }
146
+ return items;
147
+ };
148
+ const itemMatchesId = (item, listState, id) => {
149
+ const data = getThreadData(listState, id);
150
+ return item.id === id || item.id === data?.id || data?.remoteId !== void 0 && (item.id === data.remoteId || item.remoteId === data.remoteId);
151
+ };
152
+ const isSameThread = (listState, left, right) => {
153
+ if (left === right) return true;
154
+ const data = getThreadData(listState, left);
155
+ return data !== void 0 && itemMatchesId(data, listState, right);
156
+ };
157
+ const useRemoteThreadListView = (t0) => {
158
+ const $ = c(39);
159
+ const { listState, mainThreadId, threadFactory, useAdapters, onSwitchTo, onRename, onUpdateCustom, onArchive, onUnarchive, onDelete, onGenerateTitle, onInitialize, onDetach } = t0;
160
+ let t1;
161
+ let t2;
162
+ if ($[0] !== mainThreadId || $[1] !== threadFactory || $[2] !== useAdapters) {
163
+ const thread = threadFactory(mainThreadId);
164
+ const wrapped = useAdapters === void 0 ? thread : AdaptedRemoteThread({
165
+ useAdapters,
166
+ thread
167
+ });
168
+ t1 = useClientResource;
169
+ t2 = thread.key === void 0 ? wrapped : withKey(thread.key, wrapped);
170
+ $[0] = mainThreadId;
171
+ $[1] = threadFactory;
172
+ $[2] = useAdapters;
173
+ $[3] = t1;
174
+ $[4] = t2;
175
+ } else {
176
+ t1 = $[3];
177
+ t2 = $[4];
178
+ }
179
+ const mainThreadClient = t1(t2);
180
+ let t3;
181
+ if ($[5] !== listState || $[6] !== mainThreadId) {
182
+ t3 = collectItemOrder(listState, mainThreadId);
183
+ $[5] = listState;
184
+ $[6] = mainThreadId;
185
+ $[7] = t3;
186
+ } else t3 = $[7];
187
+ const itemOrder = t3;
188
+ let t4;
189
+ if ($[8] !== itemOrder || $[9] !== listState || $[10] !== mainThreadClient || $[11] !== mainThreadId || $[12] !== onArchive || $[13] !== onDelete || $[14] !== onDetach || $[15] !== onGenerateTitle || $[16] !== onInitialize || $[17] !== onRename || $[18] !== onSwitchTo || $[19] !== onUnarchive || $[20] !== onUpdateCustom) {
190
+ let t5;
191
+ if ($[22] !== listState || $[23] !== mainThreadClient || $[24] !== mainThreadId || $[25] !== onArchive || $[26] !== onDelete || $[27] !== onDetach || $[28] !== onGenerateTitle || $[29] !== onInitialize || $[30] !== onRename || $[31] !== onSwitchTo || $[32] !== onUnarchive || $[33] !== onUpdateCustom) {
192
+ t5 = (data) => withKey(data.id, ThreadListItemClient({
193
+ data,
194
+ isRunning: itemMatchesId(data, listState, mainThreadId) && mainThreadClient.state.isRunning,
195
+ onSwitchTo: (options) => handleThreadListAction("switch", () => onSwitchTo(data.id, options)),
196
+ onRename: (title) => handleThreadListAction("rename", () => onRename(data.id, title)),
197
+ onUpdateCustom: (custom) => handleThreadListAction("update custom metadata", () => onUpdateCustom(data.id, custom)),
198
+ onArchive: () => handleThreadListAction("archive", () => onArchive(data.id)),
199
+ onUnarchive: () => handleThreadListAction("unarchive", () => onUnarchive(data.id)),
200
+ onDelete: () => handleThreadListAction("delete", () => onDelete(data.id)),
201
+ onGenerateTitle: () => handleThreadListAction("generate title", () => onGenerateTitle(data.id, mainThreadClient.state.messages)),
202
+ onInitialize: () => onInitialize(data.id),
203
+ onDetach: () => handleThreadListAction("detach", () => onDetach(data.id))
204
+ }));
205
+ $[22] = listState;
206
+ $[23] = mainThreadClient;
207
+ $[24] = mainThreadId;
208
+ $[25] = onArchive;
209
+ $[26] = onDelete;
210
+ $[27] = onDetach;
211
+ $[28] = onGenerateTitle;
212
+ $[29] = onInitialize;
213
+ $[30] = onRename;
214
+ $[31] = onSwitchTo;
215
+ $[32] = onUnarchive;
216
+ $[33] = onUpdateCustom;
217
+ $[34] = t5;
218
+ } else t5 = $[34];
219
+ t4 = itemOrder.map(t5);
220
+ $[8] = itemOrder;
221
+ $[9] = listState;
222
+ $[10] = mainThreadClient;
223
+ $[11] = mainThreadId;
224
+ $[12] = onArchive;
225
+ $[13] = onDelete;
226
+ $[14] = onDetach;
227
+ $[15] = onGenerateTitle;
228
+ $[16] = onInitialize;
229
+ $[17] = onRename;
230
+ $[18] = onSwitchTo;
231
+ $[19] = onUnarchive;
232
+ $[20] = onUpdateCustom;
233
+ $[21] = t4;
234
+ } else t4 = $[21];
235
+ const threadListItems = useClientLookup(t4);
236
+ let t5;
237
+ if ($[35] !== itemOrder || $[36] !== mainThreadClient || $[37] !== threadListItems) {
238
+ t5 = {
239
+ mainThreadClient,
240
+ itemOrder,
241
+ threadListItems
242
+ };
243
+ $[35] = itemOrder;
244
+ $[36] = mainThreadClient;
245
+ $[37] = threadListItems;
246
+ $[38] = t5;
247
+ } else t5 = $[38];
248
+ return t5;
249
+ };
250
+ const useRemoteThreadList = (props) => {
251
+ const { adapter, thread: threadFactory, threadId, onThreadIdChange, onSwitchToThread, onSwitchToNewThread, onDelete } = props;
252
+ const [{ store, initialMainId, session }] = useState(() => {
253
+ const seeded = seedNewThread(EMPTY_LIST);
254
+ return {
255
+ store: new OptimisticState(seeded.state),
256
+ initialMainId: seeded.id,
257
+ session: {
258
+ adapter,
259
+ adapterAtLoad: adapter,
260
+ adapterGeneration: 0,
261
+ loadGeneration: 0,
262
+ switchGeneration: 0,
263
+ loadPromise: void 0,
264
+ loadMorePromise: void 0,
265
+ lastNotifiedRemoteId: void 0,
266
+ lastControlledThreadId: void 0,
267
+ switchTask: void 0,
268
+ mainThreadId: seeded.id,
269
+ isFirstThreadIdEffect: true,
270
+ onThreadIdChange,
271
+ onSwitchToThread,
272
+ onSwitchToNewThread
273
+ }
274
+ };
275
+ });
276
+ session.adapter = adapter;
277
+ const listState = useSyncExternalStore((onStoreChange) => store.subscribe(onStoreChange), () => store.value, () => store.value);
278
+ const [mainThreadId, setMainThreadId] = useState(initialMainId);
279
+ const assignMainThreadId = useCallback((id) => {
280
+ session.mainThreadId = id;
281
+ setMainThreadId(id);
282
+ }, [session]);
283
+ useThreadSelectionEvents(mainThreadId);
284
+ useEffect(() => {
285
+ session.adapter = adapter;
286
+ session.mainThreadId = mainThreadId;
287
+ session.onThreadIdChange = onThreadIdChange;
288
+ session.onSwitchToThread = onSwitchToThread;
289
+ session.onSwitchToNewThread = onSwitchToNewThread;
290
+ }, [
291
+ adapter,
292
+ mainThreadId,
293
+ onSwitchToNewThread,
294
+ onSwitchToThread,
295
+ onThreadIdChange,
296
+ session
297
+ ]);
298
+ const notifyRemoteId = useCallback((remoteId, emit) => {
299
+ if (session.lastNotifiedRemoteId === remoteId) return;
300
+ session.lastNotifiedRemoteId = remoteId;
301
+ if (emit) session.onThreadIdChange?.(remoteId);
302
+ }, [session]);
303
+ const getLoadThreadsPromise = useCallback(() => {
304
+ if (session.loadPromise) return session.loadPromise;
305
+ const generation = session.loadGeneration;
306
+ const adapter_0 = session.adapter;
307
+ session.loadPromise = store.optimisticUpdate({
308
+ execute: () => adapter_0.list(),
309
+ loading: (state) => ({
310
+ ...state,
311
+ isLoading: true
312
+ }),
313
+ then: (state_0, page) => {
314
+ if (generation !== session.loadGeneration) return state_0;
315
+ session.adapterAtLoad = adapter_0;
316
+ const fresh = classifyThreads(page.threads, {
317
+ threadIds: [],
318
+ archivedThreadIds: [],
319
+ threadIdMap: {},
320
+ threadData: {}
321
+ });
322
+ return {
323
+ ...state_0,
324
+ isLoading: false,
325
+ cursor: normalizeCursor(page.nextCursor),
326
+ threadIds: fresh.threadIds,
327
+ archivedThreadIds: fresh.archivedThreadIds,
328
+ threadIdMap: {
329
+ ...state_0.threadIdMap,
330
+ ...fresh.threadIdMap
331
+ },
332
+ threadData: {
333
+ ...state_0.threadData,
334
+ ...fresh.threadData
335
+ }
336
+ };
337
+ }
338
+ }).catch((error) => {
339
+ if (generation !== session.loadGeneration) return;
340
+ console.error("[assistant-ui] thread list load failed:", error);
341
+ session.loadPromise = void 0;
342
+ store.update({
343
+ ...store.baseValue,
344
+ isLoading: false
345
+ });
346
+ }).then(() => {});
347
+ return session.loadPromise;
348
+ }, [session, store]);
349
+ const reload = useCallback(() => {
350
+ const adapterChanged = adapter !== session.adapterAtLoad;
351
+ session.loadGeneration++;
352
+ session.loadPromise = void 0;
353
+ session.loadMorePromise = void 0;
354
+ if (adapterChanged) {
355
+ session.adapterGeneration++;
356
+ session.switchGeneration++;
357
+ session.switchTask = void 0;
358
+ session.adapterAtLoad = adapter;
359
+ const seeded_0 = seedNewThread(EMPTY_LIST);
360
+ store.reset({
361
+ ...seeded_0.state,
362
+ isLoading: true
363
+ });
364
+ assignMainThreadId(seeded_0.id);
365
+ notifyRemoteId(void 0, true);
366
+ } else store.update({
367
+ ...store.baseValue,
368
+ cursor: void 0
369
+ });
370
+ return getLoadThreadsPromise();
371
+ }, [
372
+ adapter,
373
+ assignMainThreadId,
374
+ getLoadThreadsPromise,
375
+ notifyRemoteId,
376
+ session,
377
+ store
378
+ ]);
379
+ useEffect(() => {
380
+ getLoadThreadsPromise();
381
+ }, [getLoadThreadsPromise]);
382
+ useEffect(() => {
383
+ if (!isDevelopment) return;
384
+ if (adapter.unstable_useAdapters !== void 0) return;
385
+ if (adapter.unstable_Provider === void 0) return;
386
+ console.warn("[assistant-ui] RemoteThreadList ignores RemoteThreadListAdapter.unstable_Provider. Expose unstable_useAdapters so per-thread history loads on this entry. useRemoteThreadListRuntime still honors unstable_Provider.");
387
+ }, [adapter]);
388
+ const loadMore = useCallback(() => {
389
+ if (session.loadMorePromise) return session.loadMorePromise;
390
+ const snapshot = store.value;
391
+ if (snapshot.cursor === void 0 || snapshot.isLoading) return RESOLVED_PROMISE;
392
+ const generation_0 = session.loadGeneration;
393
+ const cursor = snapshot.cursor;
394
+ const currentAdapter = session.adapter;
395
+ const task = store.optimisticUpdate({
396
+ execute: () => currentAdapter.list({ after: cursor }),
397
+ loading: (state_1) => ({
398
+ ...state_1,
399
+ isLoadingMore: true
400
+ }),
401
+ then: (state_2, page_0) => {
402
+ if (generation_0 !== session.loadGeneration) return state_2;
403
+ const appended = classifyThreads(page_0.threads, {
404
+ threadIds: [...state_2.threadIds],
405
+ archivedThreadIds: [...state_2.archivedThreadIds],
406
+ threadIdMap: { ...state_2.threadIdMap },
407
+ threadData: { ...state_2.threadData }
408
+ });
409
+ return {
410
+ ...state_2,
411
+ isLoadingMore: false,
412
+ cursor: normalizeCursor(page_0.nextCursor),
413
+ threadIds: appended.threadIds,
414
+ archivedThreadIds: appended.archivedThreadIds,
415
+ threadIdMap: appended.threadIdMap,
416
+ threadData: appended.threadData
417
+ };
418
+ }
419
+ }).catch((error_0) => {
420
+ if (generation_0 !== session.loadGeneration) return;
421
+ console.error("[assistant-ui] thread list loadMore failed:", error_0);
422
+ }).then(() => {
423
+ if (session.loadMorePromise === task) session.loadMorePromise = void 0;
424
+ });
425
+ session.loadMorePromise = task;
426
+ return task;
427
+ }, [session, store]);
428
+ const startSwitch = useCallback((run) => {
429
+ const generation_1 = ++session.switchGeneration;
430
+ let settle;
431
+ const task_0 = new Promise((resolve, reject) => {
432
+ settle = (error_1) => {
433
+ if (error_1 === void 0) resolve();
434
+ else reject(error_1);
435
+ };
436
+ });
437
+ session.switchTask = task_0;
438
+ run(generation_1).then(() => settle(), (error_2) => settle(error_2));
439
+ return task_0;
440
+ }, [session]);
441
+ const switchToThread = useCallback((threadIdOrRemoteId, options, emitThreadIdChange = true) => startSwitch(async (generation_2) => {
442
+ let data = getThreadData(store.value, threadIdOrRemoteId);
443
+ if (!data) {
444
+ const remoteMetadata = await session.adapter.fetch(threadIdOrRemoteId);
445
+ if (generation_2 !== session.switchGeneration) return;
446
+ const state_3 = store.value;
447
+ const mappingId = createThreadMappingId(remoteMetadata.remoteId);
448
+ const wasInTarget = remoteMetadata.status === "regular" ? state_3.threadIds.includes(remoteMetadata.remoteId) : state_3.archivedThreadIds.includes(remoteMetadata.remoteId);
449
+ const threadIdsWithoutRemote = state_3.threadIds.filter((id_0) => id_0 !== remoteMetadata.remoteId);
450
+ const archivedThreadIdsWithoutRemote = state_3.archivedThreadIds.filter((id_1) => id_1 !== remoteMetadata.remoteId);
451
+ store.update({
452
+ ...state_3,
453
+ threadIds: remoteMetadata.status === "regular" ? wasInTarget ? state_3.threadIds : [...threadIdsWithoutRemote, remoteMetadata.remoteId] : threadIdsWithoutRemote,
454
+ archivedThreadIds: remoteMetadata.status === "archived" ? wasInTarget ? state_3.archivedThreadIds : [...archivedThreadIdsWithoutRemote, remoteMetadata.remoteId] : archivedThreadIdsWithoutRemote,
455
+ threadIdMap: {
456
+ ...state_3.threadIdMap,
457
+ [remoteMetadata.remoteId]: mappingId
458
+ },
459
+ threadData: {
460
+ ...state_3.threadData,
461
+ [mappingId]: {
462
+ id: mappingId,
463
+ initializeTask: Promise.resolve({
464
+ remoteId: remoteMetadata.remoteId,
465
+ externalId: remoteMetadata.externalId
466
+ }),
467
+ remoteId: remoteMetadata.remoteId,
468
+ externalId: remoteMetadata.externalId,
469
+ status: remoteMetadata.status,
470
+ title: remoteMetadata.title,
471
+ lastMessageAt: remoteMetadata.lastMessageAt,
472
+ custom: remoteMetadata.custom
473
+ }
474
+ }
475
+ });
476
+ data = getThreadData(store.value, threadIdOrRemoteId);
477
+ }
478
+ if (!data) throw threadNotFoundError(threadIdOrRemoteId, "switching to it");
479
+ if (isSameThread(store.value, data.id, session.mainThreadId)) return;
480
+ if (data.status === "archived" && options?.unarchive !== false) {
481
+ const current = data;
482
+ const { remoteId: remoteId_0 } = await current.initializeTask;
483
+ if (generation_2 !== session.switchGeneration) return;
484
+ await store.optimisticUpdate({
485
+ execute: () => session.adapter.unarchive(remoteId_0),
486
+ optimistic: (state_4) => updateStatusReducer(state_4, current.id, "regular")
487
+ });
488
+ if (generation_2 !== session.switchGeneration) return;
489
+ data = getThreadData(store.value, current.id) ?? current;
490
+ }
491
+ if (generation_2 !== session.switchGeneration) return;
492
+ assignMainThreadId(data.id);
493
+ notifyRemoteId(data.remoteId, emitThreadIdChange);
494
+ session.onSwitchToThread?.(data.id);
495
+ }), [
496
+ assignMainThreadId,
497
+ notifyRemoteId,
498
+ session,
499
+ startSwitch,
500
+ store
501
+ ]);
502
+ const switchToNewThread = useCallback((emitThreadIdChange_0 = true) => startSwitch(async (generation_3) => {
503
+ while (store.baseValue.newThreadId !== void 0 && store.value.newThreadId === void 0) {
504
+ await store.waitForUpdate();
505
+ if (generation_3 !== session.switchGeneration) return;
506
+ }
507
+ const existing = store.value.newThreadId;
508
+ if (existing !== void 0) {
509
+ const existingId = getThreadData(store.value, existing)?.id ?? existing;
510
+ if (isSameThread(store.value, existingId, session.mainThreadId)) return;
511
+ assignMainThreadId(existingId);
512
+ notifyRemoteId(void 0, emitThreadIdChange_0);
513
+ session.onSwitchToNewThread?.();
514
+ return;
515
+ }
516
+ const seeded_1 = seedNewThread(store.baseValue);
517
+ store.update(seeded_1.state);
518
+ if (generation_3 !== session.switchGeneration) return;
519
+ assignMainThreadId(seeded_1.id);
520
+ notifyRemoteId(void 0, emitThreadIdChange_0);
521
+ session.onSwitchToNewThread?.();
522
+ }), [
523
+ assignMainThreadId,
524
+ notifyRemoteId,
525
+ session,
526
+ startSwitch,
527
+ store
528
+ ]);
529
+ const ensureNotMain = useCallback(async (threadId_0) => {
530
+ if (threadId_0 === store.value.newThreadId) throw new Error("Cannot ensure new thread is not main");
531
+ let lastAwaitedTask;
532
+ while (isSameThread(store.value, threadId_0, session.mainThreadId)) {
533
+ let switchTask = session.switchTask;
534
+ const startedFallback = !switchTask || switchTask === lastAwaitedTask;
535
+ if (startedFallback) switchTask = switchToNewThread();
536
+ lastAwaitedTask = switchTask;
537
+ try {
538
+ await switchTask;
539
+ } catch (error_3) {
540
+ if (startedFallback && session.switchTask === switchTask) throw error_3;
541
+ }
542
+ }
543
+ }, [
544
+ session,
545
+ store,
546
+ switchToNewThread
547
+ ]);
548
+ const requireAdapterGeneration = useCallback((generation_4) => {
549
+ if (generation_4 !== session.adapterGeneration) throw new ThreadListAdapterChangedError();
550
+ }, [session]);
551
+ const initialize = useCallback(async (threadId_1) => {
552
+ const currentAdapter_0 = session.adapter;
553
+ const adapterGeneration = session.adapterGeneration;
554
+ if (store.value.newThreadId !== threadId_1) {
555
+ const data_0 = getThreadData(store.value, threadId_1);
556
+ if (!data_0) throw threadNotFoundError(threadId_1, "initializing it");
557
+ if (data_0.status === "new") throw threadStatusError(threadId_1, data_0.status, "be initialized here");
558
+ const result = toInitializeResult(await data_0.initializeTask);
559
+ requireAdapterGeneration(adapterGeneration);
560
+ return result;
561
+ }
562
+ const result_0 = await store.optimisticUpdate({
563
+ execute: () => {
564
+ requireAdapterGeneration(adapterGeneration);
565
+ return currentAdapter_0.initialize(threadId_1);
566
+ },
567
+ optimistic: (state_5) => updateStatusReducer(state_5, threadId_1, "regular"),
568
+ loading: (state_6, task_1) => {
569
+ const mappingId_0 = createThreadMappingId(threadId_1);
570
+ return {
571
+ ...state_6,
572
+ threadData: {
573
+ ...state_6.threadData,
574
+ [mappingId_0]: {
575
+ ...state_6.threadData[mappingId_0],
576
+ initializeTask: task_1
577
+ }
578
+ }
579
+ };
580
+ },
581
+ then: (state_7, { remoteId: remoteId_1, externalId }) => {
582
+ if (adapterGeneration !== session.adapterGeneration) return state_7;
583
+ const data_1 = getThreadData(state_7, threadId_1);
584
+ if (!data_1) return state_7;
585
+ const mappingId_1 = createThreadMappingId(threadId_1);
586
+ return {
587
+ ...state_7,
588
+ threadIdMap: {
589
+ ...state_7.threadIdMap,
590
+ [remoteId_1]: mappingId_1
591
+ },
592
+ threadData: {
593
+ ...state_7.threadData,
594
+ [mappingId_1]: {
595
+ ...data_1,
596
+ initializeTask: Promise.resolve({
597
+ remoteId: remoteId_1,
598
+ externalId
599
+ }),
600
+ remoteId: remoteId_1,
601
+ externalId
602
+ }
603
+ }
604
+ };
605
+ }
606
+ });
607
+ requireAdapterGeneration(adapterGeneration);
608
+ if (threadId_1 === session.mainThreadId) notifyRemoteId(result_0.remoteId, true);
609
+ return toInitializeResult(result_0);
610
+ }, [
611
+ notifyRemoteId,
612
+ requireAdapterGeneration,
613
+ session,
614
+ store
615
+ ]);
616
+ const rename = useCallback((threadIdOrRemoteId_0, newTitle) => {
617
+ const currentAdapter_1 = session.adapter;
618
+ const adapterGeneration_0 = session.adapterGeneration;
619
+ const data_2 = getThreadData(store.value, threadIdOrRemoteId_0);
620
+ if (!data_2) throw threadNotFoundError(threadIdOrRemoteId_0, "renaming it");
621
+ if (data_2.status === "new") throw threadStatusError(threadIdOrRemoteId_0, data_2.status, "be renamed");
622
+ return store.optimisticUpdate({
623
+ execute: async () => {
624
+ const { remoteId: remoteId_2 } = await data_2.initializeTask;
625
+ requireAdapterGeneration(adapterGeneration_0);
626
+ return currentAdapter_1.rename(remoteId_2, newTitle);
627
+ },
628
+ optimistic: (state_8) => {
629
+ const current_0 = getThreadData(state_8, threadIdOrRemoteId_0);
630
+ if (!current_0) return state_8;
631
+ return {
632
+ ...state_8,
633
+ threadData: {
634
+ ...state_8.threadData,
635
+ [current_0.id]: {
636
+ ...current_0,
637
+ title: newTitle
638
+ }
639
+ }
640
+ };
641
+ }
642
+ });
643
+ }, [
644
+ requireAdapterGeneration,
645
+ session,
646
+ store
647
+ ]);
648
+ const updateCustom = useCallback((threadIdOrRemoteId_1, custom) => {
649
+ const currentAdapter_2 = session.adapter;
650
+ const adapterGeneration_1 = session.adapterGeneration;
651
+ const data_3 = getThreadData(store.value, threadIdOrRemoteId_1);
652
+ if (!data_3) throw threadNotFoundError(threadIdOrRemoteId_1, "updating its custom metadata");
653
+ if (data_3.status === "new") throw threadStatusError(threadIdOrRemoteId_1, data_3.status, "update custom metadata");
654
+ if (!currentAdapter_2.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
655
+ return store.optimisticUpdate({
656
+ execute: async () => {
657
+ const { remoteId: remoteId_3 } = await data_3.initializeTask;
658
+ requireAdapterGeneration(adapterGeneration_1);
659
+ if (!currentAdapter_2.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
660
+ return currentAdapter_2.updateCustom(remoteId_3, custom);
661
+ },
662
+ optimistic: (state_9) => {
663
+ const current_1 = getThreadData(state_9, threadIdOrRemoteId_1);
664
+ if (!current_1) return state_9;
665
+ return {
666
+ ...state_9,
667
+ threadData: {
668
+ ...state_9.threadData,
669
+ [current_1.id]: {
670
+ ...current_1,
671
+ custom
672
+ }
673
+ }
674
+ };
675
+ }
676
+ });
677
+ }, [
678
+ requireAdapterGeneration,
679
+ session,
680
+ store
681
+ ]);
682
+ const archive = useCallback(async (threadIdOrRemoteId_2) => {
683
+ const currentAdapter_3 = session.adapter;
684
+ const adapterGeneration_2 = session.adapterGeneration;
685
+ const data_4 = getThreadData(store.value, threadIdOrRemoteId_2);
686
+ if (!data_4) throw threadNotFoundError(threadIdOrRemoteId_2, "archiving it");
687
+ if (data_4.status !== "regular") throw threadStatusError(threadIdOrRemoteId_2, data_4.status, "be archived");
688
+ await ensureNotMain(data_4.id);
689
+ requireAdapterGeneration(adapterGeneration_2);
690
+ return store.optimisticUpdate({
691
+ execute: async () => {
692
+ const { remoteId: remoteId_4 } = await data_4.initializeTask;
693
+ requireAdapterGeneration(adapterGeneration_2);
694
+ return currentAdapter_3.archive(remoteId_4);
695
+ },
696
+ optimistic: (state_10) => updateStatusReducer(state_10, data_4.id, "archived")
697
+ });
698
+ }, [
699
+ ensureNotMain,
700
+ requireAdapterGeneration,
701
+ session,
702
+ store
703
+ ]);
704
+ const unarchive = useCallback((threadIdOrRemoteId_3) => {
705
+ const currentAdapter_4 = session.adapter;
706
+ const adapterGeneration_3 = session.adapterGeneration;
707
+ const data_5 = getThreadData(store.value, threadIdOrRemoteId_3);
708
+ if (!data_5) throw threadNotFoundError(threadIdOrRemoteId_3, "unarchiving it");
709
+ if (data_5.status !== "archived") throw threadStatusError(threadIdOrRemoteId_3, data_5.status, "be unarchived");
710
+ return store.optimisticUpdate({
711
+ execute: async () => {
712
+ try {
713
+ const { remoteId: remoteId_5 } = await data_5.initializeTask;
714
+ requireAdapterGeneration(adapterGeneration_3);
715
+ return await currentAdapter_4.unarchive(remoteId_5);
716
+ } catch (error_4) {
717
+ if (adapterGeneration_3 === session.adapterGeneration) await ensureNotMain(data_5.id);
718
+ throw error_4;
719
+ }
720
+ },
721
+ optimistic: (state_11) => updateStatusReducer(state_11, data_5.id, "regular")
722
+ });
723
+ }, [
724
+ ensureNotMain,
725
+ requireAdapterGeneration,
726
+ session,
727
+ store
728
+ ]);
729
+ const deleteThread = useCallback(async (threadIdOrRemoteId_4) => {
730
+ const currentAdapter_5 = session.adapter;
731
+ const adapterGeneration_4 = session.adapterGeneration;
732
+ const data_6 = getThreadData(store.value, threadIdOrRemoteId_4);
733
+ if (!data_6) throw threadNotFoundError(threadIdOrRemoteId_4, "deleting it");
734
+ if (data_6.status !== "regular" && data_6.status !== "archived") throw threadStatusError(threadIdOrRemoteId_4, data_6.status, "be deleted");
735
+ await ensureNotMain(data_6.id);
736
+ requireAdapterGeneration(adapterGeneration_4);
737
+ onDelete?.(data_6.id);
738
+ return store.optimisticUpdate({
739
+ execute: async () => {
740
+ const { remoteId: remoteId_6 } = await data_6.initializeTask;
741
+ requireAdapterGeneration(adapterGeneration_4);
742
+ return currentAdapter_5.delete(remoteId_6);
743
+ },
744
+ optimistic: (state_12) => updateStatusReducer(state_12, data_6.id, "deleted")
745
+ });
746
+ }, [
747
+ ensureNotMain,
748
+ onDelete,
749
+ requireAdapterGeneration,
750
+ session,
751
+ store
752
+ ]);
753
+ const generateTitle = useCallback(async (threadIdOrRemoteId_5, messages) => {
754
+ const currentAdapter_6 = session.adapter;
755
+ const adapterGeneration_5 = session.adapterGeneration;
756
+ const data_7 = getThreadData(store.value, threadIdOrRemoteId_5);
757
+ if (!data_7) throw threadNotFoundError(threadIdOrRemoteId_5, "generating its title");
758
+ if (data_7.status === "new") throw threadStatusError(threadIdOrRemoteId_5, data_7.status, "generate a title");
759
+ const { remoteId: remoteId_7 } = await data_7.initializeTask;
760
+ requireAdapterGeneration(adapterGeneration_5);
761
+ if (!isSameThread(store.value, data_7.id, session.mainThreadId)) return;
762
+ if (!messages) return;
763
+ const stream = await currentAdapter_6.generateTitle(remoteId_7, messages);
764
+ requireAdapterGeneration(adapterGeneration_5);
765
+ await applyTitleStream(stream, (newTitle_0) => {
766
+ if (adapterGeneration_5 !== session.adapterGeneration) return;
767
+ const state_13 = store.baseValue;
768
+ const current_2 = getThreadData(state_13, data_7.id);
769
+ if (!current_2) return;
770
+ store.update({
771
+ ...state_13,
772
+ threadData: {
773
+ ...state_13.threadData,
774
+ [current_2.id]: {
775
+ ...current_2,
776
+ title: newTitle_0
777
+ }
778
+ }
779
+ });
780
+ });
781
+ }, [
782
+ requireAdapterGeneration,
783
+ session,
784
+ store
785
+ ]);
786
+ const { mainThreadClient, itemOrder, threadListItems } = useRemoteThreadListView({
787
+ listState,
788
+ mainThreadId,
789
+ threadFactory,
790
+ useAdapters: adapter.unstable_useAdapters,
791
+ onSwitchTo: (id_2, options_0) => switchToThread(id_2, options_0),
792
+ onRename: (id_3, title) => rename(id_3, title),
793
+ onUpdateCustom: (id_4, custom_0) => updateCustom(id_4, custom_0),
794
+ onArchive: (id_5) => archive(id_5),
795
+ onUnarchive: (id_6) => unarchive(id_6),
796
+ onDelete: (id_7) => deleteThread(id_7),
797
+ onGenerateTitle: (id_8, messages_0) => generateTitle(id_8, messages_0),
798
+ onInitialize: async (id_9) => toInitializeResult(await initialize(id_9)),
799
+ onDetach: (id_10) => ensureNotMain(id_10)
800
+ });
801
+ const mainRemoteId = getThreadData(listState, mainThreadId)?.remoteId;
802
+ useEffect(() => {
803
+ if (session.lastNotifiedRemoteId === mainRemoteId) return;
804
+ session.lastNotifiedRemoteId = mainRemoteId;
805
+ onThreadIdChange?.(mainRemoteId);
806
+ }, [
807
+ mainRemoteId,
808
+ onThreadIdChange,
809
+ session
810
+ ]);
811
+ useEffect(() => {
812
+ if (session.isFirstThreadIdEffect) {
813
+ session.isFirstThreadIdEffect = false;
814
+ session.lastControlledThreadId = threadId;
815
+ if (threadId === void 0) return;
816
+ handleThreadListAction("switch", () => switchToThread(threadId, void 0, false));
817
+ return;
818
+ }
819
+ if (Object.is(session.lastControlledThreadId, threadId)) return;
820
+ session.lastControlledThreadId = threadId;
821
+ if (threadId === void 0) {
822
+ handleThreadListAction("create", () => switchToNewThread(false));
823
+ return;
824
+ }
825
+ handleThreadListAction("switch", () => switchToThread(threadId, void 0, false));
826
+ }, [
827
+ session,
828
+ switchToNewThread,
829
+ switchToThread,
830
+ threadId
831
+ ]);
832
+ const state_14 = useMemo(() => ({
833
+ mainThreadId,
834
+ newThreadId: listState.newThreadId ?? null,
835
+ isLoading: listState.isLoading,
836
+ isLoadingMore: listState.isLoadingMore,
837
+ hasMore: listState.cursor !== void 0,
838
+ threadIds: listState.threadIds,
839
+ archivedThreadIds: listState.archivedThreadIds,
840
+ threadItems: threadListItems.state,
841
+ main: mainThreadClient.state
842
+ }), [
843
+ listState.archivedThreadIds,
844
+ listState.cursor,
845
+ listState.isLoading,
846
+ listState.isLoadingMore,
847
+ listState.newThreadId,
848
+ listState.threadIds,
849
+ mainThreadClient.state,
850
+ mainThreadId,
851
+ threadListItems.state
852
+ ]);
853
+ return {
854
+ getState: () => state_14,
855
+ switchToThread: (id_11, options_1) => {
856
+ handleThreadListAction("switch", () => switchToThread(id_11, options_1));
857
+ },
858
+ switchToNewThread: () => {
859
+ handleThreadListAction("create", () => switchToNewThread());
860
+ },
861
+ getLoadThreadsPromise,
862
+ reload,
863
+ reloadMainThread: () => {
864
+ if (getThreadData(store.value, mainThreadId)?.status === "new") return RESOLVED_PROMISE;
865
+ return mainThreadClient.methods.unstable_refetchThread?.() ?? RESOLVED_PROMISE;
866
+ },
867
+ loadMore,
868
+ item: (selector) => {
869
+ if (selector === "main") {
870
+ const index = itemOrder.findIndex((item) => itemMatchesId(item, listState, mainThreadId));
871
+ return threadListItems.get({ index });
872
+ }
873
+ if ("id" in selector) {
874
+ const index_0 = itemOrder.findIndex((item_0) => itemMatchesId(item_0, listState, selector.id));
875
+ return threadListItems.get({ index: index_0 });
876
+ }
877
+ const id_12 = (selector.archived ? listState.archivedThreadIds : listState.threadIds)[selector.index];
878
+ if (id_12 === void 0) return threadListItems.get({ index: -1 });
879
+ const index_1 = itemOrder.findIndex((item_1) => itemMatchesId(item_1, listState, id_12));
880
+ return threadListItems.get({ index: index_1 });
881
+ },
882
+ thread: () => mainThreadClient.methods
883
+ };
884
+ };
885
+ /**
886
+ * `AuiConfig` `threads` entry backed by a `RemoteThreadListAdapter`. Thread
887
+ * bodies are born from the `thread` factory inside the client tree, so any
888
+ * `AssistantClient` host can run a remote or cloud list. Per-thread history
889
+ * and attachments come from `unstable_useAdapters`. `useRemoteThreadListRuntime`
890
+ * uses the same hook when `unstable_Provider` is omitted. Key the factory
891
+ * with `withKey` so history reloads when the visible thread changes.
892
+ */
893
+ const RemoteThreadList = resource(useRemoteThreadList);
894
+ attachTransformScopes(useRemoteThreadList, inMemoryThreadListTransformScopes);
895
+ //#endregion
896
+ export { RemoteThreadList };
897
+
898
+ //# sourceMappingURL=RemoteThreadList.js.map