@agentscope-ai/chat 1.1.20 → 1.1.22
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/bin/client.js +1 -1
- package/components/AGUI/components/HelpModal/icons.tsx +68 -0
- package/components/AGUI/components/HelpModal/index.tsx +1 -0
- package/components/AGUI/components/HelpModal/modal.tsx +101 -0
- package/components/AGUI/components/chat/Button.tsx +18 -0
- package/components/AGUI/components/chat/Chat.tsx +780 -0
- package/components/AGUI/components/chat/ChatContext.tsx +248 -0
- package/components/AGUI/components/chat/CodeBlock.tsx +406 -0
- package/components/AGUI/components/chat/Header.tsx +22 -0
- package/components/AGUI/components/chat/Icons.tsx +237 -0
- package/components/AGUI/components/chat/ImageUploadQueue.tsx +77 -0
- package/components/AGUI/components/chat/Input.tsx +24 -0
- package/components/AGUI/components/chat/Markdown.tsx +134 -0
- package/components/AGUI/components/chat/Messages.tsx +259 -0
- package/components/AGUI/components/chat/Modal.tsx +133 -0
- package/components/AGUI/components/chat/Popup.tsx +57 -0
- package/components/AGUI/components/chat/PoweredByTag.tsx +29 -0
- package/components/AGUI/components/chat/Sidebar.tsx +74 -0
- package/components/AGUI/components/chat/Suggestion.tsx +132 -0
- package/components/AGUI/components/chat/Suggestions.tsx +20 -0
- package/components/AGUI/components/chat/Textarea.tsx +61 -0
- package/components/AGUI/components/chat/Window.tsx +152 -0
- package/components/AGUI/components/chat/index.tsx +11 -0
- package/components/AGUI/components/chat/messages/AssistantMessage.tsx +69 -0
- package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +129 -0
- package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +116 -0
- package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +64 -0
- package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +26 -0
- package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +51 -0
- package/components/AGUI/components/chat/messages/UserMessage.tsx +10 -0
- package/components/AGUI/components/chat/props.ts +186 -0
- package/components/AGUI/components/index.ts +1 -0
- package/components/AGUI/context/index.ts +1 -0
- package/components/AGUI/hooks/index.ts +1 -0
- package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +122 -0
- package/components/AGUI/hooks/use-copy-to-clipboard.tsx +29 -0
- package/components/AGUI/hooks/use-dark-mode.ts +10 -0
- package/components/AGUI/hooks/use-push-to-talk.tsx +166 -0
- package/components/AGUI/index.tsx +4 -0
- package/components/AGUI/lib/utils.test.ts +7 -0
- package/components/AGUI/lib/utils.ts +27 -0
- package/components/AGUI/styles.css +0 -0
- package/components/AGUI/types/css.ts +0 -0
- package/components/AGUI/types/index.ts +1 -0
- package/components/AGUI/types/suggestions.ts +6 -0
- package/components/Accordion/Accordion.tsx +203 -0
- package/components/Accordion/BodyContent.tsx +28 -0
- package/components/Accordion/DeepThinking.tsx +91 -0
- package/components/Accordion/SoftLightTitle.tsx +13 -0
- package/components/Accordion/demo/search.tsx +39 -0
- package/components/Accordion/demo/steps.tsx +135 -0
- package/components/Accordion/demo/thinking.tsx +62 -0
- package/components/Accordion/index.en-US.md +34 -0
- package/components/Accordion/index.tsx +3 -0
- package/components/Accordion/index.zh-CN.md +34 -0
- package/components/Accordion/style.ts +208 -0
- package/components/AgentScopeRuntimeWebUI/demo/index.tsx +4 -0
- package/components/AgentScopeRuntimeWebUI/index.tsx +3 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Request/Builder.tsx +82 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Request/Card.tsx +52 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Actions.tsx +39 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Builder.tsx +205 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Card.tsx +44 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Error.tsx +7 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Message.tsx +23 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Reasoning.tsx +16 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/Response/Tool.tsx +19 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/index.tsx +0 -0
- package/components/AgentScopeRuntimeWebUI/lib/AgentScopeRuntime/types.tsx +100 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/Input/index.tsx +77 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/Input/useAttachments.tsx +53 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/MessageList/index.tsx +30 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/Welcome/index.tsx +66 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/Welcome/styles.ts +51 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/index.tsx +5 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatController.tsx +130 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatMessageHandler.tsx +87 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatRequest.tsx +114 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/hooks/useChatSessionHandler.tsx +50 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/index.tsx +18 -0
- package/components/AgentScopeRuntimeWebUI/lib/Chat/styles.tsx +59 -0
- package/components/AgentScopeRuntimeWebUI/lib/ChatAnywhere/ComposedProvider.tsx +27 -0
- package/components/AgentScopeRuntimeWebUI/lib/ChatAnywhere/index.tsx +29 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereControl.tsx +0 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereInputContext.tsx +27 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereLayoutContext.tsx +27 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereMessagesContext.tsx +82 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereOptionsContext.tsx +76 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/ChatAnywhereSessionsContext.tsx +111 -0
- package/components/AgentScopeRuntimeWebUI/lib/Context/useChatAnywhereEventEmitter.tsx +30 -0
- package/components/AgentScopeRuntimeWebUI/lib/Header/index.tsx +45 -0
- package/components/AgentScopeRuntimeWebUI/lib/Header/styles.ts +23 -0
- package/components/AgentScopeRuntimeWebUI/lib/Layout/index.tsx +45 -0
- package/components/AgentScopeRuntimeWebUI/lib/Layout/styles.tsx +104 -0
- package/components/AgentScopeRuntimeWebUI/lib/Sessions/index.tsx +114 -0
- package/components/AgentScopeRuntimeWebUI/lib/Sessions/styles.tsx +0 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/FormItem.tsx +37 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/OptionsEditor.tsx +163 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/defaultConfig.ts +43 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/OptionsPanel/index.tsx +27 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/index.tsx +57 -0
- package/components/AgentScopeRuntimeWebUI/lib/demo/sessionApi/index.ts +51 -0
- package/components/AgentScopeRuntimeWebUI/lib/types/IChatAnywhere.ts +358 -0
- package/components/AgentScopeRuntimeWebUI/lib/types/IMessages.tsx +52 -0
- package/components/AgentScopeRuntimeWebUI/lib/types/ISessions.tsx +29 -0
- package/components/AgentScopeRuntimeWebUI/lib/types/index.tsx +3 -0
- package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.tsx +37 -0
- package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.tsx +163 -0
- package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.ts +43 -0
- package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.tsx +27 -0
- package/components/AgentScopeRuntimeWebUI/starter/index.tsx +57 -0
- package/components/AgentScopeRuntimeWebUI/starter/sessionApi/index.ts +51 -0
- package/components/Attachments/DropArea.tsx +97 -0
- package/components/Attachments/FileList/AudioIcon.tsx +20 -0
- package/components/Attachments/FileList/FileListCard.tsx +270 -0
- package/components/Attachments/FileList/Progress.tsx +30 -0
- package/components/Attachments/FileList/VideoIcon.tsx +20 -0
- package/components/Attachments/FileList/index.tsx +201 -0
- package/components/Attachments/PlaceholderUploader.tsx +124 -0
- package/components/Attachments/SilentUploader.tsx +39 -0
- package/components/Attachments/context.tsx +11 -0
- package/components/Attachments/demo/basic.tsx +71 -0
- package/components/Attachments/index.en-US.md.bk +10 -0
- package/components/Attachments/index.tsx +274 -0
- package/components/Attachments/index.zh-CN.md.bk +10 -0
- package/components/Attachments/style/fileCard.ts +163 -0
- package/components/Attachments/style/index.ts +232 -0
- package/components/Attachments/util.ts +56 -0
- package/components/Bubble/Avatar.tsx +39 -0
- package/components/Bubble/Bubble.tsx +131 -0
- package/components/Bubble/BubbleList.tsx +105 -0
- package/components/Bubble/Cards.tsx +61 -0
- package/components/Bubble/Footer.tsx +55 -0
- package/components/Bubble/Interrupted.tsx +82 -0
- package/components/Bubble/ScrollToBottom.tsx +42 -0
- package/components/Bubble/Spin.tsx +13 -0
- package/components/Bubble/demo/assistantWithCode.tsx +60 -0
- package/components/Bubble/demo/assistantWithErrorStatus.tsx +102 -0
- package/components/Bubble/demo/assistantWithImage.tsx +46 -0
- package/components/Bubble/demo/assistantWithProcess.tsx +103 -0
- package/components/Bubble/demo/assistantWithSearch.tsx +69 -0
- package/components/Bubble/demo/assistantWithThinking.tsx +54 -0
- package/components/Bubble/demo/basic.tsx +55 -0
- package/components/Bubble/demo/userWithFile.tsx +27 -0
- package/components/Bubble/demo/userWithImage.tsx +26 -0
- package/components/Bubble/hooks/useDisplayData.ts +0 -0
- package/components/Bubble/hooks/useListData.ts +0 -0
- package/components/Bubble/index.en-US.md +33 -0
- package/components/Bubble/index.tsx +21 -0
- package/components/Bubble/index.zh-CN.md +33 -0
- package/components/Bubble/interface.ts +71 -0
- package/components/Bubble/loading.tsx +15 -0
- package/components/Bubble/style/avatar.ts +43 -0
- package/components/Bubble/style/footer.ts +45 -0
- package/components/Bubble/style/index.ts +192 -0
- package/components/Bubble/style/list.ts +51 -0
- package/components/ChatAnywhere/Chat/Ref.tsx +20 -0
- package/components/ChatAnywhere/Chat/index.tsx +56 -0
- package/components/ChatAnywhere/Chat/style.ts +59 -0
- package/components/ChatAnywhere/Header/index.tsx +37 -0
- package/components/ChatAnywhere/Header/style.ts +27 -0
- package/components/ChatAnywhere/Input/index.tsx +158 -0
- package/components/ChatAnywhere/Input/style.ts +14 -0
- package/components/ChatAnywhere/Layout/index.tsx +70 -0
- package/components/ChatAnywhere/Layout/style.ts +51 -0
- package/components/ChatAnywhere/SessionList/index.tsx +122 -0
- package/components/ChatAnywhere/SessionList/style.ts +53 -0
- package/components/ChatAnywhere/hooks/ChatAnywhereProvider.tsx +219 -0
- package/components/ChatAnywhere/hooks/types.ts +333 -0
- package/components/ChatAnywhere/hooks/useInput.tsx +22 -0
- package/components/ChatAnywhere/hooks/useMessages.tsx +63 -0
- package/components/ChatAnywhere/hooks/useSessionList.tsx +123 -0
- package/components/ChatAnywhere/index.tsx +49 -0
- package/components/Conversations/GroupTitle.tsx +28 -0
- package/components/Conversations/Item.tsx +189 -0
- package/components/Conversations/demo/basic.tsx +107 -0
- package/components/Conversations/demo/timeline.tsx +111 -0
- package/components/Conversations/demo/timestamp.tsx +110 -0
- package/components/Conversations/hooks/useGroupable.ts +81 -0
- package/components/Conversations/index.en-US.md +32 -0
- package/components/Conversations/index.tsx +176 -0
- package/components/Conversations/index.zh-CN.md +31 -0
- package/components/Conversations/interface.ts +69 -0
- package/components/Conversations/style.ts +153 -0
- package/components/DefaultCards/DeepThinking/index.tsx +33 -0
- package/components/DefaultCards/Files/index.tsx +69 -0
- package/components/DefaultCards/Footer/index.tsx +16 -0
- package/components/DefaultCards/Images/index.tsx +53 -0
- package/components/DefaultCards/Interrupted/index.tsx +13 -0
- package/components/DefaultCards/Text/index.tsx +13 -0
- package/components/DefaultCards/index.tsx +6 -0
- package/components/DeviceAction/actionMap.tsx +100 -0
- package/components/DeviceAction/demo/index.tsx +132 -0
- package/components/DeviceAction/index.en-US.md +19 -0
- package/components/DeviceAction/index.tsx +75 -0
- package/components/DeviceAction/index.zh-CN.md +19 -0
- package/components/Disclaimer/demo/index.tsx +4 -0
- package/components/Disclaimer/demo/withLink.tsx +4 -0
- package/components/Disclaimer/index.en-US.md +23 -0
- package/components/Disclaimer/index.tsx +42 -0
- package/components/Disclaimer/index.zh-CN.md +24 -0
- package/components/Disclaimer/style.ts +17 -0
- package/components/ImageGenerator/demo/basic.tsx +23 -0
- package/components/ImageGenerator/demo/custom.tsx +56 -0
- package/components/ImageGenerator/demo/size.tsx +15 -0
- package/components/ImageGenerator/index.en-US.md +23 -0
- package/components/ImageGenerator/index.tsx +124 -0
- package/components/ImageGenerator/index.zh-CN.md +23 -0
- package/components/ImageGenerator/style.ts +99 -0
- package/components/Markdown/Markdown/AnimationNode.tsx +89 -0
- package/components/Markdown/Markdown/Markdown.tsx +61 -0
- package/components/Markdown/Markdown/core/Parser.ts +52 -0
- package/components/Markdown/Markdown/core/Renderer.ts +121 -0
- package/components/Markdown/Markdown/core/index.ts +4 -0
- package/components/Markdown/Markdown/defaultComponents/CodeBlock.tsx +113 -0
- package/components/Markdown/Markdown/defaultComponents/DisabledImage.tsx +3 -0
- package/components/Markdown/Markdown/defaultComponents/Media.tsx +71 -0
- package/components/Markdown/Markdown/hooks/index.ts +4 -0
- package/components/Markdown/Markdown/hooks/useAnimation.tsx +27 -0
- package/components/Markdown/Markdown/hooks/useCitationsData.tsx +36 -0
- package/components/Markdown/Markdown/hooks/useStreaming.ts +503 -0
- package/components/Markdown/Markdown/hooks/useTyping.ts +22 -0
- package/components/Markdown/Markdown/index.tsx +198 -0
- package/components/Markdown/Markdown/interface.ts +217 -0
- package/components/Markdown/Markdown/style.ts +152 -0
- package/components/Markdown/demo/basic.tsx +107 -0
- package/components/Markdown/demo/citations.tsx +47 -0
- package/components/Markdown/demo/cursor.tsx +9 -0
- package/components/Markdown/demo/latex.tsx +77 -0
- package/components/Markdown/demo/typing.tsx +82 -0
- package/components/Markdown/index.en-US.md +27 -0
- package/components/Markdown/index.ts +1 -0
- package/components/Markdown/index.zh-CN.md +28 -0
- package/components/Markdown/plugins/citations/CitationComponent.tsx +72 -0
- package/components/Markdown/plugins/citations/index.tsx +37 -0
- package/components/Markdown/plugins/cursor/Dot.tsx +106 -0
- package/components/Markdown/plugins/cursor/Underline.tsx +38 -0
- package/components/Markdown/plugins/cursor/index.tsx +59 -0
- package/components/Markdown/plugins/latex/index.ts +109 -0
- package/components/Markdown/plugins/type.ts +71 -0
- package/components/Mermaid/demo/basic.tsx +12 -0
- package/components/Mermaid/demo/class.tsx +31 -0
- package/components/Mermaid/demo/flowchart.tsx +13 -0
- package/components/Mermaid/demo/sequence.tsx +18 -0
- package/components/Mermaid/demo/state.tsx +16 -0
- package/components/Mermaid/demo/timeline.tsx +15 -0
- package/components/Mermaid/index.en-US.md +27 -0
- package/components/Mermaid/index.tsx +118 -0
- package/components/Mermaid/index.zh-CN.md +27 -0
- package/components/OperateCard/OperateCard.tsx +93 -0
- package/components/OperateCard/demo/index.tsx +35 -0
- package/components/OperateCard/demo/rag.tsx +19 -0
- package/components/OperateCard/demo/thinking.tsx +17 -0
- package/components/OperateCard/demo/todo.tsx +28 -0
- package/components/OperateCard/demo/toolCall.tsx +14 -0
- package/components/OperateCard/demo/webSearch.tsx +12 -0
- package/components/OperateCard/index.en-US.md +51 -0
- package/components/OperateCard/index.tsx +1 -0
- package/components/OperateCard/index.zh-CN.md +51 -0
- package/components/OperateCard/preset/Rag.tsx +90 -0
- package/components/OperateCard/preset/Thinking.tsx +45 -0
- package/components/OperateCard/preset/TodoList.tsx +73 -0
- package/components/OperateCard/preset/ToolCall.tsx +67 -0
- package/components/OperateCard/preset/WebSearch.tsx +65 -0
- package/components/OperateCard/preset/index.tsx +5 -0
- package/components/OperateCard/style.ts +268 -0
- package/components/Provider/CustomCardsProvider.tsx +17 -0
- package/components/Provider/GlobalProvider.tsx +17 -0
- package/components/Provider/index.tsx +33 -0
- package/components/Provider/types.ts +23 -0
- package/components/ResponsesAPI/index.tsx +0 -0
- package/components/Sender/ModeSelect/index.tsx +160 -0
- package/components/Sender/ModeSelect/styles.ts +0 -0
- package/components/Sender/SenderHeader.tsx +164 -0
- package/components/Sender/StopLoading.tsx +48 -0
- package/components/Sender/components/ActionButton.tsx +106 -0
- package/components/Sender/components/ClearButton.tsx +10 -0
- package/components/Sender/components/LoadingButton.tsx +26 -0
- package/components/Sender/components/SendButton.tsx +22 -0
- package/components/Sender/components/SpeechButton/RecordingIcon.tsx +68 -0
- package/components/Sender/components/SpeechButton/index.tsx +30 -0
- package/components/Sender/demo/asr.tsx +7 -0
- package/components/Sender/demo/basic.tsx +7 -0
- package/components/Sender/demo/loading.tsx +5 -0
- package/components/Sender/demo/moreMode.tsx +45 -0
- package/components/Sender/demo/morePrefixAction.tsx +40 -0
- package/components/Sender/demo/withFile.tsx +54 -0
- package/components/Sender/demo/withImage.tsx +52 -0
- package/components/Sender/index.en-US.md +29 -0
- package/components/Sender/index.tsx +491 -0
- package/components/Sender/index.zh-CN.md +30 -0
- package/components/Sender/style/index.ts +150 -0
- package/components/Sender/useSpeech.ts +133 -0
- package/components/StatusCard/demo/index.tsx +32 -0
- package/components/StatusCard/index.en-US.md +30 -0
- package/components/StatusCard/index.tsx +162 -0
- package/components/StatusCard/index.zh-CN.md +27 -0
- package/components/StatusCard/style.ts +119 -0
- package/components/Stream/index.ts +203 -0
- package/components/Util/hooks/use-proxy-imperative-handle.ts +25 -0
- package/components/Util/sleep.ts +3 -0
- package/components/Util/type.ts +1 -0
- package/components/Util/warning.ts +118 -0
- package/components/Version/index.ts +3 -0
- package/components/Voice/Recorder.tsx +3 -0
- package/components/Voice/demo/index.tsx +0 -0
- package/components/Voice/index.en-US.md +8 -0
- package/components/Voice/index.tsx +0 -0
- package/components/Voice/index.zh-CN.md +9 -0
- package/components/Welcome/demo/EyeFollower.tsx +161 -0
- package/components/Welcome/demo/demo0.tsx +14 -0
- package/components/Welcome/demo/demo1.tsx +16 -0
- package/components/Welcome/demo/demo2.tsx +30 -0
- package/components/Welcome/demo/demo3.tsx +16 -0
- package/components/Welcome/index.en-US.md +28 -0
- package/components/Welcome/index.tsx +72 -0
- package/components/Welcome/index.zh-CN.md +28 -0
- package/components/index.ts +88 -0
- package/components/overview.en-US.md +10 -0
- package/components/overview.zh-CN.md +10 -0
- package/lib/AgentScopeRuntimeWebUI/index.d.ts +1 -0
- package/lib/AgentScopeRuntimeWebUI/index.js +1 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.d.ts +9 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.js +33 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.d.ts +7 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.js +188 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.d.ts +29 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.js +35 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.d.ts +6 -0
- package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.js +49 -0
- package/lib/AgentScopeRuntimeWebUI/starter/index.d.ts +1 -0
- package/lib/AgentScopeRuntimeWebUI/starter/index.js +70 -0
- package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.d.ts +14 -0
- package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.js +143 -0
- package/package.json +3 -2
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
import { useLangGraphInterruptRender } from "@copilotkit/react-core";
|
|
6
|
+
import { Bubble } from "@agentscope-ai/chat";
|
|
7
|
+
|
|
8
|
+
export const Messages = ({
|
|
9
|
+
messages,
|
|
10
|
+
inProgress,
|
|
11
|
+
children,
|
|
12
|
+
RenderTextMessage,
|
|
13
|
+
RenderActionExecutionMessage,
|
|
14
|
+
RenderAgentStateMessage,
|
|
15
|
+
RenderResultMessage,
|
|
16
|
+
RenderImageMessage,
|
|
17
|
+
AssistantMessage,
|
|
18
|
+
UserMessage,
|
|
19
|
+
onRegenerate,
|
|
20
|
+
onCopy,
|
|
21
|
+
onThumbsUp,
|
|
22
|
+
onThumbsDown,
|
|
23
|
+
markdownTagRenderers,
|
|
24
|
+
}: MessagesProps) => {
|
|
25
|
+
const actionResults: Record<string, string> = {};
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < messages.length; i++) {
|
|
28
|
+
if (messages[i].isActionExecutionMessage()) {
|
|
29
|
+
const id = messages[i].id;
|
|
30
|
+
const resultMessage: ResultMessage | undefined = messages.find(
|
|
31
|
+
(message) => message.isResultMessage() && message.actionExecutionId === id,
|
|
32
|
+
) as ResultMessage | undefined;
|
|
33
|
+
|
|
34
|
+
if (resultMessage) {
|
|
35
|
+
actionResults[id] = ResultMessage.decodeResult(resultMessage.result || "");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
return <Bubble.List
|
|
42
|
+
style={{ height: 0, flex: 1, }}
|
|
43
|
+
>
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
messages.map((message, index) => {
|
|
47
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
48
|
+
|
|
49
|
+
if (message.isTextMessage()) {
|
|
50
|
+
return (
|
|
51
|
+
<RenderTextMessage
|
|
52
|
+
key={message.id}
|
|
53
|
+
message={message}
|
|
54
|
+
inProgress={inProgress}
|
|
55
|
+
index={index}
|
|
56
|
+
isCurrentMessage={isCurrentMessage}
|
|
57
|
+
AssistantMessage={AssistantMessage}
|
|
58
|
+
UserMessage={UserMessage}
|
|
59
|
+
onRegenerate={onRegenerate}
|
|
60
|
+
onCopy={onCopy}
|
|
61
|
+
onThumbsUp={onThumbsUp}
|
|
62
|
+
onThumbsDown={onThumbsDown}
|
|
63
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
} else if (message.isActionExecutionMessage()) {
|
|
67
|
+
return (
|
|
68
|
+
<RenderActionExecutionMessage
|
|
69
|
+
key={index}
|
|
70
|
+
message={message}
|
|
71
|
+
inProgress={inProgress}
|
|
72
|
+
index={index}
|
|
73
|
+
isCurrentMessage={isCurrentMessage}
|
|
74
|
+
actionResult={actionResults[message.id]}
|
|
75
|
+
AssistantMessage={AssistantMessage}
|
|
76
|
+
UserMessage={UserMessage}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
return null;
|
|
84
|
+
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
</Bubble.List>
|
|
88
|
+
|
|
89
|
+
// return (
|
|
90
|
+
// <div className="copilotKitMessages" ref={messagesContainerRef}>
|
|
91
|
+
// <div className="copilotKitMessagesContainer">
|
|
92
|
+
// {messages.map((message, index) => {
|
|
93
|
+
// const isCurrentMessage = index === messages.length - 1;
|
|
94
|
+
|
|
95
|
+
// if (message.isTextMessage()) {
|
|
96
|
+
// return (
|
|
97
|
+
// <RenderTextMessage
|
|
98
|
+
// key={index}
|
|
99
|
+
// message={message}
|
|
100
|
+
// inProgress={inProgress}
|
|
101
|
+
// index={index}
|
|
102
|
+
// isCurrentMessage={isCurrentMessage}
|
|
103
|
+
// AssistantMessage={AssistantMessage}
|
|
104
|
+
// UserMessage={UserMessage}
|
|
105
|
+
// onRegenerate={onRegenerate}
|
|
106
|
+
// onCopy={onCopy}
|
|
107
|
+
// onThumbsUp={onThumbsUp}
|
|
108
|
+
// onThumbsDown={onThumbsDown}
|
|
109
|
+
// markdownTagRenderers={markdownTagRenderers}
|
|
110
|
+
// />
|
|
111
|
+
// );
|
|
112
|
+
// } else if (message.isActionExecutionMessage()) {
|
|
113
|
+
// return (
|
|
114
|
+
// <RenderActionExecutionMessage
|
|
115
|
+
// key={index}
|
|
116
|
+
// message={message}
|
|
117
|
+
// inProgress={inProgress}
|
|
118
|
+
// index={index}
|
|
119
|
+
// isCurrentMessage={isCurrentMessage}
|
|
120
|
+
// actionResult={actionResults[message.id]}
|
|
121
|
+
// AssistantMessage={AssistantMessage}
|
|
122
|
+
// UserMessage={UserMessage}
|
|
123
|
+
// />
|
|
124
|
+
// );
|
|
125
|
+
// } else if (message.isAgentStateMessage()) {
|
|
126
|
+
// return (
|
|
127
|
+
// <RenderAgentStateMessage
|
|
128
|
+
// key={index}
|
|
129
|
+
// message={message}
|
|
130
|
+
// inProgress={inProgress}
|
|
131
|
+
// index={index}
|
|
132
|
+
// isCurrentMessage={isCurrentMessage}
|
|
133
|
+
// AssistantMessage={AssistantMessage}
|
|
134
|
+
// UserMessage={UserMessage}
|
|
135
|
+
// />
|
|
136
|
+
// );
|
|
137
|
+
// } else if (message.isResultMessage()) {
|
|
138
|
+
// return (
|
|
139
|
+
// <RenderResultMessage
|
|
140
|
+
// key={index}
|
|
141
|
+
// message={message}
|
|
142
|
+
// inProgress={inProgress}
|
|
143
|
+
// index={index}
|
|
144
|
+
// isCurrentMessage={isCurrentMessage}
|
|
145
|
+
// AssistantMessage={AssistantMessage}
|
|
146
|
+
// UserMessage={UserMessage}
|
|
147
|
+
// />
|
|
148
|
+
// );
|
|
149
|
+
// } else if (message.isImageMessage && message.isImageMessage()) {
|
|
150
|
+
// return (
|
|
151
|
+
// <RenderImageMessage
|
|
152
|
+
// key={index}
|
|
153
|
+
// message={message}
|
|
154
|
+
// inProgress={inProgress}
|
|
155
|
+
// index={index}
|
|
156
|
+
// isCurrentMessage={isCurrentMessage}
|
|
157
|
+
// AssistantMessage={AssistantMessage}
|
|
158
|
+
// UserMessage={UserMessage}
|
|
159
|
+
// onRegenerate={onRegenerate}
|
|
160
|
+
// onCopy={onCopy}
|
|
161
|
+
// onThumbsUp={onThumbsUp}
|
|
162
|
+
// onThumbsDown={onThumbsDown}
|
|
163
|
+
// />
|
|
164
|
+
// );
|
|
165
|
+
// }
|
|
166
|
+
// })}
|
|
167
|
+
// {interrupt}
|
|
168
|
+
// </div>
|
|
169
|
+
|
|
170
|
+
// </div>
|
|
171
|
+
// );
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function makeInitialMessages(initial?: string | string[]): Message[] {
|
|
175
|
+
let initialArray: string[] = [];
|
|
176
|
+
if (initial) {
|
|
177
|
+
if (Array.isArray(initial)) {
|
|
178
|
+
initialArray.push(...initial);
|
|
179
|
+
} else {
|
|
180
|
+
initialArray.push(initial);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return initialArray.map(
|
|
185
|
+
(message) =>
|
|
186
|
+
new TextMessage({
|
|
187
|
+
role: Role.Assistant,
|
|
188
|
+
content: message,
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function useScrollToBottom(messages: any[]) {
|
|
194
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
195
|
+
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
196
|
+
const isProgrammaticScrollRef = useRef(false);
|
|
197
|
+
const isUserScrollUpRef = useRef(false);
|
|
198
|
+
|
|
199
|
+
const scrollToBottom = () => {
|
|
200
|
+
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
201
|
+
isProgrammaticScrollRef.current = true;
|
|
202
|
+
messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const handleScroll = () => {
|
|
207
|
+
if (isProgrammaticScrollRef.current) {
|
|
208
|
+
isProgrammaticScrollRef.current = false;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (messagesContainerRef.current) {
|
|
213
|
+
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
214
|
+
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
const container = messagesContainerRef.current;
|
|
220
|
+
if (container) {
|
|
221
|
+
container.addEventListener("scroll", handleScroll);
|
|
222
|
+
}
|
|
223
|
+
return () => {
|
|
224
|
+
if (container) {
|
|
225
|
+
container.removeEventListener("scroll", handleScroll);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
const container = messagesContainerRef.current;
|
|
232
|
+
if (!container) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const mutationObserver = new MutationObserver(() => {
|
|
237
|
+
if (!isUserScrollUpRef.current) {
|
|
238
|
+
scrollToBottom();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
mutationObserver.observe(container, {
|
|
243
|
+
childList: true,
|
|
244
|
+
subtree: true,
|
|
245
|
+
characterData: true,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return () => {
|
|
249
|
+
mutationObserver.disconnect();
|
|
250
|
+
};
|
|
251
|
+
}, []);
|
|
252
|
+
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
isUserScrollUpRef.current = false;
|
|
255
|
+
scrollToBottom();
|
|
256
|
+
}, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);
|
|
257
|
+
|
|
258
|
+
return { messagesEndRef, messagesContainerRef };
|
|
259
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React, { useMemo } 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 { CopilotChat, CopilotChatProps } from "./Chat";
|
|
10
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./messages/AssistantMessage";
|
|
11
|
+
import { UserMessage as DefaultUserMessage } from "./messages/UserMessage";
|
|
12
|
+
|
|
13
|
+
export interface CopilotModalProps extends CopilotChatProps {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the chat window should be open by default.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If the chat window should close when the user clicks outside of it.
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
clickOutsideToClose?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* If the chat window should close when the user hits the Escape key.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
hitEscapeToClose?: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The shortcut key to open the chat window.
|
|
34
|
+
* Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.
|
|
35
|
+
* @default '/'
|
|
36
|
+
*/
|
|
37
|
+
shortcut?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A callback that gets called when the chat window opens or closes.
|
|
41
|
+
*/
|
|
42
|
+
onSetOpen?: (open: boolean) => void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A custom Window component to use instead of the default.
|
|
46
|
+
*/
|
|
47
|
+
Window?: React.ComponentType<WindowProps>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A custom Button component to use instead of the default.
|
|
51
|
+
*/
|
|
52
|
+
Button?: React.ComponentType<ButtonProps>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A custom Header component to use instead of the default.
|
|
56
|
+
*/
|
|
57
|
+
Header?: React.ComponentType<HeaderProps>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const CopilotModal = ({
|
|
61
|
+
instructions,
|
|
62
|
+
defaultOpen = false,
|
|
63
|
+
clickOutsideToClose = true,
|
|
64
|
+
hitEscapeToClose = true,
|
|
65
|
+
onSetOpen,
|
|
66
|
+
onSubmitMessage,
|
|
67
|
+
onStopGeneration,
|
|
68
|
+
onReloadMessages,
|
|
69
|
+
shortcut = "/",
|
|
70
|
+
icons,
|
|
71
|
+
labels,
|
|
72
|
+
makeSystemMessage,
|
|
73
|
+
onInProgress,
|
|
74
|
+
Window = DefaultWindow,
|
|
75
|
+
Button = DefaultButton,
|
|
76
|
+
Header = DefaultHeader,
|
|
77
|
+
Messages = DefaultMessages,
|
|
78
|
+
Input = DefaultInput,
|
|
79
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
80
|
+
UserMessage = DefaultUserMessage,
|
|
81
|
+
onThumbsUp,
|
|
82
|
+
onThumbsDown,
|
|
83
|
+
onCopy,
|
|
84
|
+
onRegenerate,
|
|
85
|
+
markdownTagRenderers,
|
|
86
|
+
className,
|
|
87
|
+
children,
|
|
88
|
+
...props
|
|
89
|
+
}: CopilotModalProps) => {
|
|
90
|
+
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
91
|
+
|
|
92
|
+
const setOpen = (open: boolean) => {
|
|
93
|
+
onSetOpen?.(open);
|
|
94
|
+
setOpenState(open);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const memoizedHeader = useMemo(() => <Header />, [Header]);
|
|
98
|
+
const memoizedChildren = useMemo(() => children, [children]);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<ChatContextProvider icons={icons} labels={labels} open={openState} setOpen={setOpen}>
|
|
102
|
+
{memoizedChildren}
|
|
103
|
+
<div className={className}>
|
|
104
|
+
<Button></Button>
|
|
105
|
+
<Window
|
|
106
|
+
clickOutsideToClose={clickOutsideToClose}
|
|
107
|
+
shortcut={shortcut}
|
|
108
|
+
hitEscapeToClose={hitEscapeToClose}
|
|
109
|
+
>
|
|
110
|
+
{memoizedHeader}
|
|
111
|
+
<CopilotChat
|
|
112
|
+
{...props}
|
|
113
|
+
instructions={instructions}
|
|
114
|
+
onSubmitMessage={onSubmitMessage}
|
|
115
|
+
onStopGeneration={onStopGeneration}
|
|
116
|
+
onReloadMessages={onReloadMessages}
|
|
117
|
+
makeSystemMessage={makeSystemMessage}
|
|
118
|
+
onInProgress={onInProgress}
|
|
119
|
+
Messages={Messages}
|
|
120
|
+
Input={Input}
|
|
121
|
+
AssistantMessage={AssistantMessage}
|
|
122
|
+
UserMessage={UserMessage}
|
|
123
|
+
onThumbsUp={onThumbsUp}
|
|
124
|
+
onThumbsDown={onThumbsDown}
|
|
125
|
+
onCopy={onCopy}
|
|
126
|
+
onRegenerate={onRegenerate}
|
|
127
|
+
markdownTagRenderers={markdownTagRenderers}
|
|
128
|
+
/>
|
|
129
|
+
</Window>
|
|
130
|
+
</div>
|
|
131
|
+
</ChatContextProvider>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -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,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useDarkMode } from "../../hooks/use-dark-mode";
|
|
3
|
+
|
|
4
|
+
export function PoweredByTag({ showPoweredBy = true }: { showPoweredBy?: boolean }) {
|
|
5
|
+
const isDark = useDarkMode();
|
|
6
|
+
|
|
7
|
+
if (!showPoweredBy) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const poweredByStyle = {
|
|
12
|
+
visibility: "visible",
|
|
13
|
+
display: "block",
|
|
14
|
+
position: "static",
|
|
15
|
+
textAlign: "center",
|
|
16
|
+
fontSize: "12px",
|
|
17
|
+
padding: "3px 0",
|
|
18
|
+
color: isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
{/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}
|
|
24
|
+
<p className="poweredBy" style={poweredByStyle}>
|
|
25
|
+
Powered by CopilotKit
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CopilotContextParams,
|
|
3
|
+
extract,
|
|
4
|
+
CopilotChatSuggestionConfiguration,
|
|
5
|
+
CopilotMessagesContextParams,
|
|
6
|
+
} from "@copilotkit/react-core";
|
|
7
|
+
import { SmallSpinnerIcon } from "./Icons";
|
|
8
|
+
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
9
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
10
|
+
import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
|
|
11
|
+
|
|
12
|
+
interface SuggestionsProps {
|
|
13
|
+
title: string;
|
|
14
|
+
message: string;
|
|
15
|
+
partial?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
onClick: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Suggestion({ title, onClick, partial, className }: SuggestionsProps) {
|
|
21
|
+
return (
|
|
22
|
+
<button
|
|
23
|
+
disabled={partial}
|
|
24
|
+
onClick={(e) => {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
onClick();
|
|
27
|
+
}}
|
|
28
|
+
className={className || (partial ? "suggestion loading" : "suggestion")}
|
|
29
|
+
data-test-id="suggestion"
|
|
30
|
+
>
|
|
31
|
+
{partial ? SmallSpinnerIcon : <span>{title}</span>}
|
|
32
|
+
</button>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const reloadSuggestions = async (
|
|
37
|
+
context: CopilotContextParams & CopilotMessagesContextParams,
|
|
38
|
+
chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
|
|
39
|
+
setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,
|
|
40
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
41
|
+
) => {
|
|
42
|
+
const abortController = abortControllerRef.current;
|
|
43
|
+
|
|
44
|
+
const tools = JSON.stringify(
|
|
45
|
+
Object.values(context.actions).map((action) => ({
|
|
46
|
+
name: action.name,
|
|
47
|
+
description: action.description,
|
|
48
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
|
|
49
|
+
})),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const allSuggestions: CopilotChatSuggestion[] = [];
|
|
53
|
+
|
|
54
|
+
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
55
|
+
try {
|
|
56
|
+
const numOfSuggestionsInstructions =
|
|
57
|
+
config.minSuggestions === 0
|
|
58
|
+
? `Produce up to ${config.maxSuggestions} suggestions. ` +
|
|
59
|
+
`If there are no highly relevant suggestions you can think of, provide an empty array.`
|
|
60
|
+
: `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
61
|
+
|
|
62
|
+
const result = await extract({
|
|
63
|
+
context,
|
|
64
|
+
instructions:
|
|
65
|
+
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
66
|
+
data:
|
|
67
|
+
config.instructions +
|
|
68
|
+
"\n\n" +
|
|
69
|
+
numOfSuggestionsInstructions +
|
|
70
|
+
"\n\n" +
|
|
71
|
+
"Available tools: " +
|
|
72
|
+
tools +
|
|
73
|
+
"\n\n",
|
|
74
|
+
requestType: CopilotRequestType.Task,
|
|
75
|
+
parameters: [
|
|
76
|
+
{
|
|
77
|
+
name: "suggestions",
|
|
78
|
+
type: "object[]",
|
|
79
|
+
attributes: [
|
|
80
|
+
{
|
|
81
|
+
name: "title",
|
|
82
|
+
description:
|
|
83
|
+
"The title of the suggestion. This is shown as a button and should be short.",
|
|
84
|
+
type: "string",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "message",
|
|
88
|
+
description:
|
|
89
|
+
"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
90
|
+
type: "string",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
include: {
|
|
96
|
+
messages: true,
|
|
97
|
+
readable: true,
|
|
98
|
+
},
|
|
99
|
+
abortSignal: abortController?.signal,
|
|
100
|
+
stream: ({ status, args }) => {
|
|
101
|
+
const suggestions = args.suggestions || [];
|
|
102
|
+
const newSuggestions: CopilotChatSuggestion[] = [];
|
|
103
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
104
|
+
// if GPT provides too many suggestions, limit the number of suggestions
|
|
105
|
+
if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
const { title, message } = suggestions[i];
|
|
109
|
+
|
|
110
|
+
// If this is the last suggestion and the status is not complete, mark it as partial
|
|
111
|
+
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
112
|
+
|
|
113
|
+
newSuggestions.push({
|
|
114
|
+
title,
|
|
115
|
+
message,
|
|
116
|
+
partial,
|
|
117
|
+
className: config.className,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
allSuggestions.push(...result.suggestions);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error("Error loading suggestions", error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (abortControllerRef.current === abortController) {
|
|
130
|
+
abortControllerRef.current = null;
|
|
131
|
+
}
|
|
132
|
+
};
|