@copilotkit/react-core 0.0.0-fix-debug-infosys-20251107151227 → 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-RLR36R2Y.mjs → chunk-3V5TOYKW.mjs} +4 -4
  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-3HEGBDUK.mjs → chunk-53K6WNJG.mjs} +8 -6
  10. package/dist/{chunk-3HEGBDUK.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-E6ER5C5U.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-GIGUZ2OK.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-BCZQ5BZB.mjs → chunk-FQFXYAV7.mjs} +6 -5
  34. package/dist/{chunk-BCZQ5BZB.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-FPOOU7AG.mjs → chunk-HE22TZMF.mjs} +10 -46
  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-L3I57GMV.mjs → chunk-LHERIF3L.mjs} +4 -4
  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-TUTNHDM3.mjs → chunk-YCG6SNAU.mjs} +5 -5
  59. package/dist/{chunk-3WUDRJTT.mjs → chunk-YTQHRJUA.mjs} +9 -11
  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 +14 -12
  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 +15 -12
  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 +3 -3
  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 +16 -12
  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 +22 -6
  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 +82 -65
  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 +18 -14
  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 +18 -14
  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-3MUCKQXM.mjs +0 -71
  296. package/dist/chunk-3MUCKQXM.mjs.map +0 -1
  297. package/dist/chunk-3WUDRJTT.mjs.map +0 -1
  298. package/dist/chunk-4I6ZMKGV.mjs +0 -723
  299. package/dist/chunk-4I6ZMKGV.mjs.map +0 -1
  300. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  301. package/dist/chunk-CUWOXXM5.mjs +0 -231
  302. package/dist/chunk-CUWOXXM5.mjs.map +0 -1
  303. package/dist/chunk-DZTU6PGS.mjs +0 -1
  304. package/dist/chunk-EUX2P2E7.mjs.map +0 -1
  305. package/dist/chunk-FPOOU7AG.mjs.map +0 -1
  306. package/dist/chunk-H4AHA2Y7.mjs +0 -22
  307. package/dist/chunk-H4AHA2Y7.mjs.map +0 -1
  308. package/dist/chunk-HDOG2RTM.mjs +0 -37
  309. package/dist/chunk-HDOG2RTM.mjs.map +0 -1
  310. package/dist/chunk-HI6SPUOX.mjs +0 -142
  311. package/dist/chunk-HI6SPUOX.mjs.map +0 -1
  312. package/dist/chunk-IN74FLIZ.mjs +0 -804
  313. package/dist/chunk-IN74FLIZ.mjs.map +0 -1
  314. package/dist/chunk-N4WEHORG.mjs.map +0 -1
  315. package/dist/chunk-R4Y45UGQ.mjs +0 -25
  316. package/dist/chunk-R4Y45UGQ.mjs.map +0 -1
  317. package/dist/chunk-RLR36R2Y.mjs.map +0 -1
  318. package/dist/chunk-W2UUH57V.mjs +0 -332
  319. package/dist/chunk-W2UUH57V.mjs.map +0 -1
  320. package/dist/chunk-X5GRTEAW.mjs +0 -13
  321. package/dist/chunk-X5GRTEAW.mjs.map +0 -1
  322. package/dist/chunk-YAV3YNFQ.mjs +0 -239
  323. package/dist/chunk-YAV3YNFQ.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-E6ER5C5U.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-GIGUZ2OK.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-L3I57GMV.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-TUTNHDM3.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
@@ -61,8 +61,8 @@
61
61
  * }
62
62
  * ```
63
63
  */
64
+ import { useCopilotKit } from "@copilotkitnext/react";
64
65
  import { useEffect, useRef } from "react";
65
- import { useCopilotContext } from "../context/copilot-context";
66
66
 
67
67
  /**
68
68
  * Options for the useCopilotReadable hook.
@@ -98,40 +98,38 @@ export interface UseCopilotReadableOptions {
98
98
  convert?: (description: string, value: any) => string;
99
99
  }
100
100
 
101
- function convertToJSON(description: string, value: any): string {
102
- return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
103
- }
104
-
105
101
  /**
106
102
  * Adds the given information to the Copilot context to make it readable by Copilot.
107
103
  */
108
104
  export function useCopilotReadable(
109
- {
110
- description,
111
- value,
112
- parentId,
113
- categories,
114
- convert,
115
- available = "enabled",
116
- }: UseCopilotReadableOptions,
105
+ { description, value, convert, available }: UseCopilotReadableOptions,
117
106
  dependencies?: any[],
118
107
  ): string | undefined {
119
- const { addContext, removeContext } = useCopilotContext();
120
- const idRef = useRef<string>();
121
- convert = convert || convertToJSON;
122
-
123
- const information = convert(description, value);
124
-
108
+ const { copilotkit } = useCopilotKit();
109
+ const ctxIdRef = useRef<string | undefined>(undefined);
125
110
  useEffect(() => {
126
- if (available === "disabled") return;
111
+ if (!copilotkit) return;
112
+
113
+ const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
114
+ return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
115
+ });
116
+ if (found) {
117
+ ctxIdRef.current = found[0];
118
+ if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
119
+ return;
120
+ }
121
+ if (!found && available === "disabled") return;
127
122
 
128
- const id = addContext(information, parentId, categories);
129
- idRef.current = id;
123
+ ctxIdRef.current = copilotkit.addContext({
124
+ description,
125
+ value: (convert ?? JSON.stringify)(value),
126
+ });
130
127
 
131
128
  return () => {
132
- removeContext(id);
129
+ if (!ctxIdRef.current) return;
130
+ copilotkit.removeContext(ctxIdRef.current);
133
131
  };
134
- }, [available, information, parentId, addContext, removeContext, ...(dependencies || [])]);
132
+ }, [description, value, convert]);
135
133
 
136
- return idRef.current;
134
+ return ctxIdRef.current;
137
135
  }
@@ -16,9 +16,10 @@ interface FlatCategoryStoreElement<T> {
16
16
  }
17
17
 
18
18
  const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
19
- const [elements, dispatch] = useReducer<
20
- React.Reducer<Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>, Action<T>>
21
- >(flatCategoryStoreReducer, new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>());
19
+ const [elements, dispatch] = useReducer(
20
+ flatCategoryStoreReducer<T>,
21
+ new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>(),
22
+ );
22
23
 
23
24
  const addElement = useCallback((value: T, categories: string[]): FlatCategoryStoreId => {
24
25
  const newId = randomId();
@@ -1,18 +1,96 @@
1
- import { useCopilotAction } from "./use-copilot-action";
2
- import { FrontendAction } from "../types/frontend-action";
3
- import { Parameter } from "@copilotkit/shared";
1
+ import React, { useEffect, useRef } from "react";
2
+ import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
3
+ import { Parameter, getZodParameters, MappedParameterTypes } from "@copilotkit/shared";
4
+ import { parseJson } from "@copilotkit/shared";
5
+ import { ToolCallStatus } from "@copilotkitnext/core";
6
+ import {
7
+ type ReactFrontendTool,
8
+ useFrontendTool as useFrontendToolVNext,
9
+ } from "@copilotkitnext/react";
4
10
 
5
- type UseToolCallArgs<T extends Parameter[] | [] = []> = {
11
+ type FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<MappedParameterTypes<T>>;
12
+ type FrontendToolRenderArgs<T extends Parameter[] | []> =
13
+ | {
14
+ name: string;
15
+ args: Partial<MappedParameterTypes<T>>;
16
+ status: ToolCallStatus.InProgress;
17
+ result: undefined;
18
+ }
19
+ | {
20
+ name: string;
21
+ args: MappedParameterTypes<T>;
22
+ status: ToolCallStatus.Executing;
23
+ result: undefined;
24
+ }
25
+ | {
26
+ name: string;
27
+ args: MappedParameterTypes<T>;
28
+ status: ToolCallStatus.Complete;
29
+ result: string;
30
+ };
31
+
32
+ export type UseFrontendToolArgs<T extends Parameter[] | [] = []> = {
6
33
  available?: "disabled" | "enabled";
7
34
  } & Pick<
8
35
  FrontendAction<T>,
9
36
  "name" | "description" | "parameters" | "handler" | "followUp" | "render"
10
37
  >;
11
38
 
12
- export function useFrontendTool<const T extends Parameter[] | [] = []>(
13
- tool: UseToolCallArgs<T>,
39
+ export function useFrontendTool<const T extends Parameter[] = []>(
40
+ tool: UseFrontendToolArgs<T>,
14
41
  dependencies?: any[],
15
42
  ) {
16
- // Use the existing useCopilotAction hook
17
- useCopilotAction<T>(tool, dependencies);
43
+ const { name, description, parameters, render, followUp } = tool;
44
+ const zodParameters = getZodParameters(parameters);
45
+
46
+ const normalizedRender: FrontendToolOptions<T>["render"] | undefined = (() => {
47
+ if (typeof render === "undefined") {
48
+ return undefined;
49
+ }
50
+
51
+ if (typeof render === "string") {
52
+ const staticRender = render;
53
+ return (() =>
54
+ React.createElement(
55
+ React.Fragment,
56
+ null,
57
+ staticRender,
58
+ )) as FrontendToolOptions<T>["render"];
59
+ }
60
+
61
+ return ((args: FrontendToolRenderArgs<T>) => {
62
+ const renderArgs = {
63
+ ...args,
64
+ result: typeof args.result === "string" ? parseJson(args.result, args.result) : args.result,
65
+ } as ActionRenderProps<T>;
66
+
67
+ const rendered = render(renderArgs);
68
+
69
+ if (typeof rendered === "string") {
70
+ return React.createElement(React.Fragment, null, rendered);
71
+ }
72
+
73
+ return rendered ?? null;
74
+ }) as FrontendToolOptions<T>["render"];
75
+ })();
76
+
77
+ // Handler ref to avoid stale closures
78
+ const handlerRef = useRef<typeof tool.handler>(tool.handler);
79
+
80
+ useEffect(() => {
81
+ handlerRef.current = tool.handler;
82
+ }, [tool.handler, ...(dependencies ?? [])]);
83
+
84
+ const normalizedHandler = tool.handler
85
+ ? (args: MappedParameterTypes<T>) => handlerRef.current?.(args)
86
+ : undefined;
87
+
88
+ useFrontendToolVNext<MappedParameterTypes<T>>({
89
+ name,
90
+ description,
91
+ parameters: zodParameters,
92
+ handler: normalizedHandler,
93
+ followUp,
94
+ render: normalizedRender,
95
+ });
18
96
  }
@@ -1,24 +1,122 @@
1
- import { useCopilotAction } from "./use-copilot-action";
2
- import { FrontendAction } from "../types";
3
- import { Parameter } from "@copilotkit/shared";
1
+ import { ActionRenderProps, ActionRenderPropsWait, FrontendAction } from "../types";
2
+ import {
3
+ CopilotKitError,
4
+ CopilotKitErrorCode,
5
+ MappedParameterTypes,
6
+ Parameter,
7
+ getZodParameters,
8
+ parseJson,
9
+ } from "@copilotkit/shared";
10
+ import { useHumanInTheLoop as useHumanInTheLoopVNext } from "@copilotkitnext/react";
11
+ import { ToolCallStatus } from "@copilotkitnext/core";
12
+ import React, { ComponentType, FunctionComponent, useEffect, useRef } from "react";
4
13
 
5
- type UseToolCallArgs<T extends Parameter[] | [] = []> = {
14
+ type HumanInTheLoopOptions = Parameters<typeof useHumanInTheLoopVNext>[0];
15
+ type HumanInTheLoopRender = HumanInTheLoopOptions["render"];
16
+ type HumanInTheLoopRenderArgs = HumanInTheLoopRender extends (props: infer P) => any ? P : never;
17
+
18
+ export type UseHumanInTheLoopArgs<T extends Parameter[] | [] = []> = {
6
19
  available?: "disabled" | "enabled";
7
20
  render: FrontendAction<T>["renderAndWaitForResponse"];
21
+ followUp?: FrontendAction<T>["followUp"];
8
22
  } & Pick<FrontendAction<T>, "name" | "description" | "parameters">;
9
23
 
24
+ type HitlRendererArgs =
25
+ | {
26
+ name: string;
27
+ description: string;
28
+ args: Partial<Record<string, unknown>>;
29
+ status: ToolCallStatus.InProgress;
30
+ result: undefined;
31
+ respond: undefined;
32
+ }
33
+ | {
34
+ name: string;
35
+ description: string;
36
+ args: Record<string, unknown>;
37
+ status: ToolCallStatus.Executing;
38
+ result: undefined;
39
+ respond: (result: unknown) => Promise<void>;
40
+ }
41
+ | {
42
+ name: string;
43
+ description: string;
44
+ args: Record<string, unknown>;
45
+ status: ToolCallStatus.Complete;
46
+ result: string;
47
+ respond: undefined;
48
+ };
49
+ type HitlRenderer = FunctionComponent<HitlRendererArgs>;
50
+
10
51
  export function useHumanInTheLoop<const T extends Parameter[] | [] = []>(
11
- tool: UseToolCallArgs<T>,
52
+ tool: UseHumanInTheLoopArgs<T>,
12
53
  dependencies?: any[],
13
54
  ) {
14
55
  const { render, ...toolRest } = tool;
56
+ const { name, description, parameters, followUp } = toolRest;
57
+ const zodParameters = getZodParameters(parameters);
58
+ const renderRef = useRef<HitlRenderer | null>(null);
59
+
60
+ useEffect(() => {
61
+ renderRef.current = (args: HitlRendererArgs): React.ReactElement | null => {
62
+ if (typeof render === "string") {
63
+ return React.createElement(React.Fragment, null, render);
64
+ }
65
+
66
+ if (!render) {
67
+ return null;
68
+ }
69
+
70
+ const renderProps: ActionRenderPropsWait<T> = (() => {
71
+ const mappedArgs = args.args as unknown as MappedParameterTypes<T>;
72
+
73
+ switch (args.status) {
74
+ case ToolCallStatus.InProgress:
75
+ return {
76
+ args: mappedArgs,
77
+ respond: args.respond,
78
+ status: args.status,
79
+ handler: undefined,
80
+ };
81
+ case ToolCallStatus.Executing:
82
+ return {
83
+ args: mappedArgs,
84
+ respond: args.respond,
85
+ status: args.status,
86
+ handler: () => {},
87
+ };
88
+ case ToolCallStatus.Complete:
89
+ return {
90
+ args: mappedArgs,
91
+ respond: args.respond,
92
+ status: args.status,
93
+ result: args.result ? parseJson(args.result, args.result) : args.result,
94
+ handler: undefined,
95
+ };
96
+ default:
97
+ throw new CopilotKitError({
98
+ code: CopilotKitErrorCode.UNKNOWN,
99
+ message: `Invalid tool call status: ${(args as unknown as { status: string }).status}`,
100
+ });
101
+ }
102
+ })();
103
+
104
+ const rendered = render(renderProps);
105
+
106
+ if (typeof rendered === "string") {
107
+ return React.createElement(React.Fragment, null, rendered);
108
+ }
109
+
110
+ return rendered ?? null;
111
+ };
112
+ }, [render, ...(dependencies ?? [])]);
15
113
 
16
- useCopilotAction(
17
- {
18
- ...toolRest,
19
- available: tool.available === "disabled" ? tool.available : "remote",
20
- renderAndWaitForResponse: render,
21
- },
22
- dependencies,
23
- );
114
+ useHumanInTheLoopVNext({
115
+ name,
116
+ description,
117
+ followUp,
118
+ parameters: zodParameters,
119
+ render: ((args: HumanInTheLoopRenderArgs) =>
120
+ renderRef.current?.(args as HitlRendererArgs) ?? null) as HumanInTheLoopOptions["render"],
121
+ });
24
122
  }
@@ -1,6 +1,10 @@
1
1
  import { useCopilotContext } from "../context";
2
- import React, { useCallback } from "react";
3
- import { executeConditions } from "@copilotkit/shared";
2
+ import React, { useCallback, useEffect, useMemo } from "react";
3
+ import type { AbstractAgent, AgentSubscriber } from "@ag-ui/client";
4
+ import { MetaEventName } from "@copilotkit/runtime-client-gql";
5
+ import { dataToUUID, parseJson } from "@copilotkit/shared";
6
+ import { useAgentNodeName } from "./use-agent-nodename";
7
+ import { useCopilotChatConfiguration } from "@copilotkitnext/react";
4
8
 
5
9
  type InterruptProps = {
6
10
  event: any;
@@ -17,52 +21,116 @@ const InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, re
17
21
  return render({ event, result, resolve });
18
22
  };
19
23
 
20
- export function useLangGraphInterruptRender(): string | React.ReactElement | null {
21
- const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession, threadId } =
22
- useCopilotContext();
24
+ export function useLangGraphInterruptRender(
25
+ agent: AbstractAgent,
26
+ ): string | React.ReactElement | null {
27
+ const {
28
+ interruptActions,
29
+ agentSession,
30
+ threadId,
31
+ interruptEventQueue,
32
+ addInterruptEvent,
33
+ resolveInterruptEvent,
34
+ } = useCopilotContext();
35
+ const existingConfig = useCopilotChatConfiguration();
36
+ const resolvedAgentId = existingConfig?.agentId ?? "default";
37
+ const nodeName = useAgentNodeName(resolvedAgentId);
23
38
 
24
- const responseRef = React.useRef<string>();
25
- const resolveInterrupt = useCallback(
26
- (response: string) => {
27
- responseRef.current = response;
28
- // Use setTimeout to defer the state update to next tick
29
- setTimeout(() => {
30
- setLangGraphInterruptAction(threadId, { event: { response } });
31
- }, 0);
39
+ useEffect(() => {
40
+ if (!agent) return;
41
+ let localInterrupt: any = null;
42
+ const subscriber: AgentSubscriber = {
43
+ onCustomEvent: ({ event }) => {
44
+ if (event.name === "on_interrupt") {
45
+ const eventData = {
46
+ name: MetaEventName.LangGraphInterruptEvent,
47
+ type: event.type,
48
+ value: parseJson(event.value, event.value),
49
+ };
50
+ const eventId = dataToUUID(eventData, "interruptEvents");
51
+ localInterrupt = {
52
+ eventId,
53
+ threadId,
54
+ event: eventData,
55
+ };
56
+ }
57
+ },
58
+ onRunStartedEvent: () => {
59
+ localInterrupt = null;
60
+ },
61
+ onRunFinalized: () => {
62
+ if (localInterrupt) {
63
+ addInterruptEvent(localInterrupt);
64
+ localInterrupt = null;
65
+ }
66
+ },
67
+ };
68
+
69
+ const { unsubscribe } = agent.subscribe(subscriber);
70
+ return () => {
71
+ unsubscribe();
72
+ };
73
+ // eslint-disable-next-line react-hooks/exhaustive-deps
74
+ }, [agent, threadId]);
75
+
76
+ const handleResolve = useCallback(
77
+ (eventId: string, response?: string) => {
78
+ agent?.runAgent({
79
+ forwardedProps: {
80
+ command: {
81
+ resume: response,
82
+ },
83
+ },
84
+ });
85
+ resolveInterruptEvent(threadId, eventId, response ?? "");
32
86
  },
33
- [setLangGraphInterruptAction, threadId],
87
+ // eslint-disable-next-line react-hooks/exhaustive-deps
88
+ [agent, threadId],
34
89
  );
35
90
 
36
- if (
37
- !langGraphInterruptAction ||
38
- !langGraphInterruptAction.event ||
39
- !langGraphInterruptAction.render
40
- )
41
- return null;
91
+ return useMemo(() => {
92
+ // Get the queue for this thread and find the first unresponded event
93
+ const eventQueue = interruptEventQueue[threadId] || [];
94
+ const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
95
+
96
+ if (!currentQueuedEvent || !agentSession) return null;
97
+
98
+ // Find the first matching action from all registered actions
99
+ const allActions = Object.values(interruptActions);
100
+ const matchingAction = allActions.find((action) => {
101
+ if (!action.enabled) return true; // No filter = match all
102
+ return action.enabled({
103
+ eventValue: currentQueuedEvent.event.value,
104
+ agentMetadata: {
105
+ ...agentSession,
106
+ nodeName,
107
+ },
108
+ });
109
+ });
110
+
111
+ if (!matchingAction) return null;
42
112
 
43
- const { render, handler, event, enabled } = langGraphInterruptAction;
113
+ const { render, handler } = matchingAction;
44
114
 
45
- const conditionsMet =
46
- !agentSession || !enabled
47
- ? true
48
- : enabled({ eventValue: event.value, agentMetadata: agentSession });
115
+ const resolveInterrupt = (response: string) => {
116
+ handleResolve(currentQueuedEvent.eventId, response);
117
+ };
49
118
 
50
- if (!conditionsMet) {
51
- return null;
52
- }
119
+ let result = null;
120
+ if (handler) {
121
+ result = handler({
122
+ event: currentQueuedEvent.event,
123
+ resolve: resolveInterrupt,
124
+ });
125
+ }
53
126
 
54
- let result = null;
55
- if (handler) {
56
- result = handler({
57
- event,
127
+ if (!render) return null;
128
+
129
+ return React.createElement(InterruptRenderer, {
130
+ event: currentQueuedEvent.event,
131
+ result,
132
+ render,
58
133
  resolve: resolveInterrupt,
59
134
  });
60
- }
61
-
62
- return React.createElement(InterruptRenderer, {
63
- event,
64
- result,
65
- render,
66
- resolve: resolveInterrupt,
67
- });
135
+ }, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);
68
136
  }
@@ -1,7 +1,6 @@
1
1
  import { useContext, useEffect, useMemo } from "react";
2
2
  import { CopilotContext } from "../context/copilot-context";
3
3
  import { LangGraphInterruptRender } from "../types/interrupt-action";
4
- import { useCopilotChat } from "./use-copilot-chat_internal";
5
4
  import { useToast } from "../components/toast/toast-provider";
6
5
  import { dataToUUID } from "@copilotkit/shared";
7
6
 
@@ -9,58 +8,29 @@ export function useLangGraphInterrupt<TEventValue = any>(
9
8
  action: Omit<LangGraphInterruptRender<TEventValue>, "id">,
10
9
  dependencies?: any[],
11
10
  ) {
12
- const {
13
- setLangGraphInterruptAction,
14
- removeLangGraphInterruptAction,
15
- langGraphInterruptAction,
16
- threadId,
17
- } = useContext(CopilotContext);
18
- const { runChatCompletion } = useCopilotChat();
11
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } =
12
+ useContext(CopilotContext);
19
13
  const { addToast } = useToast();
20
14
 
21
- const actionId = dataToUUID(JSON.stringify(action), "lgAction");
22
- // We only consider action to be defined once the ID is there
23
- const hasAction = useMemo(
24
- () => Boolean(langGraphInterruptAction?.id),
25
- [langGraphInterruptAction],
26
- );
27
-
28
- const isCurrentAction = useMemo(
29
- () => langGraphInterruptAction?.id && langGraphInterruptAction?.id === actionId,
30
- [langGraphInterruptAction],
31
- );
32
-
33
- // Run chat completion to submit a response event. Only if it's the current action
34
- useEffect(() => {
35
- if (hasAction && isCurrentAction && langGraphInterruptAction?.event?.response) {
36
- runChatCompletion();
37
- }
38
- }, [langGraphInterruptAction?.event?.response, runChatCompletion, hasAction, isCurrentAction]);
15
+ const actionId = dataToUUID(action, "lgAction");
39
16
 
40
17
  useEffect(() => {
41
18
  if (!action) return;
42
- // An action was already set, with no conditions and it's not the action we're using right now.
43
- // Show a warning, as this action will not be executed
44
- if (hasAction && !isCurrentAction && !action.enabled) {
45
- addToast({
46
- type: "warning",
47
- message: "An action is already registered for the interrupt event",
48
- });
49
- return;
50
- }
51
19
 
52
- if (hasAction && isCurrentAction) {
53
- return;
54
- }
20
+ // if (!action.enabled) {
21
+ // TODO: if there are any other actions registered, we need to warn the user that a current action without "enabled" might render for everything
22
+ // addToast({
23
+ // type: "warning",
24
+ // message: "An action is already registered for the interrupt event",
25
+ // });
26
+ // return;
27
+ // }
28
+
29
+ setInterruptAction({ ...action, id: actionId });
55
30
 
56
- setLangGraphInterruptAction(threadId, { ...action, id: actionId });
57
- }, [
58
- action,
59
- hasAction,
60
- isCurrentAction,
61
- setLangGraphInterruptAction,
62
- removeLangGraphInterruptAction,
63
- threadId,
64
- ...(dependencies || []),
65
- ]);
31
+ // Cleanup: remove action on unmount
32
+ return () => {
33
+ removeInterruptAction(actionId);
34
+ };
35
+ }, [setInterruptAction, removeInterruptAction, threadId, actionId, ...(dependencies || [])]);
66
36
  }
@@ -0,0 +1,30 @@
1
+ import { useRenderToolCall } from "@copilotkitnext/react";
2
+ import { AIMessage, Message, ToolResult } from "@copilotkit/shared";
3
+ import React, { useCallback } from "react";
4
+
5
+ export function useLazyToolRenderer(): (
6
+ message?: AIMessage,
7
+ messages?: Message[],
8
+ ) => null | (() => ReturnType<ReturnType<typeof useRenderToolCall>> | null) {
9
+ const renderToolCall = useRenderToolCall();
10
+
11
+ return useCallback(
12
+ (message?: AIMessage, messages?: Message[]) => {
13
+ if (!message?.toolCalls?.length) return null;
14
+
15
+ const toolCall = message.toolCalls[0];
16
+ if (!toolCall) return null;
17
+
18
+ const toolMessage = messages?.find(
19
+ (m) => m.role === "tool" && m.toolCallId === toolCall.id,
20
+ ) as ToolResult;
21
+
22
+ return () =>
23
+ renderToolCall({
24
+ toolCall,
25
+ toolMessage,
26
+ });
27
+ },
28
+ [renderToolCall],
29
+ );
30
+ }
@@ -15,7 +15,7 @@ export function useMakeCopilotDocumentReadable(
15
15
  dependencies: any[] = [],
16
16
  ): string | undefined {
17
17
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
18
- const idRef = useRef<string>();
18
+ const idRef = useRef<string>(undefined!);
19
19
 
20
20
  useEffect(() => {
21
21
  const id = addDocumentContext(document, categories);