Files
pipelines/app/tool/perf/chat_question_fixture.dart
T
alan 509d4c624f 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>
2026-11-25 15:23:24 +00:00

99 lines
3.3 KiB
Dart

// An agent question for captures over the full-app fixture's `?chats=N`
// sessions (tool/perf/perf_fixture.dart). Off by default.
//
// `?question=opencode` 1.5 s after a chat subscribes, a pending question
// form arrives; chat_answer is acknowledged and then
// the server's `form.replied` resolution frame follows
// (OpenCode);
// `?question=claude` the same, but only the reply ack settles it (Claude
// Code's AskUserQuestion: the resolution comes later
// from the server's readback);
// `?question=fail` chat_answer is refused, so the card must stay.
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
Map<String, String> _params = const {};
void configureChatQuestionFixture(Map<String, String> params) =>
_params = params;
String get _mode => _params['question'] ?? '';
JsonMap _event(String sessionId, JsonMap body) => {
'type': 'chat_event',
'chat_event': {'session_id': sessionId, ...body},
};
/// Pushes the pending question into [sessionId] through [emit].
void chatQuestionStream(String sessionId, void Function(JsonMap frame) emit) {
if (_mode.isEmpty) return;
Timer(const Duration(milliseconds: 1500), () {
emit(
_event(sessionId, {
'kind': 'form',
'form': {
'id': '$sessionId-question',
'session_id': sessionId,
'kind': 'question',
'title': 'Database',
// Claude questions take a custom answer and can be dismissed.
if (_mode == 'claude') 'actions': ['accept', 'decline'],
'fields': [
{
'key': 'q0',
'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',
if (_mode == 'claude')
'description': 'Smaller, but **no** concurrent writers',
},
],
},
],
},
}),
);
});
}
/// The chat_answer reply, or null when `?question=` is off.
JsonMap? chatQuestionReply(JsonMap request) {
if (_mode.isEmpty || request['type'] != 'chat_answer') return null;
final id = request['id'];
if (_mode == 'fail') {
return {
'id': id,
'type': 'error',
'error': 'the question is no longer awaiting an answer',
};
}
return {'id': id, 'type': 'chat_answer'};
}
/// The OpenCode resolution frame that follows an accepted answer.
List<JsonMap> chatQuestionFollowUps(JsonMap request) {
if (_mode != 'opencode' || request['type'] != 'chat_answer') {
return const [];
}
final body = request['chat_answer'];
if (body is! Map) return const [];
final session = '${body['session_id'] ?? ''}';
return [
_event(session, {
'kind': 'form',
'form': {'id': body['form_id'], 'session_id': session, 'resolved': true},
}),
];
}