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 a9b0501..c2a34a4 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt @@ -23,6 +23,7 @@ data class ChatMessage( val status: String? = null, val kind: MessageKind = MessageKind.Text, val toolName: String? = null, + val toolCallId: String? = 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 cdebc66..8ea1ff4 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -187,6 +187,7 @@ class RemoteOpenClawRepository( status = dto.status ?: "streaming", kind = dto.kind.toMessageKind(), toolName = dto.toolName, + toolCallId = dto.toolCallId, ) messageStore = messageStore + (sessionId to next) } @@ -202,6 +203,7 @@ class RemoteOpenClawRepository( status = dto.status ?: "streaming", kind = dto.kind.toMessageKind(), toolName = dto.toolName, + toolCallId = dto.toolCallId, ) else msg } val exists = updated.any { it.id == dto.id } @@ -213,6 +215,7 @@ class RemoteOpenClawRepository( status = dto.status ?: "streaming", kind = dto.kind.toMessageKind(), toolName = dto.toolName, + toolCallId = dto.toolCallId, ) messageStore = messageStore + (sessionId to next) updateSessionPreview(sessionId, next.lastOrNull()) @@ -350,6 +353,7 @@ class RemoteOpenClawRepository( status = status, kind = kind.toMessageKind(), toolName = toolName, + toolCallId = toolCallId, ) } 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 8f3717d..3818e75 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 @@ -140,8 +140,19 @@ fun ChatScreen( val shouldAnimate = index == messages.lastIndex && message.role == MessageRole.Assistant && message.createdAt == "现在" + val linkedTool = if (message.kind == MessageKind.ToolResult) { + messages.lastOrNull { + it.kind == MessageKind.Tool && + it.toolCallId != null && + it.toolCallId == message.toolCallId + } + } else null - MessageBubble(message = message, animateText = shouldAnimate) + MessageBubble( + message = message, + animateText = shouldAnimate, + linkedToolName = linkedTool?.toolName, + ) } } } @@ -198,6 +209,7 @@ private fun RowScope.QuickActionButton(text: String, onClick: () -> Unit) { private fun MessageBubble( message: ChatMessage, animateText: Boolean = false, + linkedToolName: String? = null, ) { val alignment = when (message.role) { MessageRole.User -> Alignment.CenterEnd @@ -289,7 +301,13 @@ private fun MessageBubble( } isToolResult -> { Text( - text = if (message.status == "tool-error") "工具错误" else "工具结果", + text = buildString { + append(if (message.status == "tool-error") "工具错误" else "工具结果") + if (!linkedToolName.isNullOrBlank()) { + append(" · ") + append(linkedToolName) + } + }, style = MaterialTheme.typography.titleSmall, ) Text(text = displayText, style = MaterialTheme.typography.bodyMedium) 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 ba2e5e3..e6c2603 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt @@ -39,6 +39,7 @@ data class ChatMessageDto( val status: String? = null, val kind: String? = null, val toolName: String? = null, + val toolCallId: String? = null, ) @Serializable diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/SseModels.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/SseModels.kt index 2371987..227b1d9 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/SseModels.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/SseModels.kt @@ -16,6 +16,7 @@ data class MessageStartedEventDto( val status: String? = null, val kind: String? = null, val toolName: String? = null, + val toolCallId: String? = null, ) @Serializable @@ -28,6 +29,7 @@ data class MessageDeltaEventDto( val status: String? = null, val kind: String? = null, val toolName: String? = null, + val toolCallId: String? = null, ) @Serializable