@copilotkit/react-core 0.0.0-fix-debug-infosys-20251107162427 → 0.0.0-fix-restore-handle-method-node-http-20251222114321

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 (355) hide show
  1. package/CHANGELOG.md +309 -4
  2. package/dist/chunk-36KQV2NA.mjs +1 -0
  3. package/dist/{chunk-EDBI5PCJ.mjs → chunk-3V5TOYKW.mjs} +2 -2
  4. package/dist/chunk-3V5TOYKW.mjs.map +1 -0
  5. package/dist/chunk-4RRMC7L2.mjs +32 -0
  6. package/dist/chunk-4RRMC7L2.mjs.map +1 -0
  7. package/dist/chunk-4YZA2BZC.mjs +551 -0
  8. package/dist/chunk-4YZA2BZC.mjs.map +1 -0
  9. package/dist/{chunk-E3624YDU.mjs → chunk-53K6WNJG.mjs} +8 -6
  10. package/dist/{chunk-E3624YDU.mjs.map → chunk-53K6WNJG.mjs.map} +1 -1
  11. package/dist/{chunk-N4WEHORG.mjs → chunk-6PUNP7CD.mjs} +4 -4
  12. package/dist/chunk-6PUNP7CD.mjs.map +1 -0
  13. package/dist/chunk-7DTB7S5V.mjs +83 -0
  14. package/dist/chunk-7DTB7S5V.mjs.map +1 -0
  15. package/dist/{chunk-BBUQMG45.mjs → chunk-7IBF6RBW.mjs} +3 -3
  16. package/dist/{chunk-BBUQMG45.mjs.map → chunk-7IBF6RBW.mjs.map} +1 -1
  17. package/dist/chunk-A6NKSGH3.mjs +1 -0
  18. package/dist/{chunk-MGWRDFBE.mjs → chunk-ABWT4DRT.mjs} +2 -2
  19. package/dist/{chunk-EUX2P2E7.mjs → chunk-AFNWX62Q.mjs} +11 -9
  20. package/dist/chunk-AFNWX62Q.mjs.map +1 -0
  21. package/dist/{chunk-MQYWH4E6.mjs → chunk-BUSWSDYO.mjs} +2 -2
  22. package/dist/chunk-CDUIA2WM.mjs +60 -0
  23. package/dist/chunk-CDUIA2WM.mjs.map +1 -0
  24. package/dist/chunk-CYDWEPFL.mjs +1 -0
  25. package/dist/{chunk-ZLQVRPDS.mjs → chunk-DMLQZG75.mjs} +1 -1
  26. package/dist/chunk-DMLQZG75.mjs.map +1 -0
  27. package/dist/{chunk-U7QULEVO.mjs → chunk-E7SE25ZU.mjs} +3 -3
  28. package/dist/chunk-F555TVE4.mjs +33 -0
  29. package/dist/chunk-F555TVE4.mjs.map +1 -0
  30. package/dist/chunk-FD6FGKYY.mjs +1 -0
  31. package/dist/chunk-FDOMAPJY.mjs +59 -0
  32. package/dist/chunk-FDOMAPJY.mjs.map +1 -0
  33. package/dist/{chunk-OAGAFMUM.mjs → chunk-FQFXYAV7.mjs} +6 -5
  34. package/dist/{chunk-OAGAFMUM.mjs.map → chunk-FQFXYAV7.mjs.map} +1 -1
  35. package/dist/chunk-GPEJNVE5.mjs +80 -0
  36. package/dist/chunk-GPEJNVE5.mjs.map +1 -0
  37. package/dist/{chunk-C6IANC2R.mjs → chunk-HE22TZMF.mjs} +7 -43
  38. package/dist/chunk-HE22TZMF.mjs.map +1 -0
  39. package/dist/chunk-I76HKHPJ.mjs +32 -0
  40. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  41. package/dist/chunk-JD7BAH7U.mjs +1 -0
  42. package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
  43. package/dist/chunk-LSHFN2Y5.mjs +349 -0
  44. package/dist/chunk-LSHFN2Y5.mjs.map +1 -0
  45. package/dist/chunk-NB2FKV2V.mjs +1 -0
  46. package/dist/chunk-NBK4KBLX.mjs +54 -0
  47. package/dist/chunk-NBK4KBLX.mjs.map +1 -0
  48. package/dist/chunk-QNUAXSDP.mjs +166 -0
  49. package/dist/chunk-QNUAXSDP.mjs.map +1 -0
  50. package/dist/chunk-SPCZTZCY.mjs +1 -0
  51. package/dist/chunk-SPCZTZCY.mjs.map +1 -0
  52. package/dist/chunk-VV56AVPB.mjs +125 -0
  53. package/dist/chunk-VV56AVPB.mjs.map +1 -0
  54. package/dist/chunk-WF65O6HX.mjs +66 -0
  55. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  56. package/dist/chunk-XDFVCQD3.mjs +27 -0
  57. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  58. package/dist/{chunk-OKCYPO4I.mjs → chunk-YCG6SNAU.mjs} +3 -3
  59. package/dist/{chunk-GT5WI3AF.mjs → chunk-YTQHRJUA.mjs} +7 -9
  60. package/dist/chunk-YTQHRJUA.mjs.map +1 -0
  61. package/dist/{chunk-5FHSUKQL.mjs → chunk-YYN33GSG.mjs} +5 -2
  62. package/dist/chunk-YYN33GSG.mjs.map +1 -0
  63. package/dist/chunk-Z6JV2LRY.mjs +37 -0
  64. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  65. package/dist/chunk-ZVF5Q6IH.mjs +29 -0
  66. package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
  67. package/dist/chunk-ZYTXB6HH.mjs +151 -0
  68. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  69. package/dist/components/CopilotListeners.d.ts +3 -0
  70. package/dist/components/CopilotListeners.js +101 -0
  71. package/dist/components/CopilotListeners.js.map +1 -0
  72. package/dist/components/CopilotListeners.mjs +9 -0
  73. package/dist/components/CopilotListeners.mjs.map +1 -0
  74. package/dist/components/copilot-provider/copilot-messages.js +14 -48
  75. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  76. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  77. package/dist/components/copilot-provider/copilotkit-props.d.ts +15 -2
  78. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  79. package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
  80. package/dist/components/copilot-provider/copilotkit.js +491 -1361
  81. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  82. package/dist/components/copilot-provider/copilotkit.mjs +13 -11
  83. package/dist/components/copilot-provider/index.d.ts +2 -1
  84. package/dist/components/copilot-provider/index.js +491 -1361
  85. package/dist/components/copilot-provider/index.js.map +1 -1
  86. package/dist/components/copilot-provider/index.mjs +14 -11
  87. package/dist/components/dev-console/console-trigger.js +10 -8
  88. package/dist/components/dev-console/console-trigger.js.map +1 -1
  89. package/dist/components/dev-console/console-trigger.mjs +226 -6
  90. package/dist/components/dev-console/console-trigger.mjs.map +1 -1
  91. package/dist/components/dev-console/developer-console-modal.js +10 -8
  92. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  93. package/dist/components/dev-console/developer-console-modal.mjs +3 -3
  94. package/dist/components/error-boundary/error-boundary.d.ts +7 -7
  95. package/dist/components/error-boundary/error-boundary.js +3 -3
  96. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  97. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  98. package/dist/components/error-boundary/error-utils.d.ts +1 -1
  99. package/dist/components/error-boundary/error-utils.js +3 -3
  100. package/dist/components/error-boundary/error-utils.js.map +1 -1
  101. package/dist/components/error-boundary/error-utils.mjs +1 -1
  102. package/dist/components/index.d.ts +2 -1
  103. package/dist/components/index.js +491 -1361
  104. package/dist/components/index.js.map +1 -1
  105. package/dist/components/index.mjs +15 -11
  106. package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
  107. package/dist/components/toast/toast-provider.d.ts +3 -3
  108. package/dist/components/usage-banner.d.ts +2 -2
  109. package/dist/context/coagent-state-renders-context.d.ts +24 -0
  110. package/dist/context/coagent-state-renders-context.js +91 -0
  111. package/dist/context/coagent-state-renders-context.js.map +1 -0
  112. package/dist/context/coagent-state-renders-context.mjs +12 -0
  113. package/dist/context/coagent-state-renders-context.mjs.map +1 -0
  114. package/dist/context/copilot-context.d.ts +1 -1
  115. package/dist/context/copilot-context.js +10 -8
  116. package/dist/context/copilot-context.js.map +1 -1
  117. package/dist/context/copilot-context.mjs +1 -1
  118. package/dist/context/copilot-messages-context.d.ts +18 -11
  119. package/dist/context/copilot-messages-context.js.map +1 -1
  120. package/dist/context/copilot-messages-context.mjs +1 -1
  121. package/dist/context/index.d.ts +6 -2
  122. package/dist/context/index.js +110 -10
  123. package/dist/context/index.js.map +1 -1
  124. package/dist/context/index.mjs +20 -4
  125. package/dist/context/threads-context.d.ts +16 -0
  126. package/dist/context/threads-context.js +59 -0
  127. package/dist/context/threads-context.js.map +1 -0
  128. package/dist/context/threads-context.mjs +12 -0
  129. package/dist/context/threads-context.mjs.map +1 -0
  130. package/dist/{copilot-context-cf9de848.d.ts → copilot-context-ec77e921.d.ts} +36 -32
  131. package/dist/hooks/index.d.ts +9 -6
  132. package/dist/hooks/index.js +1109 -1841
  133. package/dist/hooks/index.js.map +1 -1
  134. package/dist/hooks/index.mjs +50 -58
  135. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  136. package/dist/hooks/use-agent-nodename.js +56 -0
  137. package/dist/hooks/use-agent-nodename.js.map +1 -0
  138. package/dist/hooks/use-agent-nodename.mjs +8 -0
  139. package/dist/hooks/use-agent-nodename.mjs.map +1 -0
  140. package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
  141. package/dist/hooks/use-coagent-state-render-bridge.js +214 -0
  142. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
  143. package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
  144. package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
  145. package/dist/hooks/use-coagent-state-render.js +31 -20
  146. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  147. package/dist/hooks/use-coagent-state-render.mjs +3 -2
  148. package/dist/hooks/use-coagent.d.ts +2 -14
  149. package/dist/hooks/use-coagent.js +138 -1898
  150. package/dist/hooks/use-coagent.js.map +1 -1
  151. package/dist/hooks/use-coagent.mjs +2 -30
  152. package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
  153. package/dist/hooks/use-configure-chat-suggestions.js +79 -0
  154. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
  155. package/dist/hooks/use-configure-chat-suggestions.mjs +47 -0
  156. package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
  157. package/dist/hooks/use-copilot-action.d.ts +8 -45
  158. package/dist/hooks/use-copilot-action.js +219 -349
  159. package/dist/hooks/use-copilot-action.js.map +1 -1
  160. package/dist/hooks/use-copilot-action.mjs +4 -5
  161. package/dist/hooks/use-copilot-additional-instructions.js +10 -8
  162. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  163. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  164. package/dist/hooks/use-copilot-authenticated-action.js +236 -248
  165. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  166. package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
  167. package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -10
  168. package/dist/hooks/use-copilot-chat-headless_c.js +585 -1374
  169. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  170. package/dist/hooks/use-copilot-chat-headless_c.mjs +12 -22
  171. package/dist/hooks/use-copilot-chat-suggestions.d.ts +35 -0
  172. package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
  173. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  174. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  175. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
  176. package/dist/hooks/use-copilot-chat.d.ts +2 -10
  177. package/dist/hooks/use-copilot-chat.js +579 -1393
  178. package/dist/hooks/use-copilot-chat.js.map +1 -1
  179. package/dist/hooks/use-copilot-chat.mjs +12 -22
  180. package/dist/hooks/use-copilot-chat_internal.d.ts +77 -14
  181. package/dist/hooks/use-copilot-chat_internal.js +577 -1367
  182. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  183. package/dist/hooks/use-copilot-chat_internal.mjs +13 -23
  184. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  185. package/dist/hooks/use-copilot-readable.js +25 -152
  186. package/dist/hooks/use-copilot-readable.js.map +1 -1
  187. package/dist/hooks/use-copilot-readable.mjs +1 -2
  188. package/dist/hooks/use-default-tool.js +216 -349
  189. package/dist/hooks/use-default-tool.js.map +1 -1
  190. package/dist/hooks/use-default-tool.mjs +5 -6
  191. package/dist/hooks/use-flat-category-store.js +4 -1
  192. package/dist/hooks/use-flat-category-store.js.map +1 -1
  193. package/dist/hooks/use-flat-category-store.mjs +1 -1
  194. package/dist/hooks/use-frontend-tool.d.ts +3 -3
  195. package/dist/hooks/use-frontend-tool.js +42 -370
  196. package/dist/hooks/use-frontend-tool.js.map +1 -1
  197. package/dist/hooks/use-frontend-tool.mjs +1 -6
  198. package/dist/hooks/use-human-in-the-loop.d.ts +4 -3
  199. package/dist/hooks/use-human-in-the-loop.js +61 -393
  200. package/dist/hooks/use-human-in-the-loop.js.map +1 -1
  201. package/dist/hooks/use-human-in-the-loop.mjs +1 -6
  202. package/dist/hooks/use-langgraph-interrupt-render.d.ts +3 -2
  203. package/dist/hooks/use-langgraph-interrupt-render.js +157 -37
  204. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  205. package/dist/hooks/use-langgraph-interrupt-render.mjs +7 -4
  206. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  207. package/dist/hooks/use-langgraph-interrupt.js +24 -1642
  208. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  209. package/dist/hooks/use-langgraph-interrupt.mjs +2 -23
  210. package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
  211. package/dist/hooks/use-lazy-tool-renderer.js +53 -0
  212. package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
  213. package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
  214. package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
  215. package/dist/hooks/use-make-copilot-document-readable.js +11 -9
  216. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  217. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  218. package/dist/hooks/use-render-tool-call.d.ts +7 -6
  219. package/dist/hooks/use-render-tool-call.js +36 -386
  220. package/dist/hooks/use-render-tool-call.js.map +1 -1
  221. package/dist/hooks/use-render-tool-call.mjs +1 -6
  222. package/dist/index.d.ts +11 -6
  223. package/dist/index.js +1456 -3033
  224. package/dist/index.js.map +1 -1
  225. package/dist/index.mjs +79 -62
  226. package/dist/lib/copilot-task.d.ts +2 -2
  227. package/dist/lib/copilot-task.js +1 -0
  228. package/dist/lib/copilot-task.js.map +1 -1
  229. package/dist/lib/copilot-task.mjs +16 -12
  230. package/dist/lib/index.d.ts +1 -1
  231. package/dist/lib/index.js +1 -0
  232. package/dist/lib/index.js.map +1 -1
  233. package/dist/lib/index.mjs +16 -12
  234. package/dist/setupTests.d.ts +2 -2
  235. package/dist/types/frontend-action.d.ts +5 -5
  236. package/dist/types/index.d.ts +4 -0
  237. package/dist/types/index.js.map +1 -1
  238. package/dist/types/index.mjs +2 -1
  239. package/dist/types/interrupt-action.d.ts +1 -1
  240. package/dist/types/interrupt-action.js.map +1 -1
  241. package/dist/types/interrupt-action.mjs +1 -0
  242. package/dist/utils/index.d.ts +0 -12
  243. package/dist/utils/index.js +6 -325
  244. package/dist/utils/index.js.map +1 -1
  245. package/dist/utils/index.mjs +1 -21
  246. package/dist/utils/utils.js.map +1 -1
  247. package/dist/v2/index.css +4 -0
  248. package/dist/v2/index.css.map +1 -0
  249. package/dist/v2/index.d.ts +2 -0
  250. package/dist/v2/index.js +27 -0
  251. package/dist/v2/index.js.map +1 -0
  252. package/dist/v2/index.mjs +6 -0
  253. package/dist/v2/index.mjs.map +1 -0
  254. package/jest.config.js +12 -0
  255. package/package.json +24 -10
  256. package/src/components/CopilotListeners.tsx +81 -0
  257. package/src/components/copilot-provider/copilot-messages.tsx +6 -48
  258. package/src/components/copilot-provider/copilotkit-props.tsx +15 -1
  259. package/src/components/copilot-provider/copilotkit.tsx +189 -148
  260. package/src/components/error-boundary/error-utils.tsx +3 -3
  261. package/src/context/coagent-state-renders-context.tsx +76 -0
  262. package/src/context/copilot-context.tsx +21 -21
  263. package/src/context/copilot-messages-context.tsx +3 -3
  264. package/src/context/index.ts +8 -0
  265. package/src/context/threads-context.tsx +41 -0
  266. package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
  267. package/src/hooks/index.ts +12 -3
  268. package/src/hooks/use-agent-nodename.ts +30 -0
  269. package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
  270. package/src/hooks/use-coagent-state-render.ts +4 -7
  271. package/src/hooks/use-coagent.ts +136 -247
  272. package/src/hooks/use-configure-chat-suggestions.tsx +86 -0
  273. package/src/hooks/use-copilot-action.ts +88 -199
  274. package/src/hooks/use-copilot-chat-headless_c.ts +2 -1
  275. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  276. package/src/hooks/use-copilot-chat.ts +4 -1
  277. package/src/hooks/use-copilot-chat_internal.ts +410 -263
  278. package/src/hooks/use-copilot-readable.ts +23 -25
  279. package/src/hooks/use-flat-category-store.ts +4 -3
  280. package/src/hooks/use-frontend-tool.ts +86 -8
  281. package/src/hooks/use-human-in-the-loop.ts +111 -13
  282. package/src/hooks/use-langgraph-interrupt-render.ts +108 -40
  283. package/src/hooks/use-langgraph-interrupt.ts +18 -48
  284. package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
  285. package/src/hooks/use-make-copilot-document-readable.ts +1 -1
  286. package/src/hooks/use-render-tool-call.ts +73 -13
  287. package/src/lib/copilot-task.ts +1 -1
  288. package/src/types/index.ts +1 -0
  289. package/src/types/interrupt-action.ts +8 -7
  290. package/src/utils/index.ts +0 -3
  291. package/src/utils/utils.ts +7 -0
  292. package/src/v2/index.css +1 -0
  293. package/src/v2/index.ts +4 -0
  294. package/tsup.config.ts +1 -1
  295. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  296. package/dist/chunk-6GPVUMBU.mjs +0 -13
  297. package/dist/chunk-6GPVUMBU.mjs.map +0 -1
  298. package/dist/chunk-AKR2SSUJ.mjs +0 -22
  299. package/dist/chunk-AKR2SSUJ.mjs.map +0 -1
  300. package/dist/chunk-BXXJQ2BL.mjs +0 -239
  301. package/dist/chunk-BXXJQ2BL.mjs.map +0 -1
  302. package/dist/chunk-C6IANC2R.mjs.map +0 -1
  303. package/dist/chunk-DXEQPN43.mjs +0 -231
  304. package/dist/chunk-DXEQPN43.mjs.map +0 -1
  305. package/dist/chunk-DZTU6PGS.mjs +0 -1
  306. package/dist/chunk-EDBI5PCJ.mjs.map +0 -1
  307. package/dist/chunk-EUX2P2E7.mjs.map +0 -1
  308. package/dist/chunk-EVVO67QO.mjs +0 -25
  309. package/dist/chunk-EVVO67QO.mjs.map +0 -1
  310. package/dist/chunk-GGLAHG3I.mjs +0 -804
  311. package/dist/chunk-GGLAHG3I.mjs.map +0 -1
  312. package/dist/chunk-GT5WI3AF.mjs.map +0 -1
  313. package/dist/chunk-HDOG2RTM.mjs +0 -37
  314. package/dist/chunk-HDOG2RTM.mjs.map +0 -1
  315. package/dist/chunk-MIXSWZSB.mjs +0 -71
  316. package/dist/chunk-MIXSWZSB.mjs.map +0 -1
  317. package/dist/chunk-N4WEHORG.mjs.map +0 -1
  318. package/dist/chunk-NSBAWITG.mjs +0 -332
  319. package/dist/chunk-NSBAWITG.mjs.map +0 -1
  320. package/dist/chunk-OT5NHMEC.mjs +0 -723
  321. package/dist/chunk-OT5NHMEC.mjs.map +0 -1
  322. package/dist/chunk-T3376SZS.mjs +0 -142
  323. package/dist/chunk-T3376SZS.mjs.map +0 -1
  324. package/dist/chunk-YPBKY4KY.mjs +0 -1
  325. package/dist/chunk-YPSGKPDA.mjs +0 -1
  326. package/dist/chunk-ZLQVRPDS.mjs.map +0 -1
  327. package/dist/chunk-ZVOLWJCY.mjs +0 -47
  328. package/dist/chunk-ZVOLWJCY.mjs.map +0 -1
  329. package/dist/hooks/use-chat.d.ts +0 -145
  330. package/dist/hooks/use-chat.js +0 -1129
  331. package/dist/hooks/use-chat.js.map +0 -1
  332. package/dist/hooks/use-chat.mjs +0 -14
  333. package/dist/index-1f5b66ac.d.ts +0 -36
  334. package/dist/utils/extract.d.ts +0 -43
  335. package/dist/utils/extract.js +0 -208
  336. package/dist/utils/extract.js.map +0 -1
  337. package/dist/utils/extract.mjs +0 -25
  338. package/dist/utils/suggestions.d.ts +0 -11
  339. package/dist/utils/suggestions.js +0 -343
  340. package/dist/utils/suggestions.js.map +0 -1
  341. package/dist/utils/suggestions.mjs +0 -25
  342. package/src/hooks/use-chat.ts +0 -1142
  343. package/src/utils/extract.ts +0 -215
  344. package/src/utils/suggestions.ts +0 -208
  345. /package/dist/{chunk-DZTU6PGS.mjs.map → chunk-36KQV2NA.mjs.map} +0 -0
  346. /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-A6NKSGH3.mjs.map} +0 -0
  347. /package/dist/{chunk-MGWRDFBE.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
  348. /package/dist/{chunk-MQYWH4E6.mjs.map → chunk-BUSWSDYO.mjs.map} +0 -0
  349. /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
  350. /package/dist/{chunk-U7QULEVO.mjs.map → chunk-E7SE25ZU.mjs.map} +0 -0
  351. /package/dist/{hooks/use-chat.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
  352. /package/dist/{utils/extract.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
  353. /package/dist/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
  354. /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
  355. /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-chat_internal.ts"],"sourcesContent":["import { useRef, useEffect, useCallback, useMemo, useState, createElement } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport { Message } from \"@copilotkit/shared\";\nimport { gqlToAGUI, Message as DeprecatedGqlMessage } from \"@copilotkit/runtime-client-gql\";\nimport { useLangGraphInterruptRender } from \"./use-langgraph-interrupt-render\";\nimport {\n useAgent,\n useCopilotChatConfiguration,\n useCopilotKit,\n useRenderCustomMessages,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\nimport { useLazyToolRenderer } from \"./use-lazy-tool-renderer\";\nimport { AbstractAgent, AGUIConnectNotImplementedError } from \"@ag-ui/client\";\nimport {\n CoAgentStateRenderBridge,\n type CoAgentStateRenderBridgeProps,\n} from \"./use-coagent-state-render-bridge\";\n\n/**\n * The type of suggestions to use in the chat.\n *\n * `auto` - Suggestions are generated automatically.\n * `manual` - Suggestions are controlled programmatically.\n * `SuggestionItem[]` - Static suggestions array.\n */\nexport type ChatSuggestions = \"auto\" | \"manual\" | Omit<Suggestion, \"isLoading\">[];\n\nexport interface AppendMessageOptions {\n /**\n * Whether to run the chat completion after appending the message. Defaults to `true`.\n */\n followUp?: boolean;\n /**\n * Whether to clear the suggestions after appending the message. Defaults to `true`.\n */\n clearSuggestions?: boolean;\n}\n\nexport interface OnStopGenerationArguments {\n /**\n * The name of the currently executing agent.\n */\n currentAgentName: string | undefined;\n\n /**\n * The messages in the chat.\n */\n messages: Message[];\n}\n\nexport type OnReloadMessagesArguments = OnStopGenerationArguments & {\n /**\n * The message on which \"regenerate\" was pressed\n */\n messageId: string;\n};\n\nexport type OnStopGeneration = (args: OnStopGenerationArguments) => void;\n\nexport type OnReloadMessages = (args: OnReloadMessagesArguments) => void;\n\nexport interface UseCopilotChatOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the `useChat` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * Initial messages to populate the chat with.\n */\n initialMessages?: Message[];\n\n /**\n * A function to generate the system message. Defaults to `defaultSystemMessage`.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).\n */\n disableSystemMessage?: boolean;\n /**\n * Controls the behavior of suggestions in the chat interface.\n *\n * `auto` (default) - Suggestions are generated automatically:\n * - When the chat is first opened (empty state)\n * - After each message exchange completes\n * - Uses configuration from `useCopilotChatSuggestions` hooks\n *\n * `manual` - Suggestions are controlled programmatically:\n * - Use `setSuggestions()` to set custom suggestions\n * - Use `generateSuggestions()` to trigger AI generation\n * - Access via `useCopilotChat` hook\n *\n * `SuggestionItem[]` - Static suggestions array:\n * - Always shows the same suggestions\n * - No AI generation involved\n */\n suggestions?: ChatSuggestions;\n\n onInProgress?: (isLoading: boolean) => void;\n onSubmitMessage?: (messageContent: string) => Promise<void> | void;\n onStopGeneration?: OnStopGeneration;\n onReloadMessages?: OnReloadMessages;\n}\n\nexport interface MCPServerConfig {\n endpoint: string;\n apiKey?: string;\n}\n\n// Old suggestion item interface, for returning from useCopilotChatInternal\ninterface SuggestionItem {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n}\n\nexport interface UseCopilotChatReturn {\n /**\n * @deprecated use `messages` instead, this is an old non ag-ui version of the messages\n * Array of messages currently visible in the chat interface\n *\n * This is the visible messages, not the raw messages from the runtime client.\n */\n visibleMessages: DeprecatedGqlMessage[];\n\n /**\n * The messages that are currently in the chat in AG-UI format.\n */\n messages: Message[];\n\n /** @deprecated use `sendMessage` in `useCopilotChatHeadless_c` instead. This will be removed in a future major version. */\n appendMessage: (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Send a new message to the chat\n *\n * ```tsx\n * await sendMessage({\n * id: \"123\",\n * role: \"user\",\n * content: \"Hello, process this request\",\n * });\n * ```\n */\n sendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Replace all messages in the chat\n *\n * ```tsx\n * setMessages([\n * { id: \"123\", role: \"user\", content: \"Hello, process this request\" },\n * { id: \"456\", role: \"assistant\", content: \"Hello, I'm the assistant\" },\n * ]);\n * ```\n *\n * **Deprecated** non-ag-ui version:\n *\n * ```tsx\n * setMessages([\n * new TextMessage({\n * content: \"Hello, process this request\",\n * role: gqlRole.User,\n * }),\n * new TextMessage({\n * content: \"Hello, I'm the assistant\",\n * role: gqlRole.Assistant,\n * ]);\n * ```\n *\n */\n setMessages: (messages: Message[] | DeprecatedGqlMessage[]) => void;\n\n /**\n * Remove a specific message by ID\n *\n * ```tsx\n * deleteMessage(\"123\");\n * ```\n */\n deleteMessage: (messageId: string) => void;\n\n /**\n * Regenerate the response for a specific message\n *\n * ```tsx\n * reloadMessages(\"123\");\n * ```\n */\n reloadMessages: (messageId: string) => Promise<void>;\n\n /**\n * Stop the current message generation\n *\n * ```tsx\n * if (isLoading) {\n * stopGeneration();\n * }\n * ```\n */\n stopGeneration: () => void;\n\n /**\n * Clear all messages and reset chat state\n *\n * ```tsx\n * reset();\n * console.log(messages); // []\n * ```\n */\n reset: () => void;\n\n /**\n * Whether the chat is currently generating a response\n *\n * ```tsx\n * if (isLoading) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isLoading: boolean;\n\n /**\n * Whether the chat agent is available to generate responses\n *\n * ```tsx\n * if (isAvailable) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isAvailable: boolean;\n\n /** Manually trigger chat completion (advanced usage) */\n runChatCompletion: () => Promise<Message[]>;\n\n /** MCP (Model Context Protocol) server configurations */\n mcpServers: MCPServerConfig[];\n\n /** Update MCP server configurations */\n setMcpServers: (mcpServers: MCPServerConfig[]) => void;\n\n /**\n * Current suggestions array\n * Use this to read the current suggestions or in conjunction with setSuggestions for manual control\n */\n suggestions: Suggestion[];\n\n /**\n * Manually set suggestions\n * Useful for manual mode or custom suggestion workflows\n */\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) => void;\n\n /**\n * Trigger AI-powered suggestion generation\n * Uses configurations from useCopilotChatSuggestions hooks\n * Respects global debouncing - only one generation can run at a time\n *\n * ```tsx\n * generateSuggestions();\n * console.log(suggestions); // [suggestion1, suggestion2, suggestion3]\n * ```\n */\n generateSuggestions: () => Promise<void>;\n\n /**\n * Clear all current suggestions\n * Also resets suggestion generation state\n */\n resetSuggestions: () => void;\n\n /** Whether suggestions are currently being generated */\n isLoadingSuggestions: boolean;\n\n /** Interrupt content for human-in-the-loop workflows */\n interrupt: string | React.ReactElement | null;\n\n agent?: ReturnType<typeof useAgent>[\"agent\"];\n\n threadId?: string;\n}\n\nexport function useCopilotChatInternal({\n suggestions,\n onInProgress,\n onSubmitMessage,\n onStopGeneration,\n onReloadMessages,\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const { copilotkit } = useCopilotKit();\n const { threadId, agentSession } = useCopilotContext();\n const existingConfig = useCopilotChatConfiguration();\n const [agentAvailable, setAgentAvailable] = useState(false);\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const { agent } = useAgent({ agentId: resolvedAgentId });\n\n useEffect(() => {\n const connect = async (agent: AbstractAgent) => {\n setAgentAvailable(false);\n try {\n await copilotkit.connectAgent({ agent });\n setAgentAvailable(true);\n } catch (error) {\n if (error instanceof AGUIConnectNotImplementedError) {\n // connect not implemented, ignore\n } else {\n throw error;\n }\n }\n };\n if (agent && existingConfig?.threadId && agent.threadId !== existingConfig.threadId) {\n agent.threadId = existingConfig.threadId;\n connect(agent);\n }\n return () => {};\n }, [existingConfig?.threadId, agent, copilotkit, resolvedAgentId]);\n\n useEffect(() => {\n onInProgress?.(Boolean(agent?.isRunning));\n }, [agent?.isRunning, onInProgress]);\n\n const interrupt = useLangGraphInterruptRender(agent);\n\n const reset = () => {\n agent?.setMessages([]);\n agent?.setState(null);\n };\n\n const deleteMessage = useCallback(\n (messageId: string) => {\n const filteredMessages = (agent?.messages ?? []).filter(\n (message) => message.id !== messageId,\n );\n agent?.setMessages(filteredMessages);\n },\n [agent?.setMessages, agent?.messages],\n );\n\n const latestDelete = useUpdatedRef(deleteMessage);\n const latestDeleteFunc = useCallback(\n (messageId: string) => {\n return latestDelete.current(messageId);\n },\n [latestDelete],\n );\n\n const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });\n\n const reload = useAsyncCallback(\n async (reloadMessageId: string): Promise<void> => {\n const messages = agent?.messages ?? [];\n // TODO: get isLoading\n const isLoading = false;\n if (isLoading || messages.length === 0) {\n return;\n }\n\n const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);\n if (reloadMessageIndex === -1) {\n console.warn(`Message with id ${reloadMessageId} not found`);\n return;\n }\n\n const reloadMessageRole = messages[reloadMessageIndex].role;\n if (reloadMessageRole !== \"assistant\") {\n console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);\n return;\n }\n let historyCutoff: Message[] = [messages[0]];\n\n if (messages.length > 2 && reloadMessageIndex !== 0) {\n // message to regenerate from is now first.\n // Work backwards to find the first the closest user message\n const lastUserMessageBeforeRegenerate = messages\n .slice(0, reloadMessageIndex)\n .reverse()\n .find((msg) => msg.role === \"user\");\n\n if (!lastUserMessageBeforeRegenerate) {\n historyCutoff = [messages[0]];\n } else {\n const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(\n (msg) => msg.id === lastUserMessageBeforeRegenerate.id,\n );\n // Include the user message, remove everything after it\n historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);\n }\n } else if (messages.length > 2 && reloadMessageIndex === 0) {\n historyCutoff = [messages[0], messages[1]];\n }\n\n agent?.setMessages(historyCutoff);\n\n if (agent) {\n copilotkit.runAgent({ agent });\n }\n return;\n },\n [agent?.setMessages, copilotkit?.runAgent],\n );\n\n const latestSendMessageFunc = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions) => {\n if (!agent) return;\n const followUp = options?.followUp ?? true;\n if (options?.clearSuggestions) {\n copilotkit.clearSuggestions(resolvedAgentId);\n }\n agent?.addMessage(message);\n if (followUp) {\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n }\n if (onSubmitMessage) {\n const content =\n typeof message.content === \"string\"\n ? message.content\n : message.content && \"text\" in message.content\n ? message.content.text\n : message.content && \"filename\" in message.content\n ? message.content.filename\n : \"\";\n onSubmitMessage(content);\n }\n },\n [agent, copilotkit, resolvedAgentId, onSubmitMessage],\n );\n\n const latestAppendFunc = useAsyncCallback(\n async (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => {\n return latestSendMessageFunc(gqlToAGUI([message])[0], options);\n },\n [latestSendMessageFunc],\n );\n\n const latestSetMessagesFunc = useCallback(\n (messages: Message[] | DeprecatedGqlMessage[]) => {\n if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {\n return agent?.setMessages?.(gqlToAGUI(messages));\n }\n return agent?.setMessages?.(messages);\n },\n [agent?.setMessages, agent],\n );\n\n const latestReload = useUpdatedRef(reload);\n const latestReloadFunc = useAsyncCallback(\n async (messageId: string) => {\n onReloadMessages?.({\n messageId,\n currentAgentName: agent?.agentId,\n messages: agent?.messages ?? [],\n });\n return await latestReload.current(messageId);\n },\n [latestReload, agent, onReloadMessages],\n );\n\n const latestStopFunc = useCallback(() => {\n onStopGeneration?.({\n currentAgentName: agent?.agentId,\n messages: agent?.messages ?? [],\n });\n return agent?.abortRun?.();\n }, [onStopGeneration, agent]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n const lazyToolRendered = useLazyToolRenderer();\n const renderCustomMessage = useRenderCustomMessages();\n const legacyCustomMessageRenderer = useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId: resolvedAgentId,\n threadId: existingConfig?.threadId ?? threadId,\n });\n const allMessages = agent?.messages ?? [];\n const resolvedMessages = useMemo(() => {\n let processedMessages = allMessages.map((message) => {\n if (message.role !== \"assistant\") {\n return message;\n }\n\n const lazyRendered = lazyToolRendered(message, allMessages);\n if (lazyRendered) {\n const renderedGenUi = lazyRendered();\n if (renderedGenUi) {\n return { ...message, generativeUI: () => renderedGenUi };\n }\n }\n\n const bridgeRenderer =\n legacyCustomMessageRenderer || renderCustomMessage\n ? () => {\n const customRender = renderCustomMessage?.({\n message,\n position: \"before\",\n });\n if (customRender) {\n return customRender;\n }\n return legacyCustomMessageRenderer?.({ message, position: \"before\" });\n }\n : null;\n\n if (bridgeRenderer) {\n return { ...message, generativeUI: bridgeRenderer };\n }\n return message;\n });\n\n const hasAssistantMessages = processedMessages.some((msg) => msg.role === \"assistant\");\n\n // TODO: what is this?\n // if (legacyCustomMessageRenderer && !hasAssistantMessages) {\n // const placeholderId = `coagent-state-render-${resolvedAgentId}`;\n // const placeholderMessage: Message = {\n // id: placeholderId,\n // role: \"assistant\",\n // content: \"\",\n // name: \"coagent-state-render\",\n // };\n // processedMessages = [\n // ...processedMessages,\n // {\n // ...placeholderMessage,\n // generativeUI: () =>\n // legacyCustomMessageRenderer({\n // message: placeholderMessage,\n // position: \"before\",\n // }),\n // } as Message,\n // ];\n // }\n\n return processedMessages;\n }, [\n agent?.messages,\n lazyToolRendered,\n allMessages,\n renderCustomMessage,\n // legacyCustomMessageRenderer,\n resolvedAgentId,\n ]);\n\n const renderedSuggestions = useMemo(() => {\n if (Array.isArray(suggestions)) {\n return {\n suggestions: suggestions.map((s) => ({ ...s, isLoading: false })),\n isLoading: false,\n };\n }\n return currentSuggestions;\n }, [suggestions, currentSuggestions]);\n\n // @ts-ignore\n return {\n messages: resolvedMessages,\n sendMessage: latestSendMessageFunc,\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n isAvailable: agentAvailable,\n isLoading: Boolean(agent?.isRunning),\n // mcpServers,\n // setMcpServers,\n suggestions: renderedSuggestions.suggestions,\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) =>\n copilotkit.addSuggestionsConfig({ suggestions }),\n generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),\n resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),\n isLoadingSuggestions: renderedSuggestions.isLoading,\n interrupt,\n agent,\n threadId,\n };\n}\n\n// store `value` in a ref and update\n// it whenever it changes.\nfunction useUpdatedRef<T>(value: T) {\n const ref = useRef(value);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n\ntype LegacyRenderParams = {\n message: Message;\n position: \"before\" | \"after\";\n};\n\ntype LegacyRenderer = ((args: LegacyRenderParams) => any) | null;\n\nfunction useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId,\n threadId,\n}: {\n copilotkit: ReturnType<typeof useCopilotKit>[\"copilotkit\"];\n agent?: AbstractAgent;\n agentId: string;\n threadId?: string;\n}): LegacyRenderer {\n return useMemo(() => {\n if (!copilotkit || !agent) {\n return null;\n }\n\n return ({ message, position }: LegacyRenderParams) => {\n const effectiveThreadId = threadId ?? agent.threadId ?? \"default\";\n const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);\n const runId = existingRunId || `pending:${message.id}`;\n const messageIndex = Math.max(\n agent.messages.findIndex((msg) => msg.id === message.id),\n 0,\n );\n\n const bridgeProps: CoAgentStateRenderBridgeProps = {\n message: message as any,\n position,\n runId,\n messageIndex,\n messageIndexInRun: 0,\n numberOfMessagesInRun: 1,\n agentId,\n stateSnapshot: (message as any).state,\n };\n\n return createElement(CoAgentStateRenderBridge, bridgeProps) as any;\n };\n }, [agent, agentId, copilotkit, threadId]);\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\nIn case of a function error:\n- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.\n- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.\n` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,QAAQ,WAAW,aAAa,SAAS,UAAU,qBAAqB;AAKjF,SAAS,WAAW,WAAW,4BAA4B;AAE3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAwB,sCAAsC;AA4RvD,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAA2B,CAAC,GAAyB;AAlTrD;AAmTE,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,EAAE,UAAU,aAAa,IAAI,kBAAkB;AACrD,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,KAAK;AAG1D,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AACnD,QAAM,EAAE,MAAM,IAAI,SAAS,EAAE,SAAS,gBAAgB,CAAC;AAEvD,YAAU,MAAM;AACd,UAAM,UAAU,CAAOA,WAAyB;AAC9C,wBAAkB,KAAK;AACvB,UAAI;AACF,cAAM,WAAW,aAAa,EAAE,OAAAA,OAAM,CAAC;AACvC,0BAAkB,IAAI;AAAA,MACxB,SAAS,OAAP;AACA,YAAI,iBAAiB,gCAAgC;AAAA,QAErD,OAAO;AACL,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,QAAI,UAAS,iDAAgB,aAAY,MAAM,aAAa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,QAAQ,iBAAiB,WAAW,QAAQ;AAClD,YAAM,eAAe,KAAK;AAAA,QACxB,MAAM,SAAS,UAAU,CAAC,QAAQ,IAAI,OAAO,QAAQ,EAAE;AAAA,QACvD;AAAA,MACF;AAEA,YAAM,cAA6C;AAAA,QACjD;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,mBAAmB;AAAA,QACnB,uBAAuB;AAAA,QACvB;AAAA,QACA,eAAgB,QAAgB;AAAA,MAClC;AAEA,aAAO,cAAc,0BAA0B,WAAW;AAAA,IAC5D;AAAA,EACF,GAAG,CAAC,OAAO,SAAS,YAAY,QAAQ,CAAC;AAC3C;AAEO,SAAS,qBACd,eACA,wBACQ;AACR,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAaG,yBAAyB;AAAA;AAAA,EAAO,2BAA2B;AAEhE;","names":["agent","_a","_b","suggestions"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-NB2FKV2V.mjs.map
@@ -0,0 +1,54 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "./chunk-SKC7AJIV.mjs";
5
+
6
+ // src/hooks/use-render-tool-call.ts
7
+ import { getZodParameters } from "@copilotkit/shared";
8
+ import { useEffect, useRef } from "react";
9
+ import { defineToolCallRenderer, useCopilotKit } from "@copilotkitnext/react";
10
+ import { parseJson } from "@copilotkit/shared";
11
+ function useRenderToolCall(tool, dependencies) {
12
+ const { copilotkit } = useCopilotKit();
13
+ const hasAddedRef = useRef(false);
14
+ useEffect(() => {
15
+ const { name, parameters, render } = tool;
16
+ const zodParameters = getZodParameters(parameters);
17
+ const renderToolCall = name === "*" ? defineToolCallRenderer({
18
+ name: "*",
19
+ render: (args) => {
20
+ return render(__spreadProps(__spreadValues({}, args), {
21
+ result: args.result ? parseJson(args.result, args.result) : args.result
22
+ }));
23
+ }
24
+ }) : defineToolCallRenderer({
25
+ name,
26
+ args: zodParameters,
27
+ render: (args) => {
28
+ return render(__spreadProps(__spreadValues({}, args), {
29
+ result: args.result ? parseJson(args.result, args.result) : args.result
30
+ }));
31
+ }
32
+ });
33
+ const existingIndex = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
34
+ if (existingIndex !== -1) {
35
+ copilotkit.renderToolCalls.splice(existingIndex, 1);
36
+ }
37
+ copilotkit.renderToolCalls.push(renderToolCall);
38
+ hasAddedRef.current = true;
39
+ return () => {
40
+ if (hasAddedRef.current) {
41
+ const index = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
42
+ if (index !== -1) {
43
+ copilotkit.renderToolCalls.splice(index, 1);
44
+ }
45
+ hasAddedRef.current = false;
46
+ }
47
+ };
48
+ }, [tool, ...dependencies != null ? dependencies : []]);
49
+ }
50
+
51
+ export {
52
+ useRenderToolCall
53
+ };
54
+ //# sourceMappingURL=chunk-NBK4KBLX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-render-tool-call.ts"],"sourcesContent":["import {\n ActionRenderProps,\n ActionRenderPropsNoArgs,\n ActionRenderPropsWait,\n FrontendAction,\n} from \"../types\";\nimport { Parameter, getZodParameters } from \"@copilotkit/shared\";\nimport React, { useEffect, useRef } from \"react\";\nimport { defineToolCallRenderer, useCopilotKit } from \"@copilotkitnext/react\";\nimport { parseJson } from \"@copilotkit/shared\";\n\ntype ToolCallRendererDefinition = Parameters<typeof defineToolCallRenderer>[0];\n\nexport type UseRenderToolCallArgs<T extends Parameter[] | [] = []> = Pick<\n FrontendAction<T>,\n \"name\" | \"description\" | \"parameters\"\n> & {\n available?: \"disabled\" | \"enabled\";\n render: T extends []\n ? (props: ActionRenderPropsNoArgs<T>) => React.ReactElement\n : (props: ActionRenderProps<T>) => React.ReactElement;\n};\n\nexport function useRenderToolCall<const T extends Parameter[] | [] = []>(\n tool: UseRenderToolCallArgs<T>,\n dependencies?: any[],\n) {\n const { copilotkit } = useCopilotKit();\n\n // Track whether we've already added this renderer to avoid duplicates\n const hasAddedRef = useRef(false);\n\n useEffect(() => {\n const { name, parameters, render } = tool;\n const zodParameters = getZodParameters(parameters);\n\n const renderToolCall =\n name === \"*\"\n ? defineToolCallRenderer({\n name: \"*\",\n render: ((args) => {\n return render({\n ...args,\n result: args.result ? parseJson(args.result, args.result) : args.result,\n });\n }) as ToolCallRendererDefinition[\"render\"],\n })\n : defineToolCallRenderer({\n name,\n args: zodParameters,\n render: ((args) => {\n return render({\n ...args,\n result: args.result ? parseJson(args.result, args.result) : args.result,\n });\n }) as ToolCallRendererDefinition[\"render\"],\n });\n\n // Remove any existing renderer with the same name\n const existingIndex = copilotkit.renderToolCalls.findIndex((r) => r.name === name);\n if (existingIndex !== -1) {\n copilotkit.renderToolCalls.splice(existingIndex, 1);\n }\n\n // Add the new renderer\n copilotkit.renderToolCalls.push(renderToolCall);\n hasAddedRef.current = true;\n\n // Cleanup: remove this renderer when the component unmounts or tool changes\n return () => {\n if (hasAddedRef.current) {\n const index = copilotkit.renderToolCalls.findIndex((r) => r.name === name);\n if (index !== -1) {\n copilotkit.renderToolCalls.splice(index, 1);\n }\n hasAddedRef.current = false;\n }\n };\n }, [tool, ...(dependencies ?? [])]);\n}\n"],"mappings":";;;;;;AAMA,SAAoB,wBAAwB;AAC5C,SAAgB,WAAW,cAAc;AACzC,SAAS,wBAAwB,qBAAqB;AACtD,SAAS,iBAAiB;AAcnB,SAAS,kBACd,MACA,cACA;AACA,QAAM,EAAE,WAAW,IAAI,cAAc;AAGrC,QAAM,cAAc,OAAO,KAAK;AAEhC,YAAU,MAAM;AACd,UAAM,EAAE,MAAM,YAAY,OAAO,IAAI;AACrC,UAAM,gBAAgB,iBAAiB,UAAU;AAEjD,UAAM,iBACJ,SAAS,MACL,uBAAuB;AAAA,MACrB,MAAM;AAAA,MACN,QAAS,CAAC,SAAS;AACjB,eAAO,OAAO,iCACT,OADS;AAAA,UAEZ,QAAQ,KAAK,SAAS,UAAU,KAAK,QAAQ,KAAK,MAAM,IAAI,KAAK;AAAA,QACnE,EAAC;AAAA,MACH;AAAA,IACF,CAAC,IACD,uBAAuB;AAAA,MACrB;AAAA,MACA,MAAM;AAAA,MACN,QAAS,CAAC,SAAS;AACjB,eAAO,OAAO,iCACT,OADS;AAAA,UAEZ,QAAQ,KAAK,SAAS,UAAU,KAAK,QAAQ,KAAK,MAAM,IAAI,KAAK;AAAA,QACnE,EAAC;AAAA,MACH;AAAA,IACF,CAAC;AAGP,UAAM,gBAAgB,WAAW,gBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,IAAI;AACjF,QAAI,kBAAkB,IAAI;AACxB,iBAAW,gBAAgB,OAAO,eAAe,CAAC;AAAA,IACpD;AAGA,eAAW,gBAAgB,KAAK,cAAc;AAC9C,gBAAY,UAAU;AAGtB,WAAO,MAAM;AACX,UAAI,YAAY,SAAS;AACvB,cAAM,QAAQ,WAAW,gBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,IAAI;AACzE,YAAI,UAAU,IAAI;AAChB,qBAAW,gBAAgB,OAAO,OAAO,CAAC;AAAA,QAC5C;AACA,oBAAY,UAAU;AAAA,MACxB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,GAAI,sCAAgB,CAAC,CAAE,CAAC;AACpC;","names":[]}
@@ -0,0 +1,166 @@
1
+ import {
2
+ useCoAgentStateRenders
3
+ } from "./chunk-FDOMAPJY.mjs";
4
+ import {
5
+ __objRest
6
+ } from "./chunk-SKC7AJIV.mjs";
7
+
8
+ // src/hooks/use-coagent-state-render-bridge.tsx
9
+ import { useAgent } from "@copilotkitnext/react";
10
+ import { useCallback, useEffect, useMemo, useState } from "react";
11
+ import { dataToUUID, parseJson } from "@copilotkit/shared";
12
+ function getStateWithoutConstantKeys(state) {
13
+ if (!state)
14
+ return {};
15
+ const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
16
+ return stateWithoutConstantKeys;
17
+ }
18
+ function areStatesEquals(a, b) {
19
+ if (a && !b || !a && b)
20
+ return false;
21
+ const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
22
+ const _b = b, {
23
+ messages: bMessages,
24
+ tools: bTools,
25
+ copilotkit: bCopilotkit
26
+ } = _b, bWithoutConstantKeys = __objRest(_b, [
27
+ "messages",
28
+ "tools",
29
+ "copilotkit"
30
+ ]);
31
+ return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
32
+ }
33
+ function useCoagentStateRenderBridge(agentId, props) {
34
+ var _a;
35
+ const { stateSnapshot, messageIndexInRun, message } = props;
36
+ const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
37
+ const { agent } = useAgent({ agentId });
38
+ const [nodeName, setNodeName] = useState(void 0);
39
+ const runId = (_a = props.runId) != null ? _a : message.runId;
40
+ const effectiveRunId = runId || "pending";
41
+ useEffect(() => {
42
+ if (!agent)
43
+ return;
44
+ const subscriber = {
45
+ onStepStartedEvent: ({ event }) => {
46
+ if (event.stepName !== nodeName) {
47
+ setNodeName(event.stepName);
48
+ }
49
+ },
50
+ onStepFinishedEvent: ({ event }) => {
51
+ if (event.stepName === nodeName) {
52
+ setNodeName(void 0);
53
+ }
54
+ }
55
+ };
56
+ const { unsubscribe } = agent.subscribe(subscriber);
57
+ return () => {
58
+ unsubscribe();
59
+ };
60
+ }, [agentId, nodeName]);
61
+ const getStateRender = useCallback(
62
+ (messageId) => {
63
+ return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
64
+ if (claimsRef.current[messageId]) {
65
+ return stateRenderId === claimsRef.current[messageId].stateRenderId;
66
+ }
67
+ const matchingAgentName = stateRender.name === agentId;
68
+ const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
69
+ return matchingAgentName && matchesNodeContext;
70
+ });
71
+ },
72
+ [coAgentStateRenders, nodeName, agentId]
73
+ );
74
+ const handleRenderRequest = ({
75
+ stateRenderId,
76
+ messageId,
77
+ runId: runId2,
78
+ stateSnapshot: renderSnapshot
79
+ }) => {
80
+ if (claimsRef.current[messageId]) {
81
+ const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
82
+ if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
83
+ claimsRef.current[messageId].runId = runId2;
84
+ }
85
+ return canRender;
86
+ }
87
+ const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
88
+ (c) => c.stateRenderId === stateRenderId && dataToUUID(getStateWithoutConstantKeys(c.stateSnapshot)) === dataToUUID(getStateWithoutConstantKeys(renderSnapshot))
89
+ );
90
+ if (renderClaimedByOtherMessage) {
91
+ if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
92
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+ if (!runId2) {
98
+ return false;
99
+ }
100
+ claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
101
+ return true;
102
+ };
103
+ return useMemo(() => {
104
+ var _a2, _b, _c;
105
+ if (messageIndexInRun !== 0) {
106
+ return null;
107
+ }
108
+ const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
109
+ if (!stateRender || !stateRenderId) {
110
+ return null;
111
+ }
112
+ const snapshot = stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
113
+ const canRender = handleRenderRequest({
114
+ stateRenderId,
115
+ messageId: message.id,
116
+ runId: effectiveRunId,
117
+ stateSnapshot: snapshot
118
+ });
119
+ if (!canRender) {
120
+ return null;
121
+ }
122
+ if (snapshot && !claimsRef.current[message.id].locked) {
123
+ if (stateSnapshot) {
124
+ claimsRef.current[message.id].stateSnapshot = snapshot;
125
+ claimsRef.current[message.id].locked = true;
126
+ } else {
127
+ claimsRef.current[message.id].stateSnapshot = snapshot;
128
+ }
129
+ }
130
+ if (stateRender.handler) {
131
+ stateRender.handler({
132
+ state: stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
133
+ nodeName: nodeName != null ? nodeName : ""
134
+ });
135
+ }
136
+ if (stateRender.render) {
137
+ const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
138
+ if (typeof stateRender.render === "string")
139
+ return stateRender.render;
140
+ return stateRender.render({
141
+ status,
142
+ // Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
143
+ state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
144
+ nodeName: nodeName != null ? nodeName : ""
145
+ });
146
+ }
147
+ }, [
148
+ getStateRender,
149
+ stateSnapshot,
150
+ agent == null ? void 0 : agent.state,
151
+ agent == null ? void 0 : agent.isRunning,
152
+ nodeName,
153
+ effectiveRunId,
154
+ message.id,
155
+ messageIndexInRun
156
+ ]);
157
+ }
158
+ function CoAgentStateRenderBridge(props) {
159
+ return useCoagentStateRenderBridge(props.agentId, props);
160
+ }
161
+
162
+ export {
163
+ useCoagentStateRenderBridge,
164
+ CoAgentStateRenderBridge
165
+ };
166
+ //# sourceMappingURL=chunk-QNUAXSDP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent-state-render-bridge.tsx"],"sourcesContent":["import { ReactCustomMessageRendererPosition, useAgent } from \"@copilotkitnext/react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AgentSubscriber } from \"@ag-ui/client\";\nimport { useCoAgentStateRenders } from \"../context\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\n\nfunction getStateWithoutConstantKeys(state: any) {\n if (!state) return {};\n const { messages, tools, copilotkit, ...stateWithoutConstantKeys } = state;\n return stateWithoutConstantKeys;\n}\n\n// Function that compares states, without the constant keys\nfunction areStatesEquals(a: any, b: any) {\n if ((a && !b) || (!a && b)) return false;\n const { messages, tools, copilotkit, ...aWithoutConstantKeys } = a;\n const {\n messages: bMessages,\n tools: bTools,\n copilotkit: bCopilotkit,\n ...bWithoutConstantKeys\n } = b;\n\n return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);\n}\n\n/**\n * Bridge hook that connects agent state renders to chat messages.\n *\n * ## Purpose\n * This hook finds matching state render configurations (registered via useCoAgentStateRender)\n * and returns UI to render in chat.\n * It ensures each state render appears bound to a specific message, preventing duplicates while\n * allowing re-binding when the underlying state changes significantly.\n *\n * ## Message-ID-Based Claiming System\n *\n * ### The Problem\n * Multiple bridge component instances render simultaneously (one per message). Without coordination,\n * they would all try to render the same state render, causing duplicates.\n *\n * ### The Solution: Message-ID Claims with State Comparison\n * Each state render is \"claimed\" by exactly one **message ID** (not runId):\n *\n * **Claim Structure**: `claimsRef.current[messageId] = { stateRenderId, runId, stateSnapshot, locked }`\n *\n * **Primary binding is by messageId because**:\n * - runId is not always available immediately (starts as \"pending\")\n * - messageId is the stable identifier throughout the message lifecycle\n * - Claims persist across component remounts via context ref\n *\n * ### Claiming Logic Flow\n *\n * 1. **Message already has a claim**:\n * - Check if the claim matches the current stateRenderId\n * - If yes → render (this message owns this render)\n * - Update runId if it was \"pending\" and now available\n *\n * 2. **State render claimed by another message**:\n * - Compare state snapshots (ignoring constant keys: messages, tools, copilotkit)\n * - If states are identical → block rendering (duplicate)\n * - **If states are different → allow claiming** (new data, new message)\n * - This handles cases where the same render type shows different states in different messages\n *\n * 3. **Unclaimed state render**:\n * - Only allow claiming if runId is \"pending\" (initial render)\n * - If runId is real but no claim exists → block (edge case protection)\n * - Create new claim: `claimsRef.current[messageId] = { stateRenderId, runId }`\n *\n * ### State Snapshot Locking\n *\n * Once a state snapshot is captured and locked for a message:\n * - The UI always renders with the locked snapshot (not live agent.state)\n * - Prevents UI from appearing \"wiped\" during state transitions\n * - Locked when: stateSnapshot prop is available (from message persistence)\n * - Unlocked state: can still update from live agent.state\n *\n * ### Synchronous Claiming (Ref-based)\n *\n * Claims are stored in a context-level ref (not React state):\n * - Multiple bridges render in the same tick\n * - State updates are async - would allow duplicates before update completes\n * - Ref provides immediate, synchronous claim checking\n * - Survives component remounts (stored in context, not component)\n *\n * ## Flow Example\n *\n * ```\n * Time 1: Message A renders, runId=undefined, state={progress: 50%}\n * → effectiveRunId = \"pending\"\n * → Claims: claimsRef[\"msgA\"] = { stateRenderId: \"tasks\", runId: \"pending\", stateSnapshot: {progress: 50%} }\n * → Renders UI with 50% progress\n *\n * Time 2: Message B renders, runId=undefined, same state\n * → Checks: \"tasks\" already claimed by msgA with same state\n * → Returns null (blocked - duplicate)\n *\n * Time 3: Real runId appears (e.g., \"run-123\")\n * → Updates claim: claimsRef[\"msgA\"].runId = \"run-123\"\n * → Message A continues rendering\n *\n * Time 4: Agent processes more, state={progress: 100%}\n * → Message A: locked to 50% (stateSnapshot locked)\n * → Message C renders with state={progress: 100%}\n * → Checks: \"tasks\" claimed by msgA but state is DIFFERENT (50% vs 100%)\n * → Allows new claim: claimsRef[\"msgC\"] = { stateRenderId: \"tasks\", runId: \"run-123\", stateSnapshot: {progress: 100%} }\n * → Both messages render independently with their own snapshots\n * ```\n */\nexport interface CoAgentStateRenderBridgeProps {\n message: any;\n position: ReactCustomMessageRendererPosition;\n runId: string;\n messageIndex: number;\n messageIndexInRun: number;\n numberOfMessagesInRun: number;\n agentId: string;\n stateSnapshot: any;\n}\n\nexport function useCoagentStateRenderBridge(agentId: string, props: CoAgentStateRenderBridgeProps) {\n const { stateSnapshot, messageIndexInRun, message } = props;\n const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();\n const { agent } = useAgent({ agentId });\n const [nodeName, setNodeName] = useState<string | undefined>(undefined);\n\n const runId = props.runId ?? message.runId;\n const effectiveRunId = runId || \"pending\";\n\n useEffect(() => {\n if (!agent) return;\n const subscriber: AgentSubscriber = {\n onStepStartedEvent: ({ event }) => {\n if (event.stepName !== nodeName) {\n setNodeName(event.stepName);\n }\n },\n onStepFinishedEvent: ({ event }) => {\n if (event.stepName === nodeName) {\n setNodeName(undefined);\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agentId, nodeName]);\n\n const getStateRender = useCallback(\n (messageId: string) => {\n return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {\n if (claimsRef.current[messageId]) {\n return stateRenderId === claimsRef.current[messageId].stateRenderId;\n }\n const matchingAgentName = stateRender.name === agentId;\n const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;\n return matchingAgentName && matchesNodeContext;\n });\n },\n [coAgentStateRenders, nodeName, agentId],\n );\n\n // Message ID-based claim system - A state render can only be claimed by one message ID\n const handleRenderRequest = ({\n stateRenderId,\n messageId,\n runId,\n stateSnapshot: renderSnapshot,\n }: {\n stateRenderId: string;\n messageId: string;\n runId?: string;\n stateSnapshot?: any;\n }): boolean => {\n // Check if this message has already claimed this state render\n if (claimsRef.current[messageId]) {\n const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;\n\n // Update runId if it doesn't exist\n if (\n canRender &&\n runId &&\n (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === \"pending\")\n ) {\n claimsRef.current[messageId].runId = runId;\n }\n\n return canRender;\n }\n\n // Do not allow render if any other message has claimed this state render\n const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(\n (c) =>\n c.stateRenderId === stateRenderId &&\n dataToUUID(getStateWithoutConstantKeys(c.stateSnapshot)) ===\n dataToUUID(getStateWithoutConstantKeys(renderSnapshot)),\n );\n if (renderClaimedByOtherMessage) {\n // If:\n // - state render already claimed\n // - snapshot exists in the claiming object and is different from current,\n if (\n renderSnapshot &&\n renderClaimedByOtherMessage.stateSnapshot &&\n !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)\n ) {\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n }\n return false;\n }\n\n // No existing claim anywhere yet – allow this message to claim even if we already know the runId.\n if (!runId) {\n return false;\n }\n\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n };\n\n return useMemo(() => {\n if (messageIndexInRun !== 0) {\n return null;\n }\n\n const [stateRenderId, stateRender] = getStateRender(message.id) ?? [];\n\n if (!stateRender || !stateRenderId) {\n return null;\n }\n\n // Is there any state we can use?\n const snapshot = stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : agent?.state;\n\n // Synchronously check/claim - returns true if this message can render\n const canRender = handleRenderRequest({\n stateRenderId,\n messageId: message.id,\n runId: effectiveRunId,\n stateSnapshot: snapshot,\n });\n if (!canRender) {\n return null;\n }\n\n // If we found state, and given that now there's a claim for the current message, let's save it in the claim\n if (snapshot && !claimsRef.current[message.id].locked) {\n if (stateSnapshot) {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n claimsRef.current[message.id].locked = true;\n } else {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n }\n }\n\n if (stateRender.handler) {\n stateRender.handler({\n state: stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : (agent?.state ?? {}),\n nodeName: nodeName ?? \"\",\n });\n }\n\n if (stateRender.render) {\n const status = agent?.isRunning ? \"inProgress\" : \"complete\";\n\n if (typeof stateRender.render === \"string\") return stateRender.render;\n\n return stateRender.render({\n status,\n // Always use state from claim, to make sure the state does not seem \"wiped\" for a fraction of a second\n state: claimsRef.current[message.id].stateSnapshot ?? {},\n nodeName: nodeName ?? \"\",\n });\n }\n }, [\n getStateRender,\n stateSnapshot,\n agent?.state,\n agent?.isRunning,\n nodeName,\n effectiveRunId,\n message.id,\n messageIndexInRun,\n ]);\n}\n\nexport function CoAgentStateRenderBridge(props: CoAgentStateRenderBridgeProps) {\n return useCoagentStateRenderBridge(props.agentId, props);\n}\n"],"mappings":";;;;;;;;AAAA,SAA6C,gBAAgB;AAC7D,SAAS,aA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AA,QAEA,QAAO,eAAU,QAAQ,QAAQ,EAAE,EAAE,kBAA9B,YAA+C,CAAC;AAAA,QACvD,UAAU,8BAAY;AAAA,MACxB,CAAC;AAAA,IACH;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,+BAAO;AAAA,IACP,+BAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACF,CAAC;AACH;AAEO,SAAS,yBAAyB,OAAsC;AAC7E,SAAO,4BAA4B,MAAM,SAAS,KAAK;AACzD;","names":["runId","_a"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-SPCZTZCY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,125 @@
1
+ import {
2
+ useAgentNodeName
3
+ } from "./chunk-I76HKHPJ.mjs";
4
+ import {
5
+ useCopilotContext
6
+ } from "./chunk-AFNWX62Q.mjs";
7
+ import {
8
+ __spreadProps,
9
+ __spreadValues
10
+ } from "./chunk-SKC7AJIV.mjs";
11
+
12
+ // src/hooks/use-langgraph-interrupt-render.ts
13
+ import React, { useCallback, useEffect, useMemo } from "react";
14
+ import { MetaEventName } from "@copilotkit/runtime-client-gql";
15
+ import { dataToUUID, parseJson } from "@copilotkit/shared";
16
+ import { useCopilotChatConfiguration } from "@copilotkitnext/react";
17
+ var InterruptRenderer = ({ event, result, render, resolve }) => {
18
+ return render({ event, result, resolve });
19
+ };
20
+ function useLangGraphInterruptRender(agent) {
21
+ var _a;
22
+ const {
23
+ interruptActions,
24
+ agentSession,
25
+ threadId,
26
+ interruptEventQueue,
27
+ addInterruptEvent,
28
+ resolveInterruptEvent
29
+ } = useCopilotContext();
30
+ const existingConfig = useCopilotChatConfiguration();
31
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
32
+ const nodeName = useAgentNodeName(resolvedAgentId);
33
+ useEffect(() => {
34
+ if (!agent)
35
+ return;
36
+ let localInterrupt = null;
37
+ const subscriber = {
38
+ onCustomEvent: ({ event }) => {
39
+ if (event.name === "on_interrupt") {
40
+ const eventData = {
41
+ name: MetaEventName.LangGraphInterruptEvent,
42
+ type: event.type,
43
+ value: parseJson(event.value, event.value)
44
+ };
45
+ const eventId = dataToUUID(eventData, "interruptEvents");
46
+ localInterrupt = {
47
+ eventId,
48
+ threadId,
49
+ event: eventData
50
+ };
51
+ }
52
+ },
53
+ onRunStartedEvent: () => {
54
+ localInterrupt = null;
55
+ },
56
+ onRunFinalized: () => {
57
+ if (localInterrupt) {
58
+ addInterruptEvent(localInterrupt);
59
+ localInterrupt = null;
60
+ }
61
+ }
62
+ };
63
+ const { unsubscribe } = agent.subscribe(subscriber);
64
+ return () => {
65
+ unsubscribe();
66
+ };
67
+ }, [agent, threadId]);
68
+ const handleResolve = useCallback(
69
+ (eventId, response) => {
70
+ agent == null ? void 0 : agent.runAgent({
71
+ forwardedProps: {
72
+ command: {
73
+ resume: response
74
+ }
75
+ }
76
+ });
77
+ resolveInterruptEvent(threadId, eventId, response != null ? response : "");
78
+ },
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ [agent, threadId]
81
+ );
82
+ return useMemo(() => {
83
+ const eventQueue = interruptEventQueue[threadId] || [];
84
+ const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
85
+ if (!currentQueuedEvent || !agentSession)
86
+ return null;
87
+ const allActions = Object.values(interruptActions);
88
+ const matchingAction = allActions.find((action) => {
89
+ if (!action.enabled)
90
+ return true;
91
+ return action.enabled({
92
+ eventValue: currentQueuedEvent.event.value,
93
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
94
+ nodeName
95
+ })
96
+ });
97
+ });
98
+ if (!matchingAction)
99
+ return null;
100
+ const { render, handler } = matchingAction;
101
+ const resolveInterrupt = (response) => {
102
+ handleResolve(currentQueuedEvent.eventId, response);
103
+ };
104
+ let result = null;
105
+ if (handler) {
106
+ result = handler({
107
+ event: currentQueuedEvent.event,
108
+ resolve: resolveInterrupt
109
+ });
110
+ }
111
+ if (!render)
112
+ return null;
113
+ return React.createElement(InterruptRenderer, {
114
+ event: currentQueuedEvent.event,
115
+ result,
116
+ render,
117
+ resolve: resolveInterrupt
118
+ });
119
+ }, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);
120
+ }
121
+
122
+ export {
123
+ useLangGraphInterruptRender
124
+ };
125
+ //# sourceMappingURL=chunk-VV56AVPB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-langgraph-interrupt-render.ts"],"sourcesContent":["import { useCopilotContext } from \"../context\";\nimport React, { useCallback, useEffect, useMemo } from \"react\";\nimport type { AbstractAgent, AgentSubscriber } from \"@ag-ui/client\";\nimport { MetaEventName } from \"@copilotkit/runtime-client-gql\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\nimport { useAgentNodeName } from \"./use-agent-nodename\";\nimport { useCopilotChatConfiguration } from \"@copilotkitnext/react\";\n\ntype InterruptProps = {\n event: any;\n result: any;\n render: (props: {\n event: any;\n result: any;\n resolve: (response: string) => void;\n }) => string | React.ReactElement;\n resolve: (response: string) => void;\n};\n\nconst InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, resolve }) => {\n return render({ event, result, resolve });\n};\n\nexport function useLangGraphInterruptRender(\n agent: AbstractAgent,\n): string | React.ReactElement | null {\n const {\n interruptActions,\n agentSession,\n threadId,\n interruptEventQueue,\n addInterruptEvent,\n resolveInterruptEvent,\n } = useCopilotContext();\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const nodeName = useAgentNodeName(resolvedAgentId);\n\n useEffect(() => {\n if (!agent) return;\n let localInterrupt: any = null;\n const subscriber: AgentSubscriber = {\n onCustomEvent: ({ event }) => {\n if (event.name === \"on_interrupt\") {\n const eventData = {\n name: MetaEventName.LangGraphInterruptEvent,\n type: event.type,\n value: parseJson(event.value, event.value),\n };\n const eventId = dataToUUID(eventData, \"interruptEvents\");\n localInterrupt = {\n eventId,\n threadId,\n event: eventData,\n };\n }\n },\n onRunStartedEvent: () => {\n localInterrupt = null;\n },\n onRunFinalized: () => {\n if (localInterrupt) {\n addInterruptEvent(localInterrupt);\n localInterrupt = null;\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agent, threadId]);\n\n const handleResolve = useCallback(\n (eventId: string, response?: string) => {\n agent?.runAgent({\n forwardedProps: {\n command: {\n resume: response,\n },\n },\n });\n resolveInterruptEvent(threadId, eventId, response ?? \"\");\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent, threadId],\n );\n\n return useMemo(() => {\n // Get the queue for this thread and find the first unresponded event\n const eventQueue = interruptEventQueue[threadId] || [];\n const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);\n\n if (!currentQueuedEvent || !agentSession) return null;\n\n // Find the first matching action from all registered actions\n const allActions = Object.values(interruptActions);\n const matchingAction = allActions.find((action) => {\n if (!action.enabled) return true; // No filter = match all\n return action.enabled({\n eventValue: currentQueuedEvent.event.value,\n agentMetadata: {\n ...agentSession,\n nodeName,\n },\n });\n });\n\n if (!matchingAction) return null;\n\n const { render, handler } = matchingAction;\n\n const resolveInterrupt = (response: string) => {\n handleResolve(currentQueuedEvent.eventId, response);\n };\n\n let result = null;\n if (handler) {\n result = handler({\n event: currentQueuedEvent.event,\n resolve: resolveInterrupt,\n });\n }\n\n if (!render) return null;\n\n return React.createElement(InterruptRenderer, {\n event: currentQueuedEvent.event,\n result,\n render,\n resolve: resolveInterrupt,\n });\n }, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);\n}\n"],"mappings":";;;;;;;;;;;;AACA,OAAO,SAAS,aAAa,WAAW,eAAe;AAEvD,SAAS,qBAAqB;AAC9B,SAAS,YAAY,iBAAiB;AAEtC,SAAS,mCAAmC;AAa5C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AACA,4BAAsB,UAAU,SAAS,8BAAY,EAAE;AAAA,IACzD;AAAA;AAAA,IAEA,CAAC,OAAO,QAAQ;AAAA,EAClB;AAEA,SAAO,QAAQ,MAAM;AAEnB,UAAM,aAAa,oBAAoB,QAAQ,KAAK,CAAC;AACrD,UAAM,qBAAqB,WAAW,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,QAAQ;AAErE,QAAI,CAAC,sBAAsB,CAAC;AAAc,aAAO;AAGjD,UAAM,aAAa,OAAO,OAAO,gBAAgB;AACjD,UAAM,iBAAiB,WAAW,KAAK,CAAC,WAAW;AACjD,UAAI,CAAC,OAAO;AAAS,eAAO;AAC5B,aAAO,OAAO,QAAQ;AAAA,QACpB,YAAY,mBAAmB,MAAM;AAAA,QACrC,eAAe,iCACV,eADU;AAAA,UAEb;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC;AAAgB,aAAO;AAE5B,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,UAAM,mBAAmB,CAAC,aAAqB;AAC7C,oBAAc,mBAAmB,SAAS,QAAQ;AAAA,IACpD;AAEA,QAAI,SAAS;AACb,QAAI,SAAS;AACX,eAAS,QAAQ;AAAA,QACf,OAAO,mBAAmB;AAAA,QAC1B,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAEA,QAAI,CAAC;AAAQ,aAAO;AAEpB,WAAO,MAAM,cAAc,mBAAmB;AAAA,MAC5C,OAAO,mBAAmB;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH,GAAG,CAAC,kBAAkB,qBAAqB,UAAU,cAAc,aAAa,CAAC;AACnF;","names":[]}
@@ -0,0 +1,66 @@
1
+ import {
2
+ useToast
3
+ } from "./chunk-EFL5OBKN.mjs";
4
+
5
+ // src/components/CopilotListeners.tsx
6
+ import { useCallback, useEffect, useRef } from "react";
7
+ import { useAgent, useCopilotChatConfiguration, useCopilotKit } from "@copilotkitnext/react";
8
+ import { parseJson } from "@copilotkit/shared";
9
+ import { CopilotKitLowLevelError } from "@copilotkit/shared";
10
+ var usePredictStateSubscription = (agent) => {
11
+ const predictStateToolsRef = useRef([]);
12
+ const getSubscriber = useCallback(
13
+ (agent2) => ({
14
+ onCustomEvent: ({ event }) => {
15
+ if (event.name === "PredictState") {
16
+ predictStateToolsRef.current = event.value;
17
+ }
18
+ },
19
+ onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
20
+ predictStateToolsRef.current.forEach((t) => {
21
+ if ((t == null ? void 0 : t.tool) !== toolCallName)
22
+ return;
23
+ const emittedState = typeof partialToolCallArgs === "string" ? parseJson(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
24
+ agent2.setState({
25
+ [t.state_key]: emittedState[t.state_key]
26
+ });
27
+ });
28
+ }
29
+ }),
30
+ []
31
+ );
32
+ useEffect(() => {
33
+ if (!agent)
34
+ return;
35
+ const subscriber = getSubscriber(agent);
36
+ const { unsubscribe } = agent.subscribe(subscriber);
37
+ return () => {
38
+ unsubscribe();
39
+ };
40
+ }, [agent, getSubscriber]);
41
+ };
42
+ function CopilotListeners() {
43
+ const { copilotkit } = useCopilotKit();
44
+ const existingConfig = useCopilotChatConfiguration();
45
+ const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
46
+ const { setBannerError } = useToast();
47
+ const { agent } = useAgent({ agentId: resolvedAgentId });
48
+ usePredictStateSubscription(agent);
49
+ useEffect(() => {
50
+ const subscriber = {
51
+ onError: ({ error }) => {
52
+ setBannerError(new CopilotKitLowLevelError({ error, message: error.message }));
53
+ }
54
+ };
55
+ const subscription = copilotkit.subscribe(subscriber);
56
+ return () => {
57
+ subscription.unsubscribe();
58
+ };
59
+ }, [copilotkit == null ? void 0 : copilotkit.subscribe]);
60
+ return null;
61
+ }
62
+
63
+ export {
64
+ CopilotListeners
65
+ };
66
+ //# sourceMappingURL=chunk-WF65O6HX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/CopilotListeners.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { useAgent, useCopilotChatConfiguration, useCopilotKit } from \"@copilotkitnext/react\";\nimport { CopilotKitError, parseJson } from \"@copilotkit/shared\";\nimport { useCopilotContext } from \"../context\";\nimport { AbstractAgent, AgentSubscriber, AGUIConnectNotImplementedError } from \"@ag-ui/client\";\nimport { useErrorToast } from \"./error-boundary/error-utils\";\nimport { CopilotKitCoreSubscriber } from \"@copilotkitnext/core\";\nimport { useToast } from \"./toast/toast-provider\";\nimport { CopilotKitLowLevelError } from \"@copilotkit/shared\";\n\nconst usePredictStateSubscription = (agent?: AbstractAgent) => {\n const predictStateToolsRef = useRef<\n {\n tool: string;\n state_key: string;\n tool_argument: string;\n }[]\n >([]);\n\n const getSubscriber = useCallback(\n (agent: AbstractAgent): AgentSubscriber => ({\n onCustomEvent: ({ event }) => {\n if (event.name === \"PredictState\") {\n predictStateToolsRef.current = event.value;\n }\n },\n onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {\n predictStateToolsRef.current.forEach((t) => {\n if (t?.tool !== toolCallName) return;\n\n const emittedState =\n typeof partialToolCallArgs === \"string\"\n ? parseJson(partialToolCallArgs as unknown as string, partialToolCallArgs)\n : partialToolCallArgs;\n\n agent.setState({\n [t.state_key]: emittedState[t.state_key],\n });\n });\n },\n }),\n [],\n );\n\n useEffect(() => {\n if (!agent) return;\n\n const subscriber = getSubscriber(agent);\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n }, [agent, getSubscriber]);\n};\n\nexport function CopilotListeners() {\n const { copilotkit } = useCopilotKit();\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId;\n const { setBannerError } = useToast();\n\n const { agent } = useAgent({ agentId: resolvedAgentId });\n\n usePredictStateSubscription(agent);\n\n useEffect(() => {\n const subscriber: CopilotKitCoreSubscriber = {\n onError: ({ error }) => {\n // @ts-expect-error -- for now, choose a random CPK error type to display the error toast\n setBannerError(new CopilotKitLowLevelError({ error, message: error.message }));\n },\n };\n const subscription = copilotkit.subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit?.subscribe]);\n\n return null;\n}\n"],"mappings":";;;;;AAAA,SAAS,aAAa,WAAoB,cAAc;AACxD,SAAS,UAAU,6BAA6B,qBAAqB;AACrE,SAA0B,iBAAiB;AAM3C,SAAS,+BAA+B;AAExC,IAAM,8BAA8B,CAAC,UAA0B;AAC7D,QAAM,uBAAuB,OAM3B,CAAC,CAAC;AAEJ,QAAM,gBAAgB;AAAA,IACpB,CAACA,YAA2C;AAAA,MAC1C,eAAe,CAAC,EAAE,MAAM,MAAM;AAC5B,YAAI,MAAM,SAAS,gBAAgB;AACjC,+BAAqB,UAAU,MAAM;AAAA,QACvC;AAAA,MACF;AAAA,MACA,qBAAqB,CAAC,EAAE,qBAAqB,aAAa,MAAM;AAC9D,6BAAqB,QAAQ,QAAQ,CAAC,MAAM;AAC1C,eAAI,uBAAG,UAAS;AAAc;AAE9B,gBAAM,eACJ,OAAO,wBAAwB,WAC3B,UAAU,qBAA0C,mBAAmB,IACvE;AAEN,UAAAA,OAAM,SAAS;AAAA,YACb,CAAC,EAAE,SAAS,GAAG,aAAa,EAAE,SAAS;AAAA,UACzC,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AAEA,YAAU,MAAM;AACd,QAAI,CAAC;AAAO;AAEZ,UAAM,aAAa,cAAc,KAAK;AACtC,UAAM,EAAE,YAAY,IAAI,MAAM,UAAU,UAAU;AAClD,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,OAAO,aAAa,CAAC;AAC3B;AAEO,SAAS,mBAAmB;AACjC,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,kBAAkB,iDAAgB;AACxC,QAAM,EAAE,eAAe,IAAI,SAAS;AAEpC,QAAM,EAAE,MAAM,IAAI,SAAS,EAAE,SAAS,gBAAgB,CAAC;AAEvD,8BAA4B,KAAK;AAEjC,YAAU,MAAM;AACd,UAAM,aAAuC;AAAA,MAC3C,SAAS,CAAC,EAAE,MAAM,MAAM;AAEtB,uBAAe,IAAI,wBAAwB,EAAE,OAAO,SAAS,MAAM,QAAQ,CAAC,CAAC;AAAA,MAC/E;AAAA,IACF;AACA,UAAM,eAAe,WAAW,UAAU,UAAU;AAEpD,WAAO,MAAM;AACX,mBAAa,YAAY;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,yCAAY,SAAS,CAAC;AAE1B,SAAO;AACT;","names":["agent"]}
@@ -0,0 +1,27 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "./chunk-SKC7AJIV.mjs";
5
+
6
+ // src/hooks/use-copilot-chat-suggestions.tsx
7
+ import {
8
+ useConfigureSuggestions,
9
+ useCopilotChatConfiguration
10
+ } from "@copilotkitnext/react";
11
+ function useCopilotChatSuggestions(config, dependencies = []) {
12
+ var _a, _b;
13
+ const existingConfig = useCopilotChatConfiguration();
14
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
15
+ const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
16
+ const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
17
+ available,
18
+ consumerAgentId: resolvedAgentId
19
+ // Use chatConfig.agentId here
20
+ });
21
+ useConfigureSuggestions(finalSuggestionConfig, dependencies);
22
+ }
23
+
24
+ export {
25
+ useCopilotChatSuggestions
26
+ };
27
+ //# sourceMappingURL=chunk-XDFVCQD3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <br/>\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\nimport {\n useConfigureSuggestions,\n useCopilotChatConfiguration,\n useCopilotKit,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { useEffect } from \"react\";\nimport { StaticSuggestionsConfig, Suggestion } from \"@copilotkitnext/core\";\n\ntype StaticSuggestionInput = Omit<Suggestion, \"isLoading\"> & Partial<Pick<Suggestion, \"isLoading\">>;\n\ntype StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, \"suggestions\"> & {\n suggestions: StaticSuggestionInput[];\n};\n\ntype DynamicSuggestionsConfigInput = {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n\n /**\n * Whether the suggestions are available. Defaults to `enabled`.\n * @default enabled\n */\n available?: \"enabled\" | \"disabled\" | \"always\" | \"before-first-message\" | \"after-first-message\";\n\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n};\n\nexport type UseCopilotChatSuggestionsConfiguration =\n | DynamicSuggestionsConfigInput\n | StaticSuggestionsConfigInput;\n\nexport function useCopilotChatSuggestions(\n config: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n\n const available =\n (config.available === \"enabled\" ? \"always\" : config.available) ?? \"before-first-message\";\n\n const finalSuggestionConfig = {\n ...config,\n available,\n consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here\n };\n useConfigureSuggestions(finalSuggestionConfig, dependencies);\n}\n"],"mappings":";;;;;;AA4DA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AA0CA,SAAS,0BACd,QACA,eAAsB,CAAC,GACvB;AA9GF;AA+GE,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AAEnD,QAAM,aACH,YAAO,cAAc,YAAY,WAAW,OAAO,cAAnD,YAAiE;AAEpE,QAAM,wBAAwB,iCACzB,SADyB;AAAA,IAE5B;AAAA,IACA,iBAAiB;AAAA;AAAA,EACnB;AACA,0BAAwB,uBAAuB,YAAY;AAC7D;","names":[]}
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-PIF5KJYI.mjs";
6
6
  import {
7
7
  useCopilotContext
8
- } from "./chunk-EUX2P2E7.mjs";
8
+ } from "./chunk-AFNWX62Q.mjs";
9
9
  import {
10
10
  useCopilotMessagesContext
11
- } from "./chunk-ZLQVRPDS.mjs";
11
+ } from "./chunk-DMLQZG75.mjs";
12
12
 
13
13
  // src/components/dev-console/developer-console-modal.tsx
14
14
  import { COPILOTKIT_VERSION } from "@copilotkit/shared";
@@ -756,4 +756,4 @@ function ContextTab({ context }) {
756
756
  export {
757
757
  DeveloperConsoleModal
758
758
  };
759
- //# sourceMappingURL=chunk-OKCYPO4I.mjs.map
759
+ //# sourceMappingURL=chunk-YCG6SNAU.mjs.map