fix(chat): keep streamed reasoning live across queued follow-ups
This commit is contained in:
@@ -54,6 +54,7 @@ List<JsonMap> transcriptRows(
|
||||
List<JsonMap> messages, {
|
||||
List<JsonMap> trailing = const [],
|
||||
bool running = false,
|
||||
String? liveMessageId,
|
||||
}) {
|
||||
final rows = <JsonMap>[];
|
||||
String? key;
|
||||
@@ -114,14 +115,18 @@ 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') {
|
||||
// Prefer the assistant identity that actually streamed: a queued follow-up
|
||||
// can be later in the transcript while this same reply is still arriving.
|
||||
// Before a first delta, do not reopen an older reply behind a new user turn.
|
||||
final streamingId =
|
||||
liveMessageId ??
|
||||
(messages.isNotEmpty && messages.last['role'] == 'assistant'
|
||||
? '${messages.last['id'] ?? ''}'
|
||||
: null);
|
||||
if (running && streamingId != null) {
|
||||
for (final row in rows.reversed) {
|
||||
if (row['kind'] == 'assistant' &&
|
||||
(row['messageIds'] as List).contains(
|
||||
'${messages.last['id'] ?? ''}',
|
||||
)) {
|
||||
(row['messageIds'] as List).contains(streamingId)) {
|
||||
row['streaming'] = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user