@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
|
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
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
25
|
var __export = (target, all) => {
|
|
38
26
|
for (var name in all)
|
|
39
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -82,7 +70,7 @@ __export(use_langgraph_interrupt_exports, {
|
|
|
82
70
|
useLangGraphInterrupt: () => useLangGraphInterrupt
|
|
83
71
|
});
|
|
84
72
|
module.exports = __toCommonJS(use_langgraph_interrupt_exports);
|
|
85
|
-
var
|
|
73
|
+
var import_react3 = require("react");
|
|
86
74
|
|
|
87
75
|
// src/context/copilot-context.tsx
|
|
88
76
|
var import_react = __toESM(require("react"));
|
|
@@ -92,10 +80,8 @@ var emptyCopilotContext = {
|
|
|
92
80
|
},
|
|
93
81
|
removeAction: () => {
|
|
94
82
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
removeCoAgentStateRender: () => {
|
|
83
|
+
setRegisteredActions: () => "",
|
|
84
|
+
removeRegisteredAction: () => {
|
|
99
85
|
},
|
|
100
86
|
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
101
87
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
@@ -115,7 +101,6 @@ var emptyCopilotContext = {
|
|
|
115
101
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
116
102
|
removeDocumentContext: () => {
|
|
117
103
|
},
|
|
118
|
-
runtimeClient: {},
|
|
119
104
|
copilotApiConfig: new class {
|
|
120
105
|
get chatApiEndpoint() {
|
|
121
106
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -155,10 +140,15 @@ var emptyCopilotContext = {
|
|
|
155
140
|
extensions: {},
|
|
156
141
|
setExtensions: () => {
|
|
157
142
|
},
|
|
158
|
-
|
|
159
|
-
|
|
143
|
+
interruptActions: {},
|
|
144
|
+
setInterruptAction: () => {
|
|
145
|
+
},
|
|
146
|
+
removeInterruptAction: () => {
|
|
160
147
|
},
|
|
161
|
-
|
|
148
|
+
interruptEventQueue: {},
|
|
149
|
+
addInterruptEvent: () => {
|
|
150
|
+
},
|
|
151
|
+
removeInterruptEvent: () => {
|
|
162
152
|
},
|
|
163
153
|
onError: () => {
|
|
164
154
|
},
|
|
@@ -172,1645 +162,37 @@ var emptyCopilotContext = {
|
|
|
172
162
|
}
|
|
173
163
|
};
|
|
174
164
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
175
|
-
function useCopilotContext() {
|
|
176
|
-
const context = import_react.default.useContext(CopilotContext);
|
|
177
|
-
if (context === emptyCopilotContext) {
|
|
178
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
179
|
-
}
|
|
180
|
-
return context;
|
|
181
|
-
}
|
|
182
165
|
function returnAndThrowInDebug(_value) {
|
|
183
166
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
184
167
|
}
|
|
185
168
|
|
|
186
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
187
|
-
var import_react9 = require("react");
|
|
188
|
-
|
|
189
|
-
// src/context/copilot-messages-context.tsx
|
|
190
|
-
var import_react2 = __toESM(require("react"));
|
|
191
|
-
var emptyCopilotContext2 = {
|
|
192
|
-
messages: [],
|
|
193
|
-
setMessages: () => [],
|
|
194
|
-
// suggestions state
|
|
195
|
-
suggestions: [],
|
|
196
|
-
setSuggestions: () => []
|
|
197
|
-
};
|
|
198
|
-
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
199
|
-
function useCopilotMessagesContext() {
|
|
200
|
-
const context = import_react2.default.useContext(CopilotMessagesContext);
|
|
201
|
-
if (context === emptyCopilotContext2) {
|
|
202
|
-
throw new Error(
|
|
203
|
-
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
return context;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/hooks/use-chat.ts
|
|
210
|
-
var import_react6 = require("react");
|
|
211
|
-
var import_react_dom = require("react-dom");
|
|
212
|
-
var import_shared4 = require("@copilotkit/shared");
|
|
213
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
214
|
-
|
|
215
|
-
// src/types/frontend-action.ts
|
|
216
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
217
|
-
var import_shared = require("@copilotkit/shared");
|
|
218
|
-
function processActionsForRuntimeRequest(actions) {
|
|
219
|
-
const filteredActions = actions.filter(
|
|
220
|
-
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
221
|
-
).map((action) => {
|
|
222
|
-
let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
|
|
223
|
-
if (action.disabled) {
|
|
224
|
-
available = import_runtime_client_gql.ActionInputAvailability.Disabled;
|
|
225
|
-
} else if (action.available === "disabled") {
|
|
226
|
-
available = import_runtime_client_gql.ActionInputAvailability.Disabled;
|
|
227
|
-
} else if (action.available === "remote") {
|
|
228
|
-
available = import_runtime_client_gql.ActionInputAvailability.Remote;
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
name: action.name,
|
|
232
|
-
description: action.description || "",
|
|
233
|
-
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
|
|
234
|
-
available
|
|
235
|
-
};
|
|
236
|
-
});
|
|
237
|
-
return filteredActions;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
241
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
242
|
-
|
|
243
169
|
// src/components/toast/toast-provider.tsx
|
|
244
|
-
var
|
|
245
|
-
var
|
|
170
|
+
var import_react2 = require("react");
|
|
171
|
+
var import_shared = require("@copilotkit/shared");
|
|
246
172
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
247
|
-
var ToastContext = (0,
|
|
173
|
+
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
248
174
|
function useToast() {
|
|
249
|
-
const context = (0,
|
|
175
|
+
const context = (0, import_react2.useContext)(ToastContext);
|
|
250
176
|
if (!context) {
|
|
251
177
|
throw new Error("useToast must be used within a ToastProvider");
|
|
252
178
|
}
|
|
253
179
|
return context;
|
|
254
180
|
}
|
|
255
181
|
|
|
256
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
257
|
-
var import_react4 = require("react");
|
|
258
|
-
var import_shared3 = require("@copilotkit/shared");
|
|
259
|
-
var useCopilotRuntimeClient = (options) => {
|
|
260
|
-
const { setBannerError } = useToast();
|
|
261
|
-
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
262
|
-
const lastStructuredErrorRef = (0, import_react4.useRef)(null);
|
|
263
|
-
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
264
|
-
try {
|
|
265
|
-
const errorEvent = {
|
|
266
|
-
type: "error",
|
|
267
|
-
timestamp: Date.now(),
|
|
268
|
-
context: {
|
|
269
|
-
source: "ui",
|
|
270
|
-
request: {
|
|
271
|
-
operation: "runtimeClient",
|
|
272
|
-
url: runtimeOptions.url,
|
|
273
|
-
startTime: Date.now()
|
|
274
|
-
},
|
|
275
|
-
technical: {
|
|
276
|
-
environment: "browser",
|
|
277
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
278
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
error
|
|
282
|
-
};
|
|
283
|
-
yield onError(errorEvent);
|
|
284
|
-
} catch (error2) {
|
|
285
|
-
console.error("Error in onError handler:", error2);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
const runtimeClient = (0, import_react4.useMemo)(() => {
|
|
289
|
-
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
290
|
-
handleGQLErrors: (error) => {
|
|
291
|
-
var _a2;
|
|
292
|
-
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
293
|
-
const graphQLErrors = error.graphQLErrors;
|
|
294
|
-
const routeError = (gqlError) => {
|
|
295
|
-
const extensions = gqlError.extensions;
|
|
296
|
-
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
297
|
-
if (visibility === import_shared3.ErrorVisibility.SILENT) {
|
|
298
|
-
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const now = Date.now();
|
|
302
|
-
const errorMessage = gqlError.message;
|
|
303
|
-
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
307
|
-
const ckError = createStructuredError(gqlError);
|
|
308
|
-
if (ckError) {
|
|
309
|
-
setBannerError(ckError);
|
|
310
|
-
traceUIError(ckError, gqlError);
|
|
311
|
-
} else {
|
|
312
|
-
const fallbackError = new import_shared3.CopilotKitError({
|
|
313
|
-
message: gqlError.message,
|
|
314
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
315
|
-
});
|
|
316
|
-
setBannerError(fallbackError);
|
|
317
|
-
traceUIError(fallbackError, gqlError);
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
graphQLErrors.forEach(routeError);
|
|
321
|
-
} else {
|
|
322
|
-
const fallbackError = new import_shared3.CopilotKitError({
|
|
323
|
-
message: (error == null ? void 0 : error.message) || String(error),
|
|
324
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
325
|
-
});
|
|
326
|
-
setBannerError(fallbackError);
|
|
327
|
-
traceUIError(fallbackError, error);
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
handleGQLWarning: (message) => {
|
|
331
|
-
console.warn(message);
|
|
332
|
-
const warningError = new import_shared3.CopilotKitError({
|
|
333
|
-
message,
|
|
334
|
-
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
335
|
-
});
|
|
336
|
-
setBannerError(warningError);
|
|
337
|
-
}
|
|
338
|
-
}));
|
|
339
|
-
}, [runtimeOptions, setBannerError, onError]);
|
|
340
|
-
return runtimeClient;
|
|
341
|
-
};
|
|
342
|
-
function createStructuredError(gqlError) {
|
|
343
|
-
var _a, _b, _c;
|
|
344
|
-
const extensions = gqlError.extensions;
|
|
345
|
-
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
346
|
-
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
347
|
-
const code = extensions == null ? void 0 : extensions.code;
|
|
348
|
-
if (code) {
|
|
349
|
-
return new import_shared3.CopilotKitError({ message, code });
|
|
350
|
-
}
|
|
351
|
-
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
352
|
-
return new import_shared3.CopilotKitApiDiscoveryError({ message });
|
|
353
|
-
}
|
|
354
|
-
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
355
|
-
return new import_shared3.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
356
|
-
}
|
|
357
|
-
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
358
|
-
return new import_shared3.CopilotKitAgentDiscoveryError({
|
|
359
|
-
agentName: "",
|
|
360
|
-
availableAgents: []
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// src/components/error-boundary/error-utils.tsx
|
|
367
|
-
var import_react5 = require("react");
|
|
368
|
-
|
|
369
|
-
// src/components/toast/exclamation-mark-icon.tsx
|
|
370
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
371
|
-
var ExclamationMarkIcon = ({
|
|
372
|
-
className,
|
|
373
|
-
style
|
|
374
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
375
|
-
"svg",
|
|
376
|
-
{
|
|
377
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
378
|
-
width: "24",
|
|
379
|
-
height: "24",
|
|
380
|
-
viewBox: "0 0 24 24",
|
|
381
|
-
fill: "none",
|
|
382
|
-
stroke: "currentColor",
|
|
383
|
-
strokeWidth: "2",
|
|
384
|
-
strokeLinecap: "round",
|
|
385
|
-
strokeLinejoin: "round",
|
|
386
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
387
|
-
style,
|
|
388
|
-
children: [
|
|
389
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
390
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
391
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
392
|
-
]
|
|
393
|
-
}
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
// src/components/error-boundary/error-utils.tsx
|
|
397
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
398
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
399
|
-
function ErrorToast({ errors }) {
|
|
400
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
401
|
-
var _a, _b, _c;
|
|
402
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
403
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
404
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
405
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
406
|
-
"div",
|
|
407
|
-
{
|
|
408
|
-
style: {
|
|
409
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
410
|
-
marginBottom: 14
|
|
411
|
-
},
|
|
412
|
-
children: [
|
|
413
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
414
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
415
|
-
"div",
|
|
416
|
-
{
|
|
417
|
-
style: {
|
|
418
|
-
fontWeight: "600",
|
|
419
|
-
marginBottom: 4
|
|
420
|
-
},
|
|
421
|
-
children: [
|
|
422
|
-
"Copilot Runtime Error:",
|
|
423
|
-
" ",
|
|
424
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
425
|
-
]
|
|
426
|
-
}
|
|
427
|
-
),
|
|
428
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
429
|
-
]
|
|
430
|
-
},
|
|
431
|
-
idx
|
|
432
|
-
);
|
|
433
|
-
});
|
|
434
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
435
|
-
"div",
|
|
436
|
-
{
|
|
437
|
-
style: {
|
|
438
|
-
fontSize: "13px",
|
|
439
|
-
maxWidth: "600px"
|
|
440
|
-
},
|
|
441
|
-
children: [
|
|
442
|
-
errorsToRender,
|
|
443
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
444
|
-
]
|
|
445
|
-
}
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
function useErrorToast() {
|
|
449
|
-
const { addToast } = useToast();
|
|
450
|
-
return (0, import_react5.useCallback)(
|
|
451
|
-
(error) => {
|
|
452
|
-
const errorId = error.map((err) => {
|
|
453
|
-
var _a, _b;
|
|
454
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
455
|
-
const stack = err.stack || "";
|
|
456
|
-
return btoa(message + stack).slice(0, 32);
|
|
457
|
-
}).join("|");
|
|
458
|
-
addToast({
|
|
459
|
-
type: "error",
|
|
460
|
-
id: errorId,
|
|
461
|
-
// Toast libraries typically dedupe by id
|
|
462
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
[addToast]
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
function useAsyncCallback(callback, deps) {
|
|
469
|
-
const addErrorToast = useErrorToast();
|
|
470
|
-
return (0, import_react5.useCallback)((...args) => __async(this, null, function* () {
|
|
471
|
-
try {
|
|
472
|
-
return yield callback(...args);
|
|
473
|
-
} catch (error) {
|
|
474
|
-
console.error("Error in async callback:", error);
|
|
475
|
-
addErrorToast([error]);
|
|
476
|
-
throw error;
|
|
477
|
-
}
|
|
478
|
-
}), deps);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// src/hooks/use-chat.ts
|
|
482
|
-
function useChat(options) {
|
|
483
|
-
const {
|
|
484
|
-
messages,
|
|
485
|
-
setMessages,
|
|
486
|
-
makeSystemMessageCallback,
|
|
487
|
-
copilotConfig,
|
|
488
|
-
setIsLoading,
|
|
489
|
-
initialMessages,
|
|
490
|
-
isLoading,
|
|
491
|
-
actions,
|
|
492
|
-
onFunctionCall,
|
|
493
|
-
onCoAgentStateRender,
|
|
494
|
-
setCoagentStatesWithRef,
|
|
495
|
-
coagentStatesRef,
|
|
496
|
-
agentSession,
|
|
497
|
-
setAgentSession,
|
|
498
|
-
threadId,
|
|
499
|
-
setThreadId,
|
|
500
|
-
runId,
|
|
501
|
-
setRunId,
|
|
502
|
-
chatAbortControllerRef,
|
|
503
|
-
agentLock,
|
|
504
|
-
extensions,
|
|
505
|
-
setExtensions,
|
|
506
|
-
langGraphInterruptAction,
|
|
507
|
-
setLangGraphInterruptAction,
|
|
508
|
-
disableSystemMessage = false
|
|
509
|
-
} = options;
|
|
510
|
-
const runChatCompletionRef = (0, import_react6.useRef)();
|
|
511
|
-
const addErrorToast = useErrorToast();
|
|
512
|
-
const { setBannerError } = useToast();
|
|
513
|
-
const { onError, showDevConsole, getAllContext } = useCopilotContext();
|
|
514
|
-
const copilotReadableContext = getAllContext();
|
|
515
|
-
const context = (0, import_react6.useMemo)(
|
|
516
|
-
() => copilotReadableContext.map((contextItem) => {
|
|
517
|
-
const [description, ...valueParts] = contextItem.value.split(":");
|
|
518
|
-
return {
|
|
519
|
-
description: description.trim(),
|
|
520
|
-
value: valueParts.join(":").trim()
|
|
521
|
-
};
|
|
522
|
-
}),
|
|
523
|
-
[copilotReadableContext]
|
|
524
|
-
);
|
|
525
|
-
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
526
|
-
try {
|
|
527
|
-
const traceEvent = {
|
|
528
|
-
type: "error",
|
|
529
|
-
timestamp: Date.now(),
|
|
530
|
-
context: {
|
|
531
|
-
source: "ui",
|
|
532
|
-
request: {
|
|
533
|
-
operation: "useChatCompletion",
|
|
534
|
-
url: copilotConfig.chatApiEndpoint,
|
|
535
|
-
startTime: Date.now()
|
|
536
|
-
},
|
|
537
|
-
technical: {
|
|
538
|
-
environment: "browser",
|
|
539
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
540
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
error
|
|
544
|
-
};
|
|
545
|
-
yield onError(traceEvent);
|
|
546
|
-
} catch (traceError) {
|
|
547
|
-
console.error("Error in use-chat onError handler:", traceError);
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
const agentSessionRef = (0, import_react6.useRef)(agentSession);
|
|
551
|
-
agentSessionRef.current = agentSession;
|
|
552
|
-
const runIdRef = (0, import_react6.useRef)(runId);
|
|
553
|
-
runIdRef.current = runId;
|
|
554
|
-
const extensionsRef = (0, import_react6.useRef)(extensions);
|
|
555
|
-
extensionsRef.current = extensions;
|
|
556
|
-
const publicApiKey = copilotConfig.publicApiKey;
|
|
557
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
558
|
-
const runtimeClient = useCopilotRuntimeClient({
|
|
559
|
-
url: copilotConfig.chatApiEndpoint,
|
|
560
|
-
publicApiKey: copilotConfig.publicApiKey,
|
|
561
|
-
headers,
|
|
562
|
-
credentials: copilotConfig.credentials,
|
|
563
|
-
showDevConsole,
|
|
564
|
-
onError
|
|
565
|
-
});
|
|
566
|
-
const pendingAppendsRef = (0, import_react6.useRef)([]);
|
|
567
|
-
const runChatCompletion = useAsyncCallback(
|
|
568
|
-
(previousMessages) => __async(this, null, function* () {
|
|
569
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
570
|
-
setIsLoading(true);
|
|
571
|
-
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
572
|
-
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) {
|
|
573
|
-
addErrorToast([
|
|
574
|
-
new Error(
|
|
575
|
-
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
576
|
-
)
|
|
577
|
-
]);
|
|
578
|
-
}
|
|
579
|
-
let newMessages = [
|
|
580
|
-
new import_runtime_client_gql3.TextMessage({
|
|
581
|
-
content: "",
|
|
582
|
-
role: import_runtime_client_gql3.Role.Assistant
|
|
583
|
-
})
|
|
584
|
-
];
|
|
585
|
-
chatAbortControllerRef.current = new AbortController();
|
|
586
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
587
|
-
const messagesWithContext = disableSystemMessage ? [...initialMessages || [], ...previousMessages] : [makeSystemMessageCallback(), ...initialMessages || [], ...previousMessages];
|
|
588
|
-
const finalProperties = __spreadValues({}, copilotConfig.properties || {});
|
|
589
|
-
let mcpServersToUse = null;
|
|
590
|
-
if (copilotConfig.mcpServers && Array.isArray(copilotConfig.mcpServers) && copilotConfig.mcpServers.length > 0) {
|
|
591
|
-
mcpServersToUse = copilotConfig.mcpServers;
|
|
592
|
-
} else if (((_a = copilotConfig.properties) == null ? void 0 : _a.mcpServers) && Array.isArray(copilotConfig.properties.mcpServers) && copilotConfig.properties.mcpServers.length > 0) {
|
|
593
|
-
mcpServersToUse = copilotConfig.properties.mcpServers;
|
|
594
|
-
}
|
|
595
|
-
if (mcpServersToUse) {
|
|
596
|
-
finalProperties.mcpServers = mcpServersToUse;
|
|
597
|
-
copilotConfig.mcpServers = mcpServersToUse;
|
|
598
|
-
}
|
|
599
|
-
const isAgentRun = agentSessionRef.current !== null;
|
|
600
|
-
const stream = runtimeClient.asStream(
|
|
601
|
-
runtimeClient.generateCopilotResponse({
|
|
602
|
-
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
603
|
-
frontend: {
|
|
604
|
-
actions: processActionsForRuntimeRequest(actions),
|
|
605
|
-
url: window.location.href
|
|
606
|
-
},
|
|
607
|
-
threadId,
|
|
608
|
-
runId: runIdRef.current,
|
|
609
|
-
extensions: extensionsRef.current,
|
|
610
|
-
metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
|
|
611
|
-
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
|
|
612
|
-
}, copilotConfig.cloud ? {
|
|
613
|
-
cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
|
|
614
|
-
guardrails: {
|
|
615
|
-
inputValidationRules: {
|
|
616
|
-
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
617
|
-
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
} : {})
|
|
621
|
-
} : {}), {
|
|
622
|
-
metadata: {
|
|
623
|
-
requestType: import_runtime_client_gql3.CopilotRequestType.Chat
|
|
624
|
-
}
|
|
625
|
-
}), agentSessionRef.current ? {
|
|
626
|
-
agentSession: agentSessionRef.current
|
|
627
|
-
} : {}), {
|
|
628
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) => {
|
|
629
|
-
const stateObject = {
|
|
630
|
-
agentName: state.name,
|
|
631
|
-
state: JSON.stringify(state.state)
|
|
632
|
-
};
|
|
633
|
-
if (state.config !== void 0) {
|
|
634
|
-
stateObject.config = JSON.stringify(state.config);
|
|
635
|
-
}
|
|
636
|
-
return stateObject;
|
|
637
|
-
}),
|
|
638
|
-
forwardedParameters: options.forwardedParameters || {},
|
|
639
|
-
context
|
|
640
|
-
}),
|
|
641
|
-
properties: finalProperties,
|
|
642
|
-
signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
|
|
643
|
-
})
|
|
644
|
-
);
|
|
645
|
-
const guardrailsEnabled = ((_h = (_g = (_f = copilotConfig.cloud) == null ? void 0 : _f.guardrails) == null ? void 0 : _g.input) == null ? void 0 : _h.restrictToTopic.enabled) || false;
|
|
646
|
-
const reader = stream.getReader();
|
|
647
|
-
let executedCoAgentStateRenders = [];
|
|
648
|
-
let followUp = void 0;
|
|
649
|
-
let messages2 = [];
|
|
650
|
-
let syncedMessages = [];
|
|
651
|
-
let interruptMessages = [];
|
|
652
|
-
try {
|
|
653
|
-
while (true) {
|
|
654
|
-
let done, value;
|
|
655
|
-
try {
|
|
656
|
-
const readResult = yield reader.read();
|
|
657
|
-
done = readResult.done;
|
|
658
|
-
value = readResult.value;
|
|
659
|
-
} catch (readError) {
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
if (done) {
|
|
663
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
664
|
-
return [];
|
|
665
|
-
}
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
669
|
-
continue;
|
|
670
|
-
}
|
|
671
|
-
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
672
|
-
extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
|
|
673
|
-
value.generateCopilotResponse.extensions || {}
|
|
674
|
-
);
|
|
675
|
-
setRunId(runIdRef.current);
|
|
676
|
-
setExtensions(extensionsRef.current);
|
|
677
|
-
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
678
|
-
const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
|
|
679
|
-
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
680
|
-
if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
|
|
681
|
-
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
682
|
-
eventValue = (0, import_shared4.parseJson)(eventValue, eventValue);
|
|
683
|
-
setLangGraphInterruptAction(threadId, {
|
|
684
|
-
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
685
|
-
value: eventValue
|
|
686
|
-
})
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
if (ev.name === import_runtime_client_gql3.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
690
|
-
const data = ev.data;
|
|
691
|
-
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
692
|
-
interruptMessages = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
693
|
-
// @ts-ignore
|
|
694
|
-
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(data.messages)
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
699
|
-
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
700
|
-
);
|
|
701
|
-
newMessages = [];
|
|
702
|
-
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
703
|
-
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
704
|
-
newMessages = [
|
|
705
|
-
new import_runtime_client_gql3.TextMessage({
|
|
706
|
-
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
707
|
-
content: guardrailsReason
|
|
708
|
-
})
|
|
709
|
-
];
|
|
710
|
-
const guardrailsError = new import_shared4.CopilotKitError({
|
|
711
|
-
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
712
|
-
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
713
|
-
});
|
|
714
|
-
yield traceUIError(guardrailsError, {
|
|
715
|
-
statusReason: value.generateCopilotResponse.status.reason,
|
|
716
|
-
statusDetails: value.generateCopilotResponse.status.details
|
|
717
|
-
});
|
|
718
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
719
|
-
break;
|
|
720
|
-
}
|
|
721
|
-
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
722
|
-
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
723
|
-
const statusDetails = value.generateCopilotResponse.status.details;
|
|
724
|
-
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
725
|
-
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
726
|
-
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
727
|
-
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
728
|
-
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
729
|
-
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
730
|
-
errorCode = originalCode;
|
|
731
|
-
}
|
|
732
|
-
const structuredError = new import_shared4.CopilotKitError({
|
|
733
|
-
message: errorMessage,
|
|
734
|
-
code: errorCode,
|
|
735
|
-
severity: originalSeverity,
|
|
736
|
-
visibility: originalVisibility
|
|
737
|
-
});
|
|
738
|
-
setBannerError(structuredError);
|
|
739
|
-
yield traceUIError(structuredError, {
|
|
740
|
-
statusReason: value.generateCopilotResponse.status.reason,
|
|
741
|
-
statusDetails: value.generateCopilotResponse.status.details,
|
|
742
|
-
originalErrorCode: originalCode,
|
|
743
|
-
preservedStructure: !!originalCode
|
|
744
|
-
});
|
|
745
|
-
setIsLoading(false);
|
|
746
|
-
throw new Error(structuredError.message);
|
|
747
|
-
} else if (messages2.length > 0) {
|
|
748
|
-
newMessages = [...messages2];
|
|
749
|
-
for (const message of messages2) {
|
|
750
|
-
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
751
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
yield onCoAgentStateRender({
|
|
755
|
-
name: message.agentName,
|
|
756
|
-
nodeName: message.nodeName,
|
|
757
|
-
state: message.state
|
|
758
|
-
});
|
|
759
|
-
executedCoAgentStateRenders.push(message.id);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
763
|
-
if (lastAgentStateMessage) {
|
|
764
|
-
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
765
|
-
syncedMessages = (0, import_runtime_client_gql3.loadMessagesFromJsonRepresentation)(
|
|
766
|
-
lastAgentStateMessage.state.messages
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
setCoagentStatesWithRef((prevAgentStates) => {
|
|
770
|
-
var _a2;
|
|
771
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
772
|
-
[lastAgentStateMessage.agentName]: {
|
|
773
|
-
name: lastAgentStateMessage.agentName,
|
|
774
|
-
state: lastAgentStateMessage.state,
|
|
775
|
-
running: lastAgentStateMessage.running,
|
|
776
|
-
active: lastAgentStateMessage.active,
|
|
777
|
-
threadId: lastAgentStateMessage.threadId,
|
|
778
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
779
|
-
runId: lastAgentStateMessage.runId,
|
|
780
|
-
// Preserve existing config from previous state
|
|
781
|
-
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
});
|
|
785
|
-
if (lastAgentStateMessage.running) {
|
|
786
|
-
setAgentSession({
|
|
787
|
-
threadId: lastAgentStateMessage.threadId,
|
|
788
|
-
agentName: lastAgentStateMessage.agentName,
|
|
789
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
790
|
-
});
|
|
791
|
-
} else {
|
|
792
|
-
if (agentLock) {
|
|
793
|
-
setAgentSession({
|
|
794
|
-
threadId: (0, import_shared4.randomId)(),
|
|
795
|
-
agentName: agentLock,
|
|
796
|
-
nodeName: void 0
|
|
797
|
-
});
|
|
798
|
-
} else {
|
|
799
|
-
setAgentSession(null);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
if (newMessages.length > 0) {
|
|
805
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
let finalMessages = constructFinalMessages(
|
|
809
|
-
[...syncedMessages, ...interruptMessages],
|
|
810
|
-
previousMessages,
|
|
811
|
-
newMessages
|
|
812
|
-
);
|
|
813
|
-
let didExecuteAction = false;
|
|
814
|
-
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
815
|
-
var _a2;
|
|
816
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
817
|
-
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
818
|
-
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
819
|
-
currentAction._setActivatingMessageId(actionMessage.id);
|
|
820
|
-
}
|
|
821
|
-
const resultMessage = yield executeAction({
|
|
822
|
-
onFunctionCall,
|
|
823
|
-
message: actionMessage,
|
|
824
|
-
chatAbortControllerRef,
|
|
825
|
-
onError: (error) => {
|
|
826
|
-
addErrorToast([error]);
|
|
827
|
-
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
828
|
-
},
|
|
829
|
-
setMessages,
|
|
830
|
-
getFinalMessages: () => finalMessages,
|
|
831
|
-
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
832
|
-
});
|
|
833
|
-
didExecuteAction = true;
|
|
834
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
835
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
836
|
-
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
837
|
-
const messagesForImmediateUpdate = [...finalMessages];
|
|
838
|
-
(0, import_react_dom.flushSync)(() => {
|
|
839
|
-
setMessages(messagesForImmediateUpdate);
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
843
|
-
currentAction._setActivatingMessageId(null);
|
|
844
|
-
}
|
|
845
|
-
return resultMessage;
|
|
846
|
-
});
|
|
847
|
-
if (onFunctionCall) {
|
|
848
|
-
const lastMessages = [];
|
|
849
|
-
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
850
|
-
const message = finalMessages[i];
|
|
851
|
-
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
852
|
-
lastMessages.unshift(message);
|
|
853
|
-
} else if (!message.isAgentStateMessage()) {
|
|
854
|
-
break;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
for (const message of lastMessages) {
|
|
858
|
-
setMessages(finalMessages);
|
|
859
|
-
const action = actions.find(
|
|
860
|
-
(action2) => action2.name === message.name
|
|
861
|
-
);
|
|
862
|
-
if (action && action.available === "frontend") {
|
|
863
|
-
continue;
|
|
864
|
-
}
|
|
865
|
-
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
866
|
-
if (action && message.isActionExecutionMessage()) {
|
|
867
|
-
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
868
|
-
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
869
|
-
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
870
|
-
);
|
|
871
|
-
if (alreadyProcessed) {
|
|
872
|
-
} else {
|
|
873
|
-
const resultMessage = yield executeActionFromMessage(
|
|
874
|
-
action,
|
|
875
|
-
message
|
|
876
|
-
);
|
|
877
|
-
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
878
|
-
if (pairedFeAction) {
|
|
879
|
-
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
880
|
-
name: pairedFeAction.name,
|
|
881
|
-
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
882
|
-
status: message.status,
|
|
883
|
-
createdAt: message.createdAt,
|
|
884
|
-
parentMessageId: message.parentMessageId
|
|
885
|
-
});
|
|
886
|
-
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
890
|
-
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
891
|
-
name: currentResultMessagePairedFeAction.name,
|
|
892
|
-
arguments: (0, import_shared4.parseJson)(message.result, message.result),
|
|
893
|
-
status: message.status,
|
|
894
|
-
createdAt: message.createdAt
|
|
895
|
-
});
|
|
896
|
-
finalMessages.push(newExecutionMessage);
|
|
897
|
-
yield executeActionFromMessage(
|
|
898
|
-
currentResultMessagePairedFeAction,
|
|
899
|
-
newExecutionMessage
|
|
900
|
-
);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
setMessages(finalMessages);
|
|
904
|
-
}
|
|
905
|
-
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
906
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
907
|
-
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
908
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
909
|
-
return yield runChatCompletionRef.current(finalMessages);
|
|
910
|
-
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
911
|
-
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
912
|
-
if (message.isActionExecutionMessage()) {
|
|
913
|
-
return finalMessages.find(
|
|
914
|
-
(msg, resultIndex) => msg.isResultMessage() && msg.actionExecutionId === message.id && resultIndex === actionExecutionIndex + 1
|
|
915
|
-
);
|
|
916
|
-
}
|
|
917
|
-
return true;
|
|
918
|
-
});
|
|
919
|
-
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
920
|
-
setMessages(repairedMessages);
|
|
921
|
-
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
922
|
-
setAgentSession({
|
|
923
|
-
threadId: agentSessionRef.current.threadId,
|
|
924
|
-
agentName: agentSessionRef.current.agentName,
|
|
925
|
-
nodeName: "__end__"
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
return newMessages.filter((message) => repairedMessageIds.includes(message.id));
|
|
929
|
-
} else {
|
|
930
|
-
return newMessages.slice();
|
|
931
|
-
}
|
|
932
|
-
} finally {
|
|
933
|
-
setIsLoading(false);
|
|
934
|
-
}
|
|
935
|
-
}),
|
|
936
|
-
[
|
|
937
|
-
messages,
|
|
938
|
-
setMessages,
|
|
939
|
-
makeSystemMessageCallback,
|
|
940
|
-
copilotConfig,
|
|
941
|
-
setIsLoading,
|
|
942
|
-
initialMessages,
|
|
943
|
-
isLoading,
|
|
944
|
-
actions,
|
|
945
|
-
onFunctionCall,
|
|
946
|
-
onCoAgentStateRender,
|
|
947
|
-
setCoagentStatesWithRef,
|
|
948
|
-
coagentStatesRef,
|
|
949
|
-
agentSession,
|
|
950
|
-
setAgentSession,
|
|
951
|
-
disableSystemMessage,
|
|
952
|
-
context
|
|
953
|
-
]
|
|
954
|
-
);
|
|
955
|
-
runChatCompletionRef.current = runChatCompletion;
|
|
956
|
-
const runChatCompletionAndHandleFunctionCall = useAsyncCallback(
|
|
957
|
-
(messages2) => __async(this, null, function* () {
|
|
958
|
-
yield runChatCompletionRef.current(messages2);
|
|
959
|
-
}),
|
|
960
|
-
[messages]
|
|
961
|
-
);
|
|
962
|
-
(0, import_react6.useEffect)(() => {
|
|
963
|
-
if (!isLoading && pendingAppendsRef.current.length > 0) {
|
|
964
|
-
const pending = pendingAppendsRef.current.splice(0);
|
|
965
|
-
const followUp = pending.some((p) => p.followUp);
|
|
966
|
-
const newMessages = [...messages, ...pending.map((p) => p.message)];
|
|
967
|
-
setMessages(newMessages);
|
|
968
|
-
if (followUp) {
|
|
969
|
-
runChatCompletionAndHandleFunctionCall(newMessages);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
973
|
-
const composeAndFlushMetaEventsInput = (0, import_react6.useCallback)(
|
|
974
|
-
(metaEvents) => {
|
|
975
|
-
return metaEvents.reduce((acc, event) => {
|
|
976
|
-
if (!event)
|
|
977
|
-
return acc;
|
|
978
|
-
switch (event.name) {
|
|
979
|
-
case import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent:
|
|
980
|
-
if (event.response) {
|
|
981
|
-
setLangGraphInterruptAction(threadId, null);
|
|
982
|
-
const value = event.value;
|
|
983
|
-
return [
|
|
984
|
-
...acc,
|
|
985
|
-
{
|
|
986
|
-
name: event.name,
|
|
987
|
-
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
988
|
-
response: typeof event.response === "string" ? event.response : JSON.stringify(event.response)
|
|
989
|
-
}
|
|
990
|
-
];
|
|
991
|
-
}
|
|
992
|
-
return acc;
|
|
993
|
-
default:
|
|
994
|
-
return acc;
|
|
995
|
-
}
|
|
996
|
-
}, []);
|
|
997
|
-
},
|
|
998
|
-
[setLangGraphInterruptAction]
|
|
999
|
-
);
|
|
1000
|
-
const append = useAsyncCallback(
|
|
1001
|
-
(message, options2) => __async(this, null, function* () {
|
|
1002
|
-
var _a;
|
|
1003
|
-
const followUp = (_a = options2 == null ? void 0 : options2.followUp) != null ? _a : true;
|
|
1004
|
-
if (isLoading) {
|
|
1005
|
-
pendingAppendsRef.current.push({ message, followUp });
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
const newMessages = [...messages, message];
|
|
1009
|
-
setMessages(newMessages);
|
|
1010
|
-
if (followUp) {
|
|
1011
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
1012
|
-
}
|
|
1013
|
-
}),
|
|
1014
|
-
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
1015
|
-
);
|
|
1016
|
-
const reload = useAsyncCallback(
|
|
1017
|
-
(reloadMessageId) => __async(this, null, function* () {
|
|
1018
|
-
if (isLoading || messages.length === 0) {
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
1022
|
-
if (reloadMessageIndex === -1) {
|
|
1023
|
-
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
1027
|
-
if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
|
|
1028
|
-
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
1029
|
-
return;
|
|
1030
|
-
}
|
|
1031
|
-
let historyCutoff = [messages[0]];
|
|
1032
|
-
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
1033
|
-
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
1034
|
-
(msg) => (
|
|
1035
|
-
// @ts-expect-error -- message has role
|
|
1036
|
-
msg.role === import_runtime_client_gql3.MessageRole.User
|
|
1037
|
-
)
|
|
1038
|
-
);
|
|
1039
|
-
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1040
|
-
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1041
|
-
);
|
|
1042
|
-
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
1043
|
-
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
1044
|
-
historyCutoff = [messages[0], messages[1]];
|
|
1045
|
-
}
|
|
1046
|
-
setMessages(historyCutoff);
|
|
1047
|
-
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
1048
|
-
}),
|
|
1049
|
-
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
1050
|
-
);
|
|
1051
|
-
const stop = () => {
|
|
1052
|
-
var _a;
|
|
1053
|
-
(_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
|
|
1054
|
-
};
|
|
1055
|
-
return {
|
|
1056
|
-
append,
|
|
1057
|
-
reload,
|
|
1058
|
-
stop,
|
|
1059
|
-
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
1063
|
-
const finalMessages = syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];
|
|
1064
|
-
if (syncedMessages.length > 0) {
|
|
1065
|
-
const messagesWithAgentState = [...previousMessages, ...newMessages];
|
|
1066
|
-
let previousMessageId = void 0;
|
|
1067
|
-
for (const message of messagesWithAgentState) {
|
|
1068
|
-
if (message.isAgentStateMessage()) {
|
|
1069
|
-
const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);
|
|
1070
|
-
if (index !== -1) {
|
|
1071
|
-
finalMessages.splice(index + 1, 0, message);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
previousMessageId = message.id;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
return finalMessages;
|
|
1078
|
-
}
|
|
1079
|
-
function executeAction(_0) {
|
|
1080
|
-
return __async(this, arguments, function* ({
|
|
1081
|
-
onFunctionCall,
|
|
1082
|
-
message,
|
|
1083
|
-
chatAbortControllerRef,
|
|
1084
|
-
onError,
|
|
1085
|
-
setMessages,
|
|
1086
|
-
getFinalMessages,
|
|
1087
|
-
isRenderAndWait
|
|
1088
|
-
}) {
|
|
1089
|
-
let result;
|
|
1090
|
-
let error = null;
|
|
1091
|
-
const currentMessagesForHandler = getFinalMessages();
|
|
1092
|
-
const handlerReturnedPromise = onFunctionCall({
|
|
1093
|
-
messages: currentMessagesForHandler,
|
|
1094
|
-
name: message.name,
|
|
1095
|
-
args: message.arguments
|
|
1096
|
-
});
|
|
1097
|
-
if (isRenderAndWait) {
|
|
1098
|
-
const currentMessagesForRender = getFinalMessages();
|
|
1099
|
-
(0, import_react_dom.flushSync)(() => {
|
|
1100
|
-
setMessages([...currentMessagesForRender]);
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
try {
|
|
1104
|
-
result = yield Promise.race([
|
|
1105
|
-
handlerReturnedPromise,
|
|
1106
|
-
// Await the promise returned by the handler
|
|
1107
|
-
new Promise(
|
|
1108
|
-
(resolve) => {
|
|
1109
|
-
var _a;
|
|
1110
|
-
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
1111
|
-
"abort",
|
|
1112
|
-
() => resolve("Operation was aborted by the user")
|
|
1113
|
-
);
|
|
1114
|
-
}
|
|
1115
|
-
),
|
|
1116
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
1117
|
-
new Promise((resolve) => {
|
|
1118
|
-
var _a;
|
|
1119
|
-
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
1120
|
-
resolve("Operation was aborted by the user");
|
|
1121
|
-
}
|
|
1122
|
-
})
|
|
1123
|
-
]);
|
|
1124
|
-
} catch (e) {
|
|
1125
|
-
onError(e);
|
|
1126
|
-
}
|
|
1127
|
-
return new import_runtime_client_gql3.ResultMessage({
|
|
1128
|
-
id: "result-" + message.id,
|
|
1129
|
-
result: import_runtime_client_gql3.ResultMessage.encodeResult(
|
|
1130
|
-
error ? {
|
|
1131
|
-
content: result,
|
|
1132
|
-
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
1133
|
-
} : result
|
|
1134
|
-
),
|
|
1135
|
-
actionExecutionId: message.id,
|
|
1136
|
-
actionName: message.name
|
|
1137
|
-
});
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
function getPairedFeAction(actions, message) {
|
|
1141
|
-
let actionName = null;
|
|
1142
|
-
if (message.isActionExecutionMessage()) {
|
|
1143
|
-
actionName = message.name;
|
|
1144
|
-
} else if (message.isResultMessage()) {
|
|
1145
|
-
actionName = message.actionName;
|
|
1146
|
-
}
|
|
1147
|
-
return actions.find(
|
|
1148
|
-
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
1149
|
-
);
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
1153
|
-
var import_react7 = require("react");
|
|
1154
|
-
var import_react_dom2 = require("react-dom");
|
|
1155
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1156
|
-
|
|
1157
|
-
// src/utils/extract.ts
|
|
1158
|
-
var import_shared5 = require("@copilotkit/shared");
|
|
1159
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1160
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1161
|
-
function extract(_0) {
|
|
1162
|
-
return __async(this, arguments, function* ({
|
|
1163
|
-
context,
|
|
1164
|
-
instructions,
|
|
1165
|
-
parameters,
|
|
1166
|
-
include,
|
|
1167
|
-
data,
|
|
1168
|
-
abortSignal,
|
|
1169
|
-
stream,
|
|
1170
|
-
requestType = import_runtime_client_gql4.CopilotRequestType.Task,
|
|
1171
|
-
forwardedParameters
|
|
1172
|
-
}) {
|
|
1173
|
-
var _a, _b;
|
|
1174
|
-
const { messages } = context;
|
|
1175
|
-
const action = {
|
|
1176
|
-
name: "extract",
|
|
1177
|
-
description: instructions,
|
|
1178
|
-
parameters,
|
|
1179
|
-
handler: (args) => {
|
|
1180
|
-
}
|
|
1181
|
-
};
|
|
1182
|
-
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
1183
|
-
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
1184
|
-
let contextString = "";
|
|
1185
|
-
if (data) {
|
|
1186
|
-
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
1187
|
-
}
|
|
1188
|
-
if (includeReadable) {
|
|
1189
|
-
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1190
|
-
}
|
|
1191
|
-
const systemMessage = new import_runtime_client_gql4.TextMessage({
|
|
1192
|
-
content: makeSystemMessage(contextString, instructions),
|
|
1193
|
-
role: import_runtime_client_gql4.Role.System
|
|
1194
|
-
});
|
|
1195
|
-
const instructionsMessage = new import_runtime_client_gql4.TextMessage({
|
|
1196
|
-
content: makeInstructionsMessage(instructions),
|
|
1197
|
-
role: import_runtime_client_gql4.Role.User
|
|
1198
|
-
});
|
|
1199
|
-
const response = context.runtimeClient.asStream(
|
|
1200
|
-
context.runtimeClient.generateCopilotResponse({
|
|
1201
|
-
data: {
|
|
1202
|
-
frontend: {
|
|
1203
|
-
actions: [
|
|
1204
|
-
{
|
|
1205
|
-
name: action.name,
|
|
1206
|
-
description: action.description || "",
|
|
1207
|
-
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || []))
|
|
1208
|
-
}
|
|
1209
|
-
],
|
|
1210
|
-
url: window.location.href
|
|
1211
|
-
},
|
|
1212
|
-
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(
|
|
1213
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql5.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1214
|
-
),
|
|
1215
|
-
metadata: {
|
|
1216
|
-
requestType
|
|
1217
|
-
},
|
|
1218
|
-
forwardedParameters: __spreadProps(__spreadValues({}, forwardedParameters != null ? forwardedParameters : {}), {
|
|
1219
|
-
toolChoice: "function",
|
|
1220
|
-
toolChoiceFunctionName: action.name
|
|
1221
|
-
})
|
|
1222
|
-
},
|
|
1223
|
-
properties: context.copilotApiConfig.properties,
|
|
1224
|
-
signal: abortSignal
|
|
1225
|
-
})
|
|
1226
|
-
);
|
|
1227
|
-
const reader = response.getReader();
|
|
1228
|
-
let isInitial = true;
|
|
1229
|
-
let actionExecutionMessage = void 0;
|
|
1230
|
-
while (true) {
|
|
1231
|
-
const { done, value } = yield reader.read();
|
|
1232
|
-
if (done) {
|
|
1233
|
-
break;
|
|
1234
|
-
}
|
|
1235
|
-
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1236
|
-
throw new Error("Aborted");
|
|
1237
|
-
}
|
|
1238
|
-
actionExecutionMessage = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1239
|
-
value.generateCopilotResponse.messages
|
|
1240
|
-
).find((msg) => msg.isActionExecutionMessage());
|
|
1241
|
-
if (!actionExecutionMessage) {
|
|
1242
|
-
continue;
|
|
1243
|
-
}
|
|
1244
|
-
stream == null ? void 0 : stream({
|
|
1245
|
-
status: isInitial ? "initial" : "inProgress",
|
|
1246
|
-
args: actionExecutionMessage.arguments
|
|
1247
|
-
});
|
|
1248
|
-
isInitial = false;
|
|
1249
|
-
}
|
|
1250
|
-
if (!actionExecutionMessage) {
|
|
1251
|
-
throw new Error("extract() failed: No function call occurred");
|
|
1252
|
-
}
|
|
1253
|
-
stream == null ? void 0 : stream({
|
|
1254
|
-
status: "complete",
|
|
1255
|
-
args: actionExecutionMessage.arguments
|
|
1256
|
-
});
|
|
1257
|
-
return actionExecutionMessage.arguments;
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
function makeInstructionsMessage(instructions) {
|
|
1261
|
-
return `
|
|
1262
|
-
The user has given you the following task to complete:
|
|
1263
|
-
|
|
1264
|
-
\`\`\`
|
|
1265
|
-
${instructions}
|
|
1266
|
-
\`\`\`
|
|
1267
|
-
|
|
1268
|
-
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
1269
|
-
`;
|
|
1270
|
-
}
|
|
1271
|
-
function makeSystemMessage(contextString, instructions) {
|
|
1272
|
-
return `
|
|
1273
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1274
|
-
|
|
1275
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
1276
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1277
|
-
|
|
1278
|
-
The user has provided you with the following context:
|
|
1279
|
-
\`\`\`
|
|
1280
|
-
${contextString}
|
|
1281
|
-
\`\`\`
|
|
1282
|
-
|
|
1283
|
-
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
1284
|
-
|
|
1285
|
-
Please assist them as best you can.
|
|
1286
|
-
|
|
1287
|
-
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
1288
|
-
`;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// src/utils/suggestions.ts
|
|
1292
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1293
|
-
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1294
|
-
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1295
|
-
const abortController = abortControllerRef.current;
|
|
1296
|
-
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1297
|
-
return;
|
|
1298
|
-
}
|
|
1299
|
-
const setSuggestionsIfNotAborted = (suggestions) => {
|
|
1300
|
-
if (!(abortController == null ? void 0 : abortController.signal.aborted) && abortControllerRef.current === abortController) {
|
|
1301
|
-
setCurrentSuggestions(suggestions);
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
try {
|
|
1305
|
-
const tools = JSON.stringify(
|
|
1306
|
-
Object.values(context.actions).map((action) => ({
|
|
1307
|
-
name: action.name,
|
|
1308
|
-
description: action.description,
|
|
1309
|
-
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters))
|
|
1310
|
-
}))
|
|
1311
|
-
);
|
|
1312
|
-
const allSuggestions = [];
|
|
1313
|
-
let hasSuccessfulSuggestions = false;
|
|
1314
|
-
let hasErrors = false;
|
|
1315
|
-
let lastError = null;
|
|
1316
|
-
const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
|
|
1317
|
-
(config) => config.instructions && config.instructions.trim().length > 0
|
|
1318
|
-
);
|
|
1319
|
-
if (enabledConfigs.length === 0) {
|
|
1320
|
-
return;
|
|
1321
|
-
}
|
|
1322
|
-
setSuggestionsIfNotAborted([]);
|
|
1323
|
-
for (const config of enabledConfigs) {
|
|
1324
|
-
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1325
|
-
setSuggestionsIfNotAborted([]);
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
try {
|
|
1329
|
-
const result = yield extract({
|
|
1330
|
-
context,
|
|
1331
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
1332
|
-
data: `${config.instructions}
|
|
1333
|
-
|
|
1334
|
-
Available tools: ${tools}
|
|
1335
|
-
|
|
1336
|
-
`,
|
|
1337
|
-
requestType: import_runtime_client_gql6.CopilotRequestType.Task,
|
|
1338
|
-
parameters: [
|
|
1339
|
-
{
|
|
1340
|
-
name: "suggestions",
|
|
1341
|
-
type: "object[]",
|
|
1342
|
-
attributes: [
|
|
1343
|
-
{
|
|
1344
|
-
name: "title",
|
|
1345
|
-
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1346
|
-
type: "string"
|
|
1347
|
-
},
|
|
1348
|
-
{
|
|
1349
|
-
name: "message",
|
|
1350
|
-
description: "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
1351
|
-
type: "string"
|
|
1352
|
-
}
|
|
1353
|
-
]
|
|
1354
|
-
}
|
|
1355
|
-
],
|
|
1356
|
-
include: {
|
|
1357
|
-
messages: true,
|
|
1358
|
-
readable: true
|
|
1359
|
-
},
|
|
1360
|
-
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1361
|
-
stream: ({ status, args }) => {
|
|
1362
|
-
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1363
|
-
return;
|
|
1364
|
-
}
|
|
1365
|
-
const suggestions = args.suggestions || [];
|
|
1366
|
-
const newSuggestions = [];
|
|
1367
|
-
for (let i = 0; i < suggestions.length; i++) {
|
|
1368
|
-
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1369
|
-
break;
|
|
1370
|
-
}
|
|
1371
|
-
const suggestion = suggestions[i];
|
|
1372
|
-
if (!suggestion || typeof suggestion !== "object") {
|
|
1373
|
-
continue;
|
|
1374
|
-
}
|
|
1375
|
-
const { title, message } = suggestion;
|
|
1376
|
-
const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
|
|
1377
|
-
const hasValidMessage = message && typeof message === "string" && message.trim().length > 0;
|
|
1378
|
-
if (!hasValidTitle) {
|
|
1379
|
-
continue;
|
|
1380
|
-
}
|
|
1381
|
-
const partial = i === suggestions.length - 1 && status !== "complete";
|
|
1382
|
-
newSuggestions.push({
|
|
1383
|
-
title: title.trim(),
|
|
1384
|
-
message: hasValidMessage ? message.trim() : "",
|
|
1385
|
-
// Use title as fallback
|
|
1386
|
-
partial,
|
|
1387
|
-
className: config.className
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
if ((result == null ? void 0 : result.suggestions) && Array.isArray(result.suggestions)) {
|
|
1394
|
-
const validSuggestions = result.suggestions.filter(
|
|
1395
|
-
(suggestion) => suggestion && typeof suggestion.title === "string" && suggestion.title.trim().length > 0
|
|
1396
|
-
).map((suggestion) => ({
|
|
1397
|
-
title: suggestion.title.trim(),
|
|
1398
|
-
message: suggestion.message && typeof suggestion.message === "string" && suggestion.message.trim() ? suggestion.message.trim() : suggestion.title.trim()
|
|
1399
|
-
}));
|
|
1400
|
-
if (validSuggestions.length > 0) {
|
|
1401
|
-
allSuggestions.push(...validSuggestions);
|
|
1402
|
-
hasSuccessfulSuggestions = true;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
} catch (error) {
|
|
1406
|
-
hasErrors = true;
|
|
1407
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
|
|
1411
|
-
const uniqueSuggestions = allSuggestions.filter(
|
|
1412
|
-
(suggestion, index, self) => index === self.findIndex((s) => s.message === suggestion.message)
|
|
1413
|
-
);
|
|
1414
|
-
setSuggestionsIfNotAborted(uniqueSuggestions);
|
|
1415
|
-
} else if (hasErrors) {
|
|
1416
|
-
const errorMessage = lastError ? lastError.message : "Failed to generate suggestions due to API errors";
|
|
1417
|
-
throw new Error(errorMessage);
|
|
1418
|
-
}
|
|
1419
|
-
} catch (error) {
|
|
1420
|
-
throw error;
|
|
1421
|
-
}
|
|
1422
|
-
});
|
|
1423
|
-
|
|
1424
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
1425
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1426
|
-
var defaultCopilotContextCategories = ["global"];
|
|
1427
|
-
|
|
1428
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
1429
|
-
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1430
|
-
|
|
1431
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1432
|
-
var import_react8 = __toESM(require("react"));
|
|
1433
|
-
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1434
|
-
return render({ event, result, resolve });
|
|
1435
|
-
};
|
|
1436
|
-
function useLangGraphInterruptRender() {
|
|
1437
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession, threadId } = useCopilotContext();
|
|
1438
|
-
const responseRef = import_react8.default.useRef();
|
|
1439
|
-
const resolveInterrupt = (0, import_react8.useCallback)(
|
|
1440
|
-
(response) => {
|
|
1441
|
-
responseRef.current = response;
|
|
1442
|
-
setTimeout(() => {
|
|
1443
|
-
setLangGraphInterruptAction(threadId, { event: { response } });
|
|
1444
|
-
}, 0);
|
|
1445
|
-
},
|
|
1446
|
-
[setLangGraphInterruptAction, threadId]
|
|
1447
|
-
);
|
|
1448
|
-
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1449
|
-
return null;
|
|
1450
|
-
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1451
|
-
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1452
|
-
if (!conditionsMet) {
|
|
1453
|
-
return null;
|
|
1454
|
-
}
|
|
1455
|
-
let result = null;
|
|
1456
|
-
if (handler) {
|
|
1457
|
-
result = handler({
|
|
1458
|
-
event,
|
|
1459
|
-
resolve: resolveInterrupt
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
return import_react8.default.createElement(InterruptRenderer, {
|
|
1463
|
-
event,
|
|
1464
|
-
result,
|
|
1465
|
-
render,
|
|
1466
|
-
resolve: resolveInterrupt
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
1471
|
-
var globalSuggestionPromise = null;
|
|
1472
|
-
function useCopilotChat(options = {}) {
|
|
1473
|
-
var _a;
|
|
1474
|
-
const makeSystemMessage2 = (_a = options.makeSystemMessage) != null ? _a : defaultSystemMessage;
|
|
1475
|
-
const {
|
|
1476
|
-
getContextString,
|
|
1477
|
-
getFunctionCallHandler,
|
|
1478
|
-
copilotApiConfig,
|
|
1479
|
-
isLoading,
|
|
1480
|
-
setIsLoading,
|
|
1481
|
-
chatInstructions,
|
|
1482
|
-
actions,
|
|
1483
|
-
coagentStatesRef,
|
|
1484
|
-
setCoagentStatesWithRef,
|
|
1485
|
-
coAgentStateRenders,
|
|
1486
|
-
agentSession,
|
|
1487
|
-
setAgentSession,
|
|
1488
|
-
forwardedParameters,
|
|
1489
|
-
agentLock,
|
|
1490
|
-
threadId,
|
|
1491
|
-
setThreadId,
|
|
1492
|
-
runId,
|
|
1493
|
-
setRunId,
|
|
1494
|
-
chatAbortControllerRef,
|
|
1495
|
-
extensions,
|
|
1496
|
-
setExtensions,
|
|
1497
|
-
langGraphInterruptAction,
|
|
1498
|
-
setLangGraphInterruptAction,
|
|
1499
|
-
chatSuggestionConfiguration,
|
|
1500
|
-
runtimeClient
|
|
1501
|
-
} = useCopilotContext();
|
|
1502
|
-
const { messages, setMessages, suggestions, setSuggestions } = useCopilotMessagesContext();
|
|
1503
|
-
const [mcpServers, setLocalMcpServers] = (0, import_react9.useState)([]);
|
|
1504
|
-
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1505
|
-
const isLoadingSuggestionsRef = (0, import_react9.useRef)(false);
|
|
1506
|
-
const abortSuggestions = (0, import_react9.useCallback)(
|
|
1507
|
-
(clear = true) => {
|
|
1508
|
-
var _a2;
|
|
1509
|
-
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
1510
|
-
suggestionsAbortControllerRef.current = null;
|
|
1511
|
-
if (clear) {
|
|
1512
|
-
setSuggestions([]);
|
|
1513
|
-
}
|
|
1514
|
-
},
|
|
1515
|
-
[setSuggestions]
|
|
1516
|
-
);
|
|
1517
|
-
const stableContext = (0, import_react9.useMemo)(() => {
|
|
1518
|
-
return {
|
|
1519
|
-
actions,
|
|
1520
|
-
copilotApiConfig,
|
|
1521
|
-
chatSuggestionConfiguration,
|
|
1522
|
-
messages,
|
|
1523
|
-
setMessages,
|
|
1524
|
-
getContextString,
|
|
1525
|
-
runtimeClient
|
|
1526
|
-
};
|
|
1527
|
-
}, [
|
|
1528
|
-
JSON.stringify(Object.keys(actions)),
|
|
1529
|
-
copilotApiConfig.chatApiEndpoint,
|
|
1530
|
-
messages.length,
|
|
1531
|
-
Object.keys(chatSuggestionConfiguration).length
|
|
1532
|
-
]);
|
|
1533
|
-
const generateSuggestionsFunc = (0, import_react9.useCallback)(() => __async(this, null, function* () {
|
|
1534
|
-
if (globalSuggestionPromise) {
|
|
1535
|
-
return globalSuggestionPromise;
|
|
1536
|
-
}
|
|
1537
|
-
globalSuggestionPromise = (() => __async(this, null, function* () {
|
|
1538
|
-
try {
|
|
1539
|
-
abortSuggestions();
|
|
1540
|
-
isLoadingSuggestionsRef.current = true;
|
|
1541
|
-
suggestionsAbortControllerRef.current = new AbortController();
|
|
1542
|
-
setSuggestions([]);
|
|
1543
|
-
yield reloadSuggestions(
|
|
1544
|
-
stableContext,
|
|
1545
|
-
chatSuggestionConfiguration,
|
|
1546
|
-
setSuggestions,
|
|
1547
|
-
suggestionsAbortControllerRef
|
|
1548
|
-
);
|
|
1549
|
-
} catch (error) {
|
|
1550
|
-
throw error;
|
|
1551
|
-
} finally {
|
|
1552
|
-
isLoadingSuggestionsRef.current = false;
|
|
1553
|
-
globalSuggestionPromise = null;
|
|
1554
|
-
}
|
|
1555
|
-
}))();
|
|
1556
|
-
return globalSuggestionPromise;
|
|
1557
|
-
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1558
|
-
const resetSuggestions = (0, import_react9.useCallback)(() => {
|
|
1559
|
-
setSuggestions([]);
|
|
1560
|
-
}, [setSuggestions]);
|
|
1561
|
-
(0, import_react9.useEffect)(() => {
|
|
1562
|
-
if (mcpServers.length > 0) {
|
|
1563
|
-
const serversCopy = [...mcpServers];
|
|
1564
|
-
copilotApiConfig.mcpServers = serversCopy;
|
|
1565
|
-
if (!copilotApiConfig.properties) {
|
|
1566
|
-
copilotApiConfig.properties = {};
|
|
1567
|
-
}
|
|
1568
|
-
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1569
|
-
}
|
|
1570
|
-
}, [mcpServers, copilotApiConfig]);
|
|
1571
|
-
const setMcpServers = (0, import_react9.useCallback)((servers) => {
|
|
1572
|
-
setLocalMcpServers(servers);
|
|
1573
|
-
}, []);
|
|
1574
|
-
const onCoAgentStateRender = useAsyncCallback(
|
|
1575
|
-
(args) => __async(this, null, function* () {
|
|
1576
|
-
var _a2;
|
|
1577
|
-
const { name, nodeName, state } = args;
|
|
1578
|
-
let action = Object.values(coAgentStateRenders).find(
|
|
1579
|
-
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
1580
|
-
);
|
|
1581
|
-
if (!action) {
|
|
1582
|
-
action = Object.values(coAgentStateRenders).find(
|
|
1583
|
-
(action2) => action2.name === name && !action2.nodeName
|
|
1584
|
-
);
|
|
1585
|
-
}
|
|
1586
|
-
if (action) {
|
|
1587
|
-
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
1588
|
-
}
|
|
1589
|
-
}),
|
|
1590
|
-
[coAgentStateRenders]
|
|
1591
|
-
);
|
|
1592
|
-
const makeSystemMessageCallback = (0, import_react9.useCallback)(() => {
|
|
1593
|
-
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1594
|
-
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1595
|
-
return new import_runtime_client_gql7.TextMessage({
|
|
1596
|
-
content: systemMessageMaker(contextString, chatInstructions),
|
|
1597
|
-
role: import_runtime_client_gql7.Role.System
|
|
1598
|
-
});
|
|
1599
|
-
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1600
|
-
const deleteMessage = (0, import_react9.useCallback)(
|
|
1601
|
-
(messageId) => {
|
|
1602
|
-
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1603
|
-
},
|
|
1604
|
-
[setMessages]
|
|
1605
|
-
);
|
|
1606
|
-
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1607
|
-
actions: Object.values(actions),
|
|
1608
|
-
copilotConfig: copilotApiConfig,
|
|
1609
|
-
initialMessages: (0, import_runtime_client_gql7.aguiToGQL)(options.initialMessages || []),
|
|
1610
|
-
onFunctionCall: getFunctionCallHandler(),
|
|
1611
|
-
onCoAgentStateRender,
|
|
1612
|
-
messages,
|
|
1613
|
-
setMessages,
|
|
1614
|
-
makeSystemMessageCallback,
|
|
1615
|
-
isLoading,
|
|
1616
|
-
setIsLoading,
|
|
1617
|
-
coagentStatesRef,
|
|
1618
|
-
setCoagentStatesWithRef,
|
|
1619
|
-
agentSession,
|
|
1620
|
-
setAgentSession,
|
|
1621
|
-
forwardedParameters,
|
|
1622
|
-
threadId,
|
|
1623
|
-
setThreadId,
|
|
1624
|
-
runId,
|
|
1625
|
-
setRunId,
|
|
1626
|
-
chatAbortControllerRef,
|
|
1627
|
-
agentLock,
|
|
1628
|
-
extensions,
|
|
1629
|
-
setExtensions,
|
|
1630
|
-
langGraphInterruptAction,
|
|
1631
|
-
setLangGraphInterruptAction,
|
|
1632
|
-
disableSystemMessage: options.disableSystemMessage
|
|
1633
|
-
}));
|
|
1634
|
-
const latestAppend = useUpdatedRef(append);
|
|
1635
|
-
const latestAppendFunc = useAsyncCallback(
|
|
1636
|
-
(message, options2) => __async(this, null, function* () {
|
|
1637
|
-
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1638
|
-
return yield latestAppend.current(message, options2);
|
|
1639
|
-
}),
|
|
1640
|
-
[latestAppend]
|
|
1641
|
-
);
|
|
1642
|
-
const latestSendMessageFunc = useAsyncCallback(
|
|
1643
|
-
(message, options2) => __async(this, null, function* () {
|
|
1644
|
-
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1645
|
-
return yield latestAppend.current((0, import_runtime_client_gql7.aguiToGQL)([message])[0], options2);
|
|
1646
|
-
}),
|
|
1647
|
-
[latestAppend]
|
|
1648
|
-
);
|
|
1649
|
-
const latestReload = useUpdatedRef(reload);
|
|
1650
|
-
const latestReloadFunc = useAsyncCallback(
|
|
1651
|
-
(messageId) => __async(this, null, function* () {
|
|
1652
|
-
return yield latestReload.current(messageId);
|
|
1653
|
-
}),
|
|
1654
|
-
[latestReload]
|
|
1655
|
-
);
|
|
1656
|
-
const latestStop = useUpdatedRef(stop);
|
|
1657
|
-
const latestStopFunc = (0, import_react9.useCallback)(() => {
|
|
1658
|
-
return latestStop.current();
|
|
1659
|
-
}, [latestStop]);
|
|
1660
|
-
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1661
|
-
const latestDeleteFunc = (0, import_react9.useCallback)(
|
|
1662
|
-
(messageId) => {
|
|
1663
|
-
return latestDelete.current(messageId);
|
|
1664
|
-
},
|
|
1665
|
-
[latestDelete]
|
|
1666
|
-
);
|
|
1667
|
-
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1668
|
-
const latestSetMessagesFunc = (0, import_react9.useCallback)(
|
|
1669
|
-
(messages2) => {
|
|
1670
|
-
if (messages2.every((message) => message instanceof import_runtime_client_gql7.Message)) {
|
|
1671
|
-
return latestSetMessages.current(messages2);
|
|
1672
|
-
}
|
|
1673
|
-
return latestSetMessages.current((0, import_runtime_client_gql7.aguiToGQL)(messages2));
|
|
1674
|
-
},
|
|
1675
|
-
[latestSetMessages]
|
|
1676
|
-
);
|
|
1677
|
-
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
1678
|
-
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1679
|
-
return yield latestRunChatCompletion.current();
|
|
1680
|
-
}), [latestRunChatCompletion]);
|
|
1681
|
-
const reset = (0, import_react9.useCallback)(() => {
|
|
1682
|
-
latestStopFunc();
|
|
1683
|
-
setMessages([]);
|
|
1684
|
-
setRunId(null);
|
|
1685
|
-
setCoagentStatesWithRef({});
|
|
1686
|
-
let initialAgentSession = null;
|
|
1687
|
-
if (agentLock) {
|
|
1688
|
-
initialAgentSession = {
|
|
1689
|
-
agentName: agentLock
|
|
1690
|
-
};
|
|
1691
|
-
}
|
|
1692
|
-
setAgentSession(initialAgentSession);
|
|
1693
|
-
resetSuggestions();
|
|
1694
|
-
}, [
|
|
1695
|
-
latestStopFunc,
|
|
1696
|
-
setMessages,
|
|
1697
|
-
setThreadId,
|
|
1698
|
-
setCoagentStatesWithRef,
|
|
1699
|
-
setAgentSession,
|
|
1700
|
-
agentLock,
|
|
1701
|
-
resetSuggestions
|
|
1702
|
-
]);
|
|
1703
|
-
const latestReset = useUpdatedRef(reset);
|
|
1704
|
-
const latestResetFunc = (0, import_react9.useCallback)(() => {
|
|
1705
|
-
return latestReset.current();
|
|
1706
|
-
}, [latestReset]);
|
|
1707
|
-
const interrupt = useLangGraphInterruptRender();
|
|
1708
|
-
return {
|
|
1709
|
-
visibleMessages: messages,
|
|
1710
|
-
messages: (0, import_runtime_client_gql7.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1711
|
-
sendMessage: latestSendMessageFunc,
|
|
1712
|
-
appendMessage: latestAppendFunc,
|
|
1713
|
-
setMessages: latestSetMessagesFunc,
|
|
1714
|
-
reloadMessages: latestReloadFunc,
|
|
1715
|
-
stopGeneration: latestStopFunc,
|
|
1716
|
-
reset: latestResetFunc,
|
|
1717
|
-
deleteMessage: latestDeleteFunc,
|
|
1718
|
-
runChatCompletion: latestRunChatCompletionFunc,
|
|
1719
|
-
isLoading,
|
|
1720
|
-
mcpServers,
|
|
1721
|
-
setMcpServers,
|
|
1722
|
-
suggestions,
|
|
1723
|
-
setSuggestions,
|
|
1724
|
-
generateSuggestions: generateSuggestionsFunc,
|
|
1725
|
-
resetSuggestions,
|
|
1726
|
-
isLoadingSuggestions: isLoadingSuggestionsRef.current,
|
|
1727
|
-
interrupt
|
|
1728
|
-
};
|
|
1729
|
-
}
|
|
1730
|
-
function useUpdatedRef(value) {
|
|
1731
|
-
const ref = (0, import_react9.useRef)(value);
|
|
1732
|
-
(0, import_react9.useEffect)(() => {
|
|
1733
|
-
ref.current = value;
|
|
1734
|
-
}, [value]);
|
|
1735
|
-
return ref;
|
|
1736
|
-
}
|
|
1737
|
-
function defaultSystemMessage(contextString, additionalInstructions) {
|
|
1738
|
-
return `
|
|
1739
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1740
|
-
|
|
1741
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
1742
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1743
|
-
|
|
1744
|
-
The user has provided you with the following context:
|
|
1745
|
-
\`\`\`
|
|
1746
|
-
${contextString}
|
|
1747
|
-
\`\`\`
|
|
1748
|
-
|
|
1749
|
-
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
1750
|
-
|
|
1751
|
-
Please assist them as best you can.
|
|
1752
|
-
|
|
1753
|
-
You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
|
|
1754
|
-
|
|
1755
|
-
If you would like to call a function, call it without saying anything else.
|
|
1756
|
-
In case of a function error:
|
|
1757
|
-
- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.
|
|
1758
|
-
- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.
|
|
1759
|
-
` + (additionalInstructions ? `
|
|
1760
|
-
|
|
1761
|
-
${additionalInstructions}` : "");
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
182
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1765
|
-
var
|
|
183
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
1766
184
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1767
|
-
|
|
1768
|
-
const {
|
|
1769
|
-
setLangGraphInterruptAction,
|
|
1770
|
-
removeLangGraphInterruptAction,
|
|
1771
|
-
langGraphInterruptAction,
|
|
1772
|
-
threadId
|
|
1773
|
-
} = (0, import_react10.useContext)(CopilotContext);
|
|
1774
|
-
const { runChatCompletion } = useCopilotChat();
|
|
185
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react3.useContext)(CopilotContext);
|
|
1775
186
|
const { addToast } = useToast();
|
|
1776
|
-
const actionId = (0,
|
|
1777
|
-
|
|
1778
|
-
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1779
|
-
[langGraphInterruptAction]
|
|
1780
|
-
);
|
|
1781
|
-
const isCurrentAction = (0, import_react10.useMemo)(
|
|
1782
|
-
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
1783
|
-
[langGraphInterruptAction]
|
|
1784
|
-
);
|
|
1785
|
-
(0, import_react10.useEffect)(() => {
|
|
1786
|
-
var _a2;
|
|
1787
|
-
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
1788
|
-
runChatCompletion();
|
|
1789
|
-
}
|
|
1790
|
-
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
1791
|
-
(0, import_react10.useEffect)(() => {
|
|
187
|
+
const actionId = (0, import_shared2.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
188
|
+
(0, import_react3.useEffect)(() => {
|
|
1792
189
|
if (!action)
|
|
1793
190
|
return;
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
return;
|
|
1800
|
-
}
|
|
1801
|
-
if (hasAction && isCurrentAction) {
|
|
1802
|
-
return;
|
|
1803
|
-
}
|
|
1804
|
-
setLangGraphInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
1805
|
-
}, [
|
|
1806
|
-
action,
|
|
1807
|
-
hasAction,
|
|
1808
|
-
isCurrentAction,
|
|
1809
|
-
setLangGraphInterruptAction,
|
|
1810
|
-
removeLangGraphInterruptAction,
|
|
1811
|
-
threadId,
|
|
1812
|
-
...dependencies || []
|
|
1813
|
-
]);
|
|
191
|
+
setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
192
|
+
return () => {
|
|
193
|
+
removeInterruptAction(actionId);
|
|
194
|
+
};
|
|
195
|
+
}, [setInterruptAction, removeInterruptAction, threadId, actionId, ...dependencies || []]);
|
|
1814
196
|
}
|
|
1815
197
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1816
198
|
0 && (module.exports = {
|