feat:【antd】【ai】chat “返回异常时空消息删除”的迁移

This commit is contained in:
YunaiV
2025-11-15 19:06:37 +08:00
parent 6dd9e9e699
commit 71e638188e
2 changed files with 20 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import { requestClient } from '#/api/request';
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
const accessStore = useAccessStore();
export namespace AiChatMessageApi {
export interface ChatMessage {
id: number; // 编号
@@ -26,10 +27,21 @@ export namespace AiChatMessageApi {
documentName: string; // 文档名称
id: number; // 段落编号
}[];
webSearchPages?: WebSearchPage[]; // 联网搜索结果
createTime: Date; // 创建时间
roleAvatar: string; // 角色头像
userAvatar: string; // 用户头像
}
/** 联网搜索页面接口 */
export interface WebSearchPage {
name: string; // 网站名称
icon: string; // 网站图标 URL
title: string; // 页面标题
url: string; // 页面 URL
snippet: string; // 简短描述
summary: string; // 内容摘要
}
}
// 消息列表
@@ -47,6 +59,7 @@ export function sendChatMessageStream(
content: string,
ctrl: any,
enableContext: boolean,
enableWebSearch: boolean,
onMessage: any,
onError: any,
onClose: any,
@@ -63,6 +76,7 @@ export function sendChatMessageStream(
conversationId,
content,
useContext: enableContext,
useSearch: enableWebSearch,
}),
onmessage: onMessage,
onerror: onError,

View File

@@ -359,6 +359,10 @@ async function doSendMessageStream(userMessage: AiChatMessageApi.ChatMessage) {
const { code, data, msg } = JSON.parse(res.data);
if (code !== 0) {
await alert(`对话异常! ${msg}`);
// 如果未接收到消息,则进行删除
if (receiveMessageFullText.value === '') {
activeMessageList.value.pop();
}
return;
}
@@ -382,7 +386,8 @@ async function doSendMessageStream(userMessage: AiChatMessageApi.ChatMessage) {
await scrollToBottom();
},
(error: any) => {
alert(`对话异常! ${error}`);
// 异常提示,并停止流
alert(`对话异常!`);
stopStream();
// 需要抛出异常,禁止重试
throw error;