@copilotkit/react-ui 0.0.0-test-custom-tag-prerelease-1-20250108200215
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 +2134 -0
- package/README.md +46 -0
- package/dist/chunk-375NVWZM.mjs +21 -0
- package/dist/chunk-375NVWZM.mjs.map +1 -0
- package/dist/chunk-3E7HY2UN.mjs +85 -0
- package/dist/chunk-3E7HY2UN.mjs.map +1 -0
- package/dist/chunk-3XAXY2Z3.mjs +18 -0
- package/dist/chunk-3XAXY2Z3.mjs.map +1 -0
- package/dist/chunk-54JAUBUJ.mjs +26 -0
- package/dist/chunk-54JAUBUJ.mjs.map +1 -0
- package/dist/chunk-6INMITFA.mjs +18 -0
- package/dist/chunk-6INMITFA.mjs.map +1 -0
- package/dist/chunk-7II4YL7R.mjs +170 -0
- package/dist/chunk-7II4YL7R.mjs.map +1 -0
- package/dist/chunk-BH6PCAAL.mjs +81 -0
- package/dist/chunk-BH6PCAAL.mjs.map +1 -0
- package/dist/chunk-CBBFRI3Q.mjs +81 -0
- package/dist/chunk-CBBFRI3Q.mjs.map +1 -0
- package/dist/chunk-DCNCY2PL.mjs +304 -0
- package/dist/chunk-DCNCY2PL.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-EMQEEXUB.mjs +97 -0
- package/dist/chunk-EMQEEXUB.mjs.map +1 -0
- package/dist/chunk-F2W5FD7L.mjs +232 -0
- package/dist/chunk-F2W5FD7L.mjs.map +1 -0
- package/dist/chunk-FZC7X5PK.mjs +262 -0
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-KXE2JCUH.mjs +1 -0
- package/dist/chunk-KXE2JCUH.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/chunk-MRFF7GSQ.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-OTPAZXVR.mjs +92 -0
- package/dist/chunk-OTPAZXVR.mjs.map +1 -0
- package/dist/chunk-PNQVKBPN.mjs +146 -0
- package/dist/chunk-PNQVKBPN.mjs.map +1 -0
- package/dist/chunk-RJCZRKTV.mjs +106 -0
- package/dist/chunk-RJCZRKTV.mjs.map +1 -0
- package/dist/chunk-RQNJNK2W.mjs +25 -0
- package/dist/chunk-RQNJNK2W.mjs.map +1 -0
- package/dist/chunk-RU73BEZM.mjs +41 -0
- package/dist/chunk-RU73BEZM.mjs.map +1 -0
- package/dist/chunk-S5MBUNGN.mjs +140 -0
- package/dist/chunk-S5MBUNGN.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/chunk-T26KLXLH.mjs.map +1 -0
- package/dist/chunk-TI7SY2RI.mjs +164 -0
- package/dist/chunk-TI7SY2RI.mjs.map +1 -0
- package/dist/chunk-UPTB2MVO.mjs +395 -0
- package/dist/chunk-UPTB2MVO.mjs.map +1 -0
- package/dist/chunk-UWVGLGFQ.mjs +95 -0
- package/dist/chunk-UWVGLGFQ.mjs.map +1 -0
- package/dist/chunk-V7W6IM2V.mjs +1 -0
- package/dist/chunk-V7W6IM2V.mjs.map +1 -0
- package/dist/chunk-VEC45H6Q.mjs +18 -0
- package/dist/chunk-VEC45H6Q.mjs.map +1 -0
- package/dist/chunk-WB3YULQ4.mjs +1 -0
- package/dist/chunk-WB3YULQ4.mjs.map +1 -0
- package/dist/chunk-WSMMTZCM.mjs +30 -0
- package/dist/chunk-WSMMTZCM.mjs.map +1 -0
- package/dist/chunk-YAGE7RCE.mjs +118 -0
- package/dist/chunk-YAGE7RCE.mjs.map +1 -0
- package/dist/chunk-YQ3D5IQV.mjs +75 -0
- package/dist/chunk-YQ3D5IQV.mjs.map +1 -0
- package/dist/chunk-YQFVRDNC.mjs +53 -0
- package/dist/chunk-YQFVRDNC.mjs.map +1 -0
- package/dist/chunk-Z2UZSN3K.mjs +29 -0
- package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
- package/dist/chunk-ZABXREBH.mjs +65 -0
- package/dist/chunk-ZABXREBH.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +7 -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 +148 -0
- package/dist/components/chat/Chat.js +2427 -0
- package/dist/components/chat/Chat.js.map +1 -0
- package/dist/components/chat/Chat.mjs +34 -0
- package/dist/components/chat/Chat.mjs.map +1 -0
- package/dist/components/chat/ChatContext.d.ts +105 -0
- package/dist/components/chat/ChatContext.js +279 -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 +523 -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 +7 -0
- package/dist/components/chat/Header.js +64 -0
- package/dist/components/chat/Header.js.map +1 -0
- package/dist/components/chat/Header.mjs +10 -0
- package/dist/components/chat/Header.mjs.map +1 -0
- package/dist/components/chat/Icons.d.ts +18 -0
- package/dist/components/chat/Icons.js +321 -0
- package/dist/components/chat/Icons.js.map +1 -0
- package/dist/components/chat/Icons.mjs +32 -0
- package/dist/components/chat/Icons.mjs.map +1 -0
- package/dist/components/chat/Input.d.ts +7 -0
- package/dist/components/chat/Input.js +324 -0
- package/dist/components/chat/Input.js.map +1 -0
- package/dist/components/chat/Input.mjs +12 -0
- package/dist/components/chat/Input.mjs.map +1 -0
- package/dist/components/chat/Markdown.d.ts +8 -0
- package/dist/components/chat/Markdown.js +583 -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 +12 -0
- package/dist/components/chat/Messages.js +217 -0
- package/dist/components/chat/Messages.js.map +1 -0
- package/dist/components/chat/Messages.mjs +12 -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 +2626 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +34 -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 +2637 -0
- package/dist/components/chat/Popup.js.map +1 -0
- package/dist/components/chat/Popup.mjs +35 -0
- package/dist/components/chat/Popup.mjs.map +1 -0
- package/dist/components/chat/Response.d.ts +7 -0
- package/dist/components/chat/Response.js +64 -0
- package/dist/components/chat/Response.js.map +1 -0
- package/dist/components/chat/Response.mjs +10 -0
- package/dist/components/chat/Response.mjs.map +1 -0
- package/dist/components/chat/Sidebar.d.ts +13 -0
- package/dist/components/chat/Sidebar.js +2646 -0
- package/dist/components/chat/Sidebar.js.map +1 -0
- package/dist/components/chat/Sidebar.mjs +35 -0
- package/dist/components/chat/Sidebar.mjs.map +1 -0
- package/dist/components/chat/Suggestion.d.ts +14 -0
- package/dist/components/chat/Suggestion.js +181 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +11 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +13 -0
- package/dist/components/chat/Textarea.js +73 -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 +7 -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 +11 -0
- package/dist/components/chat/index.js +2661 -0
- package/dist/components/chat/index.js.map +1 -0
- package/dist/components/chat/index.mjs +47 -0
- package/dist/components/chat/index.mjs.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +131 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js +111 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderResultMessage.js +64 -0
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs +10 -0
- package/dist/components/chat/messages/RenderResultMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.d.ts +7 -0
- package/dist/components/chat/messages/RenderTextMessage.js +629 -0
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs +13 -0
- package/dist/components/chat/messages/RenderTextMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +46 -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 +10 -0
- package/dist/components/dev-console/console.js +720 -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 +120 -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 +5 -0
- package/dist/components/dev-console/index.js +720 -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 +188 -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 +255 -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 +253 -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 +14 -0
- package/dist/components/index.js +2665 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +54 -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 +1 -0
- package/dist/hooks/index.js +55 -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 +83 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +53 -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-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 +751 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +2693 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +62 -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/lib/utils.test.d.ts +2 -0
- package/dist/lib/utils.test.js +9 -0
- package/dist/lib/utils.test.js.map +1 -0
- package/dist/lib/utils.test.mjs +7 -0
- package/dist/lib/utils.test.mjs.map +1 -0
- package/dist/types/css.d.ts +16 -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 +2 -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 +8 -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/jest.config.js +5 -0
- package/package.json +78 -0
- package/postcss.config.js +60 -0
- package/src/components/chat/Button.tsx +18 -0
- package/src/components/chat/Chat.tsx +517 -0
- package/src/components/chat/ChatContext.tsx +188 -0
- package/src/components/chat/CodeBlock.tsx +408 -0
- package/src/components/chat/Header.tsx +15 -0
- package/src/components/chat/Icons.tsx +223 -0
- package/src/components/chat/Input.tsx +100 -0
- package/src/components/chat/Markdown.tsx +80 -0
- package/src/components/chat/Messages.tsx +178 -0
- package/src/components/chat/Modal.tsx +117 -0
- package/src/components/chat/Popup.tsx +57 -0
- package/src/components/chat/Response.tsx +12 -0
- package/src/components/chat/Sidebar.tsx +74 -0
- package/src/components/chat/Suggestion.tsx +125 -0
- package/src/components/chat/Textarea.tsx +61 -0
- package/src/components/chat/Window.tsx +153 -0
- package/src/components/chat/index.tsx +5 -0
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +101 -0
- package/src/components/chat/messages/RenderAgentStateMessage.tsx +92 -0
- package/src/components/chat/messages/RenderResultMessage.tsx +15 -0
- package/src/components/chat/messages/RenderTextMessage.tsx +36 -0
- package/src/components/chat/props.ts +49 -0
- package/src/components/dev-console/console.tsx +281 -0
- package/src/components/dev-console/icons.tsx +92 -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 +162 -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 +164 -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 +56 -0
- package/src/css/colors.css +12 -0
- package/src/css/console.css +134 -0
- package/src/css/header.css +43 -0
- package/src/css/input.css +89 -0
- package/src/css/markdown.css +136 -0
- package/src/css/messages.css +73 -0
- package/src/css/panel.css +38 -0
- package/src/css/popup.css +22 -0
- package/src/css/response.css +26 -0
- package/src/css/sidebar.css +34 -0
- package/src/css/suggestions.css +35 -0
- package/src/css/window.css +60 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copilot-chat-suggestions.tsx +112 -0
- package/src/hooks/use-copy-to-clipboard.tsx +29 -0
- package/src/hooks/use-push-to-talk.tsx +166 -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 +15 -0
- package/src/types/index.ts +1 -0
- package/src/types/suggestions.ts +6 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { InputProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import AutoResizingTextarea from "./Textarea";
|
|
5
|
+
import { usePushToTalk } from "../../hooks/use-push-to-talk";
|
|
6
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
7
|
+
|
|
8
|
+
export const Input = ({ inProgress, onSend, isVisible = false }: InputProps) => {
|
|
9
|
+
const context = useChatContext();
|
|
10
|
+
const copilotContext = useCopilotContext();
|
|
11
|
+
|
|
12
|
+
const pushToTalkConfigured =
|
|
13
|
+
copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&
|
|
14
|
+
copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;
|
|
15
|
+
|
|
16
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
17
|
+
|
|
18
|
+
const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
19
|
+
// Check if the clicked element is not the textarea itself
|
|
20
|
+
if (event.target !== event.currentTarget) return;
|
|
21
|
+
|
|
22
|
+
textareaRef.current?.focus();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const [text, setText] = useState("");
|
|
26
|
+
const send = () => {
|
|
27
|
+
if (inProgress) return;
|
|
28
|
+
onSend(text);
|
|
29
|
+
setText("");
|
|
30
|
+
|
|
31
|
+
textareaRef.current?.focus();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (isVisible) {
|
|
36
|
+
textareaRef.current?.focus();
|
|
37
|
+
}
|
|
38
|
+
}, [isVisible]);
|
|
39
|
+
|
|
40
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
41
|
+
sendFunction: onSend,
|
|
42
|
+
inProgress,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const sendIcon =
|
|
46
|
+
inProgress || pushToTalkState === "transcribing"
|
|
47
|
+
? context.icons.activityIcon
|
|
48
|
+
: context.icons.sendIcon;
|
|
49
|
+
const showPushToTalk =
|
|
50
|
+
pushToTalkConfigured &&
|
|
51
|
+
(pushToTalkState === "idle" || pushToTalkState === "recording") &&
|
|
52
|
+
!inProgress;
|
|
53
|
+
|
|
54
|
+
const canSend = () => {
|
|
55
|
+
return !inProgress && text.trim().length > 0 && pushToTalkState === "idle";
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const sendDisabled = !canSend();
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="copilotKitInput" onClick={handleDivClick}>
|
|
62
|
+
<AutoResizingTextarea
|
|
63
|
+
ref={textareaRef}
|
|
64
|
+
placeholder={context.labels.placeholder}
|
|
65
|
+
autoFocus={true}
|
|
66
|
+
maxRows={5}
|
|
67
|
+
value={text}
|
|
68
|
+
onChange={(event) => setText(event.target.value)}
|
|
69
|
+
onKeyDown={(event) => {
|
|
70
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
if (canSend()) {
|
|
73
|
+
send();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
<div className="copilotKitInputControls">
|
|
79
|
+
{showPushToTalk && (
|
|
80
|
+
<button
|
|
81
|
+
onClick={() =>
|
|
82
|
+
setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing")
|
|
83
|
+
}
|
|
84
|
+
className={pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : ""}
|
|
85
|
+
>
|
|
86
|
+
{context.icons.pushToTalkIcon}
|
|
87
|
+
</button>
|
|
88
|
+
)}
|
|
89
|
+
<button
|
|
90
|
+
disabled={sendDisabled}
|
|
91
|
+
onClick={send}
|
|
92
|
+
data-copilotkit-in-progress={!!inProgress}
|
|
93
|
+
data-testid={inProgress ? "copilot-chat-request-in-progress" : undefined}
|
|
94
|
+
>
|
|
95
|
+
{sendIcon}
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { FC, memo } from "react";
|
|
2
|
+
import ReactMarkdown, { Options, Components } from "react-markdown";
|
|
3
|
+
import { CodeBlock } from "./CodeBlock";
|
|
4
|
+
import remarkGfm from "remark-gfm";
|
|
5
|
+
import remarkMath from "remark-math";
|
|
6
|
+
|
|
7
|
+
const MemoizedReactMarkdown: FC<Options> = memo(
|
|
8
|
+
ReactMarkdown,
|
|
9
|
+
(prevProps, nextProps) =>
|
|
10
|
+
prevProps.children === nextProps.children && prevProps.className === nextProps.className,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
type MarkdownProps = {
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Markdown = ({ content }: MarkdownProps) => {
|
|
18
|
+
return (
|
|
19
|
+
<div className="copilotKitMarkdown">
|
|
20
|
+
<MemoizedReactMarkdown components={components} remarkPlugins={[remarkGfm, remarkMath]}>
|
|
21
|
+
{content}
|
|
22
|
+
</MemoizedReactMarkdown>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const components: Components = {
|
|
28
|
+
p({ children }) {
|
|
29
|
+
return <p>{children}</p>;
|
|
30
|
+
},
|
|
31
|
+
a({ children, ...props }) {
|
|
32
|
+
return (
|
|
33
|
+
<a
|
|
34
|
+
style={{ color: "blue", textDecoration: "underline" }}
|
|
35
|
+
{...props}
|
|
36
|
+
target="_blank"
|
|
37
|
+
rel="noopener noreferrer"
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</a>
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
code({ children, className, inline, ...props }) {
|
|
44
|
+
if (children.length) {
|
|
45
|
+
if (children[0] == "▍") {
|
|
46
|
+
return (
|
|
47
|
+
<span
|
|
48
|
+
style={{
|
|
49
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
50
|
+
marginTop: "0.25rem",
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
▍
|
|
54
|
+
</span>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
children[0] = (children[0] as string).replace("`▍`", "▍");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
62
|
+
|
|
63
|
+
if (inline) {
|
|
64
|
+
return (
|
|
65
|
+
<code className={className} {...props}>
|
|
66
|
+
{children}
|
|
67
|
+
</code>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<CodeBlock
|
|
73
|
+
key={Math.random()}
|
|
74
|
+
language={(match && match[1]) || ""}
|
|
75
|
+
value={String(children).replace(/\n$/, "")}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { MessagesProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import { Message, ResultMessage, TextMessage, Role } from "@copilotkit/runtime-client-gql";
|
|
5
|
+
|
|
6
|
+
export const Messages = ({
|
|
7
|
+
messages,
|
|
8
|
+
inProgress,
|
|
9
|
+
children,
|
|
10
|
+
RenderTextMessage,
|
|
11
|
+
RenderActionExecutionMessage,
|
|
12
|
+
RenderAgentStateMessage,
|
|
13
|
+
RenderResultMessage,
|
|
14
|
+
}: MessagesProps) => {
|
|
15
|
+
const context = useChatContext();
|
|
16
|
+
const initialMessages = useMemo(
|
|
17
|
+
() => makeInitialMessages(context.labels.initial),
|
|
18
|
+
[context.labels.initial],
|
|
19
|
+
);
|
|
20
|
+
messages = [...initialMessages, ...messages];
|
|
21
|
+
|
|
22
|
+
const actionResults: Record<string, string> = {};
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < messages.length; i++) {
|
|
25
|
+
if (messages[i].isActionExecutionMessage()) {
|
|
26
|
+
const id = messages[i].id;
|
|
27
|
+
const resultMessage: ResultMessage | undefined = messages.find(
|
|
28
|
+
(message) => message.isResultMessage() && message.actionExecutionId === id,
|
|
29
|
+
) as ResultMessage | undefined;
|
|
30
|
+
|
|
31
|
+
if (resultMessage) {
|
|
32
|
+
actionResults[id] = ResultMessage.decodeResult(resultMessage.result || "");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className="copilotKitMessages" ref={messagesContainerRef}>
|
|
41
|
+
{messages.map((message, index) => {
|
|
42
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
43
|
+
|
|
44
|
+
if (message.isTextMessage()) {
|
|
45
|
+
return (
|
|
46
|
+
<RenderTextMessage
|
|
47
|
+
key={index}
|
|
48
|
+
message={message}
|
|
49
|
+
inProgress={inProgress}
|
|
50
|
+
index={index}
|
|
51
|
+
isCurrentMessage={isCurrentMessage}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
} else if (message.isActionExecutionMessage()) {
|
|
55
|
+
return (
|
|
56
|
+
<RenderActionExecutionMessage
|
|
57
|
+
key={index}
|
|
58
|
+
message={message}
|
|
59
|
+
inProgress={inProgress}
|
|
60
|
+
index={index}
|
|
61
|
+
isCurrentMessage={isCurrentMessage}
|
|
62
|
+
actionResult={actionResults[message.id]}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
} else if (message.isAgentStateMessage()) {
|
|
66
|
+
return (
|
|
67
|
+
<RenderAgentStateMessage
|
|
68
|
+
key={index}
|
|
69
|
+
message={message}
|
|
70
|
+
inProgress={inProgress}
|
|
71
|
+
index={index}
|
|
72
|
+
isCurrentMessage={isCurrentMessage}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
} else if (message.isResultMessage()) {
|
|
76
|
+
return (
|
|
77
|
+
<RenderResultMessage
|
|
78
|
+
key={index}
|
|
79
|
+
message={message}
|
|
80
|
+
inProgress={inProgress}
|
|
81
|
+
index={index}
|
|
82
|
+
isCurrentMessage={isCurrentMessage}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
})}
|
|
87
|
+
<footer ref={messagesEndRef}>{children}</footer>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function makeInitialMessages(initial?: string | string[]): Message[] {
|
|
93
|
+
let initialArray: string[] = [];
|
|
94
|
+
if (initial) {
|
|
95
|
+
if (Array.isArray(initial)) {
|
|
96
|
+
initialArray.push(...initial);
|
|
97
|
+
} else {
|
|
98
|
+
initialArray.push(initial);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return initialArray.map(
|
|
103
|
+
(message) =>
|
|
104
|
+
new TextMessage({
|
|
105
|
+
role: Role.Assistant,
|
|
106
|
+
content: message,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
export function useScrollToBottom(messages: any[]) {
|
|
111
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
112
|
+
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
113
|
+
const isProgrammaticScrollRef = useRef(false);
|
|
114
|
+
const isUserScrollUpRef = useRef(false);
|
|
115
|
+
|
|
116
|
+
const scrollToBottom = () => {
|
|
117
|
+
if (messagesEndRef.current) {
|
|
118
|
+
isProgrammaticScrollRef.current = true;
|
|
119
|
+
messagesEndRef.current.scrollIntoView({
|
|
120
|
+
behavior: "auto",
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const handleScroll = () => {
|
|
126
|
+
if (isProgrammaticScrollRef.current) {
|
|
127
|
+
isProgrammaticScrollRef.current = false;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (messagesContainerRef.current) {
|
|
132
|
+
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
133
|
+
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
const container = messagesContainerRef.current;
|
|
139
|
+
if (container) {
|
|
140
|
+
container.addEventListener("scroll", handleScroll);
|
|
141
|
+
}
|
|
142
|
+
return () => {
|
|
143
|
+
if (container) {
|
|
144
|
+
container.removeEventListener("scroll", handleScroll);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const container = messagesContainerRef.current;
|
|
151
|
+
if (!container) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const mutationObserver = new MutationObserver(() => {
|
|
156
|
+
if (!isUserScrollUpRef.current) {
|
|
157
|
+
scrollToBottom();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
mutationObserver.observe(container, {
|
|
162
|
+
childList: true,
|
|
163
|
+
subtree: true,
|
|
164
|
+
characterData: true,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
mutationObserver.disconnect();
|
|
169
|
+
};
|
|
170
|
+
}, []);
|
|
171
|
+
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
isUserScrollUpRef.current = false;
|
|
174
|
+
scrollToBottom();
|
|
175
|
+
}, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);
|
|
176
|
+
|
|
177
|
+
return { messagesEndRef, messagesContainerRef };
|
|
178
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ChatContextProvider } from "./ChatContext";
|
|
3
|
+
import { ButtonProps, HeaderProps, WindowProps } 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 { ResponseButton as DefaultResponseButton } from "./Response";
|
|
10
|
+
import { CopilotChat, CopilotChatProps } from "./Chat";
|
|
11
|
+
|
|
12
|
+
export interface CopilotModalProps extends CopilotChatProps {
|
|
13
|
+
/**
|
|
14
|
+
* Whether the chat window should be open by default.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* If the chat window should close when the user clicks outside of it.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
clickOutsideToClose?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* If the chat window should close when the user hits the Escape key.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
hitEscapeToClose?: boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The shortcut key to open the chat window.
|
|
33
|
+
* Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.
|
|
34
|
+
* @default '/'
|
|
35
|
+
*/
|
|
36
|
+
shortcut?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A callback that gets called when the chat window opens or closes.
|
|
40
|
+
*/
|
|
41
|
+
onSetOpen?: (open: boolean) => void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A custom Window component to use instead of the default.
|
|
45
|
+
*/
|
|
46
|
+
Window?: React.ComponentType<WindowProps>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A custom Button component to use instead of the default.
|
|
50
|
+
*/
|
|
51
|
+
Button?: React.ComponentType<ButtonProps>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A custom Header component to use instead of the default.
|
|
55
|
+
*/
|
|
56
|
+
Header?: React.ComponentType<HeaderProps>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const CopilotModal = ({
|
|
60
|
+
instructions,
|
|
61
|
+
defaultOpen = false,
|
|
62
|
+
clickOutsideToClose = true,
|
|
63
|
+
hitEscapeToClose = true,
|
|
64
|
+
onSetOpen,
|
|
65
|
+
onSubmitMessage,
|
|
66
|
+
onStopGeneration,
|
|
67
|
+
onReloadMessages,
|
|
68
|
+
shortcut = "/",
|
|
69
|
+
icons,
|
|
70
|
+
labels,
|
|
71
|
+
makeSystemMessage,
|
|
72
|
+
showResponseButton = true,
|
|
73
|
+
onInProgress,
|
|
74
|
+
Window = DefaultWindow,
|
|
75
|
+
Button = DefaultButton,
|
|
76
|
+
Header = DefaultHeader,
|
|
77
|
+
Messages = DefaultMessages,
|
|
78
|
+
Input = DefaultInput,
|
|
79
|
+
ResponseButton = DefaultResponseButton,
|
|
80
|
+
className,
|
|
81
|
+
children,
|
|
82
|
+
}: CopilotModalProps) => {
|
|
83
|
+
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
84
|
+
|
|
85
|
+
const setOpen = (open: boolean) => {
|
|
86
|
+
onSetOpen?.(open);
|
|
87
|
+
setOpenState(open);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<ChatContextProvider icons={icons} labels={labels} open={openState} setOpen={setOpen}>
|
|
92
|
+
{children}
|
|
93
|
+
<div className={className}>
|
|
94
|
+
<Button></Button>
|
|
95
|
+
<Window
|
|
96
|
+
clickOutsideToClose={clickOutsideToClose}
|
|
97
|
+
shortcut={shortcut}
|
|
98
|
+
hitEscapeToClose={hitEscapeToClose}
|
|
99
|
+
>
|
|
100
|
+
<Header />
|
|
101
|
+
<CopilotChat
|
|
102
|
+
instructions={instructions}
|
|
103
|
+
onSubmitMessage={onSubmitMessage}
|
|
104
|
+
onStopGeneration={onStopGeneration}
|
|
105
|
+
onReloadMessages={onReloadMessages}
|
|
106
|
+
makeSystemMessage={makeSystemMessage}
|
|
107
|
+
showResponseButton={showResponseButton}
|
|
108
|
+
onInProgress={onInProgress}
|
|
109
|
+
Messages={Messages}
|
|
110
|
+
Input={Input}
|
|
111
|
+
ResponseButton={ResponseButton}
|
|
112
|
+
/>
|
|
113
|
+
</Window>
|
|
114
|
+
</div>
|
|
115
|
+
</ChatContextProvider>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <br/>
|
|
3
|
+
* <img src="/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
|
+
* ### Look & Feel
|
|
32
|
+
*
|
|
33
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
34
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
35
|
+
* ...
|
|
36
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
37
|
+
*
|
|
38
|
+
* export function YourRootComponent() {
|
|
39
|
+
* return (
|
|
40
|
+
* <CopilotKit>
|
|
41
|
+
* ...
|
|
42
|
+
* </CopilotKit>
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
* 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.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
50
|
+
|
|
51
|
+
export function CopilotPopup(props: CopilotModalProps) {
|
|
52
|
+
props = {
|
|
53
|
+
...props,
|
|
54
|
+
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup",
|
|
55
|
+
};
|
|
56
|
+
return <CopilotModal {...props}>{props.children}</CopilotModal>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useChatContext } from "./ChatContext";
|
|
2
|
+
import { ResponseButtonProps } from "./props";
|
|
3
|
+
|
|
4
|
+
export const ResponseButton = ({ onClick, inProgress }: ResponseButtonProps) => {
|
|
5
|
+
const context = useChatContext();
|
|
6
|
+
return (
|
|
7
|
+
<button onClick={onClick} className="copilotKitResponseButton">
|
|
8
|
+
<span>{inProgress ? context.icons.stopIcon : context.icons.regenerateIcon}</span>
|
|
9
|
+
{inProgress ? context.labels.stopGenerating : context.labels.regenerateResponse}
|
|
10
|
+
</button>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <br/>
|
|
3
|
+
* <img src="/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
|
+
* ### Look & Feel
|
|
34
|
+
*
|
|
35
|
+
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
36
|
+
* ```tsx title="YourRootComponent.tsx"
|
|
37
|
+
* ...
|
|
38
|
+
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
39
|
+
*
|
|
40
|
+
* export function YourRootComponent() {
|
|
41
|
+
* return (
|
|
42
|
+
* <CopilotKit>
|
|
43
|
+
* ...
|
|
44
|
+
* </CopilotKit>
|
|
45
|
+
* );
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
* 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.
|
|
49
|
+
*/
|
|
50
|
+
import React, { useState } from "react";
|
|
51
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
52
|
+
|
|
53
|
+
export function CopilotSidebar(props: CopilotModalProps) {
|
|
54
|
+
props = {
|
|
55
|
+
...props,
|
|
56
|
+
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar",
|
|
57
|
+
};
|
|
58
|
+
const [expandedClassName, setExpandedClassName] = useState(
|
|
59
|
+
props.defaultOpen ? "sidebarExpanded" : "",
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const onSetOpen = (open: boolean) => {
|
|
63
|
+
props.onSetOpen?.(open);
|
|
64
|
+
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>
|
|
69
|
+
<CopilotModal {...props} {...{ onSetOpen }}>
|
|
70
|
+
{props.children}
|
|
71
|
+
</CopilotModal>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|