@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useState,
|
|
6
|
+
useRef,
|
|
7
|
+
ReactNode,
|
|
8
|
+
RefObject,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { CoAgentStateRender } from "../types/coagent-action";
|
|
11
|
+
|
|
12
|
+
interface StateRenderClaim {
|
|
13
|
+
stateRenderId: string;
|
|
14
|
+
stateSnapshot?: any;
|
|
15
|
+
runId?: string;
|
|
16
|
+
locked?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ClaimsRef = Record<string, StateRenderClaim>;
|
|
20
|
+
|
|
21
|
+
export interface CoAgentStateRendersContextValue {
|
|
22
|
+
coAgentStateRenders: Record<string, CoAgentStateRender<any>>;
|
|
23
|
+
setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;
|
|
24
|
+
removeCoAgentStateRender: (id: string) => void;
|
|
25
|
+
claimsRef: RefObject<ClaimsRef>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const CoAgentStateRendersContext = createContext<CoAgentStateRendersContextValue | undefined>(
|
|
29
|
+
undefined,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export function CoAgentStateRendersProvider({ children }: { children: ReactNode }) {
|
|
33
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = useState<
|
|
34
|
+
Record<string, CoAgentStateRender<any>>
|
|
35
|
+
>({});
|
|
36
|
+
|
|
37
|
+
const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {
|
|
38
|
+
setCoAgentStateRenders((prevPoints) => ({
|
|
39
|
+
...prevPoints,
|
|
40
|
+
[id]: stateRender,
|
|
41
|
+
}));
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
const removeCoAgentStateRender = useCallback((id: string) => {
|
|
45
|
+
setCoAgentStateRenders((prevPoints) => {
|
|
46
|
+
const newPoints = { ...prevPoints };
|
|
47
|
+
delete newPoints[id];
|
|
48
|
+
return newPoints;
|
|
49
|
+
});
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
const claimsRef = useRef<ClaimsRef>({});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<CoAgentStateRendersContext.Provider
|
|
56
|
+
value={{
|
|
57
|
+
coAgentStateRenders,
|
|
58
|
+
setCoAgentStateRender,
|
|
59
|
+
removeCoAgentStateRender,
|
|
60
|
+
claimsRef,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</CoAgentStateRendersContext.Provider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useCoAgentStateRenders() {
|
|
69
|
+
const context = useContext(CoAgentStateRendersContext);
|
|
70
|
+
if (!context) {
|
|
71
|
+
throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
|
|
72
|
+
}
|
|
73
|
+
return context;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { CoAgentStateRendersContext };
|
|
@@ -22,10 +22,10 @@ import {
|
|
|
22
22
|
} from "@copilotkit/runtime-client-gql";
|
|
23
23
|
import { Agent } from "@copilotkit/runtime-client-gql";
|
|
24
24
|
import {
|
|
25
|
-
|
|
25
|
+
LangGraphInterruptRender,
|
|
26
26
|
LangGraphInterruptActionSetter,
|
|
27
|
+
QueuedInterruptEvent,
|
|
27
28
|
} from "../types/interrupt-action";
|
|
28
|
-
import { SuggestionItem } from "../utils/suggestions";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Interface for the configuration of the Copilot API.
|
|
@@ -95,10 +95,10 @@ export interface CopilotApiConfig {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =
|
|
98
|
-
(props: TProps) => string | JSX.Element;
|
|
98
|
+
(props: TProps) => string | React.JSX.Element;
|
|
99
99
|
export type CoagentInChatRenderFunction = (
|
|
100
100
|
props: CoAgentStateRenderProps<any>,
|
|
101
|
-
) => string | JSX.Element | undefined | null;
|
|
101
|
+
) => string | React.JSX.Element | undefined | null;
|
|
102
102
|
|
|
103
103
|
export interface ChatComponentsCache {
|
|
104
104
|
actions: Record<string, InChatRenderFunction | string>;
|
|
@@ -127,10 +127,9 @@ export interface CopilotContextParams {
|
|
|
127
127
|
setAction: (id: string, action: FrontendAction<any>) => void;
|
|
128
128
|
removeAction: (id: string) => void;
|
|
129
129
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
removeCoAgentStateRender: (id: string) => void;
|
|
130
|
+
// registered actions for component-based rendering
|
|
131
|
+
setRegisteredActions: (actionConfig: any) => string;
|
|
132
|
+
removeRegisteredAction: (actionKey: string) => void;
|
|
134
133
|
|
|
135
134
|
chatComponentsCache: React.RefObject<ChatComponentsCache>;
|
|
136
135
|
|
|
@@ -195,9 +194,6 @@ export interface CopilotContextParams {
|
|
|
195
194
|
// i.e. when using `stop()` from `useChat`
|
|
196
195
|
chatAbortControllerRef: React.MutableRefObject<AbortController | null>;
|
|
197
196
|
|
|
198
|
-
// runtime
|
|
199
|
-
runtimeClient: CopilotRuntimeClient;
|
|
200
|
-
|
|
201
197
|
/**
|
|
202
198
|
* The forwarded parameters to use for the task.
|
|
203
199
|
*/
|
|
@@ -221,9 +217,12 @@ export interface CopilotContextParams {
|
|
|
221
217
|
|
|
222
218
|
extensions: ExtensionsInput;
|
|
223
219
|
setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
interruptActions: Record<string, LangGraphInterruptRender>;
|
|
221
|
+
setInterruptAction: LangGraphInterruptActionSetter;
|
|
222
|
+
removeInterruptAction: (actionId: string) => void;
|
|
223
|
+
interruptEventQueue: Record<string, QueuedInterruptEvent[]>;
|
|
224
|
+
addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;
|
|
225
|
+
resolveInterruptEvent: (threadId: string, eventId: string, response: string) => void;
|
|
227
226
|
|
|
228
227
|
/**
|
|
229
228
|
* Optional trace handler for comprehensive debugging and observability.
|
|
@@ -246,9 +245,8 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
246
245
|
setAction: () => {},
|
|
247
246
|
removeAction: () => {},
|
|
248
247
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
removeCoAgentStateRender: () => {},
|
|
248
|
+
setRegisteredActions: () => "",
|
|
249
|
+
removeRegisteredAction: () => {},
|
|
252
250
|
|
|
253
251
|
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
254
252
|
getContextString: (documents: DocumentPointer[], categories: string[]) =>
|
|
@@ -271,7 +269,6 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
271
269
|
getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),
|
|
272
270
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
273
271
|
removeDocumentContext: () => {},
|
|
274
|
-
runtimeClient: {} as any,
|
|
275
272
|
|
|
276
273
|
copilotApiConfig: new (class implements CopilotApiConfig {
|
|
277
274
|
get chatApiEndpoint(): string {
|
|
@@ -306,9 +303,12 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
306
303
|
availableAgents: [],
|
|
307
304
|
extensions: {},
|
|
308
305
|
setExtensions: () => {},
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
interruptActions: {},
|
|
307
|
+
setInterruptAction: () => {},
|
|
308
|
+
removeInterruptAction: () => {},
|
|
309
|
+
interruptEventQueue: {},
|
|
310
|
+
addInterruptEvent: () => {},
|
|
311
|
+
resolveInterruptEvent: () => {},
|
|
312
312
|
onError: () => {},
|
|
313
313
|
bannerError: null,
|
|
314
314
|
setBannerError: () => {},
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { Message } from "@copilotkit/runtime-client-gql";
|
|
6
6
|
import React from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { Suggestion } from "@copilotkitnext/core";
|
|
8
8
|
|
|
9
9
|
export interface CopilotMessagesContextParams {
|
|
10
10
|
messages: Message[];
|
|
11
11
|
setMessages: React.Dispatch<React.SetStateAction<Message[]>>; // suggestions state
|
|
12
|
-
suggestions:
|
|
13
|
-
setSuggestions: React.Dispatch<React.SetStateAction<
|
|
12
|
+
suggestions: Suggestion[];
|
|
13
|
+
setSuggestions: React.Dispatch<React.SetStateAction<Suggestion[]>>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const emptyCopilotContext: CopilotMessagesContextParams = {
|
package/src/context/index.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export { CopilotContext, useCopilotContext } from "./copilot-context";
|
|
2
2
|
export { CopilotMessagesContext, useCopilotMessagesContext } from "./copilot-messages-context";
|
|
3
|
+
export {
|
|
4
|
+
CoAgentStateRendersContext,
|
|
5
|
+
CoAgentStateRendersProvider,
|
|
6
|
+
useCoAgentStateRenders,
|
|
7
|
+
} from "./coagent-state-renders-context";
|
|
8
|
+
export { ThreadsContext, ThreadsProvider, useThreads } from "./threads-context";
|
|
3
9
|
export type {
|
|
4
10
|
CopilotContextParams,
|
|
5
11
|
CoagentInChatRenderFunction,
|
|
6
12
|
CopilotApiConfig,
|
|
7
13
|
} from "./copilot-context";
|
|
8
14
|
export type { CopilotMessagesContextParams } from "./copilot-messages-context";
|
|
15
|
+
export type { CoAgentStateRendersContextValue } from "./coagent-state-renders-context";
|
|
16
|
+
export type { ThreadsContextValue, ThreadsProviderProps } from "./threads-context";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, ReactNode, SetStateAction } from "react";
|
|
2
|
+
import { randomUUID } from "@copilotkit/shared";
|
|
3
|
+
|
|
4
|
+
export interface ThreadsContextValue {
|
|
5
|
+
threadId: string;
|
|
6
|
+
setThreadId: (value: SetStateAction<string>) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);
|
|
10
|
+
|
|
11
|
+
export interface ThreadsProviderProps {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
threadId?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {
|
|
17
|
+
const [internalThreadId, setThreadId] = useState<string>(explicitThreadId ?? randomUUID());
|
|
18
|
+
|
|
19
|
+
const threadId = internalThreadId;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<ThreadsContext.Provider
|
|
23
|
+
value={{
|
|
24
|
+
threadId,
|
|
25
|
+
setThreadId,
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</ThreadsContext.Provider>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useThreads() {
|
|
34
|
+
const context = useContext(ThreadsContext);
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useThreads must be used within ThreadsProvider");
|
|
37
|
+
}
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { ThreadsContext };
|
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react";
|
|
1
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { useCoAgent } from "../use-coagent";
|
|
3
|
+
import type { AgentSubscriber } from "@ag-ui/client";
|
|
4
|
+
|
|
5
|
+
// Mock functions for @copilotkitnext/react
|
|
6
|
+
const mockSetState = jest.fn();
|
|
7
|
+
const mockRunAgent = jest.fn();
|
|
8
|
+
const mockAbortRun = jest.fn();
|
|
9
|
+
const mockSubscribe = jest.fn();
|
|
10
|
+
const mockSetProperties = jest.fn();
|
|
11
|
+
|
|
12
|
+
// Store the last subscriber for triggering events
|
|
13
|
+
let lastSubscriber: AgentSubscriber | null = null;
|
|
14
|
+
|
|
15
|
+
const mockAgent = {
|
|
16
|
+
agentId: "test-agent",
|
|
17
|
+
state: { count: 0 },
|
|
18
|
+
isRunning: false,
|
|
19
|
+
threadId: "thread-123",
|
|
20
|
+
setState: mockSetState,
|
|
21
|
+
runAgent: mockRunAgent,
|
|
22
|
+
abortRun: mockAbortRun,
|
|
23
|
+
subscribe: mockSubscribe.mockImplementation((subscriber: AgentSubscriber) => {
|
|
24
|
+
lastSubscriber = subscriber;
|
|
25
|
+
return {
|
|
26
|
+
unsubscribe: jest.fn(),
|
|
27
|
+
};
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
3
30
|
|
|
4
|
-
|
|
5
|
-
|
|
31
|
+
jest.mock("@copilotkitnext/react", () => ({
|
|
32
|
+
useAgent: jest.fn(() => ({ agent: mockAgent })),
|
|
33
|
+
useCopilotKit: jest.fn(() => ({
|
|
34
|
+
copilotkit: {
|
|
35
|
+
setProperties: mockSetProperties,
|
|
36
|
+
},
|
|
37
|
+
})),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
// Mock other dependencies
|
|
6
41
|
const mockAppendMessage = jest.fn();
|
|
7
42
|
const mockRunChatCompletion = jest.fn();
|
|
8
43
|
|
|
@@ -27,7 +62,6 @@ jest.mock("../../context", () => ({
|
|
|
27
62
|
availableAgents: [],
|
|
28
63
|
coagentStates: {},
|
|
29
64
|
coagentStatesRef: { current: {} },
|
|
30
|
-
setCoagentStatesWithRef: mockSetCoagentStatesWithRef,
|
|
31
65
|
threadId: "test-thread",
|
|
32
66
|
copilotApiConfig: {
|
|
33
67
|
headers: {},
|
|
@@ -61,14 +95,10 @@ jest.mock("../../components/copilot-provider/copilot-messages", () => ({
|
|
|
61
95
|
describe("useCoAgent config synchronization", () => {
|
|
62
96
|
beforeEach(() => {
|
|
63
97
|
jest.clearAllMocks();
|
|
64
|
-
|
|
65
|
-
if (typeof updater === "function") {
|
|
66
|
-
updater({});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
98
|
+
lastSubscriber = null;
|
|
69
99
|
});
|
|
70
100
|
|
|
71
|
-
it("should call
|
|
101
|
+
it("should call setProperties when config changes", async () => {
|
|
72
102
|
const { rerender } = renderHook(
|
|
73
103
|
({ config }) =>
|
|
74
104
|
useCoAgent({
|
|
@@ -82,16 +112,20 @@ describe("useCoAgent config synchronization", () => {
|
|
|
82
112
|
);
|
|
83
113
|
|
|
84
114
|
// Clear the initial calls
|
|
85
|
-
|
|
115
|
+
mockSetProperties.mockClear();
|
|
86
116
|
|
|
87
117
|
// Change config
|
|
88
118
|
rerender({ config: { configurable: { model: "gpt-4o" } } });
|
|
89
119
|
|
|
90
|
-
//
|
|
91
|
-
|
|
120
|
+
// Wait for effect to complete and verify setProperties was called
|
|
121
|
+
await waitFor(() => {
|
|
122
|
+
expect(mockSetProperties).toHaveBeenCalledWith({
|
|
123
|
+
configurable: { model: "gpt-4o" },
|
|
124
|
+
});
|
|
125
|
+
});
|
|
92
126
|
});
|
|
93
127
|
|
|
94
|
-
it("should not call
|
|
128
|
+
it("should not call setProperties when config is unchanged", () => {
|
|
95
129
|
const config = { configurable: { model: "gpt-4" } };
|
|
96
130
|
|
|
97
131
|
const { rerender } = renderHook(
|
|
@@ -107,16 +141,16 @@ describe("useCoAgent config synchronization", () => {
|
|
|
107
141
|
);
|
|
108
142
|
|
|
109
143
|
// Clear the initial calls
|
|
110
|
-
|
|
144
|
+
mockSetProperties.mockClear();
|
|
111
145
|
|
|
112
|
-
// Re-render with same config
|
|
146
|
+
// Re-render with same config reference
|
|
113
147
|
rerender({ config });
|
|
114
148
|
|
|
115
|
-
// Should not have called
|
|
116
|
-
expect(
|
|
149
|
+
// Should not have called setProperties
|
|
150
|
+
expect(mockSetProperties).not.toHaveBeenCalled();
|
|
117
151
|
});
|
|
118
152
|
|
|
119
|
-
it("should handle backward compatibility with configurable prop", () => {
|
|
153
|
+
it("should handle backward compatibility with configurable prop", async () => {
|
|
120
154
|
const { rerender } = renderHook(
|
|
121
155
|
({ configurable }) =>
|
|
122
156
|
useCoAgent({
|
|
@@ -130,23 +164,32 @@ describe("useCoAgent config synchronization", () => {
|
|
|
130
164
|
);
|
|
131
165
|
|
|
132
166
|
// Clear the initial calls
|
|
133
|
-
|
|
167
|
+
mockSetProperties.mockClear();
|
|
134
168
|
|
|
135
169
|
// Change configurable prop
|
|
136
170
|
rerender({ configurable: { model: "gpt-4o" } });
|
|
137
171
|
|
|
138
|
-
//
|
|
139
|
-
|
|
172
|
+
// Wait for effect to complete and verify setProperties was called
|
|
173
|
+
await waitFor(() => {
|
|
174
|
+
expect(mockSetProperties).toHaveBeenCalledWith({
|
|
175
|
+
configurable: { model: "gpt-4o" },
|
|
176
|
+
});
|
|
177
|
+
});
|
|
140
178
|
});
|
|
141
179
|
|
|
142
|
-
it("should
|
|
143
|
-
|
|
180
|
+
it("should not call setProperties when both config and configurable are undefined", () => {
|
|
181
|
+
renderHook(() =>
|
|
182
|
+
useCoAgent({
|
|
183
|
+
name: "test-agent",
|
|
184
|
+
initialState: { count: 0 },
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
144
187
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
188
|
+
// Should not have called setProperties
|
|
189
|
+
expect(mockSetProperties).not.toHaveBeenCalled();
|
|
190
|
+
});
|
|
149
191
|
|
|
192
|
+
it("should handle deeply nested config changes", async () => {
|
|
150
193
|
const { rerender } = renderHook(
|
|
151
194
|
({ config }) =>
|
|
152
195
|
useCoAgent({
|
|
@@ -155,137 +198,154 @@ describe("useCoAgent config synchronization", () => {
|
|
|
155
198
|
config,
|
|
156
199
|
}),
|
|
157
200
|
{
|
|
158
|
-
initialProps: {
|
|
201
|
+
initialProps: {
|
|
202
|
+
config: {
|
|
203
|
+
configurable: {
|
|
204
|
+
model: "gpt-4",
|
|
205
|
+
settings: { temperature: 0.5 },
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
159
209
|
},
|
|
160
210
|
);
|
|
161
211
|
|
|
162
|
-
// Clear the initial calls
|
|
163
|
-
|
|
164
|
-
capturedUpdater = null;
|
|
165
|
-
|
|
166
|
-
// Change config
|
|
167
|
-
rerender({ config: { configurable: { model: "gpt-4o" } } });
|
|
168
|
-
|
|
169
|
-
// Should have called setCoagentStatesWithRef
|
|
170
|
-
expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
|
|
171
|
-
expect(capturedUpdater).toBeTruthy();
|
|
212
|
+
// Clear the initial calls
|
|
213
|
+
mockSetProperties.mockClear();
|
|
172
214
|
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
active: true,
|
|
181
|
-
threadId: "thread-123",
|
|
182
|
-
nodeName: "test-node",
|
|
183
|
-
runId: "run-456",
|
|
215
|
+
// Change nested config
|
|
216
|
+
rerender({
|
|
217
|
+
config: {
|
|
218
|
+
configurable: {
|
|
219
|
+
model: "gpt-4",
|
|
220
|
+
settings: { temperature: 0.7 }, // Only nested property changed
|
|
221
|
+
},
|
|
184
222
|
},
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const newState = capturedUpdater(prevState);
|
|
223
|
+
});
|
|
188
224
|
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
threadId: "thread-123",
|
|
198
|
-
nodeName: "test-node",
|
|
199
|
-
runId: "run-456",
|
|
200
|
-
},
|
|
225
|
+
// Wait for effect to complete and verify setProperties was called
|
|
226
|
+
await waitFor(() => {
|
|
227
|
+
expect(mockSetProperties).toHaveBeenCalledWith({
|
|
228
|
+
configurable: {
|
|
229
|
+
model: "gpt-4",
|
|
230
|
+
settings: { temperature: 0.7 },
|
|
231
|
+
},
|
|
232
|
+
});
|
|
201
233
|
});
|
|
202
234
|
});
|
|
203
235
|
|
|
204
|
-
|
|
205
|
-
|
|
236
|
+
describe("State Management", () => {
|
|
237
|
+
// Helper to create mock subscriber params
|
|
238
|
+
const createMockParams = (stateOverride: any = {}) => ({
|
|
239
|
+
messages: [],
|
|
240
|
+
state: stateOverride,
|
|
241
|
+
agent: mockAgent as any,
|
|
242
|
+
input: {} as any,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("should initialize agent state via onRunInitialized event", () => {
|
|
246
|
+
// Set agent to have NO state (empty object)
|
|
247
|
+
mockAgent.state = {} as any;
|
|
248
|
+
|
|
249
|
+
renderHook(() =>
|
|
250
|
+
useCoAgent({
|
|
251
|
+
name: "test-agent",
|
|
252
|
+
initialState: { count: 42 },
|
|
253
|
+
}),
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Verify subscription was created
|
|
257
|
+
expect(mockSubscribe).toHaveBeenCalled();
|
|
258
|
+
expect(lastSubscriber).toBeTruthy();
|
|
259
|
+
|
|
260
|
+
// Clear any initial state calls
|
|
261
|
+
mockSetState.mockClear();
|
|
262
|
+
|
|
263
|
+
// Trigger onRunInitialized with no run state
|
|
264
|
+
lastSubscriber?.onRunInitialized?.(createMockParams({}));
|
|
265
|
+
|
|
266
|
+
// Should set state to initialState
|
|
267
|
+
expect(mockSetState).toHaveBeenCalledWith({ count: 42 });
|
|
206
268
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return updater;
|
|
269
|
+
// Reset agent state
|
|
270
|
+
mockAgent.state = { count: 0 };
|
|
210
271
|
});
|
|
211
272
|
|
|
212
|
-
|
|
213
|
-
|
|
273
|
+
it("should preserve existing agent state on onRunInitialized", () => {
|
|
274
|
+
// Set agent to have existing state
|
|
275
|
+
mockAgent.state = { count: 100 };
|
|
276
|
+
|
|
277
|
+
renderHook(() =>
|
|
214
278
|
useCoAgent({
|
|
215
279
|
name: "test-agent",
|
|
216
|
-
initialState: { count:
|
|
217
|
-
config,
|
|
280
|
+
initialState: { count: 42 },
|
|
218
281
|
}),
|
|
219
|
-
|
|
220
|
-
initialProps: { config: { configurable: { model: "gpt-4" } } },
|
|
221
|
-
},
|
|
222
|
-
);
|
|
282
|
+
);
|
|
223
283
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
capturedUpdater = null;
|
|
284
|
+
// Clear any initial state calls
|
|
285
|
+
mockSetState.mockClear();
|
|
227
286
|
|
|
228
|
-
|
|
229
|
-
|
|
287
|
+
// Trigger onRunInitialized with no new state
|
|
288
|
+
lastSubscriber?.onRunInitialized?.(createMockParams({}));
|
|
289
|
+
|
|
290
|
+
// Should NOT override existing state
|
|
291
|
+
expect(mockSetState).not.toHaveBeenCalled();
|
|
292
|
+
|
|
293
|
+
// Reset agent state
|
|
294
|
+
mockAgent.state = { count: 0 };
|
|
295
|
+
});
|
|
230
296
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
297
|
+
it("should prioritize run state over initialState", () => {
|
|
298
|
+
renderHook(() =>
|
|
299
|
+
useCoAgent({
|
|
300
|
+
name: "test-agent",
|
|
301
|
+
initialState: { count: 42 },
|
|
302
|
+
}),
|
|
303
|
+
);
|
|
234
304
|
|
|
235
|
-
|
|
236
|
-
|
|
305
|
+
// Clear any initial state calls
|
|
306
|
+
mockSetState.mockClear();
|
|
237
307
|
|
|
238
|
-
|
|
308
|
+
// Trigger onRunInitialized with state from the run
|
|
309
|
+
lastSubscriber?.onRunInitialized?.(createMockParams({ count: 999 }));
|
|
239
310
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
"test-agent": {
|
|
243
|
-
name: "test-agent",
|
|
244
|
-
state: { count: 0 }, // Uses initialState
|
|
245
|
-
config: { configurable: { model: "gpt-4o" } }, // New config
|
|
246
|
-
running: false, // Default values
|
|
247
|
-
active: false,
|
|
248
|
-
threadId: undefined,
|
|
249
|
-
nodeName: undefined,
|
|
250
|
-
runId: undefined,
|
|
251
|
-
},
|
|
311
|
+
// Should use run state, not initialState
|
|
312
|
+
expect(mockSetState).toHaveBeenCalledWith({ count: 999 });
|
|
252
313
|
});
|
|
253
|
-
});
|
|
254
314
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
({ config }) =>
|
|
315
|
+
it("should handle setState with object updates", () => {
|
|
316
|
+
const { result } = renderHook(() =>
|
|
258
317
|
useCoAgent({
|
|
259
318
|
name: "test-agent",
|
|
260
319
|
initialState: { count: 0 },
|
|
261
|
-
config,
|
|
262
320
|
}),
|
|
263
|
-
|
|
264
|
-
initialProps: {
|
|
265
|
-
config: {
|
|
266
|
-
configurable: {
|
|
267
|
-
model: "gpt-4",
|
|
268
|
-
settings: { temperature: 0.5 },
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
);
|
|
321
|
+
);
|
|
274
322
|
|
|
275
|
-
|
|
276
|
-
|
|
323
|
+
// Update state with object
|
|
324
|
+
result.current.setState({ count: 5 });
|
|
277
325
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
config: {
|
|
281
|
-
configurable: {
|
|
282
|
-
model: "gpt-4",
|
|
283
|
-
settings: { temperature: 0.7 }, // Only nested property changed
|
|
284
|
-
},
|
|
285
|
-
},
|
|
326
|
+
// Should merge with existing state
|
|
327
|
+
expect(mockSetState).toHaveBeenCalledWith({ count: 5 });
|
|
286
328
|
});
|
|
287
329
|
|
|
288
|
-
|
|
289
|
-
|
|
330
|
+
it("should handle setState with function updaters", () => {
|
|
331
|
+
// Set current agent state
|
|
332
|
+
mockAgent.state = { count: 10 };
|
|
333
|
+
|
|
334
|
+
const { result } = renderHook(() =>
|
|
335
|
+
useCoAgent({
|
|
336
|
+
name: "test-agent",
|
|
337
|
+
initialState: { count: 0 },
|
|
338
|
+
}),
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
// Update state with function
|
|
342
|
+
result.current.setState((prev) => ({ count: (prev?.count || 0) + 5 }));
|
|
343
|
+
|
|
344
|
+
// Should call function with current state and set result
|
|
345
|
+
expect(mockSetState).toHaveBeenCalledWith({ count: 15 });
|
|
346
|
+
|
|
347
|
+
// Reset agent state
|
|
348
|
+
mockAgent.state = { count: 0 };
|
|
349
|
+
});
|
|
290
350
|
});
|
|
291
351
|
});
|