fix(chat): keep provided reasoning visible during live replies
This commit is contained in:
@@ -7,6 +7,7 @@ import '../../../../core/api_gateway.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import '../../domain/chat_tool_calls.dart';
|
||||
import 'chat_tool_calls_view.dart';
|
||||
import 'chat_reasoning_disclosure.dart';
|
||||
import 'native_disclosure.dart';
|
||||
|
||||
/// Builds an assistant text part; the default keeps the server's text exactly.
|
||||
@@ -188,8 +189,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
return widgets;
|
||||
}
|
||||
|
||||
/// The agent turn: the answer in the bubble, then one row with its reasoning
|
||||
/// and tool-call chips, each opening its own sheet.
|
||||
/// Reasoning stays in the transcript so an open body follows live deltas.
|
||||
Widget _agentTurn(BuildContext context, List<Widget> content, Widget bubble) {
|
||||
final parts = _partsOf(row);
|
||||
final reasoning = [
|
||||
@@ -208,13 +208,17 @@ class ChatMessageView extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (content.isNotEmpty) bubble,
|
||||
// Reasoning and tool calls share one quiet row below the answer.
|
||||
if (reasoning.isNotEmpty || tools.isNotEmpty || model.isNotEmpty)
|
||||
if (reasoning.isNotEmpty)
|
||||
ChatReasoningDisclosure(
|
||||
key: const Key('chat-turn-reasoning'),
|
||||
steps: reasoning,
|
||||
streaming: row['streaming'] == true,
|
||||
),
|
||||
if (tools.isNotEmpty || model.isNotEmpty)
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (reasoning.isNotEmpty) ChatReasoningChip(steps: reasoning),
|
||||
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
|
||||
// Which model answered, quietly, after the chips.
|
||||
if (model.isNotEmpty)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'native_disclosure.dart';
|
||||
|
||||
/// Only reasoning actually supplied by the backend. Keeping its body in the
|
||||
/// transcript (rather than a modal snapshot) lets an open disclosure rebuild
|
||||
/// with every delta, even while answer text is also arriving.
|
||||
class ChatReasoningDisclosure extends StatelessWidget {
|
||||
const ChatReasoningDisclosure({
|
||||
super.key,
|
||||
required this.steps,
|
||||
required this.streaming,
|
||||
});
|
||||
|
||||
final List<String> steps;
|
||||
final bool streaming;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final label = steps.length == 1
|
||||
? 'Reasoning'
|
||||
: 'Reasoning · ${steps.length} steps';
|
||||
final disclosure = NativeDisclosure(
|
||||
key: const Key('chat-reasoning-disclosure'),
|
||||
label: label,
|
||||
initiallyExpanded: streaming,
|
||||
childBuilder: (_) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (final (index, step) in steps.indexed)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: index == 0 ? 0 : 12, bottom: 8),
|
||||
child: SelectableText(step),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// Material's native ExpansionTile needs a surface; Cupertino must not
|
||||
// acquire a Material dependency just to show its own disclosure button.
|
||||
return DefaultTextStyle.merge(
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium,
|
||||
child: cupertino
|
||||
? disclosure
|
||||
: Material(color: Colors.transparent, child: disclosure),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -54,39 +54,7 @@ class ChatToolCallsChip extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// A turn's reasoning as a chip beside its tool chip, the same way: `Reasoning`
|
||||
/// or `Reasoning · N steps`, opening a sheet with the steps.
|
||||
class ChatReasoningChip extends StatelessWidget {
|
||||
const ChatReasoningChip({super.key, required this.steps});
|
||||
|
||||
final List<String> steps;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final label = steps.length == 1
|
||||
? 'Reasoning'
|
||||
: 'Reasoning · ${steps.length} steps';
|
||||
return _TurnChip(
|
||||
chipKey: const Key('chat-reasoning-chip'),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.lightbulb : Icons.lightbulb_outline,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
label: label,
|
||||
color: color,
|
||||
semanticsLabel: '$label, expand for details',
|
||||
sheet: _ReasoningSheet(label: label, steps: steps),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The quiet chip shell both turn summaries share, and its native sheet.
|
||||
/// The quiet tool chip shell and its native sheet.
|
||||
class _TurnChip extends StatelessWidget {
|
||||
const _TurnChip({
|
||||
required this.chipKey,
|
||||
@@ -171,49 +139,6 @@ class _TurnChip extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _ReasoningSheet extends StatelessWidget {
|
||||
const _ReasoningSheet({required this.label, required this.steps});
|
||||
|
||||
final String label;
|
||||
final List<String> steps;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return DefaultTextStyle.merge(
|
||||
style: style,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
),
|
||||
child: ListView(
|
||||
key: const Key('chat-reasoning-sheet'),
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
for (final (index, step) in steps.indexed)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: index == 0 ? 0 : 12),
|
||||
child: SelectableText(step),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ToolCallsSheet extends StatelessWidget {
|
||||
const _ToolCallsSheet({required this.calls});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// A collapsed block opened with the host's own disclosure control.
|
||||
/// A block opened with the host's own disclosure control (collapsed by default).
|
||||
///
|
||||
/// [childBuilder] runs only while the block is open, so a closed disclosure
|
||||
/// never encodes or lays out its body.
|
||||
@@ -12,17 +12,19 @@ class NativeDisclosure extends StatefulWidget {
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.childBuilder,
|
||||
this.initiallyExpanded = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final WidgetBuilder childBuilder;
|
||||
final bool initiallyExpanded;
|
||||
|
||||
@override
|
||||
State<NativeDisclosure> createState() => _NativeDisclosureState();
|
||||
}
|
||||
|
||||
class _NativeDisclosureState extends State<NativeDisclosure> {
|
||||
bool _expanded = false;
|
||||
late bool _expanded = widget.initiallyExpanded;
|
||||
|
||||
void _toggle() => setState(() => _expanded = !_expanded);
|
||||
|
||||
@@ -31,6 +33,7 @@ class _NativeDisclosureState extends State<NativeDisclosure> {
|
||||
if (chatControlsStyleOf(context) != ChatControlsStyle.cupertino) {
|
||||
return ExpansionTile(
|
||||
title: Text(widget.label),
|
||||
initiallyExpanded: widget.initiallyExpanded,
|
||||
maintainState: false,
|
||||
// A transcript block starts at the row edge, like its answer text; the
|
||||
// tile's own padding would indent it, and its body defaults to centred,
|
||||
|
||||
Reference in New Issue
Block a user