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:
@@ -388,7 +388,7 @@ class ChatRepositoryImpl(
|
|||||||
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
||||||
role = "assistant",
|
role = "assistant",
|
||||||
content = streamingContent,
|
content = streamingContent,
|
||||||
msgType = "chat",
|
msgType = wsMsg.msgType ?: "chat",
|
||||||
isStreaming = true,
|
isStreaming = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -425,7 +425,7 @@ class ChatRepositoryImpl(
|
|||||||
conversationId = sid,
|
conversationId = sid,
|
||||||
role = "assistant",
|
role = "assistant",
|
||||||
content = content,
|
content = content,
|
||||||
msgType = "chat",
|
msgType = wsMsg.msgType ?: "chat",
|
||||||
timestamp = ts,
|
timestamp = ts,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -435,7 +435,7 @@ class ChatRepositoryImpl(
|
|||||||
lastResponseContent = content
|
lastResponseContent = content
|
||||||
lastResponseTime = System.currentTimeMillis()
|
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
|
_isAssistantStreaming.value = false
|
||||||
RuntimeLog.chat("stream", "Stream end msgId=$msgId content=${content.take(80)}")
|
RuntimeLog.chat("stream", "Stream end msgId=$msgId content=${content.take(80)}")
|
||||||
}
|
}
|
||||||
@@ -488,8 +488,8 @@ class ChatRepositoryImpl(
|
|||||||
recentParsedContents.clear()
|
recentParsedContents.clear()
|
||||||
wsMsg.reviewMessages?.forEach { review ->
|
wsMsg.reviewMessages?.forEach { review ->
|
||||||
val text = review.content ?: review.text ?: return@forEach
|
val text = review.content ?: review.text ?: return@forEach
|
||||||
val role = review.role ?: "action"
|
val role = review.role ?: "assistant"
|
||||||
val rvMsgType = review.msgType ?: review.role ?: "action"
|
val rvMsgType = review.msgType ?: "action"
|
||||||
val msgId = "rv_${System.currentTimeMillis()}_${review.hashCode()}"
|
val msgId = "rv_${System.currentTimeMillis()}_${review.hashCode()}"
|
||||||
recentParsedContents.add(text)
|
recentParsedContents.add(text)
|
||||||
emitMessage(id = msgId, sessionId = wsMsg.sessionId ?: currentSessionId ?: "default", role = role, content = text, msgType = rvMsgType, isStreaming = false)
|
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",
|
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
||||||
role = "assistant",
|
role = "assistant",
|
||||||
content = text,
|
content = text,
|
||||||
msgType = "thinking",
|
msgType = wsMsg.msgType ?: "thinking",
|
||||||
isStreaming = false,
|
isStreaming = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@ class ChatRepositoryImpl(
|
|||||||
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
||||||
role = "system",
|
role = "system",
|
||||||
content = detail,
|
content = detail,
|
||||||
msgType = "tool_progress",
|
msgType = wsMsg.msgType ?: "tool_progress",
|
||||||
isStreaming = false,
|
isStreaming = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -535,7 +535,7 @@ class ChatRepositoryImpl(
|
|||||||
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
sessionId = wsMsg.sessionId ?: currentSessionId ?: "default",
|
||||||
role = "system",
|
role = "system",
|
||||||
content = wsMsg.error ?: "未知错误",
|
content = wsMsg.error ?: "未知错误",
|
||||||
msgType = "system_info",
|
msgType = wsMsg.msgType ?: "system_info",
|
||||||
isStreaming = false,
|
isStreaming = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -552,11 +552,11 @@ class ChatRepositoryImpl(
|
|||||||
conversationId = sid,
|
conversationId = sid,
|
||||||
role = "user",
|
role = "user",
|
||||||
content = text,
|
content = text,
|
||||||
msgType = "chat",
|
msgType = wsMsg.msgType ?: "chat",
|
||||||
timestamp = ts,
|
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" -> {
|
"history_response" -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user