@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,189 @@
|
|
|
1
|
+
import classnames from 'classnames';
|
|
2
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import type { DirectionType } from 'antd/es/config-provider';
|
|
4
|
+
import pickAttrs from 'rc-util/lib/pickAttrs';
|
|
5
|
+
import type { Conversation } from './interface';
|
|
6
|
+
import { SparkMoreLine } from '@agentscope-ai/icons';
|
|
7
|
+
import { Button, IconButton, Popover } from '@agentscope-ai/design';
|
|
8
|
+
|
|
9
|
+
export interface ConversationsItemProps
|
|
10
|
+
extends Omit<React.HTMLAttributes<HTMLLIElement>, 'onClick'> {
|
|
11
|
+
info: Conversation;
|
|
12
|
+
prefixCls?: string;
|
|
13
|
+
direction?: DirectionType;
|
|
14
|
+
menu?: {
|
|
15
|
+
label?: string;
|
|
16
|
+
key?: string;
|
|
17
|
+
icon?: React.ReactNode;
|
|
18
|
+
danger?: boolean;
|
|
19
|
+
onClick?: (info: Conversation) => void;
|
|
20
|
+
onEdit?: (label: string, session: Conversation) => Promise<void>;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}[];
|
|
23
|
+
active?: boolean;
|
|
24
|
+
onClick?: (info: Conversation) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const editableMap = {};
|
|
28
|
+
export function useEditable(id) {
|
|
29
|
+
const [editable, setEditable] = useState(editableMap[id]);
|
|
30
|
+
|
|
31
|
+
return [editable, (value) => {
|
|
32
|
+
for (const key in editableMap) {
|
|
33
|
+
editableMap[key] = false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
editableMap[id] = value;
|
|
37
|
+
setEditable(value);
|
|
38
|
+
}]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const ConversationsItem: React.FC<ConversationsItemProps> = (props) => {
|
|
43
|
+
const [editable, setEditable] = useEditable(props.info.key);
|
|
44
|
+
const [popoverVisible, setPopoverVisible] = useState(false);
|
|
45
|
+
const { prefixCls, info, className, direction, onClick, active, menu, ...restProps } = props;
|
|
46
|
+
const domProps = pickAttrs(restProps, {
|
|
47
|
+
aria: true,
|
|
48
|
+
data: true,
|
|
49
|
+
attr: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const { disabled } = info;
|
|
53
|
+
|
|
54
|
+
const mergedCls = classnames(
|
|
55
|
+
className,
|
|
56
|
+
`${prefixCls}-item`,
|
|
57
|
+
{ [`${prefixCls}-item-active`]: active && !disabled },
|
|
58
|
+
{ [`${prefixCls}-item-disabled`]: disabled },
|
|
59
|
+
{ [`${prefixCls}-item-timeline`]: info.timeline },
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const onInternalClick: React.MouseEventHandler<HTMLLIElement> = () => {
|
|
63
|
+
if (!disabled && onClick) {
|
|
64
|
+
onClick(info);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<li {...domProps} className={mergedCls} onClick={onInternalClick}>
|
|
70
|
+
<div className={`${prefixCls}-content`}>
|
|
71
|
+
{info.icon && <div className={`${prefixCls}-icon`}>{info.icon}</div>}
|
|
72
|
+
{
|
|
73
|
+
info.timeline && <div className={`${prefixCls}-timeline`} />
|
|
74
|
+
}
|
|
75
|
+
<Label
|
|
76
|
+
editable={editable}
|
|
77
|
+
setEditable={setEditable}
|
|
78
|
+
prefixCls={prefixCls}
|
|
79
|
+
info={info}
|
|
80
|
+
onEdit={menu?.find(item => item.key === 'edit')?.onEdit}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
menu && !disabled && (
|
|
85
|
+
<Popover
|
|
86
|
+
styles={{ body: { padding: 4 } }}
|
|
87
|
+
trigger={['click']}
|
|
88
|
+
open={popoverVisible}
|
|
89
|
+
onOpenChange={setPopoverVisible}
|
|
90
|
+
content={<div className={`${prefixCls}-menu-popover`}
|
|
91
|
+
>
|
|
92
|
+
{menu.map(item => {
|
|
93
|
+
const { key, ...rest } = item;
|
|
94
|
+
const _props = {
|
|
95
|
+
...rest,
|
|
96
|
+
onClick: function (e) {
|
|
97
|
+
if (key === 'edit') {
|
|
98
|
+
setEditable(true)
|
|
99
|
+
} else {
|
|
100
|
+
rest.onClick?.(info)
|
|
101
|
+
}
|
|
102
|
+
setPopoverVisible(false);
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return <MenuItem key={key} {..._props} info={info} />
|
|
107
|
+
})}
|
|
108
|
+
</div>} placement='bottom'>
|
|
109
|
+
<IconButton
|
|
110
|
+
bordered={false}
|
|
111
|
+
icon={<SparkMoreLine />}
|
|
112
|
+
disabled={disabled}
|
|
113
|
+
className={`${prefixCls}-menu-icon`}
|
|
114
|
+
onClick={e => e.stopPropagation()}
|
|
115
|
+
/>
|
|
116
|
+
</Popover>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
</div>
|
|
120
|
+
{
|
|
121
|
+
info.desc && <div className={`${prefixCls}-desc`} style={info.timeline ? { marginLeft: 16 } : {}} >{info.desc}</div>
|
|
122
|
+
}
|
|
123
|
+
</li>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function Label(props) {
|
|
128
|
+
const { editable, prefixCls, info, setEditable, onEdit } = props;
|
|
129
|
+
const [label, setLabel] = useState(info.label);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
setLabel(info.label);
|
|
132
|
+
}, [info.label]);
|
|
133
|
+
|
|
134
|
+
return editable ? <Input
|
|
135
|
+
prefixCls={prefixCls}
|
|
136
|
+
value={label}
|
|
137
|
+
onBlur={(v) => {
|
|
138
|
+
if (v === label) return setEditable(false);
|
|
139
|
+
onEdit(v, info)?.then(() => {
|
|
140
|
+
setLabel(v);
|
|
141
|
+
}).catch(() => {
|
|
142
|
+
setLabel(label);
|
|
143
|
+
}).finally(() => {
|
|
144
|
+
setEditable(false);
|
|
145
|
+
});
|
|
146
|
+
}}
|
|
147
|
+
setEditable={setEditable}
|
|
148
|
+
/> :
|
|
149
|
+
<div className={`${prefixCls}-label`}>{label}</div>
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
function Input({ prefixCls, value, onBlur, setEditable }) {
|
|
154
|
+
const [v, sv] = useState(value);
|
|
155
|
+
const ref = useRef<HTMLInputElement>();
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
|
|
158
|
+
ref.current.focus();
|
|
159
|
+
}, []);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
sv(value);
|
|
163
|
+
}, [value])
|
|
164
|
+
|
|
165
|
+
return <input
|
|
166
|
+
ref={ref}
|
|
167
|
+
className={`${prefixCls}-label-edit`}
|
|
168
|
+
value={v}
|
|
169
|
+
onChange={e => sv(e.target.value)}
|
|
170
|
+
onBlur={() => onBlur(v)}
|
|
171
|
+
/>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function MenuItem(props) {
|
|
175
|
+
const { label, icon, danger, info, disabled } = props;
|
|
176
|
+
|
|
177
|
+
const onClick = (e) => {
|
|
178
|
+
if (disabled) return;
|
|
179
|
+
e.stopPropagation();
|
|
180
|
+
props.onClick?.(info);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
if (icon && label) return <Button disabled={disabled} icon={icon} danger={danger} type='text' onClick={onClick}>{label}</Button>;
|
|
184
|
+
if (icon) return <IconButton disabled={disabled} icon={icon} danger={danger} bordered={false} onClick={onClick} />;
|
|
185
|
+
if (label) return <Button disabled={disabled} danger={danger} type='text' onClick={onClick}>{label}</Button>;
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export default ConversationsItem;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Button, IconButton } from '@agentscope-ai/design';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { ReactNode, useState } from 'react';
|
|
4
|
+
import { HistoryPanel } from '@agentscope-ai/chat';
|
|
5
|
+
import { SparkDeleteLine, SparkEditLine, SparkOperateLeftLine, SparkOperateRightLine, SparkPlusLine } from '@agentscope-ai/icons';
|
|
6
|
+
|
|
7
|
+
const useStyles = createStyles(({ token }) => {
|
|
8
|
+
return {
|
|
9
|
+
layout: {
|
|
10
|
+
position: 'relative',
|
|
11
|
+
display: 'flex',
|
|
12
|
+
height: 416,
|
|
13
|
+
border: `1px solid ${token.colorBorderSecondary}`,
|
|
14
|
+
borderRadius: 8,
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
},
|
|
17
|
+
left: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
width: 280,
|
|
21
|
+
background: token.colorBgLayout,
|
|
22
|
+
transition: 'margin-left 0.3s ease-in-out',
|
|
23
|
+
zIndex: 1,
|
|
24
|
+
},
|
|
25
|
+
open: {
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
left: 20,
|
|
28
|
+
top: 16,
|
|
29
|
+
},
|
|
30
|
+
close: {
|
|
31
|
+
marginLeft: -280,
|
|
32
|
+
},
|
|
33
|
+
header: {
|
|
34
|
+
margin: '16px 20px 8px 20px',
|
|
35
|
+
height: 32,
|
|
36
|
+
display: 'flex',
|
|
37
|
+
justifyContent: 'space-between',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
gap: 8,
|
|
40
|
+
fontSize: 16,
|
|
41
|
+
},
|
|
42
|
+
btn: {
|
|
43
|
+
margin: '0 20px 16px 20px',
|
|
44
|
+
|
|
45
|
+
},
|
|
46
|
+
list: {
|
|
47
|
+
height: 0,
|
|
48
|
+
flex: 1,
|
|
49
|
+
overflowY: 'scroll',
|
|
50
|
+
padding: '0 16px 16px 20px',
|
|
51
|
+
|
|
52
|
+
'&::-webkit-scrollbar': {
|
|
53
|
+
width: 4,
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
'&::-webkit-scrollbar-thumb': {
|
|
57
|
+
backgroundColor: 'transparent !important',
|
|
58
|
+
|
|
59
|
+
'&:hover': {
|
|
60
|
+
backgroundColor: `${token.colorFill} !important`,
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const items = Array.from({ length: 10 }).map((_, index) => ({
|
|
69
|
+
key: `item${index + 1}`,
|
|
70
|
+
label: `What is Spark Design?`,
|
|
71
|
+
disabled: index === 3,
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
function Layout(props: { children: ReactNode }) {
|
|
75
|
+
const { styles, cx, theme } = useStyles();
|
|
76
|
+
|
|
77
|
+
return <div className={styles.layout}>{props.children}</div>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default function () {
|
|
81
|
+
const [open, setOpen] = useState(true);
|
|
82
|
+
const { styles, cx, theme } = useStyles();
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
return <Layout>
|
|
86
|
+
<div className={styles.open}>
|
|
87
|
+
<IconButton bordered={false} icon={<SparkOperateRightLine />} onClick={() => setOpen(!open)} />
|
|
88
|
+
|
|
89
|
+
</div>
|
|
90
|
+
<div className={cx(styles.left, open ? '' : styles.close)}>
|
|
91
|
+
<div className={styles.header}>
|
|
92
|
+
<strong>SPARK CHAT</strong>
|
|
93
|
+
<IconButton bordered={false} icon={<SparkOperateLeftLine />} onClick={() => setOpen(!open)} />
|
|
94
|
+
</div>
|
|
95
|
+
<div className={styles.btn}>
|
|
96
|
+
<Button block type="primary" icon={<SparkPlusLine />}>
|
|
97
|
+
New Chat
|
|
98
|
+
</Button>
|
|
99
|
+
</div>
|
|
100
|
+
<div className={styles.list}>
|
|
101
|
+
<HistoryPanel
|
|
102
|
+
items={items}
|
|
103
|
+
defaultActiveKey="item1" />
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</Layout>
|
|
107
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Button } from '@agentscope-ai/design';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { ReactNode, useState } from 'react';
|
|
4
|
+
import { HistoryPanel } from '@agentscope-ai/chat';
|
|
5
|
+
import { SparkDeleteLine, SparkEditLine, SparkPlusLine } from '@agentscope-ai/icons';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const useStyles = createStyles(({ token }) => {
|
|
9
|
+
return {
|
|
10
|
+
layout: {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
height: 416,
|
|
13
|
+
border: `1px solid ${token.colorBorderSecondary}`,
|
|
14
|
+
borderRadius: 8,
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
},
|
|
17
|
+
left: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
width: 280,
|
|
21
|
+
background: token.colorBgLayout,
|
|
22
|
+
},
|
|
23
|
+
header: {
|
|
24
|
+
margin: '16px 20px 8px 20px',
|
|
25
|
+
height: 32,
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
gap: 8,
|
|
29
|
+
fontSize: 16,
|
|
30
|
+
},
|
|
31
|
+
btn: {
|
|
32
|
+
margin: '0 20px 16px 20px',
|
|
33
|
+
|
|
34
|
+
},
|
|
35
|
+
list: {
|
|
36
|
+
height: 0,
|
|
37
|
+
flex: 1,
|
|
38
|
+
overflowY: 'scroll',
|
|
39
|
+
padding: '0 16px 16px 20px',
|
|
40
|
+
|
|
41
|
+
'&::-webkit-scrollbar': {
|
|
42
|
+
width: 4,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
'&::-webkit-scrollbar-thumb': {
|
|
46
|
+
backgroundColor: 'transparent !important',
|
|
47
|
+
|
|
48
|
+
'&:hover': {
|
|
49
|
+
backgroundColor: `${token.colorFill} !important`,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const items = Array.from({ length: 10 }).map((_, index) => ({
|
|
58
|
+
key: `item${index + 1}`,
|
|
59
|
+
label: `What is Spark Design?`,
|
|
60
|
+
desc: new Date(Date.now() - index * 1000).toLocaleString(),
|
|
61
|
+
disabled: index === 3,
|
|
62
|
+
timeline: true,
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
function Layout(props: { children: ReactNode }) {
|
|
66
|
+
const { styles, cx, theme } = useStyles();
|
|
67
|
+
|
|
68
|
+
return <div className={styles.layout}>{props.children}</div>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default function () {
|
|
72
|
+
const [open, setOpen] = useState(false);
|
|
73
|
+
const { styles, cx, theme } = useStyles();
|
|
74
|
+
|
|
75
|
+
return <Layout>
|
|
76
|
+
<div className={styles.left}>
|
|
77
|
+
<div className={styles.header}>
|
|
78
|
+
<strong>SPARK CHAT</strong>
|
|
79
|
+
</div>
|
|
80
|
+
<div className={styles.btn}>
|
|
81
|
+
<Button block type="primary" icon={<SparkPlusLine />}>
|
|
82
|
+
New Chat
|
|
83
|
+
</Button>
|
|
84
|
+
</div>
|
|
85
|
+
<div className={styles.list}>
|
|
86
|
+
<HistoryPanel
|
|
87
|
+
menu={[
|
|
88
|
+
{
|
|
89
|
+
label: '编辑',
|
|
90
|
+
key: 'edit',
|
|
91
|
+
icon: <SparkEditLine />,
|
|
92
|
+
onEdit: (label: string) => {
|
|
93
|
+
if (label) return Promise.resolve();
|
|
94
|
+
return Promise.reject();
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: '删除',
|
|
99
|
+
key: 'delete',
|
|
100
|
+
icon: <SparkDeleteLine />,
|
|
101
|
+
danger: true,
|
|
102
|
+
onClick: (session) => {
|
|
103
|
+
console.log(session);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
]}
|
|
107
|
+
items={items} defaultActiveKey="item1" />
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</Layout>
|
|
111
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Button } from '@agentscope-ai/design';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { ReactNode, useState } from 'react';
|
|
4
|
+
import { HistoryPanel } from '@agentscope-ai/chat';
|
|
5
|
+
import { SparkDeleteLine, SparkEditLine, SparkPlusLine } from '@agentscope-ai/icons';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const useStyles = createStyles(({ token }) => {
|
|
9
|
+
return {
|
|
10
|
+
layout: {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
height: 416,
|
|
13
|
+
border: `1px solid ${token.colorBorderSecondary}`,
|
|
14
|
+
borderRadius: 8,
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
},
|
|
17
|
+
left: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
width: 280,
|
|
21
|
+
background: token.colorBgLayout,
|
|
22
|
+
},
|
|
23
|
+
header: {
|
|
24
|
+
margin: '16px 20px 8px 20px',
|
|
25
|
+
height: 32,
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
gap: 8,
|
|
29
|
+
fontSize: 16,
|
|
30
|
+
},
|
|
31
|
+
btn: {
|
|
32
|
+
margin: '0 20px 16px 20px',
|
|
33
|
+
|
|
34
|
+
},
|
|
35
|
+
list: {
|
|
36
|
+
height: 0,
|
|
37
|
+
flex: 1,
|
|
38
|
+
overflowY: 'scroll',
|
|
39
|
+
padding: '0 16px 16px 20px',
|
|
40
|
+
|
|
41
|
+
'&::-webkit-scrollbar': {
|
|
42
|
+
width: 4,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
'&::-webkit-scrollbar-thumb': {
|
|
46
|
+
backgroundColor: 'transparent !important',
|
|
47
|
+
|
|
48
|
+
'&:hover': {
|
|
49
|
+
backgroundColor: `${token.colorFill} !important`,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const items = Array.from({ length: 10 }).map((_, index) => ({
|
|
58
|
+
key: `item${index + 1}`,
|
|
59
|
+
label: `What is Spark Design?`,
|
|
60
|
+
desc: new Date(Date.now() - index * 1000).toLocaleString(),
|
|
61
|
+
disabled: index === 3,
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
function Layout(props: { children: ReactNode }) {
|
|
65
|
+
const { styles, cx, theme } = useStyles();
|
|
66
|
+
|
|
67
|
+
return <div className={styles.layout}>{props.children}</div>
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default function () {
|
|
71
|
+
const [open, setOpen] = useState(false);
|
|
72
|
+
const { styles, cx, theme } = useStyles();
|
|
73
|
+
|
|
74
|
+
return <Layout>
|
|
75
|
+
<div className={styles.left}>
|
|
76
|
+
<div className={styles.header}>
|
|
77
|
+
<strong>SPARK CHAT</strong>
|
|
78
|
+
</div>
|
|
79
|
+
<div className={styles.btn}>
|
|
80
|
+
<Button block type="primary" icon={<SparkPlusLine />}>
|
|
81
|
+
New Chat
|
|
82
|
+
</Button>
|
|
83
|
+
</div>
|
|
84
|
+
<div className={styles.list}>
|
|
85
|
+
<HistoryPanel
|
|
86
|
+
menu={[
|
|
87
|
+
{
|
|
88
|
+
label: '编辑',
|
|
89
|
+
key: 'edit',
|
|
90
|
+
icon: <SparkEditLine />,
|
|
91
|
+
onEdit: (label: string) => {
|
|
92
|
+
if (label) return Promise.resolve();
|
|
93
|
+
return Promise.reject();
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: '删除',
|
|
98
|
+
key: 'delete',
|
|
99
|
+
icon: <SparkDeleteLine />,
|
|
100
|
+
danger: true,
|
|
101
|
+
onClick: (session) => {
|
|
102
|
+
console.log(session);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
]}
|
|
106
|
+
items={items} defaultActiveKey="item1" />
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
</Layout>
|
|
110
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Conversation, Groupable } from '../interface';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 🔥 Only for handling ungrouped data. Do not use it for any other purpose! 🔥
|
|
6
|
+
*/
|
|
7
|
+
const __UNGROUPED = '__ungrouped';
|
|
8
|
+
|
|
9
|
+
type GroupList = {
|
|
10
|
+
data: Conversation[];
|
|
11
|
+
name?: string;
|
|
12
|
+
title?: Groupable['title'];
|
|
13
|
+
}[];
|
|
14
|
+
|
|
15
|
+
type GroupMap = Record<string, Conversation[]>;
|
|
16
|
+
|
|
17
|
+
const useGroupable = (
|
|
18
|
+
groupable?: { groupable?: boolean | Groupable }['groupable'],
|
|
19
|
+
items: Conversation[] = [],
|
|
20
|
+
): [groupList: GroupList, enableGroup: boolean] => {
|
|
21
|
+
const [enableGroup, sort, title] = React.useMemo(() => {
|
|
22
|
+
if (!groupable) {
|
|
23
|
+
return [false, undefined, undefined];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let baseConfig: Groupable = {
|
|
27
|
+
sort: undefined,
|
|
28
|
+
title: undefined,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (typeof groupable === 'object') {
|
|
32
|
+
baseConfig = { ...baseConfig, ...groupable };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return [true, baseConfig.sort, baseConfig.title];
|
|
36
|
+
}, [groupable]);
|
|
37
|
+
|
|
38
|
+
return React.useMemo(() => {
|
|
39
|
+
// 未开启分组模式直接返回
|
|
40
|
+
if (!enableGroup) {
|
|
41
|
+
const groupList = [
|
|
42
|
+
{
|
|
43
|
+
name: __UNGROUPED,
|
|
44
|
+
data: items,
|
|
45
|
+
title: undefined,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
return [groupList, enableGroup];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 1. 将 data 做数据分组,填充 groupMap
|
|
53
|
+
const groupMap = items.reduce<GroupMap>((acc, item) => {
|
|
54
|
+
const group = item.group || __UNGROUPED;
|
|
55
|
+
|
|
56
|
+
if (!acc[group]) {
|
|
57
|
+
acc[group] = [];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
acc[group].push(item);
|
|
61
|
+
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
|
|
65
|
+
// 2. 存在 sort 时对 groupKeys 排序
|
|
66
|
+
const groupKeys = sort
|
|
67
|
+
? Object.keys(groupMap).sort(sort)
|
|
68
|
+
: Object.keys(groupMap);
|
|
69
|
+
|
|
70
|
+
// 3. groupMap 转 groupList
|
|
71
|
+
const groupList = groupKeys.map((group) => ({
|
|
72
|
+
name: group === __UNGROUPED ? undefined : group,
|
|
73
|
+
title,
|
|
74
|
+
data: groupMap[group],
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
return [groupList, enableGroup];
|
|
78
|
+
}, [items, groupable]);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default useGroupable;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 2
|
|
3
|
+
group:
|
|
4
|
+
title: Display
|
|
5
|
+
order: 1
|
|
6
|
+
title: HistoryPanel
|
|
7
|
+
description: Conversation History Panel
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<DemoTitle title="HistoryPanel" desc="Conversation History Panel" llmTxtName="Conversations"></DemoTitle>
|
|
11
|
+
|
|
12
|
+
<code src="./demo/basic.tsx" height="auto">Example</code>
|
|
13
|
+
|
|
14
|
+
<Install>import { HistoryPanel } from '@agentscope-ai/chat'</Install>
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#### HistoryPanel Examples
|
|
18
|
+
|
|
19
|
+
The following are examples and variations of this component
|
|
20
|
+
|
|
21
|
+
<code src="./demo/timestamp.tsx" height="auto">Show Timestamp</code>
|
|
22
|
+
<code src="./demo/timeline.tsx" height="auto">Show Timestamp & Timeline</code>
|
|
23
|
+
|
|
24
|
+
#### API
|
|
25
|
+
|
|
26
|
+
##### HistoryPanel
|
|
27
|
+
|
|
28
|
+
<ApiParser source="./index.tsx" id="ConversationsProps"></ApiParser>
|
|
29
|
+
|
|
30
|
+
##### Conversation
|
|
31
|
+
|
|
32
|
+
<ApiParser source="./interface.ts" id="Conversation"></ApiParser>
|