fix(chat): keep historical cache out of the live transcript tail (#1253)
This commit is contained in:
1 parent
c581fd23d1
commit
94ec95a33c
18 files changed
+805
-18
No files matched your search
@@ -54,6 +54,8 @@ data class ChatMessageEntity(
|
||||
val sortGroup: Int = 1,
|
||||
@ColumnInfo(name = "sort_order", defaultValue = "0")
|
||||
val sortOrder: Long = 0,
|
||||
@ColumnInfo(name = "message_provenance", defaultValue = "'UNKNOWN'")
|
||||
val messageProvenance: String = "UNKNOWN",
|
||||
)
|
||||
|
||||
internal fun ChatMessageEntity.isSessionStartMarker(): Boolean =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.m57.hermescontrol.data.local
|
||||
|
||||
import com.m57.hermescontrol.ui.chat.ChatMessage
|
||||
import com.m57.hermescontrol.ui.chat.MessageProvenance
|
||||
import com.m57.hermescontrol.ui.chat.MessageRole
|
||||
import com.m57.hermescontrol.ui.chat.ToolStatus
|
||||
|
||||
@@ -40,6 +41,9 @@ fun ChatMessageEntity.toUiModel(): ChatMessage =
|
||||
completionId = completionId,
|
||||
restId = restId,
|
||||
localOrder = sortOrder.takeIf { sortGroup == 1 && it > 0 && !isSessionStartMarker() },
|
||||
messageProvenance =
|
||||
MessageProvenance.entries.firstOrNull { it.name == messageProvenance }
|
||||
?: MessageProvenance.UNKNOWN,
|
||||
)
|
||||
|
||||
fun ChatMessage.toEntity(sessionId: String): ChatMessageEntity =
|
||||
@@ -59,4 +63,5 @@ fun ChatMessage.toEntity(sessionId: String): ChatMessageEntity =
|
||||
tps = tps,
|
||||
completionId = completionId,
|
||||
restId = restId,
|
||||
messageProvenance = messageProvenance.name,
|
||||
)
|
||||
@@ -14,7 +14,7 @@ import java.io.File
|
||||
|
||||
@Database(
|
||||
entities = [ChatMessageEntity::class],
|
||||
version = 9,
|
||||
version = 10,
|
||||
exportSchema = true,
|
||||
)
|
||||
abstract class HermesDatabase : RoomDatabase() {
|
||||
@@ -115,6 +115,17 @@ abstract class HermesDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_9_10: Migration =
|
||||
object : Migration(9, 10) {
|
||||
override suspend fun migrate(connection: SQLiteConnection) {
|
||||
// v9 cannot prove whether a UUID-only row reached the server. Preserve that
|
||||
// ambiguity; only new outgoing prompts record LOCAL_PENDING before submit.
|
||||
connection.execSQL(
|
||||
"ALTER TABLE chat_messages ADD COLUMN message_provenance TEXT NOT NULL DEFAULT 'UNKNOWN'",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun get(context: Context): HermesDatabase =
|
||||
withContext(Dispatchers.IO) {
|
||||
instance?.let { return@withContext it }
|
||||
@@ -152,6 +163,7 @@ abstract class HermesDatabase : RoomDatabase() {
|
||||
MIGRATION_6_7,
|
||||
MIGRATION_7_8,
|
||||
MIGRATION_8_9,
|
||||
MIGRATION_9_10,
|
||||
).fallbackToDestructiveMigration(false)
|
||||
.build()
|
||||
.also { instance = it }
|
||||
|
||||
Reference in new issue
Block a user