@tdesign-react/chat 1.0.2-alpha.9 → 1.1.0-alpha.1

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 (303) hide show
  1. package/es/_chunks/dep-f2051ebd.js +839 -0
  2. package/es/_chunks/dep-f2051ebd.js.map +1 -0
  3. package/es/_util/reactify.js +1 -1
  4. package/es/_util/useDynamicStyle.js +1 -1
  5. package/es/attachments/index.js +1 -1
  6. package/es/chat-actionbar/index.js +1 -1
  7. package/es/chat-engine/components/a2ui/A2UIActivityRenderer.d.ts +196 -0
  8. package/es/chat-engine/components/a2ui/A2UIActivityRenderer.js +301 -0
  9. package/es/chat-engine/components/a2ui/A2UIActivityRenderer.js.map +1 -0
  10. package/es/chat-engine/components/a2ui/A2UIComponentRenderer.d.ts +37 -0
  11. package/es/chat-engine/components/a2ui/A2UIComponentRenderer.js +116 -0
  12. package/es/chat-engine/components/a2ui/A2UIComponentRenderer.js.map +1 -0
  13. package/es/chat-engine/components/a2ui/A2UIErrorBoundary.d.ts +42 -0
  14. package/es/chat-engine/components/a2ui/A2UIErrorBoundary.js +113 -0
  15. package/es/chat-engine/components/a2ui/A2UIErrorBoundary.js.map +1 -0
  16. package/es/chat-engine/components/a2ui/A2UISkeleton.d.ts +60 -0
  17. package/es/chat-engine/components/a2ui/A2UISkeleton.js +197 -0
  18. package/es/chat-engine/components/a2ui/A2UISkeleton.js.map +1 -0
  19. package/es/chat-engine/components/a2ui/A2UISurfaceRenderer.d.ts +44 -0
  20. package/es/chat-engine/components/a2ui/A2UISurfaceRenderer.js +139 -0
  21. package/es/chat-engine/components/a2ui/A2UISurfaceRenderer.js.map +1 -0
  22. package/es/chat-engine/components/a2ui/containers/A2UICard.d.ts +22 -0
  23. package/es/chat-engine/components/a2ui/containers/A2UICard.js +82 -0
  24. package/es/chat-engine/components/a2ui/containers/A2UICard.js.map +1 -0
  25. package/es/chat-engine/components/a2ui/containers/A2UIColumn.d.ts +18 -0
  26. package/es/chat-engine/components/a2ui/containers/A2UIColumn.js +81 -0
  27. package/es/chat-engine/components/a2ui/containers/A2UIColumn.js.map +1 -0
  28. package/es/chat-engine/components/a2ui/containers/A2UIList.d.ts +14 -0
  29. package/es/chat-engine/components/a2ui/containers/A2UIList.js +62 -0
  30. package/es/chat-engine/components/a2ui/containers/A2UIList.js.map +1 -0
  31. package/es/chat-engine/components/a2ui/containers/A2UIRow.d.ts +20 -0
  32. package/es/chat-engine/components/a2ui/containers/A2UIRow.js +84 -0
  33. package/es/chat-engine/components/a2ui/containers/A2UIRow.js.map +1 -0
  34. package/es/chat-engine/components/a2ui/containers/A2UITabs.d.ts +14 -0
  35. package/es/chat-engine/components/a2ui/containers/A2UITabs.js +69 -0
  36. package/es/chat-engine/components/a2ui/containers/A2UITabs.js.map +1 -0
  37. package/es/chat-engine/components/a2ui/containers/index.d.ts +8 -0
  38. package/es/chat-engine/components/a2ui/containers/index.js +30 -0
  39. package/es/chat-engine/components/a2ui/containers/index.js.map +1 -0
  40. package/es/chat-engine/components/a2ui/index.d.ts +11 -0
  41. package/es/chat-engine/components/a2ui/index.js +62 -0
  42. package/es/chat-engine/components/a2ui/index.js.map +1 -0
  43. package/es/chat-engine/components/a2ui/primitives/A2UIButton.d.ts +33 -0
  44. package/es/chat-engine/components/a2ui/primitives/A2UIButton.js +80 -0
  45. package/es/chat-engine/components/a2ui/primitives/A2UIButton.js.map +1 -0
  46. package/es/chat-engine/components/a2ui/primitives/A2UICheckBox.d.ts +12 -0
  47. package/es/chat-engine/components/a2ui/primitives/A2UICheckBox.js +43 -0
  48. package/es/chat-engine/components/a2ui/primitives/A2UICheckBox.js.map +1 -0
  49. package/es/chat-engine/components/a2ui/primitives/A2UICheckboxGroup.d.ts +50 -0
  50. package/es/chat-engine/components/a2ui/primitives/A2UICheckboxGroup.js +54 -0
  51. package/es/chat-engine/components/a2ui/primitives/A2UICheckboxGroup.js.map +1 -0
  52. package/es/chat-engine/components/a2ui/primitives/A2UIChoicePicker.d.ts +13 -0
  53. package/es/chat-engine/components/a2ui/primitives/A2UIChoicePicker.js +89 -0
  54. package/es/chat-engine/components/a2ui/primitives/A2UIChoicePicker.js.map +1 -0
  55. package/es/chat-engine/components/a2ui/primitives/A2UIDivider.d.ts +12 -0
  56. package/es/chat-engine/components/a2ui/primitives/A2UIDivider.js +25 -0
  57. package/es/chat-engine/components/a2ui/primitives/A2UIDivider.js.map +1 -0
  58. package/es/chat-engine/components/a2ui/primitives/A2UIIcon.d.ts +13 -0
  59. package/es/chat-engine/components/a2ui/primitives/A2UIIcon.js +138942 -0
  60. package/es/chat-engine/components/a2ui/primitives/A2UIIcon.js.map +1 -0
  61. package/es/chat-engine/components/a2ui/primitives/A2UIImage.d.ts +12 -0
  62. package/es/chat-engine/components/a2ui/primitives/A2UIImage.js +75 -0
  63. package/es/chat-engine/components/a2ui/primitives/A2UIImage.js.map +1 -0
  64. package/es/chat-engine/components/a2ui/primitives/A2UIInput.d.ts +20 -0
  65. package/es/chat-engine/components/a2ui/primitives/A2UIInput.js +63 -0
  66. package/es/chat-engine/components/a2ui/primitives/A2UIInput.js.map +1 -0
  67. package/es/chat-engine/components/a2ui/primitives/A2UIRadioGroup.d.ts +56 -0
  68. package/es/chat-engine/components/a2ui/primitives/A2UIRadioGroup.js +64 -0
  69. package/es/chat-engine/components/a2ui/primitives/A2UIRadioGroup.js.map +1 -0
  70. package/es/chat-engine/components/a2ui/primitives/A2UISlider.d.ts +12 -0
  71. package/es/chat-engine/components/a2ui/primitives/A2UISlider.js +55 -0
  72. package/es/chat-engine/components/a2ui/primitives/A2UISlider.js.map +1 -0
  73. package/es/chat-engine/components/a2ui/primitives/A2UIText.d.ts +12 -0
  74. package/es/chat-engine/components/a2ui/primitives/A2UIText.js +104 -0
  75. package/es/chat-engine/components/a2ui/primitives/A2UIText.js.map +1 -0
  76. package/es/chat-engine/components/a2ui/primitives/A2UITextField.d.ts +12 -0
  77. package/es/chat-engine/components/a2ui/primitives/A2UITextField.js +80 -0
  78. package/es/chat-engine/components/a2ui/primitives/A2UITextField.js.map +1 -0
  79. package/es/chat-engine/components/a2ui/primitives/index.d.ts +15 -0
  80. package/es/chat-engine/components/a2ui/primitives/index.js +39 -0
  81. package/es/chat-engine/components/a2ui/primitives/index.js.map +1 -0
  82. package/es/chat-engine/components/a2ui/registry.d.ts +35 -0
  83. package/es/chat-engine/components/a2ui/registry.js +74 -0
  84. package/es/chat-engine/components/a2ui/registry.js.map +1 -0
  85. package/es/chat-engine/components/activity/index.js +1 -1
  86. package/es/chat-engine/components/activity/registry.d.ts +1 -1
  87. package/es/chat-engine/components/activity/registry.js +1 -1
  88. package/es/chat-engine/components/activity/registry.js.map +1 -1
  89. package/es/chat-engine/components/activity/render.d.ts +2 -2
  90. package/es/chat-engine/components/activity/render.js +1 -1
  91. package/es/chat-engine/components/activity/render.js.map +1 -1
  92. package/es/chat-engine/components/activity/types.js +1 -1
  93. package/es/chat-engine/components/index.d.ts +1 -0
  94. package/es/chat-engine/components/index.js +57 -9
  95. package/es/chat-engine/components/index.js.map +1 -1
  96. package/es/chat-engine/components/json-render/A2UIJsonRenderActivityRenderer.d.ts +36 -0
  97. package/es/chat-engine/components/json-render/A2UIJsonRenderActivityRenderer.js +36 -0
  98. package/es/chat-engine/components/json-render/A2UIJsonRenderActivityRenderer.js.map +1 -0
  99. package/es/chat-engine/components/json-render/JsonRenderActivityRenderer.d.ts +46 -0
  100. package/es/chat-engine/components/json-render/JsonRenderActivityRenderer.js +36 -0
  101. package/es/chat-engine/components/json-render/JsonRenderActivityRenderer.js.map +1 -0
  102. package/es/chat-engine/components/json-render/SurfaceStateManager.d.ts +113 -0
  103. package/es/chat-engine/components/json-render/SurfaceStateManager.js +195 -0
  104. package/es/chat-engine/components/json-render/SurfaceStateManager.js.map +1 -0
  105. package/es/chat-engine/components/json-render/adapters/a2ui-to-jsonrender.d.ts +49 -0
  106. package/es/chat-engine/components/json-render/adapters/a2ui-to-jsonrender.js +307 -0
  107. package/es/chat-engine/components/json-render/adapters/a2ui-to-jsonrender.js.map +1 -0
  108. package/es/chat-engine/components/json-render/adapters/a2ui-types.d.ts +96 -0
  109. package/es/chat-engine/components/json-render/adapters/a2ui-types.js +7 -0
  110. package/es/chat-engine/components/json-render/adapters/a2ui-types.js.map +1 -0
  111. package/es/chat-engine/components/json-render/adapters/index.d.ts +7 -0
  112. package/es/chat-engine/components/json-render/adapters/index.js +11 -0
  113. package/es/chat-engine/components/json-render/adapters/index.js.map +1 -0
  114. package/es/chat-engine/components/json-render/catalog/a2ui-binding.d.ts +64 -0
  115. package/es/chat-engine/components/json-render/catalog/a2ui-binding.js +36 -0
  116. package/es/chat-engine/components/json-render/catalog/a2ui-binding.js.map +1 -0
  117. package/es/chat-engine/components/json-render/catalog/a2ui-registry.d.ts +78 -0
  118. package/es/chat-engine/components/json-render/catalog/a2ui-registry.js +36 -0
  119. package/es/chat-engine/components/json-render/catalog/a2ui-registry.js.map +1 -0
  120. package/es/chat-engine/components/json-render/catalog/button.d.ts +14 -0
  121. package/es/chat-engine/components/json-render/catalog/button.js +71 -0
  122. package/es/chat-engine/components/json-render/catalog/button.js.map +1 -0
  123. package/es/chat-engine/components/json-render/catalog/card.d.ts +11 -0
  124. package/es/chat-engine/components/json-render/catalog/card.js +57 -0
  125. package/es/chat-engine/components/json-render/catalog/card.js.map +1 -0
  126. package/es/chat-engine/components/json-render/catalog/index.d.ts +127 -0
  127. package/es/chat-engine/components/json-render/catalog/index.js +36 -0
  128. package/es/chat-engine/components/json-render/catalog/index.js.map +1 -0
  129. package/es/chat-engine/components/json-render/catalog/input.d.ts +20 -0
  130. package/es/chat-engine/components/json-render/catalog/input.js +36 -0
  131. package/es/chat-engine/components/json-render/catalog/input.js.map +1 -0
  132. package/es/chat-engine/components/json-render/catalog/layout.d.ts +44 -0
  133. package/es/chat-engine/components/json-render/catalog/layout.js +129 -0
  134. package/es/chat-engine/components/json-render/catalog/layout.js.map +1 -0
  135. package/es/chat-engine/components/json-render/catalog/text.d.ts +11 -0
  136. package/es/chat-engine/components/json-render/catalog/text.js +31 -0
  137. package/es/chat-engine/components/json-render/catalog/text.js.map +1 -0
  138. package/es/chat-engine/components/json-render/catalog.d.ts +549 -0
  139. package/es/chat-engine/components/json-render/catalog.js +147 -0
  140. package/es/chat-engine/components/json-render/catalog.js.map +1 -0
  141. package/es/chat-engine/components/json-render/config.d.ts +154 -0
  142. package/es/chat-engine/components/json-render/config.js +36 -0
  143. package/es/chat-engine/components/json-render/config.js.map +1 -0
  144. package/es/chat-engine/components/json-render/contexts/actions.d.ts +74 -0
  145. package/es/chat-engine/components/json-render/contexts/actions.js +290 -0
  146. package/es/chat-engine/components/json-render/contexts/actions.js.map +1 -0
  147. package/es/chat-engine/components/json-render/contexts/data.d.ts +45 -0
  148. package/es/chat-engine/components/json-render/contexts/data.js +104 -0
  149. package/es/chat-engine/components/json-render/contexts/data.js.map +1 -0
  150. package/es/chat-engine/components/json-render/contexts/validation.d.ts +59 -0
  151. package/es/chat-engine/components/json-render/contexts/validation.js +151 -0
  152. package/es/chat-engine/components/json-render/contexts/validation.js.map +1 -0
  153. package/es/chat-engine/components/json-render/contexts/visibility.d.ts +29 -0
  154. package/es/chat-engine/components/json-render/contexts/visibility.js +56 -0
  155. package/es/chat-engine/components/json-render/contexts/visibility.js.map +1 -0
  156. package/es/chat-engine/components/json-render/engine.d.ts +58 -0
  157. package/es/chat-engine/components/json-render/engine.js +88 -0
  158. package/es/chat-engine/components/json-render/engine.js.map +1 -0
  159. package/es/chat-engine/components/json-render/index.d.ts +34 -0
  160. package/es/chat-engine/components/json-render/index.js +36 -0
  161. package/es/chat-engine/components/json-render/index.js.map +1 -0
  162. package/es/chat-engine/components/json-render/performance.d.ts +91 -0
  163. package/es/chat-engine/components/json-render/performance.js +135 -0
  164. package/es/chat-engine/components/json-render/performance.js.map +1 -0
  165. package/es/chat-engine/components/json-render/renderer.d.ts +71 -0
  166. package/es/chat-engine/components/json-render/renderer.js +124 -0
  167. package/es/chat-engine/components/json-render/renderer.js.map +1 -0
  168. package/es/chat-engine/components/json-render/types.d.ts +69 -0
  169. package/es/chat-engine/components/json-render/types.js +7 -0
  170. package/es/chat-engine/components/json-render/types.js.map +1 -0
  171. package/es/chat-engine/components/provider/agent-state.js +39 -2
  172. package/es/chat-engine/components/provider/agent-state.js.map +1 -1
  173. package/es/chat-engine/components/toolcall/index.js +32 -2
  174. package/es/chat-engine/components/toolcall/index.js.map +1 -1
  175. package/es/chat-engine/components/toolcall/registry.js +1 -1
  176. package/es/chat-engine/components/toolcall/render.d.ts +1 -1
  177. package/es/chat-engine/components/toolcall/render.js +33 -4
  178. package/es/chat-engine/components/toolcall/render.js.map +1 -1
  179. package/es/chat-engine/components/toolcall/types.js +1 -1
  180. package/es/chat-engine/core/a2ui/index.d.ts +10 -0
  181. package/es/chat-engine/core/a2ui/index.js +24 -0
  182. package/es/chat-engine/core/a2ui/index.js.map +1 -0
  183. package/es/chat-engine/core/a2ui/processor/A2uiMessageProcessor.d.ts +197 -0
  184. package/es/chat-engine/core/a2ui/processor/A2uiMessageProcessor.js +438 -0
  185. package/es/chat-engine/core/a2ui/processor/A2uiMessageProcessor.js.map +1 -0
  186. package/es/chat-engine/core/a2ui/processor/ComponentTree.d.ts +53 -0
  187. package/es/chat-engine/core/a2ui/processor/ComponentTree.js +158 -0
  188. package/es/chat-engine/core/a2ui/processor/ComponentTree.js.map +1 -0
  189. package/es/chat-engine/core/a2ui/processor/DataStore.d.ts +63 -0
  190. package/es/chat-engine/core/a2ui/processor/DataStore.js +172 -0
  191. package/es/chat-engine/core/a2ui/processor/DataStore.js.map +1 -0
  192. package/es/chat-engine/core/a2ui/processor/PathResolver.d.ts +47 -0
  193. package/es/chat-engine/core/a2ui/processor/PathResolver.js +99 -0
  194. package/es/chat-engine/core/a2ui/processor/PathResolver.js.map +1 -0
  195. package/es/chat-engine/core/a2ui/types/index.d.ts +4 -0
  196. package/es/chat-engine/core/a2ui/types/index.js +9 -0
  197. package/es/chat-engine/core/a2ui/types/index.js.map +1 -0
  198. package/es/chat-engine/core/a2ui/types/types.d.ts +770 -0
  199. package/es/chat-engine/core/a2ui/types/types.js +104 -0
  200. package/es/chat-engine/core/a2ui/types/types.js.map +1 -0
  201. package/es/chat-engine/core/a2ui/utils/binding.d.ts +34 -0
  202. package/es/chat-engine/core/a2ui/utils/binding.js +1784 -0
  203. package/es/chat-engine/core/a2ui/utils/binding.js.map +1 -0
  204. package/es/chat-engine/core/a2ui/utils/index.d.ts +5 -0
  205. package/es/chat-engine/core/a2ui/utils/index.js +13 -0
  206. package/es/chat-engine/core/a2ui/utils/index.js.map +1 -0
  207. package/es/chat-engine/core/a2ui/utils/validation.d.ts +70 -0
  208. package/es/chat-engine/core/a2ui/utils/validation.js +333 -0
  209. package/es/chat-engine/core/a2ui/utils/validation.js.map +1 -0
  210. package/es/chat-engine/core/adapters/agui/activity-manager.d.ts +102 -0
  211. package/es/chat-engine/core/adapters/agui/activity-manager.js +144 -0
  212. package/es/chat-engine/core/adapters/agui/activity-manager.js.map +1 -0
  213. package/es/chat-engine/core/adapters/agui/event-mapper.d.ts +42 -2
  214. package/es/chat-engine/core/adapters/agui/event-mapper.js +90 -50
  215. package/es/chat-engine/core/adapters/agui/event-mapper.js.map +1 -1
  216. package/es/chat-engine/core/adapters/agui/events.d.ts +222 -222
  217. package/es/chat-engine/core/adapters/agui/events.js +34 -34
  218. package/es/chat-engine/core/adapters/agui/events.js.map +1 -1
  219. package/es/chat-engine/core/adapters/agui/index.d.ts +22 -2
  220. package/es/chat-engine/core/adapters/agui/index.js +34 -14
  221. package/es/chat-engine/core/adapters/agui/index.js.map +1 -1
  222. package/es/chat-engine/core/adapters/agui/state-manager.js +1 -1
  223. package/es/chat-engine/core/adapters/agui/types.d.ts +57 -56
  224. package/es/chat-engine/core/adapters/agui/types.js +5 -5
  225. package/es/chat-engine/core/adapters/agui/types.js.map +1 -1
  226. package/es/chat-engine/core/adapters/agui/utils.d.ts +9 -3
  227. package/es/chat-engine/core/adapters/agui/utils.js +23 -4
  228. package/es/chat-engine/core/adapters/agui/utils.js.map +1 -1
  229. package/es/chat-engine/core/event-bus/ChatEventBus.d.ts +88 -0
  230. package/es/chat-engine/core/event-bus/ChatEventBus.js +295 -0
  231. package/es/chat-engine/core/event-bus/ChatEventBus.js.map +1 -0
  232. package/es/chat-engine/core/event-bus/index.d.ts +5 -0
  233. package/es/chat-engine/core/event-bus/index.js +13 -0
  234. package/es/chat-engine/core/event-bus/index.js.map +1 -0
  235. package/es/chat-engine/core/event-bus/types.d.ts +230 -0
  236. package/es/chat-engine/core/event-bus/types.js +32 -0
  237. package/es/chat-engine/core/event-bus/types.js.map +1 -0
  238. package/es/chat-engine/core/index.d.ts +16 -1
  239. package/es/chat-engine/core/index.js +174 -17
  240. package/es/chat-engine/core/index.js.map +1 -1
  241. package/es/chat-engine/core/processor/index.js +1 -1
  242. package/es/chat-engine/core/server/batch-client.js +1 -1
  243. package/es/chat-engine/core/server/connection-manager.js +1 -1
  244. package/es/chat-engine/core/server/errors.js +1 -1
  245. package/es/chat-engine/core/server/index.js +1 -1
  246. package/es/chat-engine/core/server/llm-service.js +17 -15
  247. package/es/chat-engine/core/server/llm-service.js.map +1 -1
  248. package/es/chat-engine/core/server/sse-client.js +1 -1
  249. package/es/chat-engine/core/server/sse-parser.js +1 -1
  250. package/es/chat-engine/core/server/types.js +1 -1
  251. package/es/chat-engine/core/store/message.js +2 -2
  252. package/es/chat-engine/core/store/message.js.map +1 -1
  253. package/es/chat-engine/core/store/model.js +1 -1
  254. package/es/chat-engine/core/store/reactiveState.js +1 -1
  255. package/es/chat-engine/core/type.d.ts +18 -2
  256. package/es/chat-engine/core/type.js +1 -1
  257. package/es/chat-engine/core/utils/eventEmitter.js +1 -1
  258. package/es/chat-engine/core/utils/index.js +1 -1
  259. package/es/chat-engine/core/utils/logger.js +1 -1
  260. package/es/chat-engine/hooks/a2ui/A2UIContext.d.ts +90 -0
  261. package/es/chat-engine/hooks/a2ui/A2UIContext.js +97 -0
  262. package/es/chat-engine/hooks/a2ui/A2UIContext.js.map +1 -0
  263. package/es/chat-engine/hooks/a2ui/index.d.ts +12 -0
  264. package/es/chat-engine/hooks/a2ui/index.js +19 -0
  265. package/es/chat-engine/hooks/a2ui/index.js.map +1 -0
  266. package/es/chat-engine/hooks/a2ui/useA2UIAction.d.ts +40 -0
  267. package/es/chat-engine/hooks/a2ui/useA2UIAction.js +74 -0
  268. package/es/chat-engine/hooks/a2ui/useA2UIAction.js.map +1 -0
  269. package/es/chat-engine/hooks/a2ui/useA2UISurface.d.ts +36 -0
  270. package/es/chat-engine/hooks/a2ui/useA2UISurface.js +39 -0
  271. package/es/chat-engine/hooks/a2ui/useA2UISurface.js.map +1 -0
  272. package/es/chat-engine/hooks/a2ui/useDataBinding.d.ts +53 -0
  273. package/es/chat-engine/hooks/a2ui/useDataBinding.js +111 -0
  274. package/es/chat-engine/hooks/a2ui/useDataBinding.js.map +1 -0
  275. package/es/chat-engine/hooks/index.js +38 -4
  276. package/es/chat-engine/hooks/index.js.map +1 -1
  277. package/es/chat-engine/hooks/useAgentActivity.d.ts +1 -2
  278. package/es/chat-engine/hooks/useAgentActivity.js +1 -1
  279. package/es/chat-engine/hooks/useAgentActivity.js.map +1 -1
  280. package/es/chat-engine/hooks/useAgentState.js +39 -2
  281. package/es/chat-engine/hooks/useAgentState.js.map +1 -1
  282. package/es/chat-engine/hooks/useAgentToolcall.js +1 -1
  283. package/es/chat-engine/hooks/useChat.d.ts +3 -3
  284. package/es/chat-engine/hooks/useChat.js +40 -2
  285. package/es/chat-engine/hooks/useChat.js.map +1 -1
  286. package/es/chat-engine/hooks/useJsonRenderActivity.d.ts +56 -0
  287. package/es/chat-engine/hooks/useJsonRenderActivity.js +63 -0
  288. package/es/chat-engine/hooks/useJsonRenderActivity.js.map +1 -0
  289. package/es/chat-engine/index.d.ts +1 -3
  290. package/es/chat-engine/index.js +30 -8
  291. package/es/chat-engine/index.js.map +1 -1
  292. package/es/chat-filecard/index.js +1 -1
  293. package/es/chat-loading/index.js +1 -1
  294. package/es/chat-markdown/index.js +1 -1
  295. package/es/chat-message/index.js +1 -1
  296. package/es/chat-sender/index.js +1 -1
  297. package/es/chat-thinking/index.js +1 -1
  298. package/es/chatbot/docs/react-best-practice.d.ts +13 -0
  299. package/es/chatbot/index.js +1 -1
  300. package/es/index.js +27 -5
  301. package/es/index.js.map +1 -1
  302. package/es/style/index.js +1 -1
  303. package/package.json +6 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tdesign v1.0.2-alpha.6
2
+ * tdesign v1.0.2-alpha.15
3
3
  * (c) 2026 tdesign
4
4
  * @license MIT
5
5
  */
@@ -0,0 +1,90 @@
1
+ /**
2
+ * A2UI React Context
3
+ * 双 Context 设计:A2UIContext(运行时状态)+ ComponentRegistryContext(组件注册)
4
+ */
5
+ import React, { ReactNode } from 'react';
6
+ import type { A2uiMessageProcessor } from '../../core/a2ui';
7
+ import type { ActionHandler } from '../../core/a2ui';
8
+ /**
9
+ * A2UI 组件渲染器类型
10
+ */
11
+ export type A2UIComponentRenderer<T = any> = React.ComponentType<T>;
12
+ /**
13
+ * 组件注册表
14
+ */
15
+ export interface ComponentRegistry {
16
+ [componentType: string]: A2UIComponentRenderer;
17
+ }
18
+ /**
19
+ * 组件注册表上下文值
20
+ */
21
+ interface ComponentRegistryContextValue {
22
+ registry: ComponentRegistry;
23
+ getComponent: (type: string) => A2UIComponentRenderer | undefined;
24
+ }
25
+ /**
26
+ * 组件注册表 Provider
27
+ */
28
+ export interface ComponentRegistryProviderProps {
29
+ registry: ComponentRegistry;
30
+ children: ReactNode;
31
+ }
32
+ export declare function ComponentRegistryProvider({ registry, children }: ComponentRegistryProviderProps): import("react/jsx-runtime").JSX.Element;
33
+ /**
34
+ * 获取组件注册表
35
+ */
36
+ export declare function useComponentRegistry(): ComponentRegistryContextValue;
37
+ /**
38
+ * A2UI 运行时上下文值
39
+ */
40
+ export interface A2UIContextValue {
41
+ /** A2UI 消息处理器 */
42
+ processor: A2uiMessageProcessor;
43
+ /** 当前 Surface ID */
44
+ surfaceId: string;
45
+ /** 当前数据上下文路径(用于相对路径解析和 template 渲染) */
46
+ dataContextPath: string;
47
+ /** Action 处理回调 */
48
+ onAction?: ActionHandler;
49
+ }
50
+ /**
51
+ * A2UI 运行时 Provider
52
+ */
53
+ export interface A2UIProviderProps {
54
+ processor: A2uiMessageProcessor;
55
+ surfaceId: string;
56
+ dataContextPath?: string;
57
+ onAction?: ActionHandler;
58
+ children: ReactNode;
59
+ }
60
+ export declare function A2UIProvider({ processor, surfaceId, dataContextPath, onAction, children, }: A2UIProviderProps): import("react/jsx-runtime").JSX.Element;
61
+ /**
62
+ * 获取 A2UI 运行时上下文
63
+ */
64
+ export declare function useA2UIContext(): A2UIContextValue;
65
+ /**
66
+ * 安全获取 A2UI 上下文(可能为 null)
67
+ */
68
+ export declare function useA2UIContextSafe(): A2UIContextValue | null;
69
+ /**
70
+ * A2UI 完整 Provider(组合两个 Context)
71
+ */
72
+ export interface A2UIRootProviderProps {
73
+ processor: A2uiMessageProcessor;
74
+ surfaceId: string;
75
+ registry: ComponentRegistry;
76
+ dataContextPath?: string;
77
+ onAction?: ActionHandler;
78
+ children: ReactNode;
79
+ }
80
+ export declare function A2UIRootProvider({ processor, surfaceId, registry, dataContextPath, onAction, children, }: A2UIRootProviderProps): import("react/jsx-runtime").JSX.Element;
81
+ /**
82
+ * 数据上下文路径 Provider
83
+ * 用于 List/Template 渲染时修改子组件的数据上下文
84
+ */
85
+ export interface DataContextProviderProps {
86
+ path: string;
87
+ children: ReactNode;
88
+ }
89
+ export declare function DataContextProvider({ path, children }: DataContextProviderProps): import("react/jsx-runtime").JSX.Element;
90
+ export {};
@@ -0,0 +1,97 @@
1
+ /**
2
+ * tdesign v1.0.2-alpha.14
3
+ * (c) 2026 tdesign
4
+ * @license MIT
5
+ */
6
+
7
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
8
+ import React__default, { createContext, useMemo, useContext } from 'react';
9
+
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ var ComponentRegistryContext = /*#__PURE__*/createContext(null);
13
+ function ComponentRegistryProvider(_ref) {
14
+ var registry = _ref.registry,
15
+ children = _ref.children;
16
+ var value = useMemo(function () {
17
+ return {
18
+ registry: registry,
19
+ getComponent: function getComponent(type) {
20
+ return registry[type];
21
+ }
22
+ };
23
+ }, [registry]);
24
+ return /* @__PURE__ */React__default.createElement(ComponentRegistryContext.Provider, {
25
+ value: value
26
+ }, children);
27
+ }
28
+ function useComponentRegistry() {
29
+ var context = useContext(ComponentRegistryContext);
30
+ if (!context) {
31
+ throw new Error("useComponentRegistry must be used within ComponentRegistryProvider");
32
+ }
33
+ return context;
34
+ }
35
+ var A2UIContext = /*#__PURE__*/createContext(null);
36
+ function A2UIProvider(_ref2) {
37
+ var processor = _ref2.processor,
38
+ surfaceId = _ref2.surfaceId,
39
+ _ref2$dataContextPath = _ref2.dataContextPath,
40
+ dataContextPath = _ref2$dataContextPath === void 0 ? "/" : _ref2$dataContextPath,
41
+ onAction = _ref2.onAction,
42
+ children = _ref2.children;
43
+ var value = useMemo(function () {
44
+ return {
45
+ processor: processor,
46
+ surfaceId: surfaceId,
47
+ dataContextPath: dataContextPath,
48
+ onAction: onAction
49
+ };
50
+ }, [processor, surfaceId, dataContextPath, onAction]);
51
+ return /* @__PURE__ */React__default.createElement(A2UIContext.Provider, {
52
+ value: value
53
+ }, children);
54
+ }
55
+ function useA2UIContext() {
56
+ var context = useContext(A2UIContext);
57
+ if (!context) {
58
+ throw new Error("useA2UIContext must be used within A2UIProvider");
59
+ }
60
+ return context;
61
+ }
62
+ function useA2UIContextSafe() {
63
+ return useContext(A2UIContext);
64
+ }
65
+ function A2UIRootProvider(_ref3) {
66
+ var processor = _ref3.processor,
67
+ surfaceId = _ref3.surfaceId,
68
+ registry = _ref3.registry,
69
+ _ref3$dataContextPath = _ref3.dataContextPath,
70
+ dataContextPath = _ref3$dataContextPath === void 0 ? "/" : _ref3$dataContextPath,
71
+ onAction = _ref3.onAction,
72
+ children = _ref3.children;
73
+ return /* @__PURE__ */React__default.createElement(ComponentRegistryProvider, {
74
+ registry: registry
75
+ }, /* @__PURE__ */React__default.createElement(A2UIProvider, {
76
+ processor: processor,
77
+ surfaceId: surfaceId,
78
+ dataContextPath: dataContextPath,
79
+ onAction: onAction
80
+ }, children));
81
+ }
82
+ function DataContextProvider(_ref4) {
83
+ var path = _ref4.path,
84
+ children = _ref4.children;
85
+ var parent = useA2UIContext();
86
+ var value = useMemo(function () {
87
+ return _objectSpread(_objectSpread({}, parent), {}, {
88
+ dataContextPath: path
89
+ });
90
+ }, [parent, path]);
91
+ return /* @__PURE__ */React__default.createElement(A2UIContext.Provider, {
92
+ value: value
93
+ }, children);
94
+ }
95
+
96
+ export { A2UIProvider, A2UIRootProvider, ComponentRegistryProvider, DataContextProvider, useA2UIContext, useA2UIContextSafe, useComponentRegistry };
97
+ //# sourceMappingURL=A2UIContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2UIContext.js","sources":["../../../../../pro-components/chat/chat-engine/hooks/a2ui/A2UIContext.tsx"],"sourcesContent":["/**\n * A2UI React Context\n * 双 Context 设计:A2UIContext(运行时状态)+ ComponentRegistryContext(组件注册)\n */\n\nimport React, { createContext, useContext, useMemo, ReactNode } from 'react';\nimport type { A2uiMessageProcessor } from '../../core/a2ui';\nimport type { ActionHandler } from '../../core/a2ui';\n\n// ============= Component Registry Context =============\n\n/**\n * A2UI 组件渲染器类型\n */\nexport type A2UIComponentRenderer<T = any> = React.ComponentType<T>;\n\n/**\n * 组件注册表\n */\nexport interface ComponentRegistry {\n [componentType: string]: A2UIComponentRenderer;\n}\n\n/**\n * 组件注册表上下文值\n */\ninterface ComponentRegistryContextValue {\n registry: ComponentRegistry;\n getComponent: (type: string) => A2UIComponentRenderer | undefined;\n}\n\nconst ComponentRegistryContext = createContext<ComponentRegistryContextValue | null>(null);\n\n/**\n * 组件注册表 Provider\n */\nexport interface ComponentRegistryProviderProps {\n registry: ComponentRegistry;\n children: ReactNode;\n}\n\nexport function ComponentRegistryProvider({ registry, children }: ComponentRegistryProviderProps) {\n const value = useMemo<ComponentRegistryContextValue>(\n () => ({\n registry,\n getComponent: (type: string) => registry[type],\n }),\n [registry]\n );\n\n return (\n <ComponentRegistryContext.Provider value={value}>\n {children}\n </ComponentRegistryContext.Provider>\n );\n}\n\n/**\n * 获取组件注册表\n */\nexport function useComponentRegistry(): ComponentRegistryContextValue {\n const context = useContext(ComponentRegistryContext);\n if (!context) {\n throw new Error('useComponentRegistry must be used within ComponentRegistryProvider');\n }\n return context;\n}\n\n// ============= A2UI Runtime Context =============\n\n/**\n * A2UI 运行时上下文值\n */\nexport interface A2UIContextValue {\n /** A2UI 消息处理器 */\n processor: A2uiMessageProcessor;\n /** 当前 Surface ID */\n surfaceId: string;\n /** 当前数据上下文路径(用于相对路径解析和 template 渲染) */\n dataContextPath: string;\n /** Action 处理回调 */\n onAction?: ActionHandler;\n}\n\nconst A2UIContext = createContext<A2UIContextValue | null>(null);\n\n/**\n * A2UI 运行时 Provider\n */\nexport interface A2UIProviderProps {\n processor: A2uiMessageProcessor;\n surfaceId: string;\n dataContextPath?: string;\n onAction?: ActionHandler;\n children: ReactNode;\n}\n\nexport function A2UIProvider({\n processor,\n surfaceId,\n dataContextPath = '/',\n onAction,\n children,\n}: A2UIProviderProps) {\n const value = useMemo<A2UIContextValue>(\n () => ({\n processor,\n surfaceId,\n dataContextPath,\n onAction,\n }),\n [processor, surfaceId, dataContextPath, onAction]\n );\n\n return <A2UIContext.Provider value={value}>{children}</A2UIContext.Provider>;\n}\n\n/**\n * 获取 A2UI 运行时上下文\n */\nexport function useA2UIContext(): A2UIContextValue {\n const context = useContext(A2UIContext);\n if (!context) {\n throw new Error('useA2UIContext must be used within A2UIProvider');\n }\n return context;\n}\n\n/**\n * 安全获取 A2UI 上下文(可能为 null)\n */\nexport function useA2UIContextSafe(): A2UIContextValue | null {\n return useContext(A2UIContext);\n}\n\n// ============= 组合 Provider =============\n\n/**\n * A2UI 完整 Provider(组合两个 Context)\n */\nexport interface A2UIRootProviderProps {\n processor: A2uiMessageProcessor;\n surfaceId: string;\n registry: ComponentRegistry;\n dataContextPath?: string;\n onAction?: ActionHandler;\n children: ReactNode;\n}\n\nexport function A2UIRootProvider({\n processor,\n surfaceId,\n registry,\n dataContextPath = '/',\n onAction,\n children,\n}: A2UIRootProviderProps) {\n return (\n <ComponentRegistryProvider registry={registry}>\n <A2UIProvider\n processor={processor}\n surfaceId={surfaceId}\n dataContextPath={dataContextPath}\n onAction={onAction}\n >\n {children}\n </A2UIProvider>\n </ComponentRegistryProvider>\n );\n}\n\n// ============= Data Context Path Provider =============\n\n/**\n * 数据上下文路径 Provider\n * 用于 List/Template 渲染时修改子组件的数据上下文\n */\nexport interface DataContextProviderProps {\n path: string;\n children: ReactNode;\n}\n\nexport function DataContextProvider({ path, children }: DataContextProviderProps) {\n const parent = useA2UIContext();\n\n const value = useMemo<A2UIContextValue>(\n () => ({\n ...parent,\n dataContextPath: path,\n }),\n [parent, path]\n );\n\n return <A2UIContext.Provider value={value}>{children}</A2UIContext.Provider>;\n}\n"],"names":["ComponentRegistryContext","createContext","ComponentRegistryProvider","_ref","registry","children","value","useMemo","getComponent","type","React","createElement","Provider","useComponentRegistry","context","useContext","Error","A2UIContext","A2UIProvider","_ref2","processor","surfaceId","_ref2$dataContextPath","dataContextPath","onAction","useA2UIContext","useA2UIContextSafe","A2UIRootProvider","_ref3","_ref3$dataContextPath","DataContextProvider","_ref4","path","parent","_objectSpread"],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A2UI React 适配层 Hooks 导出
3
+ */
4
+ export { A2UIRootProvider, // 组合 Provider,一站式解决方案
5
+ useA2UIContext, // 核心 Context Hook
6
+ useComponentRegistry, // 组件注册表 Hook
7
+ type ComponentRegistry, // 核心类型
8
+ type A2UIRootProviderProps, } from './A2UIContext';
9
+ export { useDataBinding, // 单向绑定(最常用)
10
+ useTwoWayBinding, } from './useDataBinding';
11
+ export { useA2UISurface, } from './useA2UISurface';
12
+ export { useA2UIAction, } from './useA2UIAction';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * tdesign v1.0.2-alpha.14
3
+ * (c) 2026 tdesign
4
+ * @license MIT
5
+ */
6
+
7
+ export { A2UIRootProvider, useA2UIContext, useComponentRegistry } from './A2UIContext.js';
8
+ export { useDataBinding, useTwoWayBinding } from './useDataBinding.js';
9
+ export { useA2UISurface } from './useA2UISurface.js';
10
+ export { useA2UIAction } from './useA2UIAction.js';
11
+ import '@babel/runtime/helpers/defineProperty';
12
+ import 'react';
13
+ import '@babel/runtime/helpers/slicedToArray';
14
+ import '../../core/a2ui/utils/index.js';
15
+ import '../../core/a2ui/utils/binding.js';
16
+ import '@babel/runtime/helpers/typeof';
17
+ import '../../core/a2ui/utils/validation.js';
18
+ import '@babel/runtime/helpers/toConsumableArray';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A2UI Action 相关 Hooks
3
+ */
4
+ import type { A2UIAction } from '../../core/a2ui';
5
+ /**
6
+ * 获取 Action 分发函数
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * function Button({ action }: { action: A2UIAction }) {
11
+ * const dispatch = useA2UIAction();
12
+ * return <TButton onClick={() => dispatch(action)}>Click</TButton>;
13
+ * }
14
+ * ```
15
+ */
16
+ export declare function useA2UIAction(): (action: A2UIAction, componentId?: string) => void;
17
+ /**
18
+ * 创建绑定特定 Action 的回调
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * function ConfirmButton({ id }: { id: string }) {
23
+ * const handleConfirm = useActionCallback({ name: 'confirm', context: { value: true } }, id);
24
+ * return <TButton onClick={handleConfirm}>确认</TButton>;
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function useActionCallback(action: A2UIAction | undefined, componentId?: string): (() => void) | undefined;
29
+ /**
30
+ * 创建带参数的 Action 回调
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * function Input({ id }: { id: string }) {
35
+ * const handleChange = useActionWithPayload('input-change', id);
36
+ * return <TInput onChange={(val) => handleChange({ value: val })} />;
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function useActionWithPayload(actionName: string, componentId?: string): (context: Record<string, unknown>) => void;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * tdesign v1.0.2-alpha.14
3
+ * (c) 2026 tdesign
4
+ * @license MIT
5
+ */
6
+
7
+ import { useCallback } from 'react';
8
+ import { useA2UIContext } from './A2UIContext.js';
9
+ import '@babel/runtime/helpers/defineProperty';
10
+
11
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
12
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
+ function useA2UIAction() {
15
+ var _useA2UIContext = useA2UIContext(),
16
+ processor = _useA2UIContext.processor,
17
+ surfaceId = _useA2UIContext.surfaceId,
18
+ onAction = _useA2UIContext.onAction;
19
+ return useCallback(function (action, componentId) {
20
+ if (onAction) {
21
+ var context = {
22
+ surfaceId: surfaceId,
23
+ componentId: componentId,
24
+ updateData: function updateData(path, value) {
25
+ processor.updateDataValue(surfaceId, path, value);
26
+ },
27
+ getData: function getData(path) {
28
+ var surface = processor.getSurface(surfaceId);
29
+ if (!surface) return void 0;
30
+ if (!path) return surface.data;
31
+ var segments = path.split("/").filter(Boolean);
32
+ var result = surface.data;
33
+ var _iterator = _createForOfIteratorHelper(segments),
34
+ _step;
35
+ try {
36
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
+ var segment = _step.value;
38
+ if (result === null || result === void 0) return void 0;
39
+ result = result[segment];
40
+ }
41
+ } catch (err) {
42
+ _iterator.e(err);
43
+ } finally {
44
+ _iterator.f();
45
+ }
46
+ return result;
47
+ }
48
+ };
49
+ onAction(action, context);
50
+ } else {
51
+ processor.dispatchAction(action, surfaceId, componentId);
52
+ }
53
+ }, [processor, surfaceId, onAction]);
54
+ }
55
+ function useActionCallback(action, componentId) {
56
+ var dispatch = useA2UIAction();
57
+ return useCallback(function () {
58
+ if (action) {
59
+ dispatch(action, componentId);
60
+ }
61
+ }, [dispatch, action, componentId]);
62
+ }
63
+ function useActionWithPayload(actionName, componentId) {
64
+ var dispatch = useA2UIAction();
65
+ return useCallback(function (context) {
66
+ dispatch({
67
+ name: actionName,
68
+ context: context
69
+ }, componentId);
70
+ }, [dispatch, actionName, componentId]);
71
+ }
72
+
73
+ export { useA2UIAction, useActionCallback, useActionWithPayload };
74
+ //# sourceMappingURL=useA2UIAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useA2UIAction.js","sources":["../../../../../pro-components/chat/chat-engine/hooks/a2ui/useA2UIAction.ts"],"sourcesContent":["/**\n * A2UI Action 相关 Hooks\n */\n\nimport { useCallback } from 'react';\nimport { useA2UIContext } from './A2UIContext';\nimport type { A2UIAction } from '../../core/a2ui';\n\n/**\n * 获取 Action 分发函数\n * \n * @example\n * ```tsx\n * function Button({ action }: { action: A2UIAction }) {\n * const dispatch = useA2UIAction();\n * return <TButton onClick={() => dispatch(action)}>Click</TButton>;\n * }\n * ```\n */\nexport function useA2UIAction(): (action: A2UIAction, componentId?: string) => void {\n const { processor, surfaceId, onAction } = useA2UIContext();\n\n return useCallback(\n (action: A2UIAction, componentId?: string) => {\n // 优先使用外部提供的 onAction\n if (onAction) {\n const context = {\n surfaceId,\n componentId,\n updateData: (path: string, value: unknown) => {\n processor.updateDataValue(surfaceId, path, value);\n },\n getData: (path?: string) => {\n const surface = processor.getSurface(surfaceId);\n if (!surface) return undefined;\n if (!path) return surface.data;\n // 简单路径解析\n const segments = path.split('/').filter(Boolean);\n let result: unknown = surface.data;\n for (const segment of segments) {\n if (result === null || result === undefined) return undefined;\n result = (result as Record<string, unknown>)[segment];\n }\n return result;\n },\n };\n onAction(action, context);\n } else {\n // 使用 processor 内部处理\n processor.dispatchAction(action, surfaceId, componentId);\n }\n },\n [processor, surfaceId, onAction]\n );\n}\n\n/**\n * 创建绑定特定 Action 的回调\n * \n * @example\n * ```tsx\n * function ConfirmButton({ id }: { id: string }) {\n * const handleConfirm = useActionCallback({ name: 'confirm', context: { value: true } }, id);\n * return <TButton onClick={handleConfirm}>确认</TButton>;\n * }\n * ```\n */\nexport function useActionCallback(\n action: A2UIAction | undefined,\n componentId?: string\n): (() => void) | undefined {\n const dispatch = useA2UIAction();\n\n return useCallback(() => {\n if (action) {\n dispatch(action, componentId);\n }\n }, [dispatch, action, componentId]);\n}\n\n/**\n * 创建带参数的 Action 回调\n * \n * @example\n * ```tsx\n * function Input({ id }: { id: string }) {\n * const handleChange = useActionWithPayload('input-change', id);\n * return <TInput onChange={(val) => handleChange({ value: val })} />;\n * }\n * ```\n */\nexport function useActionWithPayload(\n actionName: string,\n componentId?: string\n): (context: Record<string, unknown>) => void {\n const dispatch = useA2UIAction();\n\n return useCallback(\n (context: Record<string, unknown>) => {\n dispatch({ name: actionName, context }, componentId);\n },\n [dispatch, actionName, componentId]\n );\n}\n"],"names":["useA2UIAction","_useA2UIContext","useA2UIContext","processor","surfaceId","onAction","useCallback","action","componentId","context","updateData","path","value","updateDataValue","getData","surface","getSurface","data","segments","split","filter","Boolean","result","_iterator","_createForOfIteratorHelper","_step","s","n","done","segment","err","e","f","dispatchAction","useActionCallback","dispatch","useActionWithPayload","actionName","name"],"mappings":"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"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A2UI Surface 相关 Hooks
3
+ */
4
+ import type { A2uiMessageProcessor } from '../../core/a2ui';
5
+ import type { A2UISurface, ResolvedComponent } from '../../core/a2ui';
6
+ /**
7
+ * 订阅单个 Surface
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const surface = useA2UISurface(processor, 'surface-1');
12
+ * if (!surface) return <Loading />;
13
+ * return <A2UIRenderer root={surface.root} />;
14
+ * ```
15
+ */
16
+ export declare function useA2UISurface(processor: A2uiMessageProcessor, surfaceId: string): A2UISurface | undefined;
17
+ /**
18
+ * 订阅所有 Surface
19
+ */
20
+ export declare function useA2UISurfaces(processor: A2uiMessageProcessor): A2UISurface[];
21
+ /**
22
+ * 订阅 Surface 的组件树根节点
23
+ */
24
+ export declare function useA2UIRoot(processor: A2uiMessageProcessor, surfaceId: string): ResolvedComponent | null;
25
+ /**
26
+ * 订阅 Surface 的数据模型
27
+ */
28
+ export declare function useA2UIData<T = Record<string, unknown>>(processor: A2uiMessageProcessor, surfaceId: string): T | undefined;
29
+ /**
30
+ * 订阅 Surface 状态
31
+ */
32
+ export declare function useA2UISurfaceState(processor: A2uiMessageProcessor, surfaceId: string): 'active' | 'closed' | 'pending' | undefined;
33
+ /**
34
+ * 获取 Surface IDs 列表
35
+ */
36
+ export declare function useA2UISurfaceIds(processor: A2uiMessageProcessor): string[];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * tdesign v1.0.2-alpha.14
3
+ * (c) 2026 tdesign
4
+ * @license MIT
5
+ */
6
+
7
+ import { useSyncExternalStore, useMemo } from 'react';
8
+
9
+ function useA2UISurface(processor, surfaceId) {
10
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
11
+ return snapshot.get(surfaceId);
12
+ }
13
+ function useA2UISurfaces(processor) {
14
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
15
+ return useMemo(function () {
16
+ return Array.from(snapshot.values());
17
+ }, [snapshot]);
18
+ }
19
+ function useA2UIRoot(processor, surfaceId) {
20
+ var surface = useA2UISurface(processor, surfaceId);
21
+ return (surface === null || surface === void 0 ? void 0 : surface.root) || null;
22
+ }
23
+ function useA2UIData(processor, surfaceId) {
24
+ var surface = useA2UISurface(processor, surfaceId);
25
+ return surface === null || surface === void 0 ? void 0 : surface.data;
26
+ }
27
+ function useA2UISurfaceState(processor, surfaceId) {
28
+ var surface = useA2UISurface(processor, surfaceId);
29
+ return surface === null || surface === void 0 ? void 0 : surface.state;
30
+ }
31
+ function useA2UISurfaceIds(processor) {
32
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
33
+ return useMemo(function () {
34
+ return Array.from(snapshot.keys());
35
+ }, [snapshot]);
36
+ }
37
+
38
+ export { useA2UIData, useA2UIRoot, useA2UISurface, useA2UISurfaceIds, useA2UISurfaceState, useA2UISurfaces };
39
+ //# sourceMappingURL=useA2UISurface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useA2UISurface.js","sources":["../../../../../pro-components/chat/chat-engine/hooks/a2ui/useA2UISurface.ts"],"sourcesContent":["/**\n * A2UI Surface 相关 Hooks\n */\n\nimport { useSyncExternalStore, useMemo } from 'react';\nimport type { A2uiMessageProcessor } from '../../core/a2ui';\nimport type { A2UISurface, ResolvedComponent } from '../../core/a2ui';\n\n/**\n * 订阅单个 Surface\n * \n * @example\n * ```tsx\n * const surface = useA2UISurface(processor, 'surface-1');\n * if (!surface) return <Loading />;\n * return <A2UIRenderer root={surface.root} />;\n * ```\n */\nexport function useA2UISurface(\n processor: A2uiMessageProcessor,\n surfaceId: string\n): A2UISurface | undefined {\n const snapshot = useSyncExternalStore(\n processor.subscribe,\n processor.getSnapshot,\n processor.getServerSnapshot\n );\n\n return snapshot.get(surfaceId);\n}\n\n/**\n * 订阅所有 Surface\n */\nexport function useA2UISurfaces(processor: A2uiMessageProcessor): A2UISurface[] {\n const snapshot = useSyncExternalStore(\n processor.subscribe,\n processor.getSnapshot,\n processor.getServerSnapshot\n );\n\n return useMemo(() => Array.from(snapshot.values()), [snapshot]);\n}\n\n/**\n * 订阅 Surface 的组件树根节点\n */\nexport function useA2UIRoot(\n processor: A2uiMessageProcessor,\n surfaceId: string\n): ResolvedComponent | null {\n const surface = useA2UISurface(processor, surfaceId);\n return surface?.root || null;\n}\n\n/**\n * 订阅 Surface 的数据模型\n */\nexport function useA2UIData<T = Record<string, unknown>>(\n processor: A2uiMessageProcessor,\n surfaceId: string\n): T | undefined {\n const surface = useA2UISurface(processor, surfaceId);\n return surface?.data as T | undefined;\n}\n\n/**\n * 订阅 Surface 状态\n */\nexport function useA2UISurfaceState(\n processor: A2uiMessageProcessor,\n surfaceId: string\n): 'active' | 'closed' | 'pending' | undefined {\n const surface = useA2UISurface(processor, surfaceId);\n return surface?.state;\n}\n\n/**\n * 获取 Surface IDs 列表\n */\nexport function useA2UISurfaceIds(processor: A2uiMessageProcessor): string[] {\n const snapshot = useSyncExternalStore(\n processor.subscribe,\n processor.getSnapshot,\n processor.getServerSnapshot\n );\n\n return useMemo(() => Array.from(snapshot.keys()), [snapshot]);\n}\n"],"names":["useA2UISurface","processor","surfaceId","snapshot","useSyncExternalStore","subscribe","getSnapshot","getServerSnapshot","get","useA2UISurfaces","useMemo","Array","from","values","useA2UIRoot","surface","root","useA2UIData","data","useA2UISurfaceState","state","useA2UISurfaceIds","keys"],"mappings":";;;;;;;;AAkBgB,SAAAA,cAAAA,CACdC,WACAC,SACyB,EAAA;AACzB,EAAA,IAAMC,QAAW,GAAAC,oBAAA,CACfH,SAAU,CAAAI,SAAA,EACVJ,SAAU,CAAAK,WAAA,EACVL,SAAU,CAAAM,iBACZ,CAAA,CAAA;AAEO,EAAA,OAAAJ,QAAA,CAASK,IAAIN,SAAS,CAAA,CAAA;AAC/B,CAAA;AAKO,SAASO,gBAAgBR,SAAgD,EAAA;AAC9E,EAAA,IAAME,QAAW,GAAAC,oBAAA,CACfH,SAAU,CAAAI,SAAA,EACVJ,SAAU,CAAAK,WAAA,EACVL,SAAU,CAAAM,iBACZ,CAAA,CAAA;AAEO,EAAA,OAAAG,OAAA,CAAQ,YAAA;IAAA,OAAMC,KAAA,CAAMC,IAAK,CAAAT,QAAA,CAASU,QAAQ,CAAA,CAAA;GAAG,EAAA,CAACV,QAAQ,CAAC,CAAA,CAAA;AAChE,CAAA;AAKgB,SAAAW,WAAAA,CACdb,WACAC,SAC0B,EAAA;AACpB,EAAA,IAAAa,OAAA,GAAUf,cAAe,CAAAC,SAAA,EAAWC,SAAS,CAAA,CAAA;EACnD,OAAO,CAAAa,YAAAA,IAAAA,IAAAA,8BAAAA,QAASC,IAAQ,KAAA,IAAA,CAAA;AAC1B,CAAA;AAKgB,SAAAC,WAAAA,CACdhB,WACAC,SACe,EAAA;AACT,EAAA,IAAAa,OAAA,GAAUf,cAAe,CAAAC,SAAA,EAAWC,SAAS,CAAA,CAAA;AACnD,EAAA,OAAOa,OAAS,KAATA,IAAAA,IAAAA,OAAS,KAATA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAS,CAAAG,IAAA,CAAA;AAClB,CAAA;AAKgB,SAAAC,mBAAAA,CACdlB,WACAC,SAC6C,EAAA;AACvC,EAAA,IAAAa,OAAA,GAAUf,cAAe,CAAAC,SAAA,EAAWC,SAAS,CAAA,CAAA;AACnD,EAAA,OAAOa,OAAS,KAATA,IAAAA,IAAAA,OAAS,KAATA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAS,CAAAK,KAAA,CAAA;AAClB,CAAA;AAKO,SAASC,kBAAkBpB,SAA2C,EAAA;AAC3E,EAAA,IAAME,QAAW,GAAAC,oBAAA,CACfH,SAAU,CAAAI,SAAA,EACVJ,SAAU,CAAAK,WAAA,EACVL,SAAU,CAAAM,iBACZ,CAAA,CAAA;AAEO,EAAA,OAAAG,OAAA,CAAQ,YAAA;IAAA,OAAMC,KAAA,CAAMC,IAAK,CAAAT,QAAA,CAASmB,MAAM,CAAA,CAAA;GAAG,EAAA,CAACnB,QAAQ,CAAC,CAAA,CAAA;AAC9D;;;;"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A2UI 数据绑定 Hooks
3
+ * 实现单向/双向数据绑定
4
+ */
5
+ import type { Bindable } from '../../core/a2ui/types';
6
+ /**
7
+ * 单向数据绑定 Hook
8
+ *
9
+ * 用于读取绑定值:
10
+ * - 如果是字面值,直接返回
11
+ * - 如果是路径绑定,从数据模型读取
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * function Text({ text }: { text: Bindable<string> }) {
16
+ * const resolvedText = useDataBinding(text);
17
+ * return <span>{resolvedText}</span>;
18
+ * }
19
+ * ```
20
+ */
21
+ export declare function useDataBinding<T>(value: Bindable<T>): T;
22
+ export declare function useDataBinding<T>(value: Bindable<T> | undefined): T | undefined;
23
+ /**
24
+ * 双向数据绑定 Hook
25
+ *
26
+ * 用于表单控件的双向绑定:
27
+ * - 读取:从数据模型获取当前值
28
+ * - 写入:更新数据模型
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * function TextField({ text }: { text: Bindable<string> }) {
33
+ * const [inputValue, setInputValue] = useTwoWayBinding(text, '');
34
+ * return <Input value={inputValue} onChange={setInputValue} />;
35
+ * }
36
+ * ```
37
+ */
38
+ export declare function useTwoWayBinding<T>(value: Bindable<T> | undefined, defaultValue: T): [T, (newValue: T) => void];
39
+ /**
40
+ * 获取路径绑定的完整路径
41
+ */
42
+ export declare function useBindingPath(value: Bindable<unknown> | undefined): string | null;
43
+ /**
44
+ * 批量解析绑定值
45
+ */
46
+ export declare function useDataBindings<T extends Record<string, Bindable<unknown>>>(bindings: T): {
47
+ [K in keyof T]: T[K] extends Bindable<infer V> ? V : never;
48
+ };
49
+ /**
50
+ * 解析字符串中的绑定占位符
51
+ * 支持模板字符串格式: "Hello, {{/user/name}}!"
52
+ */
53
+ export declare function useResolvedString(template: string | undefined): string;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * tdesign v1.0.2-alpha.14
3
+ * (c) 2026 tdesign
4
+ * @license MIT
5
+ */
6
+
7
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
8
+ import { useSyncExternalStore, useMemo, useCallback } from 'react';
9
+ import { useA2UIContext } from './A2UIContext.js';
10
+ import '../../core/a2ui/utils/index.js';
11
+ import { resolveBinding, isPathBinding } from '../../core/a2ui/utils/binding.js';
12
+ import '@babel/runtime/helpers/defineProperty';
13
+ import '../../core/a2ui/utils/validation.js';
14
+ import '@babel/runtime/helpers/toConsumableArray';
15
+ import '@babel/runtime/helpers/typeof';
16
+
17
+ function useDataBinding(value) {
18
+ var _useA2UIContext = useA2UIContext(),
19
+ processor = _useA2UIContext.processor,
20
+ surfaceId = _useA2UIContext.surfaceId,
21
+ dataContextPath = _useA2UIContext.dataContextPath;
22
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
23
+ var surface = snapshot.get(surfaceId);
24
+ var data = (surface === null || surface === void 0 ? void 0 : surface.data) || {};
25
+ return useMemo(function () {
26
+ if (value === void 0) return void 0;
27
+ return resolveBinding(value, data, dataContextPath);
28
+ }, [value, data, dataContextPath]);
29
+ }
30
+ function useTwoWayBinding(value, defaultValue) {
31
+ var _useA2UIContext2 = useA2UIContext(),
32
+ processor = _useA2UIContext2.processor,
33
+ surfaceId = _useA2UIContext2.surfaceId,
34
+ dataContextPath = _useA2UIContext2.dataContextPath;
35
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
36
+ var surface = snapshot.get(surfaceId);
37
+ var data = (surface === null || surface === void 0 ? void 0 : surface.data) || {};
38
+ var currentValue = useMemo(function () {
39
+ if (value === void 0) return defaultValue;
40
+ var resolved = resolveBinding(value, data, dataContextPath);
41
+ return resolved !== void 0 ? resolved : defaultValue;
42
+ }, [value, data, dataContextPath, defaultValue]);
43
+ var fullPath = useMemo(function () {
44
+ if (!isPathBinding(value)) return null;
45
+ var path = value.path;
46
+ if (path.startsWith("/")) return path;
47
+ if (!dataContextPath || dataContextPath === "/") {
48
+ return "/".concat(path);
49
+ }
50
+ return "".concat(dataContextPath, "/").concat(path).replace(/\/+/g, "/");
51
+ }, [value, dataContextPath]);
52
+ var setValue = useCallback(function (newValue) {
53
+ if (fullPath) {
54
+ processor.setData(surfaceId, fullPath, "", newValue);
55
+ }
56
+ }, [processor, surfaceId, fullPath]);
57
+ return [currentValue, setValue];
58
+ }
59
+ function useBindingPath(value) {
60
+ var _useA2UIContext3 = useA2UIContext(),
61
+ dataContextPath = _useA2UIContext3.dataContextPath;
62
+ return useMemo(function () {
63
+ if (!isPathBinding(value)) return null;
64
+ var path = value.path;
65
+ if (path.startsWith("/")) return path;
66
+ if (!dataContextPath || dataContextPath === "/") {
67
+ return "/".concat(path);
68
+ }
69
+ return "".concat(dataContextPath, "/").concat(path).replace(/\/+/g, "/");
70
+ }, [value, dataContextPath]);
71
+ }
72
+ function useDataBindings(bindings) {
73
+ var _useA2UIContext4 = useA2UIContext(),
74
+ processor = _useA2UIContext4.processor,
75
+ surfaceId = _useA2UIContext4.surfaceId,
76
+ dataContextPath = _useA2UIContext4.dataContextPath;
77
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
78
+ var surface = snapshot.get(surfaceId);
79
+ var data = (surface === null || surface === void 0 ? void 0 : surface.data) || {};
80
+ return useMemo(function () {
81
+ var result = {};
82
+ for (var _i = 0, _Object$entries = Object.entries(bindings); _i < _Object$entries.length; _i++) {
83
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
84
+ key = _Object$entries$_i[0],
85
+ value = _Object$entries$_i[1];
86
+ result[key] = resolveBinding(value, data, dataContextPath);
87
+ }
88
+ return result;
89
+ }, [bindings, data, dataContextPath]);
90
+ }
91
+ function useResolvedString(template) {
92
+ var _useA2UIContext5 = useA2UIContext(),
93
+ processor = _useA2UIContext5.processor,
94
+ surfaceId = _useA2UIContext5.surfaceId,
95
+ dataContextPath = _useA2UIContext5.dataContextPath;
96
+ var snapshot = useSyncExternalStore(processor.subscribe, processor.getSnapshot, processor.getServerSnapshot);
97
+ var surface = snapshot.get(surfaceId);
98
+ var data = (surface === null || surface === void 0 ? void 0 : surface.data) || {};
99
+ return useMemo(function () {
100
+ if (!template) return "";
101
+ return template.replace(/\{\{([^}]+)\}\}/g, function (_, path) {
102
+ var value = resolveBinding({
103
+ path: path.trim()
104
+ }, data, dataContextPath);
105
+ return value !== void 0 ? String(value) : "";
106
+ });
107
+ }, [template, data, dataContextPath]);
108
+ }
109
+
110
+ export { useBindingPath, useDataBinding, useDataBindings, useResolvedString, useTwoWayBinding };
111
+ //# sourceMappingURL=useDataBinding.js.map