fix(chat): 将流式错误信息映射为面向用户的提示方案
This commit is contained in:
1 parent
6757ad869f
commit
10b6f9b692
8 files changed
+127
-2
No files matched your search
@@ -3,7 +3,9 @@
|
||||
* SSE 流式对话核心:消息列表、runs、发送与接收。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { applyStreamErrorToMessage, type StreamErrorLabels } from '../utils/streamErrorMessage';
|
||||
import type { ChatMessage, ChatRun, RetrieverResource } from '../types/chat.types';
|
||||
|
||||
const normalizeResources = (resources: unknown) => {
|
||||
@@ -110,6 +112,7 @@ const applyEventMetadata = (msg: ChatMessage, data: Record<string, unknown>) =>
|
||||
};
|
||||
|
||||
export function useChat() {
|
||||
const { t } = useI18n();
|
||||
const messages = ref<ChatMessage[]>([]);
|
||||
const isThinking = ref(false);
|
||||
const viewId = ref(0);
|
||||
@@ -169,6 +172,13 @@ export function useChat() {
|
||||
return String(message ?? 'Unknown error');
|
||||
};
|
||||
|
||||
const streamErrorLabels = (): StreamErrorLabels => ({
|
||||
networkDisconnectedEmpty: t('chat.streamError.networkDisconnectedEmpty'),
|
||||
partialInterrupted: t('chat.streamError.partialInterrupted'),
|
||||
upstreamDisconnected: t('chat.streamError.upstreamDisconnected'),
|
||||
generic: t('chat.streamError.generic'),
|
||||
});
|
||||
|
||||
const sendMessage = async (
|
||||
query: string,
|
||||
agentId: number,
|
||||
@@ -338,7 +348,7 @@ export function useChat() {
|
||||
} else if (eventName === 'error') {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
botMsg.content += `\n[Error: ${formatStreamError(data.message)}]`;
|
||||
applyStreamErrorToMessage(botMsg, formatStreamError(data.message), streamErrorLabels());
|
||||
run.status = 'error';
|
||||
if (messages.value === runMessages) isThinking.value = false;
|
||||
} else if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||
@@ -356,7 +366,7 @@ export function useChat() {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (botMsg) {
|
||||
const message = e instanceof Error ? e.message : 'Network Issue';
|
||||
botMsg.content += `\n[Error: ${message}]`;
|
||||
applyStreamErrorToMessage(botMsg, message, streamErrorLabels());
|
||||
}
|
||||
} finally {
|
||||
if (messages.value === runMessages) {
|
||||
|
||||
Reference in new issue
Block a user