Show attachment metadata in chat cards
This commit is contained in:
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 toolName: String? = null,
|
||||
val toolCallId: String? = null,
|
||||
val contentType: String? = null,
|
||||
val sizeBytes: Int? = null,
|
||||
)
|
||||
|
||||
enum class MessageRole { User, Assistant, System }
|
||||
|
||||
+8
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user