Show attachment metadata in chat cards

This commit is contained in:
OpenClaw committed 2026-03-07 09:11:56 +08:00
1 parent 88abe085d2
commit f4fe11e523
4 files changed
+32

No files matched your search

@@ -25,6 +25,8 @@ data class ChatMessage(
val kind: MessageKind = MessageKind.Text, val kind: MessageKind = MessageKind.Text,
val toolName: String? = null, val toolName: String? = null,
val toolCallId: String? = null, val toolCallId: String? = null,
val contentType: String? = null,
val sizeBytes: Int? = null,
) )
enum class MessageRole { User, Assistant, System } enum class MessageRole { User, Assistant, System }
@@ -139,6 +139,8 @@ class RemoteOpenClawRepository(
createdAt = "现在", createdAt = "现在",
status = "uploading", status = "uploading",
kind = MessageKind.Attachment, kind = MessageKind.Attachment,
contentType = contentType,
sizeBytes = bytes.size,
) )
messageStore = messageStore + (sessionId to (currentMessages + pending)) messageStore = messageStore + (sessionId to (currentMessages + pending))
updateSessionPreview(sessionId, pending) updateSessionPreview(sessionId, pending)
@@ -156,6 +158,8 @@ class RemoteOpenClawRepository(
createdAt = remote.queuedAt, createdAt = remote.queuedAt,
status = "uploaded", status = "uploaded",
kind = MessageKind.Attachment, kind = MessageKind.Attachment,
contentType = remote.contentType,
sizeBytes = remote.sizeBytes,
) )
val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) uploaded else msg } val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) uploaded else msg }
messageStore = messageStore + (sessionId to next) messageStore = messageStore + (sessionId to next)
@@ -168,6 +172,8 @@ class RemoteOpenClawRepository(
createdAt = "刚刚", createdAt = "刚刚",
status = "upload-failed", status = "upload-failed",
kind = MessageKind.Attachment, kind = MessageKind.Attachment,
contentType = contentType,
sizeBytes = bytes.size,
) )
val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) failed else msg } val next = messageStore[sessionId].orEmpty().map { msg -> if (msg.id == localId) failed else msg }
messageStore = messageStore + (sessionId to next) messageStore = messageStore + (sessionId to next)
@@ -428,6 +434,8 @@ class RemoteOpenClawRepository(
kind = kind.toMessageKind(), kind = kind.toMessageKind(),
toolName = toolName, toolName = toolName,
toolCallId = toolCallId, toolCallId = toolCallId,
contentType = contentType,
sizeBytes = sizeBytes,
) )
} }
@@ -347,6 +347,17 @@ private fun MessageBubble(
text = displayText, text = displayText,
style = MaterialTheme.typography.bodyMedium, 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 -> { isTool -> {
Text( Text(
@@ -442,3 +453,12 @@ private fun looksStructuredOutput(text: String): Boolean {
val lineCount = trimmed.lines().size val lineCount = trimmed.lines().size
return lineCount >= 4 || trimmed.contains("\n ") || trimmed.contains("\t") 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"
}
}
@@ -40,6 +40,8 @@ data class ChatMessageDto(
val kind: String? = null, val kind: String? = null,
val toolName: String? = null, val toolName: String? = null,
val toolCallId: String? = null, val toolCallId: String? = null,
val contentType: String? = null,
val sizeBytes: Int? = null,
) )
@Serializable @Serializable