feat(chat): fold answered permissions into a turn chip like tool calls

This commit is contained in:
2026-10-24 16:05:47 +01:00
parent c7852d27d1
commit 2740bb0673
10 changed files with 536 additions and 105 deletions
@@ -16,11 +16,20 @@ typedef ChatMessageTextBuilder = Widget Function(BuildContext, String);
/// One `transcriptRows` row: a user message or one folded agent turn. Parts keep
/// order for agent turns; native disclosures retain unknown parts as raw JSON.
class ChatMessageView extends StatelessWidget {
const ChatMessageView({super.key, required this.row, this.textBuilder});
const ChatMessageView({
super.key,
required this.row,
this.textBuilder,
this.footer = const [],
});
final JsonMap row;
final ChatMessageTextBuilder? textBuilder;
/// More of an agent turn's summary chips, after its tools chip (the turn's
/// settled permission requests).
final List<Widget> footer;
@override
Widget build(BuildContext context) {
final user = row['kind'] == 'user';
@@ -205,6 +214,7 @@ class ChatMessageView extends StatelessWidget {
final model = '${row['model'] ?? ''}'.trim();
final footer = <Widget>[
if (tools.isNotEmpty) ChatToolCallsChip(calls: tools),
...this.footer,
if (model.isNotEmpty)
Text(
model,
@@ -5,6 +5,7 @@ import '../../../../core/api_gateway.dart';
import '../../../../ui/text/monospace.dart';
import '../../domain/chat_tool_calls.dart';
import '../sessions/chat_adaptive.dart';
import 'chat_turn_chip.dart';
import 'native_disclosure.dart';
/// A turn's one tool summary below its answer, as the web's chip: `N tools`,
@@ -41,7 +42,7 @@ class ChatToolCallsChip extends StatelessWidget {
size: 14,
color: color,
);
return _TurnChip(
return ChatTurnChip(
chipKey: const Key('chat-tool-chip'),
leading: leading,
label: label,
@@ -54,91 +55,6 @@ class ChatToolCallsChip extends StatelessWidget {
}
}
/// The quiet tool chip shell and its native sheet.
class _TurnChip extends StatelessWidget {
const _TurnChip({
required this.chipKey,
required this.leading,
required this.label,
required this.color,
required this.semanticsLabel,
required this.sheet,
});
final Key chipKey;
final Widget leading;
final String label;
final Color color;
final String semanticsLabel;
final Widget sheet;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
leading,
const SizedBox(width: 6),
Text(label, style: TextStyle(color: color, fontSize: 13)),
Icon(
cupertino ? CupertinoIcons.chevron_up : Icons.expand_less,
size: 14,
color: color,
),
],
);
return Semantics(
button: true,
// The child's own action is excluded with its label, so the node
// carries the activation for assistive technology.
onTap: () => _open(context, cupertino),
label: semanticsLabel,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 2),
child: cupertino
? CupertinoButton(
key: chipKey,
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
minimumSize: Size.zero,
onPressed: () => _open(context, cupertino),
child: content,
)
: InkWell(
key: chipKey,
borderRadius: BorderRadius.circular(8),
onTap: () => _open(context, cupertino),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 6,
),
child: content,
),
),
),
);
}
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,
);
}
}
class _ToolCallsSheet extends StatelessWidget {
const _ToolCallsSheet({required this.calls});
@@ -0,0 +1,91 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../sessions/chat_adaptive.dart';
/// The quiet chip under an agent turn (its tools, its permissions) and the
/// native sheet it opens.
class ChatTurnChip extends StatelessWidget {
const ChatTurnChip({
super.key,
required this.chipKey,
required this.leading,
required this.label,
required this.color,
required this.semanticsLabel,
required this.sheet,
});
final Key chipKey;
final Widget leading;
final String label;
final Color color;
final String semanticsLabel;
final Widget sheet;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
leading,
const SizedBox(width: 6),
Text(label, style: TextStyle(color: color, fontSize: 13)),
Icon(
cupertino ? CupertinoIcons.chevron_up : Icons.expand_less,
size: 14,
color: color,
),
],
);
return Semantics(
button: true,
// The child's own action is excluded with its label, so the node
// carries the activation for assistive technology.
onTap: () => _open(context, cupertino),
label: semanticsLabel,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 2),
child: cupertino
? CupertinoButton(
key: chipKey,
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
minimumSize: Size.zero,
onPressed: () => _open(context, cupertino),
child: content,
)
: InkWell(
key: chipKey,
borderRadius: BorderRadius.circular(8),
onTap: () => _open(context, cupertino),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 6,
),
child: content,
),
),
),
);
}
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,
);
}
}