@copilotkit/react-core 0.0.0-fix-debug-infosys-20251107162427 → 0.0.0-fix-restore-handle-method-node-http-20251222114321
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-EDBI5PCJ.mjs → chunk-3V5TOYKW.mjs} +2 -2
- package/dist/chunk-3V5TOYKW.mjs.map +1 -0
- package/dist/chunk-4RRMC7L2.mjs +32 -0
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/chunk-4YZA2BZC.mjs +551 -0
- package/dist/chunk-4YZA2BZC.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-C6IANC2R.mjs → chunk-HE22TZMF.mjs} +7 -43
- package/dist/chunk-HE22TZMF.mjs.map +1 -0
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
- 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-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-OKCYPO4I.mjs → chunk-YCG6SNAU.mjs} +3 -3
- 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 +13 -11
- 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 +14 -11
- 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 +2 -2
- package/dist/components/error-boundary/error-utils.d.ts +1 -1
- package/dist/components/error-boundary/error-utils.js +3 -3
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +491 -1361
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +15 -11
- package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
- package/dist/components/toast/toast-provider.d.ts +3 -3
- package/dist/components/usage-banner.d.ts +2 -2
- package/dist/context/coagent-state-renders-context.d.ts +24 -0
- package/dist/context/coagent-state-renders-context.js +91 -0
- package/dist/context/coagent-state-renders-context.js.map +1 -0
- package/dist/context/coagent-state-renders-context.mjs +12 -0
- package/dist/context/coagent-state-renders-context.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +10 -8
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/copilot-messages-context.d.ts +18 -11
- package/dist/context/copilot-messages-context.js.map +1 -1
- package/dist/context/copilot-messages-context.mjs +1 -1
- package/dist/context/index.d.ts +6 -2
- package/dist/context/index.js +110 -10
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +20 -4
- package/dist/context/threads-context.d.ts +16 -0
- package/dist/context/threads-context.js +59 -0
- package/dist/context/threads-context.js.map +1 -0
- package/dist/context/threads-context.mjs +12 -0
- package/dist/context/threads-context.mjs.map +1 -0
- package/dist/{copilot-context-cf9de848.d.ts → copilot-context-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 +50 -58
- 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 +79 -62
- 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 +16 -12
- 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 +16 -12
- 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-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/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
- /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
- /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
* }
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
+
import { useCopilotKit } from "@copilotkitnext/react";
|
|
64
65
|
import { useEffect, useRef } from "react";
|
|
65
|
-
import { useCopilotContext } from "../context/copilot-context";
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Options for the useCopilotReadable hook.
|
|
@@ -98,40 +98,38 @@ export interface UseCopilotReadableOptions {
|
|
|
98
98
|
convert?: (description: string, value: any) => string;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function convertToJSON(description: string, value: any): string {
|
|
102
|
-
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
101
|
/**
|
|
106
102
|
* Adds the given information to the Copilot context to make it readable by Copilot.
|
|
107
103
|
*/
|
|
108
104
|
export function useCopilotReadable(
|
|
109
|
-
{
|
|
110
|
-
description,
|
|
111
|
-
value,
|
|
112
|
-
parentId,
|
|
113
|
-
categories,
|
|
114
|
-
convert,
|
|
115
|
-
available = "enabled",
|
|
116
|
-
}: UseCopilotReadableOptions,
|
|
105
|
+
{ description, value, convert, available }: UseCopilotReadableOptions,
|
|
117
106
|
dependencies?: any[],
|
|
118
107
|
): string | undefined {
|
|
119
|
-
const {
|
|
120
|
-
const
|
|
121
|
-
convert = convert || convertToJSON;
|
|
122
|
-
|
|
123
|
-
const information = convert(description, value);
|
|
124
|
-
|
|
108
|
+
const { copilotkit } = useCopilotKit();
|
|
109
|
+
const ctxIdRef = useRef<string | undefined>(undefined);
|
|
125
110
|
useEffect(() => {
|
|
126
|
-
if (
|
|
111
|
+
if (!copilotkit) return;
|
|
112
|
+
|
|
113
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
114
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
115
|
+
});
|
|
116
|
+
if (found) {
|
|
117
|
+
ctxIdRef.current = found[0];
|
|
118
|
+
if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!found && available === "disabled") return;
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
124
|
+
description,
|
|
125
|
+
value: (convert ?? JSON.stringify)(value),
|
|
126
|
+
});
|
|
130
127
|
|
|
131
128
|
return () => {
|
|
132
|
-
|
|
129
|
+
if (!ctxIdRef.current) return;
|
|
130
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
133
131
|
};
|
|
134
|
-
}, [
|
|
132
|
+
}, [description, value, convert]);
|
|
135
133
|
|
|
136
|
-
return
|
|
134
|
+
return ctxIdRef.current;
|
|
137
135
|
}
|
|
@@ -16,9 +16,10 @@ interface FlatCategoryStoreElement<T> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
|
|
19
|
-
const [elements, dispatch] = useReducer
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const [elements, dispatch] = useReducer(
|
|
20
|
+
flatCategoryStoreReducer<T>,
|
|
21
|
+
new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>(),
|
|
22
|
+
);
|
|
22
23
|
|
|
23
24
|
const addElement = useCallback((value: T, categories: string[]): FlatCategoryStoreId => {
|
|
24
25
|
const newId = randomId();
|
|
@@ -1,18 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FrontendAction } from "../types/frontend-action";
|
|
3
|
-
import { Parameter } from "@copilotkit/shared";
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
|
|
3
|
+
import { Parameter, getZodParameters, MappedParameterTypes } from "@copilotkit/shared";
|
|
4
|
+
import { parseJson } from "@copilotkit/shared";
|
|
5
|
+
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
6
|
+
import {
|
|
7
|
+
type ReactFrontendTool,
|
|
8
|
+
useFrontendTool as useFrontendToolVNext,
|
|
9
|
+
} from "@copilotkitnext/react";
|
|
4
10
|
|
|
5
|
-
type
|
|
11
|
+
type FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<MappedParameterTypes<T>>;
|
|
12
|
+
type FrontendToolRenderArgs<T extends Parameter[] | []> =
|
|
13
|
+
| {
|
|
14
|
+
name: string;
|
|
15
|
+
args: Partial<MappedParameterTypes<T>>;
|
|
16
|
+
status: ToolCallStatus.InProgress;
|
|
17
|
+
result: undefined;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
name: string;
|
|
21
|
+
args: MappedParameterTypes<T>;
|
|
22
|
+
status: ToolCallStatus.Executing;
|
|
23
|
+
result: undefined;
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
name: string;
|
|
27
|
+
args: MappedParameterTypes<T>;
|
|
28
|
+
status: ToolCallStatus.Complete;
|
|
29
|
+
result: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type UseFrontendToolArgs<T extends Parameter[] | [] = []> = {
|
|
6
33
|
available?: "disabled" | "enabled";
|
|
7
34
|
} & Pick<
|
|
8
35
|
FrontendAction<T>,
|
|
9
36
|
"name" | "description" | "parameters" | "handler" | "followUp" | "render"
|
|
10
37
|
>;
|
|
11
38
|
|
|
12
|
-
export function useFrontendTool<const T extends Parameter[]
|
|
13
|
-
tool:
|
|
39
|
+
export function useFrontendTool<const T extends Parameter[] = []>(
|
|
40
|
+
tool: UseFrontendToolArgs<T>,
|
|
14
41
|
dependencies?: any[],
|
|
15
42
|
) {
|
|
16
|
-
|
|
17
|
-
|
|
43
|
+
const { name, description, parameters, render, followUp } = tool;
|
|
44
|
+
const zodParameters = getZodParameters(parameters);
|
|
45
|
+
|
|
46
|
+
const normalizedRender: FrontendToolOptions<T>["render"] | undefined = (() => {
|
|
47
|
+
if (typeof render === "undefined") {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof render === "string") {
|
|
52
|
+
const staticRender = render;
|
|
53
|
+
return (() =>
|
|
54
|
+
React.createElement(
|
|
55
|
+
React.Fragment,
|
|
56
|
+
null,
|
|
57
|
+
staticRender,
|
|
58
|
+
)) as FrontendToolOptions<T>["render"];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return ((args: FrontendToolRenderArgs<T>) => {
|
|
62
|
+
const renderArgs = {
|
|
63
|
+
...args,
|
|
64
|
+
result: typeof args.result === "string" ? parseJson(args.result, args.result) : args.result,
|
|
65
|
+
} as ActionRenderProps<T>;
|
|
66
|
+
|
|
67
|
+
const rendered = render(renderArgs);
|
|
68
|
+
|
|
69
|
+
if (typeof rendered === "string") {
|
|
70
|
+
return React.createElement(React.Fragment, null, rendered);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return rendered ?? null;
|
|
74
|
+
}) as FrontendToolOptions<T>["render"];
|
|
75
|
+
})();
|
|
76
|
+
|
|
77
|
+
// Handler ref to avoid stale closures
|
|
78
|
+
const handlerRef = useRef<typeof tool.handler>(tool.handler);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
handlerRef.current = tool.handler;
|
|
82
|
+
}, [tool.handler, ...(dependencies ?? [])]);
|
|
83
|
+
|
|
84
|
+
const normalizedHandler = tool.handler
|
|
85
|
+
? (args: MappedParameterTypes<T>) => handlerRef.current?.(args)
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
88
|
+
useFrontendToolVNext<MappedParameterTypes<T>>({
|
|
89
|
+
name,
|
|
90
|
+
description,
|
|
91
|
+
parameters: zodParameters,
|
|
92
|
+
handler: normalizedHandler,
|
|
93
|
+
followUp,
|
|
94
|
+
render: normalizedRender,
|
|
95
|
+
});
|
|
18
96
|
}
|
|
@@ -1,24 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ActionRenderProps, ActionRenderPropsWait, FrontendAction } from "../types";
|
|
2
|
+
import {
|
|
3
|
+
CopilotKitError,
|
|
4
|
+
CopilotKitErrorCode,
|
|
5
|
+
MappedParameterTypes,
|
|
6
|
+
Parameter,
|
|
7
|
+
getZodParameters,
|
|
8
|
+
parseJson,
|
|
9
|
+
} from "@copilotkit/shared";
|
|
10
|
+
import { useHumanInTheLoop as useHumanInTheLoopVNext } from "@copilotkitnext/react";
|
|
11
|
+
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
12
|
+
import React, { ComponentType, FunctionComponent, useEffect, useRef } from "react";
|
|
4
13
|
|
|
5
|
-
type
|
|
14
|
+
type HumanInTheLoopOptions = Parameters<typeof useHumanInTheLoopVNext>[0];
|
|
15
|
+
type HumanInTheLoopRender = HumanInTheLoopOptions["render"];
|
|
16
|
+
type HumanInTheLoopRenderArgs = HumanInTheLoopRender extends (props: infer P) => any ? P : never;
|
|
17
|
+
|
|
18
|
+
export type UseHumanInTheLoopArgs<T extends Parameter[] | [] = []> = {
|
|
6
19
|
available?: "disabled" | "enabled";
|
|
7
20
|
render: FrontendAction<T>["renderAndWaitForResponse"];
|
|
21
|
+
followUp?: FrontendAction<T>["followUp"];
|
|
8
22
|
} & Pick<FrontendAction<T>, "name" | "description" | "parameters">;
|
|
9
23
|
|
|
24
|
+
type HitlRendererArgs =
|
|
25
|
+
| {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
args: Partial<Record<string, unknown>>;
|
|
29
|
+
status: ToolCallStatus.InProgress;
|
|
30
|
+
result: undefined;
|
|
31
|
+
respond: undefined;
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
args: Record<string, unknown>;
|
|
37
|
+
status: ToolCallStatus.Executing;
|
|
38
|
+
result: undefined;
|
|
39
|
+
respond: (result: unknown) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
args: Record<string, unknown>;
|
|
45
|
+
status: ToolCallStatus.Complete;
|
|
46
|
+
result: string;
|
|
47
|
+
respond: undefined;
|
|
48
|
+
};
|
|
49
|
+
type HitlRenderer = FunctionComponent<HitlRendererArgs>;
|
|
50
|
+
|
|
10
51
|
export function useHumanInTheLoop<const T extends Parameter[] | [] = []>(
|
|
11
|
-
tool:
|
|
52
|
+
tool: UseHumanInTheLoopArgs<T>,
|
|
12
53
|
dependencies?: any[],
|
|
13
54
|
) {
|
|
14
55
|
const { render, ...toolRest } = tool;
|
|
56
|
+
const { name, description, parameters, followUp } = toolRest;
|
|
57
|
+
const zodParameters = getZodParameters(parameters);
|
|
58
|
+
const renderRef = useRef<HitlRenderer | null>(null);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
renderRef.current = (args: HitlRendererArgs): React.ReactElement | null => {
|
|
62
|
+
if (typeof render === "string") {
|
|
63
|
+
return React.createElement(React.Fragment, null, render);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!render) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const renderProps: ActionRenderPropsWait<T> = (() => {
|
|
71
|
+
const mappedArgs = args.args as unknown as MappedParameterTypes<T>;
|
|
72
|
+
|
|
73
|
+
switch (args.status) {
|
|
74
|
+
case ToolCallStatus.InProgress:
|
|
75
|
+
return {
|
|
76
|
+
args: mappedArgs,
|
|
77
|
+
respond: args.respond,
|
|
78
|
+
status: args.status,
|
|
79
|
+
handler: undefined,
|
|
80
|
+
};
|
|
81
|
+
case ToolCallStatus.Executing:
|
|
82
|
+
return {
|
|
83
|
+
args: mappedArgs,
|
|
84
|
+
respond: args.respond,
|
|
85
|
+
status: args.status,
|
|
86
|
+
handler: () => {},
|
|
87
|
+
};
|
|
88
|
+
case ToolCallStatus.Complete:
|
|
89
|
+
return {
|
|
90
|
+
args: mappedArgs,
|
|
91
|
+
respond: args.respond,
|
|
92
|
+
status: args.status,
|
|
93
|
+
result: args.result ? parseJson(args.result, args.result) : args.result,
|
|
94
|
+
handler: undefined,
|
|
95
|
+
};
|
|
96
|
+
default:
|
|
97
|
+
throw new CopilotKitError({
|
|
98
|
+
code: CopilotKitErrorCode.UNKNOWN,
|
|
99
|
+
message: `Invalid tool call status: ${(args as unknown as { status: string }).status}`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
const rendered = render(renderProps);
|
|
105
|
+
|
|
106
|
+
if (typeof rendered === "string") {
|
|
107
|
+
return React.createElement(React.Fragment, null, rendered);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return rendered ?? null;
|
|
111
|
+
};
|
|
112
|
+
}, [render, ...(dependencies ?? [])]);
|
|
15
113
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
114
|
+
useHumanInTheLoopVNext({
|
|
115
|
+
name,
|
|
116
|
+
description,
|
|
117
|
+
followUp,
|
|
118
|
+
parameters: zodParameters,
|
|
119
|
+
render: ((args: HumanInTheLoopRenderArgs) =>
|
|
120
|
+
renderRef.current?.(args as HitlRendererArgs) ?? null) as HumanInTheLoopOptions["render"],
|
|
121
|
+
});
|
|
24
122
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useCopilotContext } from "../context";
|
|
2
|
-
import React, { useCallback } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import React, { useCallback, useEffect, useMemo } from "react";
|
|
3
|
+
import type { AbstractAgent, AgentSubscriber } from "@ag-ui/client";
|
|
4
|
+
import { MetaEventName } from "@copilotkit/runtime-client-gql";
|
|
5
|
+
import { dataToUUID, parseJson } from "@copilotkit/shared";
|
|
6
|
+
import { useAgentNodeName } from "./use-agent-nodename";
|
|
7
|
+
import { useCopilotChatConfiguration } from "@copilotkitnext/react";
|
|
4
8
|
|
|
5
9
|
type InterruptProps = {
|
|
6
10
|
event: any;
|
|
@@ -17,52 +21,116 @@ const InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, re
|
|
|
17
21
|
return render({ event, result, resolve });
|
|
18
22
|
};
|
|
19
23
|
|
|
20
|
-
export function useLangGraphInterruptRender(
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
export function useLangGraphInterruptRender(
|
|
25
|
+
agent: AbstractAgent,
|
|
26
|
+
): string | React.ReactElement | null {
|
|
27
|
+
const {
|
|
28
|
+
interruptActions,
|
|
29
|
+
agentSession,
|
|
30
|
+
threadId,
|
|
31
|
+
interruptEventQueue,
|
|
32
|
+
addInterruptEvent,
|
|
33
|
+
resolveInterruptEvent,
|
|
34
|
+
} = useCopilotContext();
|
|
35
|
+
const existingConfig = useCopilotChatConfiguration();
|
|
36
|
+
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
37
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!agent) return;
|
|
41
|
+
let localInterrupt: any = null;
|
|
42
|
+
const subscriber: AgentSubscriber = {
|
|
43
|
+
onCustomEvent: ({ event }) => {
|
|
44
|
+
if (event.name === "on_interrupt") {
|
|
45
|
+
const eventData = {
|
|
46
|
+
name: MetaEventName.LangGraphInterruptEvent,
|
|
47
|
+
type: event.type,
|
|
48
|
+
value: parseJson(event.value, event.value),
|
|
49
|
+
};
|
|
50
|
+
const eventId = dataToUUID(eventData, "interruptEvents");
|
|
51
|
+
localInterrupt = {
|
|
52
|
+
eventId,
|
|
53
|
+
threadId,
|
|
54
|
+
event: eventData,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
onRunStartedEvent: () => {
|
|
59
|
+
localInterrupt = null;
|
|
60
|
+
},
|
|
61
|
+
onRunFinalized: () => {
|
|
62
|
+
if (localInterrupt) {
|
|
63
|
+
addInterruptEvent(localInterrupt);
|
|
64
|
+
localInterrupt = null;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
70
|
+
return () => {
|
|
71
|
+
unsubscribe();
|
|
72
|
+
};
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
|
+
}, [agent, threadId]);
|
|
75
|
+
|
|
76
|
+
const handleResolve = useCallback(
|
|
77
|
+
(eventId: string, response?: string) => {
|
|
78
|
+
agent?.runAgent({
|
|
79
|
+
forwardedProps: {
|
|
80
|
+
command: {
|
|
81
|
+
resume: response,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
resolveInterruptEvent(threadId, eventId, response ?? "");
|
|
32
86
|
},
|
|
33
|
-
|
|
87
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
|
+
[agent, threadId],
|
|
34
89
|
);
|
|
35
90
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
!
|
|
40
|
-
|
|
41
|
-
return null;
|
|
91
|
+
return useMemo(() => {
|
|
92
|
+
// Get the queue for this thread and find the first unresponded event
|
|
93
|
+
const eventQueue = interruptEventQueue[threadId] || [];
|
|
94
|
+
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
95
|
+
|
|
96
|
+
if (!currentQueuedEvent || !agentSession) return null;
|
|
97
|
+
|
|
98
|
+
// Find the first matching action from all registered actions
|
|
99
|
+
const allActions = Object.values(interruptActions);
|
|
100
|
+
const matchingAction = allActions.find((action) => {
|
|
101
|
+
if (!action.enabled) return true; // No filter = match all
|
|
102
|
+
return action.enabled({
|
|
103
|
+
eventValue: currentQueuedEvent.event.value,
|
|
104
|
+
agentMetadata: {
|
|
105
|
+
...agentSession,
|
|
106
|
+
nodeName,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!matchingAction) return null;
|
|
42
112
|
|
|
43
|
-
|
|
113
|
+
const { render, handler } = matchingAction;
|
|
44
114
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
: enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
115
|
+
const resolveInterrupt = (response: string) => {
|
|
116
|
+
handleResolve(currentQueuedEvent.eventId, response);
|
|
117
|
+
};
|
|
49
118
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
119
|
+
let result = null;
|
|
120
|
+
if (handler) {
|
|
121
|
+
result = handler({
|
|
122
|
+
event: currentQueuedEvent.event,
|
|
123
|
+
resolve: resolveInterrupt,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
53
126
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
event,
|
|
127
|
+
if (!render) return null;
|
|
128
|
+
|
|
129
|
+
return React.createElement(InterruptRenderer, {
|
|
130
|
+
event: currentQueuedEvent.event,
|
|
131
|
+
result,
|
|
132
|
+
render,
|
|
58
133
|
resolve: resolveInterrupt,
|
|
59
134
|
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return React.createElement(InterruptRenderer, {
|
|
63
|
-
event,
|
|
64
|
-
result,
|
|
65
|
-
render,
|
|
66
|
-
resolve: resolveInterrupt,
|
|
67
|
-
});
|
|
135
|
+
}, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);
|
|
68
136
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useMemo } from "react";
|
|
2
2
|
import { CopilotContext } from "../context/copilot-context";
|
|
3
3
|
import { LangGraphInterruptRender } from "../types/interrupt-action";
|
|
4
|
-
import { useCopilotChat } from "./use-copilot-chat_internal";
|
|
5
4
|
import { useToast } from "../components/toast/toast-provider";
|
|
6
5
|
import { dataToUUID } from "@copilotkit/shared";
|
|
7
6
|
|
|
@@ -9,58 +8,29 @@ export function useLangGraphInterrupt<TEventValue = any>(
|
|
|
9
8
|
action: Omit<LangGraphInterruptRender<TEventValue>, "id">,
|
|
10
9
|
dependencies?: any[],
|
|
11
10
|
) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
removeLangGraphInterruptAction,
|
|
15
|
-
langGraphInterruptAction,
|
|
16
|
-
threadId,
|
|
17
|
-
} = useContext(CopilotContext);
|
|
18
|
-
const { runChatCompletion } = useCopilotChat();
|
|
11
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } =
|
|
12
|
+
useContext(CopilotContext);
|
|
19
13
|
const { addToast } = useToast();
|
|
20
14
|
|
|
21
|
-
const actionId = dataToUUID(
|
|
22
|
-
// We only consider action to be defined once the ID is there
|
|
23
|
-
const hasAction = useMemo(
|
|
24
|
-
() => Boolean(langGraphInterruptAction?.id),
|
|
25
|
-
[langGraphInterruptAction],
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const isCurrentAction = useMemo(
|
|
29
|
-
() => langGraphInterruptAction?.id && langGraphInterruptAction?.id === actionId,
|
|
30
|
-
[langGraphInterruptAction],
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// Run chat completion to submit a response event. Only if it's the current action
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (hasAction && isCurrentAction && langGraphInterruptAction?.event?.response) {
|
|
36
|
-
runChatCompletion();
|
|
37
|
-
}
|
|
38
|
-
}, [langGraphInterruptAction?.event?.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
15
|
+
const actionId = dataToUUID(action, "lgAction");
|
|
39
16
|
|
|
40
17
|
useEffect(() => {
|
|
41
18
|
if (!action) return;
|
|
42
|
-
// An action was already set, with no conditions and it's not the action we're using right now.
|
|
43
|
-
// Show a warning, as this action will not be executed
|
|
44
|
-
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
45
|
-
addToast({
|
|
46
|
-
type: "warning",
|
|
47
|
-
message: "An action is already registered for the interrupt event",
|
|
48
|
-
});
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
19
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
20
|
+
// if (!action.enabled) {
|
|
21
|
+
// TODO: if there are any other actions registered, we need to warn the user that a current action without "enabled" might render for everything
|
|
22
|
+
// addToast({
|
|
23
|
+
// type: "warning",
|
|
24
|
+
// message: "An action is already registered for the interrupt event",
|
|
25
|
+
// });
|
|
26
|
+
// return;
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
setInterruptAction({ ...action, id: actionId });
|
|
55
30
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
setLangGraphInterruptAction,
|
|
62
|
-
removeLangGraphInterruptAction,
|
|
63
|
-
threadId,
|
|
64
|
-
...(dependencies || []),
|
|
65
|
-
]);
|
|
31
|
+
// Cleanup: remove action on unmount
|
|
32
|
+
return () => {
|
|
33
|
+
removeInterruptAction(actionId);
|
|
34
|
+
};
|
|
35
|
+
}, [setInterruptAction, removeInterruptAction, threadId, actionId, ...(dependencies || [])]);
|
|
66
36
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useRenderToolCall } from "@copilotkitnext/react";
|
|
2
|
+
import { AIMessage, Message, ToolResult } from "@copilotkit/shared";
|
|
3
|
+
import React, { useCallback } from "react";
|
|
4
|
+
|
|
5
|
+
export function useLazyToolRenderer(): (
|
|
6
|
+
message?: AIMessage,
|
|
7
|
+
messages?: Message[],
|
|
8
|
+
) => null | (() => ReturnType<ReturnType<typeof useRenderToolCall>> | null) {
|
|
9
|
+
const renderToolCall = useRenderToolCall();
|
|
10
|
+
|
|
11
|
+
return useCallback(
|
|
12
|
+
(message?: AIMessage, messages?: Message[]) => {
|
|
13
|
+
if (!message?.toolCalls?.length) return null;
|
|
14
|
+
|
|
15
|
+
const toolCall = message.toolCalls[0];
|
|
16
|
+
if (!toolCall) return null;
|
|
17
|
+
|
|
18
|
+
const toolMessage = messages?.find(
|
|
19
|
+
(m) => m.role === "tool" && m.toolCallId === toolCall.id,
|
|
20
|
+
) as ToolResult;
|
|
21
|
+
|
|
22
|
+
return () =>
|
|
23
|
+
renderToolCall({
|
|
24
|
+
toolCall,
|
|
25
|
+
toolMessage,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
[renderToolCall],
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -15,7 +15,7 @@ export function useMakeCopilotDocumentReadable(
|
|
|
15
15
|
dependencies: any[] = [],
|
|
16
16
|
): string | undefined {
|
|
17
17
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
18
|
-
const idRef = useRef<string>();
|
|
18
|
+
const idRef = useRef<string>(undefined!);
|
|
19
19
|
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
const id = addDocumentContext(document, categories);
|