diff --git a/src/renderer/src/databases/upgrades.ts b/src/renderer/src/databases/upgrades.ts index 3303ae467a..b9449b1bfd 100644 --- a/src/renderer/src/databases/upgrades.ts +++ b/src/renderer/src/databases/upgrades.ts @@ -222,7 +222,7 @@ export async function upgradeToV7(tx: Transaction): Promise { if (oldMessage.metadata?.webSearch) { hasCitationData = true citationDataToCreate.response = { - results: oldMessage.metadata.webSearch?.results, + results: oldMessage.metadata.webSearch, source: WebSearchSource.WEBSEARCH } } diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 08c1bda2e4..22c9391fbb 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -98,7 +98,7 @@ "artifacts.button.preview": "Preview", "artifacts.preview.openExternal.error.content": "Error opening the external browser.", "assistant.search.placeholder": "Search", - "deeply_thought": "Deeply thought ({{secounds}} seconds)", + "deeply_thought": "Deeply thought ({{seconds}} seconds)", "default.description": "Hello, I'm Default Assistant. You can start chatting with me right away", "default.name": "Default Assistant", "default.topic.name": "Default Topic", @@ -183,6 +183,7 @@ "settings.top_p": "Top-P", "settings.top_p.tip": "Default value is 1, the smaller the value, the less variety in the answers, the easier to understand, the larger the value, the larger the range of the AI's vocabulary, the more diverse", "suggestions.title": "Suggested Questions", + "thinking": "Thinking ({{seconds}} seconds)", "topics.auto_rename": "Auto Rename", "topics.clear.title": "Clear Messages", "topics.copy.image": "Copy as image", @@ -254,7 +255,6 @@ "input.thinking.mode.custom": "Custom", "input.thinking.mode.custom.tip": "The maximum number of tokens the model can think. Need to consider the context limit of the model, otherwise an error will be reported", "input.thinking.mode.tokens.tip": "Set the number of thinking tokens to use.", - "thinking": "Thinking", "input.thinking.budget_exceeds_max": "Thinking budget exceeds the maximum token number" }, "code_block": { diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 2280357eb3..bc15a32b7d 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -98,7 +98,7 @@ "artifacts.button.preview": "プレビュー", "artifacts.preview.openExternal.error.content": "外部ブラウザの起動に失敗しました。", "assistant.search.placeholder": "検索", - "deeply_thought": "深く考えています({{secounds}} 秒)", + "deeply_thought": "深く考えています({{seconds}} 秒)", "default.description": "こんにちは、私はデフォルトのアシスタントです。すぐにチャットを始められます。", "default.name": "デフォルトアシスタント", "default.topic.name": "デフォルトトピック", @@ -183,7 +183,7 @@ "settings.top_p": "Top-P", "settings.top_p.tip": "デフォルト値は1で、値が小さいほど回答の多様性が減り、理解しやすくなります。値が大きいほど、AIの語彙範囲が広がり、多様性が増します", "suggestions.title": "提案された質問", - "thinking": "思考中...", + "thinking": "思考中(用時 {{seconds}} 秒)", "topics.auto_rename": "自動リネーム", "topics.clear.title": "メッセージをクリア", "topics.copy.image": "画像としてコピー", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 24274355dd..bb9e43a950 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -97,7 +97,7 @@ "artifacts.button.preview": "Предпросмотр", "artifacts.preview.openExternal.error.content": "Внешний браузер открылся с ошибкой", "assistant.search.placeholder": "Поиск", - "deeply_thought": "Мыслим ({{secounds}} секунд)", + "deeply_thought": "Мыслим ({{seconds}} секунд)", "default.description": "Привет, я Ассистент по умолчанию. Вы можете начать общаться со мной прямо сейчас", "default.name": "Ассистент по умолчанию", "default.topic.name": "Топик по умолчанию", @@ -182,7 +182,7 @@ "settings.top_p": "Top-P", "settings.top_p.tip": "Значение по умолчанию 1, чем меньше значение, тем меньше вариативности в ответах, тем проще понять, чем больше значение, тем больше вариативности в ответах, тем больше разнообразие", "suggestions.title": "Предложенные вопросы", - "thinking": "Мыслим", + "thinking": "Мыслим ({{seconds}} секунд)", "topics.auto_rename": "Автопереименование", "topics.clear.title": "Очистить сообщения", "topics.copy.image": "Скопировать как изображение", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index fd8444b717..cf788b540c 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -98,7 +98,7 @@ "artifacts.button.preview": "预览", "artifacts.preview.openExternal.error.content": "外部浏览器打开出错", "assistant.search.placeholder": "搜索", - "deeply_thought": "已深度思考(用时 {{secounds}} 秒)", + "deeply_thought": "已深度思考(用时 {{seconds}} 秒)", "default.description": "你好,我是默认助手。你可以立刻开始跟我聊天。", "default.name": "默认助手", "default.topic.name": "默认话题", @@ -195,7 +195,7 @@ "settings.top_p": "Top-P", "settings.top_p.tip": "默认值为 1,值越小,AI 生成的内容越单调,也越容易理解;值越大,AI 回复的词汇围越大,越多样化", "suggestions.title": "建议的问题", - "thinking": "思考中", + "thinking": "思考中(用时 {{seconds}} 秒)", "topics.auto_rename": "生成话题名", "topics.clear.title": "清空消息", "topics.copy.image": "复制为图片", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index d110b3c32d..a11d29b0ff 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -98,7 +98,7 @@ "artifacts.button.preview": "預覽", "artifacts.preview.openExternal.error.content": "外部瀏覽器開啟出錯", "assistant.search.placeholder": "搜尋", - "deeply_thought": "已深度思考(用時 {{secounds}} 秒)", + "deeply_thought": "已深度思考(用時 {{seconds}} 秒)", "default.description": "你好,我是預設助手。你可以立即開始與我聊天。", "default.name": "預設助手", "default.topic.name": "預設話題", @@ -183,7 +183,7 @@ "settings.top_p": "Top-P", "settings.top_p.tip": "模型生成文字的隨機程度。值越小,AI 生成的內容越單調,也越容易理解;值越大,AI 回覆的詞彙範圍越大,越多樣化", "suggestions.title": "建議的問題", - "thinking": "思考中", + "thinking": "思考中(用時 {{seconds}} 秒)", "topics.auto_rename": "自動重新命名", "topics.clear.title": "清空訊息", "topics.copy.image": "複製為圖片", diff --git a/src/renderer/src/pages/home/Messages/Blocks/ThinkingBlock.tsx b/src/renderer/src/pages/home/Messages/Blocks/ThinkingBlock.tsx index 65a2f31d12..28702b739a 100644 --- a/src/renderer/src/pages/home/Messages/Blocks/ThinkingBlock.tsx +++ b/src/renderer/src/pages/home/Messages/Blocks/ThinkingBlock.tsx @@ -1,14 +1,149 @@ -import type { ThinkingMessageBlock } from '@renderer/types/newMessage' -import React from 'react' +import { CheckOutlined } from '@ant-design/icons' +import { useSettings } from '@renderer/hooks/useSettings' +import { MessageBlockStatus, type ThinkingMessageBlock } from '@renderer/types/newMessage' +import { Collapse, message as antdMessage, Tooltip } from 'antd' +import { memo, useCallback, useEffect, useMemo, useState } from 'react' +import { useTranslation } from 'react-i18next' +import BarLoader from 'react-spinners/BarLoader' +import styled from 'styled-components' -import MessageThought from '../MessageThought' +import Markdown from '../../Markdown/Markdown' interface Props { block: ThinkingMessageBlock } const ThinkingBlock: React.FC = ({ block }) => { - // 创建思考过程的显示组件 - return + const [copied, setCopied] = useState(false) + const { t } = useTranslation() + const { messageFont, fontSize, thoughtAutoCollapse } = useSettings() + const [activeKey, setActiveKey] = useState<'thought' | ''>(thoughtAutoCollapse ? '' : 'thought') + + const isThinking = useMemo(() => block.status === MessageBlockStatus.STREAMING, [block.status]) + + const fontFamily = useMemo(() => { + return messageFont === 'serif' + ? 'serif' + : '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans","Helvetica Neue", sans-serif' + }, [messageFont]) + + useEffect(() => { + if (!isThinking && thoughtAutoCollapse) { + setActiveKey('') + } else { + setActiveKey('thought') + } + }, [isThinking, thoughtAutoCollapse]) + + const copyThought = useCallback(() => { + if (block.content) { + navigator.clipboard + .writeText(block.content) + .then(() => { + antdMessage.success({ content: t('message.copied'), key: 'copy-message' }) + setCopied(true) + setTimeout(() => setCopied(false), 2000) + }) + .catch((error) => { + console.error('Failed to copy text:', error) + antdMessage.error({ content: t('message.copy.failed'), key: 'copy-message-error' }) + }) + } + }, [block.content, t]) + + if (!block.content) { + return null + } + + const thinkingTime = block.thinking_millsec || 0 + const thinkingTimeSeconds = (thinkingTime / 1000).toFixed(1) + + return ( + setActiveKey((key) => (key ? '' : 'thought'))} + className="message-thought-container" + items={[ + { + key: 'thought', + label: ( + + + {t(isThinking ? 'chat.thinking' : 'chat.deeply_thought', { + seconds: thinkingTimeSeconds + })} + + {isThinking && } + {!isThinking && ( + + { + e.stopPropagation() + copyThought() + }} + aria-label={t('common.copy')}> + {!copied && } + {copied && } + + + )} + + ), + children: ( + // FIXME: 临时兼容 +
+ +
+ ) + } + ]} + /> + ) } -export default React.memo(ThinkingBlock) +const CollapseContainer = styled(Collapse)` + margin-bottom: 15px; +` + +const MessageTitleLabel = styled.div` + display: flex; + flex-direction: row; + align-items: center; + height: 22px; + gap: 15px; +` + +const ThinkingText = styled.span` + color: var(--color-text-2); +` + +const ActionButton = styled.button` + background: none; + border: none; + color: var(--color-text-2); + cursor: pointer; + padding: 4px; + display: flex; + align-items: center; + justify-content: center; + margin-left: auto; + opacity: 0.6; + transition: all 0.3s; + + &:hover { + opacity: 1; + color: var(--color-text); + } + + &:focus-visible { + outline: 2px solid var(--color-primary); + outline-offset: 2px; + } + + .iconfont { + font-size: 14px; + } +` + +export default memo(ThinkingBlock) diff --git a/src/renderer/src/pages/home/Messages/MessageThought.tsx b/src/renderer/src/pages/home/Messages/MessageThought.tsx deleted file mode 100644 index d653c8a6e8..0000000000 --- a/src/renderer/src/pages/home/Messages/MessageThought.tsx +++ /dev/null @@ -1,136 +0,0 @@ -import { CheckOutlined } from '@ant-design/icons' -import { useSettings } from '@renderer/hooks/useSettings' -import { ThinkingMessageBlock } from '@renderer/types/newMessage' -import { Collapse, message as antdMessage, Tooltip } from 'antd' -import { FC, useEffect, useMemo, useState } from 'react' -import { useTranslation } from 'react-i18next' -import BarLoader from 'react-spinners/BarLoader' -import styled from 'styled-components' - -import Markdown from '../Markdown/Markdown' - -interface Props { - message: ThinkingMessageBlock -} - -const MessageThought: FC = ({ message }) => { - const [activeKey, setActiveKey] = useState<'thought' | ''>('thought') - const [copied, setCopied] = useState(false) - const isThinking = !message.content - const { t } = useTranslation() - const { messageFont, fontSize, thoughtAutoCollapse } = useSettings() - const fontFamily = useMemo(() => { - return messageFont === 'serif' - ? 'serif' - : '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans","Helvetica Neue", sans-serif' - }, [messageFont]) - - useEffect(() => { - if (!isThinking && thoughtAutoCollapse) setActiveKey('') - }, [isThinking, thoughtAutoCollapse]) - - if (!message.content) { - return null - } - - const copyThought = () => { - if (message.content) { - navigator.clipboard.writeText(message.content) - antdMessage.success({ content: t('message.copied'), key: 'copy-message' }) - setCopied(true) - setTimeout(() => setCopied(false), 2000) - } - } - - const thinkingTime = message.thinking_millsec || 0 - const thinkingTimeSeconds = (thinkingTime / 1000).toFixed(1) - const isPaused = message.status === 'paused' - - return ( - setActiveKey((key) => (key ? '' : 'thought'))} - className="message-thought-container" - items={[ - { - key: 'thought', - label: ( - - - {isThinking ? t('chat.thinking') : t('chat.deeply_thought', { secounds: thinkingTimeSeconds })} - - {isThinking && !isPaused && } - {(!isThinking || isPaused) && ( - - { - e.stopPropagation() - copyThought() - }} - aria-label={t('common.copy')}> - {!copied && } - {copied && } - - - )} - - ), - children: ( - // FIXME: 临时兼容 -
- -
- ) - } - ]} - /> - ) -} - -const CollapseContainer = styled(Collapse)` - margin-bottom: 15px; -` - -const MessageTitleLabel = styled.div` - display: flex; - flex-direction: row; - align-items: center; - height: 22px; - gap: 15px; -` - -const TinkingText = styled.span` - color: var(--color-text-2); -` - -const ActionButton = styled.button` - background: none; - border: none; - color: var(--color-text-2); - cursor: pointer; - padding: 4px; - display: flex; - align-items: center; - justify-content: center; - margin-left: auto; - opacity: 0.6; - transition: all 0.3s; - - &:hover { - opacity: 1; - color: var(--color-text); - } - - &:focus-visible { - outline: 2px solid var(--color-primary); - outline-offset: 2px; - } - - .iconfont { - font-size: 14px; - } -` - -export default MessageThought diff --git a/src/renderer/src/pages/settings/MCPSettings/McpPrompt.tsx b/src/renderer/src/pages/settings/MCPSettings/McpPrompt.tsx index a1c925c525..892c2410e3 100644 --- a/src/renderer/src/pages/settings/MCPSettings/McpPrompt.tsx +++ b/src/renderer/src/pages/settings/MCPSettings/McpPrompt.tsx @@ -1,5 +1,5 @@ import { MCPPrompt } from '@renderer/types' -import { Collapse, Descriptions, Empty, Flex, Tag, Tooltip, Typography } from 'antd' +import { Collapse, Descriptions, Empty, Flex, Tooltip, Typography } from 'antd' import { useTranslation } from 'react-i18next' import styled from 'styled-components' @@ -22,11 +22,11 @@ const MCPPromptsSection = ({ prompts }: MCPPromptsSectionProps) => { + {arg.name} {arg.required && ( - Required + * )} diff --git a/src/renderer/src/pages/settings/MCPSettings/McpTool.tsx b/src/renderer/src/pages/settings/MCPSettings/McpTool.tsx index 9bd0cc97bb..788db5b77e 100644 --- a/src/renderer/src/pages/settings/MCPSettings/McpTool.tsx +++ b/src/renderer/src/pages/settings/MCPSettings/McpTool.tsx @@ -51,11 +51,11 @@ const MCPToolsSection = ({ tools, server, onToggleTool }: MCPToolsSectionProps) + {key} {tool.inputSchema.required?.includes(key) && ( - Required + * )} diff --git a/src/renderer/src/store/thunk/messageThunk.ts b/src/renderer/src/store/thunk/messageThunk.ts index 7bb0991d30..cd6f37095f 100644 --- a/src/renderer/src/store/thunk/messageThunk.ts +++ b/src/renderer/src/store/thunk/messageThunk.ts @@ -1,4 +1,5 @@ import db from '@renderer/databases' +import { autoRenameTopic } from '@renderer/hooks/useTopic' import { fetchChatCompletion } from '@renderer/services/ApiService' import { createStreamProcessor, type StreamProcessorCallbacks } from '@renderer/services/StreamProcessingService' import { estimateMessagesUsage } from '@renderer/services/TokenService' @@ -590,6 +591,9 @@ const fetchAndProcessAssistantResponseImpl = async ( const contextForUsage = userMsgIndex !== -1 ? orderedMsgs.slice(0, userMsgIndex + 1) : [] const finalContextWithAssistant = [...contextForUsage, finalAssistantMsg] + // 更新topic的name + autoRenameTopic(assistant, topicId) + const usage = await estimateMessagesUsage({ assistant, messages: finalContextWithAssistant }) response.usage = usage } diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index 5f90e2bb02..abec7e37b3 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -89,7 +89,7 @@ export type LegacyMessage = { // Zhipu or Hunyuan webSearchInfo?: any[] // Web search - webSearch?: WebSearchResponse + webSearch?: WebSearchProviderResponse // MCP Tools mcpTools?: MCPToolResponse[] // Generate Image