fix(chat): place per-message reasoning left of the tools count
This commit is contained in:
@@ -203,6 +203,18 @@ class ChatMessageView extends StatelessWidget {
|
|||||||
if (isChatToolPart(part)) part,
|
if (isChatToolPart(part)) part,
|
||||||
];
|
];
|
||||||
final model = '${row['model'] ?? ''}'.trim();
|
final model = '${row['model'] ?? ''}'.trim();
|
||||||
|
final footer = <Widget>[
|
||||||
|
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
|
||||||
|
if (model.isNotEmpty)
|
||||||
|
Text(
|
||||||
|
model,
|
||||||
|
key: const Key('chat-reply-model'),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: _secondaryColor(context, _isCupertino(context)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -213,24 +225,13 @@ class ChatMessageView extends StatelessWidget {
|
|||||||
key: const Key('chat-turn-reasoning'),
|
key: const Key('chat-turn-reasoning'),
|
||||||
steps: reasoning,
|
steps: reasoning,
|
||||||
streaming: row['streaming'] == true,
|
streaming: row['streaming'] == true,
|
||||||
|
trailing: footer,
|
||||||
),
|
),
|
||||||
if (tools.isNotEmpty || model.isNotEmpty)
|
if (reasoning.isEmpty && footer.isNotEmpty)
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
children: [
|
children: footer,
|
||||||
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
|
|
||||||
// Which model answered, quietly, after the chips.
|
|
||||||
if (model.isNotEmpty)
|
|
||||||
Text(
|
|
||||||
model,
|
|
||||||
key: const Key('chat-reply-model'),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: _secondaryColor(context, _isCupertino(context)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,52 +2,100 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../sessions/chat_adaptive.dart';
|
import '../sessions/chat_adaptive.dart';
|
||||||
import 'native_disclosure.dart';
|
|
||||||
|
|
||||||
/// Only reasoning actually supplied by the backend. Keeping its body in the
|
/// Only reasoning actually supplied by the backend. Keeping its body in the
|
||||||
/// transcript (rather than a modal snapshot) lets an open disclosure rebuild
|
/// transcript (rather than a modal snapshot) lets an open disclosure rebuild
|
||||||
/// with every delta, even while answer text is also arriving.
|
/// with every delta, even while answer text is also arriving.
|
||||||
class ChatReasoningDisclosure extends StatelessWidget {
|
class ChatReasoningDisclosure extends StatefulWidget {
|
||||||
const ChatReasoningDisclosure({
|
const ChatReasoningDisclosure({
|
||||||
super.key,
|
super.key,
|
||||||
required this.steps,
|
required this.steps,
|
||||||
required this.streaming,
|
required this.streaming,
|
||||||
|
this.trailing = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<String> steps;
|
final List<String> steps;
|
||||||
final bool streaming;
|
final bool streaming;
|
||||||
|
final List<Widget> trailing;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChatReasoningDisclosure> createState() =>
|
||||||
|
_ChatReasoningDisclosureState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChatReasoningDisclosureState extends State<ChatReasoningDisclosure> {
|
||||||
|
late bool _expanded = widget.streaming;
|
||||||
|
|
||||||
|
void _toggle() => setState(() => _expanded = !_expanded);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final cupertino =
|
final cupertino =
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||||
final label = steps.length == 1
|
final label = widget.steps.length == 1
|
||||||
? 'Reasoning'
|
? 'Reasoning'
|
||||||
: 'Reasoning · ${steps.length} steps';
|
: 'Reasoning · ${widget.steps.length} steps';
|
||||||
final disclosure = NativeDisclosure(
|
final control = Semantics(
|
||||||
key: const Key('chat-reasoning-disclosure'),
|
key: const Key('chat-reasoning-toggle'),
|
||||||
|
button: true,
|
||||||
|
expanded: _expanded,
|
||||||
label: label,
|
label: label,
|
||||||
initiallyExpanded: streaming,
|
onTap: _toggle,
|
||||||
childBuilder: (_) => Column(
|
excludeSemantics: true,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
child: cupertino
|
||||||
children: [
|
? CupertinoButton(
|
||||||
for (final (index, step) in steps.indexed)
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||||
Padding(
|
minimumSize: Size.zero,
|
||||||
padding: EdgeInsets.only(top: index == 0 ? 0 : 12, bottom: 8),
|
onPressed: _toggle,
|
||||||
child: SelectableText(step),
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Flexible(child: Text(label)),
|
||||||
|
Icon(
|
||||||
|
_expanded
|
||||||
|
? CupertinoIcons.chevron_up
|
||||||
|
: CupertinoIcons.chevron_down,
|
||||||
|
size: 14,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: _toggle,
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Flexible(child: Text(label)),
|
||||||
|
Icon(
|
||||||
|
_expanded ? Icons.expand_less : Icons.expand_more,
|
||||||
|
size: 14,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
// Material's native ExpansionTile needs a surface; Cupertino must not
|
|
||||||
// acquire a Material dependency just to show its own disclosure button.
|
|
||||||
return DefaultTextStyle.merge(
|
return DefaultTextStyle.merge(
|
||||||
style: cupertino
|
style: cupertino
|
||||||
? CupertinoTheme.of(context).textTheme.textStyle
|
? CupertinoTheme.of(context).textTheme.textStyle
|
||||||
: Theme.of(context).textTheme.bodyMedium,
|
: Theme.of(context).textTheme.bodyMedium,
|
||||||
child: cupertino
|
child: Column(
|
||||||
? disclosure
|
key: const Key('chat-reasoning-disclosure'),
|
||||||
: Material(color: Colors.transparent, child: disclosure),
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Wrap(
|
||||||
|
key: const Key('chat-message-footer'),
|
||||||
|
spacing: 8,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
children: [control, ...widget.trailing],
|
||||||
|
),
|
||||||
|
if (_expanded)
|
||||||
|
for (final (index, step) in widget.steps.indexed)
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: index == 0 ? 0 : 12, bottom: 8),
|
||||||
|
child: SelectableText(step),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Per-message reasoning footer
|
||||||
|
|
||||||
|
User requested each assistant message's Reasoning control to the left of its
|
||||||
|
tools count. The compact native disclosure now shares the footer with tools and
|
||||||
|
model metadata; expanded text remains inline below and updates while streaming.
|
||||||
|
Each message retains independent expansion state, including through paging.
|
||||||
|
No reasoning is fabricated when the backend provides none. Narrow/scaled layouts
|
||||||
|
may wrap controls in their logical order instead of clipping them.
|
||||||
|
|
||||||
|
- Both-host layout regressions failed before the change.
|
||||||
|
- New per-message tests cover left-to-right placement and independent expansion.
|
||||||
|
- Existing live reasoning, paging, collapse, resync and queued-send tests pass.
|
||||||
|
- Full gate: clean analysis and **1,850 tests pass**.
|
||||||
|
- Browser: 18 checks/10 captures per host in `build/reasoning-footer-material/`
|
||||||
|
and `build/reasoning-footer-cupertino/`, including actual footer geometry and
|
||||||
|
live reasoning updates. Both footer captures visually inspected.
|
||||||
|
- Web/APK publication pending. No backend changes, service restarts, production
|
||||||
|
chat/run mutations or device use. On-device behavior remains unverified.
|
||||||
@@ -161,7 +161,80 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (final cupertino in [false, true]) {
|
for (final cupertino in [false, true]) {
|
||||||
testWidgets('reasoning disclosure and tool chip follow the answer '
|
testWidgets(
|
||||||
|
'each message keeps its reasoning beside its own tools ($cupertino)',
|
||||||
|
(tester) async {
|
||||||
|
_phone(tester);
|
||||||
|
final first = _assistant([
|
||||||
|
{'type': 'text', 'text': 'First message'},
|
||||||
|
{'type': 'reasoning', 'text': 'First reasoning'},
|
||||||
|
{
|
||||||
|
'type': 'tool',
|
||||||
|
'name': 'read',
|
||||||
|
'state': {'status': 'completed'},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
final second = _assistant([
|
||||||
|
{'type': 'text', 'text': 'Second message'},
|
||||||
|
{'type': 'reasoning', 'text': 'Second reasoning'},
|
||||||
|
{
|
||||||
|
'type': 'tool',
|
||||||
|
'name': 'read',
|
||||||
|
'state': {'status': 'completed'},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'tool',
|
||||||
|
'name': 'write',
|
||||||
|
'state': {'status': 'completed'},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
final body = ListView(
|
||||||
|
children: [
|
||||||
|
ChatMessageView(key: const Key('message-first'), row: first),
|
||||||
|
ChatMessageView(key: const Key('message-second'), row: second),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
cupertino
|
||||||
|
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||||
|
: MaterialApp(home: Scaffold(body: body)),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
for (final (key, count) in [
|
||||||
|
('message-first', '1 tool'),
|
||||||
|
('message-second', '2 tools'),
|
||||||
|
]) {
|
||||||
|
final message = find.byKey(Key(key));
|
||||||
|
final reasoning = find.descendant(
|
||||||
|
of: message,
|
||||||
|
matching: find.text('Reasoning'),
|
||||||
|
);
|
||||||
|
final tools = find.descendant(
|
||||||
|
of: message,
|
||||||
|
matching: find.text(count),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.getRect(reasoning).right,
|
||||||
|
lessThan(tester.getRect(tools).left),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.getRect(reasoning).center.dy,
|
||||||
|
closeTo(tester.getRect(tools).center.dy, 2),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await tester.tap(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('message-first')),
|
||||||
|
matching: find.text('Reasoning'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('First reasoning'), findsOneWidget);
|
||||||
|
expect(find.text('Second reasoning'), findsNothing);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets('reasoning sits immediately left of the tools count '
|
||||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||||
// The test font draws every glyph as a full square, so the chips need
|
// The test font draws every glyph as a full square, so the chips need
|
||||||
// more room than real text does on a phone.
|
// more room than real text does on a phone.
|
||||||
@@ -191,7 +264,8 @@ void main() {
|
|||||||
reasoning.top,
|
reasoning.top,
|
||||||
greaterThan(tester.getRect(find.text('The answer')).bottom),
|
greaterThan(tester.getRect(find.text('The answer')).bottom),
|
||||||
);
|
);
|
||||||
expect(reasoning.bottom, lessThan(tools.top));
|
expect(reasoning.center.dy, closeTo(tools.center.dy, 2));
|
||||||
|
expect(reasoning.right, lessThan(tools.left));
|
||||||
|
|
||||||
// The inline disclosure opens with every recorded step.
|
// The inline disclosure opens with every recorded step.
|
||||||
await tester.tap(find.text('Reasoning · 2 steps'));
|
await tester.tap(find.text('Reasoning · 2 steps'));
|
||||||
|
|||||||
@@ -96,6 +96,17 @@ try {
|
|||||||
part: { id: 'reasoning-0', type: 'reasoning' }, delta: 'Checking the recorded evidence.' });
|
part: { id: 'reasoning-0', type: 'reasoning' }, delta: 'Checking the recorded evidence.' });
|
||||||
await event({ kind: 'text', message_id: 'live-answer',
|
await event({ kind: 'text', message_id: 'live-answer',
|
||||||
part: { id: 'text-0', type: 'text' }, delta: 'The answer is arriving.' });
|
part: { id: 'text-0', type: 'text' }, delta: 'The answer is arriving.' });
|
||||||
|
await event({ kind: 'tool', message_id: 'live-answer',
|
||||||
|
part: { id: 'tool-0', type: 'tool', name: 'read', state: { status: 'completed' } } });
|
||||||
|
const footerNodes = await axNodes(connection);
|
||||||
|
const reasoningControl = footerNodes.find(node => node.name?.value === 'Reasoning' && node.role?.value === 'button');
|
||||||
|
const toolsControl = footerNodes.find(node => node.name?.value === '1 tool call, expand for details');
|
||||||
|
assert.ok(reasoningControl?.backendDOMNodeId && toolsControl?.backendDOMNodeId, 'message footer controls');
|
||||||
|
const reasoningBox = (await connection.send('DOM.getBoxModel', { backendNodeId: reasoningControl.backendDOMNodeId })).model.content;
|
||||||
|
const toolsBox = (await connection.send('DOM.getBoxModel', { backendNodeId: toolsControl.backendDOMNodeId })).model.content;
|
||||||
|
assert.ok(reasoningBox[2] < toolsBox[0], 'reasoning is left of tools');
|
||||||
|
assert.ok(Math.abs((reasoningBox[1] + reasoningBox[5]) / 2 - (toolsBox[1] + toolsBox[5]) / 2) < 3, 'same footer row');
|
||||||
|
log.checks.push('per-message reasoning is immediately left of tools count');
|
||||||
await assertPainted('Checking the recorded evidence.', 'reasoning visible while text streams', 'chat-live-reasoning');
|
await assertPainted('Checking the recorded evidence.', 'reasoning visible while text streams', 'chat-live-reasoning');
|
||||||
await assertPainted('The answer is arriving.', 'streamed answer visible', 'chat-live-answer');
|
await assertPainted('The answer is arriving.', 'streamed answer visible', 'chat-live-answer');
|
||||||
const field = (await axNodes(connection)).find(node => node.role?.value === 'textbox');
|
const field = (await axNodes(connection)).find(node => node.role?.value === 'textbox');
|
||||||
|
|||||||
Reference in New Issue
Block a user