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 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 12:50:49 +08:00
parent ce73f68bc8
commit 5dad0cd39b
@@ -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" -> {