Polish chat message hierarchy

This commit is contained in:
OpenClaw committed 2026-03-07 15:18:38 +08:00
1 parent 6c387eab7c
commit 3b8d779138
3 files changed
+19 -15

No files matched your search

@@ -188,7 +188,6 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
when {
activeSession != null -> ChatScreen(
modifier = Modifier.fillMaxSize(),
sessionTitle = activeSession.title,
messages = appState.repository.messagesFor(activeSession.id),
isSending = appState.sendingSessionId == activeSession.id,
isLoading = appState.isSyncing,
@@ -46,7 +46,6 @@ import kotlinx.coroutines.delay
@Composable
fun ChatScreen(
modifier: Modifier = Modifier,
sessionTitle: String,
messages: List<ChatMessage>,
isSending: Boolean,
isLoading: Boolean,
@@ -89,7 +88,6 @@ fun ChatScreen(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
ChatHeader(
sessionTitle = sessionTitle,
topStatus = topStatus,
onBack = onBack,
onRetry = onRetry,
@@ -267,7 +265,6 @@ private fun buildChatTopStatus(
@Composable
private fun ChatHeader(
sessionTitle: String,
topStatus: ChatTopStatus,
onBack: () -> Unit,
onRetry: () -> Unit,
@@ -279,17 +276,10 @@ private fun ChatHeader(
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Button(onClick = onBack) { Text("返回") }
Text(
text = sessionTitle,
modifier = Modifier.weight(1f),
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
TextButton(onClick = onBack) { Text("返回") }
TextButton(onClick = onRetry) {
Text(topStatus.actionLabel)
}
@@ -380,7 +370,12 @@ private fun MessageBubble(
val bubbleColor = when {
isSystemNotice -> MaterialTheme.colorScheme.surfaceContainerHigh
message.role == MessageRole.User -> MaterialTheme.colorScheme.primaryContainer
else -> MaterialTheme.colorScheme.surfaceContainerLow
isToolResult && message.status == "tool-error" -> MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.36f)
isToolResult -> MaterialTheme.colorScheme.surfaceContainer
isTool -> MaterialTheme.colorScheme.surfaceContainerLow
isAttachment && message.status == "upload-failed" -> MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.24f)
isAttachment -> MaterialTheme.colorScheme.surfaceContainerLow
else -> MaterialTheme.colorScheme.surface
}
var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) }
var expanded by remember(message.id) { mutableStateOf(false) }
@@ -431,7 +426,7 @@ private fun MessageBubble(
verticalArrangement = Arrangement.spacedBy(6.dp),
horizontalAlignment = if (isSystemNotice) Alignment.CenterHorizontally else if (message.role == MessageRole.User) Alignment.End else Alignment.Start,
) {
if (!isSystemNotice) {
if (!isSystemNotice && message.role != MessageRole.User) {
Text(
text = label,
style = MaterialTheme.typography.labelMedium,
@@ -463,6 +458,7 @@ private fun MessageBubble(
) {
when {
isThinking -> {
StatusPill(text = "思考中", tone = StatusPillTone.Warning)
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically,
@@ -595,6 +591,13 @@ private fun MessageBubble(
style = if (isSystemNotice) MaterialTheme.typography.bodyMedium else MaterialTheme.typography.bodyLarge,
color = if (isSystemNotice) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurface,
)
if (message.role == MessageRole.User && displayStatus == null) {
Text(
text = "已发送",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
if (message.retryable && localPhase == LocalMessagePhase.Failed && message.status == "send-failed") {
TextButton(onClick = { onRetryMessage(message.id) }) {
Text("重试")