89 lines
2.9 KiB
Dart
89 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
|
||
import '../../../core/api_gateway.dart';
|
||
import '../domain/chat_task_metadata.dart';
|
||
import 'chat_task_presentation.dart';
|
||
|
||
/// Icon-labelled facts, kept distinct from the task's headline and progress.
|
||
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;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final start = taskInstant(shell, 'started_at');
|
||
final duration = taskNumber(shell, 'duration_ms');
|
||
final updated = taskInstant(shell, 'updated_at');
|
||
final lastTool = taskText(shell, 'last_tool');
|
||
final tools = taskNumber(shell, 'tool_count');
|
||
final tokens = taskNumber(shell, 'token_count');
|
||
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),
|
||
),
|
||
];
|
||
return Wrap(spacing: 24, runSpacing: 16, children: facts);
|
||
}
|
||
}
|