@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCopilotContext
|
|
3
|
+
} from "./chunk-WVLHXIFP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__spreadProps,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
8
|
+
|
|
9
|
+
// src/hooks/use-configure-chat-suggestions.tsx
|
|
10
|
+
import {
|
|
11
|
+
useConfigureSuggestions,
|
|
12
|
+
useCopilotKit,
|
|
13
|
+
useSuggestions
|
|
14
|
+
} from "@copilotkitnext/react";
|
|
15
|
+
import { useEffect } from "react";
|
|
16
|
+
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
17
|
+
const { agentSession } = useCopilotContext();
|
|
18
|
+
const { copilotkit } = useCopilotKit();
|
|
19
|
+
const available = config.available === "enabled" ? "always" : config.available;
|
|
20
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
21
|
+
available,
|
|
22
|
+
consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
|
|
23
|
+
// Use chatConfig.agentId here
|
|
24
|
+
});
|
|
25
|
+
useConfigureSuggestions(finalSuggestionConfig, { deps: dependencies });
|
|
26
|
+
const result = useSuggestions({ agentId: agentSession == null ? void 0 : agentSession.agentName });
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (finalSuggestionConfig.available === "disabled")
|
|
29
|
+
return;
|
|
30
|
+
const subscription = copilotkit.subscribe({
|
|
31
|
+
onAgentsChanged: () => {
|
|
32
|
+
const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
|
|
33
|
+
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
34
|
+
copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
subscription.unsubscribe();
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
useConfigureChatSuggestions
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-CB7CRBDG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-configure-chat-suggestions.tsx"],"sourcesContent":["import {\n useConfigureSuggestions,\n useCopilotChatConfiguration,\n useCopilotKit,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { StaticSuggestionsConfig, Suggestion } from \"@copilotkitnext/core\";\nimport { useCopilotContext } from \"../context\";\nimport { useEffect, useMemo } from \"react\";\n\ntype StaticSuggestionInput = Omit<Suggestion, \"isLoading\"> & Partial<Pick<Suggestion, \"isLoading\">>;\n\ntype StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, \"suggestions\"> & {\n suggestions: StaticSuggestionInput[];\n};\n\ntype DynamicSuggestionsConfigInput = {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n\n /**\n * Whether the suggestions are available. Defaults to `enabled`.\n * @default enabled\n */\n available?: \"enabled\" | \"disabled\" | \"always\" | \"before-first-message\" | \"after-first-message\";\n\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n};\n\nexport type UseCopilotChatSuggestionsConfiguration =\n | DynamicSuggestionsConfigInput\n | StaticSuggestionsConfigInput;\n\nexport function useConfigureChatSuggestions(\n config: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n): ReturnType<typeof useSuggestions> {\n const { agentSession } = useCopilotContext();\n const { copilotkit } = useCopilotKit();\n\n const available = config.available === \"enabled\" ? \"always\" : config.available;\n\n const finalSuggestionConfig = {\n ...config,\n available,\n consumerAgentId: agentSession?.agentName, // Use chatConfig.agentId here\n };\n useConfigureSuggestions(finalSuggestionConfig, { deps: dependencies });\n\n const result = useSuggestions({ agentId: agentSession?.agentName });\n\n useEffect(() => {\n if (finalSuggestionConfig.available === \"disabled\") return;\n const subscription = copilotkit.subscribe({\n onAgentsChanged: () => {\n // When agents change, check if our target agent now exists and reload\n const agent = copilotkit.getAgent(agentSession?.agentName!);\n if (agent && !agent.isRunning && !result.suggestions.length) {\n copilotkit.reloadSuggestions(agentSession?.agentName!);\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, []);\n\n return result;\n}\n"],"mappings":";;;;;;;;;AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAA0B;AAwC5B,SAAS,4BACd,QACA,eAAsB,CAAC,GACY;AACnC,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAC3C,QAAM,EAAE,WAAW,IAAI,cAAc;AAErC,QAAM,YAAY,OAAO,cAAc,YAAY,WAAW,OAAO;AAErE,QAAM,wBAAwB,iCACzB,SADyB;AAAA,IAE5B;AAAA,IACA,iBAAiB,6CAAc;AAAA;AAAA,EACjC;AACA,0BAAwB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAErE,QAAM,SAAS,eAAe,EAAE,SAAS,6CAAc,UAAU,CAAC;AAElE,YAAU,MAAM;AACd,QAAI,sBAAsB,cAAc;AAAY;AACpD,UAAM,eAAe,WAAW,UAAU;AAAA,MACxC,iBAAiB,MAAM;AAErB,cAAM,QAAQ,WAAW,SAAS,6CAAc,SAAU;AAC1D,YAAI,SAAS,CAAC,MAAM,aAAa,CAAC,OAAO,YAAY,QAAQ;AAC3D,qBAAW,kBAAkB,6CAAc,SAAU;AAAA,QACvD;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,mBAAa,YAAY;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-CYDWEPFL.mjs.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WVLHXIFP.mjs";
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
6
6
|
import { useEffect, useRef } from "react";
|
|
7
7
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
8
8
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
9
|
-
const idRef = useRef();
|
|
9
|
+
const idRef = useRef(void 0);
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
const id = addDocumentContext(document, categories);
|
|
12
12
|
idRef.current = id;
|
|
@@ -20,4 +20,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
20
20
|
export {
|
|
21
21
|
useMakeCopilotDocumentReadable
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
23
|
+
//# sourceMappingURL=chunk-D3QSYDJR.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,cAAc;AAW3B,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,kBAAkB;AACxE,QAAM,QAAQ,OAAe;
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>(undefined!);\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n"],"mappings":";;;;;AAAA,SAAS,WAAW,cAAc;AAW3B,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,kBAAkB;AACxE,QAAM,QAAQ,OAAe,MAAU;AAEvC,YAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":[]}
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CopilotErrorBoundary
|
|
3
|
+
} from "./chunk-LHERIF3L.mjs";
|
|
4
|
+
import {
|
|
5
|
+
CopilotMessages,
|
|
6
|
+
MessagesTapProvider
|
|
7
|
+
} from "./chunk-FBD24VEH.mjs";
|
|
8
|
+
import {
|
|
9
|
+
ConsoleTrigger
|
|
10
|
+
} from "./chunk-LHKZJ2ND.mjs";
|
|
11
|
+
import {
|
|
12
|
+
shouldShowDevConsole
|
|
13
|
+
} from "./chunk-ICIK2BSB.mjs";
|
|
14
|
+
import {
|
|
15
|
+
use_tree_default
|
|
16
|
+
} from "./chunk-RKTVJRK7.mjs";
|
|
17
|
+
import {
|
|
18
|
+
use_flat_category_store_default
|
|
19
|
+
} from "./chunk-YYN33GSG.mjs";
|
|
20
|
+
import {
|
|
21
|
+
CoAgentStateRenderBridge
|
|
22
|
+
} from "./chunk-NROJOTQP.mjs";
|
|
23
|
+
import {
|
|
24
|
+
CopilotListeners
|
|
25
|
+
} from "./chunk-5X5DJRQQ.mjs";
|
|
26
|
+
import {
|
|
27
|
+
ThreadsProvider,
|
|
28
|
+
useThreads
|
|
29
|
+
} from "./chunk-F555TVE4.mjs";
|
|
30
|
+
import {
|
|
31
|
+
ToastProvider
|
|
32
|
+
} from "./chunk-EFL5OBKN.mjs";
|
|
33
|
+
import {
|
|
34
|
+
UsageBanner,
|
|
35
|
+
getErrorActions
|
|
36
|
+
} from "./chunk-6ZLPNY7X.mjs";
|
|
37
|
+
import {
|
|
38
|
+
CoAgentStateRendersProvider
|
|
39
|
+
} from "./chunk-FDOMAPJY.mjs";
|
|
40
|
+
import {
|
|
41
|
+
CopilotContext
|
|
42
|
+
} from "./chunk-WVLHXIFP.mjs";
|
|
43
|
+
import {
|
|
44
|
+
__async,
|
|
45
|
+
__objRest,
|
|
46
|
+
__restKey,
|
|
47
|
+
__spreadProps,
|
|
48
|
+
__spreadValues
|
|
49
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
50
|
+
|
|
51
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
52
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
53
|
+
import { CopilotChatConfigurationProvider, CopilotKitProvider } from "@copilotkitnext/react";
|
|
54
|
+
import { flushSync } from "react-dom";
|
|
55
|
+
import {
|
|
56
|
+
COPILOT_CLOUD_CHAT_URL,
|
|
57
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
58
|
+
randomUUID,
|
|
59
|
+
ConfigurationError,
|
|
60
|
+
MissingPublicApiKeyError
|
|
61
|
+
} from "@copilotkit/shared";
|
|
62
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
63
|
+
function CopilotKit(_a) {
|
|
64
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
65
|
+
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
66
|
+
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
67
|
+
const renderArr = useMemo(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
68
|
+
return /* @__PURE__ */ jsx(ToastProvider, { enabled, children: /* @__PURE__ */ jsx(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ jsx(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ jsx(
|
|
69
|
+
CopilotKitProvider,
|
|
70
|
+
{
|
|
71
|
+
runtimeUrl: props.runtimeUrl,
|
|
72
|
+
renderCustomMessages: renderArr,
|
|
73
|
+
useSingleEndpoint: true,
|
|
74
|
+
children: /* @__PURE__ */ jsx(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
75
|
+
}
|
|
76
|
+
) }) }) });
|
|
77
|
+
}
|
|
78
|
+
function CopilotKitInternal(cpkProps) {
|
|
79
|
+
var _b;
|
|
80
|
+
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
81
|
+
validateProps(cpkProps);
|
|
82
|
+
const publicApiKey = props.publicLicenseKey || props.publicApiKey;
|
|
83
|
+
const chatApiEndpoint = props.runtimeUrl || COPILOT_CLOUD_CHAT_URL;
|
|
84
|
+
const [actions, setActions] = useState({});
|
|
85
|
+
const [registeredActionConfigs, setRegisteredActionConfigs] = useState(/* @__PURE__ */ new Map());
|
|
86
|
+
const chatComponentsCache = useRef({
|
|
87
|
+
actions: {},
|
|
88
|
+
coAgentStateRenders: {}
|
|
89
|
+
});
|
|
90
|
+
const { addElement, removeElement, printTree, getAllElements } = use_tree_default();
|
|
91
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
92
|
+
const [chatInstructions, setChatInstructions] = useState("");
|
|
93
|
+
const [authStates, setAuthStates] = useState({});
|
|
94
|
+
const [extensions, setExtensions] = useState({});
|
|
95
|
+
const [additionalInstructions, setAdditionalInstructions] = useState([]);
|
|
96
|
+
const {
|
|
97
|
+
addElement: addDocument,
|
|
98
|
+
removeElement: removeDocument,
|
|
99
|
+
allElements: allDocuments
|
|
100
|
+
} = use_flat_category_store_default();
|
|
101
|
+
const setAction = useCallback((id, action) => {
|
|
102
|
+
setActions((prevPoints) => {
|
|
103
|
+
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
104
|
+
[id]: action
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}, []);
|
|
108
|
+
const removeAction = useCallback((id) => {
|
|
109
|
+
setActions((prevPoints) => {
|
|
110
|
+
const newPoints = __spreadValues({}, prevPoints);
|
|
111
|
+
delete newPoints[id];
|
|
112
|
+
return newPoints;
|
|
113
|
+
});
|
|
114
|
+
}, []);
|
|
115
|
+
const getContextString = useCallback(
|
|
116
|
+
(documents, categories) => {
|
|
117
|
+
const documentsString = documents.map((document) => {
|
|
118
|
+
return `${document.name} (${document.sourceApplication}):
|
|
119
|
+
${document.getContents()}`;
|
|
120
|
+
}).join("\n\n");
|
|
121
|
+
const nonDocumentStrings = printTree(categories);
|
|
122
|
+
return `${documentsString}
|
|
123
|
+
|
|
124
|
+
${nonDocumentStrings}`;
|
|
125
|
+
},
|
|
126
|
+
[printTree]
|
|
127
|
+
);
|
|
128
|
+
const addContext = useCallback(
|
|
129
|
+
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
130
|
+
return addElement(context, categories, parentId);
|
|
131
|
+
},
|
|
132
|
+
[addElement]
|
|
133
|
+
);
|
|
134
|
+
const removeContext = useCallback(
|
|
135
|
+
(id) => {
|
|
136
|
+
removeElement(id);
|
|
137
|
+
},
|
|
138
|
+
[removeElement]
|
|
139
|
+
);
|
|
140
|
+
const getAllContext = useCallback(() => {
|
|
141
|
+
return getAllElements();
|
|
142
|
+
}, [getAllElements]);
|
|
143
|
+
const getFunctionCallHandler = useCallback(
|
|
144
|
+
(customEntryPoints) => {
|
|
145
|
+
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
146
|
+
},
|
|
147
|
+
[actions]
|
|
148
|
+
);
|
|
149
|
+
const getDocumentsContext = useCallback(
|
|
150
|
+
(categories) => {
|
|
151
|
+
return allDocuments(categories);
|
|
152
|
+
},
|
|
153
|
+
[allDocuments]
|
|
154
|
+
);
|
|
155
|
+
const addDocumentContext = useCallback(
|
|
156
|
+
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
157
|
+
return addDocument(documentPointer, categories);
|
|
158
|
+
},
|
|
159
|
+
[addDocument]
|
|
160
|
+
);
|
|
161
|
+
const removeDocumentContext = useCallback(
|
|
162
|
+
(documentId) => {
|
|
163
|
+
removeDocument(documentId);
|
|
164
|
+
},
|
|
165
|
+
[removeDocument]
|
|
166
|
+
);
|
|
167
|
+
const copilotApiConfig = useMemo(() => {
|
|
168
|
+
var _a2, _b2;
|
|
169
|
+
let cloud = void 0;
|
|
170
|
+
if (publicApiKey) {
|
|
171
|
+
cloud = {
|
|
172
|
+
guardrails: {
|
|
173
|
+
input: {
|
|
174
|
+
restrictToTopic: {
|
|
175
|
+
enabled: Boolean(props.guardrails_c),
|
|
176
|
+
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
177
|
+
invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return __spreadProps(__spreadValues({
|
|
184
|
+
publicApiKey
|
|
185
|
+
}, cloud ? { cloud } : {}), {
|
|
186
|
+
chatApiEndpoint,
|
|
187
|
+
headers: props.headers || {},
|
|
188
|
+
properties: props.properties || {},
|
|
189
|
+
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
190
|
+
textToSpeechUrl: props.textToSpeechUrl,
|
|
191
|
+
credentials: props.credentials
|
|
192
|
+
});
|
|
193
|
+
}, [
|
|
194
|
+
publicApiKey,
|
|
195
|
+
props.headers,
|
|
196
|
+
props.properties,
|
|
197
|
+
props.transcribeAudioUrl,
|
|
198
|
+
props.textToSpeechUrl,
|
|
199
|
+
props.credentials,
|
|
200
|
+
props.cloudRestrictToTopic,
|
|
201
|
+
props.guardrails_c
|
|
202
|
+
]);
|
|
203
|
+
const headers = useMemo(() => {
|
|
204
|
+
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
205
|
+
if (state.status === "authenticated" && state.authHeaders) {
|
|
206
|
+
return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
|
|
207
|
+
(headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
|
|
208
|
+
[key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
|
|
209
|
+
}),
|
|
210
|
+
{}
|
|
211
|
+
));
|
|
212
|
+
}
|
|
213
|
+
return acc;
|
|
214
|
+
}, {});
|
|
215
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
216
|
+
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
217
|
+
const [internalErrorHandlers, _setInternalErrorHandler] = useState({});
|
|
218
|
+
const setInternalErrorHandler = useCallback((handler) => {
|
|
219
|
+
_setInternalErrorHandler((prev) => __spreadValues(__spreadValues({}, prev), handler));
|
|
220
|
+
}, []);
|
|
221
|
+
const removeInternalErrorHandler = useCallback((key) => {
|
|
222
|
+
_setInternalErrorHandler((prev) => {
|
|
223
|
+
const _a2 = prev, { [key]: _removed } = _a2, rest = __objRest(_a2, [__restKey(key)]);
|
|
224
|
+
return rest;
|
|
225
|
+
});
|
|
226
|
+
}, []);
|
|
227
|
+
const onErrorRef = useRef(props.onError);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
onErrorRef.current = props.onError;
|
|
230
|
+
}, [props.onError]);
|
|
231
|
+
const internalHandlersRef = useRef({});
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
internalHandlersRef.current = internalErrorHandlers;
|
|
234
|
+
}, [internalErrorHandlers]);
|
|
235
|
+
const handleErrors = useCallback(
|
|
236
|
+
(error) => __async(this, null, function* () {
|
|
237
|
+
if (copilotApiConfig.publicApiKey && onErrorRef.current) {
|
|
238
|
+
try {
|
|
239
|
+
yield onErrorRef.current(error);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
console.error("Error in public onError handler:", e);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const handlers = Object.values(internalHandlersRef.current);
|
|
245
|
+
yield Promise.all(
|
|
246
|
+
handlers.map(
|
|
247
|
+
(h) => Promise.resolve(h(error)).catch(
|
|
248
|
+
(e) => console.error("Error in internal error handler:", e)
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
}),
|
|
253
|
+
[copilotApiConfig.publicApiKey]
|
|
254
|
+
);
|
|
255
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState({});
|
|
256
|
+
const addChatSuggestionConfiguration = useCallback(
|
|
257
|
+
(id, suggestion) => {
|
|
258
|
+
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
259
|
+
},
|
|
260
|
+
[setChatSuggestionConfiguration]
|
|
261
|
+
);
|
|
262
|
+
const removeChatSuggestionConfiguration = useCallback(
|
|
263
|
+
(id) => {
|
|
264
|
+
setChatSuggestionConfiguration((prev) => {
|
|
265
|
+
const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
|
|
266
|
+
return rest;
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
[setChatSuggestionConfiguration]
|
|
270
|
+
);
|
|
271
|
+
const [availableAgents, setAvailableAgents] = useState([]);
|
|
272
|
+
const [coagentStates, setCoagentStates] = useState({});
|
|
273
|
+
const coagentStatesRef = useRef({});
|
|
274
|
+
const setCoagentStatesWithRef = useCallback(
|
|
275
|
+
(value) => {
|
|
276
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
277
|
+
coagentStatesRef.current = newValue;
|
|
278
|
+
setCoagentStates((prev) => {
|
|
279
|
+
return newValue;
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
[]
|
|
283
|
+
);
|
|
284
|
+
let initialAgentSession = null;
|
|
285
|
+
if (props.agent) {
|
|
286
|
+
initialAgentSession = {
|
|
287
|
+
agentName: props.agent
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const [agentSession, setAgentSession] = useState(initialAgentSession);
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
if (props.agent) {
|
|
293
|
+
setAgentSession({
|
|
294
|
+
agentName: props.agent
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
setAgentSession(null);
|
|
298
|
+
}
|
|
299
|
+
}, [props.agent]);
|
|
300
|
+
const { threadId, setThreadId: setInternalThreadId } = useThreads();
|
|
301
|
+
const setThreadId = useCallback(
|
|
302
|
+
(value) => {
|
|
303
|
+
if (props.threadId) {
|
|
304
|
+
throw new Error("Cannot call setThreadId() when threadId is provided via props.");
|
|
305
|
+
}
|
|
306
|
+
setInternalThreadId(value);
|
|
307
|
+
},
|
|
308
|
+
[props.threadId]
|
|
309
|
+
);
|
|
310
|
+
const [runId, setRunId] = useState(null);
|
|
311
|
+
const chatAbortControllerRef = useRef(null);
|
|
312
|
+
const showDevConsole = shouldShowDevConsole(props.showDevConsole);
|
|
313
|
+
const [interruptActions, _setInterruptActions] = useState({});
|
|
314
|
+
const setInterruptAction = useCallback(
|
|
315
|
+
(threadId2, action) => {
|
|
316
|
+
_setInterruptActions((prev) => {
|
|
317
|
+
var _a2;
|
|
318
|
+
if (action == null || !action.id) {
|
|
319
|
+
return prev;
|
|
320
|
+
}
|
|
321
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
322
|
+
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
[]
|
|
327
|
+
);
|
|
328
|
+
const removeInterruptAction = useCallback((actionId) => {
|
|
329
|
+
_setInterruptActions((prev) => {
|
|
330
|
+
const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
|
|
331
|
+
return rest;
|
|
332
|
+
});
|
|
333
|
+
}, []);
|
|
334
|
+
const [interruptEventQueue, setInterruptEventQueue] = useState({});
|
|
335
|
+
const addInterruptEvent = useCallback((queuedEvent) => {
|
|
336
|
+
setInterruptEventQueue((prev) => {
|
|
337
|
+
const threadQueue = prev[queuedEvent.threadId] || [];
|
|
338
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
339
|
+
[queuedEvent.threadId]: [...threadQueue, queuedEvent]
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}, []);
|
|
343
|
+
const removeInterruptEvent = useCallback((threadId2, eventId) => {
|
|
344
|
+
setInterruptEventQueue((prev) => {
|
|
345
|
+
const threadQueue = prev[threadId2] || [];
|
|
346
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
347
|
+
[threadId2]: threadQueue.filter((event) => event.eventId !== eventId)
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}, []);
|
|
351
|
+
const memoizedChildren = useMemo(() => children, [children]);
|
|
352
|
+
const [bannerError, setBannerError] = useState(null);
|
|
353
|
+
const agentLock = useMemo(() => {
|
|
354
|
+
var _a2;
|
|
355
|
+
return (_a2 = props.agent) != null ? _a2 : null;
|
|
356
|
+
}, [props.agent]);
|
|
357
|
+
const forwardedParameters = useMemo(
|
|
358
|
+
() => {
|
|
359
|
+
var _a2;
|
|
360
|
+
return (_a2 = props.forwardedParameters) != null ? _a2 : {};
|
|
361
|
+
},
|
|
362
|
+
[props.forwardedParameters]
|
|
363
|
+
);
|
|
364
|
+
const updateExtensions = useCallback(
|
|
365
|
+
(newExtensions) => {
|
|
366
|
+
setExtensions((prev) => {
|
|
367
|
+
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
368
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
369
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
370
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
371
|
+
return isEqual ? prev : resolved;
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
[setExtensions]
|
|
375
|
+
);
|
|
376
|
+
const updateAuthStates = useCallback(
|
|
377
|
+
(newAuthStates) => {
|
|
378
|
+
setAuthStates((prev) => {
|
|
379
|
+
const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
|
|
380
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
381
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
382
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
383
|
+
return isEqual ? prev : resolved;
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
[setAuthStates]
|
|
387
|
+
);
|
|
388
|
+
const handleSetRegisteredActions = useCallback((actionConfig) => {
|
|
389
|
+
const key = actionConfig.action.name || randomUUID();
|
|
390
|
+
setRegisteredActionConfigs((prev) => {
|
|
391
|
+
const newMap = new Map(prev);
|
|
392
|
+
newMap.set(key, actionConfig);
|
|
393
|
+
return newMap;
|
|
394
|
+
});
|
|
395
|
+
return key;
|
|
396
|
+
}, []);
|
|
397
|
+
const handleRemoveRegisteredAction = useCallback((actionKey) => {
|
|
398
|
+
setRegisteredActionConfigs((prev) => {
|
|
399
|
+
const newMap = new Map(prev);
|
|
400
|
+
newMap.delete(actionKey);
|
|
401
|
+
return newMap;
|
|
402
|
+
});
|
|
403
|
+
}, []);
|
|
404
|
+
const RegisteredActionsRenderer = useMemo(() => {
|
|
405
|
+
return () => /* @__PURE__ */ jsx(Fragment, { children: Array.from(registeredActionConfigs.entries()).map(([key, config]) => {
|
|
406
|
+
const Component = config.component;
|
|
407
|
+
return /* @__PURE__ */ jsx(Component, { action: config.action }, key);
|
|
408
|
+
}) });
|
|
409
|
+
}, [registeredActionConfigs]);
|
|
410
|
+
return /* @__PURE__ */ jsx(
|
|
411
|
+
CopilotChatConfigurationProvider,
|
|
412
|
+
{
|
|
413
|
+
agentId: (_b = agentSession == null ? void 0 : agentSession.agentName) != null ? _b : "default",
|
|
414
|
+
threadId,
|
|
415
|
+
children: /* @__PURE__ */ jsxs(
|
|
416
|
+
CopilotContext.Provider,
|
|
417
|
+
{
|
|
418
|
+
value: {
|
|
419
|
+
actions,
|
|
420
|
+
chatComponentsCache,
|
|
421
|
+
getFunctionCallHandler,
|
|
422
|
+
setAction,
|
|
423
|
+
removeAction,
|
|
424
|
+
setRegisteredActions: handleSetRegisteredActions,
|
|
425
|
+
removeRegisteredAction: handleRemoveRegisteredAction,
|
|
426
|
+
getContextString,
|
|
427
|
+
addContext,
|
|
428
|
+
removeContext,
|
|
429
|
+
getAllContext,
|
|
430
|
+
getDocumentsContext,
|
|
431
|
+
addDocumentContext,
|
|
432
|
+
removeDocumentContext,
|
|
433
|
+
copilotApiConfig,
|
|
434
|
+
isLoading,
|
|
435
|
+
setIsLoading,
|
|
436
|
+
chatSuggestionConfiguration,
|
|
437
|
+
addChatSuggestionConfiguration,
|
|
438
|
+
removeChatSuggestionConfiguration,
|
|
439
|
+
chatInstructions,
|
|
440
|
+
setChatInstructions,
|
|
441
|
+
additionalInstructions,
|
|
442
|
+
setAdditionalInstructions,
|
|
443
|
+
showDevConsole,
|
|
444
|
+
coagentStates,
|
|
445
|
+
setCoagentStates,
|
|
446
|
+
coagentStatesRef,
|
|
447
|
+
setCoagentStatesWithRef,
|
|
448
|
+
agentSession,
|
|
449
|
+
setAgentSession,
|
|
450
|
+
forwardedParameters,
|
|
451
|
+
agentLock,
|
|
452
|
+
threadId,
|
|
453
|
+
setThreadId,
|
|
454
|
+
runId,
|
|
455
|
+
setRunId,
|
|
456
|
+
chatAbortControllerRef,
|
|
457
|
+
availableAgents,
|
|
458
|
+
authConfig_c: props.authConfig_c,
|
|
459
|
+
authStates_c: authStates,
|
|
460
|
+
setAuthStates_c: updateAuthStates,
|
|
461
|
+
extensions,
|
|
462
|
+
setExtensions: updateExtensions,
|
|
463
|
+
interruptActions,
|
|
464
|
+
setInterruptAction,
|
|
465
|
+
removeInterruptAction,
|
|
466
|
+
interruptEventQueue,
|
|
467
|
+
addInterruptEvent,
|
|
468
|
+
removeInterruptEvent,
|
|
469
|
+
bannerError,
|
|
470
|
+
setBannerError,
|
|
471
|
+
onError: handleErrors,
|
|
472
|
+
internalErrorHandlers,
|
|
473
|
+
setInternalErrorHandler,
|
|
474
|
+
removeInternalErrorHandler
|
|
475
|
+
},
|
|
476
|
+
children: [
|
|
477
|
+
/* @__PURE__ */ jsx(CopilotListeners, {}),
|
|
478
|
+
/* @__PURE__ */ jsxs(CoAgentStateRendersProvider, { children: [
|
|
479
|
+
/* @__PURE__ */ jsx(MessagesTapProvider, { children: /* @__PURE__ */ jsxs(CopilotMessages, { children: [
|
|
480
|
+
memoizedChildren,
|
|
481
|
+
showDevConsole && /* @__PURE__ */ jsx(ConsoleTrigger, {}),
|
|
482
|
+
/* @__PURE__ */ jsx(RegisteredActionsRenderer, {})
|
|
483
|
+
] }) }),
|
|
484
|
+
bannerError && showDevConsole && /* @__PURE__ */ jsx(
|
|
485
|
+
UsageBanner,
|
|
486
|
+
{
|
|
487
|
+
severity: bannerError.severity,
|
|
488
|
+
message: bannerError.message,
|
|
489
|
+
onClose: () => setBannerError(null),
|
|
490
|
+
actions: getErrorActions(bannerError)
|
|
491
|
+
}
|
|
492
|
+
)
|
|
493
|
+
] })
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
var defaultCopilotContextCategories = ["global"];
|
|
501
|
+
function entryPointsToFunctionCallHandler(actions) {
|
|
502
|
+
return (_0) => __async(this, [_0], function* ({ name, args }) {
|
|
503
|
+
let actionsByFunctionName = {};
|
|
504
|
+
for (let action2 of actions) {
|
|
505
|
+
actionsByFunctionName[action2.name] = action2;
|
|
506
|
+
}
|
|
507
|
+
const action = actionsByFunctionName[name];
|
|
508
|
+
let result = void 0;
|
|
509
|
+
if (action) {
|
|
510
|
+
yield new Promise((resolve, reject) => {
|
|
511
|
+
flushSync(() => __async(this, null, function* () {
|
|
512
|
+
var _a;
|
|
513
|
+
try {
|
|
514
|
+
result = yield (_a = action.handler) == null ? void 0 : _a.call(action, args);
|
|
515
|
+
resolve();
|
|
516
|
+
} catch (error) {
|
|
517
|
+
reject(error);
|
|
518
|
+
}
|
|
519
|
+
}));
|
|
520
|
+
});
|
|
521
|
+
yield new Promise((resolve) => setTimeout(resolve, 20));
|
|
522
|
+
}
|
|
523
|
+
return result;
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
function formatFeatureName(featureName) {
|
|
527
|
+
return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
528
|
+
}
|
|
529
|
+
function validateProps(props) {
|
|
530
|
+
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
531
|
+
const hasApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
532
|
+
if (!props.runtimeUrl && !hasApiKey) {
|
|
533
|
+
throw new ConfigurationError(
|
|
534
|
+
"Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'"
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
if (cloudFeatures.length > 0 && !hasApiKey) {
|
|
538
|
+
throw new MissingPublicApiKeyError(
|
|
539
|
+
`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export {
|
|
545
|
+
CopilotKit,
|
|
546
|
+
CopilotKitInternal,
|
|
547
|
+
defaultCopilotContextCategories
|
|
548
|
+
};
|
|
549
|
+
//# sourceMappingURL=chunk-DCHSCK62.mjs.map
|