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