From 38505e513a355f14dbfa9516ab703e025e01df01 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 08:41:54 +0800 Subject: [PATCH] Improve tool cards and stream failure messaging --- .../openclawapp/data/RemoteOpenClawRepository.kt | 15 ++++++++++++++- .../openclawapp/feature/chat/ChatScreen.kt | 8 ++++++-- 2 files changed, 20 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 84e61c8..cdebc66 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -234,7 +234,20 @@ class RemoteOpenClawRepository( is SessionStreamEvent.Failed -> { val dto = event.payload - if (!dto.recoverable) return@collect + if (!dto.recoverable) { + messageStore = messageStore + ( + sessionId to (messageStore[sessionId].orEmpty() + ChatMessage( + id = "stream-failed-$sessionId", + role = MessageRole.System, + text = dto.message, + createdAt = "刚刚", + status = "stream-failed", + kind = MessageKind.Text, + )) + ) + updateSessionPreview(sessionId, messageStore[sessionId]?.lastOrNull()) + return@collect + } // recoverable: will retry via outer while loop } } 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 796e168..8f3717d 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 @@ -278,14 +278,18 @@ private fun MessageBubble( style = MaterialTheme.typography.titleSmall, ) Text( - text = displayText.ifBlank { "工具正在执行…" }, + text = when (message.status) { + "tool-done" -> "工具执行完成" + "tool-error" -> "工具执行失败" + else -> displayText.ifBlank { "工具正在执行…" } + }, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, ) } isToolResult -> { Text( - text = "工具结果", + text = if (message.status == "tool-error") "工具错误" else "工具结果", style = MaterialTheme.typography.titleSmall, ) Text(text = displayText, style = MaterialTheme.typography.bodyMedium)