@assistant-ui/core 0.2.12 → 0.2.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 (445) hide show
  1. package/dist/adapters/attachment.js.map +1 -1
  2. package/dist/adapters/directive-formatter.js.map +1 -1
  3. package/dist/adapters/speech.js.map +1 -1
  4. package/dist/adapters/thread-history.d.ts +3 -1
  5. package/dist/adapters/thread-history.d.ts.map +1 -1
  6. package/dist/adapters/voice.js.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/duplicate-detection.js.map +1 -1
  10. package/dist/internal.d.ts +2 -1
  11. package/dist/internal.js +2 -1
  12. package/dist/model-context/frame/host.js.map +1 -1
  13. package/dist/model-context/frame/provider.js.map +1 -1
  14. package/dist/model-context/frame/types.js.map +1 -1
  15. package/dist/model-context/registry.js.map +1 -1
  16. package/dist/model-context/tool.js.map +1 -1
  17. package/dist/model-context/types.d.ts +1 -0
  18. package/dist/model-context/types.d.ts.map +1 -1
  19. package/dist/model-context/types.js.map +1 -1
  20. package/dist/react/AssistantProvider.js +7 -1
  21. package/dist/react/AssistantProvider.js.map +1 -1
  22. package/dist/react/AssistantRuntimeProvider.js +18 -6
  23. package/dist/react/AssistantRuntimeProvider.js.map +1 -1
  24. package/dist/react/RuntimeAdapter.d.ts +1 -1
  25. package/dist/react/RuntimeAdapter.d.ts.map +1 -1
  26. package/dist/react/RuntimeAdapter.js +35 -6
  27. package/dist/react/RuntimeAdapter.js.map +1 -1
  28. package/dist/react/adapters/LocalStorageThreadListAdapter.js +29 -7
  29. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  30. package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -1
  31. package/dist/react/client/DataRenderers.d.ts +1 -8
  32. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  33. package/dist/react/client/DataRenderers.js +56 -36
  34. package/dist/react/client/DataRenderers.js.map +1 -1
  35. package/dist/react/client/Interactables.d.ts +1 -1
  36. package/dist/react/client/Interactables.d.ts.map +1 -1
  37. package/dist/react/client/Interactables.js +71 -70
  38. package/dist/react/client/Interactables.js.map +1 -1
  39. package/dist/react/client/Tools.d.ts +2 -13
  40. package/dist/react/client/Tools.d.ts.map +1 -1
  41. package/dist/react/client/Tools.js +121 -57
  42. package/dist/react/client/Tools.js.map +1 -1
  43. package/dist/react/client/interactable-model-context.js.map +1 -1
  44. package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
  45. package/dist/react/model-context/define-toolkit.js.map +1 -1
  46. package/dist/react/model-context/external-tool.js.map +1 -1
  47. package/dist/react/model-context/human-tool.js.map +1 -1
  48. package/dist/react/model-context/makeAssistantDataUI.js.map +1 -1
  49. package/dist/react/model-context/makeAssistantTool.js.map +1 -1
  50. package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
  51. package/dist/react/model-context/provider-tool.js.map +1 -1
  52. package/dist/react/model-context/stub-tool.js.map +1 -1
  53. package/dist/react/model-context/toolbox.js.map +1 -1
  54. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  55. package/dist/react/model-context/useAssistantDataUI.js +27 -8
  56. package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
  57. package/dist/react/model-context/useAssistantInstructions.js +33 -10
  58. package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
  59. package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
  60. package/dist/react/model-context/useAssistantTool.js +59 -17
  61. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  62. package/dist/react/model-context/useAssistantToolUI.js +30 -9
  63. package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
  64. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  65. package/dist/react/model-context/useInlineRender.js +35 -8
  66. package/dist/react/model-context/useInlineRender.js.map +1 -1
  67. package/dist/react/model-context/useInteractableState.js +65 -19
  68. package/dist/react/model-context/useInteractableState.js.map +1 -1
  69. package/dist/react/model-context/useToolArgsStatus.js +42 -14
  70. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  71. package/dist/react/primitive-hooks/useActionBarCopy.js +59 -22
  72. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  73. package/dist/react/primitive-hooks/useActionBarEdit.js +25 -7
  74. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  75. package/dist/react/primitive-hooks/useActionBarFeedback.js +49 -13
  76. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  77. package/dist/react/primitive-hooks/useActionBarReload.js +25 -7
  78. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  79. package/dist/react/primitive-hooks/useActionBarSpeak.js +28 -9
  80. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  81. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +25 -7
  82. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  83. package/dist/react/primitive-hooks/useBranchPickerNext.js +27 -11
  84. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  85. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +27 -11
  86. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  87. package/dist/react/primitive-hooks/useComposerAddAttachment.js +24 -8
  88. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  89. package/dist/react/primitive-hooks/useComposerCancel.js +25 -7
  90. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  91. package/dist/react/primitive-hooks/useComposerDictate.js +25 -7
  92. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  93. package/dist/react/primitive-hooks/useComposerSend.js +25 -7
  94. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  95. package/dist/react/primitive-hooks/useEditComposerCancel.js +18 -4
  96. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  97. package/dist/react/primitive-hooks/useEditComposerSend.js +25 -7
  98. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  99. package/dist/react/primitive-hooks/useMessageBranching.js +41 -9
  100. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  101. package/dist/react/primitive-hooks/useMessageError.js +4 -1
  102. package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
  103. package/dist/react/primitive-hooks/useMessageReload.js +25 -7
  104. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  105. package/dist/react/primitive-hooks/useSuggestionTrigger.js +31 -13
  106. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  107. package/dist/react/primitive-hooks/useThreadIsEmpty.js +4 -1
  108. package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
  109. package/dist/react/primitive-hooks/useThreadIsRunning.js +4 -1
  110. package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
  111. package/dist/react/primitive-hooks/useThreadListItemArchive.js +18 -4
  112. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  113. package/dist/react/primitive-hooks/useThreadListItemDelete.js +18 -4
  114. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  115. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +18 -4
  116. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  117. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +18 -4
  118. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  119. package/dist/react/primitive-hooks/useThreadListLoadMore.js +25 -7
  120. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  121. package/dist/react/primitive-hooks/useThreadListNew.js +18 -4
  122. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  123. package/dist/react/primitive-hooks/useThreadMessages.js +4 -1
  124. package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -1
  125. package/dist/react/primitive-hooks/useVoice.js +63 -13
  126. package/dist/react/primitive-hooks/useVoice.js.map +1 -1
  127. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +42 -7
  128. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  129. package/dist/react/primitives/composer/ComposerAttachments.js +67 -16
  130. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  131. package/dist/react/primitives/composer/ComposerIf.js +30 -9
  132. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  133. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  134. package/dist/react/primitives/generativeUI/GenerativeUI.js +55 -13
  135. package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
  136. package/dist/react/primitives/message/MessageAttachments.js +68 -16
  137. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  138. package/dist/react/primitives/message/MessageGroupedParts.d.ts +3 -2
  139. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  140. package/dist/react/primitives/message/MessageGroupedParts.js +6 -6
  141. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  142. package/dist/react/primitives/message/MessageParts.d.ts +28 -1
  143. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  144. package/dist/react/primitives/message/MessageParts.js +665 -163
  145. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  146. package/dist/react/primitives/message/MessageQuote.js +18 -2
  147. package/dist/react/primitives/message/MessageQuote.js.map +1 -1
  148. package/dist/react/primitives/messagePart/MessagePartInProgress.js +6 -2
  149. package/dist/react/primitives/messagePart/MessagePartInProgress.js.map +1 -1
  150. package/dist/react/primitives/part/PartMessages.js +46 -14
  151. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  152. package/dist/react/primitives/thread/ThreadMessages.js +67 -10
  153. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  154. package/dist/react/primitives/thread/ThreadSuggestions.js +50 -10
  155. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  156. package/dist/react/primitives/threadList/ThreadListItems.js +55 -14
  157. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  158. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +15 -2
  159. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
  160. package/dist/react/providers/AttachmentByIndexProvider.js +57 -12
  161. package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
  162. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +33 -11
  163. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  164. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +29 -6
  165. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  166. package/dist/react/providers/MessageByIndexProvider.js +49 -19
  167. package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
  168. package/dist/react/providers/PartByIndexProvider.js +29 -6
  169. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  170. package/dist/react/providers/QueueItemByIndexProvider.js +29 -6
  171. package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
  172. package/dist/react/providers/ReadonlyThreadProvider.js +83 -28
  173. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  174. package/dist/react/providers/SuggestionByIndexProvider.js +29 -6
  175. package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
  176. package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
  177. package/dist/react/providers/TextMessagePartProvider.js +75 -26
  178. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  179. package/dist/react/providers/ThreadListItemByIndexProvider.js +30 -6
  180. package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
  181. package/dist/react/providers/ThreadListItemRuntimeProvider.js +28 -5
  182. package/dist/react/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  183. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +2 -0
  184. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  185. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +19 -4
  186. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  187. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
  188. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  189. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -0
  190. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  191. package/dist/react/runtimes/RuntimeAdapterProvider.js +27 -10
  192. package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
  193. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  194. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +16 -1
  195. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  196. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  197. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  198. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  199. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +19 -17
  200. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  201. package/dist/react/runtimes/createMessageConverter.js.map +1 -1
  202. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  203. package/dist/react/runtimes/external-message-converter.js +67 -30
  204. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  205. package/dist/react/runtimes/useExternalStoreRuntime.js +44 -10
  206. package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
  207. package/dist/react/runtimes/useExternalStoreSharedOptions.js +17 -12
  208. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  209. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  210. package/dist/react/runtimes/useRemoteThreadListRuntime.js +34 -6
  211. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  212. package/dist/react/types/MessagePartComponentTypes.d.ts +5 -6
  213. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  214. package/dist/react/utils/getMessageQuote.js.map +1 -1
  215. package/dist/react/utils/groupParts.d.ts +13 -1
  216. package/dist/react/utils/groupParts.d.ts.map +1 -1
  217. package/dist/react/utils/groupParts.js +17 -5
  218. package/dist/react/utils/groupParts.js.map +1 -1
  219. package/dist/runtime/api/assistant-runtime.js.map +1 -1
  220. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  221. package/dist/runtime/api/bindings.d.ts +1 -0
  222. package/dist/runtime/api/bindings.d.ts.map +1 -1
  223. package/dist/runtime/api/composer-runtime.js.map +1 -1
  224. package/dist/runtime/api/message-part-runtime.d.ts +3 -9
  225. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  226. package/dist/runtime/api/message-part-runtime.js +3 -6
  227. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  228. package/dist/runtime/api/message-runtime.d.ts +2 -0
  229. package/dist/runtime/api/message-runtime.d.ts.map +1 -1
  230. package/dist/runtime/api/message-runtime.js +5 -0
  231. package/dist/runtime/api/message-runtime.js.map +1 -1
  232. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  233. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  234. package/dist/runtime/api/thread-list-runtime.js +1 -0
  235. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  236. package/dist/runtime/api/thread-runtime.d.ts +3 -0
  237. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  238. package/dist/runtime/api/thread-runtime.js +4 -0
  239. package/dist/runtime/api/thread-runtime.js.map +1 -1
  240. package/dist/runtime/base/base-assistant-runtime-core.js.map +1 -1
  241. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  242. package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
  243. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  244. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  245. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
  246. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  247. package/dist/runtime/branch/external-thread-branch-adapter.d.ts +30 -0
  248. package/dist/runtime/branch/external-thread-branch-adapter.d.ts.map +1 -0
  249. package/dist/runtime/branch/external-thread-branch-adapter.js +0 -0
  250. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
  251. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  252. package/dist/runtime/interfaces/thread-runtime-core.d.ts +4 -1
  253. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  254. package/dist/runtime/queue/message-queue.js.map +1 -1
  255. package/dist/runtime/utils/auto-status.js.map +1 -1
  256. package/dist/runtime/utils/external-store-message.js.map +1 -1
  257. package/dist/runtime/utils/message-repository.js.map +1 -1
  258. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +15 -0
  259. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -0
  260. package/dist/runtime/utils/resolveToolApprovalResponse.js +35 -0
  261. package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -0
  262. package/dist/runtime/utils/thread-message-like.d.ts +5 -1
  263. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  264. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  265. package/dist/runtimes/assistant-transport/utils.js.map +1 -1
  266. package/dist/runtimes/external-store/external-store-adapter.d.ts +1 -0
  267. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  268. package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
  269. package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
  270. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  271. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -0
  272. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  273. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +13 -0
  274. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  275. package/dist/runtimes/external-store/thread-message-converter.js.map +1 -1
  276. package/dist/runtimes/local/local-runtime-core.js.map +1 -1
  277. package/dist/runtimes/local/local-runtime-options.d.ts +1 -1
  278. package/dist/runtimes/local/local-thread-list-runtime-core.js.map +1 -1
  279. package/dist/runtimes/local/local-thread-runtime-core.d.ts +9 -1
  280. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  281. package/dist/runtimes/local/local-thread-runtime-core.js +65 -5
  282. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  283. package/dist/runtimes/local/should-continue.js +4 -2
  284. package/dist/runtimes/local/should-continue.js.map +1 -1
  285. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +2 -0
  286. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  287. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +4 -0
  288. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  289. package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
  290. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
  291. package/dist/runtimes/remote-thread-list/empty-thread-core.js +4 -0
  292. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  293. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  294. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +1 -0
  295. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  296. package/dist/runtimes/remote-thread-list/remote-thread-state.js +1 -0
  297. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  298. package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
  299. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  300. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  301. package/dist/store/clients/chain-of-thought-client.d.ts +2 -7
  302. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  303. package/dist/store/clients/chain-of-thought-client.js +39 -20
  304. package/dist/store/clients/chain-of-thought-client.js.map +1 -1
  305. package/dist/store/clients/model-context-client.d.ts +1 -1
  306. package/dist/store/clients/model-context-client.d.ts.map +1 -1
  307. package/dist/store/clients/model-context-client.js +67 -16
  308. package/dist/store/clients/model-context-client.js.map +1 -1
  309. package/dist/store/clients/no-op-composer-client.d.ts +2 -4
  310. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
  311. package/dist/store/clients/no-op-composer-client.js +96 -54
  312. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  313. package/dist/store/clients/runtime-adapter.d.ts +1 -3
  314. package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
  315. package/dist/store/clients/runtime-adapter.js +2 -15
  316. package/dist/store/clients/runtime-adapter.js.map +1 -1
  317. package/dist/store/clients/suggestions.d.ts +1 -4
  318. package/dist/store/clients/suggestions.d.ts.map +1 -1
  319. package/dist/store/clients/suggestions.js +63 -23
  320. package/dist/store/clients/suggestions.js.map +1 -1
  321. package/dist/store/clients/thread-message-client.d.ts +1 -1
  322. package/dist/store/clients/thread-message-client.d.ts.map +1 -1
  323. package/dist/store/clients/thread-message-client.js +184 -73
  324. package/dist/store/clients/thread-message-client.js.map +1 -1
  325. package/dist/store/internal.d.ts +2 -2
  326. package/dist/store/internal.js +2 -2
  327. package/dist/store/runtime-clients/attachment-runtime-client.d.ts +2 -4
  328. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  329. package/dist/store/runtime-clients/attachment-runtime-client.js +31 -7
  330. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
  331. package/dist/store/runtime-clients/composer-runtime-client.d.ts +2 -10
  332. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  333. package/dist/store/runtime-clients/composer-runtime-client.js +195 -72
  334. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
  335. package/dist/store/runtime-clients/liveRef.d.ts +7 -0
  336. package/dist/store/runtime-clients/liveRef.d.ts.map +1 -0
  337. package/dist/store/runtime-clients/liveRef.js +8 -0
  338. package/dist/store/runtime-clients/liveRef.js.map +1 -0
  339. package/dist/store/runtime-clients/message-part-runtime-client.d.ts +2 -4
  340. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
  341. package/dist/store/runtime-clients/message-part-runtime-client.js +49 -9
  342. package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
  343. package/dist/store/runtime-clients/message-runtime-client.d.ts +2 -7
  344. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  345. package/dist/store/runtime-clients/message-runtime-client.js +220 -54
  346. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
  347. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +2 -4
  348. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  349. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +71 -26
  350. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  351. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +2 -5
  352. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  353. package/dist/store/runtime-clients/thread-list-runtime-client.js +141 -36
  354. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  355. package/dist/store/runtime-clients/thread-runtime-client.d.ts +2 -4
  356. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  357. package/dist/store/runtime-clients/thread-runtime-client.js +196 -72
  358. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  359. package/dist/store/runtime-clients/useSubscribable.js +2 -9
  360. package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
  361. package/dist/store/scopes/message.d.ts +1 -0
  362. package/dist/store/scopes/message.d.ts.map +1 -1
  363. package/dist/store/scopes/part.d.ts +5 -6
  364. package/dist/store/scopes/part.d.ts.map +1 -1
  365. package/dist/store/scopes/queue-item.js.map +1 -1
  366. package/dist/store/scopes/thread-list-item.d.ts +1 -0
  367. package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
  368. package/dist/store/scopes/thread.d.ts +1 -0
  369. package/dist/store/scopes/thread.d.ts.map +1 -1
  370. package/dist/subscribable/subscribable.js.map +1 -1
  371. package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
  372. package/dist/types/message.d.ts +38 -5
  373. package/dist/types/message.d.ts.map +1 -1
  374. package/dist/types/message.js.map +1 -1
  375. package/dist/utils/composite-context-provider.js.map +1 -1
  376. package/dist/utils/id.js.map +1 -1
  377. package/dist/utils/json/is-json-equal.js.map +1 -1
  378. package/dist/utils/json/is-json.js.map +1 -1
  379. package/dist/utils/text.js.map +1 -1
  380. package/package.json +6 -6
  381. package/src/adapters/thread-history.ts +2 -0
  382. package/src/index.ts +5 -0
  383. package/src/internal.ts +1 -0
  384. package/src/model-context/types.ts +1 -0
  385. package/src/react/AssistantProvider.tsx +10 -1
  386. package/src/react/RuntimeAdapter.ts +25 -8
  387. package/src/react/client/DataRenderers.ts +42 -45
  388. package/src/react/client/Interactables.ts +261 -261
  389. package/src/react/client/Tools.ts +9 -9
  390. package/src/react/primitives/message/MessageGroupedParts.tsx +19 -7
  391. package/src/react/primitives/message/MessageParts.tsx +64 -13
  392. package/src/react/providers/TextMessagePartProvider.tsx +5 -3
  393. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +1 -0
  394. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +11 -0
  395. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +6 -0
  396. package/src/react/runtimes/external-message-converter.ts +3 -1
  397. package/src/react/types/MessagePartComponentTypes.ts +5 -5
  398. package/src/react/utils/groupParts.ts +27 -0
  399. package/src/runtime/api/bindings.ts +1 -0
  400. package/src/runtime/api/message-part-runtime.ts +14 -11
  401. package/src/runtime/api/message-runtime.ts +7 -0
  402. package/src/runtime/api/thread-list-runtime.ts +1 -0
  403. package/src/runtime/api/thread-runtime.ts +7 -0
  404. package/src/runtime/base/base-thread-runtime-core.ts +1 -0
  405. package/src/runtime/branch/external-thread-branch-adapter.ts +26 -0
  406. package/src/runtime/interfaces/thread-list-runtime-core.ts +1 -0
  407. package/src/runtime/interfaces/thread-runtime-core.ts +4 -0
  408. package/src/runtime/utils/resolveToolApprovalResponse.test.ts +91 -0
  409. package/src/runtime/utils/resolveToolApprovalResponse.ts +55 -0
  410. package/src/runtime/utils/thread-message-like.ts +10 -1
  411. package/src/runtimes/external-store/external-store-adapter.ts +1 -0
  412. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +24 -0
  413. package/src/runtimes/local/local-runtime-options.ts +1 -1
  414. package/src/runtimes/local/local-thread-runtime-core.test.ts +370 -0
  415. package/src/runtimes/local/local-thread-runtime-core.ts +113 -7
  416. package/src/runtimes/local/should-continue.ts +24 -13
  417. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +5 -0
  418. package/src/runtimes/remote-thread-list/empty-thread-core.ts +5 -0
  419. package/src/runtimes/remote-thread-list/remote-thread-state.ts +2 -0
  420. package/src/runtimes/remote-thread-list/types.ts +1 -0
  421. package/src/store/clients/chain-of-thought-client.ts +5 -3
  422. package/src/store/clients/model-context-client.test.ts +5 -4
  423. package/src/store/clients/model-context-client.ts +21 -21
  424. package/src/store/clients/no-op-composer-client.ts +5 -3
  425. package/src/store/clients/runtime-adapter.ts +0 -24
  426. package/src/store/clients/suggestions.ts +12 -23
  427. package/src/store/clients/thread-message-client.ts +42 -40
  428. package/src/store/internal.ts +1 -4
  429. package/src/store/runtime-clients/attachment-runtime-client.ts +14 -14
  430. package/src/store/runtime-clients/composer-runtime-client.ts +48 -45
  431. package/src/store/runtime-clients/liveRef.ts +5 -0
  432. package/src/store/runtime-clients/message-part-runtime-client.ts +5 -3
  433. package/src/store/runtime-clients/message-runtime-client.ts +42 -40
  434. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +5 -3
  435. package/src/store/runtime-clients/thread-list-runtime-client.ts +13 -11
  436. package/src/store/runtime-clients/thread-runtime-client.ts +20 -16
  437. package/src/store/runtime-clients/useSubscribable.ts +2 -10
  438. package/src/store/scopes/message.ts +1 -0
  439. package/src/store/scopes/part.ts +5 -2
  440. package/src/store/scopes/thread-list-item.ts +1 -0
  441. package/src/store/scopes/thread.ts +1 -0
  442. package/src/tests/external-store-thread-runtime-core.test.ts +57 -0
  443. package/src/tests/groupMessageParts.test.ts +84 -0
  444. package/src/tests/groupParts.test.ts +55 -0
  445. package/src/types/message.ts +45 -3
@@ -49,6 +49,7 @@ export class LocalThreadRuntimeCore
49
49
  switchToBranch: true,
50
50
  switchBranchDuringRun: true,
51
51
  edit: true,
52
+ delete: false,
52
53
  reload: true,
53
54
  cancel: true,
54
55
  unstable_copy: true,
@@ -150,6 +151,12 @@ export class LocalThreadRuntimeCore
150
151
  hasUpdates = true;
151
152
  }
152
153
 
154
+ const canDelete = options.adapters?.history?.delete !== undefined;
155
+ if (this.capabilities.delete !== canDelete) {
156
+ this.capabilities.delete = canDelete;
157
+ hasUpdates = true;
158
+ }
159
+
153
160
  const canQueue = options.unstable_enableMessageQueue === true;
154
161
  if (canQueue && !this._queue) {
155
162
  this._queue = createMessageQueue({
@@ -275,6 +282,25 @@ export class LocalThreadRuntimeCore
275
282
  }
276
283
  }
277
284
 
285
+ public async deleteMessage(messageId: string): Promise<void> {
286
+ const adapter = this._options.adapters.history;
287
+ if (!adapter?.delete)
288
+ throw new Error("Runtime does not support deleting messages.");
289
+
290
+ const messages = this.repository.getMessages();
291
+ const messageIndex = messages.findIndex((m) => m.id === messageId);
292
+ if (messageIndex === -1) throw new Error("Message not found.");
293
+
294
+ const message = messages[messageIndex]!;
295
+ const parentId = messages[messageIndex - 1]?.id ?? null;
296
+ const items = [{ parentId, message }];
297
+
298
+ await adapter.delete(items);
299
+
300
+ this.repository.deleteMessage(messageId);
301
+ this._notifySubscribers();
302
+ }
303
+
278
304
  public resumeRun({ stream, ...startConfig }: ResumeRunConfig): Promise<void> {
279
305
  if (!stream)
280
306
  throw new Error("You must pass a stream parameter to resume runs.");
@@ -297,7 +323,7 @@ export class LocalThreadRuntimeCore
297
323
 
298
324
  // add assistant message
299
325
  const id = generateId();
300
- let message: ThreadAssistantMessage = {
326
+ const message: ThreadAssistantMessage = {
301
327
  id,
302
328
  role: "assistant",
303
329
  status: { type: "running" },
@@ -312,6 +338,15 @@ export class LocalThreadRuntimeCore
312
338
  createdAt: new Date(),
313
339
  };
314
340
 
341
+ return this._runLoop(parentId, message, runConfig, runCallback);
342
+ }
343
+
344
+ private async _runLoop(
345
+ parentId: string | null,
346
+ message: ThreadAssistantMessage,
347
+ runConfig: RunConfig | undefined,
348
+ runCallback?: ChatModelAdapter["run"],
349
+ ): Promise<void> {
315
350
  this._notifyEventSubscribers("runStart", {});
316
351
 
317
352
  try {
@@ -592,22 +627,93 @@ export class LocalThreadRuntimeCore
592
627
  content: newContent,
593
628
  };
594
629
  this.repository.addOrUpdateMessage(parentId, message);
630
+ this._notifySubscribers();
595
631
 
632
+ // a result may arrive mid-run or on a non-head message; the resume
633
+ // intentionally aborts any in-flight run, unlike respondToToolApproval
596
634
  if (
597
635
  added &&
598
636
  shouldContinue(message, this._options.unstable_humanToolNames)
599
637
  ) {
600
- this.performRoundtrip(parentId, message, this._lastRunConfig).catch(
601
- () => {},
602
- );
638
+ this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
603
639
  }
604
640
  }
605
641
 
606
642
  public resumeToolCall(_options: ResumeToolCallOptions) {
607
- throw new Error("Local runtime does not support resuming tool calls.");
643
+ throw new Error(
644
+ "Local runtime does not support resuming tool calls. For human-in-the-loop tools, list the tool in unstable_humanToolNames and complete the call with addToolResult.",
645
+ );
608
646
  }
609
647
 
610
- public respondToToolApproval(_options: RespondToToolApprovalOptions) {
611
- throw new Error("Local runtime does not support tool approvals.");
648
+ public respondToToolApproval({
649
+ approvalId,
650
+ approved,
651
+ optionId,
652
+ reason,
653
+ }: RespondToToolApprovalOptions) {
654
+ let message = this.repository
655
+ .getMessages()
656
+ .findLast(
657
+ (m): m is ThreadAssistantMessage =>
658
+ m.role === "assistant" &&
659
+ m.content.some(
660
+ (c) => c.type === "tool-call" && c.approval?.id === approvalId,
661
+ ),
662
+ );
663
+
664
+ if (!message)
665
+ throw new Error("Tried to respond to a non-existing tool approval");
666
+
667
+ if (this.abortController !== null)
668
+ throw new Error(
669
+ "Tried to respond to a tool approval while a run is in progress",
670
+ );
671
+
672
+ if (message.status?.type !== "requires-action")
673
+ throw new Error(
674
+ "Tried to respond to a tool approval on a message whose status is not requires-action",
675
+ );
676
+
677
+ const target = message.content.find(
678
+ (c) => c.type === "tool-call" && c.approval?.id === approvalId,
679
+ );
680
+ if (target?.type !== "tool-call" || !target.approval)
681
+ throw new Error("Tried to respond to a non-existing tool approval");
682
+ if (target.approval.resolution !== undefined)
683
+ throw new Error(
684
+ "Tried to respond to a tool approval that was cancelled or expired",
685
+ );
686
+ if (target.approval.approved !== undefined)
687
+ throw new Error("Tried to respond to an already decided tool approval");
688
+
689
+ const targetApproval = target.approval;
690
+ const newContent = message.content.map((c) => {
691
+ if (c !== target) return c;
692
+ const approval = {
693
+ ...targetApproval,
694
+ approved,
695
+ ...(optionId != null && { optionId }),
696
+ ...(reason != null && { reason }),
697
+ };
698
+ if (approved) return { ...c, approval };
699
+ return {
700
+ ...c,
701
+ approval,
702
+ result: { error: reason || "Tool approval denied" },
703
+ isError: true,
704
+ };
705
+ });
706
+
707
+ message = { ...message, content: newContent };
708
+ const { parentId } = this.repository.getMessage(message.id);
709
+ this.repository.addOrUpdateMessage(parentId, message);
710
+ this._notifySubscribers();
711
+
712
+ if (
713
+ this.repository.headId === message.id &&
714
+ shouldContinue(message, this._options.unstable_humanToolNames)
715
+ ) {
716
+ this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
717
+ }
612
718
  }
613
719
  }
@@ -4,23 +4,34 @@ export const shouldContinue = (
4
4
  result: ThreadAssistantMessage,
5
5
  humanToolNames: string[] | undefined,
6
6
  ) => {
7
+ if (
8
+ result.status?.type !== "requires-action" ||
9
+ result.status.reason !== "tool-calls"
10
+ )
11
+ return false;
12
+
13
+ const hasPendingApproval = result.content.some(
14
+ (c) =>
15
+ c.type === "tool-call" &&
16
+ c.result === undefined &&
17
+ c.approval !== undefined &&
18
+ c.approval.approved === undefined &&
19
+ c.approval.resolution === undefined,
20
+ );
21
+ if (hasPendingApproval) return false;
22
+
7
23
  // TODO legacy behavior -- make specifying human tool names required
8
24
  if (humanToolNames === undefined) {
9
- return (
10
- result.status?.type === "requires-action" &&
11
- result.status.reason === "tool-calls" &&
12
- result.content.every((c) => c.type !== "tool-call" || !!c.result)
25
+ return result.content.every(
26
+ (c) => c.type !== "tool-call" || !!c.result || c.approval !== undefined,
13
27
  );
14
28
  }
15
29
 
16
- return (
17
- result.status?.type === "requires-action" &&
18
- result.status.reason === "tool-calls" &&
19
- result.content.every(
20
- (c) =>
21
- c.type !== "tool-call" ||
22
- !!c.result ||
23
- !humanToolNames.includes(c.toolName),
24
- )
30
+ return result.content.every(
31
+ (c) =>
32
+ c.type !== "tool-call" ||
33
+ !!c.result ||
34
+ c.approval !== undefined ||
35
+ !humanToolNames.includes(c.toolName),
25
36
  );
26
37
  };
@@ -47,6 +47,10 @@ export class ReadonlyThreadRuntimeCore
47
47
  throw READONLY_THREAD_ERROR;
48
48
  }
49
49
 
50
+ deleteMessage(): void {
51
+ throw READONLY_THREAD_ERROR;
52
+ }
53
+
50
54
  startRun(): void {
51
55
  throw READONLY_THREAD_ERROR;
52
56
  }
@@ -202,6 +206,7 @@ export class ReadonlyThreadRuntimeCore
202
206
  switchToBranch: false,
203
207
  switchBranchDuringRun: false,
204
208
  edit: false,
209
+ delete: false,
205
210
  reload: false,
206
211
  cancel: false,
207
212
  unstable_copy: false,
@@ -20,6 +20,10 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
20
20
  throw EMPTY_THREAD_ERROR;
21
21
  },
22
22
 
23
+ deleteMessage() {
24
+ throw EMPTY_THREAD_ERROR;
25
+ },
26
+
23
27
  startRun() {
24
28
  throw EMPTY_THREAD_ERROR;
25
29
  },
@@ -183,6 +187,7 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
183
187
  switchToBranch: false,
184
188
  switchBranchDuringRun: false,
185
189
  edit: false,
190
+ delete: false,
186
191
  reload: false,
187
192
  cancel: false,
188
193
  unstable_copy: false,
@@ -28,6 +28,7 @@ export type RemoteThreadData =
28
28
  readonly externalId: string | undefined;
29
29
  readonly status: "regular" | "archived";
30
30
  readonly title?: string | undefined;
31
+ readonly lastMessageAt?: Date | undefined;
31
32
  readonly custom?: Record<string, unknown> | undefined;
32
33
  };
33
34
 
@@ -75,6 +76,7 @@ export const classifyThreads = (
75
76
  externalId: thread.externalId,
76
77
  status: thread.status,
77
78
  title: thread.title,
79
+ lastMessageAt: thread.lastMessageAt,
78
80
  custom: thread.custom,
79
81
  initializeTask: Promise.resolve({
80
82
  remoteId: thread.remoteId,
@@ -13,6 +13,7 @@ export type RemoteThreadMetadata = {
13
13
  readonly remoteId: string;
14
14
  readonly externalId?: string | undefined;
15
15
  readonly title?: string | undefined;
16
+ readonly lastMessageAt?: Date | undefined;
16
17
  readonly custom?: Record<string, unknown> | undefined;
17
18
  };
18
19
 
@@ -12,13 +12,13 @@ const COMPLETE_STATUS: MessagePartStatus = Object.freeze({
12
12
  type: "complete",
13
13
  });
14
14
 
15
- export const ChainOfThoughtClient = resource(function ChainOfThoughtClient({
15
+ const useChainOfThoughtClient = ({
16
16
  parts,
17
17
  getMessagePart,
18
18
  }: {
19
19
  parts: readonly ChainOfThoughtPart[];
20
20
  getMessagePart: (selector: { index: number }) => PartMethods;
21
- }): ClientOutput<"chainOfThought"> {
21
+ }): ClientOutput<"chainOfThought"> => {
22
22
  const [collapsed, setCollapsed] = useState(true);
23
23
 
24
24
  const status = useMemo(() => {
@@ -36,4 +36,6 @@ export const ChainOfThoughtClient = resource(function ChainOfThoughtClient({
36
36
  setCollapsed,
37
37
  part: getMessagePart,
38
38
  };
39
- });
39
+ };
40
+
41
+ export const ChainOfThoughtClient = resource(useChainOfThoughtClient);
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { createResourceRoot } from "@assistant-ui/tap";
2
+ import { createTapRoot, useResource } from "@assistant-ui/tap";
3
3
  import type { Tool } from "assistant-stream";
4
4
  import { ModelContext } from "./model-context-client";
5
5
  import type {
@@ -18,9 +18,10 @@ const toolFixture = (): Tool<any, any> =>
18
18
  ({ description: "", parameters: {} as any }) as unknown as Tool<any, any>;
19
19
 
20
20
  const render = () => {
21
- const root = createResourceRoot();
22
- const sub = root.render(ModelContext());
23
- return { sub, unmount: () => root.unmount() };
21
+ const root = createTapRoot(function Root() {
22
+ return useResource(ModelContext());
23
+ });
24
+ return { sub: root, unmount: () => root.unmount() };
24
25
  };
25
26
 
26
27
  describe("ModelContext", () => {
@@ -29,25 +29,25 @@ const deriveState = (
29
29
  return { modelName, toolNames };
30
30
  };
31
31
 
32
- export const ModelContext = resource(
33
- function ModelContext(): ClientOutput<"modelContext"> {
34
- const composite = useMemo(() => new CompositeContextProvider(), []);
35
- const [state, setState] = useState<ModelContextState>(() =>
36
- deriveState(composite, INITIAL_STATE),
37
- );
38
-
39
- useEffect(() => {
32
+ const useModelContext = (): ClientOutput<"modelContext"> => {
33
+ const composite = useMemo(() => new CompositeContextProvider(), []);
34
+ const [state, setState] = useState<ModelContextState>(() =>
35
+ deriveState(composite, INITIAL_STATE),
36
+ );
37
+
38
+ useEffect(() => {
39
+ setState((prev) => deriveState(composite, prev));
40
+ return composite.subscribe(() => {
40
41
  setState((prev) => deriveState(composite, prev));
41
- return composite.subscribe(() => {
42
- setState((prev) => deriveState(composite, prev));
43
- });
44
- }, [composite]);
45
-
46
- return {
47
- getState: () => deriveState(composite, state),
48
- getModelContext: () => composite.getModelContext(),
49
- subscribe: (callback) => composite.subscribe(callback),
50
- register: (provider) => composite.registerModelContextProvider(provider),
51
- };
52
- },
53
- );
42
+ });
43
+ }, [composite]);
44
+
45
+ return {
46
+ getState: () => deriveState(composite, state),
47
+ getModelContext: () => composite.getModelContext(),
48
+ subscribe: (callback) => composite.subscribe(callback),
49
+ register: (provider) => composite.registerModelContextProvider(provider),
50
+ };
51
+ };
52
+
53
+ export const ModelContext = resource(useModelContext);
@@ -3,11 +3,11 @@ import { resource } from "@assistant-ui/tap";
3
3
  import type { ClientOutput } from "@assistant-ui/store";
4
4
  import type { ComposerState } from "../scopes/composer";
5
5
 
6
- export const NoOpComposerClient = resource(function NoOpComposerClient({
6
+ const useNoOpComposerClient = ({
7
7
  type,
8
8
  }: {
9
9
  type: "edit" | "thread";
10
- }): ClientOutput<"composer"> {
10
+ }): ClientOutput<"composer"> => {
11
11
  const state = useMemo<ComposerState>(() => {
12
12
  return {
13
13
  isEditing: false,
@@ -71,4 +71,6 @@ export const NoOpComposerClient = resource(function NoOpComposerClient({
71
71
  throw new Error("Not supported");
72
72
  },
73
73
  };
74
- });
74
+ };
75
+
76
+ export const NoOpComposerClient = resource(useNoOpComposerClient);
@@ -1,9 +1,4 @@
1
- import { useEffect } from "react";
2
- import { useResource, resource } from "@assistant-ui/tap";
3
- import type { AssistantRuntime } from "../../runtime/api/assistant-runtime";
4
- import { ThreadListClient } from "../runtime-clients/thread-list-runtime-client";
5
1
  import {
6
- useAssistantClientRef,
7
2
  Derived,
8
3
  type ScopesConfig,
9
4
  type AssistantClient,
@@ -11,25 +6,6 @@ import {
11
6
  import { ModelContext } from "./model-context-client";
12
7
  import { Suggestions } from "./suggestions";
13
8
 
14
- export const RuntimeAdapterResource = resource(function RuntimeAdapterResource(
15
- runtime: AssistantRuntime,
16
- ) {
17
- const clientRef = useAssistantClientRef();
18
-
19
- useEffect(() => {
20
- return runtime.registerModelContextProvider(
21
- clientRef.current!.modelContext(),
22
- );
23
- }, [runtime, clientRef]);
24
-
25
- return useResource(
26
- ThreadListClient({
27
- runtime: runtime.threads,
28
- __internal_assistantRuntime: runtime,
29
- }),
30
- );
31
- });
32
-
33
9
  export const baseRuntimeAdapterTransformScopes = (
34
10
  scopes: ScopesConfig,
35
11
  parent: AssistantClient,
@@ -9,17 +9,19 @@ export type SuggestionConfig =
9
9
  | string
10
10
  | { title: string; label: string; prompt: string };
11
11
 
12
- const SuggestionClient = resource(function SuggestionClient(
12
+ const useSuggestionClient = (
13
13
  state: SuggestionState,
14
- ): ClientOutput<"suggestion"> {
14
+ ): ClientOutput<"suggestion"> => {
15
15
  return {
16
16
  getState: () => state,
17
17
  };
18
- });
18
+ };
19
19
 
20
- const SuggestionsResource = resource(function SuggestionsResource(
20
+ const SuggestionClient = resource(useSuggestionClient);
21
+
22
+ const useSuggestionsResource = (
21
23
  suggestions?: SuggestionConfig[],
22
- ): ClientOutput<"suggestions"> {
24
+ ): ClientOutput<"suggestions"> => {
23
25
  const [state] = useState<SuggestionsState>(() => {
24
26
  const normalizedSuggestions = (suggestions ?? []).map((s) => {
25
27
  if (typeof s === "string") {
@@ -42,11 +44,9 @@ const SuggestionsResource = resource(function SuggestionsResource(
42
44
  });
43
45
 
44
46
  const suggestionClients = useClientLookup(
45
- () =>
46
- state.suggestions.map((suggestion, index) =>
47
- withKey(index, SuggestionClient(suggestion)),
48
- ),
49
- [state.suggestions],
47
+ state.suggestions.map((suggestion, index) =>
48
+ withKey(index, SuggestionClient(suggestion), [suggestion]),
49
+ ),
50
50
  );
51
51
 
52
52
  return {
@@ -55,17 +55,6 @@ const SuggestionsResource = resource(function SuggestionsResource(
55
55
  return suggestionClients.get({ index });
56
56
  },
57
57
  };
58
- });
58
+ };
59
59
 
60
- export const Suggestions: {
61
- (): import("@assistant-ui/tap").ResourceElement<
62
- ClientOutput<"suggestions">,
63
- undefined
64
- >;
65
- (
66
- suggestions: SuggestionConfig[],
67
- ): import("@assistant-ui/tap").ResourceElement<
68
- ClientOutput<"suggestions">,
69
- SuggestionConfig[]
70
- >;
71
- } = SuggestionsResource as any;
60
+ export const Suggestions = resource(useSuggestionsResource);
@@ -11,12 +11,13 @@ import { useClientLookup } from "@assistant-ui/store";
11
11
  import type { MessageState } from "../scopes/message";
12
12
  import type { PartState } from "../scopes/part";
13
13
  import { NoOpComposerClient } from "./no-op-composer-client";
14
+ import { getThreadMessageText } from "../../utils/text";
14
15
 
15
- const ThreadMessagePartClient = resource(function ThreadMessagePartClient({
16
+ const useThreadMessagePartClient = ({
16
17
  part,
17
18
  }: {
18
19
  part: ThreadAssistantMessagePart | ThreadUserMessagePart;
19
- }): ClientOutput<"part"> {
20
+ }): ClientOutput<"part"> => {
20
21
  const state = useMemo<PartState>(() => {
21
22
  return {
22
23
  ...part,
@@ -36,21 +37,25 @@ const ThreadMessagePartClient = resource(function ThreadMessagePartClient({
36
37
  throw new Error("Not supported");
37
38
  },
38
39
  };
39
- });
40
+ };
41
+
42
+ const ThreadMessagePartClient = resource(useThreadMessagePartClient);
43
+
44
+ const useThreadMessageAttachmentClient = ({
45
+ attachment,
46
+ }: {
47
+ attachment: Attachment;
48
+ }): ClientOutput<"attachment"> => {
49
+ return {
50
+ getState: () => attachment,
51
+ remove: () => {
52
+ throw new Error("Not supported");
53
+ },
54
+ };
55
+ };
40
56
 
41
57
  const ThreadMessageAttachmentClient = resource(
42
- function ThreadMessageAttachmentClient({
43
- attachment,
44
- }: {
45
- attachment: Attachment;
46
- }): ClientOutput<"attachment"> {
47
- return {
48
- getState: () => attachment,
49
- remove: () => {
50
- throw new Error("Not supported");
51
- },
52
- };
53
- },
58
+ useThreadMessageAttachmentClient,
54
59
  );
55
60
  export type ThreadMessageClientProps = {
56
61
  message: ThreadMessage;
@@ -60,35 +65,34 @@ export type ThreadMessageClientProps = {
60
65
  branchCount?: number;
61
66
  };
62
67
 
63
- export const ThreadMessageClient = resource(function ThreadMessageClient({
68
+ const useThreadMessageClient = ({
64
69
  message,
65
70
  index,
66
71
  isLast = true,
67
72
  branchNumber = 1,
68
73
  branchCount = 1,
69
- }: ThreadMessageClientProps): ClientOutput<"message"> {
74
+ }: ThreadMessageClientProps): ClientOutput<"message"> => {
70
75
  const [isCopiedState, setIsCopied] = useState(false);
71
76
  const [isHoveringState, setIsHovering] = useState(false);
72
77
 
73
78
  const parts = useClientLookup(
74
- () =>
75
- message.content.map((part, idx) =>
76
- withKey(
77
- "toolCallId" in part && part.toolCallId != null
78
- ? `toolCallId-${part.toolCallId}`
79
- : `index-${idx}`,
80
- ThreadMessagePartClient({ part }),
81
- ),
79
+ message.content.map((part, idx) =>
80
+ withKey(
81
+ "toolCallId" in part && part.toolCallId != null
82
+ ? `toolCallId-${part.toolCallId}`
83
+ : `index-${idx}`,
84
+ ThreadMessagePartClient({ part }),
85
+ [part],
82
86
  ),
83
- [message.content],
87
+ ),
84
88
  );
85
89
 
86
90
  const attachments = useClientLookup(
87
- () =>
88
- (message.attachments ?? []).map((attachment) =>
89
- withKey(attachment.id, ThreadMessageAttachmentClient({ attachment })),
90
- ),
91
- [message.attachments],
91
+ (message.attachments ?? []).map((attachment) =>
92
+ withKey(attachment.id, ThreadMessageAttachmentClient({ attachment }), [
93
+ attachment,
94
+ ]),
95
+ ),
92
96
  );
93
97
 
94
98
  const composer = useResource(NoOpComposerClient({ type: "edit" }));
@@ -137,6 +141,9 @@ export const ThreadMessageClient = resource(function ThreadMessageClient({
137
141
  return attachments.get(selector);
138
142
  }
139
143
  },
144
+ delete: () => {
145
+ throw new Error("Not supported in ThreadMessageProvider");
146
+ },
140
147
  reload: () => {
141
148
  throw new Error("Not supported in ThreadMessageProvider");
142
149
  },
@@ -153,16 +160,11 @@ export const ThreadMessageClient = resource(function ThreadMessageClient({
153
160
  throw new Error("Not supported in ThreadMessageProvider");
154
161
  },
155
162
  getCopyText: () => {
156
- return message.content
157
- .map((part) => {
158
- if ("text" in part && typeof part.text === "string") {
159
- return part.text;
160
- }
161
- return "";
162
- })
163
- .join("\n");
163
+ return getThreadMessageText(message);
164
164
  },
165
165
  setIsCopied,
166
166
  setIsHovering,
167
167
  };
168
- });
168
+ };
169
+
170
+ export const ThreadMessageClient = resource(useThreadMessageClient);
@@ -5,7 +5,4 @@ export { MessageClient } from "./runtime-clients/message-runtime-client";
5
5
  export { ThreadClient } from "./runtime-clients/thread-runtime-client";
6
6
  export { ThreadListItemClient } from "./runtime-clients/thread-list-item-runtime-client";
7
7
  export { ThreadListClient } from "./runtime-clients/thread-list-runtime-client";
8
- export {
9
- RuntimeAdapterResource,
10
- baseRuntimeAdapterTransformScopes,
11
- } from "./clients/runtime-adapter";
8
+ export { baseRuntimeAdapterTransformScopes } from "./clients/runtime-adapter";
@@ -3,18 +3,18 @@ import type { ClientOutput } from "@assistant-ui/store";
3
3
  import type { AttachmentRuntime } from "../../runtime/api/attachment-runtime";
4
4
  import { useSubscribable } from "./useSubscribable";
5
5
 
6
- export const AttachmentRuntimeClient = resource(
7
- function AttachmentRuntimeClient({
8
- runtime,
9
- }: {
10
- runtime: AttachmentRuntime;
11
- }): ClientOutput<"attachment"> {
12
- const state = useSubscribable(runtime);
6
+ const useAttachmentRuntimeClient = ({
7
+ runtime,
8
+ }: {
9
+ runtime: AttachmentRuntime;
10
+ }): ClientOutput<"attachment"> => {
11
+ const state = useSubscribable(runtime);
13
12
 
14
- return {
15
- getState: () => state,
16
- remove: runtime.remove,
17
- __internal_getRuntime: () => runtime,
18
- };
19
- },
20
- );
13
+ return {
14
+ getState: () => state,
15
+ remove: runtime.remove,
16
+ __internal_getRuntime: () => runtime,
17
+ };
18
+ };
19
+
20
+ export const AttachmentRuntimeClient = resource(useAttachmentRuntimeClient);