fix: show structured-output summary instead of raw JSON in OUTCOME
A --json-schema run can echo the structured {"summary":...} JSON as the
result text, which then landed verbatim in task.Result and rendered raw in
the OUTCOME card. Unwrap the summary in StreamAnalyzer when the result text
is itself such a JSON object (a plain markdown result is kept as-is), and
add a UI safety net in ApplyOutcome for rows already persisted as raw JSON.
This commit is contained in:
@@ -91,16 +91,34 @@ public sealed class StreamAnalyzer
|
||||
|
||||
private string? FallbackResult()
|
||||
{
|
||||
// A --json-schema run sometimes echoes the structured JSON as the result text; unwrap
|
||||
// that to its summary. A plain markdown result is kept verbatim (even when a separate
|
||||
// structured_output is also present). Only when there is no result text do we fall back
|
||||
// to the structured summary, then the raw JSON.
|
||||
if (SummaryFromJson(_resultMarkdown) is { } fromResult) return fromResult;
|
||||
if (!string.IsNullOrEmpty(_resultMarkdown)) return _resultMarkdown;
|
||||
if (_structuredOutputJson is null) return _resultMarkdown;
|
||||
if (SummaryFromJson(_structuredOutputJson) is { } fromStructured) return fromStructured;
|
||||
return _structuredOutputJson;
|
||||
}
|
||||
|
||||
/// <summary>Extracts a non-empty string <c>summary</c> from a JSON object, or null when
|
||||
/// the input isn't such an object (a plain markdown result parses to null and is kept).</summary>
|
||||
private static string? SummaryFromJson(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return null;
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(_structuredOutputJson);
|
||||
if (doc.RootElement.TryGetProperty("summary", out var s))
|
||||
return s.GetString();
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
if (doc.RootElement.ValueKind == JsonValueKind.Object &&
|
||||
doc.RootElement.TryGetProperty("summary", out var s) &&
|
||||
s.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
var text = s.GetString();
|
||||
return string.IsNullOrWhiteSpace(text) ? null : text;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return _structuredOutputJson;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void CollectFromAssistant(JsonElement root)
|
||||
|
||||
Reference in New Issue
Block a user