feat(chat): regenerate variants and support
Hide archived assistant variants in the linear chat view and track previous assistant as versions so regenerated responses do not duplicate or lose history. When regenerating, mark the previous assistant message with an archivedVariant flag for the UI and keep it in server history. Add a ChatMessageVersion model and a versions field to ChatMessage to store prior generated variants. Implement archiveLastAssistantAsVersion in chat providers to snapshot the last assistant message into versions and reset the message for a fresh streamed generation. Finalize flow updates to attach an adjacent archived assistant as a version when needed so the UI can present a switcher between current and past variants. These changes prevent duplicate messages, preserve previous responses, and enable variant switching.
This commit is contained in:
@@ -30,12 +30,40 @@ sealed class ChatMessage with _$ChatMessage {
|
||||
@Default(<ChatSourceReference>[])
|
||||
List<ChatSourceReference> sources,
|
||||
Map<String, dynamic>? usage,
|
||||
// Previous generated versions of this assistant message (OpenWebUI-style)
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@Default(<ChatMessageVersion>[])
|
||||
List<ChatMessageVersion> versions,
|
||||
}) = _ChatMessage;
|
||||
|
||||
factory ChatMessage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChatMessageFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ChatMessageVersion with _$ChatMessageVersion {
|
||||
const factory ChatMessageVersion({
|
||||
required String id,
|
||||
required String content,
|
||||
required DateTime timestamp,
|
||||
String? model,
|
||||
List<Map<String, dynamic>>? files,
|
||||
@JsonKey(
|
||||
name: 'sources',
|
||||
fromJson: _sourceRefsFromJson,
|
||||
toJson: _sourceRefsToJson,
|
||||
)
|
||||
@Default(<ChatSourceReference>[])
|
||||
List<ChatSourceReference> sources,
|
||||
@Default(<String>[]) List<String> followUps,
|
||||
@Default(<ChatCodeExecution>[]) List<ChatCodeExecution> codeExecutions,
|
||||
Map<String, dynamic>? usage,
|
||||
}) = _ChatMessageVersion;
|
||||
|
||||
factory ChatMessageVersion.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChatMessageVersionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ChatStatusUpdate with _$ChatStatusUpdate {
|
||||
const factory ChatStatusUpdate({
|
||||
|
||||
Reference in New Issue
Block a user