@copilotkit/react-ui 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17415 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/chunk-3W6J75HS.mjs +126 -0
- package/dist/chunk-3W6J75HS.mjs.map +1 -0
- package/dist/chunk-54JAUBUJ.mjs +26 -0
- package/dist/chunk-54JAUBUJ.mjs.map +1 -0
- package/dist/chunk-7OURDQZJ.mjs +133 -0
- package/dist/chunk-7OURDQZJ.mjs.map +1 -0
- package/dist/chunk-7PR2KJDO.mjs +222 -0
- package/dist/chunk-7PR2KJDO.mjs.map +1 -0
- package/dist/chunk-BH6PCAAL.mjs +81 -0
- package/dist/chunk-BH6PCAAL.mjs.map +1 -0
- package/dist/chunk-C3GSYRC3.mjs +118 -0
- package/dist/chunk-C3GSYRC3.mjs.map +1 -0
- package/dist/chunk-DBKRAOH7.mjs +34 -0
- package/dist/chunk-DBKRAOH7.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-ELGRNEAO.mjs +32 -0
- package/dist/chunk-ELGRNEAO.mjs.map +1 -0
- package/dist/chunk-ELUJRANC.mjs +21 -0
- package/dist/chunk-ELUJRANC.mjs.map +1 -0
- package/dist/chunk-FFJHOZX6.mjs +202 -0
- package/dist/chunk-FFJHOZX6.mjs.map +1 -0
- package/dist/chunk-GDSZGYCE.mjs +32 -0
- package/dist/chunk-GDSZGYCE.mjs.map +1 -0
- package/dist/chunk-HIW7RXCD.mjs +184 -0
- package/dist/chunk-HIW7RXCD.mjs.map +1 -0
- package/dist/chunk-IEMQ2SQW.mjs +93 -0
- package/dist/chunk-IEMQ2SQW.mjs.map +1 -0
- package/dist/chunk-IHFR6PYG.mjs +116 -0
- package/dist/chunk-IHFR6PYG.mjs.map +1 -0
- package/dist/chunk-IK2BPURM.mjs +400 -0
- package/dist/chunk-IK2BPURM.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JGMFJZMG.mjs +11 -0
- package/dist/chunk-JGMFJZMG.mjs.map +1 -0
- package/dist/chunk-JY2CSDKN.mjs +135 -0
- package/dist/chunk-JY2CSDKN.mjs.map +1 -0
- package/dist/chunk-JZ3RFQQ6.mjs +128 -0
- package/dist/chunk-JZ3RFQQ6.mjs.map +1 -0
- package/dist/chunk-KXE2JCUH.mjs +1 -0
- package/dist/chunk-KXE2JCUH.mjs.map +1 -0
- package/dist/chunk-LQEFRHRT.mjs +30 -0
- package/dist/chunk-LQEFRHRT.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-NCIAFFQ2.mjs +82 -0
- package/dist/chunk-NCIAFFQ2.mjs.map +1 -0
- package/dist/chunk-NGJ32FAP.mjs +30 -0
- package/dist/chunk-NGJ32FAP.mjs.map +1 -0
- package/dist/chunk-NRA3CFEE.mjs +97 -0
- package/dist/chunk-NRA3CFEE.mjs.map +1 -0
- package/dist/chunk-O72ZB5V3.mjs +140 -0
- package/dist/chunk-O72ZB5V3.mjs.map +1 -0
- package/dist/chunk-PLHTVHUW.mjs +82 -0
- package/dist/chunk-PLHTVHUW.mjs.map +1 -0
- package/dist/chunk-Q5V6S67N.mjs +103 -0
- package/dist/chunk-Q5V6S67N.mjs.map +1 -0
- package/dist/chunk-QB3GUN2N.mjs +31 -0
- package/dist/chunk-QB3GUN2N.mjs.map +1 -0
- package/dist/chunk-QIOJXTIQ.mjs +64 -0
- package/dist/chunk-QIOJXTIQ.mjs.map +1 -0
- package/dist/chunk-QPQRLXN3.mjs +435 -0
- package/dist/chunk-QPQRLXN3.mjs.map +1 -0
- package/dist/chunk-RYUCX3ZK.mjs +32 -0
- package/dist/chunk-RYUCX3ZK.mjs.map +1 -0
- package/dist/chunk-SC6JRFAJ.mjs +1 -0
- package/dist/chunk-SC6JRFAJ.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/chunk-T26KLXLH.mjs.map +1 -0
- package/dist/chunk-UFN2VWSR.mjs +25 -0
- package/dist/chunk-UFN2VWSR.mjs.map +1 -0
- package/dist/chunk-V7W6IM2V.mjs +1 -0
- package/dist/chunk-V7W6IM2V.mjs.map +1 -0
- package/dist/chunk-WB3YULQ4.mjs +1 -0
- package/dist/chunk-WB3YULQ4.mjs.map +1 -0
- package/dist/chunk-XWG3L6QC.mjs +258 -0
- package/dist/chunk-XWG3L6QC.mjs.map +1 -0
- package/dist/chunk-Y4FKRAKJ.mjs +12 -0
- package/dist/chunk-Y4FKRAKJ.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +9 -0
- package/dist/components/chat/Button.js +71 -0
- package/dist/components/chat/Button.js.map +1 -0
- package/dist/components/chat/Button.mjs +10 -0
- package/dist/components/chat/Button.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +204 -0
- package/dist/components/chat/Chat.js +2270 -0
- package/dist/components/chat/Chat.js.map +1 -0
- package/dist/components/chat/Chat.mjs +29 -0
- package/dist/components/chat/Chat.mjs.map +1 -0
- package/dist/components/chat/ChatContext.d.ts +145 -0
- package/dist/components/chat/ChatContext.js +329 -0
- package/dist/components/chat/ChatContext.js.map +1 -0
- package/dist/components/chat/ChatContext.mjs +13 -0
- package/dist/components/chat/ChatContext.mjs.map +1 -0
- package/dist/components/chat/CodeBlock.d.ts +14 -0
- package/dist/components/chat/CodeBlock.js +510 -0
- package/dist/components/chat/CodeBlock.js.map +1 -0
- package/dist/components/chat/CodeBlock.mjs +14 -0
- package/dist/components/chat/CodeBlock.mjs.map +1 -0
- package/dist/components/chat/Header.d.ts +9 -0
- package/dist/components/chat/Header.js +582 -0
- package/dist/components/chat/Header.js.map +1 -0
- package/dist/components/chat/Header.mjs +17 -0
- package/dist/components/chat/Header.mjs.map +1 -0
- package/dist/components/chat/Icons.d.ts +20 -0
- package/dist/components/chat/Icons.js +297 -0
- package/dist/components/chat/Icons.js.map +1 -0
- package/dist/components/chat/Icons.mjs +38 -0
- package/dist/components/chat/Icons.mjs.map +1 -0
- package/dist/components/chat/ImageUploadQueue.d.ts +13 -0
- package/dist/components/chat/ImageUploadQueue.js +106 -0
- package/dist/components/chat/ImageUploadQueue.js.map +1 -0
- package/dist/components/chat/ImageUploadQueue.mjs +8 -0
- package/dist/components/chat/ImageUploadQueue.mjs.map +1 -0
- package/dist/components/chat/Input.d.ts +9 -0
- package/dist/components/chat/Input.js +396 -0
- package/dist/components/chat/Input.js.map +1 -0
- package/dist/components/chat/Input.mjs +14 -0
- package/dist/components/chat/Input.mjs.map +1 -0
- package/dist/components/chat/Markdown.d.ts +10 -0
- package/dist/components/chat/Markdown.js +652 -0
- package/dist/components/chat/Markdown.js.map +1 -0
- package/dist/components/chat/Markdown.mjs +11 -0
- package/dist/components/chat/Markdown.mjs.map +1 -0
- package/dist/components/chat/Messages.d.ts +13 -0
- package/dist/components/chat/Messages.js +1195 -0
- package/dist/components/chat/Messages.js.map +1 -0
- package/dist/components/chat/Messages.mjs +20 -0
- package/dist/components/chat/Messages.mjs.map +1 -0
- package/dist/components/chat/Modal.d.ts +51 -0
- package/dist/components/chat/Modal.js +3075 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +38 -0
- package/dist/components/chat/Modal.mjs.map +1 -0
- package/dist/components/chat/Popup.d.ts +13 -0
- package/dist/components/chat/Popup.js +3086 -0
- package/dist/components/chat/Popup.js.map +1 -0
- package/dist/components/chat/Popup.mjs +39 -0
- package/dist/components/chat/Popup.mjs.map +1 -0
- package/dist/components/chat/PoweredByTag.d.ts +7 -0
- package/dist/components/chat/PoweredByTag.js +61 -0
- package/dist/components/chat/PoweredByTag.js.map +1 -0
- package/dist/components/chat/PoweredByTag.mjs +9 -0
- package/dist/components/chat/PoweredByTag.mjs.map +1 -0
- package/dist/components/chat/Sidebar.d.ts +13 -0
- package/dist/components/chat/Sidebar.js +3095 -0
- package/dist/components/chat/Sidebar.js.map +1 -0
- package/dist/components/chat/Sidebar.mjs +39 -0
- package/dist/components/chat/Sidebar.mjs.map +1 -0
- package/dist/components/chat/Suggestion.d.ts +12 -0
- package/dist/components/chat/Suggestion.js +56 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +9 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Suggestions.d.ts +9 -0
- package/dist/components/chat/Suggestions.js +81 -0
- package/dist/components/chat/Suggestions.js.map +1 -0
- package/dist/components/chat/Suggestions.mjs +10 -0
- package/dist/components/chat/Suggestions.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +15 -0
- package/dist/components/chat/Textarea.js +84 -0
- package/dist/components/chat/Textarea.js.map +1 -0
- package/dist/components/chat/Textarea.mjs +8 -0
- package/dist/components/chat/Textarea.mjs.map +1 -0
- package/dist/components/chat/Window.d.ts +9 -0
- package/dist/components/chat/Window.js +164 -0
- package/dist/components/chat/Window.js.map +1 -0
- package/dist/components/chat/Window.mjs +10 -0
- package/dist/components/chat/Window.mjs.map +1 -0
- package/dist/components/chat/index.d.ts +18 -0
- package/dist/components/chat/index.js +3122 -0
- package/dist/components/chat/index.js.map +1 -0
- package/dist/components/chat/index.mjs +69 -0
- package/dist/components/chat/index.mjs.map +1 -0
- package/dist/components/chat/messages/AssistantMessage.d.ts +9 -0
- package/dist/components/chat/messages/AssistantMessage.js +775 -0
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -0
- package/dist/components/chat/messages/AssistantMessage.mjs +13 -0
- package/dist/components/chat/messages/AssistantMessage.mjs.map +1 -0
- package/dist/components/chat/messages/ErrorMessage.d.ts +9 -0
- package/dist/components/chat/messages/ErrorMessage.js +722 -0
- package/dist/components/chat/messages/ErrorMessage.js.map +1 -0
- package/dist/components/chat/messages/ErrorMessage.mjs +66 -0
- package/dist/components/chat/messages/ErrorMessage.mjs.map +1 -0
- package/dist/components/chat/messages/ImageRenderer.d.ts +12 -0
- package/dist/components/chat/messages/ImageRenderer.js +58 -0
- package/dist/components/chat/messages/ImageRenderer.js.map +1 -0
- package/dist/components/chat/messages/ImageRenderer.mjs +8 -0
- package/dist/components/chat/messages/ImageRenderer.mjs.map +1 -0
- package/dist/components/chat/messages/LegacyRenderMessage.d.ts +28 -0
- package/dist/components/chat/messages/LegacyRenderMessage.js +1023 -0
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -0
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +17 -0
- package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderMessage.d.ts +9 -0
- package/dist/components/chat/messages/RenderMessage.js +898 -0
- package/dist/components/chat/messages/RenderMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderMessage.mjs +16 -0
- package/dist/components/chat/messages/RenderMessage.mjs.map +1 -0
- package/dist/components/chat/messages/UserMessage.d.ts +9 -0
- package/dist/components/chat/messages/UserMessage.js +56 -0
- package/dist/components/chat/messages/UserMessage.js.map +1 -0
- package/dist/components/chat/messages/UserMessage.mjs +8 -0
- package/dist/components/chat/messages/UserMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +298 -0
- package/dist/components/chat/props.js +19 -0
- package/dist/components/chat/props.js.map +1 -0
- package/dist/components/chat/props.mjs +2 -0
- package/dist/components/chat/props.mjs.map +1 -0
- package/dist/components/dev-console/console.d.ts +11 -0
- package/dist/components/dev-console/console.js +537 -0
- package/dist/components/dev-console/console.js.map +1 -0
- package/dist/components/dev-console/console.mjs +17 -0
- package/dist/components/dev-console/console.mjs.map +1 -0
- package/dist/components/dev-console/icons.d.ts +9 -0
- package/dist/components/dev-console/icons.js +131 -0
- package/dist/components/dev-console/icons.js.map +1 -0
- package/dist/components/dev-console/icons.mjs +16 -0
- package/dist/components/dev-console/icons.mjs.map +1 -0
- package/dist/components/dev-console/index.d.ts +3 -0
- package/dist/components/dev-console/index.js +537 -0
- package/dist/components/dev-console/index.js.map +1 -0
- package/dist/components/dev-console/index.mjs +18 -0
- package/dist/components/dev-console/index.mjs.map +1 -0
- package/dist/components/dev-console/types.d.ts +9 -0
- package/dist/components/dev-console/types.js +19 -0
- package/dist/components/dev-console/types.js.map +1 -0
- package/dist/components/dev-console/types.mjs +1 -0
- package/dist/components/dev-console/types.mjs.map +1 -0
- package/dist/components/dev-console/utils.d.ts +10 -0
- package/dist/components/dev-console/utils.js +177 -0
- package/dist/components/dev-console/utils.js.map +1 -0
- package/dist/components/dev-console/utils.mjs +16 -0
- package/dist/components/dev-console/utils.mjs.map +1 -0
- package/dist/components/help-modal/icons.d.ts +9 -0
- package/dist/components/help-modal/icons.js +107 -0
- package/dist/components/help-modal/icons.js.map +1 -0
- package/dist/components/help-modal/icons.mjs +12 -0
- package/dist/components/help-modal/icons.mjs.map +1 -0
- package/dist/components/help-modal/index.d.ts +2 -0
- package/dist/components/help-modal/index.js +137 -0
- package/dist/components/help-modal/index.js.map +1 -0
- package/dist/components/help-modal/index.mjs +10 -0
- package/dist/components/help-modal/index.mjs.map +1 -0
- package/dist/components/help-modal/modal.d.ts +5 -0
- package/dist/components/help-modal/modal.js +135 -0
- package/dist/components/help-modal/modal.js.map +1 -0
- package/dist/components/help-modal/modal.mjs +9 -0
- package/dist/components/help-modal/modal.mjs.map +1 -0
- package/dist/components/index.d.ts +19 -0
- package/dist/components/index.js +3126 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +76 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +9 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +66 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +34 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.d.ts +9 -0
- package/dist/hooks/use-copy-to-clipboard.js +60 -0
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.mjs +8 -0
- package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -0
- package/dist/hooks/use-dark-mode.d.ts +3 -0
- package/dist/hooks/use-dark-mode.js +35 -0
- package/dist/hooks/use-dark-mode.js.map +1 -0
- package/dist/hooks/use-dark-mode.mjs +8 -0
- package/dist/hooks/use-dark-mode.mjs.map +1 -0
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +195 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +1258 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +3135 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +84 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +76 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.mjs +34 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/types/css.d.ts +22 -0
- package/dist/types/css.js +19 -0
- package/dist/types/css.js.map +1 -0
- package/dist/types/css.mjs +1 -0
- package/dist/types/css.mjs.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/suggestions.d.ts +9 -0
- package/dist/types/suggestions.js +19 -0
- package/dist/types/suggestions.js.map +1 -0
- package/dist/types/suggestions.mjs +1 -0
- package/dist/types/suggestions.mjs.map +1 -0
- package/dist/v2/index.css +4 -0
- package/dist/v2/index.css.map +1 -0
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.js +2 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +83 -0
- package/postcss.config.js +60 -0
- package/src/components/chat/Button.tsx +18 -0
- package/src/components/chat/Chat.tsx +795 -0
- package/src/components/chat/ChatContext.tsx +248 -0
- package/src/components/chat/CodeBlock.tsx +418 -0
- package/src/components/chat/Header.tsx +24 -0
- package/src/components/chat/Icons.tsx +237 -0
- package/src/components/chat/ImageUploadQueue.tsx +77 -0
- package/src/components/chat/Input.tsx +156 -0
- package/src/components/chat/Markdown.tsx +144 -0
- package/src/components/chat/Messages.tsx +206 -0
- package/src/components/chat/Modal.tsx +220 -0
- package/src/components/chat/Popup.tsx +77 -0
- package/src/components/chat/PoweredByTag.tsx +42 -0
- package/src/components/chat/Sidebar.tsx +96 -0
- package/src/components/chat/Suggestion.tsx +29 -0
- package/src/components/chat/Suggestions.tsx +23 -0
- package/src/components/chat/Textarea.tsx +77 -0
- package/src/components/chat/Window.tsx +152 -0
- package/src/components/chat/index.tsx +11 -0
- package/src/components/chat/messages/AssistantMessage.tsx +118 -0
- package/src/components/chat/messages/ErrorMessage.tsx +59 -0
- package/src/components/chat/messages/ImageRenderer.tsx +37 -0
- package/src/components/chat/messages/LegacyRenderMessage.tsx +150 -0
- package/src/components/chat/messages/RenderMessage.tsx +61 -0
- package/src/components/chat/messages/UserMessage.tsx +46 -0
- package/src/components/chat/props.ts +353 -0
- package/src/components/dev-console/console.tsx +242 -0
- package/src/components/dev-console/icons.tsx +99 -0
- package/src/components/dev-console/index.tsx +2 -0
- package/src/components/dev-console/types.ts +7 -0
- package/src/components/dev-console/utils.ts +142 -0
- package/src/components/help-modal/icons.tsx +68 -0
- package/src/components/help-modal/index.tsx +1 -0
- package/src/components/help-modal/modal.tsx +101 -0
- package/src/components/index.ts +2 -0
- package/src/context/index.ts +1 -0
- package/src/css/animations.css +35 -0
- package/src/css/button.css +67 -0
- package/src/css/colors.css +78 -0
- package/src/css/console.css +166 -0
- package/src/css/crew.css +277 -0
- package/src/css/header.css +65 -0
- package/src/css/input.css +152 -0
- package/src/css/markdown.css +150 -0
- package/src/css/messages.css +244 -0
- package/src/css/panel.css +39 -0
- package/src/css/popup.css +22 -0
- package/src/css/sidebar.css +34 -0
- package/src/css/suggestions.css +43 -0
- package/src/css/window.css +60 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copilot-chat-suggestions.tsx +71 -0
- package/src/hooks/use-copy-to-clipboard.tsx +29 -0
- package/src/hooks/use-dark-mode.ts +10 -0
- package/src/hooks/use-push-to-talk.tsx +167 -0
- package/src/index.tsx +7 -0
- package/src/lib/utils.test.ts +7 -0
- package/src/lib/utils.ts +27 -0
- package/src/styles.css +14 -0
- package/src/types/css.ts +21 -0
- package/src/types/index.ts +2 -0
- package/src/types/suggestions.ts +7 -0
- package/src/v2/index.ts +1 -0
- package/src/v2/styles.css +1 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { MessagesProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import { Message } from "@copilotkit/shared";
|
|
5
|
+
import { useCopilotChatInternal } from "@copilotkit/react-core";
|
|
6
|
+
import { LegacyRenderMessage, LegacyRenderProps } from "./messages/LegacyRenderMessage";
|
|
7
|
+
|
|
8
|
+
export const Messages = ({
|
|
9
|
+
inProgress,
|
|
10
|
+
children,
|
|
11
|
+
RenderMessage,
|
|
12
|
+
AssistantMessage,
|
|
13
|
+
UserMessage,
|
|
14
|
+
ErrorMessage,
|
|
15
|
+
ImageRenderer,
|
|
16
|
+
onRegenerate,
|
|
17
|
+
onCopy,
|
|
18
|
+
onThumbsUp,
|
|
19
|
+
onThumbsDown,
|
|
20
|
+
messageFeedback,
|
|
21
|
+
markdownTagRenderers,
|
|
22
|
+
chatError,
|
|
23
|
+
|
|
24
|
+
// Legacy props
|
|
25
|
+
RenderTextMessage,
|
|
26
|
+
RenderActionExecutionMessage,
|
|
27
|
+
RenderAgentStateMessage,
|
|
28
|
+
RenderResultMessage,
|
|
29
|
+
RenderImageMessage,
|
|
30
|
+
}: MessagesProps) => {
|
|
31
|
+
const { labels, icons } = useChatContext();
|
|
32
|
+
const { messages: visibleMessages, interrupt } = useCopilotChatInternal();
|
|
33
|
+
const initialMessages = useMemo(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
34
|
+
const messages = [...initialMessages, ...visibleMessages];
|
|
35
|
+
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
36
|
+
|
|
37
|
+
// Check if any legacy props are provided
|
|
38
|
+
const hasLegacyProps = !!(
|
|
39
|
+
RenderTextMessage ||
|
|
40
|
+
RenderActionExecutionMessage ||
|
|
41
|
+
RenderAgentStateMessage ||
|
|
42
|
+
RenderResultMessage ||
|
|
43
|
+
RenderImageMessage
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Show deprecation warning if legacy props are used
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (hasLegacyProps) {
|
|
49
|
+
console.warn(
|
|
50
|
+
"[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. " +
|
|
51
|
+
"Please use the unified 'RenderMessage' prop instead. " +
|
|
52
|
+
"See migration guide: https://docs.copilotkit.ai/migration/render-message",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}, [hasLegacyProps]);
|
|
56
|
+
|
|
57
|
+
// Create legacy props object for the adapter
|
|
58
|
+
const legacyProps: LegacyRenderProps = useMemo(
|
|
59
|
+
() => ({
|
|
60
|
+
RenderTextMessage,
|
|
61
|
+
RenderActionExecutionMessage,
|
|
62
|
+
RenderAgentStateMessage,
|
|
63
|
+
RenderResultMessage,
|
|
64
|
+
RenderImageMessage,
|
|
65
|
+
}),
|
|
66
|
+
[
|
|
67
|
+
RenderTextMessage,
|
|
68
|
+
RenderActionExecutionMessage,
|
|
69
|
+
RenderAgentStateMessage,
|
|
70
|
+
RenderResultMessage,
|
|
71
|
+
RenderImageMessage,
|
|
72
|
+
],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Determine which render component to use
|
|
76
|
+
const MessageRenderer = hasLegacyProps
|
|
77
|
+
? (props: any) => <LegacyRenderMessage {...props} legacyProps={legacyProps} />
|
|
78
|
+
: RenderMessage;
|
|
79
|
+
|
|
80
|
+
const LoadingIcon = () => <span>{icons.activityIcon}</span>;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className="copilotKitMessages" ref={messagesContainerRef}>
|
|
84
|
+
<div className="copilotKitMessagesContainer">
|
|
85
|
+
{messages.map((message, index) => {
|
|
86
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
87
|
+
return (
|
|
88
|
+
<MessageRenderer
|
|
89
|
+
key={index}
|
|
90
|
+
message={message}
|
|
91
|
+
messages={messages}
|
|
92
|
+
inProgress={inProgress}
|
|
93
|
+
index={index}
|
|
94
|
+
isCurrentMessage={isCurrentMessage}
|
|
95
|
+
AssistantMessage={AssistantMessage}
|
|
96
|
+
UserMessage={UserMessage}
|
|
97
|
+
ImageRenderer={ImageRenderer}
|
|
98
|
+
onRegenerate={onRegenerate}
|
|
99
|
+
onCopy={onCopy}
|
|
100
|
+
onThumbsUp={onThumbsUp}
|
|
101
|
+
onThumbsDown={onThumbsDown}
|
|
102
|
+
messageFeedback={messageFeedback}
|
|
103
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
})}
|
|
107
|
+
{messages[messages.length - 1]?.role === "user" && inProgress && <LoadingIcon />}
|
|
108
|
+
{interrupt}
|
|
109
|
+
{chatError && ErrorMessage && <ErrorMessage error={chatError} isCurrentMessage />}
|
|
110
|
+
</div>
|
|
111
|
+
<footer className="copilotKitMessagesFooter" ref={messagesEndRef}>
|
|
112
|
+
{children}
|
|
113
|
+
</footer>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function makeInitialMessages(initial: string | string[] | undefined): Message[] {
|
|
119
|
+
if (!initial) return [];
|
|
120
|
+
|
|
121
|
+
if (Array.isArray(initial)) {
|
|
122
|
+
return initial.map((message) => {
|
|
123
|
+
return {
|
|
124
|
+
id: message,
|
|
125
|
+
role: "assistant",
|
|
126
|
+
content: message,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return [
|
|
132
|
+
{
|
|
133
|
+
id: initial,
|
|
134
|
+
role: "assistant",
|
|
135
|
+
content: initial,
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function useScrollToBottom(messages: Message[]) {
|
|
141
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
142
|
+
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
143
|
+
const isProgrammaticScrollRef = useRef(false);
|
|
144
|
+
const isUserScrollUpRef = useRef(false);
|
|
145
|
+
|
|
146
|
+
const scrollToBottom = () => {
|
|
147
|
+
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
148
|
+
isProgrammaticScrollRef.current = true;
|
|
149
|
+
messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const handleScroll = () => {
|
|
154
|
+
if (isProgrammaticScrollRef.current) {
|
|
155
|
+
isProgrammaticScrollRef.current = false;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (messagesContainerRef.current) {
|
|
160
|
+
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
161
|
+
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const container = messagesContainerRef.current;
|
|
167
|
+
if (container) {
|
|
168
|
+
container.addEventListener("scroll", handleScroll);
|
|
169
|
+
}
|
|
170
|
+
return () => {
|
|
171
|
+
if (container) {
|
|
172
|
+
container.removeEventListener("scroll", handleScroll);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}, []);
|
|
176
|
+
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const container = messagesContainerRef.current;
|
|
179
|
+
if (!container) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const mutationObserver = new MutationObserver(() => {
|
|
184
|
+
if (!isUserScrollUpRef.current) {
|
|
185
|
+
scrollToBottom();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
mutationObserver.observe(container, {
|
|
190
|
+
childList: true,
|
|
191
|
+
subtree: true,
|
|
192
|
+
characterData: true,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return () => {
|
|
196
|
+
mutationObserver.disconnect();
|
|
197
|
+
};
|
|
198
|
+
}, []);
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
isUserScrollUpRef.current = false;
|
|
202
|
+
scrollToBottom();
|
|
203
|
+
}, [messages.filter((m) => m.role === "user").length]);
|
|
204
|
+
|
|
205
|
+
return { messagesEndRef, messagesContainerRef };
|
|
206
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import React, { useMemo, useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { ChatContextProvider, useChatContext } from "./ChatContext";
|
|
3
|
+
import { ButtonProps, HeaderProps, WindowProps, CopilotObservabilityHooks } from "./props";
|
|
4
|
+
import { Window as DefaultWindow } from "./Window";
|
|
5
|
+
import { Button as DefaultButton } from "./Button";
|
|
6
|
+
import { Header as DefaultHeader } from "./Header";
|
|
7
|
+
import { Messages as DefaultMessages } from "./Messages";
|
|
8
|
+
import { Input as DefaultInput } from "./Input";
|
|
9
|
+
import { CopilotChat, CopilotChatProps } from "./Chat";
|
|
10
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./messages/AssistantMessage";
|
|
11
|
+
import { UserMessage as DefaultUserMessage } from "./messages/UserMessage";
|
|
12
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
13
|
+
import {
|
|
14
|
+
CopilotKitError,
|
|
15
|
+
CopilotKitErrorCode,
|
|
16
|
+
Severity,
|
|
17
|
+
ErrorVisibility,
|
|
18
|
+
styledConsole,
|
|
19
|
+
} from "@copilotkit/shared";
|
|
20
|
+
|
|
21
|
+
export interface CopilotModalProps extends CopilotChatProps {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the chat window should be open by default.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
defaultOpen?: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* If the chat window should close when the user clicks outside of it.
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
clickOutsideToClose?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* If the chat window should close when the user hits the Escape key.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
hitEscapeToClose?: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The shortcut key to open the chat window.
|
|
42
|
+
* Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.
|
|
43
|
+
* @default '/'
|
|
44
|
+
*/
|
|
45
|
+
shortcut?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A callback that gets called when the chat window opens or closes.
|
|
49
|
+
*/
|
|
50
|
+
onSetOpen?: (open: boolean) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A custom Window component to use instead of the default.
|
|
54
|
+
*/
|
|
55
|
+
Window?: React.ComponentType<WindowProps>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A custom Button component to use instead of the default.
|
|
59
|
+
*/
|
|
60
|
+
Button?: React.ComponentType<ButtonProps>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A custom Header component to use instead of the default.
|
|
64
|
+
*/
|
|
65
|
+
Header?: React.ComponentType<HeaderProps>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Inner component that has access to the Copilot context
|
|
69
|
+
const CopilotModalInner = ({
|
|
70
|
+
observabilityHooks,
|
|
71
|
+
onSetOpen,
|
|
72
|
+
clickOutsideToClose,
|
|
73
|
+
hitEscapeToClose,
|
|
74
|
+
shortcut,
|
|
75
|
+
className,
|
|
76
|
+
children,
|
|
77
|
+
Window,
|
|
78
|
+
Button,
|
|
79
|
+
Header,
|
|
80
|
+
...chatProps
|
|
81
|
+
}: Omit<CopilotModalProps, "icons" | "labels" | "defaultOpen"> & {
|
|
82
|
+
Window: React.ComponentType<WindowProps>;
|
|
83
|
+
Button: React.ComponentType<ButtonProps>;
|
|
84
|
+
Header: React.ComponentType<HeaderProps>;
|
|
85
|
+
clickOutsideToClose: boolean;
|
|
86
|
+
hitEscapeToClose: boolean;
|
|
87
|
+
shortcut: string;
|
|
88
|
+
}) => {
|
|
89
|
+
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
90
|
+
|
|
91
|
+
// Destructure stable values to avoid object reference changes
|
|
92
|
+
const { publicApiKey } = copilotApiConfig;
|
|
93
|
+
|
|
94
|
+
// Helper function to trigger event hooks only if publicApiKey is provided
|
|
95
|
+
const triggerObservabilityHook = useCallback(
|
|
96
|
+
(hookName: keyof CopilotObservabilityHooks, ...args: any[]) => {
|
|
97
|
+
if (publicApiKey && observabilityHooks?.[hookName]) {
|
|
98
|
+
(observabilityHooks[hookName] as any)(...args);
|
|
99
|
+
}
|
|
100
|
+
if (observabilityHooks?.[hookName] && !publicApiKey) {
|
|
101
|
+
setBannerError(
|
|
102
|
+
new CopilotKitError({
|
|
103
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
104
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
105
|
+
severity: Severity.CRITICAL,
|
|
106
|
+
visibility: ErrorVisibility.BANNER,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[publicApiKey, observabilityHooks, setBannerError],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const { open } = useChatContext();
|
|
116
|
+
const prevOpen = useRef(open);
|
|
117
|
+
|
|
118
|
+
// Monitor open state changes and trigger event hooks
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (prevOpen.current !== open) {
|
|
121
|
+
onSetOpen?.(open);
|
|
122
|
+
|
|
123
|
+
// Trigger chat minimize/expand events
|
|
124
|
+
if (open) {
|
|
125
|
+
triggerObservabilityHook("onChatExpanded");
|
|
126
|
+
} else {
|
|
127
|
+
triggerObservabilityHook("onChatMinimized");
|
|
128
|
+
}
|
|
129
|
+
prevOpen.current = open;
|
|
130
|
+
}
|
|
131
|
+
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
132
|
+
|
|
133
|
+
const memoizedHeader = useMemo(() => <Header />, [Header]);
|
|
134
|
+
const memoizedChildren = useMemo(() => children, [children]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<>
|
|
138
|
+
{memoizedChildren}
|
|
139
|
+
<div className={className}>
|
|
140
|
+
<Button></Button>
|
|
141
|
+
<Window
|
|
142
|
+
clickOutsideToClose={clickOutsideToClose}
|
|
143
|
+
shortcut={shortcut}
|
|
144
|
+
hitEscapeToClose={hitEscapeToClose}
|
|
145
|
+
>
|
|
146
|
+
{memoizedHeader}
|
|
147
|
+
<CopilotChat {...chatProps} observabilityHooks={observabilityHooks} />
|
|
148
|
+
</Window>
|
|
149
|
+
</div>
|
|
150
|
+
</>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const CopilotModal = ({
|
|
155
|
+
instructions,
|
|
156
|
+
defaultOpen = false,
|
|
157
|
+
clickOutsideToClose = true,
|
|
158
|
+
hitEscapeToClose = true,
|
|
159
|
+
onSetOpen,
|
|
160
|
+
onSubmitMessage,
|
|
161
|
+
onStopGeneration,
|
|
162
|
+
onReloadMessages,
|
|
163
|
+
shortcut = "/",
|
|
164
|
+
icons,
|
|
165
|
+
labels,
|
|
166
|
+
makeSystemMessage,
|
|
167
|
+
onInProgress,
|
|
168
|
+
Window = DefaultWindow,
|
|
169
|
+
Button = DefaultButton,
|
|
170
|
+
Header = DefaultHeader,
|
|
171
|
+
Messages = DefaultMessages,
|
|
172
|
+
Input = DefaultInput,
|
|
173
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
174
|
+
UserMessage = DefaultUserMessage,
|
|
175
|
+
onThumbsUp,
|
|
176
|
+
onThumbsDown,
|
|
177
|
+
onCopy,
|
|
178
|
+
onRegenerate,
|
|
179
|
+
markdownTagRenderers,
|
|
180
|
+
className,
|
|
181
|
+
children,
|
|
182
|
+
observabilityHooks,
|
|
183
|
+
...props
|
|
184
|
+
}: CopilotModalProps) => {
|
|
185
|
+
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<ChatContextProvider icons={icons} labels={labels} open={openState} setOpen={setOpenState}>
|
|
189
|
+
<CopilotModalInner
|
|
190
|
+
observabilityHooks={observabilityHooks}
|
|
191
|
+
onSetOpen={onSetOpen}
|
|
192
|
+
clickOutsideToClose={clickOutsideToClose ?? true}
|
|
193
|
+
hitEscapeToClose={hitEscapeToClose ?? true}
|
|
194
|
+
shortcut={shortcut ?? "/"}
|
|
195
|
+
className={className}
|
|
196
|
+
Window={Window}
|
|
197
|
+
Button={Button}
|
|
198
|
+
Header={Header}
|
|
199
|
+
instructions={instructions}
|
|
200
|
+
onSubmitMessage={onSubmitMessage}
|
|
201
|
+
onStopGeneration={onStopGeneration}
|
|
202
|
+
onReloadMessages={onReloadMessages}
|
|
203
|
+
makeSystemMessage={makeSystemMessage}
|
|
204
|
+
onInProgress={onInProgress}
|
|
205
|
+
Messages={Messages}
|
|
206
|
+
Input={Input}
|
|
207
|
+
AssistantMessage={AssistantMessage}
|
|
208
|
+
UserMessage={UserMessage}
|
|
209
|
+
onThumbsUp={onThumbsUp}
|
|
210
|
+
onThumbsDown={onThumbsDown}
|
|
211
|
+
onCopy={onCopy}
|
|
212
|
+
onRegenerate={onRegenerate}
|
|
213
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
214
|
+
{...props}
|
|
215
|
+
>
|
|
216
|
+
{children}
|
|
217
|
+
</CopilotModalInner>
|
|
218
|
+
</ChatContextProvider>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <br/>
|
|
3
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotPopup.gif" width="500" />
|
|
4
|
+
*
|
|
5
|
+
* A chatbot popup component for the CopilotKit framework. The component allows for a high degree
|
|
6
|
+
* of customization through various props and custom CSS.
|
|
7
|
+
*
|
|
8
|
+
* See [CopilotSidebar](/reference/components/chat/CopilotSidebar) for a sidebar version of this component.
|
|
9
|
+
*
|
|
10
|
+
* ## Install Dependencies
|
|
11
|
+
*
|
|
12
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
13
|
+
*
|
|
14
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
15
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
16
|
+
* ```
|
|
17
|
+
* ## Usage
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { CopilotPopup } from "@copilotkit/react-ui";
|
|
21
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
22
|
+
*
|
|
23
|
+
* <CopilotPopup
|
|
24
|
+
* labels={{
|
|
25
|
+
* title: "Your Assistant",
|
|
26
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
27
|
+
* }}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ### With Observability Hooks
|
|
32
|
+
*
|
|
33
|
+
* To monitor user interactions, provide the `observabilityHooks` prop.
|
|
34
|
+
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
|
|
38
|
+
* <CopilotPopup
|
|
39
|
+
* observabilityHooks={{
|
|
40
|
+
* onChatExpanded: () => {
|
|
41
|
+
* console.log("Popup opened");
|
|
42
|
+
* },
|
|
43
|
+
* onChatMinimized: () => {
|
|
44
|
+
* console.log("Popup closed");
|
|
45
|
+
* },
|
|
46
|
+
* }}
|
|
47
|
+
* />
|
|
48
|
+
* </CopilotKit>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ### Look & Feel
|
|
52
|
+
*
|
|
53
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
54
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
55
|
+
* ...
|
|
56
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
57
|
+
*
|
|
58
|
+
* export function YourRootComponent() {
|
|
59
|
+
* return (
|
|
60
|
+
* <CopilotKit>
|
|
61
|
+
* ...
|
|
62
|
+
* </CopilotKit>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
70
|
+
|
|
71
|
+
export function CopilotPopup(props: CopilotModalProps) {
|
|
72
|
+
props = {
|
|
73
|
+
...props,
|
|
74
|
+
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup",
|
|
75
|
+
};
|
|
76
|
+
return <CopilotModal {...props}>{props.children}</CopilotModal>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { useDarkMode } from "../../hooks/use-dark-mode";
|
|
3
|
+
|
|
4
|
+
export function PoweredByTag({ showPoweredBy = true }: { showPoweredBy?: boolean }) {
|
|
5
|
+
const [mounted, setMounted] = useState(false);
|
|
6
|
+
const isDark = useDarkMode();
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
note(tylerslaton):
|
|
10
|
+
|
|
11
|
+
Ensure we only use the isDark computed value after client-side mount.
|
|
12
|
+
This prevents hydration mismatches by using a default color on the
|
|
13
|
+
server and initial client render, then updating to the correct
|
|
14
|
+
dark mode color after hydration is complete.
|
|
15
|
+
*/
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setMounted(true);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
if (!showPoweredBy) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const poweredByStyle = {
|
|
25
|
+
visibility: "visible",
|
|
26
|
+
display: "block",
|
|
27
|
+
position: "static",
|
|
28
|
+
textAlign: "center",
|
|
29
|
+
fontSize: "12px",
|
|
30
|
+
padding: "3px 0",
|
|
31
|
+
color: mounted && isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div>
|
|
36
|
+
{/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}
|
|
37
|
+
<p className="poweredBy" style={poweredByStyle}>
|
|
38
|
+
Powered by CopilotKit
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <br/>
|
|
3
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotSidebar.gif" width="500" />
|
|
4
|
+
*
|
|
5
|
+
* A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.
|
|
6
|
+
*
|
|
7
|
+
* See [CopilotPopup](/reference/components/chat/CopilotPopup) for a popup version of this component.
|
|
8
|
+
*
|
|
9
|
+
* ## Install Dependencies
|
|
10
|
+
*
|
|
11
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
12
|
+
*
|
|
13
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
14
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ## Usage
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { CopilotSidebar } from "@copilotkit/react-ui";
|
|
21
|
+
* import "@copilotkit/react-ui/styles.css";
|
|
22
|
+
*
|
|
23
|
+
* <CopilotSidebar
|
|
24
|
+
* labels={{
|
|
25
|
+
* title: "Your Assistant",
|
|
26
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
27
|
+
* }}
|
|
28
|
+
* >
|
|
29
|
+
* <YourApp/>
|
|
30
|
+
* </CopilotSidebar>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### With Observability Hooks
|
|
34
|
+
*
|
|
35
|
+
* To monitor user interactions, provide the `observabilityHooks` prop.
|
|
36
|
+
* **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.
|
|
37
|
+
*
|
|
38
|
+
* ```tsx
|
|
39
|
+
* <CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
|
|
40
|
+
* <CopilotSidebar
|
|
41
|
+
* observabilityHooks={{
|
|
42
|
+
* onChatExpanded: () => {
|
|
43
|
+
* console.log("Sidebar opened");
|
|
44
|
+
* },
|
|
45
|
+
* onChatMinimized: () => {
|
|
46
|
+
* console.log("Sidebar closed");
|
|
47
|
+
* },
|
|
48
|
+
* }}
|
|
49
|
+
* >
|
|
50
|
+
* <YourApp/>
|
|
51
|
+
* </CopilotSidebar>
|
|
52
|
+
* </CopilotKit>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* ### Look & Feel
|
|
56
|
+
*
|
|
57
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
58
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
59
|
+
* ...
|
|
60
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
61
|
+
*
|
|
62
|
+
* export function YourRootComponent() {
|
|
63
|
+
* return (
|
|
64
|
+
* <CopilotKit>
|
|
65
|
+
* ...
|
|
66
|
+
* </CopilotKit>
|
|
67
|
+
* );
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
71
|
+
*/
|
|
72
|
+
import React, { useState } from "react";
|
|
73
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
74
|
+
|
|
75
|
+
export function CopilotSidebar(props: CopilotModalProps) {
|
|
76
|
+
props = {
|
|
77
|
+
...props,
|
|
78
|
+
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar",
|
|
79
|
+
};
|
|
80
|
+
const [expandedClassName, setExpandedClassName] = useState(
|
|
81
|
+
props.defaultOpen ? "sidebarExpanded" : "",
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const onSetOpen = (open: boolean) => {
|
|
85
|
+
props.onSetOpen?.(open);
|
|
86
|
+
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>
|
|
91
|
+
<CopilotModal {...props} {...{ onSetOpen }}>
|
|
92
|
+
{props.children}
|
|
93
|
+
</CopilotModal>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useCopilotChatInternal } from "@copilotkit/react-core";
|
|
2
|
+
import { SmallSpinnerIcon } from "./Icons";
|
|
3
|
+
|
|
4
|
+
interface SuggestionsProps {
|
|
5
|
+
title: string;
|
|
6
|
+
message: string;
|
|
7
|
+
partial?: boolean;
|
|
8
|
+
className?: string;
|
|
9
|
+
onClick: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Suggestion({ title, onClick, partial, className }: SuggestionsProps) {
|
|
13
|
+
if (!title) return null;
|
|
14
|
+
const { isLoading } = useCopilotChatInternal();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<button
|
|
18
|
+
disabled={partial || isLoading}
|
|
19
|
+
onClick={(e) => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
onClick();
|
|
22
|
+
}}
|
|
23
|
+
className={className || (partial ? "suggestion loading" : "suggestion")}
|
|
24
|
+
data-test-id="suggestion"
|
|
25
|
+
>
|
|
26
|
+
{partial ? SmallSpinnerIcon : <span>{title}</span>}
|
|
27
|
+
</button>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Suggestion } from "./Suggestion";
|
|
2
|
+
import { RenderSuggestionsListProps } from "./props";
|
|
3
|
+
|
|
4
|
+
export function Suggestions({
|
|
5
|
+
suggestions,
|
|
6
|
+
onSuggestionClick,
|
|
7
|
+
isLoading,
|
|
8
|
+
}: RenderSuggestionsListProps) {
|
|
9
|
+
return (
|
|
10
|
+
<div className="suggestions">
|
|
11
|
+
{suggestions.map((suggestion, index) => (
|
|
12
|
+
<Suggestion
|
|
13
|
+
key={index}
|
|
14
|
+
title={suggestion.title}
|
|
15
|
+
message={suggestion.message}
|
|
16
|
+
partial={suggestion.isLoading ?? suggestion.partial ?? isLoading}
|
|
17
|
+
className={suggestion.className}
|
|
18
|
+
onClick={() => onSuggestionClick(suggestion.message)}
|
|
19
|
+
/>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|