@datalayer/agent-runtimes 0.0.2

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 (571) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +56 -0
  3. package/lib/App.css +47 -0
  4. package/lib/App.d.ts +3 -0
  5. package/lib/App.js +18 -0
  6. package/lib/components/chat/components/AgentDetails.d.ts +19 -0
  7. package/lib/components/chat/components/AgentDetails.js +170 -0
  8. package/lib/components/chat/components/Chat.d.ts +105 -0
  9. package/lib/components/chat/components/Chat.js +275 -0
  10. package/lib/components/chat/components/ChatFloating.d.ts +146 -0
  11. package/lib/components/chat/components/ChatFloating.js +381 -0
  12. package/lib/components/chat/components/ChatInline.d.ts +42 -0
  13. package/lib/components/chat/components/ChatInline.js +327 -0
  14. package/lib/components/chat/components/ChatPopupStandalone.d.ts +110 -0
  15. package/lib/components/chat/components/ChatPopupStandalone.js +422 -0
  16. package/lib/components/chat/components/ChatSidebar.d.ts +78 -0
  17. package/lib/components/chat/components/ChatSidebar.js +224 -0
  18. package/lib/components/chat/components/ChatStandalone.d.ts +105 -0
  19. package/lib/components/chat/components/ChatStandalone.js +320 -0
  20. package/lib/components/chat/components/base/ChatBase.d.ts +285 -0
  21. package/lib/components/chat/components/base/ChatBase.js +1192 -0
  22. package/lib/components/chat/components/display/ToolCallDisplay.d.ts +26 -0
  23. package/lib/components/chat/components/display/ToolCallDisplay.js +225 -0
  24. package/lib/components/chat/components/display/index.d.ts +6 -0
  25. package/lib/components/chat/components/display/index.js +10 -0
  26. package/lib/components/chat/components/elements/ChatHeader.d.ts +43 -0
  27. package/lib/components/chat/components/elements/ChatHeader.js +67 -0
  28. package/lib/components/chat/components/elements/ChatInputPrompt.d.ts +26 -0
  29. package/lib/components/chat/components/elements/ChatInputPrompt.js +145 -0
  30. package/lib/components/chat/components/elements/ChatMessages.d.ts +36 -0
  31. package/lib/components/chat/components/elements/ChatMessages.js +195 -0
  32. package/lib/components/chat/components/elements/FloatingBrandButton.d.ts +34 -0
  33. package/lib/components/chat/components/elements/FloatingBrandButton.js +88 -0
  34. package/lib/components/chat/components/elements/MessagePart.d.ts +50 -0
  35. package/lib/components/chat/components/elements/MessagePart.js +48 -0
  36. package/lib/components/chat/components/elements/PoweredByTag.d.ts +26 -0
  37. package/lib/components/chat/components/elements/PoweredByTag.js +33 -0
  38. package/lib/components/chat/components/elements/ToolApprovalDialog.d.ts +42 -0
  39. package/lib/components/chat/components/elements/ToolApprovalDialog.js +96 -0
  40. package/lib/components/chat/components/index.d.ts +21 -0
  41. package/lib/components/chat/components/index.js +34 -0
  42. package/lib/components/chat/components/parts/DynamicToolPart.d.ts +20 -0
  43. package/lib/components/chat/components/parts/DynamicToolPart.js +13 -0
  44. package/lib/components/chat/components/parts/ReasoningPart.d.ts +17 -0
  45. package/lib/components/chat/components/parts/ReasoningPart.js +69 -0
  46. package/lib/components/chat/components/parts/TextPart.d.ts +28 -0
  47. package/lib/components/chat/components/parts/TextPart.js +103 -0
  48. package/lib/components/chat/components/parts/ToolPart.d.ts +17 -0
  49. package/lib/components/chat/components/parts/ToolPart.js +163 -0
  50. package/lib/components/chat/components/parts/index.d.ts +9 -0
  51. package/lib/components/chat/components/parts/index.js +13 -0
  52. package/lib/components/chat/extensions/A2UIExtension.d.ts +87 -0
  53. package/lib/components/chat/extensions/A2UIExtension.js +312 -0
  54. package/lib/components/chat/extensions/ExtensionRegistry.d.ts +66 -0
  55. package/lib/components/chat/extensions/ExtensionRegistry.js +128 -0
  56. package/lib/components/chat/extensions/MCPUIExtension.d.ts +77 -0
  57. package/lib/components/chat/extensions/MCPUIExtension.js +212 -0
  58. package/lib/components/chat/extensions/index.d.ts +9 -0
  59. package/lib/components/chat/extensions/index.js +12 -0
  60. package/lib/components/chat/handler.d.ts +20 -0
  61. package/lib/components/chat/handler.js +56 -0
  62. package/lib/components/chat/index.d.ts +61 -0
  63. package/lib/components/chat/index.js +76 -0
  64. package/lib/components/chat/inference/BaseInferenceProvider.d.ts +57 -0
  65. package/lib/components/chat/inference/BaseInferenceProvider.js +69 -0
  66. package/lib/components/chat/inference/DatalayerInferenceProvider.d.ts +83 -0
  67. package/lib/components/chat/inference/DatalayerInferenceProvider.js +305 -0
  68. package/lib/components/chat/inference/SelfHostedInferenceProvider.d.ts +54 -0
  69. package/lib/components/chat/inference/SelfHostedInferenceProvider.js +246 -0
  70. package/lib/components/chat/inference/index.d.ts +9 -0
  71. package/lib/components/chat/inference/index.js +12 -0
  72. package/lib/components/chat/middleware/MiddlewarePipeline.d.ts +118 -0
  73. package/lib/components/chat/middleware/MiddlewarePipeline.js +255 -0
  74. package/lib/components/chat/middleware/index.d.ts +7 -0
  75. package/lib/components/chat/middleware/index.js +10 -0
  76. package/lib/components/chat/protocols/A2AAdapter.d.ts +79 -0
  77. package/lib/components/chat/protocols/A2AAdapter.js +388 -0
  78. package/lib/components/chat/protocols/ACPAdapter.d.ts +161 -0
  79. package/lib/components/chat/protocols/ACPAdapter.js +504 -0
  80. package/lib/components/chat/protocols/AGUIAdapter.d.ts +82 -0
  81. package/lib/components/chat/protocols/AGUIAdapter.js +518 -0
  82. package/lib/components/chat/protocols/BaseProtocolAdapter.d.ts +75 -0
  83. package/lib/components/chat/protocols/BaseProtocolAdapter.js +119 -0
  84. package/lib/components/chat/protocols/VercelAIAdapter.d.ts +77 -0
  85. package/lib/components/chat/protocols/VercelAIAdapter.js +252 -0
  86. package/lib/components/chat/protocols/index.d.ts +11 -0
  87. package/lib/components/chat/protocols/index.js +14 -0
  88. package/lib/components/chat/store/chatStore.d.ts +158 -0
  89. package/lib/components/chat/store/chatStore.js +313 -0
  90. package/lib/components/chat/store/index.d.ts +6 -0
  91. package/lib/components/chat/store/index.js +10 -0
  92. package/lib/components/chat/tools/ToolExecutor.d.ts +49 -0
  93. package/lib/components/chat/tools/ToolExecutor.js +151 -0
  94. package/lib/components/chat/tools/index.d.ts +8 -0
  95. package/lib/components/chat/tools/index.js +11 -0
  96. package/lib/components/chat/types/extension.d.ts +181 -0
  97. package/lib/components/chat/types/extension.js +46 -0
  98. package/lib/components/chat/types/index.d.ts +11 -0
  99. package/lib/components/chat/types/index.js +16 -0
  100. package/lib/components/chat/types/inference.d.ts +117 -0
  101. package/lib/components/chat/types/inference.js +5 -0
  102. package/lib/components/chat/types/message.d.ts +117 -0
  103. package/lib/components/chat/types/message.js +50 -0
  104. package/lib/components/chat/types/middleware.d.ts +153 -0
  105. package/lib/components/chat/types/middleware.js +32 -0
  106. package/lib/components/chat/types/protocol.d.ts +209 -0
  107. package/lib/components/chat/types/protocol.js +5 -0
  108. package/lib/components/chat/types/tool.d.ts +140 -0
  109. package/lib/components/chat/types/tool.js +23 -0
  110. package/lib/components/index.d.ts +1 -0
  111. package/lib/components/index.js +6 -0
  112. package/lib/components/sparklines/Sparklines.d.ts +16 -0
  113. package/lib/components/sparklines/Sparklines.js +65 -0
  114. package/lib/components/sparklines/SparklinesLine.d.ts +8 -0
  115. package/lib/components/sparklines/SparklinesLine.js +37 -0
  116. package/lib/components/sparklines/dataProcessing.d.ts +25 -0
  117. package/lib/components/sparklines/dataProcessing.js +35 -0
  118. package/lib/components/sparklines/index.d.ts +4 -0
  119. package/lib/components/sparklines/index.js +7 -0
  120. package/lib/components/sparklines/types.d.ts +36 -0
  121. package/lib/components/sparklines/types.js +5 -0
  122. package/lib/components/ui/accordion.d.ts +7 -0
  123. package/lib/components/ui/accordion.js +22 -0
  124. package/lib/components/ui/alert-dialog.d.ts +14 -0
  125. package/lib/components/ui/alert-dialog.js +43 -0
  126. package/lib/components/ui/alert.d.ts +9 -0
  127. package/lib/components/ui/alert.js +24 -0
  128. package/lib/components/ui/aspect-ratio.d.ts +3 -0
  129. package/lib/components/ui/aspect-ratio.js +11 -0
  130. package/lib/components/ui/avatar.d.ts +6 -0
  131. package/lib/components/ui/avatar.js +18 -0
  132. package/lib/components/ui/badge.d.ts +9 -0
  133. package/lib/components/ui/badge.js +22 -0
  134. package/lib/components/ui/breadcrumb.d.ts +11 -0
  135. package/lib/components/ui/breadcrumb.js +27 -0
  136. package/lib/components/ui/button-group.d.ts +11 -0
  137. package/lib/components/ui/button-group.js +31 -0
  138. package/lib/components/ui/button.d.ts +13 -0
  139. package/lib/components/ui/button.js +39 -0
  140. package/lib/components/ui/calendar.d.ts +8 -0
  141. package/lib/components/ui/calendar.js +80 -0
  142. package/lib/components/ui/card.d.ts +9 -0
  143. package/lib/components/ui/card.js +24 -0
  144. package/lib/components/ui/carousel.d.ts +19 -0
  145. package/lib/components/ui/carousel.js +95 -0
  146. package/lib/components/ui/chart.d.ts +53 -0
  147. package/lib/components/ui/chart.js +136 -0
  148. package/lib/components/ui/checkbox.d.ts +4 -0
  149. package/lib/components/ui/checkbox.js +13 -0
  150. package/lib/components/ui/collapsible.d.ts +5 -0
  151. package/lib/components/ui/collapsible.js +17 -0
  152. package/lib/components/ui/command.d.ts +18 -0
  153. package/lib/components/ui/command.js +38 -0
  154. package/lib/components/ui/context-menu.d.ts +25 -0
  155. package/lib/components/ui/context-menu.js +55 -0
  156. package/lib/components/ui/dialog.d.ts +15 -0
  157. package/lib/components/ui/dialog.js +40 -0
  158. package/lib/components/ui/drawer.d.ts +13 -0
  159. package/lib/components/ui/drawer.js +39 -0
  160. package/lib/components/ui/dropdown-menu.d.ts +25 -0
  161. package/lib/components/ui/dropdown-menu.js +55 -0
  162. package/lib/components/ui/empty.d.ts +11 -0
  163. package/lib/components/ui/empty.js +37 -0
  164. package/lib/components/ui/field.d.ts +24 -0
  165. package/lib/components/ui/field.js +80 -0
  166. package/lib/components/ui/form.d.ts +24 -0
  167. package/lib/components/ui/form.js +63 -0
  168. package/lib/components/ui/hover-card.d.ts +6 -0
  169. package/lib/components/ui/hover-card.js +18 -0
  170. package/lib/components/ui/input-group.d.ts +19 -0
  171. package/lib/components/ui/input-group.js +69 -0
  172. package/lib/components/ui/input-otp.d.ts +11 -0
  173. package/lib/components/ui/input-otp.js +25 -0
  174. package/lib/components/ui/input.d.ts +3 -0
  175. package/lib/components/ui/input.js +6 -0
  176. package/lib/components/ui/item.d.ts +23 -0
  177. package/lib/components/ui/item.js +66 -0
  178. package/lib/components/ui/kbd.d.ts +3 -0
  179. package/lib/components/ui/kbd.js +13 -0
  180. package/lib/components/ui/label.d.ts +4 -0
  181. package/lib/components/ui/label.js +12 -0
  182. package/lib/components/ui/menubar.d.ts +26 -0
  183. package/lib/components/ui/menubar.js +58 -0
  184. package/lib/components/ui/navigation-menu.d.ts +14 -0
  185. package/lib/components/ui/navigation-menu.js +31 -0
  186. package/lib/components/ui/pagination.d.ts +13 -0
  187. package/lib/components/ui/pagination.js +29 -0
  188. package/lib/components/ui/popover.d.ts +7 -0
  189. package/lib/components/ui/popover.js +21 -0
  190. package/lib/components/ui/progress.d.ts +4 -0
  191. package/lib/components/ui/progress.js +12 -0
  192. package/lib/components/ui/radio-group.d.ts +5 -0
  193. package/lib/components/ui/radio-group.js +16 -0
  194. package/lib/components/ui/resizable.d.ts +8 -0
  195. package/lib/components/ui/resizable.js +19 -0
  196. package/lib/components/ui/scroll-area.d.ts +5 -0
  197. package/lib/components/ui/scroll-area.js +17 -0
  198. package/lib/components/ui/select.d.ts +15 -0
  199. package/lib/components/ui/select.js +42 -0
  200. package/lib/components/ui/separator.d.ts +4 -0
  201. package/lib/components/ui/separator.js +12 -0
  202. package/lib/components/ui/sheet.d.ts +13 -0
  203. package/lib/components/ui/sheet.js +44 -0
  204. package/lib/components/ui/sidebar.d.ts +69 -0
  205. package/lib/components/ui/sidebar.js +216 -0
  206. package/lib/components/ui/skeleton.d.ts +2 -0
  207. package/lib/components/ui/skeleton.js +10 -0
  208. package/lib/components/ui/slider.d.ts +4 -0
  209. package/lib/components/ui/slider.js +18 -0
  210. package/lib/components/ui/sonner.d.ts +3 -0
  211. package/lib/components/ui/sonner.js +25 -0
  212. package/lib/components/ui/spinner.d.ts +2 -0
  213. package/lib/components/ui/spinner.js +11 -0
  214. package/lib/components/ui/switch.d.ts +4 -0
  215. package/lib/components/ui/switch.js +12 -0
  216. package/lib/components/ui/table.d.ts +10 -0
  217. package/lib/components/ui/table.js +32 -0
  218. package/lib/components/ui/tabs.d.ts +7 -0
  219. package/lib/components/ui/tabs.js +21 -0
  220. package/lib/components/ui/textarea.d.ts +3 -0
  221. package/lib/components/ui/textarea.js +6 -0
  222. package/lib/components/ui/toast.d.ts +15 -0
  223. package/lib/components/ui/toast.js +38 -0
  224. package/lib/components/ui/toaster.d.ts +1 -0
  225. package/lib/components/ui/toaster.js +14 -0
  226. package/lib/components/ui/toggle-group.d.ts +9 -0
  227. package/lib/components/ui/toggle-group.js +26 -0
  228. package/lib/components/ui/toggle.d.ts +9 -0
  229. package/lib/components/ui/toggle.js +30 -0
  230. package/lib/components/ui/tooltip.d.ts +7 -0
  231. package/lib/components/ui/tooltip.js +21 -0
  232. package/lib/components/vercel-ai-elements/artifact.d.ts +23 -0
  233. package/lib/components/vercel-ai-elements/artifact.js +24 -0
  234. package/lib/components/vercel-ai-elements/code-block.d.ts +17 -0
  235. package/lib/components/vercel-ai-elements/code-block.js +94 -0
  236. package/lib/components/vercel-ai-elements/conversation.d.ts +15 -0
  237. package/lib/components/vercel-ai-elements/conversation.js +21 -0
  238. package/lib/components/vercel-ai-elements/loader.d.ts +5 -0
  239. package/lib/components/vercel-ai-elements/loader.js +8 -0
  240. package/lib/components/vercel-ai-elements/message.d.ts +46 -0
  241. package/lib/components/vercel-ai-elements/message.js +109 -0
  242. package/lib/components/vercel-ai-elements/model-selector.d.ts +35 -0
  243. package/lib/components/vercel-ai-elements/model-selector.js +22 -0
  244. package/lib/components/vercel-ai-elements/prompt-input.d.ts +195 -0
  245. package/lib/components/vercel-ai-elements/prompt-input.js +589 -0
  246. package/lib/components/vercel-ai-elements/reasoning.d.ts +26 -0
  247. package/lib/components/vercel-ai-elements/reasoning.js +80 -0
  248. package/lib/components/vercel-ai-elements/shimmer.d.ts +9 -0
  249. package/lib/components/vercel-ai-elements/shimmer.js +22 -0
  250. package/lib/components/vercel-ai-elements/sources.d.ts +12 -0
  251. package/lib/components/vercel-ai-elements/sources.js +13 -0
  252. package/lib/components/vercel-ai-elements/suggestion.d.ts +10 -0
  253. package/lib/components/vercel-ai-elements/suggestion.js +16 -0
  254. package/lib/components/vercel-ai-elements/tool.d.ts +23 -0
  255. package/lib/components/vercel-ai-elements/tool.js +52 -0
  256. package/lib/examples/A2UiRestaurantExample.d.ts +25 -0
  257. package/lib/examples/A2UiRestaurantExample.js +305 -0
  258. package/lib/examples/AgUiAgenticExample.d.ts +25 -0
  259. package/lib/examples/AgUiAgenticExample.js +63 -0
  260. package/lib/examples/AgUiBackendToolRenderingExample.d.ts +30 -0
  261. package/lib/examples/AgUiBackendToolRenderingExample.js +103 -0
  262. package/lib/examples/AgUiHaikuGenUIExample.d.ts +44 -0
  263. package/lib/examples/AgUiHaikuGenUIExample.js +151 -0
  264. package/lib/examples/AgUiHumanInTheLoopExample.d.ts +26 -0
  265. package/lib/examples/AgUiHumanInTheLoopExample.js +220 -0
  266. package/lib/examples/AgUiSharedStateExample.d.ts +25 -0
  267. package/lib/examples/AgUiSharedStateExample.js +181 -0
  268. package/lib/examples/AgUiToolsBasedGenUIExample.d.ts +25 -0
  269. package/lib/examples/AgUiToolsBasedGenUIExample.js +257 -0
  270. package/lib/examples/AgentRuntimeCustomExample.d.ts +9 -0
  271. package/lib/examples/AgentRuntimeCustomExample.js +68 -0
  272. package/lib/examples/AgentRuntimeLexical2Example.d.ts +42 -0
  273. package/lib/examples/AgentRuntimeLexical2Example.js +236 -0
  274. package/lib/examples/AgentRuntimeLexicalExample.d.ts +36 -0
  275. package/lib/examples/AgentRuntimeLexicalExample.js +260 -0
  276. package/lib/examples/AgentRuntimeLexicalSidebarExample.d.ts +41 -0
  277. package/lib/examples/AgentRuntimeLexicalSidebarExample.js +166 -0
  278. package/lib/examples/AgentRuntimeNotebookExample.d.ts +9 -0
  279. package/lib/examples/AgentRuntimeNotebookExample.js +148 -0
  280. package/lib/examples/AgentRuntimeNotebookSidebarExample.d.ts +13 -0
  281. package/lib/examples/AgentRuntimeNotebookSidebarExample.js +121 -0
  282. package/lib/examples/AgentRuntimeStandaloneExample.d.ts +21 -0
  283. package/lib/examples/AgentRuntimeStandaloneExample.js +158 -0
  284. package/lib/examples/AgentSpaceFormExample.d.ts +22 -0
  285. package/lib/examples/AgentSpaceFormExample.js +296 -0
  286. package/lib/examples/AgentSpaceHomeExample.d.ts +8 -0
  287. package/lib/examples/AgentSpaceHomeExample.js +171 -0
  288. package/lib/examples/CopilotKitLexicalExample.d.ts +38 -0
  289. package/lib/examples/CopilotKitLexicalExample.js +161 -0
  290. package/lib/examples/CopilotKitNotebookExample.d.ts +11 -0
  291. package/lib/examples/CopilotKitNotebookExample.js +70 -0
  292. package/lib/examples/DatalayerNotebookExample.d.ts +16 -0
  293. package/lib/examples/DatalayerNotebookExample.js +99 -0
  294. package/lib/examples/JupyterCellExample.d.ts +6 -0
  295. package/lib/examples/JupyterCellExample.js +19 -0
  296. package/lib/examples/JupyterNotebookExample.d.ts +6 -0
  297. package/lib/examples/JupyterNotebookExample.js +21 -0
  298. package/lib/examples/ag-ui/haiku/HaikuDisplay.d.ts +18 -0
  299. package/lib/examples/ag-ui/haiku/HaikuDisplay.js +110 -0
  300. package/lib/examples/ag-ui/haiku/InlineHaikuCard.d.ts +39 -0
  301. package/lib/examples/ag-ui/haiku/InlineHaikuCard.js +117 -0
  302. package/lib/examples/ag-ui/haiku/index.d.ts +11 -0
  303. package/lib/examples/ag-ui/haiku/index.js +15 -0
  304. package/lib/examples/ag-ui/index.d.ts +10 -0
  305. package/lib/examples/ag-ui/index.js +16 -0
  306. package/lib/examples/ag-ui/weather/InlineWeatherCard.d.ts +43 -0
  307. package/lib/examples/ag-ui/weather/InlineWeatherCard.js +180 -0
  308. package/lib/examples/ag-ui/weather/index.d.ts +9 -0
  309. package/lib/examples/ag-ui/weather/index.js +13 -0
  310. package/lib/examples/components/AgentConfiguration.d.ts +50 -0
  311. package/lib/examples/components/AgentConfiguration.js +115 -0
  312. package/lib/examples/components/AgentsDataTable.d.ts +13 -0
  313. package/lib/examples/components/AgentsDataTable.js +74 -0
  314. package/lib/examples/components/FooterMetrics.d.ts +12 -0
  315. package/lib/examples/components/FooterMetrics.js +17 -0
  316. package/lib/examples/components/Header.d.ts +27 -0
  317. package/lib/examples/components/Header.js +294 -0
  318. package/lib/examples/components/HeaderControls.d.ts +11 -0
  319. package/lib/examples/components/HeaderControls.js +24 -0
  320. package/lib/examples/components/LexicalEditor.d.ts +27 -0
  321. package/lib/examples/components/LexicalEditor.js +118 -0
  322. package/lib/examples/components/MainContent.d.ts +19 -0
  323. package/lib/examples/components/MainContent.js +68 -0
  324. package/lib/examples/components/MockFileBrowser.d.ts +12 -0
  325. package/lib/examples/components/MockFileBrowser.js +131 -0
  326. package/lib/examples/components/Rating.d.ts +14 -0
  327. package/lib/examples/components/Rating.js +12 -0
  328. package/lib/examples/components/SessionTabs.d.ts +21 -0
  329. package/lib/examples/components/SessionTabs.js +11 -0
  330. package/lib/examples/components/TimeTravel.d.ts +15 -0
  331. package/lib/examples/components/TimeTravel.js +23 -0
  332. package/lib/examples/components/index.d.ts +11 -0
  333. package/lib/examples/components/index.js +14 -0
  334. package/lib/examples/example-selector.d.ts +22 -0
  335. package/lib/examples/example-selector.js +62 -0
  336. package/lib/examples/index.d.ts +21 -0
  337. package/lib/examples/index.js +25 -0
  338. package/lib/examples/lexical/editorConfig.d.ts +76 -0
  339. package/lib/examples/lexical/editorConfig.js +55 -0
  340. package/lib/examples/lexical/lexical-theme.css +436 -0
  341. package/lib/examples/lexical/theme.d.ts +61 -0
  342. package/lib/examples/lexical/theme.js +72 -0
  343. package/lib/examples/main.d.ts +2 -0
  344. package/lib/examples/main.js +334 -0
  345. package/lib/examples/stores/agents/earthquake-detector.ipynb.json +111 -0
  346. package/lib/examples/stores/agents/earthquake-detector.json +13 -0
  347. package/lib/examples/stores/agents/earthquake-detector.lexical.json +2988 -0
  348. package/lib/examples/stores/agents/sales-forecaster.ipynb.json +111 -0
  349. package/lib/examples/stores/agents/sales-forecaster.json +13 -0
  350. package/lib/examples/stores/agents/sales-forecaster.lexical.json +2988 -0
  351. package/lib/examples/stores/agents/social-post-generator.ipynb.json +111 -0
  352. package/lib/examples/stores/agents/social-post-generator.json +13 -0
  353. package/lib/examples/stores/agents/social-post-generator.lexical.json +2988 -0
  354. package/lib/examples/stores/agents/stock-market.ipynb.json +56 -0
  355. package/lib/examples/stores/agents/stock-market.json +13 -0
  356. package/lib/examples/stores/agents/stock-market.lexical.json +1026 -0
  357. package/lib/examples/stores/examplesStore.d.ts +26 -0
  358. package/lib/examples/stores/examplesStore.js +60 -0
  359. package/lib/examples/stores/notebooks/Empty.ipynb.json +33 -0
  360. package/lib/examples/stores/notebooks/IPyWidgetsExample.ipynb.json +101 -0
  361. package/lib/examples/stores/notebooks/IPyWidgetsExampleWithState.ipynb.json +112 -0
  362. package/lib/examples/stores/notebooks/Lite.ipynb.json +128 -0
  363. package/lib/examples/stores/notebooks/Matplotlib.ipynb.json +137 -0
  364. package/lib/examples/stores/notebooks/NotebookExample1.ipynb.json +126 -0
  365. package/lib/examples/stores/notebooks/NotebookExample2.ipynb.json +48 -0
  366. package/lib/examples/stores/notebooks/NotebookOutputs.ipynb.json +49 -0
  367. package/lib/examples/stores/notebooks/NotebookToCExample.ipynb.json +102 -0
  368. package/lib/examples/stores/notebooks/OutputIPyWidgetsExample.d.ts +145 -0
  369. package/lib/examples/stores/notebooks/OutputIPyWidgetsExample.js +153 -0
  370. package/lib/examples/stores/notebooks/PyGWalker.ipynb.json +55 -0
  371. package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.d.ts +12 -0
  372. package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.js +69 -0
  373. package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.d.ts +1 -0
  374. package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.js +85 -0
  375. package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.d.ts +1 -0
  376. package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.js +62 -0
  377. package/lib/examples/vercel-ai-elements/components/ConversationShowcase.d.ts +1 -0
  378. package/lib/examples/vercel-ai-elements/components/ConversationShowcase.js +51 -0
  379. package/lib/examples/vercel-ai-elements/components/LoaderShowcase.d.ts +1 -0
  380. package/lib/examples/vercel-ai-elements/components/LoaderShowcase.js +9 -0
  381. package/lib/examples/vercel-ai-elements/components/MessageShowcase.d.ts +1 -0
  382. package/lib/examples/vercel-ai-elements/components/MessageShowcase.js +56 -0
  383. package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.d.ts +1 -0
  384. package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.js +50 -0
  385. package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.d.ts +1 -0
  386. package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.js +16 -0
  387. package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.d.ts +1 -0
  388. package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.js +72 -0
  389. package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.d.ts +1 -0
  390. package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.js +9 -0
  391. package/lib/examples/vercel-ai-elements/components/SourcesShowcase.d.ts +1 -0
  392. package/lib/examples/vercel-ai-elements/components/SourcesShowcase.js +43 -0
  393. package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.d.ts +1 -0
  394. package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.js +31 -0
  395. package/lib/examples/vercel-ai-elements/components/ToolShowcase.d.ts +1 -0
  396. package/lib/examples/vercel-ai-elements/components/ToolShowcase.js +54 -0
  397. package/lib/examples/vercel-ai-elements/index.d.ts +13 -0
  398. package/lib/examples/vercel-ai-elements/index.js +17 -0
  399. package/lib/examples/vercel-ai-elements/main.d.ts +1 -0
  400. package/lib/examples/vercel-ai-elements/main.js +9 -0
  401. package/lib/examples/vercel-ai-elements/showcase.css +128 -0
  402. package/lib/hooks/index.d.ts +68 -0
  403. package/lib/hooks/index.js +81 -0
  404. package/lib/hooks/useA2A.d.ts +75 -0
  405. package/lib/hooks/useA2A.js +368 -0
  406. package/lib/hooks/useAGUI.d.ts +63 -0
  407. package/lib/hooks/useAGUI.js +162 -0
  408. package/lib/hooks/useAcp.d.ts +121 -0
  409. package/lib/hooks/useAcp.js +459 -0
  410. package/lib/hooks/useAgents.d.ts +13 -0
  411. package/lib/hooks/useAgents.js +71 -0
  412. package/lib/hooks/useChat.d.ts +62 -0
  413. package/lib/hooks/useChat.js +363 -0
  414. package/lib/hooks/useKeyboardShortcuts.d.ts +47 -0
  415. package/lib/hooks/useKeyboardShortcuts.js +153 -0
  416. package/lib/hooks/useMobile.d.ts +1 -0
  417. package/lib/hooks/useMobile.js +19 -0
  418. package/lib/hooks/useNotebookAIAgent.d.ts +8 -0
  419. package/lib/hooks/useNotebookAIAgent.js +56 -0
  420. package/lib/hooks/useToast.d.ts +44 -0
  421. package/lib/hooks/useToast.js +128 -0
  422. package/lib/hooks/useTools.d.ts +107 -0
  423. package/lib/hooks/useTools.js +130 -0
  424. package/lib/hooks/useVercelChat.d.ts +45 -0
  425. package/lib/hooks/useVercelChat.js +62 -0
  426. package/lib/index.css +73 -0
  427. package/lib/index.d.ts +1 -0
  428. package/lib/index.js +5 -0
  429. package/lib/lexical/ChatInlinePlugin.d.ts +21 -0
  430. package/lib/lexical/ChatInlinePlugin.js +379 -0
  431. package/lib/lexical/index.d.ts +6 -0
  432. package/lib/lexical/index.js +10 -0
  433. package/lib/lib/utils.d.ts +2 -0
  434. package/lib/lib/utils.js +9 -0
  435. package/lib/main.d.ts +1 -0
  436. package/lib/main.js +12 -0
  437. package/lib/models/AIAgent.d.ts +17 -0
  438. package/lib/models/AIAgent.js +5 -0
  439. package/lib/models/index.d.ts +1 -0
  440. package/lib/models/index.js +5 -0
  441. package/lib/renderers/a2ui/components/A2UIRenderer.d.ts +7 -0
  442. package/lib/renderers/a2ui/components/A2UIRenderer.js +102 -0
  443. package/lib/renderers/a2ui/components/SurfaceRenderer.d.ts +7 -0
  444. package/lib/renderers/a2ui/components/SurfaceRenderer.js +101 -0
  445. package/lib/renderers/a2ui/components/content/AudioPlayer.d.ts +9 -0
  446. package/lib/renderers/a2ui/components/content/AudioPlayer.js +38 -0
  447. package/lib/renderers/a2ui/components/content/Divider.d.ts +9 -0
  448. package/lib/renderers/a2ui/components/content/Divider.js +35 -0
  449. package/lib/renderers/a2ui/components/content/Icon.d.ts +9 -0
  450. package/lib/renderers/a2ui/components/content/Icon.js +110 -0
  451. package/lib/renderers/a2ui/components/content/Image.d.ts +9 -0
  452. package/lib/renderers/a2ui/components/content/Image.js +61 -0
  453. package/lib/renderers/a2ui/components/content/Text.d.ts +9 -0
  454. package/lib/renderers/a2ui/components/content/Text.js +64 -0
  455. package/lib/renderers/a2ui/components/content/Video.d.ts +9 -0
  456. package/lib/renderers/a2ui/components/content/Video.js +37 -0
  457. package/lib/renderers/a2ui/components/content/index.d.ts +6 -0
  458. package/lib/renderers/a2ui/components/content/index.js +25 -0
  459. package/lib/renderers/a2ui/components/index.d.ts +5 -0
  460. package/lib/renderers/a2ui/components/index.js +24 -0
  461. package/lib/renderers/a2ui/components/interactive/Button.d.ts +11 -0
  462. package/lib/renderers/a2ui/components/interactive/Button.js +71 -0
  463. package/lib/renderers/a2ui/components/interactive/CheckBox.d.ts +9 -0
  464. package/lib/renderers/a2ui/components/interactive/CheckBox.js +48 -0
  465. package/lib/renderers/a2ui/components/interactive/DateTimeInput.d.ts +9 -0
  466. package/lib/renderers/a2ui/components/interactive/DateTimeInput.js +62 -0
  467. package/lib/renderers/a2ui/components/interactive/MultipleChoice.d.ts +9 -0
  468. package/lib/renderers/a2ui/components/interactive/MultipleChoice.js +73 -0
  469. package/lib/renderers/a2ui/components/interactive/Slider.d.ts +9 -0
  470. package/lib/renderers/a2ui/components/interactive/Slider.js +53 -0
  471. package/lib/renderers/a2ui/components/interactive/TextField.d.ts +9 -0
  472. package/lib/renderers/a2ui/components/interactive/TextField.js +72 -0
  473. package/lib/renderers/a2ui/components/interactive/index.d.ts +6 -0
  474. package/lib/renderers/a2ui/components/interactive/index.js +25 -0
  475. package/lib/renderers/a2ui/components/layout/Card.d.ts +11 -0
  476. package/lib/renderers/a2ui/components/layout/Card.js +30 -0
  477. package/lib/renderers/a2ui/components/layout/Column.d.ts +11 -0
  478. package/lib/renderers/a2ui/components/layout/Column.js +65 -0
  479. package/lib/renderers/a2ui/components/layout/List.d.ts +11 -0
  480. package/lib/renderers/a2ui/components/layout/List.js +55 -0
  481. package/lib/renderers/a2ui/components/layout/Modal.d.ts +11 -0
  482. package/lib/renderers/a2ui/components/layout/Modal.js +58 -0
  483. package/lib/renderers/a2ui/components/layout/Row.d.ts +11 -0
  484. package/lib/renderers/a2ui/components/layout/Row.js +65 -0
  485. package/lib/renderers/a2ui/components/layout/Tabs.d.ts +11 -0
  486. package/lib/renderers/a2ui/components/layout/Tabs.js +48 -0
  487. package/lib/renderers/a2ui/components/layout/index.d.ts +6 -0
  488. package/lib/renderers/a2ui/components/layout/index.js +25 -0
  489. package/lib/renderers/a2ui/context/A2UIContext.d.ts +17 -0
  490. package/lib/renderers/a2ui/context/A2UIContext.js +54 -0
  491. package/lib/renderers/a2ui/context/ThemeContext.d.ts +20 -0
  492. package/lib/renderers/a2ui/context/ThemeContext.js +333 -0
  493. package/lib/renderers/a2ui/hooks/useA2UI.d.ts +36 -0
  494. package/lib/renderers/a2ui/hooks/useA2UI.js +62 -0
  495. package/lib/renderers/a2ui/hooks/useDataBinding.d.ts +8 -0
  496. package/lib/renderers/a2ui/hooks/useDataBinding.js +83 -0
  497. package/lib/renderers/a2ui/index.d.ts +9 -0
  498. package/lib/renderers/a2ui/index.js +28 -0
  499. package/lib/renderers/a2ui/lib/utils.d.ts +11 -0
  500. package/lib/renderers/a2ui/lib/utils.js +38 -0
  501. package/lib/renderers/a2ui/types/index.d.ts +17 -0
  502. package/lib/renderers/a2ui/types/index.js +5 -0
  503. package/lib/renderers/index.d.ts +1 -0
  504. package/lib/renderers/index.js +5 -0
  505. package/lib/state/index.d.ts +1 -0
  506. package/lib/state/index.js +5 -0
  507. package/lib/state/substates/AIAgentState.d.ts +11 -0
  508. package/lib/state/substates/AIAgentState.js +42 -0
  509. package/lib/state/substates/index.d.ts +1 -0
  510. package/lib/state/substates/index.js +5 -0
  511. package/lib/stories/Button.d.ts +15 -0
  512. package/lib/stories/Button.js +13 -0
  513. package/lib/stories/Button.stories.d.ts +23 -0
  514. package/lib/stories/Button.stories.js +48 -0
  515. package/lib/stories/Cell.stories.d.ts +12 -0
  516. package/lib/stories/Cell.stories.js +123 -0
  517. package/lib/stories/Header.d.ts +12 -0
  518. package/lib/stories/Header.js +8 -0
  519. package/lib/stories/Header.stories.d.ts +18 -0
  520. package/lib/stories/Header.stories.js +30 -0
  521. package/lib/stories/Page.d.ts +3 -0
  522. package/lib/stories/Page.js +12 -0
  523. package/lib/stories/Page.stories.d.ts +12 -0
  524. package/lib/stories/Page.stories.js +28 -0
  525. package/lib/stories/assets/accessibility.png +0 -0
  526. package/lib/stories/assets/accessibility.svg +1 -0
  527. package/lib/stories/assets/addon-library.png +0 -0
  528. package/lib/stories/assets/assets.png +0 -0
  529. package/lib/stories/assets/context.png +0 -0
  530. package/lib/stories/assets/discord.svg +1 -0
  531. package/lib/stories/assets/docs.png +0 -0
  532. package/lib/stories/assets/figma-plugin.png +0 -0
  533. package/lib/stories/assets/github.svg +1 -0
  534. package/lib/stories/assets/share.png +0 -0
  535. package/lib/stories/assets/styling.png +0 -0
  536. package/lib/stories/assets/testing.png +0 -0
  537. package/lib/stories/assets/theming.png +0 -0
  538. package/lib/stories/assets/tutorials.svg +1 -0
  539. package/lib/stories/assets/youtube.svg +1 -0
  540. package/lib/stories/button.css +35 -0
  541. package/lib/stories/header.css +37 -0
  542. package/lib/stories/page.css +73 -0
  543. package/lib/test-setup.d.ts +1 -0
  544. package/lib/test-setup.js +80 -0
  545. package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.d.ts +40 -0
  546. package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.js +110 -0
  547. package/lib/tools/adapters/agent-runtimes/index.d.ts +9 -0
  548. package/lib/tools/adapters/agent-runtimes/index.js +13 -0
  549. package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +24 -0
  550. package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +50 -0
  551. package/lib/tools/adapters/agent-runtimes/notebookHooks.d.ts +24 -0
  552. package/lib/tools/adapters/agent-runtimes/notebookHooks.js +51 -0
  553. package/lib/tools/adapters/copilotkit/CopilotKitToolAdapter.d.ts +73 -0
  554. package/lib/tools/adapters/copilotkit/CopilotKitToolAdapter.js +244 -0
  555. package/lib/tools/adapters/copilotkit/index.d.ts +10 -0
  556. package/lib/tools/adapters/copilotkit/index.js +14 -0
  557. package/lib/tools/adapters/copilotkit/lexicalHooks.d.ts +27 -0
  558. package/lib/tools/adapters/copilotkit/lexicalHooks.js +59 -0
  559. package/lib/tools/adapters/copilotkit/notebookHooks.d.ts +27 -0
  560. package/lib/tools/adapters/copilotkit/notebookHooks.js +58 -0
  561. package/lib/tools/adapters/index.d.ts +1 -0
  562. package/lib/tools/adapters/index.js +5 -0
  563. package/lib/tools/index.d.ts +6 -0
  564. package/lib/tools/index.js +18 -0
  565. package/lib/types.d.ts +5 -0
  566. package/lib/types.js +5 -0
  567. package/package.json +327 -0
  568. package/style/animation/Animation.module.css +174 -0
  569. package/style/base.css +204 -0
  570. package/style/index.css +6 -0
  571. package/style/showcase-vercel-ai.css +137 -0
@@ -0,0 +1,368 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * useA2A - React hook for A2A (Agent-to-Agent) protocol.
7
+ *
8
+ * This hook provides a client interface to A2A protocol endpoints,
9
+ * supporting both synchronous message/send and streaming responses.
10
+ *
11
+ * Features:
12
+ * - Agent card discovery
13
+ * - Message sending with JSON-RPC
14
+ * - Streaming support via SSE
15
+ * - Task management
16
+ * - Message history tracking
17
+ *
18
+ * @see https://github.com/a2aproject/a2a-js
19
+ */
20
+ import { useCallback, useEffect, useRef, useState } from 'react';
21
+ /**
22
+ * Hook to manage chat state with A2A protocol.
23
+ *
24
+ * This hook provides an interface to the A2A protocol endpoint
25
+ * at /api/v1/a2a/agents/{agent_id} using JSON-RPC 2.0.
26
+ *
27
+ * Example:
28
+ * ```tsx
29
+ * const { messages, sendMessage, isConnected } = useA2A({
30
+ * baseUrl: 'http://localhost:8765',
31
+ * agentId: 'demo-agent',
32
+ * });
33
+ *
34
+ * await sendMessage('Hello!');
35
+ * ```
36
+ */
37
+ export function useA2A(options = {}) {
38
+ const { baseUrl = 'http://localhost:8765', agentId = 'demo-agent', streaming = true, autoConnect = true, onMessageSent, onMessageReceived, onTaskStatusChange, onError, } = options;
39
+ const [isConnected, setIsConnected] = useState(false);
40
+ const [agentCard, setAgentCard] = useState(null);
41
+ const [messages, setMessages] = useState([]);
42
+ const [currentTask, setCurrentTask] = useState(null);
43
+ const [isLoading, setIsLoading] = useState(false);
44
+ const [isStreaming, setIsStreaming] = useState(false);
45
+ const [streamingContent, setStreamingContent] = useState('');
46
+ const [error, setError] = useState(null);
47
+ const abortControllerRef = useRef(null);
48
+ const requestIdRef = useRef(0);
49
+ const contextIdRef = useRef(null);
50
+ // Construct the A2A endpoint URL
51
+ const agentCardUrl = `${baseUrl}/api/v1/a2a/agents/${agentId}/.well-known/agent-card.json`;
52
+ const endpointUrl = `${baseUrl}/api/v1/a2a/agents/${agentId}/`;
53
+ const streamEndpointUrl = `${baseUrl}/api/v1/a2a/agents/${agentId}/stream`;
54
+ // Generate unique request ID
55
+ const generateRequestId = useCallback(() => {
56
+ requestIdRef.current += 1;
57
+ return requestIdRef.current;
58
+ }, []);
59
+ // Connect to agent (fetch agent card)
60
+ const connect = useCallback(async () => {
61
+ try {
62
+ setError(null);
63
+ const response = await fetch(agentCardUrl);
64
+ if (!response.ok) {
65
+ throw new Error(`Failed to fetch agent card: ${response.statusText}`);
66
+ }
67
+ const card = (await response.json());
68
+ setAgentCard(card);
69
+ setIsConnected(true);
70
+ }
71
+ catch (e) {
72
+ const err = e instanceof Error ? e : new Error(String(e));
73
+ setError(err);
74
+ setIsConnected(false);
75
+ onError?.(err);
76
+ }
77
+ }, [agentCardUrl, onError]);
78
+ // Disconnect
79
+ const disconnect = useCallback(() => {
80
+ if (abortControllerRef.current) {
81
+ abortControllerRef.current.abort();
82
+ abortControllerRef.current = null;
83
+ }
84
+ setIsConnected(false);
85
+ setAgentCard(null);
86
+ contextIdRef.current = null;
87
+ }, []);
88
+ // Send message using JSON-RPC
89
+ const sendMessage = useCallback(async (content) => {
90
+ if (!isConnected) {
91
+ throw new Error('Not connected to agent');
92
+ }
93
+ setIsLoading(true);
94
+ setError(null);
95
+ // Add user message to history
96
+ const userMessage = {
97
+ role: 'user',
98
+ content,
99
+ timestamp: new Date().toISOString(),
100
+ };
101
+ setMessages(prev => [...prev, userMessage]);
102
+ onMessageSent?.(content);
103
+ // Generate or use existing context ID
104
+ if (!contextIdRef.current) {
105
+ contextIdRef.current = crypto.randomUUID();
106
+ }
107
+ const requestId = generateRequestId();
108
+ try {
109
+ if (streaming && agentCard?.capabilities?.streaming) {
110
+ // Use streaming endpoint
111
+ await sendStreamingMessage(content, requestId);
112
+ }
113
+ else {
114
+ // Use non-streaming endpoint
115
+ await sendNonStreamingMessage(content, requestId);
116
+ }
117
+ }
118
+ catch (e) {
119
+ const err = e instanceof Error ? e : new Error(String(e));
120
+ setError(err);
121
+ onError?.(err);
122
+ }
123
+ finally {
124
+ setIsLoading(false);
125
+ setIsStreaming(false);
126
+ }
127
+ }, [
128
+ isConnected,
129
+ streaming,
130
+ agentCard,
131
+ generateRequestId,
132
+ onMessageSent,
133
+ onError,
134
+ ]);
135
+ // Send non-streaming message
136
+ const sendNonStreamingMessage = async (content, requestId) => {
137
+ // Send the message
138
+ const response = await fetch(endpointUrl, {
139
+ method: 'POST',
140
+ headers: {
141
+ 'Content-Type': 'application/json',
142
+ },
143
+ body: JSON.stringify({
144
+ jsonrpc: '2.0',
145
+ id: requestId,
146
+ method: 'message/send',
147
+ params: {
148
+ message: {
149
+ kind: 'message',
150
+ messageId: crypto.randomUUID(),
151
+ role: 'user',
152
+ parts: [{ kind: 'text', text: content }],
153
+ contextId: contextIdRef.current,
154
+ },
155
+ },
156
+ }),
157
+ });
158
+ if (!response.ok) {
159
+ throw new Error(`Request failed: ${response.statusText}`);
160
+ }
161
+ const data = await response.json();
162
+ if (data.error) {
163
+ throw new Error(data.error.message || 'Unknown error');
164
+ }
165
+ let task = data.result;
166
+ setCurrentTask(task);
167
+ onTaskStatusChange?.(task);
168
+ // Poll for task completion
169
+ const maxAttempts = 60; // 60 seconds max
170
+ let attempts = 0;
171
+ while (task.status.state === 'submitted' ||
172
+ task.status.state === 'working') {
173
+ if (attempts >= maxAttempts) {
174
+ throw new Error('Task polling timeout');
175
+ }
176
+ await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second
177
+ attempts++;
178
+ // Poll task status
179
+ const pollResponse = await fetch(endpointUrl, {
180
+ method: 'POST',
181
+ headers: {
182
+ 'Content-Type': 'application/json',
183
+ },
184
+ body: JSON.stringify({
185
+ jsonrpc: '2.0',
186
+ id: generateRequestId(),
187
+ method: 'tasks/get',
188
+ params: {
189
+ id: task.id,
190
+ },
191
+ }),
192
+ });
193
+ if (!pollResponse.ok) {
194
+ throw new Error(`Poll failed: ${pollResponse.statusText}`);
195
+ }
196
+ const pollData = await pollResponse.json();
197
+ if (pollData.error) {
198
+ throw new Error(pollData.error.message || 'Unknown error');
199
+ }
200
+ task = pollData.result;
201
+ setCurrentTask(task);
202
+ onTaskStatusChange?.(task);
203
+ }
204
+ // Extract response from completed task
205
+ if (task.status.state === 'completed') {
206
+ // Check for artifacts
207
+ if (task.artifacts && task.artifacts.length > 0) {
208
+ const textParts = task.artifacts.flatMap(artifact => artifact.parts?.filter((p) => p.kind === 'text') ||
209
+ []);
210
+ const responseText = textParts.map(p => p.text).join('') || '';
211
+ if (responseText) {
212
+ const assistantMessage = {
213
+ role: 'assistant',
214
+ content: responseText,
215
+ timestamp: new Date().toISOString(),
216
+ taskId: task.id,
217
+ contextId: task.contextId,
218
+ };
219
+ setMessages(prev => [...prev, assistantMessage]);
220
+ onMessageReceived?.(assistantMessage);
221
+ }
222
+ }
223
+ // Also check status message
224
+ if (task.status?.message) {
225
+ const agentMessage = task.status.message;
226
+ const textParts = agentMessage.parts?.filter((p) => p.kind === 'text');
227
+ const responseText = textParts?.map(p => p.text).join('') || '';
228
+ if (responseText) {
229
+ const assistantMessage = {
230
+ role: 'assistant',
231
+ content: responseText,
232
+ timestamp: new Date().toISOString(),
233
+ taskId: task.id,
234
+ contextId: task.contextId,
235
+ };
236
+ setMessages(prev => [...prev, assistantMessage]);
237
+ onMessageReceived?.(assistantMessage);
238
+ }
239
+ }
240
+ }
241
+ else if (task.status.state === 'failed') {
242
+ throw new Error('Task failed');
243
+ }
244
+ else if (task.status.state === 'canceled') {
245
+ throw new Error('Task was canceled');
246
+ }
247
+ };
248
+ // Send streaming message
249
+ const sendStreamingMessage = async (content, requestId) => {
250
+ setIsStreaming(true);
251
+ setStreamingContent('');
252
+ abortControllerRef.current = new AbortController();
253
+ const response = await fetch(streamEndpointUrl, {
254
+ method: 'POST',
255
+ headers: {
256
+ 'Content-Type': 'application/json',
257
+ Accept: 'text/event-stream',
258
+ },
259
+ body: JSON.stringify({
260
+ jsonrpc: '2.0',
261
+ id: requestId,
262
+ method: 'message/stream',
263
+ params: {
264
+ message: {
265
+ kind: 'message',
266
+ messageId: crypto.randomUUID(),
267
+ role: 'user',
268
+ parts: [{ kind: 'text', text: content }],
269
+ contextId: contextIdRef.current,
270
+ },
271
+ },
272
+ }),
273
+ signal: abortControllerRef.current.signal,
274
+ });
275
+ if (!response.ok) {
276
+ throw new Error(`Stream request failed: ${response.statusText}`);
277
+ }
278
+ const reader = response.body?.getReader();
279
+ if (!reader) {
280
+ throw new Error('No response body');
281
+ }
282
+ const decoder = new TextDecoder();
283
+ let accumulatedContent = '';
284
+ try {
285
+ while (true) {
286
+ const { done, value } = await reader.read();
287
+ if (done)
288
+ break;
289
+ const chunk = decoder.decode(value, { stream: true });
290
+ const lines = chunk.split('\n');
291
+ for (const line of lines) {
292
+ if (line.startsWith('data: ')) {
293
+ const data = line.slice(6).trim();
294
+ if (data === '[DONE]') {
295
+ // Streaming complete
296
+ const assistantMessage = {
297
+ role: 'assistant',
298
+ content: accumulatedContent,
299
+ timestamp: new Date().toISOString(),
300
+ };
301
+ setMessages(prev => [...prev, assistantMessage]);
302
+ onMessageReceived?.(assistantMessage);
303
+ setStreamingContent('');
304
+ break;
305
+ }
306
+ try {
307
+ const event = JSON.parse(data);
308
+ if (event.type === 'task') {
309
+ setCurrentTask(event.task);
310
+ onTaskStatusChange?.(event.task);
311
+ }
312
+ else if (event.type === 'status') {
313
+ // Update task status
314
+ }
315
+ else if (event.type === 'artifact') {
316
+ if (event.artifact?.kind === 'text') {
317
+ accumulatedContent += event.artifact.text;
318
+ setStreamingContent(accumulatedContent);
319
+ }
320
+ }
321
+ else if (event.type === 'error') {
322
+ throw new Error(event.error);
323
+ }
324
+ }
325
+ catch (parseError) {
326
+ // Ignore JSON parse errors for incomplete chunks
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }
332
+ finally {
333
+ reader.releaseLock();
334
+ }
335
+ };
336
+ // Clear messages
337
+ const clearMessages = useCallback(() => {
338
+ setMessages([]);
339
+ setCurrentTask(null);
340
+ setStreamingContent('');
341
+ contextIdRef.current = null;
342
+ }, []);
343
+ // Auto-connect on mount
344
+ useEffect(() => {
345
+ if (autoConnect) {
346
+ connect();
347
+ }
348
+ return () => {
349
+ disconnect();
350
+ };
351
+ // eslint-disable-next-line react-hooks/exhaustive-deps
352
+ }, [autoConnect]);
353
+ return {
354
+ isConnected,
355
+ agentCard,
356
+ messages,
357
+ sendMessage,
358
+ clearMessages,
359
+ currentTask,
360
+ isLoading,
361
+ isStreaming,
362
+ streamingContent,
363
+ connect,
364
+ disconnect,
365
+ error,
366
+ };
367
+ }
368
+ export default useA2A;
@@ -0,0 +1,63 @@
1
+ export interface Message {
2
+ role: 'user' | 'assistant' | 'system';
3
+ content: string;
4
+ timestamp?: string;
5
+ }
6
+ export interface UseAGUIOptions {
7
+ /**
8
+ * Base URL for the AG-UI endpoint (e.g., 'http://localhost:8000')
9
+ */
10
+ baseUrl?: string;
11
+ /**
12
+ * Agent ID to use (default: 'demo-agent')
13
+ */
14
+ agentId?: string;
15
+ /**
16
+ * Auto-connect on mount
17
+ */
18
+ autoConnect?: boolean;
19
+ /**
20
+ * Callback when a message is sent
21
+ */
22
+ onMessageSent?: (content: string) => void;
23
+ /**
24
+ * Callback when a message is received
25
+ */
26
+ onMessageReceived?: (message: Message) => void;
27
+ /**
28
+ * Callback when an error occurs
29
+ */
30
+ onError?: (error: Error) => void;
31
+ }
32
+ /**
33
+ * Hook to manage chat state with AG-UI protocol.
34
+ *
35
+ * This hook provides an interface to the AG-UI protocol endpoint
36
+ * at /api/v1/ag-ui/{agent_id}/ which is powered by Pydantic AI's
37
+ * native AGUIApp. The AG-UI protocol accepts POST requests with
38
+ * prompts and streams back agent responses.
39
+ *
40
+ * Features:
41
+ * - POST-based message sending
42
+ * - Streaming response handling
43
+ * - Message history tracking
44
+ *
45
+ * Example:
46
+ * ```tsx
47
+ * const { messages, sendMessage, isConnected } = useAGUI({
48
+ * baseUrl: 'http://localhost:8765',
49
+ * agentId: 'demo-agent',
50
+ * });
51
+ *
52
+ * await sendMessage('Hello!');
53
+ * ```
54
+ */
55
+ export declare function useAGUI(options?: UseAGUIOptions): {
56
+ messages: Message[];
57
+ isConnected: boolean;
58
+ isSending: boolean;
59
+ error: Error | null;
60
+ sendMessage: (content: string) => Promise<void>;
61
+ connect: () => Promise<void>;
62
+ disconnect: () => void;
63
+ };
@@ -0,0 +1,162 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { useCallback, useEffect, useState } from 'react';
6
+ /**
7
+ * Hook to manage chat state with AG-UI protocol.
8
+ *
9
+ * This hook provides an interface to the AG-UI protocol endpoint
10
+ * at /api/v1/ag-ui/{agent_id}/ which is powered by Pydantic AI's
11
+ * native AGUIApp. The AG-UI protocol accepts POST requests with
12
+ * prompts and streams back agent responses.
13
+ *
14
+ * Features:
15
+ * - POST-based message sending
16
+ * - Streaming response handling
17
+ * - Message history tracking
18
+ *
19
+ * Example:
20
+ * ```tsx
21
+ * const { messages, sendMessage, isConnected } = useAGUI({
22
+ * baseUrl: 'http://localhost:8765',
23
+ * agentId: 'demo-agent',
24
+ * });
25
+ *
26
+ * await sendMessage('Hello!');
27
+ * ```
28
+ */
29
+ export function useAGUI(options = {}) {
30
+ const { baseUrl = 'http://localhost:8765', agentId = 'demo-agent', autoConnect = true, onMessageSent, onMessageReceived, onError, } = options;
31
+ const [messages, setMessages] = useState([]);
32
+ const [isConnected, setIsConnected] = useState(false);
33
+ const [isSending, setIsSending] = useState(false);
34
+ const [error, setError] = useState(null);
35
+ // Construct the AG-UI endpoint URL
36
+ const endpointUrl = `${baseUrl}/api/v1/ag-ui/${agentId}/`;
37
+ // Connect to AG-UI (check health)
38
+ const connect = useCallback(async () => {
39
+ try {
40
+ // AG-UI doesn't have a health endpoint, so we just mark as connected
41
+ setIsConnected(true);
42
+ setError(null);
43
+ }
44
+ catch (err) {
45
+ const error = err instanceof Error ? err : new Error(String(err));
46
+ setError(error);
47
+ setIsConnected(false);
48
+ onError?.(error);
49
+ }
50
+ }, [onError]);
51
+ // Disconnect from AG-UI
52
+ const disconnect = useCallback(() => {
53
+ setIsConnected(false);
54
+ }, []);
55
+ // Send a message to the agent
56
+ const sendMessage = useCallback(async (content) => {
57
+ if (!content.trim())
58
+ return;
59
+ setIsSending(true);
60
+ setError(null);
61
+ try {
62
+ // Add user message to history
63
+ const userMessage = {
64
+ role: 'user',
65
+ content,
66
+ timestamp: new Date().toISOString(),
67
+ };
68
+ setMessages(prev => [...prev, userMessage]);
69
+ onMessageSent?.(content);
70
+ // Build AG-UI RunAgentInput format
71
+ const requestBody = {
72
+ thread_id: `thread-${Date.now()}`,
73
+ run_id: `run-${Date.now()}`,
74
+ parent_run_id: null,
75
+ state: null,
76
+ messages: [
77
+ {
78
+ id: `msg-${Date.now()}`,
79
+ role: 'user',
80
+ content,
81
+ name: null,
82
+ },
83
+ ],
84
+ tools: [],
85
+ context: [],
86
+ forwarded_props: {},
87
+ };
88
+ // Send POST request to AG-UI endpoint
89
+ const response = await fetch(endpointUrl, {
90
+ method: 'POST',
91
+ headers: {
92
+ 'Content-Type': 'application/json',
93
+ },
94
+ body: JSON.stringify(requestBody),
95
+ });
96
+ if (!response.ok) {
97
+ throw new Error(`AG-UI request failed: ${response.status} ${response.statusText}`);
98
+ }
99
+ // Handle streaming response
100
+ const reader = response.body?.getReader();
101
+ if (!reader) {
102
+ throw new Error('No response body');
103
+ }
104
+ const decoder = new TextDecoder();
105
+ let assistantContent = '';
106
+ while (true) {
107
+ const { done, value } = await reader.read();
108
+ if (done)
109
+ break;
110
+ const chunk = decoder.decode(value, { stream: true });
111
+ // Parse AG-UI event stream format (server-sent events)
112
+ const lines = chunk.split('\n');
113
+ for (const line of lines) {
114
+ if (line.startsWith('data: ')) {
115
+ try {
116
+ const data = JSON.parse(line.slice(6));
117
+ // AG-UI sends TEXT_MESSAGE_CONTENT events with delta field
118
+ if (data.type === 'TEXT_MESSAGE_CONTENT' && data.delta) {
119
+ assistantContent += data.delta;
120
+ }
121
+ }
122
+ catch (e) {
123
+ // Skip invalid JSON
124
+ console.warn('Failed to parse AG-UI event:', e);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ // Add assistant message to history
130
+ const assistantMessage = {
131
+ role: 'assistant',
132
+ content: assistantContent || 'No response',
133
+ timestamp: new Date().toISOString(),
134
+ };
135
+ setMessages(prev => [...prev, assistantMessage]);
136
+ onMessageReceived?.(assistantMessage);
137
+ }
138
+ catch (err) {
139
+ const error = err instanceof Error ? err : new Error(String(err));
140
+ setError(error);
141
+ onError?.(error);
142
+ }
143
+ finally {
144
+ setIsSending(false);
145
+ }
146
+ }, [endpointUrl, onMessageSent, onMessageReceived, onError]);
147
+ // Auto-connect on mount
148
+ useEffect(() => {
149
+ if (autoConnect) {
150
+ connect();
151
+ }
152
+ }, [autoConnect, connect]);
153
+ return {
154
+ messages,
155
+ isConnected,
156
+ isSending,
157
+ error,
158
+ sendMessage,
159
+ connect,
160
+ disconnect,
161
+ };
162
+ }