3da570e647
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.
227 lines
6.6 KiB
Dart
227 lines
6.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
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, 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,
|
|
required bool cupertino,
|
|
required bool copying,
|
|
required String? copyStatus,
|
|
required VoidCallback onCopy,
|
|
}) {
|
|
final prompt = detailPrompt(run);
|
|
final facts = detailSummaryFields(run);
|
|
final metrics = detailUsageMetrics(run['usage']);
|
|
if (cupertino) {
|
|
final theme = CupertinoTheme.of(context);
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-summary'),
|
|
children: [
|
|
if (prompt != null)
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Wrap(
|
|
alignment: WrapAlignment.spaceBetween,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
children: [
|
|
Text(
|
|
'Original prompt',
|
|
style: theme.textTheme.navTitleTextStyle,
|
|
),
|
|
CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: copying ? null : onCopy,
|
|
child: const Text('Copy prompt'),
|
|
),
|
|
],
|
|
),
|
|
_CupertinoSelectableText(prompt),
|
|
if (copyStatus != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
_cupertinoMetrics(metrics),
|
|
_cupertinoFacts(facts),
|
|
],
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-summary'),
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
if (prompt != null) ...[
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'Original prompt',
|
|
style: theme.textTheme.titleMedium,
|
|
),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Copy prompt',
|
|
onPressed: copying ? null : onCopy,
|
|
icon: const Icon(Icons.copy),
|
|
),
|
|
],
|
|
),
|
|
SelectableText(prompt),
|
|
if (copyStatus != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
_materialMetrics(metrics),
|
|
_materialFacts(facts),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// One recorded Input or Output field as its own tab.
|
|
Widget runDetailFieldTab({
|
|
required String tabKey,
|
|
required dynamic value,
|
|
required String empty,
|
|
required bool cupertino,
|
|
}) {
|
|
final text = detailEmpty(value) ? empty : detailJson(value);
|
|
if (cupertino) {
|
|
return ListView(
|
|
key: Key('run-detail-tab-body-$tabKey'),
|
|
children: [
|
|
CupertinoListSection.insetGrouped(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
child: _CupertinoSelectableText(text),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return ListView(
|
|
key: Key('run-detail-tab-body-$tabKey'),
|
|
padding: const EdgeInsets.all(16),
|
|
children: [SelectableText(text)],
|
|
);
|
|
}
|
|
|
|
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: [
|
|
if (metrics.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: Text('No reported usage.'),
|
|
)
|
|
else
|
|
...metrics.map(
|
|
(metric) =>
|
|
ListTile(title: Text(metric.label), subtitle: Text(metric.value)),
|
|
),
|
|
],
|
|
);
|
|
|
|
Widget _cupertinoMetrics(List<DetailMetric> metrics) =>
|
|
CupertinoListSection.insetGrouped(
|
|
children: [
|
|
CupertinoExpansionTile(
|
|
title: const Text('Metrics'),
|
|
child: Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (metrics.isEmpty)
|
|
const Text('No reported usage.')
|
|
else
|
|
for (final metric in metrics)
|
|
CupertinoListTile(
|
|
title: Text(metric.label),
|
|
subtitle: Text(metric.value),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
|
|
/// A read-only Cupertino text control: plain, selectable text without a
|
|
/// Material dependency, while keeping native selection and copy affordances.
|
|
class _CupertinoSelectableText extends StatefulWidget {
|
|
const _CupertinoSelectableText(this.text);
|
|
final String text;
|
|
|
|
@override
|
|
State<_CupertinoSelectableText> createState() =>
|
|
_CupertinoSelectableTextState();
|
|
}
|
|
|
|
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
|
|
late final TextEditingController _controller = TextEditingController(
|
|
text: widget.text,
|
|
);
|
|
|
|
@override
|
|
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.text != oldWidget.text) _controller.text = widget.text;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => CupertinoTextField(
|
|
controller: _controller,
|
|
readOnly: true,
|
|
maxLines: null,
|
|
padding: EdgeInsets.zero,
|
|
decoration: const BoxDecoration(),
|
|
style: CupertinoTheme.of(context).textTheme.textStyle,
|
|
);
|
|
}
|