@copilotkit/react-core 1.10.6 → 1.50.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/dist/chunk-24SCZAB4.mjs +143 -0
  2. package/dist/chunk-24SCZAB4.mjs.map +1 -0
  3. package/dist/chunk-36KQV2NA.mjs +1 -0
  4. package/dist/{chunk-U7QULEVO.mjs → chunk-3GURHDG7.mjs} +3 -3
  5. package/dist/{chunk-4BHIQMN6.mjs → chunk-3R423LZT.mjs} +6 -5
  6. package/dist/{chunk-4BHIQMN6.mjs.map → chunk-3R423LZT.mjs.map} +1 -1
  7. package/dist/chunk-5X5DJRQQ.mjs +71 -0
  8. package/dist/chunk-5X5DJRQQ.mjs.map +1 -0
  9. package/dist/{chunk-N4WEHORG.mjs → chunk-6PUNP7CD.mjs} +4 -4
  10. package/dist/chunk-6PUNP7CD.mjs.map +1 -0
  11. package/dist/chunk-7BYHZLPL.mjs +32 -0
  12. package/dist/chunk-7BYHZLPL.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-A6NKSGH3.mjs +1 -0
  16. package/dist/{chunk-GT5WI3AF.mjs → chunk-BR5YEYZJ.mjs} +7 -9
  17. package/dist/chunk-BR5YEYZJ.mjs.map +1 -0
  18. package/dist/chunk-CB7CRBDG.mjs +48 -0
  19. package/dist/chunk-CB7CRBDG.mjs.map +1 -0
  20. package/dist/chunk-CYDWEPFL.mjs +1 -0
  21. package/dist/{chunk-BBUQMG45.mjs → chunk-D3QSYDJR.mjs} +3 -3
  22. package/dist/{chunk-BBUQMG45.mjs.map → chunk-D3QSYDJR.mjs.map} +1 -1
  23. package/dist/chunk-DCHSCK62.mjs +549 -0
  24. package/dist/chunk-DCHSCK62.mjs.map +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-F555TVE4.mjs +33 -0
  28. package/dist/chunk-F555TVE4.mjs.map +1 -0
  29. package/dist/{chunk-C6IANC2R.mjs → chunk-FBD24VEH.mjs} +7 -43
  30. package/dist/chunk-FBD24VEH.mjs.map +1 -0
  31. package/dist/chunk-FD6FGKYY.mjs +1 -0
  32. package/dist/chunk-FDOMAPJY.mjs +59 -0
  33. package/dist/chunk-FDOMAPJY.mjs.map +1 -0
  34. package/dist/{chunk-X7MJWPI7.mjs → chunk-GMI4KO4X.mjs} +8 -6
  35. package/dist/{chunk-X7MJWPI7.mjs.map → chunk-GMI4KO4X.mjs.map} +1 -1
  36. package/dist/chunk-IUSKVYUI.mjs +13 -0
  37. package/dist/chunk-IUSKVYUI.mjs.map +1 -0
  38. package/dist/chunk-JD7BAH7U.mjs +1 -0
  39. package/dist/{chunk-N5HOP3PG.mjs → chunk-JRT5BJF3.mjs} +2 -2
  40. package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
  41. package/dist/{chunk-DXEQPN43.mjs → chunk-LHKZJ2ND.mjs} +3 -3
  42. package/dist/chunk-NB2FKV2V.mjs +1 -0
  43. package/dist/chunk-NBK4KBLX.mjs +54 -0
  44. package/dist/chunk-NBK4KBLX.mjs.map +1 -0
  45. package/dist/chunk-NG26QEGF.mjs +46 -0
  46. package/dist/chunk-NG26QEGF.mjs.map +1 -0
  47. package/dist/chunk-NROJOTQP.mjs +163 -0
  48. package/dist/chunk-NROJOTQP.mjs.map +1 -0
  49. package/dist/{chunk-MGWRDFBE.mjs → chunk-OVYFRPSN.mjs} +2 -2
  50. package/dist/{chunk-MQYWH4E6.mjs → chunk-QU6NONOD.mjs} +2 -2
  51. package/dist/chunk-R4MR43UQ.mjs +101 -0
  52. package/dist/chunk-R4MR43UQ.mjs.map +1 -0
  53. package/dist/chunk-SPCZTZCY.mjs +1 -0
  54. package/dist/chunk-SPCZTZCY.mjs.map +1 -0
  55. package/dist/chunk-TXI72QHK.mjs +80 -0
  56. package/dist/chunk-TXI72QHK.mjs.map +1 -0
  57. package/dist/chunk-UJBV5GAG.mjs +767 -0
  58. package/dist/chunk-UJBV5GAG.mjs.map +1 -0
  59. package/dist/{chunk-OKCYPO4I.mjs → chunk-WMJVBMUX.mjs} +3 -3
  60. package/dist/{chunk-EUX2P2E7.mjs → chunk-WVLHXIFP.mjs} +11 -9
  61. package/dist/chunk-WVLHXIFP.mjs.map +1 -0
  62. package/dist/{chunk-5FHSUKQL.mjs → chunk-YYN33GSG.mjs} +5 -2
  63. package/dist/chunk-YYN33GSG.mjs.map +1 -0
  64. package/dist/chunk-ZVF5Q6IH.mjs +29 -0
  65. package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
  66. package/dist/components/CopilotListeners.d.ts +3 -0
  67. package/dist/components/CopilotListeners.js +234 -0
  68. package/dist/components/CopilotListeners.js.map +1 -0
  69. package/dist/components/CopilotListeners.mjs +14 -0
  70. package/dist/components/CopilotListeners.mjs.map +1 -0
  71. package/dist/components/copilot-provider/copilot-messages.js +14 -48
  72. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  73. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  74. package/dist/components/copilot-provider/copilotkit-props.d.ts +9 -2
  75. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  76. package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
  77. package/dist/components/copilot-provider/copilotkit.js +528 -370
  78. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  79. package/dist/components/copilot-provider/copilotkit.mjs +17 -12
  80. package/dist/components/copilot-provider/index.d.ts +2 -1
  81. package/dist/components/copilot-provider/index.js +528 -370
  82. package/dist/components/copilot-provider/index.js.map +1 -1
  83. package/dist/components/copilot-provider/index.mjs +18 -12
  84. package/dist/components/dev-console/console-trigger.js +10 -8
  85. package/dist/components/dev-console/console-trigger.js.map +1 -1
  86. package/dist/components/dev-console/console-trigger.mjs +4 -4
  87. package/dist/components/dev-console/developer-console-modal.js +10 -8
  88. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  89. package/dist/components/dev-console/developer-console-modal.mjs +3 -3
  90. package/dist/components/error-boundary/error-boundary.d.ts +7 -7
  91. package/dist/components/error-boundary/error-boundary.js +3 -3
  92. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  93. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  94. package/dist/components/error-boundary/error-utils.d.ts +1 -1
  95. package/dist/components/error-boundary/error-utils.js +3 -3
  96. package/dist/components/error-boundary/error-utils.js.map +1 -1
  97. package/dist/components/error-boundary/error-utils.mjs +1 -1
  98. package/dist/components/index.d.ts +2 -1
  99. package/dist/components/index.js +528 -370
  100. package/dist/components/index.js.map +1 -1
  101. package/dist/components/index.mjs +19 -12
  102. package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
  103. package/dist/components/toast/toast-provider.d.ts +3 -3
  104. package/dist/components/usage-banner.d.ts +2 -2
  105. package/dist/context/coagent-state-renders-context.d.ts +24 -0
  106. package/dist/context/coagent-state-renders-context.js +91 -0
  107. package/dist/context/coagent-state-renders-context.js.map +1 -0
  108. package/dist/context/coagent-state-renders-context.mjs +12 -0
  109. package/dist/context/coagent-state-renders-context.mjs.map +1 -0
  110. package/dist/context/copilot-context.d.ts +1 -1
  111. package/dist/context/copilot-context.js +10 -8
  112. package/dist/context/copilot-context.js.map +1 -1
  113. package/dist/context/copilot-context.mjs +1 -1
  114. package/dist/context/copilot-messages-context.d.ts +18 -11
  115. package/dist/context/copilot-messages-context.js.map +1 -1
  116. package/dist/context/copilot-messages-context.mjs +1 -1
  117. package/dist/context/index.d.ts +6 -2
  118. package/dist/context/index.js +110 -10
  119. package/dist/context/index.js.map +1 -1
  120. package/dist/context/index.mjs +20 -4
  121. package/dist/context/threads-context.d.ts +16 -0
  122. package/dist/context/threads-context.js +59 -0
  123. package/dist/context/threads-context.js.map +1 -0
  124. package/dist/context/threads-context.mjs +12 -0
  125. package/dist/context/threads-context.mjs.map +1 -0
  126. package/dist/{copilot-context-cf9de848.d.ts → copilot-context-1cd70a3f.d.ts} +36 -32
  127. package/dist/hooks/index.d.ts +9 -6
  128. package/dist/hooks/index.js +1445 -1839
  129. package/dist/hooks/index.js.map +1 -1
  130. package/dist/hooks/index.mjs +47 -56
  131. package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
  132. package/dist/hooks/use-coagent-state-render-bridge.js +211 -0
  133. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
  134. package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
  135. package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
  136. package/dist/hooks/use-coagent-state-render.js +31 -20
  137. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  138. package/dist/hooks/use-coagent-state-render.mjs +3 -2
  139. package/dist/hooks/use-coagent.d.ts +2 -14
  140. package/dist/hooks/use-coagent.js +109 -1906
  141. package/dist/hooks/use-coagent.js.map +1 -1
  142. package/dist/hooks/use-coagent.mjs +1 -30
  143. package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
  144. package/dist/hooks/use-configure-chat-suggestions.js +210 -0
  145. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
  146. package/dist/hooks/use-configure-chat-suggestions.mjs +13 -0
  147. package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
  148. package/dist/hooks/use-copilot-action.d.ts +8 -45
  149. package/dist/hooks/use-copilot-action.js +207 -349
  150. package/dist/hooks/use-copilot-action.js.map +1 -1
  151. package/dist/hooks/use-copilot-action.mjs +4 -5
  152. package/dist/hooks/use-copilot-additional-instructions.js +10 -8
  153. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  154. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  155. package/dist/hooks/use-copilot-authenticated-action.js +224 -248
  156. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  157. package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
  158. package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -10
  159. package/dist/hooks/use-copilot-chat-headless_c.js +973 -1369
  160. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  161. package/dist/hooks/use-copilot-chat-headless_c.mjs +12 -22
  162. package/dist/hooks/use-copilot-chat.d.ts +2 -10
  163. package/dist/hooks/use-copilot-chat.js +967 -1388
  164. package/dist/hooks/use-copilot-chat.js.map +1 -1
  165. package/dist/hooks/use-copilot-chat.mjs +12 -22
  166. package/dist/hooks/use-copilot-chat_internal.d.ts +38 -14
  167. package/dist/hooks/use-copilot-chat_internal.js +965 -1362
  168. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  169. package/dist/hooks/use-copilot-chat_internal.mjs +13 -23
  170. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  171. package/dist/hooks/use-copilot-readable.js +6 -157
  172. package/dist/hooks/use-copilot-readable.js.map +1 -1
  173. package/dist/hooks/use-copilot-readable.mjs +1 -2
  174. package/dist/hooks/use-default-tool.js +204 -349
  175. package/dist/hooks/use-default-tool.js.map +1 -1
  176. package/dist/hooks/use-default-tool.mjs +5 -6
  177. package/dist/hooks/use-flat-category-store.js +4 -1
  178. package/dist/hooks/use-flat-category-store.js.map +1 -1
  179. package/dist/hooks/use-flat-category-store.mjs +1 -1
  180. package/dist/hooks/use-frontend-tool.d.ts +3 -3
  181. package/dist/hooks/use-frontend-tool.js +30 -370
  182. package/dist/hooks/use-frontend-tool.js.map +1 -1
  183. package/dist/hooks/use-frontend-tool.mjs +1 -6
  184. package/dist/hooks/use-human-in-the-loop.d.ts +4 -3
  185. package/dist/hooks/use-human-in-the-loop.js +61 -393
  186. package/dist/hooks/use-human-in-the-loop.js.map +1 -1
  187. package/dist/hooks/use-human-in-the-loop.mjs +1 -6
  188. package/dist/hooks/use-langgraph-interrupt-render.d.ts +3 -2
  189. package/dist/hooks/use-langgraph-interrupt-render.js +92 -36
  190. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  191. package/dist/hooks/use-langgraph-interrupt-render.mjs +6 -4
  192. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  193. package/dist/hooks/use-langgraph-interrupt.js +24 -1642
  194. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  195. package/dist/hooks/use-langgraph-interrupt.mjs +2 -23
  196. package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
  197. package/dist/hooks/use-lazy-tool-renderer.js +53 -0
  198. package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
  199. package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
  200. package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
  201. package/dist/hooks/use-make-copilot-document-readable.js +11 -9
  202. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  203. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  204. package/dist/hooks/use-render-tool-call.d.ts +7 -6
  205. package/dist/hooks/use-render-tool-call.js +36 -386
  206. package/dist/hooks/use-render-tool-call.js.map +1 -1
  207. package/dist/hooks/use-render-tool-call.mjs +1 -6
  208. package/dist/index.d.ts +11 -6
  209. package/dist/index.js +1841 -2056
  210. package/dist/index.js.map +1 -1
  211. package/dist/index.mjs +82 -63
  212. package/dist/lib/copilot-task.d.ts +1 -1
  213. package/dist/lib/copilot-task.js +1 -0
  214. package/dist/lib/copilot-task.js.map +1 -1
  215. package/dist/lib/copilot-task.mjs +20 -13
  216. package/dist/lib/index.d.ts +1 -1
  217. package/dist/lib/index.js +1 -0
  218. package/dist/lib/index.js.map +1 -1
  219. package/dist/lib/index.mjs +20 -13
  220. package/dist/setupTests.d.ts +2 -2
  221. package/dist/types/frontend-action.d.ts +5 -5
  222. package/dist/types/index.d.ts +4 -0
  223. package/dist/types/index.js.map +1 -1
  224. package/dist/types/index.mjs +2 -1
  225. package/dist/types/interrupt-action.d.ts +1 -1
  226. package/dist/types/interrupt-action.js.map +1 -1
  227. package/dist/types/interrupt-action.mjs +1 -0
  228. package/dist/utils/index.d.ts +0 -12
  229. package/dist/utils/index.js +6 -325
  230. package/dist/utils/index.js.map +1 -1
  231. package/dist/utils/index.mjs +3 -23
  232. package/dist/utils/utils.js.map +1 -1
  233. package/dist/v2/index.d.ts +2 -0
  234. package/dist/v2/index.js +27 -0
  235. package/dist/v2/index.js.map +1 -0
  236. package/dist/v2/index.mjs +4 -0
  237. package/dist/v2/index.mjs.map +1 -0
  238. package/package.json +34 -23
  239. package/src/components/CopilotListeners.tsx +82 -0
  240. package/src/components/copilot-provider/copilot-messages.tsx +46 -47
  241. package/src/components/copilot-provider/copilotkit-props.tsx +8 -1
  242. package/src/components/copilot-provider/copilotkit.tsx +177 -144
  243. package/src/components/error-boundary/error-utils.tsx +3 -3
  244. package/src/context/coagent-state-renders-context.tsx +76 -0
  245. package/src/context/copilot-context.tsx +21 -21
  246. package/src/context/copilot-messages-context.tsx +3 -3
  247. package/src/context/index.ts +8 -0
  248. package/src/context/threads-context.tsx +41 -0
  249. package/src/hooks/index.ts +7 -3
  250. package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
  251. package/src/hooks/use-coagent-state-render.ts +4 -7
  252. package/src/hooks/use-coagent.ts +129 -249
  253. package/src/hooks/use-configure-chat-suggestions.tsx +85 -0
  254. package/src/hooks/use-copilot-action.ts +88 -199
  255. package/src/hooks/use-copilot-chat-headless_c.ts +2 -1
  256. package/src/hooks/use-copilot-chat.ts +4 -1
  257. package/src/hooks/use-copilot-chat_internal.ts +349 -258
  258. package/src/hooks/use-copilot-readable.ts +6 -26
  259. package/src/hooks/use-flat-category-store.ts +4 -3
  260. package/src/hooks/use-frontend-tool.ts +67 -8
  261. package/src/hooks/use-human-in-the-loop.ts +111 -13
  262. package/src/hooks/use-langgraph-interrupt-render.ts +90 -40
  263. package/src/hooks/use-langgraph-interrupt.ts +18 -47
  264. package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
  265. package/src/hooks/use-make-copilot-document-readable.ts +1 -1
  266. package/src/hooks/use-render-tool-call.ts +73 -13
  267. package/src/types/index.ts +1 -0
  268. package/src/types/interrupt-action.ts +8 -4
  269. package/src/utils/index.ts +0 -3
  270. package/src/utils/utils.ts +7 -0
  271. package/src/v2/index.ts +2 -0
  272. package/src/v2/styles.css +1 -0
  273. package/tsup.config.ts +1 -1
  274. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  275. package/dist/chunk-6GPVUMBU.mjs +0 -13
  276. package/dist/chunk-6GPVUMBU.mjs.map +0 -1
  277. package/dist/chunk-AKR2SSUJ.mjs +0 -22
  278. package/dist/chunk-AKR2SSUJ.mjs.map +0 -1
  279. package/dist/chunk-C6IANC2R.mjs.map +0 -1
  280. package/dist/chunk-CI4KD357.mjs +0 -804
  281. package/dist/chunk-CI4KD357.mjs.map +0 -1
  282. package/dist/chunk-DZTU6PGS.mjs +0 -1
  283. package/dist/chunk-EUX2P2E7.mjs.map +0 -1
  284. package/dist/chunk-EVVO67QO.mjs +0 -25
  285. package/dist/chunk-EVVO67QO.mjs.map +0 -1
  286. package/dist/chunk-GT5WI3AF.mjs.map +0 -1
  287. package/dist/chunk-HDOG2RTM.mjs +0 -37
  288. package/dist/chunk-HDOG2RTM.mjs.map +0 -1
  289. package/dist/chunk-N4WEHORG.mjs.map +0 -1
  290. package/dist/chunk-OT5NHMEC.mjs +0 -723
  291. package/dist/chunk-OT5NHMEC.mjs.map +0 -1
  292. package/dist/chunk-QHCLJODF.mjs +0 -332
  293. package/dist/chunk-QHCLJODF.mjs.map +0 -1
  294. package/dist/chunk-QV5SBF2S.mjs +0 -239
  295. package/dist/chunk-QV5SBF2S.mjs.map +0 -1
  296. package/dist/chunk-T3376SZS.mjs +0 -142
  297. package/dist/chunk-T3376SZS.mjs.map +0 -1
  298. package/dist/chunk-U3DQY67T.mjs +0 -71
  299. package/dist/chunk-U3DQY67T.mjs.map +0 -1
  300. package/dist/chunk-YPBKY4KY.mjs +0 -1
  301. package/dist/chunk-YPSGKPDA.mjs +0 -1
  302. package/dist/chunk-ZLQVRPDS.mjs.map +0 -1
  303. package/dist/chunk-ZVOLWJCY.mjs +0 -47
  304. package/dist/chunk-ZVOLWJCY.mjs.map +0 -1
  305. package/dist/hooks/use-chat.d.ts +0 -145
  306. package/dist/hooks/use-chat.js +0 -1129
  307. package/dist/hooks/use-chat.js.map +0 -1
  308. package/dist/hooks/use-chat.mjs +0 -14
  309. package/dist/index-1f5b66ac.d.ts +0 -36
  310. package/dist/utils/extract.d.ts +0 -43
  311. package/dist/utils/extract.js +0 -208
  312. package/dist/utils/extract.js.map +0 -1
  313. package/dist/utils/extract.mjs +0 -25
  314. package/dist/utils/suggestions.d.ts +0 -11
  315. package/dist/utils/suggestions.js +0 -343
  316. package/dist/utils/suggestions.js.map +0 -1
  317. package/dist/utils/suggestions.mjs +0 -25
  318. package/src/hooks/use-chat.ts +0 -1142
  319. package/src/utils/extract.ts +0 -215
  320. package/src/utils/suggestions.ts +0 -208
  321. /package/dist/{chunk-DZTU6PGS.mjs.map → chunk-36KQV2NA.mjs.map} +0 -0
  322. /package/dist/{chunk-U7QULEVO.mjs.map → chunk-3GURHDG7.mjs.map} +0 -0
  323. /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-A6NKSGH3.mjs.map} +0 -0
  324. /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
  325. /package/dist/{hooks/use-chat.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
  326. /package/dist/{utils/extract.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
  327. /package/dist/{chunk-N5HOP3PG.mjs.map → chunk-JRT5BJF3.mjs.map} +0 -0
  328. /package/dist/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
  329. /package/dist/{chunk-DXEQPN43.mjs.map → chunk-LHKZJ2ND.mjs.map} +0 -0
  330. /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
  331. /package/dist/{chunk-MGWRDFBE.mjs.map → chunk-OVYFRPSN.mjs.map} +0 -0
  332. /package/dist/{chunk-MQYWH4E6.mjs.map → chunk-QU6NONOD.mjs.map} +0 -0
  333. /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-WMJVBMUX.mjs.map} +0 -0
@@ -1,215 +0,0 @@
1
- import {
2
- Action,
3
- COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
4
- MappedParameterTypes,
5
- Parameter,
6
- actionParametersToJsonSchema,
7
- } from "@copilotkit/shared";
8
- import {
9
- ActionExecutionMessage,
10
- Message,
11
- Role,
12
- TextMessage,
13
- convertGqlOutputToMessages,
14
- CopilotRequestType,
15
- ForwardedParametersInput,
16
- } from "@copilotkit/runtime-client-gql";
17
- import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
18
- import { defaultCopilotContextCategories } from "../components";
19
- import { CopilotRuntimeClient } from "@copilotkit/runtime-client-gql";
20
- import {
21
- convertMessagesToGqlInput,
22
- filterAgentStateMessages,
23
- } from "@copilotkit/runtime-client-gql";
24
-
25
- interface InitialState<T extends Parameter[] | [] = []> {
26
- status: "initial";
27
- args: Partial<MappedParameterTypes<T>>;
28
- }
29
-
30
- interface InProgressState<T extends Parameter[] | [] = []> {
31
- status: "inProgress";
32
- args: Partial<MappedParameterTypes<T>>;
33
- }
34
-
35
- interface CompleteState<T extends Parameter[] | [] = []> {
36
- status: "complete";
37
- args: MappedParameterTypes<T>;
38
- }
39
-
40
- type StreamHandlerArgs<T extends Parameter[] | [] = []> =
41
- | InitialState<T>
42
- | InProgressState<T>
43
- | CompleteState<T>;
44
-
45
- interface ExtractOptions<T extends Parameter[]> {
46
- context: CopilotContextParams & CopilotMessagesContextParams;
47
- instructions: string;
48
- parameters: T;
49
- include?: IncludeOptions;
50
- data?: any;
51
- abortSignal?: AbortSignal;
52
- stream?: (args: StreamHandlerArgs<T>) => void;
53
- requestType?: CopilotRequestType;
54
- forwardedParameters?: ForwardedParametersInput;
55
- }
56
-
57
- interface IncludeOptions {
58
- readable?: boolean;
59
- messages?: boolean;
60
- }
61
-
62
- export async function extract<const T extends Parameter[]>({
63
- context,
64
- instructions,
65
- parameters,
66
- include,
67
- data,
68
- abortSignal,
69
- stream,
70
- requestType = CopilotRequestType.Task,
71
- forwardedParameters,
72
- }: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {
73
- const { messages } = context;
74
-
75
- const action: Action<any> = {
76
- name: "extract",
77
- description: instructions,
78
- parameters,
79
- handler: (args: any) => {},
80
- };
81
-
82
- const includeReadable = include?.readable ?? false;
83
- const includeMessages = include?.messages ?? false;
84
-
85
- let contextString = "";
86
-
87
- if (data) {
88
- contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
89
- }
90
-
91
- if (includeReadable) {
92
- contextString += context.getContextString([], defaultCopilotContextCategories);
93
- }
94
-
95
- const systemMessage: Message = new TextMessage({
96
- content: makeSystemMessage(contextString, instructions),
97
- role: Role.System,
98
- });
99
-
100
- const instructionsMessage: Message = new TextMessage({
101
- content: makeInstructionsMessage(instructions),
102
- role: Role.User,
103
- });
104
-
105
- const response = context.runtimeClient.asStream(
106
- context.runtimeClient.generateCopilotResponse({
107
- data: {
108
- frontend: {
109
- actions: [
110
- {
111
- name: action.name,
112
- description: action.description || "",
113
- jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
114
- },
115
- ],
116
- url: window.location.href,
117
- },
118
-
119
- messages: convertMessagesToGqlInput(
120
- includeMessages
121
- ? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]
122
- : [systemMessage, instructionsMessage],
123
- ),
124
- metadata: {
125
- requestType: requestType,
126
- },
127
- forwardedParameters: {
128
- ...(forwardedParameters ?? {}),
129
- toolChoice: "function",
130
- toolChoiceFunctionName: action.name,
131
- },
132
- },
133
- properties: context.copilotApiConfig.properties,
134
- signal: abortSignal,
135
- }),
136
- );
137
-
138
- const reader = response.getReader();
139
-
140
- let isInitial = true;
141
-
142
- let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;
143
-
144
- while (true) {
145
- const { done, value } = await reader.read();
146
-
147
- if (done) {
148
- break;
149
- }
150
-
151
- if (abortSignal?.aborted) {
152
- throw new Error("Aborted");
153
- }
154
-
155
- actionExecutionMessage = convertGqlOutputToMessages(
156
- value.generateCopilotResponse.messages,
157
- ).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;
158
-
159
- if (!actionExecutionMessage) {
160
- continue;
161
- }
162
-
163
- stream?.({
164
- status: isInitial ? "initial" : "inProgress",
165
- args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,
166
- });
167
-
168
- isInitial = false;
169
- }
170
-
171
- if (!actionExecutionMessage) {
172
- throw new Error("extract() failed: No function call occurred");
173
- }
174
-
175
- stream?.({
176
- status: "complete",
177
- args: actionExecutionMessage.arguments as MappedParameterTypes<T>,
178
- });
179
-
180
- return actionExecutionMessage.arguments as MappedParameterTypes<T>;
181
- }
182
-
183
- // We need to put this in a user message since some LLMs need
184
- // at least one user message to function
185
- function makeInstructionsMessage(instructions: string): string {
186
- return `
187
- The user has given you the following task to complete:
188
-
189
- \`\`\`
190
- ${instructions}
191
- \`\`\`
192
-
193
- Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
194
- `;
195
- }
196
-
197
- function makeSystemMessage(contextString: string, instructions: string): string {
198
- return `
199
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
200
-
201
- Help 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.
202
- Always be polite and respectful, and prefer brevity over verbosity.
203
-
204
- The user has provided you with the following context:
205
- \`\`\`
206
- ${contextString}
207
- \`\`\`
208
-
209
- They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
210
-
211
- Please assist them as best you can.
212
-
213
- This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
214
- `;
215
- }
@@ -1,208 +0,0 @@
1
- /**
2
- * Suggestions utility functions for CopilotKit
3
- *
4
- * This module handles the generation of chat suggestions with optimized error handling
5
- * and streaming validation to prevent infinite retry loops and console spam.
6
- */
7
-
8
- import { extract } from "./extract";
9
- import { actionParametersToJsonSchema } from "@copilotkit/shared";
10
- import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
11
- import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
12
- import { CopilotChatSuggestionConfiguration } from "../types";
13
-
14
- export interface SuggestionItem {
15
- title: string;
16
- message: string;
17
- partial?: boolean;
18
- className?: string;
19
- }
20
-
21
- export const reloadSuggestions = async (
22
- context: CopilotContextParams & CopilotMessagesContextParams,
23
- chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
24
- setCurrentSuggestions: (suggestions: SuggestionItem[]) => void,
25
- abortControllerRef: React.MutableRefObject<AbortController | null>,
26
- ): Promise<void> => {
27
- const abortController = abortControllerRef.current;
28
-
29
- // Early abort check
30
- if (abortController?.signal.aborted) {
31
- return;
32
- }
33
-
34
- // Abort-aware suggestion setter with safety checks to prevent race conditions
35
- const setSuggestionsIfNotAborted = (suggestions: SuggestionItem[]) => {
36
- if (!abortController?.signal.aborted && abortControllerRef.current === abortController) {
37
- setCurrentSuggestions(suggestions);
38
- }
39
- };
40
-
41
- try {
42
- const tools = JSON.stringify(
43
- Object.values(context.actions).map((action) => ({
44
- name: action.name,
45
- description: action.description,
46
- jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
47
- })),
48
- );
49
-
50
- const allSuggestions: SuggestionItem[] = [];
51
- let hasSuccessfulSuggestions = false;
52
- let hasErrors = false; // Track if any errors occurred
53
- let lastError: Error | null = null; // Track the last error for better error reporting
54
-
55
- // Get enabled configurations
56
- const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
57
- (config) => config.instructions && config.instructions.trim().length > 0,
58
- );
59
-
60
- if (enabledConfigs.length === 0) {
61
- return;
62
- }
63
-
64
- // Clear existing suggestions
65
- setSuggestionsIfNotAborted([]);
66
-
67
- // Generate suggestions for each configuration
68
- for (const config of enabledConfigs) {
69
- // Check if aborted before each configuration
70
- if (abortController?.signal.aborted) {
71
- setSuggestionsIfNotAborted([]);
72
- return;
73
- }
74
-
75
- try {
76
- const result = await extract({
77
- context,
78
- instructions:
79
- "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
80
- data: `${config.instructions}\n\nAvailable tools: ${tools}\n\n`,
81
- requestType: CopilotRequestType.Task,
82
- parameters: [
83
- {
84
- name: "suggestions",
85
- type: "object[]",
86
- attributes: [
87
- {
88
- name: "title",
89
- description:
90
- "The title of the suggestion. This is shown as a button and should be short.",
91
- type: "string",
92
- },
93
- {
94
- name: "message",
95
- description:
96
- "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
97
- type: "string",
98
- },
99
- ],
100
- },
101
- ],
102
- include: {
103
- messages: true,
104
- readable: true,
105
- },
106
- abortSignal: abortController?.signal,
107
- stream: ({ status, args }: { status: string; args: any }) => {
108
- // Check abort status in stream callback
109
- if (abortController?.signal.aborted) {
110
- return;
111
- }
112
-
113
- const suggestions = args.suggestions || [];
114
- const newSuggestions: SuggestionItem[] = [];
115
-
116
- for (let i = 0; i < suggestions.length; i++) {
117
- // Respect max suggestions limit
118
- if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
119
- break;
120
- }
121
-
122
- const suggestion = suggestions[i];
123
-
124
- // Skip completely empty or invalid objects during streaming
125
- if (!suggestion || typeof suggestion !== "object") {
126
- continue;
127
- }
128
-
129
- const { title, message } = suggestion;
130
-
131
- // During streaming, be permissive but require at least a meaningful title
132
- const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
133
- const hasValidMessage =
134
- message && typeof message === "string" && message.trim().length > 0;
135
-
136
- // During streaming, we need at least a title to show something useful
137
- if (!hasValidTitle) {
138
- continue;
139
- }
140
-
141
- // Mark as partial if this is the last suggestion and streaming isn't complete
142
- const partial = i === suggestions.length - 1 && status !== "complete";
143
-
144
- newSuggestions.push({
145
- title: title.trim(),
146
- message: hasValidMessage ? message.trim() : "", // Use title as fallback
147
- partial,
148
- className: config.className,
149
- });
150
- }
151
-
152
- // Update suggestions with current batch
153
- setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
154
- },
155
- });
156
-
157
- // Process final results with strict validation
158
- if (result?.suggestions && Array.isArray(result.suggestions)) {
159
- const validSuggestions = result.suggestions
160
- .filter(
161
- (suggestion: any) =>
162
- suggestion &&
163
- typeof suggestion.title === "string" &&
164
- suggestion.title.trim().length > 0,
165
- )
166
- .map((suggestion: any) => ({
167
- title: suggestion.title.trim(),
168
- message:
169
- suggestion.message &&
170
- typeof suggestion.message === "string" &&
171
- suggestion.message.trim()
172
- ? suggestion.message.trim()
173
- : suggestion.title.trim(),
174
- }));
175
-
176
- if (validSuggestions.length > 0) {
177
- allSuggestions.push(...validSuggestions);
178
- hasSuccessfulSuggestions = true;
179
- }
180
- }
181
- } catch (error) {
182
- // Simple error handling - just continue with next config, don't log here
183
- hasErrors = true;
184
- lastError = error instanceof Error ? error : new Error(String(error));
185
- }
186
- }
187
-
188
- // Display any successful suggestions we got
189
- if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
190
- // Remove duplicates based on message content
191
- const uniqueSuggestions = allSuggestions.filter(
192
- (suggestion, index, self) =>
193
- index === self.findIndex((s) => s.message === suggestion.message),
194
- );
195
-
196
- setSuggestionsIfNotAborted(uniqueSuggestions);
197
- } else if (hasErrors) {
198
- // If we had errors but no successful suggestions, throw an error with details
199
- const errorMessage = lastError
200
- ? lastError.message
201
- : "Failed to generate suggestions due to API errors";
202
- throw new Error(errorMessage);
203
- }
204
- } catch (error) {
205
- // Top-level error handler - re-throw to allow caller to handle
206
- throw error;
207
- }
208
- };