@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,3528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
27
|
+
var __objRest = (source, exclude) => {
|
|
28
|
+
var target = {};
|
|
29
|
+
for (var prop in source)
|
|
30
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
if (source != null && __getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
34
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
35
|
+
target[prop] = source[prop];
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
};
|
|
39
|
+
var __export = (target, all) => {
|
|
40
|
+
for (var name in all)
|
|
41
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
42
|
+
};
|
|
43
|
+
var __copyProps = (to, from, except, desc) => {
|
|
44
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
|
+
for (let key of __getOwnPropNames(from))
|
|
46
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
47
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
48
|
+
}
|
|
49
|
+
return to;
|
|
50
|
+
};
|
|
51
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
52
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
53
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
54
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
55
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
56
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
57
|
+
mod
|
|
58
|
+
));
|
|
59
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
60
|
+
var __async = (__this, __arguments, generator) => {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
var fulfilled = (value) => {
|
|
63
|
+
try {
|
|
64
|
+
step(generator.next(value));
|
|
65
|
+
} catch (e) {
|
|
66
|
+
reject(e);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var rejected = (value) => {
|
|
70
|
+
try {
|
|
71
|
+
step(generator.throw(value));
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
77
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/index.tsx
|
|
82
|
+
var src_exports = {};
|
|
83
|
+
__export(src_exports, {
|
|
84
|
+
CoAgentStateRendersContext: () => CoAgentStateRendersContext,
|
|
85
|
+
CoAgentStateRendersProvider: () => CoAgentStateRendersProvider,
|
|
86
|
+
CopilotContext: () => CopilotContext,
|
|
87
|
+
CopilotKit: () => CopilotKit,
|
|
88
|
+
CopilotMessagesContext: () => CopilotMessagesContext,
|
|
89
|
+
CopilotTask: () => CopilotTask,
|
|
90
|
+
SUGGESTION_RETRY_CONFIG: () => SUGGESTION_RETRY_CONFIG,
|
|
91
|
+
ThreadsContext: () => ThreadsContext,
|
|
92
|
+
ThreadsProvider: () => ThreadsProvider,
|
|
93
|
+
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
94
|
+
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
95
|
+
useCoAgent: () => useCoAgent,
|
|
96
|
+
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
97
|
+
useCoAgentStateRenders: () => useCoAgentStateRenders,
|
|
98
|
+
useCopilotAction: () => useCopilotAction,
|
|
99
|
+
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
100
|
+
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
101
|
+
useCopilotChat: () => useCopilotChat,
|
|
102
|
+
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
103
|
+
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
104
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
105
|
+
useCopilotContext: () => useCopilotContext,
|
|
106
|
+
useCopilotMessagesContext: () => useCopilotMessagesContext,
|
|
107
|
+
useCopilotReadable: () => useCopilotReadable,
|
|
108
|
+
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
109
|
+
useDefaultTool: () => useDefaultTool,
|
|
110
|
+
useFrontendTool: () => useFrontendTool,
|
|
111
|
+
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
112
|
+
useLangGraphInterrupt: () => useLangGraphInterrupt,
|
|
113
|
+
useLangGraphInterruptRender: () => useLangGraphInterruptRender,
|
|
114
|
+
useLazyToolRenderer: () => useLazyToolRenderer,
|
|
115
|
+
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
116
|
+
useRenderToolCall: () => useRenderToolCall2,
|
|
117
|
+
useThreads: () => useThreads
|
|
118
|
+
});
|
|
119
|
+
module.exports = __toCommonJS(src_exports);
|
|
120
|
+
|
|
121
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
122
|
+
var import_react15 = require("react");
|
|
123
|
+
var import_react16 = require("@copilotkitnext/react");
|
|
124
|
+
|
|
125
|
+
// src/context/copilot-context.tsx
|
|
126
|
+
var import_react = __toESM(require("react"));
|
|
127
|
+
var emptyCopilotContext = {
|
|
128
|
+
actions: {},
|
|
129
|
+
setAction: () => {
|
|
130
|
+
},
|
|
131
|
+
removeAction: () => {
|
|
132
|
+
},
|
|
133
|
+
setRegisteredActions: () => "",
|
|
134
|
+
removeRegisteredAction: () => {
|
|
135
|
+
},
|
|
136
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
137
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
138
|
+
addContext: () => "",
|
|
139
|
+
removeContext: () => {
|
|
140
|
+
},
|
|
141
|
+
getAllContext: () => [],
|
|
142
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
143
|
+
})),
|
|
144
|
+
isLoading: false,
|
|
145
|
+
setIsLoading: () => returnAndThrowInDebug(false),
|
|
146
|
+
chatInstructions: "",
|
|
147
|
+
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
148
|
+
additionalInstructions: [],
|
|
149
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
150
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
151
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
152
|
+
removeDocumentContext: () => {
|
|
153
|
+
},
|
|
154
|
+
copilotApiConfig: new class {
|
|
155
|
+
get chatApiEndpoint() {
|
|
156
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
157
|
+
}
|
|
158
|
+
get headers() {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
get body() {
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
}(),
|
|
165
|
+
chatSuggestionConfiguration: {},
|
|
166
|
+
addChatSuggestionConfiguration: () => {
|
|
167
|
+
},
|
|
168
|
+
removeChatSuggestionConfiguration: () => {
|
|
169
|
+
},
|
|
170
|
+
showDevConsole: false,
|
|
171
|
+
coagentStates: {},
|
|
172
|
+
setCoagentStates: () => {
|
|
173
|
+
},
|
|
174
|
+
coagentStatesRef: { current: {} },
|
|
175
|
+
setCoagentStatesWithRef: () => {
|
|
176
|
+
},
|
|
177
|
+
agentSession: null,
|
|
178
|
+
setAgentSession: () => {
|
|
179
|
+
},
|
|
180
|
+
forwardedParameters: {},
|
|
181
|
+
agentLock: null,
|
|
182
|
+
threadId: "",
|
|
183
|
+
setThreadId: () => {
|
|
184
|
+
},
|
|
185
|
+
runId: null,
|
|
186
|
+
setRunId: () => {
|
|
187
|
+
},
|
|
188
|
+
chatAbortControllerRef: { current: null },
|
|
189
|
+
availableAgents: [],
|
|
190
|
+
extensions: {},
|
|
191
|
+
setExtensions: () => {
|
|
192
|
+
},
|
|
193
|
+
interruptActions: {},
|
|
194
|
+
setInterruptAction: () => {
|
|
195
|
+
},
|
|
196
|
+
removeInterruptAction: () => {
|
|
197
|
+
},
|
|
198
|
+
interruptEventQueue: {},
|
|
199
|
+
addInterruptEvent: () => {
|
|
200
|
+
},
|
|
201
|
+
resolveInterruptEvent: () => {
|
|
202
|
+
},
|
|
203
|
+
onError: () => {
|
|
204
|
+
},
|
|
205
|
+
bannerError: null,
|
|
206
|
+
setBannerError: () => {
|
|
207
|
+
},
|
|
208
|
+
internalErrorHandlers: {},
|
|
209
|
+
setInternalErrorHandler: () => {
|
|
210
|
+
},
|
|
211
|
+
removeInternalErrorHandler: () => {
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
215
|
+
function useCopilotContext() {
|
|
216
|
+
const context = import_react.default.useContext(CopilotContext);
|
|
217
|
+
if (context === emptyCopilotContext) {
|
|
218
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
219
|
+
}
|
|
220
|
+
return context;
|
|
221
|
+
}
|
|
222
|
+
function returnAndThrowInDebug(_value) {
|
|
223
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/hooks/use-tree.ts
|
|
227
|
+
var import_shared = require("@copilotkit/shared");
|
|
228
|
+
var import_react2 = require("react");
|
|
229
|
+
var removeNode = (nodes, id) => {
|
|
230
|
+
return nodes.reduce((result, node) => {
|
|
231
|
+
if (node.id !== id) {
|
|
232
|
+
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
233
|
+
result.push(newNode);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}, []);
|
|
237
|
+
};
|
|
238
|
+
var addNode = (nodes, newNode, parentId) => {
|
|
239
|
+
if (!parentId) {
|
|
240
|
+
return [...nodes, newNode];
|
|
241
|
+
}
|
|
242
|
+
return nodes.map((node) => {
|
|
243
|
+
if (node.id === parentId) {
|
|
244
|
+
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
245
|
+
} else if (node.children.length) {
|
|
246
|
+
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
247
|
+
}
|
|
248
|
+
return node;
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
252
|
+
if (indentLevel === 0) {
|
|
253
|
+
return (index + 1).toString();
|
|
254
|
+
} else if (indentLevel === 1) {
|
|
255
|
+
return String.fromCharCode(65 + index);
|
|
256
|
+
} else if (indentLevel === 2) {
|
|
257
|
+
return String.fromCharCode(97 + index);
|
|
258
|
+
} else {
|
|
259
|
+
return "-";
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
263
|
+
const indent = " ".repeat(3).repeat(indentLevel);
|
|
264
|
+
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
265
|
+
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
266
|
+
const valueLines = node.value.split("\n");
|
|
267
|
+
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
268
|
+
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
269
|
+
let output = `${outputFirstLine}
|
|
270
|
+
`;
|
|
271
|
+
if (outputSubsequentLines) {
|
|
272
|
+
output += `${outputSubsequentLines}
|
|
273
|
+
`;
|
|
274
|
+
}
|
|
275
|
+
const childPrePrefix = " ".repeat(prefix.length);
|
|
276
|
+
node.children.forEach(
|
|
277
|
+
(child, index) => output += printNode(
|
|
278
|
+
child,
|
|
279
|
+
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
280
|
+
indentLevel + 1
|
|
281
|
+
)
|
|
282
|
+
);
|
|
283
|
+
return output;
|
|
284
|
+
};
|
|
285
|
+
function treeReducer(state, action) {
|
|
286
|
+
switch (action.type) {
|
|
287
|
+
case "ADD_NODE": {
|
|
288
|
+
const { value, parentId, id: newNodeId } = action;
|
|
289
|
+
const newNode = {
|
|
290
|
+
id: newNodeId,
|
|
291
|
+
value,
|
|
292
|
+
children: [],
|
|
293
|
+
categories: new Set(action.categories)
|
|
294
|
+
};
|
|
295
|
+
try {
|
|
296
|
+
return addNode(state, newNode, parentId);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
299
|
+
return state;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
case "REMOVE_NODE":
|
|
303
|
+
return removeNode(state, action.id);
|
|
304
|
+
default:
|
|
305
|
+
return state;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
var useTree = () => {
|
|
309
|
+
const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
|
|
310
|
+
const addElement = (0, import_react2.useCallback)(
|
|
311
|
+
(value, categories, parentId) => {
|
|
312
|
+
const newNodeId = (0, import_shared.randomId)();
|
|
313
|
+
dispatch({
|
|
314
|
+
type: "ADD_NODE",
|
|
315
|
+
value,
|
|
316
|
+
parentId,
|
|
317
|
+
id: newNodeId,
|
|
318
|
+
categories
|
|
319
|
+
});
|
|
320
|
+
return newNodeId;
|
|
321
|
+
},
|
|
322
|
+
[]
|
|
323
|
+
);
|
|
324
|
+
const removeElement = (0, import_react2.useCallback)((id) => {
|
|
325
|
+
dispatch({ type: "REMOVE_NODE", id });
|
|
326
|
+
}, []);
|
|
327
|
+
const getAllElements = (0, import_react2.useCallback)(() => {
|
|
328
|
+
return tree;
|
|
329
|
+
}, [tree]);
|
|
330
|
+
const printTree = (0, import_react2.useCallback)(
|
|
331
|
+
(categories) => {
|
|
332
|
+
const categoriesSet = new Set(categories);
|
|
333
|
+
let output = "";
|
|
334
|
+
tree.forEach((node, index) => {
|
|
335
|
+
if (!setsHaveIntersection(categoriesSet, node.categories)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (index !== 0) {
|
|
339
|
+
output += "\n";
|
|
340
|
+
}
|
|
341
|
+
output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
|
|
342
|
+
});
|
|
343
|
+
return output;
|
|
344
|
+
},
|
|
345
|
+
[tree]
|
|
346
|
+
);
|
|
347
|
+
return { tree, addElement, printTree, removeElement, getAllElements };
|
|
348
|
+
};
|
|
349
|
+
var use_tree_default = useTree;
|
|
350
|
+
function setsHaveIntersection(setA, setB) {
|
|
351
|
+
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
352
|
+
for (let item of smallerSet) {
|
|
353
|
+
if (largerSet.has(item)) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
361
|
+
var import_react_dom = require("react-dom");
|
|
362
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
363
|
+
|
|
364
|
+
// src/hooks/use-flat-category-store.ts
|
|
365
|
+
var import_react3 = require("react");
|
|
366
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
367
|
+
var useFlatCategoryStore = () => {
|
|
368
|
+
const [elements, dispatch] = (0, import_react3.useReducer)(
|
|
369
|
+
flatCategoryStoreReducer,
|
|
370
|
+
/* @__PURE__ */ new Map()
|
|
371
|
+
);
|
|
372
|
+
const addElement = (0, import_react3.useCallback)((value, categories) => {
|
|
373
|
+
const newId = (0, import_shared2.randomId)();
|
|
374
|
+
dispatch({
|
|
375
|
+
type: "ADD_ELEMENT",
|
|
376
|
+
value,
|
|
377
|
+
id: newId,
|
|
378
|
+
categories
|
|
379
|
+
});
|
|
380
|
+
return newId;
|
|
381
|
+
}, []);
|
|
382
|
+
const removeElement = (0, import_react3.useCallback)((id) => {
|
|
383
|
+
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
384
|
+
}, []);
|
|
385
|
+
const allElements = (0, import_react3.useCallback)(
|
|
386
|
+
(categories) => {
|
|
387
|
+
const categoriesSet = new Set(categories);
|
|
388
|
+
const result = [];
|
|
389
|
+
elements.forEach((element) => {
|
|
390
|
+
if (setsHaveIntersection2(categoriesSet, element.categories)) {
|
|
391
|
+
result.push(element.value);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return result;
|
|
395
|
+
},
|
|
396
|
+
[elements]
|
|
397
|
+
);
|
|
398
|
+
return { addElement, removeElement, allElements };
|
|
399
|
+
};
|
|
400
|
+
var use_flat_category_store_default = useFlatCategoryStore;
|
|
401
|
+
function flatCategoryStoreReducer(state, action) {
|
|
402
|
+
switch (action.type) {
|
|
403
|
+
case "ADD_ELEMENT": {
|
|
404
|
+
const { value, id, categories } = action;
|
|
405
|
+
const newElement = {
|
|
406
|
+
id,
|
|
407
|
+
value,
|
|
408
|
+
categories: new Set(categories)
|
|
409
|
+
};
|
|
410
|
+
const newState = new Map(state);
|
|
411
|
+
newState.set(id, newElement);
|
|
412
|
+
return newState;
|
|
413
|
+
}
|
|
414
|
+
case "REMOVE_ELEMENT": {
|
|
415
|
+
const newState = new Map(state);
|
|
416
|
+
newState.delete(action.id);
|
|
417
|
+
return newState;
|
|
418
|
+
}
|
|
419
|
+
default:
|
|
420
|
+
return state;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function setsHaveIntersection2(setA, setB) {
|
|
424
|
+
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
425
|
+
for (let item of smallerSet) {
|
|
426
|
+
if (largerSet.has(item)) {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
434
|
+
var import_react6 = require("react");
|
|
435
|
+
|
|
436
|
+
// src/context/copilot-messages-context.tsx
|
|
437
|
+
var import_react4 = __toESM(require("react"));
|
|
438
|
+
var emptyCopilotContext2 = {
|
|
439
|
+
messages: [],
|
|
440
|
+
setMessages: () => [],
|
|
441
|
+
// suggestions state
|
|
442
|
+
suggestions: [],
|
|
443
|
+
setSuggestions: () => []
|
|
444
|
+
};
|
|
445
|
+
var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
|
|
446
|
+
function useCopilotMessagesContext() {
|
|
447
|
+
const context = import_react4.default.useContext(CopilotMessagesContext);
|
|
448
|
+
if (context === emptyCopilotContext2) {
|
|
449
|
+
throw new Error(
|
|
450
|
+
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
return context;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/components/toast/toast-provider.tsx
|
|
457
|
+
var import_react5 = require("react");
|
|
458
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
459
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
460
|
+
var ToastContext = (0, import_react5.createContext)(void 0);
|
|
461
|
+
function getErrorSeverity(error) {
|
|
462
|
+
if (error.severity) {
|
|
463
|
+
switch (error.severity) {
|
|
464
|
+
case import_shared3.Severity.CRITICAL:
|
|
465
|
+
return "critical";
|
|
466
|
+
case import_shared3.Severity.WARNING:
|
|
467
|
+
return "warning";
|
|
468
|
+
case import_shared3.Severity.INFO:
|
|
469
|
+
return "info";
|
|
470
|
+
default:
|
|
471
|
+
return "info";
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const message = error.message.toLowerCase();
|
|
475
|
+
if (message.includes("api key") || message.includes("401") || message.includes("unauthorized") || message.includes("authentication") || message.includes("incorrect api key")) {
|
|
476
|
+
return "critical";
|
|
477
|
+
}
|
|
478
|
+
return "info";
|
|
479
|
+
}
|
|
480
|
+
function getErrorColors(severity) {
|
|
481
|
+
switch (severity) {
|
|
482
|
+
case "critical":
|
|
483
|
+
return {
|
|
484
|
+
background: "#fee2e2",
|
|
485
|
+
border: "#dc2626",
|
|
486
|
+
text: "#7f1d1d",
|
|
487
|
+
icon: "#dc2626"
|
|
488
|
+
};
|
|
489
|
+
case "warning":
|
|
490
|
+
return {
|
|
491
|
+
background: "#fef3c7",
|
|
492
|
+
border: "#d97706",
|
|
493
|
+
text: "#78350f",
|
|
494
|
+
icon: "#d97706"
|
|
495
|
+
};
|
|
496
|
+
case "info":
|
|
497
|
+
return {
|
|
498
|
+
background: "#dbeafe",
|
|
499
|
+
border: "#2563eb",
|
|
500
|
+
text: "#1e3a8a",
|
|
501
|
+
icon: "#2563eb"
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function useToast() {
|
|
506
|
+
const context = (0, import_react5.useContext)(ToastContext);
|
|
507
|
+
if (!context) {
|
|
508
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
509
|
+
}
|
|
510
|
+
return context;
|
|
511
|
+
}
|
|
512
|
+
function ToastProvider({
|
|
513
|
+
enabled,
|
|
514
|
+
children
|
|
515
|
+
}) {
|
|
516
|
+
const [toasts, setToasts] = (0, import_react5.useState)([]);
|
|
517
|
+
const [bannerError, setBannerErrorState] = (0, import_react5.useState)(null);
|
|
518
|
+
const removeToast = (0, import_react5.useCallback)((id) => {
|
|
519
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
520
|
+
}, []);
|
|
521
|
+
const addToast = (0, import_react5.useCallback)(
|
|
522
|
+
(toast) => {
|
|
523
|
+
var _a;
|
|
524
|
+
if (!enabled) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
528
|
+
setToasts((currentToasts) => {
|
|
529
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
530
|
+
return currentToasts;
|
|
531
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
532
|
+
});
|
|
533
|
+
if (toast.duration) {
|
|
534
|
+
setTimeout(() => {
|
|
535
|
+
removeToast(id);
|
|
536
|
+
}, toast.duration);
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
[enabled, removeToast]
|
|
540
|
+
);
|
|
541
|
+
const setBannerError = (0, import_react5.useCallback)(
|
|
542
|
+
(error) => {
|
|
543
|
+
if (!enabled && error !== null) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
setBannerErrorState(error);
|
|
547
|
+
},
|
|
548
|
+
[enabled]
|
|
549
|
+
);
|
|
550
|
+
const addGraphQLErrorsToast = (0, import_react5.useCallback)((errors) => {
|
|
551
|
+
console.warn("addGraphQLErrorsToast is deprecated. All errors now show as banners.");
|
|
552
|
+
}, []);
|
|
553
|
+
const value = {
|
|
554
|
+
toasts,
|
|
555
|
+
addToast,
|
|
556
|
+
addGraphQLErrorsToast,
|
|
557
|
+
removeToast,
|
|
558
|
+
enabled,
|
|
559
|
+
bannerError,
|
|
560
|
+
setBannerError
|
|
561
|
+
};
|
|
562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value, children: [
|
|
563
|
+
bannerError && (() => {
|
|
564
|
+
const severity = getErrorSeverity(bannerError);
|
|
565
|
+
const colors = getErrorColors(severity);
|
|
566
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
567
|
+
"div",
|
|
568
|
+
{
|
|
569
|
+
style: {
|
|
570
|
+
position: "fixed",
|
|
571
|
+
bottom: "20px",
|
|
572
|
+
left: "50%",
|
|
573
|
+
transform: "translateX(-50%)",
|
|
574
|
+
zIndex: 9999,
|
|
575
|
+
backgroundColor: colors.background,
|
|
576
|
+
border: `1px solid ${colors.border}`,
|
|
577
|
+
borderLeft: `4px solid ${colors.border}`,
|
|
578
|
+
borderRadius: "8px",
|
|
579
|
+
padding: "12px 16px",
|
|
580
|
+
fontSize: "13px",
|
|
581
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
582
|
+
backdropFilter: "blur(8px)",
|
|
583
|
+
maxWidth: "min(90vw, 700px)",
|
|
584
|
+
width: "100%",
|
|
585
|
+
boxSizing: "border-box",
|
|
586
|
+
overflow: "hidden"
|
|
587
|
+
},
|
|
588
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
589
|
+
"div",
|
|
590
|
+
{
|
|
591
|
+
style: {
|
|
592
|
+
display: "flex",
|
|
593
|
+
justifyContent: "space-between",
|
|
594
|
+
alignItems: "center",
|
|
595
|
+
gap: "10px"
|
|
596
|
+
},
|
|
597
|
+
children: [
|
|
598
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
599
|
+
"div",
|
|
600
|
+
{
|
|
601
|
+
style: {
|
|
602
|
+
display: "flex",
|
|
603
|
+
alignItems: "center",
|
|
604
|
+
gap: "8px",
|
|
605
|
+
flex: 1,
|
|
606
|
+
minWidth: 0
|
|
607
|
+
},
|
|
608
|
+
children: [
|
|
609
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
610
|
+
"div",
|
|
611
|
+
{
|
|
612
|
+
style: {
|
|
613
|
+
width: "12px",
|
|
614
|
+
height: "12px",
|
|
615
|
+
borderRadius: "50%",
|
|
616
|
+
backgroundColor: colors.border,
|
|
617
|
+
flexShrink: 0
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
),
|
|
621
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
622
|
+
"div",
|
|
623
|
+
{
|
|
624
|
+
style: {
|
|
625
|
+
display: "flex",
|
|
626
|
+
alignItems: "center",
|
|
627
|
+
gap: "10px",
|
|
628
|
+
flex: 1,
|
|
629
|
+
minWidth: 0
|
|
630
|
+
},
|
|
631
|
+
children: [
|
|
632
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
633
|
+
"div",
|
|
634
|
+
{
|
|
635
|
+
style: {
|
|
636
|
+
color: colors.text,
|
|
637
|
+
lineHeight: "1.4",
|
|
638
|
+
fontWeight: "400",
|
|
639
|
+
fontSize: "13px",
|
|
640
|
+
flex: 1,
|
|
641
|
+
wordBreak: "break-all",
|
|
642
|
+
overflowWrap: "break-word",
|
|
643
|
+
maxWidth: "550px",
|
|
644
|
+
overflow: "hidden",
|
|
645
|
+
display: "-webkit-box",
|
|
646
|
+
WebkitLineClamp: 10,
|
|
647
|
+
WebkitBoxOrient: "vertical"
|
|
648
|
+
},
|
|
649
|
+
children: (() => {
|
|
650
|
+
let message = bannerError.message;
|
|
651
|
+
const jsonMatch = message.match(/'message':\s*'([^']+)'/);
|
|
652
|
+
if (jsonMatch) {
|
|
653
|
+
return jsonMatch[1];
|
|
654
|
+
}
|
|
655
|
+
message = message.split(" - ")[0];
|
|
656
|
+
message = message.split(": Error code")[0];
|
|
657
|
+
message = message.replace(/:\s*\d{3}$/, "");
|
|
658
|
+
message = message.replace(/See more:.*$/g, "");
|
|
659
|
+
message = message.trim();
|
|
660
|
+
return message || "Configuration error occurred.";
|
|
661
|
+
})()
|
|
662
|
+
}
|
|
663
|
+
),
|
|
664
|
+
(() => {
|
|
665
|
+
const message = bannerError.message;
|
|
666
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
667
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
668
|
+
let url = null;
|
|
669
|
+
let buttonText = "See More";
|
|
670
|
+
const markdownMatch = markdownLinkRegex.exec(message);
|
|
671
|
+
if (markdownMatch) {
|
|
672
|
+
url = markdownMatch[2];
|
|
673
|
+
buttonText = "See More";
|
|
674
|
+
} else {
|
|
675
|
+
const urlMatch = plainUrlRegex.exec(message);
|
|
676
|
+
if (urlMatch) {
|
|
677
|
+
url = urlMatch[0].replace(/[.,;:'"]*$/, "");
|
|
678
|
+
buttonText = "See More";
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (!url)
|
|
682
|
+
return null;
|
|
683
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
684
|
+
"button",
|
|
685
|
+
{
|
|
686
|
+
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
687
|
+
style: {
|
|
688
|
+
background: colors.border,
|
|
689
|
+
color: "white",
|
|
690
|
+
border: "none",
|
|
691
|
+
borderRadius: "5px",
|
|
692
|
+
padding: "4px 10px",
|
|
693
|
+
fontSize: "11px",
|
|
694
|
+
fontWeight: "500",
|
|
695
|
+
cursor: "pointer",
|
|
696
|
+
transition: "all 0.2s ease",
|
|
697
|
+
flexShrink: 0
|
|
698
|
+
},
|
|
699
|
+
onMouseEnter: (e) => {
|
|
700
|
+
e.currentTarget.style.opacity = "0.9";
|
|
701
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
702
|
+
},
|
|
703
|
+
onMouseLeave: (e) => {
|
|
704
|
+
e.currentTarget.style.opacity = "1";
|
|
705
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
706
|
+
},
|
|
707
|
+
children: buttonText
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
})()
|
|
711
|
+
]
|
|
712
|
+
}
|
|
713
|
+
)
|
|
714
|
+
]
|
|
715
|
+
}
|
|
716
|
+
),
|
|
717
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
718
|
+
"button",
|
|
719
|
+
{
|
|
720
|
+
onClick: () => setBannerError(null),
|
|
721
|
+
style: {
|
|
722
|
+
background: "transparent",
|
|
723
|
+
border: "none",
|
|
724
|
+
color: colors.text,
|
|
725
|
+
cursor: "pointer",
|
|
726
|
+
padding: "2px",
|
|
727
|
+
borderRadius: "3px",
|
|
728
|
+
fontSize: "14px",
|
|
729
|
+
lineHeight: "1",
|
|
730
|
+
opacity: 0.6,
|
|
731
|
+
transition: "all 0.2s ease",
|
|
732
|
+
flexShrink: 0
|
|
733
|
+
},
|
|
734
|
+
title: "Dismiss",
|
|
735
|
+
onMouseEnter: (e) => {
|
|
736
|
+
e.currentTarget.style.opacity = "1";
|
|
737
|
+
e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
|
|
738
|
+
},
|
|
739
|
+
onMouseLeave: (e) => {
|
|
740
|
+
e.currentTarget.style.opacity = "0.6";
|
|
741
|
+
e.currentTarget.style.background = "transparent";
|
|
742
|
+
},
|
|
743
|
+
children: "\xD7"
|
|
744
|
+
}
|
|
745
|
+
)
|
|
746
|
+
]
|
|
747
|
+
}
|
|
748
|
+
)
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
})(),
|
|
752
|
+
children
|
|
753
|
+
] });
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// src/utils/dev-console.ts
|
|
757
|
+
function isLocalhost() {
|
|
758
|
+
if (typeof window === "undefined")
|
|
759
|
+
return false;
|
|
760
|
+
return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
|
|
761
|
+
}
|
|
762
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
763
|
+
if (showDevConsole !== void 0) {
|
|
764
|
+
return showDevConsole;
|
|
765
|
+
}
|
|
766
|
+
return isLocalhost();
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
770
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
771
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
772
|
+
var MessagesTapContext = (0, import_react6.createContext)(null);
|
|
773
|
+
function useMessagesTap() {
|
|
774
|
+
const tap = (0, import_react6.useContext)(MessagesTapContext);
|
|
775
|
+
if (!tap)
|
|
776
|
+
throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
|
|
777
|
+
return tap;
|
|
778
|
+
}
|
|
779
|
+
function MessagesTapProvider({ children }) {
|
|
780
|
+
const messagesRef = (0, import_react6.useRef)([]);
|
|
781
|
+
const tapRef = (0, import_react6.useRef)({
|
|
782
|
+
getMessagesFromTap: () => messagesRef.current,
|
|
783
|
+
updateTapMessages: (messages) => {
|
|
784
|
+
messagesRef.current = messages;
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MessagesTapContext.Provider, { value: tapRef.current, children });
|
|
788
|
+
}
|
|
789
|
+
function CopilotMessages({ children }) {
|
|
790
|
+
const [messages, setMessages] = (0, import_react6.useState)([]);
|
|
791
|
+
const lastLoadedThreadId = (0, import_react6.useRef)(void 0);
|
|
792
|
+
const lastLoadedAgentName = (0, import_react6.useRef)(void 0);
|
|
793
|
+
const lastLoadedMessages = (0, import_react6.useRef)(void 0);
|
|
794
|
+
const { updateTapMessages } = useMessagesTap();
|
|
795
|
+
const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
|
|
796
|
+
const { setBannerError } = useToast();
|
|
797
|
+
const traceUIError = (0, import_react6.useCallback)(
|
|
798
|
+
(error, originalError) => __async(this, null, function* () {
|
|
799
|
+
if (!onError || !copilotApiConfig.publicApiKey)
|
|
800
|
+
return;
|
|
801
|
+
try {
|
|
802
|
+
const traceEvent = {
|
|
803
|
+
type: "error",
|
|
804
|
+
timestamp: Date.now(),
|
|
805
|
+
context: {
|
|
806
|
+
source: "ui",
|
|
807
|
+
request: {
|
|
808
|
+
operation: "loadAgentState",
|
|
809
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
810
|
+
startTime: Date.now()
|
|
811
|
+
},
|
|
812
|
+
technical: {
|
|
813
|
+
environment: "browser",
|
|
814
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
815
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
error
|
|
819
|
+
};
|
|
820
|
+
yield onError(traceEvent);
|
|
821
|
+
} catch (traceError) {
|
|
822
|
+
console.error("Error in CopilotMessages onError handler:", traceError);
|
|
823
|
+
}
|
|
824
|
+
}),
|
|
825
|
+
[onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
|
|
826
|
+
);
|
|
827
|
+
const createStructuredError2 = (gqlError) => {
|
|
828
|
+
const extensions = gqlError.extensions;
|
|
829
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
830
|
+
if (originalError == null ? void 0 : originalError.stack) {
|
|
831
|
+
if (originalError.stack.includes("CopilotApiDiscoveryError")) {
|
|
832
|
+
return new import_shared4.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
833
|
+
}
|
|
834
|
+
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
835
|
+
return new import_shared4.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
836
|
+
}
|
|
837
|
+
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) {
|
|
838
|
+
return new import_shared4.CopilotKitAgentDiscoveryError({
|
|
839
|
+
agentName: "",
|
|
840
|
+
availableAgents: []
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
845
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
846
|
+
if (code) {
|
|
847
|
+
return new import_shared4.CopilotKitError({ message, code });
|
|
848
|
+
}
|
|
849
|
+
return null;
|
|
850
|
+
};
|
|
851
|
+
const handleGraphQLErrors = (0, import_react6.useCallback)(
|
|
852
|
+
(error) => {
|
|
853
|
+
var _a;
|
|
854
|
+
if ((_a = error.graphQLErrors) == null ? void 0 : _a.length) {
|
|
855
|
+
const graphQLErrors = error.graphQLErrors;
|
|
856
|
+
const routeError = (gqlError) => {
|
|
857
|
+
const extensions = gqlError.extensions;
|
|
858
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
859
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
860
|
+
if (!isDev) {
|
|
861
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (visibility === import_shared4.ErrorVisibility.SILENT) {
|
|
865
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
const ckError = createStructuredError2(gqlError);
|
|
869
|
+
if (ckError) {
|
|
870
|
+
setBannerError(ckError);
|
|
871
|
+
traceUIError(ckError, gqlError);
|
|
872
|
+
} else {
|
|
873
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
874
|
+
message: gqlError.message,
|
|
875
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
876
|
+
});
|
|
877
|
+
setBannerError(fallbackError);
|
|
878
|
+
traceUIError(fallbackError, gqlError);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
graphQLErrors.forEach(routeError);
|
|
882
|
+
} else {
|
|
883
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
884
|
+
if (!isDev) {
|
|
885
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
886
|
+
} else {
|
|
887
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
888
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
889
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
890
|
+
});
|
|
891
|
+
setBannerError(fallbackError);
|
|
892
|
+
traceUIError(fallbackError, error);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
[setBannerError, showDevConsole, traceUIError]
|
|
897
|
+
);
|
|
898
|
+
(0, import_react6.useEffect)(() => {
|
|
899
|
+
updateTapMessages(messages);
|
|
900
|
+
}, [messages, updateTapMessages]);
|
|
901
|
+
const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
|
|
902
|
+
const [suggestions, setSuggestions] = (0, import_react6.useState)([]);
|
|
903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
904
|
+
CopilotMessagesContext.Provider,
|
|
905
|
+
{
|
|
906
|
+
value: {
|
|
907
|
+
messages,
|
|
908
|
+
setMessages,
|
|
909
|
+
suggestions,
|
|
910
|
+
setSuggestions
|
|
911
|
+
},
|
|
912
|
+
children: memoizedChildren
|
|
913
|
+
}
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// src/components/usage-banner.tsx
|
|
918
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
919
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
920
|
+
function UsageBanner({
|
|
921
|
+
severity = import_shared5.Severity.CRITICAL,
|
|
922
|
+
message = "",
|
|
923
|
+
onClose,
|
|
924
|
+
actions
|
|
925
|
+
}) {
|
|
926
|
+
if (!message || !severity) {
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
const themes = {
|
|
930
|
+
[import_shared5.Severity.INFO]: {
|
|
931
|
+
bg: "#f8fafc",
|
|
932
|
+
border: "#e2e8f0",
|
|
933
|
+
text: "#475569",
|
|
934
|
+
accent: "#3b82f6"
|
|
935
|
+
},
|
|
936
|
+
[import_shared5.Severity.WARNING]: {
|
|
937
|
+
bg: "#fffbeb",
|
|
938
|
+
border: "#fbbf24",
|
|
939
|
+
text: "#92400e",
|
|
940
|
+
accent: "#f59e0b"
|
|
941
|
+
},
|
|
942
|
+
[import_shared5.Severity.CRITICAL]: {
|
|
943
|
+
bg: "#fef2f2",
|
|
944
|
+
border: "#fecaca",
|
|
945
|
+
text: "#dc2626",
|
|
946
|
+
accent: "#ef4444"
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
const theme = themes[severity];
|
|
950
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
951
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
952
|
+
@keyframes slideUp {
|
|
953
|
+
from { opacity: 0; transform: translateX(-50%) translateY(8px); }
|
|
954
|
+
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
.usage-banner {
|
|
958
|
+
position: fixed;
|
|
959
|
+
bottom: 24px;
|
|
960
|
+
left: 50%;
|
|
961
|
+
transform: translateX(-50%);
|
|
962
|
+
width: min(600px, calc(100vw - 32px));
|
|
963
|
+
z-index: 10000;
|
|
964
|
+
animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
.banner-content {
|
|
968
|
+
background: linear-gradient(135deg, ${theme.bg} 0%, ${theme.bg}f5 100%);
|
|
969
|
+
border: 1px solid ${theme.border};
|
|
970
|
+
border-radius: 12px;
|
|
971
|
+
padding: 18px 20px;
|
|
972
|
+
box-shadow:
|
|
973
|
+
0 4px 24px rgba(0, 0, 0, 0.08),
|
|
974
|
+
0 2px 8px rgba(0, 0, 0, 0.04),
|
|
975
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
|
976
|
+
display: flex;
|
|
977
|
+
align-items: center;
|
|
978
|
+
gap: 16px;
|
|
979
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
|
|
980
|
+
backdrop-filter: blur(12px);
|
|
981
|
+
position: relative;
|
|
982
|
+
overflow: hidden;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
.banner-content::before {
|
|
986
|
+
content: '';
|
|
987
|
+
position: absolute;
|
|
988
|
+
top: 0;
|
|
989
|
+
left: 0;
|
|
990
|
+
right: 0;
|
|
991
|
+
height: 1px;
|
|
992
|
+
background: linear-gradient(90deg, transparent, ${theme.accent}40, transparent);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
.banner-message {
|
|
996
|
+
color: ${theme.text};
|
|
997
|
+
font-size: 14px;
|
|
998
|
+
line-height: 1.5;
|
|
999
|
+
font-weight: 500;
|
|
1000
|
+
flex: 1;
|
|
1001
|
+
letter-spacing: -0.01em;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
.close-btn {
|
|
1005
|
+
background: rgba(0, 0, 0, 0.05);
|
|
1006
|
+
border: none;
|
|
1007
|
+
color: ${theme.text};
|
|
1008
|
+
cursor: pointer;
|
|
1009
|
+
padding: 0;
|
|
1010
|
+
border-radius: 6px;
|
|
1011
|
+
opacity: 0.6;
|
|
1012
|
+
transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1013
|
+
font-size: 14px;
|
|
1014
|
+
line-height: 1;
|
|
1015
|
+
flex-shrink: 0;
|
|
1016
|
+
width: 24px;
|
|
1017
|
+
height: 24px;
|
|
1018
|
+
display: flex;
|
|
1019
|
+
align-items: center;
|
|
1020
|
+
justify-content: center;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
.close-btn:hover {
|
|
1024
|
+
opacity: 1;
|
|
1025
|
+
background: rgba(0, 0, 0, 0.08);
|
|
1026
|
+
transform: scale(1.05);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
.btn-primary {
|
|
1030
|
+
background: linear-gradient(135deg, ${theme.accent} 0%, ${theme.accent}e6 100%);
|
|
1031
|
+
color: white;
|
|
1032
|
+
border: none;
|
|
1033
|
+
border-radius: 8px;
|
|
1034
|
+
padding: 10px 18px;
|
|
1035
|
+
font-size: 13px;
|
|
1036
|
+
font-weight: 600;
|
|
1037
|
+
cursor: pointer;
|
|
1038
|
+
transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1039
|
+
font-family: inherit;
|
|
1040
|
+
flex-shrink: 0;
|
|
1041
|
+
box-shadow:
|
|
1042
|
+
0 2px 8px ${theme.accent}30,
|
|
1043
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
|
1044
|
+
letter-spacing: -0.01em;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
.btn-primary:hover {
|
|
1048
|
+
transform: translateY(-1px) scale(1.02);
|
|
1049
|
+
box-shadow:
|
|
1050
|
+
0 4px 12px ${theme.accent}40,
|
|
1051
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.25);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
.btn-primary:active {
|
|
1055
|
+
transform: translateY(0) scale(0.98);
|
|
1056
|
+
transition: all 0.08s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
@media (max-width: 640px) {
|
|
1060
|
+
.usage-banner {
|
|
1061
|
+
width: calc(100vw - 24px);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
.banner-content {
|
|
1065
|
+
padding: 16px;
|
|
1066
|
+
gap: 12px;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
.banner-message {
|
|
1070
|
+
font-size: 13px;
|
|
1071
|
+
line-height: 1.45;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
.btn-primary {
|
|
1075
|
+
padding: 8px 14px;
|
|
1076
|
+
font-size: 12px;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
.close-btn {
|
|
1080
|
+
width: 22px;
|
|
1081
|
+
height: 22px;
|
|
1082
|
+
font-size: 12px;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
` }),
|
|
1086
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "usage-banner", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "banner-content", children: [
|
|
1087
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "banner-message", children: message }),
|
|
1088
|
+
(actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "btn-primary", onClick: actions.primary.onClick, children: actions.primary.label }),
|
|
1089
|
+
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "close-btn", onClick: onClose, title: "Close", children: "\xD7" })
|
|
1090
|
+
] }) })
|
|
1091
|
+
] });
|
|
1092
|
+
}
|
|
1093
|
+
var getErrorActions = (error) => {
|
|
1094
|
+
switch (error.code) {
|
|
1095
|
+
case import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR:
|
|
1096
|
+
return {
|
|
1097
|
+
primary: {
|
|
1098
|
+
label: "Show me how",
|
|
1099
|
+
onClick: () => window.open(
|
|
1100
|
+
"https://docs.copilotkit.ai/premium#how-do-i-get-access-to-premium-features",
|
|
1101
|
+
"_blank",
|
|
1102
|
+
"noopener,noreferrer"
|
|
1103
|
+
)
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
case import_shared5.CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR:
|
|
1107
|
+
return {
|
|
1108
|
+
primary: {
|
|
1109
|
+
label: "Upgrade",
|
|
1110
|
+
onClick: () => window.open("https://cloud.copilotkit.ai", "_blank", "noopener,noreferrer")
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
default:
|
|
1114
|
+
return void 0;
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
// src/utils/suggestions-constants.ts
|
|
1119
|
+
var SUGGESTION_RETRY_CONFIG = {
|
|
1120
|
+
MAX_RETRIES: 3,
|
|
1121
|
+
COOLDOWN_MS: 5e3
|
|
1122
|
+
// 5 seconds
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
1126
|
+
var import_react8 = __toESM(require("react"));
|
|
1127
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1128
|
+
|
|
1129
|
+
// src/lib/status-checker.ts
|
|
1130
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1131
|
+
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
1132
|
+
var StatusChecker = class {
|
|
1133
|
+
constructor() {
|
|
1134
|
+
this.activeKey = null;
|
|
1135
|
+
this.intervalId = null;
|
|
1136
|
+
this.instanceCount = 0;
|
|
1137
|
+
this.lastResponse = null;
|
|
1138
|
+
}
|
|
1139
|
+
start(publicApiKey, onUpdate) {
|
|
1140
|
+
return __async(this, null, function* () {
|
|
1141
|
+
this.instanceCount++;
|
|
1142
|
+
if (this.activeKey === publicApiKey)
|
|
1143
|
+
return;
|
|
1144
|
+
if (this.intervalId)
|
|
1145
|
+
clearInterval(this.intervalId);
|
|
1146
|
+
const checkStatus = () => __async(this, null, function* () {
|
|
1147
|
+
try {
|
|
1148
|
+
const response = yield fetch(`${import_shared6.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
1149
|
+
method: "GET",
|
|
1150
|
+
headers: {
|
|
1151
|
+
[import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
1152
|
+
}
|
|
1153
|
+
}).then((response2) => response2.json());
|
|
1154
|
+
this.lastResponse = response;
|
|
1155
|
+
onUpdate == null ? void 0 : onUpdate(response);
|
|
1156
|
+
return response;
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
const initialResponse = yield checkStatus();
|
|
1162
|
+
this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
|
|
1163
|
+
this.activeKey = publicApiKey;
|
|
1164
|
+
return initialResponse;
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
getLastResponse() {
|
|
1168
|
+
return this.lastResponse;
|
|
1169
|
+
}
|
|
1170
|
+
stop() {
|
|
1171
|
+
this.instanceCount--;
|
|
1172
|
+
if (this.instanceCount === 0) {
|
|
1173
|
+
if (this.intervalId) {
|
|
1174
|
+
clearInterval(this.intervalId);
|
|
1175
|
+
this.intervalId = null;
|
|
1176
|
+
this.activeKey = null;
|
|
1177
|
+
this.lastResponse = null;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1184
|
+
var import_react7 = require("react");
|
|
1185
|
+
|
|
1186
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
1187
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1188
|
+
var ExclamationMarkIcon = ({
|
|
1189
|
+
className,
|
|
1190
|
+
style
|
|
1191
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1192
|
+
"svg",
|
|
1193
|
+
{
|
|
1194
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1195
|
+
width: "24",
|
|
1196
|
+
height: "24",
|
|
1197
|
+
viewBox: "0 0 24 24",
|
|
1198
|
+
fill: "none",
|
|
1199
|
+
stroke: "currentColor",
|
|
1200
|
+
strokeWidth: "2",
|
|
1201
|
+
strokeLinecap: "round",
|
|
1202
|
+
strokeLinejoin: "round",
|
|
1203
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
1204
|
+
style,
|
|
1205
|
+
children: [
|
|
1206
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1207
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
1208
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
1209
|
+
]
|
|
1210
|
+
}
|
|
1211
|
+
);
|
|
1212
|
+
|
|
1213
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1214
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1215
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1216
|
+
function ErrorToast({ errors }) {
|
|
1217
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
1218
|
+
var _a, _b, _c;
|
|
1219
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
1220
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
1221
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
1222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1223
|
+
"div",
|
|
1224
|
+
{
|
|
1225
|
+
style: {
|
|
1226
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
1227
|
+
marginBottom: 14
|
|
1228
|
+
},
|
|
1229
|
+
children: [
|
|
1230
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
1231
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1232
|
+
"div",
|
|
1233
|
+
{
|
|
1234
|
+
style: {
|
|
1235
|
+
fontWeight: "600",
|
|
1236
|
+
marginBottom: 4
|
|
1237
|
+
},
|
|
1238
|
+
children: [
|
|
1239
|
+
"Copilot Runtime Error:",
|
|
1240
|
+
" ",
|
|
1241
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
1242
|
+
]
|
|
1243
|
+
}
|
|
1244
|
+
),
|
|
1245
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { children: message })
|
|
1246
|
+
]
|
|
1247
|
+
},
|
|
1248
|
+
idx
|
|
1249
|
+
);
|
|
1250
|
+
});
|
|
1251
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1252
|
+
"div",
|
|
1253
|
+
{
|
|
1254
|
+
style: {
|
|
1255
|
+
fontSize: "13px",
|
|
1256
|
+
maxWidth: "600px"
|
|
1257
|
+
},
|
|
1258
|
+
children: [
|
|
1259
|
+
errorsToRender,
|
|
1260
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
1261
|
+
]
|
|
1262
|
+
}
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
function useErrorToast() {
|
|
1266
|
+
const { addToast } = useToast();
|
|
1267
|
+
return (0, import_react7.useCallback)(
|
|
1268
|
+
(errors) => {
|
|
1269
|
+
const errorId = errors.map((err) => {
|
|
1270
|
+
var _a, _b;
|
|
1271
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
1272
|
+
const stack = err.stack || "";
|
|
1273
|
+
return btoa(message + stack).slice(0, 32);
|
|
1274
|
+
}).join("|");
|
|
1275
|
+
addToast({
|
|
1276
|
+
type: "error",
|
|
1277
|
+
id: errorId,
|
|
1278
|
+
// Toast libraries typically dedupe by id
|
|
1279
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast, { errors })
|
|
1280
|
+
});
|
|
1281
|
+
},
|
|
1282
|
+
[addToast]
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
function useAsyncCallback(callback, deps) {
|
|
1286
|
+
const addErrorToast = useErrorToast();
|
|
1287
|
+
return (0, import_react7.useCallback)((...args) => __async(this, null, function* () {
|
|
1288
|
+
try {
|
|
1289
|
+
return yield callback(...args);
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
console.error("Error in async callback:", error);
|
|
1292
|
+
addErrorToast([error]);
|
|
1293
|
+
throw error;
|
|
1294
|
+
}
|
|
1295
|
+
}), deps);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
1299
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1300
|
+
var statusChecker = new StatusChecker();
|
|
1301
|
+
var CopilotErrorBoundary = class extends import_react8.default.Component {
|
|
1302
|
+
constructor(props) {
|
|
1303
|
+
super(props);
|
|
1304
|
+
this.state = {
|
|
1305
|
+
hasError: false
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
static getDerivedStateFromError(error) {
|
|
1309
|
+
return { hasError: true, error };
|
|
1310
|
+
}
|
|
1311
|
+
componentDidMount() {
|
|
1312
|
+
if (this.props.publicApiKey) {
|
|
1313
|
+
statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
1314
|
+
this.setState((prevState) => {
|
|
1315
|
+
var _a;
|
|
1316
|
+
if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
|
|
1317
|
+
return { status: newStatus != null ? newStatus : void 0 };
|
|
1318
|
+
}
|
|
1319
|
+
return null;
|
|
1320
|
+
});
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
componentWillUnmount() {
|
|
1325
|
+
statusChecker.stop();
|
|
1326
|
+
}
|
|
1327
|
+
componentDidCatch(error, errorInfo) {
|
|
1328
|
+
console.error("CopilotKit Error:", error, errorInfo);
|
|
1329
|
+
}
|
|
1330
|
+
render() {
|
|
1331
|
+
var _a, _b, _c, _d;
|
|
1332
|
+
if (this.state.hasError) {
|
|
1333
|
+
if (this.state.error instanceof import_shared7.CopilotKitError) {
|
|
1334
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1335
|
+
this.props.children,
|
|
1336
|
+
this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1337
|
+
UsageBanner,
|
|
1338
|
+
{
|
|
1339
|
+
severity: (_b = (_a = this.state.status) == null ? void 0 : _a.severity) != null ? _b : this.state.error.severity,
|
|
1340
|
+
message: (_d = (_c = this.state.status) == null ? void 0 : _c.message) != null ? _d : this.state.error.message,
|
|
1341
|
+
actions: getErrorActions(this.state.error)
|
|
1342
|
+
}
|
|
1343
|
+
)
|
|
1344
|
+
] });
|
|
1345
|
+
}
|
|
1346
|
+
throw this.state.error;
|
|
1347
|
+
}
|
|
1348
|
+
return this.props.children;
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
// src/context/coagent-state-renders-context.tsx
|
|
1353
|
+
var import_react9 = require("react");
|
|
1354
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1355
|
+
var CoAgentStateRendersContext = (0, import_react9.createContext)(
|
|
1356
|
+
void 0
|
|
1357
|
+
);
|
|
1358
|
+
function CoAgentStateRendersProvider({ children }) {
|
|
1359
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react9.useState)({});
|
|
1360
|
+
const setCoAgentStateRender = (0, import_react9.useCallback)((id, stateRender) => {
|
|
1361
|
+
setCoAgentStateRenders((prevPoints) => __spreadProps(__spreadValues({}, prevPoints), {
|
|
1362
|
+
[id]: stateRender
|
|
1363
|
+
}));
|
|
1364
|
+
}, []);
|
|
1365
|
+
const removeCoAgentStateRender = (0, import_react9.useCallback)((id) => {
|
|
1366
|
+
setCoAgentStateRenders((prevPoints) => {
|
|
1367
|
+
const newPoints = __spreadValues({}, prevPoints);
|
|
1368
|
+
delete newPoints[id];
|
|
1369
|
+
return newPoints;
|
|
1370
|
+
});
|
|
1371
|
+
}, []);
|
|
1372
|
+
const claimsRef = (0, import_react9.useRef)({});
|
|
1373
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1374
|
+
CoAgentStateRendersContext.Provider,
|
|
1375
|
+
{
|
|
1376
|
+
value: {
|
|
1377
|
+
coAgentStateRenders,
|
|
1378
|
+
setCoAgentStateRender,
|
|
1379
|
+
removeCoAgentStateRender,
|
|
1380
|
+
claimsRef
|
|
1381
|
+
},
|
|
1382
|
+
children
|
|
1383
|
+
}
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
function useCoAgentStateRenders() {
|
|
1387
|
+
const context = (0, import_react9.useContext)(CoAgentStateRendersContext);
|
|
1388
|
+
if (!context) {
|
|
1389
|
+
throw new Error("useCoAgentStateRenders must be used within CoAgentStateRendersProvider");
|
|
1390
|
+
}
|
|
1391
|
+
return context;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
1395
|
+
var import_react11 = require("@copilotkitnext/react");
|
|
1396
|
+
var import_react12 = require("react");
|
|
1397
|
+
|
|
1398
|
+
// src/context/threads-context.tsx
|
|
1399
|
+
var import_react10 = require("react");
|
|
1400
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1401
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1402
|
+
var ThreadsContext = (0, import_react10.createContext)(void 0);
|
|
1403
|
+
function ThreadsProvider({ children, threadId: explicitThreadId }) {
|
|
1404
|
+
const [internalThreadId, setThreadId] = (0, import_react10.useState)(explicitThreadId != null ? explicitThreadId : (0, import_shared8.randomUUID)());
|
|
1405
|
+
const threadId = internalThreadId;
|
|
1406
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1407
|
+
ThreadsContext.Provider,
|
|
1408
|
+
{
|
|
1409
|
+
value: {
|
|
1410
|
+
threadId,
|
|
1411
|
+
setThreadId
|
|
1412
|
+
},
|
|
1413
|
+
children
|
|
1414
|
+
}
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
function useThreads() {
|
|
1418
|
+
const context = (0, import_react10.useContext)(ThreadsContext);
|
|
1419
|
+
if (!context) {
|
|
1420
|
+
throw new Error("useThreads must be used within ThreadsProvider");
|
|
1421
|
+
}
|
|
1422
|
+
return context;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
1426
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1427
|
+
function getStateWithoutConstantKeys(state) {
|
|
1428
|
+
if (!state)
|
|
1429
|
+
return {};
|
|
1430
|
+
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
1431
|
+
return stateWithoutConstantKeys;
|
|
1432
|
+
}
|
|
1433
|
+
function areStatesEquals(a, b) {
|
|
1434
|
+
if (a && !b || !a && b)
|
|
1435
|
+
return false;
|
|
1436
|
+
const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
1437
|
+
const _b = b, {
|
|
1438
|
+
messages: bMessages,
|
|
1439
|
+
tools: bTools,
|
|
1440
|
+
copilotkit: bCopilotkit
|
|
1441
|
+
} = _b, bWithoutConstantKeys = __objRest(_b, [
|
|
1442
|
+
"messages",
|
|
1443
|
+
"tools",
|
|
1444
|
+
"copilotkit"
|
|
1445
|
+
]);
|
|
1446
|
+
return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
|
|
1447
|
+
}
|
|
1448
|
+
function useCoagentStateRenderBridge(agentId, props) {
|
|
1449
|
+
var _a;
|
|
1450
|
+
const { stateSnapshot, messageIndexInRun, message } = props;
|
|
1451
|
+
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
1452
|
+
const { agent } = (0, import_react11.useAgent)({ agentId });
|
|
1453
|
+
const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
|
|
1454
|
+
const runId = (_a = props.runId) != null ? _a : message.runId;
|
|
1455
|
+
const effectiveRunId = runId || "pending";
|
|
1456
|
+
(0, import_react12.useEffect)(() => {
|
|
1457
|
+
if (!agent)
|
|
1458
|
+
return;
|
|
1459
|
+
const subscriber = {
|
|
1460
|
+
onStepStartedEvent: ({ event }) => {
|
|
1461
|
+
if (event.stepName !== nodeName) {
|
|
1462
|
+
setNodeName(event.stepName);
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
onStepFinishedEvent: ({ event }) => {
|
|
1466
|
+
if (event.stepName === nodeName) {
|
|
1467
|
+
setNodeName(void 0);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
1472
|
+
return () => {
|
|
1473
|
+
unsubscribe();
|
|
1474
|
+
};
|
|
1475
|
+
}, [agentId, nodeName]);
|
|
1476
|
+
const getStateRender = (0, import_react12.useCallback)(
|
|
1477
|
+
(messageId) => {
|
|
1478
|
+
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
1479
|
+
if (claimsRef.current[messageId]) {
|
|
1480
|
+
return stateRenderId === claimsRef.current[messageId].stateRenderId;
|
|
1481
|
+
}
|
|
1482
|
+
const matchingAgentName = stateRender.name === agentId;
|
|
1483
|
+
const matchesNodeContext = stateRender.nodeName ? stateRender.nodeName === nodeName : true;
|
|
1484
|
+
return matchingAgentName && matchesNodeContext;
|
|
1485
|
+
});
|
|
1486
|
+
},
|
|
1487
|
+
[coAgentStateRenders, nodeName, agentId]
|
|
1488
|
+
);
|
|
1489
|
+
const handleRenderRequest = ({
|
|
1490
|
+
stateRenderId,
|
|
1491
|
+
messageId,
|
|
1492
|
+
runId: runId2,
|
|
1493
|
+
stateSnapshot: renderSnapshot
|
|
1494
|
+
}) => {
|
|
1495
|
+
if (claimsRef.current[messageId]) {
|
|
1496
|
+
const canRender = claimsRef.current[messageId].stateRenderId === stateRenderId;
|
|
1497
|
+
if (canRender && runId2 && (!claimsRef.current[messageId].runId || claimsRef.current[messageId].runId === "pending")) {
|
|
1498
|
+
claimsRef.current[messageId].runId = runId2;
|
|
1499
|
+
}
|
|
1500
|
+
return canRender;
|
|
1501
|
+
}
|
|
1502
|
+
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
1503
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
|
|
1504
|
+
);
|
|
1505
|
+
if (renderClaimedByOtherMessage) {
|
|
1506
|
+
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
1507
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
1508
|
+
return true;
|
|
1509
|
+
}
|
|
1510
|
+
return false;
|
|
1511
|
+
}
|
|
1512
|
+
if (!runId2) {
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
1516
|
+
return true;
|
|
1517
|
+
};
|
|
1518
|
+
return (0, import_react12.useMemo)(() => {
|
|
1519
|
+
var _a2, _b, _c;
|
|
1520
|
+
if (messageIndexInRun !== 0) {
|
|
1521
|
+
return null;
|
|
1522
|
+
}
|
|
1523
|
+
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
1524
|
+
if (!stateRender || !stateRenderId) {
|
|
1525
|
+
return null;
|
|
1526
|
+
}
|
|
1527
|
+
const snapshot = stateSnapshot ? (0, import_shared9.parseJson)(stateSnapshot, stateSnapshot) : agent == null ? void 0 : agent.state;
|
|
1528
|
+
const canRender = handleRenderRequest({
|
|
1529
|
+
stateRenderId,
|
|
1530
|
+
messageId: message.id,
|
|
1531
|
+
runId: effectiveRunId,
|
|
1532
|
+
stateSnapshot: snapshot
|
|
1533
|
+
});
|
|
1534
|
+
if (!canRender) {
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
if (snapshot && !claimsRef.current[message.id].locked) {
|
|
1538
|
+
if (stateSnapshot) {
|
|
1539
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
1540
|
+
claimsRef.current[message.id].locked = true;
|
|
1541
|
+
} else {
|
|
1542
|
+
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (stateRender.handler) {
|
|
1546
|
+
stateRender.handler({
|
|
1547
|
+
state: stateSnapshot ? (0, import_shared9.parseJson)(stateSnapshot, stateSnapshot) : (_b = agent == null ? void 0 : agent.state) != null ? _b : {},
|
|
1548
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
if (stateRender.render) {
|
|
1552
|
+
const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" : "complete";
|
|
1553
|
+
if (typeof stateRender.render === "string")
|
|
1554
|
+
return stateRender.render;
|
|
1555
|
+
return stateRender.render({
|
|
1556
|
+
status,
|
|
1557
|
+
// Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
|
|
1558
|
+
state: (_c = claimsRef.current[message.id].stateSnapshot) != null ? _c : {},
|
|
1559
|
+
nodeName: nodeName != null ? nodeName : ""
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
}, [
|
|
1563
|
+
getStateRender,
|
|
1564
|
+
stateSnapshot,
|
|
1565
|
+
agent == null ? void 0 : agent.state,
|
|
1566
|
+
agent == null ? void 0 : agent.isRunning,
|
|
1567
|
+
nodeName,
|
|
1568
|
+
effectiveRunId,
|
|
1569
|
+
message.id,
|
|
1570
|
+
messageIndexInRun
|
|
1571
|
+
]);
|
|
1572
|
+
}
|
|
1573
|
+
function CoAgentStateRenderBridge(props) {
|
|
1574
|
+
return useCoagentStateRenderBridge(props.agentId, props);
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// src/components/CopilotListeners.tsx
|
|
1578
|
+
var import_react13 = require("react");
|
|
1579
|
+
var import_react14 = require("@copilotkitnext/react");
|
|
1580
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1581
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1582
|
+
var usePredictStateSubscription = (agent) => {
|
|
1583
|
+
const predictStateToolsRef = (0, import_react13.useRef)([]);
|
|
1584
|
+
const getSubscriber = (0, import_react13.useCallback)(
|
|
1585
|
+
(agent2) => ({
|
|
1586
|
+
onCustomEvent: ({ event }) => {
|
|
1587
|
+
if (event.name === "PredictState") {
|
|
1588
|
+
predictStateToolsRef.current = event.value;
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
1592
|
+
predictStateToolsRef.current.forEach((t) => {
|
|
1593
|
+
if ((t == null ? void 0 : t.tool) !== toolCallName)
|
|
1594
|
+
return;
|
|
1595
|
+
const emittedState = typeof partialToolCallArgs === "string" ? (0, import_shared10.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
|
|
1596
|
+
agent2.setState({
|
|
1597
|
+
[t.state_key]: emittedState[t.state_key]
|
|
1598
|
+
});
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}),
|
|
1602
|
+
[]
|
|
1603
|
+
);
|
|
1604
|
+
(0, import_react13.useEffect)(() => {
|
|
1605
|
+
if (!agent)
|
|
1606
|
+
return;
|
|
1607
|
+
const subscriber = getSubscriber(agent);
|
|
1608
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
1609
|
+
return () => {
|
|
1610
|
+
unsubscribe();
|
|
1611
|
+
};
|
|
1612
|
+
}, [agent, getSubscriber]);
|
|
1613
|
+
};
|
|
1614
|
+
function CopilotListeners() {
|
|
1615
|
+
const { copilotkit } = (0, import_react14.useCopilotKit)();
|
|
1616
|
+
const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
|
|
1617
|
+
const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
|
|
1618
|
+
const { setBannerError } = useToast();
|
|
1619
|
+
const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
|
|
1620
|
+
usePredictStateSubscription(agent);
|
|
1621
|
+
(0, import_react13.useEffect)(() => {
|
|
1622
|
+
const subscriber = {
|
|
1623
|
+
onError: ({ error }) => {
|
|
1624
|
+
setBannerError(new import_shared11.CopilotKitLowLevelError({ error, message: error.message }));
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
const subscription = copilotkit.subscribe(subscriber);
|
|
1628
|
+
return () => {
|
|
1629
|
+
subscription.unsubscribe();
|
|
1630
|
+
};
|
|
1631
|
+
}, [copilotkit == null ? void 0 : copilotkit.subscribe]);
|
|
1632
|
+
return null;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
1636
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1637
|
+
function CopilotKit(_a) {
|
|
1638
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1639
|
+
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
1640
|
+
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
1641
|
+
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
1642
|
+
const renderArr = (0, import_react15.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
1643
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1644
|
+
import_react16.CopilotKitProvider,
|
|
1645
|
+
__spreadProps(__spreadValues({}, props), {
|
|
1646
|
+
showDevConsole: showInspector,
|
|
1647
|
+
renderCustomMessages: renderArr,
|
|
1648
|
+
useSingleEndpoint: true,
|
|
1649
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
1650
|
+
})
|
|
1651
|
+
) }) }) });
|
|
1652
|
+
}
|
|
1653
|
+
function CopilotKitInternal(cpkProps) {
|
|
1654
|
+
var _b;
|
|
1655
|
+
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
1656
|
+
validateProps(cpkProps);
|
|
1657
|
+
const publicApiKey = props.publicLicenseKey || props.publicApiKey;
|
|
1658
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared12.COPILOT_CLOUD_CHAT_URL;
|
|
1659
|
+
const [actions, setActions] = (0, import_react15.useState)({});
|
|
1660
|
+
const [registeredActionConfigs, setRegisteredActionConfigs] = (0, import_react15.useState)(/* @__PURE__ */ new Map());
|
|
1661
|
+
const chatComponentsCache = (0, import_react15.useRef)({
|
|
1662
|
+
actions: {},
|
|
1663
|
+
coAgentStateRenders: {}
|
|
1664
|
+
});
|
|
1665
|
+
const { addElement, removeElement, printTree, getAllElements } = use_tree_default();
|
|
1666
|
+
const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
|
|
1667
|
+
const [chatInstructions, setChatInstructions] = (0, import_react15.useState)("");
|
|
1668
|
+
const [authStates, setAuthStates] = (0, import_react15.useState)({});
|
|
1669
|
+
const [extensions, setExtensions] = (0, import_react15.useState)({});
|
|
1670
|
+
const [additionalInstructions, setAdditionalInstructions] = (0, import_react15.useState)([]);
|
|
1671
|
+
const {
|
|
1672
|
+
addElement: addDocument,
|
|
1673
|
+
removeElement: removeDocument,
|
|
1674
|
+
allElements: allDocuments
|
|
1675
|
+
} = use_flat_category_store_default();
|
|
1676
|
+
const setAction = (0, import_react15.useCallback)((id, action) => {
|
|
1677
|
+
setActions((prevPoints) => {
|
|
1678
|
+
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
1679
|
+
[id]: action
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
}, []);
|
|
1683
|
+
const removeAction = (0, import_react15.useCallback)((id) => {
|
|
1684
|
+
setActions((prevPoints) => {
|
|
1685
|
+
const newPoints = __spreadValues({}, prevPoints);
|
|
1686
|
+
delete newPoints[id];
|
|
1687
|
+
return newPoints;
|
|
1688
|
+
});
|
|
1689
|
+
}, []);
|
|
1690
|
+
const getContextString = (0, import_react15.useCallback)(
|
|
1691
|
+
(documents, categories) => {
|
|
1692
|
+
const documentsString = documents.map((document) => {
|
|
1693
|
+
return `${document.name} (${document.sourceApplication}):
|
|
1694
|
+
${document.getContents()}`;
|
|
1695
|
+
}).join("\n\n");
|
|
1696
|
+
const nonDocumentStrings = printTree(categories);
|
|
1697
|
+
return `${documentsString}
|
|
1698
|
+
|
|
1699
|
+
${nonDocumentStrings}`;
|
|
1700
|
+
},
|
|
1701
|
+
[printTree]
|
|
1702
|
+
);
|
|
1703
|
+
const addContext = (0, import_react15.useCallback)(
|
|
1704
|
+
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
1705
|
+
return addElement(context, categories, parentId);
|
|
1706
|
+
},
|
|
1707
|
+
[addElement]
|
|
1708
|
+
);
|
|
1709
|
+
const removeContext = (0, import_react15.useCallback)(
|
|
1710
|
+
(id) => {
|
|
1711
|
+
removeElement(id);
|
|
1712
|
+
},
|
|
1713
|
+
[removeElement]
|
|
1714
|
+
);
|
|
1715
|
+
const getAllContext = (0, import_react15.useCallback)(() => {
|
|
1716
|
+
return getAllElements();
|
|
1717
|
+
}, [getAllElements]);
|
|
1718
|
+
const getFunctionCallHandler = (0, import_react15.useCallback)(
|
|
1719
|
+
(customEntryPoints) => {
|
|
1720
|
+
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
1721
|
+
},
|
|
1722
|
+
[actions]
|
|
1723
|
+
);
|
|
1724
|
+
const getDocumentsContext = (0, import_react15.useCallback)(
|
|
1725
|
+
(categories) => {
|
|
1726
|
+
return allDocuments(categories);
|
|
1727
|
+
},
|
|
1728
|
+
[allDocuments]
|
|
1729
|
+
);
|
|
1730
|
+
const addDocumentContext = (0, import_react15.useCallback)(
|
|
1731
|
+
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
1732
|
+
return addDocument(documentPointer, categories);
|
|
1733
|
+
},
|
|
1734
|
+
[addDocument]
|
|
1735
|
+
);
|
|
1736
|
+
const removeDocumentContext = (0, import_react15.useCallback)(
|
|
1737
|
+
(documentId) => {
|
|
1738
|
+
removeDocument(documentId);
|
|
1739
|
+
},
|
|
1740
|
+
[removeDocument]
|
|
1741
|
+
);
|
|
1742
|
+
const copilotApiConfig = (0, import_react15.useMemo)(() => {
|
|
1743
|
+
var _a2, _b2;
|
|
1744
|
+
let cloud = void 0;
|
|
1745
|
+
if (publicApiKey) {
|
|
1746
|
+
cloud = {
|
|
1747
|
+
guardrails: {
|
|
1748
|
+
input: {
|
|
1749
|
+
restrictToTopic: {
|
|
1750
|
+
enabled: Boolean(props.guardrails_c),
|
|
1751
|
+
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
1752
|
+
invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
return __spreadProps(__spreadValues({
|
|
1759
|
+
publicApiKey
|
|
1760
|
+
}, cloud ? { cloud } : {}), {
|
|
1761
|
+
chatApiEndpoint,
|
|
1762
|
+
headers: props.headers || {},
|
|
1763
|
+
properties: props.properties || {},
|
|
1764
|
+
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
1765
|
+
textToSpeechUrl: props.textToSpeechUrl,
|
|
1766
|
+
credentials: props.credentials
|
|
1767
|
+
});
|
|
1768
|
+
}, [
|
|
1769
|
+
publicApiKey,
|
|
1770
|
+
props.headers,
|
|
1771
|
+
props.properties,
|
|
1772
|
+
props.transcribeAudioUrl,
|
|
1773
|
+
props.textToSpeechUrl,
|
|
1774
|
+
props.credentials,
|
|
1775
|
+
props.cloudRestrictToTopic,
|
|
1776
|
+
props.guardrails_c
|
|
1777
|
+
]);
|
|
1778
|
+
const headers = (0, import_react15.useMemo)(() => {
|
|
1779
|
+
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
1780
|
+
if (state.status === "authenticated" && state.authHeaders) {
|
|
1781
|
+
return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
|
|
1782
|
+
(headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
|
|
1783
|
+
[key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
|
|
1784
|
+
}),
|
|
1785
|
+
{}
|
|
1786
|
+
));
|
|
1787
|
+
}
|
|
1788
|
+
return acc;
|
|
1789
|
+
}, {});
|
|
1790
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared12.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
1791
|
+
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
1792
|
+
const [internalErrorHandlers, _setInternalErrorHandler] = (0, import_react15.useState)({});
|
|
1793
|
+
const setInternalErrorHandler = (0, import_react15.useCallback)((handler) => {
|
|
1794
|
+
_setInternalErrorHandler((prev) => __spreadValues(__spreadValues({}, prev), handler));
|
|
1795
|
+
}, []);
|
|
1796
|
+
const removeInternalErrorHandler = (0, import_react15.useCallback)((key) => {
|
|
1797
|
+
_setInternalErrorHandler((prev) => {
|
|
1798
|
+
const _a2 = prev, { [key]: _removed } = _a2, rest = __objRest(_a2, [__restKey(key)]);
|
|
1799
|
+
return rest;
|
|
1800
|
+
});
|
|
1801
|
+
}, []);
|
|
1802
|
+
const onErrorRef = (0, import_react15.useRef)(props.onError);
|
|
1803
|
+
(0, import_react15.useEffect)(() => {
|
|
1804
|
+
onErrorRef.current = props.onError;
|
|
1805
|
+
}, [props.onError]);
|
|
1806
|
+
const internalHandlersRef = (0, import_react15.useRef)({});
|
|
1807
|
+
(0, import_react15.useEffect)(() => {
|
|
1808
|
+
internalHandlersRef.current = internalErrorHandlers;
|
|
1809
|
+
}, [internalErrorHandlers]);
|
|
1810
|
+
const handleErrors = (0, import_react15.useCallback)(
|
|
1811
|
+
(error) => __async(this, null, function* () {
|
|
1812
|
+
if (copilotApiConfig.publicApiKey && onErrorRef.current) {
|
|
1813
|
+
try {
|
|
1814
|
+
yield onErrorRef.current(error);
|
|
1815
|
+
} catch (e) {
|
|
1816
|
+
console.error("Error in public onError handler:", e);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const handlers = Object.values(internalHandlersRef.current);
|
|
1820
|
+
yield Promise.all(
|
|
1821
|
+
handlers.map(
|
|
1822
|
+
(h) => Promise.resolve(h(error)).catch(
|
|
1823
|
+
(e) => console.error("Error in internal error handler:", e)
|
|
1824
|
+
)
|
|
1825
|
+
)
|
|
1826
|
+
);
|
|
1827
|
+
}),
|
|
1828
|
+
[copilotApiConfig.publicApiKey]
|
|
1829
|
+
);
|
|
1830
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react15.useState)({});
|
|
1831
|
+
const addChatSuggestionConfiguration = (0, import_react15.useCallback)(
|
|
1832
|
+
(id, suggestion) => {
|
|
1833
|
+
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1834
|
+
},
|
|
1835
|
+
[setChatSuggestionConfiguration]
|
|
1836
|
+
);
|
|
1837
|
+
const removeChatSuggestionConfiguration = (0, import_react15.useCallback)(
|
|
1838
|
+
(id) => {
|
|
1839
|
+
setChatSuggestionConfiguration((prev) => {
|
|
1840
|
+
const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
|
|
1841
|
+
return rest;
|
|
1842
|
+
});
|
|
1843
|
+
},
|
|
1844
|
+
[setChatSuggestionConfiguration]
|
|
1845
|
+
);
|
|
1846
|
+
const [availableAgents, setAvailableAgents] = (0, import_react15.useState)([]);
|
|
1847
|
+
const [coagentStates, setCoagentStates] = (0, import_react15.useState)({});
|
|
1848
|
+
const coagentStatesRef = (0, import_react15.useRef)({});
|
|
1849
|
+
const setCoagentStatesWithRef = (0, import_react15.useCallback)(
|
|
1850
|
+
(value) => {
|
|
1851
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
1852
|
+
coagentStatesRef.current = newValue;
|
|
1853
|
+
setCoagentStates((prev) => {
|
|
1854
|
+
return newValue;
|
|
1855
|
+
});
|
|
1856
|
+
},
|
|
1857
|
+
[]
|
|
1858
|
+
);
|
|
1859
|
+
let initialAgentSession = null;
|
|
1860
|
+
if (props.agent) {
|
|
1861
|
+
initialAgentSession = {
|
|
1862
|
+
agentName: props.agent
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
const [agentSession, setAgentSession] = (0, import_react15.useState)(initialAgentSession);
|
|
1866
|
+
(0, import_react15.useEffect)(() => {
|
|
1867
|
+
if (props.agent) {
|
|
1868
|
+
setAgentSession({
|
|
1869
|
+
agentName: props.agent
|
|
1870
|
+
});
|
|
1871
|
+
} else {
|
|
1872
|
+
setAgentSession(null);
|
|
1873
|
+
}
|
|
1874
|
+
}, [props.agent]);
|
|
1875
|
+
const { threadId, setThreadId: setInternalThreadId } = useThreads();
|
|
1876
|
+
const setThreadId = (0, import_react15.useCallback)(
|
|
1877
|
+
(value) => {
|
|
1878
|
+
if (props.threadId) {
|
|
1879
|
+
throw new Error("Cannot call setThreadId() when threadId is provided via props.");
|
|
1880
|
+
}
|
|
1881
|
+
setInternalThreadId(value);
|
|
1882
|
+
},
|
|
1883
|
+
[props.threadId]
|
|
1884
|
+
);
|
|
1885
|
+
const [runId, setRunId] = (0, import_react15.useState)(null);
|
|
1886
|
+
const chatAbortControllerRef = (0, import_react15.useRef)(null);
|
|
1887
|
+
const showDevConsole = shouldShowDevConsole(props.showDevConsole);
|
|
1888
|
+
const [interruptActions, _setInterruptActions] = (0, import_react15.useState)({});
|
|
1889
|
+
const setInterruptAction = (0, import_react15.useCallback)((action) => {
|
|
1890
|
+
_setInterruptActions((prev) => {
|
|
1891
|
+
var _a2;
|
|
1892
|
+
if (action == null || !action.id) {
|
|
1893
|
+
return prev;
|
|
1894
|
+
}
|
|
1895
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
1896
|
+
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
1897
|
+
});
|
|
1898
|
+
});
|
|
1899
|
+
}, []);
|
|
1900
|
+
const removeInterruptAction = (0, import_react15.useCallback)((actionId) => {
|
|
1901
|
+
_setInterruptActions((prev) => {
|
|
1902
|
+
const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
|
|
1903
|
+
return rest;
|
|
1904
|
+
});
|
|
1905
|
+
}, []);
|
|
1906
|
+
const [interruptEventQueue, setInterruptEventQueue] = (0, import_react15.useState)({});
|
|
1907
|
+
const addInterruptEvent = (0, import_react15.useCallback)((queuedEvent) => {
|
|
1908
|
+
setInterruptEventQueue((prev) => {
|
|
1909
|
+
const threadQueue = prev[queuedEvent.threadId] || [];
|
|
1910
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
1911
|
+
[queuedEvent.threadId]: [...threadQueue, queuedEvent]
|
|
1912
|
+
});
|
|
1913
|
+
});
|
|
1914
|
+
}, []);
|
|
1915
|
+
const resolveInterruptEvent = (0, import_react15.useCallback)(
|
|
1916
|
+
(threadId2, eventId, response) => {
|
|
1917
|
+
setInterruptEventQueue((prev) => {
|
|
1918
|
+
const threadQueue = prev[threadId2] || [];
|
|
1919
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
1920
|
+
[threadId2]: threadQueue.map(
|
|
1921
|
+
(queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
|
|
1922
|
+
)
|
|
1923
|
+
});
|
|
1924
|
+
});
|
|
1925
|
+
},
|
|
1926
|
+
[]
|
|
1927
|
+
);
|
|
1928
|
+
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
1929
|
+
const [bannerError, setBannerError] = (0, import_react15.useState)(null);
|
|
1930
|
+
const agentLock = (0, import_react15.useMemo)(() => {
|
|
1931
|
+
var _a2;
|
|
1932
|
+
return (_a2 = props.agent) != null ? _a2 : null;
|
|
1933
|
+
}, [props.agent]);
|
|
1934
|
+
const forwardedParameters = (0, import_react15.useMemo)(
|
|
1935
|
+
() => {
|
|
1936
|
+
var _a2;
|
|
1937
|
+
return (_a2 = props.forwardedParameters) != null ? _a2 : {};
|
|
1938
|
+
},
|
|
1939
|
+
[props.forwardedParameters]
|
|
1940
|
+
);
|
|
1941
|
+
const updateExtensions = (0, import_react15.useCallback)(
|
|
1942
|
+
(newExtensions) => {
|
|
1943
|
+
setExtensions((prev) => {
|
|
1944
|
+
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
1945
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
1946
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
1947
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
1948
|
+
return isEqual ? prev : resolved;
|
|
1949
|
+
});
|
|
1950
|
+
},
|
|
1951
|
+
[setExtensions]
|
|
1952
|
+
);
|
|
1953
|
+
const updateAuthStates = (0, import_react15.useCallback)(
|
|
1954
|
+
(newAuthStates) => {
|
|
1955
|
+
setAuthStates((prev) => {
|
|
1956
|
+
const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
|
|
1957
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
1958
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
1959
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
1960
|
+
return isEqual ? prev : resolved;
|
|
1961
|
+
});
|
|
1962
|
+
},
|
|
1963
|
+
[setAuthStates]
|
|
1964
|
+
);
|
|
1965
|
+
const handleSetRegisteredActions = (0, import_react15.useCallback)((actionConfig) => {
|
|
1966
|
+
const key = actionConfig.action.name || (0, import_shared12.randomUUID)();
|
|
1967
|
+
setRegisteredActionConfigs((prev) => {
|
|
1968
|
+
const newMap = new Map(prev);
|
|
1969
|
+
newMap.set(key, actionConfig);
|
|
1970
|
+
return newMap;
|
|
1971
|
+
});
|
|
1972
|
+
return key;
|
|
1973
|
+
}, []);
|
|
1974
|
+
const handleRemoveRegisteredAction = (0, import_react15.useCallback)((actionKey) => {
|
|
1975
|
+
setRegisteredActionConfigs((prev) => {
|
|
1976
|
+
const newMap = new Map(prev);
|
|
1977
|
+
newMap.delete(actionKey);
|
|
1978
|
+
return newMap;
|
|
1979
|
+
});
|
|
1980
|
+
}, []);
|
|
1981
|
+
const RegisteredActionsRenderer = (0, import_react15.useMemo)(() => {
|
|
1982
|
+
return () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: Array.from(registeredActionConfigs.entries()).map(([key, config]) => {
|
|
1983
|
+
const Component = config.component;
|
|
1984
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Component, { action: config.action }, key);
|
|
1985
|
+
}) });
|
|
1986
|
+
}, [registeredActionConfigs]);
|
|
1987
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1988
|
+
import_react16.CopilotChatConfigurationProvider,
|
|
1989
|
+
{
|
|
1990
|
+
agentId: (_b = props.agent) != null ? _b : "default",
|
|
1991
|
+
threadId,
|
|
1992
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1993
|
+
CopilotContext.Provider,
|
|
1994
|
+
{
|
|
1995
|
+
value: {
|
|
1996
|
+
actions,
|
|
1997
|
+
chatComponentsCache,
|
|
1998
|
+
getFunctionCallHandler,
|
|
1999
|
+
setAction,
|
|
2000
|
+
removeAction,
|
|
2001
|
+
setRegisteredActions: handleSetRegisteredActions,
|
|
2002
|
+
removeRegisteredAction: handleRemoveRegisteredAction,
|
|
2003
|
+
getContextString,
|
|
2004
|
+
addContext,
|
|
2005
|
+
removeContext,
|
|
2006
|
+
getAllContext,
|
|
2007
|
+
getDocumentsContext,
|
|
2008
|
+
addDocumentContext,
|
|
2009
|
+
removeDocumentContext,
|
|
2010
|
+
copilotApiConfig,
|
|
2011
|
+
isLoading,
|
|
2012
|
+
setIsLoading,
|
|
2013
|
+
chatSuggestionConfiguration,
|
|
2014
|
+
addChatSuggestionConfiguration,
|
|
2015
|
+
removeChatSuggestionConfiguration,
|
|
2016
|
+
chatInstructions,
|
|
2017
|
+
setChatInstructions,
|
|
2018
|
+
additionalInstructions,
|
|
2019
|
+
setAdditionalInstructions,
|
|
2020
|
+
showDevConsole,
|
|
2021
|
+
coagentStates,
|
|
2022
|
+
setCoagentStates,
|
|
2023
|
+
coagentStatesRef,
|
|
2024
|
+
setCoagentStatesWithRef,
|
|
2025
|
+
agentSession,
|
|
2026
|
+
setAgentSession,
|
|
2027
|
+
forwardedParameters,
|
|
2028
|
+
agentLock,
|
|
2029
|
+
threadId,
|
|
2030
|
+
setThreadId,
|
|
2031
|
+
runId,
|
|
2032
|
+
setRunId,
|
|
2033
|
+
chatAbortControllerRef,
|
|
2034
|
+
availableAgents,
|
|
2035
|
+
authConfig_c: props.authConfig_c,
|
|
2036
|
+
authStates_c: authStates,
|
|
2037
|
+
setAuthStates_c: updateAuthStates,
|
|
2038
|
+
extensions,
|
|
2039
|
+
setExtensions: updateExtensions,
|
|
2040
|
+
interruptActions,
|
|
2041
|
+
setInterruptAction,
|
|
2042
|
+
removeInterruptAction,
|
|
2043
|
+
interruptEventQueue,
|
|
2044
|
+
addInterruptEvent,
|
|
2045
|
+
resolveInterruptEvent,
|
|
2046
|
+
bannerError,
|
|
2047
|
+
setBannerError,
|
|
2048
|
+
onError: handleErrors,
|
|
2049
|
+
internalErrorHandlers,
|
|
2050
|
+
setInternalErrorHandler,
|
|
2051
|
+
removeInternalErrorHandler
|
|
2052
|
+
},
|
|
2053
|
+
children: [
|
|
2054
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotListeners, {}),
|
|
2055
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(CoAgentStateRendersProvider, { children: [
|
|
2056
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(CopilotMessages, { children: [
|
|
2057
|
+
memoizedChildren,
|
|
2058
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RegisteredActionsRenderer, {})
|
|
2059
|
+
] }) }),
|
|
2060
|
+
bannerError && showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2061
|
+
UsageBanner,
|
|
2062
|
+
{
|
|
2063
|
+
severity: bannerError.severity,
|
|
2064
|
+
message: bannerError.message,
|
|
2065
|
+
onClose: () => setBannerError(null),
|
|
2066
|
+
actions: getErrorActions(bannerError)
|
|
2067
|
+
}
|
|
2068
|
+
)
|
|
2069
|
+
] })
|
|
2070
|
+
]
|
|
2071
|
+
}
|
|
2072
|
+
)
|
|
2073
|
+
}
|
|
2074
|
+
);
|
|
2075
|
+
}
|
|
2076
|
+
var defaultCopilotContextCategories = ["global"];
|
|
2077
|
+
function entryPointsToFunctionCallHandler(actions) {
|
|
2078
|
+
return (_0) => __async(this, [_0], function* ({ name, args }) {
|
|
2079
|
+
let actionsByFunctionName = {};
|
|
2080
|
+
for (let action2 of actions) {
|
|
2081
|
+
actionsByFunctionName[action2.name] = action2;
|
|
2082
|
+
}
|
|
2083
|
+
const action = actionsByFunctionName[name];
|
|
2084
|
+
let result = void 0;
|
|
2085
|
+
if (action) {
|
|
2086
|
+
yield new Promise((resolve, reject) => {
|
|
2087
|
+
(0, import_react_dom.flushSync)(() => __async(this, null, function* () {
|
|
2088
|
+
var _a;
|
|
2089
|
+
try {
|
|
2090
|
+
result = yield (_a = action.handler) == null ? void 0 : _a.call(action, args);
|
|
2091
|
+
resolve();
|
|
2092
|
+
} catch (error) {
|
|
2093
|
+
reject(error);
|
|
2094
|
+
}
|
|
2095
|
+
}));
|
|
2096
|
+
});
|
|
2097
|
+
yield new Promise((resolve) => setTimeout(resolve, 20));
|
|
2098
|
+
}
|
|
2099
|
+
return result;
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
function formatFeatureName(featureName) {
|
|
2103
|
+
return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2104
|
+
}
|
|
2105
|
+
function validateProps(props) {
|
|
2106
|
+
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
2107
|
+
const hasApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
2108
|
+
if (!props.runtimeUrl && !hasApiKey) {
|
|
2109
|
+
throw new import_shared12.ConfigurationError(
|
|
2110
|
+
"Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'"
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
2113
|
+
if (cloudFeatures.length > 0 && !hasApiKey) {
|
|
2114
|
+
throw new import_shared12.MissingPublicApiKeyError(
|
|
2115
|
+
`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
2116
|
+
);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
2121
|
+
var import_react23 = require("react");
|
|
2122
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2123
|
+
|
|
2124
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2125
|
+
var import_react19 = __toESM(require("react"));
|
|
2126
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
2127
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2128
|
+
|
|
2129
|
+
// src/hooks/use-agent-nodename.ts
|
|
2130
|
+
var import_react17 = require("react");
|
|
2131
|
+
var import_react18 = require("@copilotkitnext/react");
|
|
2132
|
+
function useAgentNodeName(agentName) {
|
|
2133
|
+
const { agent } = (0, import_react18.useAgent)({ agentId: agentName });
|
|
2134
|
+
const nodeNameRef = (0, import_react17.useRef)("start");
|
|
2135
|
+
(0, import_react17.useEffect)(() => {
|
|
2136
|
+
if (!agent)
|
|
2137
|
+
return;
|
|
2138
|
+
const subscriber = {
|
|
2139
|
+
onStepStartedEvent: ({ event }) => {
|
|
2140
|
+
nodeNameRef.current = event.stepName;
|
|
2141
|
+
},
|
|
2142
|
+
onRunStartedEvent: () => {
|
|
2143
|
+
nodeNameRef.current = "start";
|
|
2144
|
+
},
|
|
2145
|
+
onRunFinishedEvent: () => {
|
|
2146
|
+
nodeNameRef.current = "end";
|
|
2147
|
+
}
|
|
2148
|
+
};
|
|
2149
|
+
const subscription = agent.subscribe(subscriber);
|
|
2150
|
+
return () => {
|
|
2151
|
+
subscription.unsubscribe();
|
|
2152
|
+
};
|
|
2153
|
+
}, [agent]);
|
|
2154
|
+
return nodeNameRef.current;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2158
|
+
var import_react20 = require("@copilotkitnext/react");
|
|
2159
|
+
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
2160
|
+
return render({ event, result, resolve });
|
|
2161
|
+
};
|
|
2162
|
+
function useLangGraphInterruptRender(agent) {
|
|
2163
|
+
var _a;
|
|
2164
|
+
const {
|
|
2165
|
+
interruptActions,
|
|
2166
|
+
agentSession,
|
|
2167
|
+
threadId,
|
|
2168
|
+
interruptEventQueue,
|
|
2169
|
+
addInterruptEvent,
|
|
2170
|
+
resolveInterruptEvent
|
|
2171
|
+
} = useCopilotContext();
|
|
2172
|
+
const existingConfig = (0, import_react20.useCopilotChatConfiguration)();
|
|
2173
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
2174
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
2175
|
+
(0, import_react19.useEffect)(() => {
|
|
2176
|
+
if (!agent)
|
|
2177
|
+
return;
|
|
2178
|
+
let localInterrupt = null;
|
|
2179
|
+
const subscriber = {
|
|
2180
|
+
onCustomEvent: ({ event }) => {
|
|
2181
|
+
if (event.name === "on_interrupt") {
|
|
2182
|
+
const eventData = {
|
|
2183
|
+
name: import_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
2184
|
+
type: event.type,
|
|
2185
|
+
value: (0, import_shared13.parseJson)(event.value, event.value)
|
|
2186
|
+
};
|
|
2187
|
+
const eventId = (0, import_shared13.dataToUUID)(eventData, "interruptEvents");
|
|
2188
|
+
localInterrupt = {
|
|
2189
|
+
eventId,
|
|
2190
|
+
threadId,
|
|
2191
|
+
event: eventData
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
},
|
|
2195
|
+
onRunStartedEvent: () => {
|
|
2196
|
+
localInterrupt = null;
|
|
2197
|
+
},
|
|
2198
|
+
onRunFinalized: () => {
|
|
2199
|
+
if (localInterrupt) {
|
|
2200
|
+
addInterruptEvent(localInterrupt);
|
|
2201
|
+
localInterrupt = null;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
const { unsubscribe } = agent.subscribe(subscriber);
|
|
2206
|
+
return () => {
|
|
2207
|
+
unsubscribe();
|
|
2208
|
+
};
|
|
2209
|
+
}, [agent, threadId]);
|
|
2210
|
+
const handleResolve = (0, import_react19.useCallback)(
|
|
2211
|
+
(eventId, response) => {
|
|
2212
|
+
agent == null ? void 0 : agent.runAgent({
|
|
2213
|
+
forwardedProps: {
|
|
2214
|
+
command: {
|
|
2215
|
+
resume: response
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2219
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
2220
|
+
},
|
|
2221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2222
|
+
[agent, threadId]
|
|
2223
|
+
);
|
|
2224
|
+
return (0, import_react19.useMemo)(() => {
|
|
2225
|
+
const eventQueue = interruptEventQueue[threadId] || [];
|
|
2226
|
+
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
2227
|
+
if (!currentQueuedEvent || !agentSession)
|
|
2228
|
+
return null;
|
|
2229
|
+
const allActions = Object.values(interruptActions);
|
|
2230
|
+
const matchingAction = allActions.find((action) => {
|
|
2231
|
+
if (!action.enabled)
|
|
2232
|
+
return true;
|
|
2233
|
+
return action.enabled({
|
|
2234
|
+
eventValue: currentQueuedEvent.event.value,
|
|
2235
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
2236
|
+
nodeName
|
|
2237
|
+
})
|
|
2238
|
+
});
|
|
2239
|
+
});
|
|
2240
|
+
if (!matchingAction)
|
|
2241
|
+
return null;
|
|
2242
|
+
const { render, handler } = matchingAction;
|
|
2243
|
+
const resolveInterrupt = (response) => {
|
|
2244
|
+
handleResolve(currentQueuedEvent.eventId, response);
|
|
2245
|
+
};
|
|
2246
|
+
let result = null;
|
|
2247
|
+
if (handler) {
|
|
2248
|
+
result = handler({
|
|
2249
|
+
event: currentQueuedEvent.event,
|
|
2250
|
+
resolve: resolveInterrupt
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
if (!render)
|
|
2254
|
+
return null;
|
|
2255
|
+
return import_react19.default.createElement(InterruptRenderer, {
|
|
2256
|
+
event: currentQueuedEvent.event,
|
|
2257
|
+
result,
|
|
2258
|
+
render,
|
|
2259
|
+
resolve: resolveInterrupt
|
|
2260
|
+
});
|
|
2261
|
+
}, [interruptActions, interruptEventQueue, threadId, agentSession, handleResolve]);
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
2265
|
+
var import_react24 = require("@copilotkitnext/react");
|
|
2266
|
+
|
|
2267
|
+
// src/hooks/use-lazy-tool-renderer.tsx
|
|
2268
|
+
var import_react21 = require("@copilotkitnext/react");
|
|
2269
|
+
var import_react22 = require("react");
|
|
2270
|
+
function useLazyToolRenderer() {
|
|
2271
|
+
const renderToolCall = (0, import_react21.useRenderToolCall)();
|
|
2272
|
+
return (0, import_react22.useCallback)(
|
|
2273
|
+
(message, messages) => {
|
|
2274
|
+
var _a;
|
|
2275
|
+
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
2276
|
+
return null;
|
|
2277
|
+
const toolCall = message.toolCalls[0];
|
|
2278
|
+
if (!toolCall)
|
|
2279
|
+
return null;
|
|
2280
|
+
const toolMessage = messages == null ? void 0 : messages.find(
|
|
2281
|
+
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
2282
|
+
);
|
|
2283
|
+
return () => renderToolCall({
|
|
2284
|
+
toolCall,
|
|
2285
|
+
toolMessage
|
|
2286
|
+
});
|
|
2287
|
+
},
|
|
2288
|
+
[renderToolCall]
|
|
2289
|
+
);
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
2293
|
+
var import_client = require("@ag-ui/client");
|
|
2294
|
+
function useCopilotChatInternal({
|
|
2295
|
+
suggestions,
|
|
2296
|
+
onInProgress,
|
|
2297
|
+
onSubmitMessage,
|
|
2298
|
+
onStopGeneration,
|
|
2299
|
+
onReloadMessages
|
|
2300
|
+
} = {}) {
|
|
2301
|
+
var _a, _b, _c;
|
|
2302
|
+
const { copilotkit } = (0, import_react24.useCopilotKit)();
|
|
2303
|
+
const { threadId, agentSession } = useCopilotContext();
|
|
2304
|
+
const existingConfig = (0, import_react24.useCopilotChatConfiguration)();
|
|
2305
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react23.useState)(false);
|
|
2306
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
2307
|
+
const { agent } = (0, import_react24.useAgent)({ agentId: resolvedAgentId });
|
|
2308
|
+
(0, import_react23.useEffect)(() => {
|
|
2309
|
+
const connect = (agent2) => __async(this, null, function* () {
|
|
2310
|
+
setAgentAvailable(false);
|
|
2311
|
+
try {
|
|
2312
|
+
yield copilotkit.connectAgent({ agent: agent2 });
|
|
2313
|
+
setAgentAvailable(true);
|
|
2314
|
+
} catch (error) {
|
|
2315
|
+
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
2316
|
+
} else {
|
|
2317
|
+
throw error;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
});
|
|
2321
|
+
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
2322
|
+
agent.threadId = existingConfig.threadId;
|
|
2323
|
+
connect(agent);
|
|
2324
|
+
}
|
|
2325
|
+
return () => {
|
|
2326
|
+
};
|
|
2327
|
+
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
2328
|
+
(0, import_react23.useEffect)(() => {
|
|
2329
|
+
onInProgress == null ? void 0 : onInProgress(Boolean(agent == null ? void 0 : agent.isRunning));
|
|
2330
|
+
}, [agent == null ? void 0 : agent.isRunning, onInProgress]);
|
|
2331
|
+
const interrupt = useLangGraphInterruptRender(agent);
|
|
2332
|
+
const reset = () => {
|
|
2333
|
+
agent == null ? void 0 : agent.setMessages([]);
|
|
2334
|
+
agent == null ? void 0 : agent.setState(null);
|
|
2335
|
+
};
|
|
2336
|
+
const deleteMessage = (0, import_react23.useCallback)(
|
|
2337
|
+
(messageId) => {
|
|
2338
|
+
var _a2;
|
|
2339
|
+
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
2340
|
+
(message) => message.id !== messageId
|
|
2341
|
+
);
|
|
2342
|
+
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
2343
|
+
},
|
|
2344
|
+
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
2345
|
+
);
|
|
2346
|
+
const latestDelete = useUpdatedRef(deleteMessage);
|
|
2347
|
+
const latestDeleteFunc = (0, import_react23.useCallback)(
|
|
2348
|
+
(messageId) => {
|
|
2349
|
+
return latestDelete.current(messageId);
|
|
2350
|
+
},
|
|
2351
|
+
[latestDelete]
|
|
2352
|
+
);
|
|
2353
|
+
const currentSuggestions = (0, import_react24.useSuggestions)({ agentId: resolvedAgentId });
|
|
2354
|
+
const reload = useAsyncCallback(
|
|
2355
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
2356
|
+
var _a2;
|
|
2357
|
+
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
2358
|
+
const isLoading = false;
|
|
2359
|
+
if (isLoading || messages.length === 0) {
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
2363
|
+
if (reloadMessageIndex === -1) {
|
|
2364
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
2368
|
+
if (reloadMessageRole !== "assistant") {
|
|
2369
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
let historyCutoff = [messages[0]];
|
|
2373
|
+
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
2374
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
2375
|
+
if (!lastUserMessageBeforeRegenerate) {
|
|
2376
|
+
historyCutoff = [messages[0]];
|
|
2377
|
+
} else {
|
|
2378
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
2379
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
2380
|
+
);
|
|
2381
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
2382
|
+
}
|
|
2383
|
+
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
2384
|
+
historyCutoff = [messages[0], messages[1]];
|
|
2385
|
+
}
|
|
2386
|
+
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
2387
|
+
if (agent) {
|
|
2388
|
+
copilotkit.runAgent({ agent });
|
|
2389
|
+
}
|
|
2390
|
+
return;
|
|
2391
|
+
}),
|
|
2392
|
+
[agent == null ? void 0 : agent.setMessages, copilotkit == null ? void 0 : copilotkit.runAgent]
|
|
2393
|
+
);
|
|
2394
|
+
const latestSendMessageFunc = useAsyncCallback(
|
|
2395
|
+
(message, options) => __async(this, null, function* () {
|
|
2396
|
+
var _a2;
|
|
2397
|
+
if (!agent)
|
|
2398
|
+
return;
|
|
2399
|
+
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
2400
|
+
if (options == null ? void 0 : options.clearSuggestions) {
|
|
2401
|
+
copilotkit.clearSuggestions(resolvedAgentId);
|
|
2402
|
+
}
|
|
2403
|
+
agent == null ? void 0 : agent.addMessage(message);
|
|
2404
|
+
if (followUp) {
|
|
2405
|
+
try {
|
|
2406
|
+
yield copilotkit.runAgent({ agent });
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
console.error("CopilotChat: runAgent failed", error);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
if (onSubmitMessage) {
|
|
2412
|
+
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 : "";
|
|
2413
|
+
onSubmitMessage(content);
|
|
2414
|
+
}
|
|
2415
|
+
}),
|
|
2416
|
+
[agent, copilotkit, resolvedAgentId, onSubmitMessage]
|
|
2417
|
+
);
|
|
2418
|
+
const latestAppendFunc = useAsyncCallback(
|
|
2419
|
+
(message, options) => __async(this, null, function* () {
|
|
2420
|
+
return latestSendMessageFunc((0, import_runtime_client_gql2.gqlToAGUI)([message])[0], options);
|
|
2421
|
+
}),
|
|
2422
|
+
[latestSendMessageFunc]
|
|
2423
|
+
);
|
|
2424
|
+
const latestSetMessagesFunc = (0, import_react23.useCallback)(
|
|
2425
|
+
(messages) => {
|
|
2426
|
+
var _a2, _b2;
|
|
2427
|
+
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
2428
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
2429
|
+
}
|
|
2430
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
2431
|
+
},
|
|
2432
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
2433
|
+
);
|
|
2434
|
+
const latestReload = useUpdatedRef(reload);
|
|
2435
|
+
const latestReloadFunc = useAsyncCallback(
|
|
2436
|
+
(messageId) => __async(this, null, function* () {
|
|
2437
|
+
var _a2;
|
|
2438
|
+
onReloadMessages == null ? void 0 : onReloadMessages({
|
|
2439
|
+
messageId,
|
|
2440
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
2441
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
2442
|
+
});
|
|
2443
|
+
return yield latestReload.current(messageId);
|
|
2444
|
+
}),
|
|
2445
|
+
[latestReload, agent, onReloadMessages]
|
|
2446
|
+
);
|
|
2447
|
+
const latestStopFunc = (0, import_react23.useCallback)(() => {
|
|
2448
|
+
var _a2, _b2;
|
|
2449
|
+
onStopGeneration == null ? void 0 : onStopGeneration({
|
|
2450
|
+
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
2451
|
+
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
2452
|
+
});
|
|
2453
|
+
return (_b2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _b2.call(agent);
|
|
2454
|
+
}, [onStopGeneration, agent]);
|
|
2455
|
+
const latestReset = useUpdatedRef(reset);
|
|
2456
|
+
const latestResetFunc = (0, import_react23.useCallback)(() => {
|
|
2457
|
+
return latestReset.current();
|
|
2458
|
+
}, [latestReset]);
|
|
2459
|
+
const lazyToolRendered = useLazyToolRenderer();
|
|
2460
|
+
const renderCustomMessage = (0, import_react24.useRenderCustomMessages)();
|
|
2461
|
+
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
2462
|
+
copilotkit,
|
|
2463
|
+
agent,
|
|
2464
|
+
agentId: resolvedAgentId,
|
|
2465
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
2466
|
+
});
|
|
2467
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
2468
|
+
const resolvedMessages = (0, import_react23.useMemo)(() => {
|
|
2469
|
+
let processedMessages = allMessages.map((message) => {
|
|
2470
|
+
if (message.role !== "assistant") {
|
|
2471
|
+
return message;
|
|
2472
|
+
}
|
|
2473
|
+
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
2474
|
+
if (lazyRendered) {
|
|
2475
|
+
const renderedGenUi = lazyRendered();
|
|
2476
|
+
if (renderedGenUi) {
|
|
2477
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
2481
|
+
const customRender = renderCustomMessage == null ? void 0 : renderCustomMessage({
|
|
2482
|
+
message,
|
|
2483
|
+
position: "before"
|
|
2484
|
+
});
|
|
2485
|
+
if (customRender) {
|
|
2486
|
+
return customRender;
|
|
2487
|
+
}
|
|
2488
|
+
return legacyCustomMessageRenderer == null ? void 0 : legacyCustomMessageRenderer({ message, position: "before" });
|
|
2489
|
+
} : null;
|
|
2490
|
+
if (bridgeRenderer) {
|
|
2491
|
+
return __spreadProps(__spreadValues({}, message), { generativeUI: bridgeRenderer });
|
|
2492
|
+
}
|
|
2493
|
+
return message;
|
|
2494
|
+
});
|
|
2495
|
+
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
2496
|
+
return processedMessages;
|
|
2497
|
+
}, [
|
|
2498
|
+
agent == null ? void 0 : agent.messages,
|
|
2499
|
+
lazyToolRendered,
|
|
2500
|
+
allMessages,
|
|
2501
|
+
renderCustomMessage,
|
|
2502
|
+
// legacyCustomMessageRenderer,
|
|
2503
|
+
resolvedAgentId
|
|
2504
|
+
]);
|
|
2505
|
+
const renderedSuggestions = (0, import_react23.useMemo)(() => {
|
|
2506
|
+
if (Array.isArray(suggestions)) {
|
|
2507
|
+
return {
|
|
2508
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
2509
|
+
isLoading: false
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
return currentSuggestions;
|
|
2513
|
+
}, [suggestions, currentSuggestions]);
|
|
2514
|
+
return {
|
|
2515
|
+
messages: resolvedMessages,
|
|
2516
|
+
sendMessage: latestSendMessageFunc,
|
|
2517
|
+
appendMessage: latestAppendFunc,
|
|
2518
|
+
setMessages: latestSetMessagesFunc,
|
|
2519
|
+
reloadMessages: latestReloadFunc,
|
|
2520
|
+
stopGeneration: latestStopFunc,
|
|
2521
|
+
reset: latestResetFunc,
|
|
2522
|
+
deleteMessage: latestDeleteFunc,
|
|
2523
|
+
isAvailable: agentAvailable,
|
|
2524
|
+
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
2525
|
+
// mcpServers,
|
|
2526
|
+
// setMcpServers,
|
|
2527
|
+
suggestions: renderedSuggestions.suggestions,
|
|
2528
|
+
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
2529
|
+
generateSuggestions: () => __async(this, null, function* () {
|
|
2530
|
+
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
2531
|
+
}),
|
|
2532
|
+
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
2533
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
2534
|
+
interrupt,
|
|
2535
|
+
agent,
|
|
2536
|
+
threadId
|
|
2537
|
+
};
|
|
2538
|
+
}
|
|
2539
|
+
function useUpdatedRef(value) {
|
|
2540
|
+
const ref = (0, import_react23.useRef)(value);
|
|
2541
|
+
(0, import_react23.useEffect)(() => {
|
|
2542
|
+
ref.current = value;
|
|
2543
|
+
}, [value]);
|
|
2544
|
+
return ref;
|
|
2545
|
+
}
|
|
2546
|
+
function useLegacyCoagentRenderer({
|
|
2547
|
+
copilotkit,
|
|
2548
|
+
agent,
|
|
2549
|
+
agentId,
|
|
2550
|
+
threadId
|
|
2551
|
+
}) {
|
|
2552
|
+
return (0, import_react23.useMemo)(() => {
|
|
2553
|
+
if (!copilotkit || !agent) {
|
|
2554
|
+
return null;
|
|
2555
|
+
}
|
|
2556
|
+
return ({ message, position }) => {
|
|
2557
|
+
var _a;
|
|
2558
|
+
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
2559
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
2560
|
+
const runId = existingRunId || `pending:${message.id}`;
|
|
2561
|
+
const messageIndex = Math.max(
|
|
2562
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
2563
|
+
0
|
|
2564
|
+
);
|
|
2565
|
+
const bridgeProps = {
|
|
2566
|
+
message,
|
|
2567
|
+
position,
|
|
2568
|
+
runId,
|
|
2569
|
+
messageIndex,
|
|
2570
|
+
messageIndexInRun: 0,
|
|
2571
|
+
numberOfMessagesInRun: 1,
|
|
2572
|
+
agentId,
|
|
2573
|
+
stateSnapshot: message.state
|
|
2574
|
+
};
|
|
2575
|
+
return (0, import_react23.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
2576
|
+
};
|
|
2577
|
+
}, [agent, agentId, copilotkit, threadId]);
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
// src/hooks/use-copilot-chat.ts
|
|
2581
|
+
function useCopilotChat(options = {}) {
|
|
2582
|
+
const {
|
|
2583
|
+
visibleMessages,
|
|
2584
|
+
appendMessage,
|
|
2585
|
+
reloadMessages,
|
|
2586
|
+
stopGeneration,
|
|
2587
|
+
reset,
|
|
2588
|
+
isLoading,
|
|
2589
|
+
isAvailable,
|
|
2590
|
+
runChatCompletion,
|
|
2591
|
+
mcpServers,
|
|
2592
|
+
setMcpServers
|
|
2593
|
+
} = useCopilotChatInternal(options);
|
|
2594
|
+
return {
|
|
2595
|
+
visibleMessages,
|
|
2596
|
+
appendMessage,
|
|
2597
|
+
reloadMessages,
|
|
2598
|
+
stopGeneration,
|
|
2599
|
+
reset,
|
|
2600
|
+
isLoading,
|
|
2601
|
+
isAvailable,
|
|
2602
|
+
runChatCompletion,
|
|
2603
|
+
mcpServers,
|
|
2604
|
+
setMcpServers
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
// src/hooks/use-copilot-chat-headless_c.ts
|
|
2609
|
+
var import_react25 = require("react");
|
|
2610
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2611
|
+
var createNonFunctionalReturn = () => ({
|
|
2612
|
+
visibleMessages: [],
|
|
2613
|
+
messages: [],
|
|
2614
|
+
sendMessage: () => __async(void 0, null, function* () {
|
|
2615
|
+
}),
|
|
2616
|
+
appendMessage: () => __async(void 0, null, function* () {
|
|
2617
|
+
}),
|
|
2618
|
+
setMessages: () => {
|
|
2619
|
+
},
|
|
2620
|
+
deleteMessage: () => {
|
|
2621
|
+
},
|
|
2622
|
+
reloadMessages: () => __async(void 0, null, function* () {
|
|
2623
|
+
}),
|
|
2624
|
+
stopGeneration: () => {
|
|
2625
|
+
},
|
|
2626
|
+
reset: () => {
|
|
2627
|
+
},
|
|
2628
|
+
isLoading: false,
|
|
2629
|
+
isAvailable: false,
|
|
2630
|
+
runChatCompletion: () => __async(void 0, null, function* () {
|
|
2631
|
+
return [];
|
|
2632
|
+
}),
|
|
2633
|
+
mcpServers: [],
|
|
2634
|
+
setMcpServers: () => {
|
|
2635
|
+
},
|
|
2636
|
+
suggestions: [],
|
|
2637
|
+
setSuggestions: () => {
|
|
2638
|
+
},
|
|
2639
|
+
generateSuggestions: () => __async(void 0, null, function* () {
|
|
2640
|
+
}),
|
|
2641
|
+
resetSuggestions: () => {
|
|
2642
|
+
},
|
|
2643
|
+
isLoadingSuggestions: false,
|
|
2644
|
+
interrupt: null
|
|
2645
|
+
});
|
|
2646
|
+
function useCopilotChatHeadless_c(options = {}) {
|
|
2647
|
+
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
2648
|
+
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
2649
|
+
const internalResult = useCopilotChatInternal(options);
|
|
2650
|
+
(0, import_react25.useEffect)(() => {
|
|
2651
|
+
if (!hasPublicApiKey) {
|
|
2652
|
+
setBannerError(
|
|
2653
|
+
new import_shared14.CopilotKitError({
|
|
2654
|
+
message: (
|
|
2655
|
+
// add link to documentation here
|
|
2656
|
+
"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."
|
|
2657
|
+
),
|
|
2658
|
+
code: import_shared14.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2659
|
+
severity: import_shared14.Severity.WARNING,
|
|
2660
|
+
visibility: import_shared14.ErrorVisibility.BANNER
|
|
2661
|
+
})
|
|
2662
|
+
);
|
|
2663
|
+
import_shared14.styledConsole.logCopilotKitPlatformMessage();
|
|
2664
|
+
} else {
|
|
2665
|
+
setBannerError(null);
|
|
2666
|
+
}
|
|
2667
|
+
}, [hasPublicApiKey]);
|
|
2668
|
+
if (hasPublicApiKey) {
|
|
2669
|
+
return internalResult;
|
|
2670
|
+
}
|
|
2671
|
+
return createNonFunctionalReturn();
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
// src/hooks/use-copilot-action.ts
|
|
2675
|
+
var import_react32 = require("react");
|
|
2676
|
+
|
|
2677
|
+
// src/hooks/use-frontend-tool.ts
|
|
2678
|
+
var import_react26 = __toESM(require("react"));
|
|
2679
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2680
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
2681
|
+
var import_react27 = require("@copilotkitnext/react");
|
|
2682
|
+
function useFrontendTool(tool, dependencies) {
|
|
2683
|
+
const { name, description, parameters, render, followUp } = tool;
|
|
2684
|
+
const zodParameters = (0, import_shared15.getZodParameters)(parameters);
|
|
2685
|
+
const normalizedRender = (() => {
|
|
2686
|
+
if (typeof render === "undefined") {
|
|
2687
|
+
return void 0;
|
|
2688
|
+
}
|
|
2689
|
+
if (typeof render === "string") {
|
|
2690
|
+
const staticRender = render;
|
|
2691
|
+
return () => import_react26.default.createElement(
|
|
2692
|
+
import_react26.default.Fragment,
|
|
2693
|
+
null,
|
|
2694
|
+
staticRender
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
return (args) => {
|
|
2698
|
+
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
2699
|
+
result: typeof args.result === "string" ? (0, import_shared16.parseJson)(args.result, args.result) : args.result
|
|
2700
|
+
});
|
|
2701
|
+
const rendered = render(renderArgs);
|
|
2702
|
+
if (typeof rendered === "string") {
|
|
2703
|
+
return import_react26.default.createElement(import_react26.default.Fragment, null, rendered);
|
|
2704
|
+
}
|
|
2705
|
+
return rendered != null ? rendered : null;
|
|
2706
|
+
};
|
|
2707
|
+
})();
|
|
2708
|
+
const handlerRef = (0, import_react26.useRef)(tool.handler);
|
|
2709
|
+
(0, import_react26.useEffect)(() => {
|
|
2710
|
+
handlerRef.current = tool.handler;
|
|
2711
|
+
}, [tool.handler, ...dependencies != null ? dependencies : []]);
|
|
2712
|
+
const normalizedHandler = tool.handler ? (args) => {
|
|
2713
|
+
var _a;
|
|
2714
|
+
return (_a = handlerRef.current) == null ? void 0 : _a.call(handlerRef, args);
|
|
2715
|
+
} : void 0;
|
|
2716
|
+
(0, import_react27.useFrontendTool)({
|
|
2717
|
+
name,
|
|
2718
|
+
description,
|
|
2719
|
+
parameters: zodParameters,
|
|
2720
|
+
handler: normalizedHandler,
|
|
2721
|
+
followUp,
|
|
2722
|
+
render: normalizedRender
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
// src/hooks/use-render-tool-call.ts
|
|
2727
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
2728
|
+
var import_react28 = require("react");
|
|
2729
|
+
var import_react29 = require("@copilotkitnext/react");
|
|
2730
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
2731
|
+
function useRenderToolCall2(tool, dependencies) {
|
|
2732
|
+
const { copilotkit } = (0, import_react29.useCopilotKit)();
|
|
2733
|
+
const hasAddedRef = (0, import_react28.useRef)(false);
|
|
2734
|
+
(0, import_react28.useEffect)(() => {
|
|
2735
|
+
const { name, parameters, render } = tool;
|
|
2736
|
+
const zodParameters = (0, import_shared17.getZodParameters)(parameters);
|
|
2737
|
+
const renderToolCall = name === "*" ? (0, import_react29.defineToolCallRenderer)({
|
|
2738
|
+
name: "*",
|
|
2739
|
+
render: (args) => {
|
|
2740
|
+
return render(__spreadProps(__spreadValues({}, args), {
|
|
2741
|
+
result: args.result ? (0, import_shared18.parseJson)(args.result, args.result) : args.result
|
|
2742
|
+
}));
|
|
2743
|
+
}
|
|
2744
|
+
}) : (0, import_react29.defineToolCallRenderer)({
|
|
2745
|
+
name,
|
|
2746
|
+
args: zodParameters,
|
|
2747
|
+
render: (args) => {
|
|
2748
|
+
return render(__spreadProps(__spreadValues({}, args), {
|
|
2749
|
+
result: args.result ? (0, import_shared18.parseJson)(args.result, args.result) : args.result
|
|
2750
|
+
}));
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
const existingIndex = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
|
|
2754
|
+
if (existingIndex !== -1) {
|
|
2755
|
+
copilotkit.renderToolCalls.splice(existingIndex, 1);
|
|
2756
|
+
}
|
|
2757
|
+
copilotkit.renderToolCalls.push(renderToolCall);
|
|
2758
|
+
hasAddedRef.current = true;
|
|
2759
|
+
return () => {
|
|
2760
|
+
if (hasAddedRef.current) {
|
|
2761
|
+
const index = copilotkit.renderToolCalls.findIndex((r) => r.name === name);
|
|
2762
|
+
if (index !== -1) {
|
|
2763
|
+
copilotkit.renderToolCalls.splice(index, 1);
|
|
2764
|
+
}
|
|
2765
|
+
hasAddedRef.current = false;
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
}, [tool, ...dependencies != null ? dependencies : []]);
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
// src/hooks/use-human-in-the-loop.ts
|
|
2772
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
2773
|
+
var import_react30 = require("@copilotkitnext/react");
|
|
2774
|
+
var import_core = require("@copilotkitnext/core");
|
|
2775
|
+
var import_react31 = __toESM(require("react"));
|
|
2776
|
+
function useHumanInTheLoop(tool, dependencies) {
|
|
2777
|
+
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
2778
|
+
const { name, description, parameters, followUp } = toolRest;
|
|
2779
|
+
const zodParameters = (0, import_shared19.getZodParameters)(parameters);
|
|
2780
|
+
const renderRef = (0, import_react31.useRef)(null);
|
|
2781
|
+
(0, import_react31.useEffect)(() => {
|
|
2782
|
+
renderRef.current = (args) => {
|
|
2783
|
+
if (typeof render === "string") {
|
|
2784
|
+
return import_react31.default.createElement(import_react31.default.Fragment, null, render);
|
|
2785
|
+
}
|
|
2786
|
+
if (!render) {
|
|
2787
|
+
return null;
|
|
2788
|
+
}
|
|
2789
|
+
const renderProps = (() => {
|
|
2790
|
+
const mappedArgs = args.args;
|
|
2791
|
+
switch (args.status) {
|
|
2792
|
+
case import_core.ToolCallStatus.InProgress:
|
|
2793
|
+
return {
|
|
2794
|
+
args: mappedArgs,
|
|
2795
|
+
respond: args.respond,
|
|
2796
|
+
status: args.status,
|
|
2797
|
+
handler: void 0
|
|
2798
|
+
};
|
|
2799
|
+
case import_core.ToolCallStatus.Executing:
|
|
2800
|
+
return {
|
|
2801
|
+
args: mappedArgs,
|
|
2802
|
+
respond: args.respond,
|
|
2803
|
+
status: args.status,
|
|
2804
|
+
handler: () => {
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
case import_core.ToolCallStatus.Complete:
|
|
2808
|
+
return {
|
|
2809
|
+
args: mappedArgs,
|
|
2810
|
+
respond: args.respond,
|
|
2811
|
+
status: args.status,
|
|
2812
|
+
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result,
|
|
2813
|
+
handler: void 0
|
|
2814
|
+
};
|
|
2815
|
+
default:
|
|
2816
|
+
throw new import_shared19.CopilotKitError({
|
|
2817
|
+
code: import_shared19.CopilotKitErrorCode.UNKNOWN,
|
|
2818
|
+
message: `Invalid tool call status: ${args.status}`
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
})();
|
|
2822
|
+
const rendered = render(renderProps);
|
|
2823
|
+
if (typeof rendered === "string") {
|
|
2824
|
+
return import_react31.default.createElement(import_react31.default.Fragment, null, rendered);
|
|
2825
|
+
}
|
|
2826
|
+
return rendered != null ? rendered : null;
|
|
2827
|
+
};
|
|
2828
|
+
}, [render, ...dependencies != null ? dependencies : []]);
|
|
2829
|
+
(0, import_react30.useHumanInTheLoop)({
|
|
2830
|
+
name,
|
|
2831
|
+
description,
|
|
2832
|
+
followUp,
|
|
2833
|
+
parameters: zodParameters,
|
|
2834
|
+
render: (args) => {
|
|
2835
|
+
var _a2, _b;
|
|
2836
|
+
return (_b = (_a2 = renderRef.current) == null ? void 0 : _a2.call(renderRef, args)) != null ? _b : null;
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
// src/hooks/use-copilot-action.ts
|
|
2842
|
+
function getActionConfig(action) {
|
|
2843
|
+
if (action.name === "*") {
|
|
2844
|
+
return {
|
|
2845
|
+
type: "render",
|
|
2846
|
+
action
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
2850
|
+
let render = action.render;
|
|
2851
|
+
if (!render && "renderAndWaitForResponse" in action) {
|
|
2852
|
+
render = action.renderAndWaitForResponse;
|
|
2853
|
+
}
|
|
2854
|
+
if (!render && "renderAndWait" in action) {
|
|
2855
|
+
render = action.renderAndWait;
|
|
2856
|
+
}
|
|
2857
|
+
return {
|
|
2858
|
+
type: "hitl",
|
|
2859
|
+
action: __spreadProps(__spreadValues({}, action), { render })
|
|
2860
|
+
};
|
|
2861
|
+
}
|
|
2862
|
+
if ("available" in action) {
|
|
2863
|
+
if (action.available === "enabled" || action.available === "remote") {
|
|
2864
|
+
return {
|
|
2865
|
+
type: "frontend",
|
|
2866
|
+
action
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
if (action.available === "frontend" || action.available === "disabled") {
|
|
2870
|
+
return {
|
|
2871
|
+
type: "render",
|
|
2872
|
+
action
|
|
2873
|
+
};
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
if ("handler" in action) {
|
|
2877
|
+
return {
|
|
2878
|
+
type: "frontend",
|
|
2879
|
+
action
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
throw new Error("Invalid action configuration");
|
|
2883
|
+
}
|
|
2884
|
+
function useCopilotAction(action, dependencies) {
|
|
2885
|
+
const [initialActionConfig] = (0, import_react32.useState)(getActionConfig(action));
|
|
2886
|
+
const currentActionConfig = getActionConfig(action);
|
|
2887
|
+
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
2888
|
+
throw new Error("Action configuration changed between renders");
|
|
2889
|
+
}
|
|
2890
|
+
switch (currentActionConfig.type) {
|
|
2891
|
+
case "render":
|
|
2892
|
+
return useRenderToolCall2(currentActionConfig.action, dependencies);
|
|
2893
|
+
case "hitl":
|
|
2894
|
+
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
2895
|
+
case "frontend":
|
|
2896
|
+
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
2897
|
+
default:
|
|
2898
|
+
throw new Error("Invalid action configuration");
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
// src/hooks/use-coagent-state-render.ts
|
|
2903
|
+
var import_react33 = require("react");
|
|
2904
|
+
var import_shared20 = require("@copilotkit/shared");
|
|
2905
|
+
function useCoAgentStateRender(action, dependencies) {
|
|
2906
|
+
const { chatComponentsCache, availableAgents } = (0, import_react33.useContext)(CopilotContext);
|
|
2907
|
+
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
2908
|
+
const idRef = (0, import_react33.useRef)((0, import_shared20.randomId)());
|
|
2909
|
+
const { setBannerError, addToast } = useToast();
|
|
2910
|
+
(0, import_react33.useEffect)(() => {
|
|
2911
|
+
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
2912
|
+
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
2913
|
+
const agentError = new import_shared20.CopilotKitAgentDiscoveryError({
|
|
2914
|
+
agentName: action.name,
|
|
2915
|
+
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
2916
|
+
});
|
|
2917
|
+
setBannerError(agentError);
|
|
2918
|
+
}
|
|
2919
|
+
}, [availableAgents]);
|
|
2920
|
+
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
2921
|
+
if (dependencies === void 0) {
|
|
2922
|
+
if (coAgentStateRenders[idRef.current]) {
|
|
2923
|
+
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
2924
|
+
if (typeof action.render === "function") {
|
|
2925
|
+
if (chatComponentsCache.current !== null) {
|
|
2926
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
(0, import_react33.useEffect)(() => {
|
|
2932
|
+
const currentId = idRef.current;
|
|
2933
|
+
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
2934
|
+
if (id === currentId)
|
|
2935
|
+
return false;
|
|
2936
|
+
if (otherAction.name !== action.name)
|
|
2937
|
+
return false;
|
|
2938
|
+
const hasNodeName = !!action.nodeName;
|
|
2939
|
+
const hasOtherNodeName = !!otherAction.nodeName;
|
|
2940
|
+
if (!hasNodeName && !hasOtherNodeName)
|
|
2941
|
+
return true;
|
|
2942
|
+
if (hasNodeName !== hasOtherNodeName)
|
|
2943
|
+
return false;
|
|
2944
|
+
return action.nodeName === otherAction.nodeName;
|
|
2945
|
+
});
|
|
2946
|
+
if (hasDuplicate) {
|
|
2947
|
+
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`;
|
|
2948
|
+
addToast({
|
|
2949
|
+
type: "warning",
|
|
2950
|
+
message,
|
|
2951
|
+
id: `dup-action-${action.name}`
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
}, [coAgentStateRenders]);
|
|
2955
|
+
(0, import_react33.useEffect)(() => {
|
|
2956
|
+
setCoAgentStateRender(idRef.current, action);
|
|
2957
|
+
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
2958
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
2959
|
+
}
|
|
2960
|
+
return () => {
|
|
2961
|
+
removeCoAgentStateRender(idRef.current);
|
|
2962
|
+
};
|
|
2963
|
+
}, [
|
|
2964
|
+
setCoAgentStateRender,
|
|
2965
|
+
removeCoAgentStateRender,
|
|
2966
|
+
action.name,
|
|
2967
|
+
// include render only if it's a string
|
|
2968
|
+
typeof action.render === "string" ? action.render : void 0,
|
|
2969
|
+
// dependencies set by the developer
|
|
2970
|
+
...dependencies || []
|
|
2971
|
+
]);
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
// src/hooks/use-make-copilot-document-readable.ts
|
|
2975
|
+
var import_react34 = require("react");
|
|
2976
|
+
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
2977
|
+
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
2978
|
+
const idRef = (0, import_react34.useRef)(void 0);
|
|
2979
|
+
(0, import_react34.useEffect)(() => {
|
|
2980
|
+
const id = addDocumentContext(document, categories);
|
|
2981
|
+
idRef.current = id;
|
|
2982
|
+
return () => {
|
|
2983
|
+
removeDocumentContext(id);
|
|
2984
|
+
};
|
|
2985
|
+
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
2986
|
+
return idRef.current;
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
// src/hooks/use-copilot-readable.ts
|
|
2990
|
+
var import_react35 = require("@copilotkitnext/react");
|
|
2991
|
+
var import_react36 = require("react");
|
|
2992
|
+
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
2993
|
+
const { copilotkit } = (0, import_react35.useCopilotKit)();
|
|
2994
|
+
const ctxIdRef = (0, import_react36.useRef)(void 0);
|
|
2995
|
+
(0, import_react36.useEffect)(() => {
|
|
2996
|
+
if (!copilotkit)
|
|
2997
|
+
return;
|
|
2998
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
2999
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
3000
|
+
});
|
|
3001
|
+
if (found) {
|
|
3002
|
+
ctxIdRef.current = found[0];
|
|
3003
|
+
if (available === "disabled")
|
|
3004
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
if (!found && available === "disabled")
|
|
3008
|
+
return;
|
|
3009
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
3010
|
+
description,
|
|
3011
|
+
value: (convert != null ? convert : JSON.stringify)(value)
|
|
3012
|
+
});
|
|
3013
|
+
return () => {
|
|
3014
|
+
if (!ctxIdRef.current)
|
|
3015
|
+
return;
|
|
3016
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
3017
|
+
};
|
|
3018
|
+
}, [description, value, convert]);
|
|
3019
|
+
return ctxIdRef.current;
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
// src/hooks/use-coagent.ts
|
|
3023
|
+
var import_react37 = require("react");
|
|
3024
|
+
var import_react38 = require("@copilotkitnext/react");
|
|
3025
|
+
function useCoAgent(options) {
|
|
3026
|
+
const { agent } = (0, import_react38.useAgent)({ agentId: options.name });
|
|
3027
|
+
const { copilotkit } = (0, import_react38.useCopilotKit)();
|
|
3028
|
+
const nodeName = useAgentNodeName(options.name);
|
|
3029
|
+
const handleStateUpdate = (0, import_react37.useCallback)(
|
|
3030
|
+
(newState) => {
|
|
3031
|
+
if (!agent)
|
|
3032
|
+
return;
|
|
3033
|
+
if (typeof newState === "function") {
|
|
3034
|
+
const updater = newState;
|
|
3035
|
+
agent.setState(updater(agent.state));
|
|
3036
|
+
} else {
|
|
3037
|
+
agent.setState(__spreadValues(__spreadValues({}, agent.state), newState));
|
|
3038
|
+
}
|
|
3039
|
+
},
|
|
3040
|
+
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
3041
|
+
);
|
|
3042
|
+
(0, import_react37.useEffect)(() => {
|
|
3043
|
+
var _a;
|
|
3044
|
+
if (!options.config && !options.configurable)
|
|
3045
|
+
return;
|
|
3046
|
+
let config = (_a = options.config) != null ? _a : {};
|
|
3047
|
+
if (options.configurable) {
|
|
3048
|
+
config = __spreadProps(__spreadValues({}, config), {
|
|
3049
|
+
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
copilotkit.setProperties(config);
|
|
3053
|
+
}, [options.config, options.configurable]);
|
|
3054
|
+
const externalStateStr = (0, import_react37.useMemo)(
|
|
3055
|
+
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
3056
|
+
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
3057
|
+
);
|
|
3058
|
+
(0, import_react37.useEffect)(() => {
|
|
3059
|
+
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
3060
|
+
handleStateUpdate(options.state);
|
|
3061
|
+
}
|
|
3062
|
+
}, [agent, externalStateStr, handleStateUpdate]);
|
|
3063
|
+
const hasStateValues = (0, import_react37.useCallback)((value) => {
|
|
3064
|
+
return Boolean(value && Object.keys(value).length);
|
|
3065
|
+
}, []);
|
|
3066
|
+
const initialStateRef = (0, import_react37.useRef)(
|
|
3067
|
+
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
3068
|
+
);
|
|
3069
|
+
(0, import_react37.useEffect)(() => {
|
|
3070
|
+
if (isExternalStateManagement(options)) {
|
|
3071
|
+
initialStateRef.current = options.state;
|
|
3072
|
+
} else if ("initialState" in options) {
|
|
3073
|
+
initialStateRef.current = options.initialState;
|
|
3074
|
+
}
|
|
3075
|
+
}, [
|
|
3076
|
+
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
3077
|
+
]);
|
|
3078
|
+
(0, import_react37.useEffect)(() => {
|
|
3079
|
+
if (!agent)
|
|
3080
|
+
return;
|
|
3081
|
+
const subscriber = {
|
|
3082
|
+
onStateChanged: (args) => {
|
|
3083
|
+
if (isExternalStateManagement(options)) {
|
|
3084
|
+
options.setState(args.state);
|
|
3085
|
+
}
|
|
3086
|
+
},
|
|
3087
|
+
onRunInitialized: (args) => {
|
|
3088
|
+
const runHasState = hasStateValues(args.state);
|
|
3089
|
+
if (runHasState) {
|
|
3090
|
+
handleStateUpdate(args.state);
|
|
3091
|
+
return;
|
|
3092
|
+
}
|
|
3093
|
+
if (hasStateValues(agent.state)) {
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3096
|
+
if (initialStateRef.current !== void 0) {
|
|
3097
|
+
handleStateUpdate(initialStateRef.current);
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
const subscription = agent.subscribe(subscriber);
|
|
3102
|
+
return () => {
|
|
3103
|
+
subscription.unsubscribe();
|
|
3104
|
+
};
|
|
3105
|
+
}, [agent, handleStateUpdate, hasStateValues]);
|
|
3106
|
+
return (0, import_react37.useMemo)(() => {
|
|
3107
|
+
var _a, _b, _c;
|
|
3108
|
+
if (!agent) {
|
|
3109
|
+
const noop = () => {
|
|
3110
|
+
};
|
|
3111
|
+
const noopAsync = () => __async(this, null, function* () {
|
|
3112
|
+
});
|
|
3113
|
+
const initialState = (
|
|
3114
|
+
// prefer externally provided state if available
|
|
3115
|
+
(_b = (_a = "state" in options && options.state) != null ? _a : (
|
|
3116
|
+
// then initialState if provided
|
|
3117
|
+
"initialState" in options && options.initialState
|
|
3118
|
+
)) != null ? _b : {}
|
|
3119
|
+
);
|
|
3120
|
+
return {
|
|
3121
|
+
name: options.name,
|
|
3122
|
+
nodeName,
|
|
3123
|
+
threadId: void 0,
|
|
3124
|
+
running: false,
|
|
3125
|
+
state: initialState,
|
|
3126
|
+
setState: noop,
|
|
3127
|
+
start: noop,
|
|
3128
|
+
stop: noop,
|
|
3129
|
+
run: noopAsync
|
|
3130
|
+
};
|
|
3131
|
+
}
|
|
3132
|
+
return {
|
|
3133
|
+
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
3134
|
+
nodeName,
|
|
3135
|
+
threadId: agent.threadId,
|
|
3136
|
+
running: agent.isRunning,
|
|
3137
|
+
state: agent.state,
|
|
3138
|
+
setState: handleStateUpdate,
|
|
3139
|
+
// TODO: start and run both have same thing. need to figure out
|
|
3140
|
+
start: agent.runAgent,
|
|
3141
|
+
stop: agent.abortRun,
|
|
3142
|
+
run: agent.runAgent
|
|
3143
|
+
};
|
|
3144
|
+
}, [
|
|
3145
|
+
agent == null ? void 0 : agent.state,
|
|
3146
|
+
agent == null ? void 0 : agent.runAgent,
|
|
3147
|
+
agent == null ? void 0 : agent.abortRun,
|
|
3148
|
+
agent == null ? void 0 : agent.runAgent,
|
|
3149
|
+
agent == null ? void 0 : agent.threadId,
|
|
3150
|
+
agent == null ? void 0 : agent.isRunning,
|
|
3151
|
+
agent == null ? void 0 : agent.agentId,
|
|
3152
|
+
handleStateUpdate,
|
|
3153
|
+
options.name
|
|
3154
|
+
]);
|
|
3155
|
+
}
|
|
3156
|
+
var isExternalStateManagement = (options) => {
|
|
3157
|
+
return "state" in options && "setState" in options;
|
|
3158
|
+
};
|
|
3159
|
+
|
|
3160
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
3161
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
3162
|
+
var import_react39 = require("react");
|
|
3163
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
3164
|
+
var useCopilotRuntimeClient = (options) => {
|
|
3165
|
+
const { setBannerError } = useToast();
|
|
3166
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
3167
|
+
const lastStructuredErrorRef = (0, import_react39.useRef)(null);
|
|
3168
|
+
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
3169
|
+
try {
|
|
3170
|
+
const errorEvent = {
|
|
3171
|
+
type: "error",
|
|
3172
|
+
timestamp: Date.now(),
|
|
3173
|
+
context: {
|
|
3174
|
+
source: "ui",
|
|
3175
|
+
request: {
|
|
3176
|
+
operation: "runtimeClient",
|
|
3177
|
+
url: runtimeOptions.url,
|
|
3178
|
+
startTime: Date.now()
|
|
3179
|
+
},
|
|
3180
|
+
technical: {
|
|
3181
|
+
environment: "browser",
|
|
3182
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
3183
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
3184
|
+
}
|
|
3185
|
+
},
|
|
3186
|
+
error
|
|
3187
|
+
};
|
|
3188
|
+
yield onError(errorEvent);
|
|
3189
|
+
} catch (error2) {
|
|
3190
|
+
console.error("Error in onError handler:", error2);
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3193
|
+
const runtimeClient = (0, import_react39.useMemo)(() => {
|
|
3194
|
+
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
3195
|
+
handleGQLErrors: (error) => {
|
|
3196
|
+
var _a2;
|
|
3197
|
+
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
3198
|
+
const graphQLErrors = error.graphQLErrors;
|
|
3199
|
+
const routeError = (gqlError) => {
|
|
3200
|
+
const extensions = gqlError.extensions;
|
|
3201
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
3202
|
+
if (visibility === import_shared21.ErrorVisibility.SILENT) {
|
|
3203
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
3204
|
+
return;
|
|
3205
|
+
}
|
|
3206
|
+
const now = Date.now();
|
|
3207
|
+
const errorMessage = gqlError.message;
|
|
3208
|
+
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
3209
|
+
return;
|
|
3210
|
+
}
|
|
3211
|
+
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
3212
|
+
const ckError = createStructuredError(gqlError);
|
|
3213
|
+
if (ckError) {
|
|
3214
|
+
setBannerError(ckError);
|
|
3215
|
+
traceUIError(ckError, gqlError);
|
|
3216
|
+
} else {
|
|
3217
|
+
const fallbackError = new import_shared21.CopilotKitError({
|
|
3218
|
+
message: gqlError.message,
|
|
3219
|
+
code: import_shared21.CopilotKitErrorCode.UNKNOWN
|
|
3220
|
+
});
|
|
3221
|
+
setBannerError(fallbackError);
|
|
3222
|
+
traceUIError(fallbackError, gqlError);
|
|
3223
|
+
}
|
|
3224
|
+
};
|
|
3225
|
+
graphQLErrors.forEach(routeError);
|
|
3226
|
+
} else {
|
|
3227
|
+
const fallbackError = new import_shared21.CopilotKitError({
|
|
3228
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
3229
|
+
code: import_shared21.CopilotKitErrorCode.UNKNOWN
|
|
3230
|
+
});
|
|
3231
|
+
setBannerError(fallbackError);
|
|
3232
|
+
traceUIError(fallbackError, error);
|
|
3233
|
+
}
|
|
3234
|
+
},
|
|
3235
|
+
handleGQLWarning: (message) => {
|
|
3236
|
+
console.warn(message);
|
|
3237
|
+
const warningError = new import_shared21.CopilotKitError({
|
|
3238
|
+
message,
|
|
3239
|
+
code: import_shared21.CopilotKitErrorCode.UNKNOWN
|
|
3240
|
+
});
|
|
3241
|
+
setBannerError(warningError);
|
|
3242
|
+
}
|
|
3243
|
+
}));
|
|
3244
|
+
}, [runtimeOptions, setBannerError, onError]);
|
|
3245
|
+
return runtimeClient;
|
|
3246
|
+
};
|
|
3247
|
+
function createStructuredError(gqlError) {
|
|
3248
|
+
var _a, _b, _c;
|
|
3249
|
+
const extensions = gqlError.extensions;
|
|
3250
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
3251
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
3252
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
3253
|
+
if (code) {
|
|
3254
|
+
return new import_shared21.CopilotKitError({ message, code });
|
|
3255
|
+
}
|
|
3256
|
+
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
3257
|
+
return new import_shared21.CopilotKitApiDiscoveryError({ message });
|
|
3258
|
+
}
|
|
3259
|
+
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
3260
|
+
return new import_shared21.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
3261
|
+
}
|
|
3262
|
+
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
3263
|
+
return new import_shared21.CopilotKitAgentDiscoveryError({
|
|
3264
|
+
agentName: "",
|
|
3265
|
+
availableAgents: []
|
|
3266
|
+
});
|
|
3267
|
+
}
|
|
3268
|
+
return null;
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// src/hooks/use-copilot-authenticated-action.ts
|
|
3272
|
+
var import_react40 = require("react");
|
|
3273
|
+
var import_react41 = __toESM(require("react"));
|
|
3274
|
+
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
3275
|
+
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
3276
|
+
const pendingActionRef = (0, import_react40.useRef)(null);
|
|
3277
|
+
const executeAction = (0, import_react40.useCallback)(
|
|
3278
|
+
(props) => {
|
|
3279
|
+
if (typeof action.render === "function") {
|
|
3280
|
+
return action.render(props);
|
|
3281
|
+
}
|
|
3282
|
+
return action.render || import_react41.default.createElement(import_react40.Fragment);
|
|
3283
|
+
},
|
|
3284
|
+
[action]
|
|
3285
|
+
);
|
|
3286
|
+
const wrappedRender = (0, import_react40.useCallback)(
|
|
3287
|
+
(props) => {
|
|
3288
|
+
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
3289
|
+
(state) => state.status === "authenticated"
|
|
3290
|
+
);
|
|
3291
|
+
if (!isAuthenticated) {
|
|
3292
|
+
pendingActionRef.current = props;
|
|
3293
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react41.default.createElement(authConfig_c.SignInComponent, {
|
|
3294
|
+
onSignInComplete: (authState) => {
|
|
3295
|
+
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
3296
|
+
if (pendingActionRef.current) {
|
|
3297
|
+
executeAction(pendingActionRef.current);
|
|
3298
|
+
pendingActionRef.current = null;
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
}) : import_react41.default.createElement(import_react40.Fragment);
|
|
3302
|
+
}
|
|
3303
|
+
return executeAction(props);
|
|
3304
|
+
},
|
|
3305
|
+
[action, authStates_c, setAuthStates_c]
|
|
3306
|
+
);
|
|
3307
|
+
useCopilotAction(
|
|
3308
|
+
__spreadProps(__spreadValues({}, action), {
|
|
3309
|
+
render: wrappedRender
|
|
3310
|
+
}),
|
|
3311
|
+
dependencies
|
|
3312
|
+
);
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
// src/hooks/use-langgraph-interrupt.ts
|
|
3316
|
+
var import_react42 = require("react");
|
|
3317
|
+
var import_shared22 = require("@copilotkit/shared");
|
|
3318
|
+
function useLangGraphInterrupt(action, dependencies) {
|
|
3319
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react42.useContext)(CopilotContext);
|
|
3320
|
+
const { addToast } = useToast();
|
|
3321
|
+
const actionId = (0, import_shared22.dataToUUID)(action, "lgAction");
|
|
3322
|
+
(0, import_react42.useEffect)(() => {
|
|
3323
|
+
if (!action)
|
|
3324
|
+
return;
|
|
3325
|
+
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
3326
|
+
return () => {
|
|
3327
|
+
removeInterruptAction(actionId);
|
|
3328
|
+
};
|
|
3329
|
+
}, [setInterruptAction, removeInterruptAction, threadId, actionId, ...dependencies || []]);
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
// src/hooks/use-copilot-additional-instructions.ts
|
|
3333
|
+
var import_react43 = require("react");
|
|
3334
|
+
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
3335
|
+
const { setAdditionalInstructions } = useCopilotContext();
|
|
3336
|
+
(0, import_react43.useEffect)(() => {
|
|
3337
|
+
if (available === "disabled")
|
|
3338
|
+
return;
|
|
3339
|
+
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
3340
|
+
return () => {
|
|
3341
|
+
setAdditionalInstructions(
|
|
3342
|
+
(prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter((instruction) => instruction !== instructions)) || []
|
|
3343
|
+
);
|
|
3344
|
+
};
|
|
3345
|
+
}, [available, instructions, setAdditionalInstructions, ...dependencies || []]);
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
// src/hooks/use-default-tool.ts
|
|
3349
|
+
function useDefaultTool(tool, dependencies) {
|
|
3350
|
+
useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
3354
|
+
var import_react44 = require("@copilotkitnext/react");
|
|
3355
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
3356
|
+
var _a, _b;
|
|
3357
|
+
const existingConfig = (0, import_react44.useCopilotChatConfiguration)();
|
|
3358
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3359
|
+
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
3360
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
3361
|
+
available,
|
|
3362
|
+
consumerAgentId: resolvedAgentId
|
|
3363
|
+
// Use chatConfig.agentId here
|
|
3364
|
+
});
|
|
3365
|
+
(0, import_react44.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
// src/lib/copilot-task.ts
|
|
3369
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
3370
|
+
|
|
3371
|
+
// src/types/frontend-action.ts
|
|
3372
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
3373
|
+
var import_shared23 = require("@copilotkit/shared");
|
|
3374
|
+
function processActionsForRuntimeRequest(actions) {
|
|
3375
|
+
const filteredActions = actions.filter(
|
|
3376
|
+
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
3377
|
+
).map((action) => {
|
|
3378
|
+
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
3379
|
+
if (action.disabled) {
|
|
3380
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
3381
|
+
} else if (action.available === "disabled") {
|
|
3382
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
3383
|
+
} else if (action.available === "remote") {
|
|
3384
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
3385
|
+
}
|
|
3386
|
+
return {
|
|
3387
|
+
name: action.name,
|
|
3388
|
+
description: action.description || "",
|
|
3389
|
+
jsonSchema: JSON.stringify((0, import_shared23.actionParametersToJsonSchema)(action.parameters || [])),
|
|
3390
|
+
available
|
|
3391
|
+
};
|
|
3392
|
+
});
|
|
3393
|
+
return filteredActions;
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
// src/lib/copilot-task.ts
|
|
3397
|
+
var CopilotTask = class {
|
|
3398
|
+
constructor(config) {
|
|
3399
|
+
this.instructions = config.instructions;
|
|
3400
|
+
this.actions = config.actions || [];
|
|
3401
|
+
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
3402
|
+
this.includeCopilotActions = config.includeCopilotActions !== false;
|
|
3403
|
+
this.forwardedParameters = config.forwardedParameters;
|
|
3404
|
+
}
|
|
3405
|
+
/**
|
|
3406
|
+
* Run the task.
|
|
3407
|
+
* @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
|
|
3408
|
+
* @param data The data to use for the task.
|
|
3409
|
+
*/
|
|
3410
|
+
run(context, data) {
|
|
3411
|
+
return __async(this, null, function* () {
|
|
3412
|
+
var _a, _b, _c;
|
|
3413
|
+
const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
|
|
3414
|
+
for (const fn of this.actions) {
|
|
3415
|
+
actions[fn.name] = fn;
|
|
3416
|
+
}
|
|
3417
|
+
let contextString = "";
|
|
3418
|
+
if (data) {
|
|
3419
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
3420
|
+
}
|
|
3421
|
+
if (this.includeCopilotReadable) {
|
|
3422
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
3423
|
+
}
|
|
3424
|
+
const systemMessage = new import_runtime_client_gql5.TextMessage({
|
|
3425
|
+
content: taskSystemMessage(contextString, this.instructions),
|
|
3426
|
+
role: import_runtime_client_gql5.Role.System
|
|
3427
|
+
});
|
|
3428
|
+
const messages = [systemMessage];
|
|
3429
|
+
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
3430
|
+
url: context.copilotApiConfig.chatApiEndpoint,
|
|
3431
|
+
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
3432
|
+
headers: context.copilotApiConfig.headers,
|
|
3433
|
+
credentials: context.copilotApiConfig.credentials
|
|
3434
|
+
});
|
|
3435
|
+
const response = yield runtimeClient.generateCopilotResponse({
|
|
3436
|
+
data: {
|
|
3437
|
+
frontend: {
|
|
3438
|
+
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
3439
|
+
url: window.location.href
|
|
3440
|
+
},
|
|
3441
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messages)),
|
|
3442
|
+
metadata: {
|
|
3443
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.Task
|
|
3444
|
+
},
|
|
3445
|
+
forwardedParameters: __spreadValues({
|
|
3446
|
+
// if forwardedParameters is provided, use it
|
|
3447
|
+
toolChoice: "required"
|
|
3448
|
+
}, (_a = this.forwardedParameters) != null ? _a : {})
|
|
3449
|
+
},
|
|
3450
|
+
properties: context.copilotApiConfig.properties
|
|
3451
|
+
}).toPromise();
|
|
3452
|
+
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
3453
|
+
const functionCalls = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
3454
|
+
((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
|
|
3455
|
+
).filter((m) => m.isActionExecutionMessage());
|
|
3456
|
+
for (const functionCall of functionCalls) {
|
|
3457
|
+
yield functionCallHandler({
|
|
3458
|
+
messages,
|
|
3459
|
+
name: functionCall.name,
|
|
3460
|
+
args: functionCall.arguments
|
|
3461
|
+
});
|
|
3462
|
+
}
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
};
|
|
3466
|
+
function taskSystemMessage(contextString, instructions) {
|
|
3467
|
+
return `
|
|
3468
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
3469
|
+
|
|
3470
|
+
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
3471
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
3472
|
+
|
|
3473
|
+
The user has provided you with the following context:
|
|
3474
|
+
\`\`\`
|
|
3475
|
+
${contextString}
|
|
3476
|
+
\`\`\`
|
|
3477
|
+
|
|
3478
|
+
They have also provided you with functions you can call to initiate actions on their behalf.
|
|
3479
|
+
|
|
3480
|
+
Please assist them as best you can.
|
|
3481
|
+
|
|
3482
|
+
This is not a conversation, so please do not ask questions. Just call a function without saying anything else.
|
|
3483
|
+
|
|
3484
|
+
The user has given you the following task to complete:
|
|
3485
|
+
|
|
3486
|
+
\`\`\`
|
|
3487
|
+
${instructions}
|
|
3488
|
+
\`\`\`
|
|
3489
|
+
`;
|
|
3490
|
+
}
|
|
3491
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3492
|
+
0 && (module.exports = {
|
|
3493
|
+
CoAgentStateRendersContext,
|
|
3494
|
+
CoAgentStateRendersProvider,
|
|
3495
|
+
CopilotContext,
|
|
3496
|
+
CopilotKit,
|
|
3497
|
+
CopilotMessagesContext,
|
|
3498
|
+
CopilotTask,
|
|
3499
|
+
SUGGESTION_RETRY_CONFIG,
|
|
3500
|
+
ThreadsContext,
|
|
3501
|
+
ThreadsProvider,
|
|
3502
|
+
defaultCopilotContextCategories,
|
|
3503
|
+
shouldShowDevConsole,
|
|
3504
|
+
useCoAgent,
|
|
3505
|
+
useCoAgentStateRender,
|
|
3506
|
+
useCoAgentStateRenders,
|
|
3507
|
+
useCopilotAction,
|
|
3508
|
+
useCopilotAdditionalInstructions,
|
|
3509
|
+
useCopilotAuthenticatedAction_c,
|
|
3510
|
+
useCopilotChat,
|
|
3511
|
+
useCopilotChatHeadless_c,
|
|
3512
|
+
useCopilotChatInternal,
|
|
3513
|
+
useCopilotChatSuggestions,
|
|
3514
|
+
useCopilotContext,
|
|
3515
|
+
useCopilotMessagesContext,
|
|
3516
|
+
useCopilotReadable,
|
|
3517
|
+
useCopilotRuntimeClient,
|
|
3518
|
+
useDefaultTool,
|
|
3519
|
+
useFrontendTool,
|
|
3520
|
+
useHumanInTheLoop,
|
|
3521
|
+
useLangGraphInterrupt,
|
|
3522
|
+
useLangGraphInterruptRender,
|
|
3523
|
+
useLazyToolRenderer,
|
|
3524
|
+
useMakeCopilotDocumentReadable,
|
|
3525
|
+
useRenderToolCall,
|
|
3526
|
+
useThreads
|
|
3527
|
+
});
|
|
3528
|
+
//# sourceMappingURL=index.js.map
|