fix(chat): keep provided reasoning visible during live replies

This commit is contained in:
2026-10-24 01:59:52 +01:00
parent 7f88f14a52
commit fa818341cf
10 changed files with 330 additions and 96 deletions
@@ -53,6 +53,7 @@ JsonMap mergeChatHistory(JsonMap previous, JsonMap page, {bool older = false}) {
List<JsonMap> transcriptRows(
List<JsonMap> messages, {
List<JsonMap> trailing = const [],
bool running = false,
}) {
final rows = <JsonMap>[];
String? key;
@@ -113,6 +114,19 @@ List<JsonMap> transcriptRows(
}
}
flush();
// Only the newest assistant turn can be live. A running step before the
// first assistant delta must not reopen reasoning from an earlier reply.
if (running && messages.isNotEmpty && messages.last['role'] == 'assistant') {
for (final row in rows.reversed) {
if (row['kind'] == 'assistant' &&
(row['messageIds'] as List).contains(
'${messages.last['id'] ?? ''}',
)) {
row['streaming'] = true;
break;
}
}
}
rows.addAll(trailing);
return rows;
}