@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,20 @@
|
|
|
1
|
+
import { Suggestion } from "./Suggestion";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { RenderSuggestionsListProps } from "./props";
|
|
4
|
+
|
|
5
|
+
export function Suggestions({ suggestions, onSuggestionClick }: RenderSuggestionsListProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div className="suggestions">
|
|
8
|
+
{suggestions.map((suggestion, index) => (
|
|
9
|
+
<Suggestion
|
|
10
|
+
key={index}
|
|
11
|
+
title={suggestion.title}
|
|
12
|
+
message={suggestion.message}
|
|
13
|
+
partial={suggestion.partial}
|
|
14
|
+
className={suggestion.className}
|
|
15
|
+
onClick={() => onSuggestionClick(suggestion.message)}
|
|
16
|
+
/>
|
|
17
|
+
))}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from "react";
|
|
2
|
+
|
|
3
|
+
interface AutoResizingTextareaProps {
|
|
4
|
+
maxRows?: number;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
value: string;
|
|
7
|
+
onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
8
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
9
|
+
autoFocus?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(
|
|
13
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
14
|
+
const internalTextareaRef = useRef<HTMLTextAreaElement>(null);
|
|
15
|
+
const [maxHeight, setMaxHeight] = useState<number>(0);
|
|
16
|
+
|
|
17
|
+
useImperativeHandle(ref, () => internalTextareaRef.current as HTMLTextAreaElement);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const calculateMaxHeight = () => {
|
|
21
|
+
const textarea = internalTextareaRef.current;
|
|
22
|
+
if (textarea) {
|
|
23
|
+
textarea.style.height = "auto";
|
|
24
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
25
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
26
|
+
if (autoFocus) {
|
|
27
|
+
textarea.focus();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
calculateMaxHeight();
|
|
33
|
+
}, [maxRows]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const textarea = internalTextareaRef.current;
|
|
37
|
+
if (textarea) {
|
|
38
|
+
textarea.style.height = "auto";
|
|
39
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
40
|
+
}
|
|
41
|
+
}, [value, maxHeight]);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<textarea
|
|
45
|
+
ref={internalTextareaRef}
|
|
46
|
+
value={value}
|
|
47
|
+
onChange={onChange}
|
|
48
|
+
onKeyDown={onKeyDown}
|
|
49
|
+
placeholder={placeholder}
|
|
50
|
+
style={{
|
|
51
|
+
overflow: "auto",
|
|
52
|
+
resize: "none",
|
|
53
|
+
maxHeight: `${maxHeight}px`,
|
|
54
|
+
}}
|
|
55
|
+
rows={1}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export default AutoResizingTextarea;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, { useCallback, useEffect } from "react";
|
|
2
|
+
import { WindowProps } from "./props";
|
|
3
|
+
import { useChatContext } from "./ChatContext";
|
|
4
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
5
|
+
import { isMacOS } from "@copilotkit/shared";
|
|
6
|
+
|
|
7
|
+
export const Window = ({
|
|
8
|
+
children,
|
|
9
|
+
clickOutsideToClose,
|
|
10
|
+
shortcut,
|
|
11
|
+
hitEscapeToClose,
|
|
12
|
+
}: WindowProps) => {
|
|
13
|
+
const windowRef = React.useRef<HTMLDivElement>(null);
|
|
14
|
+
const context = useCopilotContext();
|
|
15
|
+
|
|
16
|
+
const { open, setOpen } = useChatContext();
|
|
17
|
+
|
|
18
|
+
const handleClickOutside = useCallback(
|
|
19
|
+
(event: MouseEvent) => {
|
|
20
|
+
if (!clickOutsideToClose) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const parentElement = windowRef.current?.parentElement;
|
|
25
|
+
|
|
26
|
+
let className = "";
|
|
27
|
+
if (event.target instanceof HTMLElement) {
|
|
28
|
+
className = event.target.className;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
open &&
|
|
33
|
+
parentElement &&
|
|
34
|
+
!parentElement.contains(event.target as any) &&
|
|
35
|
+
// prevent closing the window when clicking on the debug menu
|
|
36
|
+
!className.includes("copilotKitDebugMenu")
|
|
37
|
+
) {
|
|
38
|
+
setOpen(false);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
[clickOutsideToClose, open, setOpen],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const handleKeyDown = useCallback(
|
|
45
|
+
(event: KeyboardEvent) => {
|
|
46
|
+
const target = event.target as HTMLElement;
|
|
47
|
+
const isInput =
|
|
48
|
+
target.tagName === "INPUT" ||
|
|
49
|
+
target.tagName === "SELECT" ||
|
|
50
|
+
target.tagName === "TEXTAREA" ||
|
|
51
|
+
target.isContentEditable;
|
|
52
|
+
|
|
53
|
+
const isDescendantOfWrapper = windowRef.current?.contains(target);
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
open &&
|
|
57
|
+
event.key === "Escape" &&
|
|
58
|
+
(!isInput || isDescendantOfWrapper) &&
|
|
59
|
+
hitEscapeToClose
|
|
60
|
+
) {
|
|
61
|
+
setOpen(false);
|
|
62
|
+
} else if (
|
|
63
|
+
event.key === shortcut &&
|
|
64
|
+
((isMacOS() && event.metaKey) || (!isMacOS() && event.ctrlKey)) &&
|
|
65
|
+
(!isInput || isDescendantOfWrapper)
|
|
66
|
+
) {
|
|
67
|
+
setOpen(!open);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[hitEscapeToClose, shortcut, open, setOpen],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const adjustForMobile = useCallback(() => {
|
|
74
|
+
const copilotKitWindow = windowRef.current;
|
|
75
|
+
const vv = window.visualViewport;
|
|
76
|
+
if (!copilotKitWindow || !vv) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (window.innerWidth < 640 && open) {
|
|
81
|
+
copilotKitWindow.style.height = `${vv.height}px`;
|
|
82
|
+
copilotKitWindow.style.left = `${vv.offsetLeft}px`;
|
|
83
|
+
copilotKitWindow.style.top = `${vv.offsetTop}px`;
|
|
84
|
+
|
|
85
|
+
document.body.style.position = "fixed";
|
|
86
|
+
document.body.style.width = "100%";
|
|
87
|
+
document.body.style.height = `${window.innerHeight}px`;
|
|
88
|
+
document.body.style.overflow = "hidden";
|
|
89
|
+
document.body.style.touchAction = "none";
|
|
90
|
+
|
|
91
|
+
// Prevent scrolling on iOS
|
|
92
|
+
document.body.addEventListener("touchmove", preventScroll, {
|
|
93
|
+
passive: false,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
copilotKitWindow.style.height = "";
|
|
97
|
+
copilotKitWindow.style.left = "";
|
|
98
|
+
copilotKitWindow.style.top = "";
|
|
99
|
+
document.body.style.position = "";
|
|
100
|
+
document.body.style.height = "";
|
|
101
|
+
document.body.style.width = "";
|
|
102
|
+
document.body.style.overflow = "";
|
|
103
|
+
document.body.style.top = "";
|
|
104
|
+
document.body.style.touchAction = "";
|
|
105
|
+
|
|
106
|
+
document.body.removeEventListener("touchmove", preventScroll);
|
|
107
|
+
}
|
|
108
|
+
}, [open]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
112
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
113
|
+
if (window.visualViewport) {
|
|
114
|
+
window.visualViewport.addEventListener("resize", adjustForMobile);
|
|
115
|
+
adjustForMobile();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return () => {
|
|
119
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
120
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
121
|
+
if (window.visualViewport) {
|
|
122
|
+
window.visualViewport.removeEventListener("resize", adjustForMobile);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}, [adjustForMobile, handleClickOutside, handleKeyDown]);
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div className={`copilotKitWindow ${open ? " open" : ""}`} ref={windowRef}>
|
|
129
|
+
{children}
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const preventScroll = (event: TouchEvent): void => {
|
|
135
|
+
let targetElement = event.target as Element;
|
|
136
|
+
|
|
137
|
+
// Function to check if the target has the parent with a given class
|
|
138
|
+
const hasParentWithClass = (element: Element, className: string): boolean => {
|
|
139
|
+
while (element && element !== document.body) {
|
|
140
|
+
if (element.classList.contains(className)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
element = element.parentElement!;
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// Check if the target of the touch event is inside an element with the 'copilotKitMessages' class
|
|
149
|
+
if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./props";
|
|
2
|
+
export { CopilotPopup } from "./Popup";
|
|
3
|
+
export { CopilotSidebar } from "./Sidebar";
|
|
4
|
+
export { CopilotChat } from "./Chat";
|
|
5
|
+
export { Markdown } from "./Markdown";
|
|
6
|
+
export { AssistantMessage } from "./messages/AssistantMessage";
|
|
7
|
+
export { UserMessage } from "./messages/UserMessage";
|
|
8
|
+
export { useChatContext } from "./ChatContext";
|
|
9
|
+
export { RenderImageMessage } from "./messages/RenderImageMessage";
|
|
10
|
+
export { Suggestions as RenderSuggestionsList } from "./Suggestions";
|
|
11
|
+
export { Suggestion as RenderSuggestion } from "./Suggestion";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AssistantMessageProps } from "../props";
|
|
2
|
+
import { Bubble } from "@agentscope-ai/chat";
|
|
3
|
+
import compact from 'lodash/compact'
|
|
4
|
+
|
|
5
|
+
export const AssistantMessage = (props: AssistantMessageProps) => {
|
|
6
|
+
if (props.subComponent) return props.subComponent;
|
|
7
|
+
|
|
8
|
+
const hasThink = props.rawData.content?.includes('<think>');
|
|
9
|
+
const msgStatus = props.isCurrentMessage && props.isGenerating ? "generating" : void 0;
|
|
10
|
+
|
|
11
|
+
if (!hasThink) return <Bubble
|
|
12
|
+
role="assistant"
|
|
13
|
+
content={props.rawData.content}
|
|
14
|
+
id={props.rawData.id}
|
|
15
|
+
msgStatus={msgStatus}
|
|
16
|
+
></Bubble>;
|
|
17
|
+
|
|
18
|
+
const hasThinkEnd = props.rawData.content.includes('</think>');
|
|
19
|
+
|
|
20
|
+
const { content, think } = parseThinkContentIf(props.rawData.content);
|
|
21
|
+
|
|
22
|
+
return <Bubble
|
|
23
|
+
role="assistant"
|
|
24
|
+
cards={compact([
|
|
25
|
+
hasThink && {
|
|
26
|
+
code: 'DeepThink',
|
|
27
|
+
data: {
|
|
28
|
+
title: 'AI思考',
|
|
29
|
+
loading: !hasThinkEnd,
|
|
30
|
+
content: think,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
code: 'Text',
|
|
35
|
+
data: {
|
|
36
|
+
content: content,
|
|
37
|
+
msgStatus: msgStatus
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
])}
|
|
41
|
+
id={props.rawData.id}
|
|
42
|
+
msgStatus={msgStatus}
|
|
43
|
+
></Bubble>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function parseThinkContentIf(content) {
|
|
47
|
+
const reg0 = /<think>([\s\S]*?)<\/think>/g;
|
|
48
|
+
const reg1 = /<think>([\s\S]*)/g;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const reg0Result = content.match(reg0);
|
|
53
|
+
if (reg0Result) return {
|
|
54
|
+
think: reg0Result[0].replace(/<think>/, '').replace(/<\/think>/g, ''),
|
|
55
|
+
content: content.replace(reg0Result[0], '')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const reg1Result = content.match(reg1);
|
|
59
|
+
|
|
60
|
+
if (reg1Result) return {
|
|
61
|
+
think: reg1Result[0].replace(/<think>/, ''),
|
|
62
|
+
content: content.replace(reg1Result[0], '')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
think: '',
|
|
67
|
+
content
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { MessageStatusCode } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import { RenderMessageProps } from "../props";
|
|
3
|
+
import { RenderFunctionStatus, useCopilotContext } from "@copilotkit/react-core";
|
|
4
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
|
|
5
|
+
|
|
6
|
+
export function RenderActionExecutionMessage({
|
|
7
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
8
|
+
...props
|
|
9
|
+
}: RenderMessageProps) {
|
|
10
|
+
const { chatComponentsCache } = useCopilotContext();
|
|
11
|
+
const { message, inProgress, index, isCurrentMessage, actionResult } = props;
|
|
12
|
+
|
|
13
|
+
if (message.isActionExecutionMessage()) {
|
|
14
|
+
if (
|
|
15
|
+
chatComponentsCache.current !== null &&
|
|
16
|
+
(chatComponentsCache.current.actions[message.name] ||
|
|
17
|
+
chatComponentsCache.current.actions["*"])
|
|
18
|
+
) {
|
|
19
|
+
const render =
|
|
20
|
+
chatComponentsCache.current.actions[message.name] ||
|
|
21
|
+
chatComponentsCache.current.actions["*"];
|
|
22
|
+
// render a static string
|
|
23
|
+
if (typeof render === "string") {
|
|
24
|
+
|
|
25
|
+
// when render is static, we show it only when in progress
|
|
26
|
+
if (isCurrentMessage && inProgress) {
|
|
27
|
+
return (
|
|
28
|
+
<AssistantMessage
|
|
29
|
+
rawData={message}
|
|
30
|
+
key={index}
|
|
31
|
+
data-message-role="assistant"
|
|
32
|
+
isLoading={false}
|
|
33
|
+
isGenerating={true}
|
|
34
|
+
message={render}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
39
|
+
else {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// render is a function
|
|
44
|
+
else {
|
|
45
|
+
const args = message.arguments;
|
|
46
|
+
|
|
47
|
+
let status: RenderFunctionStatus = "inProgress";
|
|
48
|
+
|
|
49
|
+
if (actionResult !== undefined) {
|
|
50
|
+
status = "complete";
|
|
51
|
+
} else if (message.status.code !== MessageStatusCode.Pending) {
|
|
52
|
+
status = "executing";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const toRender = render({
|
|
57
|
+
status: status as any, // Cast to any as RenderFunctionStatus is a union that can be complex to narrow here
|
|
58
|
+
args,
|
|
59
|
+
result: actionResult,
|
|
60
|
+
name: message.name,
|
|
61
|
+
messageId: message.id, // Pass messageId for HITL action correlation
|
|
62
|
+
} as any);
|
|
63
|
+
|
|
64
|
+
// No result and complete: stay silent
|
|
65
|
+
if (!toRender && status === "complete") {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (typeof toRender === "string") {
|
|
69
|
+
return (
|
|
70
|
+
<AssistantMessage
|
|
71
|
+
rawData={message}
|
|
72
|
+
data-message-role="assistant"
|
|
73
|
+
key={index}
|
|
74
|
+
isLoading={false}
|
|
75
|
+
isGenerating={false}
|
|
76
|
+
message={toRender}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
return (
|
|
81
|
+
<AssistantMessage
|
|
82
|
+
rawData={message}
|
|
83
|
+
data-message-role="action-render"
|
|
84
|
+
key={index}
|
|
85
|
+
isLoading={false}
|
|
86
|
+
isGenerating={false}
|
|
87
|
+
subComponent={toRender}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
// It's useful to log this error for developers to debug their custom render functions
|
|
93
|
+
console.error(`Error executing render function for action ${message.name}: ${e}`);
|
|
94
|
+
return (
|
|
95
|
+
<AssistantMessage
|
|
96
|
+
rawData={message}
|
|
97
|
+
data-message-role="assistant"
|
|
98
|
+
key={index}
|
|
99
|
+
isLoading={false}
|
|
100
|
+
isGenerating={false}
|
|
101
|
+
subComponent={
|
|
102
|
+
<div className="copilotKitMessage copilotKitAssistantMessage">
|
|
103
|
+
<b>❌ Error executing render function for action {message.name}:</b>
|
|
104
|
+
<pre>{e instanceof Error ? e.message : String(e)}</pre>
|
|
105
|
+
</div>
|
|
106
|
+
}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// No render function found- show the default message
|
|
113
|
+
else if (!inProgress || !isCurrentMessage) {
|
|
114
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
115
|
+
return null;
|
|
116
|
+
} else {
|
|
117
|
+
// In progress
|
|
118
|
+
return (
|
|
119
|
+
<AssistantMessage
|
|
120
|
+
rawData={message}
|
|
121
|
+
key={index}
|
|
122
|
+
data-message-role="assistant"
|
|
123
|
+
isLoading={true}
|
|
124
|
+
isGenerating={true}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { RenderMessageProps } from "../props";
|
|
2
|
+
import { CoagentInChatRenderFunction, useCopilotContext } from "@copilotkit/react-core";
|
|
3
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
|
|
4
|
+
|
|
5
|
+
export function RenderAgentStateMessage({
|
|
6
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
7
|
+
...props
|
|
8
|
+
}: RenderMessageProps) {
|
|
9
|
+
const { chatComponentsCache } = useCopilotContext();
|
|
10
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
11
|
+
|
|
12
|
+
if (message.isAgentStateMessage()) {
|
|
13
|
+
let render: string | CoagentInChatRenderFunction | undefined;
|
|
14
|
+
|
|
15
|
+
if (chatComponentsCache.current !== null) {
|
|
16
|
+
render =
|
|
17
|
+
chatComponentsCache.current.coAgentStateRenders[
|
|
18
|
+
`${message.agentName}-${message.nodeName}`
|
|
19
|
+
] || chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-global`];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (render) {
|
|
23
|
+
// render a static string
|
|
24
|
+
if (typeof render === "string") {
|
|
25
|
+
// when render is static, we show it only when in progress
|
|
26
|
+
if (isCurrentMessage && inProgress) {
|
|
27
|
+
return (
|
|
28
|
+
<AssistantMessage
|
|
29
|
+
rawData={message}
|
|
30
|
+
message={render}
|
|
31
|
+
data-message-role="assistant"
|
|
32
|
+
key={index}
|
|
33
|
+
isLoading={true}
|
|
34
|
+
isGenerating={true}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
39
|
+
else {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// render is a function
|
|
44
|
+
else {
|
|
45
|
+
const state = message.state;
|
|
46
|
+
|
|
47
|
+
let status = message.active ? "inProgress" : "complete";
|
|
48
|
+
|
|
49
|
+
const toRender = render({
|
|
50
|
+
status: status as any,
|
|
51
|
+
state,
|
|
52
|
+
nodeName: message.nodeName,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// No result and complete: stay silent
|
|
56
|
+
if (!toRender && status === "complete") {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!toRender && isCurrentMessage && inProgress) {
|
|
61
|
+
return (
|
|
62
|
+
<AssistantMessage
|
|
63
|
+
data-message-role="assistant"
|
|
64
|
+
key={index}
|
|
65
|
+
rawData={message}
|
|
66
|
+
isLoading={true}
|
|
67
|
+
isGenerating={true}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
} else if (!toRender) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof toRender === "string") {
|
|
75
|
+
return (
|
|
76
|
+
<AssistantMessage
|
|
77
|
+
rawData={message}
|
|
78
|
+
message={toRender}
|
|
79
|
+
isLoading={true}
|
|
80
|
+
isGenerating={true}
|
|
81
|
+
data-message-role="assistant"
|
|
82
|
+
key={index}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
return (
|
|
87
|
+
<AssistantMessage
|
|
88
|
+
rawData={message}
|
|
89
|
+
data-message-role="agent-state-render"
|
|
90
|
+
key={index}
|
|
91
|
+
isLoading={false}
|
|
92
|
+
isGenerating={false}
|
|
93
|
+
subComponent={toRender}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// No render function found- show the default message
|
|
100
|
+
else if (!inProgress || !isCurrentMessage) {
|
|
101
|
+
// Done - silent by default to avoid a series of "done" messages
|
|
102
|
+
return null;
|
|
103
|
+
} else {
|
|
104
|
+
// In progress
|
|
105
|
+
return (
|
|
106
|
+
<AssistantMessage
|
|
107
|
+
rawData={message}
|
|
108
|
+
isLoading={true}
|
|
109
|
+
isGenerating={true}
|
|
110
|
+
data-message-role="assistant"
|
|
111
|
+
key={index}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { RenderMessageProps } from "../props";
|
|
2
|
+
import { UserMessage as DefaultUserMessage } from "./UserMessage";
|
|
3
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
|
|
4
|
+
|
|
5
|
+
export function RenderImageMessage({
|
|
6
|
+
UserMessage = DefaultUserMessage,
|
|
7
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
8
|
+
...props
|
|
9
|
+
}: RenderMessageProps) {
|
|
10
|
+
const {
|
|
11
|
+
message,
|
|
12
|
+
inProgress,
|
|
13
|
+
index,
|
|
14
|
+
isCurrentMessage,
|
|
15
|
+
onRegenerate,
|
|
16
|
+
onCopy,
|
|
17
|
+
onThumbsUp,
|
|
18
|
+
onThumbsDown,
|
|
19
|
+
} = props;
|
|
20
|
+
|
|
21
|
+
if (message.isImageMessage()) {
|
|
22
|
+
const imageData = `data:${message.format};base64,${message.bytes}`;
|
|
23
|
+
const imageComponent = (
|
|
24
|
+
<div className="copilotKitImage">
|
|
25
|
+
<img
|
|
26
|
+
src={imageData}
|
|
27
|
+
alt="User uploaded image"
|
|
28
|
+
style={{ maxWidth: "100%", maxHeight: "300px", borderRadius: "8px" }}
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (message.role === "user") {
|
|
34
|
+
return (
|
|
35
|
+
<UserMessage
|
|
36
|
+
key={index}
|
|
37
|
+
data-message-role="user"
|
|
38
|
+
message=""
|
|
39
|
+
rawData={message}
|
|
40
|
+
subComponent={imageComponent}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
} else if (message.role === "assistant") {
|
|
44
|
+
return (
|
|
45
|
+
<AssistantMessage
|
|
46
|
+
key={index}
|
|
47
|
+
data-message-role="assistant"
|
|
48
|
+
message=""
|
|
49
|
+
rawData={message}
|
|
50
|
+
subComponent={imageComponent}
|
|
51
|
+
isLoading={inProgress && isCurrentMessage && !message.bytes}
|
|
52
|
+
isGenerating={inProgress && isCurrentMessage && !!message.bytes}
|
|
53
|
+
isCurrentMessage={isCurrentMessage}
|
|
54
|
+
onRegenerate={() => onRegenerate?.(message.id)}
|
|
55
|
+
onCopy={onCopy}
|
|
56
|
+
onThumbsUp={onThumbsUp}
|
|
57
|
+
onThumbsDown={onThumbsDown}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RenderMessageProps } from "../props";
|
|
2
|
+
import { AssistantMessage as DefaultAssistantMessage } from "./AssistantMessage";
|
|
3
|
+
|
|
4
|
+
export function RenderResultMessage({
|
|
5
|
+
AssistantMessage = DefaultAssistantMessage,
|
|
6
|
+
...props
|
|
7
|
+
}: RenderMessageProps) {
|
|
8
|
+
const { message, inProgress, index, isCurrentMessage } = props;
|
|
9
|
+
|
|
10
|
+
if (message.isResultMessage() && inProgress && isCurrentMessage) {
|
|
11
|
+
return (
|
|
12
|
+
<AssistantMessage
|
|
13
|
+
key={index}
|
|
14
|
+
data-message-role="assistant"
|
|
15
|
+
rawData={message}
|
|
16
|
+
isLoading={true}
|
|
17
|
+
isGenerating={true}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Avoid 'Nothing was returned from render' React error
|
|
23
|
+
else {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|