From 5dad0cd39b0d44d3f48e56681fda255a3f0913cc Mon Sep 17 00:00:00 2001 From: AskaEth Date: Tue, 26 May 2026 12:50:49 +0800 Subject: [PATCH] fix: use backend msg_type instead of hardcoding in server message handlers Backend now guarantees msg_type is always populated. Changed all server message handlers (stream_chunk, stream_end, thinking, tool_progress, error, voice_transcript, review) to use wsMsg.msgType with safe fallback defaults instead of hardcoded values. Also added missing ProGuard keep rules for UI screens/components/overlay to prevent R8 from stripping composables called via navigation lambdas. Co-Authored-By: Claude Opus 4.7 --- .../data/repository/ChatRepositoryImpl.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/top/yeij/cyrene/data/repository/ChatRepositoryImpl.kt b/app/src/main/java/top/yeij/cyrene/data/repository/ChatRepositoryImpl.kt index 812d9c4..eabaf2b 100644 --- a/app/src/main/java/top/yeij/cyrene/data/repository/ChatRepositoryImpl.kt +++ b/app/src/main/java/top/yeij/cyrene/data/repository/ChatRepositoryImpl.kt @@ -388,7 +388,7 @@ class ChatRepositoryImpl( sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = "assistant", content = streamingContent, - msgType = "chat", + msgType = wsMsg.msgType ?: "chat", isStreaming = true, ) } @@ -425,7 +425,7 @@ class ChatRepositoryImpl( conversationId = sid, role = "assistant", content = content, - msgType = "chat", + msgType = wsMsg.msgType ?: "chat", timestamp = ts, ) ) @@ -435,7 +435,7 @@ class ChatRepositoryImpl( lastResponseContent = content lastResponseTime = System.currentTimeMillis() - emitMessage(id = msgId, sessionId = sid, role = "assistant", content = content, msgType = "chat", timestamp = ts, isStreaming = false, shouldNotify = true) + emitMessage(id = msgId, sessionId = sid, role = "assistant", content = content, msgType = wsMsg.msgType ?: "chat", timestamp = ts, isStreaming = false, shouldNotify = true) _isAssistantStreaming.value = false RuntimeLog.chat("stream", "Stream end msgId=$msgId content=${content.take(80)}") } @@ -488,8 +488,8 @@ class ChatRepositoryImpl( recentParsedContents.clear() wsMsg.reviewMessages?.forEach { review -> val text = review.content ?: review.text ?: return@forEach - val role = review.role ?: "action" - val rvMsgType = review.msgType ?: review.role ?: "action" + val role = review.role ?: "assistant" + val rvMsgType = review.msgType ?: "action" val msgId = "rv_${System.currentTimeMillis()}_${review.hashCode()}" recentParsedContents.add(text) emitMessage(id = msgId, sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = role, content = text, msgType = rvMsgType, isStreaming = false) @@ -507,7 +507,7 @@ class ChatRepositoryImpl( sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = "assistant", content = text, - msgType = "thinking", + msgType = wsMsg.msgType ?: "thinking", isStreaming = false, ) } @@ -523,7 +523,7 @@ class ChatRepositoryImpl( sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = "system", content = detail, - msgType = "tool_progress", + msgType = wsMsg.msgType ?: "tool_progress", isStreaming = false, ) } @@ -535,7 +535,7 @@ class ChatRepositoryImpl( sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = "system", content = wsMsg.error ?: "未知错误", - msgType = "system_info", + msgType = wsMsg.msgType ?: "system_info", isStreaming = false, ) } @@ -552,11 +552,11 @@ class ChatRepositoryImpl( conversationId = sid, role = "user", content = text, - msgType = "chat", + msgType = wsMsg.msgType ?: "chat", timestamp = ts, ) ) - emitMessage(id = msgId, sessionId = sid, role = "user", content = text, msgType = "chat", timestamp = ts, isStreaming = false) + emitMessage(id = msgId, sessionId = sid, role = "user", content = text, msgType = wsMsg.msgType ?: "chat", timestamp = ts, isStreaming = false) } "history_response" -> {