Show a chat turn's changed files as a chip that opens its diff
The answer footer shows '3 files changed +9 -2'; tapping opens the turn's files in the sheet (wide) or a full-screen page (narrow), and a file opens the run Changes diff viewer. Patches load through the chat's own gateway.
This commit is contained in:
@@ -11,7 +11,9 @@ export 'domain/change_wording.dart';
|
||||
export 'domain/file_change.dart';
|
||||
export 'domain/run_changes.dart';
|
||||
export 'domain/unified_patch.dart';
|
||||
export 'widgets/change_style.dart' show DiffForm, hostTextTheme, usesCupertino;
|
||||
export 'widgets/capture_section.dart' show ChangeFileRow;
|
||||
export 'widgets/change_style.dart'
|
||||
show ChangeStatText, DiffForm, hostTextTheme, usesCupertino;
|
||||
export 'widgets/changes_viewer.dart';
|
||||
export 'widgets/file_diff_viewer.dart';
|
||||
export 'widgets/patch_view.dart';
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../data/chat_repository.dart';
|
||||
import '../domain/chat_account_usage.dart';
|
||||
import '../domain/chat_sessions.dart';
|
||||
import '../domain/chat_transcript.dart';
|
||||
import '../domain/chat_turn_diffs.dart';
|
||||
import 'chat_server_queue.dart';
|
||||
import 'chat_thread_cards.dart';
|
||||
import 'chat_transcript_cache.dart';
|
||||
@@ -60,6 +61,13 @@ class ChatThreadController extends ChangeNotifier {
|
||||
final _transcriptChanges = ChangeNotifier();
|
||||
final ChatServerQueue _queue = ChatServerQueue();
|
||||
|
||||
/// The per-turn change summaries the transcript's change chips show.
|
||||
final ChatTurnDiffs turnDiffs = ChatTurnDiffs();
|
||||
|
||||
/// Fetches one turn's recorded changes through this chat's own gateway.
|
||||
Future<JsonMap> turnDiff(String turnId) =>
|
||||
_repository.turnDiff(sessionId, turnId);
|
||||
|
||||
/// Told about every queue body the server sends (the subscribe reply's and
|
||||
/// each `chat_queue` frame), so delivery states follow the server.
|
||||
void Function(JsonMap queue)? onQueue;
|
||||
@@ -208,6 +216,7 @@ class ChatThreadController extends ChangeNotifier {
|
||||
limit: 200,
|
||||
);
|
||||
if (!_owned(token)) return;
|
||||
turnDiffs.apply(page['turnDiffs'], sessionId);
|
||||
final merged = mergeChatHistory(
|
||||
{'messages': _messages},
|
||||
page,
|
||||
@@ -260,6 +269,7 @@ class ChatThreadController extends ChangeNotifier {
|
||||
try {
|
||||
final page = await _repository.history(sessionId, limit: 200);
|
||||
if (!_owned(token)) return;
|
||||
turnDiffs.apply(page['turnDiffs'], sessionId);
|
||||
if (replaceHeldTurn) {
|
||||
_messages = (page['messages'] as List? ?? const [])
|
||||
.whereType<Map>()
|
||||
@@ -336,6 +346,10 @@ class ChatThreadController extends ChangeNotifier {
|
||||
_applyQueue(envelope['chat_queue']);
|
||||
return;
|
||||
}
|
||||
if (envelope['type'] == 'chat_turn_diffs') {
|
||||
if (turnDiffs.apply(envelope['chat_turn_diffs'], sessionId)) _notify();
|
||||
return;
|
||||
}
|
||||
if (envelope['type'] == 'chat_permission') {
|
||||
final permission = envelope['chat_permission'];
|
||||
if (permission is! Map) return;
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../domain/chat_notice.dart';
|
||||
import '../domain/chat_attachment_picker.dart';
|
||||
import '../domain/chat_colors.dart';
|
||||
import '../domain/chat_transcript.dart';
|
||||
import '../domain/chat_turn_diffs.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import '../ui/sessions/chat_color_picker.dart';
|
||||
import '../ui/sessions/session_actions.dart';
|
||||
@@ -24,6 +25,7 @@ import '../ui/transcript/chat_message_view.dart';
|
||||
import '../ui/transcript/chat_transcript_selection.dart';
|
||||
import '../ui/transcript/chat_injected_rows.dart';
|
||||
import '../ui/transcript/chat_task_notices_group.dart';
|
||||
import '../ui/transcript/chat_turn_diff_chip.dart';
|
||||
import '../../artifacts/actions/artifact_file_bridge.dart';
|
||||
import '../domain/chat_session_handoff.dart';
|
||||
import 'chat_account_usage_section.dart';
|
||||
@@ -977,24 +979,28 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
);
|
||||
// Answered approvals and questions fold into their turn's chips, like
|
||||
// tool calls; only cards still waiting on the operator stay full cards.
|
||||
final allRows = groupSettledQuestions(
|
||||
groupSettledPermissions(
|
||||
transcriptRows(
|
||||
messages,
|
||||
trailing: cards,
|
||||
running:
|
||||
_controller.running &&
|
||||
!_reconnecting &&
|
||||
!_staleTranscript &&
|
||||
!cards.any(chatCardAwaitingOperator),
|
||||
awaitingResponse:
|
||||
_controller.awaitingResponse &&
|
||||
!_reconnecting &&
|
||||
!_staleTranscript &&
|
||||
!cards.any(chatCardAwaitingOperator),
|
||||
liveMessageId: _controller.liveAssistantMessageId,
|
||||
// A turn that changed files carries its summary for the change chip.
|
||||
final allRows = attachChatTurnDiffs(
|
||||
groupSettledQuestions(
|
||||
groupSettledPermissions(
|
||||
transcriptRows(
|
||||
messages,
|
||||
trailing: cards,
|
||||
running:
|
||||
_controller.running &&
|
||||
!_reconnecting &&
|
||||
!_staleTranscript &&
|
||||
!cards.any(chatCardAwaitingOperator),
|
||||
awaitingResponse:
|
||||
_controller.awaitingResponse &&
|
||||
!_reconnecting &&
|
||||
!_staleTranscript &&
|
||||
!cards.any(chatCardAwaitingOperator),
|
||||
liveMessageId: _controller.liveAssistantMessageId,
|
||||
),
|
||||
),
|
||||
),
|
||||
_controller.turnDiffs,
|
||||
);
|
||||
// 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
|
||||
@@ -1454,6 +1460,11 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
if (permissions is List<ChatPermissionCardData> && permissions.isNotEmpty)
|
||||
ChatPermissionsChip(permissions: permissions),
|
||||
...chatQuestionChips(row),
|
||||
if (row['turnDiff'] case final Map diff)
|
||||
ChatTurnDiffChip(
|
||||
summary: Map<String, dynamic>.from(diff),
|
||||
load: () => _controller.turnDiff('${diff['turn_id']}'),
|
||||
),
|
||||
];
|
||||
if (kind == 'permissions') {
|
||||
return Align(
|
||||
|
||||
@@ -89,9 +89,10 @@ class ChatRepository {
|
||||
}))['chat_shells'],
|
||||
);
|
||||
|
||||
Future<JsonMap> automations(String sessionId) => gateway.call('chat_automations', {
|
||||
'chat_query': {'session_id': sessionId},
|
||||
});
|
||||
Future<JsonMap> automations(String sessionId) =>
|
||||
gateway.call('chat_automations', {
|
||||
'chat_query': {'session_id': sessionId},
|
||||
});
|
||||
Future<List<String>> directories() async {
|
||||
final value = (await gateway.call('chat_directories'))['chat_directories'];
|
||||
if (value is! List) {
|
||||
@@ -139,20 +140,37 @@ class ChatRepository {
|
||||
'chat_query': {'session_id': sessionId, 'limit': limit, 'cursor': cursor},
|
||||
});
|
||||
final page = reply['chat_history'];
|
||||
// The session's recorded per-turn changes ride with its history.
|
||||
final turnDiffs = reply['chat_turn_diffs'];
|
||||
if (page is Map) {
|
||||
return {
|
||||
'messages': _maps(page['messages']),
|
||||
'nextCursor': '${page['next_cursor'] ?? ''}',
|
||||
'hasMore': page['has_more'] == true,
|
||||
'turnDiffs': ?turnDiffs,
|
||||
};
|
||||
}
|
||||
return {
|
||||
'messages': _maps(reply['chat_messages']),
|
||||
'nextCursor': '',
|
||||
'hasMore': false,
|
||||
'turnDiffs': ?turnDiffs,
|
||||
};
|
||||
}
|
||||
|
||||
/// One turn's recorded file changes: the `chat_turn_diff` body with its
|
||||
/// `summary` and `changes` (a `file_changes`-shaped capture).
|
||||
Future<JsonMap> turnDiff(String sessionId, String turnId) async {
|
||||
final reply = await gateway.call('chat_turn_diff', {
|
||||
'chat_turn_diff': {'session_id': sessionId, 'turn_id': turnId},
|
||||
});
|
||||
final body = reply['chat_turn_diff'];
|
||||
if (body is! Map || body['changes'] is! Map) {
|
||||
throw StateError('The server returned no changes for this turn.');
|
||||
}
|
||||
return Map<String, dynamic>.from(body);
|
||||
}
|
||||
|
||||
Future<JsonMap> subscribe(String sessionId) =>
|
||||
gateway.call('chat_subscribe', {
|
||||
'chat_subscribe': {'session_id': sessionId},
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../changes/domain/unified_patch.dart';
|
||||
|
||||
/// The server's per-turn workspace change summaries for one chat: what the
|
||||
/// transcript's "N files changed" chip shows. The server sends them with the
|
||||
/// history (`chat_turn_diffs` on a `chat_messages` reply) and pushes one per
|
||||
/// finished turn that changed files; the full patches are fetched on demand.
|
||||
class ChatTurnDiffs {
|
||||
final Map<String, JsonMap> _byTurn = {};
|
||||
|
||||
/// Summaries in the server's order (oldest first).
|
||||
List<JsonMap> get summaries => List.unmodifiable(_byTurn.values);
|
||||
|
||||
bool get isEmpty => _byTurn.isEmpty;
|
||||
|
||||
/// Folds a `chat_turn_diffs` body for [sessionId]; true when it changed
|
||||
/// anything. A body for another session, or without turns, is ignored.
|
||||
bool apply(Object? body, String sessionId) {
|
||||
if (body is! Map || '${body['session_id'] ?? ''}' != sessionId) {
|
||||
return false;
|
||||
}
|
||||
final turns = body['turn_diffs'];
|
||||
if (turns is! List) return false;
|
||||
var changed = false;
|
||||
for (final value in turns) {
|
||||
if (value is! Map) continue;
|
||||
final summary = Map<String, dynamic>.from(value);
|
||||
final id = '${summary['turn_id'] ?? ''}'.trim();
|
||||
if (id.isEmpty || chatTurnDiffFiles(summary) <= 0) continue;
|
||||
_byTurn[id] = summary;
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches each summary to the assistant row it belongs to as `turnDiff`.
|
||||
/// A row holding one of the turn's streamed message ids wins; otherwise the
|
||||
/// first assistant row created inside the turn's recorded time span. A
|
||||
/// summary that matches no held row draws nothing (it may belong to a page
|
||||
/// not loaded yet), and each summary attaches to at most one row.
|
||||
List<JsonMap> attachChatTurnDiffs(List<JsonMap> rows, ChatTurnDiffs diffs) {
|
||||
if (diffs.isEmpty) return rows;
|
||||
final assigned = <int, JsonMap>{};
|
||||
for (final summary in diffs.summaries) {
|
||||
final index = _rowFor(rows, summary, assigned);
|
||||
if (index != null) assigned[index] = summary;
|
||||
}
|
||||
if (assigned.isEmpty) return rows;
|
||||
return [
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
if (assigned[i] case final summary?)
|
||||
{...rows[i], 'turnDiff': summary}
|
||||
else
|
||||
rows[i],
|
||||
];
|
||||
}
|
||||
|
||||
int? _rowFor(List<JsonMap> rows, JsonMap summary, Map<int, JsonMap> taken) {
|
||||
final ids = {
|
||||
for (final id in summary['message_ids'] as List? ?? const []) '$id',
|
||||
};
|
||||
if (ids.isNotEmpty) {
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
if (rows[i]['kind'] != 'assistant' || taken.containsKey(i)) continue;
|
||||
final held = rows[i]['messageIds'] as List? ?? const [];
|
||||
if (held.any((id) => ids.contains('$id'))) return i;
|
||||
}
|
||||
}
|
||||
final started = summary['started_at'], ended = summary['ended_at'];
|
||||
if (started is! num || ended is! num || started <= 0) return null;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
if (rows[i]['kind'] != 'assistant' || taken.containsKey(i)) continue;
|
||||
final created = rows[i]['created_at'];
|
||||
if (created is num && created >= started && created <= ended) return i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int chatTurnDiffFiles(JsonMap summary) => _count(summary['files']);
|
||||
int chatTurnDiffAdditions(JsonMap summary) => _count(summary['additions']);
|
||||
int chatTurnDiffDeletions(JsonMap summary) => _count(summary['deletions']);
|
||||
bool chatTurnDiffTruncated(JsonMap summary) => summary['truncated'] == true;
|
||||
|
||||
/// The chip's label, e.g. `3 files changed +42 −7`.
|
||||
String chatTurnDiffLabel(JsonMap summary) {
|
||||
final files = chatTurnDiffFiles(summary);
|
||||
return '${files == 1 ? '1 file' : '$files files'} changed '
|
||||
'+${chatTurnDiffAdditions(summary)} '
|
||||
'−${chatTurnDiffDeletions(summary)}';
|
||||
}
|
||||
|
||||
/// The viewer's heading in the run Changes stat form, e.g.
|
||||
/// `3 files changed +42 -7`; a zero count is left out, as there.
|
||||
String chatTurnDiffHeading(JsonMap summary) {
|
||||
final files = chatTurnDiffFiles(summary);
|
||||
final stat = changeStat(
|
||||
chatTurnDiffAdditions(summary),
|
||||
chatTurnDiffDeletions(summary),
|
||||
);
|
||||
return '${files == 1 ? '1 file' : '$files files'} changed'
|
||||
'${stat.isEmpty ? '' : ' $stat'}';
|
||||
}
|
||||
|
||||
/// The chip's accessible name: the counts in words, and that it opens.
|
||||
String chatTurnDiffSemantics(JsonMap summary) {
|
||||
final files = chatTurnDiffFiles(summary);
|
||||
final added = chatTurnDiffAdditions(summary);
|
||||
final removed = chatTurnDiffDeletions(summary);
|
||||
return '${files == 1 ? '1 file' : '$files files'} changed, '
|
||||
'$added ${added == 1 ? 'line' : 'lines'} added, '
|
||||
'$removed ${removed == 1 ? 'line' : 'lines'} removed'
|
||||
'${chatTurnDiffTruncated(summary) ? ', partly shown' : ''}'
|
||||
', open changes';
|
||||
}
|
||||
|
||||
/// The note shown above a truncated turn's files.
|
||||
String chatTurnDiffTruncationNote(String diagnostic) {
|
||||
final detail = diagnostic.trim();
|
||||
return detail.isEmpty
|
||||
? 'Some changes exceeded the capture limits, so this is not the '
|
||||
'complete diff.'
|
||||
: detail;
|
||||
}
|
||||
|
||||
int _count(Object? value) => value is num ? value.toInt() : 0;
|
||||
@@ -13,16 +13,22 @@ class ChatTurnChip extends StatelessWidget {
|
||||
required this.label,
|
||||
required this.color,
|
||||
required this.semanticsLabel,
|
||||
required this.sheet,
|
||||
this.sheet,
|
||||
this.open,
|
||||
this.ellipsizeLabel = false,
|
||||
});
|
||||
}) : assert(sheet != null || open != null);
|
||||
|
||||
final Key chipKey;
|
||||
final Widget leading;
|
||||
final String label;
|
||||
final Color color;
|
||||
final String semanticsLabel;
|
||||
final Widget sheet;
|
||||
|
||||
/// The native sheet the chip opens, unless [open] presents it instead.
|
||||
final Widget? sheet;
|
||||
|
||||
/// A custom presentation (a full-screen route on a narrow window).
|
||||
final Future<void> Function(BuildContext context, bool cupertino)? open;
|
||||
|
||||
/// Shrink a long label to one ellipsized line. Only for a chip whose parent
|
||||
/// bounds its width (a turn footer's Wrap, an aligned row).
|
||||
@@ -89,18 +95,29 @@ class ChatTurnChip extends StatelessWidget {
|
||||
);
|
||||
|
||||
Future<void> _open(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (_) => CupertinoPopupSurface(child: SafeArea(child: sheet)),
|
||||
);
|
||||
}
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
useSafeArea: true,
|
||||
builder: (_) => sheet,
|
||||
);
|
||||
if (open case final open?) return open(context, cupertino);
|
||||
return showChatTurnSheet(context, cupertino, sheet!);
|
||||
}
|
||||
}
|
||||
|
||||
/// The native sheet a turn chip opens: a Cupertino popup surface or a
|
||||
/// Material modal bottom sheet.
|
||||
Future<void> showChatTurnSheet(
|
||||
BuildContext context,
|
||||
bool cupertino,
|
||||
Widget sheet,
|
||||
) {
|
||||
if (cupertino) {
|
||||
return showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (_) => CupertinoPopupSurface(child: SafeArea(child: sheet)),
|
||||
);
|
||||
}
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
useSafeArea: true,
|
||||
builder: (_) => sheet,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../shell/list_detail_policy.dart';
|
||||
import '../../domain/chat_turn_diffs.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
import 'chat_turn_diff_view.dart';
|
||||
|
||||
/// A turn's workspace changes below its answer, in the tool chip's family:
|
||||
/// `3 files changed +42 −7`. A wide window opens the files in the turn sheet;
|
||||
/// a narrow one opens them as a full-screen page. No diff text is inline.
|
||||
class ChatTurnDiffChip extends StatelessWidget {
|
||||
const ChatTurnDiffChip({
|
||||
super.key,
|
||||
required this.summary,
|
||||
required this.load,
|
||||
});
|
||||
|
||||
final JsonMap summary;
|
||||
|
||||
/// Fetches the turn's `chat_turn_diff` body through the chat's gateway.
|
||||
final Future<JsonMap> Function() load;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
return ChatTurnChip(
|
||||
chipKey: const Key('chat-turn-diff-chip'),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.doc_text : Icons.difference_outlined,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
label: chatTurnDiffLabel(summary),
|
||||
color: color,
|
||||
semanticsLabel: chatTurnDiffSemantics(summary),
|
||||
ellipsizeLabel: true,
|
||||
open: _open,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _open(BuildContext context, bool cupertino) {
|
||||
if (MediaQuery.sizeOf(context).width >= kListDetailMinWidth) {
|
||||
return showChatTurnSheet(
|
||||
context,
|
||||
cupertino,
|
||||
ChatTurnDiffView(summary: summary, load: load),
|
||||
);
|
||||
}
|
||||
final view = ChatTurnDiffView(summary: summary, load: load, inSheet: false);
|
||||
const title = Text('Turn changes');
|
||||
return Navigator.of(context).push<void>(
|
||||
cupertino
|
||||
? CupertinoPageRoute<void>(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: title),
|
||||
child: SafeArea(child: view),
|
||||
),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => Scaffold(
|
||||
appBar: AppBar(title: title),
|
||||
body: SafeArea(child: view),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../changes/changes.dart';
|
||||
import '../../domain/chat_turn_diffs.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// One chat turn's recorded file changes: the counts, an honest note when the
|
||||
/// capture was partial or truncated, and one row per file that opens the
|
||||
/// app's file diff viewer. It reads the changes through [load] (the chat's own
|
||||
/// gateway) when it opens; the transcript never holds the patches.
|
||||
class ChatTurnDiffView extends StatefulWidget {
|
||||
const ChatTurnDiffView({
|
||||
super.key,
|
||||
required this.summary,
|
||||
required this.load,
|
||||
this.inSheet = true,
|
||||
});
|
||||
|
||||
final JsonMap summary;
|
||||
final Future<JsonMap> Function() load;
|
||||
|
||||
/// In a sheet the list shrinks to its content under a height bound; on a
|
||||
/// full-screen page it fills the body.
|
||||
final bool inSheet;
|
||||
|
||||
@override
|
||||
State<ChatTurnDiffView> createState() => _ChatTurnDiffViewState();
|
||||
}
|
||||
|
||||
class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
late Future<JsonMap> _reply = widget.load();
|
||||
|
||||
void _retry() {
|
||||
final next = widget.load();
|
||||
setState(() {
|
||||
_reply = next;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
final list = FutureBuilder<JsonMap>(
|
||||
future: _reply,
|
||||
builder: (context, snapshot) {
|
||||
final children = <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
// The run Changes stat form (+N -M), so it is coloured alike.
|
||||
child: ChangeStatText(
|
||||
chatTurnDiffHeading(widget.summary),
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
..._body(context, snapshot, cupertino),
|
||||
];
|
||||
return ListView(
|
||||
key: const Key('chat-turn-diff-list'),
|
||||
shrinkWrap: widget.inSheet,
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
children: children,
|
||||
);
|
||||
},
|
||||
);
|
||||
// File rows may be Material list tiles inside a Cupertino surface.
|
||||
final content = Material(
|
||||
type: MaterialType.transparency,
|
||||
child: DefaultTextStyle.merge(style: style, child: list),
|
||||
);
|
||||
if (!widget.inSheet) return content;
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
),
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _body(
|
||||
BuildContext context,
|
||||
AsyncSnapshot<JsonMap> snapshot,
|
||||
bool cupertino,
|
||||
) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return [
|
||||
Text('Could not load the changes: ${snapshot.error}'),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: cupertino
|
||||
? CupertinoButton(onPressed: _retry, child: const Text('Retry'))
|
||||
: TextButton(onPressed: _retry, child: const Text('Retry')),
|
||||
),
|
||||
];
|
||||
}
|
||||
final changes = snapshot.data!['changes'];
|
||||
final capture = ChangeCapture.fromJson(
|
||||
Map<String, dynamic>.from(changes as Map),
|
||||
);
|
||||
final truncated =
|
||||
chatTurnDiffTruncated(widget.summary) ||
|
||||
!capture.complete ||
|
||||
capture.omitted > 0;
|
||||
return [
|
||||
if (truncated)
|
||||
Padding(
|
||||
key: const Key('chat-turn-diff-truncated'),
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
chatTurnDiffTruncationNote(capture.diagnostic),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final file in capture.files)
|
||||
ChangeFileRow(
|
||||
key: ValueKey<String>('chat-turn-diff-file-${file.path}'),
|
||||
file: file,
|
||||
onOpen: (file) =>
|
||||
showFileDiffViewer(context, file, files: capture.files),
|
||||
),
|
||||
if (capture.omitted > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'${capture.omitted} more '
|
||||
'${capture.omitted == 1 ? 'file was' : 'files were'} '
|
||||
'omitted by the size limit.',
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user