@copilotkit/react-core 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
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 +4188 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/chunk-2IDV5OHF.mjs +11 -0
- package/dist/chunk-2IDV5OHF.mjs.map +1 -0
- package/dist/chunk-336QEM3A.mjs +349 -0
- package/dist/chunk-336QEM3A.mjs.map +1 -0
- package/dist/chunk-36KQV2NA.mjs +1 -0
- package/dist/chunk-36KQV2NA.mjs.map +1 -0
- package/dist/chunk-3MHWEKFN.mjs +759 -0
- package/dist/chunk-3MHWEKFN.mjs.map +1 -0
- package/dist/chunk-4CEQJ2X6.mjs +31 -0
- package/dist/chunk-4CEQJ2X6.mjs.map +1 -0
- package/dist/chunk-4RRMC7L2.mjs +32 -0
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/chunk-6ESSSQ7Q.mjs +134 -0
- package/dist/chunk-6ESSSQ7Q.mjs.map +1 -0
- package/dist/chunk-6PUNP7CD.mjs +102 -0
- package/dist/chunk-6PUNP7CD.mjs.map +1 -0
- package/dist/chunk-6YOKPWQ7.mjs +1 -0
- package/dist/chunk-6YOKPWQ7.mjs.map +1 -0
- package/dist/chunk-6ZLPNY7X.mjs +225 -0
- package/dist/chunk-6ZLPNY7X.mjs.map +1 -0
- package/dist/chunk-7DTB7S5V.mjs +83 -0
- package/dist/chunk-7DTB7S5V.mjs.map +1 -0
- package/dist/chunk-7IBF6RBW.mjs +23 -0
- package/dist/chunk-7IBF6RBW.mjs.map +1 -0
- package/dist/chunk-7X3E6GHT.mjs +83 -0
- package/dist/chunk-7X3E6GHT.mjs.map +1 -0
- package/dist/chunk-A6NKSGH3.mjs +1 -0
- package/dist/chunk-A6NKSGH3.mjs.map +1 -0
- package/dist/chunk-ABWT4DRT.mjs +24 -0
- package/dist/chunk-ABWT4DRT.mjs.map +1 -0
- package/dist/chunk-AFNWX62Q.mjs +110 -0
- package/dist/chunk-AFNWX62Q.mjs.map +1 -0
- package/dist/chunk-BUSWSDYO.mjs +17 -0
- package/dist/chunk-BUSWSDYO.mjs.map +1 -0
- 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-CYDWEPFL.mjs.map +1 -0
- package/dist/chunk-DMLQZG75.mjs +25 -0
- package/dist/chunk-DMLQZG75.mjs.map +1 -0
- package/dist/chunk-E7SE25ZU.mjs +59 -0
- package/dist/chunk-E7SE25ZU.mjs.map +1 -0
- package/dist/chunk-EFL5OBKN.mjs +310 -0
- package/dist/chunk-EFL5OBKN.mjs.map +1 -0
- 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-FD6FGKYY.mjs.map +1 -0
- package/dist/chunk-FDOMAPJY.mjs +59 -0
- package/dist/chunk-FDOMAPJY.mjs.map +1 -0
- package/dist/chunk-GJOR3RI6.mjs +120 -0
- package/dist/chunk-GJOR3RI6.mjs.map +1 -0
- package/dist/chunk-GPEJNVE5.mjs +80 -0
- package/dist/chunk-GPEJNVE5.mjs.map +1 -0
- package/dist/chunk-HM6ON7AM.mjs +86 -0
- package/dist/chunk-HM6ON7AM.mjs.map +1 -0
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/chunk-ICIK2BSB.mjs +17 -0
- package/dist/chunk-ICIK2BSB.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-LUGEI4YQ.mjs +1 -0
- package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
- package/dist/chunk-N7FZFIWO.mjs +551 -0
- package/dist/chunk-N7FZFIWO.mjs.map +1 -0
- package/dist/chunk-NB2FKV2V.mjs +1 -0
- package/dist/chunk-NB2FKV2V.mjs.map +1 -0
- package/dist/chunk-NBK4KBLX.mjs +54 -0
- package/dist/chunk-NBK4KBLX.mjs.map +1 -0
- package/dist/chunk-O7ARI5CV.mjs +31 -0
- package/dist/chunk-O7ARI5CV.mjs.map +1 -0
- package/dist/chunk-P2YEE2ZI.mjs +36 -0
- package/dist/chunk-P2YEE2ZI.mjs.map +1 -0
- package/dist/chunk-PIF5KJYI.mjs +103 -0
- package/dist/chunk-PIF5KJYI.mjs.map +1 -0
- package/dist/chunk-PMAFHQ7P.mjs +65 -0
- package/dist/chunk-PMAFHQ7P.mjs.map +1 -0
- package/dist/chunk-QNUAXSDP.mjs +166 -0
- package/dist/chunk-QNUAXSDP.mjs.map +1 -0
- package/dist/chunk-RKTVJRK7.mjs +143 -0
- package/dist/chunk-RKTVJRK7.mjs.map +1 -0
- package/dist/chunk-SKC7AJIV.mjs +61 -0
- package/dist/chunk-SKC7AJIV.mjs.map +1 -0
- package/dist/chunk-SPCZTZCY.mjs +1 -0
- package/dist/chunk-SPCZTZCY.mjs.map +1 -0
- package/dist/chunk-SQDOUMPZ.mjs +125 -0
- package/dist/chunk-SQDOUMPZ.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-YJ2KZDZJ.mjs +186 -0
- package/dist/chunk-YJ2KZDZJ.mjs.map +1 -0
- package/dist/chunk-YTQHRJUA.mjs +86 -0
- package/dist/chunk-YTQHRJUA.mjs.map +1 -0
- package/dist/chunk-YYN33GSG.mjs +73 -0
- 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.d.ts +24 -0
- package/dist/components/copilot-provider/copilot-messages.js +351 -0
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.mjs +16 -0
- package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.d.ts +160 -0
- package/dist/components/copilot-provider/copilotkit-props.js +19 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.d.ts +19 -0
- package/dist/components/copilot-provider/copilotkit.js +1960 -0
- package/dist/components/copilot-provider/copilotkit.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +31 -0
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +14 -0
- package/dist/components/copilot-provider/index.js +1960 -0
- package/dist/components/copilot-provider/index.js.map +1 -0
- package/dist/components/copilot-provider/index.mjs +30 -0
- package/dist/components/copilot-provider/index.mjs.map +1 -0
- package/dist/components/dev-console/console-trigger.d.ts +8 -0
- package/dist/components/dev-console/console-trigger.js +1202 -0
- package/dist/components/dev-console/console-trigger.js.map +1 -0
- package/dist/components/dev-console/console-trigger.mjs +233 -0
- package/dist/components/dev-console/console-trigger.mjs.map +1 -0
- package/dist/components/dev-console/developer-console-modal.d.ts +10 -0
- package/dist/components/dev-console/developer-console-modal.js +987 -0
- package/dist/components/dev-console/developer-console-modal.js.map +1 -0
- package/dist/components/dev-console/developer-console-modal.mjs +12 -0
- package/dist/components/dev-console/developer-console-modal.mjs.map +1 -0
- package/dist/components/dev-console/icons.d.ts +9 -0
- package/dist/components/dev-console/icons.js +131 -0
- package/dist/components/dev-console/icons.js.map +1 -0
- package/dist/components/dev-console/icons.mjs +16 -0
- package/dist/components/dev-console/icons.mjs.map +1 -0
- package/dist/components/error-boundary/error-boundary.d.ts +31 -0
- package/dist/components/error-boundary/error-boundary.js +500 -0
- package/dist/components/error-boundary/error-boundary.js.map +1 -0
- package/dist/components/error-boundary/error-boundary.mjs +15 -0
- package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
- package/dist/components/error-boundary/error-utils.d.ts +11 -0
- package/dist/components/error-boundary/error-utils.js +190 -0
- package/dist/components/error-boundary/error-utils.js.map +1 -0
- package/dist/components/error-boundary/error-utils.mjs +14 -0
- package/dist/components/error-boundary/error-utils.mjs.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.js +1960 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +31 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
- package/dist/components/toast/exclamation-mark-icon.js +55 -0
- package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
- package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
- package/dist/components/toast/toast-provider.d.ts +27 -0
- package/dist/components/toast/toast-provider.js +347 -0
- package/dist/components/toast/toast-provider.js.map +1 -0
- package/dist/components/toast/toast-provider.mjs +10 -0
- package/dist/components/toast/toast-provider.mjs.map +1 -0
- package/dist/components/usage-banner.d.ts +29 -0
- package/dist/components/usage-banner.js +247 -0
- package/dist/components/usage-banner.js.map +1 -0
- package/dist/components/usage-banner.mjs +12 -0
- package/dist/components/usage-banner.mjs.map +1 -0
- 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 +10 -0
- package/dist/context/copilot-context.js +161 -0
- package/dist/context/copilot-context.js.map +1 -0
- package/dist/context/copilot-context.mjs +10 -0
- package/dist/context/copilot-context.mjs.map +1 -0
- package/dist/context/copilot-messages-context.d.ts +18 -0
- package/dist/context/copilot-messages-context.js +60 -0
- package/dist/context/copilot-messages-context.js.map +1 -0
- package/dist/context/copilot-messages-context.mjs +10 -0
- package/dist/context/copilot-messages-context.mjs.map +1 -0
- package/dist/context/index.d.ts +15 -0
- package/dist/context/index.js +285 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +33 -0
- package/dist/context/index.mjs.map +1 -0
- 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-ec77e921.d.ts +209 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +1774 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +91 -0
- package/dist/hooks/index.mjs.map +1 -0
- 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.d.ts +55 -0
- package/dist/hooks/use-coagent-state-render.js +255 -0
- package/dist/hooks/use-coagent-state-render.js.map +1 -0
- package/dist/hooks/use-coagent-state-render.mjs +11 -0
- package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
- package/dist/hooks/use-coagent.d.ts +192 -0
- package/dist/hooks/use-coagent.js +233 -0
- package/dist/hooks/use-coagent.js.map +1 -0
- package/dist/hooks/use-coagent.mjs +9 -0
- package/dist/hooks/use-coagent.mjs.map +1 -0
- 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 +103 -0
- package/dist/hooks/use-copilot-action.js +295 -0
- package/dist/hooks/use-copilot-action.js.map +1 -0
- package/dist/hooks/use-copilot-action.mjs +11 -0
- package/dist/hooks/use-copilot-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
- package/dist/hooks/use-copilot-additional-instructions.js +177 -0
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.d.ts +18 -0
- package/dist/hooks/use-copilot-authenticated-action.js +462 -0
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs +13 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +25 -0
- package/dist/hooks/use-copilot-chat-headless_c.js +1044 -0
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -0
- package/dist/hooks/use-copilot-chat-headless_c.mjs +24 -0
- package/dist/hooks/use-copilot-chat-headless_c.mjs.map +1 -0
- 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 +92 -0
- package/dist/hooks/use-copilot-chat.js +978 -0
- package/dist/hooks/use-copilot-chat.js.map +1 -0
- package/dist/hooks/use-copilot-chat.mjs +21 -0
- package/dist/hooks/use-copilot-chat.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat_internal.d.ts +244 -0
- package/dist/hooks/use-copilot-chat_internal.js +976 -0
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -0
- package/dist/hooks/use-copilot-chat_internal.mjs +22 -0
- package/dist/hooks/use-copilot-chat_internal.mjs.map +1 -0
- package/dist/hooks/use-copilot-readable.d.ts +37 -0
- package/dist/hooks/use-copilot-readable.js +61 -0
- package/dist/hooks/use-copilot-readable.js.map +1 -0
- package/dist/hooks/use-copilot-readable.mjs +8 -0
- package/dist/hooks/use-copilot-readable.mjs.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.d.ts +10 -0
- package/dist/hooks/use-copilot-runtime-client.js +203 -0
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.mjs +9 -0
- package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
- package/dist/hooks/use-default-tool.d.ts +8 -0
- package/dist/hooks/use-default-tool.js +302 -0
- package/dist/hooks/use-default-tool.js.map +1 -0
- package/dist/hooks/use-default-tool.mjs +12 -0
- package/dist/hooks/use-default-tool.mjs.map +1 -0
- package/dist/hooks/use-flat-category-store.d.ts +9 -0
- package/dist/hooks/use-flat-category-store.js +93 -0
- package/dist/hooks/use-flat-category-store.js.map +1 -0
- package/dist/hooks/use-flat-category-store.mjs +8 -0
- package/dist/hooks/use-flat-category-store.mjs.map +1 -0
- package/dist/hooks/use-frontend-tool.d.ts +11 -0
- package/dist/hooks/use-frontend-tool.js +104 -0
- package/dist/hooks/use-frontend-tool.js.map +1 -0
- package/dist/hooks/use-frontend-tool.mjs +8 -0
- package/dist/hooks/use-frontend-tool.mjs.map +1 -0
- package/dist/hooks/use-human-in-the-loop.d.ts +13 -0
- package/dist/hooks/use-human-in-the-loop.js +122 -0
- package/dist/hooks/use-human-in-the-loop.js.map +1 -0
- package/dist/hooks/use-human-in-the-loop.mjs +8 -0
- package/dist/hooks/use-human-in-the-loop.mjs.map +1 -0
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +6 -0
- package/dist/hooks/use-langgraph-interrupt-render.js +318 -0
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs +14 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.d.ts +14 -0
- package/dist/hooks/use-langgraph-interrupt.js +201 -0
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.mjs +10 -0
- package/dist/hooks/use-langgraph-interrupt.mjs.map +1 -0
- 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.d.ts +12 -0
- package/dist/hooks/use-make-copilot-document-readable.js +176 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
- package/dist/hooks/use-render-tool-call.d.ts +12 -0
- package/dist/hooks/use-render-tool-call.js +90 -0
- package/dist/hooks/use-render-tool-call.js.map +1 -0
- package/dist/hooks/use-render-tool-call.mjs +8 -0
- package/dist/hooks/use-render-tool-call.mjs.map +1 -0
- package/dist/hooks/use-tree.d.ts +19 -0
- package/dist/hooks/use-tree.js +175 -0
- package/dist/hooks/use-tree.js.map +1 -0
- package/dist/hooks/use-tree.mjs +8 -0
- package/dist/hooks/use-tree.mjs.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +3528 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +149 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/copilot-task.d.ts +97 -0
- package/dist/lib/copilot-task.js +194 -0
- package/dist/lib/copilot-task.js.map +1 -0
- package/dist/lib/copilot-task.mjs +31 -0
- package/dist/lib/copilot-task.mjs.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +196 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +32 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/status-checker.d.ts +17 -0
- package/dist/lib/status-checker.js +102 -0
- package/dist/lib/status-checker.js.map +1 -0
- package/dist/lib/status-checker.mjs +8 -0
- package/dist/lib/status-checker.mjs.map +1 -0
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +26 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/setupTests.mjs +24 -0
- package/dist/setupTests.mjs.map +1 -0
- package/dist/types/chat-suggestion-configuration.d.ts +22 -0
- package/dist/types/chat-suggestion-configuration.js +19 -0
- package/dist/types/chat-suggestion-configuration.js.map +1 -0
- package/dist/types/chat-suggestion-configuration.mjs +1 -0
- package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
- package/dist/types/coagent-action.d.ts +29 -0
- package/dist/types/coagent-action.js +19 -0
- package/dist/types/coagent-action.js.map +1 -0
- package/dist/types/coagent-action.mjs +1 -0
- package/dist/types/coagent-action.mjs.map +1 -0
- package/dist/types/coagent-state.d.ts +15 -0
- package/dist/types/coagent-state.js +19 -0
- package/dist/types/coagent-state.js.map +1 -0
- package/dist/types/coagent-state.mjs +1 -0
- package/dist/types/coagent-state.mjs.map +1 -0
- package/dist/types/crew.d.ts +79 -0
- package/dist/types/crew.js +19 -0
- package/dist/types/crew.js.map +1 -0
- package/dist/types/crew.mjs +2 -0
- package/dist/types/crew.mjs.map +1 -0
- package/dist/types/document-pointer.d.ts +9 -0
- package/dist/types/document-pointer.js +19 -0
- package/dist/types/document-pointer.js.map +1 -0
- package/dist/types/document-pointer.mjs +1 -0
- package/dist/types/document-pointer.mjs.map +1 -0
- package/dist/types/frontend-action.d.ts +127 -0
- package/dist/types/frontend-action.js +53 -0
- package/dist/types/frontend-action.js.map +1 -0
- package/dist/types/frontend-action.mjs +8 -0
- package/dist/types/frontend-action.mjs.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/interrupt-action.d.ts +10 -0
- package/dist/types/interrupt-action.js +19 -0
- package/dist/types/interrupt-action.js.map +1 -0
- package/dist/types/interrupt-action.mjs +2 -0
- package/dist/types/interrupt-action.mjs.map +1 -0
- package/dist/types/system-message.d.ts +3 -0
- package/dist/types/system-message.js +19 -0
- package/dist/types/system-message.js.map +1 -0
- package/dist/types/system-message.mjs +1 -0
- package/dist/types/system-message.mjs.map +1 -0
- package/dist/utils/dev-console.d.ts +3 -0
- package/dist/utils/dev-console.js +41 -0
- package/dist/utils/dev-console.js.map +1 -0
- package/dist/utils/dev-console.mjs +8 -0
- package/dist/utils/dev-console.mjs.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +13 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/suggestions-constants.d.ts +9 -0
- package/dist/utils/suggestions-constants.js +35 -0
- package/dist/utils/suggestions-constants.js.map +1 -0
- package/dist/utils/suggestions-constants.mjs +8 -0
- package/dist/utils/suggestions-constants.mjs.map +1 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.js +19 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/utils.mjs +1 -0
- package/dist/utils/utils.mjs.map +1 -0
- 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 +25 -0
- package/package.json +92 -0
- package/src/components/CopilotListeners.tsx +81 -0
- package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +75 -0
- package/src/components/copilot-provider/copilot-messages.tsx +274 -0
- package/src/components/copilot-provider/copilotkit-props.tsx +169 -0
- package/src/components/copilot-provider/copilotkit.tsx +671 -0
- package/src/components/copilot-provider/index.ts +3 -0
- package/src/components/dev-console/console-trigger.tsx +254 -0
- package/src/components/dev-console/developer-console-modal.tsx +866 -0
- package/src/components/dev-console/icons.tsx +101 -0
- package/src/components/error-boundary/error-boundary.tsx +91 -0
- package/src/components/error-boundary/error-utils.tsx +100 -0
- package/src/components/index.ts +1 -0
- package/src/components/toast/exclamation-mark-icon.tsx +27 -0
- package/src/components/toast/toast-provider.tsx +363 -0
- package/src/components/usage-banner.tsx +259 -0
- package/src/context/coagent-state-renders-context.tsx +76 -0
- package/src/context/copilot-context.tsx +332 -0
- package/src/context/copilot-messages-context.tsx +35 -0
- package/src/context/index.ts +16 -0
- package/src/context/threads-context.tsx +41 -0
- package/src/hooks/__tests__/use-coagent-config.test.ts +351 -0
- package/src/hooks/index.ts +34 -0
- 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 +152 -0
- package/src/hooks/use-coagent.ts +366 -0
- package/src/hooks/use-configure-chat-suggestions.tsx +86 -0
- package/src/hooks/use-copilot-action.ts +236 -0
- package/src/hooks/use-copilot-additional-instructions.ts +85 -0
- package/src/hooks/use-copilot-authenticated-action.ts +70 -0
- package/src/hooks/use-copilot-chat-headless_c.ts +258 -0
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat.ts +130 -0
- package/src/hooks/use-copilot-chat_internal.ts +696 -0
- package/src/hooks/use-copilot-readable.ts +135 -0
- package/src/hooks/use-copilot-runtime-client.ts +164 -0
- package/src/hooks/use-default-tool.ts +7 -0
- package/src/hooks/use-flat-category-store.ts +105 -0
- package/src/hooks/use-frontend-tool.ts +96 -0
- package/src/hooks/use-human-in-the-loop.ts +122 -0
- package/src/hooks/use-langgraph-interrupt-render.ts +136 -0
- package/src/hooks/use-langgraph-interrupt.ts +36 -0
- package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
- package/src/hooks/use-make-copilot-document-readable.ts +30 -0
- package/src/hooks/use-render-tool-call.ts +80 -0
- package/src/hooks/use-tree.ts +207 -0
- package/src/index.tsx +7 -0
- package/src/lib/copilot-task.ts +201 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/status-checker.ts +64 -0
- package/src/setupTests.ts +26 -0
- package/src/types/chat-suggestion-configuration.ts +23 -0
- package/src/types/coagent-action.ts +31 -0
- package/src/types/coagent-state.ts +13 -0
- package/src/types/crew.ts +89 -0
- package/src/types/document-pointer.ts +7 -0
- package/src/types/frontend-action.ts +202 -0
- package/src/types/index.ts +17 -0
- package/src/types/interrupt-action.ts +43 -0
- package/src/types/system-message.ts +4 -0
- package/src/utils/dev-console.ts +19 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/suggestions-constants.ts +8 -0
- package/src/utils/utils.test.ts +7 -0
- package/src/utils/utils.ts +8 -0
- package/src/v2/index.css +1 -0
- package/src/v2/index.ts +4 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,1774 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
var __async = (__this, __arguments, generator) => {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
var fulfilled = (value) => {
|
|
61
|
+
try {
|
|
62
|
+
step(generator.next(value));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
reject(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var rejected = (value) => {
|
|
68
|
+
try {
|
|
69
|
+
step(generator.throw(value));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
reject(e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/hooks/index.ts
|
|
80
|
+
var hooks_exports = {};
|
|
81
|
+
__export(hooks_exports, {
|
|
82
|
+
useCoAgent: () => useCoAgent,
|
|
83
|
+
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
84
|
+
useCopilotAction: () => useCopilotAction,
|
|
85
|
+
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
86
|
+
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
87
|
+
useCopilotChat: () => useCopilotChat,
|
|
88
|
+
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
89
|
+
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
90
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
91
|
+
useCopilotReadable: () => useCopilotReadable,
|
|
92
|
+
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
93
|
+
useDefaultTool: () => useDefaultTool,
|
|
94
|
+
useFrontendTool: () => useFrontendTool,
|
|
95
|
+
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
96
|
+
useLangGraphInterrupt: () => useLangGraphInterrupt,
|
|
97
|
+
useLangGraphInterruptRender: () => useLangGraphInterruptRender,
|
|
98
|
+
useLazyToolRenderer: () => useLazyToolRenderer,
|
|
99
|
+
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
100
|
+
useRenderToolCall: () => useRenderToolCall2
|
|
101
|
+
});
|
|
102
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
103
|
+
|
|
104
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
105
|
+
var import_react13 = require("react");
|
|
106
|
+
|
|
107
|
+
// src/context/copilot-context.tsx
|
|
108
|
+
var import_react = __toESM(require("react"));
|
|
109
|
+
var emptyCopilotContext = {
|
|
110
|
+
actions: {},
|
|
111
|
+
setAction: () => {
|
|
112
|
+
},
|
|
113
|
+
removeAction: () => {
|
|
114
|
+
},
|
|
115
|
+
setRegisteredActions: () => "",
|
|
116
|
+
removeRegisteredAction: () => {
|
|
117
|
+
},
|
|
118
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
119
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
120
|
+
addContext: () => "",
|
|
121
|
+
removeContext: () => {
|
|
122
|
+
},
|
|
123
|
+
getAllContext: () => [],
|
|
124
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
125
|
+
})),
|
|
126
|
+
isLoading: false,
|
|
127
|
+
setIsLoading: () => returnAndThrowInDebug(false),
|
|
128
|
+
chatInstructions: "",
|
|
129
|
+
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
130
|
+
additionalInstructions: [],
|
|
131
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
132
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
133
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
134
|
+
removeDocumentContext: () => {
|
|
135
|
+
},
|
|
136
|
+
copilotApiConfig: new class {
|
|
137
|
+
get chatApiEndpoint() {
|
|
138
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
139
|
+
}
|
|
140
|
+
get headers() {
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
get body() {
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
}(),
|
|
147
|
+
chatSuggestionConfiguration: {},
|
|
148
|
+
addChatSuggestionConfiguration: () => {
|
|
149
|
+
},
|
|
150
|
+
removeChatSuggestionConfiguration: () => {
|
|
151
|
+
},
|
|
152
|
+
showDevConsole: false,
|
|
153
|
+
coagentStates: {},
|
|
154
|
+
setCoagentStates: () => {
|
|
155
|
+
},
|
|
156
|
+
coagentStatesRef: { current: {} },
|
|
157
|
+
setCoagentStatesWithRef: () => {
|
|
158
|
+
},
|
|
159
|
+
agentSession: null,
|
|
160
|
+
setAgentSession: () => {
|
|
161
|
+
},
|
|
162
|
+
forwardedParameters: {},
|
|
163
|
+
agentLock: null,
|
|
164
|
+
threadId: "",
|
|
165
|
+
setThreadId: () => {
|
|
166
|
+
},
|
|
167
|
+
runId: null,
|
|
168
|
+
setRunId: () => {
|
|
169
|
+
},
|
|
170
|
+
chatAbortControllerRef: { current: null },
|
|
171
|
+
availableAgents: [],
|
|
172
|
+
extensions: {},
|
|
173
|
+
setExtensions: () => {
|
|
174
|
+
},
|
|
175
|
+
interruptActions: {},
|
|
176
|
+
setInterruptAction: () => {
|
|
177
|
+
},
|
|
178
|
+
removeInterruptAction: () => {
|
|
179
|
+
},
|
|
180
|
+
interruptEventQueue: {},
|
|
181
|
+
addInterruptEvent: () => {
|
|
182
|
+
},
|
|
183
|
+
resolveInterruptEvent: () => {
|
|
184
|
+
},
|
|
185
|
+
onError: () => {
|
|
186
|
+
},
|
|
187
|
+
bannerError: null,
|
|
188
|
+
setBannerError: () => {
|
|
189
|
+
},
|
|
190
|
+
internalErrorHandlers: {},
|
|
191
|
+
setInternalErrorHandler: () => {
|
|
192
|
+
},
|
|
193
|
+
removeInternalErrorHandler: () => {
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
197
|
+
function useCopilotContext() {
|
|
198
|
+
const context = import_react.default.useContext(CopilotContext);
|
|
199
|
+
if (context === emptyCopilotContext) {
|
|
200
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
201
|
+
}
|
|
202
|
+
return context;
|
|
203
|
+
}
|
|
204
|
+
function returnAndThrowInDebug(_value) {
|
|
205
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/components/error-boundary/error-utils.tsx
|
|
209
|
+
var import_react3 = require("react");
|
|
210
|
+
|
|
211
|
+
// src/components/toast/toast-provider.tsx
|
|
212
|
+
var import_react2 = require("react");
|
|
213
|
+
var import_shared = require("@copilotkit/shared");
|
|
214
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
215
|
+
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
216
|
+
function useToast() {
|
|
217
|
+
const context = (0, import_react2.useContext)(ToastContext);
|
|
218
|
+
if (!context) {
|
|
219
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
220
|
+
}
|
|
221
|
+
return context;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
225
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
226
|
+
var ExclamationMarkIcon = ({
|
|
227
|
+
className,
|
|
228
|
+
style
|
|
229
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
230
|
+
"svg",
|
|
231
|
+
{
|
|
232
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
233
|
+
width: "24",
|
|
234
|
+
height: "24",
|
|
235
|
+
viewBox: "0 0 24 24",
|
|
236
|
+
fill: "none",
|
|
237
|
+
stroke: "currentColor",
|
|
238
|
+
strokeWidth: "2",
|
|
239
|
+
strokeLinecap: "round",
|
|
240
|
+
strokeLinejoin: "round",
|
|
241
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
242
|
+
style,
|
|
243
|
+
children: [
|
|
244
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
245
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// src/components/error-boundary/error-utils.tsx
|
|
252
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
253
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
254
|
+
function ErrorToast({ errors }) {
|
|
255
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
256
|
+
var _a, _b, _c;
|
|
257
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
258
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
259
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
260
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
261
|
+
"div",
|
|
262
|
+
{
|
|
263
|
+
style: {
|
|
264
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
265
|
+
marginBottom: 14
|
|
266
|
+
},
|
|
267
|
+
children: [
|
|
268
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
269
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
270
|
+
"div",
|
|
271
|
+
{
|
|
272
|
+
style: {
|
|
273
|
+
fontWeight: "600",
|
|
274
|
+
marginBottom: 4
|
|
275
|
+
},
|
|
276
|
+
children: [
|
|
277
|
+
"Copilot Runtime Error:",
|
|
278
|
+
" ",
|
|
279
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
idx
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
290
|
+
"div",
|
|
291
|
+
{
|
|
292
|
+
style: {
|
|
293
|
+
fontSize: "13px",
|
|
294
|
+
maxWidth: "600px"
|
|
295
|
+
},
|
|
296
|
+
children: [
|
|
297
|
+
errorsToRender,
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
function useErrorToast() {
|
|
304
|
+
const { addToast } = useToast();
|
|
305
|
+
return (0, import_react3.useCallback)(
|
|
306
|
+
(errors) => {
|
|
307
|
+
const errorId = errors.map((err) => {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
310
|
+
const stack = err.stack || "";
|
|
311
|
+
return btoa(message + stack).slice(0, 32);
|
|
312
|
+
}).join("|");
|
|
313
|
+
addToast({
|
|
314
|
+
type: "error",
|
|
315
|
+
id: errorId,
|
|
316
|
+
// Toast libraries typically dedupe by id
|
|
317
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors })
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
[addToast]
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
function useAsyncCallback(callback, deps) {
|
|
324
|
+
const addErrorToast = useErrorToast();
|
|
325
|
+
return (0, import_react3.useCallback)((...args) => __async(this, null, function* () {
|
|
326
|
+
try {
|
|
327
|
+
return yield callback(...args);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.error("Error in async callback:", error);
|
|
330
|
+
addErrorToast([error]);
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
}), deps);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
337
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
338
|
+
|
|
339
|
+
// src/context/coagent-state-renders-context.tsx
|
|
340
|
+
var import_react4 = require("react");
|
|
341
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
342
|
+
var CoAgentStateRendersContext = (0, import_react4.createContext)(
|
|
343
|
+
void 0
|
|
344
|
+
);
|
|
345
|
+
function useCoAgentStateRenders() {
|
|
346
|
+
const context = (0, import_react4.useContext)(CoAgentStateRendersContext);
|
|
347
|
+
if (!context) {
|
|
348
|
+
throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
|
|
349
|
+
}
|
|
350
|
+
return context;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
354
|
+
var import_react7 = __toESM(require("react"));
|
|
355
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
356
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
357
|
+
|
|
358
|
+
// src/hooks/use-agent-nodename.ts
|
|
359
|
+
var import_react5 = require("react");
|
|
360
|
+
var import_react6 = require("@copilotkitnext/react");
|
|
361
|
+
function useAgentNodeName(agentName) {
|
|
362
|
+
const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
|
|
363
|
+
const nodeNameRef = (0, import_react5.useRef)("start");
|
|
364
|
+
(0, import_react5.useEffect)(() => {
|
|
365
|
+
if (!agent)
|
|
366
|
+
return;
|
|
367
|
+
const subscriber = {
|
|
368
|
+
onStepStartedEvent: ({ event }) => {
|
|
369
|
+
nodeNameRef.current = event.stepName;
|
|
370
|
+
},
|
|
371
|
+
onRunStartedEvent: () => {
|
|
372
|
+
nodeNameRef.current = "start";
|
|
373
|
+
},
|
|
374
|
+
onRunFinishedEvent: () => {
|
|
375
|
+
nodeNameRef.current = "end";
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const subscription = agent.subscribe(subscriber);
|
|
379
|
+
return () => {
|
|
380
|
+
subscription.unsubscribe();
|
|
381
|
+
};
|
|
382
|
+
}, [agent]);
|
|
383
|
+
return nodeNameRef.current;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
387
|
+
var import_react8 = require("@copilotkitnext/react");
|
|
388
|
+
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
389
|
+
return render({ event, result, resolve });
|
|
390
|
+
};
|
|
391
|
+
function useLangGraphInterruptRender(agent) {
|
|
392
|
+
var _a;
|
|
393
|
+
const {
|
|
394
|
+
interruptActions,
|
|
395
|
+
agentSession,
|
|
396
|
+
threadId,
|
|
397
|
+
interruptEventQueue,
|
|
398
|
+
addInterruptEvent,
|
|
399
|
+
resolveInterruptEvent
|
|
400
|
+
} = useCopilotContext();
|
|
401
|
+
const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
|
|
402
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
403
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
404
|
+
(0, import_react7.useEffect)(() => {
|
|
405
|
+
if (!agent)
|
|
406
|
+
return;
|
|
407
|
+
let localInterrupt = null;
|
|
408
|
+
const subscriber = {
|
|
409
|
+
onCustomEvent: ({ event }) => {
|
|
410
|
+
if (event.name === "on_interrupt") {
|
|
411
|
+
const eventData = {
|
|
412
|
+
name: import_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
413
|
+
type: event.type,
|
|
414
|
+
value: (0, import_shared2.parseJson)(event.value, event.value)
|
|
415
|
+
};
|
|
416
|
+
const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
|
|
417
|
+
localInterrupt = {
|
|
418
|
+
eventId,
|
|
419
|
+
threadId,
|
|
420
|
+
event: eventData
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
onRunStartedEvent: () => {
|
|
425
|
+
localInterrupt = null;
|
|
426
|
+
},
|
|
427
|
+
onRunFinalized: () => {
|
|
428
|
+
if (localInterrupt) {
|
|
429
|
+
addInterruptEvent(localInterrupt);
|
|
430
|
+
localInterrupt = null;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
435
|
+
return () => {
|
|
436
|
+
unsubscribe();
|
|
437
|
+
};
|
|
438
|
+
}, [agent, threadId]);
|
|
439
|
+
const handleResolve = (0, import_react7.useCallback)(
|
|
440
|
+
(eventId, response) => {
|
|
441
|
+
agent == null ? void 0 : agent.runAgent({
|
|
442
|
+
forwardedProps: {
|
|
443
|
+
command: {
|
|
444
|
+
resume: response
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
449
|
+
},
|
|
450
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
451
|
+
[agent, threadId]
|
|
452
|
+
);
|
|
453
|
+
return (0, import_react7.useMemo)(() => {
|
|
454
|
+
const eventQueue = interruptEventQueue[threadId] || [];
|
|
455
|
+
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
456
|
+
if (!currentQueuedEvent || !agentSession)
|
|
457
|
+
return null;
|
|
458
|
+
const allActions = Object.values(interruptActions);
|
|
459
|
+
const matchingAction = allActions.find((action) => {
|
|
460
|
+
if (!action.enabled)
|
|
461
|
+
return true;
|
|
462
|
+
return action.enabled({
|
|
463
|
+
eventValue: currentQueuedEvent.event.value,
|
|
464
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
465
|
+
nodeName
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
if (!matchingAction)
|
|
470
|
+
return null;
|
|
471
|
+
const { render, handler } = matchingAction;
|
|
472
|
+
const resolveInterrupt = (response) => {
|
|
473
|
+
handleResolve(currentQueuedEvent.eventId, response);
|
|
474
|
+
};
|
|
475
|
+
let result = null;
|
|
476
|
+
if (handler) {
|
|
477
|
+
result = handler({
|
|
478
|
+
event: currentQueuedEvent.event,
|
|
479
|
+
resolve: resolveInterrupt
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (!render)
|
|
483
|
+
return null;
|
|
484
|
+
return import_react7.default.createElement(InterruptRenderer, {
|
|
485
|
+
event: currentQueuedEvent.event,
|
|
486
|
+
result,
|
|
487
|
+
render,
|
|
488
|
+
resolve: resolveInterrupt
|
|
489
|
+
});
|
|
490
|
+
}, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
494
|
+
var import_react14 = require("@copilotkitnext/react");
|
|
495
|
+
|
|
496
|
+
// src/hooks/use-lazy-tool-renderer.tsx
|
|
497
|
+
var import_react9 = require("@copilotkitnext/react");
|
|
498
|
+
var import_react10 = require("react");
|
|
499
|
+
function useLazyToolRenderer() {
|
|
500
|
+
const renderToolCall = (0, import_react9.useRenderToolCall)();
|
|
501
|
+
return (0, import_react10.useCallback)(
|
|
502
|
+
(message, messages) => {
|
|
503
|
+
var _a;
|
|
504
|
+
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
505
|
+
return null;
|
|
506
|
+
const toolCall = message.toolCalls[0];
|
|
507
|
+
if (!toolCall)
|
|
508
|
+
return null;
|
|
509
|
+
const toolMessage = messages == null ? void 0 : messages.find(
|
|
510
|
+
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
511
|
+
);
|
|
512
|
+
return () => renderToolCall({
|
|
513
|
+
toolCall,
|
|
514
|
+
toolMessage
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
[renderToolCall]
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
522
|
+
var import_client = require("@ag-ui/client");
|
|
523
|
+
|
|
524
|
+
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
525
|
+
var import_react11 = require("@copilotkitnext/react");
|
|
526
|
+
var import_react12 = require("react");
|
|
527
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
528
|
+
function getStateWithoutConstantKeys(state) {
|
|
529
|
+
if (!state)
|
|
530
|
+
return {};
|
|
531
|
+
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
532
|
+
return stateWithoutConstantKeys;
|
|
533
|
+
}
|
|
534
|
+
function areStatesEquals(a, b) {
|
|
535
|
+
if (a && !b || !a && b)
|
|
536
|
+
return false;
|
|
537
|
+
const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
538
|
+
const _b = b, {
|
|
539
|
+
messages: bMessages,
|
|
540
|
+
tools: bTools,
|
|
541
|
+
copilotkit: bCopilotkit
|
|
542
|
+
} = _b, bWithoutConstantKeys = __objRest(_b, [
|
|
543
|
+
"messages",
|
|
544
|
+
"tools",
|
|
545
|
+
"copilotkit"
|
|
546
|
+
]);
|
|
547
|
+
return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
|
|
548
|
+
}
|
|
549
|
+
function useCoagentStateRenderBridge(agentId, props) {
|
|
550
|
+
var _a;
|
|
551
|
+
const { stateSnapshot, messageIndexInRun, message } = props;
|
|
552
|
+
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
553
|
+
const { agent } = (0, import_react11.useAgent)({ agentId });
|
|
554
|
+
const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
|
|
555
|
+
const runId = (_a = props.runId) != null ? _a : message.runId;
|
|
556
|
+
const effectiveRunId = runId || "pending";
|
|
557
|
+
(0, import_react12.useEffect)(() => {
|
|
558
|
+
if (!agent)
|
|
559
|
+
return;
|
|
560
|
+
const subscriber = {
|
|
561
|
+
onStepStartedEvent: ({ event }) => {
|
|
562
|
+
if (event.stepName !== nodeName) {
|
|
563
|
+
setNodeName(event.stepName);
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
onStepFinishedEvent: ({ event }) => {
|
|
567
|
+
if (event.stepName === nodeName) {
|
|
568
|
+
setNodeName(void 0);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
573
|
+
return () => {
|
|
574
|
+
unsubscribe();
|
|
575
|
+
};
|
|
576
|
+
}, [agentId, nodeName]);
|
|
577
|
+
const getStateRender = (0, import_react12.useCallback)(
|
|
578
|
+
(messageId) => {
|
|
579
|
+
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
580
|
+
if (claimsRef.current[messageId]) {
|
|
581
|
+
return stateRenderId === claimsRef.current[messageId].stateRenderId;
|
|
582
|
+
}
|
|
583
|
+
const matchingAgentName = stateRender.name === agentId;
|
|
584
|
+
const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
|
|
585
|
+
return matchingAgentName && matchesNodeContext;
|
|
586
|
+
});
|
|
587
|
+
},
|
|
588
|
+
[coAgentStateRenders, nodeName, agentId]
|
|
589
|
+
);
|
|
590
|
+
const handleRenderRequest = ({
|
|
591
|
+
stateRenderId,
|
|
592
|
+
messageId,
|
|
593
|
+
runId: runId2,
|
|
594
|
+
stateSnapshot: renderSnapshot
|
|
595
|
+
}) => {
|
|
596
|
+
if (claimsRef.current[messageId]) {
|
|
597
|
+
const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
|
|
598
|
+
if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
|
|
599
|
+
claimsRef.current[messageId].runId = runId2;
|
|
600
|
+
}
|
|
601
|
+
return canRender;
|
|
602
|
+
}
|
|
603
|
+
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
604
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
|
|
605
|
+
);
|
|
606
|
+
if (renderClaimedByOtherMessage) {
|
|
607
|
+
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
608
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
if (!runId2) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
617
|
+
return true;
|
|
618
|
+
};
|
|
619
|
+
return (0, import_react12.useMemo)(() => {
|
|
620
|
+
var _a2, _b, _c;
|
|
621
|
+
if (messageIndexInRun !== 0) {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
625
|
+
if (!stateRender || !stateRenderId) {
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
const snapshot = stateSnapshot ? (0, import_shared3.parseJson)(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
|
|
629
|
+
const canRender = handleRenderRequest({
|
|
630
|
+
stateRenderId,
|
|
631
|
+
messageId: message.id,
|
|
632
|
+
runId: effectiveRunId,
|
|
633
|
+
stateSnapshot: snapshot
|
|
634
|
+
});
|
|
635
|
+
if (!canRender) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
if (snapshot && !claimsRef.current[message.id].locked) {
|
|
639
|
+
if (stateSnapshot) {
|
|
640
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
641
|
+
claimsRef.current[message.id].locked = true;
|
|
642
|
+
} else {
|
|
643
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (stateRender.handler) {
|
|
647
|
+
stateRender.handler({
|
|
648
|
+
state: stateSnapshot ? (0, import_shared3.parseJson)(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
|
|
649
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (stateRender.render) {
|
|
653
|
+
const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
|
|
654
|
+
if (typeof stateRender.render === "string")
|
|
655
|
+
return stateRender.render;
|
|
656
|
+
return stateRender.render({
|
|
657
|
+
status,
|
|
658
|
+
// Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
|
|
659
|
+
state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
|
|
660
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
}, [
|
|
664
|
+
getStateRender,
|
|
665
|
+
stateSnapshot,
|
|
666
|
+
agent == null ? void 0 : agent.state,
|
|
667
|
+
agent == null ? void 0 : agent.isRunning,
|
|
668
|
+
nodeName,
|
|
669
|
+
effectiveRunId,
|
|
670
|
+
message.id,
|
|
671
|
+
messageIndexInRun
|
|
672
|
+
]);
|
|
673
|
+
}
|
|
674
|
+
function CoAgentStateRenderBridge(props) {
|
|
675
|
+
return useCoagentStateRenderBridge(props.agentId, props);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
679
|
+
function useCopilotChatInternal({
|
|
680
|
+
suggestions,
|
|
681
|
+
onInProgress,
|
|
682
|
+
onSubmitMessage,
|
|
683
|
+
onStopGeneration,
|
|
684
|
+
onReloadMessages
|
|
685
|
+
} = {}) {
|
|
686
|
+
var _a, _b, _c;
|
|
687
|
+
const { copilotkit } = (0, import_react14.useCopilotKit)();
|
|
688
|
+
const { threadId, agentSession } = useCopilotContext();
|
|
689
|
+
const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
|
|
690
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
|
|
691
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
692
|
+
const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
|
|
693
|
+
(0, import_react13.useEffect)(() => {
|
|
694
|
+
const connect = (agent2) => __async(this, null, function* () {
|
|
695
|
+
setAgentAvailable(false);
|
|
696
|
+
try {
|
|
697
|
+
yield copilotkit.connectAgent({ agent: agent2 });
|
|
698
|
+
setAgentAvailable(true);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
701
|
+
} else {
|
|
702
|
+
throw error;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
707
|
+
agent.threadId = existingConfig.threadId;
|
|
708
|
+
connect(agent);
|
|
709
|
+
}
|
|
710
|
+
return () => {
|
|
711
|
+
};
|
|
712
|
+
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
713
|
+
(0, import_react13.useEffect)(() => {
|
|
714
|
+
onInProgress == null ? void 0 : onInProgress(Boolean(agent == null ? void 0 : agent.isRunning));
|
|
715
|
+
}, [agent == null ? void 0 : agent.isRunning, onInProgress]);
|
|
716
|
+
const interrupt = useLangGraphInterruptRender(agent);
|
|
717
|
+
const reset = () => {
|
|
718
|
+
agent == null ? void 0 : agent.setMessages([]);
|
|
719
|
+
agent == null ? void 0 : agent.setState(null);
|
|
720
|
+
};
|
|
721
|
+
const deleteMessage = (0, import_react13.useCallback)(
|
|
722
|
+
(messageId) => {
|
|
723
|
+
var _a2;
|
|
724
|
+
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
725
|
+
(message) => message.id !== messageId
|
|
726
|
+
);
|
|
727
|
+
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
728
|
+
},
|
|
729
|
+
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
730
|
+
);
|
|
731
|
+
const latestDelete = useUpdatedRef(deleteMessage);
|
|
732
|
+
const latestDeleteFunc = (0, import_react13.useCallback)(
|
|
733
|
+
(messageId) => {
|
|
734
|
+
return latestDelete.current(messageId);
|
|
735
|
+
},
|
|
736
|
+
[latestDelete]
|
|
737
|
+
);
|
|
738
|
+
const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
|
|
739
|
+
const reload = useAsyncCallback(
|
|
740
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
741
|
+
var _a2;
|
|
742
|
+
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
743
|
+
const isLoading = false;
|
|
744
|
+
if (isLoading || messages.length === 0) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
748
|
+
if (reloadMessageIndex === -1) {
|
|
749
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
753
|
+
if (reloadMessageRole !== "assistant") {
|
|
754
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
let historyCutoff = [messages[0]];
|
|
758
|
+
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
759
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
760
|
+
if (!lastUserMessageBeforeRegenerate) {
|
|
761
|
+
historyCutoff = [messages[0]];
|
|
762
|
+
} else {
|
|
763
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
764
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
765
|
+
);
|
|
766
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
767
|
+
}
|
|
768
|
+
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
769
|
+
historyCutoff = [messages[0], messages[1]];
|
|
770
|
+
}
|
|
771
|
+
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
772
|
+
if (agent) {
|
|
773
|
+
copilotkit.runAgent({ agent });
|
|
774
|
+
}
|
|
775
|
+
return;
|
|
776
|
+
}),
|
|
777
|
+
[agent == null ? void 0 : agent.setMessages, copilotkit == null ? void 0 : copilotkit.runAgent]
|
|
778
|
+
);
|
|
779
|
+
const latestSendMessageFunc = useAsyncCallback(
|
|
780
|
+
(message, options) => __async(this, null, function* () {
|
|
781
|
+
var _a2;
|
|
782
|
+
if (!agent)
|
|
783
|
+
return;
|
|
784
|
+
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
785
|
+
if (options == null ? void 0 : options.clearSuggestions) {
|
|
786
|
+
copilotkit.clearSuggestions(resolvedAgentId);
|
|
787
|
+
}
|
|
788
|
+
agent == null ? void 0 : agent.addMessage(message);
|
|
789
|
+
if (followUp) {
|
|
790
|
+
try {
|
|
791
|
+
yield copilotkit.runAgent({ agent });
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.error("CopilotChat: runAgent failed", error);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (onSubmitMessage) {
|
|
797
|
+
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 : "";
|
|
798
|
+
onSubmitMessage(content);
|
|
799
|
+
}
|
|
800
|
+
}),
|
|
801
|
+
[agent, copilotkit, resolvedAgentId, onSubmitMessage]
|
|
802
|
+
);
|
|
803
|
+
const latestAppendFunc = useAsyncCallback(
|
|
804
|
+
(message, options) => __async(this, null, function* () {
|
|
805
|
+
return latestSendMessageFunc((0, import_runtime_client_gql2.gqlToAGUI)([message])[0], options);
|
|
806
|
+
}),
|
|
807
|
+
[latestSendMessageFunc]
|
|
808
|
+
);
|
|
809
|
+
const latestSetMessagesFunc = (0, import_react13.useCallback)(
|
|
810
|
+
(messages) => {
|
|
811
|
+
var _a2, _b2;
|
|
812
|
+
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
813
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
814
|
+
}
|
|
815
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
816
|
+
},
|
|
817
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
818
|
+
);
|
|
819
|
+
const latestReload = useUpdatedRef(reload);
|
|
820
|
+
const latestReloadFunc = useAsyncCallback(
|
|
821
|
+
(messageId) => __async(this, null, function* () {
|
|
822
|
+
var _a2;
|
|
823
|
+
onReloadMessages == null ? void 0 : onReloadMessages({
|
|
824
|
+
messageId,
|
|
825
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
826
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
827
|
+
});
|
|
828
|
+
return yield latestReload.current(messageId);
|
|
829
|
+
}),
|
|
830
|
+
[latestReload, agent, onReloadMessages]
|
|
831
|
+
);
|
|
832
|
+
const latestStopFunc = (0, import_react13.useCallback)(() => {
|
|
833
|
+
var _a2, _b2;
|
|
834
|
+
onStopGeneration == null ? void 0 : onStopGeneration({
|
|
835
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
836
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
837
|
+
});
|
|
838
|
+
return (_b2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _b2.call(agent);
|
|
839
|
+
}, [onStopGeneration, agent]);
|
|
840
|
+
const latestReset = useUpdatedRef(reset);
|
|
841
|
+
const latestResetFunc = (0, import_react13.useCallback)(() => {
|
|
842
|
+
return latestReset.current();
|
|
843
|
+
}, [latestReset]);
|
|
844
|
+
const lazyToolRendered = useLazyToolRenderer();
|
|
845
|
+
const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
|
|
846
|
+
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
847
|
+
copilotkit,
|
|
848
|
+
agent,
|
|
849
|
+
agentId: resolvedAgentId,
|
|
850
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
851
|
+
});
|
|
852
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
853
|
+
const resolvedMessages = (0, import_react13.useMemo)(() => {
|
|
854
|
+
let processedMessages = allMessages.map((message) => {
|
|
855
|
+
if (message.role !== "assistant") {
|
|
856
|
+
return message;
|
|
857
|
+
}
|
|
858
|
+
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
859
|
+
if (lazyRendered) {
|
|
860
|
+
const renderedGenUi = lazyRendered();
|
|
861
|
+
if (renderedGenUi) {
|
|
862
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
866
|
+
const customRender = renderCustomMessage == null ? void 0 : renderCustomMessage({
|
|
867
|
+
message,
|
|
868
|
+
position: "before"
|
|
869
|
+
});
|
|
870
|
+
if (customRender) {
|
|
871
|
+
return customRender;
|
|
872
|
+
}
|
|
873
|
+
return legacyCustomMessageRenderer == null ? void 0 : legacyCustomMessageRenderer({ message, position: "before" });
|
|
874
|
+
} : null;
|
|
875
|
+
if (bridgeRenderer) {
|
|
876
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: bridgeRenderer });
|
|
877
|
+
}
|
|
878
|
+
return message;
|
|
879
|
+
});
|
|
880
|
+
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
881
|
+
return processedMessages;
|
|
882
|
+
}, [
|
|
883
|
+
agent == null ? void 0 : agent.messages,
|
|
884
|
+
lazyToolRendered,
|
|
885
|
+
allMessages,
|
|
886
|
+
renderCustomMessage,
|
|
887
|
+
// legacyCustomMessageRenderer,
|
|
888
|
+
resolvedAgentId
|
|
889
|
+
]);
|
|
890
|
+
const renderedSuggestions = (0, import_react13.useMemo)(() => {
|
|
891
|
+
if (Array.isArray(suggestions)) {
|
|
892
|
+
return {
|
|
893
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
894
|
+
isLoading: false
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return currentSuggestions;
|
|
898
|
+
}, [suggestions, currentSuggestions]);
|
|
899
|
+
return {
|
|
900
|
+
messages: resolvedMessages,
|
|
901
|
+
sendMessage: latestSendMessageFunc,
|
|
902
|
+
appendMessage: latestAppendFunc,
|
|
903
|
+
setMessages: latestSetMessagesFunc,
|
|
904
|
+
reloadMessages: latestReloadFunc,
|
|
905
|
+
stopGeneration: latestStopFunc,
|
|
906
|
+
reset: latestResetFunc,
|
|
907
|
+
deleteMessage: latestDeleteFunc,
|
|
908
|
+
isAvailable: agentAvailable,
|
|
909
|
+
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
910
|
+
// mcpServers,
|
|
911
|
+
// setMcpServers,
|
|
912
|
+
suggestions: renderedSuggestions.suggestions,
|
|
913
|
+
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
914
|
+
generateSuggestions: () => __async(this, null, function* () {
|
|
915
|
+
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
916
|
+
}),
|
|
917
|
+
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
918
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
919
|
+
interrupt,
|
|
920
|
+
agent,
|
|
921
|
+
threadId
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function useUpdatedRef(value) {
|
|
925
|
+
const ref = (0, import_react13.useRef)(value);
|
|
926
|
+
(0, import_react13.useEffect)(() => {
|
|
927
|
+
ref.current = value;
|
|
928
|
+
}, [value]);
|
|
929
|
+
return ref;
|
|
930
|
+
}
|
|
931
|
+
function useLegacyCoagentRenderer({
|
|
932
|
+
copilotkit,
|
|
933
|
+
agent,
|
|
934
|
+
agentId,
|
|
935
|
+
threadId
|
|
936
|
+
}) {
|
|
937
|
+
return (0, import_react13.useMemo)(() => {
|
|
938
|
+
if (!copilotkit || !agent) {
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
return ({ message, position }) => {
|
|
942
|
+
var _a;
|
|
943
|
+
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
944
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
945
|
+
const runId = existingRunId || `pending:${message.id}`;
|
|
946
|
+
const messageIndex = Math.max(
|
|
947
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
948
|
+
0
|
|
949
|
+
);
|
|
950
|
+
const bridgeProps = {
|
|
951
|
+
message,
|
|
952
|
+
position,
|
|
953
|
+
runId,
|
|
954
|
+
messageIndex,
|
|
955
|
+
messageIndexInRun: 0,
|
|
956
|
+
numberOfMessagesInRun: 1,
|
|
957
|
+
agentId,
|
|
958
|
+
stateSnapshot: message.state
|
|
959
|
+
};
|
|
960
|
+
return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
961
|
+
};
|
|
962
|
+
}, [agent, agentId, copilotkit, threadId]);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// src/hooks/use-copilot-chat.ts
|
|
966
|
+
function useCopilotChat(options = {}) {
|
|
967
|
+
const {
|
|
968
|
+
visibleMessages,
|
|
969
|
+
appendMessage,
|
|
970
|
+
reloadMessages,
|
|
971
|
+
stopGeneration,
|
|
972
|
+
reset,
|
|
973
|
+
isLoading,
|
|
974
|
+
isAvailable,
|
|
975
|
+
runChatCompletion,
|
|
976
|
+
mcpServers,
|
|
977
|
+
setMcpServers
|
|
978
|
+
} = useCopilotChatInternal(options);
|
|
979
|
+
return {
|
|
980
|
+
visibleMessages,
|
|
981
|
+
appendMessage,
|
|
982
|
+
reloadMessages,
|
|
983
|
+
stopGeneration,
|
|
984
|
+
reset,
|
|
985
|
+
isLoading,
|
|
986
|
+
isAvailable,
|
|
987
|
+
runChatCompletion,
|
|
988
|
+
mcpServers,
|
|
989
|
+
setMcpServers
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/hooks/use-copilot-chat-headless_c.ts
|
|
994
|
+
var import_react15 = require("react");
|
|
995
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
996
|
+
var createNonFunctionalReturn = () => ({
|
|
997
|
+
visibleMessages: [],
|
|
998
|
+
messages: [],
|
|
999
|
+
sendMessage: () => __async(void 0, null, function* () {
|
|
1000
|
+
}),
|
|
1001
|
+
appendMessage: () => __async(void 0, null, function* () {
|
|
1002
|
+
}),
|
|
1003
|
+
setMessages: () => {
|
|
1004
|
+
},
|
|
1005
|
+
deleteMessage: () => {
|
|
1006
|
+
},
|
|
1007
|
+
reloadMessages: () => __async(void 0, null, function* () {
|
|
1008
|
+
}),
|
|
1009
|
+
stopGeneration: () => {
|
|
1010
|
+
},
|
|
1011
|
+
reset: () => {
|
|
1012
|
+
},
|
|
1013
|
+
isLoading: false,
|
|
1014
|
+
isAvailable: false,
|
|
1015
|
+
runChatCompletion: () => __async(void 0, null, function* () {
|
|
1016
|
+
return [];
|
|
1017
|
+
}),
|
|
1018
|
+
mcpServers: [],
|
|
1019
|
+
setMcpServers: () => {
|
|
1020
|
+
},
|
|
1021
|
+
suggestions: [],
|
|
1022
|
+
setSuggestions: () => {
|
|
1023
|
+
},
|
|
1024
|
+
generateSuggestions: () => __async(void 0, null, function* () {
|
|
1025
|
+
}),
|
|
1026
|
+
resetSuggestions: () => {
|
|
1027
|
+
},
|
|
1028
|
+
isLoadingSuggestions: false,
|
|
1029
|
+
interrupt: null
|
|
1030
|
+
});
|
|
1031
|
+
function useCopilotChatHeadless_c(options = {}) {
|
|
1032
|
+
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
1033
|
+
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
1034
|
+
const internalResult = useCopilotChatInternal(options);
|
|
1035
|
+
(0, import_react15.useEffect)(() => {
|
|
1036
|
+
if (!hasPublicApiKey) {
|
|
1037
|
+
setBannerError(
|
|
1038
|
+
new import_shared4.CopilotKitError({
|
|
1039
|
+
message: (
|
|
1040
|
+
// add link to documentation here
|
|
1041
|
+
"You're using useCopilotChatHeadless_c, a premium-only feature, which offers extensive headless chat capabilities. To continue, you'll need to provide a free public license key."
|
|
1042
|
+
),
|
|
1043
|
+
code: import_shared4.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
1044
|
+
severity: import_shared4.Severity.WARNING,
|
|
1045
|
+
visibility: import_shared4.ErrorVisibility.BANNER
|
|
1046
|
+
})
|
|
1047
|
+
);
|
|
1048
|
+
import_shared4.styledConsole.logCopilotKitPlatformMessage();
|
|
1049
|
+
} else {
|
|
1050
|
+
setBannerError(null);
|
|
1051
|
+
}
|
|
1052
|
+
}, [hasPublicApiKey]);
|
|
1053
|
+
if (hasPublicApiKey) {
|
|
1054
|
+
return internalResult;
|
|
1055
|
+
}
|
|
1056
|
+
return createNonFunctionalReturn();
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// src/hooks/use-copilot-action.ts
|
|
1060
|
+
var import_react22 = require("react");
|
|
1061
|
+
|
|
1062
|
+
// src/hooks/use-frontend-tool.ts
|
|
1063
|
+
var import_react16 = __toESM(require("react"));
|
|
1064
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1065
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1066
|
+
var import_react17 = require("@copilotkitnext/react");
|
|
1067
|
+
function useFrontendTool(tool, dependencies) {
|
|
1068
|
+
const { name, description, parameters, render, followUp } = tool;
|
|
1069
|
+
const zodParameters = (0, import_shared5.getZodParameters)(parameters);
|
|
1070
|
+
const normalizedRender = (() => {
|
|
1071
|
+
if (typeof render === "undefined") {
|
|
1072
|
+
return void 0;
|
|
1073
|
+
}
|
|
1074
|
+
if (typeof render === "string") {
|
|
1075
|
+
const staticRender = render;
|
|
1076
|
+
return () => import_react16.default.createElement(
|
|
1077
|
+
import_react16.default.Fragment,
|
|
1078
|
+
null,
|
|
1079
|
+
staticRender
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
return (args) => {
|
|
1083
|
+
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
1084
|
+
result: typeof args.result === "string" ? (0, import_shared6.parseJson)(args.result, args.result) : args.result
|
|
1085
|
+
});
|
|
1086
|
+
const rendered = render(renderArgs);
|
|
1087
|
+
if (typeof rendered === "string") {
|
|
1088
|
+
return import_react16.default.createElement(import_react16.default.Fragment, null, rendered);
|
|
1089
|
+
}
|
|
1090
|
+
return rendered != null ? rendered : null;
|
|
1091
|
+
};
|
|
1092
|
+
})();
|
|
1093
|
+
const handlerRef = (0, import_react16.useRef)(tool.handler);
|
|
1094
|
+
(0, import_react16.useEffect)(() => {
|
|
1095
|
+
handlerRef.current = tool.handler;
|
|
1096
|
+
}, [tool.handler, ...dependencies != null ? dependencies : []]);
|
|
1097
|
+
const normalizedHandler = tool.handler ? (args) => {
|
|
1098
|
+
var _a;
|
|
1099
|
+
return (_a = handlerRef.current) == null ? void 0 : _a.call(handlerRef, args);
|
|
1100
|
+
} : void 0;
|
|
1101
|
+
(0, import_react17.useFrontendTool)({
|
|
1102
|
+
name,
|
|
1103
|
+
description,
|
|
1104
|
+
parameters: zodParameters,
|
|
1105
|
+
handler: normalizedHandler,
|
|
1106
|
+
followUp,
|
|
1107
|
+
render: normalizedRender
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/hooks/use-render-tool-call.ts
|
|
1112
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1113
|
+
var import_react18 = require("react");
|
|
1114
|
+
var import_react19 = require("@copilotkitnext/react");
|
|
1115
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1116
|
+
function useRenderToolCall2(tool, dependencies) {
|
|
1117
|
+
const { copilotkit } = (0, import_react19.useCopilotKit)();
|
|
1118
|
+
const hasAddedRef = (0, import_react18.useRef)(false);
|
|
1119
|
+
(0, import_react18.useEffect)(() => {
|
|
1120
|
+
const { name, parameters, render } = tool;
|
|
1121
|
+
const zodParameters = (0, import_shared7.getZodParameters)(parameters);
|
|
1122
|
+
const renderToolCall = name === "*" ? (0, import_react19.defineToolCallRenderer)({
|
|
1123
|
+
name: "*",
|
|
1124
|
+
render: (args) => {
|
|
1125
|
+
return render(__spreadProps(__spreadValues({}, args), {
|
|
1126
|
+
result: args.result ? (0, import_shared8.parseJson)(args.result, args.result) : args.result
|
|
1127
|
+
}));
|
|
1128
|
+
}
|
|
1129
|
+
}) : (0, import_react19.defineToolCallRenderer)({
|
|
1130
|
+
name,
|
|
1131
|
+
args: zodParameters,
|
|
1132
|
+
render: (args) => {
|
|
1133
|
+
return render(__spreadProps(__spreadValues({}, args), {
|
|
1134
|
+
result: args.result ? (0, import_shared8.parseJson)(args.result, args.result) : args.result
|
|
1135
|
+
}));
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
const existingIndex = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
|
|
1139
|
+
if (existingIndex !== -1) {
|
|
1140
|
+
copilotkit.renderToolCalls.splice(existingIndex, 1);
|
|
1141
|
+
}
|
|
1142
|
+
copilotkit.renderToolCalls.push(renderToolCall);
|
|
1143
|
+
hasAddedRef.current = true;
|
|
1144
|
+
return () => {
|
|
1145
|
+
if (hasAddedRef.current) {
|
|
1146
|
+
const index = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
|
|
1147
|
+
if (index !== -1) {
|
|
1148
|
+
copilotkit.renderToolCalls.splice(index, 1);
|
|
1149
|
+
}
|
|
1150
|
+
hasAddedRef.current = false;
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
}, [tool, ...dependencies != null ? dependencies : []]);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// src/hooks/use-human-in-the-loop.ts
|
|
1157
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1158
|
+
var import_react20 = require("@copilotkitnext/react");
|
|
1159
|
+
var import_core = require("@copilotkitnext/core");
|
|
1160
|
+
var import_react21 = __toESM(require("react"));
|
|
1161
|
+
function useHumanInTheLoop(tool, dependencies) {
|
|
1162
|
+
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
1163
|
+
const { name, description, parameters, followUp } = toolRest;
|
|
1164
|
+
const zodParameters = (0, import_shared9.getZodParameters)(parameters);
|
|
1165
|
+
const renderRef = (0, import_react21.useRef)(null);
|
|
1166
|
+
(0, import_react21.useEffect)(() => {
|
|
1167
|
+
renderRef.current = (args) => {
|
|
1168
|
+
if (typeof render === "string") {
|
|
1169
|
+
return import_react21.default.createElement(import_react21.default.Fragment, null, render);
|
|
1170
|
+
}
|
|
1171
|
+
if (!render) {
|
|
1172
|
+
return null;
|
|
1173
|
+
}
|
|
1174
|
+
const renderProps = (() => {
|
|
1175
|
+
const mappedArgs = args.args;
|
|
1176
|
+
switch (args.status) {
|
|
1177
|
+
case import_core.ToolCallStatus.InProgress:
|
|
1178
|
+
return {
|
|
1179
|
+
args: mappedArgs,
|
|
1180
|
+
respond: args.respond,
|
|
1181
|
+
status: args.status,
|
|
1182
|
+
handler: void 0
|
|
1183
|
+
};
|
|
1184
|
+
case import_core.ToolCallStatus.Executing:
|
|
1185
|
+
return {
|
|
1186
|
+
args: mappedArgs,
|
|
1187
|
+
respond: args.respond,
|
|
1188
|
+
status: args.status,
|
|
1189
|
+
handler: () => {
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
case import_core.ToolCallStatus.Complete:
|
|
1193
|
+
return {
|
|
1194
|
+
args: mappedArgs,
|
|
1195
|
+
respond: args.respond,
|
|
1196
|
+
status: args.status,
|
|
1197
|
+
result: args.result ? (0, import_shared9.parseJson)(args.result, args.result) : args.result,
|
|
1198
|
+
handler: void 0
|
|
1199
|
+
};
|
|
1200
|
+
default:
|
|
1201
|
+
throw new import_shared9.CopilotKitError({
|
|
1202
|
+
code: import_shared9.CopilotKitErrorCode.UNKNOWN,
|
|
1203
|
+
message: `Invalid tool call status: ${args.status}`
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
})();
|
|
1207
|
+
const rendered = render(renderProps);
|
|
1208
|
+
if (typeof rendered === "string") {
|
|
1209
|
+
return import_react21.default.createElement(import_react21.default.Fragment, null, rendered);
|
|
1210
|
+
}
|
|
1211
|
+
return rendered != null ? rendered : null;
|
|
1212
|
+
};
|
|
1213
|
+
}, [render, ...dependencies != null ? dependencies : []]);
|
|
1214
|
+
(0, import_react20.useHumanInTheLoop)({
|
|
1215
|
+
name,
|
|
1216
|
+
description,
|
|
1217
|
+
followUp,
|
|
1218
|
+
parameters: zodParameters,
|
|
1219
|
+
render: (args) => {
|
|
1220
|
+
var _a2, _b;
|
|
1221
|
+
return (_b = (_a2 = renderRef.current) == null ? void 0 : _a2.call(renderRef, args)) != null ? _b : null;
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// src/hooks/use-copilot-action.ts
|
|
1227
|
+
function getActionConfig(action) {
|
|
1228
|
+
if (action.name === "*") {
|
|
1229
|
+
return {
|
|
1230
|
+
type: "render",
|
|
1231
|
+
action
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
1235
|
+
let render = action.render;
|
|
1236
|
+
if (!render && "renderAndWaitForResponse" in action) {
|
|
1237
|
+
render = action.renderAndWaitForResponse;
|
|
1238
|
+
}
|
|
1239
|
+
if (!render && "renderAndWait" in action) {
|
|
1240
|
+
render = action.renderAndWait;
|
|
1241
|
+
}
|
|
1242
|
+
return {
|
|
1243
|
+
type: "hitl",
|
|
1244
|
+
action: __spreadProps(__spreadValues({}, action), { render })
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
if ("available" in action) {
|
|
1248
|
+
if (action.available === "enabled" || action.available === "remote") {
|
|
1249
|
+
return {
|
|
1250
|
+
type: "frontend",
|
|
1251
|
+
action
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
if (action.available === "frontend" || action.available === "disabled") {
|
|
1255
|
+
return {
|
|
1256
|
+
type: "render",
|
|
1257
|
+
action
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
if ("handler" in action) {
|
|
1262
|
+
return {
|
|
1263
|
+
type: "frontend",
|
|
1264
|
+
action
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
throw new Error("Invalid action configuration");
|
|
1268
|
+
}
|
|
1269
|
+
function useCopilotAction(action, dependencies) {
|
|
1270
|
+
const [initialActionConfig] = (0, import_react22.useState)(getActionConfig(action));
|
|
1271
|
+
const currentActionConfig = getActionConfig(action);
|
|
1272
|
+
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
1273
|
+
throw new Error("Action configuration changed between renders");
|
|
1274
|
+
}
|
|
1275
|
+
switch (currentActionConfig.type) {
|
|
1276
|
+
case "render":
|
|
1277
|
+
return useRenderToolCall2(currentActionConfig.action, dependencies);
|
|
1278
|
+
case "hitl":
|
|
1279
|
+
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
1280
|
+
case "frontend":
|
|
1281
|
+
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
1282
|
+
default:
|
|
1283
|
+
throw new Error("Invalid action configuration");
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
// src/hooks/use-coagent-state-render.ts
|
|
1288
|
+
var import_react23 = require("react");
|
|
1289
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1290
|
+
function useCoAgentStateRender(action, dependencies) {
|
|
1291
|
+
const { chatComponentsCache, availableAgents } = (0, import_react23.useContext)(CopilotContext);
|
|
1292
|
+
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
1293
|
+
const idRef = (0, import_react23.useRef)((0, import_shared10.randomId)());
|
|
1294
|
+
const { setBannerError, addToast } = useToast();
|
|
1295
|
+
(0, import_react23.useEffect)(() => {
|
|
1296
|
+
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
1297
|
+
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1298
|
+
const agentError = new import_shared10.CopilotKitAgentDiscoveryError({
|
|
1299
|
+
agentName: action.name,
|
|
1300
|
+
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1301
|
+
});
|
|
1302
|
+
setBannerError(agentError);
|
|
1303
|
+
}
|
|
1304
|
+
}, [availableAgents]);
|
|
1305
|
+
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1306
|
+
if (dependencies === void 0) {
|
|
1307
|
+
if (coAgentStateRenders[idRef.current]) {
|
|
1308
|
+
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
1309
|
+
if (typeof action.render === "function") {
|
|
1310
|
+
if (chatComponentsCache.current !== null) {
|
|
1311
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
(0, import_react23.useEffect)(() => {
|
|
1317
|
+
const currentId = idRef.current;
|
|
1318
|
+
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
1319
|
+
if (id === currentId)
|
|
1320
|
+
return false;
|
|
1321
|
+
if (otherAction.name !== action.name)
|
|
1322
|
+
return false;
|
|
1323
|
+
const hasNodeName = !!action.nodeName;
|
|
1324
|
+
const hasOtherNodeName = !!otherAction.nodeName;
|
|
1325
|
+
if (!hasNodeName && !hasOtherNodeName)
|
|
1326
|
+
return true;
|
|
1327
|
+
if (hasNodeName !== hasOtherNodeName)
|
|
1328
|
+
return false;
|
|
1329
|
+
return action.nodeName === otherAction.nodeName;
|
|
1330
|
+
});
|
|
1331
|
+
if (hasDuplicate) {
|
|
1332
|
+
const message = action.nodeName ? `Found multiple state renders for agent ${action.name} and node ${action.nodeName}. State renders might get overridden` : `Found multiple state renders for agent ${action.name}. State renders might get overridden`;
|
|
1333
|
+
addToast({
|
|
1334
|
+
type: "warning",
|
|
1335
|
+
message,
|
|
1336
|
+
id: `dup-action-${action.name}`
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
}, [coAgentStateRenders]);
|
|
1340
|
+
(0, import_react23.useEffect)(() => {
|
|
1341
|
+
setCoAgentStateRender(idRef.current, action);
|
|
1342
|
+
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1343
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1344
|
+
}
|
|
1345
|
+
return () => {
|
|
1346
|
+
removeCoAgentStateRender(idRef.current);
|
|
1347
|
+
};
|
|
1348
|
+
}, [
|
|
1349
|
+
setCoAgentStateRender,
|
|
1350
|
+
removeCoAgentStateRender,
|
|
1351
|
+
action.name,
|
|
1352
|
+
// include render only if it's a string
|
|
1353
|
+
typeof action.render === "string" ? action.render : void 0,
|
|
1354
|
+
// dependencies set by the developer
|
|
1355
|
+
...dependencies || []
|
|
1356
|
+
]);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
// src/hooks/use-make-copilot-document-readable.ts
|
|
1360
|
+
var import_react24 = require("react");
|
|
1361
|
+
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1362
|
+
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1363
|
+
const idRef = (0, import_react24.useRef)(void 0);
|
|
1364
|
+
(0, import_react24.useEffect)(() => {
|
|
1365
|
+
const id = addDocumentContext(document, categories);
|
|
1366
|
+
idRef.current = id;
|
|
1367
|
+
return () => {
|
|
1368
|
+
removeDocumentContext(id);
|
|
1369
|
+
};
|
|
1370
|
+
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
1371
|
+
return idRef.current;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// src/hooks/use-copilot-readable.ts
|
|
1375
|
+
var import_react25 = require("@copilotkitnext/react");
|
|
1376
|
+
var import_react26 = require("react");
|
|
1377
|
+
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
1378
|
+
const { copilotkit } = (0, import_react25.useCopilotKit)();
|
|
1379
|
+
const ctxIdRef = (0, import_react26.useRef)(void 0);
|
|
1380
|
+
(0, import_react26.useEffect)(() => {
|
|
1381
|
+
if (!copilotkit)
|
|
1382
|
+
return;
|
|
1383
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
1384
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
1385
|
+
});
|
|
1386
|
+
if (found) {
|
|
1387
|
+
ctxIdRef.current = found[0];
|
|
1388
|
+
if (available === "disabled")
|
|
1389
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
if (!found && available === "disabled")
|
|
1393
|
+
return;
|
|
1394
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
1395
|
+
description,
|
|
1396
|
+
value: (convert != null ? convert : JSON.stringify)(value)
|
|
1397
|
+
});
|
|
1398
|
+
return () => {
|
|
1399
|
+
if (!ctxIdRef.current)
|
|
1400
|
+
return;
|
|
1401
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
1402
|
+
};
|
|
1403
|
+
}, [description, value, convert]);
|
|
1404
|
+
return ctxIdRef.current;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// src/hooks/use-coagent.ts
|
|
1408
|
+
var import_react27 = require("react");
|
|
1409
|
+
var import_react28 = require("@copilotkitnext/react");
|
|
1410
|
+
function useCoAgent(options) {
|
|
1411
|
+
const { agent } = (0, import_react28.useAgent)({ agentId: options.name });
|
|
1412
|
+
const { copilotkit } = (0, import_react28.useCopilotKit)();
|
|
1413
|
+
const nodeName = useAgentNodeName(options.name);
|
|
1414
|
+
const handleStateUpdate = (0, import_react27.useCallback)(
|
|
1415
|
+
(newState) => {
|
|
1416
|
+
if (!agent)
|
|
1417
|
+
return;
|
|
1418
|
+
if (typeof newState === "function") {
|
|
1419
|
+
const updater = newState;
|
|
1420
|
+
agent.setState(updater(agent.state));
|
|
1421
|
+
} else {
|
|
1422
|
+
agent.setState(__spreadValues(__spreadValues({}, agent.state), newState));
|
|
1423
|
+
}
|
|
1424
|
+
},
|
|
1425
|
+
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
1426
|
+
);
|
|
1427
|
+
(0, import_react27.useEffect)(() => {
|
|
1428
|
+
var _a;
|
|
1429
|
+
if (!options.config && !options.configurable)
|
|
1430
|
+
return;
|
|
1431
|
+
let config = (_a = options.config) != null ? _a : {};
|
|
1432
|
+
if (options.configurable) {
|
|
1433
|
+
config = __spreadProps(__spreadValues({}, config), {
|
|
1434
|
+
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
copilotkit.setProperties(config);
|
|
1438
|
+
}, [options.config, options.configurable]);
|
|
1439
|
+
const externalStateStr = (0, import_react27.useMemo)(
|
|
1440
|
+
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1441
|
+
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
1442
|
+
);
|
|
1443
|
+
(0, import_react27.useEffect)(() => {
|
|
1444
|
+
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
1445
|
+
handleStateUpdate(options.state);
|
|
1446
|
+
}
|
|
1447
|
+
}, [agent, externalStateStr, handleStateUpdate]);
|
|
1448
|
+
const hasStateValues = (0, import_react27.useCallback)((value) => {
|
|
1449
|
+
return Boolean(value && Object.keys(value).length);
|
|
1450
|
+
}, []);
|
|
1451
|
+
const initialStateRef = (0, import_react27.useRef)(
|
|
1452
|
+
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
1453
|
+
);
|
|
1454
|
+
(0, import_react27.useEffect)(() => {
|
|
1455
|
+
if (isExternalStateManagement(options)) {
|
|
1456
|
+
initialStateRef.current = options.state;
|
|
1457
|
+
} else if ("initialState" in options) {
|
|
1458
|
+
initialStateRef.current = options.initialState;
|
|
1459
|
+
}
|
|
1460
|
+
}, [
|
|
1461
|
+
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
1462
|
+
]);
|
|
1463
|
+
(0, import_react27.useEffect)(() => {
|
|
1464
|
+
if (!agent)
|
|
1465
|
+
return;
|
|
1466
|
+
const subscriber = {
|
|
1467
|
+
onStateChanged: (args) => {
|
|
1468
|
+
if (isExternalStateManagement(options)) {
|
|
1469
|
+
options.setState(args.state);
|
|
1470
|
+
}
|
|
1471
|
+
},
|
|
1472
|
+
onRunInitialized: (args) => {
|
|
1473
|
+
const runHasState = hasStateValues(args.state);
|
|
1474
|
+
if (runHasState) {
|
|
1475
|
+
handleStateUpdate(args.state);
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
if (hasStateValues(agent.state)) {
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
if (initialStateRef.current !== void 0) {
|
|
1482
|
+
handleStateUpdate(initialStateRef.current);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
const subscription = agent.subscribe(subscriber);
|
|
1487
|
+
return () => {
|
|
1488
|
+
subscription.unsubscribe();
|
|
1489
|
+
};
|
|
1490
|
+
}, [agent, handleStateUpdate, hasStateValues]);
|
|
1491
|
+
return (0, import_react27.useMemo)(() => {
|
|
1492
|
+
var _a, _b, _c;
|
|
1493
|
+
if (!agent) {
|
|
1494
|
+
const noop = () => {
|
|
1495
|
+
};
|
|
1496
|
+
const noopAsync = () => __async(this, null, function* () {
|
|
1497
|
+
});
|
|
1498
|
+
const initialState = (
|
|
1499
|
+
// prefer externally provided state if available
|
|
1500
|
+
(_b = (_a = "state" in options && options.state) != null ? _a : (
|
|
1501
|
+
// then initialState if provided
|
|
1502
|
+
"initialState" in options && options.initialState
|
|
1503
|
+
)) != null ? _b : {}
|
|
1504
|
+
);
|
|
1505
|
+
return {
|
|
1506
|
+
name: options.name,
|
|
1507
|
+
nodeName,
|
|
1508
|
+
threadId: void 0,
|
|
1509
|
+
running: false,
|
|
1510
|
+
state: initialState,
|
|
1511
|
+
setState: noop,
|
|
1512
|
+
start: noop,
|
|
1513
|
+
stop: noop,
|
|
1514
|
+
run: noopAsync
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
return {
|
|
1518
|
+
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
1519
|
+
nodeName,
|
|
1520
|
+
threadId: agent.threadId,
|
|
1521
|
+
running: agent.isRunning,
|
|
1522
|
+
state: agent.state,
|
|
1523
|
+
setState: handleStateUpdate,
|
|
1524
|
+
// TODO: start and run both have same thing. need to figure out
|
|
1525
|
+
start: agent.runAgent,
|
|
1526
|
+
stop: agent.abortRun,
|
|
1527
|
+
run: agent.runAgent
|
|
1528
|
+
};
|
|
1529
|
+
}, [
|
|
1530
|
+
agent == null ? void 0 : agent.state,
|
|
1531
|
+
agent == null ? void 0 : agent.runAgent,
|
|
1532
|
+
agent == null ? void 0 : agent.abortRun,
|
|
1533
|
+
agent == null ? void 0 : agent.runAgent,
|
|
1534
|
+
agent == null ? void 0 : agent.threadId,
|
|
1535
|
+
agent == null ? void 0 : agent.isRunning,
|
|
1536
|
+
agent == null ? void 0 : agent.agentId,
|
|
1537
|
+
handleStateUpdate,
|
|
1538
|
+
options.name
|
|
1539
|
+
]);
|
|
1540
|
+
}
|
|
1541
|
+
var isExternalStateManagement = (options) => {
|
|
1542
|
+
return "state" in options && "setState" in options;
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
1546
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1547
|
+
var import_react29 = require("react");
|
|
1548
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1549
|
+
var useCopilotRuntimeClient = (options) => {
|
|
1550
|
+
const { setBannerError } = useToast();
|
|
1551
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
1552
|
+
const lastStructuredErrorRef = (0, import_react29.useRef)(null);
|
|
1553
|
+
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
1554
|
+
try {
|
|
1555
|
+
const errorEvent = {
|
|
1556
|
+
type: "error",
|
|
1557
|
+
timestamp: Date.now(),
|
|
1558
|
+
context: {
|
|
1559
|
+
source: "ui",
|
|
1560
|
+
request: {
|
|
1561
|
+
operation: "runtimeClient",
|
|
1562
|
+
url: runtimeOptions.url,
|
|
1563
|
+
startTime: Date.now()
|
|
1564
|
+
},
|
|
1565
|
+
technical: {
|
|
1566
|
+
environment: "browser",
|
|
1567
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
1568
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
1569
|
+
}
|
|
1570
|
+
},
|
|
1571
|
+
error
|
|
1572
|
+
};
|
|
1573
|
+
yield onError(errorEvent);
|
|
1574
|
+
} catch (error2) {
|
|
1575
|
+
console.error("Error in onError handler:", error2);
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
const runtimeClient = (0, import_react29.useMemo)(() => {
|
|
1579
|
+
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
1580
|
+
handleGQLErrors: (error) => {
|
|
1581
|
+
var _a2;
|
|
1582
|
+
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
1583
|
+
const graphQLErrors = error.graphQLErrors;
|
|
1584
|
+
const routeError = (gqlError) => {
|
|
1585
|
+
const extensions = gqlError.extensions;
|
|
1586
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
1587
|
+
if (visibility === import_shared11.ErrorVisibility.SILENT) {
|
|
1588
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const now = Date.now();
|
|
1592
|
+
const errorMessage = gqlError.message;
|
|
1593
|
+
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
1597
|
+
const ckError = createStructuredError(gqlError);
|
|
1598
|
+
if (ckError) {
|
|
1599
|
+
setBannerError(ckError);
|
|
1600
|
+
traceUIError(ckError, gqlError);
|
|
1601
|
+
} else {
|
|
1602
|
+
const fallbackError = new import_shared11.CopilotKitError({
|
|
1603
|
+
message: gqlError.message,
|
|
1604
|
+
code: import_shared11.CopilotKitErrorCode.UNKNOWN
|
|
1605
|
+
});
|
|
1606
|
+
setBannerError(fallbackError);
|
|
1607
|
+
traceUIError(fallbackError, gqlError);
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
graphQLErrors.forEach(routeError);
|
|
1611
|
+
} else {
|
|
1612
|
+
const fallbackError = new import_shared11.CopilotKitError({
|
|
1613
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
1614
|
+
code: import_shared11.CopilotKitErrorCode.UNKNOWN
|
|
1615
|
+
});
|
|
1616
|
+
setBannerError(fallbackError);
|
|
1617
|
+
traceUIError(fallbackError, error);
|
|
1618
|
+
}
|
|
1619
|
+
},
|
|
1620
|
+
handleGQLWarning: (message) => {
|
|
1621
|
+
console.warn(message);
|
|
1622
|
+
const warningError = new import_shared11.CopilotKitError({
|
|
1623
|
+
message,
|
|
1624
|
+
code: import_shared11.CopilotKitErrorCode.UNKNOWN
|
|
1625
|
+
});
|
|
1626
|
+
setBannerError(warningError);
|
|
1627
|
+
}
|
|
1628
|
+
}));
|
|
1629
|
+
}, [runtimeOptions, setBannerError, onError]);
|
|
1630
|
+
return runtimeClient;
|
|
1631
|
+
};
|
|
1632
|
+
function createStructuredError(gqlError) {
|
|
1633
|
+
var _a, _b, _c;
|
|
1634
|
+
const extensions = gqlError.extensions;
|
|
1635
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
1636
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
1637
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
1638
|
+
if (code) {
|
|
1639
|
+
return new import_shared11.CopilotKitError({ message, code });
|
|
1640
|
+
}
|
|
1641
|
+
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
1642
|
+
return new import_shared11.CopilotKitApiDiscoveryError({ message });
|
|
1643
|
+
}
|
|
1644
|
+
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
1645
|
+
return new import_shared11.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
1646
|
+
}
|
|
1647
|
+
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
1648
|
+
return new import_shared11.CopilotKitAgentDiscoveryError({
|
|
1649
|
+
agentName: "",
|
|
1650
|
+
availableAgents: []
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
return null;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
// src/hooks/use-copilot-authenticated-action.ts
|
|
1657
|
+
var import_react30 = require("react");
|
|
1658
|
+
var import_react31 = __toESM(require("react"));
|
|
1659
|
+
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
1660
|
+
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
1661
|
+
const pendingActionRef = (0, import_react30.useRef)(null);
|
|
1662
|
+
const executeAction = (0, import_react30.useCallback)(
|
|
1663
|
+
(props) => {
|
|
1664
|
+
if (typeof action.render === "function") {
|
|
1665
|
+
return action.render(props);
|
|
1666
|
+
}
|
|
1667
|
+
return action.render || import_react31.default.createElement(import_react30.Fragment);
|
|
1668
|
+
},
|
|
1669
|
+
[action]
|
|
1670
|
+
);
|
|
1671
|
+
const wrappedRender = (0, import_react30.useCallback)(
|
|
1672
|
+
(props) => {
|
|
1673
|
+
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
1674
|
+
(state) => state.status === "authenticated"
|
|
1675
|
+
);
|
|
1676
|
+
if (!isAuthenticated) {
|
|
1677
|
+
pendingActionRef.current = props;
|
|
1678
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react31.default.createElement(authConfig_c.SignInComponent, {
|
|
1679
|
+
onSignInComplete: (authState) => {
|
|
1680
|
+
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
1681
|
+
if (pendingActionRef.current) {
|
|
1682
|
+
executeAction(pendingActionRef.current);
|
|
1683
|
+
pendingActionRef.current = null;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}) : import_react31.default.createElement(import_react30.Fragment);
|
|
1687
|
+
}
|
|
1688
|
+
return executeAction(props);
|
|
1689
|
+
},
|
|
1690
|
+
[action, authStates_c, setAuthStates_c]
|
|
1691
|
+
);
|
|
1692
|
+
useCopilotAction(
|
|
1693
|
+
__spreadProps(__spreadValues({}, action), {
|
|
1694
|
+
render: wrappedRender
|
|
1695
|
+
}),
|
|
1696
|
+
dependencies
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// src/hooks/use-langgraph-interrupt.ts
|
|
1701
|
+
var import_react32 = require("react");
|
|
1702
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
1703
|
+
function useLangGraphInterrupt(action, dependencies) {
|
|
1704
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react32.useContext)(CopilotContext);
|
|
1705
|
+
const { addToast } = useToast();
|
|
1706
|
+
const actionId = (0, import_shared12.dataToUUID)(action, "lgAction");
|
|
1707
|
+
(0, import_react32.useEffect)(() => {
|
|
1708
|
+
if (!action)
|
|
1709
|
+
return;
|
|
1710
|
+
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
1711
|
+
return () => {
|
|
1712
|
+
removeInterruptAction(actionId);
|
|
1713
|
+
};
|
|
1714
|
+
}, [setInterruptAction, removeInterruptAction, threadId, actionId, ...dependencies || []]);
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
// src/hooks/use-copilot-additional-instructions.ts
|
|
1718
|
+
var import_react33 = require("react");
|
|
1719
|
+
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
1720
|
+
const { setAdditionalInstructions } = useCopilotContext();
|
|
1721
|
+
(0, import_react33.useEffect)(() => {
|
|
1722
|
+
if (available === "disabled")
|
|
1723
|
+
return;
|
|
1724
|
+
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
1725
|
+
return () => {
|
|
1726
|
+
setAdditionalInstructions(
|
|
1727
|
+
(prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter((instruction) => instruction !== instructions)) || []
|
|
1728
|
+
);
|
|
1729
|
+
};
|
|
1730
|
+
}, [available, instructions, setAdditionalInstructions, ...dependencies || []]);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// src/hooks/use-default-tool.ts
|
|
1734
|
+
function useDefaultTool(tool, dependencies) {
|
|
1735
|
+
useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
1739
|
+
var import_react34 = require("@copilotkitnext/react");
|
|
1740
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
1741
|
+
var _a, _b;
|
|
1742
|
+
const existingConfig = (0, import_react34.useCopilotChatConfiguration)();
|
|
1743
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
1744
|
+
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
1745
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
1746
|
+
available,
|
|
1747
|
+
consumerAgentId: resolvedAgentId
|
|
1748
|
+
// Use chatConfig.agentId here
|
|
1749
|
+
});
|
|
1750
|
+
(0, import_react34.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
1751
|
+
}
|
|
1752
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1753
|
+
0 && (module.exports = {
|
|
1754
|
+
useCoAgent,
|
|
1755
|
+
useCoAgentStateRender,
|
|
1756
|
+
useCopilotAction,
|
|
1757
|
+
useCopilotAdditionalInstructions,
|
|
1758
|
+
useCopilotAuthenticatedAction_c,
|
|
1759
|
+
useCopilotChat,
|
|
1760
|
+
useCopilotChatHeadless_c,
|
|
1761
|
+
useCopilotChatInternal,
|
|
1762
|
+
useCopilotChatSuggestions,
|
|
1763
|
+
useCopilotReadable,
|
|
1764
|
+
useCopilotRuntimeClient,
|
|
1765
|
+
useDefaultTool,
|
|
1766
|
+
useFrontendTool,
|
|
1767
|
+
useHumanInTheLoop,
|
|
1768
|
+
useLangGraphInterrupt,
|
|
1769
|
+
useLangGraphInterruptRender,
|
|
1770
|
+
useLazyToolRenderer,
|
|
1771
|
+
useMakeCopilotDocumentReadable,
|
|
1772
|
+
useRenderToolCall
|
|
1773
|
+
});
|
|
1774
|
+
//# sourceMappingURL=index.js.map
|