@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,1960 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __restKey = (key) => typeof key === "symbol" ? key : key + "";
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols)
32
+ for (var prop of __getOwnPropSymbols(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
38
+ var __export = (target, all) => {
39
+ for (var name in all)
40
+ __defProp(target, name, { get: all[name], enumerable: true });
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
57
+ ));
58
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
59
+ var __async = (__this, __arguments, generator) => {
60
+ return new Promise((resolve, reject) => {
61
+ var fulfilled = (value) => {
62
+ try {
63
+ step(generator.next(value));
64
+ } catch (e) {
65
+ reject(e);
66
+ }
67
+ };
68
+ var rejected = (value) => {
69
+ try {
70
+ step(generator.throw(value));
71
+ } catch (e) {
72
+ reject(e);
73
+ }
74
+ };
75
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
76
+ step((generator = generator.apply(__this, __arguments)).next());
77
+ });
78
+ };
79
+
80
+ // src/components/copilot-provider/copilotkit.tsx
81
+ var copilotkit_exports = {};
82
+ __export(copilotkit_exports, {
83
+ CopilotKit: () => CopilotKit,
84
+ CopilotKitInternal: () => CopilotKitInternal,
85
+ defaultCopilotContextCategories: () => defaultCopilotContextCategories
86
+ });
87
+ module.exports = __toCommonJS(copilotkit_exports);
88
+ var import_react14 = require("react");
89
+ var import_react15 = require("@copilotkitnext/react");
90
+
91
+ // src/context/copilot-context.tsx
92
+ var import_react = __toESM(require("react"));
93
+ var emptyCopilotContext = {
94
+ actions: {},
95
+ setAction: () => {
96
+ },
97
+ removeAction: () => {
98
+ },
99
+ setRegisteredActions: () => "",
100
+ removeRegisteredAction: () => {
101
+ },
102
+ chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
103
+ getContextString: (documents, categories) => returnAndThrowInDebug(""),
104
+ addContext: () => "",
105
+ removeContext: () => {
106
+ },
107
+ getAllContext: () => [],
108
+ getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
109
+ })),
110
+ isLoading: false,
111
+ setIsLoading: () => returnAndThrowInDebug(false),
112
+ chatInstructions: "",
113
+ setChatInstructions: () => returnAndThrowInDebug(""),
114
+ additionalInstructions: [],
115
+ setAdditionalInstructions: () => returnAndThrowInDebug([]),
116
+ getDocumentsContext: (categories) => returnAndThrowInDebug([]),
117
+ addDocumentContext: () => returnAndThrowInDebug(""),
118
+ removeDocumentContext: () => {
119
+ },
120
+ copilotApiConfig: new class {
121
+ get chatApiEndpoint() {
122
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
123
+ }
124
+ get headers() {
125
+ return {};
126
+ }
127
+ get body() {
128
+ return {};
129
+ }
130
+ }(),
131
+ chatSuggestionConfiguration: {},
132
+ addChatSuggestionConfiguration: () => {
133
+ },
134
+ removeChatSuggestionConfiguration: () => {
135
+ },
136
+ showDevConsole: false,
137
+ coagentStates: {},
138
+ setCoagentStates: () => {
139
+ },
140
+ coagentStatesRef: { current: {} },
141
+ setCoagentStatesWithRef: () => {
142
+ },
143
+ agentSession: null,
144
+ setAgentSession: () => {
145
+ },
146
+ forwardedParameters: {},
147
+ agentLock: null,
148
+ threadId: "",
149
+ setThreadId: () => {
150
+ },
151
+ runId: null,
152
+ setRunId: () => {
153
+ },
154
+ chatAbortControllerRef: { current: null },
155
+ availableAgents: [],
156
+ extensions: {},
157
+ setExtensions: () => {
158
+ },
159
+ interruptActions: {},
160
+ setInterruptAction: () => {
161
+ },
162
+ removeInterruptAction: () => {
163
+ },
164
+ interruptEventQueue: {},
165
+ addInterruptEvent: () => {
166
+ },
167
+ resolveInterruptEvent: () => {
168
+ },
169
+ onError: () => {
170
+ },
171
+ bannerError: null,
172
+ setBannerError: () => {
173
+ },
174
+ internalErrorHandlers: {},
175
+ setInternalErrorHandler: () => {
176
+ },
177
+ removeInternalErrorHandler: () => {
178
+ }
179
+ };
180
+ var CopilotContext = import_react.default.createContext(emptyCopilotContext);
181
+ function useCopilotContext() {
182
+ const context = import_react.default.useContext(CopilotContext);
183
+ if (context === emptyCopilotContext) {
184
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
185
+ }
186
+ return context;
187
+ }
188
+ function returnAndThrowInDebug(_value) {
189
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
190
+ }
191
+
192
+ // src/hooks/use-tree.ts
193
+ var import_shared = require("@copilotkit/shared");
194
+ var import_react2 = require("react");
195
+ var removeNode = (nodes, id) => {
196
+ return nodes.reduce((result, node) => {
197
+ if (node.id !== id) {
198
+ const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
199
+ result.push(newNode);
200
+ }
201
+ return result;
202
+ }, []);
203
+ };
204
+ var addNode = (nodes, newNode, parentId) => {
205
+ if (!parentId) {
206
+ return [...nodes, newNode];
207
+ }
208
+ return nodes.map((node) => {
209
+ if (node.id === parentId) {
210
+ return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
211
+ } else if (node.children.length) {
212
+ return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
213
+ }
214
+ return node;
215
+ });
216
+ };
217
+ var treeIndentationRepresentation = (index, indentLevel) => {
218
+ if (indentLevel === 0) {
219
+ return (index + 1).toString();
220
+ } else if (indentLevel === 1) {
221
+ return String.fromCharCode(65 + index);
222
+ } else if (indentLevel === 2) {
223
+ return String.fromCharCode(97 + index);
224
+ } else {
225
+ return "-";
226
+ }
227
+ };
228
+ var printNode = (node, prefix = "", indentLevel = 0) => {
229
+ const indent = " ".repeat(3).repeat(indentLevel);
230
+ const prefixPlusIndentLength = prefix.length + indent.length;
231
+ const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
232
+ const valueLines = node.value.split("\n");
233
+ const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
234
+ const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
235
+ let output = `${outputFirstLine}
236
+ `;
237
+ if (outputSubsequentLines) {
238
+ output += `${outputSubsequentLines}
239
+ `;
240
+ }
241
+ const childPrePrefix = " ".repeat(prefix.length);
242
+ node.children.forEach(
243
+ (child, index) => output += printNode(
244
+ child,
245
+ `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
246
+ indentLevel + 1
247
+ )
248
+ );
249
+ return output;
250
+ };
251
+ function treeReducer(state, action) {
252
+ switch (action.type) {
253
+ case "ADD_NODE": {
254
+ const { value, parentId, id: newNodeId } = action;
255
+ const newNode = {
256
+ id: newNodeId,
257
+ value,
258
+ children: [],
259
+ categories: new Set(action.categories)
260
+ };
261
+ try {
262
+ return addNode(state, newNode, parentId);
263
+ } catch (error) {
264
+ console.error(`Error while adding node with id ${newNodeId}: ${error}`);
265
+ return state;
266
+ }
267
+ }
268
+ case "REMOVE_NODE":
269
+ return removeNode(state, action.id);
270
+ default:
271
+ return state;
272
+ }
273
+ }
274
+ var useTree = () => {
275
+ const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
276
+ const addElement = (0, import_react2.useCallback)(
277
+ (value, categories, parentId) => {
278
+ const newNodeId = (0, import_shared.randomId)();
279
+ dispatch({
280
+ type: "ADD_NODE",
281
+ value,
282
+ parentId,
283
+ id: newNodeId,
284
+ categories
285
+ });
286
+ return newNodeId;
287
+ },
288
+ []
289
+ );
290
+ const removeElement = (0, import_react2.useCallback)((id) => {
291
+ dispatch({ type: "REMOVE_NODE", id });
292
+ }, []);
293
+ const getAllElements = (0, import_react2.useCallback)(() => {
294
+ return tree;
295
+ }, [tree]);
296
+ const printTree = (0, import_react2.useCallback)(
297
+ (categories) => {
298
+ const categoriesSet = new Set(categories);
299
+ let output = "";
300
+ tree.forEach((node, index) => {
301
+ if (!setsHaveIntersection(categoriesSet, node.categories)) {
302
+ return;
303
+ }
304
+ if (index !== 0) {
305
+ output += "\n";
306
+ }
307
+ output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
308
+ });
309
+ return output;
310
+ },
311
+ [tree]
312
+ );
313
+ return { tree, addElement, printTree, removeElement, getAllElements };
314
+ };
315
+ var use_tree_default = useTree;
316
+ function setsHaveIntersection(setA, setB) {
317
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
318
+ for (let item of smallerSet) {
319
+ if (largerSet.has(item)) {
320
+ return true;
321
+ }
322
+ }
323
+ return false;
324
+ }
325
+
326
+ // src/components/copilot-provider/copilotkit.tsx
327
+ var import_react_dom = require("react-dom");
328
+ var import_shared12 = require("@copilotkit/shared");
329
+
330
+ // src/hooks/use-flat-category-store.ts
331
+ var import_react3 = require("react");
332
+ var import_shared2 = require("@copilotkit/shared");
333
+ var useFlatCategoryStore = () => {
334
+ const [elements, dispatch] = (0, import_react3.useReducer)(
335
+ flatCategoryStoreReducer,
336
+ /* @__PURE__ */ new Map()
337
+ );
338
+ const addElement = (0, import_react3.useCallback)((value, categories) => {
339
+ const newId = (0, import_shared2.randomId)();
340
+ dispatch({
341
+ type: "ADD_ELEMENT",
342
+ value,
343
+ id: newId,
344
+ categories
345
+ });
346
+ return newId;
347
+ }, []);
348
+ const removeElement = (0, import_react3.useCallback)((id) => {
349
+ dispatch({ type: "REMOVE_ELEMENT", id });
350
+ }, []);
351
+ const allElements = (0, import_react3.useCallback)(
352
+ (categories) => {
353
+ const categoriesSet = new Set(categories);
354
+ const result = [];
355
+ elements.forEach((element) => {
356
+ if (setsHaveIntersection2(categoriesSet, element.categories)) {
357
+ result.push(element.value);
358
+ }
359
+ });
360
+ return result;
361
+ },
362
+ [elements]
363
+ );
364
+ return { addElement, removeElement, allElements };
365
+ };
366
+ var use_flat_category_store_default = useFlatCategoryStore;
367
+ function flatCategoryStoreReducer(state, action) {
368
+ switch (action.type) {
369
+ case "ADD_ELEMENT": {
370
+ const { value, id, categories } = action;
371
+ const newElement = {
372
+ id,
373
+ value,
374
+ categories: new Set(categories)
375
+ };
376
+ const newState = new Map(state);
377
+ newState.set(id, newElement);
378
+ return newState;
379
+ }
380
+ case "REMOVE_ELEMENT": {
381
+ const newState = new Map(state);
382
+ newState.delete(action.id);
383
+ return newState;
384
+ }
385
+ default:
386
+ return state;
387
+ }
388
+ }
389
+ function setsHaveIntersection2(setA, setB) {
390
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
391
+ for (let item of smallerSet) {
392
+ if (largerSet.has(item)) {
393
+ return true;
394
+ }
395
+ }
396
+ return false;
397
+ }
398
+
399
+ // src/components/copilot-provider/copilot-messages.tsx
400
+ var import_react6 = require("react");
401
+
402
+ // src/context/copilot-messages-context.tsx
403
+ var import_react4 = __toESM(require("react"));
404
+ var emptyCopilotContext2 = {
405
+ messages: [],
406
+ setMessages: () => [],
407
+ // suggestions state
408
+ suggestions: [],
409
+ setSuggestions: () => []
410
+ };
411
+ var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
412
+
413
+ // src/components/toast/toast-provider.tsx
414
+ var import_react5 = require("react");
415
+ var import_shared3 = require("@copilotkit/shared");
416
+ var import_jsx_runtime = require("react/jsx-runtime");
417
+ var ToastContext = (0, import_react5.createContext)(void 0);
418
+ function getErrorSeverity(error) {
419
+ if (error.severity) {
420
+ switch (error.severity) {
421
+ case import_shared3.Severity.CRITICAL:
422
+ return "critical";
423
+ case import_shared3.Severity.WARNING:
424
+ return "warning";
425
+ case import_shared3.Severity.INFO:
426
+ return "info";
427
+ default:
428
+ return "info";
429
+ }
430
+ }
431
+ const message = error.message.toLowerCase();
432
+ if (message.includes("api key") || message.includes("401") || message.includes("unauthorized") || message.includes("authentication") || message.includes("incorrect api key")) {
433
+ return "critical";
434
+ }
435
+ return "info";
436
+ }
437
+ function getErrorColors(severity) {
438
+ switch (severity) {
439
+ case "critical":
440
+ return {
441
+ background: "#fee2e2",
442
+ border: "#dc2626",
443
+ text: "#7f1d1d",
444
+ icon: "#dc2626"
445
+ };
446
+ case "warning":
447
+ return {
448
+ background: "#fef3c7",
449
+ border: "#d97706",
450
+ text: "#78350f",
451
+ icon: "#d97706"
452
+ };
453
+ case "info":
454
+ return {
455
+ background: "#dbeafe",
456
+ border: "#2563eb",
457
+ text: "#1e3a8a",
458
+ icon: "#2563eb"
459
+ };
460
+ }
461
+ }
462
+ function useToast() {
463
+ const context = (0, import_react5.useContext)(ToastContext);
464
+ if (!context) {
465
+ throw new Error("useToast must be used within a ToastProvider");
466
+ }
467
+ return context;
468
+ }
469
+ function ToastProvider({
470
+ enabled,
471
+ children
472
+ }) {
473
+ const [toasts, setToasts] = (0, import_react5.useState)([]);
474
+ const [bannerError, setBannerErrorState] = (0, import_react5.useState)(null);
475
+ const removeToast = (0, import_react5.useCallback)((id) => {
476
+ setToasts((prev) => prev.filter((toast) => toast.id !== id));
477
+ }, []);
478
+ const addToast = (0, import_react5.useCallback)(
479
+ (toast) => {
480
+ var _a;
481
+ if (!enabled) {
482
+ return;
483
+ }
484
+ const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
485
+ setToasts((currentToasts) => {
486
+ if (currentToasts.find((toast2) => toast2.id === id))
487
+ return currentToasts;
488
+ return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
489
+ });
490
+ if (toast.duration) {
491
+ setTimeout(() => {
492
+ removeToast(id);
493
+ }, toast.duration);
494
+ }
495
+ },
496
+ [enabled, removeToast]
497
+ );
498
+ const setBannerError = (0, import_react5.useCallback)(
499
+ (error) => {
500
+ if (!enabled && error !== null) {
501
+ return;
502
+ }
503
+ setBannerErrorState(error);
504
+ },
505
+ [enabled]
506
+ );
507
+ const addGraphQLErrorsToast = (0, import_react5.useCallback)((errors) => {
508
+ console.warn("addGraphQLErrorsToast is deprecated. All errors now show as banners.");
509
+ }, []);
510
+ const value = {
511
+ toasts,
512
+ addToast,
513
+ addGraphQLErrorsToast,
514
+ removeToast,
515
+ enabled,
516
+ bannerError,
517
+ setBannerError
518
+ };
519
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value, children: [
520
+ bannerError && (() => {
521
+ const severity = getErrorSeverity(bannerError);
522
+ const colors = getErrorColors(severity);
523
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
524
+ "div",
525
+ {
526
+ style: {
527
+ position: "fixed",
528
+ bottom: "20px",
529
+ left: "50%",
530
+ transform: "translateX(-50%)",
531
+ zIndex: 9999,
532
+ backgroundColor: colors.background,
533
+ border: `1px solid ${colors.border}`,
534
+ borderLeft: `4px solid ${colors.border}`,
535
+ borderRadius: "8px",
536
+ padding: "12px 16px",
537
+ fontSize: "13px",
538
+ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
539
+ backdropFilter: "blur(8px)",
540
+ maxWidth: "min(90vw, 700px)",
541
+ width: "100%",
542
+ boxSizing: "border-box",
543
+ overflow: "hidden"
544
+ },
545
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
546
+ "div",
547
+ {
548
+ style: {
549
+ display: "flex",
550
+ justifyContent: "space-between",
551
+ alignItems: "center",
552
+ gap: "10px"
553
+ },
554
+ children: [
555
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
556
+ "div",
557
+ {
558
+ style: {
559
+ display: "flex",
560
+ alignItems: "center",
561
+ gap: "8px",
562
+ flex: 1,
563
+ minWidth: 0
564
+ },
565
+ children: [
566
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
567
+ "div",
568
+ {
569
+ style: {
570
+ width: "12px",
571
+ height: "12px",
572
+ borderRadius: "50%",
573
+ backgroundColor: colors.border,
574
+ flexShrink: 0
575
+ }
576
+ }
577
+ ),
578
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
579
+ "div",
580
+ {
581
+ style: {
582
+ display: "flex",
583
+ alignItems: "center",
584
+ gap: "10px",
585
+ flex: 1,
586
+ minWidth: 0
587
+ },
588
+ children: [
589
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
590
+ "div",
591
+ {
592
+ style: {
593
+ color: colors.text,
594
+ lineHeight: "1.4",
595
+ fontWeight: "400",
596
+ fontSize: "13px",
597
+ flex: 1,
598
+ wordBreak: "break-all",
599
+ overflowWrap: "break-word",
600
+ maxWidth: "550px",
601
+ overflow: "hidden",
602
+ display: "-webkit-box",
603
+ WebkitLineClamp: 10,
604
+ WebkitBoxOrient: "vertical"
605
+ },
606
+ children: (() => {
607
+ let message = bannerError.message;
608
+ const jsonMatch = message.match(/'message':\s*'([^']+)'/);
609
+ if (jsonMatch) {
610
+ return jsonMatch[1];
611
+ }
612
+ message = message.split(" - ")[0];
613
+ message = message.split(": Error code")[0];
614
+ message = message.replace(/:\s*\d{3}$/, "");
615
+ message = message.replace(/See more:.*$/g, "");
616
+ message = message.trim();
617
+ return message || "Configuration error occurred.";
618
+ })()
619
+ }
620
+ ),
621
+ (() => {
622
+ const message = bannerError.message;
623
+ const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
624
+ const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
625
+ let url = null;
626
+ let buttonText = "See More";
627
+ const markdownMatch = markdownLinkRegex.exec(message);
628
+ if (markdownMatch) {
629
+ url = markdownMatch[2];
630
+ buttonText = "See More";
631
+ } else {
632
+ const urlMatch = plainUrlRegex.exec(message);
633
+ if (urlMatch) {
634
+ url = urlMatch[0].replace(/[.,;:'"]*$/, "");
635
+ buttonText = "See More";
636
+ }
637
+ }
638
+ if (!url)
639
+ return null;
640
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
641
+ "button",
642
+ {
643
+ onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
644
+ style: {
645
+ background: colors.border,
646
+ color: "white",
647
+ border: "none",
648
+ borderRadius: "5px",
649
+ padding: "4px 10px",
650
+ fontSize: "11px",
651
+ fontWeight: "500",
652
+ cursor: "pointer",
653
+ transition: "all 0.2s ease",
654
+ flexShrink: 0
655
+ },
656
+ onMouseEnter: (e) => {
657
+ e.currentTarget.style.opacity = "0.9";
658
+ e.currentTarget.style.transform = "translateY(-1px)";
659
+ },
660
+ onMouseLeave: (e) => {
661
+ e.currentTarget.style.opacity = "1";
662
+ e.currentTarget.style.transform = "translateY(0)";
663
+ },
664
+ children: buttonText
665
+ }
666
+ );
667
+ })()
668
+ ]
669
+ }
670
+ )
671
+ ]
672
+ }
673
+ ),
674
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
675
+ "button",
676
+ {
677
+ onClick: () => setBannerError(null),
678
+ style: {
679
+ background: "transparent",
680
+ border: "none",
681
+ color: colors.text,
682
+ cursor: "pointer",
683
+ padding: "2px",
684
+ borderRadius: "3px",
685
+ fontSize: "14px",
686
+ lineHeight: "1",
687
+ opacity: 0.6,
688
+ transition: "all 0.2s ease",
689
+ flexShrink: 0
690
+ },
691
+ title: "Dismiss",
692
+ onMouseEnter: (e) => {
693
+ e.currentTarget.style.opacity = "1";
694
+ e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
695
+ },
696
+ onMouseLeave: (e) => {
697
+ e.currentTarget.style.opacity = "0.6";
698
+ e.currentTarget.style.background = "transparent";
699
+ },
700
+ children: "\xD7"
701
+ }
702
+ )
703
+ ]
704
+ }
705
+ )
706
+ }
707
+ );
708
+ })(),
709
+ children
710
+ ] });
711
+ }
712
+
713
+ // src/utils/dev-console.ts
714
+ function isLocalhost() {
715
+ if (typeof window === "undefined")
716
+ return false;
717
+ return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
718
+ }
719
+ function shouldShowDevConsole(showDevConsole) {
720
+ if (showDevConsole !== void 0) {
721
+ return showDevConsole;
722
+ }
723
+ return isLocalhost();
724
+ }
725
+
726
+ // src/components/copilot-provider/copilot-messages.tsx
727
+ var import_shared4 = require("@copilotkit/shared");
728
+ var import_jsx_runtime2 = require("react/jsx-runtime");
729
+ var MessagesTapContext = (0, import_react6.createContext)(null);
730
+ function useMessagesTap() {
731
+ const tap = (0, import_react6.useContext)(MessagesTapContext);
732
+ if (!tap)
733
+ throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
734
+ return tap;
735
+ }
736
+ function MessagesTapProvider({ children }) {
737
+ const messagesRef = (0, import_react6.useRef)([]);
738
+ const tapRef = (0, import_react6.useRef)({
739
+ getMessagesFromTap: () => messagesRef.current,
740
+ updateTapMessages: (messages) => {
741
+ messagesRef.current = messages;
742
+ }
743
+ });
744
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MessagesTapContext.Provider, { value: tapRef.current, children });
745
+ }
746
+ function CopilotMessages({ children }) {
747
+ const [messages, setMessages] = (0, import_react6.useState)([]);
748
+ const lastLoadedThreadId = (0, import_react6.useRef)(void 0);
749
+ const lastLoadedAgentName = (0, import_react6.useRef)(void 0);
750
+ const lastLoadedMessages = (0, import_react6.useRef)(void 0);
751
+ const { updateTapMessages } = useMessagesTap();
752
+ const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
753
+ const { setBannerError } = useToast();
754
+ const traceUIError = (0, import_react6.useCallback)(
755
+ (error, originalError) => __async(this, null, function* () {
756
+ if (!onError || !copilotApiConfig.publicApiKey)
757
+ return;
758
+ try {
759
+ const traceEvent = {
760
+ type: "error",
761
+ timestamp: Date.now(),
762
+ context: {
763
+ source: "ui",
764
+ request: {
765
+ operation: "loadAgentState",
766
+ url: copilotApiConfig.chatApiEndpoint,
767
+ startTime: Date.now()
768
+ },
769
+ technical: {
770
+ environment: "browser",
771
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
772
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
773
+ }
774
+ },
775
+ error
776
+ };
777
+ yield onError(traceEvent);
778
+ } catch (traceError) {
779
+ console.error("Error in CopilotMessages onError handler:", traceError);
780
+ }
781
+ }),
782
+ [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
783
+ );
784
+ const createStructuredError = (gqlError) => {
785
+ const extensions = gqlError.extensions;
786
+ const originalError = extensions == null ? void 0 : extensions.originalError;
787
+ if (originalError == null ? void 0 : originalError.stack) {
788
+ if (originalError.stack.includes("CopilotApiDiscoveryError")) {
789
+ return new import_shared4.CopilotKitApiDiscoveryError({ message: originalError.message });
790
+ }
791
+ if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) {
792
+ return new import_shared4.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
793
+ }
794
+ if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) {
795
+ return new import_shared4.CopilotKitAgentDiscoveryError({
796
+ agentName: "",
797
+ availableAgents: []
798
+ });
799
+ }
800
+ }
801
+ const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
802
+ const code = extensions == null ? void 0 : extensions.code;
803
+ if (code) {
804
+ return new import_shared4.CopilotKitError({ message, code });
805
+ }
806
+ return null;
807
+ };
808
+ const handleGraphQLErrors = (0, import_react6.useCallback)(
809
+ (error) => {
810
+ var _a;
811
+ if ((_a = error.graphQLErrors) == null ? void 0 : _a.length) {
812
+ const graphQLErrors = error.graphQLErrors;
813
+ const routeError = (gqlError) => {
814
+ const extensions = gqlError.extensions;
815
+ const visibility = extensions == null ? void 0 : extensions.visibility;
816
+ const isDev = shouldShowDevConsole(showDevConsole);
817
+ if (!isDev) {
818
+ console.error("CopilotKit Error (hidden in production):", gqlError.message);
819
+ return;
820
+ }
821
+ if (visibility === import_shared4.ErrorVisibility.SILENT) {
822
+ console.error("CopilotKit Silent Error:", gqlError.message);
823
+ return;
824
+ }
825
+ const ckError = createStructuredError(gqlError);
826
+ if (ckError) {
827
+ setBannerError(ckError);
828
+ traceUIError(ckError, gqlError);
829
+ } else {
830
+ const fallbackError = new import_shared4.CopilotKitError({
831
+ message: gqlError.message,
832
+ code: import_shared4.CopilotKitErrorCode.UNKNOWN
833
+ });
834
+ setBannerError(fallbackError);
835
+ traceUIError(fallbackError, gqlError);
836
+ }
837
+ };
838
+ graphQLErrors.forEach(routeError);
839
+ } else {
840
+ const isDev = shouldShowDevConsole(showDevConsole);
841
+ if (!isDev) {
842
+ console.error("CopilotKit Error (hidden in production):", error);
843
+ } else {
844
+ const fallbackError = new import_shared4.CopilotKitError({
845
+ message: (error == null ? void 0 : error.message) || String(error),
846
+ code: import_shared4.CopilotKitErrorCode.UNKNOWN
847
+ });
848
+ setBannerError(fallbackError);
849
+ traceUIError(fallbackError, error);
850
+ }
851
+ }
852
+ },
853
+ [setBannerError, showDevConsole, traceUIError]
854
+ );
855
+ (0, import_react6.useEffect)(() => {
856
+ updateTapMessages(messages);
857
+ }, [messages, updateTapMessages]);
858
+ const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
859
+ const [suggestions, setSuggestions] = (0, import_react6.useState)([]);
860
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
861
+ CopilotMessagesContext.Provider,
862
+ {
863
+ value: {
864
+ messages,
865
+ setMessages,
866
+ suggestions,
867
+ setSuggestions
868
+ },
869
+ children: memoizedChildren
870
+ }
871
+ );
872
+ }
873
+
874
+ // src/components/usage-banner.tsx
875
+ var import_shared5 = require("@copilotkit/shared");
876
+ var import_jsx_runtime3 = require("react/jsx-runtime");
877
+ function UsageBanner({
878
+ severity = import_shared5.Severity.CRITICAL,
879
+ message = "",
880
+ onClose,
881
+ actions
882
+ }) {
883
+ if (!message || !severity) {
884
+ return null;
885
+ }
886
+ const themes = {
887
+ [import_shared5.Severity.INFO]: {
888
+ bg: "#f8fafc",
889
+ border: "#e2e8f0",
890
+ text: "#475569",
891
+ accent: "#3b82f6"
892
+ },
893
+ [import_shared5.Severity.WARNING]: {
894
+ bg: "#fffbeb",
895
+ border: "#fbbf24",
896
+ text: "#92400e",
897
+ accent: "#f59e0b"
898
+ },
899
+ [import_shared5.Severity.CRITICAL]: {
900
+ bg: "#fef2f2",
901
+ border: "#fecaca",
902
+ text: "#dc2626",
903
+ accent: "#ef4444"
904
+ }
905
+ };
906
+ const theme = themes[severity];
907
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
908
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
909
+ @keyframes slideUp {
910
+ from { opacity: 0; transform: translateX(-50%) translateY(8px); }
911
+ to { opacity: 1; transform: translateX(-50%) translateY(0); }
912
+ }
913
+
914
+ .usage-banner {
915
+ position: fixed;
916
+ bottom: 24px;
917
+ left: 50%;
918
+ transform: translateX(-50%);
919
+ width: min(600px, calc(100vw - 32px));
920
+ z-index: 10000;
921
+ animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
922
+ }
923
+
924
+ .banner-content {
925
+ background: linear-gradient(135deg, ${theme.bg} 0%, ${theme.bg}f5 100%);
926
+ border: 1px solid ${theme.border};
927
+ border-radius: 12px;
928
+ padding: 18px 20px;
929
+ box-shadow:
930
+ 0 4px 24px rgba(0, 0, 0, 0.08),
931
+ 0 2px 8px rgba(0, 0, 0, 0.04),
932
+ inset 0 1px 0 rgba(255, 255, 255, 0.7);
933
+ display: flex;
934
+ align-items: center;
935
+ gap: 16px;
936
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
937
+ backdrop-filter: blur(12px);
938
+ position: relative;
939
+ overflow: hidden;
940
+ }
941
+
942
+ .banner-content::before {
943
+ content: '';
944
+ position: absolute;
945
+ top: 0;
946
+ left: 0;
947
+ right: 0;
948
+ height: 1px;
949
+ background: linear-gradient(90deg, transparent, ${theme.accent}40, transparent);
950
+ }
951
+
952
+ .banner-message {
953
+ color: ${theme.text};
954
+ font-size: 14px;
955
+ line-height: 1.5;
956
+ font-weight: 500;
957
+ flex: 1;
958
+ letter-spacing: -0.01em;
959
+ }
960
+
961
+ .close-btn {
962
+ background: rgba(0, 0, 0, 0.05);
963
+ border: none;
964
+ color: ${theme.text};
965
+ cursor: pointer;
966
+ padding: 0;
967
+ border-radius: 6px;
968
+ opacity: 0.6;
969
+ transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
970
+ font-size: 14px;
971
+ line-height: 1;
972
+ flex-shrink: 0;
973
+ width: 24px;
974
+ height: 24px;
975
+ display: flex;
976
+ align-items: center;
977
+ justify-content: center;
978
+ }
979
+
980
+ .close-btn:hover {
981
+ opacity: 1;
982
+ background: rgba(0, 0, 0, 0.08);
983
+ transform: scale(1.05);
984
+ }
985
+
986
+ .btn-primary {
987
+ background: linear-gradient(135deg, ${theme.accent} 0%, ${theme.accent}e6 100%);
988
+ color: white;
989
+ border: none;
990
+ border-radius: 8px;
991
+ padding: 10px 18px;
992
+ font-size: 13px;
993
+ font-weight: 600;
994
+ cursor: pointer;
995
+ transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
996
+ font-family: inherit;
997
+ flex-shrink: 0;
998
+ box-shadow:
999
+ 0 2px 8px ${theme.accent}30,
1000
+ inset 0 1px 0 rgba(255, 255, 255, 0.2);
1001
+ letter-spacing: -0.01em;
1002
+ }
1003
+
1004
+ .btn-primary:hover {
1005
+ transform: translateY(-1px) scale(1.02);
1006
+ box-shadow:
1007
+ 0 4px 12px ${theme.accent}40,
1008
+ inset 0 1px 0 rgba(255, 255, 255, 0.25);
1009
+ }
1010
+
1011
+ .btn-primary:active {
1012
+ transform: translateY(0) scale(0.98);
1013
+ transition: all 0.08s cubic-bezier(0.16, 1, 0.3, 1);
1014
+ }
1015
+
1016
+ @media (max-width: 640px) {
1017
+ .usage-banner {
1018
+ width: calc(100vw - 24px);
1019
+ }
1020
+
1021
+ .banner-content {
1022
+ padding: 16px;
1023
+ gap: 12px;
1024
+ }
1025
+
1026
+ .banner-message {
1027
+ font-size: 13px;
1028
+ line-height: 1.45;
1029
+ }
1030
+
1031
+ .btn-primary {
1032
+ padding: 8px 14px;
1033
+ font-size: 12px;
1034
+ }
1035
+
1036
+ .close-btn {
1037
+ width: 22px;
1038
+ height: 22px;
1039
+ font-size: 12px;
1040
+ }
1041
+ }
1042
+ ` }),
1043
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "usage-banner", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "banner-content", children: [
1044
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "banner-message", children: message }),
1045
+ (actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "btn-primary", onClick: actions.primary.onClick, children: actions.primary.label }),
1046
+ onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "close-btn", onClick: onClose, title: "Close", children: "\xD7" })
1047
+ ] }) })
1048
+ ] });
1049
+ }
1050
+ var getErrorActions = (error) => {
1051
+ switch (error.code) {
1052
+ case import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR:
1053
+ return {
1054
+ primary: {
1055
+ label: "Show me how",
1056
+ onClick: () => window.open(
1057
+ "https://docs.copilotkit.ai/premium#how-do-i-get-access-to-premium-features",
1058
+ "_blank",
1059
+ "noopener,noreferrer"
1060
+ )
1061
+ }
1062
+ };
1063
+ case import_shared5.CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR:
1064
+ return {
1065
+ primary: {
1066
+ label: "Upgrade",
1067
+ onClick: () => window.open("https://cloud.copilotkit.ai", "_blank", "noopener,noreferrer")
1068
+ }
1069
+ };
1070
+ default:
1071
+ return void 0;
1072
+ }
1073
+ };
1074
+
1075
+ // src/components/error-boundary/error-boundary.tsx
1076
+ var import_react7 = __toESM(require("react"));
1077
+ var import_shared7 = require("@copilotkit/shared");
1078
+
1079
+ // src/lib/status-checker.ts
1080
+ var import_shared6 = require("@copilotkit/shared");
1081
+ var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
1082
+ var StatusChecker = class {
1083
+ constructor() {
1084
+ this.activeKey = null;
1085
+ this.intervalId = null;
1086
+ this.instanceCount = 0;
1087
+ this.lastResponse = null;
1088
+ }
1089
+ start(publicApiKey, onUpdate) {
1090
+ return __async(this, null, function* () {
1091
+ this.instanceCount++;
1092
+ if (this.activeKey === publicApiKey)
1093
+ return;
1094
+ if (this.intervalId)
1095
+ clearInterval(this.intervalId);
1096
+ const checkStatus = () => __async(this, null, function* () {
1097
+ try {
1098
+ const response = yield fetch(`${import_shared6.COPILOT_CLOUD_API_URL}/ciu`, {
1099
+ method: "GET",
1100
+ headers: {
1101
+ [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
1102
+ }
1103
+ }).then((response2) => response2.json());
1104
+ this.lastResponse = response;
1105
+ onUpdate == null ? void 0 : onUpdate(response);
1106
+ return response;
1107
+ } catch (error) {
1108
+ return null;
1109
+ }
1110
+ });
1111
+ const initialResponse = yield checkStatus();
1112
+ this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
1113
+ this.activeKey = publicApiKey;
1114
+ return initialResponse;
1115
+ });
1116
+ }
1117
+ getLastResponse() {
1118
+ return this.lastResponse;
1119
+ }
1120
+ stop() {
1121
+ this.instanceCount--;
1122
+ if (this.instanceCount === 0) {
1123
+ if (this.intervalId) {
1124
+ clearInterval(this.intervalId);
1125
+ this.intervalId = null;
1126
+ this.activeKey = null;
1127
+ this.lastResponse = null;
1128
+ }
1129
+ }
1130
+ }
1131
+ };
1132
+
1133
+ // src/components/error-boundary/error-boundary.tsx
1134
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1135
+ var statusChecker = new StatusChecker();
1136
+ var CopilotErrorBoundary = class extends import_react7.default.Component {
1137
+ constructor(props) {
1138
+ super(props);
1139
+ this.state = {
1140
+ hasError: false
1141
+ };
1142
+ }
1143
+ static getDerivedStateFromError(error) {
1144
+ return { hasError: true, error };
1145
+ }
1146
+ componentDidMount() {
1147
+ if (this.props.publicApiKey) {
1148
+ statusChecker.start(this.props.publicApiKey, (newStatus) => {
1149
+ this.setState((prevState) => {
1150
+ var _a;
1151
+ if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
1152
+ return { status: newStatus != null ? newStatus : void 0 };
1153
+ }
1154
+ return null;
1155
+ });
1156
+ });
1157
+ }
1158
+ }
1159
+ componentWillUnmount() {
1160
+ statusChecker.stop();
1161
+ }
1162
+ componentDidCatch(error, errorInfo) {
1163
+ console.error("CopilotKit Error:", error, errorInfo);
1164
+ }
1165
+ render() {
1166
+ var _a, _b, _c, _d;
1167
+ if (this.state.hasError) {
1168
+ if (this.state.error instanceof import_shared7.CopilotKitError) {
1169
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1170
+ this.props.children,
1171
+ this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1172
+ UsageBanner,
1173
+ {
1174
+ severity: (_b = (_a = this.state.status) == null ? void 0 : _a.severity) != null ? _b : this.state.error.severity,
1175
+ message: (_d = (_c = this.state.status) == null ? void 0 : _c.message) != null ? _d : this.state.error.message,
1176
+ actions: getErrorActions(this.state.error)
1177
+ }
1178
+ )
1179
+ ] });
1180
+ }
1181
+ throw this.state.error;
1182
+ }
1183
+ return this.props.children;
1184
+ }
1185
+ };
1186
+
1187
+ // src/context/coagent-state-renders-context.tsx
1188
+ var import_react8 = require("react");
1189
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1190
+ var CoAgentStateRendersContext = (0, import_react8.createContext)(
1191
+ void 0
1192
+ );
1193
+ function CoAgentStateRendersProvider({ children }) {
1194
+ const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
1195
+ const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
1196
+ setCoAgentStateRenders((prevPoints) => __spreadProps(__spreadValues({}, prevPoints), {
1197
+ [id]: stateRender
1198
+ }));
1199
+ }, []);
1200
+ const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
1201
+ setCoAgentStateRenders((prevPoints) => {
1202
+ const newPoints = __spreadValues({}, prevPoints);
1203
+ delete newPoints[id];
1204
+ return newPoints;
1205
+ });
1206
+ }, []);
1207
+ const claimsRef = (0, import_react8.useRef)({});
1208
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1209
+ CoAgentStateRendersContext.Provider,
1210
+ {
1211
+ value: {
1212
+ coAgentStateRenders,
1213
+ setCoAgentStateRender,
1214
+ removeCoAgentStateRender,
1215
+ claimsRef
1216
+ },
1217
+ children
1218
+ }
1219
+ );
1220
+ }
1221
+ function useCoAgentStateRenders() {
1222
+ const context = (0, import_react8.useContext)(CoAgentStateRendersContext);
1223
+ if (!context) {
1224
+ throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
1225
+ }
1226
+ return context;
1227
+ }
1228
+
1229
+ // src/hooks/use-coagent-state-render-bridge.tsx
1230
+ var import_react10 = require("@copilotkitnext/react");
1231
+ var import_react11 = require("react");
1232
+
1233
+ // src/context/threads-context.tsx
1234
+ var import_react9 = require("react");
1235
+ var import_shared8 = require("@copilotkit/shared");
1236
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1237
+ var ThreadsContext = (0, import_react9.createContext)(void 0);
1238
+ function ThreadsProvider({ children, threadId: explicitThreadId }) {
1239
+ const [internalThreadId, setThreadId] = (0, import_react9.useState)(explicitThreadId != null ? explicitThreadId : (0, import_shared8.randomUUID)());
1240
+ const threadId = internalThreadId;
1241
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1242
+ ThreadsContext.Provider,
1243
+ {
1244
+ value: {
1245
+ threadId,
1246
+ setThreadId
1247
+ },
1248
+ children
1249
+ }
1250
+ );
1251
+ }
1252
+ function useThreads() {
1253
+ const context = (0, import_react9.useContext)(ThreadsContext);
1254
+ if (!context) {
1255
+ throw new Error("useThreads must be used within ThreadsProvider");
1256
+ }
1257
+ return context;
1258
+ }
1259
+
1260
+ // src/hooks/use-coagent-state-render-bridge.tsx
1261
+ var import_shared9 = require("@copilotkit/shared");
1262
+ function getStateWithoutConstantKeys(state) {
1263
+ if (!state)
1264
+ return {};
1265
+ const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
1266
+ return stateWithoutConstantKeys;
1267
+ }
1268
+ function areStatesEquals(a, b) {
1269
+ if (a && !b || !a && b)
1270
+ return false;
1271
+ const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
1272
+ const _b = b, {
1273
+ messages: bMessages,
1274
+ tools: bTools,
1275
+ copilotkit: bCopilotkit
1276
+ } = _b, bWithoutConstantKeys = __objRest(_b, [
1277
+ "messages",
1278
+ "tools",
1279
+ "copilotkit"
1280
+ ]);
1281
+ return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
1282
+ }
1283
+ function useCoagentStateRenderBridge(agentId, props) {
1284
+ var _a;
1285
+ const { stateSnapshot, messageIndexInRun, message } = props;
1286
+ const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
1287
+ const { agent } = (0, import_react10.useAgent)({ agentId });
1288
+ const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
1289
+ const runId = (_a = props.runId) != null ? _a : message.runId;
1290
+ const effectiveRunId = runId || "pending";
1291
+ (0, import_react11.useEffect)(() => {
1292
+ if (!agent)
1293
+ return;
1294
+ const subscriber = {
1295
+ onStepStartedEvent: ({ event }) => {
1296
+ if (event.stepName !== nodeName) {
1297
+ setNodeName(event.stepName);
1298
+ }
1299
+ },
1300
+ onStepFinishedEvent: ({ event }) => {
1301
+ if (event.stepName === nodeName) {
1302
+ setNodeName(void 0);
1303
+ }
1304
+ }
1305
+ };
1306
+ const { unsubscribe } = agent.subscribe(subscriber);
1307
+ return () => {
1308
+ unsubscribe();
1309
+ };
1310
+ }, [agentId, nodeName]);
1311
+ const getStateRender = (0, import_react11.useCallback)(
1312
+ (messageId) => {
1313
+ return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
1314
+ if (claimsRef.current[messageId]) {
1315
+ return stateRenderId === claimsRef.current[messageId].stateRenderId;
1316
+ }
1317
+ const matchingAgentName = stateRender.name === agentId;
1318
+ const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
1319
+ return matchingAgentName && matchesNodeContext;
1320
+ });
1321
+ },
1322
+ [coAgentStateRenders, nodeName, agentId]
1323
+ );
1324
+ const handleRenderRequest = ({
1325
+ stateRenderId,
1326
+ messageId,
1327
+ runId: runId2,
1328
+ stateSnapshot: renderSnapshot
1329
+ }) => {
1330
+ if (claimsRef.current[messageId]) {
1331
+ const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
1332
+ if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
1333
+ claimsRef.current[messageId].runId = runId2;
1334
+ }
1335
+ return canRender;
1336
+ }
1337
+ const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
1338
+ (c) => c.stateRenderId === stateRenderId && (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
1339
+ );
1340
+ if (renderClaimedByOtherMessage) {
1341
+ if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
1342
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1343
+ return true;
1344
+ }
1345
+ return false;
1346
+ }
1347
+ if (!runId2) {
1348
+ return false;
1349
+ }
1350
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1351
+ return true;
1352
+ };
1353
+ return (0, import_react11.useMemo)(() => {
1354
+ var _a2, _b, _c;
1355
+ if (messageIndexInRun !== 0) {
1356
+ return null;
1357
+ }
1358
+ const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
1359
+ if (!stateRender || !stateRenderId) {
1360
+ return null;
1361
+ }
1362
+ const snapshot = stateSnapshot ? (0, import_shared9.parseJson)(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
1363
+ const canRender = handleRenderRequest({
1364
+ stateRenderId,
1365
+ messageId: message.id,
1366
+ runId: effectiveRunId,
1367
+ stateSnapshot: snapshot
1368
+ });
1369
+ if (!canRender) {
1370
+ return null;
1371
+ }
1372
+ if (snapshot && !claimsRef.current[message.id].locked) {
1373
+ if (stateSnapshot) {
1374
+ claimsRef.current[message.id].stateSnapshot = snapshot;
1375
+ claimsRef.current[message.id].locked = true;
1376
+ } else {
1377
+ claimsRef.current[message.id].stateSnapshot = snapshot;
1378
+ }
1379
+ }
1380
+ if (stateRender.handler) {
1381
+ stateRender.handler({
1382
+ state: stateSnapshot ? (0, import_shared9.parseJson)(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
1383
+ nodeName: nodeName != null ? nodeName : ""
1384
+ });
1385
+ }
1386
+ if (stateRender.render) {
1387
+ const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
1388
+ if (typeof stateRender.render === "string")
1389
+ return stateRender.render;
1390
+ return stateRender.render({
1391
+ status,
1392
+ // Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
1393
+ state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
1394
+ nodeName: nodeName != null ? nodeName : ""
1395
+ });
1396
+ }
1397
+ }, [
1398
+ getStateRender,
1399
+ stateSnapshot,
1400
+ agent == null ? void 0 : agent.state,
1401
+ agent == null ? void 0 : agent.isRunning,
1402
+ nodeName,
1403
+ effectiveRunId,
1404
+ message.id,
1405
+ messageIndexInRun
1406
+ ]);
1407
+ }
1408
+ function CoAgentStateRenderBridge(props) {
1409
+ return useCoagentStateRenderBridge(props.agentId, props);
1410
+ }
1411
+
1412
+ // src/components/CopilotListeners.tsx
1413
+ var import_react12 = require("react");
1414
+ var import_react13 = require("@copilotkitnext/react");
1415
+ var import_shared10 = require("@copilotkit/shared");
1416
+ var import_shared11 = require("@copilotkit/shared");
1417
+ var usePredictStateSubscription = (agent) => {
1418
+ const predictStateToolsRef = (0, import_react12.useRef)([]);
1419
+ const getSubscriber = (0, import_react12.useCallback)(
1420
+ (agent2) => ({
1421
+ onCustomEvent: ({ event }) => {
1422
+ if (event.name === "PredictState") {
1423
+ predictStateToolsRef.current = event.value;
1424
+ }
1425
+ },
1426
+ onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
1427
+ predictStateToolsRef.current.forEach((t) => {
1428
+ if ((t == null ? void 0 : t.tool) !== toolCallName)
1429
+ return;
1430
+ const emittedState = typeof partialToolCallArgs === "string" ? (0, import_shared10.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
1431
+ agent2.setState({
1432
+ [t.state_key]: emittedState[t.state_key]
1433
+ });
1434
+ });
1435
+ }
1436
+ }),
1437
+ []
1438
+ );
1439
+ (0, import_react12.useEffect)(() => {
1440
+ if (!agent)
1441
+ return;
1442
+ const subscriber = getSubscriber(agent);
1443
+ const { unsubscribe } = agent.subscribe(subscriber);
1444
+ return () => {
1445
+ unsubscribe();
1446
+ };
1447
+ }, [agent, getSubscriber]);
1448
+ };
1449
+ function CopilotListeners() {
1450
+ const { copilotkit } = (0, import_react13.useCopilotKit)();
1451
+ const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1452
+ const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
1453
+ const { setBannerError } = useToast();
1454
+ const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1455
+ usePredictStateSubscription(agent);
1456
+ (0, import_react12.useEffect)(() => {
1457
+ const subscriber = {
1458
+ onError: ({ error }) => {
1459
+ setBannerError(new import_shared11.CopilotKitLowLevelError({ error, message: error.message }));
1460
+ }
1461
+ };
1462
+ const subscription = copilotkit.subscribe(subscriber);
1463
+ return () => {
1464
+ subscription.unsubscribe();
1465
+ };
1466
+ }, [copilotkit == null ? void 0 : copilotkit.subscribe]);
1467
+ return null;
1468
+ }
1469
+
1470
+ // src/components/copilot-provider/copilotkit.tsx
1471
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1472
+ function CopilotKit(_a) {
1473
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1474
+ const enabled = shouldShowDevConsole(props.showDevConsole);
1475
+ const showInspector = shouldShowDevConsole(props.enableInspector);
1476
+ const publicApiKey = props.publicApiKey || props.publicLicenseKey;
1477
+ const renderArr = (0, import_react14.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
1478
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1479
+ import_react15.CopilotKitProvider,
1480
+ __spreadProps(__spreadValues({}, props), {
1481
+ showDevConsole: showInspector,
1482
+ renderCustomMessages: renderArr,
1483
+ useSingleEndpoint: true,
1484
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
1485
+ })
1486
+ ) }) }) });
1487
+ }
1488
+ function CopilotKitInternal(cpkProps) {
1489
+ var _b;
1490
+ const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
1491
+ validateProps(cpkProps);
1492
+ const publicApiKey = props.publicLicenseKey || props.publicApiKey;
1493
+ const chatApiEndpoint = props.runtimeUrl || import_shared12.COPILOT_CLOUD_CHAT_URL;
1494
+ const [actions, setActions] = (0, import_react14.useState)({});
1495
+ const [registeredActionConfigs, setRegisteredActionConfigs] = (0, import_react14.useState)(/* @__PURE__ */ new Map());
1496
+ const chatComponentsCache = (0, import_react14.useRef)({
1497
+ actions: {},
1498
+ coAgentStateRenders: {}
1499
+ });
1500
+ const { addElement, removeElement, printTree, getAllElements } = use_tree_default();
1501
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
1502
+ const [chatInstructions, setChatInstructions] = (0, import_react14.useState)("");
1503
+ const [authStates, setAuthStates] = (0, import_react14.useState)({});
1504
+ const [extensions, setExtensions] = (0, import_react14.useState)({});
1505
+ const [additionalInstructions, setAdditionalInstructions] = (0, import_react14.useState)([]);
1506
+ const {
1507
+ addElement: addDocument,
1508
+ removeElement: removeDocument,
1509
+ allElements: allDocuments
1510
+ } = use_flat_category_store_default();
1511
+ const setAction = (0, import_react14.useCallback)((id, action) => {
1512
+ setActions((prevPoints) => {
1513
+ return __spreadProps(__spreadValues({}, prevPoints), {
1514
+ [id]: action
1515
+ });
1516
+ });
1517
+ }, []);
1518
+ const removeAction = (0, import_react14.useCallback)((id) => {
1519
+ setActions((prevPoints) => {
1520
+ const newPoints = __spreadValues({}, prevPoints);
1521
+ delete newPoints[id];
1522
+ return newPoints;
1523
+ });
1524
+ }, []);
1525
+ const getContextString = (0, import_react14.useCallback)(
1526
+ (documents, categories) => {
1527
+ const documentsString = documents.map((document) => {
1528
+ return `${document.name} (${document.sourceApplication}):
1529
+ ${document.getContents()}`;
1530
+ }).join("\n\n");
1531
+ const nonDocumentStrings = printTree(categories);
1532
+ return `${documentsString}
1533
+
1534
+ ${nonDocumentStrings}`;
1535
+ },
1536
+ [printTree]
1537
+ );
1538
+ const addContext = (0, import_react14.useCallback)(
1539
+ (context, parentId, categories = defaultCopilotContextCategories) => {
1540
+ return addElement(context, categories, parentId);
1541
+ },
1542
+ [addElement]
1543
+ );
1544
+ const removeContext = (0, import_react14.useCallback)(
1545
+ (id) => {
1546
+ removeElement(id);
1547
+ },
1548
+ [removeElement]
1549
+ );
1550
+ const getAllContext = (0, import_react14.useCallback)(() => {
1551
+ return getAllElements();
1552
+ }, [getAllElements]);
1553
+ const getFunctionCallHandler = (0, import_react14.useCallback)(
1554
+ (customEntryPoints) => {
1555
+ return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
1556
+ },
1557
+ [actions]
1558
+ );
1559
+ const getDocumentsContext = (0, import_react14.useCallback)(
1560
+ (categories) => {
1561
+ return allDocuments(categories);
1562
+ },
1563
+ [allDocuments]
1564
+ );
1565
+ const addDocumentContext = (0, import_react14.useCallback)(
1566
+ (documentPointer, categories = defaultCopilotContextCategories) => {
1567
+ return addDocument(documentPointer, categories);
1568
+ },
1569
+ [addDocument]
1570
+ );
1571
+ const removeDocumentContext = (0, import_react14.useCallback)(
1572
+ (documentId) => {
1573
+ removeDocument(documentId);
1574
+ },
1575
+ [removeDocument]
1576
+ );
1577
+ const copilotApiConfig = (0, import_react14.useMemo)(() => {
1578
+ var _a2, _b2;
1579
+ let cloud = void 0;
1580
+ if (publicApiKey) {
1581
+ cloud = {
1582
+ guardrails: {
1583
+ input: {
1584
+ restrictToTopic: {
1585
+ enabled: Boolean(props.guardrails_c),
1586
+ validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
1587
+ invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
1588
+ }
1589
+ }
1590
+ }
1591
+ };
1592
+ }
1593
+ return __spreadProps(__spreadValues({
1594
+ publicApiKey
1595
+ }, cloud ? { cloud } : {}), {
1596
+ chatApiEndpoint,
1597
+ headers: props.headers || {},
1598
+ properties: props.properties || {},
1599
+ transcribeAudioUrl: props.transcribeAudioUrl,
1600
+ textToSpeechUrl: props.textToSpeechUrl,
1601
+ credentials: props.credentials
1602
+ });
1603
+ }, [
1604
+ publicApiKey,
1605
+ props.headers,
1606
+ props.properties,
1607
+ props.transcribeAudioUrl,
1608
+ props.textToSpeechUrl,
1609
+ props.credentials,
1610
+ props.cloudRestrictToTopic,
1611
+ props.guardrails_c
1612
+ ]);
1613
+ const headers = (0, import_react14.useMemo)(() => {
1614
+ const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
1615
+ if (state.status === "authenticated" && state.authHeaders) {
1616
+ return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
1617
+ (headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
1618
+ [key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
1619
+ }),
1620
+ {}
1621
+ ));
1622
+ }
1623
+ return acc;
1624
+ }, {});
1625
+ return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared12.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1626
+ }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
1627
+ const [internalErrorHandlers, _setInternalErrorHandler] = (0, import_react14.useState)({});
1628
+ const setInternalErrorHandler = (0, import_react14.useCallback)((handler) => {
1629
+ _setInternalErrorHandler((prev) => __spreadValues(__spreadValues({}, prev), handler));
1630
+ }, []);
1631
+ const removeInternalErrorHandler = (0, import_react14.useCallback)((key) => {
1632
+ _setInternalErrorHandler((prev) => {
1633
+ const _a2 = prev, { [key]: _removed } = _a2, rest = __objRest(_a2, [__restKey(key)]);
1634
+ return rest;
1635
+ });
1636
+ }, []);
1637
+ const onErrorRef = (0, import_react14.useRef)(props.onError);
1638
+ (0, import_react14.useEffect)(() => {
1639
+ onErrorRef.current = props.onError;
1640
+ }, [props.onError]);
1641
+ const internalHandlersRef = (0, import_react14.useRef)({});
1642
+ (0, import_react14.useEffect)(() => {
1643
+ internalHandlersRef.current = internalErrorHandlers;
1644
+ }, [internalErrorHandlers]);
1645
+ const handleErrors = (0, import_react14.useCallback)(
1646
+ (error) => __async(this, null, function* () {
1647
+ if (copilotApiConfig.publicApiKey && onErrorRef.current) {
1648
+ try {
1649
+ yield onErrorRef.current(error);
1650
+ } catch (e) {
1651
+ console.error("Error in public onError handler:", e);
1652
+ }
1653
+ }
1654
+ const handlers = Object.values(internalHandlersRef.current);
1655
+ yield Promise.all(
1656
+ handlers.map(
1657
+ (h) => Promise.resolve(h(error)).catch(
1658
+ (e) => console.error("Error in internal error handler:", e)
1659
+ )
1660
+ )
1661
+ );
1662
+ }),
1663
+ [copilotApiConfig.publicApiKey]
1664
+ );
1665
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react14.useState)({});
1666
+ const addChatSuggestionConfiguration = (0, import_react14.useCallback)(
1667
+ (id, suggestion) => {
1668
+ setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1669
+ },
1670
+ [setChatSuggestionConfiguration]
1671
+ );
1672
+ const removeChatSuggestionConfiguration = (0, import_react14.useCallback)(
1673
+ (id) => {
1674
+ setChatSuggestionConfiguration((prev) => {
1675
+ const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1676
+ return rest;
1677
+ });
1678
+ },
1679
+ [setChatSuggestionConfiguration]
1680
+ );
1681
+ const [availableAgents, setAvailableAgents] = (0, import_react14.useState)([]);
1682
+ const [coagentStates, setCoagentStates] = (0, import_react14.useState)({});
1683
+ const coagentStatesRef = (0, import_react14.useRef)({});
1684
+ const setCoagentStatesWithRef = (0, import_react14.useCallback)(
1685
+ (value) => {
1686
+ const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
1687
+ coagentStatesRef.current = newValue;
1688
+ setCoagentStates((prev) => {
1689
+ return newValue;
1690
+ });
1691
+ },
1692
+ []
1693
+ );
1694
+ let initialAgentSession = null;
1695
+ if (props.agent) {
1696
+ initialAgentSession = {
1697
+ agentName: props.agent
1698
+ };
1699
+ }
1700
+ const [agentSession, setAgentSession] = (0, import_react14.useState)(initialAgentSession);
1701
+ (0, import_react14.useEffect)(() => {
1702
+ if (props.agent) {
1703
+ setAgentSession({
1704
+ agentName: props.agent
1705
+ });
1706
+ } else {
1707
+ setAgentSession(null);
1708
+ }
1709
+ }, [props.agent]);
1710
+ const { threadId, setThreadId: setInternalThreadId } = useThreads();
1711
+ const setThreadId = (0, import_react14.useCallback)(
1712
+ (value) => {
1713
+ if (props.threadId) {
1714
+ throw new Error("Cannot call setThreadId() when threadId is provided via props.");
1715
+ }
1716
+ setInternalThreadId(value);
1717
+ },
1718
+ [props.threadId]
1719
+ );
1720
+ const [runId, setRunId] = (0, import_react14.useState)(null);
1721
+ const chatAbortControllerRef = (0, import_react14.useRef)(null);
1722
+ const showDevConsole = shouldShowDevConsole(props.showDevConsole);
1723
+ const [interruptActions, _setInterruptActions] = (0, import_react14.useState)({});
1724
+ const setInterruptAction = (0, import_react14.useCallback)((action) => {
1725
+ _setInterruptActions((prev) => {
1726
+ var _a2;
1727
+ if (action == null || !action.id) {
1728
+ return prev;
1729
+ }
1730
+ return __spreadProps(__spreadValues({}, prev), {
1731
+ [action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
1732
+ });
1733
+ });
1734
+ }, []);
1735
+ const removeInterruptAction = (0, import_react14.useCallback)((actionId) => {
1736
+ _setInterruptActions((prev) => {
1737
+ const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
1738
+ return rest;
1739
+ });
1740
+ }, []);
1741
+ const [interruptEventQueue, setInterruptEventQueue] = (0, import_react14.useState)({});
1742
+ const addInterruptEvent = (0, import_react14.useCallback)((queuedEvent) => {
1743
+ setInterruptEventQueue((prev) => {
1744
+ const threadQueue = prev[queuedEvent.threadId] || [];
1745
+ return __spreadProps(__spreadValues({}, prev), {
1746
+ [queuedEvent.threadId]: [...threadQueue, queuedEvent]
1747
+ });
1748
+ });
1749
+ }, []);
1750
+ const resolveInterruptEvent = (0, import_react14.useCallback)(
1751
+ (threadId2, eventId, response) => {
1752
+ setInterruptEventQueue((prev) => {
1753
+ const threadQueue = prev[threadId2] || [];
1754
+ return __spreadProps(__spreadValues({}, prev), {
1755
+ [threadId2]: threadQueue.map(
1756
+ (queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
1757
+ )
1758
+ });
1759
+ });
1760
+ },
1761
+ []
1762
+ );
1763
+ const memoizedChildren = (0, import_react14.useMemo)(() => children, [children]);
1764
+ const [bannerError, setBannerError] = (0, import_react14.useState)(null);
1765
+ const agentLock = (0, import_react14.useMemo)(() => {
1766
+ var _a2;
1767
+ return (_a2 = props.agent) != null ? _a2 : null;
1768
+ }, [props.agent]);
1769
+ const forwardedParameters = (0, import_react14.useMemo)(
1770
+ () => {
1771
+ var _a2;
1772
+ return (_a2 = props.forwardedParameters) != null ? _a2 : {};
1773
+ },
1774
+ [props.forwardedParameters]
1775
+ );
1776
+ const updateExtensions = (0, import_react14.useCallback)(
1777
+ (newExtensions) => {
1778
+ setExtensions((prev) => {
1779
+ const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
1780
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1781
+ const isEqual = isSameLength && // @ts-ignore
1782
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1783
+ return isEqual ? prev : resolved;
1784
+ });
1785
+ },
1786
+ [setExtensions]
1787
+ );
1788
+ const updateAuthStates = (0, import_react14.useCallback)(
1789
+ (newAuthStates) => {
1790
+ setAuthStates((prev) => {
1791
+ const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
1792
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1793
+ const isEqual = isSameLength && // @ts-ignore
1794
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1795
+ return isEqual ? prev : resolved;
1796
+ });
1797
+ },
1798
+ [setAuthStates]
1799
+ );
1800
+ const handleSetRegisteredActions = (0, import_react14.useCallback)((actionConfig) => {
1801
+ const key = actionConfig.action.name || (0, import_shared12.randomUUID)();
1802
+ setRegisteredActionConfigs((prev) => {
1803
+ const newMap = new Map(prev);
1804
+ newMap.set(key, actionConfig);
1805
+ return newMap;
1806
+ });
1807
+ return key;
1808
+ }, []);
1809
+ const handleRemoveRegisteredAction = (0, import_react14.useCallback)((actionKey) => {
1810
+ setRegisteredActionConfigs((prev) => {
1811
+ const newMap = new Map(prev);
1812
+ newMap.delete(actionKey);
1813
+ return newMap;
1814
+ });
1815
+ }, []);
1816
+ const RegisteredActionsRenderer = (0, import_react14.useMemo)(() => {
1817
+ return () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: Array.from(registeredActionConfigs.entries()).map(([key, config]) => {
1818
+ const Component = config.component;
1819
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Component, { action: config.action }, key);
1820
+ }) });
1821
+ }, [registeredActionConfigs]);
1822
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1823
+ import_react15.CopilotChatConfigurationProvider,
1824
+ {
1825
+ agentId: (_b = props.agent) != null ? _b : "default",
1826
+ threadId,
1827
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1828
+ CopilotContext.Provider,
1829
+ {
1830
+ value: {
1831
+ actions,
1832
+ chatComponentsCache,
1833
+ getFunctionCallHandler,
1834
+ setAction,
1835
+ removeAction,
1836
+ setRegisteredActions: handleSetRegisteredActions,
1837
+ removeRegisteredAction: handleRemoveRegisteredAction,
1838
+ getContextString,
1839
+ addContext,
1840
+ removeContext,
1841
+ getAllContext,
1842
+ getDocumentsContext,
1843
+ addDocumentContext,
1844
+ removeDocumentContext,
1845
+ copilotApiConfig,
1846
+ isLoading,
1847
+ setIsLoading,
1848
+ chatSuggestionConfiguration,
1849
+ addChatSuggestionConfiguration,
1850
+ removeChatSuggestionConfiguration,
1851
+ chatInstructions,
1852
+ setChatInstructions,
1853
+ additionalInstructions,
1854
+ setAdditionalInstructions,
1855
+ showDevConsole,
1856
+ coagentStates,
1857
+ setCoagentStates,
1858
+ coagentStatesRef,
1859
+ setCoagentStatesWithRef,
1860
+ agentSession,
1861
+ setAgentSession,
1862
+ forwardedParameters,
1863
+ agentLock,
1864
+ threadId,
1865
+ setThreadId,
1866
+ runId,
1867
+ setRunId,
1868
+ chatAbortControllerRef,
1869
+ availableAgents,
1870
+ authConfig_c: props.authConfig_c,
1871
+ authStates_c: authStates,
1872
+ setAuthStates_c: updateAuthStates,
1873
+ extensions,
1874
+ setExtensions: updateExtensions,
1875
+ interruptActions,
1876
+ setInterruptAction,
1877
+ removeInterruptAction,
1878
+ interruptEventQueue,
1879
+ addInterruptEvent,
1880
+ resolveInterruptEvent,
1881
+ bannerError,
1882
+ setBannerError,
1883
+ onError: handleErrors,
1884
+ internalErrorHandlers,
1885
+ setInternalErrorHandler,
1886
+ removeInternalErrorHandler
1887
+ },
1888
+ children: [
1889
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotListeners, {}),
1890
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(CoAgentStateRendersProvider, { children: [
1891
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(CopilotMessages, { children: [
1892
+ memoizedChildren,
1893
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(RegisteredActionsRenderer, {})
1894
+ ] }) }),
1895
+ bannerError && showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1896
+ UsageBanner,
1897
+ {
1898
+ severity: bannerError.severity,
1899
+ message: bannerError.message,
1900
+ onClose: () => setBannerError(null),
1901
+ actions: getErrorActions(bannerError)
1902
+ }
1903
+ )
1904
+ ] })
1905
+ ]
1906
+ }
1907
+ )
1908
+ }
1909
+ );
1910
+ }
1911
+ var defaultCopilotContextCategories = ["global"];
1912
+ function entryPointsToFunctionCallHandler(actions) {
1913
+ return (_0) => __async(this, [_0], function* ({ name, args }) {
1914
+ let actionsByFunctionName = {};
1915
+ for (let action2 of actions) {
1916
+ actionsByFunctionName[action2.name] = action2;
1917
+ }
1918
+ const action = actionsByFunctionName[name];
1919
+ let result = void 0;
1920
+ if (action) {
1921
+ yield new Promise((resolve, reject) => {
1922
+ (0, import_react_dom.flushSync)(() => __async(this, null, function* () {
1923
+ var _a;
1924
+ try {
1925
+ result = yield (_a = action.handler) == null ? void 0 : _a.call(action, args);
1926
+ resolve();
1927
+ } catch (error) {
1928
+ reject(error);
1929
+ }
1930
+ }));
1931
+ });
1932
+ yield new Promise((resolve) => setTimeout(resolve, 20));
1933
+ }
1934
+ return result;
1935
+ });
1936
+ }
1937
+ function formatFeatureName(featureName) {
1938
+ return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
1939
+ }
1940
+ function validateProps(props) {
1941
+ const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
1942
+ const hasApiKey = props.publicApiKey || props.publicLicenseKey;
1943
+ if (!props.runtimeUrl && !hasApiKey) {
1944
+ throw new import_shared12.ConfigurationError(
1945
+ "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'"
1946
+ );
1947
+ }
1948
+ if (cloudFeatures.length > 0 && !hasApiKey) {
1949
+ throw new import_shared12.MissingPublicApiKeyError(
1950
+ `Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
1951
+ );
1952
+ }
1953
+ }
1954
+ // Annotate the CommonJS export names for ESM import in node:
1955
+ 0 && (module.exports = {
1956
+ CopilotKit,
1957
+ CopilotKitInternal,
1958
+ defaultCopilotContextCategories
1959
+ });
1960
+ //# sourceMappingURL=copilotkit.js.map