Refine chat and session UI hierarchy

This commit is contained in:
OpenClaw committed 2026-03-07 15:10:40 +08:00
1 parent 1e110574d5
commit 6c387eab7c
4 files changed
+324 -229

No files matched your search

@@ -18,7 +18,6 @@ import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
@@ -32,8 +31,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import cn.xiaobai.openclawapp.data.ChatMessage import cn.xiaobai.openclawapp.data.ChatMessage
import cn.xiaobai.openclawapp.data.LocalMessagePhase import cn.xiaobai.openclawapp.data.LocalMessagePhase
import cn.xiaobai.openclawapp.data.MessageKind import cn.xiaobai.openclawapp.data.MessageKind
@@ -41,6 +40,7 @@ import cn.xiaobai.openclawapp.data.MessageRole
import cn.xiaobai.openclawapp.data.localMessagePhase import cn.xiaobai.openclawapp.data.localMessagePhase
import cn.xiaobai.openclawapp.ui.EmptyStateCard import cn.xiaobai.openclawapp.ui.EmptyStateCard
import cn.xiaobai.openclawapp.ui.StatusPill import cn.xiaobai.openclawapp.ui.StatusPill
import cn.xiaobai.openclawapp.ui.StatusPillTone
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@Composable @Composable
@@ -73,119 +73,33 @@ fun ChatScreen(
} }
} }
val topStatus = remember(isSending, isLoading, streamStatus, pendingQueueStatus, cacheNotice, errorMessage) {
buildChatTopStatus(
isSending = isSending,
isLoading = isLoading,
streamStatus = streamStatus,
pendingQueueStatus = pendingQueueStatus,
cacheNotice = cacheNotice,
errorMessage = errorMessage,
)
}
Column( Column(
modifier = modifier.padding(16.dp), modifier = modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp), verticalArrangement = Arrangement.spacedBy(12.dp),
) { ) {
Column( ChatHeader(
modifier = Modifier.fillMaxWidth(), sessionTitle = sessionTitle,
verticalArrangement = Arrangement.spacedBy(8.dp), topStatus = topStatus,
) { onBack = onBack,
Row( onRetry = onRetry,
modifier = Modifier.fillMaxWidth(), onSendAttachmentStub = onSendAttachmentStub,
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Button(onClick = onBack) { Text("返回") }
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(sessionTitle, style = MaterialTheme.typography.titleLarge, maxLines = 1)
Text(
when {
isSending -> "正在等待实时回复…"
streamStatus == "recovering" -> "上游恢复中"
streamStatus == "reconnecting" -> "连接重建中"
streamStatus == "failed" -> "实时流已断开"
streamStatus == "connecting" -> "正在连接"
else -> "实时流已接入"
},
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
}
StatusPill(
text = when {
isLoading -> "同步中"
streamStatus == "recovering" -> "恢复中"
streamStatus == "reconnecting" -> "重连中"
streamStatus == "failed" -> "已断流"
streamStatus == "connecting" -> "连接中"
else -> "在线"
},
highlighted = streamStatus != "failed",
)
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedButton(onClick = onRetry) {
Text(if (streamStatus == "failed") "重新连接" else "刷新")
}
OutlinedButton(onClick = onSendAttachmentStub) {
Text("发附件")
}
}
}
if (cacheNotice != null) {
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh),
) {
Text(
text = cacheNotice,
modifier = Modifier.padding(12.dp),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
if (pendingQueueStatus != null) {
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.65f)),
) {
Text(
text = pendingQueueStatus,
modifier = Modifier.padding(12.dp),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSecondaryContainer,
)
}
}
if (errorMessage != null) {
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer),
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(14.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
errorMessage,
modifier = Modifier.weight(1f),
color = MaterialTheme.colorScheme.onErrorContainer,
)
Button(onClick = onRetry) { Text("重试") }
}
}
}
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") }
QuickActionButton("看状态") { onSend("看一下当前状态") }
}
if (messages.isEmpty() && !isLoading) { if (messages.isEmpty() && !isLoading) {
EmptyStateCard( EmptyStateCard(
title = "还没有消息", title = "还没有消息",
subtitle = "这里以后会展示真实的会话历史、流式回复和工具执行状态。", subtitle = "进入会话后,这里会显示历史消息、回复进度和工具结果。",
) )
} else { } else {
LazyColumn( LazyColumn(
@@ -221,6 +135,16 @@ fun ChatScreen(
} }
} }
if (messages.isEmpty() && !isLoading) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") }
QuickActionButton("看状态") { onSend("看一下当前状态") }
}
}
Card(modifier = Modifier.fillMaxWidth()) { Card(modifier = Modifier.fillMaxWidth()) {
Column( Column(
modifier = Modifier modifier = Modifier
@@ -229,7 +153,7 @@ fun ChatScreen(
verticalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
) { ) {
Text( Text(
if (isSending) "正在发送消息…" else "直接发一条消息给当前会话", if (isSending) "正在发送消息…" else "继续当前会话",
style = MaterialTheme.typography.labelLarge, style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
@@ -264,6 +188,165 @@ fun ChatScreen(
} }
} }
private data class ChatTopStatus(
val text: String,
val tone: StatusPillTone,
val actionLabel: String,
)
private fun buildChatTopStatus(
isSending: Boolean,
isLoading: Boolean,
streamStatus: String?,
pendingQueueStatus: String?,
cacheNotice: String?,
errorMessage: String?,
): ChatTopStatus {
return when {
errorMessage != null -> ChatTopStatus(
text = errorMessage,
tone = StatusPillTone.Error,
actionLabel = "重试",
)
pendingQueueStatus != null -> ChatTopStatus(
text = pendingQueueStatus,
tone = StatusPillTone.Warning,
actionLabel = if (streamStatus == "failed") "重连" else "刷新",
)
cacheNotice != null -> ChatTopStatus(
text = cacheNotice,
tone = StatusPillTone.Warning,
actionLabel = if (streamStatus == "failed") "重连" else "刷新",
)
isSending -> ChatTopStatus(
text = "正在等待实时回复…",
tone = StatusPillTone.Info,
actionLabel = "刷新",
)
isLoading -> ChatTopStatus(
text = "正在同步消息…",
tone = StatusPillTone.Info,
actionLabel = "刷新",
)
streamStatus == "recovering" -> ChatTopStatus(
text = "上游恢复中,消息会继续同步。",
tone = StatusPillTone.Warning,
actionLabel = "刷新",
)
streamStatus == "reconnecting" -> ChatTopStatus(
text = "正在重连实时流。",
tone = StatusPillTone.Warning,
actionLabel = "重连",
)
streamStatus == "failed" -> ChatTopStatus(
text = "实时流已断开,请重试连接。",
tone = StatusPillTone.Error,
actionLabel = "重连",
)
streamStatus == "connecting" -> ChatTopStatus(
text = "正在连接实时流。",
tone = StatusPillTone.Info,
actionLabel = "刷新",
)
else -> ChatTopStatus(
text = "在线,可继续浏览和发送消息。",
tone = StatusPillTone.Success,
actionLabel = "刷新",
)
}
}
@Composable
private fun ChatHeader(
sessionTitle: String,
topStatus: ChatTopStatus,
onBack: () -> Unit,
onRetry: () -> Unit,
onSendAttachmentStub: () -> Unit,
) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.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 = onRetry) {
Text(topStatus.actionLabel)
}
TextButton(onClick = onSendAttachmentStub) {
Text("附件")
}
}
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = when (topStatus.tone) {
StatusPillTone.Error -> MaterialTheme.colorScheme.errorContainer
StatusPillTone.Warning -> MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.55f)
StatusPillTone.Success -> MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.55f)
StatusPillTone.Info -> MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f)
StatusPillTone.Neutral -> MaterialTheme.colorScheme.surfaceContainerHigh
},
),
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 10.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically,
) {
StatusPill(
text = when (topStatus.tone) {
StatusPillTone.Error -> "需处理"
StatusPillTone.Warning -> "处理中"
StatusPillTone.Success -> "在线"
StatusPillTone.Info -> "同步中"
StatusPillTone.Neutral -> "提示"
},
tone = topStatus.tone,
)
Text(
text = topStatus.text,
style = MaterialTheme.typography.bodySmall,
color = when (topStatus.tone) {
StatusPillTone.Error -> MaterialTheme.colorScheme.onErrorContainer
StatusPillTone.Warning -> MaterialTheme.colorScheme.onTertiaryContainer
StatusPillTone.Success -> MaterialTheme.colorScheme.onSecondaryContainer
StatusPillTone.Info -> MaterialTheme.colorScheme.onPrimaryContainer
StatusPillTone.Neutral -> MaterialTheme.colorScheme.onSurfaceVariant
},
modifier = Modifier.weight(1f),
)
TextButton(onClick = onRetry) {
Text(topStatus.actionLabel)
}
}
}
}
}
@Composable @Composable
private fun RowScope.QuickActionButton(text: String, onClick: () -> Unit) { private fun RowScope.QuickActionButton(text: String, onClick: () -> Unit) {
Button(onClick = onClick, modifier = Modifier.weight(1f)) { Text(text) } Button(onClick = onClick, modifier = Modifier.weight(1f)) { Text(text) }
@@ -295,14 +378,9 @@ private fun MessageBubble(
val isAttachment = message.kind == MessageKind.Attachment val isAttachment = message.kind == MessageKind.Attachment
val isSystemNotice = message.role == MessageRole.System && !isToolResult && !isTool && !isAttachment val isSystemNotice = message.role == MessageRole.System && !isToolResult && !isTool && !isAttachment
val bubbleColor = when { val bubbleColor = when {
isAttachment && message.status == "upload-failed" -> MaterialTheme.colorScheme.errorContainer isSystemNotice -> MaterialTheme.colorScheme.surfaceContainerHigh
isAttachment -> MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.82f)
isToolResult && message.status == "tool-error" -> MaterialTheme.colorScheme.errorContainer
isToolResult -> MaterialTheme.colorScheme.tertiaryContainer
isTool -> MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.7f)
message.role == MessageRole.User -> MaterialTheme.colorScheme.primaryContainer message.role == MessageRole.User -> MaterialTheme.colorScheme.primaryContainer
message.role == MessageRole.Assistant -> MaterialTheme.colorScheme.secondaryContainer else -> MaterialTheme.colorScheme.surfaceContainerLow
else -> MaterialTheme.colorScheme.surfaceVariant
} }
var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) } var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) }
var expanded by remember(message.id) { mutableStateOf(false) } var expanded by remember(message.id) { mutableStateOf(false) }
@@ -326,25 +404,30 @@ private fun MessageBubble(
val toolResultText = if (shouldCollapseToolResult && !expanded) displayText.take(240).trimEnd() + "…" else displayText val toolResultText = if (shouldCollapseToolResult && !expanded) displayText.take(240).trimEnd() + "…" else displayText
val localPhase = message.localMessagePhase() val localPhase = message.localMessagePhase()
val displayStatus = when { val displayStatus = when {
animateText && visibleChars < message.text.length -> "streaming" animateText && visibleChars < message.text.length -> "处理中"
localPhase == LocalMessagePhase.QueueProcessing && message.kind == MessageKind.Attachment -> "队列上传中" localPhase == LocalMessagePhase.QueueProcessing -> "处理中"
localPhase == LocalMessagePhase.QueueProcessing -> "队列发送中" localPhase == LocalMessagePhase.AutoRetrying -> "处理中"
localPhase == LocalMessagePhase.AutoRetrying -> "自动重试中" message.status == "queued" -> "处理中"
message.status == "queued" -> "发送中" message.status == "uploading" -> "处理中"
message.status == "send-failed" -> "发送失败" message.status == "send-failed" -> "需重试"
message.status == "uploading" -> "上传中" message.status == "upload-failed" -> "需重试"
localPhase == LocalMessagePhase.Completed && message.kind == MessageKind.Attachment -> "已上传" message.status == "tool-running" -> "处理中"
message.status == "upload-failed" -> "上传失败"
message.status == "tool-running" -> "执行中"
message.status == "tool-done" -> "已完成"
message.status == "tool-error" -> "失败" message.status == "tool-error" -> "失败"
message.status == "stream-failed" -> "断流" message.status == "stream-failed" -> "失败"
else -> message.status localPhase == LocalMessagePhase.Completed && message.kind == MessageKind.Attachment -> "已完成"
message.status == "tool-done" -> "已完成"
else -> null
}
val statusTone = when (displayStatus) {
"处理中" -> StatusPillTone.Warning
"需重试", "失败" -> StatusPillTone.Error
"已完成" -> StatusPillTone.Success
else -> StatusPillTone.Neutral
} }
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = alignment) { Box(modifier = Modifier.fillMaxWidth(), contentAlignment = alignment) {
Column( Column(
modifier = if (isSystemNotice) Modifier.fillMaxWidth() else Modifier.fillMaxWidth(0.88f), modifier = if (isSystemNotice) Modifier.fillMaxWidth() else Modifier.fillMaxWidth(if (isToolResult) 0.94f else 0.86f),
verticalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp),
horizontalAlignment = if (isSystemNotice) Alignment.CenterHorizontally else if (message.role == MessageRole.User) Alignment.End else Alignment.Start, horizontalAlignment = if (isSystemNotice) Alignment.CenterHorizontally else if (message.role == MessageRole.User) Alignment.End else Alignment.Start,
) { ) {
@@ -357,22 +440,24 @@ private fun MessageBubble(
} }
Column( Column(
modifier = Modifier modifier = Modifier
.clip(androidx.compose.foundation.shape.RoundedCornerShape(if (isSystemNotice) 14.dp else 20.dp)) .clip(androidx.compose.foundation.shape.RoundedCornerShape(if (isSystemNotice) 14.dp else 18.dp))
.border( .border(
width = when { width = when {
isSystemNotice -> 0.dp isSystemNotice -> 0.dp
isTool || isToolResult -> 1.dp isTool || isToolResult || isAttachment -> 1.dp
else -> 0.dp else -> 0.dp
}, },
color = when { color = when {
isToolResult && message.status == "tool-error" -> MaterialTheme.colorScheme.error isToolResult && message.status == "tool-error" -> MaterialTheme.colorScheme.error
isToolResult -> MaterialTheme.colorScheme.tertiary isToolResult -> MaterialTheme.colorScheme.outlineVariant
isTool -> MaterialTheme.colorScheme.secondary isTool -> MaterialTheme.colorScheme.secondary
isAttachment && message.status == "upload-failed" -> MaterialTheme.colorScheme.error
isAttachment -> MaterialTheme.colorScheme.outlineVariant
else -> MaterialTheme.colorScheme.surfaceVariant else -> MaterialTheme.colorScheme.surfaceVariant
}, },
shape = androidx.compose.foundation.shape.RoundedCornerShape(if (isSystemNotice) 14.dp else 20.dp), shape = androidx.compose.foundation.shape.RoundedCornerShape(if (isSystemNotice) 14.dp else 18.dp),
) )
.background(if (isSystemNotice) MaterialTheme.colorScheme.surfaceContainerHigh else bubbleColor) .background(bubbleColor)
.padding(if (isSystemNotice) 10.dp else 14.dp), .padding(if (isSystemNotice) 10.dp else 14.dp),
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
) { ) {
@@ -385,7 +470,7 @@ private fun MessageBubble(
CircularProgressIndicator( CircularProgressIndicator(
modifier = Modifier.size(18.dp), modifier = Modifier.size(18.dp),
strokeWidth = 2.dp, strokeWidth = 2.dp,
color = MaterialTheme.colorScheme.onSecondaryContainer, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
Text( Text(
text = if (message.text.isBlank()) "正在思考…" else message.text, text = if (message.text.isBlank()) "正在思考…" else message.text,
@@ -395,13 +480,10 @@ private fun MessageBubble(
} }
} }
isAttachment -> { isAttachment -> {
Text( StatusPill(text = "附件", tone = if (message.status == "upload-failed") StatusPillTone.Error else StatusPillTone.Neutral)
text = "📎 附件",
style = MaterialTheme.typography.titleSmall,
)
Text( Text(
text = displayText, text = displayText,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyLarge,
) )
val meta = buildList { val meta = buildList {
message.contentType?.takeIf { it.isNotBlank() }?.let { add(it) } message.contentType?.takeIf { it.isNotBlank() }?.let { add(it) }
@@ -429,23 +511,10 @@ private fun MessageBubble(
} }
if (message.retryable && message.status == "upload-failed") { if (message.retryable && message.status == "upload-failed") {
TextButton(onClick = { onRetryAttachment(message.id) }) { TextButton(onClick = { onRetryAttachment(message.id) }) {
Text("重试上传") Text("重试")
} }
} }
} }
if (localPhase == LocalMessagePhase.QueueProcessing) {
Text(
text = "系统正在按本地待发队列继续上传这个附件…",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
} else if (localPhase == LocalMessagePhase.ManualProcessing) {
Text(
text = "正在手动发起附件上传…",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
if (attachmentDetailsExpanded) { if (attachmentDetailsExpanded) {
Column( Column(
modifier = Modifier modifier = Modifier
@@ -458,13 +527,14 @@ private fun MessageBubble(
Text("文件名:${message.text}", style = MaterialTheme.typography.bodySmall) Text("文件名:${message.text}", style = MaterialTheme.typography.bodySmall)
Text("类型:${message.contentType ?: "unknown"}", style = MaterialTheme.typography.bodySmall) Text("类型:${message.contentType ?: "unknown"}", style = MaterialTheme.typography.bodySmall)
Text("大小:${message.sizeBytes?.let(::formatBytes) ?: "unknown"}", style = MaterialTheme.typography.bodySmall) Text("大小:${message.sizeBytes?.let(::formatBytes) ?: "unknown"}", style = MaterialTheme.typography.bodySmall)
Text("状态:${displayStatus ?: "unknown"}", style = MaterialTheme.typography.bodySmall) Text("状态:${displayStatus ?: "已同步"}", style = MaterialTheme.typography.bodySmall)
} }
} }
} }
isTool -> { isTool -> {
StatusPill(text = "工具调用", tone = if (message.status == "tool-error") StatusPillTone.Error else StatusPillTone.Neutral)
Text( Text(
text = "🛠 ${message.toolName ?: "工具调用"}", text = message.toolName ?: "工具调用",
style = MaterialTheme.typography.titleSmall, style = MaterialTheme.typography.titleSmall,
) )
Text( Text(
@@ -478,16 +548,16 @@ private fun MessageBubble(
) )
} }
isToolResult -> { isToolResult -> {
Text( StatusPill(
text = buildString { text = if (message.status == "tool-error") "工具错误" else "工具结果",
append(if (message.status == "tool-error") "工具错误" else "工具结果") tone = if (message.status == "tool-error") StatusPillTone.Error else StatusPillTone.Neutral,
)
if (!linkedToolName.isNullOrBlank()) { if (!linkedToolName.isNullOrBlank()) {
append(" · ") Text(
append(linkedToolName) text = linkedToolName,
}
},
style = MaterialTheme.typography.titleSmall, style = MaterialTheme.typography.titleSmall,
) )
}
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -525,23 +595,9 @@ private fun MessageBubble(
style = if (isSystemNotice) MaterialTheme.typography.bodyMedium else MaterialTheme.typography.bodyLarge, style = if (isSystemNotice) MaterialTheme.typography.bodyMedium else MaterialTheme.typography.bodyLarge,
color = if (isSystemNotice) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurface, color = if (isSystemNotice) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurface,
) )
if (localPhase == LocalMessagePhase.QueueProcessing) {
Text(
text = "系统正在按本地待发队列继续发送这条消息…",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
if (localPhase == LocalMessagePhase.AutoRetrying) {
Text(
text = "系统正在尝试恢复发送这条消息…",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
if (message.retryable && localPhase == LocalMessagePhase.Failed && message.status == "send-failed") { if (message.retryable && localPhase == LocalMessagePhase.Failed && message.status == "send-failed") {
TextButton(onClick = { onRetryMessage(message.id) }) { TextButton(onClick = { onRetryMessage(message.id) }) {
Text("重试发送") Text("重试")
} }
} }
} }
@@ -558,7 +614,7 @@ private fun MessageBubble(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
) )
if (displayStatus != null && !isSystemNotice) { if (displayStatus != null && !isSystemNotice) {
StatusPill(text = displayStatus) StatusPill(text = displayStatus, tone = statusTone)
} }
} }
} }
@@ -15,6 +15,7 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@@ -22,11 +23,13 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import cn.xiaobai.openclawapp.data.SessionSummary import cn.xiaobai.openclawapp.data.SessionSummary
import cn.xiaobai.openclawapp.ui.EmptyStateCard import cn.xiaobai.openclawapp.ui.EmptyStateCard
import cn.xiaobai.openclawapp.ui.SectionHeader import cn.xiaobai.openclawapp.ui.SectionHeader
import cn.xiaobai.openclawapp.ui.StatusPill import cn.xiaobai.openclawapp.ui.StatusPill
import cn.xiaobai.openclawapp.ui.StatusPillTone
@Composable @Composable
fun SessionListScreen( fun SessionListScreen(
@@ -107,7 +110,7 @@ fun SessionListScreen(
Card( Card(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors( colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.55f), containerColor = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.45f),
), ),
) { ) {
Row( Row(
@@ -119,15 +122,16 @@ fun SessionListScreen(
) { ) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) { Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text("最近访问", style = MaterialTheme.typography.labelLarge) Text("最近访问", style = MaterialTheme.typography.labelLarge)
Text(recentSession.title, style = MaterialTheme.typography.titleMedium) Text(recentSession.title, style = MaterialTheme.typography.titleMedium, maxLines = 1)
Text( Text(
recentSession.lastMessage.ifBlank { "暂无摘要" }, recentSession.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2, maxLines = 2,
overflow = TextOverflow.Ellipsis,
) )
} }
Button(onClick = { onOpenSession(recentSession.id) }) { TextButton(onClick = { onOpenSession(recentSession.id) }) {
Text("继续") Text("继续")
} }
} }
@@ -149,12 +153,32 @@ fun SessionListScreen(
if (filteredSessions.isEmpty() && !isLoading) { if (filteredSessions.isEmpty() && !isLoading) {
item { item {
EmptyStateCard( EmptyStateCard(
title = "没有匹配的会话", title = if (query.isBlank()) "暂时还没有可显示的会话" else "没有匹配的会话",
subtitle = "如果你当前走的是 Remote 模式,那下一步就该检查 BFF 接口返回和 DTO 映射了。", subtitle = if (query.isBlank()) {
"稍后刷新,或先检查连接地址和登录状态。"
} else {
"换个关键词试试,或清空搜索后查看全部会话。"
},
) )
} }
} else { } else {
items(filteredSessions, key = { it.id }) { session -> items(filteredSessions, key = { it.id }) { session ->
SessionRow(
session = session,
onOpen = { onOpenSession(session.id) },
onTogglePin = { onTogglePin(session.id) },
)
}
}
}
}
@Composable
private fun SessionRow(
session: SessionSummary,
onOpen: () -> Unit,
onTogglePin: () -> Unit,
) {
Card( Card(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors( colors = CardDefaults.cardColors(
@@ -164,69 +188,70 @@ fun SessionListScreen(
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable { onOpenSession(session.id) } .clickable(onClick = onOpen)
.padding(horizontal = 14.dp, vertical = 12.dp), .padding(horizontal = 14.dp, vertical = 12.dp),
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
) { ) {
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) { ) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
Text( Text(
text = session.title, text = session.title,
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
modifier = Modifier.weight(1f),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
) )
if (session.isPinned) { if (session.isPinned) {
StatusPill(text = "置顶") StatusPill(text = "置顶", tone = StatusPillTone.Neutral)
} }
if (session.unreadCount > 0) { if (session.unreadCount > 0) {
StatusPill(text = "${session.unreadCount} 未读", highlighted = true) StatusPill(text = "${session.unreadCount} 未读", tone = StatusPillTone.Info)
} }
session.streamStatus?.let { streamStatus -> session.streamStatus?.let { streamStatus ->
StatusPill( val (label, tone) = streamStatusLabelAndTone(streamStatus)
text = when (streamStatus) { if (label != null) {
"recovering" -> "恢复中" StatusPill(text = label, tone = tone)
"reconnecting" -> "重连中"
"failed" -> "已断流"
"connecting" -> "连接中"
"live" -> "在线"
else -> streamStatus
},
highlighted = streamStatus == "live" || streamStatus == "recovering",
)
} }
} }
}
Text( Text(
text = session.id, text = session.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = session.updatedAt,
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
StatusPill(text = session.updatedAt, highlighted = true)
}
Text(
text = session.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Text(
text = session.lastMessage.ifBlank { "暂无摘要" },
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
maxLines = 2,
) )
Button(onClick = { onTogglePin(session.id) }) { TextButton(onClick = onTogglePin) {
Text(if (session.isPinned) "取消置顶" else "置顶") Text(if (session.isPinned) "取消置顶" else "置顶")
} }
} }
} }
} }
} }
}
private fun streamStatusLabelAndTone(streamStatus: String): Pair<String?, StatusPillTone> {
return when (streamStatus) {
"recovering" -> "恢复中" to StatusPillTone.Warning
"reconnecting" -> "重连中" to StatusPillTone.Warning
"failed" -> "已断流" to StatusPillTone.Error
"connecting" -> "连接中" to StatusPillTone.Warning
"live" -> "在线" to StatusPillTone.Success
else -> null to StatusPillTone.Neutral
} }
} }
@@ -62,7 +62,7 @@ fun HeroCard(
verticalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
) { ) {
if (!badge.isNullOrBlank()) { if (!badge.isNullOrBlank()) {
StatusPill(text = badge, highlighted = true) StatusPill(text = badge, tone = StatusPillTone.Info)
} }
Text( Text(
title, title,
@@ -146,21 +146,28 @@ fun MetricCard(
} }
} }
enum class StatusPillTone {
Neutral,
Info,
Success,
Warning,
Error,
}
@Composable @Composable
fun StatusPill( fun StatusPill(
text: String, text: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
highlighted: Boolean = false, highlighted: Boolean = false,
tone: StatusPillTone? = null,
) { ) {
val containerColor = if (highlighted) { val resolvedTone = tone ?: if (highlighted) StatusPillTone.Info else StatusPillTone.Neutral
MaterialTheme.colorScheme.primaryContainer val (containerColor, textColor) = when (resolvedTone) {
} else { StatusPillTone.Neutral -> MaterialTheme.colorScheme.surfaceVariant to MaterialTheme.colorScheme.onSurfaceVariant
MaterialTheme.colorScheme.surfaceVariant StatusPillTone.Info -> MaterialTheme.colorScheme.primaryContainer to MaterialTheme.colorScheme.onPrimaryContainer
} StatusPillTone.Success -> MaterialTheme.colorScheme.secondaryContainer to MaterialTheme.colorScheme.onSecondaryContainer
val textColor = if (highlighted) { StatusPillTone.Warning -> MaterialTheme.colorScheme.tertiaryContainer to MaterialTheme.colorScheme.onTertiaryContainer
MaterialTheme.colorScheme.onPrimaryContainer StatusPillTone.Error -> MaterialTheme.colorScheme.errorContainer to MaterialTheme.colorScheme.onErrorContainer
} else {
MaterialTheme.colorScheme.onSurfaceVariant
} }
Box( Box(
@@ -209,7 +216,10 @@ fun SelectableRowCard(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
) )
if (!trailing.isNullOrBlank()) { if (!trailing.isNullOrBlank()) {
StatusPill(text = trailing, highlighted = selected) StatusPill(
text = trailing,
tone = if (selected) StatusPillTone.Info else StatusPillTone.Neutral,
)
} }
} }
} }
+4
View File
@@ -429,3 +429,7 @@ Android/iOS App
- 2026-03-07:继续收清附件读取语义:BFF 开始显式维护旧 attachment id 到新远端 message id 的 alias 映射,`read_attachment()` 会先走 alias 解析再读 payload,不再完全依赖“请求 id 恰好就是 payload 主键”。 - 2026-03-07:继续收清附件读取语义:BFF 开始显式维护旧 attachment id 到新远端 message id 的 alias 映射,`read_attachment()` 会先走 alias 解析再读 payload,不再完全依赖“请求 id 恰好就是 payload 主键”。
- 2026-03-07:补齐附件 alias 持久化入口:source stub 被远端消息收编后,BFF 会保留一份轻量 redirect 元数据;重启后旧 attachment id 仍能恢复 alias 解析,而不会因为 alias 只存在内存里而失效。 - 2026-03-07:补齐附件 alias 持久化入口:source stub 被远端消息收编后,BFF 会保留一份轻量 redirect 元数据;重启后旧 attachment id 仍能恢复 alias 解析,而不会因为 alias 只存在内存里而失效。
- 2026-03-07:补齐 alias 清理一致性:当目标附件 payload 过期或被数量策略淘汰时,BFF 会同步清掉所有指向它的 redirect meta / alias 入口,避免旧 attachment id 虽还能解析但最终只会稳定 404。 - 2026-03-07:补齐 alias 清理一致性:当目标附件 payload 过期或被数量策略淘汰时,BFF 会同步清掉所有指向它的 redirect meta / alias 入口,避免旧 attachment id 虽还能解析但最终只会稳定 404。
- 2026-03-07:按产品/设计 review 收了一轮聊天与会话页 UI:聊天页顶部把返回/标题/状态/刷新/附件入口收成更轻的两层结构,并把缓存/队列/断流/同步等提示合并为一条统一状态栏;快捷动作只在空会话时展示,减少首屏被系统说明挤压。
- 2026-03-07:会话列表做了一轮信息减法:去掉重复摘要,默认不再在主列表暴露 session id,更新时间从高亮 pill 降为普通辅助文本;最近访问卡和置顶操作也改轻,优先突出“标题 + 摘要 + 关键状态”。
- 2026-03-07:开始统一状态视觉语义:`StatusPill` 新增 neutral/info/success/warning/error tone,列表流状态、聊天顶部状态、消息气泡状态都开始按“在线 / 处理中 / 失败 / 普通标签”区分,减少此前一套高亮样式混用时间、状态、标签造成的噪音。
- 2026-03-07:聊天页消息前台状态文案先收敛到用户视角:把 queue-draining / retrying-auto / uploading / send-failed 等内部细状态,前台统一归并到“处理中 / 需重试 / 已完成”这一层,细分恢复机制不再在时间线里处处抢注意力。