From 76058bd749ff25c9472e66f54d38f566b2be0e1e Mon Sep 17 00:00:00 2001 From: Hao He <57698783+Harris-H@users.noreply.github.com> Date: Sat, 12 Apr 2025 10:33:14 +0800 Subject: [PATCH] feat(MessageTools): add error handling and status indicator for tool responses (#4712) * feat(MessageTools): add error handling and status indicator for tool responses * feat(i18n): add error message for tool invocation in English, Japanese, and Russian locales --- src/renderer/src/i18n/locales/en-us.json | 3 ++- src/renderer/src/i18n/locales/ja-jp.json | 3 ++- src/renderer/src/i18n/locales/ru-ru.json | 3 ++- src/renderer/src/i18n/locales/zh-cn.json | 3 ++- src/renderer/src/i18n/locales/zh-tw.json | 3 ++- .../src/pages/home/Messages/MessageTools.tsx | 22 ++++++++++++++----- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 999c2301..916d8014 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -556,7 +556,8 @@ "switch.disabled": "Please wait for the current reply to complete", "tools": { "completed": "Completed", - "invoking": "Invoking" + "invoking": "Invoking", + "error": "Error occurred" }, "topic.added": "New topic added", "upgrade.success.button": "Restart", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 57623ddd..3fb8583a 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -555,7 +555,8 @@ "switch.disabled": "現在の応答が完了するまで切り替えを無効にします", "tools": { "completed": "完了", - "invoking": "呼び出し中" + "invoking": "呼び出し中", + "error": "エラーが発生しました" }, "topic.added": "新しいトピックが追加されました", "upgrade.success.button": "再起動", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index b2f4fc99..20593127 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -556,7 +556,8 @@ "switch.disabled": "Пожалуйста, дождитесь завершения текущего ответа", "tools": { "completed": "Завершено", - "invoking": "Вызов" + "invoking": "Вызов", + "error": "Произошла ошибка" }, "topic.added": "Новый топик добавлен", "upgrade.success.button": "Перезапустить", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 14596ae1..dd2c6368 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -556,7 +556,8 @@ "switch.disabled": "请等待当前回复完成后操作", "tools": { "completed": "已完成", - "invoking": "调用中" + "invoking": "调用中", + "error": "发生错误" }, "topic.added": "话题添加成功", "upgrade.success.button": "重启", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 0e09dfb3..9097c226 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -556,7 +556,8 @@ "switch.disabled": "請等待當前回覆完成", "tools": { "completed": "已完成", - "invoking": "調用中" + "invoking": "調用中", + "error": "發生錯誤" }, "topic.added": "新話題已新增", "upgrade.success.button": "重新啟動", diff --git a/src/renderer/src/pages/home/Messages/MessageTools.tsx b/src/renderer/src/pages/home/Messages/MessageTools.tsx index 59fc0269..dcc65c63 100644 --- a/src/renderer/src/pages/home/Messages/MessageTools.tsx +++ b/src/renderer/src/pages/home/Messages/MessageTools.tsx @@ -1,4 +1,4 @@ -import { CheckOutlined, ExpandOutlined, LoadingOutlined } from '@ant-design/icons' +import { CheckOutlined, ExpandOutlined, LoadingOutlined, WarningOutlined } from '@ant-design/icons' import { useSettings } from '@renderer/hooks/useSettings' import { Message } from '@renderer/types' import { Collapse, message as antdMessage, Modal, Tooltip } from 'antd' @@ -48,6 +48,7 @@ const MessageTools: FC = ({ message }) => { const { id, tool, status, response } = toolResponse const isInvoking = status === 'invoking' const isDone = status === 'done' + const hasError = isDone && response?.isError === true const result = { params: tool.inputSchema, response: toolResponse.response @@ -59,10 +60,15 @@ const MessageTools: FC = ({ message }) => { {tool.name} - - {isInvoking ? t('message.tools.invoking') : t('message.tools.completed')} + + {isInvoking + ? t('message.tools.invoking') + : hasError + ? t('message.tools.error') + : t('message.tools.completed')} {isInvoking && } - {isDone && } + {isDone && !hasError && } + {hasError && } @@ -195,8 +201,12 @@ const ToolName = styled.span` font-size: 13px; ` -const StatusIndicator = styled.span<{ $isInvoking: boolean }>` - color: ${(props) => (props.$isInvoking ? 'var(--color-primary)' : 'var(--color-success, #52c41a)')}; +const StatusIndicator = styled.span<{ $isInvoking: boolean; $hasError?: boolean }>` + color: ${(props) => { + if (props.$hasError) return 'var(--color-error, #ff4d4f)' + if (props.$isInvoking) return 'var(--color-primary)' + return 'var(--color-success, #52c41a)' + }}; font-size: 11px; display: flex; align-items: center;