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