@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
@@ -86,7 +86,8 @@ __export(copilot_provider_exports, {
86
86
  module.exports = __toCommonJS(copilot_provider_exports);
87
87
 
88
88
  // src/components/copilot-provider/copilotkit.tsx
89
- var import_react11 = require("react");
89
+ var import_react16 = require("react");
90
+ var import_react17 = require("@copilotkitnext/react");
90
91
 
91
92
  // src/context/copilot-context.tsx
92
93
  var import_react = __toESM(require("react"));
@@ -96,10 +97,8 @@ var emptyCopilotContext = {
96
97
  },
97
98
  removeAction: () => {
98
99
  },
99
- coAgentStateRenders: {},
100
- setCoAgentStateRender: () => {
101
- },
102
- removeCoAgentStateRender: () => {
100
+ setRegisteredActions: () => "",
101
+ removeRegisteredAction: () => {
103
102
  },
104
103
  chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
105
104
  getContextString: (documents, categories) => returnAndThrowInDebug(""),
@@ -119,7 +118,6 @@ var emptyCopilotContext = {
119
118
  addDocumentContext: () => returnAndThrowInDebug(""),
120
119
  removeDocumentContext: () => {
121
120
  },
122
- runtimeClient: {},
123
121
  copilotApiConfig: new class {
124
122
  get chatApiEndpoint() {
125
123
  throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
@@ -159,10 +157,15 @@ var emptyCopilotContext = {
159
157
  extensions: {},
160
158
  setExtensions: () => {
161
159
  },
162
- langGraphInterruptAction: null,
163
- setLangGraphInterruptAction: () => {
160
+ interruptActions: {},
161
+ setInterruptAction: () => {
162
+ },
163
+ removeInterruptAction: () => {
164
+ },
165
+ interruptEventQueue: {},
166
+ addInterruptEvent: () => {
164
167
  },
165
- removeLangGraphInterruptAction: () => {
168
+ removeInterruptEvent: () => {
166
169
  },
167
170
  onError: () => {
168
171
  },
@@ -323,13 +326,16 @@ function setsHaveIntersection(setA, setB) {
323
326
 
324
327
  // src/components/copilot-provider/copilotkit.tsx
325
328
  var import_react_dom = require("react-dom");
326
- var import_shared10 = require("@copilotkit/shared");
329
+ var import_shared13 = require("@copilotkit/shared");
327
330
 
328
331
  // src/hooks/use-flat-category-store.ts
329
332
  var import_react3 = require("react");
330
333
  var import_shared2 = require("@copilotkit/shared");
331
334
  var useFlatCategoryStore = () => {
332
- const [elements, dispatch] = (0, import_react3.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
335
+ const [elements, dispatch] = (0, import_react3.useReducer)(
336
+ flatCategoryStoreReducer,
337
+ /* @__PURE__ */ new Map()
338
+ );
333
339
  const addElement = (0, import_react3.useCallback)((value, categories) => {
334
340
  const newId = (0, import_shared2.randomId)();
335
341
  dispatch({
@@ -414,9 +420,6 @@ function useCopilotMessagesContext() {
414
420
  return context;
415
421
  }
416
422
 
417
- // src/components/copilot-provider/copilot-messages.tsx
418
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
419
-
420
423
  // src/components/toast/toast-provider.tsx
421
424
  var import_react5 = require("react");
422
425
  var import_shared3 = require("@copilotkit/shared");
@@ -752,11 +755,11 @@ function MessagesTapProvider({ children }) {
752
755
  }
753
756
  function CopilotMessages({ children }) {
754
757
  const [messages, setMessages] = (0, import_react6.useState)([]);
755
- const lastLoadedThreadId = (0, import_react6.useRef)();
756
- const lastLoadedAgentName = (0, import_react6.useRef)();
757
- const lastLoadedMessages = (0, import_react6.useRef)();
758
+ const lastLoadedThreadId = (0, import_react6.useRef)(void 0);
759
+ const lastLoadedAgentName = (0, import_react6.useRef)(void 0);
760
+ const lastLoadedMessages = (0, import_react6.useRef)(void 0);
758
761
  const { updateTapMessages } = useMessagesTap();
759
- const { threadId, agentSession, runtimeClient, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
762
+ const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
760
763
  const { setBannerError } = useToast();
761
764
  const traceUIError = (0, import_react6.useCallback)(
762
765
  (error, originalError) => __async(this, null, function* () {
@@ -788,7 +791,7 @@ function CopilotMessages({ children }) {
788
791
  }),
789
792
  [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
790
793
  );
791
- const createStructuredError2 = (gqlError) => {
794
+ const createStructuredError = (gqlError) => {
792
795
  const extensions = gqlError.extensions;
793
796
  const originalError = extensions == null ? void 0 : extensions.originalError;
794
797
  if (originalError == null ? void 0 : originalError.stack) {
@@ -829,7 +832,7 @@ function CopilotMessages({ children }) {
829
832
  console.error("CopilotKit Silent Error:", gqlError.message);
830
833
  return;
831
834
  }
832
- const ckError = createStructuredError2(gqlError);
835
+ const ckError = createStructuredError(gqlError);
833
836
  if (ckError) {
834
837
  setBannerError(ckError);
835
838
  traceUIError(ckError, gqlError);
@@ -859,39 +862,6 @@ function CopilotMessages({ children }) {
859
862
  },
860
863
  [setBannerError, showDevConsole, traceUIError]
861
864
  );
862
- (0, import_react6.useEffect)(() => {
863
- if (!threadId || threadId === lastLoadedThreadId.current)
864
- return;
865
- if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
866
- return;
867
- }
868
- const fetchMessages = () => __async(this, null, function* () {
869
- var _a, _b, _c;
870
- if (!(agentSession == null ? void 0 : agentSession.agentName))
871
- return;
872
- const result = yield runtimeClient.loadAgentState({
873
- threadId,
874
- agentName: agentSession == null ? void 0 : agentSession.agentName
875
- });
876
- if (result.error) {
877
- lastLoadedThreadId.current = threadId;
878
- lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
879
- handleGraphQLErrors(result.error);
880
- return;
881
- }
882
- const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
883
- if (newMessages === lastLoadedMessages.current)
884
- return;
885
- if ((_c = result.data) == null ? void 0 : _c.loadAgentState) {
886
- lastLoadedMessages.current = newMessages;
887
- lastLoadedThreadId.current = threadId;
888
- lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
889
- const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
890
- setMessages(messages2);
891
- }
892
- });
893
- void fetchMessages();
894
- }, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
895
865
  (0, import_react6.useEffect)(() => {
896
866
  updateTapMessages(messages);
897
867
  }, [messages, updateTapMessages]);
@@ -1112,123 +1082,12 @@ var getErrorActions = (error) => {
1112
1082
  }
1113
1083
  };
1114
1084
 
1115
- // src/hooks/use-copilot-runtime-client.ts
1116
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1117
- var import_react7 = require("react");
1118
- var import_shared6 = require("@copilotkit/shared");
1119
- var useCopilotRuntimeClient = (options) => {
1120
- const { setBannerError } = useToast();
1121
- const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
1122
- const lastStructuredErrorRef = (0, import_react7.useRef)(null);
1123
- const traceUIError = (error, originalError) => __async(void 0, null, function* () {
1124
- try {
1125
- const errorEvent = {
1126
- type: "error",
1127
- timestamp: Date.now(),
1128
- context: {
1129
- source: "ui",
1130
- request: {
1131
- operation: "runtimeClient",
1132
- url: runtimeOptions.url,
1133
- startTime: Date.now()
1134
- },
1135
- technical: {
1136
- environment: "browser",
1137
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
1138
- stackTrace: originalError instanceof Error ? originalError.stack : void 0
1139
- }
1140
- },
1141
- error
1142
- };
1143
- yield onError(errorEvent);
1144
- } catch (error2) {
1145
- console.error("Error in onError handler:", error2);
1146
- }
1147
- });
1148
- const runtimeClient = (0, import_react7.useMemo)(() => {
1149
- return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
1150
- handleGQLErrors: (error) => {
1151
- var _a2;
1152
- if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
1153
- const graphQLErrors = error.graphQLErrors;
1154
- const routeError = (gqlError) => {
1155
- const extensions = gqlError.extensions;
1156
- const visibility = extensions == null ? void 0 : extensions.visibility;
1157
- if (visibility === import_shared6.ErrorVisibility.SILENT) {
1158
- console.error("CopilotKit Silent Error:", gqlError.message);
1159
- return;
1160
- }
1161
- const now = Date.now();
1162
- const errorMessage = gqlError.message;
1163
- if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
1164
- return;
1165
- }
1166
- lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
1167
- const ckError = createStructuredError(gqlError);
1168
- if (ckError) {
1169
- setBannerError(ckError);
1170
- traceUIError(ckError, gqlError);
1171
- } else {
1172
- const fallbackError = new import_shared6.CopilotKitError({
1173
- message: gqlError.message,
1174
- code: import_shared6.CopilotKitErrorCode.UNKNOWN
1175
- });
1176
- setBannerError(fallbackError);
1177
- traceUIError(fallbackError, gqlError);
1178
- }
1179
- };
1180
- graphQLErrors.forEach(routeError);
1181
- } else {
1182
- const fallbackError = new import_shared6.CopilotKitError({
1183
- message: (error == null ? void 0 : error.message) || String(error),
1184
- code: import_shared6.CopilotKitErrorCode.UNKNOWN
1185
- });
1186
- setBannerError(fallbackError);
1187
- traceUIError(fallbackError, error);
1188
- }
1189
- },
1190
- handleGQLWarning: (message) => {
1191
- console.warn(message);
1192
- const warningError = new import_shared6.CopilotKitError({
1193
- message,
1194
- code: import_shared6.CopilotKitErrorCode.UNKNOWN
1195
- });
1196
- setBannerError(warningError);
1197
- }
1198
- }));
1199
- }, [runtimeOptions, setBannerError, onError]);
1200
- return runtimeClient;
1201
- };
1202
- function createStructuredError(gqlError) {
1203
- var _a, _b, _c;
1204
- const extensions = gqlError.extensions;
1205
- const originalError = extensions == null ? void 0 : extensions.originalError;
1206
- const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
1207
- const code = extensions == null ? void 0 : extensions.code;
1208
- if (code) {
1209
- return new import_shared6.CopilotKitError({ message, code });
1210
- }
1211
- if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
1212
- return new import_shared6.CopilotKitApiDiscoveryError({ message });
1213
- }
1214
- if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
1215
- return new import_shared6.CopilotKitRemoteEndpointDiscoveryError({ message });
1216
- }
1217
- if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
1218
- return new import_shared6.CopilotKitAgentDiscoveryError({
1219
- agentName: "",
1220
- availableAgents: []
1221
- });
1222
- }
1223
- return null;
1224
- }
1225
-
1226
1085
  // src/components/error-boundary/error-boundary.tsx
1227
- var import_react8 = __toESM(require("react"));
1228
- var import_shared8 = require("@copilotkit/shared");
1086
+ var import_react7 = __toESM(require("react"));
1087
+ var import_shared7 = require("@copilotkit/shared");
1229
1088
 
1230
1089
  // src/lib/status-checker.ts
1231
- var import_shared7 = require("@copilotkit/shared");
1090
+ var import_shared6 = require("@copilotkit/shared");
1232
1091
  var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
1233
1092
  var StatusChecker = class {
1234
1093
  constructor() {
@@ -1246,10 +1105,10 @@ var StatusChecker = class {
1246
1105
  clearInterval(this.intervalId);
1247
1106
  const checkStatus = () => __async(this, null, function* () {
1248
1107
  try {
1249
- const response = yield fetch(`${import_shared7.COPILOT_CLOUD_API_URL}/ciu`, {
1108
+ const response = yield fetch(`${import_shared6.COPILOT_CLOUD_API_URL}/ciu`, {
1250
1109
  method: "GET",
1251
1110
  headers: {
1252
- [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
1111
+ [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
1253
1112
  }
1254
1113
  }).then((response2) => response2.json());
1255
1114
  this.lastResponse = response;
@@ -1284,7 +1143,7 @@ var StatusChecker = class {
1284
1143
  // src/components/error-boundary/error-boundary.tsx
1285
1144
  var import_jsx_runtime4 = require("react/jsx-runtime");
1286
1145
  var statusChecker = new StatusChecker();
1287
- var CopilotErrorBoundary = class extends import_react8.default.Component {
1146
+ var CopilotErrorBoundary = class extends import_react7.default.Component {
1288
1147
  constructor(props) {
1289
1148
  super(props);
1290
1149
  this.state = {
@@ -1316,7 +1175,7 @@ var CopilotErrorBoundary = class extends import_react8.default.Component {
1316
1175
  render() {
1317
1176
  var _a, _b, _c, _d;
1318
1177
  if (this.state.hasError) {
1319
- if (this.state.error instanceof import_shared8.CopilotKitError) {
1178
+ if (this.state.error instanceof import_shared7.CopilotKitError) {
1320
1179
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1321
1180
  this.props.children,
1322
1181
  this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -1336,7 +1195,7 @@ var CopilotErrorBoundary = class extends import_react8.default.Component {
1336
1195
  };
1337
1196
 
1338
1197
  // src/components/dev-console/console-trigger.tsx
1339
- var import_react10 = require("react");
1198
+ var import_react9 = require("react");
1340
1199
 
1341
1200
  // src/components/dev-console/icons.tsx
1342
1201
  var import_jsx_runtime5 = require("react/jsx-runtime");
@@ -1399,14 +1258,14 @@ var CopilotKitIcon = () => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1399
1258
  );
1400
1259
 
1401
1260
  // src/components/dev-console/developer-console-modal.tsx
1402
- var import_shared9 = require("@copilotkit/shared");
1403
- var import_react9 = require("react");
1261
+ var import_shared8 = require("@copilotkit/shared");
1262
+ var import_react8 = require("react");
1404
1263
  var import_jsx_runtime6 = require("react/jsx-runtime");
1405
1264
  function DeveloperConsoleModal({ isOpen, onClose, hasApiKey }) {
1406
1265
  const context = useCopilotContext();
1407
1266
  const messagesContext = useCopilotMessagesContext();
1408
- const [activeTab, setActiveTab] = (0, import_react9.useState)("actions");
1409
- (0, import_react9.useEffect)(() => {
1267
+ const [activeTab, setActiveTab] = (0, import_react8.useState)("actions");
1268
+ (0, import_react8.useEffect)(() => {
1410
1269
  const handleEscape = (e) => {
1411
1270
  if (e.key === "Escape") {
1412
1271
  onClose();
@@ -1571,7 +1430,7 @@ function DeveloperConsoleModal({ isOpen, onClose, hasApiKey }) {
1571
1430
  },
1572
1431
  children: [
1573
1432
  "v",
1574
- import_shared9.COPILOTKIT_VERSION
1433
+ import_shared8.COPILOTKIT_VERSION
1575
1434
  ]
1576
1435
  }
1577
1436
  )
@@ -2147,15 +2006,15 @@ var INSPECTOR_HIDE_KEY = "cpk:inspector:hidden";
2147
2006
  function ConsoleTrigger({ position = "bottom-right" }) {
2148
2007
  const context = useCopilotContext();
2149
2008
  const hasApiKey = Boolean(context.copilotApiConfig.publicApiKey);
2150
- const [isModalOpen, setIsModalOpen] = (0, import_react10.useState)(false);
2151
- const [isHovered, setIsHovered] = (0, import_react10.useState)(false);
2152
- const [isDragging, setIsDragging] = (0, import_react10.useState)(false);
2153
- const [buttonPosition, setButtonPosition] = (0, import_react10.useState)(null);
2154
- const [mounted, setMounted] = (0, import_react10.useState)(false);
2155
- const [isHidden, setIsHidden] = (0, import_react10.useState)(false);
2156
- const dragRef = (0, import_react10.useRef)(null);
2157
- const buttonRef = (0, import_react10.useRef)(null);
2158
- (0, import_react10.useEffect)(() => {
2009
+ const [isModalOpen, setIsModalOpen] = (0, import_react9.useState)(false);
2010
+ const [isHovered, setIsHovered] = (0, import_react9.useState)(false);
2011
+ const [isDragging, setIsDragging] = (0, import_react9.useState)(false);
2012
+ const [buttonPosition, setButtonPosition] = (0, import_react9.useState)(null);
2013
+ const [mounted, setMounted] = (0, import_react9.useState)(false);
2014
+ const [isHidden, setIsHidden] = (0, import_react9.useState)(false);
2015
+ const dragRef = (0, import_react9.useRef)(null);
2016
+ const buttonRef = (0, import_react9.useRef)(null);
2017
+ (0, import_react9.useEffect)(() => {
2159
2018
  setMounted(true);
2160
2019
  try {
2161
2020
  const hidden = typeof window !== "undefined" ? localStorage.getItem(INSPECTOR_HIDE_KEY) : null;
@@ -2186,7 +2045,7 @@ function ConsoleTrigger({ position = "bottom-right" }) {
2186
2045
  };
2187
2046
  setIsDragging(true);
2188
2047
  };
2189
- (0, import_react10.useEffect)(() => {
2048
+ (0, import_react9.useEffect)(() => {
2190
2049
  if (!isDragging)
2191
2050
  return;
2192
2051
  const handleMouseMove = (e) => {
@@ -2357,66 +2216,343 @@ function ConsoleTrigger({ position = "bottom-right" }) {
2357
2216
  ] });
2358
2217
  }
2359
2218
 
2360
- // src/components/copilot-provider/copilotkit.tsx
2219
+ // src/context/coagent-state-renders-context.tsx
2220
+ var import_react10 = require("react");
2361
2221
  var import_jsx_runtime8 = require("react/jsx-runtime");
2222
+ var CoAgentStateRendersContext = (0, import_react10.createContext)(
2223
+ void 0
2224
+ );
2225
+ function CoAgentStateRendersProvider({ children }) {
2226
+ const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
2227
+ const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
2228
+ setCoAgentStateRenders((prevPoints) => __spreadProps(__spreadValues({}, prevPoints), {
2229
+ [id]: stateRender
2230
+ }));
2231
+ }, []);
2232
+ const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
2233
+ setCoAgentStateRenders((prevPoints) => {
2234
+ const newPoints = __spreadValues({}, prevPoints);
2235
+ delete newPoints[id];
2236
+ return newPoints;
2237
+ });
2238
+ }, []);
2239
+ const claimsRef = (0, import_react10.useRef)({});
2240
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2241
+ CoAgentStateRendersContext.Provider,
2242
+ {
2243
+ value: {
2244
+ coAgentStateRenders,
2245
+ setCoAgentStateRender,
2246
+ removeCoAgentStateRender,
2247
+ claimsRef
2248
+ },
2249
+ children
2250
+ }
2251
+ );
2252
+ }
2253
+ function useCoAgentStateRenders() {
2254
+ const context = (0, import_react10.useContext)(CoAgentStateRendersContext);
2255
+ if (!context) {
2256
+ throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
2257
+ }
2258
+ return context;
2259
+ }
2260
+
2261
+ // src/hooks/use-coagent-state-render-bridge.tsx
2262
+ var import_react12 = require("@copilotkitnext/react");
2263
+ var import_react13 = require("react");
2264
+
2265
+ // src/context/threads-context.tsx
2266
+ var import_react11 = require("react");
2267
+ var import_shared9 = require("@copilotkit/shared");
2268
+ var import_jsx_runtime9 = require("react/jsx-runtime");
2269
+ var ThreadsContext = (0, import_react11.createContext)(void 0);
2270
+ function ThreadsProvider({ children, threadId: explicitThreadId }) {
2271
+ const [internalThreadId, setThreadId] = (0, import_react11.useState)(explicitThreadId != null ? explicitThreadId : (0, import_shared9.randomUUID)());
2272
+ const threadId = internalThreadId;
2273
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2274
+ ThreadsContext.Provider,
2275
+ {
2276
+ value: {
2277
+ threadId,
2278
+ setThreadId
2279
+ },
2280
+ children
2281
+ }
2282
+ );
2283
+ }
2284
+ function useThreads() {
2285
+ const context = (0, import_react11.useContext)(ThreadsContext);
2286
+ if (!context) {
2287
+ throw new Error("useThreads must be used within ThreadsProvider");
2288
+ }
2289
+ return context;
2290
+ }
2291
+
2292
+ // src/hooks/use-coagent-state-render-bridge.tsx
2293
+ var import_shared10 = require("@copilotkit/shared");
2294
+ function getStateWithoutConstantKeys(state) {
2295
+ const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
2296
+ return stateWithoutConstantKeys;
2297
+ }
2298
+ function areStatesEquals(a, b) {
2299
+ if (a && !b || !a && b)
2300
+ return false;
2301
+ const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
2302
+ const _b = b, {
2303
+ messages: bMessages,
2304
+ tools: bTools,
2305
+ copilotkit: bCopilotkit
2306
+ } = _b, bWithoutConstantKeys = __objRest(_b, [
2307
+ "messages",
2308
+ "tools",
2309
+ "copilotkit"
2310
+ ]);
2311
+ return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
2312
+ }
2313
+ function useCoagentStateRenderBridge(agentId, props) {
2314
+ var _a;
2315
+ const { stateSnapshot, messageIndexInRun, message } = props;
2316
+ const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
2317
+ const { agent } = (0, import_react12.useAgent)({ agentId });
2318
+ const [nodeName, setNodeName] = (0, import_react13.useState)(void 0);
2319
+ const runId = (_a = props.runId) != null ? _a : message.runId;
2320
+ const effectiveRunId = runId || "pending";
2321
+ (0, import_react13.useEffect)(() => {
2322
+ if (!agent)
2323
+ return;
2324
+ const subscriber = {
2325
+ onStepStartedEvent: ({ event }) => {
2326
+ if (event.stepName !== nodeName) {
2327
+ setNodeName(event.stepName);
2328
+ }
2329
+ },
2330
+ onStepFinishedEvent: ({ event }) => {
2331
+ if (event.stepName === nodeName) {
2332
+ setNodeName(void 0);
2333
+ }
2334
+ }
2335
+ };
2336
+ const { unsubscribe } = agent.subscribe(subscriber);
2337
+ return () => {
2338
+ unsubscribe();
2339
+ };
2340
+ }, [agentId, nodeName]);
2341
+ if (messageIndexInRun !== 0) {
2342
+ return null;
2343
+ }
2344
+ const getStateRender = (0, import_react13.useCallback)(
2345
+ (messageId) => {
2346
+ return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
2347
+ if (claimsRef.current[messageId]) {
2348
+ return stateRenderId === claimsRef.current[messageId].stateRenderId;
2349
+ }
2350
+ const matchingAgentName = stateRender.name === agentId;
2351
+ const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
2352
+ return matchingAgentName && matchesNodeContext;
2353
+ });
2354
+ },
2355
+ [coAgentStateRenders, nodeName, agentId]
2356
+ );
2357
+ const handleRenderRequest = ({
2358
+ stateRenderId,
2359
+ messageId,
2360
+ runId: runId2,
2361
+ stateSnapshot: renderSnapshot
2362
+ }) => {
2363
+ if (claimsRef.current[messageId]) {
2364
+ const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
2365
+ if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
2366
+ claimsRef.current[messageId].runId = runId2;
2367
+ }
2368
+ return canRender;
2369
+ }
2370
+ const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
2371
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared10.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared10.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
2372
+ );
2373
+ if (renderClaimedByOtherMessage) {
2374
+ if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
2375
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
2376
+ return true;
2377
+ }
2378
+ return false;
2379
+ }
2380
+ if (!runId2) {
2381
+ return false;
2382
+ }
2383
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
2384
+ return true;
2385
+ };
2386
+ return (0, import_react13.useMemo)(() => {
2387
+ var _a2, _b, _c;
2388
+ const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
2389
+ if (!stateRender || !stateRenderId) {
2390
+ return null;
2391
+ }
2392
+ const snapshot = stateSnapshot ? (0, import_shared10.parseJson)(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
2393
+ const canRender = handleRenderRequest({
2394
+ stateRenderId,
2395
+ messageId: message.id,
2396
+ runId: effectiveRunId,
2397
+ stateSnapshot: snapshot
2398
+ });
2399
+ if (!canRender) {
2400
+ return null;
2401
+ }
2402
+ if (snapshot && !claimsRef.current[message.id].locked) {
2403
+ if (stateSnapshot) {
2404
+ claimsRef.current[message.id].stateSnapshot = snapshot;
2405
+ claimsRef.current[message.id].locked = true;
2406
+ } else {
2407
+ claimsRef.current[message.id].stateSnapshot = snapshot;
2408
+ }
2409
+ }
2410
+ if (stateRender.handler) {
2411
+ stateRender.handler({
2412
+ state: stateSnapshot ? (0, import_shared10.parseJson)(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
2413
+ nodeName: nodeName != null ? nodeName : ""
2414
+ });
2415
+ }
2416
+ if (stateRender.render) {
2417
+ const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
2418
+ if (typeof stateRender.render === "string")
2419
+ return stateRender.render;
2420
+ return stateRender.render({
2421
+ status,
2422
+ // Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
2423
+ state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
2424
+ nodeName: nodeName != null ? nodeName : ""
2425
+ });
2426
+ }
2427
+ }, [
2428
+ getStateRender,
2429
+ stateSnapshot,
2430
+ agent == null ? void 0 : agent.state,
2431
+ agent == null ? void 0 : agent.isRunning,
2432
+ nodeName,
2433
+ effectiveRunId,
2434
+ message.id
2435
+ ]);
2436
+ }
2437
+ function CoAgentStateRenderBridge(props) {
2438
+ return useCoagentStateRenderBridge(props.agentId, props);
2439
+ }
2440
+
2441
+ // src/components/CopilotListeners.tsx
2442
+ var import_react14 = require("react");
2443
+ var import_react15 = require("@copilotkitnext/react");
2444
+ var import_shared11 = require("@copilotkit/shared");
2445
+ var import_shared12 = require("@copilotkit/shared");
2446
+ var usePredictStateSubscription = (agent) => {
2447
+ const predictStateToolsRef = (0, import_react14.useRef)([]);
2448
+ const getSubscriber = (0, import_react14.useCallback)(
2449
+ (agent2) => ({
2450
+ onCustomEvent: ({ event }) => {
2451
+ if (event.name === "PredictState") {
2452
+ predictStateToolsRef.current = event.value;
2453
+ }
2454
+ },
2455
+ onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
2456
+ predictStateToolsRef.current.forEach((t) => {
2457
+ if ((t == null ? void 0 : t.tool) !== toolCallName)
2458
+ return;
2459
+ const emittedState = typeof partialToolCallArgs === "string" ? (0, import_shared11.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
2460
+ agent2.setState({
2461
+ [t.state_key]: emittedState[t.state_key]
2462
+ });
2463
+ });
2464
+ }
2465
+ }),
2466
+ []
2467
+ );
2468
+ (0, import_react14.useEffect)(() => {
2469
+ if (!agent)
2470
+ return;
2471
+ const subscriber = getSubscriber(agent);
2472
+ const { unsubscribe } = agent.subscribe(subscriber);
2473
+ return () => {
2474
+ unsubscribe();
2475
+ };
2476
+ }, [agent, getSubscriber]);
2477
+ };
2478
+ function CopilotListeners() {
2479
+ var _a, _b;
2480
+ const { copilotkit } = (0, import_react15.useCopilotKit)();
2481
+ const { agentSession } = useCopilotContext();
2482
+ const existingConfig = (0, import_react15.useCopilotChatConfiguration)();
2483
+ const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
2484
+ const { setBannerError } = useToast();
2485
+ const { agent } = (0, import_react15.useAgent)({ agentId: resolvedAgentId });
2486
+ usePredictStateSubscription(agent);
2487
+ (0, import_react14.useEffect)(() => {
2488
+ const subscriber = {
2489
+ onError: ({ error }) => {
2490
+ setBannerError(new import_shared12.CopilotKitLowLevelError({ error, message: error.message }));
2491
+ }
2492
+ };
2493
+ const subscription = copilotkit.subscribe(subscriber);
2494
+ return () => {
2495
+ subscription.unsubscribe();
2496
+ };
2497
+ }, [copilotkit == null ? void 0 : copilotkit.subscribe]);
2498
+ return null;
2499
+ }
2500
+
2501
+ // src/components/copilot-provider/copilotkit.tsx
2502
+ var import_jsx_runtime10 = require("react/jsx-runtime");
2362
2503
  function CopilotKit(_a) {
2363
2504
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2364
2505
  const enabled = shouldShowDevConsole(props.showDevConsole);
2365
2506
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
2366
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
2507
+ const renderArr = (0, import_react16.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
2508
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2509
+ import_react17.CopilotKitProvider,
2510
+ {
2511
+ runtimeUrl: props.runtimeUrl,
2512
+ renderCustomMessages: renderArr,
2513
+ useSingleEndpoint: true,
2514
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
2515
+ }
2516
+ ) }) }) });
2367
2517
  }
2368
2518
  function CopilotKitInternal(cpkProps) {
2369
2519
  var _b;
2370
2520
  const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
2371
2521
  validateProps(cpkProps);
2372
2522
  const publicApiKey = props.publicLicenseKey || props.publicApiKey;
2373
- const chatApiEndpoint = props.runtimeUrl || import_shared10.COPILOT_CLOUD_CHAT_URL;
2374
- const [actions, setActions] = (0, import_react11.useState)({});
2375
- const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react11.useState)({});
2376
- const chatComponentsCache = (0, import_react11.useRef)({
2523
+ const chatApiEndpoint = props.runtimeUrl || import_shared13.COPILOT_CLOUD_CHAT_URL;
2524
+ const [actions, setActions] = (0, import_react16.useState)({});
2525
+ const [registeredActionConfigs, setRegisteredActionConfigs] = (0, import_react16.useState)(/* @__PURE__ */ new Map());
2526
+ const chatComponentsCache = (0, import_react16.useRef)({
2377
2527
  actions: {},
2378
2528
  coAgentStateRenders: {}
2379
2529
  });
2380
2530
  const { addElement, removeElement, printTree, getAllElements } = use_tree_default();
2381
- const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
2382
- const [chatInstructions, setChatInstructions] = (0, import_react11.useState)("");
2383
- const [authStates, setAuthStates] = (0, import_react11.useState)({});
2384
- const [extensions, setExtensions] = (0, import_react11.useState)({});
2385
- const [additionalInstructions, setAdditionalInstructions] = (0, import_react11.useState)([]);
2531
+ const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
2532
+ const [chatInstructions, setChatInstructions] = (0, import_react16.useState)("");
2533
+ const [authStates, setAuthStates] = (0, import_react16.useState)({});
2534
+ const [extensions, setExtensions] = (0, import_react16.useState)({});
2535
+ const [additionalInstructions, setAdditionalInstructions] = (0, import_react16.useState)([]);
2386
2536
  const {
2387
2537
  addElement: addDocument,
2388
2538
  removeElement: removeDocument,
2389
2539
  allElements: allDocuments
2390
2540
  } = use_flat_category_store_default();
2391
- const setAction = (0, import_react11.useCallback)((id, action) => {
2541
+ const setAction = (0, import_react16.useCallback)((id, action) => {
2392
2542
  setActions((prevPoints) => {
2393
2543
  return __spreadProps(__spreadValues({}, prevPoints), {
2394
2544
  [id]: action
2395
2545
  });
2396
2546
  });
2397
2547
  }, []);
2398
- const removeAction = (0, import_react11.useCallback)((id) => {
2548
+ const removeAction = (0, import_react16.useCallback)((id) => {
2399
2549
  setActions((prevPoints) => {
2400
2550
  const newPoints = __spreadValues({}, prevPoints);
2401
2551
  delete newPoints[id];
2402
2552
  return newPoints;
2403
2553
  });
2404
2554
  }, []);
2405
- const setCoAgentStateRender = (0, import_react11.useCallback)((id, stateRender) => {
2406
- setCoAgentStateRenders((prevPoints) => {
2407
- return __spreadProps(__spreadValues({}, prevPoints), {
2408
- [id]: stateRender
2409
- });
2410
- });
2411
- }, []);
2412
- const removeCoAgentStateRender = (0, import_react11.useCallback)((id) => {
2413
- setCoAgentStateRenders((prevPoints) => {
2414
- const newPoints = __spreadValues({}, prevPoints);
2415
- delete newPoints[id];
2416
- return newPoints;
2417
- });
2418
- }, []);
2419
- const getContextString = (0, import_react11.useCallback)(
2555
+ const getContextString = (0, import_react16.useCallback)(
2420
2556
  (documents, categories) => {
2421
2557
  const documentsString = documents.map((document2) => {
2422
2558
  return `${document2.name} (${document2.sourceApplication}):
@@ -2429,46 +2565,46 @@ ${nonDocumentStrings}`;
2429
2565
  },
2430
2566
  [printTree]
2431
2567
  );
2432
- const addContext = (0, import_react11.useCallback)(
2568
+ const addContext = (0, import_react16.useCallback)(
2433
2569
  (context, parentId, categories = defaultCopilotContextCategories) => {
2434
2570
  return addElement(context, categories, parentId);
2435
2571
  },
2436
2572
  [addElement]
2437
2573
  );
2438
- const removeContext = (0, import_react11.useCallback)(
2574
+ const removeContext = (0, import_react16.useCallback)(
2439
2575
  (id) => {
2440
2576
  removeElement(id);
2441
2577
  },
2442
2578
  [removeElement]
2443
2579
  );
2444
- const getAllContext = (0, import_react11.useCallback)(() => {
2580
+ const getAllContext = (0, import_react16.useCallback)(() => {
2445
2581
  return getAllElements();
2446
2582
  }, [getAllElements]);
2447
- const getFunctionCallHandler = (0, import_react11.useCallback)(
2583
+ const getFunctionCallHandler = (0, import_react16.useCallback)(
2448
2584
  (customEntryPoints) => {
2449
2585
  return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
2450
2586
  },
2451
2587
  [actions]
2452
2588
  );
2453
- const getDocumentsContext = (0, import_react11.useCallback)(
2589
+ const getDocumentsContext = (0, import_react16.useCallback)(
2454
2590
  (categories) => {
2455
2591
  return allDocuments(categories);
2456
2592
  },
2457
2593
  [allDocuments]
2458
2594
  );
2459
- const addDocumentContext = (0, import_react11.useCallback)(
2595
+ const addDocumentContext = (0, import_react16.useCallback)(
2460
2596
  (documentPointer, categories = defaultCopilotContextCategories) => {
2461
2597
  return addDocument(documentPointer, categories);
2462
2598
  },
2463
2599
  [addDocument]
2464
2600
  );
2465
- const removeDocumentContext = (0, import_react11.useCallback)(
2601
+ const removeDocumentContext = (0, import_react16.useCallback)(
2466
2602
  (documentId) => {
2467
2603
  removeDocument(documentId);
2468
2604
  },
2469
2605
  [removeDocument]
2470
2606
  );
2471
- const copilotApiConfig = (0, import_react11.useMemo)(() => {
2607
+ const copilotApiConfig = (0, import_react16.useMemo)(() => {
2472
2608
  var _a2, _b2;
2473
2609
  let cloud = void 0;
2474
2610
  if (publicApiKey) {
@@ -2504,7 +2640,7 @@ ${nonDocumentStrings}`;
2504
2640
  props.cloudRestrictToTopic,
2505
2641
  props.guardrails_c
2506
2642
  ]);
2507
- const headers = (0, import_react11.useMemo)(() => {
2643
+ const headers = (0, import_react16.useMemo)(() => {
2508
2644
  const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
2509
2645
  if (state.status === "authenticated" && state.authHeaders) {
2510
2646
  return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
@@ -2516,27 +2652,27 @@ ${nonDocumentStrings}`;
2516
2652
  }
2517
2653
  return acc;
2518
2654
  }, {});
2519
- return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared10.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
2655
+ return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared13.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
2520
2656
  }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
2521
- const [internalErrorHandlers, _setInternalErrorHandler] = (0, import_react11.useState)({});
2522
- const setInternalErrorHandler = (0, import_react11.useCallback)((handler) => {
2657
+ const [internalErrorHandlers, _setInternalErrorHandler] = (0, import_react16.useState)({});
2658
+ const setInternalErrorHandler = (0, import_react16.useCallback)((handler) => {
2523
2659
  _setInternalErrorHandler((prev) => __spreadValues(__spreadValues({}, prev), handler));
2524
2660
  }, []);
2525
- const removeInternalErrorHandler = (0, import_react11.useCallback)((key) => {
2661
+ const removeInternalErrorHandler = (0, import_react16.useCallback)((key) => {
2526
2662
  _setInternalErrorHandler((prev) => {
2527
2663
  const _a2 = prev, { [key]: _removed } = _a2, rest = __objRest(_a2, [__restKey(key)]);
2528
2664
  return rest;
2529
2665
  });
2530
2666
  }, []);
2531
- const onErrorRef = (0, import_react11.useRef)(props.onError);
2532
- (0, import_react11.useEffect)(() => {
2667
+ const onErrorRef = (0, import_react16.useRef)(props.onError);
2668
+ (0, import_react16.useEffect)(() => {
2533
2669
  onErrorRef.current = props.onError;
2534
2670
  }, [props.onError]);
2535
- const internalHandlersRef = (0, import_react11.useRef)({});
2536
- (0, import_react11.useEffect)(() => {
2671
+ const internalHandlersRef = (0, import_react16.useRef)({});
2672
+ (0, import_react16.useEffect)(() => {
2537
2673
  internalHandlersRef.current = internalErrorHandlers;
2538
2674
  }, [internalErrorHandlers]);
2539
- const handleErrors = (0, import_react11.useCallback)(
2675
+ const handleErrors = (0, import_react16.useCallback)(
2540
2676
  (error) => __async(this, null, function* () {
2541
2677
  if (copilotApiConfig.publicApiKey && onErrorRef.current) {
2542
2678
  try {
@@ -2556,22 +2692,14 @@ ${nonDocumentStrings}`;
2556
2692
  }),
2557
2693
  [copilotApiConfig.publicApiKey]
2558
2694
  );
2559
- const runtimeClient = useCopilotRuntimeClient({
2560
- url: copilotApiConfig.chatApiEndpoint,
2561
- publicApiKey,
2562
- headers,
2563
- credentials: copilotApiConfig.credentials,
2564
- showDevConsole: shouldShowDevConsole(props.showDevConsole),
2565
- onError: handleErrors
2566
- });
2567
- const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react11.useState)({});
2568
- const addChatSuggestionConfiguration = (0, import_react11.useCallback)(
2695
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react16.useState)({});
2696
+ const addChatSuggestionConfiguration = (0, import_react16.useCallback)(
2569
2697
  (id, suggestion) => {
2570
2698
  setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
2571
2699
  },
2572
2700
  [setChatSuggestionConfiguration]
2573
2701
  );
2574
- const removeChatSuggestionConfiguration = (0, import_react11.useCallback)(
2702
+ const removeChatSuggestionConfiguration = (0, import_react16.useCallback)(
2575
2703
  (id) => {
2576
2704
  setChatSuggestionConfiguration((prev) => {
2577
2705
  const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
@@ -2580,10 +2708,10 @@ ${nonDocumentStrings}`;
2580
2708
  },
2581
2709
  [setChatSuggestionConfiguration]
2582
2710
  );
2583
- const [availableAgents, setAvailableAgents] = (0, import_react11.useState)([]);
2584
- const [coagentStates, setCoagentStates] = (0, import_react11.useState)({});
2585
- const coagentStatesRef = (0, import_react11.useRef)({});
2586
- const setCoagentStatesWithRef = (0, import_react11.useCallback)(
2711
+ const [availableAgents, setAvailableAgents] = (0, import_react16.useState)([]);
2712
+ const [coagentStates, setCoagentStates] = (0, import_react16.useState)({});
2713
+ const coagentStatesRef = (0, import_react16.useRef)({});
2714
+ const setCoagentStatesWithRef = (0, import_react16.useCallback)(
2587
2715
  (value) => {
2588
2716
  const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
2589
2717
  coagentStatesRef.current = newValue;
@@ -2593,28 +2721,14 @@ ${nonDocumentStrings}`;
2593
2721
  },
2594
2722
  []
2595
2723
  );
2596
- const hasLoadedAgents = (0, import_react11.useRef)(false);
2597
- (0, import_react11.useEffect)(() => {
2598
- if (hasLoadedAgents.current)
2599
- return;
2600
- const fetchData = () => __async(this, null, function* () {
2601
- var _a2;
2602
- const result = yield runtimeClient.availableAgents();
2603
- if ((_a2 = result.data) == null ? void 0 : _a2.availableAgents) {
2604
- setAvailableAgents(result.data.availableAgents.agents);
2605
- }
2606
- hasLoadedAgents.current = true;
2607
- });
2608
- void fetchData();
2609
- }, []);
2610
2724
  let initialAgentSession = null;
2611
2725
  if (props.agent) {
2612
2726
  initialAgentSession = {
2613
2727
  agentName: props.agent
2614
2728
  };
2615
2729
  }
2616
- const [agentSession, setAgentSession] = (0, import_react11.useState)(initialAgentSession);
2617
- (0, import_react11.useEffect)(() => {
2730
+ const [agentSession, setAgentSession] = (0, import_react16.useState)(initialAgentSession);
2731
+ (0, import_react16.useEffect)(() => {
2618
2732
  if (props.agent) {
2619
2733
  setAgentSession({
2620
2734
  agentName: props.agent
@@ -2623,8 +2737,8 @@ ${nonDocumentStrings}`;
2623
2737
  setAgentSession(null);
2624
2738
  }
2625
2739
  }, [props.agent]);
2626
- const [internalThreadId, setInternalThreadId] = (0, import_react11.useState)(props.threadId || (0, import_shared10.randomUUID)());
2627
- const setThreadId = (0, import_react11.useCallback)(
2740
+ const { threadId, setThreadId: setInternalThreadId } = useThreads();
2741
+ const setThreadId = (0, import_react16.useCallback)(
2628
2742
  (value) => {
2629
2743
  if (props.threadId) {
2630
2744
  throw new Error("Cannot call setThreadId() when threadId is provided via props.");
@@ -2633,51 +2747,61 @@ ${nonDocumentStrings}`;
2633
2747
  },
2634
2748
  [props.threadId]
2635
2749
  );
2636
- (0, import_react11.useEffect)(() => {
2637
- if (props.threadId !== void 0) {
2638
- setInternalThreadId(props.threadId);
2639
- }
2640
- }, [props.threadId]);
2641
- const [runId, setRunId] = (0, import_react11.useState)(null);
2642
- const chatAbortControllerRef = (0, import_react11.useRef)(null);
2750
+ const [runId, setRunId] = (0, import_react16.useState)(null);
2751
+ const chatAbortControllerRef = (0, import_react16.useRef)(null);
2643
2752
  const showDevConsole = shouldShowDevConsole(props.showDevConsole);
2644
- const [langGraphInterruptActions, _setLangGraphInterruptAction] = (0, import_react11.useState)({});
2645
- const setLangGraphInterruptAction = (0, import_react11.useCallback)(
2646
- (threadId, action) => {
2647
- _setLangGraphInterruptAction((prev) => {
2648
- var _a2, _b2, _c;
2649
- if (action == null)
2650
- return __spreadProps(__spreadValues({}, prev), {
2651
- [threadId]: null
2652
- });
2653
- let event = (_a2 = prev[threadId]) == null ? void 0 : _a2.event;
2654
- if (action.event) {
2655
- event = __spreadValues(__spreadValues({}, ((_b2 = prev[threadId]) == null ? void 0 : _b2.event) || {}), action.event);
2753
+ const [interruptActions, _setInterruptActions] = (0, import_react16.useState)({});
2754
+ const setInterruptAction = (0, import_react16.useCallback)(
2755
+ (threadId2, action) => {
2756
+ _setInterruptActions((prev) => {
2757
+ var _a2;
2758
+ if (action == null || !action.id) {
2759
+ return prev;
2656
2760
  }
2657
2761
  return __spreadProps(__spreadValues({}, prev), {
2658
- [threadId]: __spreadProps(__spreadValues(__spreadValues({}, (_c = prev[threadId]) != null ? _c : {}), action), { event })
2762
+ [action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
2659
2763
  });
2660
2764
  });
2661
2765
  },
2662
2766
  []
2663
2767
  );
2664
- const removeLangGraphInterruptAction = (0, import_react11.useCallback)((threadId) => {
2665
- setLangGraphInterruptAction(threadId, null);
2768
+ const removeInterruptAction = (0, import_react16.useCallback)((actionId) => {
2769
+ _setInterruptActions((prev) => {
2770
+ const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
2771
+ return rest;
2772
+ });
2666
2773
  }, []);
2667
- const memoizedChildren = (0, import_react11.useMemo)(() => children, [children]);
2668
- const [bannerError, setBannerError] = (0, import_react11.useState)(null);
2669
- const agentLock = (0, import_react11.useMemo)(() => {
2774
+ const [interruptEventQueue, setInterruptEventQueue] = (0, import_react16.useState)({});
2775
+ const addInterruptEvent = (0, import_react16.useCallback)((queuedEvent) => {
2776
+ setInterruptEventQueue((prev) => {
2777
+ const threadQueue = prev[queuedEvent.threadId] || [];
2778
+ return __spreadProps(__spreadValues({}, prev), {
2779
+ [queuedEvent.threadId]: [...threadQueue, queuedEvent]
2780
+ });
2781
+ });
2782
+ }, []);
2783
+ const removeInterruptEvent = (0, import_react16.useCallback)((threadId2, eventId) => {
2784
+ setInterruptEventQueue((prev) => {
2785
+ const threadQueue = prev[threadId2] || [];
2786
+ return __spreadProps(__spreadValues({}, prev), {
2787
+ [threadId2]: threadQueue.filter((event) => event.eventId !== eventId)
2788
+ });
2789
+ });
2790
+ }, []);
2791
+ const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
2792
+ const [bannerError, setBannerError] = (0, import_react16.useState)(null);
2793
+ const agentLock = (0, import_react16.useMemo)(() => {
2670
2794
  var _a2;
2671
2795
  return (_a2 = props.agent) != null ? _a2 : null;
2672
2796
  }, [props.agent]);
2673
- const forwardedParameters = (0, import_react11.useMemo)(
2797
+ const forwardedParameters = (0, import_react16.useMemo)(
2674
2798
  () => {
2675
2799
  var _a2;
2676
2800
  return (_a2 = props.forwardedParameters) != null ? _a2 : {};
2677
2801
  },
2678
2802
  [props.forwardedParameters]
2679
2803
  );
2680
- const updateExtensions = (0, import_react11.useCallback)(
2804
+ const updateExtensions = (0, import_react16.useCallback)(
2681
2805
  (newExtensions) => {
2682
2806
  setExtensions((prev) => {
2683
2807
  const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
@@ -2689,7 +2813,7 @@ ${nonDocumentStrings}`;
2689
2813
  },
2690
2814
  [setExtensions]
2691
2815
  );
2692
- const updateAuthStates = (0, import_react11.useCallback)(
2816
+ const updateAuthStates = (0, import_react16.useCallback)(
2693
2817
  (newAuthStates) => {
2694
2818
  setAuthStates((prev) => {
2695
2819
  const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
@@ -2701,81 +2825,115 @@ ${nonDocumentStrings}`;
2701
2825
  },
2702
2826
  [setAuthStates]
2703
2827
  );
2704
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2705
- CopilotContext.Provider,
2828
+ const handleSetRegisteredActions = (0, import_react16.useCallback)((actionConfig) => {
2829
+ const key = actionConfig.action.name || (0, import_shared13.randomUUID)();
2830
+ setRegisteredActionConfigs((prev) => {
2831
+ const newMap = new Map(prev);
2832
+ newMap.set(key, actionConfig);
2833
+ return newMap;
2834
+ });
2835
+ return key;
2836
+ }, []);
2837
+ const handleRemoveRegisteredAction = (0, import_react16.useCallback)((actionKey) => {
2838
+ setRegisteredActionConfigs((prev) => {
2839
+ const newMap = new Map(prev);
2840
+ newMap.delete(actionKey);
2841
+ return newMap;
2842
+ });
2843
+ }, []);
2844
+ const RegisteredActionsRenderer = (0, import_react16.useMemo)(() => {
2845
+ return () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: Array.from(registeredActionConfigs.entries()).map(([key, config]) => {
2846
+ const Component = config.component;
2847
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Component, { action: config.action }, key);
2848
+ }) });
2849
+ }, [registeredActionConfigs]);
2850
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2851
+ import_react17.CopilotChatConfigurationProvider,
2706
2852
  {
2707
- value: {
2708
- actions,
2709
- chatComponentsCache,
2710
- getFunctionCallHandler,
2711
- setAction,
2712
- removeAction,
2713
- coAgentStateRenders,
2714
- setCoAgentStateRender,
2715
- removeCoAgentStateRender,
2716
- getContextString,
2717
- addContext,
2718
- removeContext,
2719
- getAllContext,
2720
- getDocumentsContext,
2721
- addDocumentContext,
2722
- removeDocumentContext,
2723
- copilotApiConfig,
2724
- isLoading,
2725
- setIsLoading,
2726
- chatSuggestionConfiguration,
2727
- addChatSuggestionConfiguration,
2728
- removeChatSuggestionConfiguration,
2729
- chatInstructions,
2730
- setChatInstructions,
2731
- additionalInstructions,
2732
- setAdditionalInstructions,
2733
- showDevConsole,
2734
- coagentStates,
2735
- setCoagentStates,
2736
- coagentStatesRef,
2737
- setCoagentStatesWithRef,
2738
- agentSession,
2739
- setAgentSession,
2740
- runtimeClient,
2741
- forwardedParameters,
2742
- agentLock,
2743
- threadId: internalThreadId,
2744
- setThreadId,
2745
- runId,
2746
- setRunId,
2747
- chatAbortControllerRef,
2748
- availableAgents,
2749
- authConfig_c: props.authConfig_c,
2750
- authStates_c: authStates,
2751
- setAuthStates_c: updateAuthStates,
2752
- extensions,
2753
- setExtensions: updateExtensions,
2754
- langGraphInterruptAction: (_b = langGraphInterruptActions[internalThreadId]) != null ? _b : null,
2755
- setLangGraphInterruptAction,
2756
- removeLangGraphInterruptAction,
2757
- bannerError,
2758
- setBannerError,
2759
- onError: handleErrors,
2760
- internalErrorHandlers,
2761
- setInternalErrorHandler,
2762
- removeInternalErrorHandler
2763
- },
2764
- children: [
2765
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(CopilotMessages, { children: [
2766
- memoizedChildren,
2767
- showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ConsoleTrigger, {})
2768
- ] }) }),
2769
- bannerError && showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2770
- UsageBanner,
2771
- {
2772
- severity: bannerError.severity,
2773
- message: bannerError.message,
2774
- onClose: () => setBannerError(null),
2775
- actions: getErrorActions(bannerError)
2776
- }
2777
- )
2778
- ]
2853
+ agentId: (_b = agentSession == null ? void 0 : agentSession.agentName) != null ? _b : "default",
2854
+ threadId,
2855
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
2856
+ CopilotContext.Provider,
2857
+ {
2858
+ value: {
2859
+ actions,
2860
+ chatComponentsCache,
2861
+ getFunctionCallHandler,
2862
+ setAction,
2863
+ removeAction,
2864
+ setRegisteredActions: handleSetRegisteredActions,
2865
+ removeRegisteredAction: handleRemoveRegisteredAction,
2866
+ getContextString,
2867
+ addContext,
2868
+ removeContext,
2869
+ getAllContext,
2870
+ getDocumentsContext,
2871
+ addDocumentContext,
2872
+ removeDocumentContext,
2873
+ copilotApiConfig,
2874
+ isLoading,
2875
+ setIsLoading,
2876
+ chatSuggestionConfiguration,
2877
+ addChatSuggestionConfiguration,
2878
+ removeChatSuggestionConfiguration,
2879
+ chatInstructions,
2880
+ setChatInstructions,
2881
+ additionalInstructions,
2882
+ setAdditionalInstructions,
2883
+ showDevConsole,
2884
+ coagentStates,
2885
+ setCoagentStates,
2886
+ coagentStatesRef,
2887
+ setCoagentStatesWithRef,
2888
+ agentSession,
2889
+ setAgentSession,
2890
+ forwardedParameters,
2891
+ agentLock,
2892
+ threadId,
2893
+ setThreadId,
2894
+ runId,
2895
+ setRunId,
2896
+ chatAbortControllerRef,
2897
+ availableAgents,
2898
+ authConfig_c: props.authConfig_c,
2899
+ authStates_c: authStates,
2900
+ setAuthStates_c: updateAuthStates,
2901
+ extensions,
2902
+ setExtensions: updateExtensions,
2903
+ interruptActions,
2904
+ setInterruptAction,
2905
+ removeInterruptAction,
2906
+ interruptEventQueue,
2907
+ addInterruptEvent,
2908
+ removeInterruptEvent,
2909
+ bannerError,
2910
+ setBannerError,
2911
+ onError: handleErrors,
2912
+ internalErrorHandlers,
2913
+ setInternalErrorHandler,
2914
+ removeInternalErrorHandler
2915
+ },
2916
+ children: [
2917
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CopilotListeners, {}),
2918
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(CoAgentStateRendersProvider, { children: [
2919
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(CopilotMessages, { children: [
2920
+ memoizedChildren,
2921
+ showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ConsoleTrigger, {}),
2922
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RegisteredActionsRenderer, {})
2923
+ ] }) }),
2924
+ bannerError && showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2925
+ UsageBanner,
2926
+ {
2927
+ severity: bannerError.severity,
2928
+ message: bannerError.message,
2929
+ onClose: () => setBannerError(null),
2930
+ actions: getErrorActions(bannerError)
2931
+ }
2932
+ )
2933
+ ] })
2934
+ ]
2935
+ }
2936
+ )
2779
2937
  }
2780
2938
  );
2781
2939
  }
@@ -2812,12 +2970,12 @@ function validateProps(props) {
2812
2970
  const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
2813
2971
  const hasApiKey = props.publicApiKey || props.publicLicenseKey;
2814
2972
  if (!props.runtimeUrl && !hasApiKey) {
2815
- throw new import_shared10.ConfigurationError(
2973
+ throw new import_shared13.ConfigurationError(
2816
2974
  "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'"
2817
2975
  );
2818
2976
  }
2819
2977
  if (cloudFeatures.length > 0 && !hasApiKey) {
2820
- throw new import_shared10.MissingPublicApiKeyError(
2978
+ throw new import_shared13.MissingPublicApiKeyError(
2821
2979
  `Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
2822
2980
  );
2823
2981
  }