Route local message writes through phase mapping
This commit is contained in:
1 parent
85b974b900
commit
7b56c88be9
3 files changed
+45
-13
No files matched your search
@@ -79,3 +79,29 @@ fun ChatMessage.isLocalPendingActive(): Boolean {
|
||||
fun ChatMessage.isLocalFailure(): Boolean {
|
||||
return localMessagePhase() == LocalMessagePhase.Failed
|
||||
}
|
||||
|
||||
fun textStatusForLocalPhase(
|
||||
phase: LocalMessagePhase,
|
||||
fallback: String = "queued",
|
||||
): String {
|
||||
return when (phase) {
|
||||
LocalMessagePhase.QueueProcessing -> "queue-draining"
|
||||
LocalMessagePhase.AutoRetrying -> "retrying-auto"
|
||||
LocalMessagePhase.ManualProcessing -> "queued"
|
||||
LocalMessagePhase.Failed -> "send-failed"
|
||||
else -> fallback
|
||||
}
|
||||
}
|
||||
|
||||
fun attachmentStatusForLocalPhase(
|
||||
phase: LocalMessagePhase,
|
||||
fallback: String = "uploading",
|
||||
): String {
|
||||
return when (phase) {
|
||||
LocalMessagePhase.QueueProcessing -> "queue-draining"
|
||||
LocalMessagePhase.ManualProcessing -> "uploading"
|
||||
LocalMessagePhase.Failed -> "upload-failed"
|
||||
LocalMessagePhase.Completed -> "uploaded"
|
||||
else -> fallback
|
||||
}
|
||||
}
|
||||
+18
-13
@@ -3,8 +3,11 @@ package cn.xiaobai.openclawapp.data
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import cn.xiaobai.openclawapp.data.LocalMessagePhase
|
||||
import cn.xiaobai.openclawapp.data.attachmentStatusForLocalPhase
|
||||
import cn.xiaobai.openclawapp.data.isLocalFailure
|
||||
import cn.xiaobai.openclawapp.data.isLocalPendingActive
|
||||
import cn.xiaobai.openclawapp.data.textStatusForLocalPhase
|
||||
import cn.xiaobai.openclawapp.network.MobileGatewayApi
|
||||
import cn.xiaobai.openclawapp.network.SessionSummaryDto
|
||||
import cn.xiaobai.openclawapp.network.SessionStreamEvent
|
||||
@@ -234,7 +237,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = text,
|
||||
createdAt = "现在",
|
||||
status = "queued",
|
||||
status = textStatusForLocalPhase(LocalMessagePhase.ManualProcessing),
|
||||
),
|
||||
ChatMessage(
|
||||
id = "local-thinking-$sessionId-${withoutThinking.size + 2}",
|
||||
@@ -279,7 +282,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = fileName,
|
||||
createdAt = "现在",
|
||||
status = "queue-draining",
|
||||
status = attachmentStatusForLocalPhase(LocalMessagePhase.QueueProcessing),
|
||||
kind = MessageKind.Attachment,
|
||||
contentType = contentType,
|
||||
sizeBytes = bytes.size,
|
||||
@@ -298,7 +301,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = remote.fileName,
|
||||
createdAt = remote.queuedAt,
|
||||
status = "uploaded",
|
||||
status = attachmentStatusForLocalPhase(LocalMessagePhase.Completed),
|
||||
kind = MessageKind.Attachment,
|
||||
contentType = remote.contentType,
|
||||
sizeBytes = remote.sizeBytes,
|
||||
@@ -316,7 +319,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = fileName,
|
||||
createdAt = "刚刚",
|
||||
status = "upload-failed",
|
||||
status = attachmentStatusForLocalPhase(LocalMessagePhase.Failed),
|
||||
kind = MessageKind.Attachment,
|
||||
contentType = contentType,
|
||||
sizeBytes = bytes.size,
|
||||
@@ -336,9 +339,10 @@ class RemoteOpenClawRepository(
|
||||
private suspend fun retryAttachmentInternal(sessionId: String, messageId: String, fromQueueDrain: Boolean) {
|
||||
val payload = attachmentRetryStore[messageId] ?: return
|
||||
val current = messageStore[sessionId].orEmpty()
|
||||
val phase = if (fromQueueDrain) LocalMessagePhase.QueueProcessing else LocalMessagePhase.ManualProcessing
|
||||
val uploading = current.map { msg ->
|
||||
if (msg.id == messageId) msg.copy(
|
||||
status = if (fromQueueDrain) "queue-draining" else "uploading",
|
||||
status = attachmentStatusForLocalPhase(phase),
|
||||
retryable = false,
|
||||
createdAt = "现在",
|
||||
) else msg
|
||||
@@ -357,7 +361,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = remote.fileName,
|
||||
createdAt = remote.queuedAt,
|
||||
status = "uploaded",
|
||||
status = attachmentStatusForLocalPhase(LocalMessagePhase.Completed),
|
||||
kind = MessageKind.Attachment,
|
||||
contentType = remote.contentType,
|
||||
sizeBytes = remote.sizeBytes,
|
||||
@@ -375,7 +379,7 @@ class RemoteOpenClawRepository(
|
||||
role = MessageRole.User,
|
||||
text = payload.fileName,
|
||||
createdAt = "刚刚",
|
||||
status = "upload-failed",
|
||||
status = attachmentStatusForLocalPhase(LocalMessagePhase.Failed),
|
||||
kind = MessageKind.Attachment,
|
||||
contentType = payload.contentType,
|
||||
sizeBytes = payload.bytes.size,
|
||||
@@ -503,13 +507,14 @@ class RemoteOpenClawRepository(
|
||||
val payload = textRetryStore[messageId] ?: return
|
||||
val current = messageStore[sessionId].orEmpty()
|
||||
val isAutoRetry = messageId in autoRetryMessageIds
|
||||
val phase = when {
|
||||
fromQueueDrain -> LocalMessagePhase.QueueProcessing
|
||||
isAutoRetry -> LocalMessagePhase.AutoRetrying
|
||||
else -> LocalMessagePhase.ManualProcessing
|
||||
}
|
||||
val retried = current.map { msg ->
|
||||
if (msg.id == messageId) msg.copy(
|
||||
status = when {
|
||||
fromQueueDrain -> "queue-draining"
|
||||
isAutoRetry -> "retrying-auto"
|
||||
else -> "queued"
|
||||
},
|
||||
status = textStatusForLocalPhase(phase),
|
||||
retryable = false,
|
||||
createdAt = "现在",
|
||||
) else msg
|
||||
@@ -801,7 +806,7 @@ class RemoteOpenClawRepository(
|
||||
)
|
||||
message.copy(
|
||||
id = failedId,
|
||||
status = "send-failed",
|
||||
status = textStatusForLocalPhase(LocalMessagePhase.Failed),
|
||||
retryable = true,
|
||||
createdAt = "刚刚",
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user