@copilotkit/react-core 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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 (497) hide show
  1. package/CHANGELOG.md +4188 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/dist/chunk-2IDV5OHF.mjs +11 -0
  5. package/dist/chunk-2IDV5OHF.mjs.map +1 -0
  6. package/dist/chunk-336QEM3A.mjs +349 -0
  7. package/dist/chunk-336QEM3A.mjs.map +1 -0
  8. package/dist/chunk-36KQV2NA.mjs +1 -0
  9. package/dist/chunk-36KQV2NA.mjs.map +1 -0
  10. package/dist/chunk-3MHWEKFN.mjs +759 -0
  11. package/dist/chunk-3MHWEKFN.mjs.map +1 -0
  12. package/dist/chunk-4CEQJ2X6.mjs +31 -0
  13. package/dist/chunk-4CEQJ2X6.mjs.map +1 -0
  14. package/dist/chunk-4RRMC7L2.mjs +32 -0
  15. package/dist/chunk-4RRMC7L2.mjs.map +1 -0
  16. package/dist/chunk-6ESSSQ7Q.mjs +134 -0
  17. package/dist/chunk-6ESSSQ7Q.mjs.map +1 -0
  18. package/dist/chunk-6PUNP7CD.mjs +102 -0
  19. package/dist/chunk-6PUNP7CD.mjs.map +1 -0
  20. package/dist/chunk-6YOKPWQ7.mjs +1 -0
  21. package/dist/chunk-6YOKPWQ7.mjs.map +1 -0
  22. package/dist/chunk-6ZLPNY7X.mjs +225 -0
  23. package/dist/chunk-6ZLPNY7X.mjs.map +1 -0
  24. package/dist/chunk-7DTB7S5V.mjs +83 -0
  25. package/dist/chunk-7DTB7S5V.mjs.map +1 -0
  26. package/dist/chunk-7IBF6RBW.mjs +23 -0
  27. package/dist/chunk-7IBF6RBW.mjs.map +1 -0
  28. package/dist/chunk-7X3E6GHT.mjs +83 -0
  29. package/dist/chunk-7X3E6GHT.mjs.map +1 -0
  30. package/dist/chunk-A6NKSGH3.mjs +1 -0
  31. package/dist/chunk-A6NKSGH3.mjs.map +1 -0
  32. package/dist/chunk-ABWT4DRT.mjs +24 -0
  33. package/dist/chunk-ABWT4DRT.mjs.map +1 -0
  34. package/dist/chunk-AFNWX62Q.mjs +110 -0
  35. package/dist/chunk-AFNWX62Q.mjs.map +1 -0
  36. package/dist/chunk-BUSWSDYO.mjs +17 -0
  37. package/dist/chunk-BUSWSDYO.mjs.map +1 -0
  38. package/dist/chunk-CDUIA2WM.mjs +60 -0
  39. package/dist/chunk-CDUIA2WM.mjs.map +1 -0
  40. package/dist/chunk-CYDWEPFL.mjs +1 -0
  41. package/dist/chunk-CYDWEPFL.mjs.map +1 -0
  42. package/dist/chunk-DMLQZG75.mjs +25 -0
  43. package/dist/chunk-DMLQZG75.mjs.map +1 -0
  44. package/dist/chunk-E7SE25ZU.mjs +59 -0
  45. package/dist/chunk-E7SE25ZU.mjs.map +1 -0
  46. package/dist/chunk-EFL5OBKN.mjs +310 -0
  47. package/dist/chunk-EFL5OBKN.mjs.map +1 -0
  48. package/dist/chunk-F555TVE4.mjs +33 -0
  49. package/dist/chunk-F555TVE4.mjs.map +1 -0
  50. package/dist/chunk-FD6FGKYY.mjs +1 -0
  51. package/dist/chunk-FD6FGKYY.mjs.map +1 -0
  52. package/dist/chunk-FDOMAPJY.mjs +59 -0
  53. package/dist/chunk-FDOMAPJY.mjs.map +1 -0
  54. package/dist/chunk-GJOR3RI6.mjs +120 -0
  55. package/dist/chunk-GJOR3RI6.mjs.map +1 -0
  56. package/dist/chunk-GPEJNVE5.mjs +80 -0
  57. package/dist/chunk-GPEJNVE5.mjs.map +1 -0
  58. package/dist/chunk-HM6ON7AM.mjs +86 -0
  59. package/dist/chunk-HM6ON7AM.mjs.map +1 -0
  60. package/dist/chunk-I76HKHPJ.mjs +32 -0
  61. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  62. package/dist/chunk-ICIK2BSB.mjs +17 -0
  63. package/dist/chunk-ICIK2BSB.mjs.map +1 -0
  64. package/dist/chunk-JD7BAH7U.mjs +1 -0
  65. package/dist/chunk-JD7BAH7U.mjs.map +1 -0
  66. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  67. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  68. package/dist/chunk-N7FZFIWO.mjs +551 -0
  69. package/dist/chunk-N7FZFIWO.mjs.map +1 -0
  70. package/dist/chunk-NB2FKV2V.mjs +1 -0
  71. package/dist/chunk-NB2FKV2V.mjs.map +1 -0
  72. package/dist/chunk-NBK4KBLX.mjs +54 -0
  73. package/dist/chunk-NBK4KBLX.mjs.map +1 -0
  74. package/dist/chunk-O7ARI5CV.mjs +31 -0
  75. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  76. package/dist/chunk-P2YEE2ZI.mjs +36 -0
  77. package/dist/chunk-P2YEE2ZI.mjs.map +1 -0
  78. package/dist/chunk-PIF5KJYI.mjs +103 -0
  79. package/dist/chunk-PIF5KJYI.mjs.map +1 -0
  80. package/dist/chunk-PMAFHQ7P.mjs +65 -0
  81. package/dist/chunk-PMAFHQ7P.mjs.map +1 -0
  82. package/dist/chunk-QNUAXSDP.mjs +166 -0
  83. package/dist/chunk-QNUAXSDP.mjs.map +1 -0
  84. package/dist/chunk-RKTVJRK7.mjs +143 -0
  85. package/dist/chunk-RKTVJRK7.mjs.map +1 -0
  86. package/dist/chunk-SKC7AJIV.mjs +61 -0
  87. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  88. package/dist/chunk-SPCZTZCY.mjs +1 -0
  89. package/dist/chunk-SPCZTZCY.mjs.map +1 -0
  90. package/dist/chunk-SQDOUMPZ.mjs +125 -0
  91. package/dist/chunk-SQDOUMPZ.mjs.map +1 -0
  92. package/dist/chunk-WF65O6HX.mjs +66 -0
  93. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  94. package/dist/chunk-XDFVCQD3.mjs +27 -0
  95. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  96. package/dist/chunk-YJ2KZDZJ.mjs +186 -0
  97. package/dist/chunk-YJ2KZDZJ.mjs.map +1 -0
  98. package/dist/chunk-YTQHRJUA.mjs +86 -0
  99. package/dist/chunk-YTQHRJUA.mjs.map +1 -0
  100. package/dist/chunk-YYN33GSG.mjs +73 -0
  101. package/dist/chunk-YYN33GSG.mjs.map +1 -0
  102. package/dist/chunk-Z6JV2LRY.mjs +37 -0
  103. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  104. package/dist/chunk-ZVF5Q6IH.mjs +29 -0
  105. package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
  106. package/dist/chunk-ZYTXB6HH.mjs +151 -0
  107. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  108. package/dist/components/CopilotListeners.d.ts +3 -0
  109. package/dist/components/CopilotListeners.js +101 -0
  110. package/dist/components/CopilotListeners.js.map +1 -0
  111. package/dist/components/CopilotListeners.mjs +9 -0
  112. package/dist/components/CopilotListeners.mjs.map +1 -0
  113. package/dist/components/copilot-provider/copilot-messages.d.ts +24 -0
  114. package/dist/components/copilot-provider/copilot-messages.js +351 -0
  115. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  116. package/dist/components/copilot-provider/copilot-messages.mjs +16 -0
  117. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  118. package/dist/components/copilot-provider/copilotkit-props.d.ts +160 -0
  119. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  120. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  121. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  122. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  123. package/dist/components/copilot-provider/copilotkit.d.ts +19 -0
  124. package/dist/components/copilot-provider/copilotkit.js +1960 -0
  125. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  126. package/dist/components/copilot-provider/copilotkit.mjs +31 -0
  127. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  128. package/dist/components/copilot-provider/index.d.ts +14 -0
  129. package/dist/components/copilot-provider/index.js +1960 -0
  130. package/dist/components/copilot-provider/index.js.map +1 -0
  131. package/dist/components/copilot-provider/index.mjs +30 -0
  132. package/dist/components/copilot-provider/index.mjs.map +1 -0
  133. package/dist/components/dev-console/console-trigger.d.ts +8 -0
  134. package/dist/components/dev-console/console-trigger.js +1202 -0
  135. package/dist/components/dev-console/console-trigger.js.map +1 -0
  136. package/dist/components/dev-console/console-trigger.mjs +233 -0
  137. package/dist/components/dev-console/console-trigger.mjs.map +1 -0
  138. package/dist/components/dev-console/developer-console-modal.d.ts +10 -0
  139. package/dist/components/dev-console/developer-console-modal.js +987 -0
  140. package/dist/components/dev-console/developer-console-modal.js.map +1 -0
  141. package/dist/components/dev-console/developer-console-modal.mjs +12 -0
  142. package/dist/components/dev-console/developer-console-modal.mjs.map +1 -0
  143. package/dist/components/dev-console/icons.d.ts +9 -0
  144. package/dist/components/dev-console/icons.js +131 -0
  145. package/dist/components/dev-console/icons.js.map +1 -0
  146. package/dist/components/dev-console/icons.mjs +16 -0
  147. package/dist/components/dev-console/icons.mjs.map +1 -0
  148. package/dist/components/error-boundary/error-boundary.d.ts +31 -0
  149. package/dist/components/error-boundary/error-boundary.js +500 -0
  150. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  151. package/dist/components/error-boundary/error-boundary.mjs +15 -0
  152. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  153. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  154. package/dist/components/error-boundary/error-utils.js +190 -0
  155. package/dist/components/error-boundary/error-utils.js.map +1 -0
  156. package/dist/components/error-boundary/error-utils.mjs +14 -0
  157. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  158. package/dist/components/index.d.ts +14 -0
  159. package/dist/components/index.js +1960 -0
  160. package/dist/components/index.js.map +1 -0
  161. package/dist/components/index.mjs +31 -0
  162. package/dist/components/index.mjs.map +1 -0
  163. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  164. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  165. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  166. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  167. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  168. package/dist/components/toast/toast-provider.d.ts +27 -0
  169. package/dist/components/toast/toast-provider.js +347 -0
  170. package/dist/components/toast/toast-provider.js.map +1 -0
  171. package/dist/components/toast/toast-provider.mjs +10 -0
  172. package/dist/components/toast/toast-provider.mjs.map +1 -0
  173. package/dist/components/usage-banner.d.ts +29 -0
  174. package/dist/components/usage-banner.js +247 -0
  175. package/dist/components/usage-banner.js.map +1 -0
  176. package/dist/components/usage-banner.mjs +12 -0
  177. package/dist/components/usage-banner.mjs.map +1 -0
  178. package/dist/context/coagent-state-renders-context.d.ts +24 -0
  179. package/dist/context/coagent-state-renders-context.js +91 -0
  180. package/dist/context/coagent-state-renders-context.js.map +1 -0
  181. package/dist/context/coagent-state-renders-context.mjs +12 -0
  182. package/dist/context/coagent-state-renders-context.mjs.map +1 -0
  183. package/dist/context/copilot-context.d.ts +10 -0
  184. package/dist/context/copilot-context.js +161 -0
  185. package/dist/context/copilot-context.js.map +1 -0
  186. package/dist/context/copilot-context.mjs +10 -0
  187. package/dist/context/copilot-context.mjs.map +1 -0
  188. package/dist/context/copilot-messages-context.d.ts +18 -0
  189. package/dist/context/copilot-messages-context.js +60 -0
  190. package/dist/context/copilot-messages-context.js.map +1 -0
  191. package/dist/context/copilot-messages-context.mjs +10 -0
  192. package/dist/context/copilot-messages-context.mjs.map +1 -0
  193. package/dist/context/index.d.ts +15 -0
  194. package/dist/context/index.js +285 -0
  195. package/dist/context/index.js.map +1 -0
  196. package/dist/context/index.mjs +33 -0
  197. package/dist/context/index.mjs.map +1 -0
  198. package/dist/context/threads-context.d.ts +16 -0
  199. package/dist/context/threads-context.js +59 -0
  200. package/dist/context/threads-context.js.map +1 -0
  201. package/dist/context/threads-context.mjs +12 -0
  202. package/dist/context/threads-context.mjs.map +1 -0
  203. package/dist/copilot-context-ec77e921.d.ts +209 -0
  204. package/dist/hooks/index.d.ts +33 -0
  205. package/dist/hooks/index.js +1774 -0
  206. package/dist/hooks/index.js.map +1 -0
  207. package/dist/hooks/index.mjs +91 -0
  208. package/dist/hooks/index.mjs.map +1 -0
  209. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  210. package/dist/hooks/use-agent-nodename.js +56 -0
  211. package/dist/hooks/use-agent-nodename.js.map +1 -0
  212. package/dist/hooks/use-agent-nodename.mjs +8 -0
  213. package/dist/hooks/use-agent-nodename.mjs.map +1 -0
  214. package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
  215. package/dist/hooks/use-coagent-state-render-bridge.js +214 -0
  216. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
  217. package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
  218. package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
  219. package/dist/hooks/use-coagent-state-render.d.ts +55 -0
  220. package/dist/hooks/use-coagent-state-render.js +255 -0
  221. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  222. package/dist/hooks/use-coagent-state-render.mjs +11 -0
  223. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  224. package/dist/hooks/use-coagent.d.ts +192 -0
  225. package/dist/hooks/use-coagent.js +233 -0
  226. package/dist/hooks/use-coagent.js.map +1 -0
  227. package/dist/hooks/use-coagent.mjs +9 -0
  228. package/dist/hooks/use-coagent.mjs.map +1 -0
  229. package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
  230. package/dist/hooks/use-configure-chat-suggestions.js +79 -0
  231. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
  232. package/dist/hooks/use-configure-chat-suggestions.mjs +47 -0
  233. package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
  234. package/dist/hooks/use-copilot-action.d.ts +103 -0
  235. package/dist/hooks/use-copilot-action.js +295 -0
  236. package/dist/hooks/use-copilot-action.js.map +1 -0
  237. package/dist/hooks/use-copilot-action.mjs +11 -0
  238. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  239. package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
  240. package/dist/hooks/use-copilot-additional-instructions.js +177 -0
  241. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
  242. package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
  243. package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
  244. package/dist/hooks/use-copilot-authenticated-action.d.ts +18 -0
  245. package/dist/hooks/use-copilot-authenticated-action.js +462 -0
  246. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
  247. package/dist/hooks/use-copilot-authenticated-action.mjs +13 -0
  248. package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
  249. package/dist/hooks/use-copilot-chat-headless_c.d.ts +25 -0
  250. package/dist/hooks/use-copilot-chat-headless_c.js +1044 -0
  251. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -0
  252. package/dist/hooks/use-copilot-chat-headless_c.mjs +24 -0
  253. package/dist/hooks/use-copilot-chat-headless_c.mjs.map +1 -0
  254. package/dist/hooks/use-copilot-chat-suggestions.d.ts +35 -0
  255. package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
  256. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  257. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  258. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
  259. package/dist/hooks/use-copilot-chat.d.ts +92 -0
  260. package/dist/hooks/use-copilot-chat.js +978 -0
  261. package/dist/hooks/use-copilot-chat.js.map +1 -0
  262. package/dist/hooks/use-copilot-chat.mjs +21 -0
  263. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  264. package/dist/hooks/use-copilot-chat_internal.d.ts +244 -0
  265. package/dist/hooks/use-copilot-chat_internal.js +976 -0
  266. package/dist/hooks/use-copilot-chat_internal.js.map +1 -0
  267. package/dist/hooks/use-copilot-chat_internal.mjs +22 -0
  268. package/dist/hooks/use-copilot-chat_internal.mjs.map +1 -0
  269. package/dist/hooks/use-copilot-readable.d.ts +37 -0
  270. package/dist/hooks/use-copilot-readable.js +61 -0
  271. package/dist/hooks/use-copilot-readable.js.map +1 -0
  272. package/dist/hooks/use-copilot-readable.mjs +8 -0
  273. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  274. package/dist/hooks/use-copilot-runtime-client.d.ts +10 -0
  275. package/dist/hooks/use-copilot-runtime-client.js +203 -0
  276. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  277. package/dist/hooks/use-copilot-runtime-client.mjs +9 -0
  278. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  279. package/dist/hooks/use-default-tool.d.ts +8 -0
  280. package/dist/hooks/use-default-tool.js +302 -0
  281. package/dist/hooks/use-default-tool.js.map +1 -0
  282. package/dist/hooks/use-default-tool.mjs +12 -0
  283. package/dist/hooks/use-default-tool.mjs.map +1 -0
  284. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  285. package/dist/hooks/use-flat-category-store.js +93 -0
  286. package/dist/hooks/use-flat-category-store.js.map +1 -0
  287. package/dist/hooks/use-flat-category-store.mjs +8 -0
  288. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  289. package/dist/hooks/use-frontend-tool.d.ts +11 -0
  290. package/dist/hooks/use-frontend-tool.js +104 -0
  291. package/dist/hooks/use-frontend-tool.js.map +1 -0
  292. package/dist/hooks/use-frontend-tool.mjs +8 -0
  293. package/dist/hooks/use-frontend-tool.mjs.map +1 -0
  294. package/dist/hooks/use-human-in-the-loop.d.ts +13 -0
  295. package/dist/hooks/use-human-in-the-loop.js +122 -0
  296. package/dist/hooks/use-human-in-the-loop.js.map +1 -0
  297. package/dist/hooks/use-human-in-the-loop.mjs +8 -0
  298. package/dist/hooks/use-human-in-the-loop.mjs.map +1 -0
  299. package/dist/hooks/use-langgraph-interrupt-render.d.ts +6 -0
  300. package/dist/hooks/use-langgraph-interrupt-render.js +318 -0
  301. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -0
  302. package/dist/hooks/use-langgraph-interrupt-render.mjs +14 -0
  303. package/dist/hooks/use-langgraph-interrupt-render.mjs.map +1 -0
  304. package/dist/hooks/use-langgraph-interrupt.d.ts +14 -0
  305. package/dist/hooks/use-langgraph-interrupt.js +201 -0
  306. package/dist/hooks/use-langgraph-interrupt.js.map +1 -0
  307. package/dist/hooks/use-langgraph-interrupt.mjs +10 -0
  308. package/dist/hooks/use-langgraph-interrupt.mjs.map +1 -0
  309. package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
  310. package/dist/hooks/use-lazy-tool-renderer.js +53 -0
  311. package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
  312. package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
  313. package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
  314. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  315. package/dist/hooks/use-make-copilot-document-readable.js +176 -0
  316. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  317. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  318. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  319. package/dist/hooks/use-render-tool-call.d.ts +12 -0
  320. package/dist/hooks/use-render-tool-call.js +90 -0
  321. package/dist/hooks/use-render-tool-call.js.map +1 -0
  322. package/dist/hooks/use-render-tool-call.mjs +8 -0
  323. package/dist/hooks/use-render-tool-call.mjs.map +1 -0
  324. package/dist/hooks/use-tree.d.ts +19 -0
  325. package/dist/hooks/use-tree.js +175 -0
  326. package/dist/hooks/use-tree.js.map +1 -0
  327. package/dist/hooks/use-tree.mjs +8 -0
  328. package/dist/hooks/use-tree.mjs.map +1 -0
  329. package/dist/index.d.ts +43 -0
  330. package/dist/index.js +3528 -0
  331. package/dist/index.js.map +1 -0
  332. package/dist/index.mjs +149 -0
  333. package/dist/index.mjs.map +1 -0
  334. package/dist/lib/copilot-task.d.ts +97 -0
  335. package/dist/lib/copilot-task.js +194 -0
  336. package/dist/lib/copilot-task.js.map +1 -0
  337. package/dist/lib/copilot-task.mjs +31 -0
  338. package/dist/lib/copilot-task.mjs.map +1 -0
  339. package/dist/lib/index.d.ts +11 -0
  340. package/dist/lib/index.js +196 -0
  341. package/dist/lib/index.js.map +1 -0
  342. package/dist/lib/index.mjs +32 -0
  343. package/dist/lib/index.mjs.map +1 -0
  344. package/dist/lib/status-checker.d.ts +17 -0
  345. package/dist/lib/status-checker.js +102 -0
  346. package/dist/lib/status-checker.js.map +1 -0
  347. package/dist/lib/status-checker.mjs +8 -0
  348. package/dist/lib/status-checker.mjs.map +1 -0
  349. package/dist/setupTests.d.ts +2 -0
  350. package/dist/setupTests.js +26 -0
  351. package/dist/setupTests.js.map +1 -0
  352. package/dist/setupTests.mjs +24 -0
  353. package/dist/setupTests.mjs.map +1 -0
  354. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  355. package/dist/types/chat-suggestion-configuration.js +19 -0
  356. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  357. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  358. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  359. package/dist/types/coagent-action.d.ts +29 -0
  360. package/dist/types/coagent-action.js +19 -0
  361. package/dist/types/coagent-action.js.map +1 -0
  362. package/dist/types/coagent-action.mjs +1 -0
  363. package/dist/types/coagent-action.mjs.map +1 -0
  364. package/dist/types/coagent-state.d.ts +15 -0
  365. package/dist/types/coagent-state.js +19 -0
  366. package/dist/types/coagent-state.js.map +1 -0
  367. package/dist/types/coagent-state.mjs +1 -0
  368. package/dist/types/coagent-state.mjs.map +1 -0
  369. package/dist/types/crew.d.ts +79 -0
  370. package/dist/types/crew.js +19 -0
  371. package/dist/types/crew.js.map +1 -0
  372. package/dist/types/crew.mjs +2 -0
  373. package/dist/types/crew.mjs.map +1 -0
  374. package/dist/types/document-pointer.d.ts +9 -0
  375. package/dist/types/document-pointer.js +19 -0
  376. package/dist/types/document-pointer.js.map +1 -0
  377. package/dist/types/document-pointer.mjs +1 -0
  378. package/dist/types/document-pointer.mjs.map +1 -0
  379. package/dist/types/frontend-action.d.ts +127 -0
  380. package/dist/types/frontend-action.js +53 -0
  381. package/dist/types/frontend-action.js.map +1 -0
  382. package/dist/types/frontend-action.mjs +8 -0
  383. package/dist/types/frontend-action.mjs.map +1 -0
  384. package/dist/types/index.d.ts +12 -0
  385. package/dist/types/index.js +19 -0
  386. package/dist/types/index.js.map +1 -0
  387. package/dist/types/index.mjs +4 -0
  388. package/dist/types/index.mjs.map +1 -0
  389. package/dist/types/interrupt-action.d.ts +10 -0
  390. package/dist/types/interrupt-action.js +19 -0
  391. package/dist/types/interrupt-action.js.map +1 -0
  392. package/dist/types/interrupt-action.mjs +2 -0
  393. package/dist/types/interrupt-action.mjs.map +1 -0
  394. package/dist/types/system-message.d.ts +3 -0
  395. package/dist/types/system-message.js +19 -0
  396. package/dist/types/system-message.js.map +1 -0
  397. package/dist/types/system-message.mjs +1 -0
  398. package/dist/types/system-message.mjs.map +1 -0
  399. package/dist/utils/dev-console.d.ts +3 -0
  400. package/dist/utils/dev-console.js +41 -0
  401. package/dist/utils/dev-console.js.map +1 -0
  402. package/dist/utils/dev-console.mjs +8 -0
  403. package/dist/utils/dev-console.mjs.map +1 -0
  404. package/dist/utils/index.d.ts +2 -0
  405. package/dist/utils/index.js +52 -0
  406. package/dist/utils/index.js.map +1 -0
  407. package/dist/utils/index.mjs +13 -0
  408. package/dist/utils/index.mjs.map +1 -0
  409. package/dist/utils/suggestions-constants.d.ts +9 -0
  410. package/dist/utils/suggestions-constants.js +35 -0
  411. package/dist/utils/suggestions-constants.js.map +1 -0
  412. package/dist/utils/suggestions-constants.mjs +8 -0
  413. package/dist/utils/suggestions-constants.mjs.map +1 -0
  414. package/dist/utils/utils.d.ts +2 -0
  415. package/dist/utils/utils.js +19 -0
  416. package/dist/utils/utils.js.map +1 -0
  417. package/dist/utils/utils.mjs +1 -0
  418. package/dist/utils/utils.mjs.map +1 -0
  419. package/dist/v2/index.css +4 -0
  420. package/dist/v2/index.css.map +1 -0
  421. package/dist/v2/index.d.ts +2 -0
  422. package/dist/v2/index.js +27 -0
  423. package/dist/v2/index.js.map +1 -0
  424. package/dist/v2/index.mjs +6 -0
  425. package/dist/v2/index.mjs.map +1 -0
  426. package/jest.config.js +25 -0
  427. package/package.json +92 -0
  428. package/src/components/CopilotListeners.tsx +81 -0
  429. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +75 -0
  430. package/src/components/copilot-provider/copilot-messages.tsx +274 -0
  431. package/src/components/copilot-provider/copilotkit-props.tsx +169 -0
  432. package/src/components/copilot-provider/copilotkit.tsx +671 -0
  433. package/src/components/copilot-provider/index.ts +3 -0
  434. package/src/components/dev-console/console-trigger.tsx +254 -0
  435. package/src/components/dev-console/developer-console-modal.tsx +866 -0
  436. package/src/components/dev-console/icons.tsx +101 -0
  437. package/src/components/error-boundary/error-boundary.tsx +91 -0
  438. package/src/components/error-boundary/error-utils.tsx +100 -0
  439. package/src/components/index.ts +1 -0
  440. package/src/components/toast/exclamation-mark-icon.tsx +27 -0
  441. package/src/components/toast/toast-provider.tsx +363 -0
  442. package/src/components/usage-banner.tsx +259 -0
  443. package/src/context/coagent-state-renders-context.tsx +76 -0
  444. package/src/context/copilot-context.tsx +332 -0
  445. package/src/context/copilot-messages-context.tsx +35 -0
  446. package/src/context/index.ts +16 -0
  447. package/src/context/threads-context.tsx +41 -0
  448. package/src/hooks/__tests__/use-coagent-config.test.ts +351 -0
  449. package/src/hooks/index.ts +34 -0
  450. package/src/hooks/use-agent-nodename.ts +30 -0
  451. package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
  452. package/src/hooks/use-coagent-state-render.ts +152 -0
  453. package/src/hooks/use-coagent.ts +366 -0
  454. package/src/hooks/use-configure-chat-suggestions.tsx +86 -0
  455. package/src/hooks/use-copilot-action.ts +236 -0
  456. package/src/hooks/use-copilot-additional-instructions.ts +85 -0
  457. package/src/hooks/use-copilot-authenticated-action.ts +70 -0
  458. package/src/hooks/use-copilot-chat-headless_c.ts +258 -0
  459. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  460. package/src/hooks/use-copilot-chat.ts +130 -0
  461. package/src/hooks/use-copilot-chat_internal.ts +696 -0
  462. package/src/hooks/use-copilot-readable.ts +135 -0
  463. package/src/hooks/use-copilot-runtime-client.ts +164 -0
  464. package/src/hooks/use-default-tool.ts +7 -0
  465. package/src/hooks/use-flat-category-store.ts +105 -0
  466. package/src/hooks/use-frontend-tool.ts +96 -0
  467. package/src/hooks/use-human-in-the-loop.ts +122 -0
  468. package/src/hooks/use-langgraph-interrupt-render.ts +136 -0
  469. package/src/hooks/use-langgraph-interrupt.ts +36 -0
  470. package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
  471. package/src/hooks/use-make-copilot-document-readable.ts +30 -0
  472. package/src/hooks/use-render-tool-call.ts +80 -0
  473. package/src/hooks/use-tree.ts +207 -0
  474. package/src/index.tsx +7 -0
  475. package/src/lib/copilot-task.ts +201 -0
  476. package/src/lib/index.ts +1 -0
  477. package/src/lib/status-checker.ts +64 -0
  478. package/src/setupTests.ts +26 -0
  479. package/src/types/chat-suggestion-configuration.ts +23 -0
  480. package/src/types/coagent-action.ts +31 -0
  481. package/src/types/coagent-state.ts +13 -0
  482. package/src/types/crew.ts +89 -0
  483. package/src/types/document-pointer.ts +7 -0
  484. package/src/types/frontend-action.ts +202 -0
  485. package/src/types/index.ts +17 -0
  486. package/src/types/interrupt-action.ts +43 -0
  487. package/src/types/system-message.ts +4 -0
  488. package/src/utils/dev-console.ts +19 -0
  489. package/src/utils/index.ts +2 -0
  490. package/src/utils/suggestions-constants.ts +8 -0
  491. package/src/utils/utils.test.ts +7 -0
  492. package/src/utils/utils.ts +8 -0
  493. package/src/v2/index.css +1 -0
  494. package/src/v2/index.ts +4 -0
  495. package/tsconfig.json +8 -0
  496. package/tsup.config.ts +16 -0
  497. package/typedoc.json +4 -0
@@ -0,0 +1,135 @@
1
+ /**
2
+ * `useCopilotReadable` is a React hook that provides app-state and other information
3
+ * to the Copilot. Optionally, the hook can also handle hierarchical state within your
4
+ * application, passing these parent-child relationships to the Copilot.
5
+ *
6
+ * ## Usage
7
+ *
8
+ * ### Simple Usage
9
+ *
10
+ * In its most basic usage, useCopilotReadable accepts a single string argument
11
+ * representing any piece of app state, making it available for the Copilot to use
12
+ * as context when responding to user input.
13
+ *
14
+ * ```tsx
15
+ * import { useCopilotReadable } from "@copilotkit/react-core";
16
+ *
17
+ * export function MyComponent() {
18
+ * const [employees, setEmployees] = useState([]);
19
+ *
20
+ * useCopilotReadable({
21
+ * description: "The list of employees",
22
+ * value: employees,
23
+ * });
24
+ * }
25
+ * ```
26
+ *
27
+ * ### Nested Components
28
+ *
29
+ * Optionally, you can maintain the hierarchical structure of information by passing
30
+ * `parentId`. This allows you to use `useCopilotReadable` in nested components:
31
+ *
32
+ * ```tsx /employeeContextId/1 {17,23}
33
+ * import { useCopilotReadable } from "@copilotkit/react-core";
34
+ *
35
+ * function Employee(props: EmployeeProps) {
36
+ * const { employeeName, workProfile, metadata } = props;
37
+ *
38
+ * // propagate any information to copilot
39
+ * const employeeContextId = useCopilotReadable({
40
+ * description: "Employee name",
41
+ * value: employeeName
42
+ * });
43
+ *
44
+ * // Pass a parentID to maintain a hierarchical structure.
45
+ * // Especially useful with child React components, list elements, etc.
46
+ * useCopilotReadable({
47
+ * description: "Work profile",
48
+ * value: workProfile.description(),
49
+ * parentId: employeeContextId
50
+ * });
51
+ *
52
+ * useCopilotReadable({
53
+ * description: "Employee metadata",
54
+ * value: metadata.description(),
55
+ * parentId: employeeContextId
56
+ * });
57
+ *
58
+ * return (
59
+ * // Render as usual...
60
+ * );
61
+ * }
62
+ * ```
63
+ */
64
+ import { useCopilotKit } from "@copilotkitnext/react";
65
+ import { useEffect, useRef } from "react";
66
+
67
+ /**
68
+ * Options for the useCopilotReadable hook.
69
+ */
70
+ export interface UseCopilotReadableOptions {
71
+ /**
72
+ * The description of the information to be added to the Copilot context.
73
+ */
74
+ description: string;
75
+ /**
76
+ * The value to be added to the Copilot context. Object values are automatically stringified.
77
+ */
78
+ value: any;
79
+ /**
80
+ * The ID of the parent context, if any.
81
+ */
82
+ parentId?: string;
83
+ /**
84
+ * An array of categories to control which context are visible where. Particularly useful
85
+ * with CopilotTextarea (see `useMakeAutosuggestionFunction`)
86
+ */
87
+ categories?: string[];
88
+
89
+ /**
90
+ * Whether the context is available to the Copilot.
91
+ */
92
+ available?: "enabled" | "disabled";
93
+
94
+ /**
95
+ * A custom conversion function to use to serialize the value to a string. If not provided, the value
96
+ * will be serialized using `JSON.stringify`.
97
+ */
98
+ convert?: (description: string, value: any) => string;
99
+ }
100
+
101
+ /**
102
+ * Adds the given information to the Copilot context to make it readable by Copilot.
103
+ */
104
+ export function useCopilotReadable(
105
+ { description, value, convert, available }: UseCopilotReadableOptions,
106
+ dependencies?: any[],
107
+ ): string | undefined {
108
+ const { copilotkit } = useCopilotKit();
109
+ const ctxIdRef = useRef<string | undefined>(undefined);
110
+ useEffect(() => {
111
+ if (!copilotkit) return;
112
+
113
+ const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
114
+ return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
115
+ });
116
+ if (found) {
117
+ ctxIdRef.current = found[0];
118
+ if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
119
+ return;
120
+ }
121
+ if (!found && available === "disabled") return;
122
+
123
+ ctxIdRef.current = copilotkit.addContext({
124
+ description,
125
+ value: (convert ?? JSON.stringify)(value),
126
+ });
127
+
128
+ return () => {
129
+ if (!ctxIdRef.current) return;
130
+ copilotkit.removeContext(ctxIdRef.current);
131
+ };
132
+ }, [description, value, convert]);
133
+
134
+ return ctxIdRef.current;
135
+ }
@@ -0,0 +1,164 @@
1
+ import {
2
+ CopilotRuntimeClient,
3
+ CopilotRuntimeClientOptions,
4
+ GraphQLError,
5
+ } from "@copilotkit/runtime-client-gql";
6
+ import { useToast } from "../components/toast/toast-provider";
7
+ import { useMemo, useRef } from "react";
8
+ import {
9
+ ErrorVisibility,
10
+ CopilotKitApiDiscoveryError,
11
+ CopilotKitRemoteEndpointDiscoveryError,
12
+ CopilotKitAgentDiscoveryError,
13
+ CopilotKitError,
14
+ CopilotKitErrorCode,
15
+ CopilotErrorHandler,
16
+ CopilotErrorEvent,
17
+ } from "@copilotkit/shared";
18
+ import { shouldShowDevConsole } from "../utils/dev-console";
19
+
20
+ export interface CopilotRuntimeClientHookOptions extends CopilotRuntimeClientOptions {
21
+ showDevConsole?: boolean;
22
+ onError: CopilotErrorHandler;
23
+ }
24
+
25
+ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions) => {
26
+ const { setBannerError } = useToast();
27
+ const { showDevConsole, onError, ...runtimeOptions } = options;
28
+
29
+ // Deduplication state for structured errors
30
+ const lastStructuredErrorRef = useRef<{ message: string; timestamp: number } | null>(null);
31
+
32
+ // Helper function to trace UI errors
33
+ const traceUIError = async (error: CopilotKitError, originalError?: any) => {
34
+ try {
35
+ const errorEvent: CopilotErrorEvent = {
36
+ type: "error",
37
+ timestamp: Date.now(),
38
+ context: {
39
+ source: "ui",
40
+ request: {
41
+ operation: "runtimeClient",
42
+ url: runtimeOptions.url,
43
+ startTime: Date.now(),
44
+ },
45
+ technical: {
46
+ environment: "browser",
47
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : undefined,
48
+ stackTrace: originalError instanceof Error ? originalError.stack : undefined,
49
+ },
50
+ },
51
+ error,
52
+ };
53
+ await onError(errorEvent);
54
+ } catch (error) {
55
+ console.error("Error in onError handler:", error);
56
+ }
57
+ };
58
+
59
+ const runtimeClient = useMemo(() => {
60
+ return new CopilotRuntimeClient({
61
+ ...runtimeOptions,
62
+ handleGQLErrors: (error) => {
63
+ if ((error as any).graphQLErrors?.length) {
64
+ const graphQLErrors = (error as any).graphQLErrors as GraphQLError[];
65
+
66
+ // Route all errors to banners for consistent UI
67
+ const routeError = (gqlError: GraphQLError) => {
68
+ const extensions = gqlError.extensions;
69
+ const visibility = extensions?.visibility as ErrorVisibility;
70
+
71
+ // Silent errors - just log
72
+ if (visibility === ErrorVisibility.SILENT) {
73
+ console.error("CopilotKit Silent Error:", gqlError.message);
74
+ return;
75
+ }
76
+
77
+ // All errors (including DEV_ONLY) show as banners for consistency
78
+ // Deduplicate to prevent spam
79
+ const now = Date.now();
80
+ const errorMessage = gqlError.message;
81
+ if (
82
+ lastStructuredErrorRef.current &&
83
+ lastStructuredErrorRef.current.message === errorMessage &&
84
+ now - lastStructuredErrorRef.current.timestamp < 150
85
+ ) {
86
+ return; // Skip duplicate
87
+ }
88
+ lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
89
+
90
+ const ckError = createStructuredError(gqlError);
91
+ if (ckError) {
92
+ setBannerError(ckError);
93
+ // Trace the error
94
+ traceUIError(ckError, gqlError);
95
+ // TODO: if onError & renderError should work without key, insert here
96
+ } else {
97
+ // Fallback for unstructured errors
98
+ const fallbackError = new CopilotKitError({
99
+ message: gqlError.message,
100
+ code: CopilotKitErrorCode.UNKNOWN,
101
+ });
102
+ setBannerError(fallbackError);
103
+ // Trace the fallback error
104
+ traceUIError(fallbackError, gqlError);
105
+ // TODO: if onError & renderError should work without key, insert here
106
+ }
107
+ };
108
+
109
+ // Process all errors as banners
110
+ graphQLErrors.forEach(routeError);
111
+ } else {
112
+ // Route non-GraphQL errors to banner as well
113
+ const fallbackError = new CopilotKitError({
114
+ message: error?.message || String(error),
115
+ code: CopilotKitErrorCode.UNKNOWN,
116
+ });
117
+ setBannerError(fallbackError);
118
+ // Trace the non-GraphQL error
119
+ traceUIError(fallbackError, error);
120
+ // TODO: if onError & renderError should work without key, insert here
121
+ }
122
+ },
123
+ handleGQLWarning: (message: string) => {
124
+ console.warn(message);
125
+ // Show warnings as banners too for consistency
126
+ const warningError = new CopilotKitError({
127
+ message,
128
+ code: CopilotKitErrorCode.UNKNOWN,
129
+ });
130
+ setBannerError(warningError);
131
+ },
132
+ });
133
+ }, [runtimeOptions, setBannerError, onError]);
134
+
135
+ return runtimeClient;
136
+ };
137
+
138
+ // Create appropriate structured error from GraphQL error
139
+ function createStructuredError(gqlError: GraphQLError): CopilotKitError | null {
140
+ const extensions = gqlError.extensions;
141
+ const originalError = extensions?.originalError as any;
142
+ const message = originalError?.message || gqlError.message;
143
+ const code = extensions?.code as CopilotKitErrorCode;
144
+
145
+ if (code) {
146
+ return new CopilotKitError({ message, code });
147
+ }
148
+
149
+ // Legacy error detection by stack trace
150
+ if (originalError?.stack?.includes("CopilotApiDiscoveryError")) {
151
+ return new CopilotKitApiDiscoveryError({ message });
152
+ }
153
+ if (originalError?.stack?.includes("CopilotKitRemoteEndpointDiscoveryError")) {
154
+ return new CopilotKitRemoteEndpointDiscoveryError({ message });
155
+ }
156
+ if (originalError?.stack?.includes("CopilotKitAgentDiscoveryError")) {
157
+ return new CopilotKitAgentDiscoveryError({
158
+ agentName: "",
159
+ availableAgents: [],
160
+ });
161
+ }
162
+
163
+ return null;
164
+ }
@@ -0,0 +1,7 @@
1
+ import { useCopilotAction } from "./use-copilot-action";
2
+ import { CatchAllFrontendAction } from "../types/frontend-action";
3
+
4
+ export function useDefaultTool(tool: Omit<CatchAllFrontendAction, "name">, dependencies?: any[]) {
5
+ // Use the existing useCopilotAction hook
6
+ useCopilotAction({ ...tool, name: "*" } satisfies CatchAllFrontendAction, dependencies);
7
+ }
@@ -0,0 +1,105 @@
1
+ import { useCallback, useReducer } from "react";
2
+ import { randomId } from "@copilotkit/shared";
3
+
4
+ export type FlatCategoryStoreId = string;
5
+
6
+ export interface UseFlatCategoryStoreReturn<T> {
7
+ addElement: (value: T, categories: string[]) => FlatCategoryStoreId;
8
+ removeElement: (id: FlatCategoryStoreId) => void;
9
+ allElements: (categories: string[]) => T[];
10
+ }
11
+
12
+ interface FlatCategoryStoreElement<T> {
13
+ id: FlatCategoryStoreId;
14
+ value: T;
15
+ categories: Set<string>;
16
+ }
17
+
18
+ const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
19
+ const [elements, dispatch] = useReducer(
20
+ flatCategoryStoreReducer<T>,
21
+ new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>(),
22
+ );
23
+
24
+ const addElement = useCallback((value: T, categories: string[]): FlatCategoryStoreId => {
25
+ const newId = randomId();
26
+ dispatch({
27
+ type: "ADD_ELEMENT",
28
+ value,
29
+ id: newId,
30
+ categories,
31
+ });
32
+ return newId;
33
+ }, []);
34
+
35
+ const removeElement = useCallback((id: FlatCategoryStoreId): void => {
36
+ dispatch({ type: "REMOVE_ELEMENT", id });
37
+ }, []);
38
+
39
+ const allElements = useCallback(
40
+ (categories: string[]): T[] => {
41
+ const categoriesSet = new Set(categories);
42
+ const result: T[] = [];
43
+ elements.forEach((element) => {
44
+ if (setsHaveIntersection(categoriesSet, element.categories)) {
45
+ result.push(element.value);
46
+ }
47
+ });
48
+ return result;
49
+ },
50
+ [elements],
51
+ );
52
+
53
+ return { addElement, removeElement, allElements };
54
+ };
55
+
56
+ export default useFlatCategoryStore;
57
+
58
+ // Action types
59
+ type Action<T> =
60
+ | {
61
+ type: "ADD_ELEMENT";
62
+ value: T;
63
+ id: FlatCategoryStoreId;
64
+ categories: string[];
65
+ }
66
+ | { type: "REMOVE_ELEMENT"; id: FlatCategoryStoreId };
67
+
68
+ // Reducer
69
+ function flatCategoryStoreReducer<T>(
70
+ state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,
71
+ action: Action<T>,
72
+ ): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {
73
+ switch (action.type) {
74
+ case "ADD_ELEMENT": {
75
+ const { value, id, categories } = action;
76
+ const newElement: FlatCategoryStoreElement<T> = {
77
+ id,
78
+ value,
79
+ categories: new Set(categories),
80
+ };
81
+ const newState = new Map(state);
82
+ newState.set(id, newElement);
83
+ return newState;
84
+ }
85
+ case "REMOVE_ELEMENT": {
86
+ const newState = new Map(state);
87
+ newState.delete(action.id);
88
+ return newState;
89
+ }
90
+ default:
91
+ return state;
92
+ }
93
+ }
94
+
95
+ function setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {
96
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
97
+
98
+ for (let item of smallerSet) {
99
+ if (largerSet.has(item)) {
100
+ return true;
101
+ }
102
+ }
103
+
104
+ return false;
105
+ }
@@ -0,0 +1,96 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
3
+ import { Parameter, getZodParameters, MappedParameterTypes } from "@copilotkit/shared";
4
+ import { parseJson } from "@copilotkit/shared";
5
+ import { ToolCallStatus } from "@copilotkitnext/core";
6
+ import {
7
+ type ReactFrontendTool,
8
+ useFrontendTool as useFrontendToolVNext,
9
+ } from "@copilotkitnext/react";
10
+
11
+ type FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<MappedParameterTypes<T>>;
12
+ type FrontendToolRenderArgs<T extends Parameter[] | []> =
13
+ | {
14
+ name: string;
15
+ args: Partial<MappedParameterTypes<T>>;
16
+ status: ToolCallStatus.InProgress;
17
+ result: undefined;
18
+ }
19
+ | {
20
+ name: string;
21
+ args: MappedParameterTypes<T>;
22
+ status: ToolCallStatus.Executing;
23
+ result: undefined;
24
+ }
25
+ | {
26
+ name: string;
27
+ args: MappedParameterTypes<T>;
28
+ status: ToolCallStatus.Complete;
29
+ result: string;
30
+ };
31
+
32
+ export type UseFrontendToolArgs<T extends Parameter[] | [] = []> = {
33
+ available?: "disabled" | "enabled";
34
+ } & Pick<
35
+ FrontendAction<T>,
36
+ "name" | "description" | "parameters" | "handler" | "followUp" | "render"
37
+ >;
38
+
39
+ export function useFrontendTool<const T extends Parameter[] = []>(
40
+ tool: UseFrontendToolArgs<T>,
41
+ dependencies?: any[],
42
+ ) {
43
+ const { name, description, parameters, render, followUp } = tool;
44
+ const zodParameters = getZodParameters(parameters);
45
+
46
+ const normalizedRender: FrontendToolOptions<T>["render"] | undefined = (() => {
47
+ if (typeof render === "undefined") {
48
+ return undefined;
49
+ }
50
+
51
+ if (typeof render === "string") {
52
+ const staticRender = render;
53
+ return (() =>
54
+ React.createElement(
55
+ React.Fragment,
56
+ null,
57
+ staticRender,
58
+ )) as FrontendToolOptions<T>["render"];
59
+ }
60
+
61
+ return ((args: FrontendToolRenderArgs<T>) => {
62
+ const renderArgs = {
63
+ ...args,
64
+ result: typeof args.result === "string" ? parseJson(args.result, args.result) : args.result,
65
+ } as ActionRenderProps<T>;
66
+
67
+ const rendered = render(renderArgs);
68
+
69
+ if (typeof rendered === "string") {
70
+ return React.createElement(React.Fragment, null, rendered);
71
+ }
72
+
73
+ return rendered ?? null;
74
+ }) as FrontendToolOptions<T>["render"];
75
+ })();
76
+
77
+ // Handler ref to avoid stale closures
78
+ const handlerRef = useRef<typeof tool.handler>(tool.handler);
79
+
80
+ useEffect(() => {
81
+ handlerRef.current = tool.handler;
82
+ }, [tool.handler, ...(dependencies ?? [])]);
83
+
84
+ const normalizedHandler = tool.handler
85
+ ? (args: MappedParameterTypes<T>) => handlerRef.current?.(args)
86
+ : undefined;
87
+
88
+ useFrontendToolVNext<MappedParameterTypes<T>>({
89
+ name,
90
+ description,
91
+ parameters: zodParameters,
92
+ handler: normalizedHandler,
93
+ followUp,
94
+ render: normalizedRender,
95
+ });
96
+ }
@@ -0,0 +1,122 @@
1
+ import { ActionRenderProps, ActionRenderPropsWait, FrontendAction } from "../types";
2
+ import {
3
+ CopilotKitError,
4
+ CopilotKitErrorCode,
5
+ MappedParameterTypes,
6
+ Parameter,
7
+ getZodParameters,
8
+ parseJson,
9
+ } from "@copilotkit/shared";
10
+ import { useHumanInTheLoop as useHumanInTheLoopVNext } from "@copilotkitnext/react";
11
+ import { ToolCallStatus } from "@copilotkitnext/core";
12
+ import React, { ComponentType, FunctionComponent, useEffect, useRef } from "react";
13
+
14
+ type HumanInTheLoopOptions = Parameters<typeof useHumanInTheLoopVNext>[0];
15
+ type HumanInTheLoopRender = HumanInTheLoopOptions["render"];
16
+ type HumanInTheLoopRenderArgs = HumanInTheLoopRender extends (props: infer P) => any ? P : never;
17
+
18
+ export type UseHumanInTheLoopArgs<T extends Parameter[] | [] = []> = {
19
+ available?: "disabled" | "enabled";
20
+ render: FrontendAction<T>["renderAndWaitForResponse"];
21
+ followUp?: FrontendAction<T>["followUp"];
22
+ } & Pick<FrontendAction<T>, "name" | "description" | "parameters">;
23
+
24
+ type HitlRendererArgs =
25
+ | {
26
+ name: string;
27
+ description: string;
28
+ args: Partial<Record<string, unknown>>;
29
+ status: ToolCallStatus.InProgress;
30
+ result: undefined;
31
+ respond: undefined;
32
+ }
33
+ | {
34
+ name: string;
35
+ description: string;
36
+ args: Record<string, unknown>;
37
+ status: ToolCallStatus.Executing;
38
+ result: undefined;
39
+ respond: (result: unknown) => Promise<void>;
40
+ }
41
+ | {
42
+ name: string;
43
+ description: string;
44
+ args: Record<string, unknown>;
45
+ status: ToolCallStatus.Complete;
46
+ result: string;
47
+ respond: undefined;
48
+ };
49
+ type HitlRenderer = FunctionComponent<HitlRendererArgs>;
50
+
51
+ export function useHumanInTheLoop<const T extends Parameter[] | [] = []>(
52
+ tool: UseHumanInTheLoopArgs<T>,
53
+ dependencies?: any[],
54
+ ) {
55
+ const { render, ...toolRest } = tool;
56
+ const { name, description, parameters, followUp } = toolRest;
57
+ const zodParameters = getZodParameters(parameters);
58
+ const renderRef = useRef<HitlRenderer | null>(null);
59
+
60
+ useEffect(() => {
61
+ renderRef.current = (args: HitlRendererArgs): React.ReactElement | null => {
62
+ if (typeof render === "string") {
63
+ return React.createElement(React.Fragment, null, render);
64
+ }
65
+
66
+ if (!render) {
67
+ return null;
68
+ }
69
+
70
+ const renderProps: ActionRenderPropsWait<T> = (() => {
71
+ const mappedArgs = args.args as unknown as MappedParameterTypes<T>;
72
+
73
+ switch (args.status) {
74
+ case ToolCallStatus.InProgress:
75
+ return {
76
+ args: mappedArgs,
77
+ respond: args.respond,
78
+ status: args.status,
79
+ handler: undefined,
80
+ };
81
+ case ToolCallStatus.Executing:
82
+ return {
83
+ args: mappedArgs,
84
+ respond: args.respond,
85
+ status: args.status,
86
+ handler: () => {},
87
+ };
88
+ case ToolCallStatus.Complete:
89
+ return {
90
+ args: mappedArgs,
91
+ respond: args.respond,
92
+ status: args.status,
93
+ result: args.result ? parseJson(args.result, args.result) : args.result,
94
+ handler: undefined,
95
+ };
96
+ default:
97
+ throw new CopilotKitError({
98
+ code: CopilotKitErrorCode.UNKNOWN,
99
+ message: `Invalid tool call status: ${(args as unknown as { status: string }).status}`,
100
+ });
101
+ }
102
+ })();
103
+
104
+ const rendered = render(renderProps);
105
+
106
+ if (typeof rendered === "string") {
107
+ return React.createElement(React.Fragment, null, rendered);
108
+ }
109
+
110
+ return rendered ?? null;
111
+ };
112
+ }, [render, ...(dependencies ?? [])]);
113
+
114
+ useHumanInTheLoopVNext({
115
+ name,
116
+ description,
117
+ followUp,
118
+ parameters: zodParameters,
119
+ render: ((args: HumanInTheLoopRenderArgs) =>
120
+ renderRef.current?.(args as HitlRendererArgs) ?? null) as HumanInTheLoopOptions["render"],
121
+ });
122
+ }