feat(app): show the run's recorded facts in its Summary
Stage, Started, Finished, Duration, Provider/model, Target and Verdict come from the run reply and the current stage's latest recorded visit. An absent fact reads Unavailable; tokens and cost keep their Metrics home.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../pipelines/pipeline_format.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
|
||||
/// The exact wording for a Summary fact the reply did not record.
|
||||
///
|
||||
/// It is the same word the Summary's usage rows already use for an unreported
|
||||
/// value, so one absent fact never reads as `0`, `false` or an empty field.
|
||||
const String summaryUnknownValue = 'Unavailable';
|
||||
|
||||
/// The run Summary's recorded facts, in the web summary's order: the current
|
||||
/// stage and the run's timing, then the latest recorded visit's effective
|
||||
/// provider/model, target and verdict.
|
||||
///
|
||||
/// The latest visit is the one the Graph tab opens for the current stage, so
|
||||
/// the Summary and the recorded-visit pane describe the same evidence. Tokens
|
||||
/// and cost stay in [detailUsageMetrics], their existing Summary home. A fact
|
||||
/// the server did not record reads [summaryUnknownValue].
|
||||
List<DetailMetric> detailSummaryFields(JsonMap run) {
|
||||
final steps = detailRunSteps(run);
|
||||
final stage = _text(run['current_stage']);
|
||||
final latest = _latestVisit(steps, stage);
|
||||
return [
|
||||
(label: 'Stage', value: stage ?? summaryUnknownValue),
|
||||
(
|
||||
label: 'Started',
|
||||
value:
|
||||
formatLocalTimestamp(_text(run['created_at'])) ?? summaryUnknownValue,
|
||||
),
|
||||
(
|
||||
label: 'Finished',
|
||||
value:
|
||||
formatLocalTimestamp(_text(run['finished_at'])) ??
|
||||
summaryUnknownValue,
|
||||
),
|
||||
(label: 'Duration', value: _duration(run) ?? summaryUnknownValue),
|
||||
(
|
||||
label: 'Provider/model',
|
||||
value: latest == null
|
||||
? summaryUnknownValue
|
||||
: detailVisitProviderModel(latest) ?? summaryUnknownValue,
|
||||
),
|
||||
(
|
||||
label: 'Target',
|
||||
value: latest == null
|
||||
? summaryUnknownValue
|
||||
: _text(latest['target']) ?? summaryUnknownValue,
|
||||
),
|
||||
(label: 'Verdict', value: _verdict(latest) ?? summaryUnknownValue),
|
||||
];
|
||||
}
|
||||
|
||||
/// The latest recorded visit of [stage], or the latest visit when the reply
|
||||
/// records no current stage. It is the same visit the Graph tab opens for that
|
||||
/// stage, so a fact and its Stage row never come from different visits.
|
||||
JsonMap? _latestVisit(List<JsonMap> steps, String? stage) {
|
||||
JsonMap? latest;
|
||||
for (final step in steps) {
|
||||
if (stage == null || _text(step['stage']) == stage) latest = step;
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
/// The run's stored duration from its own start and finish, never a live
|
||||
/// estimate and never a zero for an unfinished run.
|
||||
String? _duration(JsonMap run) {
|
||||
final seconds = durationSeconds(
|
||||
_text(run['created_at']),
|
||||
_text(run['finished_at']),
|
||||
);
|
||||
return seconds == null ? null : formatDuration(seconds);
|
||||
}
|
||||
|
||||
/// The recorded verdict as the web pane spells it: the option above its
|
||||
/// reason, one part when only one was recorded, nothing when neither was.
|
||||
String? _verdict(JsonMap? step) {
|
||||
if (step == null) return null;
|
||||
final verdict = detailVisitVerdict(step);
|
||||
if (verdict == null) return null;
|
||||
final parts = [verdict.option, verdict.reason].whereType<String>();
|
||||
return parts.isEmpty ? null : parts.join('\n');
|
||||
}
|
||||
|
||||
String? _text(dynamic value) {
|
||||
if (value == null) return null;
|
||||
final text = '$value'.trim();
|
||||
return text.isEmpty ? null : text;
|
||||
}
|
||||
@@ -3,10 +3,11 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_summary_fields.dart';
|
||||
|
||||
/// The Summary tab: the stored original prompt with its copy control and the
|
||||
/// reported usage metrics. Neither the prompt nor a metric is replaced by a
|
||||
/// fallback value.
|
||||
/// The Summary tab: the stored original prompt with its copy control, the
|
||||
/// run's recorded facts and the reported usage metrics. Neither the prompt nor
|
||||
/// a fact is replaced by a fallback value.
|
||||
Widget runDetailSummaryTab({
|
||||
required BuildContext context,
|
||||
required JsonMap run,
|
||||
@@ -16,6 +17,7 @@ Widget runDetailSummaryTab({
|
||||
required VoidCallback onCopy,
|
||||
}) {
|
||||
final prompt = detailPrompt(run);
|
||||
final facts = detailSummaryFields(run);
|
||||
final metrics = detailUsageMetrics(run['usage']);
|
||||
if (cupertino) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
@@ -55,6 +57,7 @@ Widget runDetailSummaryTab({
|
||||
),
|
||||
),
|
||||
_cupertinoMetrics(metrics),
|
||||
_cupertinoFacts(facts),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -89,6 +92,7 @@ Widget runDetailSummaryTab({
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
_materialMetrics(metrics),
|
||||
_materialFacts(facts),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -123,6 +127,24 @@ Widget runDetailFieldTab({
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialFacts(List<DetailMetric> facts) => Column(
|
||||
children: [
|
||||
for (final fact in facts)
|
||||
ListTile(title: Text(fact.label), subtitle: Text(fact.value)),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _cupertinoFacts(List<DetailMetric> facts) =>
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
for (final fact in facts)
|
||||
CupertinoListTile(
|
||||
title: Text(fact.label),
|
||||
subtitle: Text(fact.value),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _materialMetrics(List<DetailMetric> metrics) => ExpansionTile(
|
||||
title: const Text('Metrics'),
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user