@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,158 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react'
|
|
2
|
+
import { useProviderContext, ChatInput, uuid, Sender, Attachments } from '@agentscope-ai/chat';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
import { useChatAnywhere } from '../hooks/ChatAnywhereProvider';
|
|
5
|
+
import { useInput } from '../hooks/useInput';
|
|
6
|
+
import { Button, GetProp, Space, Upload } from 'antd';
|
|
7
|
+
import Style from './style';
|
|
8
|
+
import { IconButton } from '@agentscope-ai/design';
|
|
9
|
+
|
|
10
|
+
type AttachedFiles = GetProp<typeof Attachments, 'items'>;
|
|
11
|
+
|
|
12
|
+
export default forwardRef(function (_, ref) {
|
|
13
|
+
const [content, setContent] = React.useState('');
|
|
14
|
+
const onUpload = useChatAnywhere(v => v.onUpload);
|
|
15
|
+
const resetData = new Array(onUpload?.length || 0).fill([]);
|
|
16
|
+
const [attachedFiles, setAttachedFiles] = React.useState<AttachedFiles[]>(resetData);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setAttachedFiles(resetData);
|
|
19
|
+
}, [resetData.length]);
|
|
20
|
+
|
|
21
|
+
const inputContext = useInput();
|
|
22
|
+
const uiConfig = useChatAnywhere(v => v.uiConfig);
|
|
23
|
+
const { getPrefixCls } = useProviderContext();
|
|
24
|
+
const prefixCls = getPrefixCls('chat-anywhere-sender');
|
|
25
|
+
const onStop = useChatAnywhere(v => v.onStop);
|
|
26
|
+
const onInput = useChatAnywhere(v => {
|
|
27
|
+
const defaultValue = {
|
|
28
|
+
beforeUI: undefined,
|
|
29
|
+
afterUI: undefined,
|
|
30
|
+
morePrefixActions: undefined,
|
|
31
|
+
maxLength: undefined,
|
|
32
|
+
zoomable: true,
|
|
33
|
+
beforeSubmit: () => Promise.resolve(true),
|
|
34
|
+
header: [],
|
|
35
|
+
hide: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
...defaultValue,
|
|
40
|
+
...v.onInput,
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
React.useImperativeHandle(ref, () => {
|
|
45
|
+
return {
|
|
46
|
+
setInputContent: setContent
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
inputContext.setDisabled(onInput.disabled);
|
|
52
|
+
}, [onInput.disabled])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (onInput.hide) return null;
|
|
56
|
+
|
|
57
|
+
const handleFileChange = async (index, fileList) => {
|
|
58
|
+
setAttachedFiles(attachedFiles => {
|
|
59
|
+
return attachedFiles.map((item, i) => {
|
|
60
|
+
if (i === index) {
|
|
61
|
+
return fileList;
|
|
62
|
+
}
|
|
63
|
+
return item;
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const prefixNodes = onUpload?.length ?
|
|
69
|
+
onUpload.map((item, index) => {
|
|
70
|
+
return <Upload
|
|
71
|
+
{...item}
|
|
72
|
+
fileList={attachedFiles[index]}
|
|
73
|
+
key={index}
|
|
74
|
+
onChange={(info) => {
|
|
75
|
+
if (item.beforeUpload && info.file.status) {
|
|
76
|
+
handleFileChange(index, info.fileList)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!item.beforeUpload) {
|
|
80
|
+
handleFileChange(index, info.fileList)
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
showUploadList={false}
|
|
84
|
+
>
|
|
85
|
+
<IconButton
|
|
86
|
+
icon={item.icon}
|
|
87
|
+
bordered={false}
|
|
88
|
+
/>
|
|
89
|
+
</Upload>
|
|
90
|
+
}) : [];
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const senderHeader = (
|
|
94
|
+
<Sender.Header
|
|
95
|
+
closable={false}
|
|
96
|
+
open={attachedFiles?.some(item => item.length)}
|
|
97
|
+
>
|
|
98
|
+
{
|
|
99
|
+
attachedFiles.map((files, index) => {
|
|
100
|
+
if (!files.length) return null;
|
|
101
|
+
return <Attachments
|
|
102
|
+
key={index}
|
|
103
|
+
items={files}
|
|
104
|
+
onChange={(info) => handleFileChange(index, info.fileList)}
|
|
105
|
+
/>
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
</Sender.Header>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const submitFileList = attachedFiles.map(files => files.filter(file => file.status === 'done'));
|
|
112
|
+
const fileLoading = attachedFiles.some(files => files.some(file => file.status === 'uploading'));
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
return <>
|
|
117
|
+
<Style />
|
|
118
|
+
<div
|
|
119
|
+
className={cls(`${prefixCls}-wrapper`)}
|
|
120
|
+
>
|
|
121
|
+
{
|
|
122
|
+
uiConfig.quickInput && <div className={cls(`${prefixCls}-wrapper-header`)}>{uiConfig.quickInput}</div>
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
{
|
|
126
|
+
onInput.beforeUI
|
|
127
|
+
}
|
|
128
|
+
<ChatInput
|
|
129
|
+
placeholder={onInput.placeholder}
|
|
130
|
+
value={content}
|
|
131
|
+
onChange={setContent}
|
|
132
|
+
maxLength={onInput.maxLength}
|
|
133
|
+
disabled={fileLoading || inputContext.disabled}
|
|
134
|
+
scalable={onInput?.zoomable}
|
|
135
|
+
header={senderHeader}
|
|
136
|
+
prefix={<>
|
|
137
|
+
{prefixNodes}
|
|
138
|
+
{onInput?.morePrefixActions}
|
|
139
|
+
</>}
|
|
140
|
+
onSubmit={async () => {
|
|
141
|
+
const next = await (onInput.beforeSubmit || (() => Promise.resolve(true)))();
|
|
142
|
+
if (!next) return;
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
onInput.onSubmit({ query: content, fileList: submitFileList });
|
|
145
|
+
setContent('');
|
|
146
|
+
setAttachedFiles(resetData);
|
|
147
|
+
}}
|
|
148
|
+
onCancel={() => {
|
|
149
|
+
onStop?.();
|
|
150
|
+
inputContext.setLoading(false);
|
|
151
|
+
}}
|
|
152
|
+
loading={inputContext.loading}
|
|
153
|
+
/>
|
|
154
|
+
{
|
|
155
|
+
onInput.afterUI
|
|
156
|
+
}
|
|
157
|
+
</div></>
|
|
158
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createGlobalStyle } from 'antd-style';
|
|
2
|
+
|
|
3
|
+
export default createGlobalStyle`
|
|
4
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-sender-wrapper {
|
|
5
|
+
position: relative;
|
|
6
|
+
|
|
7
|
+
&-header {
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: 8px;
|
|
10
|
+
margin-bottom: 12px;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
`;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import { useProviderContext } from '@agentscope-ai/chat';
|
|
4
|
+
import { Drawer } from 'antd';
|
|
5
|
+
import { useResponsive } from 'ahooks';
|
|
6
|
+
import { useChatAnywhere } from '../hooks/ChatAnywhereProvider';
|
|
7
|
+
import Style from './style';
|
|
8
|
+
|
|
9
|
+
interface IProps {
|
|
10
|
+
top?: React.ReactNode;
|
|
11
|
+
left?: React.ReactNode;
|
|
12
|
+
right?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function Left(props: IProps) {
|
|
17
|
+
const {
|
|
18
|
+
sessionListShow,
|
|
19
|
+
setSessionListShow,
|
|
20
|
+
} = useChatAnywhere(v => ({ sessionListShow: v.sessionListShow, setSessionListShow: v.setSessionListShow }))
|
|
21
|
+
const { getPrefixCls } = useProviderContext();
|
|
22
|
+
const prefixCls = getPrefixCls('chat-anywhere-layout');
|
|
23
|
+
const isMobile = isMobileHook();
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setSessionListShow(!isMobile)
|
|
27
|
+
}, [isMobile])
|
|
28
|
+
|
|
29
|
+
if (!props.left) return null;
|
|
30
|
+
|
|
31
|
+
if (!isMobile)
|
|
32
|
+
return <div className={classnames(`${prefixCls}-left`, sessionListShow ? '' : `${prefixCls}-left-hide`)}>
|
|
33
|
+
{props.left}
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
return <Drawer width={"80vw"} styles={{ body: { padding: 0 } }} open={sessionListShow} onClose={() => { setSessionListShow(false) }} title={null} closable={false} placement="left">
|
|
37
|
+
<div style={{ display: 'flex', flexDirection: 'column', }}>
|
|
38
|
+
{props.left}
|
|
39
|
+
</div>
|
|
40
|
+
</Drawer>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default function (props: IProps) {
|
|
44
|
+
const { getPrefixCls } = useProviderContext();
|
|
45
|
+
const prefixCls = getPrefixCls('chat-anywhere-layout');
|
|
46
|
+
const uiConfig = useChatAnywhere(state => state.uiConfig);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return <>
|
|
50
|
+
<Style />
|
|
51
|
+
<div className={prefixCls}>
|
|
52
|
+
<div className={`${prefixCls}-main`}>
|
|
53
|
+
<Left {...props} />
|
|
54
|
+
|
|
55
|
+
<div className={`${prefixCls}-right`} style={{
|
|
56
|
+
background: uiConfig?.background,
|
|
57
|
+
}}>
|
|
58
|
+
{props.top}
|
|
59
|
+
{props.right}
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div></>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const isMobileHook = () => {
|
|
66
|
+
const responsive = useResponsive();
|
|
67
|
+
const uiConfig = useChatAnywhere(state => state.uiConfig);
|
|
68
|
+
|
|
69
|
+
return !responsive.md || uiConfig?.narrowScreen;
|
|
70
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createGlobalStyle } from 'antd-style';
|
|
2
|
+
|
|
3
|
+
export default createGlobalStyle`
|
|
4
|
+
|
|
5
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-layout {
|
|
6
|
+
*::-webkit-scrollbar {
|
|
7
|
+
display: none;
|
|
8
|
+
}
|
|
9
|
+
font-family: ${(p) => p.theme.fontFamily};
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
position: relative;
|
|
12
|
+
height: 100%;
|
|
13
|
+
background: ${(p) => p.theme.colorBgBase};
|
|
14
|
+
|
|
15
|
+
&-main {
|
|
16
|
+
display: flex;
|
|
17
|
+
height: 100%;
|
|
18
|
+
background: ${(p) => p.theme.colorBgBase};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&-left {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
height: 100vh;
|
|
25
|
+
box-sizing: border-box;
|
|
26
|
+
background-color: ${(p) => p.theme.colorBgBase};
|
|
27
|
+
width: 240px;
|
|
28
|
+
transition: all 0.2s;
|
|
29
|
+
|
|
30
|
+
&-hide {
|
|
31
|
+
margin-left: -168px;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&-right {
|
|
37
|
+
position: relative;
|
|
38
|
+
width: 0;
|
|
39
|
+
flex: 1;
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
background: ${(p) => p.theme.colorFillTertiary};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
*[data-tauri-drag-region] {
|
|
49
|
+
-webkit-app-region: drag;
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Conversations } from '@agentscope-ai/chat';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
import { useProviderContext } from '@agentscope-ai/chat';
|
|
5
|
+
import { Button, IconButton } from '@agentscope-ai/design';
|
|
6
|
+
import { useChatAnywhere } from '../hooks/ChatAnywhereProvider';
|
|
7
|
+
import { useSessionList } from '../hooks/useSessionList';
|
|
8
|
+
import { useMessages } from '../hooks/useMessages';
|
|
9
|
+
import { isMobileHook } from '../Layout';
|
|
10
|
+
import Style from './style';
|
|
11
|
+
import { SparkOperateLeftLine, SparkOperateRightLine, SparkPlusLine, SparkDeleteLine } from "@agentscope-ai/icons";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export default function () {
|
|
15
|
+
const { getPrefixCls } = useProviderContext();
|
|
16
|
+
const prefixCls = getPrefixCls('chat-anywhere-session-list');
|
|
17
|
+
const sessionListShow = useChatAnywhere(v => v.sessionListShow);
|
|
18
|
+
|
|
19
|
+
return <>
|
|
20
|
+
<Style />
|
|
21
|
+
<div className={cls(`${prefixCls}`, sessionListShow ? '' : `${prefixCls}-hide`)}>
|
|
22
|
+
<InnerAdder />
|
|
23
|
+
<InnerSession />
|
|
24
|
+
</div>
|
|
25
|
+
</>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function InnerSession() {
|
|
29
|
+
const { getPrefixCls } = useProviderContext();
|
|
30
|
+
const prefixCls = getPrefixCls('chat-anywhere-session-list');
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
currentSessionKey,
|
|
34
|
+
setCurrentSessionKey,
|
|
35
|
+
currentRegenerateIndex,
|
|
36
|
+
sessionList,
|
|
37
|
+
getMessagesBySession,
|
|
38
|
+
setSessionListShow
|
|
39
|
+
} = useSessionList();
|
|
40
|
+
const { setMessages } = useMessages();
|
|
41
|
+
const getLoading = useChatAnywhere(v => v.getLoading);
|
|
42
|
+
const onSessionKeyChange = useChatAnywhere(v => v.onSessionKeyChange);
|
|
43
|
+
const isMobile = isMobileHook();
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const messages = getMessagesBySession(currentSessionKey, currentRegenerateIndex);
|
|
48
|
+
setMessages(messages);
|
|
49
|
+
}, [currentSessionKey, currentRegenerateIndex]);
|
|
50
|
+
|
|
51
|
+
return <div className={`${prefixCls}-session`} >
|
|
52
|
+
<Conversations
|
|
53
|
+
menu={[
|
|
54
|
+
{
|
|
55
|
+
key: 'delete',
|
|
56
|
+
icon: <SparkDeleteLine />,
|
|
57
|
+
danger: true,
|
|
58
|
+
onClick: (session) => { },
|
|
59
|
+
},
|
|
60
|
+
]}
|
|
61
|
+
activeKey={currentSessionKey}
|
|
62
|
+
items={sessionList}
|
|
63
|
+
onActiveChange={key => {
|
|
64
|
+
if (getLoading()) return;
|
|
65
|
+
if (isMobile) {
|
|
66
|
+
setSessionListShow(false);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
requestIdleCallback(() => {
|
|
70
|
+
setCurrentSessionKey(key);
|
|
71
|
+
onSessionKeyChange(key);
|
|
72
|
+
})
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function InnerAdder() {
|
|
79
|
+
const { getPrefixCls } = useProviderContext();
|
|
80
|
+
const prefixCls = getPrefixCls('chat-anywhere-session-list');
|
|
81
|
+
const {
|
|
82
|
+
currentSessionKey,
|
|
83
|
+
setCurrentSessionKey,
|
|
84
|
+
deleteSession,
|
|
85
|
+
createSession,
|
|
86
|
+
sessionList,
|
|
87
|
+
sessionListShow,
|
|
88
|
+
setSessionListShow
|
|
89
|
+
} = useSessionList();
|
|
90
|
+
const uiConfig = useChatAnywhere(v => v.uiConfig);
|
|
91
|
+
const isMobile = isMobileHook();
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
return <>
|
|
95
|
+
<div className={`${prefixCls}-logo`}>
|
|
96
|
+
{uiConfig?.logo}
|
|
97
|
+
<IconButton
|
|
98
|
+
bordered={false}
|
|
99
|
+
onClick={() => setSessionListShow(!sessionListShow)}
|
|
100
|
+
icon={
|
|
101
|
+
sessionListShow ? <SparkOperateLeftLine /> : <SparkOperateRightLine />
|
|
102
|
+
}></IconButton>
|
|
103
|
+
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div className={`${prefixCls}-adder`}>
|
|
107
|
+
<Button
|
|
108
|
+
type="primary"
|
|
109
|
+
block
|
|
110
|
+
icon={<SparkPlusLine />}
|
|
111
|
+
onClick={() => {
|
|
112
|
+
if (isMobile) {
|
|
113
|
+
setSessionListShow(false);
|
|
114
|
+
}
|
|
115
|
+
createSession();
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
New Session
|
|
119
|
+
</Button>
|
|
120
|
+
</div>
|
|
121
|
+
</>
|
|
122
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createGlobalStyle } from 'antd-style';
|
|
2
|
+
|
|
3
|
+
export default createGlobalStyle`
|
|
4
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-session-list {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
height: 0;
|
|
8
|
+
flex: 1;
|
|
9
|
+
width: 100%;
|
|
10
|
+
|
|
11
|
+
.${(p) => p.theme.prefixCls}-conversations {
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&-session {
|
|
16
|
+
height: 0;
|
|
17
|
+
flex: 1;
|
|
18
|
+
padding: 8px 20px;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&-logo {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
padding: 0 20px;
|
|
27
|
+
height: 64px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&-adder {
|
|
31
|
+
padding: 0 20px 8px 20px;
|
|
32
|
+
button {
|
|
33
|
+
border-radius: 6px;
|
|
34
|
+
box-shadow: 15px 0px 30px -10px rgba(131, 88, 246, 0.4),
|
|
35
|
+
0px 0px 30px -10px rgba(255, 142, 168, 0.4),
|
|
36
|
+
-15px 0px 30px -10px rgba(225, 163, 37, 0.4);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&-hide {
|
|
41
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-session-list-adder-logo > div {
|
|
42
|
+
opacity: 0;
|
|
43
|
+
}
|
|
44
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-session-list-adder {
|
|
45
|
+
opacity: 0;
|
|
46
|
+
}
|
|
47
|
+
.${(p) => p.theme.prefixCls}-chat-anywhere-session-list-session {
|
|
48
|
+
opacity: 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
`;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TMessage, TSession, IChatAnywhereConfig } from './types';
|
|
3
|
+
import { useGetState } from 'ahooks';
|
|
4
|
+
import { useSessionList } from './useSessionList';
|
|
5
|
+
import { createContext, useContextSelector } from 'use-context-selector';
|
|
6
|
+
import { useMessages } from './useMessages';
|
|
7
|
+
import { useInput } from './useInput';
|
|
8
|
+
import { ScrollToBottomOptions } from 'use-stick-to-bottom';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export function ChatAnywhereProvider(props:
|
|
12
|
+
IChatAnywhereConfig &
|
|
13
|
+
{ children: React.ReactNode, }
|
|
14
|
+
) {
|
|
15
|
+
|
|
16
|
+
const [sessionList, setSessionList, getSessionList] = useGetState<TSession[]>([]);
|
|
17
|
+
const [currentSessionKey, setCurrentSessionKey, getCurrentSessionKey] = useGetState<string>('0');
|
|
18
|
+
const [currentRegenerateIndex, setCurrentRegenerateIndex, getCurrentRegenerateIndex] = useGetState<number>(0);
|
|
19
|
+
const [messages, setMessages, getMessages] = useGetState<TMessage[]>([]);
|
|
20
|
+
const [loading, setLoading, getLoading] = useGetState<boolean>(false);
|
|
21
|
+
const [disabled, setDisabled, getDisabled] = useGetState<boolean>(false);
|
|
22
|
+
const [sessionListShow, setSessionListShow, getSessionListShow] = useGetState<boolean>(true);
|
|
23
|
+
|
|
24
|
+
const { children, ...rest } = props;
|
|
25
|
+
|
|
26
|
+
const value = {
|
|
27
|
+
sessionList,
|
|
28
|
+
setSessionList,
|
|
29
|
+
getSessionList,
|
|
30
|
+
currentSessionKey,
|
|
31
|
+
setCurrentSessionKey,
|
|
32
|
+
getCurrentSessionKey,
|
|
33
|
+
messages,
|
|
34
|
+
setMessages,
|
|
35
|
+
getMessages,
|
|
36
|
+
loading,
|
|
37
|
+
setLoading,
|
|
38
|
+
getLoading,
|
|
39
|
+
disabled,
|
|
40
|
+
setDisabled,
|
|
41
|
+
getDisabled,
|
|
42
|
+
sessionListShow,
|
|
43
|
+
setSessionListShow,
|
|
44
|
+
getSessionListShow,
|
|
45
|
+
currentRegenerateIndex,
|
|
46
|
+
setCurrentRegenerateIndex,
|
|
47
|
+
getCurrentRegenerateIndex,
|
|
48
|
+
...rest,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
return <ChatAnywhereContext.Provider value={value}>
|
|
54
|
+
{children}
|
|
55
|
+
</ChatAnywhereContext.Provider>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const ChatAnywhereContext = createContext<IChatAnywhereContext>(undefined);
|
|
59
|
+
|
|
60
|
+
export function useChatAnywhere<Selected>(selector: (value: IChatAnywhereContext) => Selected) {
|
|
61
|
+
try {
|
|
62
|
+
const context = useContextSelector(ChatAnywhereContext, selector);
|
|
63
|
+
return context;
|
|
64
|
+
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return {} as Selected;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export interface IChatAnywhereContext {
|
|
71
|
+
/**
|
|
72
|
+
* @description 会话列表数据,包含所有可用的聊天会话
|
|
73
|
+
* @descriptionEn Session list data containing all available chat sessions
|
|
74
|
+
*/
|
|
75
|
+
sessionList: TSession[];
|
|
76
|
+
/**
|
|
77
|
+
* @description 设置会话列表的状态更新函数
|
|
78
|
+
* @descriptionEn State update function for setting session list
|
|
79
|
+
*/
|
|
80
|
+
setSessionList: React.Dispatch<React.SetStateAction<TSession[]>>
|
|
81
|
+
/**
|
|
82
|
+
* @description 获取当前会话列表的同步函数
|
|
83
|
+
* @descriptionEn Synchronous function to get current session list
|
|
84
|
+
*/
|
|
85
|
+
getSessionList: () => TSession[];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @description 当前激活会话的唯一标识符
|
|
89
|
+
* @descriptionEn Unique identifier for the currently active session
|
|
90
|
+
*/
|
|
91
|
+
currentSessionKey: string;
|
|
92
|
+
/**
|
|
93
|
+
* @description 设置当前会话标识符的状态更新函数
|
|
94
|
+
* @descriptionEn State update function for setting current session identifier
|
|
95
|
+
*/
|
|
96
|
+
setCurrentSessionKey: React.Dispatch<React.SetStateAction<string>>;
|
|
97
|
+
/**
|
|
98
|
+
* @description 获取当前会话标识符的同步函数
|
|
99
|
+
* @descriptionEn Synchronous function to get current session identifier
|
|
100
|
+
*/
|
|
101
|
+
getCurrentSessionKey: () => string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @description 当前会话的消息列表
|
|
105
|
+
* @descriptionEn Message list for the current session
|
|
106
|
+
*/
|
|
107
|
+
messages: TMessage[];
|
|
108
|
+
/**
|
|
109
|
+
* @description 设置消息列表的状态更新函数
|
|
110
|
+
* @descriptionEn State update function for setting message list
|
|
111
|
+
*/
|
|
112
|
+
setMessages: React.Dispatch<React.SetStateAction<TMessage[]>>;
|
|
113
|
+
/**
|
|
114
|
+
* @description 获取当前消息列表的同步函数
|
|
115
|
+
* @descriptionEn Synchronous function to get current message list
|
|
116
|
+
*/
|
|
117
|
+
getMessages: () => TMessage[];
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @description 是否正在加载状态,影响UI的交互性
|
|
121
|
+
* @descriptionEn Whether in loading state, affects UI interactivity
|
|
122
|
+
*/
|
|
123
|
+
loading: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* @description 设置加载状态的状态更新函数
|
|
126
|
+
* @descriptionEn State update function for setting loading state
|
|
127
|
+
*/
|
|
128
|
+
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
|
129
|
+
/**
|
|
130
|
+
* @description 获取当前加载状态的同步函数
|
|
131
|
+
* @descriptionEn Synchronous function to get current loading state
|
|
132
|
+
*/
|
|
133
|
+
getLoading: () => boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @description 是否禁用组件,影响所有交互功能
|
|
137
|
+
* @descriptionEn Whether to disable the component, affects all interaction functionality
|
|
138
|
+
*/
|
|
139
|
+
disabled: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @description 设置禁用状态的状态更新函数
|
|
142
|
+
* @descriptionEn State update function for setting disabled state
|
|
143
|
+
*/
|
|
144
|
+
setDisabled: React.Dispatch<React.SetStateAction<boolean>>;
|
|
145
|
+
/**
|
|
146
|
+
* @description 获取当前禁用状态的同步函数
|
|
147
|
+
* @descriptionEn Synchronous function to get current disabled state
|
|
148
|
+
*/
|
|
149
|
+
getDisabled: () => boolean;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @description 是否显示会话列表,控制侧边栏的可见性
|
|
153
|
+
* @descriptionEn Whether to show session list, controls sidebar visibility
|
|
154
|
+
*/
|
|
155
|
+
sessionListShow: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* @description 设置会话列表显示状态的状态更新函数
|
|
158
|
+
* @descriptionEn State update function for setting session list display state
|
|
159
|
+
*/
|
|
160
|
+
setSessionListShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
161
|
+
/**
|
|
162
|
+
* @description 获取当前会话列表显示状态的同步函数
|
|
163
|
+
* @descriptionEn Synchronous function to get current session list display state
|
|
164
|
+
*/
|
|
165
|
+
getSessionListShow: () => boolean;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @description 当前重新生成的消息索引,用于定位重新生成的消息
|
|
169
|
+
* @descriptionEn Current regenerate message index for locating regenerated messages
|
|
170
|
+
*/
|
|
171
|
+
currentRegenerateIndex: number;
|
|
172
|
+
/**
|
|
173
|
+
* @description 设置重新生成索引的状态更新函数
|
|
174
|
+
* @descriptionEn State update function for setting regenerate index
|
|
175
|
+
*/
|
|
176
|
+
setCurrentRegenerateIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
177
|
+
/**
|
|
178
|
+
* @description 获取当前重新生成索引的同步函数
|
|
179
|
+
* @descriptionEn Synchronous function to get current regenerate index
|
|
180
|
+
*/
|
|
181
|
+
getCurrentRegenerateIndex: () => number;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @description 输入事件的处理函数,用于处理用户输入
|
|
185
|
+
* @descriptionEn Input event handler for processing user input
|
|
186
|
+
*/
|
|
187
|
+
onInput?: IChatAnywhereConfig['onInput'];
|
|
188
|
+
/**
|
|
189
|
+
* @description 停止生成事件的处理函数,用于中断AI响应
|
|
190
|
+
* @descriptionEn Stop generation event handler for interrupting AI responses
|
|
191
|
+
*/
|
|
192
|
+
onStop?: IChatAnywhereConfig['onStop'];
|
|
193
|
+
/**
|
|
194
|
+
* @description 文件上传事件的处理函数,用于处理文件上传
|
|
195
|
+
* @descriptionEn File upload event handler for processing file uploads
|
|
196
|
+
*/
|
|
197
|
+
onUpload?: IChatAnywhereConfig['onUpload'];
|
|
198
|
+
/**
|
|
199
|
+
* @description 会话切换事件的处理函数,用于处理会话变更
|
|
200
|
+
* @descriptionEn Session change event handler for processing session switches
|
|
201
|
+
*/
|
|
202
|
+
onSessionKeyChange?: IChatAnywhereConfig['onSessionKeyChange'];
|
|
203
|
+
/**
|
|
204
|
+
* @description UI配置对象,用于自定义界面外观和行为
|
|
205
|
+
* @descriptionEn UI configuration object for customizing interface appearance and behavior
|
|
206
|
+
*/
|
|
207
|
+
uiConfig?: IChatAnywhereConfig['uiConfig'];
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
export type ChatAnywhereRef =
|
|
212
|
+
ReturnType<typeof useMessages> &
|
|
213
|
+
ReturnType<typeof useInput> &
|
|
214
|
+
ReturnType<typeof useSessionList> &
|
|
215
|
+
{
|
|
216
|
+
setInputContent: (content: string) => void;
|
|
217
|
+
scrollToBottom: (options?: ScrollToBottomOptions) => void;
|
|
218
|
+
reload: () => void;
|
|
219
|
+
};
|