From dc6e3fe4425ced741cbb1f22240575e7ef1a8336 Mon Sep 17 00:00:00 2001 From: Mika Kuns Date: Tue, 21 Apr 2026 15:05:40 +0200 Subject: [PATCH] feat(ui): render assistant text blocks, skip thinking --- .../Helpers/StreamLineFormatter.cs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/ClaudeDo.Ui/Helpers/StreamLineFormatter.cs b/src/ClaudeDo.Ui/Helpers/StreamLineFormatter.cs index aec50f7..1990bed 100644 --- a/src/ClaudeDo.Ui/Helpers/StreamLineFormatter.cs +++ b/src/ClaudeDo.Ui/Helpers/StreamLineFormatter.cs @@ -69,7 +69,55 @@ public class StreamLineFormatter } } - private static string? FormatAssistant(JsonElement root) => null; + private static string? FormatAssistant(JsonElement root) + { + if (!TryGetContentArray(root, out var content)) + return null; + + var sb = new StringBuilder(); + foreach (var block in content.EnumerateArray()) + { + if (block.ValueKind != JsonValueKind.Object) continue; + if (!block.TryGetProperty("type", out var blockTypeProp)) continue; + + switch (blockTypeProp.GetString()) + { + case "text": + if (block.TryGetProperty("text", out var textProp)) + { + var text = textProp.GetString(); + if (!string.IsNullOrEmpty(text)) + { + sb.Append(text); + if (!text.EndsWith('\n')) sb.Append('\n'); + } + } + break; + + case "tool_use": + // Filled in by a later task. + break; + + case "thinking": + default: + // Filtered. + break; + } + } + + return sb.Length == 0 ? null : sb.ToString(); + } + + private static bool TryGetContentArray(JsonElement root, out JsonElement content) + { + content = default; + if (!root.TryGetProperty("message", out var message)) return false; + if (message.ValueKind != JsonValueKind.Object) return false; + if (!message.TryGetProperty("content", out var c)) return false; + if (c.ValueKind != JsonValueKind.Array) return false; + content = c; + return true; + } private static string? FormatUser(JsonElement root) => null;