feat(chat): ChatGPT-style transcript and composer
Agent replies sit on the page without a bubble and get a copy control; the operator's turn is a neutral rounded bubble; the composer is one filled pill with +, a borderless field and a round Send, and its placeholder names the chat's folder. Also fixes two picker tests left stale by the native picker.
This commit is contained in:
@@ -19,8 +19,16 @@ import 'chat_command_actions.dart';
|
||||
import 'chat_command_palette.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
|
||||
/// The composer's multiline placeholder, verbatim from the web client.
|
||||
const String chatComposerPlaceholder = 'Message the agent… or / for commands';
|
||||
/// The composer's placeholder when the chat names no working directory.
|
||||
const String chatComposerPlaceholder = 'Message the agent';
|
||||
|
||||
/// The composer's placeholder for a chat working in [directory]: its folder
|
||||
/// name, as the operator would say it, or the generic placeholder without one.
|
||||
String chatComposerPlaceholderFor(String directory) {
|
||||
final parts = directory.trim().split(RegExp(r'[/\\]'));
|
||||
final name = parts.lastWhere((part) => part.isNotEmpty, orElse: () => '');
|
||||
return name.isEmpty ? chatComposerPlaceholder : 'Work on $name';
|
||||
}
|
||||
|
||||
/// The single primary control's words while a turn is and is not running.
|
||||
const String chatSendLabel = 'Send';
|
||||
@@ -73,10 +81,14 @@ class ChatComposerBar extends StatefulWidget {
|
||||
this.commands,
|
||||
this.paste,
|
||||
this.backgroundTasks,
|
||||
this.placeholder = chatComposerPlaceholder,
|
||||
});
|
||||
|
||||
final ChatComposerController composer;
|
||||
|
||||
/// The empty field's hint; see [chatComposerPlaceholderFor].
|
||||
final String placeholder;
|
||||
|
||||
/// Runs `/new`, `/close` and `/rename` for the open session. A host without a
|
||||
/// session (null) keeps those commands on the unavailable report.
|
||||
final ChatCommandActions? commands;
|
||||
@@ -615,39 +627,33 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
text: error,
|
||||
failed: true,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_attach(context, cupertino),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
includeSemantics: false,
|
||||
onKeyEvent: _onKey,
|
||||
child: _field(cupertino),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
if (widget.backgroundTasks != null)
|
||||
widget.backgroundTasks!,
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (widget.running) ...[
|
||||
_primary(context, cupertino, stop: true),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
_primary(context, cupertino),
|
||||
],
|
||||
if (widget.backgroundTasks != null)
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: widget.backgroundTasks!,
|
||||
),
|
||||
_pill(
|
||||
context,
|
||||
cupertino,
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_attach(context, cupertino),
|
||||
Expanded(
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
includeSemantics: false,
|
||||
onKeyEvent: _onKey,
|
||||
child: _field(cupertino),
|
||||
),
|
||||
),
|
||||
if (widget.running) ...[
|
||||
_primary(context, cupertino, stop: true),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
],
|
||||
_primary(context, cupertino),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -657,6 +663,23 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The field and its controls in one rounded filled surface, in the host's
|
||||
/// own fill role, so the composer reads as a single input rather than a row
|
||||
/// of separate controls.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) {
|
||||
final fill = cupertino
|
||||
? CupertinoColors.systemGrey6.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
return DecoratedBox(
|
||||
key: const Key('chat-composer-pill'),
|
||||
decoration: BoxDecoration(
|
||||
color: fill,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(28)),
|
||||
),
|
||||
child: Padding(padding: const EdgeInsets.all(4), child: child),
|
||||
);
|
||||
}
|
||||
|
||||
/// The attach control: a host button that opens the picker, disabled when the
|
||||
/// host has no picker or one prompt is already awaiting its reply.
|
||||
Widget _attach(BuildContext context, bool cupertino) {
|
||||
@@ -672,7 +695,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
key: const Key('chat-composer-attach'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onPressed,
|
||||
child: const Icon(CupertinoIcons.paperclip),
|
||||
child: const Icon(CupertinoIcons.add),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -681,7 +704,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
key: const Key('chat-composer-attach'),
|
||||
tooltip: chatAttachLabel,
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(Icons.attach_file),
|
||||
icon: const Icon(Icons.add),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -875,7 +898,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
if (!width.isFinite) return 1;
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: chatComposerPlaceholder,
|
||||
text: widget.placeholder,
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
),
|
||||
textDirection: Directionality.of(context),
|
||||
@@ -904,7 +927,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
key: const Key('chat-composer-field'),
|
||||
controller: _text,
|
||||
focusNode: _focus,
|
||||
placeholder: chatComposerPlaceholder,
|
||||
placeholder: widget.placeholder,
|
||||
// The pill draws the field's surface; the field adds no border.
|
||||
decoration: null,
|
||||
placeholderStyle: const TextStyle(
|
||||
color: CupertinoColors.placeholderText,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -933,12 +958,15 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
onEditingComplete: () {},
|
||||
onSubmitted: (_) => _submitDraft(),
|
||||
onChanged: _onDraftEdited,
|
||||
decoration: const InputDecoration(
|
||||
hintText: chatComposerPlaceholder,
|
||||
// Let the complete, web-matched hint wrap when the attachment and
|
||||
// primary controls leave little horizontal room.
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.placeholder,
|
||||
// Let a long folder name wrap when the attach and primary controls
|
||||
// leave little horizontal room.
|
||||
hintMaxLines: 2,
|
||||
border: OutlineInputBorder(),
|
||||
// The pill draws the field's surface; the field adds no border.
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -998,7 +1026,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
onPressed: enabled ? press : null,
|
||||
icon: stop
|
||||
? const ChatStopIcon(child: Icon(Icons.stop))
|
||||
: const Icon(Icons.send),
|
||||
: const Icon(Icons.arrow_upward),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -901,6 +901,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
running: _controller.running,
|
||||
commands: _commandActions(),
|
||||
picker: widget.attachmentPicker,
|
||||
placeholder: chatComposerPlaceholderFor(
|
||||
'${widget.session?['directory'] ?? ''}',
|
||||
),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The accessible name of a reply's copy control, and its name just after a
|
||||
/// copy succeeded.
|
||||
const String chatCopyLabel = 'Copy';
|
||||
const String chatCopiedLabel = 'Copied';
|
||||
|
||||
/// An icon-only control beneath a finished reply that puts the reply's text on
|
||||
/// the clipboard. It shows a check for a moment after copying, so the operator
|
||||
/// sees the copy landed without a separate toast.
|
||||
class ChatCopyButton extends StatefulWidget {
|
||||
const ChatCopyButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<ChatCopyButton> createState() => _ChatCopyButtonState();
|
||||
}
|
||||
|
||||
class _ChatCopyButtonState extends State<ChatCopyButton> {
|
||||
bool _copied = false;
|
||||
Timer? _reset;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_reset?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _copy() async {
|
||||
await Clipboard.setData(ClipboardData(text: widget.text));
|
||||
if (!mounted) return;
|
||||
setState(() => _copied = true);
|
||||
_reset?.cancel();
|
||||
_reset = Timer(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _copied = false);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = _copied ? chatCopiedLabel : chatCopyLabel;
|
||||
if (widget.cupertino) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: const Key('chat-message-copy'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _copy,
|
||||
child: Icon(
|
||||
_copied ? CupertinoIcons.checkmark : CupertinoIcons.doc_on_doc,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
key: const Key('chat-message-copy'),
|
||||
tooltip: label,
|
||||
onPressed: _copy,
|
||||
icon: Icon(_copied ? Icons.check : Icons.copy_outlined),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The operator's turn: a neutral filled, evenly rounded bubble with no border,
|
||||
/// in the host's own surface roles. The agent's turn has no bubble at all; its
|
||||
/// text sits on the page, so only the operator's words are enclosed.
|
||||
class ChatUserBubble extends StatelessWidget {
|
||||
const ChatUserBubble({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final Widget child;
|
||||
|
||||
static const BorderRadius _radius = BorderRadius.all(Radius.circular(20));
|
||||
static const EdgeInsets _padding = EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (cupertino) {
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.systemGrey5.resolveFrom(context),
|
||||
borderRadius: _radius,
|
||||
),
|
||||
child: Padding(padding: _padding, child: child),
|
||||
);
|
||||
}
|
||||
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
||||
// inside the bubble keeps its ink and background.
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: const RoundedRectangleBorder(borderRadius: _radius),
|
||||
child: Padding(padding: _padding, child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The agent's answer drawn straight on the page. Material keeps a transparent
|
||||
/// surface so disclosure ListTiles still paint their ink.
|
||||
class ChatAgentSurface extends StatelessWidget {
|
||||
const ChatAgentSurface({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => cupertino
|
||||
? child
|
||||
: Material(type: MaterialType.transparency, child: child);
|
||||
}
|
||||
|
||||
/// The transcript's reading text: the host's large body role, so answers read
|
||||
/// at a comfortable size and still follow the operator's text scaling.
|
||||
TextStyle? chatMessageTextStyle(BuildContext context, bool cupertino) =>
|
||||
cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyLarge;
|
||||
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import '../../domain/chat_tool_calls.dart';
|
||||
import 'chat_copy_button.dart';
|
||||
import 'chat_message_bubble.dart';
|
||||
import 'chat_turn_activity_view.dart';
|
||||
import 'native_disclosure.dart';
|
||||
|
||||
@@ -34,40 +36,18 @@ class ChatMessageView extends StatelessWidget {
|
||||
final role = user ? 'User' : 'Assistant';
|
||||
final cupertino = _isCupertino(context);
|
||||
final content = user ? _userParts(context) : _agentParts(context);
|
||||
// No visible role label, as on the web: side and colour say who spoke and
|
||||
// the row's semantics label names the role. The bubble shrinks to its
|
||||
// content (a disclosure still takes the full measure).
|
||||
final body = Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: content,
|
||||
// No visible role label: side and surface say who spoke and the row's
|
||||
// semantics label names the role. The operator's turn is a neutral bubble
|
||||
// that shrinks to its content; the agent's answer sits on the page with no
|
||||
// bubble, so long replies read as a document rather than a balloon.
|
||||
final body = DefaultTextStyle.merge(
|
||||
style: chatMessageTextStyle(context, cupertino),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: content,
|
||||
),
|
||||
);
|
||||
// The web draws the operator's turn right-aligned in an accent-tinted bubble
|
||||
// and the agent's left-aligned on the neutral surface, both capped to a
|
||||
// readable measure.
|
||||
final contentBody = cupertino
|
||||
? DefaultTextStyle.merge(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: body,
|
||||
)
|
||||
: body;
|
||||
// A Material surface (not a bare DecoratedBox) so the disclosure ListTiles
|
||||
// inside the bubble keep their ink and background.
|
||||
final bubble = cupertino
|
||||
? Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: _bubbleDecoration(context, cupertino, user: user),
|
||||
child: contentBody,
|
||||
)
|
||||
: Material(
|
||||
color: _bubbleColor(context, cupertino, user: user),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: _bubbleShape(context, cupertino, user: user),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
child: contentBody,
|
||||
),
|
||||
);
|
||||
return Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
@@ -81,13 +61,20 @@ class ChatMessageView extends StatelessWidget {
|
||||
: AlignmentDirectional.centerStart,
|
||||
child: ConstrainedBox(
|
||||
// The operator's turn leaves a margin on a phone, so the two
|
||||
// sides read as a conversation.
|
||||
// sides read as a conversation; the answer keeps a readable
|
||||
// measure on a wide pane.
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: user
|
||||
? (constraints.maxWidth * 0.85).clamp(0, 560).toDouble()
|
||||
: 560,
|
||||
: 720,
|
||||
),
|
||||
child: user ? bubble : _agentTurn(context, content, bubble),
|
||||
child: user
|
||||
? ChatUserBubble(cupertino: cupertino, child: body)
|
||||
: _agentTurn(
|
||||
context,
|
||||
content,
|
||||
ChatAgentSurface(cupertino: cupertino, child: body),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -95,75 +82,6 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Color _bubbleColor(
|
||||
BuildContext context,
|
||||
bool cupertino, {
|
||||
required bool user,
|
||||
}) {
|
||||
final accent = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final surface = cupertino
|
||||
? CupertinoColors.secondarySystemGroupedBackground.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerLow;
|
||||
return user ? accent.withValues(alpha: 0.16) : surface;
|
||||
}
|
||||
|
||||
ShapeBorder _bubbleShape(
|
||||
BuildContext context,
|
||||
bool cupertino, {
|
||||
required bool user,
|
||||
}) {
|
||||
final accent = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final border = cupertino
|
||||
? CupertinoColors.separator.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.outlineVariant;
|
||||
return RoundedRectangleBorder(
|
||||
side: BorderSide(color: user ? accent.withValues(alpha: 0.4) : border),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: const Radius.circular(12),
|
||||
topRight: const Radius.circular(12),
|
||||
bottomLeft: Radius.circular(user ? 12 : 4),
|
||||
bottomRight: Radius.circular(user ? 4 : 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
BoxDecoration _bubbleDecoration(
|
||||
BuildContext context,
|
||||
bool cupertino, {
|
||||
required bool user,
|
||||
}) {
|
||||
final Color accent;
|
||||
final Color surface;
|
||||
final Color border;
|
||||
if (cupertino) {
|
||||
accent = CupertinoTheme.of(context).primaryColor;
|
||||
surface = CupertinoColors.secondarySystemGroupedBackground.resolveFrom(
|
||||
context,
|
||||
);
|
||||
border = CupertinoColors.separator.resolveFrom(context);
|
||||
} else {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
accent = scheme.primary;
|
||||
surface = scheme.surfaceContainerLow;
|
||||
border = scheme.outlineVariant;
|
||||
}
|
||||
final radius = BorderRadius.only(
|
||||
topLeft: const Radius.circular(12),
|
||||
topRight: const Radius.circular(12),
|
||||
bottomLeft: Radius.circular(user ? 12 : 4),
|
||||
bottomRight: Radius.circular(user ? 4 : 12),
|
||||
);
|
||||
return BoxDecoration(
|
||||
color: user ? accent.withValues(alpha: 0.16) : surface,
|
||||
border: Border.all(color: user ? accent.withValues(alpha: 0.4) : border),
|
||||
borderRadius: radius,
|
||||
);
|
||||
}
|
||||
|
||||
Color _secondaryColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
@@ -198,7 +116,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
|
||||
/// Stable activity precedes the answer; permission summaries and recorded
|
||||
/// model remain beneath it. Pending interaction cards are rendered separately.
|
||||
Widget _agentTurn(BuildContext context, List<Widget> content, Widget bubble) {
|
||||
Widget _agentTurn(BuildContext context, List<Widget> content, Widget answer) {
|
||||
final parts = _partsOf(row);
|
||||
final reasoning = [
|
||||
for (final part in parts)
|
||||
@@ -211,7 +129,10 @@ class ChatMessageView extends StatelessWidget {
|
||||
if (isChatToolPart(part)) part,
|
||||
];
|
||||
final model = '${row['model'] ?? ''}'.trim();
|
||||
final copyText = row['streaming'] == true ? '' : _answerText(parts);
|
||||
final footer = <Widget>[
|
||||
if (copyText.isNotEmpty)
|
||||
ChatCopyButton(text: copyText, cupertino: _isCupertino(context)),
|
||||
...this.footer,
|
||||
if (model.isNotEmpty)
|
||||
Text(
|
||||
@@ -241,9 +162,9 @@ class ChatMessageView extends StatelessWidget {
|
||||
],
|
||||
streaming: row['streaming'] == true,
|
||||
),
|
||||
// A little air between the one-line turn status and the answer bubble.
|
||||
// A little air between the one-line turn status and the answer.
|
||||
if (content.isNotEmpty) const SizedBox(height: 6),
|
||||
if (content.isNotEmpty) bubble,
|
||||
if (content.isNotEmpty) answer,
|
||||
if (footer.isNotEmpty)
|
||||
Wrap(
|
||||
key: const Key('chat-message-footer'),
|
||||
@@ -255,6 +176,16 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// The answer as the operator reads it: the turn's text parts in order,
|
||||
/// without reasoning, tools or attachments.
|
||||
String _answerText(List<JsonMap> parts) => [
|
||||
for (final part in parts)
|
||||
if ((part['type'] == null || part['type'] == 'text') &&
|
||||
part['text'] is String &&
|
||||
(part['text'] as String).trim().isNotEmpty)
|
||||
(part['text'] as String).trim(),
|
||||
].join('\n\n');
|
||||
|
||||
List<Widget> _agentParts(BuildContext context) {
|
||||
final widgets = <Widget>[];
|
||||
final parts = _partsOf(row);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# Chat: ChatGPT-style transcript and composer
|
||||
|
||||
Branch `chat/chatgpt-look`.
|
||||
|
||||
- Agent replies render on the page with no bubble (`ChatAgentSurface`), in the
|
||||
host's large body role; the readable cap on wide panes is 720.
|
||||
- The operator's turn is a neutral filled bubble with an even radius and no
|
||||
border (`ChatUserBubble`).
|
||||
- A finished reply with text has an icon-only copy control
|
||||
(`chat-message-copy`) that copies its text parts and shows a check for 2 s.
|
||||
Streaming or text-less turns have none. The per-reply model label stays.
|
||||
- The composer is one rounded filled pill (`chat-composer-pill`) holding "+"
|
||||
(opens the host picker directly, same key `chat-composer-attach`), a
|
||||
borderless field and a round arrow Send (Stop beside it while running).
|
||||
Background tasks sit above the pill at the end.
|
||||
- Placeholder is `Work on <folder>` from the session's `directory`, else
|
||||
`Message the agent`; slash commands still start with `/`.
|
||||
- Fixed two picker tests left stale by the native picker (962b358a): they now
|
||||
inject `ChatAttachmentPicker.unsupported` instead of relying on the VM host.
|
||||
|
||||
## Checks
|
||||
|
||||
- `flutter test`: 1992 passed. `flutter analyze`: one pre-existing info in
|
||||
`test/features/artifacts/ui/artifact_viewer_page_test.dart`.
|
||||
- Chrome captures of `tool/chat_composer_probe_entry.dart` at 390x844, Material
|
||||
light and Cupertino dark, show the bubble-less reply, copy control, gray
|
||||
user bubble and pill composer.
|
||||
- Both `tool/chat_composer_probe.mjs` (expects Enter to insert a newline; Enter
|
||||
now sends) and `tool/chat_message_probe.mjs` (expects the old "Reasoning,
|
||||
expand for details" activity label) fail on checks that predate this change.
|
||||
The message probe's semantics dump does show the new `Copy` control.
|
||||
- Not verified on a device.
|
||||
@@ -207,7 +207,10 @@ void main() {
|
||||
testWidgets('the attach control is disabled without a host picker', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpBar(tester);
|
||||
await pumpBar(
|
||||
tester,
|
||||
picker: const ChatAttachmentPicker.unsupported('No picker here.'),
|
||||
);
|
||||
|
||||
final attach = tester.widget<IconButton>(
|
||||
find.byKey(const Key('chat-composer-attach')),
|
||||
|
||||
@@ -76,10 +76,12 @@ Widget composerThread(
|
||||
ChatDraftStore? drafts,
|
||||
String Function()? newOperationId,
|
||||
VoidCallback? onBack,
|
||||
JsonMap? session,
|
||||
}) {
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
session: session,
|
||||
syncToken: syncToken,
|
||||
onBack: onBack ?? () {},
|
||||
drafts: drafts ?? MemoryChatDraftStore(),
|
||||
|
||||
@@ -30,4 +30,47 @@ void main() {
|
||||
expect(paragraph.overflow, TextOverflow.ellipsis);
|
||||
}
|
||||
});
|
||||
|
||||
test('the placeholder names the chat\'s folder when it has one', () {
|
||||
expect(chatComposerPlaceholderFor('/Users/ada/repos/tank'), 'Work on tank');
|
||||
expect(
|
||||
chatComposerPlaceholderFor('/Users/ada/repos/tank/'),
|
||||
'Work on tank',
|
||||
);
|
||||
expect(chatComposerPlaceholderFor(r'C:\\work\\tank'), 'Work on tank');
|
||||
expect(chatComposerPlaceholderFor(' '), chatComposerPlaceholder);
|
||||
expect(chatComposerPlaceholderFor('/'), chatComposerPlaceholder);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('the composer is one pill holding attach, field and Send '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
composerThread(
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final pill = find.byKey(const Key('chat-composer-pill'));
|
||||
for (final key in [
|
||||
'chat-composer-attach',
|
||||
'chat-composer-field',
|
||||
'chat-composer-primary',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(of: pill, matching: find.byKey(Key(key))),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
find.descendant(of: pill, matching: find.text('Work on tank')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker_stub.dart';
|
||||
|
||||
void main() {
|
||||
test('passes the chosen names, MIME types and bytes through', () async {
|
||||
@@ -58,8 +59,12 @@ void main() {
|
||||
expect(opened, 1);
|
||||
});
|
||||
|
||||
test('the host picker reports its unsupported capability honestly', () async {
|
||||
final picker = hostChatAttachmentPicker;
|
||||
// The test VM is a dart:io host, which now has the native picker, so the
|
||||
// unsupported path is exercised through the stub's own picker.
|
||||
test('an unsupported host picker reports its capability honestly', () async {
|
||||
const picker = ChatAttachmentPicker.unsupported(
|
||||
chatAttachmentUnsupportedMessage,
|
||||
);
|
||||
|
||||
expect(picker.isSupported, isFalse);
|
||||
await expectLater(
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
|
||||
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
|
||||
|
||||
final JsonMap _answer = _row({
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{'type': 'reasoning', 'text': 'Thinking it over'},
|
||||
{'type': 'text', 'text': 'First paragraph.'},
|
||||
{'type': 'text', 'text': 'Second paragraph.'},
|
||||
],
|
||||
});
|
||||
|
||||
final JsonMap _question = _row({
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Please prepare the system'},
|
||||
],
|
||||
});
|
||||
|
||||
Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
|
||||
final body = ListView(
|
||||
children: [for (final row in rows) ChatMessageView(row: row)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(home: CupertinoPageScaffold(child: body));
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'cupertino' : 'material';
|
||||
|
||||
testWidgets('only the operator turn is a bubble ($style)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
|
||||
Finder bubbleAround(String text) => find.ancestor(
|
||||
of: find.text(text),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
);
|
||||
expect(bubbleAround('Please prepare the system'), findsOneWidget);
|
||||
expect(bubbleAround('First paragraph.'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('First paragraph.'),
|
||||
matching: find.byType(ChatAgentSurface),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a finished reply copies its answer text ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
|
||||
// The operator's own turn has nothing to copy beneath it.
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-message-copy')));
|
||||
await tester.pump();
|
||||
|
||||
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
|
||||
final done = cupertino ? CupertinoIcons.checkmark : Icons.check;
|
||||
final copy = cupertino ? CupertinoIcons.doc_on_doc : Icons.copy_outlined;
|
||||
expect(find.byIcon(done), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(find.byIcon(copy), findsOneWidget);
|
||||
expect(find.byIcon(done), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a streaming or text-less reply offers no copy', (tester) async {
|
||||
final streaming = {..._answer, 'streaming': true};
|
||||
final reasoningOnly = _row({
|
||||
'id': 'a2',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{'type': 'reasoning', 'text': 'Only thinking'},
|
||||
],
|
||||
});
|
||||
await tester.pumpWidget(_host([streaming, reasoningOnly]));
|
||||
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user