@copilotkit/react-core 0.0.0-fix-debug-infosys-20251107151227 → 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-RLR36R2Y.mjs → chunk-3V5TOYKW.mjs} +4 -4
- 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-3HEGBDUK.mjs → chunk-53K6WNJG.mjs} +8 -6
- package/dist/{chunk-3HEGBDUK.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-E6ER5C5U.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-GIGUZ2OK.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-BCZQ5BZB.mjs → chunk-FQFXYAV7.mjs} +6 -5
- package/dist/{chunk-BCZQ5BZB.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-FPOOU7AG.mjs → chunk-HE22TZMF.mjs} +10 -46
- 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-L3I57GMV.mjs → chunk-LHERIF3L.mjs} +4 -4
- 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-TUTNHDM3.mjs → chunk-YCG6SNAU.mjs} +5 -5
- package/dist/{chunk-3WUDRJTT.mjs → chunk-YTQHRJUA.mjs} +9 -11
- 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 +14 -12
- 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 +15 -12
- package/dist/components/dev-console/console-trigger.js +10 -8
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +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 +16 -12
- package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
- package/dist/components/toast/toast-provider.d.ts +3 -3
- package/dist/components/usage-banner.d.ts +2 -2
- package/dist/context/coagent-state-renders-context.d.ts +24 -0
- package/dist/context/coagent-state-renders-context.js +91 -0
- package/dist/context/coagent-state-renders-context.js.map +1 -0
- package/dist/context/coagent-state-renders-context.mjs +12 -0
- package/dist/context/coagent-state-renders-context.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +10 -8
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/copilot-messages-context.d.ts +18 -11
- package/dist/context/copilot-messages-context.js.map +1 -1
- package/dist/context/copilot-messages-context.mjs +1 -1
- package/dist/context/index.d.ts +6 -2
- package/dist/context/index.js +110 -10
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +22 -6
- 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 +82 -65
- 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-3MUCKQXM.mjs +0 -71
- package/dist/chunk-3MUCKQXM.mjs.map +0 -1
- package/dist/chunk-3WUDRJTT.mjs.map +0 -1
- package/dist/chunk-4I6ZMKGV.mjs +0 -723
- package/dist/chunk-4I6ZMKGV.mjs.map +0 -1
- package/dist/chunk-5FHSUKQL.mjs.map +0 -1
- package/dist/chunk-CUWOXXM5.mjs +0 -231
- package/dist/chunk-CUWOXXM5.mjs.map +0 -1
- package/dist/chunk-DZTU6PGS.mjs +0 -1
- package/dist/chunk-EUX2P2E7.mjs.map +0 -1
- package/dist/chunk-FPOOU7AG.mjs.map +0 -1
- package/dist/chunk-H4AHA2Y7.mjs +0 -22
- package/dist/chunk-H4AHA2Y7.mjs.map +0 -1
- package/dist/chunk-HDOG2RTM.mjs +0 -37
- package/dist/chunk-HDOG2RTM.mjs.map +0 -1
- package/dist/chunk-HI6SPUOX.mjs +0 -142
- package/dist/chunk-HI6SPUOX.mjs.map +0 -1
- package/dist/chunk-IN74FLIZ.mjs +0 -804
- package/dist/chunk-IN74FLIZ.mjs.map +0 -1
- package/dist/chunk-N4WEHORG.mjs.map +0 -1
- package/dist/chunk-R4Y45UGQ.mjs +0 -25
- package/dist/chunk-R4Y45UGQ.mjs.map +0 -1
- package/dist/chunk-RLR36R2Y.mjs.map +0 -1
- package/dist/chunk-W2UUH57V.mjs +0 -332
- package/dist/chunk-W2UUH57V.mjs.map +0 -1
- package/dist/chunk-X5GRTEAW.mjs +0 -13
- package/dist/chunk-X5GRTEAW.mjs.map +0 -1
- package/dist/chunk-YAV3YNFQ.mjs +0 -239
- package/dist/chunk-YAV3YNFQ.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-E6ER5C5U.mjs.map → chunk-BUSWSDYO.mjs.map} +0 -0
- /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
- /package/dist/{chunk-GIGUZ2OK.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-L3I57GMV.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
- /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
- /package/dist/{chunk-TUTNHDM3.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useRenderToolCall
|
|
3
|
+
} from "./chunk-NBK4KBLX.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useFrontendTool
|
|
6
|
+
} from "./chunk-CDUIA2WM.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useHumanInTheLoop
|
|
9
|
+
} from "./chunk-7DTB7S5V.mjs";
|
|
10
|
+
import {
|
|
11
|
+
__spreadProps,
|
|
12
|
+
__spreadValues
|
|
13
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
14
|
+
|
|
15
|
+
// src/hooks/use-copilot-action.ts
|
|
16
|
+
import { useState } from "react";
|
|
17
|
+
function getActionConfig(action) {
|
|
18
|
+
if (action.name === "*") {
|
|
19
|
+
return {
|
|
20
|
+
type: "render",
|
|
21
|
+
action
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
25
|
+
let render = action.render;
|
|
26
|
+
if (!render && "renderAndWaitForResponse" in action) {
|
|
27
|
+
render = action.renderAndWaitForResponse;
|
|
28
|
+
}
|
|
29
|
+
if (!render && "renderAndWait" in action) {
|
|
30
|
+
render = action.renderAndWait;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
type: "hitl",
|
|
34
|
+
action: __spreadProps(__spreadValues({}, action), { render })
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if ("available" in action) {
|
|
38
|
+
if (action.available === "enabled" || action.available === "remote") {
|
|
39
|
+
return {
|
|
40
|
+
type: "frontend",
|
|
41
|
+
action
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (action.available === "frontend" || action.available === "disabled") {
|
|
45
|
+
return {
|
|
46
|
+
type: "render",
|
|
47
|
+
action
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if ("handler" in action) {
|
|
52
|
+
return {
|
|
53
|
+
type: "frontend",
|
|
54
|
+
action
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
throw new Error("Invalid action configuration");
|
|
58
|
+
}
|
|
59
|
+
function useCopilotAction(action, dependencies) {
|
|
60
|
+
const [initialActionConfig] = useState(getActionConfig(action));
|
|
61
|
+
const currentActionConfig = getActionConfig(action);
|
|
62
|
+
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
63
|
+
throw new Error("Action configuration changed between renders");
|
|
64
|
+
}
|
|
65
|
+
switch (currentActionConfig.type) {
|
|
66
|
+
case "render":
|
|
67
|
+
return useRenderToolCall(currentActionConfig.action, dependencies);
|
|
68
|
+
case "hitl":
|
|
69
|
+
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
70
|
+
case "frontend":
|
|
71
|
+
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
72
|
+
default:
|
|
73
|
+
throw new Error("Invalid action configuration");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
useCopilotAction
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chunk-GPEJNVE5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-copilot-action.ts"],"sourcesContent":["/**\n * Example usage of useCopilotAction with complex parameters:\n *\n * @example\n * useCopilotAction({\n * name: \"myAction\",\n * parameters: [\n * { name: \"arg1\", type: \"string\", enum: [\"option1\", \"option2\", \"option3\"], required: false },\n * { name: \"arg2\", type: \"number\" },\n * {\n * name: \"arg3\",\n * type: \"object\",\n * attributes: [\n * { name: \"nestedArg1\", type: \"boolean\" },\n * { name: \"xyz\", required: false },\n * ],\n * },\n * { name: \"arg4\", type: \"number[]\" },\n * ],\n * handler: ({ arg1, arg2, arg3, arg4 }) => {\n * const x = arg3.nestedArg1;\n * const z = arg3.xyz;\n * console.log(arg1, arg2, arg3);\n * },\n * });\n *\n * @example\n * // Simple action without parameters\n * useCopilotAction({\n * name: \"myAction\",\n * handler: () => {\n * console.log(\"No parameters provided.\");\n * },\n * });\n *\n * @example\n * // Interactive action with UI rendering and response handling\n * useCopilotAction({\n * name: \"handleMeeting\",\n * description: \"Handle a meeting by booking or canceling\",\n * parameters: [\n * {\n * name: \"meeting\",\n * type: \"string\",\n * description: \"The meeting to handle\",\n * required: true,\n * },\n * {\n * name: \"date\",\n * type: \"string\",\n * description: \"The date of the meeting\",\n * required: true,\n * },\n * {\n * name: \"title\",\n * type: \"string\",\n * description: \"The title of the meeting\",\n * required: true,\n * },\n * ],\n * renderAndWaitForResponse: ({ args, respond, status }) => {\n * const { meeting, date, title } = args;\n * return (\n * <MeetingConfirmationDialog\n * meeting={meeting}\n * date={date}\n * title={title}\n * onConfirm={() => respond('meeting confirmed')}\n * onCancel={() => respond('meeting canceled')}\n * />\n * );\n * },\n * });\n *\n * @example\n * // Catch all action allows you to render actions that are not defined in the frontend\n * useCopilotAction({\n * name: \"*\",\n * render: ({ name, args, status, result, handler, respond }) => {\n * return <div>Rendering action: {name}</div>;\n * },\n * });\n */\n\n/**\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-action/useCopilotAction.gif\" width=\"500\" />\n * `useCopilotAction` is a React hook that you can use in your application to provide\n * custom actions that can be called by the AI. Essentially, it allows the Copilot to\n * execute these actions contextually during a chat, based on the user's interactions\n * and needs.\n *\n * Here's how it works:\n *\n * Use `useCopilotAction` to set up actions that the Copilot can call. To provide\n * more context to the Copilot, you can provide it with a `description` (for example to explain\n * what the action does, under which conditions it can be called, etc.).\n *\n * Then you define the parameters of the action, which can be simple, e.g. primitives like strings or numbers,\n * or complex, e.g. objects or arrays.\n *\n * Finally, you provide a `handler` function that receives the parameters and returns a result.\n * CopilotKit takes care of automatically inferring the parameter types, so you get type safety\n * and autocompletion for free.\n *\n * To render a custom UI for the action, you can provide a `render()` function. This function\n * lets you render a custom component or return a string to display.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * useCopilotAction({\n * name: \"sayHello\",\n * description: \"Say hello to someone.\",\n * parameters: [\n * {\n * name: \"name\",\n * type: \"string\",\n * description: \"name of the person to say greet\",\n * },\n * ],\n * handler: async ({ name }) => {\n * alert(`Hello, ${name}!`);\n * },\n * });\n * ```\n *\n * ## Generative UI\n *\n * This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.\n */\nimport { useEffect, useRef, useState } from \"react\";\nimport { Parameter } from \"@copilotkit/shared\";\nimport { CatchAllFrontendAction, FrontendAction } from \"../types/frontend-action\";\nimport { useFrontendTool, UseFrontendToolArgs } from \"./use-frontend-tool\";\nimport { useRenderToolCall, UseRenderToolCallArgs } from \"./use-render-tool-call\";\nimport { useHumanInTheLoop, UseHumanInTheLoopArgs } from \"./use-human-in-the-loop\";\nimport { useCopilotContext } from \"../context\";\n\n// Helper to determine which component and action config to use\nfunction getActionConfig<const T extends Parameter[] | [] = []>(\n action: FrontendAction<T> | CatchAllFrontendAction,\n) {\n if (action.name === \"*\") {\n return {\n type: \"render\" as const,\n action: action as UseRenderToolCallArgs<T>,\n };\n }\n\n if (\"renderAndWaitForResponse\" in action || \"renderAndWait\" in action) {\n let render = action.render;\n if (!render && \"renderAndWaitForResponse\" in action) {\n // @ts-expect-error -- renderAndWaitForResponse is deprecated, but we need to support it for backwards compatibility\n render = action.renderAndWaitForResponse;\n }\n if (!render && \"renderAndWait\" in action) {\n // @ts-expect-error -- renderAndWait is deprecated, but we need to support it for backwards compatibility\n render = action.renderAndWait;\n }\n\n return {\n type: \"hitl\" as const,\n action: { ...action, render } as UseHumanInTheLoopArgs<T>,\n };\n }\n\n if (\"available\" in action) {\n if (action.available === \"enabled\" || action.available === \"remote\") {\n return {\n type: \"frontend\" as const,\n action: action as UseFrontendToolArgs<T>,\n };\n }\n if (action.available === \"frontend\" || action.available === \"disabled\") {\n return {\n type: \"render\" as const,\n action: action as UseRenderToolCallArgs<T>,\n };\n }\n }\n\n if (\"handler\" in action) {\n return {\n type: \"frontend\" as const,\n action: action as UseFrontendToolArgs<T>,\n };\n }\n\n throw new Error(\"Invalid action configuration\");\n}\n\n/**\n * useCopilotAction is a legacy hook maintained for backwards compatibility.\n *\n * To avoid violating React's Rules of Hooks (which prohibit conditional hook calls),\n * we use a registration pattern:\n * 1. This hook registers the action configuration with the CopilotContext\n * 2. A renderer component in CopilotKit actually renders the appropriate hook wrapper\n * 3. React properly manages hook state since components are rendered, not conditionally called\n *\n * This allows action types to change between renders without corrupting React's hook state.\n */\nexport function useCopilotAction<const T extends Parameter[] | [] = []>(\n action: FrontendAction<T> | CatchAllFrontendAction,\n dependencies?: any[],\n): void {\n const [initialActionConfig] = useState(getActionConfig(action));\n const currentActionConfig = getActionConfig(action);\n\n /**\n * Calling hooks conditionally violates React's Rules of Hooks. This rule exists because\n * React maintains the call stack for hooks like useEffect or useState, and conditionally\n * calling a hook would result in inconsistent call stacks between renders.\n *\n * Unfortunately, useCopilotAction _has_ to conditionally call a hook based on the\n * supplied parameters. In order to avoid breaking React's call stack tracking, while\n * breaking the Rule of Hooks, we use a ref to store the initial action configuration\n * and throw an error if the _configuration_ changes such that we would call a different hook.\n */\n if (initialActionConfig.type !== currentActionConfig.type) {\n throw new Error(\"Action configuration changed between renders\");\n }\n\n switch (currentActionConfig.type) {\n case \"render\":\n return useRenderToolCall(currentActionConfig.action, dependencies);\n case \"hitl\":\n return useHumanInTheLoop(currentActionConfig.action, dependencies);\n case \"frontend\":\n return useFrontendTool(currentActionConfig.action, dependencies);\n default:\n throw new Error(\"Invalid action configuration\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoIA,SAA4B,gBAAgB;AAS5C,SAAS,gBACP,QACA;AACA,MAAI,OAAO,SAAS,KAAK;AACvB,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF;AA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
3
|
} from "./chunk-ICIK2BSB.mjs";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
useToast
|
|
6
|
+
} from "./chunk-EFL5OBKN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
useCopilotContext
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
CopilotMessagesContext
|
|
12
|
+
} from "./chunk-DMLQZG75.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__async
|
|
15
15
|
} from "./chunk-SKC7AJIV.mjs";
|
|
@@ -24,9 +24,6 @@ import {
|
|
|
24
24
|
createContext,
|
|
25
25
|
useContext
|
|
26
26
|
} from "react";
|
|
27
|
-
import {
|
|
28
|
-
loadMessagesFromJsonRepresentation
|
|
29
|
-
} from "@copilotkit/runtime-client-gql";
|
|
30
27
|
import {
|
|
31
28
|
ErrorVisibility,
|
|
32
29
|
CopilotKitApiDiscoveryError,
|
|
@@ -55,11 +52,11 @@ function MessagesTapProvider({ children }) {
|
|
|
55
52
|
}
|
|
56
53
|
function CopilotMessages({ children }) {
|
|
57
54
|
const [messages, setMessages] = useState([]);
|
|
58
|
-
const lastLoadedThreadId = useRef();
|
|
59
|
-
const lastLoadedAgentName = useRef();
|
|
60
|
-
const lastLoadedMessages = useRef();
|
|
55
|
+
const lastLoadedThreadId = useRef(void 0);
|
|
56
|
+
const lastLoadedAgentName = useRef(void 0);
|
|
57
|
+
const lastLoadedMessages = useRef(void 0);
|
|
61
58
|
const { updateTapMessages } = useMessagesTap();
|
|
62
|
-
const { threadId, agentSession,
|
|
59
|
+
const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
|
|
63
60
|
const { setBannerError } = useToast();
|
|
64
61
|
const traceUIError = useCallback(
|
|
65
62
|
(error, originalError) => __async(this, null, function* () {
|
|
@@ -162,39 +159,6 @@ function CopilotMessages({ children }) {
|
|
|
162
159
|
},
|
|
163
160
|
[setBannerError, showDevConsole, traceUIError]
|
|
164
161
|
);
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
167
|
-
return;
|
|
168
|
-
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const fetchMessages = () => __async(this, null, function* () {
|
|
172
|
-
var _a, _b, _c;
|
|
173
|
-
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
174
|
-
return;
|
|
175
|
-
const result = yield runtimeClient.loadAgentState({
|
|
176
|
-
threadId,
|
|
177
|
-
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
178
|
-
});
|
|
179
|
-
if (result.error) {
|
|
180
|
-
lastLoadedThreadId.current = threadId;
|
|
181
|
-
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
182
|
-
handleGraphQLErrors(result.error);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
186
|
-
if (newMessages === lastLoadedMessages.current)
|
|
187
|
-
return;
|
|
188
|
-
if ((_c = result.data) == null ? void 0 : _c.loadAgentState) {
|
|
189
|
-
lastLoadedMessages.current = newMessages;
|
|
190
|
-
lastLoadedThreadId.current = threadId;
|
|
191
|
-
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
192
|
-
const messages2 = loadMessagesFromJsonRepresentation(JSON.parse(newMessages || "[]"));
|
|
193
|
-
setMessages(messages2);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
void fetchMessages();
|
|
197
|
-
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
198
162
|
useEffect(() => {
|
|
199
163
|
updateTapMessages(messages);
|
|
200
164
|
}, [messages, updateTapMessages]);
|
|
@@ -219,4 +183,4 @@ export {
|
|
|
219
183
|
MessagesTapProvider,
|
|
220
184
|
CopilotMessages
|
|
221
185
|
};
|
|
222
|
-
//# sourceMappingURL=chunk-
|
|
186
|
+
//# sourceMappingURL=chunk-HE22TZMF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-provider/copilot-messages.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport {\n ReactNode,\n useEffect,\n useState,\n useRef,\n useCallback,\n useMemo,\n createContext,\n useContext,\n} from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport {\n loadMessagesFromJsonRepresentation,\n Message,\n GraphQLError,\n} from \"@copilotkit/runtime-client-gql\";\nimport { useCopilotContext } from \"../../context/copilot-context\";\nimport { useToast } from \"../toast/toast-provider\";\nimport { shouldShowDevConsole } from \"../../utils/dev-console\";\nimport {\n ErrorVisibility,\n CopilotKitApiDiscoveryError,\n CopilotKitRemoteEndpointDiscoveryError,\n CopilotKitAgentDiscoveryError,\n CopilotKitError,\n CopilotKitErrorCode,\n} from \"@copilotkit/shared\";\nimport { Suggestion } from \"@copilotkitnext/core\";\n\n// Helper to determine if error should show as banner based on visibility and legacy patterns\nfunction shouldShowAsBanner(gqlError: GraphQLError): boolean {\n const extensions = gqlError.extensions;\n if (!extensions) return false;\n\n // Priority 1: Check error code for discovery errors (these should always be banners)\n const code = extensions.code as CopilotKitErrorCode;\n if (\n code === CopilotKitErrorCode.AGENT_NOT_FOUND ||\n code === CopilotKitErrorCode.API_NOT_FOUND ||\n code === CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND ||\n code === CopilotKitErrorCode.CONFIGURATION_ERROR ||\n code === CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR ||\n code === CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR\n ) {\n return true;\n }\n\n // Priority 2: Check banner visibility\n if (extensions.visibility === ErrorVisibility.BANNER) {\n return true;\n }\n\n // Priority 3: Check for critical errors that should be banners regardless of formal classification\n const errorMessage = gqlError.message.toLowerCase();\n if (\n errorMessage.includes(\"api key\") ||\n errorMessage.includes(\"401\") ||\n errorMessage.includes(\"unauthorized\") ||\n errorMessage.includes(\"authentication\") ||\n errorMessage.includes(\"incorrect api key\")\n ) {\n return true;\n }\n\n // Priority 4: Legacy stack trace detection for discovery errors\n const originalError = extensions.originalError as any;\n if (originalError?.stack) {\n return (\n originalError.stack.includes(\"CopilotApiDiscoveryError\") ||\n originalError.stack.includes(\"CopilotKitRemoteEndpointDiscoveryError\") ||\n originalError.stack.includes(\"CopilotKitAgentDiscoveryError\")\n );\n }\n\n return false;\n}\n\n/**\n * MessagesTap is used to mitigate performance issues when we only need\n * a snapshot of the messages, not a continuously updating stream of messages.\n */\n\nexport type MessagesTap = {\n getMessagesFromTap: () => Message[];\n updateTapMessages: (messages: Message[]) => void;\n};\n\nconst MessagesTapContext = createContext<MessagesTap | null>(null);\n\nexport function useMessagesTap() {\n const tap = useContext(MessagesTapContext);\n if (!tap) throw new Error(\"useMessagesTap must be used inside <MessagesTapProvider>\");\n return tap;\n}\n\nexport function MessagesTapProvider({ children }: { children: React.ReactNode }) {\n const messagesRef = useRef<Message[]>([]);\n\n const tapRef = useRef<MessagesTap>({\n getMessagesFromTap: () => messagesRef.current,\n updateTapMessages: (messages: Message[]) => {\n messagesRef.current = messages;\n },\n });\n\n return (\n <MessagesTapContext.Provider value={tapRef.current}>{children}</MessagesTapContext.Provider>\n );\n}\n\n/**\n * CopilotKit messages context.\n */\n\nexport function CopilotMessages({ children }: { children: ReactNode }) {\n const [messages, setMessages] = useState<Message[]>([]);\n const lastLoadedThreadId = useRef<string>(undefined!);\n const lastLoadedAgentName = useRef<string>(undefined!);\n const lastLoadedMessages = useRef<string>(undefined!);\n\n const { updateTapMessages } = useMessagesTap();\n\n const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();\n const { setBannerError } = useToast();\n\n // Helper function to trace UI errors (similar to useCopilotRuntimeClient)\n const traceUIError = useCallback(\n async (error: CopilotKitError, originalError?: any) => {\n // Just check if onError and publicApiKey are defined\n if (!onError || !copilotApiConfig.publicApiKey) return;\n\n try {\n const traceEvent = {\n type: \"error\" as const,\n timestamp: Date.now(),\n context: {\n source: \"ui\" as const,\n request: {\n operation: \"loadAgentState\",\n url: copilotApiConfig.chatApiEndpoint,\n startTime: Date.now(),\n },\n technical: {\n environment: \"browser\",\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n stackTrace: originalError instanceof Error ? originalError.stack : undefined,\n },\n },\n error,\n };\n await onError(traceEvent);\n } catch (traceError) {\n console.error(\"Error in CopilotMessages onError handler:\", traceError);\n }\n },\n [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint],\n );\n\n const createStructuredError = (gqlError: GraphQLError): CopilotKitError | null => {\n const extensions = gqlError.extensions;\n const originalError = extensions?.originalError as any;\n\n // Priority: Check stack trace for discovery errors first\n if (originalError?.stack) {\n if (originalError.stack.includes(\"CopilotApiDiscoveryError\")) {\n return new CopilotKitApiDiscoveryError({ message: originalError.message });\n }\n if (originalError.stack.includes(\"CopilotKitRemoteEndpointDiscoveryError\")) {\n return new CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });\n }\n if (originalError.stack.includes(\"CopilotKitAgentDiscoveryError\")) {\n return new CopilotKitAgentDiscoveryError({\n agentName: \"\",\n availableAgents: [],\n });\n }\n }\n\n // Fallback: Use the formal error code if available\n const message = originalError?.message || gqlError.message;\n const code = extensions?.code as CopilotKitErrorCode;\n\n if (code) {\n return new CopilotKitError({ message, code });\n }\n\n return null;\n };\n\n const handleGraphQLErrors = useCallback(\n (error: any) => {\n if (error.graphQLErrors?.length) {\n const graphQLErrors = error.graphQLErrors as GraphQLError[];\n\n // Route all errors to banners for consistent UI\n const routeError = (gqlError: GraphQLError) => {\n const extensions = gqlError.extensions;\n const visibility = extensions?.visibility as ErrorVisibility;\n const isDev = shouldShowDevConsole(showDevConsole);\n\n if (!isDev) {\n console.error(\"CopilotKit Error (hidden in production):\", gqlError.message);\n return;\n }\n\n // Silent errors - just log\n if (visibility === ErrorVisibility.SILENT) {\n console.error(\"CopilotKit Silent Error:\", gqlError.message);\n return;\n }\n\n // All other errors (including DEV_ONLY) show as banners for consistency\n const ckError = createStructuredError(gqlError);\n if (ckError) {\n setBannerError(ckError);\n // Trace the structured error\n traceUIError(ckError, gqlError);\n } else {\n // Fallback: create a generic error for unstructured GraphQL errors\n const fallbackError = new CopilotKitError({\n message: gqlError.message,\n code: CopilotKitErrorCode.UNKNOWN,\n });\n setBannerError(fallbackError);\n // Trace the fallback error\n traceUIError(fallbackError, gqlError);\n }\n };\n\n // Process all errors as banners\n graphQLErrors.forEach(routeError);\n } else {\n const isDev = shouldShowDevConsole(showDevConsole);\n if (!isDev) {\n console.error(\"CopilotKit Error (hidden in production):\", error);\n } else {\n // Route non-GraphQL errors to banner as well\n const fallbackError = new CopilotKitError({\n message: error?.message || String(error),\n code: CopilotKitErrorCode.UNKNOWN,\n });\n setBannerError(fallbackError);\n // Trace the non-GraphQL error\n traceUIError(fallbackError, error);\n }\n }\n },\n [setBannerError, showDevConsole, traceUIError],\n );\n\n useEffect(() => {\n updateTapMessages(messages);\n }, [messages, updateTapMessages]);\n\n const memoizedChildren = useMemo(() => children, [children]);\n const [suggestions, setSuggestions] = useState<Suggestion[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n suggestions,\n setSuggestions,\n }}\n >\n {memoizedChildren}\n </CopilotMessagesContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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import { useEffect, useRef } from "react";
|
|
3
|
+
import { useAgent } from "@copilotkitnext/react";
|
|
4
|
+
function useAgentNodeName(agentName) {
|
|
5
|
+
const { agent } = useAgent({ agentId: agentName });
|
|
6
|
+
const nodeNameRef = useRef("start");
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!agent)
|
|
9
|
+
return;
|
|
10
|
+
const subscriber = {
|
|
11
|
+
onStepStartedEvent: ({ event }) => {
|
|
12
|
+
nodeNameRef.current = event.stepName;
|
|
13
|
+
},
|
|
14
|
+
onRunStartedEvent: () => {
|
|
15
|
+
nodeNameRef.current = "start";
|
|
16
|
+
},
|
|
17
|
+
onRunFinishedEvent: () => {
|
|
18
|
+
nodeNameRef.current = "end";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const subscription = agent.subscribe(subscriber);
|
|
22
|
+
return () => {
|
|
23
|
+
subscription.unsubscribe();
|
|
24
|
+
};
|
|
25
|
+
}, [agent]);
|
|
26
|
+
return nodeNameRef.current;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
useAgentNodeName
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=chunk-I76HKHPJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-agent-nodename.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport type { AgentSubscriber } from \"@ag-ui/client\";\nimport { useAgent } from \"@copilotkitnext/react\";\n\nexport function useAgentNodeName(agentName?: string) {\n const { agent } = useAgent({ agentId: agentName });\n const nodeNameRef = useRef<string>(\"start\");\n\n useEffect(() => {\n if (!agent) return;\n const subscriber: AgentSubscriber = {\n onStepStartedEvent: ({ event }) => {\n nodeNameRef.current = event.stepName;\n },\n onRunStartedEvent: () => {\n nodeNameRef.current = \"start\";\n },\n onRunFinishedEvent: () => {\n nodeNameRef.current = \"end\";\n },\n };\n\n const subscription = agent.subscribe(subscriber);\n return () => {\n subscription.unsubscribe();\n };\n }, [agent]);\n\n return nodeNameRef.current;\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAElC,SAAS,gBAAgB;AAElB,SAAS,iBAAiB,WAAoB;AACnD,QAAM,EAAE,MAAM,IAAI,SAAS,EAAE,SAAS,UAAU,CAAC;AACjD,QAAM,cAAc,OAAe,OAAO;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC;AAAO;AACZ,UAAM,aAA8B;AAAA,MAClC,oBAAoB,CAAC,EAAE,MAAM,MAAM;AACjC,oBAAY,UAAU,MAAM;AAAA,MAC9B;AAAA,MACA,mBAAmB,MAAM;AACvB,oBAAY,UAAU;AAAA,MACxB;AAAA,MACA,oBAAoB,MAAM;AACxB,oBAAY,UAAU;AAAA,MACxB;AAAA,IACF;AAEA,UAAM,eAAe,MAAM,UAAU,UAAU;AAC/C,WAAO,MAAM;AACX,mBAAa,YAAY;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO,YAAY;AACrB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-JD7BAH7U.mjs.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StatusChecker
|
|
3
3
|
} from "./chunk-PMAFHQ7P.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useErrorToast
|
|
6
|
+
} from "./chunk-6PUNP7CD.mjs";
|
|
4
7
|
import {
|
|
5
8
|
UsageBanner,
|
|
6
9
|
getErrorActions
|
|
7
10
|
} from "./chunk-6ZLPNY7X.mjs";
|
|
8
|
-
import {
|
|
9
|
-
useErrorToast
|
|
10
|
-
} from "./chunk-N4WEHORG.mjs";
|
|
11
11
|
|
|
12
12
|
// src/components/error-boundary/error-boundary.tsx
|
|
13
13
|
import React, { useEffect } from "react";
|
|
@@ -80,4 +80,4 @@ export {
|
|
|
80
80
|
CopilotErrorBoundary,
|
|
81
81
|
ErrorToast
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-LHERIF3L.mjs.map
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useLangGraphInterruptRender
|
|
3
|
+
} from "./chunk-VV56AVPB.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useLazyToolRenderer
|
|
6
|
+
} from "./chunk-ZVF5Q6IH.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useAsyncCallback
|
|
9
|
+
} from "./chunk-6PUNP7CD.mjs";
|
|
10
|
+
import {
|
|
11
|
+
CoAgentStateRenderBridge
|
|
12
|
+
} from "./chunk-QNUAXSDP.mjs";
|
|
13
|
+
import {
|
|
14
|
+
useCopilotContext
|
|
15
|
+
} from "./chunk-AFNWX62Q.mjs";
|
|
16
|
+
import {
|
|
17
|
+
__async,
|
|
18
|
+
__spreadProps,
|
|
19
|
+
__spreadValues
|
|
20
|
+
} from "./chunk-SKC7AJIV.mjs";
|
|
21
|
+
|
|
22
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
23
|
+
import { useRef, useEffect, useCallback, useMemo, useState, createElement } from "react";
|
|
24
|
+
import { gqlToAGUI, Message as DeprecatedGqlMessage } from "@copilotkit/runtime-client-gql";
|
|
25
|
+
import {
|
|
26
|
+
useAgent,
|
|
27
|
+
useCopilotChatConfiguration,
|
|
28
|
+
useCopilotKit,
|
|
29
|
+
useRenderCustomMessages,
|
|
30
|
+
useSuggestions
|
|
31
|
+
} from "@copilotkitnext/react";
|
|
32
|
+
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
33
|
+
function useCopilotChatInternal({
|
|
34
|
+
suggestions,
|
|
35
|
+
onInProgress,
|
|
36
|
+
onSubmitMessage,
|
|
37
|
+
onStopGeneration,
|
|
38
|
+
onReloadMessages
|
|
39
|
+
} = {}) {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
const { copilotkit } = useCopilotKit();
|
|
42
|
+
const { threadId, agentSession } = useCopilotContext();
|
|
43
|
+
const existingConfig = useCopilotChatConfiguration();
|
|
44
|
+
const [agentAvailable, setAgentAvailable] = useState(false);
|
|
45
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
46
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const connect = (agent2) => __async(this, null, function* () {
|
|
49
|
+
setAgentAvailable(false);
|
|
50
|
+
try {
|
|
51
|
+
yield copilotkit.connectAgent({ agent: agent2 });
|
|
52
|
+
setAgentAvailable(true);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof AGUIConnectNotImplementedError) {
|
|
55
|
+
} else {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
61
|
+
agent.threadId = existingConfig.threadId;
|
|
62
|
+
connect(agent);
|
|
63
|
+
}
|
|
64
|
+
return () => {
|
|
65
|
+
};
|
|
66
|
+
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
onInProgress == null ? void 0 : onInProgress(Boolean(agent == null ? void 0 : agent.isRunning));
|
|
69
|
+
}, [agent == null ? void 0 : agent.isRunning, onInProgress]);
|
|
70
|
+
const interrupt = useLangGraphInterruptRender(agent);
|
|
71
|
+
const reset = () => {
|
|
72
|
+
agent == null ? void 0 : agent.setMessages([]);
|
|
73
|
+
agent == null ? void 0 : agent.setState(null);
|
|
74
|
+
};
|
|
75
|
+
const deleteMessage = useCallback(
|
|
76
|
+
(messageId) => {
|
|
77
|
+
var _a2;
|
|
78
|
+
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
79
|
+
(message) => message.id !== messageId
|
|
80
|
+
);
|
|
81
|
+
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
82
|
+
},
|
|
83
|
+
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
84
|
+
);
|
|
85
|
+
const latestDelete = useUpdatedRef(deleteMessage);
|
|
86
|
+
const latestDeleteFunc = useCallback(
|
|
87
|
+
(messageId) => {
|
|
88
|
+
return latestDelete.current(messageId);
|
|
89
|
+
},
|
|
90
|
+
[latestDelete]
|
|
91
|
+
);
|
|
92
|
+
const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });
|
|
93
|
+
const reload = useAsyncCallback(
|
|
94
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
95
|
+
var _a2;
|
|
96
|
+
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
97
|
+
const isLoading = false;
|
|
98
|
+
if (isLoading || messages.length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
102
|
+
if (reloadMessageIndex === -1) {
|
|
103
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
107
|
+
if (reloadMessageRole !== "assistant") {
|
|
108
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
let historyCutoff = [messages[0]];
|
|
112
|
+
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
113
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
114
|
+
if (!lastUserMessageBeforeRegenerate) {
|
|
115
|
+
historyCutoff = [messages[0]];
|
|
116
|
+
} else {
|
|
117
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
118
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
119
|
+
);
|
|
120
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
121
|
+
}
|
|
122
|
+
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
123
|
+
historyCutoff = [messages[0], messages[1]];
|
|
124
|
+
}
|
|
125
|
+
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
126
|
+
if (agent) {
|
|
127
|
+
copilotkit.runAgent({ agent });
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}),
|
|
131
|
+
[agent == null ? void 0 : agent.setMessages, copilotkit == null ? void 0 : copilotkit.runAgent]
|
|
132
|
+
);
|
|
133
|
+
const latestSendMessageFunc = useAsyncCallback(
|
|
134
|
+
(message, options) => __async(this, null, function* () {
|
|
135
|
+
var _a2;
|
|
136
|
+
if (!agent)
|
|
137
|
+
return;
|
|
138
|
+
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
139
|
+
if (options == null ? void 0 : options.clearSuggestions) {
|
|
140
|
+
copilotkit.clearSuggestions(resolvedAgentId);
|
|
141
|
+
}
|
|
142
|
+
agent == null ? void 0 : agent.addMessage(message);
|
|
143
|
+
if (followUp) {
|
|
144
|
+
try {
|
|
145
|
+
yield copilotkit.runAgent({ agent });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error("CopilotChat: runAgent failed", error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (onSubmitMessage) {
|
|
151
|
+
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 : "";
|
|
152
|
+
onSubmitMessage(content);
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
[agent, copilotkit, resolvedAgentId, onSubmitMessage]
|
|
156
|
+
);
|
|
157
|
+
const latestAppendFunc = useAsyncCallback(
|
|
158
|
+
(message, options) => __async(this, null, function* () {
|
|
159
|
+
return latestSendMessageFunc(gqlToAGUI([message])[0], options);
|
|
160
|
+
}),
|
|
161
|
+
[latestSendMessageFunc]
|
|
162
|
+
);
|
|
163
|
+
const latestSetMessagesFunc = useCallback(
|
|
164
|
+
(messages) => {
|
|
165
|
+
var _a2, _b2;
|
|
166
|
+
if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {
|
|
167
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, gqlToAGUI(messages));
|
|
168
|
+
}
|
|
169
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
170
|
+
},
|
|
171
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
172
|
+
);
|
|
173
|
+
const latestReload = useUpdatedRef(reload);
|
|
174
|
+
const latestReloadFunc = useAsyncCallback(
|
|
175
|
+
(messageId) => __async(this, null, function* () {
|
|
176
|
+
var _a2;
|
|
177
|
+
onReloadMessages == null ? void 0 : onReloadMessages({
|
|
178
|
+
messageId,
|
|
179
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
180
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
181
|
+
});
|
|
182
|
+
return yield latestReload.current(messageId);
|
|
183
|
+
}),
|
|
184
|
+
[latestReload, agent, onReloadMessages]
|
|
185
|
+
);
|
|
186
|
+
const latestStopFunc = useCallback(() => {
|
|
187
|
+
var _a2, _b2;
|
|
188
|
+
onStopGeneration == null ? void 0 : onStopGeneration({
|
|
189
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
190
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
191
|
+
});
|
|
192
|
+
return (_b2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _b2.call(agent);
|
|
193
|
+
}, [onStopGeneration, agent]);
|
|
194
|
+
const latestReset = useUpdatedRef(reset);
|
|
195
|
+
const latestResetFunc = useCallback(() => {
|
|
196
|
+
return latestReset.current();
|
|
197
|
+
}, [latestReset]);
|
|
198
|
+
const lazyToolRendered = useLazyToolRenderer();
|
|
199
|
+
const renderCustomMessage = useRenderCustomMessages();
|
|
200
|
+
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
201
|
+
copilotkit,
|
|
202
|
+
agent,
|
|
203
|
+
agentId: resolvedAgentId,
|
|
204
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
205
|
+
});
|
|
206
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
207
|
+
const resolvedMessages = useMemo(() => {
|
|
208
|
+
let processedMessages = allMessages.map((message) => {
|
|
209
|
+
if (message.role !== "assistant") {
|
|
210
|
+
return message;
|
|
211
|
+
}
|
|
212
|
+
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
213
|
+
if (lazyRendered) {
|
|
214
|
+
const renderedGenUi = lazyRendered();
|
|
215
|
+
if (renderedGenUi) {
|
|
216
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
220
|
+
const customRender = renderCustomMessage == null ? void 0 : renderCustomMessage({
|
|
221
|
+
message,
|
|
222
|
+
position: "before"
|
|
223
|
+
});
|
|
224
|
+
if (customRender) {
|
|
225
|
+
return customRender;
|
|
226
|
+
}
|
|
227
|
+
return legacyCustomMessageRenderer == null ? void 0 : legacyCustomMessageRenderer({ message, position: "before" });
|
|
228
|
+
} : null;
|
|
229
|
+
if (bridgeRenderer) {
|
|
230
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: bridgeRenderer });
|
|
231
|
+
}
|
|
232
|
+
return message;
|
|
233
|
+
});
|
|
234
|
+
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
235
|
+
return processedMessages;
|
|
236
|
+
}, [
|
|
237
|
+
agent == null ? void 0 : agent.messages,
|
|
238
|
+
lazyToolRendered,
|
|
239
|
+
allMessages,
|
|
240
|
+
renderCustomMessage,
|
|
241
|
+
// legacyCustomMessageRenderer,
|
|
242
|
+
resolvedAgentId
|
|
243
|
+
]);
|
|
244
|
+
const renderedSuggestions = useMemo(() => {
|
|
245
|
+
if (Array.isArray(suggestions)) {
|
|
246
|
+
return {
|
|
247
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
248
|
+
isLoading: false
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return currentSuggestions;
|
|
252
|
+
}, [suggestions, currentSuggestions]);
|
|
253
|
+
return {
|
|
254
|
+
messages: resolvedMessages,
|
|
255
|
+
sendMessage: latestSendMessageFunc,
|
|
256
|
+
appendMessage: latestAppendFunc,
|
|
257
|
+
setMessages: latestSetMessagesFunc,
|
|
258
|
+
reloadMessages: latestReloadFunc,
|
|
259
|
+
stopGeneration: latestStopFunc,
|
|
260
|
+
reset: latestResetFunc,
|
|
261
|
+
deleteMessage: latestDeleteFunc,
|
|
262
|
+
isAvailable: agentAvailable,
|
|
263
|
+
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
264
|
+
// mcpServers,
|
|
265
|
+
// setMcpServers,
|
|
266
|
+
suggestions: renderedSuggestions.suggestions,
|
|
267
|
+
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
268
|
+
generateSuggestions: () => __async(this, null, function* () {
|
|
269
|
+
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
270
|
+
}),
|
|
271
|
+
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
272
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
273
|
+
interrupt,
|
|
274
|
+
agent,
|
|
275
|
+
threadId
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function useUpdatedRef(value) {
|
|
279
|
+
const ref = useRef(value);
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
ref.current = value;
|
|
282
|
+
}, [value]);
|
|
283
|
+
return ref;
|
|
284
|
+
}
|
|
285
|
+
function useLegacyCoagentRenderer({
|
|
286
|
+
copilotkit,
|
|
287
|
+
agent,
|
|
288
|
+
agentId,
|
|
289
|
+
threadId
|
|
290
|
+
}) {
|
|
291
|
+
return useMemo(() => {
|
|
292
|
+
if (!copilotkit || !agent) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
return ({ message, position }) => {
|
|
296
|
+
var _a;
|
|
297
|
+
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
298
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
299
|
+
const runId = existingRunId || `pending:${message.id}`;
|
|
300
|
+
const messageIndex = Math.max(
|
|
301
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
302
|
+
0
|
|
303
|
+
);
|
|
304
|
+
const bridgeProps = {
|
|
305
|
+
message,
|
|
306
|
+
position,
|
|
307
|
+
runId,
|
|
308
|
+
messageIndex,
|
|
309
|
+
messageIndexInRun: 0,
|
|
310
|
+
numberOfMessagesInRun: 1,
|
|
311
|
+
agentId,
|
|
312
|
+
stateSnapshot: message.state
|
|
313
|
+
};
|
|
314
|
+
return createElement(CoAgentStateRenderBridge, bridgeProps);
|
|
315
|
+
};
|
|
316
|
+
}, [agent, agentId, copilotkit, threadId]);
|
|
317
|
+
}
|
|
318
|
+
function defaultSystemMessage(contextString, additionalInstructions) {
|
|
319
|
+
return `
|
|
320
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
321
|
+
|
|
322
|
+
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.
|
|
323
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
324
|
+
|
|
325
|
+
The user has provided you with the following context:
|
|
326
|
+
\`\`\`
|
|
327
|
+
${contextString}
|
|
328
|
+
\`\`\`
|
|
329
|
+
|
|
330
|
+
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
331
|
+
|
|
332
|
+
Please assist them as best you can.
|
|
333
|
+
|
|
334
|
+
You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
|
|
335
|
+
|
|
336
|
+
If you would like to call a function, call it without saying anything else.
|
|
337
|
+
In case of a function error:
|
|
338
|
+
- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.
|
|
339
|
+
- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.
|
|
340
|
+
` + (additionalInstructions ? `
|
|
341
|
+
|
|
342
|
+
${additionalInstructions}` : "");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
useCopilotChatInternal,
|
|
347
|
+
defaultSystemMessage
|
|
348
|
+
};
|
|
349
|
+
//# sourceMappingURL=chunk-LSHFN2Y5.mjs.map
|