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