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 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 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(); 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; }