feat(ui): render assistant text blocks, skip thinking
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user