Link tool results to tool calls in chat UI
This commit is contained in:
1 parent
38505e513a
commit
91b3b54b9d
5 files changed
+28
-2
No files matched your search
@@ -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 }
|
||||
|
||||
+4
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -39,6 +39,7 @@ data class ChatMessageDto(
|
||||
val status: String? = null,
|
||||
val kind: String? = null,
|
||||
val toolName: String? = null,
|
||||
val toolCallId: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user