Persist retryable message cache state
This commit is contained in:
1 parent
b3bcef7f79
commit
03ea1d959c
2 files changed
+44
-5
No files matched your search
@@ -94,8 +94,7 @@ class OpenClawAppState(
|
|||||||
remote.refreshAgents()
|
remote.refreshAgents()
|
||||||
remote.refreshSessions()
|
remote.refreshSessions()
|
||||||
preferences.saveOverviewSnapshot(remote.exportOverviewSnapshot())
|
preferences.saveOverviewSnapshot(remote.exportOverviewSnapshot())
|
||||||
val recentIds = listOfNotNull(activeSessionId, remote.recentSession()?.id).distinct().take(3)
|
persistRecentMessageCache(remote)
|
||||||
preferences.saveRecentMessageSnapshotBucket(remote.exportRecentMessageSnapshotBucket(recentIds))
|
|
||||||
isShowingCachedData = false
|
isShowingCachedData = false
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
syncError = it.message ?: "远程同步失败"
|
syncError = it.message ?: "远程同步失败"
|
||||||
@@ -126,8 +125,7 @@ class OpenClawAppState(
|
|||||||
isSyncing = true
|
isSyncing = true
|
||||||
runCatching {
|
runCatching {
|
||||||
remote.refreshMessages(sessionId)
|
remote.refreshMessages(sessionId)
|
||||||
val recentIds = listOf(sessionId) + repository.sessions.map { it.id }
|
persistRecentMessageCache(remote, preferredSessionId = sessionId)
|
||||||
preferences.saveRecentMessageSnapshotBucket(remote.exportRecentMessageSnapshotBucket(recentIds.take(3)))
|
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
syncError = it.message ?: "会话消息加载失败"
|
syncError = it.message ?: "会话消息加载失败"
|
||||||
feedbackMessage = "消息加载失败"
|
feedbackMessage = "消息加载失败"
|
||||||
@@ -144,7 +142,9 @@ class OpenClawAppState(
|
|||||||
sendingSessionId = sessionId
|
sendingSessionId = sessionId
|
||||||
runCatching {
|
runCatching {
|
||||||
remote.sendMessageRemote(sessionId, text)
|
remote.sendMessageRemote(sessionId, text)
|
||||||
|
persistRecentMessageCache(remote, preferredSessionId = sessionId)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
persistRecentMessageCache(remote, preferredSessionId = sessionId)
|
||||||
syncError = it.message ?: "消息发送失败"
|
syncError = it.message ?: "消息发送失败"
|
||||||
feedbackMessage = "消息发送失败"
|
feedbackMessage = "消息发送失败"
|
||||||
}
|
}
|
||||||
@@ -155,8 +155,10 @@ class OpenClawAppState(
|
|||||||
sendingSessionId = sessionId
|
sendingSessionId = sessionId
|
||||||
runCatching {
|
runCatching {
|
||||||
repository.retryMessage(sessionId, messageId)
|
repository.retryMessage(sessionId, messageId)
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
feedbackMessage = "已重新发送消息"
|
feedbackMessage = "已重新发送消息"
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
syncError = it.message ?: "消息重试失败"
|
syncError = it.message ?: "消息重试失败"
|
||||||
feedbackMessage = "消息重试失败"
|
feedbackMessage = "消息重试失败"
|
||||||
}
|
}
|
||||||
@@ -185,8 +187,10 @@ class OpenClawAppState(
|
|||||||
) {
|
) {
|
||||||
runCatching {
|
runCatching {
|
||||||
repository.uploadAttachmentStub(sessionId, fileName, bytes, contentType)
|
repository.uploadAttachmentStub(sessionId, fileName, bytes, contentType)
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
feedbackMessage = "附件已加入发送队列"
|
feedbackMessage = "附件已加入发送队列"
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
syncError = it.message ?: "附件上传失败"
|
syncError = it.message ?: "附件上传失败"
|
||||||
feedbackMessage = "附件上传失败"
|
feedbackMessage = "附件上传失败"
|
||||||
}
|
}
|
||||||
@@ -195,8 +199,10 @@ class OpenClawAppState(
|
|||||||
suspend fun retryAttachment(sessionId: String, messageId: String) {
|
suspend fun retryAttachment(sessionId: String, messageId: String) {
|
||||||
runCatching {
|
runCatching {
|
||||||
repository.retryAttachment(sessionId, messageId)
|
repository.retryAttachment(sessionId, messageId)
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
feedbackMessage = "已重新发起附件上传"
|
feedbackMessage = "已重新发起附件上传"
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
(repository as? RemoteOpenClawRepository)?.let { persistRecentMessageCache(it, preferredSessionId = sessionId) }
|
||||||
syncError = it.message ?: "附件重试失败"
|
syncError = it.message ?: "附件重试失败"
|
||||||
feedbackMessage = "附件重试失败"
|
feedbackMessage = "附件重试失败"
|
||||||
}
|
}
|
||||||
@@ -227,6 +233,17 @@ class OpenClawAppState(
|
|||||||
fun clearConfigError() {
|
fun clearConfigError() {
|
||||||
configError = null
|
configError = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun persistRecentMessageCache(
|
||||||
|
remote: RemoteOpenClawRepository,
|
||||||
|
preferredSessionId: String? = activeSessionId,
|
||||||
|
) {
|
||||||
|
val recentIds = listOfNotNull(preferredSessionId, remote.recentSession()?.id)
|
||||||
|
.plus(repository.sessions.map { it.id })
|
||||||
|
.distinct()
|
||||||
|
.take(3)
|
||||||
|
preferences.saveRecentMessageSnapshotBucket(remote.exportRecentMessageSnapshotBucket(recentIds))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MainTab {
|
enum class MainTab {
|
||||||
|
|||||||
+23
-1
@@ -84,7 +84,11 @@ class RemoteOpenClawRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hydrateRecentMessages(bucket: MessageCacheBucket) {
|
override fun hydrateRecentMessages(bucket: MessageCacheBucket) {
|
||||||
val restored = bucket.items.associate { item -> item.sessionId to item.messages.map { it.toDomain() } }
|
val restored = bucket.items.associate { item ->
|
||||||
|
item.sessionId to item.messages
|
||||||
|
.map { cached -> restoreCachedMessage(item.sessionId, cached) }
|
||||||
|
.filterNot { it.id.startsWith("local-thinking-") }
|
||||||
|
}
|
||||||
messageStore = messageStore + restored
|
messageStore = messageStore + restored
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,6 +526,24 @@ class RemoteOpenClawRepository(
|
|||||||
updateSessionPreview(sessionId, next.lastOrNull())
|
updateSessionPreview(sessionId, next.lastOrNull())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun restoreCachedMessage(sessionId: String, cached: MessageCacheItem): ChatMessage {
|
||||||
|
val domain = cached.toDomain()
|
||||||
|
return when {
|
||||||
|
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "queued" -> {
|
||||||
|
textRetryStore[domain.id] = TextRetryPayload(sessionId, domain.text)
|
||||||
|
domain.copy(status = "send-failed", retryable = true)
|
||||||
|
}
|
||||||
|
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "send-failed" -> {
|
||||||
|
textRetryStore[domain.id] = TextRetryPayload(sessionId, domain.text)
|
||||||
|
domain.copy(retryable = true)
|
||||||
|
}
|
||||||
|
domain.kind == MessageKind.Attachment && domain.status == "uploading" -> {
|
||||||
|
domain.copy(status = "upload-failed", retryable = false)
|
||||||
|
}
|
||||||
|
else -> domain
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun mergeSnapshotWithLocalPending(
|
private fun mergeSnapshotWithLocalPending(
|
||||||
remoteMessages: List<ChatMessage>,
|
remoteMessages: List<ChatMessage>,
|
||||||
localPending: List<ChatMessage>,
|
localPending: List<ChatMessage>,
|
||||||
|
|||||||
Reference in new issue
Block a user