From 3f607f6c1ac93e63d573a66ad6546b70a138002a Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 09:21:22 +0800 Subject: [PATCH] Format session previews for attachment and tool events --- .../data/RemoteOpenClawRepository.kt | 18 +++++++++++++++++- .../feature/sessions/SessionListScreen.kt | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) 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 654068a..21f0dc1 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -400,7 +400,7 @@ class RemoteOpenClawRepository( } private fun updateSessionPreview(sessionId: String, lastMessage: ChatMessage?) { - val preview = lastMessage?.text?.trim().orEmpty() + val preview = lastMessage?.toSessionPreview().orEmpty() val updatedAt = lastMessage?.createdAt ?: "刚刚" sessions = sessions.map { session -> if (session.id == sessionId) { @@ -483,6 +483,22 @@ class RemoteOpenClawRepository( ) } + private fun ChatMessage.toSessionPreview(): String { + return when (kind) { + MessageKind.Attachment -> "[附件] $text" + MessageKind.Tool -> "[工具] ${toolName ?: text}" + MessageKind.ToolResult -> if (status == "tool-error") "[工具错误] ${linkedPreviewText(text)}" else "[工具结果] ${linkedPreviewText(text)}" + MessageKind.Thinking -> "[思考中] ${linkedPreviewText(text)}" + MessageKind.Text -> when { + role == MessageRole.System && status == "stream-failed" -> "[断流] ${linkedPreviewText(text)}" + role == MessageRole.System -> "[系统] ${linkedPreviewText(text)}" + else -> linkedPreviewText(text) + } + } + } + + private fun linkedPreviewText(value: String): String = value.trim().replace("\n", " ").take(80) + private fun cn.xiaobai.openclawapp.network.ChatMessageDto.toDomainMessage(): ChatMessage { return ChatMessage( id = id, diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/sessions/SessionListScreen.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/sessions/SessionListScreen.kt index fab8a63..b64b55d 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/sessions/SessionListScreen.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/sessions/SessionListScreen.kt @@ -125,7 +125,7 @@ fun SessionListScreen( Text("最近访问", style = MaterialTheme.typography.labelLarge) Text(recentSession.title, style = MaterialTheme.typography.titleMedium) Text( - recentSession.lastMessage, + recentSession.lastMessage.ifBlank { "暂无摘要" }, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, ) @@ -209,7 +209,7 @@ fun SessionListScreen( StatusPill(text = session.updatedAt, highlighted = true) } Text( - text = session.lastMessage, + text = session.lastMessage.ifBlank { "暂无摘要" }, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, )