From f4fe11e52335a1bbcb50b0af4d43923bcbae7155 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 09:11:56 +0800 Subject: [PATCH] Show attachment metadata in chat cards --- .../cn/xiaobai/openclawapp/data/Models.kt | 2 ++ .../data/RemoteOpenClawRepository.kt | 8 ++++++++ .../openclawapp/feature/chat/ChatScreen.kt | 20 +++++++++++++++++++ .../openclawapp/network/MobileGatewayDtos.kt | 2 ++ 4 files changed, 32 insertions(+) diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt index 7f47747..e99d0ff 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt @@ -25,6 +25,8 @@ data class ChatMessage( val kind: MessageKind = MessageKind.Text, val toolName: String? = null, val toolCallId: String? = null, + val contentType: String? = null, + val sizeBytes: Int? = null, ) enum class MessageRole { User, Assistant, System } diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt index e24f1cb..ee41344 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -139,6 +139,8 @@ class RemoteOpenClawRepository( createdAt = "现在", status = "uploading", kind = MessageKind.Attachment, + contentType = contentType, + sizeBytes = bytes.size, ) messageStore = messageStore + (sessionId to (currentMessages + pending)) updateSessionPreview(sessionId, pending) @@ -156,6 +158,8 @@ class RemoteOpenClawRepository( createdAt = remote.queuedAt, status = "uploaded", kind = MessageKind.Attachment, + contentType = remote.contentType, + sizeBytes = remote.sizeBytes, ) val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) uploaded else msg } messageStore = messageStore + (sessionId to next) @@ -168,6 +172,8 @@ class RemoteOpenClawRepository( createdAt = "刚刚", status = "upload-failed", kind = MessageKind.Attachment, + contentType = contentType, + sizeBytes = bytes.size, ) val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) failed else msg } messageStore = messageStore + (sessionId to next) @@ -428,6 +434,8 @@ class RemoteOpenClawRepository( kind = kind.toMessageKind(), toolName = toolName, toolCallId = toolCallId, + contentType = contentType, + sizeBytes = sizeBytes, ) } diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt index db10974..49b961e 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt @@ -347,6 +347,17 @@ private fun MessageBubble( text = displayText, style = MaterialTheme.typography.bodyMedium, ) + val meta = buildList { + message.contentType?.takeIf { it.isNotBlank() }?.let { add(it) } + message.sizeBytes?.let { add(formatBytes(it)) } + }.joinToString(" · ") + if (meta.isNotBlank()) { + Text( + text = meta, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } } isTool -> { Text( @@ -442,3 +453,12 @@ private fun looksStructuredOutput(text: String): Boolean { val lineCount = trimmed.lines().size return lineCount >= 4 || trimmed.contains("\n ") || trimmed.contains("\t") } + +private fun formatBytes(bytes: Int): String { + val value = bytes.toLong().coerceAtLeast(0) + return when { + value >= 1024L * 1024L -> String.format("%.1f MB", value / 1024f / 1024f) + value >= 1024L -> String.format("%.1f KB", value / 1024f) + else -> "$value B" + } +} diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt index f9bbb5c..9b41a42 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt @@ -40,6 +40,8 @@ data class ChatMessageDto( val kind: String? = null, val toolName: String? = null, val toolCallId: String? = null, + val contentType: String? = null, + val sizeBytes: Int? = null, ) @Serializable