@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,71 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { ConfigProvider, Modal, Image as ImageViewer } from 'antd';
|
|
3
|
+
import { useProviderContext } from "@agentscope-ai/chat";
|
|
4
|
+
import { Locale } from "antd/es/locale";
|
|
5
|
+
import { SparkFalseLine, SparkPlayCircleFill } from "@agentscope-ai/icons";
|
|
6
|
+
|
|
7
|
+
export default function (props) {
|
|
8
|
+
try {
|
|
9
|
+
const src = props.src;
|
|
10
|
+
const url = new URL(src);
|
|
11
|
+
const pathname = url.pathname;
|
|
12
|
+
|
|
13
|
+
const isVideo = pathname.endsWith(".mp4");
|
|
14
|
+
const isAudio = pathname.endsWith(".mp3") || pathname.endsWith(".wav");
|
|
15
|
+
|
|
16
|
+
if (isAudio) {
|
|
17
|
+
return <audio src={props.src} {...props} controls />
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isVideo) {
|
|
21
|
+
return <Video src={props.src} {...props} />
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
return <Image src={props.src} {...props} />
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function Image(props) {
|
|
33
|
+
return <ConfigProvider
|
|
34
|
+
locale={{
|
|
35
|
+
Image: { preview: '' }
|
|
36
|
+
} as Locale}
|
|
37
|
+
><ImageViewer src={props.src} {...props} /></ConfigProvider>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Video(props) {
|
|
41
|
+
const src = props.src;
|
|
42
|
+
const [open, setOpen] = useState(false);
|
|
43
|
+
const { getPrefixCls } = useProviderContext();
|
|
44
|
+
const prefixCls = getPrefixCls('markdown-video');
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
return <>
|
|
48
|
+
<div className={prefixCls}>
|
|
49
|
+
<div className={`${prefixCls}-poster`} onClick={() => setOpen(true)}>
|
|
50
|
+
<SparkPlayCircleFill className={`${prefixCls}-play`} />
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<Modal
|
|
55
|
+
closeIcon={<a><SparkFalseLine style={{ fontSize: 20 }} /></a>}
|
|
56
|
+
centered
|
|
57
|
+
transitionName=""
|
|
58
|
+
footer={null} width={500} title="" styles={{
|
|
59
|
+
content: {
|
|
60
|
+
padding: 0
|
|
61
|
+
}
|
|
62
|
+
}} open={open} destroyOnHidden onCancel={() => setOpen(false)}>
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
<video controls autoPlay style={{ display: 'block', width: '100%' }}>
|
|
66
|
+
<source src={src} type="video/mp4" />
|
|
67
|
+
</video>
|
|
68
|
+
</Modal>
|
|
69
|
+
|
|
70
|
+
</>
|
|
71
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import AnimationNode from '../AnimationNode';
|
|
3
|
+
import { MarkdownProps } from '../interface';
|
|
4
|
+
|
|
5
|
+
export type HTMLTag = 'div' | 'p' | 'li' | 'h1' | 'h2' | 'h3' | 'h4' | 'strong';
|
|
6
|
+
type AnimationComponents = Record<HTMLTag, React.FC<React.ComponentProps<HTMLTag>>>;
|
|
7
|
+
|
|
8
|
+
const ANIMATION_TAGS: HTMLTag[] = ['div', 'p', 'li', 'h1', 'h2', 'h3', 'h4', 'strong'];
|
|
9
|
+
|
|
10
|
+
const useAnimation = (streaming: MarkdownProps['streaming']) => {
|
|
11
|
+
const { enableAnimation = false, animationConfig } = streaming || {};
|
|
12
|
+
|
|
13
|
+
const animatedComponents = useMemo(() => {
|
|
14
|
+
if (!enableAnimation) return {};
|
|
15
|
+
|
|
16
|
+
return ANIMATION_TAGS.reduce<AnimationComponents>((acc, tag) => {
|
|
17
|
+
const AnimatedComponent: React.FC<React.ComponentProps<typeof tag>> = React.memo((props) => (
|
|
18
|
+
<AnimationNode nodeTag={tag} animationConfig={animationConfig} {...props} />
|
|
19
|
+
));
|
|
20
|
+
return { ...acc, [tag]: AnimatedComponent };
|
|
21
|
+
}, {} as AnimationComponents);
|
|
22
|
+
}, [enableAnimation, JSON.stringify(animationConfig)]);
|
|
23
|
+
|
|
24
|
+
return animatedComponents;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default useAnimation;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { MarkdownProps } from '../interface';
|
|
3
|
+
import InnerCitationComponent, { CitationComponentProps } from '../../plugins/citations/CitationComponent';
|
|
4
|
+
|
|
5
|
+
const emptyArray = [];
|
|
6
|
+
const emptyMap = {};
|
|
7
|
+
|
|
8
|
+
export default function useCitationsData(
|
|
9
|
+
props: Pick<MarkdownProps, 'citations' | 'citationsMap'>,
|
|
10
|
+
) {
|
|
11
|
+
const { citations = emptyArray, citationsMap = emptyMap } = props;
|
|
12
|
+
|
|
13
|
+
const [citationsData, CitationComponent] = useMemo(() => {
|
|
14
|
+
const map = { ...citationsMap };
|
|
15
|
+
|
|
16
|
+
citations.forEach((item, index) => {
|
|
17
|
+
const key = index + 1;
|
|
18
|
+
map[key] = item;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
return [map, (function citationComponentWrapper() {
|
|
25
|
+
return function (props: CitationComponentProps) {
|
|
26
|
+
return <InnerCitationComponent {...props} citationsData={map} />;
|
|
27
|
+
}
|
|
28
|
+
})()];
|
|
29
|
+
}, [citations, citationsMap]);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
CitationComponent,
|
|
33
|
+
citationsData,
|
|
34
|
+
citationsDataCount: Object.keys(citationsData).length,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { MarkdownProps } from '../interface';
|
|
3
|
+
|
|
4
|
+
enum TokenType {
|
|
5
|
+
Text = 0,
|
|
6
|
+
Link = 1,
|
|
7
|
+
Image = 2,
|
|
8
|
+
Heading = 3,
|
|
9
|
+
MaybeEmphasis = 4,
|
|
10
|
+
Emphasis = 5,
|
|
11
|
+
Strong = 6,
|
|
12
|
+
XML = 7,
|
|
13
|
+
MaybeCode = 8,
|
|
14
|
+
Code = 9,
|
|
15
|
+
MaybeHr = 10,
|
|
16
|
+
MaybeList = 11,
|
|
17
|
+
MaybeInlineMath = 12,
|
|
18
|
+
InlineMath = 13,
|
|
19
|
+
MaybeBlockMath = 14,
|
|
20
|
+
BlockMath = 15,
|
|
21
|
+
MaybeBackslashMath = 16,
|
|
22
|
+
Word = 17,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const Markdown_Symbols = {
|
|
26
|
+
emphasis: ['*', '_'],
|
|
27
|
+
code: ['`'],
|
|
28
|
+
list: ['-', '+', '*'],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 辅助函数:判断是否是英文字母
|
|
32
|
+
const isEnglishLetter = (char: string): boolean => {
|
|
33
|
+
const code = char.charCodeAt(0);
|
|
34
|
+
return (code >= 65 && code <= 90) || (code >= 97 && code <= 122); // A-Z or a-z
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 辅助函数:判断是否是单词的一部分(字母、数字、连字符、撇号)
|
|
38
|
+
const isWordChar = (char: string): boolean => {
|
|
39
|
+
const code = char.charCodeAt(0);
|
|
40
|
+
return (
|
|
41
|
+
(code >= 65 && code <= 90) || // A-Z
|
|
42
|
+
(code >= 97 && code <= 122) || // a-z
|
|
43
|
+
(code >= 48 && code <= 57) || // 0-9
|
|
44
|
+
char === '-' || // 连字符 (well-known)
|
|
45
|
+
char === "'" // 撇号 (don't)
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 辅助函数:判断是否是单词分隔符
|
|
50
|
+
const isWordSeparator = (char: string): boolean => {
|
|
51
|
+
return (
|
|
52
|
+
char === ' ' ||
|
|
53
|
+
char === '\n' ||
|
|
54
|
+
char === '\t' ||
|
|
55
|
+
char === ',' ||
|
|
56
|
+
char === '.' ||
|
|
57
|
+
char === '!' ||
|
|
58
|
+
char === '?' ||
|
|
59
|
+
char === ';' ||
|
|
60
|
+
char === ':' ||
|
|
61
|
+
char === ')' ||
|
|
62
|
+
char === ']' ||
|
|
63
|
+
char === '}' ||
|
|
64
|
+
char === '"' ||
|
|
65
|
+
char === "'" ||
|
|
66
|
+
char === '>' ||
|
|
67
|
+
char === '<'
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const STREAM_BUFFER_INIT = {
|
|
72
|
+
processedLength: 0,
|
|
73
|
+
rawStream: '',
|
|
74
|
+
pending: '',
|
|
75
|
+
token: TokenType.Text,
|
|
76
|
+
tokens: [TokenType.Text],
|
|
77
|
+
headingLevel: 0,
|
|
78
|
+
emphasisCount: 0,
|
|
79
|
+
backtickCount: 0,
|
|
80
|
+
dollarCount: 0,
|
|
81
|
+
mathDelimiter: '' as '$' | '$$' | '\\(' | '\\[' | '',
|
|
82
|
+
blockMathEnding: false, // 标记是否遇到了结束的 $$
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const useStreaming = (input: string, config?: MarkdownProps['streaming'], cursor?: MarkdownProps['cursor']) => {
|
|
86
|
+
const { hasNextChunk = false, enableWordCaching = false, enableMathCaching = true } = config || {};
|
|
87
|
+
|
|
88
|
+
const [output, setOutput] = useState('');
|
|
89
|
+
const streamBuffer = useRef({ ...STREAM_BUFFER_INIT });
|
|
90
|
+
|
|
91
|
+
const pushToken = useCallback((type: TokenType) => {
|
|
92
|
+
streamBuffer.current.tokens = [...streamBuffer.current.tokens, type];
|
|
93
|
+
streamBuffer.current.token = type;
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
const popToken = useCallback(() => {
|
|
97
|
+
const { tokens } = streamBuffer.current;
|
|
98
|
+
if (tokens.length <= 1) return;
|
|
99
|
+
|
|
100
|
+
const newTokens = [...tokens.slice(0, -1)];
|
|
101
|
+
streamBuffer.current.tokens = newTokens;
|
|
102
|
+
streamBuffer.current.token = newTokens[newTokens.length - 1];
|
|
103
|
+
}, []);
|
|
104
|
+
|
|
105
|
+
const flushOutput = (needPopToken = true) => {
|
|
106
|
+
if (needPopToken) popToken();
|
|
107
|
+
|
|
108
|
+
streamBuffer.current.pending = '';
|
|
109
|
+
streamBuffer.current.blockMathEnding = false;
|
|
110
|
+
const renderText = streamBuffer.current.rawStream;
|
|
111
|
+
if (renderText) {
|
|
112
|
+
setOutput(renderText);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const handleChunk = (chunk: string) => {
|
|
117
|
+
const buffer = streamBuffer.current;
|
|
118
|
+
for (const char of chunk) {
|
|
119
|
+
buffer.rawStream += char;
|
|
120
|
+
buffer.pending += char;
|
|
121
|
+
|
|
122
|
+
const { token, pending, tokens, emphasisCount } = buffer;
|
|
123
|
+
switch (token) {
|
|
124
|
+
case TokenType.Image: {
|
|
125
|
+
/**
|
|
126
|
+
* \![
|
|
127
|
+
* ^
|
|
128
|
+
*/
|
|
129
|
+
const isInvalidStart = pending.indexOf('![') === -1;
|
|
130
|
+
/**
|
|
131
|
+
* \![image]()
|
|
132
|
+
* ^
|
|
133
|
+
*/
|
|
134
|
+
const isImageEnd = char === ')' || char === '\n';
|
|
135
|
+
if (isInvalidStart || isImageEnd) {
|
|
136
|
+
if (tokens[tokens.length - 2] === TokenType.Link) {
|
|
137
|
+
popToken();
|
|
138
|
+
} else {
|
|
139
|
+
flushOutput();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case TokenType.Link: {
|
|
145
|
+
// not support link reference definitions, [foo]: /url "title" \n[foo]
|
|
146
|
+
const isReferenceLink = pending.endsWith(']:');
|
|
147
|
+
const isLinkEnd = char === ')' || char === '\n';
|
|
148
|
+
const isImageInLink = char === '!';
|
|
149
|
+
if (isImageInLink) {
|
|
150
|
+
pushToken(TokenType.Image);
|
|
151
|
+
} else if (isLinkEnd || isReferenceLink) {
|
|
152
|
+
flushOutput();
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case TokenType.Heading: {
|
|
157
|
+
/**
|
|
158
|
+
* # token / ## token / #####token
|
|
159
|
+
* ^ ^ ^
|
|
160
|
+
*/
|
|
161
|
+
buffer.headingLevel++;
|
|
162
|
+
|
|
163
|
+
const shouldFlushOutput = char !== '#' || buffer.headingLevel >= 6;
|
|
164
|
+
if (shouldFlushOutput) {
|
|
165
|
+
flushOutput();
|
|
166
|
+
buffer.headingLevel = 0;
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case TokenType.MaybeEmphasis: {
|
|
171
|
+
/**
|
|
172
|
+
* /* / *\/n
|
|
173
|
+
^ ^
|
|
174
|
+
*/
|
|
175
|
+
const shouldFlushOutput = char === ' ' || char === '\n';
|
|
176
|
+
if (shouldFlushOutput) {
|
|
177
|
+
flushOutput();
|
|
178
|
+
} else if (Markdown_Symbols.emphasis.includes(char)) {
|
|
179
|
+
buffer.emphasisCount++;
|
|
180
|
+
} else {
|
|
181
|
+
popToken();
|
|
182
|
+
if (emphasisCount === 1) {
|
|
183
|
+
/**
|
|
184
|
+
* _token_ / *token*
|
|
185
|
+
* ^ ^
|
|
186
|
+
*/
|
|
187
|
+
pushToken(TokenType.Emphasis);
|
|
188
|
+
} else if (emphasisCount === 2) {
|
|
189
|
+
/**
|
|
190
|
+
* __token__ / **token**
|
|
191
|
+
* ^ ^
|
|
192
|
+
*/
|
|
193
|
+
pushToken(TokenType.Strong);
|
|
194
|
+
} else if (emphasisCount === 3) {
|
|
195
|
+
/**
|
|
196
|
+
* ___token___ / ***token***
|
|
197
|
+
* ^ ^
|
|
198
|
+
*/
|
|
199
|
+
pushToken(TokenType.Emphasis);
|
|
200
|
+
pushToken(TokenType.Strong);
|
|
201
|
+
} else {
|
|
202
|
+
// no more than 3
|
|
203
|
+
buffer.emphasisCount = 0;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case TokenType.Strong: {
|
|
210
|
+
/**
|
|
211
|
+
* __token__ / **token**
|
|
212
|
+
* ^ ^
|
|
213
|
+
*/
|
|
214
|
+
if (char === '\n') {
|
|
215
|
+
flushOutput();
|
|
216
|
+
} else if (pending.endsWith('**') || pending.endsWith('__')) {
|
|
217
|
+
if (tokens[tokens.length - 2] === TokenType.Emphasis) {
|
|
218
|
+
popToken();
|
|
219
|
+
} else {
|
|
220
|
+
flushOutput();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case TokenType.Emphasis: {
|
|
227
|
+
/**
|
|
228
|
+
* _token_ / *token*
|
|
229
|
+
* ^ ^
|
|
230
|
+
*/
|
|
231
|
+
if (char === '\n') {
|
|
232
|
+
flushOutput();
|
|
233
|
+
buffer.emphasisCount = 0;
|
|
234
|
+
} else if (Markdown_Symbols.emphasis.includes(char)) {
|
|
235
|
+
flushOutput();
|
|
236
|
+
buffer.emphasisCount = 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case TokenType.XML: {
|
|
242
|
+
/**
|
|
243
|
+
* <XML /> /<XML></XML>
|
|
244
|
+
* ^ ^
|
|
245
|
+
*/
|
|
246
|
+
const shouldFlushOutput = char === '>' || pending === '< ' || char === '\n';
|
|
247
|
+
if (shouldFlushOutput) {
|
|
248
|
+
flushOutput();
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case TokenType.MaybeCode: {
|
|
254
|
+
if (char === '`') {
|
|
255
|
+
buffer.backtickCount++;
|
|
256
|
+
} else {
|
|
257
|
+
if (buffer.backtickCount > 2) {
|
|
258
|
+
/**
|
|
259
|
+
* ```
|
|
260
|
+
* ^
|
|
261
|
+
*/
|
|
262
|
+
flushOutput();
|
|
263
|
+
buffer.backtickCount = 0;
|
|
264
|
+
} else {
|
|
265
|
+
/**
|
|
266
|
+
* ``
|
|
267
|
+
* ^
|
|
268
|
+
*/
|
|
269
|
+
popToken();
|
|
270
|
+
pushToken(TokenType.Code);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
case TokenType.Code: {
|
|
276
|
+
if (char === '`') {
|
|
277
|
+
buffer.backtickCount--;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (buffer.backtickCount === 0) {
|
|
281
|
+
flushOutput();
|
|
282
|
+
buffer.backtickCount = 0;
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case TokenType.MaybeHr: {
|
|
287
|
+
if (char !== '-' && char !== '=') {
|
|
288
|
+
flushOutput();
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case TokenType.MaybeList: {
|
|
293
|
+
if (char !== ' ') {
|
|
294
|
+
flushOutput();
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case TokenType.MaybeInlineMath: {
|
|
299
|
+
/**
|
|
300
|
+
* $ / $$
|
|
301
|
+
* ^ ^
|
|
302
|
+
*/
|
|
303
|
+
if (char === '$') {
|
|
304
|
+
buffer.dollarCount++;
|
|
305
|
+
if (buffer.dollarCount === 2) {
|
|
306
|
+
// $$ 块级公式
|
|
307
|
+
popToken();
|
|
308
|
+
pushToken(TokenType.MaybeBlockMath);
|
|
309
|
+
buffer.mathDelimiter = '$$';
|
|
310
|
+
}
|
|
311
|
+
} else if (char === '\n') {
|
|
312
|
+
// $ 后跟换行,不是有效的公式
|
|
313
|
+
flushOutput();
|
|
314
|
+
buffer.dollarCount = 0;
|
|
315
|
+
buffer.mathDelimiter = '';
|
|
316
|
+
} else {
|
|
317
|
+
// 确认为行内公式
|
|
318
|
+
popToken();
|
|
319
|
+
pushToken(TokenType.InlineMath);
|
|
320
|
+
buffer.mathDelimiter = '$';
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case TokenType.InlineMath: {
|
|
325
|
+
/**
|
|
326
|
+
* $x^2$ / \(x^2\)
|
|
327
|
+
* ^ ^
|
|
328
|
+
*/
|
|
329
|
+
if (buffer.mathDelimiter === '$') {
|
|
330
|
+
if (char === '$') {
|
|
331
|
+
flushOutput();
|
|
332
|
+
buffer.dollarCount = 0;
|
|
333
|
+
buffer.mathDelimiter = '';
|
|
334
|
+
} else if (char === '\n') {
|
|
335
|
+
// 行内公式不应跨行
|
|
336
|
+
flushOutput();
|
|
337
|
+
buffer.dollarCount = 0;
|
|
338
|
+
buffer.mathDelimiter = '';
|
|
339
|
+
}
|
|
340
|
+
} else if (buffer.mathDelimiter === '\\(') {
|
|
341
|
+
if (pending.endsWith('\\)')) {
|
|
342
|
+
flushOutput();
|
|
343
|
+
buffer.mathDelimiter = '';
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
case TokenType.MaybeBlockMath: {
|
|
349
|
+
/**
|
|
350
|
+
* $$
|
|
351
|
+
* ^
|
|
352
|
+
*/
|
|
353
|
+
if (char !== '$') {
|
|
354
|
+
// $$ 后跟任何非 $ 字符,确认为块级公式
|
|
355
|
+
popToken();
|
|
356
|
+
pushToken(TokenType.BlockMath);
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case TokenType.BlockMath: {
|
|
361
|
+
/**
|
|
362
|
+
* $$E=mc^2$$
|
|
363
|
+
* ^^
|
|
364
|
+
*/
|
|
365
|
+
// 处理 $$ 块级公式
|
|
366
|
+
if (buffer.mathDelimiter === '$$') {
|
|
367
|
+
// 检测是否遇到结束的 $$
|
|
368
|
+
if (char === '$') {
|
|
369
|
+
buffer.dollarCount++;
|
|
370
|
+
if (buffer.dollarCount === 2) {
|
|
371
|
+
// 遇到了结束 $$,立即释放缓存
|
|
372
|
+
flushOutput();
|
|
373
|
+
buffer.dollarCount = 0;
|
|
374
|
+
buffer.mathDelimiter = '';
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
buffer.dollarCount = 0;
|
|
378
|
+
}
|
|
379
|
+
} else if (buffer.mathDelimiter === '\\[') {
|
|
380
|
+
// 处理 \[...\] 块级公式
|
|
381
|
+
if (pending.endsWith('\\]')) {
|
|
382
|
+
flushOutput();
|
|
383
|
+
buffer.mathDelimiter = '';
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
case TokenType.MaybeBackslashMath: {
|
|
389
|
+
/**
|
|
390
|
+
* \( / \[
|
|
391
|
+
* ^ ^
|
|
392
|
+
*/
|
|
393
|
+
if (char === '(') {
|
|
394
|
+
// \( 行内公式
|
|
395
|
+
popToken();
|
|
396
|
+
pushToken(TokenType.InlineMath);
|
|
397
|
+
buffer.mathDelimiter = '\\(';
|
|
398
|
+
} else if (char === '[') {
|
|
399
|
+
// \[ 块级公式
|
|
400
|
+
popToken();
|
|
401
|
+
pushToken(TokenType.BlockMath);
|
|
402
|
+
buffer.mathDelimiter = '\\[';
|
|
403
|
+
} else {
|
|
404
|
+
// 不是数学公式,普通反斜杠
|
|
405
|
+
flushOutput();
|
|
406
|
+
buffer.mathDelimiter = '';
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
case TokenType.Word: {
|
|
411
|
+
/**
|
|
412
|
+
* Hello world
|
|
413
|
+
* ^
|
|
414
|
+
* 缓存英文单词,直到遇到分隔符(空格、标点等)
|
|
415
|
+
*/
|
|
416
|
+
if (isWordSeparator(char)) {
|
|
417
|
+
// 遇到分隔符,释放缓存显示完整单词
|
|
418
|
+
flushOutput();
|
|
419
|
+
} else if (!isWordChar(char)) {
|
|
420
|
+
// 遇到非单词字符且非分隔符(如 Markdown 符号),也释放缓存
|
|
421
|
+
flushOutput();
|
|
422
|
+
}
|
|
423
|
+
// 否则继续缓存单词字符
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
default: {
|
|
427
|
+
buffer.pending = char;
|
|
428
|
+
|
|
429
|
+
if (char === '!') {
|
|
430
|
+
pushToken(TokenType.Image);
|
|
431
|
+
} else if (char === '[') {
|
|
432
|
+
pushToken(TokenType.Link);
|
|
433
|
+
} else if (char === '#') {
|
|
434
|
+
pushToken(TokenType.Heading);
|
|
435
|
+
} else if (char === '_' || char === '*') {
|
|
436
|
+
pushToken(TokenType.MaybeEmphasis);
|
|
437
|
+
buffer.emphasisCount = 1;
|
|
438
|
+
} else if (char === '<') {
|
|
439
|
+
pushToken(TokenType.XML);
|
|
440
|
+
} else if (char === '`') {
|
|
441
|
+
pushToken(TokenType.MaybeCode);
|
|
442
|
+
buffer.backtickCount = 1;
|
|
443
|
+
} else if (char === '-' || char === '=') {
|
|
444
|
+
pushToken(TokenType.MaybeHr);
|
|
445
|
+
} else if (Markdown_Symbols.list.includes(char)) {
|
|
446
|
+
pushToken(TokenType.MaybeList);
|
|
447
|
+
} else if (enableMathCaching && char === '$') {
|
|
448
|
+
// 只有启用公式缓存时,才缓存 $ 符号的公式
|
|
449
|
+
pushToken(TokenType.MaybeInlineMath);
|
|
450
|
+
buffer.dollarCount = 1;
|
|
451
|
+
buffer.mathDelimiter = '';
|
|
452
|
+
} else if (enableMathCaching && char === '\\') {
|
|
453
|
+
// 只有启用公式缓存时,才缓存 \ 开头的公式
|
|
454
|
+
pushToken(TokenType.MaybeBackslashMath);
|
|
455
|
+
} else if (enableWordCaching && isEnglishLetter(char)) {
|
|
456
|
+
// 只有启用单词缓存时,才缓存英文单词
|
|
457
|
+
pushToken(TokenType.Word);
|
|
458
|
+
} else {
|
|
459
|
+
flushOutput(false);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const cursorContent = useMemo(() => {
|
|
467
|
+
if (config?.enableAnimation) return '';
|
|
468
|
+
if (cursor) {
|
|
469
|
+
if (cursor === 'dot') return ' :dot:';
|
|
470
|
+
if (cursor === 'underline') return ' :underline:';
|
|
471
|
+
return ' :dot:';
|
|
472
|
+
}
|
|
473
|
+
return '';
|
|
474
|
+
}, [cursor]);
|
|
475
|
+
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
if (!input) {
|
|
478
|
+
setOutput('');
|
|
479
|
+
streamBuffer.current = { ...STREAM_BUFFER_INIT };
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (typeof input !== 'string') {
|
|
484
|
+
console.error(`X-Markdown: input must be string, not ${typeof input}.`);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (!hasNextChunk) {
|
|
489
|
+
setOutput(input);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const chunk = input.slice(streamBuffer.current.processedLength);
|
|
494
|
+
if (chunk.length) {
|
|
495
|
+
streamBuffer.current.processedLength += chunk.length;
|
|
496
|
+
handleChunk(chunk);
|
|
497
|
+
}
|
|
498
|
+
}, [input, hasNextChunk]);
|
|
499
|
+
|
|
500
|
+
return output + cursorContent;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export default useStreaming;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useTyping = ({ content, typing }) => {
|
|
4
|
+
const [index, setIndex] = useState(0);
|
|
5
|
+
const timer = useRef<NodeJS.Timeout>();
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (typing) {
|
|
9
|
+
timer.current = setInterval(() => {
|
|
10
|
+
setIndex((v) => v + 1);
|
|
11
|
+
}, typeof typing === 'number' ? typing : 5);
|
|
12
|
+
} else {
|
|
13
|
+
timer.current && clearInterval(timer.current);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return () => clearInterval(timer.current);
|
|
17
|
+
}, [typing]);
|
|
18
|
+
|
|
19
|
+
if (!typing) return content;
|
|
20
|
+
|
|
21
|
+
return content.slice(0, index);
|
|
22
|
+
};
|