Chat: answered questions collapse into their turn like tool calls

This commit is contained in:
2026-11-03 19:31:40 +00:00
parent fa6c0864db
commit fc94210595
14 changed files with 760 additions and 38 deletions
@@ -369,7 +369,10 @@ class ChatThreadController extends ChangeNotifier {
if (body['kind'] == 'form') {
final form = body['form'];
if (form is! Map) return;
_cards.foldForm(Map<String, dynamic>.from(form));
_cards.foldForm(
Map<String, dynamic>.from(form),
raisedIn: _answeringMessageId(),
);
return;
}
final current = _thread;
@@ -415,6 +418,21 @@ class ChatThreadController extends ChangeNotifier {
].any((key) => usage[key] != null);
}
/// The agent message a question frame arrives during: the streamed reply,
/// else the last answer when it is the agent's. A question raised before the
/// reply starts names none rather than an older turn.
String? _answeringMessageId() {
final live = _liveAssistantMessageId;
if (live != null && live.isNotEmpty) return live;
for (final message in _messages.reversed) {
if (chatInjectedKind(message) != null) continue;
if (message['role'] != 'assistant') return null;
final id = '${message['id'] ?? ''}'.trim();
return id.isEmpty ? null : id;
}
return null;
}
/// The pushed envelope body, or null for another message type. The server
/// wraps `chat_event` in the typed envelope; domain code never sees the
/// transport fields.