diff --git a/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt b/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt index 6137854..7e6aa3b 100644 --- a/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt +++ b/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt @@ -107,9 +107,14 @@ class ChatController( val granted: Boolean? = null, ) : Item - // The turn's end tag ("Handled", "Failed", …) from turn_done; the - // reply carries the text, this carries the outcome. - data class Outcome(override val id: Long, val outcome: String) : Item + // The turn's end tag ("handled", "failed", …) from turn_done; the + // reply carries the text, this carries the outcome, and a failed + // turn carries the reason it broke. + data class Outcome( + override val id: Long, + val outcome: String, + val reason: String? = null, + ) : Item // One applied event with the seq the claw gave it: the cache window // needs the seqs to resume from, and a lagged drop leaves a gap the @@ -443,7 +448,9 @@ class ChatController( item.copy(streaming = false) } } - event.outcome?.let { outcome -> list = list + Outcome(newId(), outcome) } + event.outcome?.let { outcome -> + list = list + Outcome(newId(), outcome, event.reason) + } } is ClawEvent.Attachment -> list = list + Attachment(newId(), event.id, event.name, event.media, event.size, event.caption) diff --git a/android/app/src/main/java/rs/rhema/phone/net/Models.kt b/android/app/src/main/java/rs/rhema/phone/net/Models.kt index f223f88..a1fc51b 100644 --- a/android/app/src/main/java/rs/rhema/phone/net/Models.kt +++ b/android/app/src/main/java/rs/rhema/phone/net/Models.kt @@ -180,10 +180,15 @@ sealed interface ClawEvent { // The reply is null when the turn ended without producing text — // a failed turn, mostly. Nullable on purpose: a dropped frame would - // hide exactly the turns a viewer needs the outcome tag for. + // hide exactly the turns a viewer needs the outcome tag for. A + // failed turn also carries the handler's own words on what broke. @Serializable @SerialName("turn_done") - data class TurnDone(val reply: String? = null, val outcome: String? = null) : ClawEvent + data class TurnDone( + val reply: String? = null, + val outcome: String? = null, + val reason: String? = null, + ) : ClawEvent // A file the agent produced. The bytes are not on the stream; they // live at GET /v1/attachments/{id} behind the same bearer token. diff --git a/android/app/src/main/java/rs/rhema/phone/ui/ChatScreen.kt b/android/app/src/main/java/rs/rhema/phone/ui/ChatScreen.kt index 03cbe8d..f476584 100644 --- a/android/app/src/main/java/rs/rhema/phone/ui/ChatScreen.kt +++ b/android/app/src/main/java/rs/rhema/phone/ui/ChatScreen.kt @@ -590,7 +590,7 @@ private fun TurnGroupRow( is ChatController.Attachment -> AttachmentCard(item, container) is ChatController.Consent -> ConsentCard(item, controller) is ChatController.Reply -> ReplyBlock(item) - is ChatController.Outcome -> OutcomeTag(item.outcome) + is ChatController.Outcome -> OutcomeTag(item.outcome, item.reason) else -> Unit // thinking and tool calls never render } } @@ -641,7 +641,7 @@ private fun ReplyBlock(item: ChatController.Reply) { } @Composable -private fun OutcomeTag(outcome: String) { +private fun OutcomeTag(outcome: String, reason: String?) { // A steered turn was cut short by the next message, not failed: the // reply that replaced it streams right below, so the word reads as // an accent, not an error — the same distinction the web UI draws. @@ -651,11 +651,37 @@ private fun OutcomeTag(outcome: String) { outcome.equals("Aborted", ignoreCase = true) -> TogetherWarn else -> TogetherMuted } - Text( - outcome, - style = MaterialTheme.typography.bodySmall, - color = color, - ) + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text( + outcome, + style = MaterialTheme.typography.bodySmall, + color = color, + ) + if (reason != null) FailureReason(reason) + } +} + +// The failure's own words, kept whole and set in mono: a provider error +// names the endpoint, the status, and the body, and wrapping is what +// makes all of it readable — the same block the web surface draws. +@Composable +private fun FailureReason(reason: String) { + Surface( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(8.dp), + color = TogetherSurface2, + ) { + Row(modifier = Modifier.height(IntrinsicSize.Min)) { + AccentBar(TogetherBorderStrong, width = 2.dp) + Text( + reason, + modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp), + style = MaterialTheme.typography.bodySmall, + fontFamily = TogetherMono, + color = TogetherText, + ) + } + } } @Composable