@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.
- package/dist/chunk-24SCZAB4.mjs +143 -0
- package/dist/chunk-24SCZAB4.mjs.map +1 -0
- package/dist/chunk-36KQV2NA.mjs +1 -0
- package/dist/{chunk-U7QULEVO.mjs → chunk-3GURHDG7.mjs} +3 -3
- package/dist/{chunk-4BHIQMN6.mjs → chunk-3R423LZT.mjs} +6 -5
- package/dist/{chunk-4BHIQMN6.mjs.map → chunk-3R423LZT.mjs.map} +1 -1
- package/dist/chunk-5X5DJRQQ.mjs +71 -0
- package/dist/chunk-5X5DJRQQ.mjs.map +1 -0
- package/dist/{chunk-N4WEHORG.mjs → chunk-6PUNP7CD.mjs} +4 -4
- package/dist/chunk-6PUNP7CD.mjs.map +1 -0
- package/dist/chunk-7BYHZLPL.mjs +32 -0
- package/dist/chunk-7BYHZLPL.mjs.map +1 -0
- package/dist/chunk-7DTB7S5V.mjs +83 -0
- package/dist/chunk-7DTB7S5V.mjs.map +1 -0
- package/dist/chunk-A6NKSGH3.mjs +1 -0
- package/dist/{chunk-GT5WI3AF.mjs → chunk-BR5YEYZJ.mjs} +7 -9
- package/dist/chunk-BR5YEYZJ.mjs.map +1 -0
- package/dist/chunk-CB7CRBDG.mjs +48 -0
- package/dist/chunk-CB7CRBDG.mjs.map +1 -0
- package/dist/chunk-CYDWEPFL.mjs +1 -0
- package/dist/{chunk-BBUQMG45.mjs → chunk-D3QSYDJR.mjs} +3 -3
- package/dist/{chunk-BBUQMG45.mjs.map → chunk-D3QSYDJR.mjs.map} +1 -1
- package/dist/chunk-DCHSCK62.mjs +549 -0
- package/dist/chunk-DCHSCK62.mjs.map +1 -0
- package/dist/{chunk-ZLQVRPDS.mjs → chunk-DMLQZG75.mjs} +1 -1
- package/dist/chunk-DMLQZG75.mjs.map +1 -0
- package/dist/chunk-F555TVE4.mjs +33 -0
- package/dist/chunk-F555TVE4.mjs.map +1 -0
- package/dist/{chunk-C6IANC2R.mjs → chunk-FBD24VEH.mjs} +7 -43
- package/dist/chunk-FBD24VEH.mjs.map +1 -0
- package/dist/chunk-FD6FGKYY.mjs +1 -0
- package/dist/chunk-FDOMAPJY.mjs +59 -0
- package/dist/chunk-FDOMAPJY.mjs.map +1 -0
- package/dist/{chunk-X7MJWPI7.mjs → chunk-GMI4KO4X.mjs} +8 -6
- package/dist/{chunk-X7MJWPI7.mjs.map → chunk-GMI4KO4X.mjs.map} +1 -1
- package/dist/chunk-IUSKVYUI.mjs +13 -0
- package/dist/chunk-IUSKVYUI.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/{chunk-N5HOP3PG.mjs → chunk-JRT5BJF3.mjs} +2 -2
- package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
- package/dist/{chunk-DXEQPN43.mjs → chunk-LHKZJ2ND.mjs} +3 -3
- package/dist/chunk-NB2FKV2V.mjs +1 -0
- package/dist/chunk-NBK4KBLX.mjs +54 -0
- package/dist/chunk-NBK4KBLX.mjs.map +1 -0
- package/dist/chunk-NG26QEGF.mjs +46 -0
- package/dist/chunk-NG26QEGF.mjs.map +1 -0
- package/dist/chunk-NROJOTQP.mjs +163 -0
- package/dist/chunk-NROJOTQP.mjs.map +1 -0
- package/dist/{chunk-MGWRDFBE.mjs → chunk-OVYFRPSN.mjs} +2 -2
- package/dist/{chunk-MQYWH4E6.mjs → chunk-QU6NONOD.mjs} +2 -2
- package/dist/chunk-R4MR43UQ.mjs +101 -0
- package/dist/chunk-R4MR43UQ.mjs.map +1 -0
- package/dist/chunk-SPCZTZCY.mjs +1 -0
- package/dist/chunk-SPCZTZCY.mjs.map +1 -0
- package/dist/chunk-TXI72QHK.mjs +80 -0
- package/dist/chunk-TXI72QHK.mjs.map +1 -0
- package/dist/chunk-UJBV5GAG.mjs +767 -0
- package/dist/chunk-UJBV5GAG.mjs.map +1 -0
- package/dist/{chunk-OKCYPO4I.mjs → chunk-WMJVBMUX.mjs} +3 -3
- package/dist/{chunk-EUX2P2E7.mjs → chunk-WVLHXIFP.mjs} +11 -9
- package/dist/chunk-WVLHXIFP.mjs.map +1 -0
- package/dist/{chunk-5FHSUKQL.mjs → chunk-YYN33GSG.mjs} +5 -2
- package/dist/chunk-YYN33GSG.mjs.map +1 -0
- package/dist/chunk-ZVF5Q6IH.mjs +29 -0
- package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
- package/dist/components/CopilotListeners.d.ts +3 -0
- package/dist/components/CopilotListeners.js +234 -0
- package/dist/components/CopilotListeners.js.map +1 -0
- package/dist/components/CopilotListeners.mjs +14 -0
- package/dist/components/CopilotListeners.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +14 -48
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +9 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +528 -370
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +17 -12
- package/dist/components/copilot-provider/index.d.ts +2 -1
- package/dist/components/copilot-provider/index.js +528 -370
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +18 -12
- package/dist/components/dev-console/console-trigger.js +10 -8
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +4 -4
- package/dist/components/dev-console/developer-console-modal.js +10 -8
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +3 -3
- package/dist/components/error-boundary/error-boundary.d.ts +7 -7
- package/dist/components/error-boundary/error-boundary.js +3 -3
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/error-boundary/error-utils.d.ts +1 -1
- package/dist/components/error-boundary/error-utils.js +3 -3
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +528 -370
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +19 -12
- package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
- package/dist/components/toast/toast-provider.d.ts +3 -3
- package/dist/components/usage-banner.d.ts +2 -2
- package/dist/context/coagent-state-renders-context.d.ts +24 -0
- package/dist/context/coagent-state-renders-context.js +91 -0
- package/dist/context/coagent-state-renders-context.js.map +1 -0
- package/dist/context/coagent-state-renders-context.mjs +12 -0
- package/dist/context/coagent-state-renders-context.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +10 -8
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/copilot-messages-context.d.ts +18 -11
- package/dist/context/copilot-messages-context.js.map +1 -1
- package/dist/context/copilot-messages-context.mjs +1 -1
- package/dist/context/index.d.ts +6 -2
- package/dist/context/index.js +110 -10
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +20 -4
- package/dist/context/threads-context.d.ts +16 -0
- package/dist/context/threads-context.js +59 -0
- package/dist/context/threads-context.js.map +1 -0
- package/dist/context/threads-context.mjs +12 -0
- package/dist/context/threads-context.mjs.map +1 -0
- package/dist/{copilot-context-cf9de848.d.ts → copilot-context-1cd70a3f.d.ts} +36 -32
- package/dist/hooks/index.d.ts +9 -6
- package/dist/hooks/index.js +1445 -1839
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +47 -56
- package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +211 -0
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
- package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
- package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
- package/dist/hooks/use-coagent-state-render.js +31 -20
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -2
- package/dist/hooks/use-coagent.d.ts +2 -14
- package/dist/hooks/use-coagent.js +109 -1906
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +1 -30
- package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
- package/dist/hooks/use-configure-chat-suggestions.js +210 -0
- package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-configure-chat-suggestions.mjs +13 -0
- package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +8 -45
- package/dist/hooks/use-copilot-action.js +207 -349
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -5
- package/dist/hooks/use-copilot-additional-instructions.js +10 -8
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +224 -248
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -10
- package/dist/hooks/use-copilot-chat-headless_c.js +973 -1369
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +12 -22
- package/dist/hooks/use-copilot-chat.d.ts +2 -10
- package/dist/hooks/use-copilot-chat.js +967 -1388
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +12 -22
- package/dist/hooks/use-copilot-chat_internal.d.ts +38 -14
- package/dist/hooks/use-copilot-chat_internal.js +965 -1362
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +13 -23
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +6 -157
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -2
- package/dist/hooks/use-default-tool.js +204 -349
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +5 -6
- package/dist/hooks/use-flat-category-store.js +4 -1
- package/dist/hooks/use-flat-category-store.js.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +1 -1
- package/dist/hooks/use-frontend-tool.d.ts +3 -3
- package/dist/hooks/use-frontend-tool.js +30 -370
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -6
- package/dist/hooks/use-human-in-the-loop.d.ts +4 -3
- package/dist/hooks/use-human-in-the-loop.js +61 -393
- package/dist/hooks/use-human-in-the-loop.js.map +1 -1
- package/dist/hooks/use-human-in-the-loop.mjs +1 -6
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +3 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +92 -36
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +6 -4
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +24 -1642
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -23
- package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
- package/dist/hooks/use-lazy-tool-renderer.js +53 -0
- package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
- package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
- package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.js +11 -9
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-render-tool-call.d.ts +7 -6
- package/dist/hooks/use-render-tool-call.js +36 -386
- package/dist/hooks/use-render-tool-call.js.map +1 -1
- package/dist/hooks/use-render-tool-call.mjs +1 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +1841 -2056
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -63
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +1 -0
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +20 -13
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +20 -13
- package/dist/setupTests.d.ts +2 -2
- package/dist/types/frontend-action.d.ts +5 -5
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/types/interrupt-action.mjs +1 -0
- package/dist/utils/index.d.ts +0 -12
- package/dist/utils/index.js +6 -325
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +3 -23
- package/dist/utils/utils.js.map +1 -1
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.js +27 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/index.mjs +4 -0
- package/dist/v2/index.mjs.map +1 -0
- package/package.json +34 -23
- package/src/components/CopilotListeners.tsx +82 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -47
- package/src/components/copilot-provider/copilotkit-props.tsx +8 -1
- package/src/components/copilot-provider/copilotkit.tsx +177 -144
- package/src/components/error-boundary/error-utils.tsx +3 -3
- package/src/context/coagent-state-renders-context.tsx +76 -0
- package/src/context/copilot-context.tsx +21 -21
- package/src/context/copilot-messages-context.tsx +3 -3
- package/src/context/index.ts +8 -0
- package/src/context/threads-context.tsx +41 -0
- package/src/hooks/index.ts +7 -3
- package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
- package/src/hooks/use-coagent-state-render.ts +4 -7
- package/src/hooks/use-coagent.ts +129 -249
- package/src/hooks/use-configure-chat-suggestions.tsx +85 -0
- package/src/hooks/use-copilot-action.ts +88 -199
- package/src/hooks/use-copilot-chat-headless_c.ts +2 -1
- package/src/hooks/use-copilot-chat.ts +4 -1
- package/src/hooks/use-copilot-chat_internal.ts +349 -258
- package/src/hooks/use-copilot-readable.ts +6 -26
- package/src/hooks/use-flat-category-store.ts +4 -3
- package/src/hooks/use-frontend-tool.ts +67 -8
- package/src/hooks/use-human-in-the-loop.ts +111 -13
- package/src/hooks/use-langgraph-interrupt-render.ts +90 -40
- package/src/hooks/use-langgraph-interrupt.ts +18 -47
- package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
- package/src/hooks/use-make-copilot-document-readable.ts +1 -1
- package/src/hooks/use-render-tool-call.ts +73 -13
- package/src/types/index.ts +1 -0
- package/src/types/interrupt-action.ts +8 -4
- package/src/utils/index.ts +0 -3
- package/src/utils/utils.ts +7 -0
- package/src/v2/index.ts +2 -0
- package/src/v2/styles.css +1 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-5FHSUKQL.mjs.map +0 -1
- package/dist/chunk-6GPVUMBU.mjs +0 -13
- package/dist/chunk-6GPVUMBU.mjs.map +0 -1
- package/dist/chunk-AKR2SSUJ.mjs +0 -22
- package/dist/chunk-AKR2SSUJ.mjs.map +0 -1
- package/dist/chunk-C6IANC2R.mjs.map +0 -1
- package/dist/chunk-CI4KD357.mjs +0 -804
- package/dist/chunk-CI4KD357.mjs.map +0 -1
- package/dist/chunk-DZTU6PGS.mjs +0 -1
- package/dist/chunk-EUX2P2E7.mjs.map +0 -1
- package/dist/chunk-EVVO67QO.mjs +0 -25
- package/dist/chunk-EVVO67QO.mjs.map +0 -1
- package/dist/chunk-GT5WI3AF.mjs.map +0 -1
- package/dist/chunk-HDOG2RTM.mjs +0 -37
- package/dist/chunk-HDOG2RTM.mjs.map +0 -1
- package/dist/chunk-N4WEHORG.mjs.map +0 -1
- package/dist/chunk-OT5NHMEC.mjs +0 -723
- package/dist/chunk-OT5NHMEC.mjs.map +0 -1
- package/dist/chunk-QHCLJODF.mjs +0 -332
- package/dist/chunk-QHCLJODF.mjs.map +0 -1
- package/dist/chunk-QV5SBF2S.mjs +0 -239
- package/dist/chunk-QV5SBF2S.mjs.map +0 -1
- package/dist/chunk-T3376SZS.mjs +0 -142
- package/dist/chunk-T3376SZS.mjs.map +0 -1
- package/dist/chunk-U3DQY67T.mjs +0 -71
- package/dist/chunk-U3DQY67T.mjs.map +0 -1
- package/dist/chunk-YPBKY4KY.mjs +0 -1
- package/dist/chunk-YPSGKPDA.mjs +0 -1
- package/dist/chunk-ZLQVRPDS.mjs.map +0 -1
- package/dist/chunk-ZVOLWJCY.mjs +0 -47
- package/dist/chunk-ZVOLWJCY.mjs.map +0 -1
- package/dist/hooks/use-chat.d.ts +0 -145
- package/dist/hooks/use-chat.js +0 -1129
- package/dist/hooks/use-chat.js.map +0 -1
- package/dist/hooks/use-chat.mjs +0 -14
- package/dist/index-1f5b66ac.d.ts +0 -36
- package/dist/utils/extract.d.ts +0 -43
- package/dist/utils/extract.js +0 -208
- package/dist/utils/extract.js.map +0 -1
- package/dist/utils/extract.mjs +0 -25
- package/dist/utils/suggestions.d.ts +0 -11
- package/dist/utils/suggestions.js +0 -343
- package/dist/utils/suggestions.js.map +0 -1
- package/dist/utils/suggestions.mjs +0 -25
- package/src/hooks/use-chat.ts +0 -1142
- package/src/utils/extract.ts +0 -215
- package/src/utils/suggestions.ts +0 -208
- /package/dist/{chunk-DZTU6PGS.mjs.map → chunk-36KQV2NA.mjs.map} +0 -0
- /package/dist/{chunk-U7QULEVO.mjs.map → chunk-3GURHDG7.mjs.map} +0 -0
- /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-A6NKSGH3.mjs.map} +0 -0
- /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
- /package/dist/{hooks/use-chat.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
- /package/dist/{utils/extract.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
- /package/dist/{chunk-N5HOP3PG.mjs.map → chunk-JRT5BJF3.mjs.map} +0 -0
- /package/dist/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
- /package/dist/{chunk-DXEQPN43.mjs.map → chunk-LHKZJ2ND.mjs.map} +0 -0
- /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
- /package/dist/{chunk-MGWRDFBE.mjs.map → chunk-OVYFRPSN.mjs.map} +0 -0
- /package/dist/{chunk-MQYWH4E6.mjs.map → chunk-QU6NONOD.mjs.map} +0 -0
- /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-WMJVBMUX.mjs.map} +0 -0
|
@@ -130,218 +130,107 @@
|
|
|
130
130
|
*
|
|
131
131
|
* This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.
|
|
132
132
|
*/
|
|
133
|
-
import {
|
|
134
|
-
import {
|
|
135
|
-
import {
|
|
136
|
-
import {
|
|
137
|
-
import {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} from "../types/frontend-action";
|
|
144
|
-
import { useToast } from "../components/toast/toast-provider";
|
|
145
|
-
|
|
146
|
-
// We implement useCopilotAction dependency handling so that
|
|
147
|
-
// the developer has the option to not provide any dependencies.
|
|
148
|
-
// In this case, we assume they want to update the handler on each rerender.
|
|
149
|
-
// To avoid getting stuck in an infinite loop, we update the handler directly,
|
|
150
|
-
// skipping React state updates.
|
|
151
|
-
// This is ok in this case, because the handler is not part of any UI that
|
|
152
|
-
// needs to be updated.
|
|
153
|
-
// useCallback, useMemo or other memoization techniques are not suitable here,
|
|
154
|
-
// because they will cause a infinite rerender loop.
|
|
155
|
-
export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
133
|
+
import { useEffect, useRef, useState } from "react";
|
|
134
|
+
import { Parameter } from "@copilotkit/shared";
|
|
135
|
+
import { CatchAllFrontendAction, FrontendAction } from "../types/frontend-action";
|
|
136
|
+
import { useFrontendTool, UseFrontendToolArgs } from "./use-frontend-tool";
|
|
137
|
+
import { useRenderToolCall, UseRenderToolCallArgs } from "./use-render-tool-call";
|
|
138
|
+
import { useHumanInTheLoop, UseHumanInTheLoopArgs } from "./use-human-in-the-loop";
|
|
139
|
+
import { useCopilotContext } from "../context";
|
|
140
|
+
|
|
141
|
+
// Helper to determine which component and action config to use
|
|
142
|
+
function getActionConfig<const T extends Parameter[] | [] = []>(
|
|
156
143
|
action: FrontendAction<T> | CatchAllFrontendAction,
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// clone the action to avoid mutating the original object
|
|
166
|
-
action = { ...action };
|
|
167
|
-
|
|
168
|
-
// const { currentlyActivatingHitlActionMessageIdRef } = useCopilotContext() as any; // <-- REMOVE THIS FOR NOW
|
|
144
|
+
) {
|
|
145
|
+
if (action.name === "*") {
|
|
146
|
+
return {
|
|
147
|
+
type: "render" as const,
|
|
148
|
+
action: action as UseRenderToolCallArgs<T>,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
169
151
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// remove the renderAndWait function from the action
|
|
181
|
-
action.renderAndWait = undefined;
|
|
182
|
-
action.renderAndWaitForResponse = undefined;
|
|
152
|
+
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
153
|
+
let render = action.render;
|
|
154
|
+
if (!render && "renderAndWaitForResponse" in action) {
|
|
155
|
+
// @ts-expect-error -- renderAndWaitForResponse is deprecated, but we need to support it for backwards compatibility
|
|
156
|
+
render = action.renderAndWaitForResponse;
|
|
157
|
+
}
|
|
158
|
+
if (!render && "renderAndWait" in action) {
|
|
159
|
+
// @ts-expect-error -- renderAndWait is deprecated, but we need to support it for backwards compatibility
|
|
160
|
+
render = action.renderAndWait;
|
|
161
|
+
}
|
|
183
162
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
activatingMessageIdRef.current = id;
|
|
163
|
+
return {
|
|
164
|
+
type: "hitl" as const,
|
|
165
|
+
action: { ...action, render } as UseHumanInTheLoopArgs<T>,
|
|
188
166
|
};
|
|
167
|
+
}
|
|
189
168
|
|
|
190
|
-
|
|
191
|
-
action.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let reject: (error: any) => void;
|
|
196
|
-
const promise = new Promise<any>((resolvePromise, rejectPromise) => {
|
|
197
|
-
resolve = resolvePromise;
|
|
198
|
-
reject = rejectPromise;
|
|
199
|
-
});
|
|
200
|
-
renderAndWaitRef.current = {
|
|
201
|
-
promise,
|
|
202
|
-
resolve: resolve!,
|
|
203
|
-
reject: reject!,
|
|
204
|
-
messageId: currentActivatingId,
|
|
169
|
+
if ("available" in action) {
|
|
170
|
+
if (action.available === "enabled" || action.available === "remote") {
|
|
171
|
+
return {
|
|
172
|
+
type: "frontend" as const,
|
|
173
|
+
action: action as UseFrontendToolArgs<T>,
|
|
205
174
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// add a render function that will be called when the action is rendered
|
|
212
|
-
action.render = ((props: ActionRenderProps<T> & { messageId?: string }): React.ReactElement => {
|
|
213
|
-
const currentRenderMessageId = props.messageId;
|
|
214
|
-
// For renderAndWaitForResponse, the 'executing' state might be set by use-chat before
|
|
215
|
-
// this specific action instance's handler (and thus its promise) is ready.
|
|
216
|
-
// This logic adjusts the status to 'inProgress' if the current render
|
|
217
|
-
// isn't for the actively processing HITL action, preventing premature interaction.
|
|
218
|
-
let status = props.status;
|
|
219
|
-
if (props.status === "executing") {
|
|
220
|
-
if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
|
|
221
|
-
status = "inProgress";
|
|
222
|
-
} else if (
|
|
223
|
-
renderAndWaitRef.current.messageId !== currentRenderMessageId &&
|
|
224
|
-
activatingMessageIdRef.current !== currentRenderMessageId
|
|
225
|
-
) {
|
|
226
|
-
status = "inProgress";
|
|
227
|
-
}
|
|
228
|
-
// If conditions met, status remains 'executing'
|
|
229
|
-
}
|
|
230
|
-
// Create type safe waitProps based on whether T extends empty array or not
|
|
231
|
-
const waitProps = {
|
|
232
|
-
status,
|
|
233
|
-
args: props.args,
|
|
234
|
-
result: props.result,
|
|
235
|
-
// handler and respond should only be provided if this is the truly active instance
|
|
236
|
-
// and its promise infrastructure is ready.
|
|
237
|
-
handler:
|
|
238
|
-
status === "executing" &&
|
|
239
|
-
renderAndWaitRef.current &&
|
|
240
|
-
renderAndWaitRef.current.messageId === currentRenderMessageId
|
|
241
|
-
? renderAndWaitRef.current!.resolve
|
|
242
|
-
: undefined,
|
|
243
|
-
respond:
|
|
244
|
-
status === "executing" &&
|
|
245
|
-
renderAndWaitRef.current &&
|
|
246
|
-
renderAndWaitRef.current.messageId === currentRenderMessageId
|
|
247
|
-
? renderAndWaitRef.current!.resolve
|
|
248
|
-
: undefined,
|
|
249
|
-
} as T extends [] ? ActionRenderPropsNoArgsWait<T> : ActionRenderPropsWait<T>;
|
|
250
|
-
|
|
251
|
-
// Type guard to check if renderAndWait is for no args case
|
|
252
|
-
const isNoArgsRenderWait = (
|
|
253
|
-
_fn:
|
|
254
|
-
| ((props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement)
|
|
255
|
-
| ((props: ActionRenderPropsWait<T>) => React.ReactElement),
|
|
256
|
-
): _fn is (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement => {
|
|
257
|
-
return action.parameters?.length === 0;
|
|
175
|
+
}
|
|
176
|
+
if (action.available === "frontend" || action.available === "disabled") {
|
|
177
|
+
return {
|
|
178
|
+
type: "render" as const,
|
|
179
|
+
action: action as UseRenderToolCallArgs<T>,
|
|
258
180
|
};
|
|
259
|
-
|
|
260
|
-
// Safely call renderAndWait with correct props type
|
|
261
|
-
if (renderAndWait) {
|
|
262
|
-
if (isNoArgsRenderWait(renderAndWait)) {
|
|
263
|
-
return renderAndWait(waitProps as ActionRenderPropsNoArgsWait<T>);
|
|
264
|
-
} else {
|
|
265
|
-
return renderAndWait(waitProps as ActionRenderPropsWait<T>);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Return empty Fragment instead of null
|
|
270
|
-
return createElement(Fragment);
|
|
271
|
-
}) as any;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// If the developer doesn't provide dependencies, we assume they want to
|
|
275
|
-
// update handler and render function when the action object changes.
|
|
276
|
-
// This ensures that any captured variables in the handler are up to date.
|
|
277
|
-
if (dependencies === undefined) {
|
|
278
|
-
if (actions[idRef.current]) {
|
|
279
|
-
// catch all actions don't have a handler
|
|
280
|
-
if (isFrontendAction(action)) {
|
|
281
|
-
actions[idRef.current].handler = action.handler as any;
|
|
282
|
-
}
|
|
283
|
-
if (typeof action.render === "function") {
|
|
284
|
-
if (chatComponentsCache.current !== null) {
|
|
285
|
-
// TODO: using as any here because the type definitions are getting to tricky
|
|
286
|
-
// not wasting time on this now - we know the types are compatible
|
|
287
|
-
chatComponentsCache.current.actions[action.name] = action.render as any;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
181
|
}
|
|
291
182
|
}
|
|
292
183
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (hasDuplicate) {
|
|
299
|
-
addToast({
|
|
300
|
-
type: "warning",
|
|
301
|
-
message: `Found an already registered action with name ${action.name}.`,
|
|
302
|
-
id: `dup-action-${action.name}`,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}, [actions]);
|
|
306
|
-
|
|
307
|
-
useEffect(() => {
|
|
308
|
-
setAction(idRef.current, action as any);
|
|
309
|
-
if (chatComponentsCache.current !== null && action.render !== undefined) {
|
|
310
|
-
// see comment about type safety above
|
|
311
|
-
chatComponentsCache.current.actions[action.name] = action.render as any;
|
|
312
|
-
}
|
|
313
|
-
return () => {
|
|
314
|
-
// NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.
|
|
315
|
-
// This is because we currently don't have access to the messages array in CopilotContext.
|
|
316
|
-
// UPDATE: We now have access, we should remove the entry if not referenced by any message.
|
|
317
|
-
removeAction(idRef.current);
|
|
184
|
+
if ("handler" in action) {
|
|
185
|
+
return {
|
|
186
|
+
type: "frontend" as const,
|
|
187
|
+
action: action as UseFrontendToolArgs<T>,
|
|
318
188
|
};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
isFrontendAction(action) ? action.description : undefined,
|
|
323
|
-
action.name,
|
|
324
|
-
isFrontendAction(action) ? action.disabled : undefined,
|
|
325
|
-
isFrontendAction(action) ? action.available : undefined,
|
|
326
|
-
// This should be faster than deep equality checking
|
|
327
|
-
// In addition, all major JS engines guarantee the order of object keys
|
|
328
|
-
JSON.stringify(isFrontendAction(action) ? action.parameters : []),
|
|
329
|
-
// include render only if it's a string
|
|
330
|
-
typeof action.render === "string" ? action.render : undefined,
|
|
331
|
-
// dependencies set by the developer
|
|
332
|
-
...(dependencies || []),
|
|
333
|
-
]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
throw new Error("Invalid action configuration");
|
|
334
192
|
}
|
|
335
193
|
|
|
336
|
-
|
|
194
|
+
/**
|
|
195
|
+
* useCopilotAction is a legacy hook maintained for backwards compatibility.
|
|
196
|
+
*
|
|
197
|
+
* To avoid violating React's Rules of Hooks (which prohibit conditional hook calls),
|
|
198
|
+
* we use a registration pattern:
|
|
199
|
+
* 1. This hook registers the action configuration with the CopilotContext
|
|
200
|
+
* 2. A renderer component in CopilotKit actually renders the appropriate hook wrapper
|
|
201
|
+
* 3. React properly manages hook state since components are rendered, not conditionally called
|
|
202
|
+
*
|
|
203
|
+
* This allows action types to change between renders without corrupting React's hook state.
|
|
204
|
+
*/
|
|
205
|
+
export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
337
206
|
action: FrontendAction<T> | CatchAllFrontendAction,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
207
|
+
dependencies?: any[],
|
|
208
|
+
): void {
|
|
209
|
+
const [initialActionConfig] = useState(getActionConfig(action));
|
|
210
|
+
const currentActionConfig = getActionConfig(action);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Calling hooks conditionally violates React's Rules of Hooks. This rule exists because
|
|
214
|
+
* React maintains the call stack for hooks like useEffect or useState, and conditionally
|
|
215
|
+
* calling a hook would result in inconsistent call stacks between renders.
|
|
216
|
+
*
|
|
217
|
+
* Unfortunately, useCopilotAction _has_ to conditionally call a hook based on the
|
|
218
|
+
* supplied parameters. In order to avoid breaking React's call stack tracking, while
|
|
219
|
+
* breaking the Rule of Hooks, we use a ref to store the initial action configuration
|
|
220
|
+
* and throw an error if the _configuration_ changes such that we would call a different hook.
|
|
221
|
+
*/
|
|
222
|
+
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
223
|
+
throw new Error("Action configuration changed between renders");
|
|
224
|
+
}
|
|
341
225
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
226
|
+
switch (currentActionConfig.type) {
|
|
227
|
+
case "render":
|
|
228
|
+
return useRenderToolCall(currentActionConfig.action, dependencies);
|
|
229
|
+
case "hitl":
|
|
230
|
+
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
231
|
+
case "frontend":
|
|
232
|
+
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
233
|
+
default:
|
|
234
|
+
throw new Error("Invalid action configuration");
|
|
235
|
+
}
|
|
347
236
|
}
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
import { useEffect } from "react";
|
|
162
162
|
import { useCopilotContext } from "../context/copilot-context";
|
|
163
163
|
import {
|
|
164
|
-
|
|
164
|
+
useCopilotChatInternal,
|
|
165
165
|
defaultSystemMessage,
|
|
166
166
|
UseCopilotChatOptions as UseCopilotChatOptions_c,
|
|
167
167
|
UseCopilotChatReturn as UseCopilotChatReturn_c,
|
|
@@ -188,6 +188,7 @@ const createNonFunctionalReturn = (): UseCopilotChatReturn_c => ({
|
|
|
188
188
|
stopGeneration: () => {},
|
|
189
189
|
reset: () => {},
|
|
190
190
|
isLoading: false,
|
|
191
|
+
isAvailable: false,
|
|
191
192
|
runChatCompletion: async () => [],
|
|
192
193
|
mcpServers: [],
|
|
193
194
|
setMcpServers: () => {},
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
|
|
76
76
|
import {
|
|
77
77
|
UseCopilotChatOptions,
|
|
78
|
-
|
|
78
|
+
useCopilotChatInternal,
|
|
79
79
|
UseCopilotChatReturn as UseCopilotChatReturnInternal,
|
|
80
80
|
} from "./use-copilot-chat_internal";
|
|
81
81
|
|
|
@@ -100,6 +100,7 @@ export type UseCopilotChatReturn = Omit<
|
|
|
100
100
|
*
|
|
101
101
|
* **Open Source Friendly** - Works without requiring a `publicApiKey`.
|
|
102
102
|
*/
|
|
103
|
+
// TODO: Do we need this? If so, does it work properly? test.
|
|
103
104
|
export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotChatReturn {
|
|
104
105
|
const {
|
|
105
106
|
visibleMessages,
|
|
@@ -108,6 +109,7 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
|
|
|
108
109
|
stopGeneration,
|
|
109
110
|
reset,
|
|
110
111
|
isLoading,
|
|
112
|
+
isAvailable,
|
|
111
113
|
runChatCompletion,
|
|
112
114
|
mcpServers,
|
|
113
115
|
setMcpServers,
|
|
@@ -120,6 +122,7 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
|
|
|
120
122
|
stopGeneration,
|
|
121
123
|
reset,
|
|
122
124
|
isLoading,
|
|
125
|
+
isAvailable,
|
|
123
126
|
runChatCompletion,
|
|
124
127
|
mcpServers,
|
|
125
128
|
setMcpServers,
|