f487257081
The chat thread header gains an Info action that opens a platform sheet (Material bottom sheet, Cupertino popup) with the four harness-reported usage facts in the web order and wording: rate, tokens, context and reported cost. Unknown facts read Unavailable; reported zeros stay zero. A live usage frame replaces an open panel without adding messages or touching turn state.
763 lines
27 KiB
Dart
763 lines
27 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../domain/chat_activity_detail.dart';
|
|
import '../domain/chat_transcript.dart';
|
|
import '../ui/sessions/chat_adaptive.dart';
|
|
import '../ui/transcript/chat_markdown_view.dart';
|
|
import '../ui/transcript/chat_message_view.dart';
|
|
import 'chat_composer_bar.dart';
|
|
import 'chat_composer_controller.dart';
|
|
import 'chat_draft_store.dart';
|
|
import 'chat_row_keys.dart';
|
|
import 'chat_thread_controller.dart';
|
|
import 'chat_transcript_card.dart';
|
|
|
|
/// One read-only conversation: the controller's transcript in the order the
|
|
/// server reports it, rendered by the existing [ChatMessageView].
|
|
///
|
|
/// Assistant text goes through [ChatMarkdownView]'s builder, so stored and live
|
|
/// prose share the supported markdown subset. User text keeps the server's exact
|
|
/// characters, and reasoning/tool disclosures stay plain text.
|
|
///
|
|
/// History and live-subscription failures are separate notices: readable stored
|
|
/// history must never hide a refused live watch. The shell owns the navigation
|
|
/// bar, so this view adds only its own Back control and content.
|
|
class ChatThreadView extends StatefulWidget {
|
|
const ChatThreadView({
|
|
super.key,
|
|
required this.gateway,
|
|
required this.sessionId,
|
|
required this.onBack,
|
|
this.title = '',
|
|
this.syncToken = 0,
|
|
this.drafts,
|
|
this.newOperationId,
|
|
});
|
|
|
|
final ApiGateway gateway;
|
|
final String sessionId;
|
|
final VoidCallback onBack;
|
|
|
|
/// The list row's title when this visit knows it; a deep link may not.
|
|
final String title;
|
|
|
|
/// Advances when the shared socket is replaced, keeping this selection.
|
|
final int syncToken;
|
|
|
|
/// Draft persistence for tests and previews; production uses the app store.
|
|
final ChatDraftStore? drafts;
|
|
|
|
/// Test/fixture seam for deterministic operation ids.
|
|
final String Function()? newOperationId;
|
|
|
|
@override
|
|
State<ChatThreadView> createState() => _ChatThreadViewState();
|
|
}
|
|
|
|
class _ChatThreadViewState extends State<ChatThreadView> {
|
|
late ChatThreadController _controller = _attach();
|
|
late ChatComposerController _composer = _attachComposer();
|
|
late ChatRowKeys _rowKeys = ChatRowKeys();
|
|
|
|
/// A sent turn shown before history or a live frame echoes it.
|
|
final List<JsonMap> _optimistic = [];
|
|
|
|
ChatThreadController _attach() =>
|
|
ChatThreadController(widget.gateway, widget.sessionId)..load();
|
|
|
|
ChatComposerController _attachComposer() => ChatComposerController(
|
|
widget.gateway,
|
|
widget.sessionId,
|
|
drafts: widget.drafts,
|
|
newOperationId: widget.newOperationId,
|
|
onOptimistic: _onOptimistic,
|
|
onRejected: _onRejected,
|
|
);
|
|
|
|
void _onOptimistic(ChatComposerSend send) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_optimistic.add({
|
|
'id': send.optimisticId,
|
|
'session_id': send.sessionId,
|
|
'role': 'user',
|
|
'operation_id': send.operationId,
|
|
'native_message_id': send.nativeMessageId,
|
|
'parts': [
|
|
{'type': 'text', 'text': send.text},
|
|
],
|
|
});
|
|
});
|
|
}
|
|
|
|
void _onRejected(ChatComposerSend send, String error) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_optimistic.removeWhere((row) => row['operation_id'] == send.operationId);
|
|
});
|
|
}
|
|
|
|
/// Reports the harness's recorded usage. The standard sheet is dismissed the
|
|
/// platform's way (drag/barrier/Back, or a popup tap) and closes explicitly.
|
|
Future<void> _openInfo() async {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
if (cupertino) {
|
|
await showCupertinoModalPopup<void>(
|
|
context: context,
|
|
builder: (sheetContext) => Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: SafeArea(
|
|
child: CupertinoPopupSurface(
|
|
child: _ChatInfoSheet(controller: _controller),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
await showModalBottomSheet<void>(
|
|
context: context,
|
|
showDragHandle: true,
|
|
isScrollControlled: true,
|
|
useSafeArea: true,
|
|
builder: (sheetContext) => _ChatInfoSheet(controller: _controller),
|
|
);
|
|
}
|
|
|
|
/// Local turns whose authoritative copy is not in the held transcript yet.
|
|
/// A live user frame or a history page that carries the same operation,
|
|
/// native id or message id hides the local copy instead of drawing it twice.
|
|
List<JsonMap> _visibleMessages() {
|
|
final messages = _controller.messages;
|
|
return [
|
|
...messages,
|
|
for (final pending in _optimistic)
|
|
if (!messages.any((message) => _isEcho(pending, message))) pending,
|
|
];
|
|
}
|
|
|
|
bool _isEcho(JsonMap pending, JsonMap message) {
|
|
if (message['role'] != 'user') return false;
|
|
if (pending['id'] == message['id']) return true;
|
|
final operation = pending['operation_id'];
|
|
if (operation != null && operation == message['operation_id']) return true;
|
|
final native = '${pending['native_message_id'] ?? ''}';
|
|
return native.isNotEmpty && native == message['native_message_id'];
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant ChatThreadView oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.gateway != widget.gateway ||
|
|
oldWidget.sessionId != widget.sessionId) {
|
|
_controller.dispose();
|
|
_composer.dispose();
|
|
_controller = _attach();
|
|
_composer = _attachComposer();
|
|
_rowKeys = ChatRowKeys();
|
|
_optimistic.clear();
|
|
} else if (oldWidget.syncToken != widget.syncToken) {
|
|
unawaited(_controller.resync());
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_composer.dispose();
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => AnimatedBuilder(
|
|
animation: _controller,
|
|
builder: (context, _) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
final cards = chatCardRows(
|
|
permissions: _controller.permissionFrames,
|
|
forms: _controller.questionForms,
|
|
answerFor: _controller.permissionAnswerFor,
|
|
permissionErrorFor: _controller.permissionErrorFor,
|
|
formErrorFor: _controller.questionErrorFor,
|
|
);
|
|
// A pending approval/question means the turn is waiting on the operator,
|
|
// not generating, so the transcript indicator and its live region stand
|
|
// down; the composer's Stop control still follows `running`.
|
|
final awaiting = cards.any(chatCardAwaitingOperator);
|
|
final rows = transcriptRows(_visibleMessages(), trailing: cards);
|
|
// Older pages prepend messages and a live frame can append one, so a
|
|
// folded assistant turn's first message id is not a stable identity.
|
|
// ChatRowKeys carries a turn's key forward while it still holds any of
|
|
// its previous messages, keeping the element (and its open disclosures)
|
|
// across paging and streaming.
|
|
final keys = _rowKeys.forRows(rows);
|
|
final initialLoad = !_controller.loaded && _controller.loading;
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView(
|
|
key: ValueKey<String>('chat-thread-${widget.sessionId}'),
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
children: [
|
|
Padding(
|
|
key: const Key('chat-thread-header'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 16, 4),
|
|
child: Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
_backButton(cupertino),
|
|
if (widget.title.trim().isNotEmpty)
|
|
Text(
|
|
widget.title.trim(),
|
|
style: cupertino
|
|
? CupertinoTheme.of(
|
|
context,
|
|
).textTheme.navTitleTextStyle
|
|
: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
ChatBarAction(
|
|
key: const Key('chat-info'),
|
|
label: 'Chat information',
|
|
onPressed: _openInfo,
|
|
materialIcon: Icons.info_outline,
|
|
cupertinoIcon: CupertinoIcons.info,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (initialLoad)
|
|
Padding(
|
|
key: const Key('chat-thread-loading'),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Center(
|
|
child: cupertino
|
|
? const CupertinoActivityIndicator()
|
|
: const CircularProgressIndicator(),
|
|
),
|
|
),
|
|
if (_controller.hasMore)
|
|
Padding(
|
|
key: const Key('chat-load-older'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: cupertino
|
|
? CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: _controller.loading
|
|
? null
|
|
: _controller.loadOlder,
|
|
child: const Text('Load older'),
|
|
)
|
|
: TextButton(
|
|
onPressed: _controller.loading
|
|
? null
|
|
: _controller.loadOlder,
|
|
child: const Text('Load older'),
|
|
),
|
|
),
|
|
),
|
|
if (_controller.error != null)
|
|
ChatErrorNotice(
|
|
key: const Key('chat-history-error'),
|
|
message: 'Chat history unavailable\n${_controller.error}',
|
|
onRetry: _controller.load,
|
|
),
|
|
if (_controller.subscriptionError != null)
|
|
ChatErrorNotice(
|
|
key: const Key('chat-live-error'),
|
|
message:
|
|
'Live updates unavailable\n${_controller.subscriptionError}',
|
|
onRetry: _controller.resync,
|
|
),
|
|
if (_controller.loaded &&
|
|
rows.isEmpty &&
|
|
_controller.error == null)
|
|
const Padding(
|
|
key: Key('chat-thread-empty'),
|
|
padding: EdgeInsets.all(16),
|
|
child: Text('No messages in this chat yet.'),
|
|
),
|
|
for (var index = 0; index < rows.length; index++)
|
|
Padding(
|
|
key: ValueKey<String>(keys[index]),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: _transcriptRow(rows[index]),
|
|
),
|
|
if (_controller.running && !awaiting)
|
|
Padding(
|
|
key: const Key('chat-running'),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: const Text('Assistant is responding…'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
ChatComposerBar(
|
|
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
|
composer: _composer,
|
|
running: _controller.running,
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
|
|
Widget _transcriptRow(JsonMap row) {
|
|
final kind = '${row['kind'] ?? ''}';
|
|
if (kind == 'activity') return _ChatActivityLine(row: row);
|
|
if (kind == 'permission' || kind == 'question') {
|
|
return ChatTranscriptCard(
|
|
row: row,
|
|
onPermissionDecision: _controller.replyPermission,
|
|
onQuestionAnswer: _controller.answerQuestion,
|
|
);
|
|
}
|
|
return ChatMessageView(row: row, textBuilder: chatMarkdownText);
|
|
}
|
|
|
|
Widget _backButton(bool cupertino) => cupertino
|
|
? CupertinoButton(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 8, 0),
|
|
onPressed: widget.onBack,
|
|
child: const Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(CupertinoIcons.back),
|
|
SizedBox(width: 4),
|
|
Text('Back'),
|
|
],
|
|
),
|
|
)
|
|
: TextButton.icon(
|
|
onPressed: widget.onBack,
|
|
icon: const Icon(Icons.arrow_back),
|
|
label: const Text('Back to chats'),
|
|
);
|
|
}
|
|
|
|
/// One reported usage metric: its web label, whether the harness reported it,
|
|
/// and the displayed value. Unavailable is a word, never a zero.
|
|
typedef _ChatInfoMetric = ({
|
|
String key,
|
|
String label,
|
|
bool available,
|
|
String value,
|
|
});
|
|
|
|
const _chatInfoUnavailable = 'Unavailable';
|
|
|
|
/// The four chat usage facts in the web order and wording.
|
|
///
|
|
/// Values come only from [ChatThreadController.usage]; a missing count, amount
|
|
/// or window is "Unavailable". A reported zero stays a reported zero, and the
|
|
/// context row keeps the web's partial forms when only one side was reported.
|
|
List<_ChatInfoMetric> _chatInfoMetrics(JsonMap? usage) {
|
|
final scope = '${usage?['scope'] ?? ''}';
|
|
final basis = '${usage?['rate_basis'] ?? ''}';
|
|
final rate = _chatInfoAmount(usage?['output_tokens_per_second']);
|
|
final total = _chatInfoCount(usage?['total_tokens']);
|
|
final used = _chatInfoCount(usage?['context_tokens']);
|
|
final reportedWindow = _chatInfoCount(usage?['context_window']);
|
|
// The web treats a zero context window as no reported limit.
|
|
final limit = reportedWindow != null && reportedWindow > 0
|
|
? reportedWindow
|
|
: null;
|
|
final cost = _chatInfoAmount(usage?['cost_usd']);
|
|
final context = used != null && limit != null
|
|
? '${_chatInfoInteger(used)} / ${_chatInfoInteger(limit)}'
|
|
: limit != null
|
|
? '${_chatInfoInteger(limit)} limit'
|
|
: used != null
|
|
? '${_chatInfoInteger(used)} used'
|
|
: _chatInfoUnavailable;
|
|
return [
|
|
(
|
|
key: 'rate',
|
|
label: basis == 'turn' ? 'Avg output rate' : 'Output rate',
|
|
available: rate != null,
|
|
value: rate == null ? _chatInfoUnavailable : _chatInfoRate(rate),
|
|
),
|
|
(
|
|
key: 'tokens',
|
|
label: scope == 'turn' ? 'Turn tokens' : 'Total tokens',
|
|
available: total != null,
|
|
value: total == null ? _chatInfoUnavailable : _chatInfoInteger(total),
|
|
),
|
|
(
|
|
key: 'context',
|
|
label: 'Context',
|
|
available: used != null || limit != null,
|
|
value: context,
|
|
),
|
|
(
|
|
key: 'cost',
|
|
label: 'Reported cost',
|
|
available: cost != null,
|
|
value: cost == null ? _chatInfoUnavailable : _chatInfoDollars(cost),
|
|
),
|
|
];
|
|
}
|
|
|
|
int? _chatInfoCount(Object? value) => value is int && value >= 0 ? value : null;
|
|
|
|
num? _chatInfoAmount(Object? value) =>
|
|
value is num && value.isFinite && value >= 0 ? value : null;
|
|
|
|
String _chatInfoInteger(int value) {
|
|
final digits = value.toString();
|
|
final grouped = StringBuffer();
|
|
for (var index = 0; index < digits.length; index++) {
|
|
if (index > 0 && (digits.length - index) % 3 == 0) grouped.write(',');
|
|
grouped.write(digits[index]);
|
|
}
|
|
return grouped.toString();
|
|
}
|
|
|
|
String _chatInfoRate(num value) {
|
|
final atMostOneDecimal = value.toStringAsFixed(1);
|
|
final number = atMostOneDecimal.endsWith('.0')
|
|
? atMostOneDecimal.substring(0, atMostOneDecimal.length - 2)
|
|
: atMostOneDecimal;
|
|
return value > 0 && value < 0.1 ? '<0.1 tok/s' : '$number tok/s';
|
|
}
|
|
|
|
String _chatInfoDollars(num value) {
|
|
if (value > 0 && value < 0.000001) return '<\$0.000001';
|
|
final fixed = value.toStringAsFixed(6);
|
|
final point = fixed.indexOf('.');
|
|
var decimals = fixed.substring(point + 1);
|
|
while (decimals.length > 4 && decimals.endsWith('0')) {
|
|
decimals = decimals.substring(0, decimals.length - 1);
|
|
}
|
|
final whole = int.parse(fixed.substring(0, point));
|
|
return '\$${_chatInfoInteger(whole)}.$decimals';
|
|
}
|
|
|
|
/// The "Chat information" panel. It rebuilds from the controller, so metrics
|
|
/// that arrive while it is open replace the displayed snapshot.
|
|
class _ChatInfoSheet extends StatelessWidget {
|
|
const _ChatInfoSheet({required this.controller});
|
|
|
|
final ChatThreadController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
return AnimatedBuilder(
|
|
animation: controller,
|
|
builder: (context, _) {
|
|
final titleStyle = cupertino
|
|
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
|
: Theme.of(context).textTheme.titleLarge;
|
|
final content = Column(
|
|
key: const Key('chat-info-sheet'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 16, 4),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Semantics(
|
|
header: true,
|
|
child: Text('Chat information', style: titleStyle),
|
|
),
|
|
),
|
|
if (cupertino)
|
|
CupertinoButton(
|
|
key: const Key('chat-info-close'),
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Close'),
|
|
)
|
|
else
|
|
TextButton(
|
|
key: const Key('chat-info-close'),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Close'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
for (final metric in _chatInfoMetrics(controller.usage))
|
|
_ChatInfoRow(metric: metric, cupertino: cupertino),
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 24, 16),
|
|
child: Text(
|
|
'Last reported by the harness. '
|
|
'Unavailable values are not estimated.',
|
|
style:
|
|
(cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodySmall)
|
|
?.copyWith(
|
|
color: cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(
|
|
context,
|
|
)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
if (!cupertino) return SingleChildScrollView(child: content);
|
|
// A tall text scale must scroll inside the popup rather than push its
|
|
// heading off-screen. The height follows the viewport, not a fixed size.
|
|
return ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
|
),
|
|
child: SingleChildScrollView(child: content),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ChatInfoRow extends StatelessWidget {
|
|
const _ChatInfoRow({required this.metric, required this.cupertino});
|
|
|
|
final _ChatInfoMetric metric;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final secondary = cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant;
|
|
final labelStyle =
|
|
(cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodySmall)
|
|
?.copyWith(color: secondary);
|
|
final valueStyle = cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodyLarge;
|
|
return Padding(
|
|
key: Key('chat-info-metric-${metric.key}'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 6, 24, 6),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(metric.label, style: labelStyle),
|
|
Text(
|
|
metric.value,
|
|
key: Key('chat-info-value-${metric.key}'),
|
|
style: metric.available
|
|
? valueStyle
|
|
: valueStyle?.copyWith(color: secondary),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One recorded activity line for a turn.
|
|
///
|
|
/// The line is a summary of the recorded sequence. Its wording and state come
|
|
/// from the recorded row, and the icon only repeats that state with theme roles,
|
|
/// so an unknown kind or state is still readable without colour. The trailing
|
|
/// control expands the same line into the recorded lifecycle and any recorded
|
|
/// input, output, error, duration and edit diff; collapsing restores the single
|
|
/// line without touching the turn.
|
|
class _ChatActivityLine extends StatefulWidget {
|
|
const _ChatActivityLine({required this.row});
|
|
|
|
final JsonMap row;
|
|
|
|
@override
|
|
State<_ChatActivityLine> createState() => _ChatActivityLineState();
|
|
}
|
|
|
|
class _ChatActivityLineState extends State<_ChatActivityLine> {
|
|
bool _expanded = false;
|
|
|
|
void _toggle() => setState(() => _expanded = !_expanded);
|
|
|
|
/// The latest recorded update, which is also the line's label/state. With no
|
|
/// records (a caller-built row) the row itself carries the same fields.
|
|
JsonMap _record() {
|
|
final records = widget.row['records'];
|
|
if (records is List) {
|
|
for (final record in records.reversed) {
|
|
if (record is Map) return JsonMap.from(record);
|
|
}
|
|
}
|
|
return widget.row;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
final state = '${widget.row['state'] ?? ''}'.trim().toLowerCase();
|
|
final failed = state == 'failed' || state == 'error';
|
|
final running = state == 'running';
|
|
final completed =
|
|
state == 'completed' || state == 'ended' || state == 'succeeded';
|
|
final secondary = _secondary(context, cupertino);
|
|
final color = failed
|
|
? (cupertino
|
|
? CupertinoColors.systemRed.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.error)
|
|
: secondary;
|
|
final style =
|
|
(cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodySmall)
|
|
?.copyWith(color: color);
|
|
final icon = failed
|
|
? (cupertino
|
|
? CupertinoIcons.exclamationmark_circle
|
|
: Icons.error_outline)
|
|
: running
|
|
? (cupertino ? CupertinoIcons.arrow_2_circlepath : Icons.sync)
|
|
: completed
|
|
? (cupertino
|
|
? CupertinoIcons.check_mark_circled
|
|
: Icons.check_circle_outline)
|
|
: (cupertino ? CupertinoIcons.circle : Icons.circle_outlined);
|
|
final label = '${widget.row['label'] ?? ''}'.trim();
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Semantics(
|
|
container: true,
|
|
label: label,
|
|
value: state,
|
|
child: ExcludeSemantics(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, color: color),
|
|
const SizedBox(width: 8),
|
|
Expanded(child: Text(label, style: style)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
_toggleControl(cupertino),
|
|
],
|
|
),
|
|
if (_expanded) _detail(context, cupertino, secondary),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The host's own disclosure control, with an action label that states what a
|
|
/// tap does. Cupertino's button has no built-in label, so the wrapping node
|
|
/// carries it and the button keeps the pointer handling.
|
|
Widget _toggleControl(bool cupertino) {
|
|
const key = ValueKey<String>('chat-activity-toggle');
|
|
final label = _expanded ? 'Collapse activity' : 'Expand activity';
|
|
final icon = Icon(
|
|
_expanded
|
|
? (cupertino ? CupertinoIcons.chevron_up : Icons.expand_less)
|
|
: (cupertino ? CupertinoIcons.chevron_down : Icons.expand_more),
|
|
);
|
|
if (!cupertino) {
|
|
return IconButton(
|
|
key: key,
|
|
tooltip: label,
|
|
onPressed: _toggle,
|
|
icon: icon,
|
|
);
|
|
}
|
|
return Semantics(
|
|
container: true,
|
|
button: true,
|
|
label: label,
|
|
onTap: _toggle,
|
|
child: ExcludeSemantics(
|
|
child: CupertinoButton(
|
|
key: key,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: _toggle,
|
|
child: icon,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The expanded section: every recorded field, with the exact absence sentence
|
|
/// for one the record did not carry. Only [ChatActivityDetail] reads the
|
|
/// record, so the line and its details cannot disagree about a field.
|
|
Widget _detail(BuildContext context, bool cupertino, Color secondary) {
|
|
final detail = chatActivityDetail(_record());
|
|
final baseStyle = cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.bodyMedium;
|
|
final labelStyle = TextStyle(color: secondary, fontWeight: FontWeight.w600);
|
|
Widget field(String label, String value) {
|
|
final absent =
|
|
value == chatActivityLifecycleAbsent ||
|
|
value == chatActivityInputAbsent ||
|
|
value == chatActivityOutputAbsent ||
|
|
value == chatActivityErrorAbsent ||
|
|
value == chatActivityDurationAbsent ||
|
|
value == chatActivityDiffAbsent;
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.only(top: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: labelStyle),
|
|
DefaultTextStyle.merge(
|
|
style: absent ? TextStyle(color: secondary) : const TextStyle(),
|
|
child: SelectableText(value),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return DefaultTextStyle.merge(
|
|
style: baseStyle,
|
|
child: Padding(
|
|
key: const ValueKey<String>('chat-activity-details'),
|
|
padding: const EdgeInsetsDirectional.only(bottom: 2),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
field('Lifecycle', detail.lifecycle),
|
|
field('Input', detail.input),
|
|
field('Output', detail.output),
|
|
field('Error', detail.error),
|
|
field('Duration', detail.duration),
|
|
field('Edit diff', detail.diff),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Color _secondary(BuildContext context, bool cupertino) => cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant;
|
|
}
|