5425001d82
One picker offers a new chat (the saved Open in chat harness and model) or any open chat. An existing chat gets the reference appended to its draft and focused, never sent. Artifacts gain the action in their viewer and gallery; the run and pipeline item becomes Send to chat.
223 lines
7.8 KiB
Dart
223 lines
7.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../artifacts/domain/artifact_record.dart';
|
|
import '../../artifacts/domain/artifact_url.dart';
|
|
import '../../artifacts/ui/artifact_external_open.dart';
|
|
import '../actions/session_export_repair_action.dart';
|
|
import 'run_detail_visit_recorded.dart';
|
|
import 'run_detail_visit_documents.dart';
|
|
import 'run_detail_visit_session_state.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
|
|
/// The visit's recorded session pointer, its recorded export state 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. Complete, partial, missing, skipped, repair and unrecognised
|
|
/// states each keep the server's own word and diagnostic; recorded repair
|
|
/// attempts and their open-option labels stay read-only. An export whose
|
|
/// recorded evidence is incomplete or truncated offers the web client's
|
|
/// export-only repair, which sends that exact visit's recorded sequence and
|
|
/// keeps this recorded state until the server replies; a legacy `session.html`
|
|
/// with no recorded evidence offers no control, exactly as the web does. 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.run,
|
|
required this.step,
|
|
required this.gateway,
|
|
required this.onRunChanged,
|
|
required this.configuredEndpoint,
|
|
this.onSendToChat,
|
|
this.openExternal = openArtifactExternally,
|
|
});
|
|
|
|
final JsonMap run;
|
|
final JsonMap step;
|
|
final ApiGateway gateway;
|
|
final ValueChanged<JsonMap> onRunChanged;
|
|
final String configuredEndpoint;
|
|
final ArtifactExternalOpen openExternal;
|
|
final void Function(String draft)? onSendToChat;
|
|
|
|
@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 fact = session.exportFact;
|
|
final sequence = recordedCount(widget.step['sequence']);
|
|
final repair = _repairAction(session, sequence);
|
|
final showReason =
|
|
export != null &&
|
|
fact?.reason != null &&
|
|
fact!.state != VisitSessionExportState.repair;
|
|
final children = <Widget>[
|
|
if (session.sessionId != null)
|
|
_SessionFact(label: 'Session', value: session.sessionId!),
|
|
if (fact != null)
|
|
_SessionFact(
|
|
key: const Key('run-visit-session-export'),
|
|
label: 'Export',
|
|
value: fact.word,
|
|
),
|
|
if (showReason)
|
|
_SessionFact(
|
|
key: const Key('run-visit-session-export-reason'),
|
|
label: 'Reason',
|
|
value: fact.reason!,
|
|
),
|
|
if (export != null && note != null) Text(note),
|
|
..._repairFacts(session.repairs),
|
|
if (export == null)
|
|
Text(session.message)
|
|
else if (resolved == null)
|
|
const Text(visitSessionEndpointMissing)
|
|
else
|
|
_openButton(export.artifact, resolved),
|
|
?repair,
|
|
if (_status != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Semantics(liveRegion: true, child: Text(_status!)),
|
|
),
|
|
RunVisitDocuments(
|
|
step: widget.step,
|
|
run: widget.run,
|
|
configuredEndpoint: widget.configuredEndpoint,
|
|
onSendToChat: widget.onSendToChat,
|
|
),
|
|
];
|
|
// Flat on the page on both hosts; the turn documents below are a flat
|
|
// titled list too, so nothing is a group nested in a group.
|
|
return ListView(
|
|
key: const Key('run-visit-body-session'),
|
|
padding: withBarClearance(context, const EdgeInsets.all(16)),
|
|
children: _spaced(children),
|
|
);
|
|
}
|
|
|
|
Widget _openButton(ArtifactRecord export, ResolvedArtifactUrl resolved) {
|
|
final label = 'Open ${export.name.isEmpty ? 'session.html' : export.name}';
|
|
return Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(onPressed: () => _open(resolved), child: Text(label)),
|
|
);
|
|
}
|
|
|
|
/// The export-only repair option: offered only for a visit whose recorded
|
|
/// session identity and sequence can be read again, and whose recorded export
|
|
/// evidence is incomplete or truncated (or which has no openable document at
|
|
/// all). A legacy `session.html` chosen only by the no-evidence fallback has
|
|
/// no evidence to repair and keeps the web's absence of the control. The
|
|
/// visit's own recorded sequence is sent, never a guessed one.
|
|
Widget? _repairAction(VisitSessionState session, int sequence) {
|
|
final runId = recordedCount(widget.run['id']);
|
|
if (runId < 1 || sequence < 1) return null;
|
|
if (detailVisitRepairIdentity(widget.step) == null) return null;
|
|
final export = session.export;
|
|
if (export != null && !visitSessionExportNeedsRepair(export)) return null;
|
|
final status = recordedText(widget.step['status']);
|
|
final runStatus = recordedText(widget.run['status']);
|
|
final pending = recordedCount(widget.run['export_pending_sequence']);
|
|
final running =
|
|
widget.step['agent_active'] == true ||
|
|
status == 'running' ||
|
|
status == 'queued' ||
|
|
runStatus == 'running' ||
|
|
runStatus == 'queued' ||
|
|
(runStatus == 'waiting' && pending != sequence);
|
|
return SessionExportRepairAction(
|
|
runId: runId,
|
|
sequence: sequence,
|
|
gateway: widget.gateway,
|
|
running: running,
|
|
onRepaired: widget.onRunChanged,
|
|
);
|
|
}
|
|
|
|
/// Recorded repair attempts, in the pane's own fact rows. These labels stay
|
|
/// read-only; the request is made only by [SessionExportRepairAction].
|
|
List<Widget> _repairFacts(List<VisitSessionRepair> repairs) {
|
|
final facts = <Widget>[];
|
|
for (var index = 0; index < repairs.length; index += 1) {
|
|
final repair = repairs[index];
|
|
facts.add(
|
|
_SessionFact(
|
|
key: ValueKey('run-visit-session-repair-$index'),
|
|
label: 'Repair',
|
|
value: repair.label,
|
|
),
|
|
);
|
|
final option = repair.option;
|
|
if (option != null) {
|
|
facts.add(
|
|
_SessionFact(
|
|
key: ValueKey('run-visit-session-repair-option-$index'),
|
|
label: 'Repair option',
|
|
value: option,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
return facts;
|
|
}
|
|
|
|
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({super.key, required this.label, required this.value});
|
|
|
|
final String label;
|
|
final String value;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(value),
|
|
],
|
|
);
|
|
}
|
|
}
|