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

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