@assistant-ui/react 0.12.11 → 0.12.14

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 (357) hide show
  1. package/README.md +68 -58
  2. package/dist/client/ExternalThread.d.ts.map +1 -1
  3. package/dist/client/ExternalThread.js +25 -13
  4. package/dist/client/ExternalThread.js.map +1 -1
  5. package/dist/client/InMemoryThreadList.d.ts.map +1 -1
  6. package/dist/client/InMemoryThreadList.js +1 -2
  7. package/dist/client/InMemoryThreadList.js.map +1 -1
  8. package/dist/client/index.d.ts +1 -2
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +2 -2
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/context/providers/AttachmentByIndexProvider.d.ts +1 -7
  13. package/dist/context/providers/AttachmentByIndexProvider.d.ts.map +1 -1
  14. package/dist/context/providers/AttachmentByIndexProvider.js +1 -22
  15. package/dist/context/providers/AttachmentByIndexProvider.js.map +1 -1
  16. package/dist/context/providers/ChainOfThoughtByIndicesProvider.d.ts +1 -5
  17. package/dist/context/providers/ChainOfThoughtByIndicesProvider.d.ts.map +1 -1
  18. package/dist/context/providers/ChainOfThoughtByIndicesProvider.js +1 -19
  19. package/dist/context/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  20. package/dist/context/providers/ChainOfThoughtPartByIndexProvider.d.ts +1 -4
  21. package/dist/context/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
  22. package/dist/context/providers/ChainOfThoughtPartByIndexProvider.js +1 -12
  23. package/dist/context/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  24. package/dist/context/providers/MessageByIndexProvider.d.ts +1 -4
  25. package/dist/context/providers/MessageByIndexProvider.d.ts.map +1 -1
  26. package/dist/context/providers/MessageByIndexProvider.js +1 -17
  27. package/dist/context/providers/MessageByIndexProvider.js.map +1 -1
  28. package/dist/context/providers/PartByIndexProvider.d.ts +1 -4
  29. package/dist/context/providers/PartByIndexProvider.d.ts.map +1 -1
  30. package/dist/context/providers/PartByIndexProvider.js +1 -12
  31. package/dist/context/providers/PartByIndexProvider.js.map +1 -1
  32. package/dist/context/providers/SuggestionByIndexProvider.d.ts +1 -5
  33. package/dist/context/providers/SuggestionByIndexProvider.d.ts.map +1 -1
  34. package/dist/context/providers/SuggestionByIndexProvider.js +1 -12
  35. package/dist/context/providers/SuggestionByIndexProvider.js.map +1 -1
  36. package/dist/context/providers/TextMessagePartProvider.d.ts +1 -5
  37. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  38. package/dist/context/providers/TextMessagePartProvider.js +1 -25
  39. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  40. package/dist/context/providers/ThreadListItemProvider.d.ts +1 -9
  41. package/dist/context/providers/ThreadListItemProvider.d.ts.map +1 -1
  42. package/dist/context/providers/ThreadListItemProvider.js +1 -19
  43. package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
  44. package/dist/context/providers/index.d.ts +1 -0
  45. package/dist/context/providers/index.d.ts.map +1 -1
  46. package/dist/context/providers/index.js +1 -0
  47. package/dist/context/providers/index.js.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  53. package/dist/legacy-runtime/AssistantRuntimeProvider.js +8 -9
  54. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  55. package/dist/legacy-runtime/RuntimeAdapter.d.ts +1 -2
  56. package/dist/legacy-runtime/RuntimeAdapter.d.ts.map +1 -1
  57. package/dist/legacy-runtime/RuntimeAdapter.js +1 -48
  58. package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -1
  59. package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  60. package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js +135 -27
  61. package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  62. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +280 -112
  63. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
  64. package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js +1 -1
  65. package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js.map +1 -1
  66. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts +1 -1
  67. package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts.map +1 -1
  68. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +22 -0
  69. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
  70. package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js.map +1 -1
  71. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  72. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +17 -13
  73. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  74. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  75. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +8 -6
  76. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  77. package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.d.ts +1 -1
  78. package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.d.ts.map +1 -1
  79. package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.js +1 -1
  80. package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.js.map +1 -1
  81. package/dist/legacy-runtime/runtime-cores/external-store/index.d.ts +1 -1
  82. package/dist/legacy-runtime/runtime-cores/external-store/index.d.ts.map +1 -1
  83. package/dist/legacy-runtime/runtime-cores/external-store/index.js +1 -1
  84. package/dist/legacy-runtime/runtime-cores/external-store/index.js.map +1 -1
  85. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
  86. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js +14 -4
  87. package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
  88. package/dist/model-context/index.d.ts +4 -13
  89. package/dist/model-context/index.d.ts.map +1 -1
  90. package/dist/model-context/index.js +6 -11
  91. package/dist/model-context/index.js.map +1 -1
  92. package/dist/primitives/actionBarMore/ActionBarMoreContent.d.ts +1 -1
  93. package/dist/primitives/actionBarMore/ActionBarMoreContent.d.ts.map +1 -1
  94. package/dist/primitives/actionBarMore/ActionBarMoreContent.js +1 -1
  95. package/dist/primitives/actionBarMore/ActionBarMoreContent.js.map +1 -1
  96. package/dist/primitives/actionBarMore/ActionBarMoreItem.d.ts +1 -1
  97. package/dist/primitives/actionBarMore/ActionBarMoreItem.d.ts.map +1 -1
  98. package/dist/primitives/actionBarMore/ActionBarMoreItem.js +1 -1
  99. package/dist/primitives/actionBarMore/ActionBarMoreItem.js.map +1 -1
  100. package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts +1 -1
  101. package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts.map +1 -1
  102. package/dist/primitives/actionBarMore/ActionBarMoreRoot.js +1 -1
  103. package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -1
  104. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.d.ts +1 -1
  105. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.d.ts.map +1 -1
  106. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js +1 -1
  107. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js.map +1 -1
  108. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.d.ts +1 -1
  109. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.d.ts.map +1 -1
  110. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js +1 -1
  111. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js.map +1 -1
  112. package/dist/primitives/actionBarMore/scope.d.ts +1 -1
  113. package/dist/primitives/actionBarMore/scope.d.ts.map +1 -1
  114. package/dist/primitives/actionBarMore/scope.js +1 -1
  115. package/dist/primitives/actionBarMore/scope.js.map +1 -1
  116. package/dist/primitives/assistantModal/AssistantModalAnchor.d.ts +1 -1
  117. package/dist/primitives/assistantModal/AssistantModalAnchor.d.ts.map +1 -1
  118. package/dist/primitives/assistantModal/AssistantModalAnchor.js +1 -1
  119. package/dist/primitives/assistantModal/AssistantModalAnchor.js.map +1 -1
  120. package/dist/primitives/assistantModal/AssistantModalContent.d.ts +1 -1
  121. package/dist/primitives/assistantModal/AssistantModalContent.d.ts.map +1 -1
  122. package/dist/primitives/assistantModal/AssistantModalContent.js +1 -1
  123. package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
  124. package/dist/primitives/assistantModal/AssistantModalRoot.d.ts +1 -1
  125. package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
  126. package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -1
  127. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  128. package/dist/primitives/assistantModal/AssistantModalTrigger.d.ts +1 -1
  129. package/dist/primitives/assistantModal/AssistantModalTrigger.d.ts.map +1 -1
  130. package/dist/primitives/assistantModal/AssistantModalTrigger.js +1 -1
  131. package/dist/primitives/assistantModal/AssistantModalTrigger.js.map +1 -1
  132. package/dist/primitives/assistantModal/scope.d.ts +1 -1
  133. package/dist/primitives/assistantModal/scope.d.ts.map +1 -1
  134. package/dist/primitives/assistantModal/scope.js +1 -1
  135. package/dist/primitives/assistantModal/scope.js.map +1 -1
  136. package/dist/primitives/chainOfThought/ChainOfThoughtParts.d.ts +1 -38
  137. package/dist/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
  138. package/dist/primitives/chainOfThought/ChainOfThoughtParts.js +1 -38
  139. package/dist/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  140. package/dist/primitives/composer/ComposerAttachmentDropzone.js +2 -2
  141. package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
  142. package/dist/primitives/composer/ComposerAttachments.d.ts +1 -36
  143. package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  144. package/dist/primitives/composer/ComposerAttachments.js +1 -61
  145. package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
  146. package/dist/primitives/composer/ComposerIf.d.ts +2 -17
  147. package/dist/primitives/composer/ComposerIf.d.ts.map +1 -1
  148. package/dist/primitives/composer/ComposerIf.js +1 -23
  149. package/dist/primitives/composer/ComposerIf.js.map +1 -1
  150. package/dist/primitives/composer/ComposerInput.js +2 -2
  151. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  152. package/dist/primitives/message/MessageAttachments.d.ts +1 -36
  153. package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
  154. package/dist/primitives/message/MessageAttachments.js +1 -65
  155. package/dist/primitives/message/MessageAttachments.js.map +1 -1
  156. package/dist/primitives/message/MessageIf.d.ts +1 -1
  157. package/dist/primitives/message/MessageIf.js +1 -1
  158. package/dist/primitives/message/MessageParts.d.ts +5 -219
  159. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  160. package/dist/primitives/message/MessageParts.js +29 -270
  161. package/dist/primitives/message/MessageParts.js.map +1 -1
  162. package/dist/primitives/message/MessagePartsGrouped.d.ts +1 -1
  163. package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
  164. package/dist/primitives/message/MessagePartsGrouped.js +2 -2
  165. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  166. package/dist/primitives/thread/ThreadEmpty.d.ts +3 -0
  167. package/dist/primitives/thread/ThreadEmpty.d.ts.map +1 -1
  168. package/dist/primitives/thread/ThreadEmpty.js +4 -1
  169. package/dist/primitives/thread/ThreadEmpty.js.map +1 -1
  170. package/dist/primitives/thread/ThreadIf.d.ts +1 -1
  171. package/dist/primitives/thread/ThreadIf.js +1 -1
  172. package/dist/primitives/thread/ThreadMessages.d.ts +1 -94
  173. package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
  174. package/dist/primitives/thread/ThreadMessages.js +1 -109
  175. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  176. package/dist/primitives/thread/ThreadSuggestions.d.ts +1 -52
  177. package/dist/primitives/thread/ThreadSuggestions.d.ts.map +1 -1
  178. package/dist/primitives/thread/ThreadSuggestions.js +1 -56
  179. package/dist/primitives/thread/ThreadSuggestions.js.map +1 -1
  180. package/dist/primitives/thread/ThreadViewportSlack.js +2 -2
  181. package/dist/primitives/thread/ThreadViewportSlack.js.map +1 -1
  182. package/dist/primitives/threadList/ThreadListItems.d.ts +1 -34
  183. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  184. package/dist/primitives/threadList/ThreadListItems.js +1 -35
  185. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  186. package/dist/primitives/threadListItem/ThreadListItemTitle.d.ts +1 -7
  187. package/dist/primitives/threadListItem/ThreadListItemTitle.d.ts.map +1 -1
  188. package/dist/primitives/threadListItem/ThreadListItemTitle.js +1 -7
  189. package/dist/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
  190. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.d.ts +1 -1
  191. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.d.ts.map +1 -1
  192. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js +1 -1
  193. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js.map +1 -1
  194. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.d.ts +1 -1
  195. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.d.ts.map +1 -1
  196. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js +1 -1
  197. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js.map +1 -1
  198. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.d.ts +1 -1
  199. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.d.ts.map +1 -1
  200. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js +1 -1
  201. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js.map +1 -1
  202. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.d.ts +1 -1
  203. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.d.ts.map +1 -1
  204. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js +1 -1
  205. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js.map +1 -1
  206. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.d.ts +1 -1
  207. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.d.ts.map +1 -1
  208. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js +1 -1
  209. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js.map +1 -1
  210. package/dist/primitives/threadListItemMore/scope.d.ts +1 -1
  211. package/dist/primitives/threadListItemMore/scope.d.ts.map +1 -1
  212. package/dist/primitives/threadListItemMore/scope.js +1 -1
  213. package/dist/primitives/threadListItemMore/scope.js.map +1 -1
  214. package/dist/types/index.d.ts +2 -2
  215. package/dist/types/index.d.ts.map +1 -1
  216. package/dist/types/scopes/index.d.ts +1 -2
  217. package/dist/types/scopes/index.d.ts.map +1 -1
  218. package/package.json +10 -12
  219. package/src/client/ExternalThread.ts +25 -13
  220. package/src/client/InMemoryThreadList.ts +1 -2
  221. package/src/client/index.ts +3 -2
  222. package/src/context/providers/AttachmentByIndexProvider.tsx +4 -34
  223. package/src/context/providers/ChainOfThoughtByIndicesProvider.tsx +1 -34
  224. package/src/context/providers/ChainOfThoughtPartByIndexProvider.tsx +1 -18
  225. package/src/context/providers/MessageByIndexProvider.tsx +1 -23
  226. package/src/context/providers/PartByIndexProvider.tsx +1 -18
  227. package/src/context/providers/SuggestionByIndexProvider.tsx +4 -21
  228. package/src/context/providers/TextMessagePartProvider.tsx +1 -46
  229. package/src/context/providers/ThreadListItemProvider.tsx +4 -33
  230. package/src/context/providers/index.ts +1 -0
  231. package/src/index.ts +1 -1
  232. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +13 -21
  233. package/src/legacy-runtime/RuntimeAdapter.ts +1 -66
  234. package/src/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.ts +179 -40
  235. package/src/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.ts +1 -1
  236. package/src/legacy-runtime/runtime-cores/assistant-transport/index.ts +1 -0
  237. package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +25 -0
  238. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +22 -13
  239. package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.test.ts +6 -3
  240. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts +19 -21
  241. package/src/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.ts +1 -0
  242. package/src/legacy-runtime/runtime-cores/external-store/index.ts +1 -0
  243. package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.ts +20 -4
  244. package/src/model-context/index.ts +29 -22
  245. package/src/primitives/actionBarMore/ActionBarMoreContent.tsx +1 -1
  246. package/src/primitives/actionBarMore/ActionBarMoreItem.tsx +1 -1
  247. package/src/primitives/actionBarMore/ActionBarMoreRoot.tsx +1 -1
  248. package/src/primitives/actionBarMore/ActionBarMoreSeparator.tsx +1 -1
  249. package/src/primitives/actionBarMore/ActionBarMoreTrigger.tsx +1 -1
  250. package/src/primitives/actionBarMore/scope.ts +1 -1
  251. package/src/primitives/assistantModal/AssistantModalAnchor.tsx +1 -1
  252. package/src/primitives/assistantModal/AssistantModalContent.tsx +1 -1
  253. package/src/primitives/assistantModal/AssistantModalRoot.tsx +1 -1
  254. package/src/primitives/assistantModal/AssistantModalTrigger.tsx +1 -1
  255. package/src/primitives/assistantModal/scope.ts +1 -1
  256. package/src/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -85
  257. package/src/primitives/composer/ComposerAttachmentDropzone.tsx +2 -2
  258. package/src/primitives/composer/ComposerAttachments.tsx +4 -110
  259. package/src/primitives/composer/ComposerIf.ts +2 -42
  260. package/src/primitives/composer/ComposerInput.tsx +2 -2
  261. package/src/primitives/message/MessageAttachments.tsx +4 -113
  262. package/src/primitives/message/MessageIf.ts +1 -1
  263. package/src/primitives/message/MessageParts.tsx +43 -642
  264. package/src/primitives/message/MessagePartsGrouped.tsx +3 -3
  265. package/src/primitives/thread/ThreadEmpty.ts +4 -3
  266. package/src/primitives/thread/ThreadIf.ts +1 -1
  267. package/src/primitives/thread/ThreadMessages.tsx +4 -217
  268. package/src/primitives/thread/ThreadSuggestions.tsx +4 -106
  269. package/src/primitives/thread/ThreadViewportSlack.tsx +2 -2
  270. package/src/primitives/threadList/ThreadListItems.tsx +4 -79
  271. package/src/primitives/threadListItem/ThreadListItemTitle.test.tsx +7 -3
  272. package/src/primitives/threadListItem/ThreadListItemTitle.tsx +1 -17
  273. package/src/primitives/threadListItemMore/ThreadListItemMoreContent.tsx +1 -1
  274. package/src/primitives/threadListItemMore/ThreadListItemMoreItem.tsx +1 -1
  275. package/src/primitives/threadListItemMore/ThreadListItemMoreRoot.tsx +1 -1
  276. package/src/primitives/threadListItemMore/ThreadListItemMoreSeparator.tsx +1 -1
  277. package/src/primitives/threadListItemMore/ThreadListItemMoreTrigger.tsx +1 -1
  278. package/src/primitives/threadListItemMore/scope.ts +1 -1
  279. package/src/tests/BaseComposerRuntimeCore.test.ts +106 -1
  280. package/src/tests/DataRenderers.test.ts +1 -2
  281. package/src/types/index.ts +3 -2
  282. package/src/types/scopes/index.ts +5 -3
  283. package/dist/client/DataRenderers.d.ts +0 -3
  284. package/dist/client/DataRenderers.d.ts.map +0 -1
  285. package/dist/client/DataRenderers.js +0 -33
  286. package/dist/client/DataRenderers.js.map +0 -1
  287. package/dist/client/Tools.d.ts +0 -8
  288. package/dist/client/Tools.d.ts.map +0 -1
  289. package/dist/client/Tools.js +0 -68
  290. package/dist/client/Tools.js.map +0 -1
  291. package/dist/model-context/makeAssistantDataUI.d.ts +0 -7
  292. package/dist/model-context/makeAssistantDataUI.d.ts.map +0 -1
  293. package/dist/model-context/makeAssistantDataUI.js +0 -11
  294. package/dist/model-context/makeAssistantDataUI.js.map +0 -1
  295. package/dist/model-context/makeAssistantTool.d.ts +0 -7
  296. package/dist/model-context/makeAssistantTool.d.ts.map +0 -1
  297. package/dist/model-context/makeAssistantTool.js +0 -11
  298. package/dist/model-context/makeAssistantTool.js.map +0 -1
  299. package/dist/model-context/makeAssistantToolUI.d.ts +0 -7
  300. package/dist/model-context/makeAssistantToolUI.d.ts.map +0 -1
  301. package/dist/model-context/makeAssistantToolUI.js +0 -11
  302. package/dist/model-context/makeAssistantToolUI.js.map +0 -1
  303. package/dist/model-context/toolbox.d.ts +0 -10
  304. package/dist/model-context/toolbox.d.ts.map +0 -1
  305. package/dist/model-context/toolbox.js +0 -3
  306. package/dist/model-context/toolbox.js.map +0 -1
  307. package/dist/model-context/useAssistantDataUI.d.ts +0 -7
  308. package/dist/model-context/useAssistantDataUI.d.ts.map +0 -1
  309. package/dist/model-context/useAssistantDataUI.js +0 -12
  310. package/dist/model-context/useAssistantDataUI.js.map +0 -1
  311. package/dist/model-context/useAssistantInstructions.d.ts +0 -4
  312. package/dist/model-context/useAssistantInstructions.d.ts.map +0 -1
  313. package/dist/model-context/useAssistantInstructions.js +0 -23
  314. package/dist/model-context/useAssistantInstructions.js.map +0 -1
  315. package/dist/model-context/useAssistantTool.d.ts +0 -7
  316. package/dist/model-context/useAssistantTool.d.ts.map +0 -1
  317. package/dist/model-context/useAssistantTool.js +0 -23
  318. package/dist/model-context/useAssistantTool.js.map +0 -1
  319. package/dist/model-context/useAssistantToolUI.d.ts +0 -7
  320. package/dist/model-context/useAssistantToolUI.d.ts.map +0 -1
  321. package/dist/model-context/useAssistantToolUI.js +0 -12
  322. package/dist/model-context/useAssistantToolUI.js.map +0 -1
  323. package/dist/model-context/useInlineRender.d.ts +0 -4
  324. package/dist/model-context/useInlineRender.d.ts.map +0 -1
  325. package/dist/model-context/useInlineRender.js +0 -16
  326. package/dist/model-context/useInlineRender.js.map +0 -1
  327. package/dist/types/MessagePartComponentTypes.d.ts +0 -33
  328. package/dist/types/MessagePartComponentTypes.d.ts.map +0 -1
  329. package/dist/types/MessagePartComponentTypes.js +0 -2
  330. package/dist/types/MessagePartComponentTypes.js.map +0 -1
  331. package/dist/types/scopes/dataRenderers.d.ts +0 -13
  332. package/dist/types/scopes/dataRenderers.d.ts.map +0 -1
  333. package/dist/types/scopes/dataRenderers.js +0 -2
  334. package/dist/types/scopes/dataRenderers.js.map +0 -1
  335. package/dist/types/scopes/tools.d.ts +0 -13
  336. package/dist/types/scopes/tools.d.ts.map +0 -1
  337. package/dist/types/scopes/tools.js +0 -2
  338. package/dist/types/scopes/tools.js.map +0 -1
  339. package/dist/types/store-augmentation.d.ts +0 -10
  340. package/dist/types/store-augmentation.d.ts.map +0 -1
  341. package/dist/types/store-augmentation.js +0 -2
  342. package/dist/types/store-augmentation.js.map +0 -1
  343. package/src/client/DataRenderers.ts +0 -42
  344. package/src/client/Tools.ts +0 -97
  345. package/src/model-context/makeAssistantDataUI.ts +0 -22
  346. package/src/model-context/makeAssistantTool.ts +0 -22
  347. package/src/model-context/makeAssistantToolUI.ts +0 -22
  348. package/src/model-context/toolbox.ts +0 -17
  349. package/src/model-context/useAssistantDataUI.ts +0 -18
  350. package/src/model-context/useAssistantInstructions.ts +0 -32
  351. package/src/model-context/useAssistantTool.ts +0 -39
  352. package/src/model-context/useAssistantToolUI.ts +0 -20
  353. package/src/model-context/useInlineRender.ts +0 -27
  354. package/src/types/MessagePartComponentTypes.ts +0 -66
  355. package/src/types/scopes/dataRenderers.ts +0 -15
  356. package/src/types/scopes/tools.ts +0 -18
  357. package/src/types/store-augmentation.ts +0 -11
@@ -1,362 +1,18 @@
1
1
  "use client";
2
2
 
3
+ import type { FC } from "react";
3
4
  import {
4
- type ComponentType,
5
- type FC,
6
- memo,
7
- PropsWithChildren,
8
- useMemo,
9
- } from "react";
10
- import { useAuiState, useAui } from "@assistant-ui/store";
11
- import {
12
- PartByIndexProvider,
13
- TextMessagePartProvider,
14
- } from "../../context/providers";
15
- import { ChainOfThoughtByIndicesProvider } from "../../context/providers/ChainOfThoughtByIndicesProvider";
5
+ MessagePrimitiveParts as MessagePrimitivePartsBase,
6
+ MessagePartComponent as MessagePartComponentBase,
7
+ MessagePrimitivePartByIndex as MessagePrimitivePartByIndexBase,
8
+ messagePartsDefaultComponents,
9
+ } from "@assistant-ui/core/react";
16
10
  import { MessagePartPrimitiveText } from "../messagePart/MessagePartText";
17
11
  import { MessagePartPrimitiveImage } from "../messagePart/MessagePartImage";
18
- import type {
19
- Unstable_AudioMessagePartComponent,
20
- DataMessagePartComponent,
21
- DataMessagePartProps,
22
- EmptyMessagePartComponent,
23
- TextMessagePartComponent,
24
- ImageMessagePartComponent,
25
- SourceMessagePartComponent,
26
- ToolCallMessagePartComponent,
27
- ToolCallMessagePartProps,
28
- FileMessagePartComponent,
29
- ReasoningMessagePartComponent,
30
- ReasoningGroupComponent,
31
- } from "../../types/MessagePartComponentTypes";
32
12
  import { MessagePartPrimitiveInProgress } from "../messagePart/MessagePartInProgress";
33
- import type { MessagePartStatus } from "@assistant-ui/core";
34
- import { useShallow } from "zustand/shallow";
35
-
36
- type MessagePartRange =
37
- | { type: "single"; index: number }
38
- | { type: "toolGroup"; startIndex: number; endIndex: number }
39
- | { type: "reasoningGroup"; startIndex: number; endIndex: number }
40
- | { type: "chainOfThoughtGroup"; startIndex: number; endIndex: number };
41
-
42
- /**
43
- * Creates a group state manager for a specific part type.
44
- * Returns functions to start, end, and finalize groups.
45
- */
46
- const createGroupState = <
47
- T extends "toolGroup" | "reasoningGroup" | "chainOfThoughtGroup",
48
- >(
49
- groupType: T,
50
- ) => {
51
- let start = -1;
52
-
53
- return {
54
- startGroup: (index: number) => {
55
- if (start === -1) {
56
- start = index;
57
- }
58
- },
59
- endGroup: (endIndex: number, ranges: MessagePartRange[]) => {
60
- if (start !== -1) {
61
- ranges.push({
62
- type: groupType,
63
- startIndex: start,
64
- endIndex,
65
- } as MessagePartRange);
66
- start = -1;
67
- }
68
- },
69
- finalize: (endIndex: number, ranges: MessagePartRange[]) => {
70
- if (start !== -1) {
71
- ranges.push({
72
- type: groupType,
73
- startIndex: start,
74
- endIndex,
75
- } as MessagePartRange);
76
- }
77
- },
78
- };
79
- };
80
-
81
- /**
82
- * Groups consecutive tool-call and reasoning message parts into ranges.
83
- * Always groups tool calls and reasoning parts, even if there's only one.
84
- * When useChainOfThought is true, groups tool-call and reasoning parts together.
85
- */
86
- const groupMessageParts = (
87
- messageTypes: readonly string[],
88
- useChainOfThought: boolean,
89
- ): MessagePartRange[] => {
90
- const ranges: MessagePartRange[] = [];
91
-
92
- if (useChainOfThought) {
93
- const chainOfThoughtGroup = createGroupState("chainOfThoughtGroup");
94
-
95
- for (let i = 0; i < messageTypes.length; i++) {
96
- const type = messageTypes[i];
97
-
98
- if (type === "tool-call" || type === "reasoning") {
99
- chainOfThoughtGroup.startGroup(i);
100
- } else {
101
- chainOfThoughtGroup.endGroup(i - 1, ranges);
102
- ranges.push({ type: "single", index: i });
103
- }
104
- }
105
-
106
- chainOfThoughtGroup.finalize(messageTypes.length - 1, ranges);
107
- } else {
108
- const toolGroup = createGroupState("toolGroup");
109
- const reasoningGroup = createGroupState("reasoningGroup");
110
-
111
- for (let i = 0; i < messageTypes.length; i++) {
112
- const type = messageTypes[i];
113
-
114
- if (type === "tool-call") {
115
- reasoningGroup.endGroup(i - 1, ranges);
116
- toolGroup.startGroup(i);
117
- } else if (type === "reasoning") {
118
- toolGroup.endGroup(i - 1, ranges);
119
- reasoningGroup.startGroup(i);
120
- } else {
121
- toolGroup.endGroup(i - 1, ranges);
122
- reasoningGroup.endGroup(i - 1, ranges);
123
- ranges.push({ type: "single", index: i });
124
- }
125
- }
126
13
 
127
- toolGroup.finalize(messageTypes.length - 1, ranges);
128
- reasoningGroup.finalize(messageTypes.length - 1, ranges);
129
- }
130
-
131
- return ranges;
132
- };
133
-
134
- const useMessagePartsGroups = (
135
- useChainOfThought: boolean,
136
- ): MessagePartRange[] => {
137
- const messageTypes = useAuiState(
138
- useShallow((s) => s.message.parts.map((c: any) => c.type)),
139
- );
140
-
141
- return useMemo(() => {
142
- if (messageTypes.length === 0) {
143
- return [];
144
- }
145
- return groupMessageParts(messageTypes, useChainOfThought);
146
- }, [messageTypes, useChainOfThought]);
147
- };
148
-
149
- export namespace MessagePrimitiveParts {
150
- type DataConfig = {
151
- /** Map data event names to specific components */
152
- by_name?: Record<string, DataMessagePartComponent | undefined> | undefined;
153
- /** Fallback component for unmatched data events */
154
- Fallback?: DataMessagePartComponent | undefined;
155
- };
156
-
157
- type BaseComponents = {
158
- /** Component for rendering empty messages */
159
- Empty?: EmptyMessagePartComponent | undefined;
160
- /** Component for rendering text content */
161
- Text?: TextMessagePartComponent | undefined;
162
- /** Component for rendering source content */
163
- Source?: SourceMessagePartComponent | undefined;
164
- /** Component for rendering image content */
165
- Image?: ImageMessagePartComponent | undefined;
166
- /** Component for rendering file content */
167
- File?: FileMessagePartComponent | undefined;
168
- /** Component for rendering audio content (experimental) */
169
- Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;
170
- /** Configuration for data part rendering */
171
- data?: DataConfig | undefined;
172
- };
173
-
174
- type ToolsConfig =
175
- | {
176
- /** Map of tool names to their specific components */
177
- by_name?:
178
- | Record<string, ToolCallMessagePartComponent | undefined>
179
- | undefined;
180
- /** Fallback component for unregistered tools */
181
- Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;
182
- }
183
- | {
184
- /** Override component that handles all tool calls */
185
- Override: ComponentType<ToolCallMessagePartProps>;
186
- };
187
-
188
- /**
189
- * Standard component configuration for rendering reasoning and tool-call parts
190
- * individually (with optional grouping).
191
- *
192
- * Cannot be combined with `ChainOfThought`.
193
- */
194
- type StandardComponents = BaseComponents & {
195
- /** Component for rendering reasoning content (typically hidden) */
196
- Reasoning?: ReasoningMessagePartComponent | undefined;
197
- /** Configuration for tool call rendering */
198
- tools?: ToolsConfig | undefined;
199
-
200
- /**
201
- * Component for rendering grouped consecutive tool calls.
202
- *
203
- * When provided, this component will automatically wrap consecutive tool-call
204
- * message parts, allowing you to create collapsible sections, custom styling,
205
- * or other grouped presentations for multiple tool calls.
206
- *
207
- * The component receives:
208
- * - `startIndex`: The index of the first tool call in the group
209
- * - `endIndex`: The index of the last tool call in the group
210
- * - `children`: The rendered tool call components
211
- *
212
- * @example
213
- * ```tsx
214
- * // Collapsible tool group
215
- * ToolGroup: ({ startIndex, endIndex, children }) => (
216
- * <details className="tool-group">
217
- * <summary>
218
- * {endIndex - startIndex + 1} tool calls
219
- * </summary>
220
- * <div className="tool-group-content">
221
- * {children}
222
- * </div>
223
- * </details>
224
- * )
225
- * ```
226
- *
227
- * @param startIndex - Index of the first tool call in the group
228
- * @param endIndex - Index of the last tool call in the group
229
- * @param children - Rendered tool call components to display within the group
230
- *
231
- * @deprecated This feature is still experimental and subject to change.
232
- */
233
- ToolGroup?: ComponentType<
234
- PropsWithChildren<{ startIndex: number; endIndex: number }>
235
- >;
236
-
237
- /**
238
- * Component for rendering grouped reasoning parts.
239
- *
240
- * When provided, this component will automatically wrap reasoning message parts
241
- * (one or more consecutive) in a group container. Each reasoning part inside
242
- * renders its own text independently - no text merging occurs.
243
- *
244
- * The component receives:
245
- * - `startIndex`: The index of the first reasoning part in the group
246
- * - `endIndex`: The index of the last reasoning part in the group
247
- * - `children`: The rendered Reasoning components (one per part)
248
- *
249
- * @example
250
- * ```tsx
251
- * // Collapsible reasoning group
252
- * ReasoningGroup: ({ children }) => (
253
- * <details className="reasoning-group">
254
- * <summary>Reasoning</summary>
255
- * <div className="reasoning-content">
256
- * {children}
257
- * </div>
258
- * </details>
259
- * )
260
- * ```
261
- *
262
- * @param startIndex - Index of the first reasoning part in the group
263
- * @param endIndex - Index of the last reasoning part in the group
264
- * @param children - Rendered reasoning part components
265
- */
266
- ReasoningGroup?: ReasoningGroupComponent;
267
-
268
- ChainOfThought?: never;
269
- };
270
-
271
- /**
272
- * Chain of thought component configuration.
273
- *
274
- * When `ChainOfThought` is set, it takes control of rendering ALL reasoning and
275
- * tool-call parts in the message. The `Reasoning`, `tools`, `ReasoningGroup`, and
276
- * `ToolGroup` components cannot be used alongside it.
277
- *
278
- * The component is automatically wrapped in a ChainOfThoughtByIndicesProvider
279
- * that sets up the chainOfThought client scope with the correct parts.
280
- *
281
- * @example
282
- * ```tsx
283
- * // Chain of thought with accordion
284
- * ChainOfThought: () => (
285
- * <ChainOfThoughtPrimitive.Root>
286
- * <ChainOfThoughtPrimitive.AccordionTrigger>
287
- * Toggle reasoning
288
- * </ChainOfThoughtPrimitive.AccordionTrigger>
289
- * <ChainOfThoughtPrimitive.Parts />
290
- * </ChainOfThoughtPrimitive.Root>
291
- * )
292
- * ```
293
- */
294
- type ChainOfThoughtComponents = BaseComponents & {
295
- ChainOfThought: ComponentType;
296
-
297
- Reasoning?: never;
298
- tools?: never;
299
- ToolGroup?: never;
300
- ReasoningGroup?: never;
301
- };
302
-
303
- export type Props = {
304
- /**
305
- * Component configuration for rendering different types of message content.
306
- *
307
- * You can provide custom components for each content type (text, image, file, etc.)
308
- * and configure tool rendering behavior. If not provided, default components will be used.
309
- *
310
- * Use either `Reasoning`/`tools`/`ToolGroup`/`ReasoningGroup` for standard rendering,
311
- * or `ChainOfThought` to group all reasoning and tool-call parts into a single
312
- * collapsible component. These two modes are mutually exclusive.
313
- */
314
- components?: StandardComponents | ChainOfThoughtComponents | undefined;
315
- /**
316
- * When enabled, shows the Empty component if the last part in the message
317
- * is anything other than Text or Reasoning.
318
- *
319
- * This can be useful to ensure there's always a visible element at the end
320
- * of messages that end with non-text content like tool calls or images.
321
- *
322
- * @experimental This API is experimental and may change in future versions.
323
- * @default true
324
- */
325
- unstable_showEmptyOnNonTextEnd?: boolean | undefined;
326
- };
327
- }
328
-
329
- const ToolUIDisplay = ({
330
- Fallback,
331
- ...props
332
- }: {
333
- Fallback: ToolCallMessagePartComponent | undefined;
334
- } & ToolCallMessagePartProps) => {
335
- const Render = useAuiState((s) => {
336
- const Render = s.tools.tools[props.toolName] ?? Fallback;
337
- if (Array.isArray(Render)) return Render[0] ?? Fallback;
338
- return Render;
339
- });
340
- if (!Render) return null;
341
- return <Render {...props} />;
342
- };
343
-
344
- const DataUIDisplay = ({
345
- Fallback,
346
- ...props
347
- }: {
348
- Fallback: DataMessagePartComponent | undefined;
349
- } & DataMessagePartProps) => {
350
- const Render = useAuiState((s) => {
351
- const Render = s.dataRenderers.renderers[props.name] ?? Fallback;
352
- if (Array.isArray(Render)) return Render[0] ?? Fallback;
353
- return Render;
354
- });
355
- if (!Render) return null;
356
- return <Render {...props} />;
357
- };
358
-
359
- const defaultComponents = {
14
+ const webDefaultComponents = {
15
+ ...messagePartsDefaultComponents,
360
16
  Text: () => (
361
17
  <p style={{ whiteSpace: "pre-line" }}>
362
18
  <MessagePartPrimitiveText />
@@ -365,308 +21,53 @@ const defaultComponents = {
365
21
  </MessagePartPrimitiveInProgress>
366
22
  </p>
367
23
  ),
368
- Reasoning: () => null,
369
- Source: () => null,
370
24
  Image: () => <MessagePartPrimitiveImage />,
371
- File: () => null,
372
- Unstable_Audio: () => null,
373
- ToolGroup: ({ children }) => children,
374
- ReasoningGroup: ({ children }) => children,
375
25
  } satisfies MessagePrimitiveParts.Props["components"];
376
26
 
377
- type MessagePartComponentProps = {
378
- components: MessagePrimitiveParts.Props["components"];
379
- };
380
-
381
- export const MessagePartComponent: FC<MessagePartComponentProps> = ({
382
- components: {
383
- Text = defaultComponents.Text,
384
- Reasoning = defaultComponents.Reasoning,
385
- Image = defaultComponents.Image,
386
- Source = defaultComponents.Source,
387
- File = defaultComponents.File,
388
- Unstable_Audio: Audio = defaultComponents.Unstable_Audio,
389
- tools = {},
390
- data,
391
- } = {},
392
- }) => {
393
- const aui = useAui();
394
- const part = useAuiState((s) => s.part);
395
-
396
- const type = part.type;
397
- if (type === "tool-call") {
398
- const addResult = aui.part().addToolResult;
399
- const resume = aui.part().resumeToolCall;
400
- if ("Override" in tools)
401
- return <tools.Override {...part} addResult={addResult} resume={resume} />;
402
- const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;
403
- return (
404
- <ToolUIDisplay
405
- {...part}
406
- Fallback={Tool}
407
- addResult={addResult}
408
- resume={resume}
409
- />
410
- );
411
- }
412
-
413
- if (part.status?.type === "requires-action")
414
- throw new Error("Encountered unexpected requires-action status");
415
-
416
- switch (type) {
417
- case "text":
418
- return <Text {...part} />;
419
-
420
- case "reasoning":
421
- return <Reasoning {...part} />;
422
-
423
- case "source":
424
- return <Source {...part} />;
425
-
426
- case "image":
427
- return <Image {...part} />;
428
-
429
- case "file":
430
- return <File {...part} />;
431
-
432
- case "audio":
433
- return <Audio {...part} />;
434
-
435
- case "data": {
436
- const Data = data?.by_name?.[part.name] ?? data?.Fallback;
437
- return <DataUIDisplay {...part} Fallback={Data} />;
438
- }
439
-
440
- default:
441
- const unhandledType: never = type;
442
- throw new Error(`Unknown message part type: ${unhandledType}`);
443
- }
444
- };
445
-
446
- export namespace MessagePrimitivePartByIndex {
447
- export type Props = {
448
- index: number;
449
- components: MessagePrimitiveParts.Props["components"];
450
- };
27
+ export namespace MessagePrimitiveParts {
28
+ export type Props = MessagePrimitivePartsBase.Props;
451
29
  }
452
30
 
453
31
  /**
454
- * Renders a single message part at the specified index.
455
- *
456
- * This component provides direct access to render a specific message part
457
- * within the current message context, using the provided component configuration.
458
- *
459
- * @example
460
- * ```tsx
461
- * <MessagePrimitive.PartByIndex
462
- * index={0}
463
- * components={{
464
- * Text: MyTextComponent,
465
- * Image: MyImageComponent
466
- * }}
467
- * />
468
- * ```
469
- */
470
- export const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props> =
471
- memo(
472
- ({ index, components }) => {
473
- return (
474
- <PartByIndexProvider index={index}>
475
- <MessagePartComponent components={components} />
476
- </PartByIndexProvider>
477
- );
478
- },
479
- (prev, next) =>
480
- prev.index === next.index &&
481
- prev.components?.Text === next.components?.Text &&
482
- prev.components?.Reasoning === next.components?.Reasoning &&
483
- prev.components?.Source === next.components?.Source &&
484
- prev.components?.Image === next.components?.Image &&
485
- prev.components?.File === next.components?.File &&
486
- prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&
487
- prev.components?.tools === next.components?.tools &&
488
- prev.components?.data === next.components?.data &&
489
- prev.components?.ToolGroup === next.components?.ToolGroup &&
490
- prev.components?.ReasoningGroup === next.components?.ReasoningGroup,
491
- );
492
-
493
- MessagePrimitivePartByIndex.displayName = "MessagePrimitive.PartByIndex";
494
-
495
- const EmptyPartFallback: FC<{
496
- status: MessagePartStatus;
497
- component: TextMessagePartComponent;
498
- }> = ({ status, component: Component }) => {
499
- return (
500
- <TextMessagePartProvider text="" isRunning={status.type === "running"}>
501
- <Component type="text" text="" status={status} />
502
- </TextMessagePartProvider>
503
- );
504
- };
505
-
506
- const COMPLETE_STATUS: MessagePartStatus = Object.freeze({
507
- type: "complete",
508
- });
509
-
510
- const EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {
511
- const status = useAuiState(
512
- (s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,
513
- );
514
-
515
- if (components?.Empty) return <components.Empty status={status} />;
516
-
517
- return (
518
- <EmptyPartFallback
519
- status={status}
520
- component={components?.Text ?? defaultComponents.Text}
521
- />
522
- );
523
- };
524
-
525
- const EmptyParts = memo(
526
- EmptyPartsImpl,
527
- (prev, next) =>
528
- prev.components?.Empty === next.components?.Empty &&
529
- prev.components?.Text === next.components?.Text,
530
- );
531
-
532
- const ConditionalEmptyImpl: FC<{
533
- components: MessagePrimitiveParts.Props["components"];
534
- enabled: boolean;
535
- }> = ({ components, enabled }) => {
536
- const shouldShowEmpty = useAuiState((s) => {
537
- if (!enabled) return false;
538
- if (s.message.parts.length === 0) return false;
539
-
540
- const lastPart = s.message.parts[s.message.parts.length - 1];
541
- return lastPart?.type !== "text" && lastPart?.type !== "reasoning";
542
- });
543
-
544
- if (!shouldShowEmpty) return null;
545
- return <EmptyParts components={components} />;
546
- };
547
-
548
- const ConditionalEmpty = memo(
549
- ConditionalEmptyImpl,
550
- (prev, next) =>
551
- prev.enabled === next.enabled &&
552
- prev.components?.Empty === next.components?.Empty &&
553
- prev.components?.Text === next.components?.Text,
554
- );
555
-
556
- /**
557
- * Renders the parts of a message with support for multiple content types.
558
- *
559
- * This component automatically handles different types of message content including
560
- * text, images, files, tool calls, and more. It provides a flexible component
561
- * system for customizing how each content type is rendered.
562
- *
563
- * @example
564
- * ```tsx
565
- * <MessagePrimitive.Parts
566
- * components={{
567
- * Text: ({ text }) => <p className="message-text">{text}</p>,
568
- * Image: ({ image }) => <img src={image} alt="Message image" />,
569
- * tools: {
570
- * by_name: {
571
- * calculator: CalculatorTool,
572
- * weather: WeatherTool,
573
- * },
574
- * Fallback: DefaultToolComponent
575
- * }
576
- * }}
577
- * />
578
- * ```
32
+ * Renders the parts of a message with web-specific default components.
579
33
  */
580
34
  export const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({
581
35
  components,
582
- unstable_showEmptyOnNonTextEnd = true,
36
+ ...rest
583
37
  }) => {
584
- const contentLength = useAuiState((s) => s.message.parts.length);
585
- const useChainOfThought = !!components?.ChainOfThought;
586
- const messageRanges = useMessagePartsGroups(useChainOfThought);
587
-
588
- const partsElements = useMemo(() => {
589
- if (contentLength === 0) {
590
- return <EmptyParts components={components} />;
591
- }
592
-
593
- return messageRanges.map((range) => {
594
- if (range.type === "single") {
595
- return (
596
- <MessagePrimitivePartByIndex
597
- key={range.index}
598
- index={range.index}
599
- components={components}
600
- />
601
- );
602
- } else if (range.type === "chainOfThoughtGroup") {
603
- const ChainOfThoughtComponent = components?.ChainOfThought;
604
- if (!ChainOfThoughtComponent) return null;
605
- return (
606
- <ChainOfThoughtByIndicesProvider
607
- key={`chainOfThought-${range.startIndex}`}
608
- startIndex={range.startIndex}
609
- endIndex={range.endIndex}
610
- >
611
- <ChainOfThoughtComponent />
612
- </ChainOfThoughtByIndicesProvider>
613
- );
614
- } else if (range.type === "toolGroup") {
615
- const ToolGroupComponent =
616
- components?.ToolGroup ?? defaultComponents.ToolGroup;
617
- return (
618
- <ToolGroupComponent
619
- key={`tool-${range.startIndex}`}
620
- startIndex={range.startIndex}
621
- endIndex={range.endIndex}
622
- >
623
- {Array.from(
624
- { length: range.endIndex - range.startIndex + 1 },
625
- (_, i) => (
626
- <MessagePrimitivePartByIndex
627
- key={i}
628
- index={range.startIndex + i}
629
- components={components}
630
- />
631
- ),
632
- )}
633
- </ToolGroupComponent>
634
- );
635
- } else {
636
- // reasoningGroup
637
- const ReasoningGroupComponent =
638
- components?.ReasoningGroup ?? defaultComponents.ReasoningGroup;
639
- return (
640
- <ReasoningGroupComponent
641
- key={`reasoning-${range.startIndex}`}
642
- startIndex={range.startIndex}
643
- endIndex={range.endIndex}
644
- >
645
- {Array.from(
646
- { length: range.endIndex - range.startIndex + 1 },
647
- (_, i) => (
648
- <MessagePrimitivePartByIndex
649
- key={i}
650
- index={range.startIndex + i}
651
- components={components}
652
- />
653
- ),
654
- )}
655
- </ReasoningGroupComponent>
656
- );
38
+ const merged = components
39
+ ? {
40
+ Text: components.Text ?? webDefaultComponents.Text,
41
+ Image: components.Image ?? webDefaultComponents.Image,
42
+ Reasoning:
43
+ components.Reasoning ?? messagePartsDefaultComponents.Reasoning,
44
+ Source: components.Source ?? messagePartsDefaultComponents.Source,
45
+ File: components.File ?? messagePartsDefaultComponents.File,
46
+ Unstable_Audio:
47
+ components.Unstable_Audio ??
48
+ messagePartsDefaultComponents.Unstable_Audio,
49
+ ...("ChainOfThought" in components
50
+ ? { ChainOfThought: components.ChainOfThought }
51
+ : {
52
+ tools: components.tools,
53
+ data: components.data,
54
+ ToolGroup:
55
+ components.ToolGroup ?? messagePartsDefaultComponents.ToolGroup,
56
+ ReasoningGroup:
57
+ components.ReasoningGroup ??
58
+ messagePartsDefaultComponents.ReasoningGroup,
59
+ }),
60
+ Empty: components.Empty,
657
61
  }
658
- });
659
- }, [messageRanges, components, contentLength]);
62
+ : webDefaultComponents;
660
63
 
661
- return (
662
- <>
663
- {partsElements}
664
- <ConditionalEmpty
665
- components={components}
666
- enabled={unstable_showEmptyOnNonTextEnd}
667
- />
668
- </>
669
- );
64
+ return <MessagePrimitivePartsBase components={merged as any} {...rest} />;
670
65
  };
671
66
 
672
67
  MessagePrimitiveParts.displayName = "MessagePrimitive.Parts";
68
+
69
+ // Re-export everything else unchanged
70
+ export {
71
+ MessagePartComponentBase as MessagePartComponent,
72
+ MessagePrimitivePartByIndexBase as MessagePrimitivePartByIndex,
73
+ };