@copilotkit/react-core 2.0.0-next.1 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (538) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -12
  3. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts +954 -0
  4. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +1 -0
  5. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts +954 -0
  6. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +1 -0
  7. package/dist/MarkdownSurfaces-C2XZISKn.cjs +3964 -0
  8. package/dist/MarkdownSurfaces-C2XZISKn.cjs.map +1 -0
  9. package/dist/MarkdownSurfaces-ChSlVYOk.mjs +3655 -0
  10. package/dist/MarkdownSurfaces-ChSlVYOk.mjs.map +1 -0
  11. package/dist/context.cjs +144 -0
  12. package/dist/context.cjs.map +1 -0
  13. package/dist/context.d.cts +166 -0
  14. package/dist/context.d.cts.map +1 -0
  15. package/dist/context.d.mts +166 -0
  16. package/dist/context.d.mts.map +1 -0
  17. package/dist/context.mjs +136 -0
  18. package/dist/context.mjs.map +1 -0
  19. package/dist/generative-ui.cjs +8151 -0
  20. package/dist/generative-ui.cjs.map +1 -0
  21. package/dist/generative-ui.d.cts +4952 -0
  22. package/dist/generative-ui.d.cts.map +1 -0
  23. package/dist/generative-ui.d.mts +4952 -0
  24. package/dist/generative-ui.d.mts.map +1 -0
  25. package/dist/generative-ui.mjs +8137 -0
  26. package/dist/generative-ui.mjs.map +1 -0
  27. package/dist/headless.cjs +1927 -0
  28. package/dist/headless.cjs.map +1 -0
  29. package/dist/headless.d.cts +1117 -0
  30. package/dist/headless.d.cts.map +1 -0
  31. package/dist/headless.d.mts +1008 -0
  32. package/dist/headless.d.mts.map +1 -0
  33. package/dist/headless.mjs +1869 -0
  34. package/dist/headless.mjs.map +1 -0
  35. package/dist/index.cjs +15576 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.css +2 -0
  38. package/dist/index.d.cts +3450 -0
  39. package/dist/index.d.cts.map +1 -0
  40. package/dist/index.d.mts +3433 -0
  41. package/dist/index.d.mts.map +1 -0
  42. package/dist/index.mjs +13927 -146
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/index.umd.js +18856 -0
  45. package/dist/index.umd.js.map +1 -0
  46. package/package.json +124 -52
  47. package/CHANGELOG.md +0 -4210
  48. package/dist/chunk-2IDV5OHF.mjs +0 -11
  49. package/dist/chunk-2IDV5OHF.mjs.map +0 -1
  50. package/dist/chunk-36KQV2NA.mjs +0 -1
  51. package/dist/chunk-36KQV2NA.mjs.map +0 -1
  52. package/dist/chunk-3V5TOYKW.mjs +0 -120
  53. package/dist/chunk-3V5TOYKW.mjs.map +0 -1
  54. package/dist/chunk-4CEQJ2X6.mjs +0 -31
  55. package/dist/chunk-4CEQJ2X6.mjs.map +0 -1
  56. package/dist/chunk-4RRMC7L2.mjs +0 -32
  57. package/dist/chunk-4RRMC7L2.mjs.map +0 -1
  58. package/dist/chunk-4YZA2BZC.mjs +0 -551
  59. package/dist/chunk-4YZA2BZC.mjs.map +0 -1
  60. package/dist/chunk-53K6WNJG.mjs +0 -36
  61. package/dist/chunk-53K6WNJG.mjs.map +0 -1
  62. package/dist/chunk-6ESSSQ7Q.mjs +0 -134
  63. package/dist/chunk-6ESSSQ7Q.mjs.map +0 -1
  64. package/dist/chunk-6PUNP7CD.mjs +0 -102
  65. package/dist/chunk-6PUNP7CD.mjs.map +0 -1
  66. package/dist/chunk-6YOKPWQ7.mjs +0 -1
  67. package/dist/chunk-6YOKPWQ7.mjs.map +0 -1
  68. package/dist/chunk-6ZLPNY7X.mjs +0 -225
  69. package/dist/chunk-6ZLPNY7X.mjs.map +0 -1
  70. package/dist/chunk-7DTB7S5V.mjs +0 -83
  71. package/dist/chunk-7DTB7S5V.mjs.map +0 -1
  72. package/dist/chunk-7IBF6RBW.mjs +0 -23
  73. package/dist/chunk-7IBF6RBW.mjs.map +0 -1
  74. package/dist/chunk-A6NKSGH3.mjs +0 -1
  75. package/dist/chunk-A6NKSGH3.mjs.map +0 -1
  76. package/dist/chunk-ABWT4DRT.mjs +0 -24
  77. package/dist/chunk-ABWT4DRT.mjs.map +0 -1
  78. package/dist/chunk-AFNWX62Q.mjs +0 -110
  79. package/dist/chunk-AFNWX62Q.mjs.map +0 -1
  80. package/dist/chunk-BUSWSDYO.mjs +0 -17
  81. package/dist/chunk-BUSWSDYO.mjs.map +0 -1
  82. package/dist/chunk-CDUIA2WM.mjs +0 -60
  83. package/dist/chunk-CDUIA2WM.mjs.map +0 -1
  84. package/dist/chunk-CYDWEPFL.mjs +0 -1
  85. package/dist/chunk-CYDWEPFL.mjs.map +0 -1
  86. package/dist/chunk-DMLQZG75.mjs +0 -25
  87. package/dist/chunk-DMLQZG75.mjs.map +0 -1
  88. package/dist/chunk-E7SE25ZU.mjs +0 -59
  89. package/dist/chunk-E7SE25ZU.mjs.map +0 -1
  90. package/dist/chunk-EFL5OBKN.mjs +0 -310
  91. package/dist/chunk-EFL5OBKN.mjs.map +0 -1
  92. package/dist/chunk-F555TVE4.mjs +0 -33
  93. package/dist/chunk-F555TVE4.mjs.map +0 -1
  94. package/dist/chunk-FD6FGKYY.mjs +0 -1
  95. package/dist/chunk-FD6FGKYY.mjs.map +0 -1
  96. package/dist/chunk-FDOMAPJY.mjs +0 -59
  97. package/dist/chunk-FDOMAPJY.mjs.map +0 -1
  98. package/dist/chunk-FQFXYAV7.mjs +0 -86
  99. package/dist/chunk-FQFXYAV7.mjs.map +0 -1
  100. package/dist/chunk-GPEJNVE5.mjs +0 -80
  101. package/dist/chunk-GPEJNVE5.mjs.map +0 -1
  102. package/dist/chunk-HE22TZMF.mjs +0 -186
  103. package/dist/chunk-HE22TZMF.mjs.map +0 -1
  104. package/dist/chunk-I76HKHPJ.mjs +0 -32
  105. package/dist/chunk-I76HKHPJ.mjs.map +0 -1
  106. package/dist/chunk-ICIK2BSB.mjs +0 -17
  107. package/dist/chunk-ICIK2BSB.mjs.map +0 -1
  108. package/dist/chunk-JD7BAH7U.mjs +0 -1
  109. package/dist/chunk-JD7BAH7U.mjs.map +0 -1
  110. package/dist/chunk-LHERIF3L.mjs +0 -83
  111. package/dist/chunk-LHERIF3L.mjs.map +0 -1
  112. package/dist/chunk-LSHFN2Y5.mjs +0 -349
  113. package/dist/chunk-LSHFN2Y5.mjs.map +0 -1
  114. package/dist/chunk-LUGEI4YQ.mjs +0 -1
  115. package/dist/chunk-LUGEI4YQ.mjs.map +0 -1
  116. package/dist/chunk-NB2FKV2V.mjs +0 -1
  117. package/dist/chunk-NB2FKV2V.mjs.map +0 -1
  118. package/dist/chunk-NBK4KBLX.mjs +0 -54
  119. package/dist/chunk-NBK4KBLX.mjs.map +0 -1
  120. package/dist/chunk-O7ARI5CV.mjs +0 -31
  121. package/dist/chunk-O7ARI5CV.mjs.map +0 -1
  122. package/dist/chunk-PIF5KJYI.mjs +0 -103
  123. package/dist/chunk-PIF5KJYI.mjs.map +0 -1
  124. package/dist/chunk-PMAFHQ7P.mjs +0 -65
  125. package/dist/chunk-PMAFHQ7P.mjs.map +0 -1
  126. package/dist/chunk-QNUAXSDP.mjs +0 -166
  127. package/dist/chunk-QNUAXSDP.mjs.map +0 -1
  128. package/dist/chunk-RKTVJRK7.mjs +0 -143
  129. package/dist/chunk-RKTVJRK7.mjs.map +0 -1
  130. package/dist/chunk-SKC7AJIV.mjs +0 -61
  131. package/dist/chunk-SKC7AJIV.mjs.map +0 -1
  132. package/dist/chunk-SPCZTZCY.mjs +0 -1
  133. package/dist/chunk-SPCZTZCY.mjs.map +0 -1
  134. package/dist/chunk-VV56AVPB.mjs +0 -125
  135. package/dist/chunk-VV56AVPB.mjs.map +0 -1
  136. package/dist/chunk-WF65O6HX.mjs +0 -66
  137. package/dist/chunk-WF65O6HX.mjs.map +0 -1
  138. package/dist/chunk-XDFVCQD3.mjs +0 -27
  139. package/dist/chunk-XDFVCQD3.mjs.map +0 -1
  140. package/dist/chunk-YCG6SNAU.mjs +0 -759
  141. package/dist/chunk-YCG6SNAU.mjs.map +0 -1
  142. package/dist/chunk-YTQHRJUA.mjs +0 -86
  143. package/dist/chunk-YTQHRJUA.mjs.map +0 -1
  144. package/dist/chunk-YYN33GSG.mjs +0 -73
  145. package/dist/chunk-YYN33GSG.mjs.map +0 -1
  146. package/dist/chunk-Z6JV2LRY.mjs +0 -37
  147. package/dist/chunk-Z6JV2LRY.mjs.map +0 -1
  148. package/dist/chunk-ZVF5Q6IH.mjs +0 -29
  149. package/dist/chunk-ZVF5Q6IH.mjs.map +0 -1
  150. package/dist/chunk-ZYTXB6HH.mjs +0 -151
  151. package/dist/chunk-ZYTXB6HH.mjs.map +0 -1
  152. package/dist/components/CopilotListeners.d.ts +0 -3
  153. package/dist/components/CopilotListeners.js +0 -101
  154. package/dist/components/CopilotListeners.js.map +0 -1
  155. package/dist/components/CopilotListeners.mjs +0 -9
  156. package/dist/components/CopilotListeners.mjs.map +0 -1
  157. package/dist/components/copilot-provider/copilot-messages.d.ts +0 -24
  158. package/dist/components/copilot-provider/copilot-messages.js +0 -351
  159. package/dist/components/copilot-provider/copilot-messages.js.map +0 -1
  160. package/dist/components/copilot-provider/copilot-messages.mjs +0 -16
  161. package/dist/components/copilot-provider/copilot-messages.mjs.map +0 -1
  162. package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -160
  163. package/dist/components/copilot-provider/copilotkit-props.js +0 -19
  164. package/dist/components/copilot-provider/copilotkit-props.js.map +0 -1
  165. package/dist/components/copilot-provider/copilotkit-props.mjs +0 -1
  166. package/dist/components/copilot-provider/copilotkit-props.mjs.map +0 -1
  167. package/dist/components/copilot-provider/copilotkit.d.ts +0 -19
  168. package/dist/components/copilot-provider/copilotkit.js +0 -1960
  169. package/dist/components/copilot-provider/copilotkit.js.map +0 -1
  170. package/dist/components/copilot-provider/copilotkit.mjs +0 -31
  171. package/dist/components/copilot-provider/copilotkit.mjs.map +0 -1
  172. package/dist/components/copilot-provider/index.d.ts +0 -14
  173. package/dist/components/copilot-provider/index.js +0 -1960
  174. package/dist/components/copilot-provider/index.js.map +0 -1
  175. package/dist/components/copilot-provider/index.mjs +0 -30
  176. package/dist/components/copilot-provider/index.mjs.map +0 -1
  177. package/dist/components/dev-console/console-trigger.d.ts +0 -8
  178. package/dist/components/dev-console/console-trigger.js +0 -1202
  179. package/dist/components/dev-console/console-trigger.js.map +0 -1
  180. package/dist/components/dev-console/console-trigger.mjs +0 -233
  181. package/dist/components/dev-console/console-trigger.mjs.map +0 -1
  182. package/dist/components/dev-console/developer-console-modal.d.ts +0 -10
  183. package/dist/components/dev-console/developer-console-modal.js +0 -987
  184. package/dist/components/dev-console/developer-console-modal.js.map +0 -1
  185. package/dist/components/dev-console/developer-console-modal.mjs +0 -12
  186. package/dist/components/dev-console/developer-console-modal.mjs.map +0 -1
  187. package/dist/components/dev-console/icons.d.ts +0 -9
  188. package/dist/components/dev-console/icons.js +0 -131
  189. package/dist/components/dev-console/icons.js.map +0 -1
  190. package/dist/components/dev-console/icons.mjs +0 -16
  191. package/dist/components/dev-console/icons.mjs.map +0 -1
  192. package/dist/components/error-boundary/error-boundary.d.ts +0 -31
  193. package/dist/components/error-boundary/error-boundary.js +0 -500
  194. package/dist/components/error-boundary/error-boundary.js.map +0 -1
  195. package/dist/components/error-boundary/error-boundary.mjs +0 -15
  196. package/dist/components/error-boundary/error-boundary.mjs.map +0 -1
  197. package/dist/components/error-boundary/error-utils.d.ts +0 -11
  198. package/dist/components/error-boundary/error-utils.js +0 -190
  199. package/dist/components/error-boundary/error-utils.js.map +0 -1
  200. package/dist/components/error-boundary/error-utils.mjs +0 -14
  201. package/dist/components/error-boundary/error-utils.mjs.map +0 -1
  202. package/dist/components/index.d.ts +0 -14
  203. package/dist/components/index.js +0 -1960
  204. package/dist/components/index.js.map +0 -1
  205. package/dist/components/index.mjs +0 -31
  206. package/dist/components/index.mjs.map +0 -1
  207. package/dist/components/toast/exclamation-mark-icon.d.ts +0 -9
  208. package/dist/components/toast/exclamation-mark-icon.js +0 -55
  209. package/dist/components/toast/exclamation-mark-icon.js.map +0 -1
  210. package/dist/components/toast/exclamation-mark-icon.mjs +0 -8
  211. package/dist/components/toast/exclamation-mark-icon.mjs.map +0 -1
  212. package/dist/components/toast/toast-provider.d.ts +0 -27
  213. package/dist/components/toast/toast-provider.js +0 -347
  214. package/dist/components/toast/toast-provider.js.map +0 -1
  215. package/dist/components/toast/toast-provider.mjs +0 -10
  216. package/dist/components/toast/toast-provider.mjs.map +0 -1
  217. package/dist/components/usage-banner.d.ts +0 -29
  218. package/dist/components/usage-banner.js +0 -247
  219. package/dist/components/usage-banner.js.map +0 -1
  220. package/dist/components/usage-banner.mjs +0 -12
  221. package/dist/components/usage-banner.mjs.map +0 -1
  222. package/dist/context/coagent-state-renders-context.d.ts +0 -24
  223. package/dist/context/coagent-state-renders-context.js +0 -91
  224. package/dist/context/coagent-state-renders-context.js.map +0 -1
  225. package/dist/context/coagent-state-renders-context.mjs +0 -12
  226. package/dist/context/coagent-state-renders-context.mjs.map +0 -1
  227. package/dist/context/copilot-context.d.ts +0 -10
  228. package/dist/context/copilot-context.js +0 -161
  229. package/dist/context/copilot-context.js.map +0 -1
  230. package/dist/context/copilot-context.mjs +0 -10
  231. package/dist/context/copilot-context.mjs.map +0 -1
  232. package/dist/context/copilot-messages-context.d.ts +0 -18
  233. package/dist/context/copilot-messages-context.js +0 -60
  234. package/dist/context/copilot-messages-context.js.map +0 -1
  235. package/dist/context/copilot-messages-context.mjs +0 -10
  236. package/dist/context/copilot-messages-context.mjs.map +0 -1
  237. package/dist/context/index.d.ts +0 -15
  238. package/dist/context/index.js +0 -285
  239. package/dist/context/index.js.map +0 -1
  240. package/dist/context/index.mjs +0 -33
  241. package/dist/context/index.mjs.map +0 -1
  242. package/dist/context/threads-context.d.ts +0 -16
  243. package/dist/context/threads-context.js +0 -59
  244. package/dist/context/threads-context.js.map +0 -1
  245. package/dist/context/threads-context.mjs +0 -12
  246. package/dist/context/threads-context.mjs.map +0 -1
  247. package/dist/copilot-context-ec77e921.d.ts +0 -209
  248. package/dist/hooks/index.d.ts +0 -33
  249. package/dist/hooks/index.js +0 -1774
  250. package/dist/hooks/index.js.map +0 -1
  251. package/dist/hooks/index.mjs +0 -91
  252. package/dist/hooks/index.mjs.map +0 -1
  253. package/dist/hooks/use-agent-nodename.d.ts +0 -3
  254. package/dist/hooks/use-agent-nodename.js +0 -56
  255. package/dist/hooks/use-agent-nodename.js.map +0 -1
  256. package/dist/hooks/use-agent-nodename.mjs +0 -8
  257. package/dist/hooks/use-agent-nodename.mjs.map +0 -1
  258. package/dist/hooks/use-coagent-state-render-bridge.d.ts +0 -100
  259. package/dist/hooks/use-coagent-state-render-bridge.js +0 -214
  260. package/dist/hooks/use-coagent-state-render-bridge.js.map +0 -1
  261. package/dist/hooks/use-coagent-state-render-bridge.mjs +0 -15
  262. package/dist/hooks/use-coagent-state-render-bridge.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 -255
  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 -233
  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 -295
  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 -177
  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 -462
  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 -1044
  295. package/dist/hooks/use-copilot-chat-headless_c.js.map +0 -1
  296. package/dist/hooks/use-copilot-chat-headless_c.mjs +0 -24
  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 -978
  305. package/dist/hooks/use-copilot-chat.js.map +0 -1
  306. package/dist/hooks/use-copilot-chat.mjs +0 -21
  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 -976
  310. package/dist/hooks/use-copilot-chat_internal.js.map +0 -1
  311. package/dist/hooks/use-copilot-chat_internal.mjs +0 -22
  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 -203
  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 -302
  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 -93
  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 -104
  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 -318
  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 -201
  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 -176
  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 -90
  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 -175
  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 -3528
  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 -194
  378. package/dist/lib/copilot-task.js.map +0 -1
  379. package/dist/lib/copilot-task.mjs +0 -31
  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 -196
  383. package/dist/lib/index.js.map +0 -1
  384. package/dist/lib/index.mjs +0 -32
  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 -26
  393. package/dist/setupTests.js.map +0 -1
  394. package/dist/setupTests.mjs +0 -24
  395. package/dist/setupTests.mjs.map +0 -1
  396. package/dist/types/chat-suggestion-configuration.d.ts +0 -22
  397. package/dist/types/chat-suggestion-configuration.js +0 -19
  398. package/dist/types/chat-suggestion-configuration.js.map +0 -1
  399. package/dist/types/chat-suggestion-configuration.mjs +0 -1
  400. package/dist/types/chat-suggestion-configuration.mjs.map +0 -1
  401. package/dist/types/coagent-action.d.ts +0 -29
  402. package/dist/types/coagent-action.js +0 -19
  403. package/dist/types/coagent-action.js.map +0 -1
  404. package/dist/types/coagent-action.mjs +0 -1
  405. package/dist/types/coagent-action.mjs.map +0 -1
  406. package/dist/types/coagent-state.d.ts +0 -15
  407. package/dist/types/coagent-state.js +0 -19
  408. package/dist/types/coagent-state.js.map +0 -1
  409. package/dist/types/coagent-state.mjs +0 -1
  410. package/dist/types/coagent-state.mjs.map +0 -1
  411. package/dist/types/crew.d.ts +0 -79
  412. package/dist/types/crew.js +0 -19
  413. package/dist/types/crew.js.map +0 -1
  414. package/dist/types/crew.mjs +0 -2
  415. package/dist/types/crew.mjs.map +0 -1
  416. package/dist/types/document-pointer.d.ts +0 -9
  417. package/dist/types/document-pointer.js +0 -19
  418. package/dist/types/document-pointer.js.map +0 -1
  419. package/dist/types/document-pointer.mjs +0 -1
  420. package/dist/types/document-pointer.mjs.map +0 -1
  421. package/dist/types/frontend-action.d.ts +0 -127
  422. package/dist/types/frontend-action.js +0 -53
  423. package/dist/types/frontend-action.js.map +0 -1
  424. package/dist/types/frontend-action.mjs +0 -8
  425. package/dist/types/frontend-action.mjs.map +0 -1
  426. package/dist/types/index.d.ts +0 -12
  427. package/dist/types/index.js +0 -19
  428. package/dist/types/index.js.map +0 -1
  429. package/dist/types/index.mjs +0 -4
  430. package/dist/types/index.mjs.map +0 -1
  431. package/dist/types/interrupt-action.d.ts +0 -10
  432. package/dist/types/interrupt-action.js +0 -19
  433. package/dist/types/interrupt-action.js.map +0 -1
  434. package/dist/types/interrupt-action.mjs +0 -2
  435. package/dist/types/interrupt-action.mjs.map +0 -1
  436. package/dist/types/system-message.d.ts +0 -3
  437. package/dist/types/system-message.js +0 -19
  438. package/dist/types/system-message.js.map +0 -1
  439. package/dist/types/system-message.mjs +0 -1
  440. package/dist/types/system-message.mjs.map +0 -1
  441. package/dist/utils/dev-console.d.ts +0 -3
  442. package/dist/utils/dev-console.js +0 -41
  443. package/dist/utils/dev-console.js.map +0 -1
  444. package/dist/utils/dev-console.mjs +0 -8
  445. package/dist/utils/dev-console.mjs.map +0 -1
  446. package/dist/utils/index.d.ts +0 -2
  447. package/dist/utils/index.js +0 -52
  448. package/dist/utils/index.js.map +0 -1
  449. package/dist/utils/index.mjs +0 -13
  450. package/dist/utils/index.mjs.map +0 -1
  451. package/dist/utils/suggestions-constants.d.ts +0 -9
  452. package/dist/utils/suggestions-constants.js +0 -35
  453. package/dist/utils/suggestions-constants.js.map +0 -1
  454. package/dist/utils/suggestions-constants.mjs +0 -8
  455. package/dist/utils/suggestions-constants.mjs.map +0 -1
  456. package/dist/utils/utils.d.ts +0 -2
  457. package/dist/utils/utils.js +0 -19
  458. package/dist/utils/utils.js.map +0 -1
  459. package/dist/utils/utils.mjs +0 -1
  460. package/dist/utils/utils.mjs.map +0 -1
  461. package/dist/v2/index.css +0 -4
  462. package/dist/v2/index.css.map +0 -1
  463. package/dist/v2/index.d.ts +0 -2
  464. package/dist/v2/index.js +0 -27
  465. package/dist/v2/index.js.map +0 -1
  466. package/dist/v2/index.mjs +0 -6
  467. package/dist/v2/index.mjs.map +0 -1
  468. package/jest.config.js +0 -25
  469. package/src/components/CopilotListeners.tsx +0 -81
  470. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +0 -75
  471. package/src/components/copilot-provider/copilot-messages.tsx +0 -274
  472. package/src/components/copilot-provider/copilotkit-props.tsx +0 -169
  473. package/src/components/copilot-provider/copilotkit.tsx +0 -671
  474. package/src/components/copilot-provider/index.ts +0 -3
  475. package/src/components/dev-console/console-trigger.tsx +0 -254
  476. package/src/components/dev-console/developer-console-modal.tsx +0 -866
  477. package/src/components/dev-console/icons.tsx +0 -101
  478. package/src/components/error-boundary/error-boundary.tsx +0 -91
  479. package/src/components/error-boundary/error-utils.tsx +0 -100
  480. package/src/components/index.ts +0 -1
  481. package/src/components/toast/exclamation-mark-icon.tsx +0 -27
  482. package/src/components/toast/toast-provider.tsx +0 -363
  483. package/src/components/usage-banner.tsx +0 -259
  484. package/src/context/coagent-state-renders-context.tsx +0 -76
  485. package/src/context/copilot-context.tsx +0 -332
  486. package/src/context/copilot-messages-context.tsx +0 -35
  487. package/src/context/index.ts +0 -16
  488. package/src/context/threads-context.tsx +0 -41
  489. package/src/hooks/__tests__/use-coagent-config.test.ts +0 -351
  490. package/src/hooks/index.ts +0 -34
  491. package/src/hooks/use-agent-nodename.ts +0 -30
  492. package/src/hooks/use-coagent-state-render-bridge.tsx +0 -293
  493. package/src/hooks/use-coagent-state-render.ts +0 -152
  494. package/src/hooks/use-coagent.ts +0 -366
  495. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  496. package/src/hooks/use-copilot-action.ts +0 -236
  497. package/src/hooks/use-copilot-additional-instructions.ts +0 -85
  498. package/src/hooks/use-copilot-authenticated-action.ts +0 -70
  499. package/src/hooks/use-copilot-chat-headless_c.ts +0 -258
  500. package/src/hooks/use-copilot-chat-suggestions.tsx +0 -124
  501. package/src/hooks/use-copilot-chat.ts +0 -130
  502. package/src/hooks/use-copilot-chat_internal.ts +0 -696
  503. package/src/hooks/use-copilot-readable.ts +0 -135
  504. package/src/hooks/use-copilot-runtime-client.ts +0 -164
  505. package/src/hooks/use-default-tool.ts +0 -7
  506. package/src/hooks/use-flat-category-store.ts +0 -105
  507. package/src/hooks/use-frontend-tool.ts +0 -96
  508. package/src/hooks/use-human-in-the-loop.ts +0 -122
  509. package/src/hooks/use-langgraph-interrupt-render.ts +0 -136
  510. package/src/hooks/use-langgraph-interrupt.ts +0 -36
  511. package/src/hooks/use-lazy-tool-renderer.tsx +0 -30
  512. package/src/hooks/use-make-copilot-document-readable.ts +0 -30
  513. package/src/hooks/use-render-tool-call.ts +0 -80
  514. package/src/hooks/use-tree.ts +0 -207
  515. package/src/index.tsx +0 -7
  516. package/src/lib/copilot-task.ts +0 -201
  517. package/src/lib/index.ts +0 -1
  518. package/src/lib/status-checker.ts +0 -64
  519. package/src/setupTests.ts +0 -26
  520. package/src/types/chat-suggestion-configuration.ts +0 -23
  521. package/src/types/coagent-action.ts +0 -31
  522. package/src/types/coagent-state.ts +0 -13
  523. package/src/types/crew.ts +0 -89
  524. package/src/types/document-pointer.ts +0 -7
  525. package/src/types/frontend-action.ts +0 -202
  526. package/src/types/index.ts +0 -17
  527. package/src/types/interrupt-action.ts +0 -43
  528. package/src/types/system-message.ts +0 -4
  529. package/src/utils/dev-console.ts +0 -19
  530. package/src/utils/index.ts +0 -2
  531. package/src/utils/suggestions-constants.ts +0 -8
  532. package/src/utils/utils.test.ts +0 -7
  533. package/src/utils/utils.ts +0 -8
  534. package/src/v2/index.css +0 -1
  535. package/src/v2/index.ts +0 -4
  536. package/tsconfig.json +0 -8
  537. package/tsup.config.ts +0 -16
  538. package/typedoc.json +0 -4
@@ -0,0 +1,1869 @@
1
+ import { CopilotKitContext, CopilotKitCoreReact, useCopilotKit, useCopilotKit as useCopilotKit$1, useDefaultAgentId } from "@copilotkit/react-core/context";
2
+ import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
+ import { DEFAULT_AGENT_ID, partialJSONParse, randomUUID } from "@copilotkit/shared";
4
+ import { Fragment, jsx } from "react/jsx-runtime";
5
+ import { CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, ɵInterruptState, ɵclearAgentInterruptState, ɵcreateThreadStore, ɵgetAgentInterruptState, ɵisHttpAgent, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
6
+ import { randomUUID as randomUUID$1 } from "@ag-ui/client";
7
+ import { z } from "zod";
8
+ import { contentToText } from "@ag-ui/core";
9
+
10
+ //#region src/lib/shallow-stable-ref.ts
11
+ /**
12
+ * Shallow equality comparison for objects.
13
+ */
14
+ function shallowEqual(obj1, obj2) {
15
+ const keys1 = Object.keys(obj1);
16
+ const keys2 = Object.keys(obj2);
17
+ if (keys1.length !== keys2.length) return false;
18
+ for (const key of keys1) if (obj1[key] !== obj2[key]) return false;
19
+ return true;
20
+ }
21
+ /**
22
+ * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
23
+ * class instances, and other exotic objects that happen to have typeof "object".
24
+ */
25
+ function isPlainObject$1(obj) {
26
+ return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
27
+ }
28
+ /**
29
+ * Returns the same reference as long as the value is shallowly equal to the
30
+ * previous render's value.
31
+ *
32
+ * - Identical references bail out immediately (O(1)).
33
+ * - Plain objects ({}) are shallow-compared key-by-key.
34
+ * - Arrays, Dates, class instances, functions, and primitives are compared by
35
+ * reference only — shallowEqual is never called on non-plain objects, which
36
+ * avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).
37
+ *
38
+ * Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow
39
+ * equality check isn't defeated by a new object reference on every render.
40
+ */
41
+ function useShallowStableRef(value) {
42
+ const ref = useRef(value);
43
+ if (ref.current === value) return ref.current;
44
+ if (isPlainObject$1(ref.current) && isPlainObject$1(value)) {
45
+ if (shallowEqual(ref.current, value)) return ref.current;
46
+ }
47
+ ref.current = value;
48
+ return ref.current;
49
+ }
50
+
51
+ //#endregion
52
+ //#region src/providers/CopilotChatConfigurationProvider.tsx
53
+ const CopilotChatDefaultLabels = {
54
+ chatInputPlaceholder: "Type a message...",
55
+ chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
56
+ chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
57
+ chatInputToolbarFinishTranscribeButtonLabel: "Finish",
58
+ chatInputToolbarAddButtonLabel: "Add attachments",
59
+ chatInputToolbarToolsButtonLabel: "Tools",
60
+ chatInputToolbarSendButtonLabel: "Send message",
61
+ chatInputToolbarStopButtonLabel: "Stop",
62
+ assistantMessageToolbarCopyCodeLabel: "Copy",
63
+ assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
64
+ assistantMessageToolbarCopyMessageLabel: "Copy",
65
+ assistantMessageToolbarInspectorLabel: "View in Inspector",
66
+ assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
67
+ assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
68
+ assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
69
+ assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
70
+ assistantMessageToolbarInspectorHideLabel: "Hide this icon",
71
+ assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
72
+ assistantMessageToolbarThumbsUpLabel: "Good response",
73
+ assistantMessageToolbarThumbsDownLabel: "Bad response",
74
+ assistantMessageFeedbackCommentPlaceholder: "Add a comment (optional)",
75
+ assistantMessageFeedbackCommentSubmitLabel: "Send comment",
76
+ assistantMessageToolbarReadAloudLabel: "Read aloud",
77
+ assistantMessageToolbarRegenerateLabel: "Regenerate",
78
+ userMessageToolbarCopyMessageLabel: "Copy",
79
+ userMessageToolbarEditMessageLabel: "Edit",
80
+ userMessageToolbarPreviousBranchLabel: "Previous branch",
81
+ userMessageToolbarNextBranchLabel: "Next branch",
82
+ chatDisclaimerText: "AI can make mistakes. Please verify important information.",
83
+ chatToggleOpenLabel: "Open chat",
84
+ chatToggleCloseLabel: "Close chat",
85
+ chatScrollToBottomLabel: "Scroll to bottom",
86
+ modalHeaderTitle: "CopilotKit Chat",
87
+ welcomeMessageText: "How can I help you today?",
88
+ reasoningMessageThinkingLabel: "Thinking…",
89
+ chatInputSlashMenuLabel: "Slash commands",
90
+ chatInputSlashMenuEmptyText: "No commands found",
91
+ attachmentRemoveButtonLabel: "Remove attachment",
92
+ attachmentPlayVideoButtonLabel: "Play video",
93
+ attachmentPreviewCloseButtonLabel: "Close preview",
94
+ modalHeaderCloseButtonLabel: "Close",
95
+ modalHeaderThreadsButtonLabel: "Open threads",
96
+ sidebarLabel: "Copilot chat sidebar"
97
+ };
98
+ /**
99
+ * Mobile breakpoint below which the chat modal and the thread-list drawer are
100
+ * mutually exclusive. At or above this width both surfaces may coexist. This
101
+ * mirrors the `(max-width: 767px)` / `(min-width: 768px)` split already used by
102
+ * CopilotChatInput and CopilotSidebarView.
103
+ */
104
+ const MOBILE_MAX_WIDTH_PX = 767;
105
+ /**
106
+ * Reports whether the current viewport is in the mobile range (`<768px`), where
107
+ * the chat modal and drawer must not be open simultaneously. SSR-safe and
108
+ * defensive against environments without `matchMedia` (treated as desktop, so
109
+ * no mutual-exclusion constraint is applied).
110
+ *
111
+ * @returns `true` when the viewport is mobile-width, `false` otherwise.
112
+ */
113
+ function isMobileViewport() {
114
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
115
+ return window.matchMedia(`(max-width: ${MOBILE_MAX_WIDTH_PX}px)`).matches;
116
+ }
117
+ const CopilotChatConfiguration = createContext(null);
118
+ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, hasExplicitThreadId, isModalDefaultOpen }) => {
119
+ const parentConfig = useContext(CopilotChatConfiguration);
120
+ const stableLabels = useShallowStableRef(labels);
121
+ const mergedLabels = useMemo(() => ({
122
+ ...CopilotChatDefaultLabels,
123
+ ...parentConfig?.labels,
124
+ ...stableLabels
125
+ }), [stableLabels, parentConfig?.labels]);
126
+ const providerAgentId = useDefaultAgentId();
127
+ const resolvedAgentId = agentId ?? parentConfig?.agentId ?? providerAgentId ?? DEFAULT_AGENT_ID;
128
+ const threadIdPropIsAuthoritative = threadId !== void 0 && hasExplicitThreadId !== false;
129
+ const isThreadIdControlled = threadIdPropIsAuthoritative;
130
+ const [activeThreadOverride, setActiveThreadOverride] = useState(null);
131
+ const resolvedThreadId = useMemo(() => {
132
+ if (threadIdPropIsAuthoritative) return threadId;
133
+ if (activeThreadOverride) return activeThreadOverride.threadId;
134
+ if (parentConfig?.threadId) return parentConfig.threadId;
135
+ if (threadId) return threadId;
136
+ return randomUUID();
137
+ }, [
138
+ threadIdPropIsAuthoritative,
139
+ threadId,
140
+ parentConfig?.threadId,
141
+ activeThreadOverride
142
+ ]);
143
+ const copilotkit = useContext(CopilotKitContext)?.copilotkit;
144
+ const openThreadRef = useRef(null);
145
+ const latestThreadIdRef = useRef(resolvedThreadId);
146
+ latestThreadIdRef.current = resolvedThreadId;
147
+ useEffect(() => {
148
+ if (copilotkit === void 0) return;
149
+ const registration = copilotkit.registerOpenThread({
150
+ agentId: resolvedAgentId,
151
+ threadId: latestThreadIdRef.current
152
+ });
153
+ openThreadRef.current = registration;
154
+ return () => {
155
+ registration.unregister();
156
+ openThreadRef.current = null;
157
+ };
158
+ }, [copilotkit, resolvedAgentId]);
159
+ useEffect(() => {
160
+ openThreadRef.current?.update(resolvedThreadId);
161
+ }, [resolvedThreadId]);
162
+ const resolvedHasExplicitThreadId = (threadIdPropIsAuthoritative ? true : activeThreadOverride?.explicit ?? hasExplicitThreadId ?? false) || !!parentConfig?.hasExplicitThreadId;
163
+ const [internalModalOpen, setInternalModalOpen] = useState(isModalDefaultOpen ?? true);
164
+ const hasExplicitDefault = isModalDefaultOpen !== void 0;
165
+ const setAndSync = useCallback((open) => {
166
+ setInternalModalOpen(open);
167
+ parentConfig?.setModalOpen(open);
168
+ }, [parentConfig?.setModalOpen]);
169
+ const isMounted = useRef(false);
170
+ useEffect(() => {
171
+ if (!hasExplicitDefault) return;
172
+ if (!isMounted.current) {
173
+ isMounted.current = true;
174
+ return;
175
+ }
176
+ if (parentConfig?.isModalOpen === void 0) return;
177
+ setInternalModalOpen(parentConfig.isModalOpen);
178
+ }, [parentConfig?.isModalOpen, hasExplicitDefault]);
179
+ const resolvedIsModalOpen = hasExplicitDefault ? internalModalOpen : parentConfig?.isModalOpen ?? internalModalOpen;
180
+ const resolvedSetModalOpen = hasExplicitDefault ? setAndSync : parentConfig?.setModalOpen ?? setInternalModalOpen;
181
+ const [ownDrawerOpen, setOwnDrawerOpen] = useState(false);
182
+ const [ownDrawerCount, setOwnDrawerCount] = useState(0);
183
+ const modalCloseRef = useRef(() => {});
184
+ modalCloseRef.current = resolvedSetModalOpen;
185
+ const registeredModalClosersRef = useRef([]);
186
+ const ownRegisterModalCloser = useCallback((closeModal) => {
187
+ registeredModalClosersRef.current.push(closeModal);
188
+ return () => {
189
+ registeredModalClosersRef.current = registeredModalClosersRef.current.filter((entry) => entry !== closeModal);
190
+ };
191
+ }, []);
192
+ const ownSetDrawerOpen = useCallback((open) => {
193
+ setOwnDrawerOpen(open);
194
+ if (open && isMobileViewport()) {
195
+ const registered = registeredModalClosersRef.current;
196
+ (registered.length > 0 ? registered[registered.length - 1] : modalCloseRef.current)(false);
197
+ }
198
+ }, []);
199
+ const ownRegisterDrawer = useCallback(() => {
200
+ setOwnDrawerCount((count) => count + 1);
201
+ return () => {
202
+ setOwnDrawerCount((count) => Math.max(0, count - 1));
203
+ };
204
+ }, []);
205
+ const resolvedDrawerOpen = parentConfig ? parentConfig.drawerOpen : ownDrawerOpen;
206
+ const resolvedSetDrawerOpen = parentConfig ? parentConfig.setDrawerOpen : ownSetDrawerOpen;
207
+ const resolvedDrawerRegistered = parentConfig ? parentConfig.drawerRegistered : ownDrawerCount > 0;
208
+ const resolvedRegisterDrawer = parentConfig ? parentConfig.registerDrawer : ownRegisterDrawer;
209
+ const resolvedRegisterModalCloser = parentConfig ? parentConfig.ɵregisterModalCloser : ownRegisterModalCloser;
210
+ useEffect(() => {
211
+ if (!hasExplicitDefault) return;
212
+ return resolvedRegisterModalCloser(resolvedSetModalOpen);
213
+ }, [
214
+ hasExplicitDefault,
215
+ resolvedRegisterModalCloser,
216
+ resolvedSetModalOpen
217
+ ]);
218
+ const isThreadIdControlledRef = useRef(isThreadIdControlled);
219
+ isThreadIdControlledRef.current = isThreadIdControlled;
220
+ const ownSetActiveThreadId = useCallback((id, options) => {
221
+ setActiveThreadOverride({
222
+ threadId: id,
223
+ explicit: options?.explicit ?? true
224
+ });
225
+ }, []);
226
+ const ownStartNewThread = useCallback(() => {
227
+ setActiveThreadOverride({
228
+ threadId: randomUUID(),
229
+ explicit: false
230
+ });
231
+ }, []);
232
+ const parentSetActiveThreadId = parentConfig?.setActiveThreadId;
233
+ const parentStartNewThread = parentConfig?.startNewThread;
234
+ const resolvedSetActiveThreadId = useCallback((id, options) => {
235
+ if (isThreadIdControlledRef.current) {
236
+ console.warn("[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");
237
+ return;
238
+ }
239
+ if (parentSetActiveThreadId) {
240
+ parentSetActiveThreadId(id, options);
241
+ return;
242
+ }
243
+ ownSetActiveThreadId(id, options);
244
+ }, [parentSetActiveThreadId, ownSetActiveThreadId]);
245
+ const resolvedStartNewThread = useCallback(() => {
246
+ if (isThreadIdControlledRef.current) {
247
+ console.warn("[CopilotKit] Ignoring startNewThread(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");
248
+ return;
249
+ }
250
+ if (parentStartNewThread) {
251
+ parentStartNewThread();
252
+ return;
253
+ }
254
+ ownStartNewThread();
255
+ }, [parentStartNewThread, ownStartNewThread]);
256
+ const setModalOpenWithDrawerExclusion = useCallback((open) => {
257
+ if (open && isMobileViewport()) resolvedSetDrawerOpen(false);
258
+ resolvedSetModalOpen(open);
259
+ }, [resolvedSetModalOpen, resolvedSetDrawerOpen]);
260
+ const configurationValue = useMemo(() => ({
261
+ labels: mergedLabels,
262
+ agentId: resolvedAgentId,
263
+ threadId: resolvedThreadId,
264
+ hasExplicitThreadId: resolvedHasExplicitThreadId,
265
+ isModalOpen: resolvedIsModalOpen,
266
+ setModalOpen: setModalOpenWithDrawerExclusion,
267
+ drawerOpen: resolvedDrawerOpen,
268
+ setDrawerOpen: resolvedSetDrawerOpen,
269
+ drawerRegistered: resolvedDrawerRegistered,
270
+ registerDrawer: resolvedRegisterDrawer,
271
+ ɵregisterModalCloser: resolvedRegisterModalCloser,
272
+ setActiveThreadId: resolvedSetActiveThreadId,
273
+ startNewThread: resolvedStartNewThread
274
+ }), [
275
+ mergedLabels,
276
+ resolvedAgentId,
277
+ resolvedThreadId,
278
+ resolvedHasExplicitThreadId,
279
+ resolvedIsModalOpen,
280
+ setModalOpenWithDrawerExclusion,
281
+ resolvedDrawerOpen,
282
+ resolvedSetDrawerOpen,
283
+ resolvedDrawerRegistered,
284
+ resolvedRegisterDrawer,
285
+ resolvedRegisterModalCloser,
286
+ resolvedSetActiveThreadId,
287
+ resolvedStartNewThread
288
+ ]);
289
+ return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, {
290
+ value: configurationValue,
291
+ children
292
+ });
293
+ };
294
+ const useCopilotChatConfiguration = () => {
295
+ return useContext(CopilotChatConfiguration);
296
+ };
297
+ /**
298
+ * Reports modal open/close requests to the host, and — when `open` is
299
+ * supplied — makes the modal state of an already-established chat
300
+ * configuration **controlled** for the subtree it wraps.
301
+ *
302
+ * This is deliberately a scope component rather than another mode inside
303
+ * {@link CopilotChatConfigurationProvider}. The provider resolves modal state
304
+ * across a nested chain (own state, parent sync, drawer mutual-exclusion, the
305
+ * modal-closer registry); a controlled branch inside that resolution would add
306
+ * a fourth interacting mode. Overriding the context for the subtree instead
307
+ * leaves every one of those paths untouched:
308
+ *
309
+ * - `isModalOpen` is replaced with the host's `open`, so the rendered surface
310
+ * follows the prop from the very first frame (no open-then-close flash).
311
+ * - `setModalOpen` still calls the underlying setter, so the existing
312
+ * parent-sync and drawer mutual-exclusion side effects continue to run, and
313
+ * *then* reports the request through `onOpenChange`.
314
+ * - The wrapped setter is registered as the modal closer, so the drawer's
315
+ * mobile mutual-exclusion reaches the host instead of silently flipping
316
+ * state that nothing displays.
317
+ *
318
+ * A host that supplies `open` and ignores `onOpenChange` gets a modal pinned
319
+ * to `open`, which is the standard controlled-component contract. A host that
320
+ * supplies only `onOpenChange` is notified while the modal keeps managing
321
+ * itself.
322
+ *
323
+ * Renders `children` unchanged when no chat configuration is in scope.
324
+ */
325
+ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
326
+ const parentConfig = useContext(CopilotChatConfiguration);
327
+ const parentSetModalOpen = parentConfig?.setModalOpen;
328
+ const registerModalCloser = parentConfig?.ɵregisterModalCloser;
329
+ const setModalOpen = useCallback((next) => {
330
+ parentSetModalOpen?.(next);
331
+ onOpenChange?.(next);
332
+ }, [parentSetModalOpen, onOpenChange]);
333
+ useEffect(() => {
334
+ if (!registerModalCloser) return;
335
+ return registerModalCloser(setModalOpen);
336
+ }, [registerModalCloser, setModalOpen]);
337
+ const configurationValue = useMemo(() => parentConfig ? {
338
+ ...parentConfig,
339
+ isModalOpen: open ?? parentConfig.isModalOpen,
340
+ setModalOpen
341
+ } : null, [
342
+ parentConfig,
343
+ open,
344
+ setModalOpen
345
+ ]);
346
+ if (!configurationValue) return /* @__PURE__ */ jsx(Fragment, { children });
347
+ return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, {
348
+ value: configurationValue,
349
+ children
350
+ });
351
+ };
352
+ ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
353
+
354
+ //#endregion
355
+ //#region src/hooks/use-agent.tsx
356
+ let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
357
+ UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
358
+ UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
359
+ UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
360
+ return UseAgentUpdate;
361
+ }({});
362
+ const ALL_UPDATES = [
363
+ UseAgentUpdate.OnMessagesChanged,
364
+ UseAgentUpdate.OnStateChanged,
365
+ UseAgentUpdate.OnRunStatusChanged
366
+ ];
367
+ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
368
+ if (threadId != null && runtimeAgentId == null) throw new Error(`useAgent: \`threadId\` requires \`runtimeAgentId\`. A threadId is written onto a single agent, but an agent resolved by agentId alone is shared, so scoping a thread to it would clobber other useAgent callers. Pass a distinct local \`agentId\` and the runtime agent to route to, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${agentId ?? "default"}", threadId }).`);
369
+ if (runtimeAgentId != null && threadId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires \`threadId\`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, e.g. useAgent({ agentId: "${agentId ?? "chat-1"}", runtimeAgentId: "${runtimeAgentId}", threadId }), or bind to the agent directly with useAgent({ agentId: "${runtimeAgentId}" }).`);
370
+ if (runtimeAgentId != null && agentId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${runtimeAgentId}", threadId }).`);
371
+ const chatConfig = useCopilotChatConfiguration();
372
+ const providerAgentId = useDefaultAgentId();
373
+ const resolvedAgentId = agentId ?? chatConfig?.agentId ?? providerAgentId ?? DEFAULT_AGENT_ID;
374
+ const { copilotkit } = useCopilotKit$1();
375
+ const providerThrottleMs = copilotkit.defaultThrottleMs;
376
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
377
+ const updateFlags = useMemo(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
378
+ const provisionalAgentCache = useRef(/* @__PURE__ */ new Map());
379
+ const [registeredProxyAgent, setRegisteredProxyAgent] = useState(null);
380
+ useEffect(() => {
381
+ if (runtimeAgentId == null) {
382
+ setRegisteredProxyAgent(null);
383
+ return;
384
+ }
385
+ const { agent: proxy, unregister } = copilotkit.registerProxiedAgent({
386
+ agentId: resolvedAgentId,
387
+ runtimeAgentId
388
+ });
389
+ provisionalAgentCache.current.delete(resolvedAgentId);
390
+ setRegisteredProxyAgent(proxy);
391
+ return () => {
392
+ unregister();
393
+ setRegisteredProxyAgent(null);
394
+ };
395
+ }, [
396
+ copilotkit,
397
+ resolvedAgentId,
398
+ runtimeAgentId
399
+ ]);
400
+ const { agent, isReady } = useMemo(() => {
401
+ if (runtimeAgentId != null) {
402
+ if (registeredProxyAgent) {
403
+ provisionalAgentCache.current.delete(resolvedAgentId);
404
+ return {
405
+ agent: registeredProxyAgent,
406
+ isReady: true
407
+ };
408
+ }
409
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
410
+ if (cached) {
411
+ copilotkit.applyHeadersToAgent(cached);
412
+ return {
413
+ agent: cached,
414
+ isReady: false
415
+ };
416
+ }
417
+ const provisional = new ProxiedCopilotRuntimeAgent({
418
+ runtimeUrl: copilotkit.runtimeUrl,
419
+ agentId: resolvedAgentId,
420
+ runtimeAgentId,
421
+ transport: copilotkit.runtimeTransport,
422
+ runtimeMode: "pending"
423
+ });
424
+ copilotkit.applyHeadersToAgent(provisional);
425
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
426
+ return {
427
+ agent: provisional,
428
+ isReady: false
429
+ };
430
+ }
431
+ const existing = copilotkit.getAgent(resolvedAgentId);
432
+ if (existing) {
433
+ provisionalAgentCache.current.delete(resolvedAgentId);
434
+ return {
435
+ agent: existing,
436
+ isReady: true
437
+ };
438
+ }
439
+ const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
440
+ const status = copilotkit.runtimeConnectionStatus;
441
+ if (isRuntimeConfigured && (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
442
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
443
+ if (cached) return {
444
+ agent: cached,
445
+ isReady: false
446
+ };
447
+ const provisional = new ProxiedCopilotRuntimeAgent({
448
+ runtimeUrl: copilotkit.runtimeUrl,
449
+ agentId: resolvedAgentId,
450
+ transport: copilotkit.runtimeTransport,
451
+ credentials: copilotkit.credentials,
452
+ runtimeMode: "pending"
453
+ });
454
+ copilotkit.applyHeadersToAgent(provisional);
455
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
456
+ return {
457
+ agent: provisional,
458
+ isReady: false
459
+ };
460
+ }
461
+ if (isRuntimeConfigured && status === CopilotKitCoreRuntimeConnectionStatus.Error) {
462
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
463
+ if (cached) return {
464
+ agent: cached,
465
+ isReady: false
466
+ };
467
+ const provisional = new ProxiedCopilotRuntimeAgent({
468
+ runtimeUrl: copilotkit.runtimeUrl,
469
+ agentId: resolvedAgentId,
470
+ transport: copilotkit.runtimeTransport,
471
+ credentials: copilotkit.credentials,
472
+ runtimeMode: "pending"
473
+ });
474
+ copilotkit.applyHeadersToAgent(provisional);
475
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
476
+ return {
477
+ agent: provisional,
478
+ isReady: false
479
+ };
480
+ }
481
+ const knownAgents = Object.keys(copilotkit.agents ?? {});
482
+ const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
483
+ throw new Error(`useAgent: Agent '${resolvedAgentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
484
+ }, [
485
+ resolvedAgentId,
486
+ runtimeAgentId,
487
+ registeredProxyAgent,
488
+ copilotkit.agents,
489
+ copilotkit.runtimeConnectionStatus,
490
+ copilotkit.runtimeUrl,
491
+ copilotkit.runtimeTransport,
492
+ copilotkit.credentials,
493
+ JSON.stringify(copilotkit.headers)
494
+ ]);
495
+ useEffect(() => {
496
+ if (updateFlags.length === 0) return;
497
+ let active = true;
498
+ const handlers = {};
499
+ let batchScheduled = false;
500
+ const batchedForceUpdate = () => {
501
+ if (!active) return;
502
+ if (!batchScheduled) {
503
+ batchScheduled = true;
504
+ queueMicrotask(() => {
505
+ batchScheduled = false;
506
+ if (active) forceUpdate();
507
+ });
508
+ }
509
+ };
510
+ if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = batchedForceUpdate;
511
+ if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
512
+ if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
513
+ handlers.onRunInitialized = batchedForceUpdate;
514
+ handlers.onRunStartedEvent = batchedForceUpdate;
515
+ handlers.onRunFinalized = batchedForceUpdate;
516
+ handlers.onRunFailed = batchedForceUpdate;
517
+ handlers.onRunErrorEvent = batchedForceUpdate;
518
+ }
519
+ const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
520
+ return () => {
521
+ active = false;
522
+ subscription.unsubscribe();
523
+ };
524
+ }, [
525
+ agent,
526
+ forceUpdate,
527
+ throttleMs,
528
+ providerThrottleMs,
529
+ updateFlags
530
+ ]);
531
+ useEffect(() => {
532
+ if (ɵisHttpAgent(agent)) copilotkit.applyHeadersToAgent(agent);
533
+ if (agent instanceof ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
534
+ }, [
535
+ agent,
536
+ JSON.stringify(copilotkit.headers),
537
+ copilotkit.credentials
538
+ ]);
539
+ const configThreadId = chatConfig?.threadId;
540
+ const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
541
+ const resolvedThreadId = threadId ?? (configHasExplicitThreadId ? configThreadId : void 0);
542
+ useEffect(() => {
543
+ if (!resolvedThreadId) return;
544
+ agent.threadId = resolvedThreadId;
545
+ }, [agent, resolvedThreadId]);
546
+ return {
547
+ agent,
548
+ isReady
549
+ };
550
+ }
551
+
552
+ //#endregion
553
+ //#region src/hooks/tool-registration.ts
554
+ /**
555
+ * Deps comparison shared by `useFrontendTool` (and through it
556
+ * `useHumanInTheLoop` and `useComponent`) and `useRenderTool`. Not part of the
557
+ * public API.
558
+ */
559
+ const EMPTY_DEPS$1 = [];
560
+ function isPlainObject(value) {
561
+ const proto = Object.getPrototypeOf(value);
562
+ return proto === Object.prototype || proto === null;
563
+ }
564
+ /**
565
+ * Plain data (primitives, plain objects, arrays, dates) compares by value.
566
+ * Functions always compare equal: these hooks used to compare
567
+ * `JSON.stringify(deps)`, which turns every function into `null`, and a
568
+ * function that counted as changed would re-register on every render when it
569
+ * is written inline (and loop in a component that also reads
570
+ * `useRenderToolCall`). Everything else (class instances, maps, sets) compares
571
+ * by identity. A cycle inside plain data is safe: a pair already being
572
+ * compared counts as equal for that branch.
573
+ */
574
+ function depEqual(a, b, seen) {
575
+ if (Object.is(a, b)) return true;
576
+ if (typeof a === "function" && typeof b === "function") return true;
577
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
578
+ if (a instanceof Date && b instanceof Date) return Object.is(a.getTime(), b.getTime());
579
+ const aIsArray = Array.isArray(a);
580
+ if (aIsArray !== Array.isArray(b)) return false;
581
+ if (!aIsArray && !(isPlainObject(a) && isPlainObject(b))) return false;
582
+ if (seen.get(a) === b) return true;
583
+ seen.set(a, b);
584
+ if (aIsArray) {
585
+ const left = a;
586
+ const right = b;
587
+ if (left.length !== right.length) return false;
588
+ for (let i = 0; i < left.length; i++) if (!depEqual(left[i], right[i], seen)) return false;
589
+ return true;
590
+ }
591
+ const left = a;
592
+ const right = b;
593
+ const leftKeys = Object.keys(left);
594
+ if (leftKeys.length !== Object.keys(right).length) return false;
595
+ for (const key of leftKeys) {
596
+ if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
597
+ if (!depEqual(left[key], right[key], seen)) return false;
598
+ }
599
+ return true;
600
+ }
601
+ /** Whether two deps arrays are equal. A change in length is always a change. */
602
+ function depsEqual(prev, next) {
603
+ if (prev.length !== next.length) return false;
604
+ const seen = /* @__PURE__ */ new Map();
605
+ for (let i = 0; i < prev.length; i++) if (!depEqual(prev[i], next[i], seen)) return false;
606
+ return true;
607
+ }
608
+ /**
609
+ * Turns a caller's `deps` array into a number that changes exactly when the
610
+ * deps change, by the rules of {@link depsEqual}. Put the number, not the
611
+ * array, in the registration effect's dependency list: that keeps the list a
612
+ * constant length and never serializes a value.
613
+ */
614
+ function useDepsVersion(deps) {
615
+ const next = deps ?? EMPTY_DEPS$1;
616
+ const ref = useRef({
617
+ deps: next,
618
+ version: 0
619
+ });
620
+ if (ref.current.deps !== next && !depsEqual(ref.current.deps, next)) ref.current = {
621
+ deps: next,
622
+ version: ref.current.version + 1
623
+ };
624
+ return ref.current.version;
625
+ }
626
+
627
+ //#endregion
628
+ //#region src/hooks/use-frontend-tool.tsx
629
+ function useFrontendTool(tool, deps) {
630
+ const { copilotkit } = useCopilotKit$1();
631
+ const depsVersion = useDepsVersion(deps);
632
+ useLayoutEffect(() => {
633
+ const name = tool.name;
634
+ if (copilotkit.getTool({
635
+ toolName: name,
636
+ agentId: tool.agentId
637
+ })) {
638
+ console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
639
+ copilotkit.removeTool(name, tool.agentId);
640
+ }
641
+ copilotkit.addTool(tool);
642
+ if (tool.render) copilotkit.addHookRenderToolCall({
643
+ name,
644
+ args: tool.parameters,
645
+ agentId: tool.agentId,
646
+ render: tool.render
647
+ });
648
+ return () => {
649
+ copilotkit.removeTool(name, tool.agentId);
650
+ };
651
+ }, [
652
+ tool.name,
653
+ tool.available,
654
+ copilotkit,
655
+ depsVersion,
656
+ JSON.stringify(tool.webmcp ?? null)
657
+ ]);
658
+ }
659
+
660
+ //#endregion
661
+ //#region src/hooks/use-frontend-tools.tsx
662
+ const EMPTY_DEPS = [];
663
+ const EMPTY_TOOLS = [];
664
+ /**
665
+ * Register a list of frontend tools whose length can change between renders.
666
+ *
667
+ * `useFrontendTool` registers exactly one tool per call, so it cannot be called
668
+ * in a loop over a runtime-length list without breaking the rules of hooks.
669
+ * This hook runs a single effect over the whole array instead, which makes it
670
+ * safe to build the list from state, props, or a server response.
671
+ *
672
+ * Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
673
+ * tool that disappears from the array is unregistered on the next render, and
674
+ * every tool is unregistered on unmount. Renderers stay registered after
675
+ * unmount so past tool calls still render in the chat history.
676
+ *
677
+ * @param tools - The tools to register. May be empty and may change length.
678
+ * @param deps - Extra dependencies that force re-registration, compared by
679
+ * identity like the second argument of `useEffect`. Use this when a handler
680
+ * closes over a value that is not part of the tool definition. Keep the array
681
+ * a constant length across renders.
682
+ *
683
+ * @example
684
+ * Register one tool per item in application state:
685
+ * ```tsx
686
+ * const [reports, setReports] = useState<Report[]>([]);
687
+ *
688
+ * useFrontendTools(
689
+ * reports.map((report) => ({
690
+ * name: `open_${report.id}`,
691
+ * description: `Open the ${report.title} report`,
692
+ * handler: async () => navigate(`/reports/${report.id}`),
693
+ * })),
694
+ * [navigate],
695
+ * );
696
+ * ```
697
+ *
698
+ * @example
699
+ * Register tools described by the backend:
700
+ * ```tsx
701
+ * const { data } = useQuery(fetchToolDescriptors);
702
+ *
703
+ * useFrontendTools(
704
+ * (data ?? []).map((descriptor) => ({
705
+ * name: descriptor.name,
706
+ * description: descriptor.description,
707
+ * parameters: z.object({ query: z.string() }),
708
+ * handler: async ({ query }) => runDescriptor(descriptor.id, query),
709
+ * })),
710
+ * );
711
+ * ```
712
+ */
713
+ function useFrontendTools(tools, deps) {
714
+ const { copilotkit } = useCopilotKit$1();
715
+ const toolList = tools ?? EMPTY_TOOLS;
716
+ const extraDeps = deps ?? EMPTY_DEPS;
717
+ useLayoutEffect(() => {
718
+ const deduped = /* @__PURE__ */ new Map();
719
+ for (const tool of toolList) {
720
+ const key = `${tool.agentId ?? ""}:${tool.name}`;
721
+ if (deduped.has(key)) console.warn(`Tool '${tool.name}' is listed more than once for agent '${tool.agentId || "global"}' in the same useFrontendTools call. Using the last entry.`);
722
+ deduped.set(key, tool);
723
+ }
724
+ const registered = [...deduped.values()];
725
+ for (const tool of registered) {
726
+ if (copilotkit.getTool({
727
+ toolName: tool.name,
728
+ agentId: tool.agentId
729
+ })) {
730
+ console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
731
+ copilotkit.removeTool(tool.name, tool.agentId);
732
+ }
733
+ copilotkit.addTool(tool);
734
+ if (tool.render) copilotkit.addHookRenderToolCall({
735
+ name: tool.name,
736
+ args: tool.parameters,
737
+ agentId: tool.agentId,
738
+ render: tool.render
739
+ });
740
+ }
741
+ return () => {
742
+ for (const tool of registered) copilotkit.removeTool(tool.name, tool.agentId);
743
+ };
744
+ }, [
745
+ JSON.stringify(toolList.map((tool) => [
746
+ tool.name,
747
+ tool.description ?? null,
748
+ tool.agentId ?? null,
749
+ tool.available ?? null,
750
+ tool.webmcp ?? null
751
+ ])),
752
+ copilotkit,
753
+ ...extraDeps
754
+ ]);
755
+ }
756
+
757
+ //#endregion
758
+ //#region src/hooks/use-component.tsx
759
+ /**
760
+ * Registers a React component as a frontend tool renderer in chat.
761
+ *
762
+ * This hook is a convenience wrapper around `useFrontendTool` that:
763
+ * - builds a model-facing tool description,
764
+ * - forwards optional schema parameters (any Standard Schema V1 compatible library),
765
+ * - renders your component with tool call parameters.
766
+ *
767
+ * Use this when you want to display a typed visual component for a tool call
768
+ * without manually wiring a full frontend tool object.
769
+ *
770
+ * When `parameters` is provided, render props are inferred from the schema.
771
+ * When omitted, the render component may accept any props.
772
+ *
773
+ * @typeParam TSchema - Schema describing tool parameters, or `undefined` when no schema is given.
774
+ * @param config - Tool registration config.
775
+ * @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
776
+ *
777
+ * @example
778
+ * ```tsx
779
+ * // Without parameters — render accepts any props
780
+ * useComponent({
781
+ * name: "showGreeting",
782
+ * render: ({ message }: { message: string }) => <div>{message}</div>,
783
+ * });
784
+ * ```
785
+ *
786
+ * @example
787
+ * ```tsx
788
+ * // With parameters — render props inferred from schema
789
+ * useComponent({
790
+ * name: "showWeatherCard",
791
+ * parameters: z.object({ city: z.string() }),
792
+ * render: ({ city }) => <div>{city}</div>,
793
+ * });
794
+ * ```
795
+ *
796
+ * @example
797
+ * ```tsx
798
+ * useComponent(
799
+ * {
800
+ * name: "renderProfile",
801
+ * parameters: z.object({ userId: z.string() }),
802
+ * render: ProfileCard,
803
+ * agentId: "support-agent",
804
+ * },
805
+ * [selectedAgentId],
806
+ * );
807
+ * ```
808
+ */
809
+ function useComponent(config, deps) {
810
+ const prefix = `Use this tool to display the "${config.name}" component in the chat. This tool renders a visual UI component for the user.`;
811
+ const fullDescription = config.description ? `${prefix}\n\n${config.description}` : prefix;
812
+ useFrontendTool({
813
+ name: config.name,
814
+ description: fullDescription,
815
+ parameters: config.parameters,
816
+ render: ({ args }) => {
817
+ const Component = config.render;
818
+ return /* @__PURE__ */ jsx(Component, { ...args });
819
+ },
820
+ agentId: config.agentId,
821
+ followUp: config.followUp
822
+ }, deps);
823
+ }
824
+
825
+ //#endregion
826
+ //#region src/hooks/use-human-in-the-loop.tsx
827
+ /** Registration name of a catch-all tool: handles any otherwise-unhandled call. */
828
+ const WILDCARD_TOOL_NAME = "*";
829
+ function useHumanInTheLoop(tool, deps) {
830
+ const { copilotkit } = useCopilotKit$1();
831
+ const resolvePromiseRef = useRef(null);
832
+ const cleanupAbortRef = useRef(null);
833
+ const respond = useCallback(async (result) => {
834
+ if (resolvePromiseRef.current) {
835
+ cleanupAbortRef.current?.();
836
+ cleanupAbortRef.current = null;
837
+ resolvePromiseRef.current(result);
838
+ resolvePromiseRef.current = null;
839
+ }
840
+ }, []);
841
+ const handler = useCallback(async (_args, context) => {
842
+ const signal = context?.signal;
843
+ return new Promise((resolve, reject) => {
844
+ if (signal?.aborted) {
845
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
846
+ return;
847
+ }
848
+ resolvePromiseRef.current = resolve;
849
+ if (signal) {
850
+ const onAbort = () => {
851
+ cleanupAbortRef.current = null;
852
+ resolvePromiseRef.current = null;
853
+ reject(/* @__PURE__ */ new Error("Human-in-the-loop interaction aborted"));
854
+ };
855
+ signal.addEventListener("abort", onAbort, { once: true });
856
+ cleanupAbortRef.current = () => {
857
+ signal.removeEventListener("abort", onAbort);
858
+ };
859
+ }
860
+ });
861
+ }, []);
862
+ const RenderComponent = useCallback((props) => {
863
+ const ToolComponent = tool.render;
864
+ const name = tool.name === WILDCARD_TOOL_NAME ? props.name : tool.name;
865
+ if (props.status === ToolCallStatus.InProgress) {
866
+ const enhancedProps = {
867
+ ...props,
868
+ name,
869
+ description: tool.description || "",
870
+ agentId: tool.agentId,
871
+ respond: void 0
872
+ };
873
+ return React.createElement(ToolComponent, enhancedProps);
874
+ } else if (props.status === ToolCallStatus.Executing) {
875
+ const enhancedProps = {
876
+ ...props,
877
+ name,
878
+ description: tool.description || "",
879
+ agentId: tool.agentId,
880
+ respond
881
+ };
882
+ return React.createElement(ToolComponent, enhancedProps);
883
+ } else if (props.status === ToolCallStatus.Complete) {
884
+ const enhancedProps = {
885
+ ...props,
886
+ name,
887
+ description: tool.description || "",
888
+ agentId: tool.agentId,
889
+ respond: void 0
890
+ };
891
+ return React.createElement(ToolComponent, enhancedProps);
892
+ }
893
+ return props;
894
+ }, [
895
+ tool.render,
896
+ tool.name,
897
+ tool.description,
898
+ tool.agentId,
899
+ respond
900
+ ]);
901
+ useFrontendTool({
902
+ ...tool,
903
+ type: "human-in-the-loop",
904
+ handler,
905
+ render: RenderComponent
906
+ }, deps);
907
+ useLayoutEffect(() => {
908
+ return () => {
909
+ copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
910
+ };
911
+ }, [
912
+ copilotkit,
913
+ tool.name,
914
+ tool.agentId
915
+ ]);
916
+ }
917
+
918
+ //#endregion
919
+ //#region src/types/interrupt.ts
920
+ /** Name of the legacy custom event agents emit to signal an interrupt. */
921
+ const INTERRUPT_EVENT_NAME = "on_interrupt";
922
+
923
+ //#endregion
924
+ //#region src/hooks/use-interrupt.tsx
925
+ /** Recognize thenables returned by interrupt preprocessing handlers. */
926
+ function isPromiseLike(value) {
927
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
928
+ }
929
+ /** Derive the legacy-compatible `event` for any pending interrupt. */
930
+ function toLegacyEvent(pending) {
931
+ if (pending.kind === "legacy") return pending.event;
932
+ return {
933
+ name: INTERRUPT_EVENT_NAME,
934
+ value: pending.interrupts[0]
935
+ };
936
+ }
937
+ /**
938
+ * Handles agent interrupts with optional filtering, preprocessing, and resume behavior.
939
+ *
940
+ * Supports both the AG-UI standard interrupt flow (`RUN_FINISHED` with
941
+ * `outcome.type === "interrupt"`) and the legacy custom-event flow
942
+ * (`on_interrupt`). For standard interrupts, `render` receives `interrupt`
943
+ * (the primary one) and `interrupts` (the full open set); call `resolve(payload)`
944
+ * to resume or `cancel()` to cancel. Resuming addresses the targeted interrupt
945
+ * and, once every open interrupt is addressed, submits a single spec `resume`
946
+ * array via `copilotkit.runAgent`.
947
+ *
948
+ * - `renderInChat: true` (default): the element is published into `<CopilotChat>`; returns `void`.
949
+ * - `renderInChat: false`: the hook returns the interrupt element for manual placement.
950
+ *
951
+ * @example
952
+ * ```tsx
953
+ * useInterrupt({
954
+ * render: ({ interrupt, resolve, cancel }) => (
955
+ * <div>
956
+ * <p>{interrupt?.message}</p>
957
+ * <button onClick={() => resolve({ approved: true })}>Approve</button>
958
+ * <button onClick={() => cancel()}>Cancel</button>
959
+ * </div>
960
+ * ),
961
+ * });
962
+ * ```
963
+ */
964
+ function useInterrupt(config) {
965
+ const { copilotkit } = useCopilotKit$1();
966
+ const { agent } = useAgent({
967
+ agentId: config.agentId,
968
+ updates: []
969
+ });
970
+ const [pending, setPending] = useState(null);
971
+ const pendingRef = useRef(pending);
972
+ pendingRef.current = pending;
973
+ const [handlerResult, setHandlerResult] = useState(null);
974
+ const interruptStateRef = useRef(new ɵInterruptState());
975
+ useEffect(() => {
976
+ let localLegacy = null;
977
+ let localStandard = null;
978
+ const subscription = agent.subscribe({
979
+ onCustomEvent: ({ event }) => {
980
+ if (event.name === INTERRUPT_EVENT_NAME) localLegacy = {
981
+ name: event.name,
982
+ value: event.value
983
+ };
984
+ },
985
+ onRunFinishedEvent: (params) => {
986
+ if (params.outcome === "interrupt") localStandard = params.interrupts;
987
+ },
988
+ onRunStartedEvent: (params) => {
989
+ if (!agent.pendingInterrupts?.length || params?.input?.resume !== void 0) ɵclearAgentInterruptState(agent);
990
+ localLegacy = null;
991
+ localStandard = null;
992
+ interruptStateRef.current = new ɵInterruptState();
993
+ setPending(null);
994
+ },
995
+ onRunFinalized: () => {
996
+ if (localStandard && localStandard.length > 0) {
997
+ interruptStateRef.current = ɵgetAgentInterruptState(agent, localStandard);
998
+ setPending(interruptStateRef.current.pending);
999
+ } else if (localLegacy) {
1000
+ interruptStateRef.current = new ɵInterruptState();
1001
+ interruptStateRef.current.setLegacy(localLegacy);
1002
+ setPending(interruptStateRef.current.pending);
1003
+ }
1004
+ localLegacy = null;
1005
+ localStandard = null;
1006
+ },
1007
+ onRunFailed: () => {
1008
+ localLegacy = null;
1009
+ localStandard = null;
1010
+ interruptStateRef.current = new ɵInterruptState();
1011
+ setPending(null);
1012
+ }
1013
+ });
1014
+ interruptStateRef.current = agent.pendingInterrupts?.length ? ɵgetAgentInterruptState(agent) : new ɵInterruptState();
1015
+ setPending(interruptStateRef.current.pending);
1016
+ return () => {
1017
+ subscription.unsubscribe();
1018
+ interruptStateRef.current = new ɵInterruptState();
1019
+ };
1020
+ }, [agent]);
1021
+ /** Record an explicit answer and resume once the complete batch is addressed. */
1022
+ const resolve = useCallback(async (payload, interruptId) => {
1023
+ const current = pendingRef.current;
1024
+ if (!current) return;
1025
+ if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
1026
+ if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
1027
+ console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
1028
+ return;
1029
+ }
1030
+ const decision = interruptStateRef.current.resolve(payload, interruptId, agent.messages);
1031
+ if (decision.kind === "legacy-resume") try {
1032
+ return await copilotkit.runAgent({
1033
+ agent,
1034
+ forwardedProps: { command: {
1035
+ resume: decision.payload,
1036
+ interruptEvent: decision.interruptValue
1037
+ } }
1038
+ });
1039
+ } catch (err) {
1040
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
1041
+ setPending(null);
1042
+ throw err;
1043
+ }
1044
+ if (decision.kind === "expired") {
1045
+ console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
1046
+ interruptStateRef.current = new ɵInterruptState();
1047
+ setPending(null);
1048
+ return;
1049
+ }
1050
+ if (decision.kind !== "resume") return;
1051
+ for (const toolResult of decision.toolResults) agent.addMessage({
1052
+ id: randomUUID$1(),
1053
+ role: "tool",
1054
+ toolCallId: toolResult.toolCallId,
1055
+ content: toolResult.content
1056
+ });
1057
+ try {
1058
+ return await copilotkit.runAgent({
1059
+ agent,
1060
+ resume: decision.resume
1061
+ });
1062
+ } catch (err) {
1063
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
1064
+ interruptStateRef.current = new ɵInterruptState();
1065
+ setPending(null);
1066
+ throw err;
1067
+ }
1068
+ }, [agent, copilotkit]);
1069
+ /** Cancel a standard interrupt or dismiss a legacy interrupt locally. */
1070
+ const cancel = useCallback(async (interruptId) => {
1071
+ const current = pendingRef.current;
1072
+ if (!current) return;
1073
+ if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
1074
+ if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
1075
+ console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
1076
+ return;
1077
+ }
1078
+ const decision = interruptStateRef.current.cancel(interruptId, agent.messages);
1079
+ if (decision.kind === "dismiss") {
1080
+ console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
1081
+ interruptStateRef.current = new ɵInterruptState();
1082
+ setPending(null);
1083
+ return;
1084
+ }
1085
+ if (decision.kind === "expired") {
1086
+ console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
1087
+ interruptStateRef.current = new ɵInterruptState();
1088
+ setPending(null);
1089
+ return;
1090
+ }
1091
+ if (decision.kind !== "resume") return;
1092
+ for (const toolResult of decision.toolResults) agent.addMessage({
1093
+ id: randomUUID$1(),
1094
+ role: "tool",
1095
+ toolCallId: toolResult.toolCallId,
1096
+ content: toolResult.content
1097
+ });
1098
+ try {
1099
+ return await copilotkit.runAgent({
1100
+ agent,
1101
+ resume: decision.resume
1102
+ });
1103
+ } catch (err) {
1104
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
1105
+ interruptStateRef.current = new ɵInterruptState();
1106
+ setPending(null);
1107
+ throw err;
1108
+ }
1109
+ }, [agent, copilotkit]);
1110
+ const renderRef = useRef(config.render);
1111
+ renderRef.current = config.render;
1112
+ const enabledRef = useRef(config.enabled);
1113
+ enabledRef.current = config.enabled;
1114
+ const handlerRef = useRef(config.handler);
1115
+ handlerRef.current = config.handler;
1116
+ const resolveRef = useRef(resolve);
1117
+ resolveRef.current = resolve;
1118
+ const cancelRef = useRef(cancel);
1119
+ cancelRef.current = cancel;
1120
+ /** Evaluate the consumer filter, logging failures and disabling their UI. */
1121
+ const isEnabled = (event) => {
1122
+ const predicate = enabledRef.current;
1123
+ if (!predicate) return true;
1124
+ try {
1125
+ return predicate(event);
1126
+ } catch (err) {
1127
+ console.error("[CopilotKit] useInterrupt enabled predicate threw; treating interrupt as disabled:", err);
1128
+ return false;
1129
+ }
1130
+ };
1131
+ useEffect(() => {
1132
+ if (!pending) {
1133
+ setHandlerResult(null);
1134
+ return;
1135
+ }
1136
+ const legacyEvent = toLegacyEvent(pending);
1137
+ if (!isEnabled(legacyEvent)) {
1138
+ setHandlerResult(null);
1139
+ return;
1140
+ }
1141
+ const handler = handlerRef.current;
1142
+ if (!handler) {
1143
+ setHandlerResult(null);
1144
+ return;
1145
+ }
1146
+ let cancelled = false;
1147
+ let maybePromise;
1148
+ try {
1149
+ maybePromise = handler({
1150
+ event: legacyEvent,
1151
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
1152
+ interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
1153
+ resolve: resolveRef.current,
1154
+ cancel: cancelRef.current
1155
+ });
1156
+ } catch (err) {
1157
+ console.error("[CopilotKit] useInterrupt handler threw; result will be null:", err);
1158
+ if (!cancelled) setHandlerResult(null);
1159
+ return () => {
1160
+ cancelled = true;
1161
+ };
1162
+ }
1163
+ if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).then((resolved) => {
1164
+ if (!cancelled) setHandlerResult(resolved);
1165
+ }).catch((err) => {
1166
+ console.error("[CopilotKit] useInterrupt handler rejected; result will be null:", err);
1167
+ if (!cancelled) setHandlerResult(null);
1168
+ });
1169
+ else setHandlerResult(maybePromise);
1170
+ return () => {
1171
+ cancelled = true;
1172
+ };
1173
+ }, [pending]);
1174
+ const element = useMemo(() => {
1175
+ if (!pending) return null;
1176
+ const legacyEvent = toLegacyEvent(pending);
1177
+ if (!isEnabled(legacyEvent)) return null;
1178
+ return renderRef.current({
1179
+ event: legacyEvent,
1180
+ interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
1181
+ interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
1182
+ result: handlerResult,
1183
+ resolve,
1184
+ cancel
1185
+ });
1186
+ }, [
1187
+ pending,
1188
+ handlerResult,
1189
+ resolve,
1190
+ cancel
1191
+ ]);
1192
+ useEffect(() => {
1193
+ if (config.renderInChat === false) return;
1194
+ copilotkit.setInterruptElement(element);
1195
+ }, [
1196
+ element,
1197
+ config.renderInChat,
1198
+ copilotkit
1199
+ ]);
1200
+ useEffect(() => {
1201
+ if (config.renderInChat === false) return;
1202
+ return () => {
1203
+ copilotkit.setInterruptElement(null);
1204
+ };
1205
+ }, []);
1206
+ if (config.renderInChat === false) return element;
1207
+ }
1208
+
1209
+ //#endregion
1210
+ //#region src/hooks/use-suggestions.tsx
1211
+ function useSuggestions({ agentId } = {}) {
1212
+ const { copilotkit } = useCopilotKit$1();
1213
+ const config = useCopilotChatConfiguration();
1214
+ const providerAgentId = useDefaultAgentId();
1215
+ const resolvedAgentId = useMemo(() => agentId ?? config?.agentId ?? providerAgentId ?? DEFAULT_AGENT_ID, [
1216
+ agentId,
1217
+ config?.agentId,
1218
+ providerAgentId
1219
+ ]);
1220
+ const [suggestions, setSuggestions] = useState(() => {
1221
+ return copilotkit.getSuggestions(resolvedAgentId).suggestions;
1222
+ });
1223
+ const [isLoading, setIsLoading] = useState(() => {
1224
+ return copilotkit.getSuggestions(resolvedAgentId).isLoading;
1225
+ });
1226
+ useEffect(() => {
1227
+ const result = copilotkit.getSuggestions(resolvedAgentId);
1228
+ setSuggestions(result.suggestions);
1229
+ setIsLoading(result.isLoading);
1230
+ }, [copilotkit, resolvedAgentId]);
1231
+ useEffect(() => {
1232
+ const subscription = copilotkit.subscribe({
1233
+ onSuggestionsChanged: ({ agentId: changedAgentId, suggestions }) => {
1234
+ if (changedAgentId !== resolvedAgentId) return;
1235
+ setSuggestions(suggestions);
1236
+ },
1237
+ onSuggestionsStartedLoading: ({ agentId: changedAgentId }) => {
1238
+ if (changedAgentId !== resolvedAgentId) return;
1239
+ setIsLoading(true);
1240
+ },
1241
+ onSuggestionsFinishedLoading: ({ agentId: changedAgentId }) => {
1242
+ if (changedAgentId !== resolvedAgentId) return;
1243
+ setIsLoading(false);
1244
+ },
1245
+ onSuggestionsConfigChanged: () => {
1246
+ const result = copilotkit.getSuggestions(resolvedAgentId);
1247
+ setSuggestions(result.suggestions);
1248
+ setIsLoading(result.isLoading);
1249
+ }
1250
+ });
1251
+ return () => {
1252
+ subscription.unsubscribe();
1253
+ };
1254
+ }, [copilotkit, resolvedAgentId]);
1255
+ return {
1256
+ suggestions,
1257
+ reloadSuggestions: useCallback(() => {
1258
+ copilotkit.reloadSuggestions(resolvedAgentId);
1259
+ }, [copilotkit, resolvedAgentId]),
1260
+ clearSuggestions: useCallback(() => {
1261
+ copilotkit.clearSuggestions(resolvedAgentId);
1262
+ }, [copilotkit, resolvedAgentId]),
1263
+ isLoading
1264
+ };
1265
+ }
1266
+
1267
+ //#endregion
1268
+ //#region src/hooks/use-configure-suggestions.tsx
1269
+ function useConfigureSuggestions(config, deps) {
1270
+ const { copilotkit } = useCopilotKit$1();
1271
+ const chatConfig = useCopilotChatConfiguration();
1272
+ const extraDeps = deps ?? [];
1273
+ const resolvedConsumerAgentId = useMemo(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID, [chatConfig?.agentId]);
1274
+ const rawConsumerAgentId = useMemo(() => config ? config.consumerAgentId : void 0, [config]);
1275
+ const normalizationCacheRef = useRef({
1276
+ serialized: null,
1277
+ config: null
1278
+ });
1279
+ const { normalizedConfig, serializedConfig } = useMemo(() => {
1280
+ if (!config) {
1281
+ normalizationCacheRef.current = {
1282
+ serialized: null,
1283
+ config: null
1284
+ };
1285
+ return {
1286
+ normalizedConfig: null,
1287
+ serializedConfig: null
1288
+ };
1289
+ }
1290
+ if (config.available === "disabled") {
1291
+ normalizationCacheRef.current = {
1292
+ serialized: null,
1293
+ config: null
1294
+ };
1295
+ return {
1296
+ normalizedConfig: null,
1297
+ serializedConfig: null
1298
+ };
1299
+ }
1300
+ let built;
1301
+ if (isDynamicConfig(config)) built = { ...config };
1302
+ else {
1303
+ const normalizedSuggestions = normalizeStaticSuggestions(config.suggestions);
1304
+ built = {
1305
+ ...config,
1306
+ suggestions: normalizedSuggestions
1307
+ };
1308
+ }
1309
+ const serialized = JSON.stringify(built);
1310
+ const cache = normalizationCacheRef.current;
1311
+ if (cache.serialized === serialized && cache.config) return {
1312
+ normalizedConfig: cache.config,
1313
+ serializedConfig: serialized
1314
+ };
1315
+ normalizationCacheRef.current = {
1316
+ serialized,
1317
+ config: built
1318
+ };
1319
+ return {
1320
+ normalizedConfig: built,
1321
+ serializedConfig: serialized
1322
+ };
1323
+ }, [
1324
+ config,
1325
+ resolvedConsumerAgentId,
1326
+ ...extraDeps
1327
+ ]);
1328
+ const latestConfigRef = useRef(null);
1329
+ latestConfigRef.current = normalizedConfig;
1330
+ const previousSerializedConfigRef = useRef(null);
1331
+ const targetAgentId = useMemo(() => {
1332
+ if (!normalizedConfig) return resolvedConsumerAgentId;
1333
+ const consumer = normalizedConfig.consumerAgentId;
1334
+ if (!consumer || consumer === "*") return resolvedConsumerAgentId;
1335
+ return consumer;
1336
+ }, [normalizedConfig, resolvedConsumerAgentId]);
1337
+ const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
1338
+ const isDynamicConfigType = useMemo(() => !!normalizedConfig && "instructions" in normalizedConfig, [normalizedConfig]);
1339
+ const requestReload = useCallback(() => {
1340
+ if (!normalizedConfig) return;
1341
+ if (isGlobalConfig) {
1342
+ const seen = /* @__PURE__ */ new Set();
1343
+ const agents = Object.values(copilotkit.agents ?? {});
1344
+ for (const entry of agents) {
1345
+ const agentId = entry.agentId;
1346
+ if (!agentId) continue;
1347
+ seen.add(agentId);
1348
+ if (!entry.isRunning) copilotkit.reloadSuggestions(agentId);
1349
+ }
1350
+ if (targetAgentId && !seen.has(targetAgentId)) copilotkit.reloadSuggestions(targetAgentId);
1351
+ return;
1352
+ }
1353
+ if (!targetAgentId) return;
1354
+ copilotkit.reloadSuggestions(targetAgentId);
1355
+ }, [
1356
+ copilotkit,
1357
+ isGlobalConfig,
1358
+ normalizedConfig,
1359
+ targetAgentId
1360
+ ]);
1361
+ useEffect(() => {
1362
+ if (!serializedConfig || !latestConfigRef.current) return;
1363
+ const id = copilotkit.addSuggestionsConfig(latestConfigRef.current);
1364
+ requestReload();
1365
+ return () => {
1366
+ copilotkit.removeSuggestionsConfig(id);
1367
+ };
1368
+ }, [
1369
+ copilotkit,
1370
+ serializedConfig,
1371
+ requestReload
1372
+ ]);
1373
+ useEffect(() => {
1374
+ if (!normalizedConfig) {
1375
+ previousSerializedConfigRef.current = null;
1376
+ return;
1377
+ }
1378
+ if (serializedConfig && previousSerializedConfigRef.current === serializedConfig) return;
1379
+ if (serializedConfig) previousSerializedConfigRef.current = serializedConfig;
1380
+ requestReload();
1381
+ }, [
1382
+ normalizedConfig,
1383
+ requestReload,
1384
+ serializedConfig
1385
+ ]);
1386
+ useEffect(() => {
1387
+ if (!normalizedConfig || extraDeps.length === 0) return;
1388
+ requestReload();
1389
+ }, [
1390
+ extraDeps.length,
1391
+ normalizedConfig,
1392
+ requestReload,
1393
+ ...extraDeps
1394
+ ]);
1395
+ useEffect(() => {
1396
+ if (!normalizedConfig || !isDynamicConfigType) return;
1397
+ if (!targetAgentId) return;
1398
+ if (!!copilotkit.getAgent(targetAgentId)) return;
1399
+ const subscription = copilotkit.subscribe({ onAgentsChanged: () => {
1400
+ if (copilotkit.getAgent(targetAgentId)) {
1401
+ requestReload();
1402
+ subscription.unsubscribe();
1403
+ }
1404
+ } });
1405
+ return () => {
1406
+ subscription.unsubscribe();
1407
+ };
1408
+ }, [
1409
+ copilotkit,
1410
+ normalizedConfig,
1411
+ isDynamicConfigType,
1412
+ targetAgentId,
1413
+ requestReload
1414
+ ]);
1415
+ }
1416
+ function isDynamicConfig(config) {
1417
+ return "instructions" in config;
1418
+ }
1419
+ function normalizeStaticSuggestions(suggestions) {
1420
+ return suggestions.map((suggestion) => ({
1421
+ ...suggestion,
1422
+ isLoading: suggestion.isLoading ?? false
1423
+ }));
1424
+ }
1425
+
1426
+ //#endregion
1427
+ //#region src/hooks/use-agent-context.tsx
1428
+ function useAgentContext(context) {
1429
+ const { description, value } = context;
1430
+ const { copilotkit } = useCopilotKit$1();
1431
+ const stringValue = useMemo(() => {
1432
+ if (typeof value === "string") return value;
1433
+ return JSON.stringify(value);
1434
+ }, [value]);
1435
+ useLayoutEffect(() => {
1436
+ if (!copilotkit) return;
1437
+ const id = copilotkit.addContext({
1438
+ description,
1439
+ value: stringValue
1440
+ });
1441
+ return () => {
1442
+ copilotkit.removeContext(id);
1443
+ };
1444
+ }, [
1445
+ description,
1446
+ stringValue,
1447
+ copilotkit
1448
+ ]);
1449
+ }
1450
+
1451
+ //#endregion
1452
+ //#region src/hooks/use-threads.tsx
1453
+ function useThreadStoreSelector(store, selector) {
1454
+ return useSyncExternalStore(useCallback((onStoreChange) => {
1455
+ const subscription = store.select(selector).subscribe(onStoreChange);
1456
+ return () => subscription.unsubscribe();
1457
+ }, [store, selector]), () => selector(store.getState()), () => selector(store.getServerState()));
1458
+ }
1459
+ /**
1460
+ * React hook for listing and managing CopilotKit Intelligence threads.
1461
+ *
1462
+ * On mount the hook fetches the thread list for the runtime-authenticated user
1463
+ * and the given `agentId`. When CopilotKit Intelligence exposes a WebSocket
1464
+ * URL, it also opens a realtime subscription so the `threads` array stays
1465
+ * current without polling — thread creates, renames, archives, and deletes
1466
+ * from any client are reflected immediately.
1467
+ *
1468
+ * Mutation methods (`renameThread`, `archiveThread`, `unarchiveThread`,
1469
+ * `deleteThread`) return promises that resolve once the platform confirms the
1470
+ * operation and reject with an `Error` on failure.
1471
+ *
1472
+ * @param input - Agent identifier and optional list controls.
1473
+ * @returns Thread list state and stable mutation callbacks.
1474
+ *
1475
+ * @example
1476
+ * ```tsx
1477
+ * import { useThreads } from "@copilotkit/react-core";
1478
+ *
1479
+ * function ThreadList() {
1480
+ * const { threads, isLoading, renameThread, deleteThread } = useThreads({
1481
+ * agentId: "agent-1",
1482
+ * });
1483
+ *
1484
+ * if (isLoading) return <p>Loading…</p>;
1485
+ *
1486
+ * return (
1487
+ * <ul>
1488
+ * {threads.map((t) => (
1489
+ * <li key={t.id}>
1490
+ * {t.name ?? "Untitled"}
1491
+ * <button onClick={() => renameThread(t.id, "New name")}>Rename</button>
1492
+ * <button onClick={() => deleteThread(t.id)}>Delete</button>
1493
+ * </li>
1494
+ * ))}
1495
+ * </ul>
1496
+ * );
1497
+ * }
1498
+ * ```
1499
+ */
1500
+ function useThreads({ agentId, includeArchived, limit, enabled = true }) {
1501
+ const { copilotkit } = useCopilotKit$1();
1502
+ const [store] = useState(() => ɵcreateThreadStore({ fetch: copilotkit.ɵruntimeFetch }));
1503
+ const coreThreads = useThreadStoreSelector(store, ɵselectThreads);
1504
+ const threads = useMemo(() => coreThreads.map(({ id, agentId, name, archived, createdAt, updatedAt, lastRunAt }) => ({
1505
+ id,
1506
+ agentId,
1507
+ name,
1508
+ archived,
1509
+ createdAt,
1510
+ updatedAt,
1511
+ ...lastRunAt !== void 0 ? { lastRunAt } : {}
1512
+ })), [coreThreads]);
1513
+ const storeIsLoading = useThreadStoreSelector(store, ɵselectThreadsIsLoading);
1514
+ const storeError = useThreadStoreSelector(store, ɵselectThreadsError);
1515
+ const fetchMoreError = useThreadStoreSelector(store, ɵselectFetchMoreError);
1516
+ const hasMoreThreads = useThreadStoreSelector(store, ɵselectHasNextPage);
1517
+ const isFetchingMoreThreads = useThreadStoreSelector(store, ɵselectIsFetchingNextPage);
1518
+ const isMutating = useThreadStoreSelector(store, ɵselectIsMutating);
1519
+ const headersKey = copilotkit.ɵheadersGeneration;
1520
+ const runtimeStatus = copilotkit.runtimeConnectionStatus;
1521
+ const threadListEndpointSupported = copilotkit.threadEndpoints?.list !== false;
1522
+ const threadMutationsSupported = copilotkit.threadEndpoints?.mutations !== false;
1523
+ const threadEndpointsUnavailable = !!copilotkit.runtimeUrl && runtimeStatus === CopilotKitCoreRuntimeConnectionStatus.Connected && !threadListEndpointSupported;
1524
+ const runtimeError = useMemo(() => {
1525
+ if (copilotkit.runtimeUrl) return null;
1526
+ return /* @__PURE__ */ new Error("Runtime URL is not configured");
1527
+ }, [copilotkit.runtimeUrl]);
1528
+ const threadEndpointsError = useMemo(() => {
1529
+ if (!threadEndpointsUnavailable) return null;
1530
+ return /* @__PURE__ */ new Error("Thread endpoints are not available on this CopilotKit runtime");
1531
+ }, [threadEndpointsUnavailable]);
1532
+ const threadMutationsError = useMemo(() => {
1533
+ if (threadMutationsSupported) return null;
1534
+ return /* @__PURE__ */ new Error("Thread mutations are not available on this CopilotKit runtime");
1535
+ }, [threadMutationsSupported]);
1536
+ const [hasDispatchedContext, setHasDispatchedContext] = useState(false);
1537
+ const preConnectLoading = enabled && !!copilotkit.runtimeUrl && !threadEndpointsUnavailable && !hasDispatchedContext;
1538
+ const [configErrorDismissed, setConfigErrorDismissed] = useState(false);
1539
+ useEffect(() => {
1540
+ setConfigErrorDismissed(false);
1541
+ }, [runtimeError, threadEndpointsError]);
1542
+ const activeRuntimeError = configErrorDismissed ? null : runtimeError;
1543
+ const activeThreadEndpointsError = configErrorDismissed ? null : threadEndpointsError;
1544
+ const isLoading = activeRuntimeError || activeThreadEndpointsError ? false : preConnectLoading || storeIsLoading;
1545
+ const error = activeRuntimeError ?? activeThreadEndpointsError ?? storeError;
1546
+ const listError = storeError;
1547
+ useEffect(() => {
1548
+ store.start();
1549
+ return () => {
1550
+ store.stop();
1551
+ };
1552
+ }, [store]);
1553
+ useEffect(() => {
1554
+ if (!enabled) return;
1555
+ copilotkit.registerThreadStore(agentId, store);
1556
+ return () => {
1557
+ copilotkit.unregisterThreadStore(agentId);
1558
+ };
1559
+ }, [
1560
+ copilotkit,
1561
+ agentId,
1562
+ store,
1563
+ enabled
1564
+ ]);
1565
+ useEffect(() => {
1566
+ if (!enabled) {
1567
+ store.setContext(null);
1568
+ setHasDispatchedContext(false);
1569
+ return;
1570
+ }
1571
+ if (!copilotkit.runtimeUrl) {
1572
+ store.setContext(null);
1573
+ setHasDispatchedContext(false);
1574
+ return;
1575
+ }
1576
+ if (runtimeStatus !== CopilotKitCoreRuntimeConnectionStatus.Connected) return;
1577
+ if (!threadListEndpointSupported) {
1578
+ store.setContext(null);
1579
+ setHasDispatchedContext(false);
1580
+ return;
1581
+ }
1582
+ const context = {
1583
+ runtimeUrl: copilotkit.runtimeUrl,
1584
+ wsUrl: copilotkit.intelligence?.wsUrl,
1585
+ agentId,
1586
+ includeArchived,
1587
+ limit
1588
+ };
1589
+ store.setContext(context);
1590
+ setHasDispatchedContext(true);
1591
+ }, [
1592
+ store,
1593
+ enabled,
1594
+ copilotkit.runtimeUrl,
1595
+ runtimeStatus,
1596
+ headersKey,
1597
+ copilotkit.intelligence?.wsUrl,
1598
+ threadListEndpointSupported,
1599
+ agentId,
1600
+ includeArchived,
1601
+ limit
1602
+ ]);
1603
+ const guardMutation = useCallback((mutation) => {
1604
+ return (...args) => {
1605
+ if (threadMutationsError) return Promise.reject(threadMutationsError);
1606
+ return mutation(...args);
1607
+ };
1608
+ }, [threadMutationsError]);
1609
+ const renameThread = useMemo(() => guardMutation((threadId, name) => store.renameThread(threadId, name)), [store, guardMutation]);
1610
+ const archiveThread = useMemo(() => guardMutation((threadId) => store.archiveThread(threadId)), [store, guardMutation]);
1611
+ const unarchiveThread = useMemo(() => guardMutation((threadId) => store.unarchiveThread(threadId)), [store, guardMutation]);
1612
+ const deleteThread = useMemo(() => guardMutation((threadId) => store.deleteThread(threadId)), [store, guardMutation]);
1613
+ return {
1614
+ threads,
1615
+ isLoading,
1616
+ error,
1617
+ listError,
1618
+ fetchMoreError,
1619
+ hasMoreThreads,
1620
+ isFetchingMoreThreads,
1621
+ isMutating,
1622
+ fetchMoreThreads: useCallback(() => store.fetchNextPage(), [store]),
1623
+ refetchThreads: useCallback(() => store.refetchThreads(), [store]),
1624
+ startNewThread: useCallback(() => {
1625
+ setConfigErrorDismissed(true);
1626
+ store.startNewThread();
1627
+ }, [store]),
1628
+ renameThread,
1629
+ archiveThread,
1630
+ unarchiveThread,
1631
+ deleteThread
1632
+ };
1633
+ }
1634
+
1635
+ //#endregion
1636
+ //#region src/types/defineToolCallRenderer.ts
1637
+ function defineToolCallRenderer(def) {
1638
+ const argsSchema = def.name === "*" && !def.args ? z.any() : def.args;
1639
+ return {
1640
+ name: def.name,
1641
+ args: argsSchema,
1642
+ render: def.render,
1643
+ ...def.agentId ? { agentId: def.agentId } : {},
1644
+ ...def.group ? { group: true } : {}
1645
+ };
1646
+ }
1647
+
1648
+ //#endregion
1649
+ //#region src/hooks/use-render-tool.tsx
1650
+ /**
1651
+ * Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
1652
+ *
1653
+ * Key behavior:
1654
+ * - deduplicates by `agentId:name` (latest registration wins),
1655
+ * - keeps renderer entries on cleanup so historical chat tool calls can still render,
1656
+ * - refreshes registration when `deps` change.
1657
+ *
1658
+ * @typeParam S - Schema type describing tool call parameters.
1659
+ * @param config - Renderer config for wildcard or named tools.
1660
+ * @param deps - Optional dependencies to refresh registration.
1661
+ *
1662
+ * @example
1663
+ * ```tsx
1664
+ * useRenderTool(
1665
+ * {
1666
+ * name: "searchDocs",
1667
+ * parameters: z.object({ query: z.string() }),
1668
+ * render: ({ status, parameters, result }) => {
1669
+ * if (status === "executing") return <div>Searching {parameters.query}</div>;
1670
+ * if (status === "complete") return <div>{result}</div>;
1671
+ * return <div>Preparing...</div>;
1672
+ * },
1673
+ * },
1674
+ * [],
1675
+ * );
1676
+ * ```
1677
+ *
1678
+ * @example
1679
+ * ```tsx
1680
+ * useRenderTool(
1681
+ * {
1682
+ * name: "summarize",
1683
+ * parameters: z.object({ text: z.string() }),
1684
+ * agentId: "research-agent",
1685
+ * render: ({ name, status }) => <div>{name}: {status}</div>,
1686
+ * },
1687
+ * [selectedAgentId],
1688
+ * );
1689
+ * ```
1690
+ */
1691
+ function useRenderTool(config, deps) {
1692
+ const { copilotkit } = useCopilotKit$1();
1693
+ const depsVersion = useDepsVersion(deps);
1694
+ useEffect(() => {
1695
+ const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
1696
+ name: "*",
1697
+ render: (props) => config.render({
1698
+ ...props,
1699
+ parameters: props.args
1700
+ }),
1701
+ ...config.agentId ? { agentId: config.agentId } : {},
1702
+ group: config.group
1703
+ }) : defineToolCallRenderer({
1704
+ name: config.name,
1705
+ args: config.parameters,
1706
+ render: (props) => {
1707
+ if (props.status === ToolCallStatus.InProgress) return config.render({
1708
+ ...props,
1709
+ parameters: props.args
1710
+ });
1711
+ if (props.status === ToolCallStatus.Executing) return config.render({
1712
+ ...props,
1713
+ parameters: props.args
1714
+ });
1715
+ return config.render({
1716
+ ...props,
1717
+ parameters: props.args
1718
+ });
1719
+ },
1720
+ ...config.agentId ? { agentId: config.agentId } : {},
1721
+ group: config.group
1722
+ });
1723
+ copilotkit.addHookRenderToolCall(renderer);
1724
+ }, [
1725
+ config.name,
1726
+ config.group,
1727
+ copilotkit,
1728
+ depsVersion
1729
+ ]);
1730
+ }
1731
+
1732
+ //#endregion
1733
+ //#region src/hooks/use-render-tool-call.tsx
1734
+ /**
1735
+ * Memoized component that renders a single tool call.
1736
+ * This prevents unnecessary re-renders when parent components update
1737
+ * but the tool call data hasn't changed.
1738
+ */
1739
+ const ToolCallRenderer = React.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
1740
+ const args = useMemo(() => partialJSONParse(toolCall.function.arguments), [toolCall.function.arguments]);
1741
+ const toolName = toolCall.function.name;
1742
+ if (toolMessage) return /* @__PURE__ */ jsx(RenderComponent, {
1743
+ name: toolName,
1744
+ toolCallId: toolCall.id,
1745
+ args,
1746
+ status: ToolCallStatus.Complete,
1747
+ result: contentToText(toolMessage.content)
1748
+ });
1749
+ else if (isExecuting) return /* @__PURE__ */ jsx(RenderComponent, {
1750
+ name: toolName,
1751
+ toolCallId: toolCall.id,
1752
+ args,
1753
+ status: ToolCallStatus.Executing,
1754
+ result: void 0
1755
+ });
1756
+ else return /* @__PURE__ */ jsx(RenderComponent, {
1757
+ name: toolName,
1758
+ toolCallId: toolCall.id,
1759
+ args,
1760
+ status: ToolCallStatus.InProgress,
1761
+ result: void 0
1762
+ });
1763
+ }, (prevProps, nextProps) => {
1764
+ if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
1765
+ if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
1766
+ if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
1767
+ if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
1768
+ if (prevProps.isExecuting !== nextProps.isExecuting) return false;
1769
+ if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
1770
+ return true;
1771
+ });
1772
+ const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
1773
+ /**
1774
+ * Reports tool calls that resolved to no renderer.
1775
+ *
1776
+ * A tool call with no renderer paints an empty message container and says
1777
+ * nothing else, so the only signal a developer gets today is a blank space in
1778
+ * the chat. This names the call and the renderers that *are* registered, which
1779
+ * is the whole diagnosis when the cause is a name that does not match.
1780
+ *
1781
+ * @param toolNames - The unmatched tool names collected during render.
1782
+ * @param registered - The registry as it stands now, re-read at report time.
1783
+ * @param alreadyWarned - Names already reported, mutated to keep this once per name.
1784
+ */
1785
+ function warnAboutUnrenderedToolCalls(toolNames, registered, alreadyWarned) {
1786
+ const registeredNames = Array.from(new Set(registered.map((rc) => rc.name)));
1787
+ const hasWildcard = registeredNames.includes("*");
1788
+ for (const toolName of toolNames) {
1789
+ if (hasWildcard || registeredNames.includes(toolName)) continue;
1790
+ if (alreadyWarned.has(toolName)) continue;
1791
+ alreadyWarned.add(toolName);
1792
+ console.warn(`[CopilotKit] The agent called the tool "${toolName}", and no renderer is registered for it, so that message rendered nothing. ` + (registeredNames.length === 0 ? "No tool-call renderers are registered. " : `Registered renderers: ${registeredNames.map((name) => `"${name}"`).join(", ")}. `) + `Register one with useRenderTool({ name: "${toolName}", ... }), or call useDefaultRenderTool() for a built-in card that covers every tool the agent calls. This warning is development-only.`);
1793
+ }
1794
+ }
1795
+ /**
1796
+ * The tool-call renderers registered on the provider, kept current.
1797
+ * @internal
1798
+ */
1799
+ function useToolCallRenderers() {
1800
+ const { copilotkit } = useCopilotKit$1();
1801
+ return useSyncExternalStore((callback) => copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
1802
+ }
1803
+ /**
1804
+ * Hook that returns a function to render tool calls based on the render functions
1805
+ * defined in CopilotKitProvider.
1806
+ *
1807
+ * @returns A function that takes a tool call and optional tool message and returns the rendered component
1808
+ */
1809
+ function useRenderToolCall() {
1810
+ const { copilotkit, executingToolCallIds } = useCopilotKit$1();
1811
+ const agentId = useCopilotChatConfiguration()?.agentId ?? DEFAULT_AGENT_ID;
1812
+ const unrenderedToolNames = useRef(/* @__PURE__ */ new Set());
1813
+ const warnedToolNames = useRef(/* @__PURE__ */ new Set());
1814
+ const renderToolCalls = useToolCallRenderers();
1815
+ const renderToolCall = useCallback(({ toolCall, toolMessage }) => {
1816
+ const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
1817
+ const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
1818
+ if (!renderConfig) {
1819
+ if (IS_DEVELOPMENT) unrenderedToolNames.current.add(toolCall.function.name);
1820
+ return null;
1821
+ }
1822
+ const RenderComponent = renderConfig.render;
1823
+ return /* @__PURE__ */ jsx(ToolCallRenderer, {
1824
+ toolCall,
1825
+ toolMessage,
1826
+ RenderComponent,
1827
+ isExecuting: executingToolCallIds.has(toolCall.id)
1828
+ }, toolCall.id);
1829
+ }, [
1830
+ renderToolCalls,
1831
+ executingToolCallIds,
1832
+ agentId
1833
+ ]);
1834
+ useEffect(() => {
1835
+ if (!IS_DEVELOPMENT) return;
1836
+ if (unrenderedToolNames.current.size === 0) return;
1837
+ const timer = setTimeout(() => {
1838
+ const pending = Array.from(unrenderedToolNames.current);
1839
+ unrenderedToolNames.current.clear();
1840
+ warnAboutUnrenderedToolCalls(pending, copilotkit.renderToolCalls, warnedToolNames.current);
1841
+ }, 0);
1842
+ return () => clearTimeout(timer);
1843
+ });
1844
+ return renderToolCall;
1845
+ }
1846
+
1847
+ //#endregion
1848
+ //#region src/hooks/use-capabilities.tsx
1849
+ /**
1850
+ * Returns the capabilities declared by the given agent (or the agent resolved
1851
+ * from the surrounding chat configuration, falling back to the default agent).
1852
+ * Capabilities are populated from the runtime `/info` response at connection
1853
+ * time. The hook reads them synchronously from the agent instance — there is
1854
+ * no separate loading state, but the value will be `undefined` until the
1855
+ * runtime handshake completes.
1856
+ *
1857
+ * @param agentId - Optional agent ID. If omitted, inherits the surrounding
1858
+ * chat configuration's agent, falling back to the default agent.
1859
+ * @returns The agent's capabilities, or `undefined` if the agent doesn't
1860
+ * declare capabilities.
1861
+ */
1862
+ function useCapabilities(agentId) {
1863
+ const { agent } = useAgent({ agentId });
1864
+ if (agent && "capabilities" in agent) return agent.capabilities;
1865
+ }
1866
+
1867
+ //#endregion
1868
+ export { CopilotChatConfigurationProvider, CopilotChatDefaultLabels, CopilotKitCoreReact, UseAgentUpdate, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useFrontendTool, useFrontendTools, useHumanInTheLoop, useInterrupt, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
1869
+ //# sourceMappingURL=headless.mjs.map