Place items shown mid-turn inside the running turn
Live chat events name a message by id and carry no time, so messages the client created from them had no created_at. A running turn then had no timed rows, and an item the agent showed mid-turn (show_file, show_diff) was placed after the last timed row: above the prompt and the whole running reply, usually off screen, until a reload brought the server's times. Messages created from live events are now stamped with their arrival; a history read still replaces them with the server's times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -172,7 +172,13 @@ List<JsonMap> chatMessageList(Object? messages) => [
|
||||
/// Fold a live chat frame into an immutable thread snapshot. Text and reasoning
|
||||
/// deltas append by part id, tool snapshots merge without dropping prior fields,
|
||||
/// and step frames update turn activity. Frames for another session are ignored.
|
||||
JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
/// A live event names a message by id and carries no time, so a message this
|
||||
/// creates is stamped with when it arrived ([now], epoch ms). Without one, a
|
||||
/// running turn has no timed rows and an item the agent shows mid-turn
|
||||
/// (show_file, show_diff) is placed above the whole turn; a later history
|
||||
/// read replaces the stamp with the server's own time.
|
||||
JsonMap applyChatEvent(JsonMap thread, JsonMap frame, {int Function()? now}) {
|
||||
int arrived() => (now ?? _nowMs)();
|
||||
final session = thread['sessionId'];
|
||||
if (session != null &&
|
||||
frame['session_id'] != null &&
|
||||
@@ -203,6 +209,7 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
'id': id,
|
||||
'session_id': frame['session_id'],
|
||||
'role': 'user',
|
||||
'created_at': arrived(),
|
||||
'client': frame['client'],
|
||||
'operation_id': frame['operation_id'],
|
||||
'parts': [
|
||||
@@ -229,6 +236,7 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
'id': messageId,
|
||||
'session_id': frame['session_id'],
|
||||
'role': 'assistant',
|
||||
'created_at': arrived(),
|
||||
'kind': ?injected,
|
||||
'parts': <JsonMap>[],
|
||||
});
|
||||
@@ -341,3 +349,5 @@ String latestReplyModel(List<JsonMap> messages) {
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
int _nowMs() => DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
Reference in New Issue
Block a user