refactor(ui): skeleton dispatch for StreamLineFormatter rewrite

This commit is contained in:
Mika Kuns
2026-04-21 15:00:00 +02:00
parent b4741137d0
commit 668087cda4

View File

@@ -6,6 +6,7 @@ namespace ClaudeDo.Ui.Helpers;
public class StreamLineFormatter
{
private const int MaxLength = 50_000;
private const int MaxArgChars = 120;
public string? FormatLine(string line)
{
@@ -22,73 +23,42 @@ public class StreamLineFormatter
using (doc)
{
var root = doc.RootElement;
if (root.ValueKind != JsonValueKind.Object)
return null;
if (!root.TryGetProperty("type", out var typeProp))
return null;
var type = typeProp.GetString();
switch (type)
return typeProp.GetString() switch
{
case "stream_event":
return FormatStreamEvent(root);
case "result":
if (root.TryGetProperty("result", out var resultProp))
return $"\n--- Result ---\n{resultProp.GetString()}\n";
return null;
case "system":
if (root.TryGetProperty("subtype", out var subtypeProp) &&
subtypeProp.GetString() == "api_retry")
return "\n[Retrying API call...]\n";
return null;
default:
return null;
}
"system" => FormatSystem(root),
"assistant" => FormatAssistant(root),
"user" => FormatUser(root),
"result" => FormatResult(root),
_ => null,
};
}
}
private static string? FormatStreamEvent(JsonElement root)
private static string? FormatSystem(JsonElement root)
{
if (!root.TryGetProperty("event", out var ev))
if (!root.TryGetProperty("subtype", out var subtypeProp))
return null;
if (!ev.TryGetProperty("type", out var evTypeProp))
return null;
var evType = evTypeProp.GetString();
switch (evType)
return subtypeProp.GetString() switch
{
case "content_block_delta":
if (!ev.TryGetProperty("delta", out var delta))
return null;
if (!delta.TryGetProperty("type", out var deltaTypeProp))
return null;
var deltaType = deltaTypeProp.GetString();
if (deltaType == "text_delta")
{
return delta.TryGetProperty("text", out var textProp)
? textProp.GetString()
: null;
}
return null; // input_json_delta and others → skip
"api_retry" => "[Retrying API call...]\n",
_ => null,
};
}
case "content_block_stop":
return "\n";
private static string? FormatAssistant(JsonElement root) => null;
case "content_block_start":
if (!ev.TryGetProperty("content_block", out var cb))
return null;
if (cb.TryGetProperty("type", out var cbTypeProp) &&
cbTypeProp.GetString() == "tool_use" &&
cb.TryGetProperty("name", out var nameProp))
return $"\n[Tool: {nameProp.GetString()}]\n";
return null;
private static string? FormatUser(JsonElement root) => null;
default:
return null; // message_start, message_delta, etc.
}
private static string? FormatResult(JsonElement root)
{
if (root.TryGetProperty("result", out var resultProp))
return $"\n--- Result ---\n{resultProp.GetString()}\n";
return null;
}
public string FormatFile(string filePath)