Render agent questions as markdown

A question's text, its description and its options' descriptions now
use the transcript's markdown renderer (bold, code, lists, links) in
the card's own text styles; tapping an option's formatted description
still selects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 15:23:24 +00:00
parent 03688f0c1f
commit 509d4c624f
5 changed files with 93 additions and 6 deletions
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import '../../../core/api_gateway.dart';
import 'chat_card_styles.dart';
import 'chat_question_card_model.dart';
import 'chat_question_markdown.dart';
import 'chat_composer_bar.dart' show chatEnterSends;
import 'chat_no_reveal.dart';
import 'chat_question_option_controls.dart';
@@ -63,9 +64,12 @@ Widget _field({
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(label, style: chatCardLabelStyle(context)),
ChatQuestionMarkdown(label, style: chatCardLabelStyle(context)),
if (description.isNotEmpty && description != title)
Text(description, style: chatCardSecondaryStyle(context)),
ChatQuestionMarkdown(
description,
style: chatCardSecondaryStyle(context),
),
if ('${field['type'] ?? ''}' == 'external')
_external(context, field)
else if ('${field['type'] ?? ''}' == 'boolean')
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import '../ui/transcript/chat_markdown_view.dart';
/// A question's text (its title, description or an option's description)
/// rendered as markdown in [style]: agents format questions with bold, code,
/// lists and links, the same subset the transcript draws.
class ChatQuestionMarkdown extends StatelessWidget {
const ChatQuestionMarkdown(this.text, {super.key, this.style});
final String text;
final TextStyle? style;
@override
Widget build(BuildContext context) {
final view = ChatMarkdownView(text: text);
final style = this.style;
return style == null
? view
: DefaultTextStyle.merge(style: style, child: view);
}
}
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import 'chat_question_card_model.dart';
import 'chat_question_markdown.dart';
/// Native option controls for one question field. Single-select uses the host's
/// radio/checklist pattern, multi-select toggles choices, and `onChanged`
@@ -30,7 +31,7 @@ Widget chatQuestionOptionsField({
title: Text(chatQuestionOptionLabel(option)),
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
? null
: Text('${option['description']}'.trim()),
: ChatQuestionMarkdown('${option['description']}'.trim()),
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
onChanged: (on) => onChanged(
@@ -53,7 +54,7 @@ Widget chatQuestionOptionsField({
title: Text(chatQuestionOptionLabel(option)),
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
? null
: Text('${option['description']}'.trim()),
: ChatQuestionMarkdown('${option['description']}'.trim()),
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
),
@@ -345,6 +345,57 @@ void main() {
variant: TargetPlatformVariant.only(TargetPlatform.linux),
);
testWidgets('a question and its option descriptions render markdown', (
tester,
) async {
await tester.pumpWidget(
scrollHost(
ChatQuestionCard(
form: {
'id': 'q',
'kind': 'question',
'fields': [
{
'key': 'q0',
'title': 'Use **Postgres** or `sqlite`?',
'type': 'string',
'options': [
{
'value': 'A',
'label': 'A',
'description': 'Keeps **all** data',
},
],
},
],
},
onSubmit: (answers, action) async {},
),
),
);
await tester.pumpAndSettle();
// The markers are formatting, never shown as text.
expect(find.textContaining('**', findRichText: true), findsNothing);
expect(find.textContaining('`', findRichText: true), findsNothing);
// Bold wraps its words in a span of its own (visitChildren skips spans
// without text, so walk them directly).
final bold = <String>[];
void walk(InlineSpan span) {
if (span is! TextSpan) return;
if (span.style?.fontWeight == FontWeight.bold) {
bold.add(span.toPlainText());
}
for (final child in span.children ?? const <InlineSpan>[]) {
walk(child);
}
}
for (final text in tester.widgetList<RichText>(find.byType(RichText))) {
walk(text.text);
}
expect(bold, containsAll(['Postgres', 'all']));
});
testWidgets('dismissing a question sends the reply to the composer', (
tester,
) async {
+11 -2
View File
@@ -42,13 +42,22 @@ void chatQuestionStream(String sessionId, void Function(JsonMap frame) emit) {
'fields': [
{
'key': 'q0',
'title': 'Which database should the release use?',
'title': _mode == 'claude'
? 'Which **database** should the `release` use?\n\n'
'- Postgres keeps the current schema\n'
'- SQLite needs a migration'
: 'Which database should the release use?',
'type': 'string',
'required': true,
if (_mode == 'claude') 'custom': true,
'options': [
{'value': 'Postgres', 'label': 'Postgres'},
{'value': 'SQLite', 'label': 'SQLite'},
{
'value': 'SQLite',
'label': 'SQLite',
if (_mode == 'claude')
'description': 'Smaller, but **no** concurrent writers',
},
],
},
],