@copilotkitnext/react 0.0.22-alpha.1 → 0.0.22-alpha.3
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/dist/chunk-32YJ5VJ4.mjs +157 -0
- package/dist/chunk-32YJ5VJ4.mjs.map +1 -0
- package/dist/chunk-36HFWACS.mjs +1 -0
- package/dist/chunk-36HFWACS.mjs.map +1 -0
- package/dist/chunk-3TA5QBSZ.mjs +122 -0
- package/dist/chunk-3TA5QBSZ.mjs.map +1 -0
- package/dist/chunk-46BZRXWT.mjs +16 -0
- package/dist/chunk-46BZRXWT.mjs.map +1 -0
- package/dist/chunk-4UDBR75C.mjs +106 -0
- package/dist/chunk-4UDBR75C.mjs.map +1 -0
- package/dist/chunk-4XJK5IVQ.mjs +83 -0
- package/dist/chunk-4XJK5IVQ.mjs.map +1 -0
- package/dist/chunk-5AAT4Z3C.mjs +107 -0
- package/dist/chunk-5AAT4Z3C.mjs.map +1 -0
- package/dist/chunk-5JNWVLQI.mjs +72 -0
- package/dist/chunk-5JNWVLQI.mjs.map +1 -0
- package/dist/chunk-5SC3CO5Q.mjs +69 -0
- package/dist/chunk-5SC3CO5Q.mjs.map +1 -0
- package/dist/chunk-6VUKDHOD.mjs +1 -0
- package/dist/chunk-6VUKDHOD.mjs.map +1 -0
- package/dist/chunk-AEFM73CL.mjs +32 -0
- package/dist/chunk-AEFM73CL.mjs.map +1 -0
- package/dist/chunk-AI3Z3CHN.mjs +97 -0
- package/dist/chunk-AI3Z3CHN.mjs.map +1 -0
- package/dist/chunk-AXFRCGH6.mjs +107 -0
- package/dist/chunk-AXFRCGH6.mjs.map +1 -0
- package/dist/chunk-BT6C5OPU.mjs +278 -0
- package/dist/chunk-BT6C5OPU.mjs.map +1 -0
- package/dist/chunk-CGLGXQAU.mjs +78 -0
- package/dist/chunk-CGLGXQAU.mjs.map +1 -0
- package/dist/chunk-CSHBUHRW.mjs +69 -0
- package/dist/chunk-CSHBUHRW.mjs.map +1 -0
- package/dist/chunk-CZ3GI3IF.mjs +283 -0
- package/dist/chunk-CZ3GI3IF.mjs.map +1 -0
- package/dist/chunk-DVUQO72Z.mjs +1 -0
- package/dist/chunk-DVUQO72Z.mjs.map +1 -0
- package/dist/chunk-E4HD4M7R.mjs +76 -0
- package/dist/chunk-E4HD4M7R.mjs.map +1 -0
- package/dist/chunk-E56GYBP3.mjs +101 -0
- package/dist/chunk-E56GYBP3.mjs.map +1 -0
- package/dist/chunk-EJ5ZEAAN.mjs +57 -0
- package/dist/chunk-EJ5ZEAAN.mjs.map +1 -0
- package/dist/chunk-ETWJDCGE.mjs +1 -0
- package/dist/chunk-ETWJDCGE.mjs.map +1 -0
- package/dist/chunk-F43IPGPA.mjs +311 -0
- package/dist/chunk-F43IPGPA.mjs.map +1 -0
- package/dist/chunk-FIBK3DYE.mjs +26 -0
- package/dist/chunk-FIBK3DYE.mjs.map +1 -0
- package/dist/chunk-FVURPXQK.mjs +45 -0
- package/dist/chunk-FVURPXQK.mjs.map +1 -0
- package/dist/chunk-FZR2XQKR.mjs +44 -0
- package/dist/chunk-FZR2XQKR.mjs.map +1 -0
- package/dist/chunk-IA4CLXDM.mjs +76 -0
- package/dist/chunk-IA4CLXDM.mjs.map +1 -0
- package/dist/chunk-IH5VFJ4L.mjs +60 -0
- package/dist/chunk-IH5VFJ4L.mjs.map +1 -0
- package/dist/chunk-IICUCI5S.mjs +43 -0
- package/dist/chunk-IICUCI5S.mjs.map +1 -0
- package/dist/chunk-JLVGSNAO.mjs +311 -0
- package/dist/chunk-JLVGSNAO.mjs.map +1 -0
- package/dist/chunk-JWOIINVV.mjs +237 -0
- package/dist/chunk-JWOIINVV.mjs.map +1 -0
- package/dist/chunk-KCVDFZJX.mjs +873 -0
- package/dist/chunk-KCVDFZJX.mjs.map +1 -0
- package/dist/chunk-KPRUSQ3K.mjs +1 -0
- package/dist/chunk-KPRUSQ3K.mjs.map +1 -0
- package/dist/chunk-MWC5OV7Z.mjs +1 -0
- package/dist/chunk-MWC5OV7Z.mjs.map +1 -0
- package/dist/chunk-N5EP5OD5.mjs +1 -0
- package/dist/chunk-N5EP5OD5.mjs.map +1 -0
- package/dist/chunk-NASFZS3N.mjs +43 -0
- package/dist/chunk-NASFZS3N.mjs.map +1 -0
- package/dist/chunk-NB2GZAKG.mjs +131 -0
- package/dist/chunk-NB2GZAKG.mjs.map +1 -0
- package/dist/chunk-NB4DFAZH.mjs +185 -0
- package/dist/chunk-NB4DFAZH.mjs.map +1 -0
- package/dist/chunk-NNAYEAP2.mjs +49 -0
- package/dist/chunk-NNAYEAP2.mjs.map +1 -0
- package/dist/chunk-NNPKBGD6.mjs +37 -0
- package/dist/chunk-NNPKBGD6.mjs.map +1 -0
- package/dist/chunk-OMPVTGXH.mjs +122 -0
- package/dist/chunk-OMPVTGXH.mjs.map +1 -0
- package/dist/chunk-QFBM3ZT2.mjs +45 -0
- package/dist/chunk-QFBM3ZT2.mjs.map +1 -0
- package/dist/chunk-QJ6DZ645.mjs +78 -0
- package/dist/chunk-QJ6DZ645.mjs.map +1 -0
- package/dist/chunk-R5OLAA3L.mjs +135 -0
- package/dist/chunk-R5OLAA3L.mjs.map +1 -0
- package/dist/chunk-RF2CGPHQ.mjs +215 -0
- package/dist/chunk-RF2CGPHQ.mjs.map +1 -0
- package/dist/chunk-RGD2L3Z4.mjs +96 -0
- package/dist/chunk-RGD2L3Z4.mjs.map +1 -0
- package/dist/chunk-RK5P2LG6.mjs +57 -0
- package/dist/chunk-RK5P2LG6.mjs.map +1 -0
- package/dist/chunk-RRXDJCXI.mjs +60 -0
- package/dist/chunk-RRXDJCXI.mjs.map +1 -0
- package/dist/chunk-SPDE34WC.mjs +283 -0
- package/dist/chunk-SPDE34WC.mjs.map +1 -0
- package/dist/chunk-TAUOEJH2.mjs +120 -0
- package/dist/chunk-TAUOEJH2.mjs.map +1 -0
- package/dist/chunk-TKFOXPXF.mjs +157 -0
- package/dist/chunk-TKFOXPXF.mjs.map +1 -0
- package/dist/chunk-UOX5D73C.mjs +22 -0
- package/dist/chunk-UOX5D73C.mjs.map +1 -0
- package/dist/chunk-US4KNAAV.mjs +1 -0
- package/dist/chunk-US4KNAAV.mjs.map +1 -0
- package/dist/chunk-UZB3CTOY.mjs +873 -0
- package/dist/chunk-UZB3CTOY.mjs.map +1 -0
- package/dist/chunk-VBI6JXPC.mjs +1 -0
- package/dist/chunk-VBI6JXPC.mjs.map +1 -0
- package/dist/chunk-VE3SBLU7.mjs +215 -0
- package/dist/chunk-VE3SBLU7.mjs.map +1 -0
- package/dist/chunk-VUHFLJWI.mjs +185 -0
- package/dist/chunk-VUHFLJWI.mjs.map +1 -0
- package/dist/chunk-VVAXSF3M.mjs +61 -0
- package/dist/chunk-VVAXSF3M.mjs.map +1 -0
- package/dist/chunk-W5DUKRCI.mjs +97 -0
- package/dist/chunk-W5DUKRCI.mjs.map +1 -0
- package/dist/chunk-WNRDFAZ5.mjs +22 -0
- package/dist/chunk-WNRDFAZ5.mjs.map +1 -0
- package/dist/chunk-XO4IRKSC.mjs +11 -0
- package/dist/chunk-XO4IRKSC.mjs.map +1 -0
- package/dist/chunk-XU5CEPYQ.mjs +75 -0
- package/dist/chunk-XU5CEPYQ.mjs.map +1 -0
- package/dist/chunk-YPH4BHOY.mjs +39 -0
- package/dist/chunk-YPH4BHOY.mjs.map +1 -0
- package/dist/chunk-YVPPF62K.mjs +32 -0
- package/dist/chunk-YVPPF62K.mjs.map +1 -0
- package/dist/chunk-YZUPVMHC.mjs +1 -0
- package/dist/chunk-YZUPVMHC.mjs.map +1 -0
- package/dist/chunk-Z3OIGQCZ.mjs +75 -0
- package/dist/chunk-Z3OIGQCZ.mjs.map +1 -0
- package/dist/chunk-ZIDT52TM.mjs +131 -0
- package/dist/chunk-ZIDT52TM.mjs.map +1 -0
- package/dist/components/CopilotKitInspector.d.mts +13 -0
- package/dist/components/CopilotKitInspector.d.ts +13 -0
- package/dist/components/CopilotKitInspector.js +69 -0
- package/dist/components/CopilotKitInspector.js.map +1 -0
- package/dist/components/CopilotKitInspector.mjs +7 -0
- package/dist/components/CopilotKitInspector.mjs.map +1 -0
- package/dist/components/WildcardToolCallRender.d.mts +7 -0
- package/dist/components/WildcardToolCallRender.d.ts +7 -0
- package/dist/components/WildcardToolCallRender.js +106 -0
- package/dist/components/WildcardToolCallRender.js.map +1 -0
- package/dist/components/WildcardToolCallRender.mjs +8 -0
- package/dist/components/WildcardToolCallRender.mjs.map +1 -0
- package/dist/components/chat/CopilotChat.d.mts +30 -0
- package/dist/components/chat/CopilotChat.d.ts +30 -0
- package/dist/components/chat/CopilotChat.js +2934 -0
- package/dist/components/chat/CopilotChat.js.map +1 -0
- package/dist/components/chat/CopilotChat.mjs +37 -0
- package/dist/components/chat/CopilotChat.mjs.map +1 -0
- package/dist/components/chat/CopilotChatAssistantMessage.d.mts +45 -0
- package/dist/components/chat/CopilotChatAssistantMessage.d.ts +45 -0
- package/dist/components/chat/CopilotChatAssistantMessage.js +735 -0
- package/dist/components/chat/CopilotChatAssistantMessage.js.map +1 -0
- package/dist/components/chat/CopilotChatAssistantMessage.mjs +29 -0
- package/dist/components/chat/CopilotChatAssistantMessage.mjs.map +1 -0
- package/dist/components/chat/CopilotChatAudioRecorder.d.mts +11 -0
- package/dist/components/chat/CopilotChatAudioRecorder.d.ts +11 -0
- package/dist/components/chat/CopilotChatAudioRecorder.js +131 -0
- package/dist/components/chat/CopilotChatAudioRecorder.js.map +1 -0
- package/dist/components/chat/CopilotChatAudioRecorder.mjs +9 -0
- package/dist/components/chat/CopilotChatAudioRecorder.mjs.map +1 -0
- package/dist/components/chat/CopilotChatInput.d.mts +67 -0
- package/dist/components/chat/CopilotChatInput.d.ts +67 -0
- package/dist/components/chat/CopilotChatInput.js +1305 -0
- package/dist/components/chat/CopilotChatInput.js.map +1 -0
- package/dist/components/chat/CopilotChatInput.mjs +16 -0
- package/dist/components/chat/CopilotChatInput.mjs.map +1 -0
- package/dist/components/chat/CopilotChatMessageView.d.mts +29 -0
- package/dist/components/chat/CopilotChatMessageView.d.ts +29 -0
- package/dist/components/chat/CopilotChatMessageView.js +1164 -0
- package/dist/components/chat/CopilotChatMessageView.js.map +1 -0
- package/dist/components/chat/CopilotChatMessageView.mjs +31 -0
- package/dist/components/chat/CopilotChatMessageView.mjs.map +1 -0
- package/dist/components/chat/CopilotChatSuggestionPill.d.mts +11 -0
- package/dist/components/chat/CopilotChatSuggestionPill.d.ts +11 -0
- package/dist/components/chat/CopilotChatSuggestionPill.js +76 -0
- package/dist/components/chat/CopilotChatSuggestionPill.js.map +1 -0
- package/dist/components/chat/CopilotChatSuggestionPill.mjs +10 -0
- package/dist/components/chat/CopilotChatSuggestionPill.mjs.map +1 -0
- package/dist/components/chat/CopilotChatSuggestionView.d.mts +33 -0
- package/dist/components/chat/CopilotChatSuggestionView.d.ts +33 -0
- package/dist/components/chat/CopilotChatSuggestionView.js +179 -0
- package/dist/components/chat/CopilotChatSuggestionView.js.map +1 -0
- package/dist/components/chat/CopilotChatSuggestionView.mjs +12 -0
- package/dist/components/chat/CopilotChatSuggestionView.mjs.map +1 -0
- package/dist/components/chat/CopilotChatToggleButton.d.mts +14 -0
- package/dist/components/chat/CopilotChatToggleButton.d.ts +14 -0
- package/dist/components/chat/CopilotChatToggleButton.js +222 -0
- package/dist/components/chat/CopilotChatToggleButton.js.map +1 -0
- package/dist/components/chat/CopilotChatToggleButton.mjs +16 -0
- package/dist/components/chat/CopilotChatToggleButton.mjs.map +1 -0
- package/dist/components/chat/CopilotChatToolCallsView.d.mts +10 -0
- package/dist/components/chat/CopilotChatToolCallsView.d.ts +10 -0
- package/dist/components/chat/CopilotChatToolCallsView.js +264 -0
- package/dist/components/chat/CopilotChatToolCallsView.js.map +1 -0
- package/dist/components/chat/CopilotChatToolCallsView.mjs +24 -0
- package/dist/components/chat/CopilotChatToolCallsView.mjs.map +1 -0
- package/dist/components/chat/CopilotChatUserMessage.d.mts +52 -0
- package/dist/components/chat/CopilotChatUserMessage.d.ts +52 -0
- package/dist/components/chat/CopilotChatUserMessage.js +523 -0
- package/dist/components/chat/CopilotChatUserMessage.js.map +1 -0
- package/dist/components/chat/CopilotChatUserMessage.mjs +14 -0
- package/dist/components/chat/CopilotChatUserMessage.mjs.map +1 -0
- package/dist/components/chat/CopilotChatView.d.mts +54 -0
- package/dist/components/chat/CopilotChatView.d.ts +54 -0
- package/dist/components/chat/CopilotChatView.js +2640 -0
- package/dist/components/chat/CopilotChatView.js.map +1 -0
- package/dist/components/chat/CopilotChatView.mjs +38 -0
- package/dist/components/chat/CopilotChatView.mjs.map +1 -0
- package/dist/components/chat/CopilotModalHeader.d.mts +22 -0
- package/dist/components/chat/CopilotModalHeader.d.ts +22 -0
- package/dist/components/chat/CopilotModalHeader.js +186 -0
- package/dist/components/chat/CopilotModalHeader.js.map +1 -0
- package/dist/components/chat/CopilotModalHeader.mjs +12 -0
- package/dist/components/chat/CopilotModalHeader.mjs.map +1 -0
- package/dist/components/chat/CopilotPopup.d.mts +33 -0
- package/dist/components/chat/CopilotPopup.d.ts +33 -0
- package/dist/components/chat/CopilotPopup.js +3343 -0
- package/dist/components/chat/CopilotPopup.js.map +1 -0
- package/dist/components/chat/CopilotPopup.mjs +43 -0
- package/dist/components/chat/CopilotPopup.mjs.map +1 -0
- package/dist/components/chat/CopilotPopupView.d.mts +30 -0
- package/dist/components/chat/CopilotPopupView.d.ts +30 -0
- package/dist/components/chat/CopilotPopupView.js +3003 -0
- package/dist/components/chat/CopilotPopupView.js.map +1 -0
- package/dist/components/chat/CopilotPopupView.mjs +41 -0
- package/dist/components/chat/CopilotPopupView.mjs.map +1 -0
- package/dist/components/chat/CopilotSidebar.d.mts +31 -0
- package/dist/components/chat/CopilotSidebar.d.ts +31 -0
- package/dist/components/chat/CopilotSidebar.js +3266 -0
- package/dist/components/chat/CopilotSidebar.js.map +1 -0
- package/dist/components/chat/CopilotSidebar.mjs +43 -0
- package/dist/components/chat/CopilotSidebar.mjs.map +1 -0
- package/dist/components/chat/CopilotSidebarView.d.mts +28 -0
- package/dist/components/chat/CopilotSidebarView.d.ts +28 -0
- package/dist/components/chat/CopilotSidebarView.js +2941 -0
- package/dist/components/chat/CopilotSidebarView.js.map +1 -0
- package/dist/components/chat/CopilotSidebarView.mjs +41 -0
- package/dist/components/chat/CopilotSidebarView.mjs.map +1 -0
- package/dist/components/chat/index.d.mts +23 -0
- package/dist/components/chat/index.d.ts +23 -0
- package/dist/components/chat/index.js +3503 -0
- package/dist/components/chat/index.js.map +1 -0
- package/dist/components/chat/index.mjs +95 -0
- package/dist/components/chat/index.mjs.map +1 -0
- package/dist/components/index.d.mts +29 -0
- package/dist/components/index.d.ts +29 -0
- package/dist/components/index.js +3583 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +104 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/ui/button.d.mts +14 -0
- package/dist/components/ui/button.d.ts +14 -0
- package/dist/components/ui/button.js +150 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/button.mjs +10 -0
- package/dist/components/ui/button.mjs.map +1 -0
- package/dist/components/ui/dropdown-menu.d.mts +28 -0
- package/dist/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/components/ui/dropdown-menu.js +291 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/dropdown-menu.mjs +37 -0
- package/dist/components/ui/dropdown-menu.mjs.map +1 -0
- package/dist/components/ui/tooltip.d.mts +10 -0
- package/dist/components/ui/tooltip.d.ts +10 -0
- package/dist/components/ui/tooltip.js +103 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/components/ui/tooltip.mjs +14 -0
- package/dist/components/ui/tooltip.mjs.map +1 -0
- package/dist/hooks/index.d.mts +19 -0
- package/dist/hooks/index.d.ts +19 -0
- package/dist/hooks/index.js +691 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +45 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-agent-context.d.mts +5 -0
- package/dist/hooks/use-agent-context.d.ts +5 -0
- package/dist/hooks/use-agent-context.js +116 -0
- package/dist/hooks/use-agent-context.js.map +1 -0
- package/dist/hooks/use-agent-context.mjs +10 -0
- package/dist/hooks/use-agent-context.mjs.map +1 -0
- package/dist/hooks/use-agent.d.mts +16 -0
- package/dist/hooks/use-agent.d.ts +16 -0
- package/dist/hooks/use-agent.js +171 -0
- package/dist/hooks/use-agent.js.map +1 -0
- package/dist/hooks/use-agent.mjs +12 -0
- package/dist/hooks/use-agent.mjs.map +1 -0
- package/dist/hooks/use-configure-suggestions.d.mts +13 -0
- package/dist/hooks/use-configure-suggestions.d.ts +13 -0
- package/dist/hooks/use-configure-suggestions.js +232 -0
- package/dist/hooks/use-configure-suggestions.js.map +1 -0
- package/dist/hooks/use-configure-suggestions.mjs +11 -0
- package/dist/hooks/use-configure-suggestions.mjs.map +1 -0
- package/dist/hooks/use-frontend-tool.d.mts +8 -0
- package/dist/hooks/use-frontend-tool.d.ts +8 -0
- package/dist/hooks/use-frontend-tool.js +137 -0
- package/dist/hooks/use-frontend-tool.js.map +1 -0
- package/dist/hooks/use-frontend-tool.mjs +10 -0
- package/dist/hooks/use-frontend-tool.mjs.map +1 -0
- package/dist/hooks/use-human-in-the-loop.d.mts +7 -0
- package/dist/hooks/use-human-in-the-loop.d.ts +7 -0
- package/dist/hooks/use-human-in-the-loop.js +206 -0
- package/dist/hooks/use-human-in-the-loop.js.map +1 -0
- package/dist/hooks/use-human-in-the-loop.mjs +11 -0
- package/dist/hooks/use-human-in-the-loop.mjs.map +1 -0
- package/dist/hooks/use-keyboard-height.d.mts +15 -0
- package/dist/hooks/use-keyboard-height.d.ts +15 -0
- package/dist/hooks/use-keyboard-height.js +68 -0
- package/dist/hooks/use-keyboard-height.js.map +1 -0
- package/dist/hooks/use-keyboard-height.mjs +7 -0
- package/dist/hooks/use-keyboard-height.mjs.map +1 -0
- package/dist/hooks/use-render-activity-message.d.mts +5 -0
- package/dist/hooks/use-render-activity-message.d.ts +5 -0
- package/dist/hooks/use-render-activity-message.js +158 -0
- package/dist/hooks/use-render-activity-message.js.map +1 -0
- package/dist/hooks/use-render-activity-message.mjs +12 -0
- package/dist/hooks/use-render-activity-message.mjs.map +1 -0
- package/dist/hooks/use-render-custom-messages.d.mts +11 -0
- package/dist/hooks/use-render-custom-messages.d.ts +11 -0
- package/dist/hooks/use-render-custom-messages.js +170 -0
- package/dist/hooks/use-render-custom-messages.js.map +1 -0
- package/dist/hooks/use-render-custom-messages.mjs +12 -0
- package/dist/hooks/use-render-custom-messages.mjs.map +1 -0
- package/dist/hooks/use-render-tool-call.d.mts +16 -0
- package/dist/hooks/use-render-tool-call.d.ts +16 -0
- package/dist/hooks/use-render-tool-call.js +208 -0
- package/dist/hooks/use-render-tool-call.js.map +1 -0
- package/dist/hooks/use-render-tool-call.mjs +11 -0
- package/dist/hooks/use-render-tool-call.mjs.map +1 -0
- package/dist/hooks/use-suggestions.d.mts +14 -0
- package/dist/hooks/use-suggestions.d.ts +14 -0
- package/dist/hooks/use-suggestions.js +176 -0
- package/dist/hooks/use-suggestions.js.map +1 -0
- package/dist/hooks/use-suggestions.mjs +11 -0
- package/dist/hooks/use-suggestions.mjs.map +1 -0
- package/dist/index.d.mts +46 -635
- package/dist/index.d.ts +46 -635
- package/dist/index.mjs +110 -3960
- package/dist/index.mjs.map +1 -1
- package/dist/lib/react-core.d.mts +33 -0
- package/dist/lib/react-core.d.ts +33 -0
- package/dist/lib/react-core.js +73 -0
- package/dist/lib/react-core.js.map +1 -0
- package/dist/lib/react-core.mjs +7 -0
- package/dist/lib/react-core.mjs.map +1 -0
- package/dist/lib/slots.d.mts +16 -0
- package/dist/lib/slots.d.ts +16 -0
- package/dist/lib/slots.js +60 -0
- package/dist/lib/slots.js.map +1 -0
- package/dist/lib/slots.mjs +7 -0
- package/dist/lib/slots.mjs.map +1 -0
- package/dist/lib/utils.d.mts +5 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +35 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.mjs +7 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/providers/CopilotChatConfigurationProvider.d.mts +43 -0
- package/dist/providers/CopilotChatConfigurationProvider.d.ts +43 -0
- package/dist/providers/CopilotChatConfigurationProvider.js +109 -0
- package/dist/providers/CopilotChatConfigurationProvider.js.map +1 -0
- package/dist/providers/CopilotChatConfigurationProvider.mjs +11 -0
- package/dist/providers/CopilotChatConfigurationProvider.mjs.map +1 -0
- package/dist/providers/CopilotKitProvider.d.mts +33 -0
- package/dist/providers/CopilotKitProvider.d.ts +33 -0
- package/dist/providers/CopilotKitProvider.js +314 -0
- package/dist/providers/CopilotKitProvider.js.map +1 -0
- package/dist/providers/CopilotKitProvider.mjs +12 -0
- package/dist/providers/CopilotKitProvider.mjs.map +1 -0
- package/dist/providers/index.d.mts +13 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.js +396 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +18 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/types/defineToolCallRenderer.d.mts +41 -0
- package/dist/types/defineToolCallRenderer.d.ts +41 -0
- package/dist/types/defineToolCallRenderer.js +40 -0
- package/dist/types/defineToolCallRenderer.js.map +1 -0
- package/dist/types/defineToolCallRenderer.mjs +7 -0
- package/dist/types/defineToolCallRenderer.mjs.map +1 -0
- package/dist/types/frontend-tool.d.mts +9 -0
- package/dist/types/frontend-tool.d.ts +9 -0
- package/dist/types/frontend-tool.js +19 -0
- package/dist/types/frontend-tool.js.map +1 -0
- package/dist/types/frontend-tool.mjs +2 -0
- package/dist/types/frontend-tool.mjs.map +1 -0
- package/dist/types/human-in-the-loop.d.mts +29 -0
- package/dist/types/human-in-the-loop.d.ts +29 -0
- package/dist/types/human-in-the-loop.js +19 -0
- package/dist/types/human-in-the-loop.js.map +1 -0
- package/dist/types/human-in-the-loop.mjs +2 -0
- package/dist/types/human-in-the-loop.mjs.map +1 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +42 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +13 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/react-activity-message-renderer.d.mts +29 -0
- package/dist/types/react-activity-message-renderer.d.ts +29 -0
- package/dist/types/react-activity-message-renderer.js +19 -0
- package/dist/types/react-activity-message-renderer.js.map +1 -0
- package/dist/types/react-activity-message-renderer.mjs +2 -0
- package/dist/types/react-activity-message-renderer.mjs.map +1 -0
- package/dist/types/react-custom-message-renderer.d.mts +18 -0
- package/dist/types/react-custom-message-renderer.d.ts +18 -0
- package/dist/types/react-custom-message-renderer.js +19 -0
- package/dist/types/react-custom-message-renderer.js.map +1 -0
- package/dist/types/react-custom-message-renderer.mjs +2 -0
- package/dist/types/react-custom-message-renderer.mjs.map +1 -0
- package/dist/types/react-tool-call-renderer.d.mts +30 -0
- package/dist/types/react-tool-call-renderer.d.ts +30 -0
- package/dist/types/react-tool-call-renderer.js +19 -0
- package/dist/types/react-tool-call-renderer.js.map +1 -0
- package/dist/types/react-tool-call-renderer.mjs +2 -0
- package/dist/types/react-tool-call-renderer.mjs.map +1 -0
- package/package.json +8 -7
package/dist/index.mjs
CHANGED
|
@@ -1,3968 +1,118 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import "./chunk-N5EP5OD5.mjs";
|
|
3
|
+
import "./chunk-KPRUSQ3K.mjs";
|
|
4
|
+
import "./chunk-US4KNAAV.mjs";
|
|
5
|
+
import "./chunk-36HFWACS.mjs";
|
|
6
|
+
import "./chunk-DVUQO72Z.mjs";
|
|
7
|
+
import "./chunk-VBI6JXPC.mjs";
|
|
8
|
+
import "./chunk-MWC5OV7Z.mjs";
|
|
9
|
+
import "./chunk-6VUKDHOD.mjs";
|
|
4
10
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
useEffect as useEffect2,
|
|
8
|
-
useLayoutEffect,
|
|
9
|
-
forwardRef as forwardRef2,
|
|
10
|
-
useImperativeHandle as useImperativeHandle2,
|
|
11
|
-
useCallback,
|
|
12
|
-
useMemo as useMemo2
|
|
13
|
-
} from "react";
|
|
14
|
-
import { twMerge as twMerge3 } from "tailwind-merge";
|
|
15
|
-
import { Plus, Mic, ArrowUp, X, Check, Square } from "lucide-react";
|
|
16
|
-
|
|
17
|
-
// src/providers/CopilotChatConfigurationProvider.tsx
|
|
18
|
-
import { createContext, useContext, useMemo, useState } from "react";
|
|
19
|
-
import { DEFAULT_AGENT_ID, randomUUID } from "@copilotkitnext/shared";
|
|
20
|
-
import { jsx } from "react/jsx-runtime";
|
|
21
|
-
var CopilotChatDefaultLabels = {
|
|
22
|
-
chatInputPlaceholder: "Type a message...",
|
|
23
|
-
chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
|
|
24
|
-
chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
|
|
25
|
-
chatInputToolbarFinishTranscribeButtonLabel: "Finish",
|
|
26
|
-
chatInputToolbarAddButtonLabel: "Add photos or files",
|
|
27
|
-
chatInputToolbarToolsButtonLabel: "Tools",
|
|
28
|
-
assistantMessageToolbarCopyCodeLabel: "Copy",
|
|
29
|
-
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
30
|
-
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
31
|
-
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
32
|
-
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
33
|
-
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
34
|
-
assistantMessageToolbarRegenerateLabel: "Regenerate",
|
|
35
|
-
userMessageToolbarCopyMessageLabel: "Copy",
|
|
36
|
-
userMessageToolbarEditMessageLabel: "Edit",
|
|
37
|
-
chatDisclaimerText: "AI can make mistakes. Please verify important information.",
|
|
38
|
-
chatToggleOpenLabel: "Open chat",
|
|
39
|
-
chatToggleCloseLabel: "Close chat",
|
|
40
|
-
modalHeaderTitle: "CopilotKit Chat"
|
|
41
|
-
};
|
|
42
|
-
var CopilotChatConfiguration = createContext(null);
|
|
43
|
-
var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, isModalDefaultOpen }) => {
|
|
44
|
-
const parentConfig = useContext(CopilotChatConfiguration);
|
|
45
|
-
const mergedLabels = useMemo(
|
|
46
|
-
() => ({
|
|
47
|
-
...CopilotChatDefaultLabels,
|
|
48
|
-
...parentConfig?.labels ?? {},
|
|
49
|
-
...labels ?? {}
|
|
50
|
-
}),
|
|
51
|
-
[labels, parentConfig?.labels]
|
|
52
|
-
);
|
|
53
|
-
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? DEFAULT_AGENT_ID;
|
|
54
|
-
const resolvedThreadId = useMemo(() => {
|
|
55
|
-
if (threadId) {
|
|
56
|
-
return threadId;
|
|
57
|
-
}
|
|
58
|
-
if (parentConfig?.threadId) {
|
|
59
|
-
return parentConfig.threadId;
|
|
60
|
-
}
|
|
61
|
-
return randomUUID();
|
|
62
|
-
}, [threadId, parentConfig?.threadId]);
|
|
63
|
-
const resolvedDefaultOpen = isModalDefaultOpen ?? parentConfig?.isModalDefaultOpen ?? true;
|
|
64
|
-
const [internalModalOpen, setInternalModalOpen] = useState(
|
|
65
|
-
parentConfig?.isModalOpen ?? resolvedDefaultOpen
|
|
66
|
-
);
|
|
67
|
-
const resolvedIsModalOpen = parentConfig?.isModalOpen ?? internalModalOpen;
|
|
68
|
-
const resolvedSetModalOpen = parentConfig?.setModalOpen ?? setInternalModalOpen;
|
|
69
|
-
const configurationValue = useMemo(
|
|
70
|
-
() => ({
|
|
71
|
-
labels: mergedLabels,
|
|
72
|
-
agentId: resolvedAgentId,
|
|
73
|
-
threadId: resolvedThreadId,
|
|
74
|
-
isModalOpen: resolvedIsModalOpen,
|
|
75
|
-
setModalOpen: resolvedSetModalOpen,
|
|
76
|
-
isModalDefaultOpen: resolvedDefaultOpen
|
|
77
|
-
}),
|
|
78
|
-
[
|
|
79
|
-
mergedLabels,
|
|
80
|
-
resolvedAgentId,
|
|
81
|
-
resolvedThreadId,
|
|
82
|
-
resolvedIsModalOpen,
|
|
83
|
-
resolvedSetModalOpen,
|
|
84
|
-
resolvedDefaultOpen
|
|
85
|
-
]
|
|
86
|
-
);
|
|
87
|
-
return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, { value: configurationValue, children });
|
|
88
|
-
};
|
|
89
|
-
var useCopilotChatConfiguration = () => {
|
|
90
|
-
const configuration = useContext(CopilotChatConfiguration);
|
|
91
|
-
return configuration;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// src/components/ui/button.tsx
|
|
95
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
96
|
-
import { cva } from "class-variance-authority";
|
|
97
|
-
|
|
98
|
-
// src/lib/utils.ts
|
|
99
|
-
import { clsx } from "clsx";
|
|
100
|
-
import { twMerge } from "tailwind-merge";
|
|
101
|
-
function cn(...inputs) {
|
|
102
|
-
return twMerge(clsx(inputs));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/components/ui/button.tsx
|
|
106
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
107
|
-
var buttonVariants = cva(
|
|
108
|
-
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
109
|
-
{
|
|
110
|
-
variants: {
|
|
111
|
-
variant: {
|
|
112
|
-
default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
|
113
|
-
destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
114
|
-
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
115
|
-
secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
|
116
|
-
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50 cursor-pointer",
|
|
117
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
118
|
-
assistantMessageToolbarButton: [
|
|
119
|
-
"cursor-pointer",
|
|
120
|
-
// Background and text
|
|
121
|
-
"p-0 text-[rgb(93,93,93)] hover:bg-[#E8E8E8]",
|
|
122
|
-
// Dark mode - lighter gray for better contrast
|
|
123
|
-
"dark:text-[rgb(243,243,243)] dark:hover:bg-[#303030]",
|
|
124
|
-
// Shape and sizing
|
|
125
|
-
"h-8 w-8",
|
|
126
|
-
// Interactions
|
|
127
|
-
"transition-colors",
|
|
128
|
-
// Hover states
|
|
129
|
-
"hover:text-[rgb(93,93,93)]",
|
|
130
|
-
"dark:hover:text-[rgb(243,243,243)]"
|
|
131
|
-
],
|
|
132
|
-
chatInputToolbarPrimary: [
|
|
133
|
-
"cursor-pointer",
|
|
134
|
-
// Background and text
|
|
135
|
-
"bg-black text-white",
|
|
136
|
-
// Dark mode
|
|
137
|
-
"dark:bg-white dark:text-black dark:focus-visible:outline-white",
|
|
138
|
-
// Shape and sizing
|
|
139
|
-
"rounded-full",
|
|
140
|
-
// Interactions
|
|
141
|
-
"transition-colors",
|
|
142
|
-
// Focus states
|
|
143
|
-
"focus:outline-none",
|
|
144
|
-
// Hover states
|
|
145
|
-
"hover:opacity-70 disabled:hover:opacity-100",
|
|
146
|
-
// Disabled states
|
|
147
|
-
"disabled:cursor-not-allowed disabled:bg-[#00000014] disabled:text-[rgb(13,13,13)]",
|
|
148
|
-
"dark:disabled:bg-[#454545] dark:disabled:text-white "
|
|
149
|
-
],
|
|
150
|
-
chatInputToolbarSecondary: [
|
|
151
|
-
"cursor-pointer",
|
|
152
|
-
// Background and text
|
|
153
|
-
"bg-transparent text-[#444444]",
|
|
154
|
-
// Dark mode
|
|
155
|
-
"dark:text-white dark:border-[#404040]",
|
|
156
|
-
// Shape and sizing
|
|
157
|
-
"rounded-full",
|
|
158
|
-
// Interactions
|
|
159
|
-
"transition-colors",
|
|
160
|
-
// Focus states
|
|
161
|
-
"focus:outline-none",
|
|
162
|
-
// Hover states
|
|
163
|
-
"hover:bg-[#f8f8f8] hover:text-[#333333]",
|
|
164
|
-
"dark:hover:bg-[#404040] dark:hover:text-[#FFFFFF]",
|
|
165
|
-
// Disabled states
|
|
166
|
-
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
167
|
-
"disabled:hover:bg-transparent disabled:hover:text-[#444444]",
|
|
168
|
-
"dark:disabled:hover:bg-transparent dark:disabled:hover:text-[#CCCCCC]"
|
|
169
|
-
]
|
|
170
|
-
},
|
|
171
|
-
size: {
|
|
172
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
173
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
174
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
175
|
-
icon: "size-9",
|
|
176
|
-
chatInputToolbarIcon: [
|
|
177
|
-
// Shape and sizing
|
|
178
|
-
"h-9 w-9 rounded-full"
|
|
179
|
-
],
|
|
180
|
-
chatInputToolbarIconLabel: [
|
|
181
|
-
// Shape and sizing
|
|
182
|
-
"h-9 px-3 rounded-full",
|
|
183
|
-
// Layout
|
|
184
|
-
"gap-2",
|
|
185
|
-
// Typography
|
|
186
|
-
"font-normal"
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
defaultVariants: {
|
|
191
|
-
variant: "default",
|
|
192
|
-
size: "default"
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
);
|
|
196
|
-
function Button({
|
|
197
|
-
className,
|
|
198
|
-
variant,
|
|
199
|
-
size,
|
|
200
|
-
asChild = false,
|
|
201
|
-
...props
|
|
202
|
-
}) {
|
|
203
|
-
const Comp = asChild ? Slot : "button";
|
|
204
|
-
return /* @__PURE__ */ jsx2(
|
|
205
|
-
Comp,
|
|
206
|
-
{
|
|
207
|
-
"data-slot": "button",
|
|
208
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
209
|
-
...props
|
|
210
|
-
}
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/components/ui/tooltip.tsx
|
|
215
|
-
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
216
|
-
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
217
|
-
function TooltipProvider({
|
|
218
|
-
delayDuration = 0,
|
|
219
|
-
...props
|
|
220
|
-
}) {
|
|
221
|
-
return /* @__PURE__ */ jsx3(
|
|
222
|
-
TooltipPrimitive.Provider,
|
|
223
|
-
{
|
|
224
|
-
"data-slot": "tooltip-provider",
|
|
225
|
-
delayDuration,
|
|
226
|
-
...props
|
|
227
|
-
}
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
function Tooltip({
|
|
231
|
-
...props
|
|
232
|
-
}) {
|
|
233
|
-
return /* @__PURE__ */ jsx3(TooltipProvider, { children: /* @__PURE__ */ jsx3(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
|
|
234
|
-
}
|
|
235
|
-
function TooltipTrigger({
|
|
236
|
-
...props
|
|
237
|
-
}) {
|
|
238
|
-
return /* @__PURE__ */ jsx3(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
|
|
239
|
-
}
|
|
240
|
-
function TooltipContent({
|
|
241
|
-
className,
|
|
242
|
-
sideOffset = 0,
|
|
243
|
-
children,
|
|
244
|
-
...props
|
|
245
|
-
}) {
|
|
246
|
-
return /* @__PURE__ */ jsx3(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
|
|
247
|
-
TooltipPrimitive.Content,
|
|
248
|
-
{
|
|
249
|
-
"data-slot": "tooltip-content",
|
|
250
|
-
sideOffset,
|
|
251
|
-
className: cn(
|
|
252
|
-
"bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
|
253
|
-
className
|
|
254
|
-
),
|
|
255
|
-
...props,
|
|
256
|
-
children: [
|
|
257
|
-
children,
|
|
258
|
-
/* @__PURE__ */ jsx3(TooltipPrimitive.Arrow, { className: "bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
|
|
259
|
-
]
|
|
260
|
-
}
|
|
261
|
-
) });
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/components/ui/dropdown-menu.tsx
|
|
265
|
-
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
266
|
-
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
|
|
267
|
-
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
268
|
-
function DropdownMenu({
|
|
269
|
-
...props
|
|
270
|
-
}) {
|
|
271
|
-
return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
|
|
272
|
-
}
|
|
273
|
-
function DropdownMenuTrigger({
|
|
274
|
-
...props
|
|
275
|
-
}) {
|
|
276
|
-
return /* @__PURE__ */ jsx4(
|
|
277
|
-
DropdownMenuPrimitive.Trigger,
|
|
278
|
-
{
|
|
279
|
-
"data-slot": "dropdown-menu-trigger",
|
|
280
|
-
...props
|
|
281
|
-
}
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
function DropdownMenuContent({
|
|
285
|
-
className,
|
|
286
|
-
sideOffset = 4,
|
|
287
|
-
...props
|
|
288
|
-
}) {
|
|
289
|
-
return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx4(
|
|
290
|
-
DropdownMenuPrimitive.Content,
|
|
291
|
-
{
|
|
292
|
-
"data-slot": "dropdown-menu-content",
|
|
293
|
-
sideOffset,
|
|
294
|
-
className: cn(
|
|
295
|
-
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
|
296
|
-
className
|
|
297
|
-
),
|
|
298
|
-
...props
|
|
299
|
-
}
|
|
300
|
-
) });
|
|
301
|
-
}
|
|
302
|
-
function DropdownMenuItem({
|
|
303
|
-
className,
|
|
304
|
-
inset,
|
|
305
|
-
variant = "default",
|
|
306
|
-
...props
|
|
307
|
-
}) {
|
|
308
|
-
return /* @__PURE__ */ jsx4(
|
|
309
|
-
DropdownMenuPrimitive.Item,
|
|
310
|
-
{
|
|
311
|
-
"data-slot": "dropdown-menu-item",
|
|
312
|
-
"data-inset": inset,
|
|
313
|
-
"data-variant": variant,
|
|
314
|
-
className: cn(
|
|
315
|
-
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
316
|
-
className
|
|
317
|
-
),
|
|
318
|
-
...props
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
function DropdownMenuSeparator({
|
|
323
|
-
className,
|
|
324
|
-
...props
|
|
325
|
-
}) {
|
|
326
|
-
return /* @__PURE__ */ jsx4(
|
|
327
|
-
DropdownMenuPrimitive.Separator,
|
|
328
|
-
{
|
|
329
|
-
"data-slot": "dropdown-menu-separator",
|
|
330
|
-
className: cn("bg-border -mx-1 my-1 h-px", className),
|
|
331
|
-
...props
|
|
332
|
-
}
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
function DropdownMenuSub({
|
|
336
|
-
...props
|
|
337
|
-
}) {
|
|
338
|
-
return /* @__PURE__ */ jsx4(DropdownMenuPrimitive.Sub, { "data-slot": "dropdown-menu-sub", ...props });
|
|
339
|
-
}
|
|
340
|
-
function DropdownMenuSubTrigger({
|
|
341
|
-
className,
|
|
342
|
-
inset,
|
|
343
|
-
children,
|
|
344
|
-
...props
|
|
345
|
-
}) {
|
|
346
|
-
return /* @__PURE__ */ jsxs2(
|
|
347
|
-
DropdownMenuPrimitive.SubTrigger,
|
|
348
|
-
{
|
|
349
|
-
"data-slot": "dropdown-menu-sub-trigger",
|
|
350
|
-
"data-inset": inset,
|
|
351
|
-
className: cn(
|
|
352
|
-
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
|
|
353
|
-
className
|
|
354
|
-
),
|
|
355
|
-
...props,
|
|
356
|
-
children: [
|
|
357
|
-
children,
|
|
358
|
-
/* @__PURE__ */ jsx4(ChevronRightIcon, { className: "ml-auto size-4" })
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
function DropdownMenuSubContent({
|
|
364
|
-
className,
|
|
365
|
-
...props
|
|
366
|
-
}) {
|
|
367
|
-
return /* @__PURE__ */ jsx4(
|
|
368
|
-
DropdownMenuPrimitive.SubContent,
|
|
369
|
-
{
|
|
370
|
-
"data-slot": "dropdown-menu-sub-content",
|
|
371
|
-
className: cn(
|
|
372
|
-
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
|
373
|
-
className
|
|
374
|
-
),
|
|
375
|
-
...props
|
|
376
|
-
}
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/components/chat/CopilotChatAudioRecorder.tsx
|
|
381
|
-
import { useRef, useEffect, useImperativeHandle, forwardRef } from "react";
|
|
382
|
-
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
383
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
384
|
-
var AudioRecorderError = class extends Error {
|
|
385
|
-
constructor(message) {
|
|
386
|
-
super(message);
|
|
387
|
-
this.name = "AudioRecorderError";
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
var CopilotChatAudioRecorder = forwardRef((props, ref) => {
|
|
391
|
-
const { className, ...divProps } = props;
|
|
392
|
-
const canvasRef = useRef(null);
|
|
393
|
-
const getLoudness = (n) => {
|
|
394
|
-
const elapsed = Date.now() / 1e3;
|
|
395
|
-
const samples = [];
|
|
396
|
-
for (let i = 0; i < n; i++) {
|
|
397
|
-
const position = i / n * 10 + elapsed * 0.5;
|
|
398
|
-
const wave1 = Math.sin(position * 2) * 0.3;
|
|
399
|
-
const wave2 = Math.sin(position * 5 + elapsed) * 0.2;
|
|
400
|
-
const wave3 = Math.sin(position * 0.5 + elapsed * 0.3) * 0.4;
|
|
401
|
-
const noise = (Math.random() - 0.5) * 0.1;
|
|
402
|
-
const envelope = Math.sin(elapsed * 0.7) * 0.5 + 0.5;
|
|
403
|
-
let amplitude = (wave1 + wave2 + wave3 + noise) * envelope;
|
|
404
|
-
amplitude = Math.max(0, Math.min(1, amplitude * 0.5 + 0.3));
|
|
405
|
-
samples.push(amplitude);
|
|
406
|
-
}
|
|
407
|
-
return samples;
|
|
408
|
-
};
|
|
409
|
-
useEffect(() => {
|
|
410
|
-
const canvas = canvasRef.current;
|
|
411
|
-
if (!canvas) return;
|
|
412
|
-
const ctx = canvas.getContext("2d");
|
|
413
|
-
if (!ctx) return;
|
|
414
|
-
let animationId;
|
|
415
|
-
const draw = () => {
|
|
416
|
-
const rect = canvas.getBoundingClientRect();
|
|
417
|
-
const dpr = window.devicePixelRatio || 1;
|
|
418
|
-
if (canvas.width !== rect.width * dpr || canvas.height !== rect.height * dpr) {
|
|
419
|
-
canvas.width = rect.width * dpr;
|
|
420
|
-
canvas.height = rect.height * dpr;
|
|
421
|
-
ctx.scale(dpr, dpr);
|
|
422
|
-
ctx.imageSmoothingEnabled = false;
|
|
423
|
-
}
|
|
424
|
-
const barWidth = 2;
|
|
425
|
-
const minHeight = 2;
|
|
426
|
-
const maxHeight = 20;
|
|
427
|
-
const gap = 2;
|
|
428
|
-
const numSamples = Math.ceil(rect.width / (barWidth + gap));
|
|
429
|
-
const loudnessData = getLoudness(numSamples);
|
|
430
|
-
ctx.clearRect(0, 0, rect.width, rect.height);
|
|
431
|
-
const computedStyle = getComputedStyle(canvas);
|
|
432
|
-
const currentForeground = computedStyle.color;
|
|
433
|
-
ctx.fillStyle = currentForeground;
|
|
434
|
-
const centerY = rect.height / 2;
|
|
435
|
-
for (let i = 0; i < loudnessData.length; i++) {
|
|
436
|
-
const sample = loudnessData[i] ?? 0;
|
|
437
|
-
const barHeight = Math.round(
|
|
438
|
-
sample * (maxHeight - minHeight) + minHeight
|
|
439
|
-
);
|
|
440
|
-
const x = Math.round(i * (barWidth + gap));
|
|
441
|
-
const y = Math.round(centerY - barHeight / 2);
|
|
442
|
-
ctx.fillRect(x, y, barWidth, barHeight);
|
|
443
|
-
}
|
|
444
|
-
animationId = requestAnimationFrame(draw);
|
|
445
|
-
};
|
|
446
|
-
draw();
|
|
447
|
-
return () => {
|
|
448
|
-
if (animationId) {
|
|
449
|
-
cancelAnimationFrame(animationId);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}, []);
|
|
453
|
-
useImperativeHandle(
|
|
454
|
-
ref,
|
|
455
|
-
() => ({
|
|
456
|
-
get state() {
|
|
457
|
-
return "idle";
|
|
458
|
-
},
|
|
459
|
-
start: async () => {
|
|
460
|
-
},
|
|
461
|
-
stop: () => new Promise((resolve) => {
|
|
462
|
-
const emptyBlob = new Blob([], { type: "audio/webm" });
|
|
463
|
-
resolve(emptyBlob);
|
|
464
|
-
}),
|
|
465
|
-
dispose: () => {
|
|
466
|
-
}
|
|
467
|
-
}),
|
|
468
|
-
[]
|
|
469
|
-
);
|
|
470
|
-
return /* @__PURE__ */ jsx5("div", { className: twMerge2("h-[44px] w-full px-5", className), ...divProps, children: /* @__PURE__ */ jsx5(
|
|
471
|
-
"canvas",
|
|
472
|
-
{
|
|
473
|
-
ref: canvasRef,
|
|
474
|
-
className: "w-full h-full",
|
|
475
|
-
style: { imageRendering: "pixelated" }
|
|
476
|
-
}
|
|
477
|
-
) });
|
|
478
|
-
});
|
|
479
|
-
CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
|
|
480
|
-
|
|
481
|
-
// src/lib/slots.tsx
|
|
482
|
-
import React2 from "react";
|
|
483
|
-
function renderSlot(slot, DefaultComponent, props) {
|
|
484
|
-
if (typeof slot === "string") {
|
|
485
|
-
return React2.createElement(DefaultComponent, {
|
|
486
|
-
...props,
|
|
487
|
-
className: slot
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
if (typeof slot === "function") {
|
|
491
|
-
const Comp = slot;
|
|
492
|
-
return React2.createElement(Comp, props);
|
|
493
|
-
}
|
|
494
|
-
if (slot && typeof slot === "object" && !React2.isValidElement(slot)) {
|
|
495
|
-
return React2.createElement(DefaultComponent, {
|
|
496
|
-
...props,
|
|
497
|
-
...slot
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
return React2.createElement(DefaultComponent, props);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/components/chat/CopilotChatInput.tsx
|
|
504
|
-
import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
505
|
-
var SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
|
|
506
|
-
var SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
507
|
-
function CopilotChatInput({
|
|
508
|
-
mode = "input",
|
|
509
|
-
onSubmitMessage,
|
|
510
|
-
onStop,
|
|
511
|
-
isRunning = false,
|
|
512
|
-
onStartTranscribe,
|
|
513
|
-
onCancelTranscribe,
|
|
514
|
-
onFinishTranscribe,
|
|
515
|
-
onAddFile,
|
|
516
|
-
onChange,
|
|
517
|
-
value,
|
|
518
|
-
toolsMenu,
|
|
519
|
-
autoFocus = true,
|
|
520
|
-
textArea,
|
|
521
|
-
sendButton,
|
|
522
|
-
startTranscribeButton,
|
|
523
|
-
cancelTranscribeButton,
|
|
524
|
-
finishTranscribeButton,
|
|
525
|
-
addMenuButton,
|
|
526
|
-
audioRecorder,
|
|
527
|
-
children,
|
|
528
|
-
className,
|
|
529
|
-
...props
|
|
530
|
-
}) {
|
|
531
|
-
const isControlled = value !== void 0;
|
|
532
|
-
const [internalValue, setInternalValue] = useState2(() => value ?? "");
|
|
533
|
-
useEffect2(() => {
|
|
534
|
-
if (!isControlled && value !== void 0) {
|
|
535
|
-
setInternalValue(value);
|
|
536
|
-
}
|
|
537
|
-
}, [isControlled, value]);
|
|
538
|
-
const resolvedValue = isControlled ? value ?? "" : internalValue;
|
|
539
|
-
const [layout, setLayout] = useState2("compact");
|
|
540
|
-
const ignoreResizeRef = useRef2(false);
|
|
541
|
-
const resizeEvaluationRafRef = useRef2(null);
|
|
542
|
-
const isExpanded = mode === "input" && layout === "expanded";
|
|
543
|
-
const [commandQuery, setCommandQuery] = useState2(null);
|
|
544
|
-
const [slashHighlightIndex, setSlashHighlightIndex] = useState2(0);
|
|
545
|
-
const inputRef = useRef2(null);
|
|
546
|
-
const gridRef = useRef2(null);
|
|
547
|
-
const addButtonContainerRef = useRef2(null);
|
|
548
|
-
const actionsContainerRef = useRef2(null);
|
|
549
|
-
const audioRecorderRef = useRef2(null);
|
|
550
|
-
const slashMenuRef = useRef2(null);
|
|
551
|
-
const config = useCopilotChatConfiguration();
|
|
552
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
553
|
-
const previousModalStateRef = useRef2(void 0);
|
|
554
|
-
const measurementCanvasRef = useRef2(null);
|
|
555
|
-
const measurementsRef = useRef2({
|
|
556
|
-
singleLineHeight: 0,
|
|
557
|
-
maxHeight: 0,
|
|
558
|
-
paddingLeft: 0,
|
|
559
|
-
paddingRight: 0
|
|
560
|
-
});
|
|
561
|
-
const commandItems = useMemo2(() => {
|
|
562
|
-
const entries = [];
|
|
563
|
-
const seen = /* @__PURE__ */ new Set();
|
|
564
|
-
const pushItem = (item) => {
|
|
565
|
-
if (item === "-") {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
if (item.items && item.items.length > 0) {
|
|
569
|
-
for (const nested of item.items) {
|
|
570
|
-
pushItem(nested);
|
|
571
|
-
}
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
if (!seen.has(item.label)) {
|
|
575
|
-
seen.add(item.label);
|
|
576
|
-
entries.push(item);
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
if (onAddFile) {
|
|
580
|
-
pushItem({
|
|
581
|
-
label: labels.chatInputToolbarAddButtonLabel,
|
|
582
|
-
action: onAddFile
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
if (toolsMenu && toolsMenu.length > 0) {
|
|
586
|
-
for (const item of toolsMenu) {
|
|
587
|
-
pushItem(item);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return entries;
|
|
591
|
-
}, [labels.chatInputToolbarAddButtonLabel, onAddFile, toolsMenu]);
|
|
592
|
-
const filteredCommands = useMemo2(() => {
|
|
593
|
-
if (commandQuery === null) {
|
|
594
|
-
return [];
|
|
595
|
-
}
|
|
596
|
-
if (commandItems.length === 0) {
|
|
597
|
-
return [];
|
|
598
|
-
}
|
|
599
|
-
const query = commandQuery.trim().toLowerCase();
|
|
600
|
-
if (query.length === 0) {
|
|
601
|
-
return commandItems;
|
|
602
|
-
}
|
|
603
|
-
const startsWith = [];
|
|
604
|
-
const contains = [];
|
|
605
|
-
for (const item of commandItems) {
|
|
606
|
-
const label = item.label.toLowerCase();
|
|
607
|
-
if (label.startsWith(query)) {
|
|
608
|
-
startsWith.push(item);
|
|
609
|
-
} else if (label.includes(query)) {
|
|
610
|
-
contains.push(item);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
return [...startsWith, ...contains];
|
|
614
|
-
}, [commandItems, commandQuery]);
|
|
615
|
-
useEffect2(() => {
|
|
616
|
-
if (!autoFocus) {
|
|
617
|
-
previousModalStateRef.current = config?.isModalOpen;
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
if (config?.isModalOpen && !previousModalStateRef.current) {
|
|
621
|
-
inputRef.current?.focus();
|
|
622
|
-
}
|
|
623
|
-
previousModalStateRef.current = config?.isModalOpen;
|
|
624
|
-
}, [config?.isModalOpen, autoFocus]);
|
|
625
|
-
useEffect2(() => {
|
|
626
|
-
if (commandItems.length === 0 && commandQuery !== null) {
|
|
627
|
-
setCommandQuery(null);
|
|
628
|
-
}
|
|
629
|
-
}, [commandItems.length, commandQuery]);
|
|
630
|
-
const previousCommandQueryRef = useRef2(null);
|
|
631
|
-
useEffect2(() => {
|
|
632
|
-
if (commandQuery !== null && commandQuery !== previousCommandQueryRef.current && filteredCommands.length > 0) {
|
|
633
|
-
setSlashHighlightIndex(0);
|
|
634
|
-
}
|
|
635
|
-
previousCommandQueryRef.current = commandQuery;
|
|
636
|
-
}, [commandQuery, filteredCommands.length]);
|
|
637
|
-
useEffect2(() => {
|
|
638
|
-
if (commandQuery === null) {
|
|
639
|
-
setSlashHighlightIndex(0);
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
if (filteredCommands.length === 0) {
|
|
643
|
-
setSlashHighlightIndex(-1);
|
|
644
|
-
} else if (slashHighlightIndex < 0 || slashHighlightIndex >= filteredCommands.length) {
|
|
645
|
-
setSlashHighlightIndex(0);
|
|
646
|
-
}
|
|
647
|
-
}, [commandQuery, filteredCommands, slashHighlightIndex]);
|
|
648
|
-
useEffect2(() => {
|
|
649
|
-
const recorder = audioRecorderRef.current;
|
|
650
|
-
if (!recorder) {
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
if (mode === "transcribe") {
|
|
654
|
-
recorder.start().catch(console.error);
|
|
655
|
-
} else {
|
|
656
|
-
if (recorder.state === "recording") {
|
|
657
|
-
recorder.stop().catch(console.error);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}, [mode]);
|
|
661
|
-
useEffect2(() => {
|
|
662
|
-
if (mode !== "input") {
|
|
663
|
-
setLayout("compact");
|
|
664
|
-
setCommandQuery(null);
|
|
665
|
-
}
|
|
666
|
-
}, [mode]);
|
|
667
|
-
const updateSlashState = useCallback(
|
|
668
|
-
(value2) => {
|
|
669
|
-
if (commandItems.length === 0) {
|
|
670
|
-
setCommandQuery((prev) => prev === null ? prev : null);
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
if (value2.startsWith("/")) {
|
|
674
|
-
const firstLine = value2.split(/\r?\n/, 1)[0] ?? "";
|
|
675
|
-
const query = firstLine.slice(1);
|
|
676
|
-
setCommandQuery((prev) => prev === query ? prev : query);
|
|
677
|
-
} else {
|
|
678
|
-
setCommandQuery((prev) => prev === null ? prev : null);
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
[commandItems.length]
|
|
682
|
-
);
|
|
683
|
-
useEffect2(() => {
|
|
684
|
-
updateSlashState(resolvedValue);
|
|
685
|
-
}, [resolvedValue, updateSlashState]);
|
|
686
|
-
const handleChange = (e) => {
|
|
687
|
-
const nextValue = e.target.value;
|
|
688
|
-
if (!isControlled) {
|
|
689
|
-
setInternalValue(nextValue);
|
|
690
|
-
}
|
|
691
|
-
onChange?.(nextValue);
|
|
692
|
-
updateSlashState(nextValue);
|
|
693
|
-
};
|
|
694
|
-
const clearInputValue = useCallback(() => {
|
|
695
|
-
if (!isControlled) {
|
|
696
|
-
setInternalValue("");
|
|
697
|
-
}
|
|
698
|
-
if (onChange) {
|
|
699
|
-
onChange("");
|
|
700
|
-
}
|
|
701
|
-
}, [isControlled, onChange]);
|
|
702
|
-
const runCommand = useCallback(
|
|
703
|
-
(item) => {
|
|
704
|
-
clearInputValue();
|
|
705
|
-
item.action?.();
|
|
706
|
-
setCommandQuery(null);
|
|
707
|
-
setSlashHighlightIndex(0);
|
|
708
|
-
requestAnimationFrame(() => {
|
|
709
|
-
inputRef.current?.focus();
|
|
710
|
-
});
|
|
711
|
-
},
|
|
712
|
-
[clearInputValue]
|
|
713
|
-
);
|
|
714
|
-
const handleKeyDown = (e) => {
|
|
715
|
-
if (commandQuery !== null && mode === "input") {
|
|
716
|
-
if (e.key === "ArrowDown") {
|
|
717
|
-
if (filteredCommands.length > 0) {
|
|
718
|
-
e.preventDefault();
|
|
719
|
-
setSlashHighlightIndex((prev) => {
|
|
720
|
-
if (filteredCommands.length === 0) {
|
|
721
|
-
return prev;
|
|
722
|
-
}
|
|
723
|
-
const next = prev === -1 ? 0 : (prev + 1) % filteredCommands.length;
|
|
724
|
-
return next;
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
if (e.key === "ArrowUp") {
|
|
730
|
-
if (filteredCommands.length > 0) {
|
|
731
|
-
e.preventDefault();
|
|
732
|
-
setSlashHighlightIndex((prev) => {
|
|
733
|
-
if (filteredCommands.length === 0) {
|
|
734
|
-
return prev;
|
|
735
|
-
}
|
|
736
|
-
if (prev === -1) {
|
|
737
|
-
return filteredCommands.length - 1;
|
|
738
|
-
}
|
|
739
|
-
return prev <= 0 ? filteredCommands.length - 1 : prev - 1;
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
if (e.key === "Enter") {
|
|
745
|
-
const selected = slashHighlightIndex >= 0 ? filteredCommands[slashHighlightIndex] : void 0;
|
|
746
|
-
if (selected) {
|
|
747
|
-
e.preventDefault();
|
|
748
|
-
runCommand(selected);
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
if (e.key === "Escape") {
|
|
753
|
-
e.preventDefault();
|
|
754
|
-
setCommandQuery(null);
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
759
|
-
e.preventDefault();
|
|
760
|
-
if (isProcessing) {
|
|
761
|
-
onStop?.();
|
|
762
|
-
} else {
|
|
763
|
-
send();
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
const send = () => {
|
|
768
|
-
if (!onSubmitMessage) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
const trimmed = resolvedValue.trim();
|
|
772
|
-
if (!trimmed) {
|
|
773
|
-
return;
|
|
774
|
-
}
|
|
775
|
-
onSubmitMessage(trimmed);
|
|
776
|
-
if (!isControlled) {
|
|
777
|
-
setInternalValue("");
|
|
778
|
-
onChange?.("");
|
|
779
|
-
}
|
|
780
|
-
if (inputRef.current) {
|
|
781
|
-
inputRef.current.focus();
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
|
|
785
|
-
ref: inputRef,
|
|
786
|
-
value: resolvedValue,
|
|
787
|
-
onChange: handleChange,
|
|
788
|
-
onKeyDown: handleKeyDown,
|
|
789
|
-
autoFocus,
|
|
790
|
-
className: twMerge3(
|
|
791
|
-
"w-full py-3",
|
|
792
|
-
isExpanded ? "px-5" : "pr-5"
|
|
793
|
-
)
|
|
794
|
-
});
|
|
795
|
-
const isProcessing = mode !== "transcribe" && isRunning;
|
|
796
|
-
const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
|
|
797
|
-
const canStop = !!onStop;
|
|
798
|
-
const handleSendButtonClick = () => {
|
|
799
|
-
if (isProcessing) {
|
|
800
|
-
onStop?.();
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
send();
|
|
804
|
-
};
|
|
805
|
-
const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
|
|
806
|
-
ref: audioRecorderRef
|
|
807
|
-
});
|
|
808
|
-
const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
|
|
809
|
-
onClick: handleSendButtonClick,
|
|
810
|
-
disabled: isProcessing ? !canStop : !canSend,
|
|
811
|
-
children: isProcessing && canStop ? /* @__PURE__ */ jsx6(Square, { className: "size-[18px] fill-current" }) : void 0
|
|
812
|
-
});
|
|
813
|
-
const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
|
|
814
|
-
onClick: onStartTranscribe
|
|
815
|
-
});
|
|
816
|
-
const BoundCancelTranscribeButton = renderSlot(cancelTranscribeButton, CopilotChatInput.CancelTranscribeButton, {
|
|
817
|
-
onClick: onCancelTranscribe
|
|
818
|
-
});
|
|
819
|
-
const BoundFinishTranscribeButton = renderSlot(finishTranscribeButton, CopilotChatInput.FinishTranscribeButton, {
|
|
820
|
-
onClick: onFinishTranscribe
|
|
821
|
-
});
|
|
822
|
-
const BoundAddMenuButton = renderSlot(addMenuButton, CopilotChatInput.AddMenuButton, {
|
|
823
|
-
disabled: mode === "transcribe",
|
|
824
|
-
onAddFile,
|
|
825
|
-
toolsMenu
|
|
826
|
-
});
|
|
827
|
-
if (children) {
|
|
828
|
-
const childProps = {
|
|
829
|
-
textArea: BoundTextArea,
|
|
830
|
-
audioRecorder: BoundAudioRecorder,
|
|
831
|
-
sendButton: BoundSendButton,
|
|
832
|
-
startTranscribeButton: BoundStartTranscribeButton,
|
|
833
|
-
cancelTranscribeButton: BoundCancelTranscribeButton,
|
|
834
|
-
finishTranscribeButton: BoundFinishTranscribeButton,
|
|
835
|
-
addMenuButton: BoundAddMenuButton,
|
|
836
|
-
onSubmitMessage,
|
|
837
|
-
onStop,
|
|
838
|
-
isRunning,
|
|
839
|
-
onStartTranscribe,
|
|
840
|
-
onCancelTranscribe,
|
|
841
|
-
onFinishTranscribe,
|
|
842
|
-
onAddFile,
|
|
843
|
-
mode,
|
|
844
|
-
toolsMenu,
|
|
845
|
-
autoFocus
|
|
846
|
-
};
|
|
847
|
-
return /* @__PURE__ */ jsx6(Fragment, { children: children(childProps) });
|
|
848
|
-
}
|
|
849
|
-
const handleContainerClick = (e) => {
|
|
850
|
-
const target = e.target;
|
|
851
|
-
if (target.tagName !== "BUTTON" && !target.closest("button") && inputRef.current && mode === "input") {
|
|
852
|
-
inputRef.current.focus();
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
const ensureMeasurements = useCallback(() => {
|
|
856
|
-
const textarea = inputRef.current;
|
|
857
|
-
if (!textarea) {
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
const previousValue = textarea.value;
|
|
861
|
-
const previousHeight = textarea.style.height;
|
|
862
|
-
textarea.style.height = "auto";
|
|
863
|
-
const computedStyle = window.getComputedStyle(textarea);
|
|
864
|
-
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
|
865
|
-
const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
|
|
866
|
-
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
867
|
-
const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0;
|
|
868
|
-
textarea.value = "";
|
|
869
|
-
const singleLineHeight = textarea.scrollHeight;
|
|
870
|
-
textarea.value = previousValue;
|
|
871
|
-
const contentHeight = singleLineHeight - paddingTop - paddingBottom;
|
|
872
|
-
const maxHeight = contentHeight * 5 + paddingTop + paddingBottom;
|
|
873
|
-
measurementsRef.current = {
|
|
874
|
-
singleLineHeight,
|
|
875
|
-
maxHeight,
|
|
876
|
-
paddingLeft,
|
|
877
|
-
paddingRight
|
|
878
|
-
};
|
|
879
|
-
textarea.style.height = previousHeight;
|
|
880
|
-
textarea.style.maxHeight = `${maxHeight}px`;
|
|
881
|
-
}, []);
|
|
882
|
-
const adjustTextareaHeight = useCallback(() => {
|
|
883
|
-
const textarea = inputRef.current;
|
|
884
|
-
if (!textarea) {
|
|
885
|
-
return 0;
|
|
886
|
-
}
|
|
887
|
-
if (measurementsRef.current.singleLineHeight === 0) {
|
|
888
|
-
ensureMeasurements();
|
|
889
|
-
}
|
|
890
|
-
const { maxHeight } = measurementsRef.current;
|
|
891
|
-
if (maxHeight) {
|
|
892
|
-
textarea.style.maxHeight = `${maxHeight}px`;
|
|
893
|
-
}
|
|
894
|
-
textarea.style.height = "auto";
|
|
895
|
-
const scrollHeight = textarea.scrollHeight;
|
|
896
|
-
if (maxHeight) {
|
|
897
|
-
textarea.style.height = `${Math.min(scrollHeight, maxHeight)}px`;
|
|
898
|
-
} else {
|
|
899
|
-
textarea.style.height = `${scrollHeight}px`;
|
|
900
|
-
}
|
|
901
|
-
return scrollHeight;
|
|
902
|
-
}, [ensureMeasurements]);
|
|
903
|
-
const updateLayout = useCallback((nextLayout) => {
|
|
904
|
-
setLayout((prev) => {
|
|
905
|
-
if (prev === nextLayout) {
|
|
906
|
-
return prev;
|
|
907
|
-
}
|
|
908
|
-
ignoreResizeRef.current = true;
|
|
909
|
-
return nextLayout;
|
|
910
|
-
});
|
|
911
|
-
}, []);
|
|
912
|
-
const evaluateLayout = useCallback(() => {
|
|
913
|
-
if (mode !== "input") {
|
|
914
|
-
updateLayout("compact");
|
|
915
|
-
return;
|
|
916
|
-
}
|
|
917
|
-
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
918
|
-
const isMobileViewport = window.matchMedia("(max-width: 767px)").matches;
|
|
919
|
-
if (isMobileViewport) {
|
|
920
|
-
ensureMeasurements();
|
|
921
|
-
adjustTextareaHeight();
|
|
922
|
-
updateLayout("expanded");
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
const textarea = inputRef.current;
|
|
927
|
-
const grid = gridRef.current;
|
|
928
|
-
const addContainer = addButtonContainerRef.current;
|
|
929
|
-
const actionsContainer = actionsContainerRef.current;
|
|
930
|
-
if (!textarea || !grid || !addContainer || !actionsContainer) {
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
if (measurementsRef.current.singleLineHeight === 0) {
|
|
934
|
-
ensureMeasurements();
|
|
935
|
-
}
|
|
936
|
-
const scrollHeight = adjustTextareaHeight();
|
|
937
|
-
const baseline = measurementsRef.current.singleLineHeight;
|
|
938
|
-
const hasExplicitBreak = resolvedValue.includes("\n");
|
|
939
|
-
const renderedMultiline = baseline > 0 ? scrollHeight > baseline + 1 : false;
|
|
940
|
-
let shouldExpand = hasExplicitBreak || renderedMultiline;
|
|
941
|
-
if (!shouldExpand) {
|
|
942
|
-
const gridStyles = window.getComputedStyle(grid);
|
|
943
|
-
const paddingLeft = parseFloat(gridStyles.paddingLeft) || 0;
|
|
944
|
-
const paddingRight = parseFloat(gridStyles.paddingRight) || 0;
|
|
945
|
-
const columnGap = parseFloat(gridStyles.columnGap) || 0;
|
|
946
|
-
const gridAvailableWidth = grid.clientWidth - paddingLeft - paddingRight;
|
|
947
|
-
if (gridAvailableWidth > 0) {
|
|
948
|
-
const addWidth = addContainer.getBoundingClientRect().width;
|
|
949
|
-
const actionsWidth = actionsContainer.getBoundingClientRect().width;
|
|
950
|
-
const compactWidth = Math.max(gridAvailableWidth - addWidth - actionsWidth - columnGap * 2, 0);
|
|
951
|
-
const canvas = measurementCanvasRef.current ?? document.createElement("canvas");
|
|
952
|
-
if (!measurementCanvasRef.current) {
|
|
953
|
-
measurementCanvasRef.current = canvas;
|
|
954
|
-
}
|
|
955
|
-
const context = canvas.getContext("2d");
|
|
956
|
-
if (context) {
|
|
957
|
-
const textareaStyles = window.getComputedStyle(textarea);
|
|
958
|
-
const font = textareaStyles.font || `${textareaStyles.fontStyle} ${textareaStyles.fontVariant} ${textareaStyles.fontWeight} ${textareaStyles.fontSize}/${textareaStyles.lineHeight} ${textareaStyles.fontFamily}`;
|
|
959
|
-
context.font = font;
|
|
960
|
-
const compactInnerWidth = Math.max(
|
|
961
|
-
compactWidth - (measurementsRef.current.paddingLeft || 0) - (measurementsRef.current.paddingRight || 0),
|
|
962
|
-
0
|
|
963
|
-
);
|
|
964
|
-
if (compactInnerWidth > 0) {
|
|
965
|
-
const lines = resolvedValue.length > 0 ? resolvedValue.split("\n") : [""];
|
|
966
|
-
let longestWidth = 0;
|
|
967
|
-
for (const line of lines) {
|
|
968
|
-
const metrics = context.measureText(line || " ");
|
|
969
|
-
if (metrics.width > longestWidth) {
|
|
970
|
-
longestWidth = metrics.width;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
if (longestWidth > compactInnerWidth) {
|
|
974
|
-
shouldExpand = true;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
const nextLayout = shouldExpand ? "expanded" : "compact";
|
|
981
|
-
updateLayout(nextLayout);
|
|
982
|
-
}, [adjustTextareaHeight, ensureMeasurements, mode, resolvedValue, updateLayout]);
|
|
983
|
-
useLayoutEffect(() => {
|
|
984
|
-
evaluateLayout();
|
|
985
|
-
}, [evaluateLayout]);
|
|
986
|
-
useEffect2(() => {
|
|
987
|
-
if (typeof ResizeObserver === "undefined") {
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
const textarea = inputRef.current;
|
|
991
|
-
const grid = gridRef.current;
|
|
992
|
-
const addContainer = addButtonContainerRef.current;
|
|
993
|
-
const actionsContainer = actionsContainerRef.current;
|
|
994
|
-
if (!textarea || !grid || !addContainer || !actionsContainer) {
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
const scheduleEvaluation = () => {
|
|
998
|
-
if (ignoreResizeRef.current) {
|
|
999
|
-
ignoreResizeRef.current = false;
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
if (typeof window === "undefined") {
|
|
1003
|
-
evaluateLayout();
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
if (resizeEvaluationRafRef.current !== null) {
|
|
1007
|
-
cancelAnimationFrame(resizeEvaluationRafRef.current);
|
|
1008
|
-
}
|
|
1009
|
-
resizeEvaluationRafRef.current = window.requestAnimationFrame(() => {
|
|
1010
|
-
resizeEvaluationRafRef.current = null;
|
|
1011
|
-
evaluateLayout();
|
|
1012
|
-
});
|
|
1013
|
-
};
|
|
1014
|
-
const observer = new ResizeObserver(() => {
|
|
1015
|
-
scheduleEvaluation();
|
|
1016
|
-
});
|
|
1017
|
-
observer.observe(grid);
|
|
1018
|
-
observer.observe(addContainer);
|
|
1019
|
-
observer.observe(actionsContainer);
|
|
1020
|
-
observer.observe(textarea);
|
|
1021
|
-
return () => {
|
|
1022
|
-
observer.disconnect();
|
|
1023
|
-
if (typeof window !== "undefined" && resizeEvaluationRafRef.current !== null) {
|
|
1024
|
-
cancelAnimationFrame(resizeEvaluationRafRef.current);
|
|
1025
|
-
resizeEvaluationRafRef.current = null;
|
|
1026
|
-
}
|
|
1027
|
-
};
|
|
1028
|
-
}, [evaluateLayout]);
|
|
1029
|
-
const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
|
|
1030
|
-
useEffect2(() => {
|
|
1031
|
-
if (!slashMenuVisible || slashHighlightIndex < 0) {
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
const active = slashMenuRef.current?.querySelector(
|
|
1035
|
-
`[data-slash-index="${slashHighlightIndex}"]`
|
|
1036
|
-
);
|
|
1037
|
-
active?.scrollIntoView({ block: "nearest" });
|
|
1038
|
-
}, [slashMenuVisible, slashHighlightIndex]);
|
|
1039
|
-
const slashMenu = slashMenuVisible ? /* @__PURE__ */ jsx6(
|
|
1040
|
-
"div",
|
|
1041
|
-
{
|
|
1042
|
-
"data-testid": "copilot-slash-menu",
|
|
1043
|
-
role: "listbox",
|
|
1044
|
-
"aria-label": "Slash commands",
|
|
1045
|
-
ref: slashMenuRef,
|
|
1046
|
-
className: "absolute bottom-full left-0 right-0 z-30 mb-2 max-h-64 overflow-y-auto rounded-lg border border-border bg-white shadow-lg dark:border-[#3a3a3a] dark:bg-[#1f1f1f]",
|
|
1047
|
-
style: { maxHeight: `${SLASH_MENU_MAX_VISIBLE_ITEMS * SLASH_MENU_ITEM_HEIGHT_PX}px` },
|
|
1048
|
-
children: filteredCommands.length === 0 ? /* @__PURE__ */ jsx6("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No commands found" }) : filteredCommands.map((item, index) => {
|
|
1049
|
-
const isActive = index === slashHighlightIndex;
|
|
1050
|
-
return /* @__PURE__ */ jsx6(
|
|
1051
|
-
"button",
|
|
1052
|
-
{
|
|
1053
|
-
type: "button",
|
|
1054
|
-
role: "option",
|
|
1055
|
-
"aria-selected": isActive,
|
|
1056
|
-
"data-active": isActive ? "true" : void 0,
|
|
1057
|
-
"data-slash-index": index,
|
|
1058
|
-
className: twMerge3(
|
|
1059
|
-
"w-full px-3 py-2 text-left text-sm transition-colors",
|
|
1060
|
-
"hover:bg-muted dark:hover:bg-[#2f2f2f]",
|
|
1061
|
-
isActive ? "bg-muted dark:bg-[#2f2f2f]" : "bg-transparent"
|
|
1062
|
-
),
|
|
1063
|
-
onMouseEnter: () => setSlashHighlightIndex(index),
|
|
1064
|
-
onMouseDown: (event) => {
|
|
1065
|
-
event.preventDefault();
|
|
1066
|
-
runCommand(item);
|
|
1067
|
-
},
|
|
1068
|
-
children: item.label
|
|
1069
|
-
},
|
|
1070
|
-
`${item.label}-${index}`
|
|
1071
|
-
);
|
|
1072
|
-
})
|
|
1073
|
-
}
|
|
1074
|
-
) : null;
|
|
1075
|
-
return /* @__PURE__ */ jsx6(
|
|
1076
|
-
"div",
|
|
1077
|
-
{
|
|
1078
|
-
className: twMerge3(
|
|
1079
|
-
// Layout
|
|
1080
|
-
"flex w-full flex-col items-center justify-center",
|
|
1081
|
-
// Interaction
|
|
1082
|
-
"cursor-text",
|
|
1083
|
-
// Overflow and clipping
|
|
1084
|
-
"overflow-visible bg-clip-padding contain-inline-size",
|
|
1085
|
-
// Background
|
|
1086
|
-
"bg-white dark:bg-[#303030]",
|
|
1087
|
-
// Visual effects
|
|
1088
|
-
"shadow-[0_4px_4px_0_#0000000a,0_0_1px_0_#0000009e] rounded-[28px]",
|
|
1089
|
-
className
|
|
1090
|
-
),
|
|
1091
|
-
onClick: handleContainerClick,
|
|
1092
|
-
...props,
|
|
1093
|
-
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1094
|
-
children: /* @__PURE__ */ jsxs3(
|
|
1095
|
-
"div",
|
|
1096
|
-
{
|
|
1097
|
-
ref: gridRef,
|
|
1098
|
-
className: twMerge3(
|
|
1099
|
-
"grid w-full gap-x-3 gap-y-3 px-3 py-2",
|
|
1100
|
-
isExpanded ? "grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_auto]" : "grid-cols-[auto_minmax(0,1fr)_auto] items-center"
|
|
1101
|
-
),
|
|
1102
|
-
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1103
|
-
children: [
|
|
1104
|
-
/* @__PURE__ */ jsx6(
|
|
1105
|
-
"div",
|
|
1106
|
-
{
|
|
1107
|
-
ref: addButtonContainerRef,
|
|
1108
|
-
className: twMerge3(
|
|
1109
|
-
"flex items-center",
|
|
1110
|
-
isExpanded ? "row-start-2" : "row-start-1",
|
|
1111
|
-
"col-start-1"
|
|
1112
|
-
),
|
|
1113
|
-
children: BoundAddMenuButton
|
|
1114
|
-
}
|
|
1115
|
-
),
|
|
1116
|
-
/* @__PURE__ */ jsx6(
|
|
1117
|
-
"div",
|
|
1118
|
-
{
|
|
1119
|
-
className: twMerge3(
|
|
1120
|
-
"relative flex min-w-0 flex-col",
|
|
1121
|
-
isExpanded ? "col-span-3 row-start-1" : "col-start-2 row-start-1"
|
|
1122
|
-
),
|
|
1123
|
-
children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1124
|
-
BoundTextArea,
|
|
1125
|
-
slashMenu
|
|
1126
|
-
] })
|
|
1127
|
-
}
|
|
1128
|
-
),
|
|
1129
|
-
/* @__PURE__ */ jsx6(
|
|
1130
|
-
"div",
|
|
1131
|
-
{
|
|
1132
|
-
ref: actionsContainerRef,
|
|
1133
|
-
className: twMerge3(
|
|
1134
|
-
"flex items-center justify-end gap-2",
|
|
1135
|
-
isExpanded ? "col-start-3 row-start-2" : "col-start-3 row-start-1"
|
|
1136
|
-
),
|
|
1137
|
-
children: mode === "transcribe" ? /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1138
|
-
onCancelTranscribe && BoundCancelTranscribeButton,
|
|
1139
|
-
onFinishTranscribe && BoundFinishTranscribeButton
|
|
1140
|
-
] }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1141
|
-
onStartTranscribe && BoundStartTranscribeButton,
|
|
1142
|
-
BoundSendButton
|
|
1143
|
-
] })
|
|
1144
|
-
}
|
|
1145
|
-
)
|
|
1146
|
-
]
|
|
1147
|
-
}
|
|
1148
|
-
)
|
|
1149
|
-
}
|
|
1150
|
-
);
|
|
1151
|
-
}
|
|
1152
|
-
((CopilotChatInput2) => {
|
|
1153
|
-
CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ jsx6("div", { className: "mr-[10px]", children: /* @__PURE__ */ jsx6(
|
|
1154
|
-
Button,
|
|
1155
|
-
{
|
|
1156
|
-
type: "button",
|
|
1157
|
-
variant: "chatInputToolbarPrimary",
|
|
1158
|
-
size: "chatInputToolbarIcon",
|
|
1159
|
-
className,
|
|
1160
|
-
...props,
|
|
1161
|
-
children: children ?? /* @__PURE__ */ jsx6(ArrowUp, { className: "size-[18px]" })
|
|
1162
|
-
}
|
|
1163
|
-
) });
|
|
1164
|
-
CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
1165
|
-
const config = useCopilotChatConfiguration();
|
|
1166
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1167
|
-
return /* @__PURE__ */ jsxs3(Tooltip, { children: [
|
|
1168
|
-
/* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
|
|
1169
|
-
Button,
|
|
1170
|
-
{
|
|
1171
|
-
type: "button",
|
|
1172
|
-
variant: "chatInputToolbarSecondary",
|
|
1173
|
-
size: "chatInputToolbarIcon",
|
|
1174
|
-
className: twMerge3(defaultClassName, className),
|
|
1175
|
-
...props,
|
|
1176
|
-
children: icon
|
|
1177
|
-
}
|
|
1178
|
-
) }),
|
|
1179
|
-
/* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx6("p", { children: labels[labelKey] }) })
|
|
1180
|
-
] });
|
|
1181
|
-
};
|
|
1182
|
-
CopilotChatInput2.StartTranscribeButton = (props) => /* @__PURE__ */ jsx6(
|
|
1183
|
-
CopilotChatInput2.ToolbarButton,
|
|
1184
|
-
{
|
|
1185
|
-
icon: /* @__PURE__ */ jsx6(Mic, { className: "size-[18px]" }),
|
|
1186
|
-
labelKey: "chatInputToolbarStartTranscribeButtonLabel",
|
|
1187
|
-
defaultClassName: "mr-2",
|
|
1188
|
-
...props
|
|
1189
|
-
}
|
|
1190
|
-
);
|
|
1191
|
-
CopilotChatInput2.CancelTranscribeButton = (props) => /* @__PURE__ */ jsx6(
|
|
1192
|
-
CopilotChatInput2.ToolbarButton,
|
|
1193
|
-
{
|
|
1194
|
-
icon: /* @__PURE__ */ jsx6(X, { className: "size-[18px]" }),
|
|
1195
|
-
labelKey: "chatInputToolbarCancelTranscribeButtonLabel",
|
|
1196
|
-
defaultClassName: "mr-2",
|
|
1197
|
-
...props
|
|
1198
|
-
}
|
|
1199
|
-
);
|
|
1200
|
-
CopilotChatInput2.FinishTranscribeButton = (props) => /* @__PURE__ */ jsx6(
|
|
1201
|
-
CopilotChatInput2.ToolbarButton,
|
|
1202
|
-
{
|
|
1203
|
-
icon: /* @__PURE__ */ jsx6(Check, { className: "size-[18px]" }),
|
|
1204
|
-
labelKey: "chatInputToolbarFinishTranscribeButtonLabel",
|
|
1205
|
-
defaultClassName: "mr-[10px]",
|
|
1206
|
-
...props
|
|
1207
|
-
}
|
|
1208
|
-
);
|
|
1209
|
-
CopilotChatInput2.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
|
|
1210
|
-
const config = useCopilotChatConfiguration();
|
|
1211
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1212
|
-
const menuItems = useMemo2(() => {
|
|
1213
|
-
const items = [];
|
|
1214
|
-
if (onAddFile) {
|
|
1215
|
-
items.push({
|
|
1216
|
-
label: labels.chatInputToolbarAddButtonLabel,
|
|
1217
|
-
action: onAddFile
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
if (toolsMenu && toolsMenu.length > 0) {
|
|
1221
|
-
if (items.length > 0) {
|
|
1222
|
-
items.push("-");
|
|
1223
|
-
}
|
|
1224
|
-
for (const item of toolsMenu) {
|
|
1225
|
-
if (item === "-") {
|
|
1226
|
-
if (items.length === 0 || items[items.length - 1] === "-") {
|
|
1227
|
-
continue;
|
|
1228
|
-
}
|
|
1229
|
-
items.push(item);
|
|
1230
|
-
} else {
|
|
1231
|
-
items.push(item);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
while (items.length > 0 && items[items.length - 1] === "-") {
|
|
1235
|
-
items.pop();
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
return items;
|
|
1239
|
-
}, [onAddFile, toolsMenu, labels.chatInputToolbarAddButtonLabel]);
|
|
1240
|
-
const renderMenuItems = useCallback(
|
|
1241
|
-
(items) => items.map((item, index) => {
|
|
1242
|
-
if (item === "-") {
|
|
1243
|
-
return /* @__PURE__ */ jsx6(DropdownMenuSeparator, {}, `separator-${index}`);
|
|
1244
|
-
}
|
|
1245
|
-
if (item.items && item.items.length > 0) {
|
|
1246
|
-
return /* @__PURE__ */ jsxs3(DropdownMenuSub, { children: [
|
|
1247
|
-
/* @__PURE__ */ jsx6(DropdownMenuSubTrigger, { children: item.label }),
|
|
1248
|
-
/* @__PURE__ */ jsx6(DropdownMenuSubContent, { children: renderMenuItems(item.items) })
|
|
1249
|
-
] }, `group-${index}`);
|
|
1250
|
-
}
|
|
1251
|
-
return /* @__PURE__ */ jsx6(DropdownMenuItem, { onClick: item.action, children: item.label }, `item-${index}`);
|
|
1252
|
-
}),
|
|
1253
|
-
[]
|
|
1254
|
-
);
|
|
1255
|
-
const hasMenuItems = menuItems.length > 0;
|
|
1256
|
-
const isDisabled = disabled || !hasMenuItems;
|
|
1257
|
-
return /* @__PURE__ */ jsxs3(DropdownMenu, { children: [
|
|
1258
|
-
/* @__PURE__ */ jsxs3(Tooltip, { children: [
|
|
1259
|
-
/* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
|
|
1260
|
-
Button,
|
|
1261
|
-
{
|
|
1262
|
-
type: "button",
|
|
1263
|
-
variant: "chatInputToolbarSecondary",
|
|
1264
|
-
size: "chatInputToolbarIcon",
|
|
1265
|
-
className: twMerge3("ml-1", className),
|
|
1266
|
-
disabled: isDisabled,
|
|
1267
|
-
...props,
|
|
1268
|
-
children: /* @__PURE__ */ jsx6(Plus, { className: "size-[20px]" })
|
|
1269
|
-
}
|
|
1270
|
-
) }) }),
|
|
1271
|
-
/* @__PURE__ */ jsx6(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsxs3("p", { className: "flex items-center gap-1 text-xs font-medium", children: [
|
|
1272
|
-
/* @__PURE__ */ jsx6("span", { children: "Add files and more" }),
|
|
1273
|
-
/* @__PURE__ */ jsx6("code", { className: "rounded bg-[#4a4a4a] px-1 py-[1px] font-mono text-[11px] text-white dark:bg-[#e0e0e0] dark:text-black", children: "/" })
|
|
1274
|
-
] }) })
|
|
1275
|
-
] }),
|
|
1276
|
-
hasMenuItems && /* @__PURE__ */ jsx6(DropdownMenuContent, { side: "top", align: "start", children: renderMenuItems(menuItems) })
|
|
1277
|
-
] });
|
|
1278
|
-
};
|
|
1279
|
-
CopilotChatInput2.TextArea = forwardRef2(function TextArea2({ style, className, autoFocus, ...props }, ref) {
|
|
1280
|
-
const internalTextareaRef = useRef2(null);
|
|
1281
|
-
const config = useCopilotChatConfiguration();
|
|
1282
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1283
|
-
useImperativeHandle2(ref, () => internalTextareaRef.current);
|
|
1284
|
-
useEffect2(() => {
|
|
1285
|
-
const textarea = internalTextareaRef.current;
|
|
1286
|
-
if (!textarea) return;
|
|
1287
|
-
const handleFocus = () => {
|
|
1288
|
-
setTimeout(() => {
|
|
1289
|
-
textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1290
|
-
}, 300);
|
|
1291
|
-
};
|
|
1292
|
-
textarea.addEventListener("focus", handleFocus);
|
|
1293
|
-
return () => textarea.removeEventListener("focus", handleFocus);
|
|
1294
|
-
}, []);
|
|
1295
|
-
useEffect2(() => {
|
|
1296
|
-
if (autoFocus) {
|
|
1297
|
-
internalTextareaRef.current?.focus();
|
|
1298
|
-
}
|
|
1299
|
-
}, [autoFocus]);
|
|
1300
|
-
return /* @__PURE__ */ jsx6(
|
|
1301
|
-
"textarea",
|
|
1302
|
-
{
|
|
1303
|
-
ref: internalTextareaRef,
|
|
1304
|
-
...props,
|
|
1305
|
-
style: {
|
|
1306
|
-
overflow: "auto",
|
|
1307
|
-
resize: "none",
|
|
1308
|
-
...style
|
|
1309
|
-
},
|
|
1310
|
-
placeholder: labels.chatInputPlaceholder,
|
|
1311
|
-
className: twMerge3(
|
|
1312
|
-
"bg-transparent outline-none antialiased font-regular leading-relaxed text-[16px] placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
|
|
1313
|
-
className
|
|
1314
|
-
),
|
|
1315
|
-
rows: 1
|
|
1316
|
-
}
|
|
1317
|
-
);
|
|
1318
|
-
});
|
|
1319
|
-
CopilotChatInput2.AudioRecorder = CopilotChatAudioRecorder;
|
|
1320
|
-
})(CopilotChatInput || (CopilotChatInput = {}));
|
|
1321
|
-
CopilotChatInput.TextArea.displayName = "CopilotChatInput.TextArea";
|
|
1322
|
-
CopilotChatInput.SendButton.displayName = "CopilotChatInput.SendButton";
|
|
1323
|
-
CopilotChatInput.ToolbarButton.displayName = "CopilotChatInput.ToolbarButton";
|
|
1324
|
-
CopilotChatInput.StartTranscribeButton.displayName = "CopilotChatInput.StartTranscribeButton";
|
|
1325
|
-
CopilotChatInput.CancelTranscribeButton.displayName = "CopilotChatInput.CancelTranscribeButton";
|
|
1326
|
-
CopilotChatInput.FinishTranscribeButton.displayName = "CopilotChatInput.FinishTranscribeButton";
|
|
1327
|
-
CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
|
|
1328
|
-
var CopilotChatInput_default = CopilotChatInput;
|
|
1329
|
-
|
|
1330
|
-
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
1331
|
-
import { useState as useState6 } from "react";
|
|
11
|
+
CopilotPopup
|
|
12
|
+
} from "./chunk-IH5VFJ4L.mjs";
|
|
1332
13
|
import {
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
ThumbsUp,
|
|
1336
|
-
ThumbsDown,
|
|
1337
|
-
Volume2,
|
|
1338
|
-
RefreshCw
|
|
1339
|
-
} from "lucide-react";
|
|
1340
|
-
import { twMerge as twMerge4 } from "tailwind-merge";
|
|
1341
|
-
import "katex/dist/katex.min.css";
|
|
1342
|
-
import { Streamdown } from "streamdown";
|
|
1343
|
-
|
|
1344
|
-
// src/hooks/use-render-tool-call.tsx
|
|
1345
|
-
import { useCallback as useCallback2, useEffect as useEffect5, useState as useState4, useSyncExternalStore } from "react";
|
|
1346
|
-
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
1347
|
-
|
|
1348
|
-
// src/providers/CopilotKitProvider.tsx
|
|
14
|
+
CopilotPopupView
|
|
15
|
+
} from "./chunk-VUHFLJWI.mjs";
|
|
1349
16
|
import {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
useMemo as useMemo3,
|
|
1353
|
-
useEffect as useEffect4,
|
|
1354
|
-
useReducer,
|
|
1355
|
-
useRef as useRef4,
|
|
1356
|
-
useState as useState3
|
|
1357
|
-
} from "react";
|
|
1358
|
-
import { z } from "zod";
|
|
1359
|
-
|
|
1360
|
-
// src/lib/react-core.ts
|
|
1361
|
-
import { CopilotKitCore } from "@copilotkitnext/core";
|
|
1362
|
-
var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
1363
|
-
_renderToolCalls = [];
|
|
1364
|
-
_renderCustomMessages = [];
|
|
1365
|
-
_renderActivityMessages = [];
|
|
1366
|
-
constructor(config) {
|
|
1367
|
-
super(config);
|
|
1368
|
-
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
1369
|
-
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
1370
|
-
this._renderActivityMessages = config.renderActivityMessages ?? [];
|
|
1371
|
-
}
|
|
1372
|
-
get renderCustomMessages() {
|
|
1373
|
-
return this._renderCustomMessages;
|
|
1374
|
-
}
|
|
1375
|
-
get renderActivityMessages() {
|
|
1376
|
-
return this._renderActivityMessages;
|
|
1377
|
-
}
|
|
1378
|
-
get renderToolCalls() {
|
|
1379
|
-
return this._renderToolCalls;
|
|
1380
|
-
}
|
|
1381
|
-
setRenderToolCalls(renderToolCalls) {
|
|
1382
|
-
this._renderToolCalls = renderToolCalls;
|
|
1383
|
-
void this.notifySubscribers(
|
|
1384
|
-
(subscriber) => {
|
|
1385
|
-
const reactSubscriber = subscriber;
|
|
1386
|
-
if (reactSubscriber.onRenderToolCallsChanged) {
|
|
1387
|
-
reactSubscriber.onRenderToolCallsChanged({
|
|
1388
|
-
copilotkit: this,
|
|
1389
|
-
renderToolCalls: this.renderToolCalls
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
},
|
|
1393
|
-
"Subscriber onRenderToolCallsChanged error:"
|
|
1394
|
-
);
|
|
1395
|
-
}
|
|
1396
|
-
// Override to accept React-specific subscriber type
|
|
1397
|
-
subscribe(subscriber) {
|
|
1398
|
-
return super.subscribe(subscriber);
|
|
1399
|
-
}
|
|
1400
|
-
unsubscribe(subscriber) {
|
|
1401
|
-
super.unsubscribe(subscriber);
|
|
1402
|
-
}
|
|
1403
|
-
};
|
|
1404
|
-
|
|
1405
|
-
// src/components/CopilotKitInspector.tsx
|
|
1406
|
-
import * as React4 from "react";
|
|
1407
|
-
import { createComponent } from "@lit-labs/react";
|
|
17
|
+
CopilotSidebar
|
|
18
|
+
} from "./chunk-QFBM3ZT2.mjs";
|
|
1408
19
|
import {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
import {
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
const renderActivityMessagesList = useStableArrayProp(
|
|
1506
|
-
renderActivityMessages,
|
|
1507
|
-
"renderActivityMessages must be a stable array."
|
|
1508
|
-
);
|
|
1509
|
-
const frontendToolsList = useStableArrayProp(
|
|
1510
|
-
frontendTools,
|
|
1511
|
-
"frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
|
|
1512
|
-
);
|
|
1513
|
-
const humanInTheLoopList = useStableArrayProp(
|
|
1514
|
-
humanInTheLoop,
|
|
1515
|
-
"humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead."
|
|
1516
|
-
);
|
|
1517
|
-
const processedHumanInTheLoopTools = useMemo3(() => {
|
|
1518
|
-
const processedTools = [];
|
|
1519
|
-
const processedRenderToolCalls = [];
|
|
1520
|
-
humanInTheLoopList.forEach((tool) => {
|
|
1521
|
-
const frontendTool = {
|
|
1522
|
-
name: tool.name,
|
|
1523
|
-
description: tool.description,
|
|
1524
|
-
parameters: tool.parameters,
|
|
1525
|
-
followUp: tool.followUp,
|
|
1526
|
-
...tool.agentId && { agentId: tool.agentId },
|
|
1527
|
-
handler: async () => {
|
|
1528
|
-
return new Promise((resolve) => {
|
|
1529
|
-
console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
|
|
1530
|
-
resolve(void 0);
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
};
|
|
1534
|
-
processedTools.push(frontendTool);
|
|
1535
|
-
if (tool.render) {
|
|
1536
|
-
processedRenderToolCalls.push({
|
|
1537
|
-
name: tool.name,
|
|
1538
|
-
args: tool.parameters,
|
|
1539
|
-
render: tool.render,
|
|
1540
|
-
...tool.agentId && { agentId: tool.agentId }
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
});
|
|
1544
|
-
return { tools: processedTools, renderToolCalls: processedRenderToolCalls };
|
|
1545
|
-
}, [humanInTheLoopList]);
|
|
1546
|
-
const allTools = useMemo3(() => {
|
|
1547
|
-
const tools = [];
|
|
1548
|
-
tools.push(...frontendToolsList);
|
|
1549
|
-
tools.push(...processedHumanInTheLoopTools.tools);
|
|
1550
|
-
return tools;
|
|
1551
|
-
}, [frontendToolsList, processedHumanInTheLoopTools]);
|
|
1552
|
-
const allRenderToolCalls = useMemo3(() => {
|
|
1553
|
-
const combined = [...renderToolCallsList];
|
|
1554
|
-
frontendToolsList.forEach((tool) => {
|
|
1555
|
-
if (tool.render) {
|
|
1556
|
-
const args = tool.parameters || (tool.name === "*" ? z.any() : void 0);
|
|
1557
|
-
if (args) {
|
|
1558
|
-
combined.push({
|
|
1559
|
-
name: tool.name,
|
|
1560
|
-
args,
|
|
1561
|
-
render: tool.render
|
|
1562
|
-
});
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
});
|
|
1566
|
-
combined.push(...processedHumanInTheLoopTools.renderToolCalls);
|
|
1567
|
-
return combined;
|
|
1568
|
-
}, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
|
|
1569
|
-
const copilotkit = useMemo3(() => {
|
|
1570
|
-
const copilotkit2 = new CopilotKitCoreReact({
|
|
1571
|
-
runtimeUrl,
|
|
1572
|
-
runtimeTransport: useSingleEndpoint ? "single" : "rest",
|
|
1573
|
-
headers,
|
|
1574
|
-
properties,
|
|
1575
|
-
agents__unsafe_dev_only: agents,
|
|
1576
|
-
tools: allTools,
|
|
1577
|
-
renderToolCalls: allRenderToolCalls,
|
|
1578
|
-
renderActivityMessages: renderActivityMessagesList,
|
|
1579
|
-
renderCustomMessages: renderCustomMessagesList
|
|
1580
|
-
});
|
|
1581
|
-
return copilotkit2;
|
|
1582
|
-
}, [allTools, allRenderToolCalls, renderActivityMessagesList, renderCustomMessagesList, useSingleEndpoint]);
|
|
1583
|
-
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1584
|
-
useEffect4(() => {
|
|
1585
|
-
const unsubscribe = copilotkit.subscribe({
|
|
1586
|
-
onRenderToolCallsChanged: () => {
|
|
1587
|
-
forceUpdate();
|
|
1588
|
-
}
|
|
1589
|
-
});
|
|
1590
|
-
return () => {
|
|
1591
|
-
unsubscribe();
|
|
1592
|
-
};
|
|
1593
|
-
}, [copilotkit]);
|
|
1594
|
-
useEffect4(() => {
|
|
1595
|
-
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1596
|
-
copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
|
|
1597
|
-
copilotkit.setHeaders(headers);
|
|
1598
|
-
copilotkit.setProperties(properties);
|
|
1599
|
-
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1600
|
-
}, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
|
|
1601
|
-
return /* @__PURE__ */ jsxs4(
|
|
1602
|
-
CopilotKitContext.Provider,
|
|
1603
|
-
{
|
|
1604
|
-
value: {
|
|
1605
|
-
copilotkit
|
|
1606
|
-
},
|
|
1607
|
-
children: [
|
|
1608
|
-
children,
|
|
1609
|
-
shouldRenderInspector ? /* @__PURE__ */ jsx8(CopilotKitInspector, { core: copilotkit }) : null
|
|
1610
|
-
]
|
|
1611
|
-
}
|
|
1612
|
-
);
|
|
1613
|
-
};
|
|
1614
|
-
var useCopilotKit = () => {
|
|
1615
|
-
const context = useContext2(CopilotKitContext);
|
|
1616
|
-
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1617
|
-
if (!context) {
|
|
1618
|
-
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1619
|
-
}
|
|
1620
|
-
useEffect4(() => {
|
|
1621
|
-
const unsubscribe = context.copilotkit.subscribe({
|
|
1622
|
-
onRuntimeConnectionStatusChanged: () => {
|
|
1623
|
-
forceUpdate();
|
|
1624
|
-
}
|
|
1625
|
-
});
|
|
1626
|
-
return () => {
|
|
1627
|
-
unsubscribe();
|
|
1628
|
-
};
|
|
1629
|
-
}, []);
|
|
1630
|
-
return context;
|
|
1631
|
-
};
|
|
1632
|
-
|
|
1633
|
-
// src/hooks/use-render-tool-call.tsx
|
|
1634
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID2 } from "@copilotkitnext/shared";
|
|
1635
|
-
import { partialJSONParse } from "@copilotkitnext/shared";
|
|
1636
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1637
|
-
function useRenderToolCall() {
|
|
1638
|
-
const { copilotkit } = useCopilotKit();
|
|
1639
|
-
const config = useCopilotChatConfiguration();
|
|
1640
|
-
const agentId = config?.agentId ?? DEFAULT_AGENT_ID2;
|
|
1641
|
-
const [executingToolCallIds, setExecutingToolCallIds] = useState4(() => /* @__PURE__ */ new Set());
|
|
1642
|
-
const renderToolCalls = useSyncExternalStore(
|
|
1643
|
-
(callback) => {
|
|
1644
|
-
return copilotkit.subscribe({
|
|
1645
|
-
onRenderToolCallsChanged: callback
|
|
1646
|
-
});
|
|
1647
|
-
},
|
|
1648
|
-
() => copilotkit.renderToolCalls,
|
|
1649
|
-
() => copilotkit.renderToolCalls
|
|
1650
|
-
);
|
|
1651
|
-
useEffect5(() => {
|
|
1652
|
-
const unsubscribe = copilotkit.subscribe({
|
|
1653
|
-
onToolExecutionStart: ({ toolCallId }) => {
|
|
1654
|
-
setExecutingToolCallIds((prev) => {
|
|
1655
|
-
if (prev.has(toolCallId)) return prev;
|
|
1656
|
-
const next = new Set(prev);
|
|
1657
|
-
next.add(toolCallId);
|
|
1658
|
-
return next;
|
|
1659
|
-
});
|
|
1660
|
-
},
|
|
1661
|
-
onToolExecutionEnd: ({ toolCallId }) => {
|
|
1662
|
-
setExecutingToolCallIds((prev) => {
|
|
1663
|
-
if (!prev.has(toolCallId)) return prev;
|
|
1664
|
-
const next = new Set(prev);
|
|
1665
|
-
next.delete(toolCallId);
|
|
1666
|
-
return next;
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
});
|
|
1670
|
-
return () => unsubscribe();
|
|
1671
|
-
}, [copilotkit]);
|
|
1672
|
-
const renderToolCall = useCallback2(
|
|
1673
|
-
({
|
|
1674
|
-
toolCall,
|
|
1675
|
-
toolMessage
|
|
1676
|
-
}) => {
|
|
1677
|
-
const exactMatches = renderToolCalls.filter(
|
|
1678
|
-
(rc) => rc.name === toolCall.function.name
|
|
1679
|
-
);
|
|
1680
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1681
|
-
if (!renderConfig) {
|
|
1682
|
-
return null;
|
|
1683
|
-
}
|
|
1684
|
-
const RenderComponent = renderConfig.render;
|
|
1685
|
-
const args = partialJSONParse(toolCall.function.arguments);
|
|
1686
|
-
const toolName = toolCall.function.name;
|
|
1687
|
-
if (toolMessage) {
|
|
1688
|
-
return /* @__PURE__ */ jsx9(
|
|
1689
|
-
RenderComponent,
|
|
1690
|
-
{
|
|
1691
|
-
name: toolName,
|
|
1692
|
-
args,
|
|
1693
|
-
status: ToolCallStatus.Complete,
|
|
1694
|
-
result: toolMessage.content
|
|
1695
|
-
},
|
|
1696
|
-
toolCall.id
|
|
1697
|
-
);
|
|
1698
|
-
} else if (executingToolCallIds.has(toolCall.id)) {
|
|
1699
|
-
return /* @__PURE__ */ jsx9(
|
|
1700
|
-
RenderComponent,
|
|
1701
|
-
{
|
|
1702
|
-
name: toolName,
|
|
1703
|
-
args,
|
|
1704
|
-
status: ToolCallStatus.Executing,
|
|
1705
|
-
result: void 0
|
|
1706
|
-
},
|
|
1707
|
-
toolCall.id
|
|
1708
|
-
);
|
|
1709
|
-
} else {
|
|
1710
|
-
return /* @__PURE__ */ jsx9(
|
|
1711
|
-
RenderComponent,
|
|
1712
|
-
{
|
|
1713
|
-
name: toolName,
|
|
1714
|
-
args,
|
|
1715
|
-
status: ToolCallStatus.InProgress,
|
|
1716
|
-
result: void 0
|
|
1717
|
-
},
|
|
1718
|
-
toolCall.id
|
|
1719
|
-
);
|
|
1720
|
-
}
|
|
1721
|
-
},
|
|
1722
|
-
[renderToolCalls, executingToolCallIds, agentId]
|
|
1723
|
-
);
|
|
1724
|
-
return renderToolCall;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
// src/hooks/use-render-custom-messages.tsx
|
|
1728
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1729
|
-
function useRenderCustomMessages() {
|
|
1730
|
-
const { copilotkit } = useCopilotKit();
|
|
1731
|
-
const config = useCopilotChatConfiguration();
|
|
1732
|
-
if (!config) {
|
|
1733
|
-
return null;
|
|
1734
|
-
}
|
|
1735
|
-
const { agentId, threadId } = config;
|
|
1736
|
-
const customMessageRenderers = copilotkit.renderCustomMessages.filter((renderer) => renderer.agentId === void 0 || renderer.agentId === agentId).sort((a, b) => {
|
|
1737
|
-
const aHasAgent = a.agentId !== void 0;
|
|
1738
|
-
const bHasAgent = b.agentId !== void 0;
|
|
1739
|
-
if (aHasAgent === bHasAgent) return 0;
|
|
1740
|
-
return aHasAgent ? -1 : 1;
|
|
1741
|
-
});
|
|
1742
|
-
return function(params) {
|
|
1743
|
-
if (!customMessageRenderers.length) {
|
|
1744
|
-
return null;
|
|
1745
|
-
}
|
|
1746
|
-
const { message, position } = params;
|
|
1747
|
-
const runId = copilotkit.getRunIdForMessage(agentId, threadId, message.id);
|
|
1748
|
-
const agent = copilotkit.getAgent(agentId);
|
|
1749
|
-
if (!agent) {
|
|
1750
|
-
throw new Error("Agent not found");
|
|
1751
|
-
}
|
|
1752
|
-
const messagesIdsInRun = agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === runId).map((msg) => msg.id);
|
|
1753
|
-
const messageIndex = agent.messages.findIndex((msg) => msg.id === message.id) ?? 0;
|
|
1754
|
-
const messageIndexInRun = Math.min(messagesIdsInRun.indexOf(message.id), 0);
|
|
1755
|
-
const numberOfMessagesInRun = messagesIdsInRun.length;
|
|
1756
|
-
const stateSnapshot = copilotkit.getStateByRun(agentId, threadId, runId);
|
|
1757
|
-
let result = null;
|
|
1758
|
-
for (const renderer of customMessageRenderers) {
|
|
1759
|
-
if (!renderer.render) {
|
|
1760
|
-
continue;
|
|
1761
|
-
}
|
|
1762
|
-
const Component = renderer.render;
|
|
1763
|
-
result = /* @__PURE__ */ jsx10(
|
|
1764
|
-
Component,
|
|
1765
|
-
{
|
|
1766
|
-
message,
|
|
1767
|
-
position,
|
|
1768
|
-
runId,
|
|
1769
|
-
messageIndex,
|
|
1770
|
-
messageIndexInRun,
|
|
1771
|
-
numberOfMessagesInRun,
|
|
1772
|
-
agentId,
|
|
1773
|
-
stateSnapshot
|
|
1774
|
-
},
|
|
1775
|
-
`${runId}-${message.id}-${position}`
|
|
1776
|
-
);
|
|
1777
|
-
if (result) {
|
|
1778
|
-
break;
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
return result;
|
|
1782
|
-
};
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
// src/hooks/use-render-activity-message.tsx
|
|
1786
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID3 } from "@copilotkitnext/shared";
|
|
1787
|
-
import { useCallback as useCallback3 } from "react";
|
|
1788
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1789
|
-
function useRenderActivityMessage() {
|
|
1790
|
-
const { copilotkit } = useCopilotKit();
|
|
1791
|
-
const config = useCopilotChatConfiguration();
|
|
1792
|
-
const agentId = config?.agentId ?? DEFAULT_AGENT_ID3;
|
|
1793
|
-
const renderers = copilotkit.renderActivityMessages;
|
|
1794
|
-
return useCallback3(
|
|
1795
|
-
(message) => {
|
|
1796
|
-
if (!renderers.length) {
|
|
1797
|
-
return null;
|
|
1798
|
-
}
|
|
1799
|
-
const matches = renderers.filter(
|
|
1800
|
-
(renderer2) => renderer2.activityType === message.activityType
|
|
1801
|
-
);
|
|
1802
|
-
const renderer = matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*");
|
|
1803
|
-
if (!renderer) {
|
|
1804
|
-
return null;
|
|
1805
|
-
}
|
|
1806
|
-
const parseResult = renderer.content.safeParse(message.content);
|
|
1807
|
-
if (!parseResult.success) {
|
|
1808
|
-
console.warn(
|
|
1809
|
-
`Failed to parse content for activity message '${message.activityType}':`,
|
|
1810
|
-
parseResult.error
|
|
1811
|
-
);
|
|
1812
|
-
return null;
|
|
1813
|
-
}
|
|
1814
|
-
const Component = renderer.render;
|
|
1815
|
-
const agent = copilotkit.getAgent(agentId);
|
|
1816
|
-
return /* @__PURE__ */ jsx11(
|
|
1817
|
-
Component,
|
|
1818
|
-
{
|
|
1819
|
-
activityType: message.activityType,
|
|
1820
|
-
content: parseResult.data,
|
|
1821
|
-
message,
|
|
1822
|
-
agent
|
|
1823
|
-
},
|
|
1824
|
-
message.id
|
|
1825
|
-
);
|
|
1826
|
-
},
|
|
1827
|
-
[agentId, copilotkit, renderers]
|
|
1828
|
-
);
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
// src/hooks/use-frontend-tool.tsx
|
|
1832
|
-
import { useEffect as useEffect6 } from "react";
|
|
1833
|
-
function useFrontendTool(tool) {
|
|
1834
|
-
const { copilotkit } = useCopilotKit();
|
|
1835
|
-
useEffect6(() => {
|
|
1836
|
-
const name = tool.name;
|
|
1837
|
-
if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
|
|
1838
|
-
console.warn(
|
|
1839
|
-
`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`
|
|
1840
|
-
);
|
|
1841
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
1842
|
-
}
|
|
1843
|
-
copilotkit.addTool(tool);
|
|
1844
|
-
if (tool.render) {
|
|
1845
|
-
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1846
|
-
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
1847
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
1848
|
-
for (const rc of currentRenderToolCalls) {
|
|
1849
|
-
mergedMap.set(keyOf(rc), rc);
|
|
1850
|
-
}
|
|
1851
|
-
const newEntry = {
|
|
1852
|
-
name,
|
|
1853
|
-
args: tool.parameters,
|
|
1854
|
-
agentId: tool.agentId,
|
|
1855
|
-
render: tool.render
|
|
1856
|
-
};
|
|
1857
|
-
mergedMap.set(keyOf(newEntry), newEntry);
|
|
1858
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
1859
|
-
}
|
|
1860
|
-
return () => {
|
|
1861
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
1862
|
-
};
|
|
1863
|
-
}, [tool.name, copilotkit]);
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
// src/hooks/use-human-in-the-loop.tsx
|
|
1867
|
-
import { useCallback as useCallback4, useRef as useRef5, useEffect as useEffect7 } from "react";
|
|
1868
|
-
import React7 from "react";
|
|
1869
|
-
function useHumanInTheLoop(tool) {
|
|
1870
|
-
const { copilotkit } = useCopilotKit();
|
|
1871
|
-
const resolvePromiseRef = useRef5(null);
|
|
1872
|
-
const respond = useCallback4(async (result) => {
|
|
1873
|
-
if (resolvePromiseRef.current) {
|
|
1874
|
-
resolvePromiseRef.current(result);
|
|
1875
|
-
resolvePromiseRef.current = null;
|
|
1876
|
-
}
|
|
1877
|
-
}, []);
|
|
1878
|
-
const handler = useCallback4(async () => {
|
|
1879
|
-
return new Promise((resolve) => {
|
|
1880
|
-
resolvePromiseRef.current = resolve;
|
|
1881
|
-
});
|
|
1882
|
-
}, []);
|
|
1883
|
-
const RenderComponent = useCallback4(
|
|
1884
|
-
(props) => {
|
|
1885
|
-
const ToolComponent = tool.render;
|
|
1886
|
-
if (props.status === "inProgress") {
|
|
1887
|
-
const enhancedProps = {
|
|
1888
|
-
...props,
|
|
1889
|
-
name: tool.name,
|
|
1890
|
-
description: tool.description || "",
|
|
1891
|
-
respond: void 0
|
|
1892
|
-
};
|
|
1893
|
-
return React7.createElement(ToolComponent, enhancedProps);
|
|
1894
|
-
} else if (props.status === "executing") {
|
|
1895
|
-
const enhancedProps = {
|
|
1896
|
-
...props,
|
|
1897
|
-
name: tool.name,
|
|
1898
|
-
description: tool.description || "",
|
|
1899
|
-
respond
|
|
1900
|
-
};
|
|
1901
|
-
return React7.createElement(ToolComponent, enhancedProps);
|
|
1902
|
-
} else if (props.status === "complete") {
|
|
1903
|
-
const enhancedProps = {
|
|
1904
|
-
...props,
|
|
1905
|
-
name: tool.name,
|
|
1906
|
-
description: tool.description || "",
|
|
1907
|
-
respond: void 0
|
|
1908
|
-
};
|
|
1909
|
-
return React7.createElement(ToolComponent, enhancedProps);
|
|
1910
|
-
}
|
|
1911
|
-
return React7.createElement(ToolComponent, props);
|
|
1912
|
-
},
|
|
1913
|
-
[tool.render, tool.name, tool.description, respond]
|
|
1914
|
-
);
|
|
1915
|
-
const frontendTool = {
|
|
1916
|
-
...tool,
|
|
1917
|
-
handler,
|
|
1918
|
-
render: RenderComponent
|
|
1919
|
-
};
|
|
1920
|
-
useFrontendTool(frontendTool);
|
|
1921
|
-
useEffect7(() => {
|
|
1922
|
-
return () => {
|
|
1923
|
-
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1924
|
-
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
1925
|
-
const filtered = currentRenderToolCalls.filter(
|
|
1926
|
-
(rc) => keyOf(rc) !== keyOf({ name: tool.name, agentId: tool.agentId })
|
|
1927
|
-
);
|
|
1928
|
-
copilotkit.setRenderToolCalls(filtered);
|
|
1929
|
-
};
|
|
1930
|
-
}, [copilotkit, tool.name, tool.agentId]);
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1933
|
-
// src/hooks/use-agent.tsx
|
|
1934
|
-
import { useMemo as useMemo4, useEffect as useEffect8, useReducer as useReducer2 } from "react";
|
|
1935
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
|
|
1936
|
-
var ALL_UPDATES = [
|
|
1937
|
-
"OnMessagesChanged" /* OnMessagesChanged */,
|
|
1938
|
-
"OnStateChanged" /* OnStateChanged */,
|
|
1939
|
-
"OnRunStatusChanged" /* OnRunStatusChanged */
|
|
1940
|
-
];
|
|
1941
|
-
function useAgent({ agentId, updates } = {}) {
|
|
1942
|
-
agentId ??= DEFAULT_AGENT_ID4;
|
|
1943
|
-
const { copilotkit } = useCopilotKit();
|
|
1944
|
-
const [, forceUpdate] = useReducer2((x) => x + 1, 0);
|
|
1945
|
-
const updateFlags = useMemo4(
|
|
1946
|
-
() => updates ?? ALL_UPDATES,
|
|
1947
|
-
[JSON.stringify(updates)]
|
|
1948
|
-
);
|
|
1949
|
-
const agent = useMemo4(() => {
|
|
1950
|
-
return copilotkit.getAgent(agentId);
|
|
1951
|
-
}, [
|
|
1952
|
-
agentId,
|
|
1953
|
-
copilotkit.agents,
|
|
1954
|
-
copilotkit.runtimeConnectionStatus,
|
|
1955
|
-
copilotkit
|
|
1956
|
-
]);
|
|
1957
|
-
useEffect8(() => {
|
|
1958
|
-
if (!agent) {
|
|
1959
|
-
return;
|
|
1960
|
-
}
|
|
1961
|
-
if (updateFlags.length === 0) {
|
|
1962
|
-
return;
|
|
1963
|
-
}
|
|
1964
|
-
const handlers = {};
|
|
1965
|
-
if (updateFlags.includes("OnMessagesChanged" /* OnMessagesChanged */)) {
|
|
1966
|
-
handlers.onMessagesChanged = () => {
|
|
1967
|
-
forceUpdate();
|
|
1968
|
-
};
|
|
1969
|
-
}
|
|
1970
|
-
if (updateFlags.includes("OnStateChanged" /* OnStateChanged */)) {
|
|
1971
|
-
handlers.onStateChanged = () => {
|
|
1972
|
-
forceUpdate();
|
|
1973
|
-
};
|
|
1974
|
-
}
|
|
1975
|
-
if (updateFlags.includes("OnRunStatusChanged" /* OnRunStatusChanged */)) {
|
|
1976
|
-
handlers.onRunInitialized = () => {
|
|
1977
|
-
forceUpdate();
|
|
1978
|
-
};
|
|
1979
|
-
handlers.onRunFinalized = () => {
|
|
1980
|
-
forceUpdate();
|
|
1981
|
-
};
|
|
1982
|
-
handlers.onRunFailed = () => {
|
|
1983
|
-
forceUpdate();
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
const subscription = agent.subscribe(handlers);
|
|
1987
|
-
return () => subscription.unsubscribe();
|
|
1988
|
-
}, [agent, forceUpdate, JSON.stringify(updateFlags)]);
|
|
1989
|
-
return {
|
|
1990
|
-
agent
|
|
1991
|
-
};
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
// src/hooks/use-agent-context.tsx
|
|
1995
|
-
import { useEffect as useEffect9 } from "react";
|
|
1996
|
-
function useAgentContext(context) {
|
|
1997
|
-
const { description, value } = context;
|
|
1998
|
-
const { copilotkit } = useCopilotKit();
|
|
1999
|
-
useEffect9(() => {
|
|
2000
|
-
if (!copilotkit) return;
|
|
2001
|
-
const id = copilotkit.addContext(context);
|
|
2002
|
-
return () => {
|
|
2003
|
-
copilotkit.removeContext(id);
|
|
2004
|
-
};
|
|
2005
|
-
}, [description, value, copilotkit]);
|
|
2006
|
-
}
|
|
2007
|
-
|
|
2008
|
-
// src/hooks/use-suggestions.tsx
|
|
2009
|
-
import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo5, useState as useState5 } from "react";
|
|
2010
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
|
|
2011
|
-
function useSuggestions({ agentId } = {}) {
|
|
2012
|
-
const { copilotkit } = useCopilotKit();
|
|
2013
|
-
const config = useCopilotChatConfiguration();
|
|
2014
|
-
const resolvedAgentId = useMemo5(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
|
|
2015
|
-
const [suggestions, setSuggestions] = useState5(() => {
|
|
2016
|
-
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2017
|
-
return result.suggestions;
|
|
2018
|
-
});
|
|
2019
|
-
const [isLoading, setIsLoading] = useState5(() => {
|
|
2020
|
-
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2021
|
-
return result.isLoading;
|
|
2022
|
-
});
|
|
2023
|
-
useEffect10(() => {
|
|
2024
|
-
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2025
|
-
setSuggestions(result.suggestions);
|
|
2026
|
-
setIsLoading(result.isLoading);
|
|
2027
|
-
}, [copilotkit, resolvedAgentId]);
|
|
2028
|
-
useEffect10(() => {
|
|
2029
|
-
const unsubscribe = copilotkit.subscribe({
|
|
2030
|
-
onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
|
|
2031
|
-
if (changedAgentId !== resolvedAgentId) {
|
|
2032
|
-
return;
|
|
2033
|
-
}
|
|
2034
|
-
setSuggestions(suggestions2);
|
|
2035
|
-
},
|
|
2036
|
-
onSuggestionsStartedLoading: ({ agentId: changedAgentId }) => {
|
|
2037
|
-
if (changedAgentId !== resolvedAgentId) {
|
|
2038
|
-
return;
|
|
2039
|
-
}
|
|
2040
|
-
setIsLoading(true);
|
|
2041
|
-
},
|
|
2042
|
-
onSuggestionsFinishedLoading: ({ agentId: changedAgentId }) => {
|
|
2043
|
-
if (changedAgentId !== resolvedAgentId) {
|
|
2044
|
-
return;
|
|
2045
|
-
}
|
|
2046
|
-
setIsLoading(false);
|
|
2047
|
-
},
|
|
2048
|
-
onSuggestionsConfigChanged: () => {
|
|
2049
|
-
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2050
|
-
setSuggestions(result.suggestions);
|
|
2051
|
-
setIsLoading(result.isLoading);
|
|
2052
|
-
}
|
|
2053
|
-
});
|
|
2054
|
-
return () => {
|
|
2055
|
-
unsubscribe();
|
|
2056
|
-
};
|
|
2057
|
-
}, [copilotkit, resolvedAgentId]);
|
|
2058
|
-
const reloadSuggestions = useCallback5(() => {
|
|
2059
|
-
copilotkit.reloadSuggestions(resolvedAgentId);
|
|
2060
|
-
}, [copilotkit, resolvedAgentId]);
|
|
2061
|
-
const clearSuggestions = useCallback5(() => {
|
|
2062
|
-
copilotkit.clearSuggestions(resolvedAgentId);
|
|
2063
|
-
}, [copilotkit, resolvedAgentId]);
|
|
2064
|
-
return {
|
|
2065
|
-
suggestions,
|
|
2066
|
-
reloadSuggestions,
|
|
2067
|
-
clearSuggestions,
|
|
2068
|
-
isLoading
|
|
2069
|
-
};
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
// src/hooks/use-configure-suggestions.tsx
|
|
2073
|
-
import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo6, useRef as useRef6 } from "react";
|
|
2074
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6 } from "@copilotkitnext/shared";
|
|
2075
|
-
var EMPTY_DEPS = [];
|
|
2076
|
-
function useConfigureSuggestions(config, options) {
|
|
2077
|
-
const { copilotkit } = useCopilotKit();
|
|
2078
|
-
const chatConfig = useCopilotChatConfiguration();
|
|
2079
|
-
const extraDeps = options?.deps ?? EMPTY_DEPS;
|
|
2080
|
-
const resolvedConsumerAgentId = useMemo6(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
|
|
2081
|
-
const rawConsumerAgentId = useMemo6(() => config ? config.consumerAgentId : void 0, [config]);
|
|
2082
|
-
const normalizationCacheRef = useRef6({
|
|
2083
|
-
serialized: null,
|
|
2084
|
-
config: null
|
|
2085
|
-
});
|
|
2086
|
-
const { normalizedConfig, serializedConfig } = useMemo6(() => {
|
|
2087
|
-
if (!config) {
|
|
2088
|
-
normalizationCacheRef.current = { serialized: null, config: null };
|
|
2089
|
-
return { normalizedConfig: null, serializedConfig: null };
|
|
2090
|
-
}
|
|
2091
|
-
if (config.available === "disabled") {
|
|
2092
|
-
normalizationCacheRef.current = { serialized: null, config: null };
|
|
2093
|
-
return { normalizedConfig: null, serializedConfig: null };
|
|
2094
|
-
}
|
|
2095
|
-
let built;
|
|
2096
|
-
if (isDynamicConfig(config)) {
|
|
2097
|
-
built = {
|
|
2098
|
-
...config
|
|
2099
|
-
};
|
|
2100
|
-
} else {
|
|
2101
|
-
const normalizedSuggestions = normalizeStaticSuggestions(config.suggestions);
|
|
2102
|
-
const baseConfig = {
|
|
2103
|
-
...config,
|
|
2104
|
-
suggestions: normalizedSuggestions
|
|
2105
|
-
};
|
|
2106
|
-
built = baseConfig;
|
|
2107
|
-
}
|
|
2108
|
-
const serialized = JSON.stringify(built);
|
|
2109
|
-
const cache = normalizationCacheRef.current;
|
|
2110
|
-
if (cache.serialized === serialized && cache.config) {
|
|
2111
|
-
return { normalizedConfig: cache.config, serializedConfig: serialized };
|
|
2112
|
-
}
|
|
2113
|
-
normalizationCacheRef.current = { serialized, config: built };
|
|
2114
|
-
return { normalizedConfig: built, serializedConfig: serialized };
|
|
2115
|
-
}, [config, resolvedConsumerAgentId, ...extraDeps]);
|
|
2116
|
-
const latestConfigRef = useRef6(null);
|
|
2117
|
-
latestConfigRef.current = normalizedConfig;
|
|
2118
|
-
const previousSerializedConfigRef = useRef6(null);
|
|
2119
|
-
const targetAgentId = useMemo6(() => {
|
|
2120
|
-
if (!normalizedConfig) {
|
|
2121
|
-
return resolvedConsumerAgentId;
|
|
2122
|
-
}
|
|
2123
|
-
const consumer = normalizedConfig.consumerAgentId;
|
|
2124
|
-
if (!consumer || consumer === "*") {
|
|
2125
|
-
return resolvedConsumerAgentId;
|
|
2126
|
-
}
|
|
2127
|
-
return consumer;
|
|
2128
|
-
}, [normalizedConfig, resolvedConsumerAgentId]);
|
|
2129
|
-
const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
|
|
2130
|
-
const requestReload = useCallback6(() => {
|
|
2131
|
-
if (!normalizedConfig) {
|
|
2132
|
-
return;
|
|
2133
|
-
}
|
|
2134
|
-
if (isGlobalConfig) {
|
|
2135
|
-
const agents = Object.values(copilotkit.agents ?? {});
|
|
2136
|
-
for (const entry of agents) {
|
|
2137
|
-
const agentId = entry.agentId;
|
|
2138
|
-
if (!agentId) {
|
|
2139
|
-
continue;
|
|
2140
|
-
}
|
|
2141
|
-
if (!entry.isRunning) {
|
|
2142
|
-
copilotkit.reloadSuggestions(agentId);
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
return;
|
|
2146
|
-
}
|
|
2147
|
-
if (!targetAgentId) {
|
|
2148
|
-
return;
|
|
2149
|
-
}
|
|
2150
|
-
copilotkit.reloadSuggestions(targetAgentId);
|
|
2151
|
-
}, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
|
|
2152
|
-
useEffect11(() => {
|
|
2153
|
-
if (!serializedConfig || !latestConfigRef.current) {
|
|
2154
|
-
return;
|
|
2155
|
-
}
|
|
2156
|
-
const id = copilotkit.addSuggestionsConfig(latestConfigRef.current);
|
|
2157
|
-
requestReload();
|
|
2158
|
-
return () => {
|
|
2159
|
-
copilotkit.removeSuggestionsConfig(id);
|
|
2160
|
-
};
|
|
2161
|
-
}, [copilotkit, serializedConfig, requestReload]);
|
|
2162
|
-
useEffect11(() => {
|
|
2163
|
-
if (!normalizedConfig) {
|
|
2164
|
-
previousSerializedConfigRef.current = null;
|
|
2165
|
-
return;
|
|
2166
|
-
}
|
|
2167
|
-
if (serializedConfig && previousSerializedConfigRef.current === serializedConfig) {
|
|
2168
|
-
return;
|
|
2169
|
-
}
|
|
2170
|
-
if (serializedConfig) {
|
|
2171
|
-
previousSerializedConfigRef.current = serializedConfig;
|
|
2172
|
-
}
|
|
2173
|
-
requestReload();
|
|
2174
|
-
}, [normalizedConfig, requestReload, serializedConfig]);
|
|
2175
|
-
useEffect11(() => {
|
|
2176
|
-
if (!normalizedConfig || extraDeps.length === 0) {
|
|
2177
|
-
return;
|
|
2178
|
-
}
|
|
2179
|
-
requestReload();
|
|
2180
|
-
}, [extraDeps.length, normalizedConfig, requestReload, ...extraDeps]);
|
|
2181
|
-
}
|
|
2182
|
-
function isDynamicConfig(config) {
|
|
2183
|
-
return "instructions" in config;
|
|
2184
|
-
}
|
|
2185
|
-
function normalizeStaticSuggestions(suggestions) {
|
|
2186
|
-
return suggestions.map((suggestion) => ({
|
|
2187
|
-
...suggestion,
|
|
2188
|
-
isLoading: suggestion.isLoading ?? false
|
|
2189
|
-
}));
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
// src/components/chat/CopilotChatToolCallsView.tsx
|
|
2193
|
-
import React8 from "react";
|
|
2194
|
-
import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
|
|
2195
|
-
function CopilotChatToolCallsView({
|
|
2196
|
-
message,
|
|
2197
|
-
messages = []
|
|
2198
|
-
}) {
|
|
2199
|
-
const renderToolCall = useRenderToolCall();
|
|
2200
|
-
if (!message.toolCalls || message.toolCalls.length === 0) {
|
|
2201
|
-
return null;
|
|
2202
|
-
}
|
|
2203
|
-
return /* @__PURE__ */ jsx12(Fragment2, { children: message.toolCalls.map((toolCall) => {
|
|
2204
|
-
const toolMessage = messages.find(
|
|
2205
|
-
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
2206
|
-
);
|
|
2207
|
-
return /* @__PURE__ */ jsx12(React8.Fragment, { children: renderToolCall({
|
|
2208
|
-
toolCall,
|
|
2209
|
-
toolMessage
|
|
2210
|
-
}) }, toolCall.id);
|
|
2211
|
-
}) });
|
|
2212
|
-
}
|
|
2213
|
-
var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
|
|
2214
|
-
|
|
2215
|
-
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
2216
|
-
import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2217
|
-
function CopilotChatAssistantMessage({
|
|
2218
|
-
message,
|
|
2219
|
-
messages,
|
|
2220
|
-
isRunning,
|
|
2221
|
-
onThumbsUp,
|
|
2222
|
-
onThumbsDown,
|
|
2223
|
-
onReadAloud,
|
|
2224
|
-
onRegenerate,
|
|
2225
|
-
additionalToolbarItems,
|
|
2226
|
-
toolbarVisible = true,
|
|
2227
|
-
markdownRenderer,
|
|
2228
|
-
toolbar,
|
|
2229
|
-
copyButton,
|
|
2230
|
-
thumbsUpButton,
|
|
2231
|
-
thumbsDownButton,
|
|
2232
|
-
readAloudButton,
|
|
2233
|
-
regenerateButton,
|
|
2234
|
-
toolCallsView,
|
|
2235
|
-
children,
|
|
2236
|
-
className,
|
|
2237
|
-
...props
|
|
2238
|
-
}) {
|
|
2239
|
-
const boundMarkdownRenderer = renderSlot(
|
|
2240
|
-
markdownRenderer,
|
|
2241
|
-
CopilotChatAssistantMessage.MarkdownRenderer,
|
|
2242
|
-
{
|
|
2243
|
-
content: message.content || ""
|
|
2244
|
-
}
|
|
2245
|
-
);
|
|
2246
|
-
const boundCopyButton = renderSlot(
|
|
2247
|
-
copyButton,
|
|
2248
|
-
CopilotChatAssistantMessage.CopyButton,
|
|
2249
|
-
{
|
|
2250
|
-
onClick: async () => {
|
|
2251
|
-
if (message.content) {
|
|
2252
|
-
try {
|
|
2253
|
-
await navigator.clipboard.writeText(message.content);
|
|
2254
|
-
} catch (err) {
|
|
2255
|
-
console.error("Failed to copy message:", err);
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
);
|
|
2261
|
-
const boundThumbsUpButton = renderSlot(
|
|
2262
|
-
thumbsUpButton,
|
|
2263
|
-
CopilotChatAssistantMessage.ThumbsUpButton,
|
|
2264
|
-
{
|
|
2265
|
-
onClick: onThumbsUp
|
|
2266
|
-
}
|
|
2267
|
-
);
|
|
2268
|
-
const boundThumbsDownButton = renderSlot(
|
|
2269
|
-
thumbsDownButton,
|
|
2270
|
-
CopilotChatAssistantMessage.ThumbsDownButton,
|
|
2271
|
-
{
|
|
2272
|
-
onClick: onThumbsDown
|
|
2273
|
-
}
|
|
2274
|
-
);
|
|
2275
|
-
const boundReadAloudButton = renderSlot(
|
|
2276
|
-
readAloudButton,
|
|
2277
|
-
CopilotChatAssistantMessage.ReadAloudButton,
|
|
2278
|
-
{
|
|
2279
|
-
onClick: onReadAloud
|
|
2280
|
-
}
|
|
2281
|
-
);
|
|
2282
|
-
const boundRegenerateButton = renderSlot(
|
|
2283
|
-
regenerateButton,
|
|
2284
|
-
CopilotChatAssistantMessage.RegenerateButton,
|
|
2285
|
-
{
|
|
2286
|
-
onClick: onRegenerate
|
|
2287
|
-
}
|
|
2288
|
-
);
|
|
2289
|
-
const boundToolbar = renderSlot(
|
|
2290
|
-
toolbar,
|
|
2291
|
-
CopilotChatAssistantMessage.Toolbar,
|
|
2292
|
-
{
|
|
2293
|
-
children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1", children: [
|
|
2294
|
-
boundCopyButton,
|
|
2295
|
-
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
2296
|
-
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
2297
|
-
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
2298
|
-
(onRegenerate || regenerateButton) && boundRegenerateButton,
|
|
2299
|
-
additionalToolbarItems
|
|
2300
|
-
] })
|
|
2301
|
-
}
|
|
2302
|
-
);
|
|
2303
|
-
const boundToolCallsView = renderSlot(
|
|
2304
|
-
toolCallsView,
|
|
2305
|
-
CopilotChatToolCallsView_default,
|
|
2306
|
-
{
|
|
2307
|
-
message,
|
|
2308
|
-
messages
|
|
2309
|
-
}
|
|
2310
|
-
);
|
|
2311
|
-
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
2312
|
-
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
2313
|
-
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
2314
|
-
if (children) {
|
|
2315
|
-
return /* @__PURE__ */ jsx13(Fragment3, { children: children({
|
|
2316
|
-
markdownRenderer: boundMarkdownRenderer,
|
|
2317
|
-
toolbar: boundToolbar,
|
|
2318
|
-
toolCallsView: boundToolCallsView,
|
|
2319
|
-
copyButton: boundCopyButton,
|
|
2320
|
-
thumbsUpButton: boundThumbsUpButton,
|
|
2321
|
-
thumbsDownButton: boundThumbsDownButton,
|
|
2322
|
-
readAloudButton: boundReadAloudButton,
|
|
2323
|
-
regenerateButton: boundRegenerateButton,
|
|
2324
|
-
message,
|
|
2325
|
-
messages,
|
|
2326
|
-
isRunning,
|
|
2327
|
-
onThumbsUp,
|
|
2328
|
-
onThumbsDown,
|
|
2329
|
-
onReadAloud,
|
|
2330
|
-
onRegenerate,
|
|
2331
|
-
additionalToolbarItems,
|
|
2332
|
-
toolbarVisible: shouldShowToolbar
|
|
2333
|
-
}) });
|
|
2334
|
-
}
|
|
2335
|
-
return /* @__PURE__ */ jsxs5(
|
|
2336
|
-
"div",
|
|
2337
|
-
{
|
|
2338
|
-
className: twMerge4(
|
|
2339
|
-
"prose max-w-full break-words dark:prose-invert",
|
|
2340
|
-
className
|
|
2341
|
-
),
|
|
2342
|
-
...props,
|
|
2343
|
-
"data-message-id": message.id,
|
|
2344
|
-
children: [
|
|
2345
|
-
boundMarkdownRenderer,
|
|
2346
|
-
boundToolCallsView,
|
|
2347
|
-
shouldShowToolbar && boundToolbar
|
|
2348
|
-
]
|
|
2349
|
-
}
|
|
2350
|
-
);
|
|
2351
|
-
}
|
|
2352
|
-
((CopilotChatAssistantMessage2) => {
|
|
2353
|
-
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ jsx13(Streamdown, { className, ...props, children: content ?? "" });
|
|
2354
|
-
CopilotChatAssistantMessage2.Toolbar = ({
|
|
2355
|
-
className,
|
|
2356
|
-
...props
|
|
2357
|
-
}) => /* @__PURE__ */ jsx13(
|
|
2358
|
-
"div",
|
|
2359
|
-
{
|
|
2360
|
-
className: twMerge4(
|
|
2361
|
-
"w-full bg-transparent flex items-center -ml-[5px] -mt-[0px]",
|
|
2362
|
-
className
|
|
2363
|
-
),
|
|
2364
|
-
...props
|
|
2365
|
-
}
|
|
2366
|
-
);
|
|
2367
|
-
CopilotChatAssistantMessage2.ToolbarButton = ({ title, children, ...props }) => {
|
|
2368
|
-
return /* @__PURE__ */ jsxs5(Tooltip, { children: [
|
|
2369
|
-
/* @__PURE__ */ jsx13(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx13(
|
|
2370
|
-
Button,
|
|
2371
|
-
{
|
|
2372
|
-
type: "button",
|
|
2373
|
-
variant: "assistantMessageToolbarButton",
|
|
2374
|
-
"aria-label": title,
|
|
2375
|
-
...props,
|
|
2376
|
-
children
|
|
2377
|
-
}
|
|
2378
|
-
) }),
|
|
2379
|
-
/* @__PURE__ */ jsx13(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx13("p", { children: title }) })
|
|
2380
|
-
] });
|
|
2381
|
-
};
|
|
2382
|
-
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2383
|
-
const config = useCopilotChatConfiguration();
|
|
2384
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2385
|
-
const [copied, setCopied] = useState6(false);
|
|
2386
|
-
const handleClick = (event) => {
|
|
2387
|
-
setCopied(true);
|
|
2388
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2389
|
-
if (onClick) {
|
|
2390
|
-
onClick(event);
|
|
2391
|
-
}
|
|
2392
|
-
};
|
|
2393
|
-
return /* @__PURE__ */ jsx13(
|
|
2394
|
-
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2395
|
-
{
|
|
2396
|
-
title: title || labels.assistantMessageToolbarCopyMessageLabel,
|
|
2397
|
-
onClick: handleClick,
|
|
2398
|
-
className,
|
|
2399
|
-
...props,
|
|
2400
|
-
children: copied ? /* @__PURE__ */ jsx13(Check2, { className: "size-[18px]" }) : /* @__PURE__ */ jsx13(Copy, { className: "size-[18px]" })
|
|
2401
|
-
}
|
|
2402
|
-
);
|
|
2403
|
-
};
|
|
2404
|
-
CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
|
|
2405
|
-
const config = useCopilotChatConfiguration();
|
|
2406
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2407
|
-
return /* @__PURE__ */ jsx13(
|
|
2408
|
-
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2409
|
-
{
|
|
2410
|
-
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
2411
|
-
...props,
|
|
2412
|
-
children: /* @__PURE__ */ jsx13(ThumbsUp, { className: "size-[18px]" })
|
|
2413
|
-
}
|
|
2414
|
-
);
|
|
2415
|
-
};
|
|
2416
|
-
CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
|
|
2417
|
-
const config = useCopilotChatConfiguration();
|
|
2418
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2419
|
-
return /* @__PURE__ */ jsx13(
|
|
2420
|
-
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2421
|
-
{
|
|
2422
|
-
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
2423
|
-
...props,
|
|
2424
|
-
children: /* @__PURE__ */ jsx13(ThumbsDown, { className: "size-[18px]" })
|
|
2425
|
-
}
|
|
2426
|
-
);
|
|
2427
|
-
};
|
|
2428
|
-
CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
|
|
2429
|
-
const config = useCopilotChatConfiguration();
|
|
2430
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2431
|
-
return /* @__PURE__ */ jsx13(
|
|
2432
|
-
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2433
|
-
{
|
|
2434
|
-
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
2435
|
-
...props,
|
|
2436
|
-
children: /* @__PURE__ */ jsx13(Volume2, { className: "size-[20px]" })
|
|
2437
|
-
}
|
|
2438
|
-
);
|
|
2439
|
-
};
|
|
2440
|
-
CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
|
|
2441
|
-
const config = useCopilotChatConfiguration();
|
|
2442
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2443
|
-
return /* @__PURE__ */ jsx13(
|
|
2444
|
-
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2445
|
-
{
|
|
2446
|
-
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
2447
|
-
...props,
|
|
2448
|
-
children: /* @__PURE__ */ jsx13(RefreshCw, { className: "size-[18px]" })
|
|
2449
|
-
}
|
|
2450
|
-
);
|
|
2451
|
-
};
|
|
2452
|
-
})(CopilotChatAssistantMessage || (CopilotChatAssistantMessage = {}));
|
|
2453
|
-
CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistantMessage.MarkdownRenderer";
|
|
2454
|
-
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
2455
|
-
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
2456
|
-
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
2457
|
-
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
2458
|
-
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
2459
|
-
CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
|
|
2460
|
-
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
2461
|
-
|
|
2462
|
-
// src/components/chat/CopilotChatUserMessage.tsx
|
|
2463
|
-
import { useMemo as useMemo7, useState as useState7 } from "react";
|
|
2464
|
-
import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
|
|
2465
|
-
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
2466
|
-
import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2467
|
-
function flattenUserMessageContent(content) {
|
|
2468
|
-
if (!content) {
|
|
2469
|
-
return "";
|
|
2470
|
-
}
|
|
2471
|
-
if (typeof content === "string") {
|
|
2472
|
-
return content;
|
|
2473
|
-
}
|
|
2474
|
-
return content.map((part) => {
|
|
2475
|
-
if (part && typeof part === "object" && "type" in part && part.type === "text" && typeof part.text === "string") {
|
|
2476
|
-
return part.text;
|
|
2477
|
-
}
|
|
2478
|
-
return "";
|
|
2479
|
-
}).filter((text) => text.length > 0).join("\n");
|
|
2480
|
-
}
|
|
2481
|
-
function CopilotChatUserMessage({
|
|
2482
|
-
message,
|
|
2483
|
-
onEditMessage,
|
|
2484
|
-
branchIndex,
|
|
2485
|
-
numberOfBranches,
|
|
2486
|
-
onSwitchToBranch,
|
|
2487
|
-
additionalToolbarItems,
|
|
2488
|
-
messageRenderer,
|
|
2489
|
-
toolbar,
|
|
2490
|
-
copyButton,
|
|
2491
|
-
editButton,
|
|
2492
|
-
branchNavigation,
|
|
2493
|
-
children,
|
|
2494
|
-
className,
|
|
2495
|
-
...props
|
|
2496
|
-
}) {
|
|
2497
|
-
const flattenedContent = useMemo7(
|
|
2498
|
-
() => flattenUserMessageContent(message.content),
|
|
2499
|
-
[message.content]
|
|
2500
|
-
);
|
|
2501
|
-
const BoundMessageRenderer = renderSlot(
|
|
2502
|
-
messageRenderer,
|
|
2503
|
-
CopilotChatUserMessage.MessageRenderer,
|
|
2504
|
-
{
|
|
2505
|
-
content: flattenedContent
|
|
2506
|
-
}
|
|
2507
|
-
);
|
|
2508
|
-
const BoundCopyButton = renderSlot(
|
|
2509
|
-
copyButton,
|
|
2510
|
-
CopilotChatUserMessage.CopyButton,
|
|
2511
|
-
{
|
|
2512
|
-
onClick: async () => {
|
|
2513
|
-
if (flattenedContent) {
|
|
2514
|
-
try {
|
|
2515
|
-
await navigator.clipboard.writeText(flattenedContent);
|
|
2516
|
-
} catch (err) {
|
|
2517
|
-
console.error("Failed to copy message:", err);
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
);
|
|
2523
|
-
const BoundEditButton = renderSlot(
|
|
2524
|
-
editButton,
|
|
2525
|
-
CopilotChatUserMessage.EditButton,
|
|
2526
|
-
{
|
|
2527
|
-
onClick: () => onEditMessage?.({ message })
|
|
2528
|
-
}
|
|
2529
|
-
);
|
|
2530
|
-
const BoundBranchNavigation = renderSlot(
|
|
2531
|
-
branchNavigation,
|
|
2532
|
-
CopilotChatUserMessage.BranchNavigation,
|
|
2533
|
-
{
|
|
2534
|
-
currentBranch: branchIndex,
|
|
2535
|
-
numberOfBranches,
|
|
2536
|
-
onSwitchToBranch,
|
|
2537
|
-
message
|
|
2538
|
-
}
|
|
2539
|
-
);
|
|
2540
|
-
const showBranchNavigation = numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
|
|
2541
|
-
const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
|
|
2542
|
-
children: /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-1 justify-end", children: [
|
|
2543
|
-
additionalToolbarItems,
|
|
2544
|
-
BoundCopyButton,
|
|
2545
|
-
onEditMessage && BoundEditButton,
|
|
2546
|
-
showBranchNavigation && BoundBranchNavigation
|
|
2547
|
-
] })
|
|
2548
|
-
});
|
|
2549
|
-
if (children) {
|
|
2550
|
-
return /* @__PURE__ */ jsx14(Fragment4, { children: children({
|
|
2551
|
-
messageRenderer: BoundMessageRenderer,
|
|
2552
|
-
toolbar: BoundToolbar,
|
|
2553
|
-
copyButton: BoundCopyButton,
|
|
2554
|
-
editButton: BoundEditButton,
|
|
2555
|
-
branchNavigation: BoundBranchNavigation,
|
|
2556
|
-
message,
|
|
2557
|
-
branchIndex,
|
|
2558
|
-
numberOfBranches,
|
|
2559
|
-
additionalToolbarItems
|
|
2560
|
-
}) });
|
|
2561
|
-
}
|
|
2562
|
-
return /* @__PURE__ */ jsxs6(
|
|
2563
|
-
"div",
|
|
2564
|
-
{
|
|
2565
|
-
className: twMerge5("flex flex-col items-end group pt-10", className),
|
|
2566
|
-
"data-message-id": message.id,
|
|
2567
|
-
...props,
|
|
2568
|
-
children: [
|
|
2569
|
-
BoundMessageRenderer,
|
|
2570
|
-
BoundToolbar
|
|
2571
|
-
]
|
|
2572
|
-
}
|
|
2573
|
-
);
|
|
2574
|
-
}
|
|
2575
|
-
((CopilotChatUserMessage2) => {
|
|
2576
|
-
CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */ jsx14(
|
|
2577
|
-
"div",
|
|
2578
|
-
{
|
|
2579
|
-
className: twMerge5("flex flex-col items-end group", className),
|
|
2580
|
-
...props,
|
|
2581
|
-
children
|
|
2582
|
-
}
|
|
2583
|
-
);
|
|
2584
|
-
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ jsx14(
|
|
2585
|
-
"div",
|
|
2586
|
-
{
|
|
2587
|
-
className: twMerge5(
|
|
2588
|
-
"prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
|
|
2589
|
-
className
|
|
2590
|
-
),
|
|
2591
|
-
children: content
|
|
2592
|
-
}
|
|
2593
|
-
);
|
|
2594
|
-
CopilotChatUserMessage2.Toolbar = ({
|
|
2595
|
-
className,
|
|
2596
|
-
...props
|
|
2597
|
-
}) => /* @__PURE__ */ jsx14(
|
|
2598
|
-
"div",
|
|
2599
|
-
{
|
|
2600
|
-
className: twMerge5(
|
|
2601
|
-
"w-full bg-transparent flex items-center justify-end -mr-[5px] mt-[4px] invisible group-hover:visible",
|
|
2602
|
-
className
|
|
2603
|
-
),
|
|
2604
|
-
...props
|
|
2605
|
-
}
|
|
2606
|
-
);
|
|
2607
|
-
CopilotChatUserMessage2.ToolbarButton = ({ title, children, className, ...props }) => {
|
|
2608
|
-
return /* @__PURE__ */ jsxs6(Tooltip, { children: [
|
|
2609
|
-
/* @__PURE__ */ jsx14(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx14(
|
|
2610
|
-
Button,
|
|
2611
|
-
{
|
|
2612
|
-
type: "button",
|
|
2613
|
-
variant: "assistantMessageToolbarButton",
|
|
2614
|
-
"aria-label": title,
|
|
2615
|
-
className: twMerge5(className),
|
|
2616
|
-
...props,
|
|
2617
|
-
children
|
|
2618
|
-
}
|
|
2619
|
-
) }),
|
|
2620
|
-
/* @__PURE__ */ jsx14(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx14("p", { children: title }) })
|
|
2621
|
-
] });
|
|
2622
|
-
};
|
|
2623
|
-
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2624
|
-
const config = useCopilotChatConfiguration();
|
|
2625
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2626
|
-
const [copied, setCopied] = useState7(false);
|
|
2627
|
-
const handleClick = (event) => {
|
|
2628
|
-
setCopied(true);
|
|
2629
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2630
|
-
if (onClick) {
|
|
2631
|
-
onClick(event);
|
|
2632
|
-
}
|
|
2633
|
-
};
|
|
2634
|
-
return /* @__PURE__ */ jsx14(
|
|
2635
|
-
CopilotChatUserMessage2.ToolbarButton,
|
|
2636
|
-
{
|
|
2637
|
-
title: title || labels.userMessageToolbarCopyMessageLabel,
|
|
2638
|
-
onClick: handleClick,
|
|
2639
|
-
className,
|
|
2640
|
-
...props,
|
|
2641
|
-
children: copied ? /* @__PURE__ */ jsx14(Check3, { className: "size-[18px]" }) : /* @__PURE__ */ jsx14(Copy2, { className: "size-[18px]" })
|
|
2642
|
-
}
|
|
2643
|
-
);
|
|
2644
|
-
};
|
|
2645
|
-
CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
|
|
2646
|
-
const config = useCopilotChatConfiguration();
|
|
2647
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2648
|
-
return /* @__PURE__ */ jsx14(
|
|
2649
|
-
CopilotChatUserMessage2.ToolbarButton,
|
|
2650
|
-
{
|
|
2651
|
-
title: title || labels.userMessageToolbarEditMessageLabel,
|
|
2652
|
-
className,
|
|
2653
|
-
...props,
|
|
2654
|
-
children: /* @__PURE__ */ jsx14(Edit, { className: "size-[18px]" })
|
|
2655
|
-
}
|
|
2656
|
-
);
|
|
2657
|
-
};
|
|
2658
|
-
CopilotChatUserMessage2.BranchNavigation = ({
|
|
2659
|
-
className,
|
|
2660
|
-
currentBranch = 0,
|
|
2661
|
-
numberOfBranches = 1,
|
|
2662
|
-
onSwitchToBranch,
|
|
2663
|
-
message,
|
|
2664
|
-
...props
|
|
2665
|
-
}) => {
|
|
2666
|
-
if (!numberOfBranches || numberOfBranches <= 1 || !onSwitchToBranch) {
|
|
2667
|
-
return null;
|
|
2668
|
-
}
|
|
2669
|
-
const canGoPrev = currentBranch > 0;
|
|
2670
|
-
const canGoNext = currentBranch < numberOfBranches - 1;
|
|
2671
|
-
return /* @__PURE__ */ jsxs6("div", { className: twMerge5("flex items-center gap-1", className), ...props, children: [
|
|
2672
|
-
/* @__PURE__ */ jsx14(
|
|
2673
|
-
Button,
|
|
2674
|
-
{
|
|
2675
|
-
type: "button",
|
|
2676
|
-
variant: "assistantMessageToolbarButton",
|
|
2677
|
-
onClick: () => onSwitchToBranch?.({
|
|
2678
|
-
branchIndex: currentBranch - 1,
|
|
2679
|
-
numberOfBranches,
|
|
2680
|
-
message
|
|
2681
|
-
}),
|
|
2682
|
-
disabled: !canGoPrev,
|
|
2683
|
-
className: "h-6 w-6 p-0",
|
|
2684
|
-
children: /* @__PURE__ */ jsx14(ChevronLeft, { className: "size-[20px]" })
|
|
2685
|
-
}
|
|
2686
|
-
),
|
|
2687
|
-
/* @__PURE__ */ jsxs6("span", { className: "text-sm text-muted-foreground px-0 font-medium", children: [
|
|
2688
|
-
currentBranch + 1,
|
|
2689
|
-
"/",
|
|
2690
|
-
numberOfBranches
|
|
2691
|
-
] }),
|
|
2692
|
-
/* @__PURE__ */ jsx14(
|
|
2693
|
-
Button,
|
|
2694
|
-
{
|
|
2695
|
-
type: "button",
|
|
2696
|
-
variant: "assistantMessageToolbarButton",
|
|
2697
|
-
onClick: () => onSwitchToBranch?.({
|
|
2698
|
-
branchIndex: currentBranch + 1,
|
|
2699
|
-
numberOfBranches,
|
|
2700
|
-
message
|
|
2701
|
-
}),
|
|
2702
|
-
disabled: !canGoNext,
|
|
2703
|
-
className: "h-6 w-6 p-0",
|
|
2704
|
-
children: /* @__PURE__ */ jsx14(ChevronRight, { className: "size-[20px]" })
|
|
2705
|
-
}
|
|
2706
|
-
)
|
|
2707
|
-
] });
|
|
2708
|
-
};
|
|
2709
|
-
})(CopilotChatUserMessage || (CopilotChatUserMessage = {}));
|
|
2710
|
-
CopilotChatUserMessage.Container.displayName = "CopilotChatUserMessage.Container";
|
|
2711
|
-
CopilotChatUserMessage.MessageRenderer.displayName = "CopilotChatUserMessage.MessageRenderer";
|
|
2712
|
-
CopilotChatUserMessage.Toolbar.displayName = "CopilotChatUserMessage.Toolbar";
|
|
2713
|
-
CopilotChatUserMessage.ToolbarButton.displayName = "CopilotChatUserMessage.ToolbarButton";
|
|
2714
|
-
CopilotChatUserMessage.CopyButton.displayName = "CopilotChatUserMessage.CopyButton";
|
|
2715
|
-
CopilotChatUserMessage.EditButton.displayName = "CopilotChatUserMessage.EditButton";
|
|
2716
|
-
CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.BranchNavigation";
|
|
2717
|
-
var CopilotChatUserMessage_default = CopilotChatUserMessage;
|
|
2718
|
-
|
|
2719
|
-
// src/components/chat/CopilotChatSuggestionPill.tsx
|
|
2720
|
-
import React9 from "react";
|
|
2721
|
-
import { Loader2 } from "lucide-react";
|
|
2722
|
-
import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2723
|
-
var baseClasses = "group inline-flex h-7 sm:h-8 items-center gap-1 sm:gap-1.5 rounded-full border border-border/60 bg-background px-2.5 sm:px-3 text-[11px] sm:text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
|
|
2724
|
-
var labelClasses = "whitespace-nowrap font-medium leading-none";
|
|
2725
|
-
var CopilotChatSuggestionPill = React9.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
|
|
2726
|
-
const showIcon = !isLoading && icon;
|
|
2727
|
-
return /* @__PURE__ */ jsxs7(
|
|
2728
|
-
"button",
|
|
2729
|
-
{
|
|
2730
|
-
ref,
|
|
2731
|
-
"data-slot": "suggestion-pill",
|
|
2732
|
-
className: cn(baseClasses, className),
|
|
2733
|
-
type: type ?? "button",
|
|
2734
|
-
"aria-busy": isLoading || void 0,
|
|
2735
|
-
disabled: isLoading || props.disabled,
|
|
2736
|
-
...props,
|
|
2737
|
-
children: [
|
|
2738
|
-
isLoading ? /* @__PURE__ */ jsx15("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsx15(Loader2, { className: "h-3.5 sm:h-4 w-3.5 sm:w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ jsx15("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: icon }),
|
|
2739
|
-
/* @__PURE__ */ jsx15("span", { className: labelClasses, children })
|
|
2740
|
-
]
|
|
2741
|
-
}
|
|
2742
|
-
);
|
|
2743
|
-
});
|
|
2744
|
-
CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
|
|
2745
|
-
var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
|
|
2746
|
-
|
|
2747
|
-
// src/components/chat/CopilotChatSuggestionView.tsx
|
|
2748
|
-
import React10 from "react";
|
|
2749
|
-
import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2750
|
-
var DefaultContainer = React10.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
|
|
2751
|
-
return /* @__PURE__ */ jsx16(
|
|
2752
|
-
"div",
|
|
2753
|
-
{
|
|
2754
|
-
ref,
|
|
2755
|
-
className: cn(
|
|
2756
|
-
"flex flex-wrap items-center gap-1.5 sm:gap-2 pl-0 pr-4 sm:px-0 pointer-events-none",
|
|
2757
|
-
className
|
|
2758
|
-
),
|
|
2759
|
-
...props
|
|
2760
|
-
}
|
|
2761
|
-
);
|
|
2762
|
-
});
|
|
2763
|
-
var CopilotChatSuggestionView = React10.forwardRef(function CopilotChatSuggestionView2({
|
|
2764
|
-
suggestions,
|
|
2765
|
-
onSelectSuggestion,
|
|
2766
|
-
loadingIndexes,
|
|
2767
|
-
container,
|
|
2768
|
-
suggestion: suggestionSlot,
|
|
2769
|
-
className,
|
|
2770
|
-
children,
|
|
2771
|
-
...restProps
|
|
2772
|
-
}, ref) {
|
|
2773
|
-
const loadingSet = React10.useMemo(() => {
|
|
2774
|
-
if (!loadingIndexes || loadingIndexes.length === 0) {
|
|
2775
|
-
return /* @__PURE__ */ new Set();
|
|
2776
|
-
}
|
|
2777
|
-
return new Set(loadingIndexes);
|
|
2778
|
-
}, [loadingIndexes]);
|
|
2779
|
-
const ContainerElement = renderSlot(container, DefaultContainer, {
|
|
2780
|
-
ref,
|
|
2781
|
-
className,
|
|
2782
|
-
...restProps
|
|
2783
|
-
});
|
|
2784
|
-
const suggestionElements = suggestions.map((suggestion, index) => {
|
|
2785
|
-
const isLoading = loadingSet.has(index) || suggestion.isLoading === true;
|
|
2786
|
-
const pill = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
|
|
2787
|
-
children: suggestion.title,
|
|
2788
|
-
isLoading,
|
|
2789
|
-
type: "button",
|
|
2790
|
-
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
2791
|
-
});
|
|
2792
|
-
return React10.cloneElement(pill, {
|
|
2793
|
-
key: `${suggestion.title}-${index}`
|
|
2794
|
-
});
|
|
2795
|
-
});
|
|
2796
|
-
const boundContainer = React10.cloneElement(
|
|
2797
|
-
ContainerElement,
|
|
2798
|
-
void 0,
|
|
2799
|
-
suggestionElements
|
|
2800
|
-
);
|
|
2801
|
-
if (typeof children === "function") {
|
|
2802
|
-
const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill_default, {
|
|
2803
|
-
children: suggestions[0]?.title ?? "",
|
|
2804
|
-
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
|
|
2805
|
-
type: "button"
|
|
2806
|
-
});
|
|
2807
|
-
return /* @__PURE__ */ jsx16(Fragment5, { children: children({
|
|
2808
|
-
container: boundContainer,
|
|
2809
|
-
suggestion: sampleSuggestion,
|
|
2810
|
-
suggestions,
|
|
2811
|
-
onSelectSuggestion,
|
|
2812
|
-
loadingIndexes,
|
|
2813
|
-
className,
|
|
2814
|
-
...restProps
|
|
2815
|
-
}) });
|
|
2816
|
-
}
|
|
2817
|
-
if (children) {
|
|
2818
|
-
return /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
2819
|
-
boundContainer,
|
|
2820
|
-
children
|
|
2821
|
-
] });
|
|
2822
|
-
}
|
|
2823
|
-
return boundContainer;
|
|
2824
|
-
});
|
|
2825
|
-
CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
|
|
2826
|
-
var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
|
|
2827
|
-
|
|
2828
|
-
// src/components/chat/CopilotChatMessageView.tsx
|
|
2829
|
-
import { twMerge as twMerge6 } from "tailwind-merge";
|
|
2830
|
-
import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2831
|
-
function CopilotChatMessageView({
|
|
2832
|
-
messages = [],
|
|
2833
|
-
assistantMessage,
|
|
2834
|
-
userMessage,
|
|
2835
|
-
cursor,
|
|
2836
|
-
isRunning = false,
|
|
2837
|
-
children,
|
|
2838
|
-
className,
|
|
2839
|
-
...props
|
|
2840
|
-
}) {
|
|
2841
|
-
const renderCustomMessage = useRenderCustomMessages();
|
|
2842
|
-
const renderActivityMessage = useRenderActivityMessage();
|
|
2843
|
-
const messageElements = messages.flatMap((message) => {
|
|
2844
|
-
const elements = [];
|
|
2845
|
-
if (renderCustomMessage) {
|
|
2846
|
-
elements.push(
|
|
2847
|
-
renderCustomMessage({
|
|
2848
|
-
message,
|
|
2849
|
-
position: "before"
|
|
2850
|
-
})
|
|
2851
|
-
);
|
|
2852
|
-
}
|
|
2853
|
-
if (message.role === "assistant") {
|
|
2854
|
-
elements.push(
|
|
2855
|
-
renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
|
|
2856
|
-
key: message.id,
|
|
2857
|
-
message,
|
|
2858
|
-
messages,
|
|
2859
|
-
isRunning
|
|
2860
|
-
})
|
|
2861
|
-
);
|
|
2862
|
-
} else if (message.role === "user") {
|
|
2863
|
-
elements.push(
|
|
2864
|
-
renderSlot(userMessage, CopilotChatUserMessage_default, {
|
|
2865
|
-
key: message.id,
|
|
2866
|
-
message
|
|
2867
|
-
})
|
|
2868
|
-
);
|
|
2869
|
-
} else if (message.role === "activity") {
|
|
2870
|
-
const renderedActivity = renderActivityMessage(message);
|
|
2871
|
-
if (renderedActivity) {
|
|
2872
|
-
elements.push(renderedActivity);
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
if (renderCustomMessage) {
|
|
2876
|
-
elements.push(
|
|
2877
|
-
renderCustomMessage({
|
|
2878
|
-
message,
|
|
2879
|
-
position: "after"
|
|
2880
|
-
})
|
|
2881
|
-
);
|
|
2882
|
-
}
|
|
2883
|
-
return elements;
|
|
2884
|
-
}).filter(Boolean);
|
|
2885
|
-
if (children) {
|
|
2886
|
-
return children({ messageElements, messages, isRunning });
|
|
2887
|
-
}
|
|
2888
|
-
return /* @__PURE__ */ jsxs9("div", { className: twMerge6("flex flex-col", className), ...props, children: [
|
|
2889
|
-
messageElements,
|
|
2890
|
-
isRunning && renderSlot(cursor, CopilotChatMessageView.Cursor, {})
|
|
2891
|
-
] });
|
|
2892
|
-
}
|
|
2893
|
-
CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
2894
|
-
return /* @__PURE__ */ jsx17(
|
|
2895
|
-
"div",
|
|
2896
|
-
{
|
|
2897
|
-
className: twMerge6("w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1", className),
|
|
2898
|
-
...props
|
|
2899
|
-
}
|
|
2900
|
-
);
|
|
2901
|
-
};
|
|
2902
|
-
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
2903
|
-
|
|
2904
|
-
// src/components/chat/CopilotChatView.tsx
|
|
2905
|
-
import React11, { useRef as useRef7, useState as useState9, useEffect as useEffect13 } from "react";
|
|
2906
|
-
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
2907
|
-
import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
2908
|
-
import { ChevronDown } from "lucide-react";
|
|
2909
|
-
|
|
2910
|
-
// src/hooks/use-keyboard-height.tsx
|
|
2911
|
-
import { useState as useState8, useEffect as useEffect12 } from "react";
|
|
2912
|
-
function useKeyboardHeight() {
|
|
2913
|
-
const [keyboardState, setKeyboardState] = useState8({
|
|
2914
|
-
isKeyboardOpen: false,
|
|
2915
|
-
keyboardHeight: 0,
|
|
2916
|
-
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
2917
|
-
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
2918
|
-
});
|
|
2919
|
-
useEffect12(() => {
|
|
2920
|
-
if (typeof window === "undefined") {
|
|
2921
|
-
return;
|
|
2922
|
-
}
|
|
2923
|
-
const visualViewport = window.visualViewport;
|
|
2924
|
-
if (!visualViewport) {
|
|
2925
|
-
return;
|
|
2926
|
-
}
|
|
2927
|
-
const updateKeyboardState = () => {
|
|
2928
|
-
const layoutHeight = window.innerHeight;
|
|
2929
|
-
const visualHeight = visualViewport.height;
|
|
2930
|
-
const keyboardHeight = Math.max(0, layoutHeight - visualHeight);
|
|
2931
|
-
const isKeyboardOpen = keyboardHeight > 150;
|
|
2932
|
-
setKeyboardState({
|
|
2933
|
-
isKeyboardOpen,
|
|
2934
|
-
keyboardHeight,
|
|
2935
|
-
availableHeight: visualHeight,
|
|
2936
|
-
viewportHeight: layoutHeight
|
|
2937
|
-
});
|
|
2938
|
-
};
|
|
2939
|
-
updateKeyboardState();
|
|
2940
|
-
visualViewport.addEventListener("resize", updateKeyboardState);
|
|
2941
|
-
visualViewport.addEventListener("scroll", updateKeyboardState);
|
|
2942
|
-
return () => {
|
|
2943
|
-
visualViewport.removeEventListener("resize", updateKeyboardState);
|
|
2944
|
-
visualViewport.removeEventListener("scroll", updateKeyboardState);
|
|
2945
|
-
};
|
|
2946
|
-
}, []);
|
|
2947
|
-
return keyboardState;
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
// src/components/chat/CopilotChatView.tsx
|
|
2951
|
-
import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2952
|
-
function CopilotChatView({
|
|
2953
|
-
messageView,
|
|
2954
|
-
input,
|
|
2955
|
-
scrollView,
|
|
2956
|
-
scrollToBottomButton,
|
|
2957
|
-
feather,
|
|
2958
|
-
inputContainer,
|
|
2959
|
-
disclaimer,
|
|
2960
|
-
suggestionView,
|
|
2961
|
-
messages = [],
|
|
2962
|
-
autoScroll = true,
|
|
2963
|
-
inputProps,
|
|
2964
|
-
isRunning = false,
|
|
2965
|
-
suggestions,
|
|
2966
|
-
suggestionLoadingIndexes,
|
|
2967
|
-
onSelectSuggestion,
|
|
2968
|
-
children,
|
|
2969
|
-
className,
|
|
2970
|
-
...props
|
|
2971
|
-
}) {
|
|
2972
|
-
const inputContainerRef = useRef7(null);
|
|
2973
|
-
const [inputContainerHeight, setInputContainerHeight] = useState9(0);
|
|
2974
|
-
const [isResizing, setIsResizing] = useState9(false);
|
|
2975
|
-
const resizeTimeoutRef = useRef7(null);
|
|
2976
|
-
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
2977
|
-
useEffect13(() => {
|
|
2978
|
-
const element = inputContainerRef.current;
|
|
2979
|
-
if (!element) return;
|
|
2980
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
|
2981
|
-
for (const entry of entries) {
|
|
2982
|
-
const newHeight = entry.contentRect.height;
|
|
2983
|
-
setInputContainerHeight((prevHeight) => {
|
|
2984
|
-
if (newHeight !== prevHeight) {
|
|
2985
|
-
setIsResizing(true);
|
|
2986
|
-
if (resizeTimeoutRef.current) {
|
|
2987
|
-
clearTimeout(resizeTimeoutRef.current);
|
|
2988
|
-
}
|
|
2989
|
-
resizeTimeoutRef.current = setTimeout(() => {
|
|
2990
|
-
setIsResizing(false);
|
|
2991
|
-
}, 250);
|
|
2992
|
-
return newHeight;
|
|
2993
|
-
}
|
|
2994
|
-
return prevHeight;
|
|
2995
|
-
});
|
|
2996
|
-
}
|
|
2997
|
-
});
|
|
2998
|
-
resizeObserver.observe(element);
|
|
2999
|
-
setInputContainerHeight(element.offsetHeight);
|
|
3000
|
-
return () => {
|
|
3001
|
-
resizeObserver.disconnect();
|
|
3002
|
-
if (resizeTimeoutRef.current) {
|
|
3003
|
-
clearTimeout(resizeTimeoutRef.current);
|
|
3004
|
-
}
|
|
3005
|
-
};
|
|
3006
|
-
}, []);
|
|
3007
|
-
const BoundMessageView = renderSlot(messageView, CopilotChatMessageView_default, {
|
|
3008
|
-
messages,
|
|
3009
|
-
isRunning
|
|
3010
|
-
});
|
|
3011
|
-
const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
|
|
3012
|
-
const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
|
|
3013
|
-
const BoundSuggestionView = hasSuggestions ? renderSlot(
|
|
3014
|
-
suggestionView,
|
|
3015
|
-
CopilotChatSuggestionView_default,
|
|
3016
|
-
{
|
|
3017
|
-
suggestions,
|
|
3018
|
-
loadingIndexes: suggestionLoadingIndexes,
|
|
3019
|
-
onSelectSuggestion,
|
|
3020
|
-
className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
|
|
3021
|
-
}
|
|
3022
|
-
) : null;
|
|
3023
|
-
const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
|
|
3024
|
-
const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
|
|
3025
|
-
autoScroll,
|
|
3026
|
-
scrollToBottomButton,
|
|
3027
|
-
inputContainerHeight,
|
|
3028
|
-
isResizing,
|
|
3029
|
-
children: /* @__PURE__ */ jsx18("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ jsxs10("div", { className: "max-w-3xl mx-auto", children: [
|
|
3030
|
-
BoundMessageView,
|
|
3031
|
-
hasSuggestions ? /* @__PURE__ */ jsx18("div", { className: "pl-0 pr-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
|
|
3032
|
-
] }) })
|
|
3033
|
-
});
|
|
3034
|
-
const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
|
|
3035
|
-
const BoundDisclaimer = renderSlot(disclaimer, CopilotChatView.Disclaimer, {});
|
|
3036
|
-
const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
|
|
3037
|
-
ref: inputContainerRef,
|
|
3038
|
-
keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
|
|
3039
|
-
children: /* @__PURE__ */ jsxs10(Fragment6, { children: [
|
|
3040
|
-
/* @__PURE__ */ jsx18("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6 pointer-events-auto", children: BoundInput }),
|
|
3041
|
-
BoundDisclaimer
|
|
3042
|
-
] })
|
|
3043
|
-
});
|
|
3044
|
-
if (children) {
|
|
3045
|
-
return children({
|
|
3046
|
-
messageView: BoundMessageView,
|
|
3047
|
-
input: BoundInput,
|
|
3048
|
-
scrollView: BoundScrollView,
|
|
3049
|
-
scrollToBottomButton: BoundScrollToBottomButton,
|
|
3050
|
-
feather: BoundFeather,
|
|
3051
|
-
inputContainer: BoundInputContainer,
|
|
3052
|
-
disclaimer: BoundDisclaimer,
|
|
3053
|
-
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ jsx18(Fragment6, {})
|
|
3054
|
-
});
|
|
3055
|
-
}
|
|
3056
|
-
return /* @__PURE__ */ jsxs10("div", { className: twMerge7("relative h-full", className), ...props, children: [
|
|
3057
|
-
BoundScrollView,
|
|
3058
|
-
BoundFeather,
|
|
3059
|
-
BoundInputContainer
|
|
3060
|
-
] });
|
|
3061
|
-
}
|
|
3062
|
-
((CopilotChatView2) => {
|
|
3063
|
-
const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
|
|
3064
|
-
const { isAtBottom, scrollToBottom } = useStickToBottomContext();
|
|
3065
|
-
return /* @__PURE__ */ jsxs10(Fragment6, { children: [
|
|
3066
|
-
/* @__PURE__ */ jsx18(StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx18("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) }),
|
|
3067
|
-
!isAtBottom && !isResizing && /* @__PURE__ */ jsx18(
|
|
3068
|
-
"div",
|
|
3069
|
-
{
|
|
3070
|
-
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
3071
|
-
style: {
|
|
3072
|
-
bottom: `${inputContainerHeight + 16}px`
|
|
3073
|
-
},
|
|
3074
|
-
children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
|
|
3075
|
-
onClick: () => scrollToBottom()
|
|
3076
|
-
})
|
|
3077
|
-
}
|
|
3078
|
-
)
|
|
3079
|
-
] });
|
|
3080
|
-
};
|
|
3081
|
-
CopilotChatView2.ScrollView = ({
|
|
3082
|
-
children,
|
|
3083
|
-
autoScroll = true,
|
|
3084
|
-
scrollToBottomButton,
|
|
3085
|
-
inputContainerHeight = 0,
|
|
3086
|
-
isResizing = false,
|
|
3087
|
-
className,
|
|
3088
|
-
...props
|
|
3089
|
-
}) => {
|
|
3090
|
-
const [hasMounted, setHasMounted] = useState9(false);
|
|
3091
|
-
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
|
|
3092
|
-
const [showScrollButton, setShowScrollButton] = useState9(false);
|
|
3093
|
-
useEffect13(() => {
|
|
3094
|
-
setHasMounted(true);
|
|
3095
|
-
}, []);
|
|
3096
|
-
useEffect13(() => {
|
|
3097
|
-
if (autoScroll) return;
|
|
3098
|
-
const scrollElement = scrollRef.current;
|
|
3099
|
-
if (!scrollElement) return;
|
|
3100
|
-
const checkScroll = () => {
|
|
3101
|
-
const atBottom = scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight < 10;
|
|
3102
|
-
setShowScrollButton(!atBottom);
|
|
3103
|
-
};
|
|
3104
|
-
checkScroll();
|
|
3105
|
-
scrollElement.addEventListener("scroll", checkScroll);
|
|
3106
|
-
const resizeObserver = new ResizeObserver(checkScroll);
|
|
3107
|
-
resizeObserver.observe(scrollElement);
|
|
3108
|
-
return () => {
|
|
3109
|
-
scrollElement.removeEventListener("scroll", checkScroll);
|
|
3110
|
-
resizeObserver.disconnect();
|
|
3111
|
-
};
|
|
3112
|
-
}, [scrollRef, autoScroll]);
|
|
3113
|
-
if (!hasMounted) {
|
|
3114
|
-
return /* @__PURE__ */ jsx18("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx18("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) });
|
|
3115
|
-
}
|
|
3116
|
-
if (!autoScroll) {
|
|
3117
|
-
return /* @__PURE__ */ jsxs10(
|
|
3118
|
-
"div",
|
|
3119
|
-
{
|
|
3120
|
-
ref: scrollRef,
|
|
3121
|
-
className: cn(
|
|
3122
|
-
"h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden relative",
|
|
3123
|
-
className
|
|
3124
|
-
),
|
|
3125
|
-
...props,
|
|
3126
|
-
children: [
|
|
3127
|
-
/* @__PURE__ */ jsx18("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }),
|
|
3128
|
-
showScrollButton && !isResizing && /* @__PURE__ */ jsx18(
|
|
3129
|
-
"div",
|
|
3130
|
-
{
|
|
3131
|
-
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
3132
|
-
style: {
|
|
3133
|
-
bottom: `${inputContainerHeight + 16}px`
|
|
3134
|
-
},
|
|
3135
|
-
children: renderSlot(scrollToBottomButton, CopilotChatView2.ScrollToBottomButton, {
|
|
3136
|
-
onClick: () => scrollToBottom()
|
|
3137
|
-
})
|
|
3138
|
-
}
|
|
3139
|
-
)
|
|
3140
|
-
]
|
|
3141
|
-
}
|
|
3142
|
-
);
|
|
3143
|
-
}
|
|
3144
|
-
return /* @__PURE__ */ jsx18(
|
|
3145
|
-
StickToBottom,
|
|
3146
|
-
{
|
|
3147
|
-
className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
|
|
3148
|
-
resize: "smooth",
|
|
3149
|
-
initial: "smooth",
|
|
3150
|
-
...props,
|
|
3151
|
-
children: /* @__PURE__ */ jsx18(
|
|
3152
|
-
ScrollContent,
|
|
3153
|
-
{
|
|
3154
|
-
scrollToBottomButton,
|
|
3155
|
-
inputContainerHeight,
|
|
3156
|
-
isResizing,
|
|
3157
|
-
children
|
|
3158
|
-
}
|
|
3159
|
-
)
|
|
3160
|
-
}
|
|
3161
|
-
);
|
|
3162
|
-
};
|
|
3163
|
-
CopilotChatView2.ScrollToBottomButton = ({
|
|
3164
|
-
className,
|
|
3165
|
-
...props
|
|
3166
|
-
}) => /* @__PURE__ */ jsx18(
|
|
3167
|
-
Button,
|
|
3168
|
-
{
|
|
3169
|
-
variant: "outline",
|
|
3170
|
-
size: "sm",
|
|
3171
|
-
className: twMerge7(
|
|
3172
|
-
"rounded-full w-10 h-10 p-0 pointer-events-auto",
|
|
3173
|
-
"bg-white dark:bg-gray-900",
|
|
3174
|
-
"shadow-lg border border-gray-200 dark:border-gray-700",
|
|
3175
|
-
"hover:bg-gray-50 dark:hover:bg-gray-800",
|
|
3176
|
-
"flex items-center justify-center cursor-pointer",
|
|
3177
|
-
className
|
|
3178
|
-
),
|
|
3179
|
-
...props,
|
|
3180
|
-
children: /* @__PURE__ */ jsx18(ChevronDown, { className: "w-4 h-4 text-gray-600 dark:text-white" })
|
|
3181
|
-
}
|
|
3182
|
-
);
|
|
3183
|
-
CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */ jsx18(
|
|
3184
|
-
"div",
|
|
3185
|
-
{
|
|
3186
|
-
className: cn(
|
|
3187
|
-
"absolute bottom-0 left-0 right-4 h-24 pointer-events-none z-10 bg-gradient-to-t",
|
|
3188
|
-
"from-white via-white to-transparent",
|
|
3189
|
-
"dark:from-[rgb(33,33,33)] dark:via-[rgb(33,33,33)]",
|
|
3190
|
-
className
|
|
3191
|
-
),
|
|
3192
|
-
style,
|
|
3193
|
-
...props
|
|
3194
|
-
}
|
|
3195
|
-
);
|
|
3196
|
-
CopilotChatView2.InputContainer = React11.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ jsx18(
|
|
3197
|
-
"div",
|
|
3198
|
-
{
|
|
3199
|
-
ref,
|
|
3200
|
-
className: cn("absolute bottom-0 left-0 right-0 z-20 pointer-events-none", className),
|
|
3201
|
-
style: {
|
|
3202
|
-
// Adjust position when keyboard is open to keep input visible
|
|
3203
|
-
transform: keyboardHeight > 0 ? `translateY(-${keyboardHeight}px)` : void 0,
|
|
3204
|
-
transition: "transform 0.2s ease-out"
|
|
3205
|
-
},
|
|
3206
|
-
...props,
|
|
3207
|
-
children
|
|
3208
|
-
}
|
|
3209
|
-
));
|
|
3210
|
-
CopilotChatView2.InputContainer.displayName = "CopilotChatView.InputContainer";
|
|
3211
|
-
CopilotChatView2.Disclaimer = ({ className, ...props }) => {
|
|
3212
|
-
const config = useCopilotChatConfiguration();
|
|
3213
|
-
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
3214
|
-
return /* @__PURE__ */ jsx18(
|
|
3215
|
-
"div",
|
|
3216
|
-
{
|
|
3217
|
-
className: cn("text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto", className),
|
|
3218
|
-
...props,
|
|
3219
|
-
children: labels.chatDisclaimerText
|
|
3220
|
-
}
|
|
3221
|
-
);
|
|
3222
|
-
};
|
|
3223
|
-
})(CopilotChatView || (CopilotChatView = {}));
|
|
3224
|
-
var CopilotChatView_default = CopilotChatView;
|
|
3225
|
-
|
|
3226
|
-
// src/components/chat/CopilotChat.tsx
|
|
3227
|
-
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
|
|
3228
|
-
import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo8 } from "react";
|
|
3229
|
-
import { merge } from "ts-deepmerge";
|
|
3230
|
-
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
3231
|
-
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
3232
|
-
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
3233
|
-
const existingConfig = useCopilotChatConfiguration();
|
|
3234
|
-
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID7;
|
|
3235
|
-
const resolvedThreadId = useMemo8(
|
|
3236
|
-
() => threadId ?? existingConfig?.threadId ?? randomUUID2(),
|
|
3237
|
-
[threadId, existingConfig?.threadId]
|
|
3238
|
-
);
|
|
3239
|
-
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
3240
|
-
const { copilotkit } = useCopilotKit();
|
|
3241
|
-
const { suggestions: autoSuggestions } = useSuggestions({ agentId: resolvedAgentId });
|
|
3242
|
-
const {
|
|
3243
|
-
inputProps: providedInputProps,
|
|
3244
|
-
messageView: providedMessageView,
|
|
3245
|
-
suggestionView: providedSuggestionView,
|
|
3246
|
-
...restProps
|
|
3247
|
-
} = props;
|
|
3248
|
-
useEffect14(() => {
|
|
3249
|
-
const connect = async (agent2) => {
|
|
3250
|
-
try {
|
|
3251
|
-
await copilotkit.connectAgent({ agent: agent2 });
|
|
3252
|
-
} catch (error) {
|
|
3253
|
-
if (error instanceof AGUIConnectNotImplementedError) {
|
|
3254
|
-
} else {
|
|
3255
|
-
throw error;
|
|
3256
|
-
}
|
|
3257
|
-
}
|
|
3258
|
-
};
|
|
3259
|
-
if (agent) {
|
|
3260
|
-
agent.threadId = resolvedThreadId;
|
|
3261
|
-
connect(agent);
|
|
3262
|
-
}
|
|
3263
|
-
return () => {
|
|
3264
|
-
};
|
|
3265
|
-
}, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
|
|
3266
|
-
const onSubmitInput = useCallback7(
|
|
3267
|
-
async (value) => {
|
|
3268
|
-
agent?.addMessage({
|
|
3269
|
-
id: randomUUID2(),
|
|
3270
|
-
role: "user",
|
|
3271
|
-
content: value
|
|
3272
|
-
});
|
|
3273
|
-
if (agent) {
|
|
3274
|
-
try {
|
|
3275
|
-
await copilotkit.runAgent({ agent });
|
|
3276
|
-
} catch (error) {
|
|
3277
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
},
|
|
3281
|
-
[agent, copilotkit]
|
|
3282
|
-
);
|
|
3283
|
-
const handleSelectSuggestion = useCallback7(
|
|
3284
|
-
async (suggestion) => {
|
|
3285
|
-
if (!agent) {
|
|
3286
|
-
return;
|
|
3287
|
-
}
|
|
3288
|
-
agent.addMessage({
|
|
3289
|
-
id: randomUUID2(),
|
|
3290
|
-
role: "user",
|
|
3291
|
-
content: suggestion.message
|
|
3292
|
-
});
|
|
3293
|
-
try {
|
|
3294
|
-
await copilotkit.runAgent({ agent });
|
|
3295
|
-
} catch (error) {
|
|
3296
|
-
console.error("CopilotChat: runAgent failed after selecting suggestion", error);
|
|
3297
|
-
}
|
|
3298
|
-
},
|
|
3299
|
-
[agent, copilotkit]
|
|
3300
|
-
);
|
|
3301
|
-
const stopCurrentRun = useCallback7(() => {
|
|
3302
|
-
if (!agent) {
|
|
3303
|
-
return;
|
|
3304
|
-
}
|
|
3305
|
-
try {
|
|
3306
|
-
copilotkit.stopAgent({ agent });
|
|
3307
|
-
} catch (error) {
|
|
3308
|
-
console.error("CopilotChat: stopAgent failed", error);
|
|
3309
|
-
try {
|
|
3310
|
-
agent.abortRun();
|
|
3311
|
-
} catch (abortError) {
|
|
3312
|
-
console.error("CopilotChat: abortRun fallback failed", abortError);
|
|
3313
|
-
}
|
|
3314
|
-
}
|
|
3315
|
-
}, [agent, copilotkit]);
|
|
3316
|
-
const mergedProps = merge(
|
|
3317
|
-
{
|
|
3318
|
-
isRunning: agent?.isRunning ?? false,
|
|
3319
|
-
suggestions: autoSuggestions,
|
|
3320
|
-
onSelectSuggestion: handleSelectSuggestion,
|
|
3321
|
-
suggestionView: providedSuggestionView
|
|
3322
|
-
},
|
|
3323
|
-
{
|
|
3324
|
-
...restProps,
|
|
3325
|
-
...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
|
|
3326
|
-
}
|
|
3327
|
-
);
|
|
3328
|
-
const providedStopHandler = providedInputProps?.onStop;
|
|
3329
|
-
const hasMessages = (agent?.messages?.length ?? 0) > 0;
|
|
3330
|
-
const shouldAllowStop = (agent?.isRunning ?? false) && hasMessages;
|
|
3331
|
-
const effectiveStopHandler = shouldAllowStop ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
3332
|
-
const finalInputProps = {
|
|
3333
|
-
...providedInputProps,
|
|
3334
|
-
onSubmitMessage: onSubmitInput,
|
|
3335
|
-
onStop: effectiveStopHandler,
|
|
3336
|
-
isRunning: agent?.isRunning ?? false
|
|
3337
|
-
};
|
|
3338
|
-
finalInputProps.mode = agent?.isRunning ? "processing" : finalInputProps.mode ?? "input";
|
|
3339
|
-
const finalProps = merge(mergedProps, {
|
|
3340
|
-
messages: agent?.messages ?? [],
|
|
3341
|
-
inputProps: finalInputProps
|
|
3342
|
-
});
|
|
3343
|
-
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
3344
|
-
return /* @__PURE__ */ jsx19(
|
|
3345
|
-
CopilotChatConfigurationProvider,
|
|
3346
|
-
{
|
|
3347
|
-
agentId: resolvedAgentId,
|
|
3348
|
-
threadId: resolvedThreadId,
|
|
3349
|
-
labels,
|
|
3350
|
-
isModalDefaultOpen,
|
|
3351
|
-
children: RenderedChatView
|
|
3352
|
-
}
|
|
3353
|
-
);
|
|
3354
|
-
}
|
|
3355
|
-
((CopilotChat2) => {
|
|
3356
|
-
CopilotChat2.View = CopilotChatView;
|
|
3357
|
-
})(CopilotChat || (CopilotChat = {}));
|
|
3358
|
-
|
|
3359
|
-
// src/components/chat/CopilotChatToggleButton.tsx
|
|
3360
|
-
import React12, { useState as useState10 } from "react";
|
|
3361
|
-
import { MessageCircle, X as X2 } from "lucide-react";
|
|
3362
|
-
import { jsx as jsx20, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
3363
|
-
var DefaultOpenIcon = ({
|
|
3364
|
-
className,
|
|
3365
|
-
...props
|
|
3366
|
-
}) => /* @__PURE__ */ jsx20(MessageCircle, { className: cn("h-6 w-6", className), strokeWidth: 1.75, fill: "currentColor", ...props });
|
|
3367
|
-
var DefaultCloseIcon = ({
|
|
3368
|
-
className,
|
|
3369
|
-
...props
|
|
3370
|
-
}) => /* @__PURE__ */ jsx20(X2, { className: cn("h-6 w-6", className), strokeWidth: 1.75, ...props });
|
|
3371
|
-
DefaultOpenIcon.displayName = "CopilotChatToggleButton.OpenIcon";
|
|
3372
|
-
DefaultCloseIcon.displayName = "CopilotChatToggleButton.CloseIcon";
|
|
3373
|
-
var ICON_TRANSITION_STYLE = Object.freeze({
|
|
3374
|
-
transition: "opacity 120ms ease-out, transform 260ms cubic-bezier(0.22, 1, 0.36, 1)"
|
|
3375
|
-
});
|
|
3376
|
-
var ICON_WRAPPER_BASE = "pointer-events-none absolute inset-0 flex items-center justify-center will-change-transform";
|
|
3377
|
-
var BUTTON_BASE_CLASSES = cn(
|
|
3378
|
-
"fixed bottom-6 right-6 z-[1100] flex h-14 w-14 items-center justify-center",
|
|
3379
|
-
"rounded-full border border-primary bg-primary text-primary-foreground",
|
|
3380
|
-
"shadow-sm transition-all duration-200 ease-out",
|
|
3381
|
-
"hover:scale-[1.04] hover:shadow-md",
|
|
3382
|
-
"cursor-pointer",
|
|
3383
|
-
"active:scale-[0.96]",
|
|
3384
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
3385
|
-
"disabled:pointer-events-none disabled:opacity-60"
|
|
3386
|
-
);
|
|
3387
|
-
var CopilotChatToggleButton = React12.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
3388
|
-
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
3389
|
-
const configuration = useCopilotChatConfiguration();
|
|
3390
|
-
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3391
|
-
const [fallbackOpen, setFallbackOpen] = useState10(false);
|
|
3392
|
-
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
3393
|
-
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
3394
|
-
const handleClick = (event) => {
|
|
3395
|
-
if (disabled) {
|
|
3396
|
-
return;
|
|
3397
|
-
}
|
|
3398
|
-
if (onClick) {
|
|
3399
|
-
onClick(event);
|
|
3400
|
-
}
|
|
3401
|
-
if (event.defaultPrevented) {
|
|
3402
|
-
return;
|
|
3403
|
-
}
|
|
3404
|
-
const nextOpen = !isOpen;
|
|
3405
|
-
setModalOpen(nextOpen);
|
|
3406
|
-
};
|
|
3407
|
-
const renderedOpenIcon = renderSlot(
|
|
3408
|
-
openIcon,
|
|
3409
|
-
DefaultOpenIcon,
|
|
3410
|
-
{
|
|
3411
|
-
className: "h-6 w-6",
|
|
3412
|
-
"aria-hidden": true,
|
|
3413
|
-
focusable: false
|
|
3414
|
-
}
|
|
3415
|
-
);
|
|
3416
|
-
const renderedCloseIcon = renderSlot(
|
|
3417
|
-
closeIcon,
|
|
3418
|
-
DefaultCloseIcon,
|
|
3419
|
-
{
|
|
3420
|
-
className: "h-6 w-6",
|
|
3421
|
-
"aria-hidden": true,
|
|
3422
|
-
focusable: false
|
|
3423
|
-
}
|
|
3424
|
-
);
|
|
3425
|
-
const openIconElement = /* @__PURE__ */ jsx20(
|
|
3426
|
-
"span",
|
|
3427
|
-
{
|
|
3428
|
-
"aria-hidden": "true",
|
|
3429
|
-
"data-slot": "chat-toggle-button-open-icon",
|
|
3430
|
-
className: ICON_WRAPPER_BASE,
|
|
3431
|
-
style: {
|
|
3432
|
-
...ICON_TRANSITION_STYLE,
|
|
3433
|
-
opacity: isOpen ? 0 : 1,
|
|
3434
|
-
transform: `scale(${isOpen ? 0.75 : 1}) rotate(${isOpen ? 90 : 0}deg)`
|
|
3435
|
-
},
|
|
3436
|
-
children: renderedOpenIcon
|
|
3437
|
-
}
|
|
3438
|
-
);
|
|
3439
|
-
const closeIconElement = /* @__PURE__ */ jsx20(
|
|
3440
|
-
"span",
|
|
3441
|
-
{
|
|
3442
|
-
"aria-hidden": "true",
|
|
3443
|
-
"data-slot": "chat-toggle-button-close-icon",
|
|
3444
|
-
className: ICON_WRAPPER_BASE,
|
|
3445
|
-
style: {
|
|
3446
|
-
...ICON_TRANSITION_STYLE,
|
|
3447
|
-
opacity: isOpen ? 1 : 0,
|
|
3448
|
-
transform: `scale(${isOpen ? 1 : 0.75}) rotate(${isOpen ? 0 : -90}deg)`
|
|
3449
|
-
},
|
|
3450
|
-
children: renderedCloseIcon
|
|
3451
|
-
}
|
|
3452
|
-
);
|
|
3453
|
-
return /* @__PURE__ */ jsxs11(
|
|
3454
|
-
"button",
|
|
3455
|
-
{
|
|
3456
|
-
ref,
|
|
3457
|
-
type: type ?? "button",
|
|
3458
|
-
"data-slot": "chat-toggle-button",
|
|
3459
|
-
"data-state": isOpen ? "open" : "closed",
|
|
3460
|
-
className: cn(BUTTON_BASE_CLASSES, className),
|
|
3461
|
-
"aria-label": isOpen ? labels.chatToggleCloseLabel : labels.chatToggleOpenLabel,
|
|
3462
|
-
"aria-pressed": isOpen,
|
|
3463
|
-
disabled,
|
|
3464
|
-
onClick: handleClick,
|
|
3465
|
-
...restProps,
|
|
3466
|
-
children: [
|
|
3467
|
-
openIconElement,
|
|
3468
|
-
closeIconElement
|
|
3469
|
-
]
|
|
3470
|
-
}
|
|
3471
|
-
);
|
|
3472
|
-
});
|
|
3473
|
-
CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
3474
|
-
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3475
|
-
|
|
3476
|
-
// src/components/chat/CopilotSidebarView.tsx
|
|
3477
|
-
import { useEffect as useEffect15, useRef as useRef8, useState as useState11 } from "react";
|
|
3478
|
-
|
|
3479
|
-
// src/components/chat/CopilotModalHeader.tsx
|
|
3480
|
-
import { useCallback as useCallback8 } from "react";
|
|
3481
|
-
import { X as X3 } from "lucide-react";
|
|
3482
|
-
import { jsx as jsx21, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
3483
|
-
function CopilotModalHeader({
|
|
3484
|
-
title,
|
|
3485
|
-
titleContent,
|
|
3486
|
-
closeButton,
|
|
3487
|
-
children,
|
|
3488
|
-
className,
|
|
3489
|
-
...rest
|
|
3490
|
-
}) {
|
|
3491
|
-
const configuration = useCopilotChatConfiguration();
|
|
3492
|
-
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
3493
|
-
const resolvedTitle = title ?? fallbackTitle;
|
|
3494
|
-
const handleClose = useCallback8(() => {
|
|
3495
|
-
configuration?.setModalOpen(false);
|
|
3496
|
-
}, [configuration]);
|
|
3497
|
-
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
|
|
3498
|
-
children: resolvedTitle
|
|
3499
|
-
});
|
|
3500
|
-
const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, {
|
|
3501
|
-
onClick: handleClose
|
|
3502
|
-
});
|
|
3503
|
-
if (children) {
|
|
3504
|
-
return children({
|
|
3505
|
-
titleContent: BoundTitle,
|
|
3506
|
-
closeButton: BoundCloseButton,
|
|
3507
|
-
title: resolvedTitle,
|
|
3508
|
-
...rest
|
|
3509
|
-
});
|
|
3510
|
-
}
|
|
3511
|
-
return /* @__PURE__ */ jsx21(
|
|
3512
|
-
"header",
|
|
3513
|
-
{
|
|
3514
|
-
"data-slot": "copilot-modal-header",
|
|
3515
|
-
className: cn(
|
|
3516
|
-
"flex items-center justify-between border-b border-border px-4 py-4",
|
|
3517
|
-
"bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",
|
|
3518
|
-
className
|
|
3519
|
-
),
|
|
3520
|
-
...rest,
|
|
3521
|
-
children: /* @__PURE__ */ jsxs12("div", { className: "flex w-full items-center gap-2", children: [
|
|
3522
|
-
/* @__PURE__ */ jsx21("div", { className: "flex-1", "aria-hidden": "true" }),
|
|
3523
|
-
/* @__PURE__ */ jsx21("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
|
|
3524
|
-
/* @__PURE__ */ jsx21("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
|
|
3525
|
-
] })
|
|
3526
|
-
}
|
|
3527
|
-
);
|
|
3528
|
-
}
|
|
3529
|
-
CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
3530
|
-
((CopilotModalHeader2) => {
|
|
3531
|
-
CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */ jsx21(
|
|
3532
|
-
"div",
|
|
3533
|
-
{
|
|
3534
|
-
className: cn(
|
|
3535
|
-
"w-full text-base font-medium leading-none tracking-tight text-foreground",
|
|
3536
|
-
className
|
|
3537
|
-
),
|
|
3538
|
-
...props,
|
|
3539
|
-
children
|
|
3540
|
-
}
|
|
3541
|
-
);
|
|
3542
|
-
CopilotModalHeader2.CloseButton = ({
|
|
3543
|
-
className,
|
|
3544
|
-
...props
|
|
3545
|
-
}) => /* @__PURE__ */ jsx21(
|
|
3546
|
-
"button",
|
|
3547
|
-
{
|
|
3548
|
-
type: "button",
|
|
3549
|
-
className: cn(
|
|
3550
|
-
"inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition cursor-pointer",
|
|
3551
|
-
"hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
3552
|
-
className
|
|
3553
|
-
),
|
|
3554
|
-
"aria-label": "Close",
|
|
3555
|
-
...props,
|
|
3556
|
-
children: /* @__PURE__ */ jsx21(X3, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
3557
|
-
}
|
|
3558
|
-
);
|
|
3559
|
-
})(CopilotModalHeader || (CopilotModalHeader = {}));
|
|
3560
|
-
CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
|
|
3561
|
-
CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
|
|
3562
|
-
|
|
3563
|
-
// src/components/chat/CopilotSidebarView.tsx
|
|
3564
|
-
import { Fragment as Fragment7, jsx as jsx22, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
3565
|
-
var DEFAULT_SIDEBAR_WIDTH = 480;
|
|
3566
|
-
var SIDEBAR_TRANSITION_MS = 260;
|
|
3567
|
-
function CopilotSidebarView({ header, width, ...props }) {
|
|
3568
|
-
const configuration = useCopilotChatConfiguration();
|
|
3569
|
-
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
3570
|
-
const sidebarRef = useRef8(null);
|
|
3571
|
-
const [sidebarWidth, setSidebarWidth] = useState11(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
3572
|
-
const widthToCss = (w) => {
|
|
3573
|
-
return typeof w === "number" ? `${w}px` : w;
|
|
3574
|
-
};
|
|
3575
|
-
const widthToMargin = (w) => {
|
|
3576
|
-
if (typeof w === "number") {
|
|
3577
|
-
return `${w}px`;
|
|
3578
|
-
}
|
|
3579
|
-
return w;
|
|
3580
|
-
};
|
|
3581
|
-
useEffect15(() => {
|
|
3582
|
-
if (width !== void 0) {
|
|
3583
|
-
return;
|
|
3584
|
-
}
|
|
3585
|
-
if (typeof window === "undefined") {
|
|
3586
|
-
return;
|
|
3587
|
-
}
|
|
3588
|
-
const element = sidebarRef.current;
|
|
3589
|
-
if (!element) {
|
|
3590
|
-
return;
|
|
3591
|
-
}
|
|
3592
|
-
const updateWidth = () => {
|
|
3593
|
-
const rect = element.getBoundingClientRect();
|
|
3594
|
-
if (rect.width > 0) {
|
|
3595
|
-
setSidebarWidth(rect.width);
|
|
3596
|
-
}
|
|
3597
|
-
};
|
|
3598
|
-
updateWidth();
|
|
3599
|
-
if (typeof ResizeObserver !== "undefined") {
|
|
3600
|
-
const observer = new ResizeObserver(() => updateWidth());
|
|
3601
|
-
observer.observe(element);
|
|
3602
|
-
return () => observer.disconnect();
|
|
3603
|
-
}
|
|
3604
|
-
window.addEventListener("resize", updateWidth);
|
|
3605
|
-
return () => window.removeEventListener("resize", updateWidth);
|
|
3606
|
-
}, [width]);
|
|
3607
|
-
const headerElement = renderSlot(header, CopilotModalHeader, {});
|
|
3608
|
-
return /* @__PURE__ */ jsxs13(Fragment7, { children: [
|
|
3609
|
-
isSidebarOpen && /* @__PURE__ */ jsx22(
|
|
3610
|
-
"style",
|
|
3611
|
-
{
|
|
3612
|
-
dangerouslySetInnerHTML: {
|
|
3613
|
-
__html: `
|
|
3614
|
-
@media (min-width: 768px) {
|
|
3615
|
-
body {
|
|
3616
|
-
margin-inline-end: ${widthToMargin(sidebarWidth)};
|
|
3617
|
-
transition: margin-inline-end ${SIDEBAR_TRANSITION_MS}ms ease;
|
|
3618
|
-
}
|
|
3619
|
-
}`
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3622
|
-
),
|
|
3623
|
-
/* @__PURE__ */ jsx22(CopilotChatToggleButton_default, {}),
|
|
3624
|
-
/* @__PURE__ */ jsx22(
|
|
3625
|
-
"aside",
|
|
3626
|
-
{
|
|
3627
|
-
ref: sidebarRef,
|
|
3628
|
-
"data-copilot-sidebar": true,
|
|
3629
|
-
className: cn(
|
|
3630
|
-
"fixed right-0 top-0 z-[1200] flex",
|
|
3631
|
-
// Height with dvh fallback and safe area support
|
|
3632
|
-
"h-[100vh] h-[100dvh] max-h-screen",
|
|
3633
|
-
// Responsive width: full on mobile, custom on desktop
|
|
3634
|
-
"w-full",
|
|
3635
|
-
"border-l border-border bg-background text-foreground shadow-xl",
|
|
3636
|
-
"transition-transform duration-300 ease-out",
|
|
3637
|
-
isSidebarOpen ? "translate-x-0" : "translate-x-full pointer-events-none"
|
|
3638
|
-
),
|
|
3639
|
-
style: {
|
|
3640
|
-
// Use CSS custom property for responsive width
|
|
3641
|
-
["--sidebar-width"]: widthToCss(sidebarWidth),
|
|
3642
|
-
// Safe area insets for iOS
|
|
3643
|
-
paddingTop: "env(safe-area-inset-top)",
|
|
3644
|
-
paddingBottom: "env(safe-area-inset-bottom)"
|
|
3645
|
-
},
|
|
3646
|
-
"aria-hidden": !isSidebarOpen,
|
|
3647
|
-
"aria-label": "Copilot chat sidebar",
|
|
3648
|
-
role: "complementary",
|
|
3649
|
-
children: /* @__PURE__ */ jsxs13("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
|
|
3650
|
-
headerElement,
|
|
3651
|
-
/* @__PURE__ */ jsx22("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ jsx22(CopilotChatView_default, { ...props }) })
|
|
3652
|
-
] })
|
|
3653
|
-
}
|
|
3654
|
-
)
|
|
3655
|
-
] });
|
|
3656
|
-
}
|
|
3657
|
-
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
3658
|
-
|
|
3659
|
-
// src/components/chat/CopilotPopupView.tsx
|
|
3660
|
-
import { useEffect as useEffect16, useMemo as useMemo9, useRef as useRef9, useState as useState12 } from "react";
|
|
3661
|
-
import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3662
|
-
var DEFAULT_POPUP_WIDTH = 420;
|
|
3663
|
-
var DEFAULT_POPUP_HEIGHT = 560;
|
|
3664
|
-
var dimensionToCss = (value, fallback) => {
|
|
3665
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
3666
|
-
return `${value}px`;
|
|
3667
|
-
}
|
|
3668
|
-
if (typeof value === "string" && value.trim().length > 0) {
|
|
3669
|
-
return value;
|
|
3670
|
-
}
|
|
3671
|
-
return `${fallback}px`;
|
|
3672
|
-
};
|
|
3673
|
-
function CopilotPopupView({
|
|
3674
|
-
header,
|
|
3675
|
-
width,
|
|
3676
|
-
height,
|
|
3677
|
-
clickOutsideToClose,
|
|
3678
|
-
className,
|
|
3679
|
-
...restProps
|
|
3680
|
-
}) {
|
|
3681
|
-
const configuration = useCopilotChatConfiguration();
|
|
3682
|
-
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
3683
|
-
const setModalOpen = configuration?.setModalOpen;
|
|
3684
|
-
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3685
|
-
const containerRef = useRef9(null);
|
|
3686
|
-
const [isRendered, setIsRendered] = useState12(isPopupOpen);
|
|
3687
|
-
const [isAnimatingOut, setIsAnimatingOut] = useState12(false);
|
|
3688
|
-
useEffect16(() => {
|
|
3689
|
-
if (isPopupOpen) {
|
|
3690
|
-
setIsRendered(true);
|
|
3691
|
-
setIsAnimatingOut(false);
|
|
3692
|
-
return;
|
|
3693
|
-
}
|
|
3694
|
-
if (!isRendered) {
|
|
3695
|
-
return;
|
|
3696
|
-
}
|
|
3697
|
-
setIsAnimatingOut(true);
|
|
3698
|
-
const timeout = setTimeout(() => {
|
|
3699
|
-
setIsRendered(false);
|
|
3700
|
-
setIsAnimatingOut(false);
|
|
3701
|
-
}, 200);
|
|
3702
|
-
return () => clearTimeout(timeout);
|
|
3703
|
-
}, [isPopupOpen, isRendered]);
|
|
3704
|
-
useEffect16(() => {
|
|
3705
|
-
if (!isPopupOpen) {
|
|
3706
|
-
return;
|
|
3707
|
-
}
|
|
3708
|
-
if (typeof window === "undefined") {
|
|
3709
|
-
return;
|
|
3710
|
-
}
|
|
3711
|
-
const handleKeyDown = (event) => {
|
|
3712
|
-
if (event.key === "Escape") {
|
|
3713
|
-
event.preventDefault();
|
|
3714
|
-
setModalOpen?.(false);
|
|
3715
|
-
}
|
|
3716
|
-
};
|
|
3717
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
3718
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3719
|
-
}, [isPopupOpen, setModalOpen]);
|
|
3720
|
-
useEffect16(() => {
|
|
3721
|
-
if (!isPopupOpen) {
|
|
3722
|
-
return;
|
|
3723
|
-
}
|
|
3724
|
-
const focusTimer = setTimeout(() => {
|
|
3725
|
-
containerRef.current?.focus({ preventScroll: true });
|
|
3726
|
-
}, 200);
|
|
3727
|
-
return () => clearTimeout(focusTimer);
|
|
3728
|
-
}, [isPopupOpen]);
|
|
3729
|
-
useEffect16(() => {
|
|
3730
|
-
if (!isPopupOpen || !clickOutsideToClose) {
|
|
3731
|
-
return;
|
|
3732
|
-
}
|
|
3733
|
-
if (typeof document === "undefined") {
|
|
3734
|
-
return;
|
|
3735
|
-
}
|
|
3736
|
-
const handlePointerDown = (event) => {
|
|
3737
|
-
const target = event.target;
|
|
3738
|
-
if (!target) {
|
|
3739
|
-
return;
|
|
3740
|
-
}
|
|
3741
|
-
const container = containerRef.current;
|
|
3742
|
-
if (container?.contains(target)) {
|
|
3743
|
-
return;
|
|
3744
|
-
}
|
|
3745
|
-
const toggleButton = document.querySelector("[data-slot='chat-toggle-button']");
|
|
3746
|
-
if (toggleButton && toggleButton.contains(target)) {
|
|
3747
|
-
return;
|
|
3748
|
-
}
|
|
3749
|
-
setModalOpen?.(false);
|
|
3750
|
-
};
|
|
3751
|
-
document.addEventListener("pointerdown", handlePointerDown);
|
|
3752
|
-
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
3753
|
-
}, [isPopupOpen, clickOutsideToClose, setModalOpen]);
|
|
3754
|
-
const headerElement = useMemo9(() => renderSlot(header, CopilotModalHeader, {}), [header]);
|
|
3755
|
-
const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
|
|
3756
|
-
const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
|
|
3757
|
-
const popupStyle = useMemo9(
|
|
3758
|
-
() => ({
|
|
3759
|
-
"--copilot-popup-width": resolvedWidth,
|
|
3760
|
-
"--copilot-popup-height": resolvedHeight,
|
|
3761
|
-
"--copilot-popup-max-width": "calc(100vw - 3rem)",
|
|
3762
|
-
"--copilot-popup-max-height": "calc(100dvh - 7.5rem)",
|
|
3763
|
-
paddingTop: "env(safe-area-inset-top)",
|
|
3764
|
-
paddingBottom: "env(safe-area-inset-bottom)",
|
|
3765
|
-
paddingLeft: "env(safe-area-inset-left)",
|
|
3766
|
-
paddingRight: "env(safe-area-inset-right)"
|
|
3767
|
-
}),
|
|
3768
|
-
[resolvedHeight, resolvedWidth]
|
|
3769
|
-
);
|
|
3770
|
-
const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "pointer-events-auto translate-y-0 opacity-100 md:scale-100" : "pointer-events-none translate-y-4 opacity-0 md:translate-y-5 md:scale-[0.95]";
|
|
3771
|
-
const popupContent = isRendered ? /* @__PURE__ */ jsx23(
|
|
3772
|
-
"div",
|
|
3773
|
-
{
|
|
3774
|
-
className: cn(
|
|
3775
|
-
"fixed inset-0 z-[1200] flex max-w-full flex-col items-stretch",
|
|
3776
|
-
"md:inset-auto md:bottom-24 md:right-6 md:items-end md:gap-4"
|
|
3777
|
-
),
|
|
3778
|
-
children: /* @__PURE__ */ jsxs14(
|
|
3779
|
-
"div",
|
|
3780
|
-
{
|
|
3781
|
-
ref: containerRef,
|
|
3782
|
-
tabIndex: -1,
|
|
3783
|
-
role: "dialog",
|
|
3784
|
-
"aria-label": labels.modalHeaderTitle,
|
|
3785
|
-
"data-copilot-popup": true,
|
|
3786
|
-
className: cn(
|
|
3787
|
-
"relative flex h-full w-full flex-col overflow-hidden bg-background text-foreground",
|
|
3788
|
-
"origin-bottom focus:outline-none transform-gpu transition-transform transition-opacity duration-200 ease-out",
|
|
3789
|
-
"md:transition-transform md:transition-opacity",
|
|
3790
|
-
"rounded-none border border-border/0 shadow-none ring-0",
|
|
3791
|
-
"md:h-[var(--copilot-popup-height)] md:w-[var(--copilot-popup-width)]",
|
|
3792
|
-
"md:max-h-[var(--copilot-popup-max-height)] md:max-w-[var(--copilot-popup-max-width)]",
|
|
3793
|
-
"md:origin-bottom-right md:rounded-2xl md:border-border md:shadow-xl md:ring-1 md:ring-border/40",
|
|
3794
|
-
popupAnimationClass
|
|
3795
|
-
),
|
|
3796
|
-
style: popupStyle,
|
|
3797
|
-
children: [
|
|
3798
|
-
headerElement,
|
|
3799
|
-
/* @__PURE__ */ jsx23("div", { className: "flex-1 overflow-hidden", "data-popup-chat": true, children: /* @__PURE__ */ jsx23(
|
|
3800
|
-
CopilotChatView_default,
|
|
3801
|
-
{
|
|
3802
|
-
...restProps,
|
|
3803
|
-
className: cn("h-full min-h-0", className)
|
|
3804
|
-
}
|
|
3805
|
-
) })
|
|
3806
|
-
]
|
|
3807
|
-
}
|
|
3808
|
-
)
|
|
3809
|
-
}
|
|
3810
|
-
) : null;
|
|
3811
|
-
return /* @__PURE__ */ jsxs14(Fragment8, { children: [
|
|
3812
|
-
/* @__PURE__ */ jsx23(CopilotChatToggleButton_default, {}),
|
|
3813
|
-
popupContent
|
|
3814
|
-
] });
|
|
3815
|
-
}
|
|
3816
|
-
CopilotPopupView.displayName = "CopilotPopupView";
|
|
3817
|
-
|
|
3818
|
-
// src/components/chat/CopilotSidebar.tsx
|
|
3819
|
-
import { useMemo as useMemo10 } from "react";
|
|
3820
|
-
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
3821
|
-
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
3822
|
-
const SidebarViewOverride = useMemo10(() => {
|
|
3823
|
-
const Component = (viewProps) => {
|
|
3824
|
-
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
3825
|
-
return /* @__PURE__ */ jsx24(
|
|
3826
|
-
CopilotSidebarView,
|
|
3827
|
-
{
|
|
3828
|
-
...restProps,
|
|
3829
|
-
header: header ?? viewHeader,
|
|
3830
|
-
width: width ?? viewWidth
|
|
3831
|
-
}
|
|
3832
|
-
);
|
|
3833
|
-
};
|
|
3834
|
-
return Object.assign(Component, CopilotChatView_default);
|
|
3835
|
-
}, [header, width]);
|
|
3836
|
-
return /* @__PURE__ */ jsx24(
|
|
3837
|
-
CopilotChat,
|
|
3838
|
-
{
|
|
3839
|
-
...chatProps,
|
|
3840
|
-
chatView: SidebarViewOverride,
|
|
3841
|
-
isModalDefaultOpen: defaultOpen
|
|
3842
|
-
}
|
|
3843
|
-
);
|
|
3844
|
-
}
|
|
3845
|
-
CopilotSidebar.displayName = "CopilotSidebar";
|
|
3846
|
-
|
|
3847
|
-
// src/components/chat/CopilotPopup.tsx
|
|
3848
|
-
import { useMemo as useMemo11 } from "react";
|
|
3849
|
-
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
3850
|
-
function CopilotPopup({
|
|
3851
|
-
header,
|
|
3852
|
-
defaultOpen,
|
|
3853
|
-
width,
|
|
3854
|
-
height,
|
|
3855
|
-
clickOutsideToClose,
|
|
3856
|
-
...chatProps
|
|
3857
|
-
}) {
|
|
3858
|
-
const PopupViewOverride = useMemo11(() => {
|
|
3859
|
-
const Component = (viewProps) => {
|
|
3860
|
-
const {
|
|
3861
|
-
header: viewHeader,
|
|
3862
|
-
width: viewWidth,
|
|
3863
|
-
height: viewHeight,
|
|
3864
|
-
clickOutsideToClose: viewClickOutsideToClose,
|
|
3865
|
-
...restProps
|
|
3866
|
-
} = viewProps;
|
|
3867
|
-
return /* @__PURE__ */ jsx25(
|
|
3868
|
-
CopilotPopupView,
|
|
3869
|
-
{
|
|
3870
|
-
...restProps,
|
|
3871
|
-
header: header ?? viewHeader,
|
|
3872
|
-
width: width ?? viewWidth,
|
|
3873
|
-
height: height ?? viewHeight,
|
|
3874
|
-
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose
|
|
3875
|
-
}
|
|
3876
|
-
);
|
|
3877
|
-
};
|
|
3878
|
-
return Object.assign(Component, CopilotChatView_default);
|
|
3879
|
-
}, [clickOutsideToClose, header, height, width]);
|
|
3880
|
-
return /* @__PURE__ */ jsx25(
|
|
3881
|
-
CopilotChat,
|
|
3882
|
-
{
|
|
3883
|
-
...chatProps,
|
|
3884
|
-
chatView: PopupViewOverride,
|
|
3885
|
-
isModalDefaultOpen: defaultOpen
|
|
3886
|
-
}
|
|
3887
|
-
);
|
|
3888
|
-
}
|
|
3889
|
-
CopilotPopup.displayName = "CopilotPopup";
|
|
3890
|
-
|
|
3891
|
-
// src/types/defineToolCallRenderer.ts
|
|
3892
|
-
import { z as z2 } from "zod";
|
|
3893
|
-
function defineToolCallRenderer(def) {
|
|
3894
|
-
const argsSchema = def.name === "*" && !def.args ? z2.any() : def.args;
|
|
3895
|
-
return {
|
|
3896
|
-
name: def.name,
|
|
3897
|
-
args: argsSchema,
|
|
3898
|
-
render: def.render,
|
|
3899
|
-
...def.agentId ? { agentId: def.agentId } : {}
|
|
3900
|
-
};
|
|
3901
|
-
}
|
|
3902
|
-
|
|
3903
|
-
// src/components/WildcardToolCallRender.tsx
|
|
3904
|
-
import { useState as useState13 } from "react";
|
|
3905
|
-
import { jsx as jsx26, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
3906
|
-
var WildcardToolCallRender = defineToolCallRenderer({
|
|
3907
|
-
name: "*",
|
|
3908
|
-
render: ({ args, result, name, status }) => {
|
|
3909
|
-
const [isExpanded, setIsExpanded] = useState13(false);
|
|
3910
|
-
const statusString = String(status);
|
|
3911
|
-
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
3912
|
-
const isComplete = statusString === "complete";
|
|
3913
|
-
const statusStyles = isActive ? "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-400" : isComplete ? "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400" : "bg-zinc-100 text-zinc-800 dark:bg-zinc-700/40 dark:text-zinc-300";
|
|
3914
|
-
return /* @__PURE__ */ jsx26("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ jsxs15("div", { className: "rounded-xl border border-zinc-200/60 dark:border-zinc-800/60 bg-white/70 dark:bg-zinc-900/50 shadow-sm backdrop-blur p-4", children: [
|
|
3915
|
-
/* @__PURE__ */ jsxs15(
|
|
3916
|
-
"div",
|
|
3917
|
-
{
|
|
3918
|
-
className: "flex items-center justify-between gap-3 cursor-pointer",
|
|
3919
|
-
onClick: () => setIsExpanded(!isExpanded),
|
|
3920
|
-
children: [
|
|
3921
|
-
/* @__PURE__ */ jsxs15("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
3922
|
-
/* @__PURE__ */ jsx26(
|
|
3923
|
-
"svg",
|
|
3924
|
-
{
|
|
3925
|
-
className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
|
|
3926
|
-
fill: "none",
|
|
3927
|
-
viewBox: "0 0 24 24",
|
|
3928
|
-
strokeWidth: 2,
|
|
3929
|
-
stroke: "currentColor",
|
|
3930
|
-
children: /* @__PURE__ */ jsx26(
|
|
3931
|
-
"path",
|
|
3932
|
-
{
|
|
3933
|
-
strokeLinecap: "round",
|
|
3934
|
-
strokeLinejoin: "round",
|
|
3935
|
-
d: "M8.25 4.5l7.5 7.5-7.5 7.5"
|
|
3936
|
-
}
|
|
3937
|
-
)
|
|
3938
|
-
}
|
|
3939
|
-
),
|
|
3940
|
-
/* @__PURE__ */ jsx26("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
|
|
3941
|
-
/* @__PURE__ */ jsx26("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
|
|
3942
|
-
] }),
|
|
3943
|
-
/* @__PURE__ */ jsx26(
|
|
3944
|
-
"span",
|
|
3945
|
-
{
|
|
3946
|
-
className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
|
|
3947
|
-
children: String(status)
|
|
3948
|
-
}
|
|
3949
|
-
)
|
|
3950
|
-
]
|
|
3951
|
-
}
|
|
3952
|
-
),
|
|
3953
|
-
isExpanded && /* @__PURE__ */ jsxs15("div", { className: "mt-3 grid gap-4", children: [
|
|
3954
|
-
/* @__PURE__ */ jsxs15("div", { children: [
|
|
3955
|
-
/* @__PURE__ */ jsx26("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
|
|
3956
|
-
/* @__PURE__ */ jsx26("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: JSON.stringify(args ?? {}, null, 2) })
|
|
3957
|
-
] }),
|
|
3958
|
-
result !== void 0 && /* @__PURE__ */ jsxs15("div", { children: [
|
|
3959
|
-
/* @__PURE__ */ jsx26("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
|
|
3960
|
-
/* @__PURE__ */ jsx26("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) })
|
|
3961
|
-
] })
|
|
3962
|
-
] })
|
|
3963
|
-
] }) });
|
|
3964
|
-
}
|
|
3965
|
-
});
|
|
20
|
+
CopilotSidebarView
|
|
21
|
+
} from "./chunk-3TA5QBSZ.mjs";
|
|
22
|
+
import {
|
|
23
|
+
CopilotModalHeader
|
|
24
|
+
} from "./chunk-E56GYBP3.mjs";
|
|
25
|
+
import {
|
|
26
|
+
CopilotChatToggleButton,
|
|
27
|
+
DefaultCloseIcon,
|
|
28
|
+
DefaultOpenIcon
|
|
29
|
+
} from "./chunk-R5OLAA3L.mjs";
|
|
30
|
+
import {
|
|
31
|
+
CopilotChat
|
|
32
|
+
} from "./chunk-TKFOXPXF.mjs";
|
|
33
|
+
import {
|
|
34
|
+
CopilotChatView_default
|
|
35
|
+
} from "./chunk-F43IPGPA.mjs";
|
|
36
|
+
import {
|
|
37
|
+
CopilotChatInput_default
|
|
38
|
+
} from "./chunk-KCVDFZJX.mjs";
|
|
39
|
+
import {
|
|
40
|
+
AudioRecorderError,
|
|
41
|
+
CopilotChatAudioRecorder
|
|
42
|
+
} from "./chunk-4UDBR75C.mjs";
|
|
43
|
+
import {
|
|
44
|
+
CopilotChatMessageView_default
|
|
45
|
+
} from "./chunk-W5DUKRCI.mjs";
|
|
46
|
+
import {
|
|
47
|
+
CopilotChatUserMessage_default
|
|
48
|
+
} from "./chunk-BT6C5OPU.mjs";
|
|
49
|
+
import {
|
|
50
|
+
CopilotChatAssistantMessage_default
|
|
51
|
+
} from "./chunk-CZ3GI3IF.mjs";
|
|
52
|
+
import {
|
|
53
|
+
CopilotChatSuggestionView_default
|
|
54
|
+
} from "./chunk-RGD2L3Z4.mjs";
|
|
55
|
+
import {
|
|
56
|
+
CopilotChatSuggestionPill_default
|
|
57
|
+
} from "./chunk-NNPKBGD6.mjs";
|
|
58
|
+
import {
|
|
59
|
+
CopilotChatToolCallsView_default
|
|
60
|
+
} from "./chunk-YVPPF62K.mjs";
|
|
61
|
+
import "./chunk-TAUOEJH2.mjs";
|
|
62
|
+
import "./chunk-JWOIINVV.mjs";
|
|
63
|
+
import "./chunk-VVAXSF3M.mjs";
|
|
64
|
+
import "./chunk-FZR2XQKR.mjs";
|
|
65
|
+
import {
|
|
66
|
+
WildcardToolCallRender
|
|
67
|
+
} from "./chunk-5JNWVLQI.mjs";
|
|
68
|
+
import {
|
|
69
|
+
defineToolCallRenderer
|
|
70
|
+
} from "./chunk-46BZRXWT.mjs";
|
|
71
|
+
import "./chunk-FIBK3DYE.mjs";
|
|
72
|
+
import "./chunk-XO4IRKSC.mjs";
|
|
73
|
+
import "./chunk-ETWJDCGE.mjs";
|
|
74
|
+
import {
|
|
75
|
+
useRenderToolCall
|
|
76
|
+
} from "./chunk-5AAT4Z3C.mjs";
|
|
77
|
+
import {
|
|
78
|
+
useSuggestions
|
|
79
|
+
} from "./chunk-Z3OIGQCZ.mjs";
|
|
80
|
+
import {
|
|
81
|
+
useAgentContext
|
|
82
|
+
} from "./chunk-WNRDFAZ5.mjs";
|
|
83
|
+
import {
|
|
84
|
+
useAgent
|
|
85
|
+
} from "./chunk-E4HD4M7R.mjs";
|
|
86
|
+
import {
|
|
87
|
+
useConfigureSuggestions
|
|
88
|
+
} from "./chunk-ZIDT52TM.mjs";
|
|
89
|
+
import {
|
|
90
|
+
useHumanInTheLoop
|
|
91
|
+
} from "./chunk-QJ6DZ645.mjs";
|
|
92
|
+
import {
|
|
93
|
+
useFrontendTool
|
|
94
|
+
} from "./chunk-NASFZS3N.mjs";
|
|
95
|
+
import {
|
|
96
|
+
useRenderActivityMessage
|
|
97
|
+
} from "./chunk-EJ5ZEAAN.mjs";
|
|
98
|
+
import {
|
|
99
|
+
useRenderCustomMessages
|
|
100
|
+
} from "./chunk-CSHBUHRW.mjs";
|
|
101
|
+
import "./chunk-YZUPVMHC.mjs";
|
|
102
|
+
import {
|
|
103
|
+
CopilotChatConfigurationProvider,
|
|
104
|
+
useCopilotChatConfiguration
|
|
105
|
+
} from "./chunk-4XJK5IVQ.mjs";
|
|
106
|
+
import {
|
|
107
|
+
CopilotKitProvider,
|
|
108
|
+
useCopilotKit
|
|
109
|
+
} from "./chunk-VE3SBLU7.mjs";
|
|
110
|
+
import {
|
|
111
|
+
CopilotKitInspector
|
|
112
|
+
} from "./chunk-YPH4BHOY.mjs";
|
|
113
|
+
import {
|
|
114
|
+
CopilotKitCoreReact
|
|
115
|
+
} from "./chunk-NNAYEAP2.mjs";
|
|
3966
116
|
export {
|
|
3967
117
|
AudioRecorderError,
|
|
3968
118
|
CopilotChat,
|