@copilotkit/react-core 1.10.6 → 1.50.0-beta.0

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 (333) hide show
  1. package/dist/chunk-24SCZAB4.mjs +143 -0
  2. package/dist/chunk-24SCZAB4.mjs.map +1 -0
  3. package/dist/chunk-36KQV2NA.mjs +1 -0
  4. package/dist/{chunk-U7QULEVO.mjs → chunk-3GURHDG7.mjs} +3 -3
  5. package/dist/{chunk-4BHIQMN6.mjs → chunk-3R423LZT.mjs} +6 -5
  6. package/dist/{chunk-4BHIQMN6.mjs.map → chunk-3R423LZT.mjs.map} +1 -1
  7. package/dist/chunk-5X5DJRQQ.mjs +71 -0
  8. package/dist/chunk-5X5DJRQQ.mjs.map +1 -0
  9. package/dist/{chunk-N4WEHORG.mjs → chunk-6PUNP7CD.mjs} +4 -4
  10. package/dist/chunk-6PUNP7CD.mjs.map +1 -0
  11. package/dist/chunk-7BYHZLPL.mjs +32 -0
  12. package/dist/chunk-7BYHZLPL.mjs.map +1 -0
  13. package/dist/chunk-7DTB7S5V.mjs +83 -0
  14. package/dist/chunk-7DTB7S5V.mjs.map +1 -0
  15. package/dist/chunk-A6NKSGH3.mjs +1 -0
  16. package/dist/{chunk-GT5WI3AF.mjs → chunk-BR5YEYZJ.mjs} +7 -9
  17. package/dist/chunk-BR5YEYZJ.mjs.map +1 -0
  18. package/dist/chunk-CB7CRBDG.mjs +48 -0
  19. package/dist/chunk-CB7CRBDG.mjs.map +1 -0
  20. package/dist/chunk-CYDWEPFL.mjs +1 -0
  21. package/dist/{chunk-BBUQMG45.mjs → chunk-D3QSYDJR.mjs} +3 -3
  22. package/dist/{chunk-BBUQMG45.mjs.map → chunk-D3QSYDJR.mjs.map} +1 -1
  23. package/dist/chunk-DCHSCK62.mjs +549 -0
  24. package/dist/chunk-DCHSCK62.mjs.map +1 -0
  25. package/dist/{chunk-ZLQVRPDS.mjs → chunk-DMLQZG75.mjs} +1 -1
  26. package/dist/chunk-DMLQZG75.mjs.map +1 -0
  27. package/dist/chunk-F555TVE4.mjs +33 -0
  28. package/dist/chunk-F555TVE4.mjs.map +1 -0
  29. package/dist/{chunk-C6IANC2R.mjs → chunk-FBD24VEH.mjs} +7 -43
  30. package/dist/chunk-FBD24VEH.mjs.map +1 -0
  31. package/dist/chunk-FD6FGKYY.mjs +1 -0
  32. package/dist/chunk-FDOMAPJY.mjs +59 -0
  33. package/dist/chunk-FDOMAPJY.mjs.map +1 -0
  34. package/dist/{chunk-X7MJWPI7.mjs → chunk-GMI4KO4X.mjs} +8 -6
  35. package/dist/{chunk-X7MJWPI7.mjs.map → chunk-GMI4KO4X.mjs.map} +1 -1
  36. package/dist/chunk-IUSKVYUI.mjs +13 -0
  37. package/dist/chunk-IUSKVYUI.mjs.map +1 -0
  38. package/dist/chunk-JD7BAH7U.mjs +1 -0
  39. package/dist/{chunk-N5HOP3PG.mjs → chunk-JRT5BJF3.mjs} +2 -2
  40. package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
  41. package/dist/{chunk-DXEQPN43.mjs → chunk-LHKZJ2ND.mjs} +3 -3
  42. package/dist/chunk-NB2FKV2V.mjs +1 -0
  43. package/dist/chunk-NBK4KBLX.mjs +54 -0
  44. package/dist/chunk-NBK4KBLX.mjs.map +1 -0
  45. package/dist/chunk-NG26QEGF.mjs +46 -0
  46. package/dist/chunk-NG26QEGF.mjs.map +1 -0
  47. package/dist/chunk-NROJOTQP.mjs +163 -0
  48. package/dist/chunk-NROJOTQP.mjs.map +1 -0
  49. package/dist/{chunk-MGWRDFBE.mjs → chunk-OVYFRPSN.mjs} +2 -2
  50. package/dist/{chunk-MQYWH4E6.mjs → chunk-QU6NONOD.mjs} +2 -2
  51. package/dist/chunk-R4MR43UQ.mjs +101 -0
  52. package/dist/chunk-R4MR43UQ.mjs.map +1 -0
  53. package/dist/chunk-SPCZTZCY.mjs +1 -0
  54. package/dist/chunk-SPCZTZCY.mjs.map +1 -0
  55. package/dist/chunk-TXI72QHK.mjs +80 -0
  56. package/dist/chunk-TXI72QHK.mjs.map +1 -0
  57. package/dist/chunk-UJBV5GAG.mjs +767 -0
  58. package/dist/chunk-UJBV5GAG.mjs.map +1 -0
  59. package/dist/{chunk-OKCYPO4I.mjs → chunk-WMJVBMUX.mjs} +3 -3
  60. package/dist/{chunk-EUX2P2E7.mjs → chunk-WVLHXIFP.mjs} +11 -9
  61. package/dist/chunk-WVLHXIFP.mjs.map +1 -0
  62. package/dist/{chunk-5FHSUKQL.mjs → chunk-YYN33GSG.mjs} +5 -2
  63. package/dist/chunk-YYN33GSG.mjs.map +1 -0
  64. package/dist/chunk-ZVF5Q6IH.mjs +29 -0
  65. package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
  66. package/dist/components/CopilotListeners.d.ts +3 -0
  67. package/dist/components/CopilotListeners.js +234 -0
  68. package/dist/components/CopilotListeners.js.map +1 -0
  69. package/dist/components/CopilotListeners.mjs +14 -0
  70. package/dist/components/CopilotListeners.mjs.map +1 -0
  71. package/dist/components/copilot-provider/copilot-messages.js +14 -48
  72. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  73. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  74. package/dist/components/copilot-provider/copilotkit-props.d.ts +9 -2
  75. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  76. package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
  77. package/dist/components/copilot-provider/copilotkit.js +528 -370
  78. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  79. package/dist/components/copilot-provider/copilotkit.mjs +17 -12
  80. package/dist/components/copilot-provider/index.d.ts +2 -1
  81. package/dist/components/copilot-provider/index.js +528 -370
  82. package/dist/components/copilot-provider/index.js.map +1 -1
  83. package/dist/components/copilot-provider/index.mjs +18 -12
  84. package/dist/components/dev-console/console-trigger.js +10 -8
  85. package/dist/components/dev-console/console-trigger.js.map +1 -1
  86. package/dist/components/dev-console/console-trigger.mjs +4 -4
  87. package/dist/components/dev-console/developer-console-modal.js +10 -8
  88. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  89. package/dist/components/dev-console/developer-console-modal.mjs +3 -3
  90. package/dist/components/error-boundary/error-boundary.d.ts +7 -7
  91. package/dist/components/error-boundary/error-boundary.js +3 -3
  92. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  93. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  94. package/dist/components/error-boundary/error-utils.d.ts +1 -1
  95. package/dist/components/error-boundary/error-utils.js +3 -3
  96. package/dist/components/error-boundary/error-utils.js.map +1 -1
  97. package/dist/components/error-boundary/error-utils.mjs +1 -1
  98. package/dist/components/index.d.ts +2 -1
  99. package/dist/components/index.js +528 -370
  100. package/dist/components/index.js.map +1 -1
  101. package/dist/components/index.mjs +19 -12
  102. package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
  103. package/dist/components/toast/toast-provider.d.ts +3 -3
  104. package/dist/components/usage-banner.d.ts +2 -2
  105. package/dist/context/coagent-state-renders-context.d.ts +24 -0
  106. package/dist/context/coagent-state-renders-context.js +91 -0
  107. package/dist/context/coagent-state-renders-context.js.map +1 -0
  108. package/dist/context/coagent-state-renders-context.mjs +12 -0
  109. package/dist/context/coagent-state-renders-context.mjs.map +1 -0
  110. package/dist/context/copilot-context.d.ts +1 -1
  111. package/dist/context/copilot-context.js +10 -8
  112. package/dist/context/copilot-context.js.map +1 -1
  113. package/dist/context/copilot-context.mjs +1 -1
  114. package/dist/context/copilot-messages-context.d.ts +18 -11
  115. package/dist/context/copilot-messages-context.js.map +1 -1
  116. package/dist/context/copilot-messages-context.mjs +1 -1
  117. package/dist/context/index.d.ts +6 -2
  118. package/dist/context/index.js +110 -10
  119. package/dist/context/index.js.map +1 -1
  120. package/dist/context/index.mjs +20 -4
  121. package/dist/context/threads-context.d.ts +16 -0
  122. package/dist/context/threads-context.js +59 -0
  123. package/dist/context/threads-context.js.map +1 -0
  124. package/dist/context/threads-context.mjs +12 -0
  125. package/dist/context/threads-context.mjs.map +1 -0
  126. package/dist/{copilot-context-cf9de848.d.ts → copilot-context-1cd70a3f.d.ts} +36 -32
  127. package/dist/hooks/index.d.ts +9 -6
  128. package/dist/hooks/index.js +1445 -1839
  129. package/dist/hooks/index.js.map +1 -1
  130. package/dist/hooks/index.mjs +47 -56
  131. package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
  132. package/dist/hooks/use-coagent-state-render-bridge.js +211 -0
  133. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
  134. package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
  135. package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
  136. package/dist/hooks/use-coagent-state-render.js +31 -20
  137. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  138. package/dist/hooks/use-coagent-state-render.mjs +3 -2
  139. package/dist/hooks/use-coagent.d.ts +2 -14
  140. package/dist/hooks/use-coagent.js +109 -1906
  141. package/dist/hooks/use-coagent.js.map +1 -1
  142. package/dist/hooks/use-coagent.mjs +1 -30
  143. package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
  144. package/dist/hooks/use-configure-chat-suggestions.js +210 -0
  145. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
  146. package/dist/hooks/use-configure-chat-suggestions.mjs +13 -0
  147. package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
  148. package/dist/hooks/use-copilot-action.d.ts +8 -45
  149. package/dist/hooks/use-copilot-action.js +207 -349
  150. package/dist/hooks/use-copilot-action.js.map +1 -1
  151. package/dist/hooks/use-copilot-action.mjs +4 -5
  152. package/dist/hooks/use-copilot-additional-instructions.js +10 -8
  153. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  154. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  155. package/dist/hooks/use-copilot-authenticated-action.js +224 -248
  156. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  157. package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
  158. package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -10
  159. package/dist/hooks/use-copilot-chat-headless_c.js +973 -1369
  160. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  161. package/dist/hooks/use-copilot-chat-headless_c.mjs +12 -22
  162. package/dist/hooks/use-copilot-chat.d.ts +2 -10
  163. package/dist/hooks/use-copilot-chat.js +967 -1388
  164. package/dist/hooks/use-copilot-chat.js.map +1 -1
  165. package/dist/hooks/use-copilot-chat.mjs +12 -22
  166. package/dist/hooks/use-copilot-chat_internal.d.ts +38 -14
  167. package/dist/hooks/use-copilot-chat_internal.js +965 -1362
  168. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  169. package/dist/hooks/use-copilot-chat_internal.mjs +13 -23
  170. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  171. package/dist/hooks/use-copilot-readable.js +6 -157
  172. package/dist/hooks/use-copilot-readable.js.map +1 -1
  173. package/dist/hooks/use-copilot-readable.mjs +1 -2
  174. package/dist/hooks/use-default-tool.js +204 -349
  175. package/dist/hooks/use-default-tool.js.map +1 -1
  176. package/dist/hooks/use-default-tool.mjs +5 -6
  177. package/dist/hooks/use-flat-category-store.js +4 -1
  178. package/dist/hooks/use-flat-category-store.js.map +1 -1
  179. package/dist/hooks/use-flat-category-store.mjs +1 -1
  180. package/dist/hooks/use-frontend-tool.d.ts +3 -3
  181. package/dist/hooks/use-frontend-tool.js +30 -370
  182. package/dist/hooks/use-frontend-tool.js.map +1 -1
  183. package/dist/hooks/use-frontend-tool.mjs +1 -6
  184. package/dist/hooks/use-human-in-the-loop.d.ts +4 -3
  185. package/dist/hooks/use-human-in-the-loop.js +61 -393
  186. package/dist/hooks/use-human-in-the-loop.js.map +1 -1
  187. package/dist/hooks/use-human-in-the-loop.mjs +1 -6
  188. package/dist/hooks/use-langgraph-interrupt-render.d.ts +3 -2
  189. package/dist/hooks/use-langgraph-interrupt-render.js +92 -36
  190. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  191. package/dist/hooks/use-langgraph-interrupt-render.mjs +6 -4
  192. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  193. package/dist/hooks/use-langgraph-interrupt.js +24 -1642
  194. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  195. package/dist/hooks/use-langgraph-interrupt.mjs +2 -23
  196. package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
  197. package/dist/hooks/use-lazy-tool-renderer.js +53 -0
  198. package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
  199. package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
  200. package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
  201. package/dist/hooks/use-make-copilot-document-readable.js +11 -9
  202. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  203. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  204. package/dist/hooks/use-render-tool-call.d.ts +7 -6
  205. package/dist/hooks/use-render-tool-call.js +36 -386
  206. package/dist/hooks/use-render-tool-call.js.map +1 -1
  207. package/dist/hooks/use-render-tool-call.mjs +1 -6
  208. package/dist/index.d.ts +11 -6
  209. package/dist/index.js +1841 -2056
  210. package/dist/index.js.map +1 -1
  211. package/dist/index.mjs +82 -63
  212. package/dist/lib/copilot-task.d.ts +1 -1
  213. package/dist/lib/copilot-task.js +1 -0
  214. package/dist/lib/copilot-task.js.map +1 -1
  215. package/dist/lib/copilot-task.mjs +20 -13
  216. package/dist/lib/index.d.ts +1 -1
  217. package/dist/lib/index.js +1 -0
  218. package/dist/lib/index.js.map +1 -1
  219. package/dist/lib/index.mjs +20 -13
  220. package/dist/setupTests.d.ts +2 -2
  221. package/dist/types/frontend-action.d.ts +5 -5
  222. package/dist/types/index.d.ts +4 -0
  223. package/dist/types/index.js.map +1 -1
  224. package/dist/types/index.mjs +2 -1
  225. package/dist/types/interrupt-action.d.ts +1 -1
  226. package/dist/types/interrupt-action.js.map +1 -1
  227. package/dist/types/interrupt-action.mjs +1 -0
  228. package/dist/utils/index.d.ts +0 -12
  229. package/dist/utils/index.js +6 -325
  230. package/dist/utils/index.js.map +1 -1
  231. package/dist/utils/index.mjs +3 -23
  232. package/dist/utils/utils.js.map +1 -1
  233. package/dist/v2/index.d.ts +2 -0
  234. package/dist/v2/index.js +27 -0
  235. package/dist/v2/index.js.map +1 -0
  236. package/dist/v2/index.mjs +4 -0
  237. package/dist/v2/index.mjs.map +1 -0
  238. package/package.json +34 -23
  239. package/src/components/CopilotListeners.tsx +82 -0
  240. package/src/components/copilot-provider/copilot-messages.tsx +46 -47
  241. package/src/components/copilot-provider/copilotkit-props.tsx +8 -1
  242. package/src/components/copilot-provider/copilotkit.tsx +177 -144
  243. package/src/components/error-boundary/error-utils.tsx +3 -3
  244. package/src/context/coagent-state-renders-context.tsx +76 -0
  245. package/src/context/copilot-context.tsx +21 -21
  246. package/src/context/copilot-messages-context.tsx +3 -3
  247. package/src/context/index.ts +8 -0
  248. package/src/context/threads-context.tsx +41 -0
  249. package/src/hooks/index.ts +7 -3
  250. package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
  251. package/src/hooks/use-coagent-state-render.ts +4 -7
  252. package/src/hooks/use-coagent.ts +129 -249
  253. package/src/hooks/use-configure-chat-suggestions.tsx +85 -0
  254. package/src/hooks/use-copilot-action.ts +88 -199
  255. package/src/hooks/use-copilot-chat-headless_c.ts +2 -1
  256. package/src/hooks/use-copilot-chat.ts +4 -1
  257. package/src/hooks/use-copilot-chat_internal.ts +349 -258
  258. package/src/hooks/use-copilot-readable.ts +6 -26
  259. package/src/hooks/use-flat-category-store.ts +4 -3
  260. package/src/hooks/use-frontend-tool.ts +67 -8
  261. package/src/hooks/use-human-in-the-loop.ts +111 -13
  262. package/src/hooks/use-langgraph-interrupt-render.ts +90 -40
  263. package/src/hooks/use-langgraph-interrupt.ts +18 -47
  264. package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
  265. package/src/hooks/use-make-copilot-document-readable.ts +1 -1
  266. package/src/hooks/use-render-tool-call.ts +73 -13
  267. package/src/types/index.ts +1 -0
  268. package/src/types/interrupt-action.ts +8 -4
  269. package/src/utils/index.ts +0 -3
  270. package/src/utils/utils.ts +7 -0
  271. package/src/v2/index.ts +2 -0
  272. package/src/v2/styles.css +1 -0
  273. package/tsup.config.ts +1 -1
  274. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  275. package/dist/chunk-6GPVUMBU.mjs +0 -13
  276. package/dist/chunk-6GPVUMBU.mjs.map +0 -1
  277. package/dist/chunk-AKR2SSUJ.mjs +0 -22
  278. package/dist/chunk-AKR2SSUJ.mjs.map +0 -1
  279. package/dist/chunk-C6IANC2R.mjs.map +0 -1
  280. package/dist/chunk-CI4KD357.mjs +0 -804
  281. package/dist/chunk-CI4KD357.mjs.map +0 -1
  282. package/dist/chunk-DZTU6PGS.mjs +0 -1
  283. package/dist/chunk-EUX2P2E7.mjs.map +0 -1
  284. package/dist/chunk-EVVO67QO.mjs +0 -25
  285. package/dist/chunk-EVVO67QO.mjs.map +0 -1
  286. package/dist/chunk-GT5WI3AF.mjs.map +0 -1
  287. package/dist/chunk-HDOG2RTM.mjs +0 -37
  288. package/dist/chunk-HDOG2RTM.mjs.map +0 -1
  289. package/dist/chunk-N4WEHORG.mjs.map +0 -1
  290. package/dist/chunk-OT5NHMEC.mjs +0 -723
  291. package/dist/chunk-OT5NHMEC.mjs.map +0 -1
  292. package/dist/chunk-QHCLJODF.mjs +0 -332
  293. package/dist/chunk-QHCLJODF.mjs.map +0 -1
  294. package/dist/chunk-QV5SBF2S.mjs +0 -239
  295. package/dist/chunk-QV5SBF2S.mjs.map +0 -1
  296. package/dist/chunk-T3376SZS.mjs +0 -142
  297. package/dist/chunk-T3376SZS.mjs.map +0 -1
  298. package/dist/chunk-U3DQY67T.mjs +0 -71
  299. package/dist/chunk-U3DQY67T.mjs.map +0 -1
  300. package/dist/chunk-YPBKY4KY.mjs +0 -1
  301. package/dist/chunk-YPSGKPDA.mjs +0 -1
  302. package/dist/chunk-ZLQVRPDS.mjs.map +0 -1
  303. package/dist/chunk-ZVOLWJCY.mjs +0 -47
  304. package/dist/chunk-ZVOLWJCY.mjs.map +0 -1
  305. package/dist/hooks/use-chat.d.ts +0 -145
  306. package/dist/hooks/use-chat.js +0 -1129
  307. package/dist/hooks/use-chat.js.map +0 -1
  308. package/dist/hooks/use-chat.mjs +0 -14
  309. package/dist/index-1f5b66ac.d.ts +0 -36
  310. package/dist/utils/extract.d.ts +0 -43
  311. package/dist/utils/extract.js +0 -208
  312. package/dist/utils/extract.js.map +0 -1
  313. package/dist/utils/extract.mjs +0 -25
  314. package/dist/utils/suggestions.d.ts +0 -11
  315. package/dist/utils/suggestions.js +0 -343
  316. package/dist/utils/suggestions.js.map +0 -1
  317. package/dist/utils/suggestions.mjs +0 -25
  318. package/src/hooks/use-chat.ts +0 -1142
  319. package/src/utils/extract.ts +0 -215
  320. package/src/utils/suggestions.ts +0 -208
  321. /package/dist/{chunk-DZTU6PGS.mjs.map → chunk-36KQV2NA.mjs.map} +0 -0
  322. /package/dist/{chunk-U7QULEVO.mjs.map → chunk-3GURHDG7.mjs.map} +0 -0
  323. /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-A6NKSGH3.mjs.map} +0 -0
  324. /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
  325. /package/dist/{hooks/use-chat.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
  326. /package/dist/{utils/extract.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
  327. /package/dist/{chunk-N5HOP3PG.mjs.map → chunk-JRT5BJF3.mjs.map} +0 -0
  328. /package/dist/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
  329. /package/dist/{chunk-DXEQPN43.mjs.map → chunk-LHKZJ2ND.mjs.map} +0 -0
  330. /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
  331. /package/dist/{chunk-MGWRDFBE.mjs.map → chunk-OVYFRPSN.mjs.map} +0 -0
  332. /package/dist/{chunk-MQYWH4E6.mjs.map → chunk-QU6NONOD.mjs.map} +0 -0
  333. /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-WMJVBMUX.mjs.map} +0 -0
@@ -130,218 +130,107 @@
130
130
  *
131
131
  * This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.
132
132
  */
133
- import { Parameter, randomId } from "@copilotkit/shared";
134
- import { createElement, Fragment, useEffect, useRef } from "react";
135
- import { useCopilotContext } from "../context/copilot-context";
136
- import { useAsyncCallback } from "../components/error-boundary/error-utils";
137
- import {
138
- ActionRenderProps,
139
- ActionRenderPropsNoArgsWait,
140
- ActionRenderPropsWait,
141
- CatchAllFrontendAction,
142
- FrontendAction,
143
- } from "../types/frontend-action";
144
- import { useToast } from "../components/toast/toast-provider";
145
-
146
- // We implement useCopilotAction dependency handling so that
147
- // the developer has the option to not provide any dependencies.
148
- // In this case, we assume they want to update the handler on each rerender.
149
- // To avoid getting stuck in an infinite loop, we update the handler directly,
150
- // skipping React state updates.
151
- // This is ok in this case, because the handler is not part of any UI that
152
- // needs to be updated.
153
- // useCallback, useMemo or other memoization techniques are not suitable here,
154
- // because they will cause a infinite rerender loop.
155
- export function useCopilotAction<const T extends Parameter[] | [] = []>(
133
+ import { useEffect, useRef, useState } from "react";
134
+ import { Parameter } from "@copilotkit/shared";
135
+ import { CatchAllFrontendAction, FrontendAction } from "../types/frontend-action";
136
+ import { useFrontendTool, UseFrontendToolArgs } from "./use-frontend-tool";
137
+ import { useRenderToolCall, UseRenderToolCallArgs } from "./use-render-tool-call";
138
+ import { useHumanInTheLoop, UseHumanInTheLoopArgs } from "./use-human-in-the-loop";
139
+ import { useCopilotContext } from "../context";
140
+
141
+ // Helper to determine which component and action config to use
142
+ function getActionConfig<const T extends Parameter[] | [] = []>(
156
143
  action: FrontendAction<T> | CatchAllFrontendAction,
157
- dependencies?: any[],
158
- ): void {
159
- const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
160
- const idRef = useRef<string>(randomId());
161
- const renderAndWaitRef = useRef<RenderAndWaitForResponse | null>(null);
162
- const activatingMessageIdRef = useRef<string | null>(null);
163
- const { addToast } = useToast();
164
-
165
- // clone the action to avoid mutating the original object
166
- action = { ...action };
167
-
168
- // const { currentlyActivatingHitlActionMessageIdRef } = useCopilotContext() as any; // <-- REMOVE THIS FOR NOW
144
+ ) {
145
+ if (action.name === "*") {
146
+ return {
147
+ type: "render" as const,
148
+ action: action as UseRenderToolCallArgs<T>,
149
+ };
150
+ }
169
151
 
170
- // If the developer provides a renderAndWaitForResponse function, we transform the action
171
- // to use a promise internally, so that we can treat it like a normal action.
172
- if (
173
- // renderAndWaitForResponse is not available for catch all actions
174
- isFrontendAction(action) &&
175
- // check if renderAndWaitForResponse is set
176
- (action.renderAndWait || action.renderAndWaitForResponse)
177
- ) {
178
- (action as any)._isRenderAndWait = true; // Internal flag to identify this action type later
179
- const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
180
- // remove the renderAndWait function from the action
181
- action.renderAndWait = undefined;
182
- action.renderAndWaitForResponse = undefined;
152
+ if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
153
+ let render = action.render;
154
+ if (!render && "renderAndWaitForResponse" in action) {
155
+ // @ts-expect-error -- renderAndWaitForResponse is deprecated, but we need to support it for backwards compatibility
156
+ render = action.renderAndWaitForResponse;
157
+ }
158
+ if (!render && "renderAndWait" in action) {
159
+ // @ts-expect-error -- renderAndWait is deprecated, but we need to support it for backwards compatibility
160
+ render = action.renderAndWait;
161
+ }
183
162
 
184
- // Add a method for use-chat.ts to set the activating message ID.
185
- // This helps correlate the action instance with the message being processed by use-chat.
186
- (action as any)._setActivatingMessageId = (id: string | null) => {
187
- activatingMessageIdRef.current = id;
163
+ return {
164
+ type: "hitl" as const,
165
+ action: { ...action, render } as UseHumanInTheLoopArgs<T>,
188
166
  };
167
+ }
189
168
 
190
- // add a handler that will be called when the action is executed
191
- action.handler = useAsyncCallback(async () => {
192
- const currentActivatingId = activatingMessageIdRef.current;
193
- // we create a new promise when the handler is called
194
- let resolve: (result: any) => void;
195
- let reject: (error: any) => void;
196
- const promise = new Promise<any>((resolvePromise, rejectPromise) => {
197
- resolve = resolvePromise;
198
- reject = rejectPromise;
199
- });
200
- renderAndWaitRef.current = {
201
- promise,
202
- resolve: resolve!,
203
- reject: reject!,
204
- messageId: currentActivatingId,
169
+ if ("available" in action) {
170
+ if (action.available === "enabled" || action.available === "remote") {
171
+ return {
172
+ type: "frontend" as const,
173
+ action: action as UseFrontendToolArgs<T>,
205
174
  };
206
- // then we await the promise (it will be resolved in the original renderAndWait function)
207
- const result = await promise;
208
- return result;
209
- }, []) as any;
210
-
211
- // add a render function that will be called when the action is rendered
212
- action.render = ((props: ActionRenderProps<T> & { messageId?: string }): React.ReactElement => {
213
- const currentRenderMessageId = props.messageId;
214
- // For renderAndWaitForResponse, the 'executing' state might be set by use-chat before
215
- // this specific action instance's handler (and thus its promise) is ready.
216
- // This logic adjusts the status to 'inProgress' if the current render
217
- // isn't for the actively processing HITL action, preventing premature interaction.
218
- let status = props.status;
219
- if (props.status === "executing") {
220
- if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
221
- status = "inProgress";
222
- } else if (
223
- renderAndWaitRef.current.messageId !== currentRenderMessageId &&
224
- activatingMessageIdRef.current !== currentRenderMessageId
225
- ) {
226
- status = "inProgress";
227
- }
228
- // If conditions met, status remains 'executing'
229
- }
230
- // Create type safe waitProps based on whether T extends empty array or not
231
- const waitProps = {
232
- status,
233
- args: props.args,
234
- result: props.result,
235
- // handler and respond should only be provided if this is the truly active instance
236
- // and its promise infrastructure is ready.
237
- handler:
238
- status === "executing" &&
239
- renderAndWaitRef.current &&
240
- renderAndWaitRef.current.messageId === currentRenderMessageId
241
- ? renderAndWaitRef.current!.resolve
242
- : undefined,
243
- respond:
244
- status === "executing" &&
245
- renderAndWaitRef.current &&
246
- renderAndWaitRef.current.messageId === currentRenderMessageId
247
- ? renderAndWaitRef.current!.resolve
248
- : undefined,
249
- } as T extends [] ? ActionRenderPropsNoArgsWait<T> : ActionRenderPropsWait<T>;
250
-
251
- // Type guard to check if renderAndWait is for no args case
252
- const isNoArgsRenderWait = (
253
- _fn:
254
- | ((props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement)
255
- | ((props: ActionRenderPropsWait<T>) => React.ReactElement),
256
- ): _fn is (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement => {
257
- return action.parameters?.length === 0;
175
+ }
176
+ if (action.available === "frontend" || action.available === "disabled") {
177
+ return {
178
+ type: "render" as const,
179
+ action: action as UseRenderToolCallArgs<T>,
258
180
  };
259
-
260
- // Safely call renderAndWait with correct props type
261
- if (renderAndWait) {
262
- if (isNoArgsRenderWait(renderAndWait)) {
263
- return renderAndWait(waitProps as ActionRenderPropsNoArgsWait<T>);
264
- } else {
265
- return renderAndWait(waitProps as ActionRenderPropsWait<T>);
266
- }
267
- }
268
-
269
- // Return empty Fragment instead of null
270
- return createElement(Fragment);
271
- }) as any;
272
- }
273
-
274
- // If the developer doesn't provide dependencies, we assume they want to
275
- // update handler and render function when the action object changes.
276
- // This ensures that any captured variables in the handler are up to date.
277
- if (dependencies === undefined) {
278
- if (actions[idRef.current]) {
279
- // catch all actions don't have a handler
280
- if (isFrontendAction(action)) {
281
- actions[idRef.current].handler = action.handler as any;
282
- }
283
- if (typeof action.render === "function") {
284
- if (chatComponentsCache.current !== null) {
285
- // TODO: using as any here because the type definitions are getting to tricky
286
- // not wasting time on this now - we know the types are compatible
287
- chatComponentsCache.current.actions[action.name] = action.render as any;
288
- }
289
- }
290
181
  }
291
182
  }
292
183
 
293
- useEffect(() => {
294
- const hasDuplicate = Object.values(actions).some(
295
- (otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current],
296
- );
297
-
298
- if (hasDuplicate) {
299
- addToast({
300
- type: "warning",
301
- message: `Found an already registered action with name ${action.name}.`,
302
- id: `dup-action-${action.name}`,
303
- });
304
- }
305
- }, [actions]);
306
-
307
- useEffect(() => {
308
- setAction(idRef.current, action as any);
309
- if (chatComponentsCache.current !== null && action.render !== undefined) {
310
- // see comment about type safety above
311
- chatComponentsCache.current.actions[action.name] = action.render as any;
312
- }
313
- return () => {
314
- // NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.
315
- // This is because we currently don't have access to the messages array in CopilotContext.
316
- // UPDATE: We now have access, we should remove the entry if not referenced by any message.
317
- removeAction(idRef.current);
184
+ if ("handler" in action) {
185
+ return {
186
+ type: "frontend" as const,
187
+ action: action as UseFrontendToolArgs<T>,
318
188
  };
319
- }, [
320
- setAction,
321
- removeAction,
322
- isFrontendAction(action) ? action.description : undefined,
323
- action.name,
324
- isFrontendAction(action) ? action.disabled : undefined,
325
- isFrontendAction(action) ? action.available : undefined,
326
- // This should be faster than deep equality checking
327
- // In addition, all major JS engines guarantee the order of object keys
328
- JSON.stringify(isFrontendAction(action) ? action.parameters : []),
329
- // include render only if it's a string
330
- typeof action.render === "string" ? action.render : undefined,
331
- // dependencies set by the developer
332
- ...(dependencies || []),
333
- ]);
189
+ }
190
+
191
+ throw new Error("Invalid action configuration");
334
192
  }
335
193
 
336
- function isFrontendAction<T extends Parameter[]>(
194
+ /**
195
+ * useCopilotAction is a legacy hook maintained for backwards compatibility.
196
+ *
197
+ * To avoid violating React's Rules of Hooks (which prohibit conditional hook calls),
198
+ * we use a registration pattern:
199
+ * 1. This hook registers the action configuration with the CopilotContext
200
+ * 2. A renderer component in CopilotKit actually renders the appropriate hook wrapper
201
+ * 3. React properly manages hook state since components are rendered, not conditionally called
202
+ *
203
+ * This allows action types to change between renders without corrupting React's hook state.
204
+ */
205
+ export function useCopilotAction<const T extends Parameter[] | [] = []>(
337
206
  action: FrontendAction<T> | CatchAllFrontendAction,
338
- ): action is FrontendAction<T> {
339
- return action.name !== "*";
340
- }
207
+ dependencies?: any[],
208
+ ): void {
209
+ const [initialActionConfig] = useState(getActionConfig(action));
210
+ const currentActionConfig = getActionConfig(action);
211
+
212
+ /**
213
+ * Calling hooks conditionally violates React's Rules of Hooks. This rule exists because
214
+ * React maintains the call stack for hooks like useEffect or useState, and conditionally
215
+ * calling a hook would result in inconsistent call stacks between renders.
216
+ *
217
+ * Unfortunately, useCopilotAction _has_ to conditionally call a hook based on the
218
+ * supplied parameters. In order to avoid breaking React's call stack tracking, while
219
+ * breaking the Rule of Hooks, we use a ref to store the initial action configuration
220
+ * and throw an error if the _configuration_ changes such that we would call a different hook.
221
+ */
222
+ if (initialActionConfig.type !== currentActionConfig.type) {
223
+ throw new Error("Action configuration changed between renders");
224
+ }
341
225
 
342
- interface RenderAndWaitForResponse {
343
- promise: Promise<any>;
344
- resolve: (result: any) => void;
345
- reject: (error: any) => void;
346
- messageId: string | null;
226
+ switch (currentActionConfig.type) {
227
+ case "render":
228
+ return useRenderToolCall(currentActionConfig.action, dependencies);
229
+ case "hitl":
230
+ return useHumanInTheLoop(currentActionConfig.action, dependencies);
231
+ case "frontend":
232
+ return useFrontendTool(currentActionConfig.action, dependencies);
233
+ default:
234
+ throw new Error("Invalid action configuration");
235
+ }
347
236
  }
@@ -161,7 +161,7 @@
161
161
  import { useEffect } from "react";
162
162
  import { useCopilotContext } from "../context/copilot-context";
163
163
  import {
164
- useCopilotChat as useCopilotChatInternal,
164
+ useCopilotChatInternal,
165
165
  defaultSystemMessage,
166
166
  UseCopilotChatOptions as UseCopilotChatOptions_c,
167
167
  UseCopilotChatReturn as UseCopilotChatReturn_c,
@@ -188,6 +188,7 @@ const createNonFunctionalReturn = (): UseCopilotChatReturn_c => ({
188
188
  stopGeneration: () => {},
189
189
  reset: () => {},
190
190
  isLoading: false,
191
+ isAvailable: false,
191
192
  runChatCompletion: async () => [],
192
193
  mcpServers: [],
193
194
  setMcpServers: () => {},
@@ -75,7 +75,7 @@
75
75
 
76
76
  import {
77
77
  UseCopilotChatOptions,
78
- useCopilotChat as useCopilotChatInternal,
78
+ useCopilotChatInternal,
79
79
  UseCopilotChatReturn as UseCopilotChatReturnInternal,
80
80
  } from "./use-copilot-chat_internal";
81
81
 
@@ -100,6 +100,7 @@ export type UseCopilotChatReturn = Omit<
100
100
  *
101
101
  * **Open Source Friendly** - Works without requiring a `publicApiKey`.
102
102
  */
103
+ // TODO: Do we need this? If so, does it work properly? test.
103
104
  export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotChatReturn {
104
105
  const {
105
106
  visibleMessages,
@@ -108,6 +109,7 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
108
109
  stopGeneration,
109
110
  reset,
110
111
  isLoading,
112
+ isAvailable,
111
113
  runChatCompletion,
112
114
  mcpServers,
113
115
  setMcpServers,
@@ -120,6 +122,7 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
120
122
  stopGeneration,
121
123
  reset,
122
124
  isLoading,
125
+ isAvailable,
123
126
  runChatCompletion,
124
127
  mcpServers,
125
128
  setMcpServers,