refactor(ui): skeleton dispatch for StreamLineFormatter rewrite
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ClaudeDo.Ui.Helpers;
|
|||||||
public class StreamLineFormatter
|
public class StreamLineFormatter
|
||||||
{
|
{
|
||||||
private const int MaxLength = 50_000;
|
private const int MaxLength = 50_000;
|
||||||
|
private const int MaxArgChars = 120;
|
||||||
|
|
||||||
public string? FormatLine(string line)
|
public string? FormatLine(string line)
|
||||||
{
|
{
|
||||||
@@ -22,73 +23,42 @@ public class StreamLineFormatter
|
|||||||
using (doc)
|
using (doc)
|
||||||
{
|
{
|
||||||
var root = doc.RootElement;
|
var root = doc.RootElement;
|
||||||
|
if (root.ValueKind != JsonValueKind.Object)
|
||||||
|
return null;
|
||||||
if (!root.TryGetProperty("type", out var typeProp))
|
if (!root.TryGetProperty("type", out var typeProp))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var type = typeProp.GetString();
|
return typeProp.GetString() switch
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
{
|
||||||
case "stream_event":
|
"system" => FormatSystem(root),
|
||||||
return FormatStreamEvent(root);
|
"assistant" => FormatAssistant(root),
|
||||||
|
"user" => FormatUser(root),
|
||||||
case "result":
|
"result" => FormatResult(root),
|
||||||
if (root.TryGetProperty("result", out var resultProp))
|
_ => null,
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return null;
|
||||||
if (!ev.TryGetProperty("type", out var evTypeProp))
|
return subtypeProp.GetString() switch
|
||||||
return null;
|
|
||||||
|
|
||||||
var evType = evTypeProp.GetString();
|
|
||||||
|
|
||||||
switch (evType)
|
|
||||||
{
|
{
|
||||||
case "content_block_delta":
|
"api_retry" => "[Retrying API call...]\n",
|
||||||
if (!ev.TryGetProperty("delta", out var delta))
|
_ => null,
|
||||||
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
|
|
||||||
|
|
||||||
case "content_block_stop":
|
private static string? FormatAssistant(JsonElement root) => null;
|
||||||
return "\n";
|
|
||||||
|
|
||||||
case "content_block_start":
|
private static string? FormatUser(JsonElement root) => null;
|
||||||
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;
|
|
||||||
|
|
||||||
default:
|
private static string? FormatResult(JsonElement root)
|
||||||
return null; // message_start, message_delta, etc.
|
{
|
||||||
}
|
if (root.TryGetProperty("result", out var resultProp))
|
||||||
|
return $"\n--- Result ---\n{resultProp.GetString()}\n";
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FormatFile(string filePath)
|
public string FormatFile(string filePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user