feat: 消息会话的调整和增加时间戳
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
<ChatRoleMe v-if="msg.messageRole === MessageRole.ME" :msg="msg">
|
||||
<template #header>
|
||||
<!-- 名字和时间 -->
|
||||
<ChatNameTime :showReverse="true" />
|
||||
<ChatNameTime :showReverse="true" :msg="msg" />
|
||||
</template>
|
||||
</ChatRoleMe>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<ChatRoleAI v-if="msg.messageRole === MessageRole.AI" :msg="msg">
|
||||
<template #header>
|
||||
<!-- 名字和时间 -->
|
||||
<ChatNameTime :showReverse="false" />
|
||||
<ChatNameTime :showReverse="false" :msg="msg" />
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
@@ -316,6 +316,7 @@ const loadConversationMessages = async (convId: string) => {
|
||||
messageId: msg.messageId,
|
||||
messageRole: msg.messageSenderRole === 'user' ? MessageRole.ME : MessageRole.AI,
|
||||
messageContent: msg.messageContent,
|
||||
timestamp: msg.timestamp,
|
||||
finished: true, // 历史消息已完成
|
||||
}));
|
||||
console.log("加载历史消息:", chatMsgList.value);
|
||||
@@ -348,7 +349,8 @@ const initWebSocket = async () => {
|
||||
|
||||
// 使用配置的WebSocket服务器地址
|
||||
const token = getAccessToken();
|
||||
const wsUrl = `wss://onefeel.brother7.cn/ingress/agent/ws/chat?access_token=${token}`;
|
||||
// const wsUrl = `wss://onefeel.brother7.cn/ingress/agent/ws/chat?access_token=${token}`;
|
||||
const wsUrl = `wss://onefeel.brother7.cn/ingress/nianxx/ws?token=${token}`;
|
||||
// 初始化WebSocket管理器
|
||||
webSocketManager = new WebSocketManager({
|
||||
wsUrl: wsUrl,
|
||||
@@ -408,6 +410,17 @@ const initWebSocket = async () => {
|
||||
// 处理WebSocket消息
|
||||
const handleWebSocketMessage = (data: any) => {
|
||||
console.log("收到WebSocket消息:", data);
|
||||
|
||||
if (data.type === 'notification' && data.event === 'connected') {
|
||||
console.log("WebSocket连接已建立,服务器消息:", data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'heartbeat') {
|
||||
console.log("收到心跳消息:", data);
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证关键字段(若服务端传回 conversationId/agentId,则校验是否属于当前会话)
|
||||
if (data.conversationId && data.conversationId !== conversationId.value) {
|
||||
console.warn("收到不属于当前会话的消息,忽略", data.conversationId);
|
||||
@@ -428,7 +441,7 @@ const handleWebSocketMessage = (data: any) => {
|
||||
}
|
||||
|
||||
// 优先使用 messageId 进行匹配
|
||||
const msgId = data.messageId || data.id || data.msgId;
|
||||
const msgId = data.messageId || data.reply_message_id || data.id || data.msgId;
|
||||
let aiMsgIndex = -1;
|
||||
if (msgId && pendingMap.has(msgId)) {
|
||||
aiMsgIndex = pendingMap.get(msgId);
|
||||
@@ -462,8 +475,14 @@ const handleWebSocketMessage = (data: any) => {
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
/// 对于通知类消息,如果没有明确的完成状态,默认视为已完成,触发后续处理逻辑(例如心跳、连接建立等事件)
|
||||
if (data.type === 'notification') {
|
||||
data.finish = data.finish || true; // 确保 finish 字段存在
|
||||
}
|
||||
|
||||
// 处理完成状态
|
||||
if (data.finish) {
|
||||
chatMsgList.value[aiMsgIndex].timestamp = Date.now();
|
||||
chatMsgList.value[aiMsgIndex].finished = data.finish;
|
||||
const msg = chatMsgList.value[aiMsgIndex].messageContent;
|
||||
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
@@ -554,6 +573,7 @@ const sendMessage = async (message: string, isInstruct: boolean = false) => {
|
||||
messageId: IdUtils.generateMessageId(),
|
||||
messageRole: MessageRole.ME,
|
||||
messageContent: message,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
chatMsgList.value.push(newMsg);
|
||||
inputMessage.value = "";
|
||||
|
||||
Reference in New Issue
Block a user