97 lines
3.5 KiB
Dart
97 lines
3.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
|
||
import '../../../core/api_gateway.dart';
|
||
import '../domain/chat_task_metadata.dart';
|
||
|
||
/// Recorded task facts in the row, with unabridged progress in selected detail.
|
||
class ChatTaskMetadataView extends StatelessWidget {
|
||
const ChatTaskMetadataView({
|
||
super.key,
|
||
required this.shell,
|
||
required this.now,
|
||
this.detail = false,
|
||
});
|
||
|
||
final JsonMap shell;
|
||
final DateTime now;
|
||
final bool detail;
|
||
|
||
String _date(BuildContext context, DateTime time) {
|
||
final material = Localizations.of<MaterialLocalizations>(
|
||
context,
|
||
MaterialLocalizations,
|
||
);
|
||
final date = material != null
|
||
? '${time.day} ${material.formatMonthYear(time)}'
|
||
: '${time.day} ${CupertinoLocalizations.of(context).datePickerMonth(time.month)} ${time.year}';
|
||
return '$date · ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final start = taskInstant(shell, 'started_at');
|
||
final elapsed = taskElapsed(shell, now);
|
||
final duration = taskNumber(shell, 'duration_ms');
|
||
final updated = taskInstant(shell, 'updated_at');
|
||
final description = taskText(shell, 'description');
|
||
final progress = taskText(shell, 'progress');
|
||
final kind = taskText(shell, 'task_type');
|
||
final lastTool = taskText(shell, 'last_tool');
|
||
final tools = taskNumber(shell, 'tool_count');
|
||
final tokens = taskNumber(shell, 'token_count');
|
||
final counters = [
|
||
if (tools != null) '$tools tool calls',
|
||
if (tokens != null) '$tokens tokens',
|
||
];
|
||
final state = elapsed == null
|
||
? 'Running'
|
||
: 'Running · ${taskDuration(elapsed)}';
|
||
final kindLabel = kind == null
|
||
? null
|
||
: '${kind[0].toUpperCase()}${kind.substring(1).replaceAll('_', ' ')}';
|
||
final summary =
|
||
progress ??
|
||
(description != null &&
|
||
!'${shell['command'] ?? ''}'.endsWith(description)
|
||
? description
|
||
: null);
|
||
final facts = <String>[
|
||
if (!detail) kindLabel == null ? state : '$kindLabel · $state',
|
||
if (detail && elapsed != null) 'Elapsed: ${taskDuration(elapsed)}',
|
||
start == null
|
||
? 'Start time unavailable'
|
||
: 'Started ${_date(context, start)}',
|
||
if (start != null && elapsed == null)
|
||
'Start time is ahead of this device’s clock',
|
||
if (elapsed == null && duration != null)
|
||
'Reported runtime: ${taskDuration(Duration(milliseconds: duration))}',
|
||
if (detail) ...[?kindLabel, ?description, ?progress] else ...[?summary],
|
||
if (counters.isNotEmpty) counters.join(' · '),
|
||
if (detail && lastTool != null) 'Last tool: $lastTool',
|
||
if (detail && updated != null) 'Last update ${_date(context, updated)}',
|
||
];
|
||
// CupertinoListTile supplies a one-line default; explicitly allow metadata
|
||
// to wrap and grow with the available width and system text scaling.
|
||
return DefaultTextStyle(
|
||
style: DefaultTextStyle.of(context).style,
|
||
softWrap: true,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
for (final fact in facts)
|
||
Padding(
|
||
padding: const EdgeInsets.only(top: 2),
|
||
child: Text(
|
||
fact,
|
||
maxLines: detail ? null : 2,
|
||
overflow: detail ? TextOverflow.clip : TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|