diff --git a/web/src/components/playground/MessageContent.js b/web/src/components/playground/MessageContent.js
index 714a6550..e71971e3 100644
--- a/web/src/components/playground/MessageContent.js
+++ b/web/src/components/playground/MessageContent.js
@@ -15,10 +15,23 @@ const MessageContent = ({ message, className, styleState, onToggleReasoningExpan
const { t } = useTranslation();
if (message.status === 'error') {
+ let errorText;
+
+ if (Array.isArray(message.content)) {
+ const textContent = message.content.find(item => item.type === 'text');
+ errorText = textContent && textContent.text && typeof textContent.text === 'string'
+ ? textContent.text
+ : t('请求发生错误');
+ } else if (typeof message.content === 'string') {
+ errorText = message.content;
+ } else {
+ errorText = t('请求发生错误');
+ }
+
return (
@@ -230,7 +252,6 @@ const MessageContent = ({ message, className, styleState, onToggleReasoningExpan
);
}
} else {
- // 用户文本消息
return (
diff --git a/web/src/pages/Playground/Playground.js b/web/src/pages/Playground/Playground.js
index db3d8938..661b0db9 100644
--- a/web/src/pages/Playground/Playground.js
+++ b/web/src/pages/Playground/Playground.js
@@ -712,18 +712,41 @@ const Playground = () => {
const handleMessageCopy = useCallback((message) => {
if (!message.content) return;
+ let textToCopy;
+
+ if (Array.isArray(message.content)) {
+ const textContent = message.content.find(item => item.type === 'text');
+ if (textContent && textContent.text && typeof textContent.text === 'string') {
+ textToCopy = textContent.text;
+ } else {
+ Toast.warning({
+ content: t('此消息没有可复制的文本内容'),
+ duration: 2,
+ });
+ return;
+ }
+ } else if (typeof message.content === 'string') {
+ textToCopy = message.content;
+ } else {
+ Toast.warning({
+ content: t('无法复制此类型的消息内容'),
+ duration: 2,
+ });
+ return;
+ }
+
if (navigator.clipboard && navigator.clipboard.writeText) {
- navigator.clipboard.writeText(message.content).then(() => {
+ navigator.clipboard.writeText(textToCopy).then(() => {
Toast.success({
content: t('消息已复制到剪贴板'),
duration: 2,
});
}).catch(err => {
console.error('Clipboard API 复制失败:', err);
- fallbackCopyToClipboard(message.content);
+ fallbackCopyToClipboard(textToCopy);
});
} else {
- fallbackCopyToClipboard(message.content);
+ fallbackCopyToClipboard(textToCopy);
}
}, [t]);
@@ -790,7 +813,14 @@ const Playground = () => {
if (targetMessage.role === 'user') {
const newMessages = prevMessages.slice(0, messageIndex);
setTimeout(() => {
- onMessageSend(targetMessage.content);
+ let contentToSend;
+ if (Array.isArray(targetMessage.content)) {
+ const textContent = targetMessage.content.find(item => item.type === 'text');
+ contentToSend = textContent && textContent.text ? textContent.text : '';
+ } else {
+ contentToSend = targetMessage.content;
+ }
+ onMessageSend(contentToSend);
}, 100);
return newMessages;
} else if (targetMessage.role === 'assistant') {
@@ -802,7 +832,14 @@ const Playground = () => {
const userMessage = prevMessages[userMessageIndex];
const newMessages = prevMessages.slice(0, userMessageIndex);
setTimeout(() => {
- onMessageSend(userMessage.content);
+ let contentToSend;
+ if (Array.isArray(userMessage.content)) {
+ const textContent = userMessage.content.find(item => item.type === 'text');
+ contentToSend = textContent && textContent.text ? textContent.text : '';
+ } else {
+ contentToSend = userMessage.content;
+ }
+ onMessageSend(contentToSend);
}, 100);
return newMessages;
}