Wash the operator's bubbles softly in the chat colour
A coloured chat's own messages blend 22% of its shade over the host's neutral bubble fill; text keeps the host colours and uncoloured chats are unchanged.
This commit is contained in:
@@ -25,6 +25,7 @@ import '../ui/sessions/chat_color_picker.dart';
|
|||||||
import '../ui/sessions/session_actions.dart';
|
import '../ui/sessions/session_actions.dart';
|
||||||
import '../ui/sessions/session_row_content.dart';
|
import '../ui/sessions/session_row_content.dart';
|
||||||
import '../ui/transcript/chat_markdown_view.dart';
|
import '../ui/transcript/chat_markdown_view.dart';
|
||||||
|
import '../ui/transcript/chat_message_bubble.dart';
|
||||||
import '../ui/transcript/chat_message_view.dart';
|
import '../ui/transcript/chat_message_view.dart';
|
||||||
import '../ui/transcript/chat_transcript_selection.dart';
|
import '../ui/transcript/chat_transcript_selection.dart';
|
||||||
import '../ui/transcript/chat_injected_rows.dart';
|
import '../ui/transcript/chat_injected_rows.dart';
|
||||||
@@ -989,360 +990,366 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => AnimatedBuilder(
|
Widget build(BuildContext context) => ChatBubbleColor(
|
||||||
animation: Listenable.merge([
|
// The operator's own bubbles take a soft wash of the chat's colour.
|
||||||
_controller.transcriptChanges,
|
name: chatSessionColor(widget.session),
|
||||||
_composer.deliveries,
|
child: AnimatedBuilder(
|
||||||
_shellRuns.membership,
|
animation: Listenable.merge([
|
||||||
]),
|
_controller.transcriptChanges,
|
||||||
builder: (context, _) {
|
_composer.deliveries,
|
||||||
final cupertino =
|
_shellRuns.membership,
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
]),
|
||||||
final messages = _visibleMessages();
|
builder: (context, _) {
|
||||||
final cards = chatCardRows(
|
final cupertino =
|
||||||
permissions: _controller.permissionFrames,
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||||
forms: _controller.questionForms,
|
final messages = _visibleMessages();
|
||||||
answerFor: _controller.permissionAnswerFor,
|
final cards = chatCardRows(
|
||||||
permissionErrorFor: _controller.permissionErrorFor,
|
permissions: _controller.permissionFrames,
|
||||||
formErrorFor: _controller.questionErrorFor,
|
forms: _controller.questionForms,
|
||||||
);
|
answerFor: _controller.permissionAnswerFor,
|
||||||
// Answered approvals and questions fold into their turn's chips, like
|
permissionErrorFor: _controller.permissionErrorFor,
|
||||||
// tool calls; only cards still waiting on the operator stay full cards.
|
formErrorFor: _controller.questionErrorFor,
|
||||||
// A turn that changed files carries its summary for the change chip.
|
);
|
||||||
final allRows = attachChatTurnDiffs(
|
// Answered approvals and questions fold into their turn's chips, like
|
||||||
groupSettledQuestions(
|
// tool calls; only cards still waiting on the operator stay full cards.
|
||||||
groupSettledPermissions(
|
// A turn that changed files carries its summary for the change chip.
|
||||||
withChatShownItems(
|
final allRows = attachChatTurnDiffs(
|
||||||
transcriptRows(
|
groupSettledQuestions(
|
||||||
messages,
|
groupSettledPermissions(
|
||||||
trailing: cards,
|
withChatShownItems(
|
||||||
running:
|
transcriptRows(
|
||||||
_controller.running &&
|
messages,
|
||||||
!_reconnecting &&
|
trailing: cards,
|
||||||
!_staleTranscript &&
|
running:
|
||||||
!cards.any(chatCardAwaitingOperator),
|
_controller.running &&
|
||||||
awaitingResponse:
|
!_reconnecting &&
|
||||||
_controller.awaitingResponse &&
|
!_staleTranscript &&
|
||||||
!_reconnecting &&
|
!cards.any(chatCardAwaitingOperator),
|
||||||
!_staleTranscript &&
|
awaitingResponse:
|
||||||
!cards.any(chatCardAwaitingOperator),
|
_controller.awaitingResponse &&
|
||||||
liveMessageId: _controller.liveAssistantMessageId,
|
!_reconnecting &&
|
||||||
|
!_staleTranscript &&
|
||||||
|
!cards.any(chatCardAwaitingOperator),
|
||||||
|
liveMessageId: _controller.liveAssistantMessageId,
|
||||||
|
),
|
||||||
|
// Placed only against a loaded transcript, so an entry never
|
||||||
|
// leads an empty one and then jumps down when history arrives.
|
||||||
|
_controller.loaded ? _controller.shown : const [],
|
||||||
|
hasMore: _controller.hasMore,
|
||||||
),
|
),
|
||||||
// Placed only against a loaded transcript, so an entry never
|
|
||||||
// leads an empty one and then jumps down when history arrives.
|
|
||||||
_controller.loaded ? _controller.shown : const [],
|
|
||||||
hasMore: _controller.hasMore,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
_controller.turnDiffs,
|
||||||
_controller.turnDiffs,
|
);
|
||||||
);
|
// A transcript held from before a socket gap may still say a compaction is
|
||||||
// A transcript held from before a socket gap may still say a compaction is
|
// running even when the repair's read is refused. That running state is
|
||||||
// running even when the repair's read is refused. That running state is
|
// stale, so no compaction notice is derived from it until a fresh read or
|
||||||
// stale, so no compaction notice is derived from it until a fresh read or
|
// frame replaces the transcript. Fresh failure notices still report.
|
||||||
// frame replaces the transcript. Fresh failure notices still report.
|
//
|
||||||
//
|
// Notices report recorded conditions only: a refused read/watch and a
|
||||||
// Notices report recorded conditions only: a refused read/watch and a
|
// running compaction. A dismissal keeps one hidden until its condition
|
||||||
// running compaction. A dismissal keeps one hidden until its condition
|
// changes. A running compaction's own activity line is that notice, so it
|
||||||
// changes. A running compaction's own activity line is that notice, so it
|
// is not drawn twice; hiding it when dismissed is the whole dismissal.
|
||||||
// is not drawn twice; hiding it when dismissed is the whole dismissal.
|
final allNotices = _reconnecting
|
||||||
final allNotices = _reconnecting
|
? const <ChatNotice>[]
|
||||||
? const <ChatNotice>[]
|
: chatNotices(
|
||||||
: chatNotices(
|
historyError: _controller.error,
|
||||||
historyError: _controller.error,
|
liveError: _controller.subscriptionError,
|
||||||
liveError: _controller.subscriptionError,
|
messages: _staleTranscript ? const [] : _controller.messages,
|
||||||
messages: _staleTranscript ? const [] : _controller.messages,
|
);
|
||||||
);
|
final notices = _dismissals.visible(allNotices);
|
||||||
final notices = _dismissals.visible(allNotices);
|
final compactionNotice = _noticeOf(notices, ChatNoticeKind.compaction);
|
||||||
final compactionNotice = _noticeOf(notices, ChatNoticeKind.compaction);
|
// The operator's own shell commands sit among the turns by start time;
|
||||||
// The operator's own shell commands sit among the turns by start time;
|
// dismissed ones fold into a chip under the answer that followed them.
|
||||||
// dismissed ones fold into a chip under the answer that followed them.
|
final rows = attachChatShellHistory(
|
||||||
final rows = attachChatShellHistory(
|
withChatShellRunRows([
|
||||||
withChatShellRunRows([
|
for (final row in allRows)
|
||||||
for (final row in allRows)
|
if (!_hiddenRunningCompaction(row)) row,
|
||||||
if (!_hiddenRunningCompaction(row)) row,
|
], _shellRuns.runs),
|
||||||
], _shellRuns.runs),
|
_shellRuns.dismissedRuns,
|
||||||
_shellRuns.dismissedRuns,
|
);
|
||||||
);
|
// Older pages prepend messages and a live frame can append one, so a
|
||||||
// Older pages prepend messages and a live frame can append one, so a
|
// folded assistant turn's first message id is not a stable identity.
|
||||||
// folded assistant turn's first message id is not a stable identity.
|
// ChatRowKeys carries a turn's key forward while it still holds any of
|
||||||
// ChatRowKeys carries a turn's key forward while it still holds any of
|
// its previous messages, keeping the element (and its open disclosures)
|
||||||
// its previous messages, keeping the element (and its open disclosures)
|
// across paging and streaming.
|
||||||
// across paging and streaming.
|
final keys = _rowKeys.forRows(rows);
|
||||||
final keys = _rowKeys.forRows(rows);
|
final split = _splitFor(rows);
|
||||||
final split = _splitFor(rows);
|
final initialLoad = !_controller.loaded && _controller.loading;
|
||||||
final initialLoad = !_controller.loaded && _controller.loading;
|
final historyNotice = _noticeOf(
|
||||||
final historyNotice = _noticeOf(
|
notices,
|
||||||
notices,
|
ChatNoticeKind.connectionRefused,
|
||||||
ChatNoticeKind.connectionRefused,
|
);
|
||||||
);
|
final liveNotice = _noticeOf(notices, ChatNoticeKind.liveFailure);
|
||||||
final liveNotice = _noticeOf(notices, ChatNoticeKind.liveFailure);
|
final messageIds = _messageIds();
|
||||||
final messageIds = _messageIds();
|
final newMessages = chatNewMessageCount(messageIds, _newestAtRelease);
|
||||||
final newMessages = chatNewMessageCount(messageIds, _newestAtRelease);
|
final showJump = chatShowsJumpToLatest(
|
||||||
final showJump = chatShowsJumpToLatest(
|
following: _following,
|
||||||
following: _following,
|
distanceFromBottom: _distanceFromBottom,
|
||||||
distanceFromBottom: _distanceFromBottom,
|
itemCount: messageIds.length,
|
||||||
itemCount: messageIds.length,
|
);
|
||||||
);
|
// Place the first loaded transcript and keep a following view at the end.
|
||||||
// Place the first loaded transcript and keep a following view at the end.
|
// Scheduling after the build means the new extent is already laid out.
|
||||||
// Scheduling after the build means the new extent is already laid out.
|
_scheduleFollow();
|
||||||
_scheduleFollow();
|
// Under the app shell the conversation takes over the app's bar (title,
|
||||||
// Under the app shell the conversation takes over the app's bar (title,
|
// Back, model, information) instead of drawing a second bar below it.
|
||||||
// Back, model, information) instead of drawing a second bar below it.
|
final inShellBar = ShellBar.available(context);
|
||||||
final inShellBar = ShellBar.available(context);
|
// The measured header owns its space so scrolled text never falls
|
||||||
// The measured header owns its space so scrolled text never falls
|
// behind the controls; the transcript ends at the composer's top edge, so
|
||||||
// behind the controls; the transcript ends at the composer's top edge, so
|
// nothing renders behind the composer and the viewport shrinks as the
|
||||||
// nothing renders behind the composer and the viewport shrinks as the
|
// composer grows.
|
||||||
// composer grows.
|
// Every input of the composer comes from this widget's configuration,
|
||||||
// Every input of the composer comes from this widget's configuration,
|
// the composer, the images and the running state.
|
||||||
// the composer, the images and the running state.
|
final composerBar = _chrome.widgetFor(
|
||||||
final composerBar = _chrome.widgetFor(
|
'composer',
|
||||||
'composer',
|
_controller.running,
|
||||||
_controller.running,
|
[widget, _composer, _images],
|
||||||
[widget, _composer, _images],
|
() => ChatComposerBar(
|
||||||
() => ChatComposerBar(
|
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
||||||
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
composer: _composer,
|
||||||
composer: _composer,
|
running: _controller.running,
|
||||||
running: _controller.running,
|
commands: _commandActions(),
|
||||||
commands: _commandActions(),
|
picker: widget.attachmentPicker,
|
||||||
picker: widget.attachmentPicker,
|
images: _images,
|
||||||
images: _images,
|
placeholder: chatComposerPlaceholderFor(
|
||||||
placeholder: chatComposerPlaceholderFor(
|
'${widget.session?['directory'] ?? ''}',
|
||||||
'${widget.session?['directory'] ?? ''}',
|
),
|
||||||
|
chatColor: chatSessionColor(widget.session),
|
||||||
|
pasteTarget: widget.pasteTarget,
|
||||||
|
runShell: _shellRuns.start,
|
||||||
|
backgroundTasks: ChatBackgroundTasks(
|
||||||
|
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||||
|
gateway: widget.gateway,
|
||||||
|
sessionId: widget.sessionId,
|
||||||
|
syncToken: widget.syncToken,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
chatColor: chatSessionColor(widget.session),
|
);
|
||||||
pasteTarget: widget.pasteTarget,
|
final page = FloatingBarOverlay(
|
||||||
runShell: _shellRuns.start,
|
bar: ChatPaneBarReveal(bar: composerBar),
|
||||||
backgroundTasks: ChatBackgroundTasks(
|
child: SegmentedBarOverlay(
|
||||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
reserveSpace: true,
|
||||||
gateway: widget.gateway,
|
bar: ChatPaneBarReveal(bar: _header(context, inShellBar)),
|
||||||
sessionId: widget.sessionId,
|
child: NotificationListener<ScrollMetricsNotification>(
|
||||||
syncToken: widget.syncToken,
|
onNotification: _onScrollMetrics,
|
||||||
),
|
child: NotificationListener<ScrollNotification>(
|
||||||
),
|
onNotification: _onScrollNotification,
|
||||||
);
|
child: LayoutBuilder(
|
||||||
final page = FloatingBarOverlay(
|
builder: (context, constraints) {
|
||||||
bar: ChatPaneBarReveal(bar: composerBar),
|
// Rows keep to the centred reading column on a wide
|
||||||
child: SegmentedBarOverlay(
|
// window; the margins beside it still scroll the list.
|
||||||
reserveSpace: true,
|
final side = chatReadingInset(constraints.maxWidth);
|
||||||
bar: ChatPaneBarReveal(bar: _header(context, inShellBar)),
|
// Answers draw Copy in a strip left of the column; every
|
||||||
child: NotificationListener<ScrollMetricsNotification>(
|
// other row keeps to the column by insetting past it.
|
||||||
onNotification: _onScrollMetrics,
|
final gutter = chatCopyGutter(constraints.maxWidth);
|
||||||
child: NotificationListener<ScrollNotification>(
|
final media = MediaQuery.paddingOf(context);
|
||||||
onNotification: _onScrollNotification,
|
final transcript = [
|
||||||
child: LayoutBuilder(
|
for (var index = 0; index < rows.length; index++)
|
||||||
builder: (context, constraints) {
|
Padding(
|
||||||
// Rows keep to the centred reading column on a wide
|
key: ValueKey<String>(keys[index]),
|
||||||
// window; the margins beside it still scroll the list.
|
padding: EdgeInsets.only(
|
||||||
final side = chatReadingInset(constraints.maxWidth);
|
left:
|
||||||
// Answers draw Copy in a strip left of the column; every
|
16 +
|
||||||
// other row keeps to the column by insetting past it.
|
(rows[index]['kind'] == 'assistant'
|
||||||
final gutter = chatCopyGutter(constraints.maxWidth);
|
? 0
|
||||||
final media = MediaQuery.paddingOf(context);
|
: gutter),
|
||||||
final transcript = [
|
right: 16,
|
||||||
for (var index = 0; index < rows.length; index++)
|
),
|
||||||
Padding(
|
// Slivers mount only visible rows. Defer constructing
|
||||||
key: ValueKey<String>(keys[index]),
|
// their chips and checking cached widgets until then,
|
||||||
padding: EdgeInsets.only(
|
// rather than visiting the entire history per delta.
|
||||||
left:
|
child: ChatCopyGutter(
|
||||||
16 +
|
width: rows[index]['kind'] == 'assistant'
|
||||||
(rows[index]['kind'] == 'assistant' ? 0 : gutter),
|
? gutter
|
||||||
right: 16,
|
: 0,
|
||||||
),
|
child: Builder(
|
||||||
// Slivers mount only visible rows. Defer constructing
|
builder: (_) => _entering(
|
||||||
// their chips and checking cached widgets until then,
|
|
||||||
// rather than visiting the entire history per delta.
|
|
||||||
child: ChatCopyGutter(
|
|
||||||
width: rows[index]['kind'] == 'assistant'
|
|
||||||
? gutter
|
|
||||||
: 0,
|
|
||||||
child: Builder(
|
|
||||||
builder: (_) => _entering(
|
|
||||||
rows[index],
|
|
||||||
_transcriptRow(
|
|
||||||
rows[index],
|
rows[index],
|
||||||
keys[index],
|
_transcriptRow(
|
||||||
onDismissCompaction:
|
rows[index],
|
||||||
compactionNotice != null &&
|
keys[index],
|
||||||
chatNoticeActivityCondition(
|
onDismissCompaction:
|
||||||
rows[index],
|
compactionNotice != null &&
|
||||||
) ==
|
chatNoticeActivityCondition(
|
||||||
compactionNotice.condition
|
rows[index],
|
||||||
? () => _dismiss(compactionNotice)
|
) ==
|
||||||
: null,
|
compactionNotice.condition
|
||||||
|
? () => _dismiss(compactionNotice)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
];
|
||||||
];
|
_rowWidgets.prune();
|
||||||
_rowWidgets.prune();
|
final stack = Stack(
|
||||||
final stack = Stack(
|
children: [
|
||||||
children: [
|
// At rest the first item starts below the floating bar;
|
||||||
// At rest the first item starts below the floating bar;
|
// the viewport itself ends above the composer.
|
||||||
// the viewport itself ends above the composer.
|
// Bottom-anchored at the split row, the newest rows are
|
||||||
// Bottom-anchored at the split row, the newest rows are
|
// laid out first and older ones only when scrolled to.
|
||||||
// laid out first and older ones only when scrolled to.
|
ChatTranscriptSelectionArea(
|
||||||
ChatTranscriptSelectionArea(
|
child: ChatTranscriptScrollView(
|
||||||
child: ChatTranscriptScrollView(
|
key: ValueKey<String>(
|
||||||
key: ValueKey<String>(
|
'chat-thread-${widget.sessionId}',
|
||||||
'chat-thread-${widget.sessionId}',
|
),
|
||||||
),
|
controller: _scroll,
|
||||||
controller: _scroll,
|
splitAfter: split < 0
|
||||||
splitAfter: split < 0
|
? null
|
||||||
? null
|
: ValueKey<String>(keys[split]),
|
||||||
: ValueKey<String>(keys[split]),
|
padding: EdgeInsets.fromLTRB(
|
||||||
padding: EdgeInsets.fromLTRB(
|
side - gutter,
|
||||||
side - gutter,
|
media.top + 8,
|
||||||
media.top + 8,
|
side,
|
||||||
side,
|
8,
|
||||||
8,
|
),
|
||||||
),
|
children: chatCopyGutterInset(gutter, transcript, [
|
||||||
children: chatCopyGutterInset(gutter, transcript, [
|
if (initialLoad)
|
||||||
if (initialLoad)
|
Padding(
|
||||||
Padding(
|
key: const Key('chat-thread-loading'),
|
||||||
key: const Key('chat-thread-loading'),
|
padding: const EdgeInsets.all(16),
|
||||||
padding: const EdgeInsets.all(16),
|
child: Center(
|
||||||
child: Center(
|
child: cupertino
|
||||||
child: cupertino
|
? const CupertinoActivityIndicator()
|
||||||
? const CupertinoActivityIndicator()
|
: const CircularProgressIndicator(),
|
||||||
: const CircularProgressIndicator(),
|
),
|
||||||
),
|
),
|
||||||
),
|
if (_controller.hasMore)
|
||||||
if (_controller.hasMore)
|
Padding(
|
||||||
Padding(
|
key: const Key('chat-load-older'),
|
||||||
key: const Key('chat-load-older'),
|
padding: const EdgeInsets.symmetric(
|
||||||
padding: const EdgeInsets.symmetric(
|
horizontal: 16,
|
||||||
horizontal: 16,
|
),
|
||||||
|
child: Align(
|
||||||
|
alignment: AlignmentDirectional.centerStart,
|
||||||
|
child: cupertino
|
||||||
|
? CupertinoButton(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: _controller.loading
|
||||||
|
? null
|
||||||
|
: _controller.loadOlder,
|
||||||
|
child: const Text('Load older'),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: _controller.loading
|
||||||
|
? null
|
||||||
|
: _controller.loadOlder,
|
||||||
|
child: const Text('Load older'),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Align(
|
if (historyNotice != null)
|
||||||
alignment: AlignmentDirectional.centerStart,
|
_ChatNoticeLine(
|
||||||
child: cupertino
|
key: const Key('chat-history-error'),
|
||||||
? CupertinoButton(
|
notice: historyNotice,
|
||||||
padding: EdgeInsets.zero,
|
onDismiss: _dismiss,
|
||||||
onPressed: _controller.loading
|
onRetry: _controller.load,
|
||||||
? null
|
|
||||||
: _controller.loadOlder,
|
|
||||||
child: const Text('Load older'),
|
|
||||||
)
|
|
||||||
: TextButton(
|
|
||||||
onPressed: _controller.loading
|
|
||||||
? null
|
|
||||||
: _controller.loadOlder,
|
|
||||||
child: const Text('Load older'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
if (liveNotice != null)
|
||||||
if (historyNotice != null)
|
_ChatNoticeLine(
|
||||||
_ChatNoticeLine(
|
key: const Key('chat-live-error'),
|
||||||
key: const Key('chat-history-error'),
|
notice: liveNotice,
|
||||||
notice: historyNotice,
|
onDismiss: _dismiss,
|
||||||
onDismiss: _dismiss,
|
onRetry: _controller.resync,
|
||||||
onRetry: _controller.load,
|
|
||||||
),
|
|
||||||
if (liveNotice != null)
|
|
||||||
_ChatNoticeLine(
|
|
||||||
key: const Key('chat-live-error'),
|
|
||||||
notice: liveNotice,
|
|
||||||
onDismiss: _dismiss,
|
|
||||||
onRetry: _controller.resync,
|
|
||||||
),
|
|
||||||
if (_controller.loaded &&
|
|
||||||
allRows.isEmpty &&
|
|
||||||
allNotices.isEmpty &&
|
|
||||||
_commandNotices.isEmpty &&
|
|
||||||
_controller.error == null)
|
|
||||||
const Padding(
|
|
||||||
key: Key('chat-thread-empty'),
|
|
||||||
padding: EdgeInsets.all(16),
|
|
||||||
child: Text('No messages in this chat yet.'),
|
|
||||||
),
|
|
||||||
...transcript,
|
|
||||||
// Messages the server holds queued (one sent before
|
|
||||||
// a reload, or from another device) follow the
|
|
||||||
// transcript: none has reached the harness yet.
|
|
||||||
for (final prompt
|
|
||||||
in _controller.queuedOutsideTranscript)
|
|
||||||
Padding(
|
|
||||||
key: ValueKey<String>(
|
|
||||||
'chat-queued-${prompt['operation_id']}',
|
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(
|
if (_controller.loaded &&
|
||||||
horizontal: 16,
|
allRows.isEmpty &&
|
||||||
|
allNotices.isEmpty &&
|
||||||
|
_commandNotices.isEmpty &&
|
||||||
|
_controller.error == null)
|
||||||
|
const Padding(
|
||||||
|
key: Key('chat-thread-empty'),
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Text('No messages in this chat yet.'),
|
||||||
),
|
),
|
||||||
child: _queuedRow(prompt, cupertino),
|
...transcript,
|
||||||
),
|
// Messages the server holds queued (one sent before
|
||||||
// Messages the server has not accepted follow the
|
// a reload, or from another device) follow the
|
||||||
// transcript until they are retried or edited.
|
// transcript: none has reached the harness yet.
|
||||||
for (final send in _composer.deliveries.unsent)
|
for (final prompt
|
||||||
Padding(
|
in _controller.queuedOutsideTranscript)
|
||||||
key: ValueKey<String>(
|
Padding(
|
||||||
'chat-unsent-${send.operationId}',
|
key: ValueKey<String>(
|
||||||
|
'chat-queued-${prompt['operation_id']}',
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
),
|
||||||
|
child: _queuedRow(prompt, cupertino),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(
|
// Messages the server has not accepted follow the
|
||||||
horizontal: 16,
|
// transcript until they are retried or edited.
|
||||||
|
for (final send in _composer.deliveries.unsent)
|
||||||
|
Padding(
|
||||||
|
key: ValueKey<String>(
|
||||||
|
'chat-unsent-${send.operationId}',
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
),
|
||||||
|
child: _unsentRow(send, cupertino),
|
||||||
),
|
),
|
||||||
child: _unsentRow(send, cupertino),
|
// The conversation's own command lines sit after the
|
||||||
),
|
// turns, as on the web; they are never bubbles.
|
||||||
// The conversation's own command lines sit after the
|
for (final notice in _commandNotices)
|
||||||
// turns, as on the web; they are never bubbles.
|
_ChatNoticeLine(
|
||||||
for (final notice in _commandNotices)
|
key: ValueKey<String>(
|
||||||
_ChatNoticeLine(
|
'chat-command-notice-${notice.condition}',
|
||||||
key: ValueKey<String>(
|
),
|
||||||
'chat-command-notice-${notice.condition}',
|
notice: notice,
|
||||||
|
onDismiss: _dismiss,
|
||||||
),
|
),
|
||||||
notice: notice,
|
]),
|
||||||
onDismiss: _dismiss,
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (showJump)
|
|
||||||
PositionedDirectional(
|
|
||||||
end: side + 16,
|
|
||||||
bottom: 16,
|
|
||||||
child: _ChatJumpToLatest(
|
|
||||||
key: const Key('chat-jump-to-latest'),
|
|
||||||
label: chatJumpToLatestLabel(newMessages),
|
|
||||||
cupertino: cupertino,
|
|
||||||
onPressed: _followLatest,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
if (showJump)
|
||||||
);
|
PositionedDirectional(
|
||||||
return AboveFloatingBar(child: stack);
|
end: side + 16,
|
||||||
},
|
bottom: 16,
|
||||||
|
child: _ChatJumpToLatest(
|
||||||
|
key: const Key('chat-jump-to-latest'),
|
||||||
|
label: chatJumpToLatestLabel(newMessages),
|
||||||
|
cupertino: cupertino,
|
||||||
|
onPressed: _followLatest,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
return AboveFloatingBar(child: stack);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
// The bar and the jump control float over the transcript and the
|
||||||
// The bar and the jump control float over the transcript and the
|
// composer sits below it; the wheel over them scrolls it, as a page
|
||||||
// composer sits below it; the wheel over them scrolls it, as a page
|
// scrolls under fixed bars.
|
||||||
// scrolls under fixed bars.
|
final column = VerticalWheelForwarder(controller: _scroll, child: page);
|
||||||
final column = VerticalWheelForwarder(controller: _scroll, child: page);
|
final wideFiles =
|
||||||
final wideFiles =
|
_filesVisible && MediaQuery.sizeOf(context).width >= 700;
|
||||||
_filesVisible && MediaQuery.sizeOf(context).width >= 700;
|
final content = wideFiles
|
||||||
final content = wideFiles
|
? Row(
|
||||||
? Row(
|
children: [
|
||||||
children: [
|
Expanded(child: column),
|
||||||
Expanded(child: column),
|
SizedBox(
|
||||||
SizedBox(
|
width: filesPanelWidth(MediaQuery.sizeOf(context).width),
|
||||||
width: filesPanelWidth(MediaQuery.sizeOf(context).width),
|
child: FilesPanel(controller: _files),
|
||||||
child: FilesPanel(controller: _files),
|
),
|
||||||
),
|
],
|
||||||
],
|
)
|
||||||
)
|
: column;
|
||||||
: column;
|
if (!inShellBar) return content;
|
||||||
if (!inShellBar) return content;
|
// The conversation draws its own floating bar; the page shows none.
|
||||||
// The conversation draws its own floating bar; the page shows none.
|
final title = widget.title.trim();
|
||||||
final title = widget.title.trim();
|
return ShellBar(
|
||||||
return ShellBar(
|
barless: true,
|
||||||
barless: true,
|
title: title.isEmpty ? null : title,
|
||||||
title: title.isEmpty ? null : title,
|
child: content,
|
||||||
child: content,
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The floating bar: Back where this page can go back (a pushed phone page,
|
/// The floating bar: Back where this page can go back (a pushed phone page,
|
||||||
|
|||||||
@@ -1,7 +1,34 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// The operator's turn: a neutral filled, evenly rounded bubble with no border,
|
import '../sessions/chat_color_palette.dart';
|
||||||
|
|
||||||
|
/// How strongly a coloured chat's shade washes the operator's bubbles over
|
||||||
|
/// the host's neutral bubble fill. Text keeps the host's colours.
|
||||||
|
const double chatBubbleTint = 0.22;
|
||||||
|
|
||||||
|
/// The open chat's colour name for the operator's bubbles below it; a chat
|
||||||
|
/// with no colour (or no scope) keeps the host's neutral bubble.
|
||||||
|
class ChatBubbleColor extends InheritedWidget {
|
||||||
|
const ChatBubbleColor({super.key, required this.name, required super.child});
|
||||||
|
|
||||||
|
final String? name;
|
||||||
|
|
||||||
|
static String? of(BuildContext context) =>
|
||||||
|
context.dependOnInheritedWidgetOfExactType<ChatBubbleColor>()?.name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(ChatBubbleColor old) => old.name != name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [base] washed with the open chat's shade, or [base] for an uncoloured chat.
|
||||||
|
Color chatBubbleFill(BuildContext context, Color base) {
|
||||||
|
final shade = chatColorShade(context, ChatBubbleColor.of(context));
|
||||||
|
if (shade == null) return base;
|
||||||
|
return Color.alphaBlend(shade.withValues(alpha: chatBubbleTint), base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The operator's turn: a filled (neutral, or softly in the chat's colour), evenly rounded bubble with no border,
|
||||||
/// in the host's own surface roles. The agent's turn has no bubble at all; its
|
/// 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.
|
/// text sits on the page, so only the operator's words are enclosed.
|
||||||
class ChatUserBubble extends StatelessWidget {
|
class ChatUserBubble extends StatelessWidget {
|
||||||
@@ -25,7 +52,10 @@ class ChatUserBubble extends StatelessWidget {
|
|||||||
if (cupertino) {
|
if (cupertino) {
|
||||||
return DecoratedBox(
|
return DecoratedBox(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: CupertinoColors.systemGrey5.resolveFrom(context),
|
color: chatBubbleFill(
|
||||||
|
context,
|
||||||
|
CupertinoColors.systemGrey5.resolveFrom(context),
|
||||||
|
),
|
||||||
borderRadius: _radius,
|
borderRadius: _radius,
|
||||||
),
|
),
|
||||||
child: Padding(padding: _padding, child: child),
|
child: Padding(padding: _padding, child: child),
|
||||||
@@ -34,7 +64,10 @@ class ChatUserBubble extends StatelessWidget {
|
|||||||
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
||||||
// inside the bubble keeps its ink and background.
|
// inside the bubble keeps its ink and background.
|
||||||
return Material(
|
return Material(
|
||||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
color: chatBubbleFill(
|
||||||
|
context,
|
||||||
|
Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||||
|
),
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
shape: const RoundedRectangleBorder(borderRadius: _radius),
|
shape: const RoundedRectangleBorder(borderRadius: _radius),
|
||||||
child: Padding(padding: _padding, child: child),
|
child: Padding(padding: _padding, child: child),
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Future<void> pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required bool cupertino,
|
||||||
|
String? color,
|
||||||
|
Brightness brightness = Brightness.light,
|
||||||
|
}) async {
|
||||||
|
final bubble = ChatBubbleColor(
|
||||||
|
name: color,
|
||||||
|
child: ChatUserBubble(cupertino: cupertino, child: const Text('Hello')),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
cupertino
|
||||||
|
? CupertinoApp(
|
||||||
|
theme: CupertinoThemeData(brightness: brightness),
|
||||||
|
home: Center(child: bubble),
|
||||||
|
)
|
||||||
|
: MaterialApp(
|
||||||
|
theme: ThemeData(brightness: brightness),
|
||||||
|
home: Scaffold(body: Center(child: bubble)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color materialFill(WidgetTester tester) => tester
|
||||||
|
.widget<Material>(
|
||||||
|
find
|
||||||
|
.descendant(
|
||||||
|
of: find.byType(ChatUserBubble),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
)
|
||||||
|
.first,
|
||||||
|
)
|
||||||
|
.color!;
|
||||||
|
|
||||||
|
Color cupertinoFill(WidgetTester tester) =>
|
||||||
|
(tester
|
||||||
|
.widget<DecoratedBox>(
|
||||||
|
find
|
||||||
|
.descendant(
|
||||||
|
of: find.byType(ChatUserBubble),
|
||||||
|
matching: find.byType(DecoratedBox),
|
||||||
|
)
|
||||||
|
.first,
|
||||||
|
)
|
||||||
|
.decoration
|
||||||
|
as BoxDecoration)
|
||||||
|
.color!;
|
||||||
|
|
||||||
|
for (final brightness in Brightness.values) {
|
||||||
|
testWidgets('Material ${brightness.name}: a coloured chat washes the '
|
||||||
|
'bubble softly; an uncoloured chat keeps the host fill', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pump(tester, cupertino: false, brightness: brightness);
|
||||||
|
final neutral = materialFill(tester);
|
||||||
|
final context = tester.element(find.byType(ChatUserBubble));
|
||||||
|
expect(neutral, Theme.of(context).colorScheme.surfaceContainerHighest);
|
||||||
|
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
cupertino: false,
|
||||||
|
color: 'teal',
|
||||||
|
brightness: brightness,
|
||||||
|
);
|
||||||
|
final tinted = materialFill(tester);
|
||||||
|
expect(tinted, isNot(neutral));
|
||||||
|
expect(tinted.a, 1);
|
||||||
|
// Soft: every channel stays within the tint's share of the neutral fill.
|
||||||
|
for (final (a, b) in [
|
||||||
|
(tinted.r, neutral.r),
|
||||||
|
(tinted.g, neutral.g),
|
||||||
|
(tinted.b, neutral.b),
|
||||||
|
]) {
|
||||||
|
expect((a - b).abs(), lessThanOrEqualTo(chatBubbleTint + 0.01));
|
||||||
|
}
|
||||||
|
// The text keeps the host's colour.
|
||||||
|
final style = DefaultTextStyle.of(
|
||||||
|
tester.element(find.text('Hello')),
|
||||||
|
).style;
|
||||||
|
await pump(tester, cupertino: false, brightness: brightness);
|
||||||
|
expect(
|
||||||
|
DefaultTextStyle.of(tester.element(find.text('Hello'))).style.color,
|
||||||
|
style.color,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('Cupertino: a coloured chat washes the bubble; none keeps grey', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pump(tester, cupertino: true);
|
||||||
|
final neutral = cupertinoFill(tester);
|
||||||
|
expect(
|
||||||
|
neutral,
|
||||||
|
CupertinoColors.systemGrey5.resolveFrom(
|
||||||
|
tester.element(find.byType(ChatUserBubble)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await pump(tester, cupertino: true, color: 'blue');
|
||||||
|
expect(cupertinoFill(tester), isNot(neutral));
|
||||||
|
await pump(tester, cupertino: true, color: 'not-a-colour');
|
||||||
|
expect(cupertinoFill(tester), neutral);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('a bubble with no colour scope stays neutral', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: ChatUserBubble(cupertino: false, child: Text('Hello')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final context = tester.element(find.byType(ChatUserBubble));
|
||||||
|
expect(
|
||||||
|
materialFill(tester),
|
||||||
|
Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user