@copilotkit/react-core 1.10.7-next.0 → 1.50.0-beta.1
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/CHANGELOG.md +0 -7
- 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-OAGAFMUM.mjs → chunk-3R423LZT.mjs} +6 -5
- package/dist/{chunk-OAGAFMUM.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-E3624YDU.mjs → chunk-GMI4KO4X.mjs} +8 -6
- package/dist/{chunk-E3624YDU.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-EDBI5PCJ.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 +15 -10
- 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 +16 -10
- 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 +17 -10
- 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 +78 -59
- 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 +18 -11
- 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 +18 -11
- 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 +1 -21
- 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 +20 -9
- 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-BXXJQ2BL.mjs +0 -239
- package/dist/chunk-BXXJQ2BL.mjs.map +0 -1
- package/dist/chunk-C6IANC2R.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-GGLAHG3I.mjs +0 -804
- package/dist/chunk-GGLAHG3I.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-MIXSWZSB.mjs +0 -71
- package/dist/chunk-MIXSWZSB.mjs.map +0 -1
- package/dist/chunk-N4WEHORG.mjs.map +0 -1
- package/dist/chunk-NSBAWITG.mjs +0 -332
- package/dist/chunk-NSBAWITG.mjs.map +0 -1
- package/dist/chunk-OT5NHMEC.mjs +0 -723
- package/dist/chunk-OT5NHMEC.mjs.map +0 -1
- package/dist/chunk-T3376SZS.mjs +0 -142
- package/dist/chunk-T3376SZS.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-EDBI5PCJ.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/use-chat.js
DELETED
|
@@ -1,1129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __async = (__this, __arguments, generator) => {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
var fulfilled = (value) => {
|
|
61
|
-
try {
|
|
62
|
-
step(generator.next(value));
|
|
63
|
-
} catch (e) {
|
|
64
|
-
reject(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var rejected = (value) => {
|
|
68
|
-
try {
|
|
69
|
-
step(generator.throw(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
reject(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// src/hooks/use-chat.ts
|
|
80
|
-
var use_chat_exports = {};
|
|
81
|
-
__export(use_chat_exports, {
|
|
82
|
-
useChat: () => useChat
|
|
83
|
-
});
|
|
84
|
-
module.exports = __toCommonJS(use_chat_exports);
|
|
85
|
-
var import_react5 = require("react");
|
|
86
|
-
var import_react_dom = require("react-dom");
|
|
87
|
-
var import_shared4 = require("@copilotkit/shared");
|
|
88
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
89
|
-
|
|
90
|
-
// src/types/frontend-action.ts
|
|
91
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
92
|
-
var import_shared = require("@copilotkit/shared");
|
|
93
|
-
function processActionsForRuntimeRequest(actions) {
|
|
94
|
-
const filteredActions = actions.filter(
|
|
95
|
-
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
96
|
-
).map((action) => {
|
|
97
|
-
let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
|
|
98
|
-
if (action.disabled) {
|
|
99
|
-
available = import_runtime_client_gql.ActionInputAvailability.Disabled;
|
|
100
|
-
} else if (action.available === "disabled") {
|
|
101
|
-
available = import_runtime_client_gql.ActionInputAvailability.Disabled;
|
|
102
|
-
} else if (action.available === "remote") {
|
|
103
|
-
available = import_runtime_client_gql.ActionInputAvailability.Remote;
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
name: action.name,
|
|
107
|
-
description: action.description || "",
|
|
108
|
-
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
|
|
109
|
-
available
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
return filteredActions;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/context/copilot-context.tsx
|
|
116
|
-
var import_react = __toESM(require("react"));
|
|
117
|
-
var emptyCopilotContext = {
|
|
118
|
-
actions: {},
|
|
119
|
-
setAction: () => {
|
|
120
|
-
},
|
|
121
|
-
removeAction: () => {
|
|
122
|
-
},
|
|
123
|
-
coAgentStateRenders: {},
|
|
124
|
-
setCoAgentStateRender: () => {
|
|
125
|
-
},
|
|
126
|
-
removeCoAgentStateRender: () => {
|
|
127
|
-
},
|
|
128
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
129
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
130
|
-
addContext: () => "",
|
|
131
|
-
removeContext: () => {
|
|
132
|
-
},
|
|
133
|
-
getAllContext: () => [],
|
|
134
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
135
|
-
})),
|
|
136
|
-
isLoading: false,
|
|
137
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
138
|
-
chatInstructions: "",
|
|
139
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
140
|
-
additionalInstructions: [],
|
|
141
|
-
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
142
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
143
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
144
|
-
removeDocumentContext: () => {
|
|
145
|
-
},
|
|
146
|
-
runtimeClient: {},
|
|
147
|
-
copilotApiConfig: new class {
|
|
148
|
-
get chatApiEndpoint() {
|
|
149
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
150
|
-
}
|
|
151
|
-
get headers() {
|
|
152
|
-
return {};
|
|
153
|
-
}
|
|
154
|
-
get body() {
|
|
155
|
-
return {};
|
|
156
|
-
}
|
|
157
|
-
}(),
|
|
158
|
-
chatSuggestionConfiguration: {},
|
|
159
|
-
addChatSuggestionConfiguration: () => {
|
|
160
|
-
},
|
|
161
|
-
removeChatSuggestionConfiguration: () => {
|
|
162
|
-
},
|
|
163
|
-
showDevConsole: false,
|
|
164
|
-
coagentStates: {},
|
|
165
|
-
setCoagentStates: () => {
|
|
166
|
-
},
|
|
167
|
-
coagentStatesRef: { current: {} },
|
|
168
|
-
setCoagentStatesWithRef: () => {
|
|
169
|
-
},
|
|
170
|
-
agentSession: null,
|
|
171
|
-
setAgentSession: () => {
|
|
172
|
-
},
|
|
173
|
-
forwardedParameters: {},
|
|
174
|
-
agentLock: null,
|
|
175
|
-
threadId: "",
|
|
176
|
-
setThreadId: () => {
|
|
177
|
-
},
|
|
178
|
-
runId: null,
|
|
179
|
-
setRunId: () => {
|
|
180
|
-
},
|
|
181
|
-
chatAbortControllerRef: { current: null },
|
|
182
|
-
availableAgents: [],
|
|
183
|
-
extensions: {},
|
|
184
|
-
setExtensions: () => {
|
|
185
|
-
},
|
|
186
|
-
langGraphInterruptAction: null,
|
|
187
|
-
setLangGraphInterruptAction: () => {
|
|
188
|
-
},
|
|
189
|
-
removeLangGraphInterruptAction: () => {
|
|
190
|
-
},
|
|
191
|
-
onError: () => {
|
|
192
|
-
},
|
|
193
|
-
bannerError: null,
|
|
194
|
-
setBannerError: () => {
|
|
195
|
-
},
|
|
196
|
-
internalErrorHandlers: {},
|
|
197
|
-
setInternalErrorHandler: () => {
|
|
198
|
-
},
|
|
199
|
-
removeInternalErrorHandler: () => {
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
203
|
-
function useCopilotContext() {
|
|
204
|
-
const context = import_react.default.useContext(CopilotContext);
|
|
205
|
-
if (context === emptyCopilotContext) {
|
|
206
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
207
|
-
}
|
|
208
|
-
return context;
|
|
209
|
-
}
|
|
210
|
-
function returnAndThrowInDebug(_value) {
|
|
211
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
215
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
216
|
-
|
|
217
|
-
// src/components/toast/toast-provider.tsx
|
|
218
|
-
var import_react2 = require("react");
|
|
219
|
-
var import_shared2 = require("@copilotkit/shared");
|
|
220
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
221
|
-
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
222
|
-
function useToast() {
|
|
223
|
-
const context = (0, import_react2.useContext)(ToastContext);
|
|
224
|
-
if (!context) {
|
|
225
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
226
|
-
}
|
|
227
|
-
return context;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
231
|
-
var import_react3 = require("react");
|
|
232
|
-
var import_shared3 = require("@copilotkit/shared");
|
|
233
|
-
var useCopilotRuntimeClient = (options) => {
|
|
234
|
-
const { setBannerError } = useToast();
|
|
235
|
-
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
236
|
-
const lastStructuredErrorRef = (0, import_react3.useRef)(null);
|
|
237
|
-
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
238
|
-
try {
|
|
239
|
-
const errorEvent = {
|
|
240
|
-
type: "error",
|
|
241
|
-
timestamp: Date.now(),
|
|
242
|
-
context: {
|
|
243
|
-
source: "ui",
|
|
244
|
-
request: {
|
|
245
|
-
operation: "runtimeClient",
|
|
246
|
-
url: runtimeOptions.url,
|
|
247
|
-
startTime: Date.now()
|
|
248
|
-
},
|
|
249
|
-
technical: {
|
|
250
|
-
environment: "browser",
|
|
251
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
252
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
error
|
|
256
|
-
};
|
|
257
|
-
yield onError(errorEvent);
|
|
258
|
-
} catch (error2) {
|
|
259
|
-
console.error("Error in onError handler:", error2);
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
263
|
-
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
264
|
-
handleGQLErrors: (error) => {
|
|
265
|
-
var _a2;
|
|
266
|
-
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
267
|
-
const graphQLErrors = error.graphQLErrors;
|
|
268
|
-
const routeError = (gqlError) => {
|
|
269
|
-
const extensions = gqlError.extensions;
|
|
270
|
-
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
271
|
-
if (visibility === import_shared3.ErrorVisibility.SILENT) {
|
|
272
|
-
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const now = Date.now();
|
|
276
|
-
const errorMessage = gqlError.message;
|
|
277
|
-
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
281
|
-
const ckError = createStructuredError(gqlError);
|
|
282
|
-
if (ckError) {
|
|
283
|
-
setBannerError(ckError);
|
|
284
|
-
traceUIError(ckError, gqlError);
|
|
285
|
-
} else {
|
|
286
|
-
const fallbackError = new import_shared3.CopilotKitError({
|
|
287
|
-
message: gqlError.message,
|
|
288
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
289
|
-
});
|
|
290
|
-
setBannerError(fallbackError);
|
|
291
|
-
traceUIError(fallbackError, gqlError);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
graphQLErrors.forEach(routeError);
|
|
295
|
-
} else {
|
|
296
|
-
const fallbackError = new import_shared3.CopilotKitError({
|
|
297
|
-
message: (error == null ? void 0 : error.message) || String(error),
|
|
298
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
299
|
-
});
|
|
300
|
-
setBannerError(fallbackError);
|
|
301
|
-
traceUIError(fallbackError, error);
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
handleGQLWarning: (message) => {
|
|
305
|
-
console.warn(message);
|
|
306
|
-
const warningError = new import_shared3.CopilotKitError({
|
|
307
|
-
message,
|
|
308
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
309
|
-
});
|
|
310
|
-
setBannerError(warningError);
|
|
311
|
-
}
|
|
312
|
-
}));
|
|
313
|
-
}, [runtimeOptions, setBannerError, onError]);
|
|
314
|
-
return runtimeClient;
|
|
315
|
-
};
|
|
316
|
-
function createStructuredError(gqlError) {
|
|
317
|
-
var _a, _b, _c;
|
|
318
|
-
const extensions = gqlError.extensions;
|
|
319
|
-
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
320
|
-
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
321
|
-
const code = extensions == null ? void 0 : extensions.code;
|
|
322
|
-
if (code) {
|
|
323
|
-
return new import_shared3.CopilotKitError({ message, code });
|
|
324
|
-
}
|
|
325
|
-
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
326
|
-
return new import_shared3.CopilotKitApiDiscoveryError({ message });
|
|
327
|
-
}
|
|
328
|
-
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
329
|
-
return new import_shared3.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
330
|
-
}
|
|
331
|
-
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
332
|
-
return new import_shared3.CopilotKitAgentDiscoveryError({
|
|
333
|
-
agentName: "",
|
|
334
|
-
availableAgents: []
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// src/components/error-boundary/error-utils.tsx
|
|
341
|
-
var import_react4 = require("react");
|
|
342
|
-
|
|
343
|
-
// src/components/toast/exclamation-mark-icon.tsx
|
|
344
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
345
|
-
var ExclamationMarkIcon = ({
|
|
346
|
-
className,
|
|
347
|
-
style
|
|
348
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
349
|
-
"svg",
|
|
350
|
-
{
|
|
351
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
352
|
-
width: "24",
|
|
353
|
-
height: "24",
|
|
354
|
-
viewBox: "0 0 24 24",
|
|
355
|
-
fill: "none",
|
|
356
|
-
stroke: "currentColor",
|
|
357
|
-
strokeWidth: "2",
|
|
358
|
-
strokeLinecap: "round",
|
|
359
|
-
strokeLinejoin: "round",
|
|
360
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
361
|
-
style,
|
|
362
|
-
children: [
|
|
363
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
364
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
365
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
366
|
-
]
|
|
367
|
-
}
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
// src/components/error-boundary/error-utils.tsx
|
|
371
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
372
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
373
|
-
function ErrorToast({ errors }) {
|
|
374
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
375
|
-
var _a, _b, _c;
|
|
376
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
377
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
378
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
379
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
380
|
-
"div",
|
|
381
|
-
{
|
|
382
|
-
style: {
|
|
383
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
384
|
-
marginBottom: 14
|
|
385
|
-
},
|
|
386
|
-
children: [
|
|
387
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
388
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
389
|
-
"div",
|
|
390
|
-
{
|
|
391
|
-
style: {
|
|
392
|
-
fontWeight: "600",
|
|
393
|
-
marginBottom: 4
|
|
394
|
-
},
|
|
395
|
-
children: [
|
|
396
|
-
"Copilot Runtime Error:",
|
|
397
|
-
" ",
|
|
398
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
399
|
-
]
|
|
400
|
-
}
|
|
401
|
-
),
|
|
402
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
403
|
-
]
|
|
404
|
-
},
|
|
405
|
-
idx
|
|
406
|
-
);
|
|
407
|
-
});
|
|
408
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
409
|
-
"div",
|
|
410
|
-
{
|
|
411
|
-
style: {
|
|
412
|
-
fontSize: "13px",
|
|
413
|
-
maxWidth: "600px"
|
|
414
|
-
},
|
|
415
|
-
children: [
|
|
416
|
-
errorsToRender,
|
|
417
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
418
|
-
]
|
|
419
|
-
}
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
function useErrorToast() {
|
|
423
|
-
const { addToast } = useToast();
|
|
424
|
-
return (0, import_react4.useCallback)(
|
|
425
|
-
(error) => {
|
|
426
|
-
const errorId = error.map((err) => {
|
|
427
|
-
var _a, _b;
|
|
428
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
429
|
-
const stack = err.stack || "";
|
|
430
|
-
return btoa(message + stack).slice(0, 32);
|
|
431
|
-
}).join("|");
|
|
432
|
-
addToast({
|
|
433
|
-
type: "error",
|
|
434
|
-
id: errorId,
|
|
435
|
-
// Toast libraries typically dedupe by id
|
|
436
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
437
|
-
});
|
|
438
|
-
},
|
|
439
|
-
[addToast]
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
function useAsyncCallback(callback, deps) {
|
|
443
|
-
const addErrorToast = useErrorToast();
|
|
444
|
-
return (0, import_react4.useCallback)((...args) => __async(this, null, function* () {
|
|
445
|
-
try {
|
|
446
|
-
return yield callback(...args);
|
|
447
|
-
} catch (error) {
|
|
448
|
-
console.error("Error in async callback:", error);
|
|
449
|
-
addErrorToast([error]);
|
|
450
|
-
throw error;
|
|
451
|
-
}
|
|
452
|
-
}), deps);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// src/hooks/use-chat.ts
|
|
456
|
-
function useChat(options) {
|
|
457
|
-
const {
|
|
458
|
-
messages,
|
|
459
|
-
setMessages,
|
|
460
|
-
makeSystemMessageCallback,
|
|
461
|
-
copilotConfig,
|
|
462
|
-
setIsLoading,
|
|
463
|
-
initialMessages,
|
|
464
|
-
isLoading,
|
|
465
|
-
actions,
|
|
466
|
-
onFunctionCall,
|
|
467
|
-
onCoAgentStateRender,
|
|
468
|
-
setCoagentStatesWithRef,
|
|
469
|
-
coagentStatesRef,
|
|
470
|
-
agentSession,
|
|
471
|
-
setAgentSession,
|
|
472
|
-
threadId,
|
|
473
|
-
setThreadId,
|
|
474
|
-
runId,
|
|
475
|
-
setRunId,
|
|
476
|
-
chatAbortControllerRef,
|
|
477
|
-
agentLock,
|
|
478
|
-
extensions,
|
|
479
|
-
setExtensions,
|
|
480
|
-
langGraphInterruptAction,
|
|
481
|
-
setLangGraphInterruptAction,
|
|
482
|
-
disableSystemMessage = false
|
|
483
|
-
} = options;
|
|
484
|
-
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
485
|
-
const addErrorToast = useErrorToast();
|
|
486
|
-
const { setBannerError } = useToast();
|
|
487
|
-
const { onError, showDevConsole, getAllContext } = useCopilotContext();
|
|
488
|
-
const copilotReadableContext = getAllContext();
|
|
489
|
-
const context = (0, import_react5.useMemo)(
|
|
490
|
-
() => copilotReadableContext.map((contextItem) => {
|
|
491
|
-
const [description, ...valueParts] = contextItem.value.split(":");
|
|
492
|
-
return {
|
|
493
|
-
description: description.trim(),
|
|
494
|
-
value: valueParts.join(":").trim()
|
|
495
|
-
};
|
|
496
|
-
}),
|
|
497
|
-
[copilotReadableContext]
|
|
498
|
-
);
|
|
499
|
-
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
500
|
-
try {
|
|
501
|
-
const traceEvent = {
|
|
502
|
-
type: "error",
|
|
503
|
-
timestamp: Date.now(),
|
|
504
|
-
context: {
|
|
505
|
-
source: "ui",
|
|
506
|
-
request: {
|
|
507
|
-
operation: "useChatCompletion",
|
|
508
|
-
url: copilotConfig.chatApiEndpoint,
|
|
509
|
-
startTime: Date.now()
|
|
510
|
-
},
|
|
511
|
-
technical: {
|
|
512
|
-
environment: "browser",
|
|
513
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
514
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
error
|
|
518
|
-
};
|
|
519
|
-
yield onError(traceEvent);
|
|
520
|
-
} catch (traceError) {
|
|
521
|
-
console.error("Error in use-chat onError handler:", traceError);
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
525
|
-
agentSessionRef.current = agentSession;
|
|
526
|
-
const runIdRef = (0, import_react5.useRef)(runId);
|
|
527
|
-
runIdRef.current = runId;
|
|
528
|
-
const extensionsRef = (0, import_react5.useRef)(extensions);
|
|
529
|
-
extensionsRef.current = extensions;
|
|
530
|
-
const publicApiKey = copilotConfig.publicApiKey;
|
|
531
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
532
|
-
const runtimeClient = useCopilotRuntimeClient({
|
|
533
|
-
url: copilotConfig.chatApiEndpoint,
|
|
534
|
-
publicApiKey: copilotConfig.publicApiKey,
|
|
535
|
-
headers,
|
|
536
|
-
credentials: copilotConfig.credentials,
|
|
537
|
-
showDevConsole,
|
|
538
|
-
onError
|
|
539
|
-
});
|
|
540
|
-
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
541
|
-
const runChatCompletion = useAsyncCallback(
|
|
542
|
-
(previousMessages) => __async(this, null, function* () {
|
|
543
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
544
|
-
setIsLoading(true);
|
|
545
|
-
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
546
|
-
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
547
|
-
addErrorToast([
|
|
548
|
-
new Error(
|
|
549
|
-
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
550
|
-
)
|
|
551
|
-
]);
|
|
552
|
-
}
|
|
553
|
-
let newMessages = [
|
|
554
|
-
new import_runtime_client_gql3.TextMessage({
|
|
555
|
-
content: "",
|
|
556
|
-
role: import_runtime_client_gql3.Role.Assistant
|
|
557
|
-
})
|
|
558
|
-
];
|
|
559
|
-
chatAbortControllerRef.current = new AbortController();
|
|
560
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
561
|
-
const messagesWithContext = disableSystemMessage ? [...initialMessages || [], ...previousMessages] : [makeSystemMessageCallback(), ...initialMessages || [], ...previousMessages];
|
|
562
|
-
const finalProperties = __spreadValues({}, copilotConfig.properties || {});
|
|
563
|
-
let mcpServersToUse = null;
|
|
564
|
-
if (copilotConfig.mcpServers && Array.isArray(copilotConfig.mcpServers) && copilotConfig.mcpServers.length > 0) {
|
|
565
|
-
mcpServersToUse = copilotConfig.mcpServers;
|
|
566
|
-
} else if (((_a = copilotConfig.properties) == null ? void 0 : _a.mcpServers) && Array.isArray(copilotConfig.properties.mcpServers) && copilotConfig.properties.mcpServers.length > 0) {
|
|
567
|
-
mcpServersToUse = copilotConfig.properties.mcpServers;
|
|
568
|
-
}
|
|
569
|
-
if (mcpServersToUse) {
|
|
570
|
-
finalProperties.mcpServers = mcpServersToUse;
|
|
571
|
-
copilotConfig.mcpServers = mcpServersToUse;
|
|
572
|
-
}
|
|
573
|
-
const isAgentRun = agentSessionRef.current !== null;
|
|
574
|
-
const stream = runtimeClient.asStream(
|
|
575
|
-
runtimeClient.generateCopilotResponse({
|
|
576
|
-
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
577
|
-
frontend: {
|
|
578
|
-
actions: processActionsForRuntimeRequest(actions),
|
|
579
|
-
url: window.location.href
|
|
580
|
-
},
|
|
581
|
-
threadId,
|
|
582
|
-
runId: runIdRef.current,
|
|
583
|
-
extensions: extensionsRef.current,
|
|
584
|
-
metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
|
|
585
|
-
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
|
|
586
|
-
}, copilotConfig.cloud ? {
|
|
587
|
-
cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
|
|
588
|
-
guardrails: {
|
|
589
|
-
inputValidationRules: {
|
|
590
|
-
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
591
|
-
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
} : {})
|
|
595
|
-
} : {}), {
|
|
596
|
-
metadata: {
|
|
597
|
-
requestType: import_runtime_client_gql3.CopilotRequestType.Chat
|
|
598
|
-
}
|
|
599
|
-
}), agentSessionRef.current ? {
|
|
600
|
-
agentSession: agentSessionRef.current
|
|
601
|
-
} : {}), {
|
|
602
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) => {
|
|
603
|
-
const stateObject = {
|
|
604
|
-
agentName: state.name,
|
|
605
|
-
state: JSON.stringify(state.state)
|
|
606
|
-
};
|
|
607
|
-
if (state.config !== void 0) {
|
|
608
|
-
stateObject.config = JSON.stringify(state.config);
|
|
609
|
-
}
|
|
610
|
-
return stateObject;
|
|
611
|
-
}),
|
|
612
|
-
forwardedParameters: options.forwardedParameters || {},
|
|
613
|
-
context
|
|
614
|
-
}),
|
|
615
|
-
properties: finalProperties,
|
|
616
|
-
signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
|
|
617
|
-
})
|
|
618
|
-
);
|
|
619
|
-
const guardrailsEnabled = ((_h = (_g = (_f = copilotConfig.cloud) == null ? void 0 : _f.guardrails) == null ? void 0 : _g.input) == null ? void 0 : _h.restrictToTopic.enabled) || false;
|
|
620
|
-
const reader = stream.getReader();
|
|
621
|
-
let executedCoAgentStateRenders = [];
|
|
622
|
-
let followUp = void 0;
|
|
623
|
-
let messages2 = [];
|
|
624
|
-
let syncedMessages = [];
|
|
625
|
-
let interruptMessages = [];
|
|
626
|
-
try {
|
|
627
|
-
while (true) {
|
|
628
|
-
let done, value;
|
|
629
|
-
try {
|
|
630
|
-
const readResult = yield reader.read();
|
|
631
|
-
done = readResult.done;
|
|
632
|
-
value = readResult.value;
|
|
633
|
-
} catch (readError) {
|
|
634
|
-
break;
|
|
635
|
-
}
|
|
636
|
-
if (done) {
|
|
637
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
638
|
-
return [];
|
|
639
|
-
}
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
643
|
-
continue;
|
|
644
|
-
}
|
|
645
|
-
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
646
|
-
extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
|
|
647
|
-
value.generateCopilotResponse.extensions || {}
|
|
648
|
-
);
|
|
649
|
-
setRunId(runIdRef.current);
|
|
650
|
-
setExtensions(extensionsRef.current);
|
|
651
|
-
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
652
|
-
const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
|
|
653
|
-
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
654
|
-
if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
|
|
655
|
-
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
656
|
-
eventValue = (0, import_shared4.parseJson)(eventValue, eventValue);
|
|
657
|
-
setLangGraphInterruptAction(threadId, {
|
|
658
|
-
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
659
|
-
value: eventValue
|
|
660
|
-
})
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
if (ev.name === import_runtime_client_gql3.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
664
|
-
const data = ev.data;
|
|
665
|
-
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
666
|
-
interruptMessages = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
667
|
-
// @ts-ignore
|
|
668
|
-
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(data.messages)
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
673
|
-
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
674
|
-
);
|
|
675
|
-
newMessages = [];
|
|
676
|
-
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
677
|
-
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
678
|
-
newMessages = [
|
|
679
|
-
new import_runtime_client_gql3.TextMessage({
|
|
680
|
-
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
681
|
-
content: guardrailsReason
|
|
682
|
-
})
|
|
683
|
-
];
|
|
684
|
-
const guardrailsError = new import_shared4.CopilotKitError({
|
|
685
|
-
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
686
|
-
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
687
|
-
});
|
|
688
|
-
yield traceUIError(guardrailsError, {
|
|
689
|
-
statusReason: value.generateCopilotResponse.status.reason,
|
|
690
|
-
statusDetails: value.generateCopilotResponse.status.details
|
|
691
|
-
});
|
|
692
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
696
|
-
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
697
|
-
const statusDetails = value.generateCopilotResponse.status.details;
|
|
698
|
-
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
699
|
-
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
700
|
-
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
701
|
-
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
702
|
-
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
703
|
-
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
704
|
-
errorCode = originalCode;
|
|
705
|
-
}
|
|
706
|
-
const structuredError = new import_shared4.CopilotKitError({
|
|
707
|
-
message: errorMessage,
|
|
708
|
-
code: errorCode,
|
|
709
|
-
severity: originalSeverity,
|
|
710
|
-
visibility: originalVisibility
|
|
711
|
-
});
|
|
712
|
-
setBannerError(structuredError);
|
|
713
|
-
yield traceUIError(structuredError, {
|
|
714
|
-
statusReason: value.generateCopilotResponse.status.reason,
|
|
715
|
-
statusDetails: value.generateCopilotResponse.status.details,
|
|
716
|
-
originalErrorCode: originalCode,
|
|
717
|
-
preservedStructure: !!originalCode
|
|
718
|
-
});
|
|
719
|
-
setIsLoading(false);
|
|
720
|
-
throw new Error(structuredError.message);
|
|
721
|
-
} else if (messages2.length > 0) {
|
|
722
|
-
newMessages = [...messages2];
|
|
723
|
-
for (const message of messages2) {
|
|
724
|
-
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
725
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
726
|
-
break;
|
|
727
|
-
}
|
|
728
|
-
yield onCoAgentStateRender({
|
|
729
|
-
name: message.agentName,
|
|
730
|
-
nodeName: message.nodeName,
|
|
731
|
-
state: message.state
|
|
732
|
-
});
|
|
733
|
-
executedCoAgentStateRenders.push(message.id);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
737
|
-
if (lastAgentStateMessage) {
|
|
738
|
-
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
739
|
-
syncedMessages = (0, import_runtime_client_gql3.loadMessagesFromJsonRepresentation)(
|
|
740
|
-
lastAgentStateMessage.state.messages
|
|
741
|
-
);
|
|
742
|
-
}
|
|
743
|
-
setCoagentStatesWithRef((prevAgentStates) => {
|
|
744
|
-
var _a2;
|
|
745
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
746
|
-
[lastAgentStateMessage.agentName]: {
|
|
747
|
-
name: lastAgentStateMessage.agentName,
|
|
748
|
-
state: lastAgentStateMessage.state,
|
|
749
|
-
running: lastAgentStateMessage.running,
|
|
750
|
-
active: lastAgentStateMessage.active,
|
|
751
|
-
threadId: lastAgentStateMessage.threadId,
|
|
752
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
753
|
-
runId: lastAgentStateMessage.runId,
|
|
754
|
-
// Preserve existing config from previous state
|
|
755
|
-
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
});
|
|
759
|
-
if (lastAgentStateMessage.running) {
|
|
760
|
-
setAgentSession({
|
|
761
|
-
threadId: lastAgentStateMessage.threadId,
|
|
762
|
-
agentName: lastAgentStateMessage.agentName,
|
|
763
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
764
|
-
});
|
|
765
|
-
} else {
|
|
766
|
-
if (agentLock) {
|
|
767
|
-
setAgentSession({
|
|
768
|
-
threadId: (0, import_shared4.randomId)(),
|
|
769
|
-
agentName: agentLock,
|
|
770
|
-
nodeName: void 0
|
|
771
|
-
});
|
|
772
|
-
} else {
|
|
773
|
-
setAgentSession(null);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
if (newMessages.length > 0) {
|
|
779
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
let finalMessages = constructFinalMessages(
|
|
783
|
-
[...syncedMessages, ...interruptMessages],
|
|
784
|
-
previousMessages,
|
|
785
|
-
newMessages
|
|
786
|
-
);
|
|
787
|
-
let didExecuteAction = false;
|
|
788
|
-
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
789
|
-
var _a2;
|
|
790
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
791
|
-
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
792
|
-
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
793
|
-
currentAction._setActivatingMessageId(actionMessage.id);
|
|
794
|
-
}
|
|
795
|
-
const resultMessage = yield executeAction({
|
|
796
|
-
onFunctionCall,
|
|
797
|
-
message: actionMessage,
|
|
798
|
-
chatAbortControllerRef,
|
|
799
|
-
onError: (error) => {
|
|
800
|
-
addErrorToast([error]);
|
|
801
|
-
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
802
|
-
},
|
|
803
|
-
setMessages,
|
|
804
|
-
getFinalMessages: () => finalMessages,
|
|
805
|
-
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
806
|
-
});
|
|
807
|
-
didExecuteAction = true;
|
|
808
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
809
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
810
|
-
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
811
|
-
const messagesForImmediateUpdate = [...finalMessages];
|
|
812
|
-
(0, import_react_dom.flushSync)(() => {
|
|
813
|
-
setMessages(messagesForImmediateUpdate);
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
817
|
-
currentAction._setActivatingMessageId(null);
|
|
818
|
-
}
|
|
819
|
-
return resultMessage;
|
|
820
|
-
});
|
|
821
|
-
if (onFunctionCall) {
|
|
822
|
-
const lastMessages = [];
|
|
823
|
-
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
824
|
-
const message = finalMessages[i];
|
|
825
|
-
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
826
|
-
lastMessages.unshift(message);
|
|
827
|
-
} else if (!message.isAgentStateMessage()) {
|
|
828
|
-
break;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
for (const message of lastMessages) {
|
|
832
|
-
setMessages(finalMessages);
|
|
833
|
-
const action = actions.find(
|
|
834
|
-
(action2) => action2.name === message.name
|
|
835
|
-
);
|
|
836
|
-
if (action && action.available === "frontend") {
|
|
837
|
-
continue;
|
|
838
|
-
}
|
|
839
|
-
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
840
|
-
if (action && message.isActionExecutionMessage()) {
|
|
841
|
-
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
842
|
-
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
843
|
-
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
844
|
-
);
|
|
845
|
-
if (alreadyProcessed) {
|
|
846
|
-
} else {
|
|
847
|
-
const resultMessage = yield executeActionFromMessage(
|
|
848
|
-
action,
|
|
849
|
-
message
|
|
850
|
-
);
|
|
851
|
-
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
852
|
-
if (pairedFeAction) {
|
|
853
|
-
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
854
|
-
name: pairedFeAction.name,
|
|
855
|
-
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
856
|
-
status: message.status,
|
|
857
|
-
createdAt: message.createdAt,
|
|
858
|
-
parentMessageId: message.parentMessageId
|
|
859
|
-
});
|
|
860
|
-
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
864
|
-
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
865
|
-
name: currentResultMessagePairedFeAction.name,
|
|
866
|
-
arguments: (0, import_shared4.parseJson)(message.result, message.result),
|
|
867
|
-
status: message.status,
|
|
868
|
-
createdAt: message.createdAt
|
|
869
|
-
});
|
|
870
|
-
finalMessages.push(newExecutionMessage);
|
|
871
|
-
yield executeActionFromMessage(
|
|
872
|
-
currentResultMessagePairedFeAction,
|
|
873
|
-
newExecutionMessage
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
setMessages(finalMessages);
|
|
878
|
-
}
|
|
879
|
-
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
880
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
881
|
-
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
882
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
883
|
-
return yield runChatCompletionRef.current(finalMessages);
|
|
884
|
-
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
885
|
-
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
886
|
-
if (message.isActionExecutionMessage()) {
|
|
887
|
-
return finalMessages.find(
|
|
888
|
-
(msg, resultIndex) => msg.isResultMessage() && msg.actionExecutionId === message.id && resultIndex === actionExecutionIndex + 1
|
|
889
|
-
);
|
|
890
|
-
}
|
|
891
|
-
return true;
|
|
892
|
-
});
|
|
893
|
-
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
894
|
-
setMessages(repairedMessages);
|
|
895
|
-
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
896
|
-
setAgentSession({
|
|
897
|
-
threadId: agentSessionRef.current.threadId,
|
|
898
|
-
agentName: agentSessionRef.current.agentName,
|
|
899
|
-
nodeName: "__end__"
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
return newMessages.filter((message) => repairedMessageIds.includes(message.id));
|
|
903
|
-
} else {
|
|
904
|
-
return newMessages.slice();
|
|
905
|
-
}
|
|
906
|
-
} finally {
|
|
907
|
-
setIsLoading(false);
|
|
908
|
-
}
|
|
909
|
-
}),
|
|
910
|
-
[
|
|
911
|
-
messages,
|
|
912
|
-
setMessages,
|
|
913
|
-
makeSystemMessageCallback,
|
|
914
|
-
copilotConfig,
|
|
915
|
-
setIsLoading,
|
|
916
|
-
initialMessages,
|
|
917
|
-
isLoading,
|
|
918
|
-
actions,
|
|
919
|
-
onFunctionCall,
|
|
920
|
-
onCoAgentStateRender,
|
|
921
|
-
setCoagentStatesWithRef,
|
|
922
|
-
coagentStatesRef,
|
|
923
|
-
agentSession,
|
|
924
|
-
setAgentSession,
|
|
925
|
-
disableSystemMessage,
|
|
926
|
-
context
|
|
927
|
-
]
|
|
928
|
-
);
|
|
929
|
-
runChatCompletionRef.current = runChatCompletion;
|
|
930
|
-
const runChatCompletionAndHandleFunctionCall = useAsyncCallback(
|
|
931
|
-
(messages2) => __async(this, null, function* () {
|
|
932
|
-
yield runChatCompletionRef.current(messages2);
|
|
933
|
-
}),
|
|
934
|
-
[messages]
|
|
935
|
-
);
|
|
936
|
-
(0, import_react5.useEffect)(() => {
|
|
937
|
-
if (!isLoading && pendingAppendsRef.current.length > 0) {
|
|
938
|
-
const pending = pendingAppendsRef.current.splice(0);
|
|
939
|
-
const followUp = pending.some((p) => p.followUp);
|
|
940
|
-
const newMessages = [...messages, ...pending.map((p) => p.message)];
|
|
941
|
-
setMessages(newMessages);
|
|
942
|
-
if (followUp) {
|
|
943
|
-
runChatCompletionAndHandleFunctionCall(newMessages);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
947
|
-
const composeAndFlushMetaEventsInput = (0, import_react5.useCallback)(
|
|
948
|
-
(metaEvents) => {
|
|
949
|
-
return metaEvents.reduce((acc, event) => {
|
|
950
|
-
if (!event)
|
|
951
|
-
return acc;
|
|
952
|
-
switch (event.name) {
|
|
953
|
-
case import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent:
|
|
954
|
-
if (event.response) {
|
|
955
|
-
setLangGraphInterruptAction(threadId, null);
|
|
956
|
-
const value = event.value;
|
|
957
|
-
return [
|
|
958
|
-
...acc,
|
|
959
|
-
{
|
|
960
|
-
name: event.name,
|
|
961
|
-
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
962
|
-
response: typeof event.response === "string" ? event.response : JSON.stringify(event.response)
|
|
963
|
-
}
|
|
964
|
-
];
|
|
965
|
-
}
|
|
966
|
-
return acc;
|
|
967
|
-
default:
|
|
968
|
-
return acc;
|
|
969
|
-
}
|
|
970
|
-
}, []);
|
|
971
|
-
},
|
|
972
|
-
[setLangGraphInterruptAction]
|
|
973
|
-
);
|
|
974
|
-
const append = useAsyncCallback(
|
|
975
|
-
(message, options2) => __async(this, null, function* () {
|
|
976
|
-
var _a;
|
|
977
|
-
const followUp = (_a = options2 == null ? void 0 : options2.followUp) != null ? _a : true;
|
|
978
|
-
if (isLoading) {
|
|
979
|
-
pendingAppendsRef.current.push({ message, followUp });
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
const newMessages = [...messages, message];
|
|
983
|
-
setMessages(newMessages);
|
|
984
|
-
if (followUp) {
|
|
985
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
986
|
-
}
|
|
987
|
-
}),
|
|
988
|
-
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
989
|
-
);
|
|
990
|
-
const reload = useAsyncCallback(
|
|
991
|
-
(reloadMessageId) => __async(this, null, function* () {
|
|
992
|
-
if (isLoading || messages.length === 0) {
|
|
993
|
-
return;
|
|
994
|
-
}
|
|
995
|
-
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
996
|
-
if (reloadMessageIndex === -1) {
|
|
997
|
-
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
1001
|
-
if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
|
|
1002
|
-
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
let historyCutoff = [messages[0]];
|
|
1006
|
-
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
1007
|
-
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
1008
|
-
(msg) => (
|
|
1009
|
-
// @ts-expect-error -- message has role
|
|
1010
|
-
msg.role === import_runtime_client_gql3.MessageRole.User
|
|
1011
|
-
)
|
|
1012
|
-
);
|
|
1013
|
-
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1014
|
-
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1015
|
-
);
|
|
1016
|
-
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
1017
|
-
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
1018
|
-
historyCutoff = [messages[0], messages[1]];
|
|
1019
|
-
}
|
|
1020
|
-
setMessages(historyCutoff);
|
|
1021
|
-
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
1022
|
-
}),
|
|
1023
|
-
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
1024
|
-
);
|
|
1025
|
-
const stop = () => {
|
|
1026
|
-
var _a;
|
|
1027
|
-
(_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
|
|
1028
|
-
};
|
|
1029
|
-
return {
|
|
1030
|
-
append,
|
|
1031
|
-
reload,
|
|
1032
|
-
stop,
|
|
1033
|
-
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
1037
|
-
const finalMessages = syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];
|
|
1038
|
-
if (syncedMessages.length > 0) {
|
|
1039
|
-
const messagesWithAgentState = [...previousMessages, ...newMessages];
|
|
1040
|
-
let previousMessageId = void 0;
|
|
1041
|
-
for (const message of messagesWithAgentState) {
|
|
1042
|
-
if (message.isAgentStateMessage()) {
|
|
1043
|
-
const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);
|
|
1044
|
-
if (index !== -1) {
|
|
1045
|
-
finalMessages.splice(index + 1, 0, message);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
previousMessageId = message.id;
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
return finalMessages;
|
|
1052
|
-
}
|
|
1053
|
-
function executeAction(_0) {
|
|
1054
|
-
return __async(this, arguments, function* ({
|
|
1055
|
-
onFunctionCall,
|
|
1056
|
-
message,
|
|
1057
|
-
chatAbortControllerRef,
|
|
1058
|
-
onError,
|
|
1059
|
-
setMessages,
|
|
1060
|
-
getFinalMessages,
|
|
1061
|
-
isRenderAndWait
|
|
1062
|
-
}) {
|
|
1063
|
-
let result;
|
|
1064
|
-
let error = null;
|
|
1065
|
-
const currentMessagesForHandler = getFinalMessages();
|
|
1066
|
-
const handlerReturnedPromise = onFunctionCall({
|
|
1067
|
-
messages: currentMessagesForHandler,
|
|
1068
|
-
name: message.name,
|
|
1069
|
-
args: message.arguments
|
|
1070
|
-
});
|
|
1071
|
-
if (isRenderAndWait) {
|
|
1072
|
-
const currentMessagesForRender = getFinalMessages();
|
|
1073
|
-
(0, import_react_dom.flushSync)(() => {
|
|
1074
|
-
setMessages([...currentMessagesForRender]);
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
try {
|
|
1078
|
-
result = yield Promise.race([
|
|
1079
|
-
handlerReturnedPromise,
|
|
1080
|
-
// Await the promise returned by the handler
|
|
1081
|
-
new Promise(
|
|
1082
|
-
(resolve) => {
|
|
1083
|
-
var _a;
|
|
1084
|
-
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
1085
|
-
"abort",
|
|
1086
|
-
() => resolve("Operation was aborted by the user")
|
|
1087
|
-
);
|
|
1088
|
-
}
|
|
1089
|
-
),
|
|
1090
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
1091
|
-
new Promise((resolve) => {
|
|
1092
|
-
var _a;
|
|
1093
|
-
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
1094
|
-
resolve("Operation was aborted by the user");
|
|
1095
|
-
}
|
|
1096
|
-
})
|
|
1097
|
-
]);
|
|
1098
|
-
} catch (e) {
|
|
1099
|
-
onError(e);
|
|
1100
|
-
}
|
|
1101
|
-
return new import_runtime_client_gql3.ResultMessage({
|
|
1102
|
-
id: "result-" + message.id,
|
|
1103
|
-
result: import_runtime_client_gql3.ResultMessage.encodeResult(
|
|
1104
|
-
error ? {
|
|
1105
|
-
content: result,
|
|
1106
|
-
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
1107
|
-
} : result
|
|
1108
|
-
),
|
|
1109
|
-
actionExecutionId: message.id,
|
|
1110
|
-
actionName: message.name
|
|
1111
|
-
});
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
function getPairedFeAction(actions, message) {
|
|
1115
|
-
let actionName = null;
|
|
1116
|
-
if (message.isActionExecutionMessage()) {
|
|
1117
|
-
actionName = message.name;
|
|
1118
|
-
} else if (message.isResultMessage()) {
|
|
1119
|
-
actionName = message.actionName;
|
|
1120
|
-
}
|
|
1121
|
-
return actions.find(
|
|
1122
|
-
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1126
|
-
0 && (module.exports = {
|
|
1127
|
-
useChat
|
|
1128
|
-
});
|
|
1129
|
-
//# sourceMappingURL=use-chat.js.map
|