Files
pipelines/app/lib/features/chat/conversation/chat_task_metadata_view.dart
T

89 lines
2.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}