@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
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,91 +1,81 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
useLangGraphInterrupt
|
|
4
|
-
} from "../chunk-U3DQY67T.mjs";
|
|
1
|
+
import "../chunk-A6NKSGH3.mjs";
|
|
5
2
|
import {
|
|
6
3
|
useMakeCopilotDocumentReadable
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import {
|
|
9
|
-
useRenderToolCall
|
|
10
|
-
} from "../chunk-AKR2SSUJ.mjs";
|
|
4
|
+
} from "../chunk-D3QSYDJR.mjs";
|
|
11
5
|
import {
|
|
12
6
|
useCopilotReadable
|
|
13
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-IUSKVYUI.mjs";
|
|
14
8
|
import {
|
|
15
|
-
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import {
|
|
18
|
-
useFrontendTool
|
|
19
|
-
} from "../chunk-6GPVUMBU.mjs";
|
|
9
|
+
useCopilotRuntimeClient
|
|
10
|
+
} from "../chunk-6ESSSQ7Q.mjs";
|
|
20
11
|
import {
|
|
21
|
-
|
|
22
|
-
} from "../chunk-
|
|
12
|
+
useDefaultTool
|
|
13
|
+
} from "../chunk-QU6NONOD.mjs";
|
|
23
14
|
import {
|
|
24
|
-
|
|
25
|
-
} from "../chunk-
|
|
15
|
+
useLangGraphInterrupt
|
|
16
|
+
} from "../chunk-7BYHZLPL.mjs";
|
|
26
17
|
import {
|
|
27
|
-
runAgent,
|
|
28
|
-
startAgent,
|
|
29
|
-
stopAgent,
|
|
30
18
|
useCoAgent
|
|
31
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-24SCZAB4.mjs";
|
|
32
20
|
import {
|
|
33
21
|
useCopilotAdditionalInstructions
|
|
34
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-OVYFRPSN.mjs";
|
|
35
23
|
import {
|
|
36
24
|
useCopilotAuthenticatedAction_c
|
|
37
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-3GURHDG7.mjs";
|
|
38
26
|
import {
|
|
39
27
|
useCopilotAction
|
|
40
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-TXI72QHK.mjs";
|
|
41
29
|
import {
|
|
42
|
-
|
|
43
|
-
} from "../chunk-
|
|
30
|
+
useRenderToolCall
|
|
31
|
+
} from "../chunk-NBK4KBLX.mjs";
|
|
32
|
+
import {
|
|
33
|
+
useFrontendTool
|
|
34
|
+
} from "../chunk-NG26QEGF.mjs";
|
|
44
35
|
import {
|
|
45
|
-
|
|
46
|
-
} from "../chunk-
|
|
36
|
+
useHumanInTheLoop
|
|
37
|
+
} from "../chunk-7DTB7S5V.mjs";
|
|
38
|
+
import {
|
|
39
|
+
useCopilotChatHeadless_c
|
|
40
|
+
} from "../chunk-3R423LZT.mjs";
|
|
47
41
|
import {
|
|
48
42
|
useCopilotChat
|
|
49
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-GMI4KO4X.mjs";
|
|
44
|
+
import {
|
|
45
|
+
useCopilotChatInternal
|
|
46
|
+
} from "../chunk-UJBV5GAG.mjs";
|
|
47
|
+
import {
|
|
48
|
+
useLazyToolRenderer
|
|
49
|
+
} from "../chunk-ZVF5Q6IH.mjs";
|
|
50
50
|
import {
|
|
51
51
|
useLangGraphInterruptRender
|
|
52
|
-
} from "../chunk-
|
|
53
|
-
import "../chunk-OT5NHMEC.mjs";
|
|
54
|
-
import "../chunk-4CEQJ2X6.mjs";
|
|
55
|
-
import "../chunk-CI4KD357.mjs";
|
|
56
|
-
import "../chunk-C6IANC2R.mjs";
|
|
57
|
-
import "../chunk-N4VN2B5S.mjs";
|
|
58
|
-
import "../chunk-ICIK2BSB.mjs";
|
|
59
|
-
import "../chunk-2IDV5OHF.mjs";
|
|
60
|
-
import "../chunk-DXEQPN43.mjs";
|
|
61
|
-
import "../chunk-OKCYPO4I.mjs";
|
|
62
|
-
import "../chunk-PIF5KJYI.mjs";
|
|
63
|
-
import "../chunk-RKTVJRK7.mjs";
|
|
64
|
-
import "../chunk-PMAFHQ7P.mjs";
|
|
65
|
-
import "../chunk-5FHSUKQL.mjs";
|
|
52
|
+
} from "../chunk-R4MR43UQ.mjs";
|
|
66
53
|
import {
|
|
67
|
-
|
|
68
|
-
} from "../chunk-
|
|
69
|
-
import
|
|
54
|
+
useConfigureChatSuggestions
|
|
55
|
+
} from "../chunk-CB7CRBDG.mjs";
|
|
56
|
+
import {
|
|
57
|
+
useCoAgentStateRender
|
|
58
|
+
} from "../chunk-BR5YEYZJ.mjs";
|
|
59
|
+
import "../chunk-6PUNP7CD.mjs";
|
|
70
60
|
import "../chunk-O7ARI5CV.mjs";
|
|
61
|
+
import "../chunk-NROJOTQP.mjs";
|
|
62
|
+
import "../chunk-NB2FKV2V.mjs";
|
|
63
|
+
import "../chunk-F555TVE4.mjs";
|
|
71
64
|
import "../chunk-EFL5OBKN.mjs";
|
|
72
|
-
import "../chunk-
|
|
73
|
-
import "../chunk-
|
|
74
|
-
import "../chunk-
|
|
75
|
-
import "../chunk-ZLQVRPDS.mjs";
|
|
65
|
+
import "../chunk-FDOMAPJY.mjs";
|
|
66
|
+
import "../chunk-WVLHXIFP.mjs";
|
|
67
|
+
import "../chunk-DMLQZG75.mjs";
|
|
76
68
|
import "../chunk-SKC7AJIV.mjs";
|
|
77
69
|
export {
|
|
78
|
-
runAgent,
|
|
79
|
-
startAgent,
|
|
80
|
-
stopAgent,
|
|
81
70
|
useCoAgent,
|
|
82
71
|
useCoAgentStateRender,
|
|
72
|
+
useConfigureChatSuggestions,
|
|
83
73
|
useCopilotAction,
|
|
84
74
|
useCopilotAdditionalInstructions,
|
|
85
75
|
useCopilotAuthenticatedAction_c,
|
|
86
|
-
|
|
76
|
+
useCopilotChat,
|
|
87
77
|
useCopilotChatHeadless_c,
|
|
88
|
-
|
|
78
|
+
useCopilotChatInternal,
|
|
89
79
|
useCopilotReadable,
|
|
90
80
|
useCopilotRuntimeClient,
|
|
91
81
|
useDefaultTool,
|
|
@@ -93,6 +83,7 @@ export {
|
|
|
93
83
|
useHumanInTheLoop,
|
|
94
84
|
useLangGraphInterrupt,
|
|
95
85
|
useLangGraphInterruptRender,
|
|
86
|
+
useLazyToolRenderer,
|
|
96
87
|
useMakeCopilotDocumentReadable,
|
|
97
88
|
useRenderToolCall
|
|
98
89
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactCustomMessageRendererPosition } from '@copilotkitnext/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bridge hook that connects agent state renders to chat messages.
|
|
6
|
+
*
|
|
7
|
+
* ## Purpose
|
|
8
|
+
* This hook finds matching state render configurations (registered via useCoAgentStateRender)
|
|
9
|
+
* and returns UI to render in chat.
|
|
10
|
+
* It ensures each state render appears bound to a specific message, preventing duplicates while
|
|
11
|
+
* allowing re-binding when the underlying state changes significantly.
|
|
12
|
+
*
|
|
13
|
+
* ## Message-ID-Based Claiming System
|
|
14
|
+
*
|
|
15
|
+
* ### The Problem
|
|
16
|
+
* Multiple bridge component instances render simultaneously (one per message). Without coordination,
|
|
17
|
+
* they would all try to render the same state render, causing duplicates.
|
|
18
|
+
*
|
|
19
|
+
* ### The Solution: Message-ID Claims with State Comparison
|
|
20
|
+
* Each state render is "claimed" by exactly one **message ID** (not runId):
|
|
21
|
+
*
|
|
22
|
+
* **Claim Structure**: `claimsRef.current[messageId] = { stateRenderId, runId, stateSnapshot, locked }`
|
|
23
|
+
*
|
|
24
|
+
* **Primary binding is by messageId because**:
|
|
25
|
+
* - runId is not always available immediately (starts as "pending")
|
|
26
|
+
* - messageId is the stable identifier throughout the message lifecycle
|
|
27
|
+
* - Claims persist across component remounts via context ref
|
|
28
|
+
*
|
|
29
|
+
* ### Claiming Logic Flow
|
|
30
|
+
*
|
|
31
|
+
* 1. **Message already has a claim**:
|
|
32
|
+
* - Check if the claim matches the current stateRenderId
|
|
33
|
+
* - If yes → render (this message owns this render)
|
|
34
|
+
* - Update runId if it was "pending" and now available
|
|
35
|
+
*
|
|
36
|
+
* 2. **State render claimed by another message**:
|
|
37
|
+
* - Compare state snapshots (ignoring constant keys: messages, tools, copilotkit)
|
|
38
|
+
* - If states are identical → block rendering (duplicate)
|
|
39
|
+
* - **If states are different → allow claiming** (new data, new message)
|
|
40
|
+
* - This handles cases where the same render type shows different states in different messages
|
|
41
|
+
*
|
|
42
|
+
* 3. **Unclaimed state render**:
|
|
43
|
+
* - Only allow claiming if runId is "pending" (initial render)
|
|
44
|
+
* - If runId is real but no claim exists → block (edge case protection)
|
|
45
|
+
* - Create new claim: `claimsRef.current[messageId] = { stateRenderId, runId }`
|
|
46
|
+
*
|
|
47
|
+
* ### State Snapshot Locking
|
|
48
|
+
*
|
|
49
|
+
* Once a state snapshot is captured and locked for a message:
|
|
50
|
+
* - The UI always renders with the locked snapshot (not live agent.state)
|
|
51
|
+
* - Prevents UI from appearing "wiped" during state transitions
|
|
52
|
+
* - Locked when: stateSnapshot prop is available (from message persistence)
|
|
53
|
+
* - Unlocked state: can still update from live agent.state
|
|
54
|
+
*
|
|
55
|
+
* ### Synchronous Claiming (Ref-based)
|
|
56
|
+
*
|
|
57
|
+
* Claims are stored in a context-level ref (not React state):
|
|
58
|
+
* - Multiple bridges render in the same tick
|
|
59
|
+
* - State updates are async - would allow duplicates before update completes
|
|
60
|
+
* - Ref provides immediate, synchronous claim checking
|
|
61
|
+
* - Survives component remounts (stored in context, not component)
|
|
62
|
+
*
|
|
63
|
+
* ## Flow Example
|
|
64
|
+
*
|
|
65
|
+
* ```
|
|
66
|
+
* Time 1: Message A renders, runId=undefined, state={progress: 50%}
|
|
67
|
+
* → effectiveRunId = "pending"
|
|
68
|
+
* → Claims: claimsRef["msgA"] = { stateRenderId: "tasks", runId: "pending", stateSnapshot: {progress: 50%} }
|
|
69
|
+
* → Renders UI with 50% progress
|
|
70
|
+
*
|
|
71
|
+
* Time 2: Message B renders, runId=undefined, same state
|
|
72
|
+
* → Checks: "tasks" already claimed by msgA with same state
|
|
73
|
+
* → Returns null (blocked - duplicate)
|
|
74
|
+
*
|
|
75
|
+
* Time 3: Real runId appears (e.g., "run-123")
|
|
76
|
+
* → Updates claim: claimsRef["msgA"].runId = "run-123"
|
|
77
|
+
* → Message A continues rendering
|
|
78
|
+
*
|
|
79
|
+
* Time 4: Agent processes more, state={progress: 100%}
|
|
80
|
+
* → Message A: locked to 50% (stateSnapshot locked)
|
|
81
|
+
* → Message C renders with state={progress: 100%}
|
|
82
|
+
* → Checks: "tasks" claimed by msgA but state is DIFFERENT (50% vs 100%)
|
|
83
|
+
* → Allows new claim: claimsRef["msgC"] = { stateRenderId: "tasks", runId: "run-123", stateSnapshot: {progress: 100%} }
|
|
84
|
+
* → Both messages render independently with their own snapshots
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
interface CoAgentStateRenderBridgeProps {
|
|
88
|
+
message: any;
|
|
89
|
+
position: ReactCustomMessageRendererPosition;
|
|
90
|
+
runId: string;
|
|
91
|
+
messageIndex: number;
|
|
92
|
+
messageIndexInRun: number;
|
|
93
|
+
numberOfMessagesInRun: number;
|
|
94
|
+
agentId: string;
|
|
95
|
+
stateSnapshot: any;
|
|
96
|
+
}
|
|
97
|
+
declare function useCoagentStateRenderBridge(agentId: string, props: CoAgentStateRenderBridgeProps): string | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null | undefined;
|
|
98
|
+
declare function CoAgentStateRenderBridge(props: CoAgentStateRenderBridgeProps): string | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null | undefined;
|
|
99
|
+
|
|
100
|
+
export { CoAgentStateRenderBridge, CoAgentStateRenderBridgeProps, useCoagentStateRenderBridge };
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __objRest = (source, exclude) => {
|
|
9
|
+
var target = {};
|
|
10
|
+
for (var prop in source)
|
|
11
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
if (source != null && __getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
15
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
16
|
+
target[prop] = source[prop];
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
35
|
+
var use_coagent_state_render_bridge_exports = {};
|
|
36
|
+
__export(use_coagent_state_render_bridge_exports, {
|
|
37
|
+
CoAgentStateRenderBridge: () => CoAgentStateRenderBridge,
|
|
38
|
+
useCoagentStateRenderBridge: () => useCoagentStateRenderBridge
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(use_coagent_state_render_bridge_exports);
|
|
41
|
+
var import_react2 = require("@copilotkitnext/react");
|
|
42
|
+
var import_react3 = require("react");
|
|
43
|
+
|
|
44
|
+
// src/context/coagent-state-renders-context.tsx
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
var CoAgentStateRendersContext = (0, import_react.createContext)(
|
|
48
|
+
void 0
|
|
49
|
+
);
|
|
50
|
+
function useCoAgentStateRenders() {
|
|
51
|
+
const context = (0, import_react.useContext)(CoAgentStateRendersContext);
|
|
52
|
+
if (!context) {
|
|
53
|
+
throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
|
|
54
|
+
}
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
59
|
+
var import_shared = require("@copilotkit/shared");
|
|
60
|
+
function getStateWithoutConstantKeys(state) {
|
|
61
|
+
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
62
|
+
return stateWithoutConstantKeys;
|
|
63
|
+
}
|
|
64
|
+
function areStatesEquals(a, b) {
|
|
65
|
+
if (a && !b || !a && b)
|
|
66
|
+
return false;
|
|
67
|
+
const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
68
|
+
const _b = b, {
|
|
69
|
+
messages: bMessages,
|
|
70
|
+
tools: bTools,
|
|
71
|
+
copilotkit: bCopilotkit
|
|
72
|
+
} = _b, bWithoutConstantKeys = __objRest(_b, [
|
|
73
|
+
"messages",
|
|
74
|
+
"tools",
|
|
75
|
+
"copilotkit"
|
|
76
|
+
]);
|
|
77
|
+
return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
|
|
78
|
+
}
|
|
79
|
+
function useCoagentStateRenderBridge(agentId, props) {
|
|
80
|
+
var _a;
|
|
81
|
+
const { stateSnapshot, messageIndexInRun, message } = props;
|
|
82
|
+
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
83
|
+
const { agent } = (0, import_react2.useAgent)({ agentId });
|
|
84
|
+
const [nodeName, setNodeName] = (0, import_react3.useState)(void 0);
|
|
85
|
+
const runId = (_a = props.runId) != null ? _a : message.runId;
|
|
86
|
+
const effectiveRunId = runId || "pending";
|
|
87
|
+
(0, import_react3.useEffect)(() => {
|
|
88
|
+
if (!agent)
|
|
89
|
+
return;
|
|
90
|
+
const subscriber = {
|
|
91
|
+
onStepStartedEvent: ({ event }) => {
|
|
92
|
+
if (event.stepName !== nodeName) {
|
|
93
|
+
setNodeName(event.stepName);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onStepFinishedEvent: ({ event }) => {
|
|
97
|
+
if (event.stepName === nodeName) {
|
|
98
|
+
setNodeName(void 0);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
103
|
+
return () => {
|
|
104
|
+
unsubscribe();
|
|
105
|
+
};
|
|
106
|
+
}, [agentId, nodeName]);
|
|
107
|
+
if (messageIndexInRun !== 0) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const getStateRender = (0, import_react3.useCallback)(
|
|
111
|
+
(messageId) => {
|
|
112
|
+
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
113
|
+
if (claimsRef.current[messageId]) {
|
|
114
|
+
return stateRenderId === claimsRef.current[messageId].stateRenderId;
|
|
115
|
+
}
|
|
116
|
+
const matchingAgentName = stateRender.name === agentId;
|
|
117
|
+
const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
|
|
118
|
+
return matchingAgentName && matchesNodeContext;
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
[coAgentStateRenders, nodeName, agentId]
|
|
122
|
+
);
|
|
123
|
+
const handleRenderRequest = ({
|
|
124
|
+
stateRenderId,
|
|
125
|
+
messageId,
|
|
126
|
+
runId: runId2,
|
|
127
|
+
stateSnapshot: renderSnapshot
|
|
128
|
+
}) => {
|
|
129
|
+
if (claimsRef.current[messageId]) {
|
|
130
|
+
const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
|
|
131
|
+
if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
|
|
132
|
+
claimsRef.current[messageId].runId = runId2;
|
|
133
|
+
}
|
|
134
|
+
return canRender;
|
|
135
|
+
}
|
|
136
|
+
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
137
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) === (0, import_shared.dataToUUID)(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot)))
|
|
138
|
+
);
|
|
139
|
+
if (renderClaimedByOtherMessage) {
|
|
140
|
+
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
141
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (!runId2) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
return (0, import_react3.useMemo)(() => {
|
|
153
|
+
var _a2, _b, _c;
|
|
154
|
+
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
155
|
+
if (!stateRender || !stateRenderId) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const snapshot = stateSnapshot ? (0, import_shared.parseJson)(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
|
|
159
|
+
const canRender = handleRenderRequest({
|
|
160
|
+
stateRenderId,
|
|
161
|
+
messageId: message.id,
|
|
162
|
+
runId: effectiveRunId,
|
|
163
|
+
stateSnapshot: snapshot
|
|
164
|
+
});
|
|
165
|
+
if (!canRender) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
if (snapshot && !claimsRef.current[message.id].locked) {
|
|
169
|
+
if (stateSnapshot) {
|
|
170
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
171
|
+
claimsRef.current[message.id].locked = true;
|
|
172
|
+
} else {
|
|
173
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (stateRender.handler) {
|
|
177
|
+
stateRender.handler({
|
|
178
|
+
state: stateSnapshot ? (0, import_shared.parseJson)(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
|
|
179
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (stateRender.render) {
|
|
183
|
+
const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
|
|
184
|
+
if (typeof stateRender.render === "string")
|
|
185
|
+
return stateRender.render;
|
|
186
|
+
return stateRender.render({
|
|
187
|
+
status,
|
|
188
|
+
// Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
|
|
189
|
+
state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
|
|
190
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}, [
|
|
194
|
+
getStateRender,
|
|
195
|
+
stateSnapshot,
|
|
196
|
+
agent == null ? void 0 : agent.state,
|
|
197
|
+
agent == null ? void 0 : agent.isRunning,
|
|
198
|
+
nodeName,
|
|
199
|
+
effectiveRunId,
|
|
200
|
+
message.id
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
function CoAgentStateRenderBridge(props) {
|
|
204
|
+
return useCoagentStateRenderBridge(props.agentId, props);
|
|
205
|
+
}
|
|
206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
+
0 && (module.exports = {
|
|
208
|
+
CoAgentStateRenderBridge,
|
|
209
|
+
useCoagentStateRenderBridge
|
|
210
|
+
});
|
|
211
|
+
//# sourceMappingURL=use-coagent-state-render-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-coagent-state-render-bridge.tsx","../../src/context/coagent-state-renders-context.tsx"],"sourcesContent":["import { ReactCustomMessageRendererPosition, useAgent } from \"@copilotkitnext/react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AgentSubscriber } from \"@ag-ui/client\";\nimport { useCoAgentStateRenders } from \"../context\";\nimport { dataToUUID, parseJson } from \"@copilotkit/shared\";\n\nfunction getStateWithoutConstantKeys(state: any) {\n const { messages, tools, copilotkit, ...stateWithoutConstantKeys } = state;\n return stateWithoutConstantKeys;\n}\n\n// Function that compares states, without the constant keys\nfunction areStatesEquals(a: any, b: any) {\n if ((a && !b) || (!a && b)) return false;\n const { messages, tools, copilotkit, ...aWithoutConstantKeys } = a;\n const {\n messages: bMessages,\n tools: bTools,\n copilotkit: bCopilotkit,\n ...bWithoutConstantKeys\n } = b;\n\n return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);\n}\n\n/**\n * Bridge hook that connects agent state renders to chat messages.\n *\n * ## Purpose\n * This hook finds matching state render configurations (registered via useCoAgentStateRender)\n * and returns UI to render in chat.\n * It ensures each state render appears bound to a specific message, preventing duplicates while\n * allowing re-binding when the underlying state changes significantly.\n *\n * ## Message-ID-Based Claiming System\n *\n * ### The Problem\n * Multiple bridge component instances render simultaneously (one per message). Without coordination,\n * they would all try to render the same state render, causing duplicates.\n *\n * ### The Solution: Message-ID Claims with State Comparison\n * Each state render is \"claimed\" by exactly one **message ID** (not runId):\n *\n * **Claim Structure**: `claimsRef.current[messageId] = { stateRenderId, runId, stateSnapshot, locked }`\n *\n * **Primary binding is by messageId because**:\n * - runId is not always available immediately (starts as \"pending\")\n * - messageId is the stable identifier throughout the message lifecycle\n * - Claims persist across component remounts via context ref\n *\n * ### Claiming Logic Flow\n *\n * 1. **Message already has a claim**:\n * - Check if the claim matches the current stateRenderId\n * - If yes → render (this message owns this render)\n * - Update runId if it was \"pending\" and now available\n *\n * 2. **State render claimed by another message**:\n * - Compare state snapshots (ignoring constant keys: messages, tools, copilotkit)\n * - If states are identical → block rendering (duplicate)\n * - **If states are different → allow claiming** (new data, new message)\n * - This handles cases where the same render type shows different states in different messages\n *\n * 3. **Unclaimed state render**:\n * - Only allow claiming if runId is \"pending\" (initial render)\n * - If runId is real but no claim exists → block (edge case protection)\n * - Create new claim: `claimsRef.current[messageId] = { stateRenderId, runId }`\n *\n * ### State Snapshot Locking\n *\n * Once a state snapshot is captured and locked for a message:\n * - The UI always renders with the locked snapshot (not live agent.state)\n * - Prevents UI from appearing \"wiped\" during state transitions\n * - Locked when: stateSnapshot prop is available (from message persistence)\n * - Unlocked state: can still update from live agent.state\n *\n * ### Synchronous Claiming (Ref-based)\n *\n * Claims are stored in a context-level ref (not React state):\n * - Multiple bridges render in the same tick\n * - State updates are async - would allow duplicates before update completes\n * - Ref provides immediate, synchronous claim checking\n * - Survives component remounts (stored in context, not component)\n *\n * ## Flow Example\n *\n * ```\n * Time 1: Message A renders, runId=undefined, state={progress: 50%}\n * → effectiveRunId = \"pending\"\n * → Claims: claimsRef[\"msgA\"] = { stateRenderId: \"tasks\", runId: \"pending\", stateSnapshot: {progress: 50%} }\n * → Renders UI with 50% progress\n *\n * Time 2: Message B renders, runId=undefined, same state\n * → Checks: \"tasks\" already claimed by msgA with same state\n * → Returns null (blocked - duplicate)\n *\n * Time 3: Real runId appears (e.g., \"run-123\")\n * → Updates claim: claimsRef[\"msgA\"].runId = \"run-123\"\n * → Message A continues rendering\n *\n * Time 4: Agent processes more, state={progress: 100%}\n * → Message A: locked to 50% (stateSnapshot locked)\n * → Message C renders with state={progress: 100%}\n * → Checks: \"tasks\" claimed by msgA but state is DIFFERENT (50% vs 100%)\n * → Allows new claim: claimsRef[\"msgC\"] = { stateRenderId: \"tasks\", runId: \"run-123\", stateSnapshot: {progress: 100%} }\n * → Both messages render independently with their own snapshots\n * ```\n */\nexport interface CoAgentStateRenderBridgeProps {\n message: any;\n position: ReactCustomMessageRendererPosition;\n runId: string;\n messageIndex: number;\n messageIndexInRun: number;\n numberOfMessagesInRun: number;\n agentId: string;\n stateSnapshot: any;\n}\n\nexport function useCoagentStateRenderBridge(agentId: string, props: CoAgentStateRenderBridgeProps) {\n const { stateSnapshot, messageIndexInRun, message } = props;\n const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();\n const { agent } = useAgent({ agentId });\n const [nodeName, setNodeName] = useState<string | undefined>(undefined);\n\n const runId = props.runId ?? message.runId;\n const effectiveRunId = runId || \"pending\";\n\n useEffect(() => {\n if (!agent) return;\n const subscriber: AgentSubscriber = {\n onStepStartedEvent: ({ event }) => {\n if (event.stepName !== nodeName) {\n setNodeName(event.stepName);\n }\n },\n onStepFinishedEvent: ({ event }) => {\n if (event.stepName === nodeName) {\n setNodeName(undefined);\n }\n },\n };\n\n const { unsubscribe } = agent.subscribe(subscriber);\n return () => {\n unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [agentId, nodeName]);\n\n if (messageIndexInRun !== 0) {\n return null;\n }\n\n const getStateRender = useCallback(\n (messageId: string) => {\n return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {\n if (claimsRef.current[messageId]) {\n return stateRenderId === claimsRef.current[messageId].stateRenderId;\n }\n const matchingAgentName = stateRender.name === agentId;\n const matchesNodeContext = stateRender.nodeName\n ? stateRender.nodeName === nodeName\n : true;\n return matchingAgentName && matchesNodeContext;\n });\n },\n [coAgentStateRenders, nodeName, agentId],\n );\n\n // Message ID-based claim system - A state render can only be claimed by one message ID\n const handleRenderRequest = ({\n stateRenderId,\n messageId,\n runId,\n stateSnapshot: renderSnapshot,\n }: {\n stateRenderId: string;\n messageId: string;\n runId?: string;\n stateSnapshot?: any;\n }): boolean => {\n // Check if this message has already claimed this state render\n if (claimsRef.current[messageId]) {\n const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;\n\n // Update runId if it doesn't exist\n if (\n canRender &&\n runId &&\n (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === \"pending\")\n ) {\n claimsRef.current[messageId].runId = runId;\n }\n\n return canRender;\n }\n\n // Do not allow render if any other message has claimed this state render\n const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(\n (c) =>\n c.stateRenderId === stateRenderId &&\n dataToUUID(JSON.stringify(getStateWithoutConstantKeys(c.stateSnapshot))) ===\n dataToUUID(JSON.stringify(getStateWithoutConstantKeys(renderSnapshot))),\n );\n if (renderClaimedByOtherMessage) {\n // If:\n // - state render already claimed\n // - snapshot exists in the claiming object and is different from current,\n if (\n renderSnapshot &&\n renderClaimedByOtherMessage.stateSnapshot &&\n !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)\n ) {\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n }\n return false;\n }\n\n // No existing claim anywhere yet – allow this message to claim even if we already know the runId.\n if (!runId) {\n return false;\n }\n\n claimsRef.current[messageId] = { stateRenderId, runId };\n return true;\n };\n\n return useMemo(() => {\n const [stateRenderId, stateRender] = getStateRender(message.id) ?? [];\n\n if (!stateRender || !stateRenderId) {\n return null;\n }\n\n // Is there any state we can use?\n const snapshot = stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : agent?.state;\n\n // Synchronously check/claim - returns true if this message can render\n const canRender = handleRenderRequest({\n stateRenderId,\n messageId: message.id,\n runId: effectiveRunId,\n stateSnapshot: snapshot,\n });\n if (!canRender) {\n return null;\n }\n\n // If we found state, and given that now there's a claim for the current message, let's save it in the claim\n if (snapshot && !claimsRef.current[message.id].locked) {\n if (stateSnapshot) {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n claimsRef.current[message.id].locked = true;\n } else {\n claimsRef.current[message.id].stateSnapshot = snapshot;\n }\n }\n\n if (stateRender.handler) {\n stateRender.handler({\n state: stateSnapshot ? parseJson(stateSnapshot, stateSnapshot) : (agent?.state ?? {}),\n nodeName: nodeName ?? \"\",\n });\n }\n\n if (stateRender.render) {\n const status = agent?.isRunning ? \"inProgress\" : \"complete\";\n\n if (typeof stateRender.render === \"string\") return stateRender.render;\n\n return stateRender.render({\n status,\n // Always use state from claim, to make sure the state does not seem \"wiped\" for a fraction of a second\n state: claimsRef.current[message.id].stateSnapshot ?? {},\n nodeName: nodeName ?? \"\",\n });\n }\n }, [\n getStateRender,\n stateSnapshot,\n agent?.state,\n agent?.isRunning,\n nodeName,\n effectiveRunId,\n message.id,\n ]);\n}\n\nexport function CoAgentStateRenderBridge(props: CoAgentStateRenderBridgeProps) {\n return useCoagentStateRenderBridge(props.agentId, props);\n}\n","import React, {\n createContext,\n useContext,\n useCallback,\n useState,\n useRef,\n ReactNode,\n RefObject,\n} from \"react\";\nimport { CoAgentStateRender } from \"../types/coagent-action\";\n\ninterface StateRenderClaim {\n stateRenderId: string;\n stateSnapshot?: any;\n runId?: string;\n locked?: boolean;\n}\n\ntype ClaimsRef = Record<string, StateRenderClaim>;\n\nexport interface CoAgentStateRendersContextValue {\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n claimsRef: RefObject<ClaimsRef>;\n}\n\nconst CoAgentStateRendersContext = createContext<CoAgentStateRendersContextValue | undefined>(\n undefined,\n);\n\nexport function CoAgentStateRendersProvider({ children }: { children: ReactNode }) {\n const [coAgentStateRenders, setCoAgentStateRenders] = useState<\n Record<string, CoAgentStateRender<any>>\n >({});\n\n const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {\n setCoAgentStateRenders((prevPoints) => ({\n ...prevPoints,\n [id]: stateRender,\n }));\n }, []);\n\n const removeCoAgentStateRender = useCallback((id: string) => {\n setCoAgentStateRenders((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const claimsRef = useRef<ClaimsRef>({});\n\n return (\n <CoAgentStateRendersContext.Provider\n value={{\n coAgentStateRenders,\n setCoAgentStateRender,\n removeCoAgentStateRender,\n claimsRef,\n }}\n >\n {children}\n </CoAgentStateRendersContext.Provider>\n );\n}\n\nexport function useCoAgentStateRenders() {\n const context = useContext(CoAgentStateRendersContext);\n if (!context) {\n throw new Error(\"useCoAgentStateRenders must be used within CoAgentStateRendersProvider\");\n }\n return context;\n}\n\nexport { CoAgentStateRendersContext };\n"],"mappings":"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","names":["import_react","runId","_a"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CoAgentStateRenderBridge,
|
|
3
|
+
useCoagentStateRenderBridge
|
|
4
|
+
} from "../chunk-NROJOTQP.mjs";
|
|
5
|
+
import "../chunk-NB2FKV2V.mjs";
|
|
6
|
+
import "../chunk-F555TVE4.mjs";
|
|
7
|
+
import "../chunk-FDOMAPJY.mjs";
|
|
8
|
+
import "../chunk-WVLHXIFP.mjs";
|
|
9
|
+
import "../chunk-DMLQZG75.mjs";
|
|
10
|
+
import "../chunk-SKC7AJIV.mjs";
|
|
11
|
+
export {
|
|
12
|
+
CoAgentStateRenderBridge,
|
|
13
|
+
useCoagentStateRenderBridge
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=use-coagent-state-render-bridge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -53,7 +53,7 @@ __export(use_coagent_state_render_exports, {
|
|
|
53
53
|
useCoAgentStateRender: () => useCoAgentStateRender
|
|
54
54
|
});
|
|
55
55
|
module.exports = __toCommonJS(use_coagent_state_render_exports);
|
|
56
|
-
var
|
|
56
|
+
var import_react4 = require("react");
|
|
57
57
|
|
|
58
58
|
// src/context/copilot-context.tsx
|
|
59
59
|
var import_react = __toESM(require("react"));
|
|
@@ -63,10 +63,8 @@ var emptyCopilotContext = {
|
|
|
63
63
|
},
|
|
64
64
|
removeAction: () => {
|
|
65
65
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
removeCoAgentStateRender: () => {
|
|
66
|
+
setRegisteredActions: () => "",
|
|
67
|
+
removeRegisteredAction: () => {
|
|
70
68
|
},
|
|
71
69
|
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
72
70
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
@@ -86,7 +84,6 @@ var emptyCopilotContext = {
|
|
|
86
84
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
87
85
|
removeDocumentContext: () => {
|
|
88
86
|
},
|
|
89
|
-
runtimeClient: {},
|
|
90
87
|
copilotApiConfig: new class {
|
|
91
88
|
get chatApiEndpoint() {
|
|
92
89
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -126,10 +123,15 @@ var emptyCopilotContext = {
|
|
|
126
123
|
extensions: {},
|
|
127
124
|
setExtensions: () => {
|
|
128
125
|
},
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
interruptActions: {},
|
|
127
|
+
setInterruptAction: () => {
|
|
128
|
+
},
|
|
129
|
+
removeInterruptAction: () => {
|
|
131
130
|
},
|
|
132
|
-
|
|
131
|
+
interruptEventQueue: {},
|
|
132
|
+
addInterruptEvent: () => {
|
|
133
|
+
},
|
|
134
|
+
removeInterruptEvent: () => {
|
|
133
135
|
},
|
|
134
136
|
onError: () => {
|
|
135
137
|
},
|
|
@@ -163,18 +165,27 @@ function useToast() {
|
|
|
163
165
|
return context;
|
|
164
166
|
}
|
|
165
167
|
|
|
168
|
+
// src/context/coagent-state-renders-context.tsx
|
|
169
|
+
var import_react3 = require("react");
|
|
170
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
171
|
+
var CoAgentStateRendersContext = (0, import_react3.createContext)(
|
|
172
|
+
void 0
|
|
173
|
+
);
|
|
174
|
+
function useCoAgentStateRenders() {
|
|
175
|
+
const context = (0, import_react3.useContext)(CoAgentStateRendersContext);
|
|
176
|
+
if (!context) {
|
|
177
|
+
throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
|
|
178
|
+
}
|
|
179
|
+
return context;
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
// src/hooks/use-coagent-state-render.ts
|
|
167
183
|
function useCoAgentStateRender(action, dependencies) {
|
|
168
|
-
const {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
coAgentStateRenders,
|
|
172
|
-
chatComponentsCache,
|
|
173
|
-
availableAgents
|
|
174
|
-
} = (0, import_react3.useContext)(CopilotContext);
|
|
175
|
-
const idRef = (0, import_react3.useRef)((0, import_shared2.randomId)());
|
|
184
|
+
const { chatComponentsCache, availableAgents } = (0, import_react4.useContext)(CopilotContext);
|
|
185
|
+
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
186
|
+
const idRef = (0, import_react4.useRef)((0, import_shared2.randomId)());
|
|
176
187
|
const { setBannerError, addToast } = useToast();
|
|
177
|
-
(0,
|
|
188
|
+
(0, import_react4.useEffect)(() => {
|
|
178
189
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
179
190
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
180
191
|
const agentError = new import_shared2.CopilotKitAgentDiscoveryError({
|
|
@@ -195,7 +206,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
195
206
|
}
|
|
196
207
|
}
|
|
197
208
|
}
|
|
198
|
-
(0,
|
|
209
|
+
(0, import_react4.useEffect)(() => {
|
|
199
210
|
const currentId = idRef.current;
|
|
200
211
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
201
212
|
if (id === currentId)
|
|
@@ -219,7 +230,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
219
230
|
});
|
|
220
231
|
}
|
|
221
232
|
}, [coAgentStateRenders]);
|
|
222
|
-
(0,
|
|
233
|
+
(0, import_react4.useEffect)(() => {
|
|
223
234
|
setCoAgentStateRender(idRef.current, action);
|
|
224
235
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
225
236
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|