Make chat reasoning a footer chip that opens a live sheet like tools

This commit is contained in:
2026-10-24 18:13:03 +01:00
parent ef575898f2
commit 5cb43b6dc8
11 changed files with 646 additions and 165 deletions
+62 -6
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -9,8 +11,9 @@ const _style = String.fromEnvironment(
defaultValue: 'material',
);
/// Visible fixture for one user row and one folded assistant turn. The unknown
/// part and the tool body start collapsed so the browser probe has to open them.
/// 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([
{
@@ -57,10 +60,7 @@ void main() {
],
},
]);
final content = ListView(
padding: const EdgeInsets.all(16),
children: [for (final row in rows) ChatMessageView(row: row)],
);
final content = _LiveTranscript(rows: rows);
if (_style == 'cupertino') {
runApp(
CupertinoApp(
@@ -80,3 +80,59 @@ void main() {
),
);
}
/// 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),
],
);
}
}