@assistant-ui/core 0.3.14 → 0.3.16

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 (341) hide show
  1. package/dist/adapters/voice.js +11 -0
  2. package/dist/adapters/voice.js.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/internal.d.ts +8 -2
  5. package/dist/internal.js +9 -3
  6. package/dist/model-context/frame/host.d.ts +1 -1
  7. package/dist/model-context/frame/host.d.ts.map +1 -1
  8. package/dist/model-context/frame/host.js +20 -5
  9. package/dist/model-context/frame/host.js.map +1 -1
  10. package/dist/model-context/frame/provider.d.ts +6 -0
  11. package/dist/model-context/frame/provider.d.ts.map +1 -1
  12. package/dist/model-context/frame/provider.js +126 -16
  13. package/dist/model-context/frame/provider.js.map +1 -1
  14. package/dist/model-context/frame/types.d.ts +4 -1
  15. package/dist/model-context/frame/types.d.ts.map +1 -1
  16. package/dist/model-context/frame/types.js.map +1 -1
  17. package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
  18. package/dist/model-context/interactable-composer-metadata.js +1 -1
  19. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  20. package/dist/model-context/registry.d.ts +2 -2
  21. package/dist/model-context/registry.d.ts.map +1 -1
  22. package/dist/model-context/registry.js +9 -28
  23. package/dist/model-context/registry.js.map +1 -1
  24. package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
  25. package/dist/react/client/InMemoryThreadList.js +24 -20
  26. package/dist/react/client/InMemoryThreadList.js.map +1 -1
  27. package/dist/react/client/Interactables.d.ts.map +1 -1
  28. package/dist/react/client/Interactables.js +59 -177
  29. package/dist/react/client/Interactables.js.map +1 -1
  30. package/dist/react/client/RemoteThreadList.d.ts +1 -1
  31. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  32. package/dist/react/client/RemoteThreadList.js +117 -78
  33. package/dist/react/client/RemoteThreadList.js.map +1 -1
  34. package/dist/react/index.d.ts +2 -1
  35. package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
  36. package/dist/react/interactables-legacy/Interactables.js +56 -174
  37. package/dist/react/interactables-legacy/Interactables.js.map +1 -1
  38. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
  39. package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
  40. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
  41. package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
  42. package/dist/react/primitive-hooks/useActionBarCopy.js +7 -1
  43. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  44. package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts +3 -0
  45. package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -1
  46. package/dist/react/primitive-hooks/useThreadIsEmpty.js +3 -0
  47. package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
  48. package/dist/react/primitive-hooks/useThreadIsRunning.d.ts +3 -0
  49. package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -1
  50. package/dist/react/primitive-hooks/useThreadIsRunning.js +3 -0
  51. package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
  52. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  53. package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
  54. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  55. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  56. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +3 -1
  57. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  58. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +6 -0
  59. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  60. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -1
  61. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  62. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +174 -64
  63. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  64. package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
  65. package/dist/react/runtimes/RemoteThreadResource.js +2 -0
  66. package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
  67. package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
  68. package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
  69. package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
  70. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  71. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js +1 -1
  72. package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  73. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
  74. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  75. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +20 -67
  76. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  77. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
  78. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
  79. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
  80. package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
  81. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  82. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +38 -5
  83. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  84. package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
  85. package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
  86. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  87. package/dist/react/runtimes/external-message-converter.d.ts +6 -25
  88. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  89. package/dist/react/runtimes/external-message-converter.js +33 -233
  90. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  91. package/dist/runtime/api/composer-runtime.d.ts +1 -1
  92. package/dist/runtime/api/composer-runtime.js.map +1 -1
  93. package/dist/runtime/api/thread-runtime.d.ts +1 -2
  94. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  95. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
  96. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  97. package/dist/runtime/base/base-composer-runtime-core.js +14 -29
  98. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  99. package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -4
  100. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  101. package/dist/runtime/base/base-thread-runtime-core.js +3 -9
  102. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  103. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
  104. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  105. package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
  106. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  107. package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
  108. package/dist/runtime/interfaces/thread-runtime-core.d.ts +1 -1
  109. package/dist/runtime/internal.d.ts +2 -1
  110. package/dist/runtime/internal.js +2 -1
  111. package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
  112. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  113. package/dist/runtime/queue/message-queue.js +1 -1
  114. package/dist/runtime/queue/message-queue.js.map +1 -1
  115. package/dist/runtime/queue/queue-item.d.ts +12 -0
  116. package/dist/runtime/queue/queue-item.d.ts.map +1 -0
  117. package/dist/runtime/queue/queue-item.js +6 -0
  118. package/dist/runtime/queue/queue-item.js.map +1 -0
  119. package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
  120. package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
  121. package/dist/runtime/utils/abortable-thread-load.js +35 -0
  122. package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
  123. package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
  124. package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
  125. package/dist/runtime/utils/attachment-add-operations.js +43 -0
  126. package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
  127. package/dist/runtime/utils/auto-status.d.ts +6 -1
  128. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  129. package/dist/runtime/utils/auto-status.js +7 -1
  130. package/dist/runtime/utils/auto-status.js.map +1 -1
  131. package/dist/runtime/utils/external-message-conversion.d.ts +47 -0
  132. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
  133. package/dist/runtime/utils/external-message-conversion.js +221 -0
  134. package/dist/runtime/utils/external-message-conversion.js.map +1 -0
  135. package/dist/runtime/utils/external-store-message.d.ts +2 -1
  136. package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
  137. package/dist/runtime/utils/external-store-message.js +2 -1
  138. package/dist/runtime/utils/external-store-message.js.map +1 -1
  139. package/dist/runtime/utils/message-repository-session.d.ts +30 -0
  140. package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
  141. package/dist/runtime/utils/message-repository-session.js +130 -0
  142. package/dist/runtime/utils/message-repository-session.js.map +1 -0
  143. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  144. package/dist/runtime/utils/message-repository.js +30 -22
  145. package/dist/runtime/utils/message-repository.js.map +1 -1
  146. package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
  147. package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
  148. package/dist/runtime/utils/pending-tool-calls.js +22 -0
  149. package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
  150. package/dist/runtime/utils/thread-message-like.d.ts +2 -1
  151. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  152. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  153. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
  154. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  155. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +3 -10
  156. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  157. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +19 -1
  158. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  159. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +124 -20
  160. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  161. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +102 -0
  162. package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -0
  163. package/dist/runtimes/inert/InertThreadRuntimeCore.js +156 -0
  164. package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -0
  165. package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -1
  166. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  167. package/dist/runtimes/local/local-thread-runtime-core.js +45 -8
  168. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  169. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +12 -60
  170. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  171. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +10 -145
  172. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  173. package/dist/runtimes/remote-thread-list/adapter-changed.d.ts +9 -0
  174. package/dist/runtimes/remote-thread-list/adapter-changed.d.ts.map +1 -0
  175. package/dist/runtimes/remote-thread-list/adapter-changed.js +13 -0
  176. package/dist/runtimes/remote-thread-list/adapter-changed.js.map +1 -0
  177. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
  178. package/dist/runtimes/remote-thread-list/empty-thread-core.js +16 -155
  179. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  180. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +2 -0
  181. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
  182. package/dist/runtimes/remote-thread-list/optimistic-state.js +11 -0
  183. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  184. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
  185. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  186. package/dist/runtimes/remote-thread-list/remote-thread-state.js +77 -1
  187. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  188. package/dist/runtimes/remote-thread-list/types.d.ts +3 -0
  189. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  190. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  191. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -0
  192. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  193. package/dist/store/clients/external-thread.d.ts.map +1 -1
  194. package/dist/store/clients/external-thread.js +75 -100
  195. package/dist/store/clients/external-thread.js.map +1 -1
  196. package/dist/store/clients/single-thread-list.d.ts.map +1 -1
  197. package/dist/store/clients/single-thread-list.js +1 -1
  198. package/dist/store/clients/single-thread-list.js.map +1 -1
  199. package/dist/store/clients/suggestions.d.ts.map +1 -1
  200. package/dist/store/clients/suggestions.js +16 -7
  201. package/dist/store/clients/suggestions.js.map +1 -1
  202. package/dist/store/index.d.ts +4 -2
  203. package/dist/store/runtime-clients/handle-runtime-action.d.ts.map +1 -1
  204. package/dist/store/runtime-clients/handle-runtime-action.js +2 -0
  205. package/dist/store/runtime-clients/handle-runtime-action.js.map +1 -1
  206. package/dist/store/scope-registration.d.ts +1 -1
  207. package/dist/store/scopes/composer.d.ts +2 -1
  208. package/dist/store/scopes/composer.d.ts.map +1 -1
  209. package/dist/store/scopes/message.d.ts +1 -1
  210. package/dist/store/scopes/queue-item.d.ts +2 -9
  211. package/dist/store/scopes/queue-item.d.ts.map +1 -1
  212. package/dist/store/scopes/queue-item.js +0 -6
  213. package/dist/types/message.d.ts +8 -4
  214. package/dist/types/message.d.ts.map +1 -1
  215. package/dist/types/message.js.map +1 -1
  216. package/dist/utils/data-url.d.ts +14 -1
  217. package/dist/utils/data-url.d.ts.map +1 -1
  218. package/dist/utils/data-url.js +13 -1
  219. package/dist/utils/data-url.js.map +1 -1
  220. package/dist/utils/invoke-user-callback.d.ts +5 -0
  221. package/dist/utils/invoke-user-callback.d.ts.map +1 -0
  222. package/dist/utils/invoke-user-callback.js +19 -0
  223. package/dist/utils/invoke-user-callback.js.map +1 -0
  224. package/dist/utils/normalizePartStatus.js.map +1 -1
  225. package/dist/utils/silent-runtime-action.d.ts +6 -0
  226. package/dist/utils/silent-runtime-action.d.ts.map +1 -0
  227. package/dist/utils/silent-runtime-action.js +7 -0
  228. package/dist/utils/silent-runtime-action.js.map +1 -0
  229. package/package.json +10 -10
  230. package/src/adapters/voice.test.ts +66 -1
  231. package/src/adapters/voice.ts +8 -0
  232. package/src/internal.ts +13 -0
  233. package/src/model-context/frame/host.test.ts +152 -9
  234. package/src/model-context/frame/host.ts +23 -5
  235. package/src/model-context/frame/provider.test.ts +601 -19
  236. package/src/model-context/frame/provider.ts +158 -20
  237. package/src/model-context/frame/types.ts +5 -0
  238. package/src/model-context/interactable-composer-metadata.ts +1 -1
  239. package/src/model-context/registry.test.ts +44 -0
  240. package/src/model-context/registry.ts +13 -35
  241. package/src/react/client/InMemoryThreadList.test.tsx +49 -0
  242. package/src/react/client/InMemoryThreadList.ts +7 -1
  243. package/src/react/client/Interactables.ts +19 -178
  244. package/src/react/client/RemoteThreadList.test.ts +292 -0
  245. package/src/react/client/RemoteThreadList.ts +119 -82
  246. package/src/react/interactables-legacy/Interactables.ts +20 -177
  247. package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
  248. package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
  249. package/src/react/primitive-hooks/useActionBarCopy.test.ts +15 -0
  250. package/src/react/primitive-hooks/useActionBarCopy.ts +13 -3
  251. package/src/react/primitive-hooks/useThreadIsEmpty.ts +3 -0
  252. package/src/react/primitive-hooks/useThreadIsRunning.ts +3 -0
  253. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +12 -0
  254. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.republish.test.ts +87 -0
  255. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +251 -76
  256. package/src/react/runtimes/RemoteThreadResource.ts +2 -0
  257. package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
  258. package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.test.tsx +58 -0
  259. package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.ts +3 -1
  260. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +92 -0
  261. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +40 -141
  262. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
  263. package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
  264. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +98 -3
  265. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +68 -6
  266. package/src/react/runtimes/external-message-converter.test.ts +0 -14
  267. package/src/react/runtimes/external-message-converter.test.tsx +77 -0
  268. package/src/react/runtimes/external-message-converter.ts +58 -481
  269. package/src/react/runtimes/useLocalRuntime.test.tsx +5 -5
  270. package/src/runtime/api/composer-runtime.ts +1 -1
  271. package/src/runtime/api/message-runtime.test.ts +28 -1
  272. package/src/runtime/base/base-composer-runtime-core.ts +20 -40
  273. package/src/runtime/base/base-thread-runtime-core.test.ts +16 -0
  274. package/src/runtime/base/base-thread-runtime-core.ts +6 -11
  275. package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
  276. package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
  277. package/src/runtime/interfaces/thread-runtime-core.ts +1 -1
  278. package/src/runtime/internal.ts +5 -0
  279. package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
  280. package/src/runtime/queue/message-queue.ts +1 -4
  281. package/src/runtime/queue/queue-item.ts +10 -0
  282. package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
  283. package/src/runtime/utils/abortable-thread-load.ts +53 -0
  284. package/src/runtime/utils/attachment-add-operations.ts +59 -0
  285. package/src/runtime/utils/auto-status.ts +33 -0
  286. package/src/runtime/utils/external-message-conversion.test.ts +113 -0
  287. package/src/runtime/utils/external-message-conversion.ts +494 -0
  288. package/src/runtime/utils/external-store-message.ts +2 -0
  289. package/src/runtime/utils/message-repository-session.test.ts +195 -0
  290. package/src/runtime/utils/message-repository-session.ts +176 -0
  291. package/src/runtime/utils/message-repository.ts +33 -22
  292. package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
  293. package/src/runtime/utils/pending-tool-calls.ts +35 -0
  294. package/src/runtime/utils/thread-message-like.ts +2 -0
  295. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
  296. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +179 -28
  297. package/src/runtimes/inert/InertThreadRuntimeCore.test.ts +253 -0
  298. package/src/runtimes/inert/InertThreadRuntimeCore.ts +232 -0
  299. package/src/runtimes/local/local-thread-runtime-core.test.ts +491 -1
  300. package/src/runtimes/local/local-thread-runtime-core.ts +86 -11
  301. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +17 -209
  302. package/src/runtimes/remote-thread-list/adapter-changed.ts +10 -0
  303. package/src/runtimes/remote-thread-list/empty-thread-core.ts +28 -221
  304. package/src/runtimes/remote-thread-list/optimistic-state.test.ts +18 -0
  305. package/src/runtimes/remote-thread-list/optimistic-state.ts +13 -0
  306. package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +37 -0
  307. package/src/runtimes/remote-thread-list/remote-thread-state.ts +123 -0
  308. package/src/runtimes/remote-thread-list/types.ts +4 -0
  309. package/src/runtimes/tool-invocations/EDGE_CASES.md +17 -0
  310. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +140 -0
  311. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +3 -0
  312. package/src/store/clients/external-thread.ts +17 -62
  313. package/src/store/clients/single-thread-list.ts +4 -1
  314. package/src/store/clients/suggestions.test.ts +31 -0
  315. package/src/store/clients/suggestions.ts +18 -19
  316. package/src/store/runtime-clients/handle-runtime-action.test.ts +40 -0
  317. package/src/store/runtime-clients/handle-runtime-action.ts +3 -0
  318. package/src/store/scopes/message.ts +1 -1
  319. package/src/store/scopes/queue-item.ts +2 -9
  320. package/src/tests/MessageRepository.test.ts +125 -0
  321. package/src/tests/RemoteThreadListThreadListRuntimeCore-errors.test.ts +2 -2
  322. package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +194 -0
  323. package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +8 -6
  324. package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
  325. package/src/tests/empty-thread-core.test.ts +6 -0
  326. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +184 -0
  327. package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
  328. package/src/tests/external-thread-attachments.test.tsx +173 -0
  329. package/src/tests/external-thread-isEmpty.test.tsx +100 -0
  330. package/src/tests/remote-thread-list-adapter-switch.test.ts +383 -0
  331. package/src/tests/single-thread-list-item.test.tsx +47 -0
  332. package/src/tests/thread-message-like.test.ts +39 -1
  333. package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +67 -0
  334. package/src/types/message.ts +9 -4
  335. package/src/utils/data-url.test.ts +52 -1
  336. package/src/utils/data-url.ts +21 -0
  337. package/src/utils/invoke-user-callback.test.ts +82 -0
  338. package/src/utils/invoke-user-callback.ts +31 -0
  339. package/src/utils/normalizePartStatus.ts +1 -1
  340. package/src/utils/silent-runtime-action.ts +6 -0
  341. package/dist/store/scopes/queue-item.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { BaseSubscribable } from "../../subscribable/subscribable.js";
2
- import { generateId } from "../../utils/id.js";
3
2
  import { OptimisticState } from "../../runtimes/remote-thread-list/optimistic-state.js";
4
3
  import { EMPTY_THREAD_CORE } from "../../runtimes/remote-thread-list/empty-thread-core.js";
5
- import { classifyThreads, createThreadMappingId, getThreadData, normalizeCursor, updateStatusReducer } from "../../runtimes/remote-thread-list/remote-thread-state.js";
4
+ import { classifyThreads, createEmptyRemoteThreadState, createThreadMappingId, getThreadData, normalizeCursor, preserveMidLoadTransitions, seedNewThread, statusSnapshot, updateStatusReducer } from "../../runtimes/remote-thread-list/remote-thread-state.js";
5
+ import { ThreadListAdapterChangedError } from "../../runtimes/remote-thread-list/adapter-changed.js";
6
6
  import { useStableRuntimeAdapters } from "./useRuntimeAdapters.js";
7
7
  import { RuntimeAdapterProvider } from "./RuntimeAdapterProvider.js";
8
8
  import { isTitleSourceMessage } from "./RemoteThreadResource.js";
@@ -15,6 +15,7 @@ import { create } from "zustand";
15
15
  //#region src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx
16
16
  const threadNotFoundError = (threadIdOrRemoteId, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" not found while ${action}.`);
17
17
  const threadStatusError = (threadIdOrRemoteId, status, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`);
18
+ const EMPTY_REMOTE_STATE = createEmptyRemoteThreadState();
18
19
  var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
19
20
  _options;
20
21
  _hookManager;
@@ -22,19 +23,13 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
22
23
  _loadThreadsPromise;
23
24
  _loadMorePromise;
24
25
  _loadGeneration = 0;
26
+ _adapterGeneration = 0;
27
+ _replaceListOnNextLoad = false;
28
+ _staleThreadIdsOnReplace;
25
29
  _switchGeneration = 0;
26
30
  _switchTask;
27
31
  _mainThreadId;
28
- _state = new OptimisticState({
29
- isLoading: true,
30
- isLoadingMore: false,
31
- cursor: void 0,
32
- newThreadId: void 0,
33
- threadIds: [],
34
- archivedThreadIds: [],
35
- threadIdMap: {},
36
- threadData: {}
37
- });
32
+ _state = new OptimisticState(EMPTY_REMOTE_STATE);
38
33
  _useAdaptersProvider = ({ children }) => {
39
34
  const useAdapters = this._options.adapter.unstable_useAdapters;
40
35
  if (useAdapters === void 0) return children;
@@ -62,6 +57,8 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
62
57
  getLoadThreadsPromise() {
63
58
  if (!this._loadThreadsPromise) {
64
59
  const generation = this._loadGeneration;
60
+ let replacedList = false;
61
+ const statusAtRequest = statusSnapshot(this._state.baseValue);
65
62
  this._loadThreadsPromise = this._state.optimisticUpdate({
66
63
  execute: () => this._options.adapter.list(),
67
64
  loading: (state) => {
@@ -72,13 +69,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
72
69
  },
73
70
  then: (state, l) => {
74
71
  if (generation !== this._loadGeneration) return state;
72
+ if (this._replaceListOnNextLoad) {
73
+ this._replaceListOnNextLoad = false;
74
+ replacedList = true;
75
+ return this._replaceWithThreads(state, l.threads, normalizeCursor(l.nextCursor));
76
+ }
75
77
  const fresh = classifyThreads(l.threads, {
76
78
  threadIds: [],
77
79
  archivedThreadIds: [],
78
80
  threadIdMap: {},
79
81
  threadData: {}
80
82
  });
81
- return {
83
+ const merged = {
82
84
  ...state,
83
85
  isLoading: false,
84
86
  cursor: normalizeCursor(l.nextCursor),
@@ -93,16 +95,29 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
93
95
  ...fresh.threadData
94
96
  }
95
97
  };
98
+ return preserveMidLoadTransitions(merged, state, statusAtRequest);
96
99
  }
97
100
  }).catch((error) => {
98
101
  if (generation !== this._loadGeneration) return;
99
102
  console.error("[assistant-ui] thread list load failed:", error);
100
103
  this._loadThreadsPromise = void 0;
101
- this._state.update({
102
- ...this._state.baseValue,
103
- isLoading: false
104
- });
105
- }).then(() => {});
104
+ if (!this._replaceListOnNextLoad) {
105
+ this._state.update({
106
+ ...this._state.baseValue,
107
+ isLoading: false
108
+ });
109
+ return;
110
+ }
111
+ this._replaceListOnNextLoad = false;
112
+ replacedList = true;
113
+ this._state.update(this._replaceWithThreads(this._state.baseValue, [], void 0));
114
+ }).then(() => {
115
+ if (!replacedList) return;
116
+ const threadId = this._options.threadId;
117
+ if (threadId === void 0) return;
118
+ if (this.getItemById(threadId)?.id === this._mainThreadId) return;
119
+ this._switchToThreadFromProp(threadId).catch(() => {});
120
+ });
106
121
  }
107
122
  return this._loadThreadsPromise;
108
123
  }
@@ -139,6 +154,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
139
154
  };
140
155
  }
141
156
  }).catch((error) => {
157
+ if (generation !== this._loadGeneration) return;
142
158
  console.error("[assistant-ui] thread list loadMore failed:", error);
143
159
  }).then(() => {
144
160
  if (this._loadMorePromise === dedup) this._loadMorePromise = void 0;
@@ -156,6 +172,9 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
156
172
  this._hookManager = new RemoteThreadListHookInstanceManager(options.runtimeHook, this);
157
173
  this._hookManager.__internal_setDefaultAdapters(this._runtimeAdapters);
158
174
  this._hookManager.__internal_subscribeRunningChanged(() => this._notifySubscribers());
175
+ this._hookManager.__internal_subscribeRuntimeReplaced(() => {
176
+ queueMicrotask(() => this._notifySubscribers());
177
+ });
159
178
  this.useProvider = create(() => ({ Provider: this.resolveProvider(options.adapter) }));
160
179
  this.__internal_setOptions(options);
161
180
  this.switchToNewThread();
@@ -172,8 +191,13 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
172
191
  this._hookManager.setRuntimeHook(options.runtimeHook);
173
192
  if (adapterChanged) {
174
193
  this._loadGeneration++;
194
+ this._adapterGeneration++;
195
+ this._switchGeneration++;
196
+ this._switchTask = void 0;
175
197
  this._loadThreadsPromise = void 0;
176
198
  this._loadMorePromise = void 0;
199
+ this._replaceListOnNextLoad = true;
200
+ this._staleThreadIdsOnReplace = new Set(Object.values(this._state.baseValue.threadData).filter((item) => item.status !== "new").map((item) => item.id));
177
201
  this._state.update({
178
202
  ...this._state.baseValue,
179
203
  cursor: void 0
@@ -181,6 +205,71 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
181
205
  }
182
206
  if (controlledThreadIdChanged) this._switchToThreadFromProp(options.threadId).catch(() => {});
183
207
  }
208
+ _requireAdapterGeneration(generation) {
209
+ if (generation !== this._adapterGeneration) throw new ThreadListAdapterChangedError();
210
+ }
211
+ _requireAdapterSettled() {
212
+ if (this._replaceListOnNextLoad) throw new ThreadListAdapterChangedError();
213
+ }
214
+ _replaceWithThreads(state, threads, cursor) {
215
+ const fresh = classifyThreads(threads, {
216
+ threadIds: [],
217
+ archivedThreadIds: [],
218
+ threadIdMap: {},
219
+ threadData: {}
220
+ });
221
+ const threadIdMap = { ...fresh.threadIdMap };
222
+ const threadData = { ...fresh.threadData };
223
+ const threadIds = [...fresh.threadIds];
224
+ const archivedThreadIds = [...fresh.archivedThreadIds];
225
+ if (state.newThreadId) {
226
+ const mappingId = state.threadIdMap[state.newThreadId];
227
+ const draft = mappingId ? state.threadData[mappingId] : void 0;
228
+ if (draft?.status === "new") {
229
+ threadIdMap[state.newThreadId] = mappingId;
230
+ threadData[mappingId] = draft;
231
+ }
232
+ }
233
+ const stale = this._staleThreadIdsOnReplace;
234
+ if (stale) for (const item of Object.values(state.threadData)) {
235
+ if (stale.has(item.id)) continue;
236
+ if (item.status !== "new" && item.remoteId === void 0) continue;
237
+ const mappingId = createThreadMappingId(item.id);
238
+ if (threadData[mappingId]) continue;
239
+ threadIdMap[item.id] = mappingId;
240
+ if (item.remoteId !== void 0) threadIdMap[item.remoteId] = mappingId;
241
+ threadData[mappingId] = item;
242
+ if (item.remoteId === void 0) continue;
243
+ if (item.status === "regular" && !threadIds.includes(item.remoteId)) threadIds.push(item.remoteId);
244
+ else if (item.status === "archived" && !archivedThreadIds.includes(item.remoteId)) archivedThreadIds.push(item.remoteId);
245
+ }
246
+ this._staleThreadIdsOnReplace = void 0;
247
+ let nextState = {
248
+ ...state,
249
+ isLoading: false,
250
+ cursor,
251
+ threadIds,
252
+ archivedThreadIds,
253
+ threadIdMap,
254
+ threadData,
255
+ newThreadId: state.newThreadId !== void 0 && threadIdMap[state.newThreadId] === void 0 ? void 0 : state.newThreadId
256
+ };
257
+ if (getThreadData(nextState, this._mainThreadId) === void 0) {
258
+ const preservedDraft = nextState.newThreadId;
259
+ if (preservedDraft !== void 0) this._mainThreadId = preservedDraft;
260
+ else {
261
+ const seeded = seedNewThread(nextState);
262
+ this._mainThreadId = seeded.id;
263
+ nextState = seeded.state;
264
+ }
265
+ if (this._options.threadId === void 0) this._notifyThreadIdChange();
266
+ else this._lastNotifiedThreadId = void 0;
267
+ }
268
+ const nextIds = new Set(Object.values(nextState.threadData).map((item) => item.id));
269
+ for (const item of Object.values(state.threadData)) if (!nextIds.has(item.id)) this._hookManager.stopThreadRuntime(item.id);
270
+ this._hookManager.startThreadRuntime(this._mainThreadId).then(() => this._notifySubscribers(), () => void 0);
271
+ return nextState;
272
+ }
184
273
  __internal_load() {
185
274
  this.getLoadThreadsPromise();
186
275
  if (this._initialThreadLoaded) return;
@@ -275,6 +364,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
275
364
  return task;
276
365
  }
277
366
  async _switchToThread(threadIdOrRemoteId, options, generation, emitThreadIdChange) {
367
+ if (this._replaceListOnNextLoad && threadIdOrRemoteId !== this._state.value.newThreadId) throw new ThreadListAdapterChangedError();
278
368
  let data = this.getItemById(threadIdOrRemoteId);
279
369
  if (!data) {
280
370
  const remoteMetadata = await this._options.adapter.fetch(threadIdOrRemoteId);
@@ -350,38 +440,22 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
350
440
  const state = this._state.baseValue;
351
441
  let id = this._state.value.newThreadId;
352
442
  if (id === void 0) {
353
- do
354
- id = `__LOCALID_${generateId()}`;
355
- while (state.threadIdMap[id]);
356
- const mappingId = createThreadMappingId(id);
357
- this._state.update({
358
- ...state,
359
- newThreadId: id,
360
- threadIdMap: {
361
- ...state.threadIdMap,
362
- [id]: mappingId
363
- },
364
- threadData: {
365
- ...state.threadData,
366
- [mappingId]: {
367
- status: "new",
368
- id,
369
- remoteId: void 0,
370
- externalId: void 0,
371
- title: void 0,
372
- custom: void 0
373
- }
374
- }
375
- });
443
+ const next = seedNewThread(state);
444
+ id = next.id;
445
+ this._state.update(next.state);
376
446
  }
377
447
  return this._switchToThread(id, void 0, generation, emitThreadIdChange);
378
448
  }
379
449
  initialize = async (threadId) => {
450
+ const adapter = this._options.adapter;
451
+ const adapterGeneration = this._adapterGeneration;
380
452
  if (this._state.value.newThreadId !== threadId) {
453
+ this._requireAdapterSettled();
381
454
  const data = this.getItemById(threadId);
382
455
  if (!data) throw threadNotFoundError(threadId, "initializing it");
383
456
  if (data.status === "new") throw threadStatusError(threadId, data.status, "be initialized here");
384
457
  const { remoteId, externalId } = await data.initializeTask;
458
+ this._requireAdapterGeneration(adapterGeneration);
385
459
  return {
386
460
  remoteId,
387
461
  externalId
@@ -389,7 +463,8 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
389
463
  }
390
464
  const { remoteId, externalId } = await this._state.optimisticUpdate({
391
465
  execute: () => {
392
- return this._options.adapter.initialize(threadId);
466
+ this._requireAdapterGeneration(adapterGeneration);
467
+ return adapter.initialize(threadId);
393
468
  },
394
469
  optimistic: (state) => {
395
470
  return updateStatusReducer(state, threadId, "regular");
@@ -408,6 +483,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
408
483
  };
409
484
  },
410
485
  then: (state, { remoteId, externalId }) => {
486
+ if (adapterGeneration !== this._adapterGeneration) return state;
411
487
  const data = getThreadData(state, threadId);
412
488
  if (!data) return state;
413
489
  const mappingId = createThreadMappingId(threadId);
@@ -432,46 +508,61 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
432
508
  };
433
509
  }
434
510
  });
511
+ this._requireAdapterGeneration(adapterGeneration);
435
512
  return {
436
513
  remoteId,
437
514
  externalId
438
515
  };
439
516
  };
440
517
  generateTitle = async (threadId) => {
518
+ this._requireAdapterSettled();
519
+ const adapter = this._options.adapter;
520
+ const adapterGeneration = this._adapterGeneration;
441
521
  const data = this.getItemById(threadId);
442
522
  if (!data) throw threadNotFoundError(threadId, "generating its title");
443
523
  if (data.status === "new") throw threadStatusError(threadId, data.status, "generate a title");
444
524
  const { remoteId } = await data.initializeTask;
525
+ this._requireAdapterGeneration(adapterGeneration);
445
526
  const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);
446
527
  if (!runtimeCore) return;
447
528
  const messages = runtimeCore.messages.filter(isTitleSourceMessage);
448
- const stream = await this._options.adapter.generateTitle(remoteId, messages);
529
+ const stream = await adapter.generateTitle(remoteId, messages);
449
530
  const messageStream = AssistantMessageStream.fromAssistantStream(stream);
450
531
  for await (const result of messageStream) {
532
+ if (adapterGeneration !== this._adapterGeneration) return;
451
533
  const newTitle = result.parts.filter((c) => c.type === "text")[0]?.text;
452
- const state = this._state.baseValue;
453
- const currentData = getThreadData(state, data.id);
454
- if (!currentData) continue;
455
- this._state.update({
456
- ...state,
457
- threadData: {
458
- ...state.threadData,
459
- [currentData.id]: {
460
- ...currentData,
461
- title: newTitle
462
- }
534
+ await this._state.optimisticUpdate({
535
+ execute: async () => {},
536
+ optimistic: (state) => {
537
+ if (adapterGeneration !== this._adapterGeneration) return state;
538
+ const currentData = getThreadData(state, data.id);
539
+ if (!currentData) return state;
540
+ return {
541
+ ...state,
542
+ threadData: {
543
+ ...state.threadData,
544
+ [currentData.id]: {
545
+ ...currentData,
546
+ title: newTitle
547
+ }
548
+ }
549
+ };
463
550
  }
464
551
  });
465
552
  }
466
553
  };
467
- rename(threadIdOrRemoteId, newTitle) {
554
+ async rename(threadIdOrRemoteId, newTitle) {
555
+ this._requireAdapterSettled();
556
+ const adapter = this._options.adapter;
557
+ const adapterGeneration = this._adapterGeneration;
468
558
  const data = this.getItemById(threadIdOrRemoteId);
469
559
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "renaming it");
470
560
  if (data.status === "new") throw threadStatusError(threadIdOrRemoteId, data.status, "be renamed");
471
561
  return this._state.optimisticUpdate({
472
562
  execute: async () => {
473
563
  const { remoteId } = await data.initializeTask;
474
- return this._options.adapter.rename(remoteId, newTitle);
564
+ this._requireAdapterGeneration(adapterGeneration);
565
+ return adapter.rename(remoteId, newTitle);
475
566
  },
476
567
  optimistic: (state) => {
477
568
  const data = getThreadData(state, threadIdOrRemoteId);
@@ -489,15 +580,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
489
580
  }
490
581
  });
491
582
  }
492
- updateCustom(threadIdOrRemoteId, custom) {
583
+ async updateCustom(threadIdOrRemoteId, custom) {
584
+ this._requireAdapterSettled();
585
+ const adapter = this._options.adapter;
586
+ const adapterGeneration = this._adapterGeneration;
493
587
  const data = this.getItemById(threadIdOrRemoteId);
494
588
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "updating its custom metadata");
495
589
  if (data.status === "new") throw threadStatusError(threadIdOrRemoteId, data.status, "update custom metadata");
496
- if (!this._options.adapter.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
590
+ if (!adapter.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
497
591
  return this._state.optimisticUpdate({
498
592
  execute: async () => {
499
593
  const { remoteId } = await data.initializeTask;
500
- const adapter = this._options.adapter;
594
+ this._requireAdapterGeneration(adapterGeneration);
501
595
  if (!adapter.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
502
596
  return adapter.updateCustom(remoteId, custom);
503
597
  },
@@ -533,21 +627,29 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
533
627
  }
534
628
  }
535
629
  async archive(threadIdOrRemoteId) {
630
+ this._requireAdapterSettled();
631
+ const adapter = this._options.adapter;
632
+ const adapterGeneration = this._adapterGeneration;
536
633
  const data = this.getItemById(threadIdOrRemoteId);
537
634
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "archiving it");
538
635
  if (data.status !== "regular") throw threadStatusError(threadIdOrRemoteId, data.status, "be archived");
539
636
  await this._ensureThreadIsNotMain(data.id);
637
+ this._requireAdapterGeneration(adapterGeneration);
540
638
  return this._state.optimisticUpdate({
541
639
  execute: async () => {
542
640
  const { remoteId } = await data.initializeTask;
543
- return this._options.adapter.archive(remoteId);
641
+ this._requireAdapterGeneration(adapterGeneration);
642
+ return adapter.archive(remoteId);
544
643
  },
545
644
  optimistic: (state) => {
546
645
  return updateStatusReducer(state, data.id, "archived");
547
646
  }
548
647
  });
549
648
  }
550
- unarchive(threadIdOrRemoteId) {
649
+ async unarchive(threadIdOrRemoteId) {
650
+ this._requireAdapterSettled();
651
+ const adapter = this._options.adapter;
652
+ const adapterGeneration = this._adapterGeneration;
551
653
  const data = this.getItemById(threadIdOrRemoteId);
552
654
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "unarchiving it");
553
655
  if (data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be unarchived");
@@ -555,9 +657,10 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
555
657
  execute: async () => {
556
658
  try {
557
659
  const { remoteId } = await data.initializeTask;
558
- return await this._options.adapter.unarchive(remoteId);
660
+ this._requireAdapterGeneration(adapterGeneration);
661
+ return await adapter.unarchive(remoteId);
559
662
  } catch (error) {
560
- await this._ensureThreadIsNotMain(data.id);
663
+ if (adapterGeneration === this._adapterGeneration) await this._ensureThreadIsNotMain(data.id);
561
664
  throw error;
562
665
  }
563
666
  },
@@ -567,15 +670,20 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
567
670
  });
568
671
  }
569
672
  async delete(threadIdOrRemoteId) {
673
+ this._requireAdapterSettled();
674
+ const adapter = this._options.adapter;
675
+ const adapterGeneration = this._adapterGeneration;
570
676
  const data = this.getItemById(threadIdOrRemoteId);
571
677
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "deleting it");
572
678
  if (data.status !== "regular" && data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be deleted");
573
679
  await this._ensureThreadIsNotMain(data.id);
680
+ this._requireAdapterGeneration(adapterGeneration);
574
681
  this._hookManager.stopThreadRuntime(data.id);
575
682
  return this._state.optimisticUpdate({
576
683
  execute: async () => {
577
684
  const { remoteId } = await data.initializeTask;
578
- return await this._options.adapter.delete(remoteId);
685
+ this._requireAdapterGeneration(adapterGeneration);
686
+ return await adapter.delete(remoteId);
579
687
  },
580
688
  optimistic: (state) => {
581
689
  return updateStatusReducer(state, data.id, "deleted");
@@ -586,10 +694,12 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
586
694
  this._hookManager.__internal_dispose();
587
695
  }
588
696
  async detach(threadIdOrRemoteId) {
697
+ const adapterGeneration = this._adapterGeneration;
589
698
  const data = this.getItemById(threadIdOrRemoteId);
590
699
  if (!data) throw threadNotFoundError(threadIdOrRemoteId, "detaching it");
591
700
  if (data.status !== "regular" && data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be detached");
592
701
  await this._ensureThreadIsNotMain(data.id);
702
+ this._requireAdapterGeneration(adapterGeneration);
593
703
  this._hookManager.stopThreadRuntime(data.id);
594
704
  }
595
705
  useBoundIds = create(() => []);