@copilotkit/react-core 1.51.5-next.0 → 1.51.5-next.1

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