merge(app): land the recorded visit pane after a retained deadline
This commit is contained in:
@@ -247,3 +247,14 @@ class PipelinesClient implements ApiGateway {
|
||||
await _states.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// The configured server origin of [gateway], or blank when the gateway does
|
||||
/// not expose one (a feature fixture).
|
||||
///
|
||||
/// Relative artifact and session urls resolve only against this origin; an
|
||||
/// absolute recorded http(s) url still resolves without it. The cast lives here
|
||||
/// so callers never repeat it.
|
||||
String configuredGatewayEndpoint(ApiGateway gateway) {
|
||||
final client = gateway is PipelinesClient ? gateway : null;
|
||||
return client?.endpoint?.toString() ?? '';
|
||||
}
|
||||
|
||||
@@ -107,3 +107,25 @@ List<ArtifactRecord> visitArtifacts(JsonMap step, List<JsonMap> runSteps) {
|
||||
if (!artifact.isPublicName || !seen.contains(artifact.name)) artifact,
|
||||
];
|
||||
}
|
||||
|
||||
/// The gallery group of exactly one recorded visit, addressed by its index in
|
||||
/// [runSteps]. The whole run is still read so a shared `public/` file stays with
|
||||
/// the visit that first recorded it and the group keeps the run's own visit
|
||||
/// numbering. Null when the index is out of range or the visit recorded no
|
||||
/// presentable stage artifact.
|
||||
ArtifactGroup? visitArtifactGroup(List<JsonMap> runSteps, int index) {
|
||||
if (index < 0 || index >= runSteps.length) return null;
|
||||
final step = runSteps[index];
|
||||
final stage = '${step['stage'] ?? ''}';
|
||||
final visits = visitsByStage(runSteps)[stage];
|
||||
if (visits == null) return null;
|
||||
// The pane passes the index of the same parsed list, so the recorded map is
|
||||
// the identical instance the stage grouping holds.
|
||||
final position = visits.indexOf(step);
|
||||
if (position < 0) return null;
|
||||
final visit = displayVisit(step, position);
|
||||
for (final group in artifactGroups(runSteps)) {
|
||||
if (group.stageKey == stage && group.visit == visit) return group;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -35,15 +35,6 @@ bool _runExecuting(JsonMap run) =>
|
||||
run['executing'] == true ||
|
||||
_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
|
||||
|
||||
/// The configured endpoint from the app's shared transport, when the gateway
|
||||
/// exposes it. Feature fixtures without an endpoint leave it blank, which only
|
||||
/// disables relative url resolution: an absolute recorded http(s) url still
|
||||
/// resolves. The url rules themselves live in `artifact_url.dart`.
|
||||
String _gatewayEndpoint(ApiGateway gateway) {
|
||||
final endpoint = gateway is PipelinesClient ? gateway.endpoint : null;
|
||||
return endpoint?.toString() ?? '';
|
||||
}
|
||||
|
||||
/// The run detail's standard native action that opens the recorded artifact
|
||||
/// groups. It is composed only when [showRunArtifactsAction] is true.
|
||||
class RunArtifactsButton extends StatelessWidget {
|
||||
@@ -63,7 +54,7 @@ class RunArtifactsButton extends StatelessWidget {
|
||||
context,
|
||||
steps: steps,
|
||||
executing: _runExecuting(run),
|
||||
configuredEndpoint: _gatewayEndpoint(gateway),
|
||||
configuredEndpoint: configuredGatewayEndpoint(gateway),
|
||||
);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoButton.tinted(
|
||||
@@ -86,12 +77,14 @@ class RunArtifactsButton extends StatelessWidget {
|
||||
Future<void> showArtifactGallery(
|
||||
BuildContext context, {
|
||||
required List<JsonMap> steps,
|
||||
int? focusIndex,
|
||||
bool executing = false,
|
||||
String configuredEndpoint = '',
|
||||
ArtifactExternalOpen openExternal = openArtifactExternally,
|
||||
}) {
|
||||
final page = ArtifactGalleryPage(
|
||||
steps: List<JsonMap>.unmodifiable(steps),
|
||||
focusIndex: focusIndex,
|
||||
executing: executing,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
openExternal: openExternal,
|
||||
|
||||
@@ -33,10 +33,16 @@ const String artifactGalleryTitle = 'Artifacts';
|
||||
/// actions plus file `Download`/`Share` for a server-served url. Markdown
|
||||
/// previews use the same chat markdown renderer by default. It never filters,
|
||||
/// and an external url is never fetched for preview or file transfer.
|
||||
///
|
||||
/// [focusIndex] limits the page to the visited `steps` index's attributed
|
||||
/// group. The whole run is still passed so shared `public/` files keep their
|
||||
/// first visit and the group keeps the run's visit numbering; the page then
|
||||
/// lists exactly what the opening pane listed.
|
||||
class ArtifactGalleryPage extends StatefulWidget {
|
||||
const ArtifactGalleryPage({
|
||||
super.key,
|
||||
required this.steps,
|
||||
this.focusIndex,
|
||||
this.executing = false,
|
||||
this.configuredEndpoint = '',
|
||||
this.openExternal = openArtifactExternally,
|
||||
@@ -46,6 +52,10 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
|
||||
/// The `steps` index whose group this page shows, or null for every group.
|
||||
final int? focusIndex;
|
||||
|
||||
final bool executing;
|
||||
final String configuredEndpoint;
|
||||
final ArtifactExternalOpen openExternal;
|
||||
@@ -61,10 +71,16 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
late final Map<String, JsonMap> _stepsByGroup = recordedStepsByGroup(
|
||||
widget.steps,
|
||||
);
|
||||
late final List<ArtifactGroup> _groups = artifactGroups(widget.steps);
|
||||
late final List<ArtifactGroup> _groups = _groupsOf(widget.focusIndex);
|
||||
String? _selectedIdentity;
|
||||
String? _status;
|
||||
|
||||
List<ArtifactGroup> _groupsOf(int? focusIndex) {
|
||||
if (focusIndex == null) return artifactGroups(widget.steps);
|
||||
final group = visitArtifactGroup(widget.steps, focusIndex);
|
||||
return group == null ? const <ArtifactGroup>[] : <ArtifactGroup>[group];
|
||||
}
|
||||
|
||||
Future<void> _select(ArtifactGroup group, ArtifactRecord artifact) async {
|
||||
final identity = artifactVisitIdentity(group, artifact);
|
||||
final resolved = artifact.hasUrl
|
||||
@@ -227,12 +243,28 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
setState(() => _status = message);
|
||||
}
|
||||
|
||||
/// The page's one summary line: a focused visit uses its own capture summary,
|
||||
/// a run-level page uses the run header, and an empty reply says so.
|
||||
String _summary(List<ArtifactGroup> groups) {
|
||||
final focusIndex = widget.focusIndex;
|
||||
if (focusIndex != null &&
|
||||
focusIndex >= 0 &&
|
||||
focusIndex < widget.steps.length) {
|
||||
final focused = widget.steps[focusIndex];
|
||||
final count = groups.fold<int>(
|
||||
0,
|
||||
(total, group) => total + group.artifacts.length,
|
||||
);
|
||||
return artifactsSummary(focused, count: count);
|
||||
}
|
||||
if (widget.steps.isEmpty) return 'No steps recorded for this run.';
|
||||
return artifactsHeader(widget.steps, executing: widget.executing);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final groups = _groups;
|
||||
final summary = widget.steps.isEmpty
|
||||
? 'No steps recorded for this run.'
|
||||
: artifactsHeader(widget.steps, executing: widget.executing);
|
||||
final summary = _summary(groups);
|
||||
final body = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
|
||||
@@ -20,6 +20,7 @@ Widget buildCupertinoRunDetail({
|
||||
required String? copyStatus,
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
required String configuredEndpoint,
|
||||
}) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
return RunDetailTabs(
|
||||
@@ -28,6 +29,7 @@ Widget buildCupertinoRunDetail({
|
||||
copying: copying,
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
|
||||
@@ -20,6 +20,7 @@ Widget buildMaterialRunDetail({
|
||||
required String? copyStatus,
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
required String configuredEndpoint,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return RunDetailTabs(
|
||||
@@ -28,6 +29,7 @@ Widget buildMaterialRunDetail({
|
||||
copying: copying,
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
|
||||
@@ -55,7 +55,7 @@ class _RunDetailTabStripState extends State<RunDetailTabStrip> {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: _ScrollWhenOverflowing(
|
||||
child: ScrollWhenOverflowing(
|
||||
child: KeyedSubtree(
|
||||
key: const Key('run-detail-tabs'),
|
||||
child: cupertino ? _cupertinoControl() : _materialControl(),
|
||||
@@ -97,8 +97,11 @@ class _RunDetailTabStripState extends State<RunDetailTabStrip> {
|
||||
|
||||
/// Gives [child] at least the pane width, then scrolls instead of squeezing it
|
||||
/// below its content width.
|
||||
class _ScrollWhenOverflowing extends StatelessWidget {
|
||||
const _ScrollWhenOverflowing({required this.child});
|
||||
///
|
||||
/// The run detail's tab strips both use this, so the pointer-drag rule and the
|
||||
/// minimum-width rule live in one place.
|
||||
class ScrollWhenOverflowing extends StatelessWidget {
|
||||
const ScrollWhenOverflowing({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'run_detail_tab.dart';
|
||||
import 'run_detail_tab_bodies.dart';
|
||||
import 'run_detail_tab_strip.dart';
|
||||
import 'run_detail_timeline.dart';
|
||||
import 'run_detail_visit.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
|
||||
/// The least height the selected tab keeps for its own content.
|
||||
///
|
||||
@@ -23,7 +25,7 @@ const double kRunDetailMinContentHeight = 240;
|
||||
///
|
||||
/// The Graph tab fills its slot with [RunGraphView] from the run's own pinned
|
||||
/// graph and recorded steps. A visited stage click selects that stage's latest
|
||||
/// recorded visit and switches to Timeline, where the row is highlighted. A
|
||||
/// recorded visit and switches to Timeline, where that visit's pane opens. A
|
||||
/// node with no recorded visit reports nothing, so no visit is invented.
|
||||
class RunDetailTabs extends StatefulWidget {
|
||||
const RunDetailTabs({
|
||||
@@ -34,6 +36,7 @@ class RunDetailTabs extends StatefulWidget {
|
||||
required this.copying,
|
||||
required this.copyStatus,
|
||||
required this.onCopy,
|
||||
required this.configuredEndpoint,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
@@ -47,6 +50,10 @@ class RunDetailTabs extends StatefulWidget {
|
||||
final String? copyStatus;
|
||||
final VoidCallback onCopy;
|
||||
|
||||
/// The configured server origin used to resolve a recorded session export
|
||||
/// through the landed safe-link helper. Blank leaves relative urls unresolved.
|
||||
final String configuredEndpoint;
|
||||
|
||||
@override
|
||||
State<RunDetailTabs> createState() => _RunDetailTabsState();
|
||||
}
|
||||
@@ -71,15 +78,24 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
/// Selects the stage's latest recorded visit. An unvisited stage has none,
|
||||
/// so the detail stays where it is rather than fabricating a visit.
|
||||
void _openStage(String stageKey) {
|
||||
final visit = latestDetailVisit(widget.run['steps'], stageKey);
|
||||
if (visit == null) return;
|
||||
final index = latestDetailVisitIndex(widget.run['steps'], stageKey);
|
||||
if (index == null) return;
|
||||
setState(() {
|
||||
_selectedStage = stageKey;
|
||||
_selectedVisit = visit.sequence;
|
||||
_selectedVisit = index;
|
||||
_tab = RunDetailTab.timeline;
|
||||
});
|
||||
}
|
||||
|
||||
/// Opens one recorded timeline row. The row index is also the index into the
|
||||
/// detail's own steps, so the pane reads exactly the visit it came from.
|
||||
void _openVisit(int index) {
|
||||
if (detailVisitStepAt(widget.run, index) == null) return;
|
||||
setState(() => _selectedVisit = index);
|
||||
}
|
||||
|
||||
void _closeVisit() => setState(() => _selectedVisit = null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
@@ -151,10 +167,33 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
cupertino: widget.cupertino,
|
||||
);
|
||||
case RunDetailTab.timeline:
|
||||
final visits = detailTimeline(widget.run['steps']);
|
||||
final index = _selectedVisit;
|
||||
if (index != null && index >= 0 && index < visits.length) {
|
||||
final step = detailVisitStepAt(widget.run, index);
|
||||
if (step != null) {
|
||||
return KeyedSubtree(
|
||||
key: const Key('run-detail-tab-body-timeline'),
|
||||
child: RunVisitPane(
|
||||
run: widget.run,
|
||||
visit: visits[index],
|
||||
visitIndex: index,
|
||||
step: step,
|
||||
runSteps: detailRunSteps(widget.run),
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
cupertino: widget.cupertino,
|
||||
onClose: _closeVisit,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return RunTimelineList(
|
||||
visits: detailTimeline(widget.run['steps']),
|
||||
selectedSequence: _selectedVisit,
|
||||
visits: visits,
|
||||
selectedSequence: index != null && index >= 0 && index < visits.length
|
||||
? visits[index].sequence
|
||||
: null,
|
||||
cupertino: widget.cupertino,
|
||||
onSelected: _openVisit,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,25 @@ import 'run_detail_content.dart';
|
||||
|
||||
/// The Timeline tab's recorded visits, one native row per visit.
|
||||
///
|
||||
/// [selectedSequence] is the server sequence of the visit selected from the
|
||||
/// Graph tab. Only an actual recorded visit can match, so an unvisited stage
|
||||
/// leaves every row unselected.
|
||||
/// [onSelected] receives the row's index in [visits], so the caller opens
|
||||
/// exactly the recorded step it was built from. [selectedSequence] highlights a
|
||||
/// row when a selection is applied while the list is rendered; the current
|
||||
/// flow replaces the rows with the pane, so it only matters for a defensive
|
||||
/// host that keeps both visible. Only an actual recorded visit can match, so an
|
||||
/// unvisited stage leaves every row unselected.
|
||||
class RunTimelineList extends StatelessWidget {
|
||||
const RunTimelineList({
|
||||
super.key,
|
||||
required this.visits,
|
||||
required this.cupertino,
|
||||
this.selectedSequence,
|
||||
this.onSelected,
|
||||
});
|
||||
|
||||
final List<DetailVisit> visits;
|
||||
final bool cupertino;
|
||||
final int? selectedSequence;
|
||||
final ValueChanged<int>? onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -38,6 +43,7 @@ class RunTimelineList extends StatelessWidget {
|
||||
visit: visits[index],
|
||||
selected: visits[index].sequence == selectedSequence,
|
||||
cupertino: cupertino,
|
||||
onTap: onSelected == null ? null : () => onSelected!(index),
|
||||
),
|
||||
];
|
||||
if (cupertino) {
|
||||
@@ -59,19 +65,22 @@ class RunTimelineList extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// One recorded visit. [selected] highlights the row the Graph tab selected;
|
||||
/// it is never true for a stage with no recorded visit.
|
||||
/// One recorded visit. [selected] marks the row an applied selection identifies;
|
||||
/// the current flow opens the pane instead of leaving a highlighted row. It is
|
||||
/// never true for a stage with no recorded visit.
|
||||
class RunTimelineRow extends StatelessWidget {
|
||||
const RunTimelineRow({
|
||||
super.key,
|
||||
required this.visit,
|
||||
required this.selected,
|
||||
required this.cupertino,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
final DetailVisit visit;
|
||||
final bool selected;
|
||||
final bool cupertino;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -93,6 +102,7 @@ class RunTimelineRow extends StatelessWidget {
|
||||
context,
|
||||
)
|
||||
: null,
|
||||
onTap: onTap,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -101,6 +111,7 @@ class RunTimelineRow extends StatelessWidget {
|
||||
leading: Icon(selected ? Icons.check_circle : Icons.circle_outlined),
|
||||
title: Text(visit.title),
|
||||
subtitle: Text(visit.subtitle),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/pipelines_client.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import 'run_detail_actions.dart';
|
||||
import 'run_detail_content.dart';
|
||||
@@ -45,6 +46,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
final run = widget.controller.detail;
|
||||
if (run == null) return _placeholder(context, cupertino: cupertino);
|
||||
final prompt = detailPrompt(run);
|
||||
final endpoint = configuredGatewayEndpoint(widget.gateway);
|
||||
final headerActions = RunDetailActions(
|
||||
run: run,
|
||||
gateway: widget.gateway,
|
||||
@@ -62,6 +64,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
copyStatus: _copyStatus,
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
|
||||
configuredEndpoint: endpoint,
|
||||
)
|
||||
: buildMaterialRunDetail(
|
||||
context: context,
|
||||
@@ -73,6 +76,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
copyStatus: _copyStatus,
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
|
||||
configuredEndpoint: endpoint,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
import 'run_detail_visit_sections.dart';
|
||||
|
||||
/// The selected recorded visit inside the Timeline tab.
|
||||
///
|
||||
/// It leads with the visit's own headline facts, then native tabbed sections.
|
||||
/// A fact the reply did not record is not drawn at all; a blank verdict or
|
||||
/// diagnostic is not rendered as an empty decision.
|
||||
class RunVisitPane extends StatefulWidget {
|
||||
const RunVisitPane({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.visit,
|
||||
required this.visitIndex,
|
||||
required this.step,
|
||||
required this.runSteps,
|
||||
required this.configuredEndpoint,
|
||||
required this.cupertino,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final DetailVisit visit;
|
||||
|
||||
/// The visit's index in [runSteps], so the artifacts section can open exactly
|
||||
/// this visit's gallery group.
|
||||
final int visitIndex;
|
||||
|
||||
final JsonMap step;
|
||||
final List<JsonMap> runSteps;
|
||||
final String configuredEndpoint;
|
||||
final bool cupertino;
|
||||
final VoidCallback onClose;
|
||||
|
||||
@override
|
||||
State<RunVisitPane> createState() => _RunVisitPaneState();
|
||||
}
|
||||
|
||||
class _RunVisitPaneState extends State<RunVisitPane> {
|
||||
RunVisitSection _section = RunVisitSection.input;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant RunVisitPane oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// A different visit starts at its first section, like a newly opened pane.
|
||||
if (oldWidget.visit.sequence != widget.visit.sequence ||
|
||||
oldWidget.visit.stage != widget.visit.stage) {
|
||||
_section = RunVisitSection.input;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = _VisitStyle.of(context);
|
||||
final facts = detailVisitFacts(widget.step);
|
||||
final verdict = detailVisitVerdict(widget.step);
|
||||
final diagnostic = detailVisitDiagnostic(widget.step);
|
||||
return Column(
|
||||
key: const Key('run-visit-pane'),
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 3,
|
||||
fit: FlexFit.loose,
|
||||
child: SingleChildScrollView(
|
||||
key: const Key('run-visit-facts'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_bar(style),
|
||||
for (final fact in facts) _FactRow(fact: fact, style: style),
|
||||
if (verdict != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text('Verdict', style: style.heading),
|
||||
if (verdict.option != null) Text(verdict.option!),
|
||||
if (verdict.reason != null)
|
||||
Text(verdict.reason!, style: style.value),
|
||||
],
|
||||
if (diagnostic != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text('Diagnostic', style: style.heading),
|
||||
Text(diagnostic, style: style.value),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
RunVisitSectionStrip(
|
||||
selected: _section,
|
||||
onSelected: (section) => setState(() => _section = section),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: runVisitSectionBody(
|
||||
section: _section,
|
||||
run: widget.run,
|
||||
step: widget.step,
|
||||
visitIndex: widget.visitIndex,
|
||||
stageKey: widget.visit.stage,
|
||||
runSteps: widget.runSteps,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
cupertino: widget.cupertino,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bar(_VisitStyle style) {
|
||||
final close = widget.cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('run-visit-back'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onClose,
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(CupertinoIcons.back),
|
||||
SizedBox(width: 4),
|
||||
Flexible(child: Text('Back to timeline')),
|
||||
],
|
||||
),
|
||||
)
|
||||
: TextButton.icon(
|
||||
key: const Key('run-visit-back'),
|
||||
onPressed: widget.onClose,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to timeline'),
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Align(alignment: AlignmentDirectional.centerStart, child: close),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.visit.title,
|
||||
key: const Key('run-visit-title'),
|
||||
style: style.heading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FactRow extends StatelessWidget {
|
||||
const _FactRow({required this.fact, required this.style});
|
||||
|
||||
final VisitFact fact;
|
||||
final _VisitStyle style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: '${fact.label}: ', style: style.muted),
|
||||
TextSpan(text: fact.value, style: style.value),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Host text roles only: no palette, font family or explicit size.
|
||||
class _VisitStyle {
|
||||
const _VisitStyle({
|
||||
required this.value,
|
||||
required this.muted,
|
||||
required this.heading,
|
||||
});
|
||||
|
||||
factory _VisitStyle.of(BuildContext context) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
return _VisitStyle(
|
||||
value: theme.textTheme.textStyle,
|
||||
muted: theme.textTheme.textStyle.copyWith(color: secondary),
|
||||
heading: theme.textTheme.navTitleTextStyle,
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return _VisitStyle(
|
||||
value: theme.textTheme.bodyMedium ?? const TextStyle(),
|
||||
muted: (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
heading: theme.textTheme.titleSmall ?? const TextStyle(),
|
||||
);
|
||||
}
|
||||
|
||||
final TextStyle value;
|
||||
final TextStyle muted;
|
||||
final TextStyle heading;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../artifacts/domain/artifact_groups.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
import '../../artifacts/domain/artifact_summary.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_action.dart';
|
||||
import '../../artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
/// The visit's recorded stage artifacts, in recorded order.
|
||||
///
|
||||
/// Selecting a row opens the existing artifact gallery page for exactly this
|
||||
/// visit, so the pane never grows a second viewer or a link-only substitute.
|
||||
/// The page receives the whole run so a shared `public/` file stays with the
|
||||
/// visit that first recorded it, and it lists exactly the rows shown here.
|
||||
///
|
||||
/// An empty list is never described as "nothing recorded" on its own: the
|
||||
/// existing capture semantics say whether the capture is unavailable, still
|
||||
/// pending or explicitly empty for this visit.
|
||||
class RunVisitArtifacts extends StatelessWidget {
|
||||
const RunVisitArtifacts({
|
||||
super.key,
|
||||
required this.step,
|
||||
required this.visitIndex,
|
||||
required this.runSteps,
|
||||
required this.configuredEndpoint,
|
||||
});
|
||||
|
||||
final JsonMap step;
|
||||
|
||||
/// The visit's index in [runSteps], so the opened page is the same group.
|
||||
final int visitIndex;
|
||||
|
||||
final List<JsonMap> runSteps;
|
||||
final String configuredEndpoint;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final artifacts = visitArtifacts(step, runSteps);
|
||||
final notes = artifactCaptureNotes(step);
|
||||
if (artifacts.isEmpty) {
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-artifacts'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Text(artifactsSummary(step, count: 0)),
|
||||
for (final note in notes)
|
||||
Padding(padding: const EdgeInsets.only(top: 4), child: Text(note)),
|
||||
],
|
||||
);
|
||||
}
|
||||
void open() => showArtifactGallery(
|
||||
context,
|
||||
steps: runSteps.isEmpty ? <JsonMap>[step] : runSteps,
|
||||
focusIndex: runSteps.isEmpty ? 0 : visitIndex,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
);
|
||||
final noteRows = [
|
||||
for (final note in notes)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Text(note),
|
||||
),
|
||||
];
|
||||
if (usesCupertinoHost(context)) {
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-artifacts'),
|
||||
children: [
|
||||
...noteRows,
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
for (final artifact in artifacts)
|
||||
_CupertinoArtifactRow(artifact: artifact, onTap: open),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-artifacts'),
|
||||
children: [
|
||||
...noteRows,
|
||||
for (final artifact in artifacts)
|
||||
ListTile(
|
||||
title: Text(artifactDisplayName(artifact)),
|
||||
subtitle: Text(artifactFactsLabel(artifact)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: open,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CupertinoArtifactRow extends StatelessWidget {
|
||||
const _CupertinoArtifactRow({required this.artifact, required this.onTap});
|
||||
|
||||
final ArtifactRecord artifact;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoListTile(
|
||||
title: Text(artifactDisplayName(artifact)),
|
||||
subtitle: Text(artifactFactsLabel(artifact)),
|
||||
trailing: const Icon(CupertinoIcons.chevron_forward),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../graph/widgets/stage_definition_view.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
|
||||
/// The Definition section: the authored definition this run pinned for the
|
||||
/// visit's stage, rendered by the landed [StageDefinitionView].
|
||||
///
|
||||
/// When the reply's graph does not declare the stage, the pane's exact missing
|
||||
/// sentence is shown instead. Nothing is reconstructed from the current source.
|
||||
class RunVisitDefinition extends StatelessWidget {
|
||||
const RunVisitDefinition({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.stageKey,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final String stageKey;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final graph = detailGraph(run);
|
||||
if (!detailVisitHasDefinition(graph, stageKey)) {
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-definition'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: const [Text(unknownStageDefinition)],
|
||||
);
|
||||
}
|
||||
final pipelineId = run['pipeline_id'];
|
||||
final version = run['version'];
|
||||
return KeyedSubtree(
|
||||
key: const Key('run-visit-body-definition'),
|
||||
child: StageDefinitionView(
|
||||
graph: graph!,
|
||||
stageKey: stageKey,
|
||||
pipelineId: pipelineId is num ? pipelineId.toInt() : 0,
|
||||
pipelineName: detailPipeline(run),
|
||||
version: version is num ? version.toInt() : 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../graph/domain/stage_definition.dart';
|
||||
import '../../pipelines/pipeline_format.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The exact empty wording for a visit's recorded Input and Output. They are
|
||||
/// the run tabs' own sentences, so a visit never says something different for
|
||||
/// the same absent fact.
|
||||
const String visitEmptyInput = 'No input recorded.';
|
||||
const String visitEmptyOutput = 'No output recorded.';
|
||||
|
||||
/// One always-visible fact of a recorded visit.
|
||||
typedef VisitFact = ({String label, String value});
|
||||
|
||||
/// The detail's own recorded steps as maps, in recorded order.
|
||||
List<JsonMap> detailRunSteps(JsonMap run) {
|
||||
final steps = run['steps'];
|
||||
if (steps is! List) return const <JsonMap>[];
|
||||
return steps.whereType<Map>().map(JsonMap.from).toList();
|
||||
}
|
||||
|
||||
/// The raw step at [index] of the detail's own `steps`, or null when the reply
|
||||
/// has no such recorded visit.
|
||||
///
|
||||
/// The order is the server's recorded order, the same order [detailTimeline]
|
||||
/// uses, so a row and its pane always describe one visit.
|
||||
JsonMap? detailVisitStepAt(JsonMap run, int index) {
|
||||
final steps = detailRunSteps(run);
|
||||
if (index < 0 || index >= steps.length) return null;
|
||||
return steps[index];
|
||||
}
|
||||
|
||||
/// The row index of [stageKey]'s latest recorded visit, or null when the run
|
||||
/// never recorded that stage. It reads the same ordered timeline the rows do,
|
||||
/// so a Graph click opens exactly the row the operator would have selected.
|
||||
int? latestDetailVisitIndex(dynamic steps, String stageKey) {
|
||||
final visits = detailTimeline(steps);
|
||||
int? latest;
|
||||
for (var index = 0; index < visits.length; index += 1) {
|
||||
if (visits[index].stage == stageKey) latest = index;
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
/// The visit's recorded facts, in the pane's order. A field the server did not
|
||||
/// record is absent rather than zero, false or a guessed value.
|
||||
List<VisitFact> detailVisitFacts(JsonMap step) {
|
||||
final facts = <VisitFact>[];
|
||||
final status = _text(step['status']);
|
||||
if (status != null) facts.add((label: 'Status', value: status));
|
||||
final outcome = _text(step['outcome']);
|
||||
if (outcome != null) facts.add((label: 'Outcome', value: outcome));
|
||||
final duration = detailVisitDuration(step);
|
||||
if (duration != null) facts.add((label: 'Duration', value: duration));
|
||||
final model = detailVisitProviderModel(step);
|
||||
if (model != null) facts.add((label: 'Provider/model', value: model));
|
||||
final target = _text(step['target']);
|
||||
if (target != null) facts.add((label: 'Target', value: target));
|
||||
return facts;
|
||||
}
|
||||
|
||||
/// The visit's duration, only when the server recorded both timestamps and the
|
||||
/// finish is not before the start. One stamp is not a zero-length visit.
|
||||
String? detailVisitDuration(JsonMap step) {
|
||||
final seconds = durationSeconds(
|
||||
_text(step['started_at']),
|
||||
_text(step['finished_at']),
|
||||
);
|
||||
return seconds == null ? null : formatDuration(seconds);
|
||||
}
|
||||
|
||||
/// The effective provider/model this visit ran with, joined as
|
||||
/// `provider / model` when both were recorded. A visit that recorded neither
|
||||
/// has no row; one recorded part is shown alone, never completed locally.
|
||||
String? detailVisitProviderModel(JsonMap step) {
|
||||
final provider = _text(step['provider']);
|
||||
final model = _text(step['model']);
|
||||
if (provider != null && model != null) return '$provider / $model';
|
||||
return provider ?? model;
|
||||
}
|
||||
|
||||
/// A recorded verdict, or null when the server recorded no option and no
|
||||
/// reason. An empty recorded verdict is not rendered as a decision.
|
||||
({String? option, String? reason})? detailVisitVerdict(JsonMap step) {
|
||||
final verdict = step['verdict'];
|
||||
if (verdict is! Map) return null;
|
||||
final option = _text(verdict['option']);
|
||||
final reason = _text(verdict['reason']);
|
||||
if (option == null && reason == null) return null;
|
||||
return (option: option, reason: reason);
|
||||
}
|
||||
|
||||
/// The visit's diagnostic exactly as recorded, or null when it is blank.
|
||||
String? detailVisitDiagnostic(JsonMap step) => _text(step['diagnostic']);
|
||||
|
||||
/// Whether the reply's pinned graph declares [stageKey], so the Definition
|
||||
/// section shows the authored definition rather than its missing wording.
|
||||
bool detailVisitHasDefinition(JsonMap? graph, String stageKey) =>
|
||||
graph != null && stageDefinitionFor(graph, stageKey) != null;
|
||||
|
||||
String? _text(dynamic value) {
|
||||
if (value == null) return null;
|
||||
final text = '$value'.trim();
|
||||
return text.isEmpty ? null : text;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import 'run_detail_tab_bodies.dart';
|
||||
import 'run_detail_tab_strip.dart';
|
||||
import 'run_detail_visit_artifacts.dart';
|
||||
import 'run_detail_visit_definition.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
import 'run_detail_visit_session.dart';
|
||||
|
||||
/// The visit pane's recorded sections, in the Android audit order the web
|
||||
/// client follows: the turn's Input and Output, its Artifacts, its Session and
|
||||
/// the authored Definition.
|
||||
enum RunVisitSection {
|
||||
input('Input'),
|
||||
output('Output'),
|
||||
artifacts('Artifacts'),
|
||||
session('Session'),
|
||||
definition('Definition');
|
||||
|
||||
const RunVisitSection(this.label);
|
||||
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// The visit pane's native tab strip: a Material segmented button or a Cupertino
|
||||
/// segmented control. It scrolls instead of squeezing the labels when a narrow
|
||||
/// pane or scaled text cannot fit them.
|
||||
class RunVisitSectionStrip extends StatelessWidget {
|
||||
const RunVisitSectionStrip({
|
||||
super.key,
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final RunVisitSection selected;
|
||||
final ValueChanged<RunVisitSection> onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: ScrollWhenOverflowing(
|
||||
child: KeyedSubtree(
|
||||
key: const Key('run-visit-tabs'),
|
||||
child: cupertino ? _cupertinoControl() : _materialControl(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialControl() => SegmentedButton<RunVisitSection>(
|
||||
segments: [
|
||||
for (final section in RunVisitSection.values)
|
||||
ButtonSegment(value: section, label: _label(section)),
|
||||
],
|
||||
selected: {selected},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: (selection) => onSelected(selection.single),
|
||||
);
|
||||
|
||||
Widget _cupertinoControl() => CupertinoSegmentedControl<RunVisitSection>(
|
||||
groupValue: selected,
|
||||
onValueChanged: onSelected,
|
||||
children: {
|
||||
for (final section in RunVisitSection.values)
|
||||
section: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: _label(section),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
Widget _label(RunVisitSection section) => KeyedSubtree(
|
||||
key: ValueKey('run-visit-tab-${section.name}'),
|
||||
child: Text(section.label, maxLines: 1, softWrap: false),
|
||||
);
|
||||
}
|
||||
|
||||
/// The selected section's body for one recorded visit.
|
||||
Widget runVisitSectionBody({
|
||||
required RunVisitSection section,
|
||||
required JsonMap run,
|
||||
required JsonMap step,
|
||||
required int visitIndex,
|
||||
required String stageKey,
|
||||
required List<JsonMap> runSteps,
|
||||
required String configuredEndpoint,
|
||||
required bool cupertino,
|
||||
}) {
|
||||
switch (section) {
|
||||
case RunVisitSection.input:
|
||||
return runDetailFieldTab(
|
||||
tabKey: 'visit-input',
|
||||
value: step['input'],
|
||||
empty: visitEmptyInput,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
case RunVisitSection.output:
|
||||
return runDetailFieldTab(
|
||||
tabKey: 'visit-output',
|
||||
value: step['output'],
|
||||
empty: visitEmptyOutput,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
case RunVisitSection.artifacts:
|
||||
return RunVisitArtifacts(
|
||||
step: step,
|
||||
visitIndex: visitIndex,
|
||||
runSteps: runSteps,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
);
|
||||
case RunVisitSection.session:
|
||||
return RunVisitSession(
|
||||
step: step,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
);
|
||||
case RunVisitSection.definition:
|
||||
return RunVisitDefinition(run: run, stageKey: stageKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
import '../../artifacts/domain/artifact_url.dart';
|
||||
import '../../artifacts/ui/artifact_external_open.dart';
|
||||
import 'run_detail_visit_session_state.dart';
|
||||
|
||||
/// The visit's recorded session pointer and, when the visit exported one, a
|
||||
/// read-only external open of that document.
|
||||
///
|
||||
/// The state comes from [detailVisitSession], so a legacy `session.html`, a
|
||||
/// repair, a still-running session and a failed one each report what the server
|
||||
/// recorded. The open goes through the landed safe-link helper: the recorded url
|
||||
/// is resolved by [resolveArtifactUrl] and passed to [openArtifactExternally]
|
||||
/// without being fetched, rewritten or previewed. A refusal is reported.
|
||||
class RunVisitSession extends StatefulWidget {
|
||||
const RunVisitSession({
|
||||
super.key,
|
||||
required this.step,
|
||||
required this.configuredEndpoint,
|
||||
this.openExternal = openArtifactExternally,
|
||||
});
|
||||
|
||||
final JsonMap step;
|
||||
final String configuredEndpoint;
|
||||
final ArtifactExternalOpen openExternal;
|
||||
|
||||
@override
|
||||
State<RunVisitSession> createState() => _RunVisitSessionState();
|
||||
}
|
||||
|
||||
class _RunVisitSessionState extends State<RunVisitSession> {
|
||||
String? _status;
|
||||
|
||||
Future<void> _open(ResolvedArtifactUrl resolved) async {
|
||||
final opened = await widget.openExternal(resolved.uri);
|
||||
if (!mounted) return;
|
||||
setState(
|
||||
() => _status = opened
|
||||
? 'Link opened externally.'
|
||||
: 'Could not open the link.',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final session = detailVisitSession(widget.step);
|
||||
final export = session.export;
|
||||
final resolved = export == null
|
||||
? null
|
||||
: resolveArtifactUrl(widget.configuredEndpoint, export.artifact.url);
|
||||
final note = export?.statusNote;
|
||||
final children = <Widget>[
|
||||
if (session.sessionId != null)
|
||||
_SessionFact(label: 'Session', value: session.sessionId!),
|
||||
if (export != null) ...[
|
||||
if (note != null) Text(note),
|
||||
if (resolved == null)
|
||||
const Text(visitSessionEndpointMissing)
|
||||
else
|
||||
_openButton(export.artifact, resolved),
|
||||
] else
|
||||
Text(session.message),
|
||||
if (_status != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Semantics(liveRegion: true, child: Text(_status!)),
|
||||
),
|
||||
];
|
||||
if (usesCupertinoHost(context)) {
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-session'),
|
||||
children: [
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _spaced(children),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return ListView(
|
||||
key: const Key('run-visit-body-session'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: _spaced(children),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _openButton(ArtifactRecord export, ResolvedArtifactUrl resolved) {
|
||||
final label = 'Open ${export.name.isEmpty ? 'session.html' : export.name}';
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => _open(resolved),
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
return Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: TextButton(onPressed: () => _open(resolved), child: Text(label)),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _spaced(List<Widget> children) => [
|
||||
for (var index = 0; index < children.length; index += 1) ...[
|
||||
if (index > 0) const SizedBox(height: 8),
|
||||
children[index],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
class _SessionFact extends StatelessWidget {
|
||||
const _SessionFact({required this.label, required this.value});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final cupertino = CupertinoTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: usesCupertinoHost(context)
|
||||
? cupertino.textTheme.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
)
|
||||
: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(value),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
import '../../artifacts/domain/artifact_selection.dart';
|
||||
|
||||
/// The exact wording for a visit that never started a harness session, in the
|
||||
/// web audit pane's order: a skipped visit, a stopped one, a model visit whose
|
||||
/// session is still being created, a failed one, and a model visit with no
|
||||
/// identity at all. Only a non-model visit with nothing recorded gets the
|
||||
/// generic sentence.
|
||||
const String visitSessionSkipped =
|
||||
'This visit was skipped; no harness session was started.';
|
||||
const String visitSessionStopped =
|
||||
'The stage stopped before a harness session was recorded.';
|
||||
const String visitSessionStarting = 'The stage session is being created.';
|
||||
const String visitSessionFailed = 'The stage did not create a harness session.';
|
||||
const String visitSessionNoIdentity =
|
||||
'Runtime error: this model stage has no recorded session identity.';
|
||||
const String visitSessionNone = 'This visit has no harness session.';
|
||||
|
||||
/// An export that exists but cannot be resolved through the configured server.
|
||||
const String visitSessionEndpointMissing =
|
||||
'Set the server URL in Settings to open the session.';
|
||||
|
||||
/// A recorded session export document and the evidence the server recorded for
|
||||
/// it.
|
||||
class VisitSessionExport {
|
||||
const VisitSessionExport({
|
||||
required this.artifact,
|
||||
this.status,
|
||||
this.diagnostic,
|
||||
this.truncated = false,
|
||||
});
|
||||
|
||||
final ArtifactRecord artifact;
|
||||
final String? status;
|
||||
final String? diagnostic;
|
||||
final bool truncated;
|
||||
|
||||
/// A partial or failed export is still the recorded document; it stays
|
||||
/// openable and the pane says what the evidence reports.
|
||||
bool get isComplete => status == 'complete' && !truncated;
|
||||
|
||||
/// The evidence sentence shown beside a present but incomplete export, or
|
||||
/// null when the export is complete or the visit recorded no evidence.
|
||||
String? get statusNote {
|
||||
if (isComplete) return null;
|
||||
if (status == null && !truncated) return null;
|
||||
return 'This export is ${status ?? 'partial'}; full session evidence is '
|
||||
'not available.';
|
||||
}
|
||||
}
|
||||
|
||||
/// A visit's recorded session: its identity, an openable export document and,
|
||||
/// when neither exists, the one sentence describing the recorded state.
|
||||
class VisitSessionState {
|
||||
const VisitSessionState({this.sessionId, this.export, this.message = ''});
|
||||
|
||||
final String? sessionId;
|
||||
final VisitSessionExport? export;
|
||||
|
||||
/// Empty exactly when [export] is present.
|
||||
final String message;
|
||||
}
|
||||
|
||||
/// Resolves the recorded session state without inventing a session.
|
||||
///
|
||||
/// The export is looked up through the recorded export evidence (including a
|
||||
/// repair that replaced it) and then, for a historical visit that recorded no
|
||||
/// evidence at all, through the `session.html` its inventory carries. When the
|
||||
/// evidence names no file, its own status and diagnostic are reported instead
|
||||
/// of claiming the inventory is empty.
|
||||
VisitSessionState detailVisitSession(JsonMap step) {
|
||||
final sessionId = detailVisitSessionIdentity(step);
|
||||
final export = detailVisitSessionExport(step);
|
||||
if (export != null) {
|
||||
return VisitSessionState(sessionId: sessionId, export: export);
|
||||
}
|
||||
if (sessionId != null) {
|
||||
return VisitSessionState(
|
||||
sessionId: sessionId,
|
||||
message: _missingExportMessage(step, sessionId),
|
||||
);
|
||||
}
|
||||
return VisitSessionState(message: _noSessionMessage(step));
|
||||
}
|
||||
|
||||
/// The recorded harness session identity, from the step or its export evidence.
|
||||
String? detailVisitSessionIdentity(JsonMap step) {
|
||||
final direct = _text(step['session_id']);
|
||||
if (direct != null) return direct;
|
||||
final evidence = _firstEvidence(step);
|
||||
return evidence == null ? null : _text(evidence['session_id']);
|
||||
}
|
||||
|
||||
/// The visit's recorded export document, or null when no recorded export name
|
||||
/// is present in the inventory.
|
||||
///
|
||||
/// The step's own `session_export` is preferred; a repair document is used
|
||||
/// when that is the file the inventory actually carries. A visit with no export
|
||||
/// evidence at all falls back to its `session.html` system artifact, exactly as
|
||||
/// the web audit pane does for runs recorded before the evidence field existed.
|
||||
VisitSessionExport? detailVisitSessionExport(JsonMap step) {
|
||||
final evidence = _exportEvidence(step);
|
||||
for (final entry in evidence) {
|
||||
final artifact = _artifactNamed(step, _text(entry['html']));
|
||||
if (artifact == null) continue;
|
||||
return VisitSessionExport(
|
||||
artifact: artifact,
|
||||
status: _text(entry['status']),
|
||||
diagnostic: _text(entry['diagnostic']),
|
||||
truncated: entry['truncated'] == true,
|
||||
);
|
||||
}
|
||||
if (evidence.isNotEmpty) return null;
|
||||
for (final artifact in systemArtifacts(step)) {
|
||||
if (artifact.name == 'session.html') {
|
||||
return VisitSessionExport(artifact: artifact);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _missingExportMessage(JsonMap step, String sessionId) {
|
||||
final evidence = _firstEvidence(step);
|
||||
final recovery = step['session_export_recovery'];
|
||||
final recoveryStatus = recovery is Map ? _text(recovery['status']) : null;
|
||||
final evidenceStatus = evidence == null ? null : _text(evidence['status']);
|
||||
final String status;
|
||||
if (recoveryStatus == 'pending' || recoveryStatus == 'running') {
|
||||
status = 'pending recovery';
|
||||
} else if (evidenceStatus == 'complete') {
|
||||
status = 'not available in the artifact inventory';
|
||||
} else {
|
||||
status = evidenceStatus ?? 'not yet available';
|
||||
}
|
||||
final diagnostic = evidence == null ? null : _text(evidence['diagnostic']);
|
||||
final suffix = diagnostic == null ? '' : ' $diagnostic';
|
||||
return 'Session $sessionId is recorded. Its export is $status.$suffix';
|
||||
}
|
||||
|
||||
String _noSessionMessage(JsonMap step) {
|
||||
final status = _text(step['status']);
|
||||
if (status == 'skipped' || _text(step['outcome']) == 'skipped') {
|
||||
return visitSessionSkipped;
|
||||
}
|
||||
if (status == 'canceled' || status == 'interrupted') {
|
||||
return visitSessionStopped;
|
||||
}
|
||||
final model = _text(step['provider']) != null || _text(step['model']) != null;
|
||||
if (!model) return visitSessionNone;
|
||||
if (status == 'running') return visitSessionStarting;
|
||||
if (status == 'failed') {
|
||||
final diagnostic = _text(step['diagnostic']);
|
||||
return diagnostic == null
|
||||
? visitSessionFailed
|
||||
: '$visitSessionFailed $diagnostic';
|
||||
}
|
||||
return visitSessionNoIdentity;
|
||||
}
|
||||
|
||||
/// The recorded export evidence, most current first: a complete repair, then a
|
||||
/// complete original, then every remaining candidate. A failed later attempt
|
||||
/// never hides an earlier verified document; an older original never hides the
|
||||
/// repair that replaced it.
|
||||
List<Map> _exportEvidence(JsonMap step) {
|
||||
final repairs = <Map>[];
|
||||
final recordedRepairs = step['session_export_repairs'];
|
||||
if (recordedRepairs is List) {
|
||||
for (final entry in recordedRepairs.reversed) {
|
||||
if (entry is Map) repairs.add(entry);
|
||||
}
|
||||
}
|
||||
final original = step['session_export'];
|
||||
final ordered = <Map>[];
|
||||
void add(Map entry) {
|
||||
for (final candidate in ordered) {
|
||||
if (identical(candidate, entry)) return;
|
||||
}
|
||||
ordered.add(entry);
|
||||
}
|
||||
|
||||
for (final repair in repairs) {
|
||||
if (_isComplete(repair)) add(repair);
|
||||
}
|
||||
if (original is Map && _isComplete(original)) add(original);
|
||||
for (final repair in repairs) {
|
||||
add(repair);
|
||||
}
|
||||
if (original is Map) add(original);
|
||||
return ordered;
|
||||
}
|
||||
|
||||
Map? _firstEvidence(JsonMap step) {
|
||||
final original = step['session_export'];
|
||||
if (original is Map) return original;
|
||||
final repairs = step['session_export_repairs'];
|
||||
if (repairs is List) {
|
||||
for (final entry in repairs.reversed) {
|
||||
if (entry is Map) return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool _isComplete(Map evidence) =>
|
||||
_text(evidence['status']) == 'complete' &&
|
||||
_positive(evidence['messages']) &&
|
||||
_positive(evidence['html_bytes']) &&
|
||||
evidence['truncated'] != true &&
|
||||
_text(evidence['diagnostic']) == null;
|
||||
|
||||
bool _positive(dynamic value) {
|
||||
if (value is num) return value > 0;
|
||||
if (value is String) return (int.tryParse(value.trim()) ?? 0) > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
ArtifactRecord? _artifactNamed(JsonMap step, String? name) {
|
||||
if (name == null) return null;
|
||||
for (final artifact in artifactsOf(step)) {
|
||||
if (artifact.name == name) return artifact;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _text(dynamic value) {
|
||||
if (value == null) return null;
|
||||
final text = '$value'.trim();
|
||||
return text.isEmpty ? null : text;
|
||||
}
|
||||
Reference in New Issue
Block a user