Present background tasks as adaptive status cards
This commit is contained in:
@@ -3,8 +3,9 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/chat_task_metadata.dart';
|
||||
import 'chat_task_presentation.dart';
|
||||
|
||||
/// Recorded task facts in the row, with unabridged progress in selected detail.
|
||||
/// Icon-labelled facts, kept distinct from the task's headline and progress.
|
||||
class ChatTaskMetadataView extends StatelessWidget {
|
||||
const ChatTaskMetadataView({
|
||||
super.key,
|
||||
@@ -12,85 +13,76 @@ class ChatTaskMetadataView extends StatelessWidget {
|
||||
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 facts = <Widget>[
|
||||
if (!detail)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context) ? CupertinoIcons.clock : Icons.schedule,
|
||||
label: 'Started',
|
||||
value: start == null
|
||||
? 'Start time unavailable'
|
||||
: formatTaskDate(context, start),
|
||||
),
|
||||
if (!detail && start != null && start.isAfter(now))
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.exclamationmark_circle
|
||||
: Icons.info_outline,
|
||||
label: 'Device clock',
|
||||
value: 'Start time is ahead of this device’s clock',
|
||||
),
|
||||
if (!detail && start == null && duration != null)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.timer
|
||||
: Icons.timer_outlined,
|
||||
label: 'Reported runtime',
|
||||
value: taskDuration(Duration(milliseconds: duration)),
|
||||
),
|
||||
if (!detail && tools != null)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.wrench
|
||||
: Icons.build_outlined,
|
||||
label: 'Tool calls',
|
||||
value: formatTaskCount(tools),
|
||||
),
|
||||
if (!detail && tokens != null)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.number
|
||||
: Icons.token_outlined,
|
||||
label: 'Tokens',
|
||||
value: formatTaskCount(tokens),
|
||||
),
|
||||
if (detail && lastTool != null)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.wrench
|
||||
: Icons.build_outlined,
|
||||
label: 'Last tool',
|
||||
value: lastTool,
|
||||
),
|
||||
if (detail && updated != null)
|
||||
ChatTaskFact(
|
||||
icon: taskCupertino(context)
|
||||
? CupertinoIcons.arrow_clockwise
|
||||
: Icons.update,
|
||||
label: 'Last update',
|
||||
value: formatTaskDate(context, updated),
|
||||
),
|
||||
];
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return Wrap(spacing: 24, runSpacing: 16, children: facts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user