@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,76 @@
1
+ import React, {
2
+ createContext,
3
+ useContext,
4
+ useCallback,
5
+ useState,
6
+ useRef,
7
+ ReactNode,
8
+ RefObject,
9
+ } from "react";
10
+ import { CoAgentStateRender } from "../types/coagent-action";
11
+
12
+ interface StateRenderClaim {
13
+ stateRenderId: string;
14
+ stateSnapshot?: any;
15
+ runId?: string;
16
+ locked?: boolean;
17
+ }
18
+
19
+ type ClaimsRef = Record<string, StateRenderClaim>;
20
+
21
+ export interface CoAgentStateRendersContextValue {
22
+ coAgentStateRenders: Record<string, CoAgentStateRender<any>>;
23
+ setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;
24
+ removeCoAgentStateRender: (id: string) => void;
25
+ claimsRef: RefObject<ClaimsRef>;
26
+ }
27
+
28
+ const CoAgentStateRendersContext = createContext<CoAgentStateRendersContextValue | undefined>(
29
+ undefined,
30
+ );
31
+
32
+ export function CoAgentStateRendersProvider({ children }: { children: ReactNode }) {
33
+ const [coAgentStateRenders, setCoAgentStateRenders] = useState<
34
+ Record<string, CoAgentStateRender<any>>
35
+ >({});
36
+
37
+ const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {
38
+ setCoAgentStateRenders((prevPoints) => ({
39
+ ...prevPoints,
40
+ [id]: stateRender,
41
+ }));
42
+ }, []);
43
+
44
+ const removeCoAgentStateRender = useCallback((id: string) => {
45
+ setCoAgentStateRenders((prevPoints) => {
46
+ const newPoints = { ...prevPoints };
47
+ delete newPoints[id];
48
+ return newPoints;
49
+ });
50
+ }, []);
51
+
52
+ const claimsRef = useRef<ClaimsRef>({});
53
+
54
+ return (
55
+ <CoAgentStateRendersContext.Provider
56
+ value={{
57
+ coAgentStateRenders,
58
+ setCoAgentStateRender,
59
+ removeCoAgentStateRender,
60
+ claimsRef,
61
+ }}
62
+ >
63
+ {children}
64
+ </CoAgentStateRendersContext.Provider>
65
+ );
66
+ }
67
+
68
+ export function useCoAgentStateRenders() {
69
+ const context = useContext(CoAgentStateRendersContext);
70
+ if (!context) {
71
+ throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
72
+ }
73
+ return context;
74
+ }
75
+
76
+ export { CoAgentStateRendersContext };
@@ -22,10 +22,10 @@ import {
22
22
  } from "@copilotkit/runtime-client-gql";
23
23
  import { Agent } from "@copilotkit/runtime-client-gql";
24
24
  import {
25
- LangGraphInterruptAction,
25
+ LangGraphInterruptRender,
26
26
  LangGraphInterruptActionSetter,
27
+ QueuedInterruptEvent,
27
28
  } from "../types/interrupt-action";
28
- import { SuggestionItem } from "../utils/suggestions";
29
29
 
30
30
  /**
31
31
  * Interface for the configuration of the Copilot API.
@@ -95,10 +95,10 @@ export interface CopilotApiConfig {
95
95
  }
96
96
 
97
97
  export type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =
98
- (props: TProps) => string | JSX.Element;
98
+ (props: TProps) => string | React.JSX.Element;
99
99
  export type CoagentInChatRenderFunction = (
100
100
  props: CoAgentStateRenderProps<any>,
101
- ) => string | JSX.Element | undefined | null;
101
+ ) => string | React.JSX.Element | undefined | null;
102
102
 
103
103
  export interface ChatComponentsCache {
104
104
  actions: Record<string, InChatRenderFunction | string>;
@@ -127,10 +127,9 @@ export interface CopilotContextParams {
127
127
  setAction: (id: string, action: FrontendAction<any>) => void;
128
128
  removeAction: (id: string) => void;
129
129
 
130
- // coagent actions
131
- coAgentStateRenders: Record<string, CoAgentStateRender<any>>;
132
- setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;
133
- removeCoAgentStateRender: (id: string) => void;
130
+ // registered actions for component-based rendering
131
+ setRegisteredActions: (actionConfig: any) => string;
132
+ removeRegisteredAction: (actionKey: string) => void;
134
133
 
135
134
  chatComponentsCache: React.RefObject<ChatComponentsCache>;
136
135
 
@@ -195,9 +194,6 @@ export interface CopilotContextParams {
195
194
  // i.e. when using `stop()` from `useChat`
196
195
  chatAbortControllerRef: React.MutableRefObject<AbortController | null>;
197
196
 
198
- // runtime
199
- runtimeClient: CopilotRuntimeClient;
200
-
201
197
  /**
202
198
  * The forwarded parameters to use for the task.
203
199
  */
@@ -221,9 +217,12 @@ export interface CopilotContextParams {
221
217
 
222
218
  extensions: ExtensionsInput;
223
219
  setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;
224
- langGraphInterruptAction: LangGraphInterruptAction | null;
225
- setLangGraphInterruptAction: LangGraphInterruptActionSetter;
226
- removeLangGraphInterruptAction: (threadId: string) => void;
220
+ interruptActions: Record<string, LangGraphInterruptRender>;
221
+ setInterruptAction: LangGraphInterruptActionSetter;
222
+ removeInterruptAction: (actionId: string) => void;
223
+ interruptEventQueue: Record<string, QueuedInterruptEvent[]>;
224
+ addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;
225
+ resolveInterruptEvent: (threadId: string, eventId: string, response: string) => void;
227
226
 
228
227
  /**
229
228
  * Optional trace handler for comprehensive debugging and observability.
@@ -246,9 +245,8 @@ const emptyCopilotContext: CopilotContextParams = {
246
245
  setAction: () => {},
247
246
  removeAction: () => {},
248
247
 
249
- coAgentStateRenders: {},
250
- setCoAgentStateRender: () => {},
251
- removeCoAgentStateRender: () => {},
248
+ setRegisteredActions: () => "",
249
+ removeRegisteredAction: () => {},
252
250
 
253
251
  chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
254
252
  getContextString: (documents: DocumentPointer[], categories: string[]) =>
@@ -271,7 +269,6 @@ const emptyCopilotContext: CopilotContextParams = {
271
269
  getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),
272
270
  addDocumentContext: () => returnAndThrowInDebug(""),
273
271
  removeDocumentContext: () => {},
274
- runtimeClient: {} as any,
275
272
 
276
273
  copilotApiConfig: new (class implements CopilotApiConfig {
277
274
  get chatApiEndpoint(): string {
@@ -306,9 +303,12 @@ const emptyCopilotContext: CopilotContextParams = {
306
303
  availableAgents: [],
307
304
  extensions: {},
308
305
  setExtensions: () => {},
309
- langGraphInterruptAction: null,
310
- setLangGraphInterruptAction: () => {},
311
- removeLangGraphInterruptAction: () => {},
306
+ interruptActions: {},
307
+ setInterruptAction: () => {},
308
+ removeInterruptAction: () => {},
309
+ interruptEventQueue: {},
310
+ addInterruptEvent: () => {},
311
+ resolveInterruptEvent: () => {},
312
312
  onError: () => {},
313
313
  bannerError: null,
314
314
  setBannerError: () => {},
@@ -4,13 +4,13 @@
4
4
 
5
5
  import { Message } from "@copilotkit/runtime-client-gql";
6
6
  import React from "react";
7
- import { SuggestionItem } from "../utils/suggestions";
7
+ import { Suggestion } from "@copilotkitnext/core";
8
8
 
9
9
  export interface CopilotMessagesContextParams {
10
10
  messages: Message[];
11
11
  setMessages: React.Dispatch<React.SetStateAction<Message[]>>; // suggestions state
12
- suggestions: SuggestionItem[];
13
- setSuggestions: React.Dispatch<React.SetStateAction<SuggestionItem[]>>;
12
+ suggestions: Suggestion[];
13
+ setSuggestions: React.Dispatch<React.SetStateAction<Suggestion[]>>;
14
14
  }
15
15
 
16
16
  const emptyCopilotContext: CopilotMessagesContextParams = {
@@ -1,8 +1,16 @@
1
1
  export { CopilotContext, useCopilotContext } from "./copilot-context";
2
2
  export { CopilotMessagesContext, useCopilotMessagesContext } from "./copilot-messages-context";
3
+ export {
4
+ CoAgentStateRendersContext,
5
+ CoAgentStateRendersProvider,
6
+ useCoAgentStateRenders,
7
+ } from "./coagent-state-renders-context";
8
+ export { ThreadsContext, ThreadsProvider, useThreads } from "./threads-context";
3
9
  export type {
4
10
  CopilotContextParams,
5
11
  CoagentInChatRenderFunction,
6
12
  CopilotApiConfig,
7
13
  } from "./copilot-context";
8
14
  export type { CopilotMessagesContextParams } from "./copilot-messages-context";
15
+ export type { CoAgentStateRendersContextValue } from "./coagent-state-renders-context";
16
+ export type { ThreadsContextValue, ThreadsProviderProps } from "./threads-context";
@@ -0,0 +1,41 @@
1
+ import React, { createContext, useContext, useState, ReactNode, SetStateAction } from "react";
2
+ import { randomUUID } from "@copilotkit/shared";
3
+
4
+ export interface ThreadsContextValue {
5
+ threadId: string;
6
+ setThreadId: (value: SetStateAction<string>) => void;
7
+ }
8
+
9
+ const ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);
10
+
11
+ export interface ThreadsProviderProps {
12
+ children: ReactNode;
13
+ threadId?: string;
14
+ }
15
+
16
+ export function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {
17
+ const [internalThreadId, setThreadId] = useState<string>(explicitThreadId ?? randomUUID());
18
+
19
+ const threadId = internalThreadId;
20
+
21
+ return (
22
+ <ThreadsContext.Provider
23
+ value={{
24
+ threadId,
25
+ setThreadId,
26
+ }}
27
+ >
28
+ {children}
29
+ </ThreadsContext.Provider>
30
+ );
31
+ }
32
+
33
+ export function useThreads() {
34
+ const context = useContext(ThreadsContext);
35
+ if (!context) {
36
+ throw new Error("useThreads must be used within ThreadsProvider");
37
+ }
38
+ return context;
39
+ }
40
+
41
+ export { ThreadsContext };
@@ -1,8 +1,43 @@
1
- import { renderHook } from "@testing-library/react";
1
+ import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { useCoAgent } from "../use-coagent";
3
+ import type { AgentSubscriber } from "@ag-ui/client";
4
+
5
+ // Mock functions for @copilotkitnext/react
6
+ const mockSetState = jest.fn();
7
+ const mockRunAgent = jest.fn();
8
+ const mockAbortRun = jest.fn();
9
+ const mockSubscribe = jest.fn();
10
+ const mockSetProperties = jest.fn();
11
+
12
+ // Store the last subscriber for triggering events
13
+ let lastSubscriber: AgentSubscriber | null = null;
14
+
15
+ const mockAgent = {
16
+ agentId: "test-agent",
17
+ state: { count: 0 },
18
+ isRunning: false,
19
+ threadId: "thread-123",
20
+ setState: mockSetState,
21
+ runAgent: mockRunAgent,
22
+ abortRun: mockAbortRun,
23
+ subscribe: mockSubscribe.mockImplementation((subscriber: AgentSubscriber) => {
24
+ lastSubscriber = subscriber;
25
+ return {
26
+ unsubscribe: jest.fn(),
27
+ };
28
+ }),
29
+ };
3
30
 
4
- // Mock the dependencies
5
- const mockSetCoagentStatesWithRef = jest.fn();
31
+ jest.mock("@copilotkitnext/react", () => ({
32
+ useAgent: jest.fn(() => ({ agent: mockAgent })),
33
+ useCopilotKit: jest.fn(() => ({
34
+ copilotkit: {
35
+ setProperties: mockSetProperties,
36
+ },
37
+ })),
38
+ }));
39
+
40
+ // Mock other dependencies
6
41
  const mockAppendMessage = jest.fn();
7
42
  const mockRunChatCompletion = jest.fn();
8
43
 
@@ -27,7 +62,6 @@ jest.mock("../../context", () => ({
27
62
  availableAgents: [],
28
63
  coagentStates: {},
29
64
  coagentStatesRef: { current: {} },
30
- setCoagentStatesWithRef: mockSetCoagentStatesWithRef,
31
65
  threadId: "test-thread",
32
66
  copilotApiConfig: {
33
67
  headers: {},
@@ -61,14 +95,10 @@ jest.mock("../../components/copilot-provider/copilot-messages", () => ({
61
95
  describe("useCoAgent config synchronization", () => {
62
96
  beforeEach(() => {
63
97
  jest.clearAllMocks();
64
- mockSetCoagentStatesWithRef.mockImplementation((updater) => {
65
- if (typeof updater === "function") {
66
- updater({});
67
- }
68
- });
98
+ lastSubscriber = null;
69
99
  });
70
100
 
71
- it("should call setCoagentStatesWithRef when config changes", () => {
101
+ it("should call setProperties when config changes", async () => {
72
102
  const { rerender } = renderHook(
73
103
  ({ config }) =>
74
104
  useCoAgent({
@@ -82,16 +112,20 @@ describe("useCoAgent config synchronization", () => {
82
112
  );
83
113
 
84
114
  // Clear the initial calls
85
- mockSetCoagentStatesWithRef.mockClear();
115
+ mockSetProperties.mockClear();
86
116
 
87
117
  // Change config
88
118
  rerender({ config: { configurable: { model: "gpt-4o" } } });
89
119
 
90
- // Should have called setCoagentStatesWithRef with new config
91
- expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
120
+ // Wait for effect to complete and verify setProperties was called
121
+ await waitFor(() => {
122
+ expect(mockSetProperties).toHaveBeenCalledWith({
123
+ configurable: { model: "gpt-4o" },
124
+ });
125
+ });
92
126
  });
93
127
 
94
- it("should not call setCoagentStatesWithRef when config is unchanged", () => {
128
+ it("should not call setProperties when config is unchanged", () => {
95
129
  const config = { configurable: { model: "gpt-4" } };
96
130
 
97
131
  const { rerender } = renderHook(
@@ -107,16 +141,16 @@ describe("useCoAgent config synchronization", () => {
107
141
  );
108
142
 
109
143
  // Clear the initial calls
110
- mockSetCoagentStatesWithRef.mockClear();
144
+ mockSetProperties.mockClear();
111
145
 
112
- // Re-render with same config
146
+ // Re-render with same config reference
113
147
  rerender({ config });
114
148
 
115
- // Should not have called setCoagentStatesWithRef
116
- expect(mockSetCoagentStatesWithRef).not.toHaveBeenCalled();
149
+ // Should not have called setProperties
150
+ expect(mockSetProperties).not.toHaveBeenCalled();
117
151
  });
118
152
 
119
- it("should handle backward compatibility with configurable prop", () => {
153
+ it("should handle backward compatibility with configurable prop", async () => {
120
154
  const { rerender } = renderHook(
121
155
  ({ configurable }) =>
122
156
  useCoAgent({
@@ -130,23 +164,32 @@ describe("useCoAgent config synchronization", () => {
130
164
  );
131
165
 
132
166
  // Clear the initial calls
133
- mockSetCoagentStatesWithRef.mockClear();
167
+ mockSetProperties.mockClear();
134
168
 
135
169
  // Change configurable prop
136
170
  rerender({ configurable: { model: "gpt-4o" } });
137
171
 
138
- // Should have called setCoagentStatesWithRef
139
- expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
172
+ // Wait for effect to complete and verify setProperties was called
173
+ await waitFor(() => {
174
+ expect(mockSetProperties).toHaveBeenCalledWith({
175
+ configurable: { model: "gpt-4o" },
176
+ });
177
+ });
140
178
  });
141
179
 
142
- it("should update config while preserving other state properties", () => {
143
- let capturedUpdater: any = null;
180
+ it("should not call setProperties when both config and configurable are undefined", () => {
181
+ renderHook(() =>
182
+ useCoAgent({
183
+ name: "test-agent",
184
+ initialState: { count: 0 },
185
+ }),
186
+ );
144
187
 
145
- mockSetCoagentStatesWithRef.mockImplementation((updater) => {
146
- capturedUpdater = updater;
147
- return updater;
148
- });
188
+ // Should not have called setProperties
189
+ expect(mockSetProperties).not.toHaveBeenCalled();
190
+ });
149
191
 
192
+ it("should handle deeply nested config changes", async () => {
150
193
  const { rerender } = renderHook(
151
194
  ({ config }) =>
152
195
  useCoAgent({
@@ -155,137 +198,154 @@ describe("useCoAgent config synchronization", () => {
155
198
  config,
156
199
  }),
157
200
  {
158
- initialProps: { config: { configurable: { model: "gpt-4" } } },
201
+ initialProps: {
202
+ config: {
203
+ configurable: {
204
+ model: "gpt-4",
205
+ settings: { temperature: 0.5 },
206
+ },
207
+ },
208
+ },
159
209
  },
160
210
  );
161
211
 
162
- // Clear the initial calls and reset captured updater
163
- mockSetCoagentStatesWithRef.mockClear();
164
- capturedUpdater = null;
165
-
166
- // Change config
167
- rerender({ config: { configurable: { model: "gpt-4o" } } });
168
-
169
- // Should have called setCoagentStatesWithRef
170
- expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
171
- expect(capturedUpdater).toBeTruthy();
212
+ // Clear the initial calls
213
+ mockSetProperties.mockClear();
172
214
 
173
- // Test the updater function behavior
174
- const prevState = {
175
- "test-agent": {
176
- name: "test-agent",
177
- state: { count: 5 },
178
- config: { configurable: { model: "gpt-4" } },
179
- running: true,
180
- active: true,
181
- threadId: "thread-123",
182
- nodeName: "test-node",
183
- runId: "run-456",
215
+ // Change nested config
216
+ rerender({
217
+ config: {
218
+ configurable: {
219
+ model: "gpt-4",
220
+ settings: { temperature: 0.7 }, // Only nested property changed
221
+ },
184
222
  },
185
- };
186
-
187
- const newState = capturedUpdater(prevState);
223
+ });
188
224
 
189
- // Verify the state is updated correctly
190
- expect(newState).toEqual({
191
- "test-agent": {
192
- name: "test-agent",
193
- state: { count: 5 }, // State preserved
194
- config: { configurable: { model: "gpt-4o" } }, // Config updated
195
- running: true, // Other properties preserved
196
- active: true,
197
- threadId: "thread-123",
198
- nodeName: "test-node",
199
- runId: "run-456",
200
- },
225
+ // Wait for effect to complete and verify setProperties was called
226
+ await waitFor(() => {
227
+ expect(mockSetProperties).toHaveBeenCalledWith({
228
+ configurable: {
229
+ model: "gpt-4",
230
+ settings: { temperature: 0.7 },
231
+ },
232
+ });
201
233
  });
202
234
  });
203
235
 
204
- it("should create new agent state when agent doesn't exist", () => {
205
- let capturedUpdater: any = null;
236
+ describe("State Management", () => {
237
+ // Helper to create mock subscriber params
238
+ const createMockParams = (stateOverride: any = {}) => ({
239
+ messages: [],
240
+ state: stateOverride,
241
+ agent: mockAgent as any,
242
+ input: {} as any,
243
+ });
244
+
245
+ it("should initialize agent state via onRunInitialized event", () => {
246
+ // Set agent to have NO state (empty object)
247
+ mockAgent.state = {} as any;
248
+
249
+ renderHook(() =>
250
+ useCoAgent({
251
+ name: "test-agent",
252
+ initialState: { count: 42 },
253
+ }),
254
+ );
255
+
256
+ // Verify subscription was created
257
+ expect(mockSubscribe).toHaveBeenCalled();
258
+ expect(lastSubscriber).toBeTruthy();
259
+
260
+ // Clear any initial state calls
261
+ mockSetState.mockClear();
262
+
263
+ // Trigger onRunInitialized with no run state
264
+ lastSubscriber?.onRunInitialized?.(createMockParams({}));
265
+
266
+ // Should set state to initialState
267
+ expect(mockSetState).toHaveBeenCalledWith({ count: 42 });
206
268
 
207
- mockSetCoagentStatesWithRef.mockImplementation((updater) => {
208
- capturedUpdater = updater;
209
- return updater;
269
+ // Reset agent state
270
+ mockAgent.state = { count: 0 };
210
271
  });
211
272
 
212
- const { rerender } = renderHook(
213
- ({ config }) =>
273
+ it("should preserve existing agent state on onRunInitialized", () => {
274
+ // Set agent to have existing state
275
+ mockAgent.state = { count: 100 };
276
+
277
+ renderHook(() =>
214
278
  useCoAgent({
215
279
  name: "test-agent",
216
- initialState: { count: 0 },
217
- config,
280
+ initialState: { count: 42 },
218
281
  }),
219
- {
220
- initialProps: { config: { configurable: { model: "gpt-4" } } },
221
- },
222
- );
282
+ );
223
283
 
224
- // Clear the initial calls and reset captured updater
225
- mockSetCoagentStatesWithRef.mockClear();
226
- capturedUpdater = null;
284
+ // Clear any initial state calls
285
+ mockSetState.mockClear();
227
286
 
228
- // Change config
229
- rerender({ config: { configurable: { model: "gpt-4o" } } });
287
+ // Trigger onRunInitialized with no new state
288
+ lastSubscriber?.onRunInitialized?.(createMockParams({}));
289
+
290
+ // Should NOT override existing state
291
+ expect(mockSetState).not.toHaveBeenCalled();
292
+
293
+ // Reset agent state
294
+ mockAgent.state = { count: 0 };
295
+ });
230
296
 
231
- // Should have called setCoagentStatesWithRef
232
- expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
233
- expect(capturedUpdater).toBeTruthy();
297
+ it("should prioritize run state over initialState", () => {
298
+ renderHook(() =>
299
+ useCoAgent({
300
+ name: "test-agent",
301
+ initialState: { count: 42 },
302
+ }),
303
+ );
234
304
 
235
- // Test the updater function behavior with empty previous state
236
- const prevState = {}; // No existing agent state
305
+ // Clear any initial state calls
306
+ mockSetState.mockClear();
237
307
 
238
- const newState = capturedUpdater(prevState);
308
+ // Trigger onRunInitialized with state from the run
309
+ lastSubscriber?.onRunInitialized?.(createMockParams({ count: 999 }));
239
310
 
240
- // Verify the state creates a new agent state with default values
241
- expect(newState).toEqual({
242
- "test-agent": {
243
- name: "test-agent",
244
- state: { count: 0 }, // Uses initialState
245
- config: { configurable: { model: "gpt-4o" } }, // New config
246
- running: false, // Default values
247
- active: false,
248
- threadId: undefined,
249
- nodeName: undefined,
250
- runId: undefined,
251
- },
311
+ // Should use run state, not initialState
312
+ expect(mockSetState).toHaveBeenCalledWith({ count: 999 });
252
313
  });
253
- });
254
314
 
255
- it("should handle deeply nested config changes", () => {
256
- const { rerender } = renderHook(
257
- ({ config }) =>
315
+ it("should handle setState with object updates", () => {
316
+ const { result } = renderHook(() =>
258
317
  useCoAgent({
259
318
  name: "test-agent",
260
319
  initialState: { count: 0 },
261
- config,
262
320
  }),
263
- {
264
- initialProps: {
265
- config: {
266
- configurable: {
267
- model: "gpt-4",
268
- settings: { temperature: 0.5 },
269
- },
270
- },
271
- },
272
- },
273
- );
321
+ );
274
322
 
275
- // Clear the initial calls
276
- mockSetCoagentStatesWithRef.mockClear();
323
+ // Update state with object
324
+ result.current.setState({ count: 5 });
277
325
 
278
- // Change nested config
279
- rerender({
280
- config: {
281
- configurable: {
282
- model: "gpt-4",
283
- settings: { temperature: 0.7 }, // Only nested property changed
284
- },
285
- },
326
+ // Should merge with existing state
327
+ expect(mockSetState).toHaveBeenCalledWith({ count: 5 });
286
328
  });
287
329
 
288
- // Should detect the nested change
289
- expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
330
+ it("should handle setState with function updaters", () => {
331
+ // Set current agent state
332
+ mockAgent.state = { count: 10 };
333
+
334
+ const { result } = renderHook(() =>
335
+ useCoAgent({
336
+ name: "test-agent",
337
+ initialState: { count: 0 },
338
+ }),
339
+ );
340
+
341
+ // Update state with function
342
+ result.current.setState((prev) => ({ count: (prev?.count || 0) + 5 }));
343
+
344
+ // Should call function with current state and set result
345
+ expect(mockSetState).toHaveBeenCalledWith({ count: 15 });
346
+
347
+ // Reset agent state
348
+ mockAgent.state = { count: 0 };
349
+ });
290
350
  });
291
351
  });