feat(app): run Input and Output read as named fields, not JSON; the separate Original prompt block is gone
This commit is contained in:
@@ -5,6 +5,7 @@ import '../../../core/api_gateway.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_summary_fields.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
import 'run_field_body.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
|
||||
/// The Summary tab: the run's identity, the recorded facts as key/value rows,
|
||||
@@ -27,7 +28,7 @@ Widget runDetailSummaryTab({
|
||||
}) {
|
||||
final rows = detailSummaryRows(run);
|
||||
final identity = detailSummaryIdentity(run);
|
||||
final prompt = detailPrompt(run);
|
||||
// No separate "Original prompt": the run's Input carries it, as data.
|
||||
if (cupertino) {
|
||||
return ListView(
|
||||
key: const Key('run-detail-tab-body-summary'),
|
||||
@@ -44,14 +45,6 @@ Widget runDetailSummaryTab({
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [_cupertinoBlock(context, row)],
|
||||
),
|
||||
if (prompt != null)
|
||||
_cupertinoPrompt(
|
||||
context,
|
||||
prompt: prompt,
|
||||
copying: copying,
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
),
|
||||
_cupertinoFieldSection(
|
||||
context,
|
||||
key: 'run-detail-summary-input',
|
||||
@@ -87,14 +80,6 @@ Widget runDetailSummaryTab({
|
||||
),
|
||||
for (final row in rows)
|
||||
row.block ? _materialBlock(context, row) : _materialRow(context, row),
|
||||
if (prompt != null)
|
||||
_materialPrompt(
|
||||
context,
|
||||
prompt: prompt,
|
||||
copying: copying,
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
),
|
||||
_materialFieldSection(
|
||||
context,
|
||||
key: 'run-detail-summary-input',
|
||||
@@ -215,50 +200,7 @@ Widget _materialFieldSection(
|
||||
title: Text(title),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.start,
|
||||
childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||
children: [SelectableText(detailEmpty(value) ? empty : detailJson(value))],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialPrompt(
|
||||
BuildContext context, {
|
||||
required String prompt,
|
||||
required bool copying,
|
||||
required String? copyStatus,
|
||||
required VoidCallback onCopy,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
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)),
|
||||
),
|
||||
],
|
||||
),
|
||||
children: [RunFieldBody(value: value, empty: empty, cupertino: false)],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -343,8 +285,11 @@ Widget _cupertinoFieldSection(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: _CupertinoSelectableText(
|
||||
detailEmpty(value) ? empty : detailJson(value),
|
||||
child: RunFieldBody(
|
||||
value: value,
|
||||
empty: empty,
|
||||
cupertino: true,
|
||||
textBuilder: _CupertinoSelectableText.new,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -353,44 +298,6 @@ Widget _cupertinoFieldSection(
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoPrompt(
|
||||
BuildContext context, {
|
||||
required String prompt,
|
||||
required bool copying,
|
||||
required String? copyStatus,
|
||||
required VoidCallback onCopy,
|
||||
}) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
return 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)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _slug(String label) => label.toLowerCase().replaceAll(' ', '-');
|
||||
|
||||
/// A read-only Cupertino text control: plain, selectable text without a
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
/// The web's `displayText`: a list joins its items, a map reads `key=value`
|
||||
/// pairs, anything else is its plain string.
|
||||
String runFieldText(dynamic value) {
|
||||
if (value is List) return value.map(runFieldText).join(', ');
|
||||
if (value is Map) {
|
||||
return value.entries
|
||||
.map((entry) => '${entry.key}=${runFieldText(entry.value)}')
|
||||
.join(', ');
|
||||
}
|
||||
return '${value ?? 'null'}';
|
||||
}
|
||||
|
||||
/// The web's `looksLikeMarkdown`: a heading, fence, list item or table row.
|
||||
bool runFieldLooksLikeMarkdown(String text) =>
|
||||
RegExp(r'^#{1,6}\s', multiLine: true).hasMatch(text) ||
|
||||
text.contains('```') ||
|
||||
RegExp(r'^\s*(?:[-*]|\d+\.)\s+', multiLine: true).hasMatch(text) ||
|
||||
RegExp(r'^\|.+\|', multiLine: true).hasMatch(text);
|
||||
|
||||
/// A run's recorded Input or Output as the web draws it: each field under its
|
||||
/// own name with its value as text, markdown when it reads as markdown, and a
|
||||
/// lone `markdown` field as the document itself. Never raw JSON.
|
||||
class RunFieldBody extends StatelessWidget {
|
||||
const RunFieldBody({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.empty,
|
||||
required this.cupertino,
|
||||
this.textBuilder,
|
||||
});
|
||||
|
||||
final dynamic value;
|
||||
final String empty;
|
||||
final bool cupertino;
|
||||
|
||||
/// Draws a plain value; the host's selectable text by default.
|
||||
final Widget Function(String text)? textBuilder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final map = value is Map ? Map<String, dynamic>.from(value as Map) : null;
|
||||
if (map == null || map.isEmpty) return _plain(empty);
|
||||
if (map.length == 1 && map.keys.single.toLowerCase() == 'markdown') {
|
||||
return _value(runFieldText(map.values.single));
|
||||
}
|
||||
final caption =
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.labelMedium)
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final (index, entry) in map.entries.indexed)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: index == 0 ? 0 : 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
entry.key.trim().isEmpty ? 'value' : entry.key,
|
||||
style: caption,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_value(runFieldText(entry.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _value(String text) => runFieldLooksLikeMarkdown(text)
|
||||
? ChatMarkdownView(text: text)
|
||||
: _plain(text);
|
||||
|
||||
Widget _plain(String text) => textBuilder?.call(text) ?? SelectableText(text);
|
||||
}
|
||||
Reference in New Issue
Block a user