139 lines
3.7 KiB
Dart
139 lines
3.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
|
|
|
const _style = String.fromEnvironment(
|
|
'CHAT_MESSAGE_PROBE_STYLE',
|
|
defaultValue: 'material',
|
|
);
|
|
|
|
/// Visible fixture for one user row, one folded assistant turn and one live
|
|
/// turn whose newest reasoning step grows every half second. The unknown part
|
|
/// and the tool body start collapsed so the browser probe has to open them.
|
|
void main() {
|
|
final rows = transcriptRows([
|
|
{
|
|
'id': 'probe-user',
|
|
'role': 'user',
|
|
'client': 'Ada phone',
|
|
'parts': [
|
|
{
|
|
'type': 'text',
|
|
'text':
|
|
'Please keep every word of this prompt, including the trailing '
|
|
'detail that wraps onto another line at a narrow width.',
|
|
},
|
|
{'type': 'file', 'name': 'plan.md', 'uri': '/workspace/plan.md'},
|
|
{'type': 'file', 'uri': '/workspace/results/report.csv'},
|
|
],
|
|
},
|
|
{
|
|
'id': 'probe-assistant',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{
|
|
'type': 'text',
|
|
'text': 'I checked the transcript and kept the original order.',
|
|
},
|
|
{
|
|
'type': 'reasoning',
|
|
'text':
|
|
'The user asked for exact text, so the raw string stays as sent.',
|
|
},
|
|
{
|
|
'type': 'tool',
|
|
'name': 'shell',
|
|
'state': {
|
|
'status': 'completed',
|
|
'input': {'command': 'ls -la'},
|
|
},
|
|
},
|
|
{'type': 'text', 'text': 'Second answer line after the tool call.'},
|
|
{
|
|
'type': 'future_part',
|
|
'payload': {'kept': true, 'count': 2},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
final content = _LiveTranscript(rows: rows);
|
|
if (_style == 'cupertino') {
|
|
runApp(
|
|
CupertinoApp(
|
|
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
|
home: CupertinoPageScaffold(child: SafeArea(child: content)),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
runApp(
|
|
MaterialApp(
|
|
theme: ThemeData(
|
|
brightness: Brightness.dark,
|
|
platform: TargetPlatform.android,
|
|
),
|
|
home: Scaffold(body: SafeArea(child: content)),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The fixture rows plus a streaming turn, rebuilt on each tick the way the
|
|
/// thread repaints a live delta.
|
|
class _LiveTranscript extends StatefulWidget {
|
|
const _LiveTranscript({required this.rows});
|
|
|
|
final List<Map<String, dynamic>> rows;
|
|
|
|
@override
|
|
State<_LiveTranscript> createState() => _LiveTranscriptState();
|
|
}
|
|
|
|
class _LiveTranscriptState extends State<_LiveTranscript> {
|
|
int _tick = 0;
|
|
late final Timer _timer;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_timer = Timer.periodic(
|
|
const Duration(milliseconds: 500),
|
|
(_) => setState(() => _tick++),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_timer.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final live = {
|
|
...transcriptRows([
|
|
{
|
|
'id': 'probe-live',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{'type': 'reasoning', 'id': 'r1', 'text': 'Live step one settled.'},
|
|
{'type': 'text', 'id': 't1', 'text': 'Live answer so far.'},
|
|
{'type': 'reasoning', 'id': 'r2', 'text': 'Live tick $_tick.'},
|
|
],
|
|
},
|
|
]).single,
|
|
'streaming': true,
|
|
};
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
for (final row in [...widget.rows, live])
|
|
ChatMessageView(key: ValueKey(row['key']), row: row),
|
|
],
|
|
);
|
|
}
|
|
}
|