Expose pending queue status in chat
This commit is contained in:
1 parent
d8a20bad3a
commit
ad4de3cbeb
6 files changed
+58
-9
No files matched your search
@@ -194,6 +194,13 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
isLoading = appState.isSyncing,
|
isLoading = appState.isSyncing,
|
||||||
errorMessage = appState.syncError,
|
errorMessage = appState.syncError,
|
||||||
streamStatus = appState.repository.streamStatusFor(activeSession.id),
|
streamStatus = appState.repository.streamStatusFor(activeSession.id),
|
||||||
|
pendingQueueStatus = appState.repository.pendingQueueStatus(activeSession.id).let { queue ->
|
||||||
|
when {
|
||||||
|
queue.isDraining && queue.sessionCount > 0 -> "当前会话还有 ${queue.sessionCount} 条待发消息,系统正在按本地队列继续发送。"
|
||||||
|
queue.sessionCount > 0 -> "当前会话还有 ${queue.sessionCount} 条待发消息未完成,可继续重试或等待下一次自动处理。"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
},
|
||||||
cacheNotice = if (appState.isShowingCachedData) {
|
cacheNotice = if (appState.isShowingCachedData) {
|
||||||
"当前展示的是本地缓存${appState.cacheSavedAt?.let { "(保存于 $it)" } ?: ""},正在等待最新数据。"
|
"当前展示的是本地缓存${appState.cacheSavedAt?.let { "(保存于 $it)" } ?: ""},正在等待最新数据。"
|
||||||
} else null,
|
} else null,
|
||||||
|
|||||||
@@ -41,3 +41,9 @@ data class ServerStatus(
|
|||||||
val defaultAgent: String,
|
val defaultAgent: String,
|
||||||
val updatedAt: String,
|
val updatedAt: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class PendingQueueStatus(
|
||||||
|
val totalCount: Int = 0,
|
||||||
|
val sessionCount: Int = 0,
|
||||||
|
val isDraining: Boolean = false,
|
||||||
|
)
|
||||||
@@ -11,6 +11,7 @@ interface OpenClawRepository {
|
|||||||
|
|
||||||
fun findSession(sessionId: String): SessionSummary?
|
fun findSession(sessionId: String): SessionSummary?
|
||||||
fun messagesFor(sessionId: String): List<ChatMessage>
|
fun messagesFor(sessionId: String): List<ChatMessage>
|
||||||
|
fun pendingQueueStatus(sessionId: String? = null): PendingQueueStatus
|
||||||
fun recentSession(): SessionSummary?
|
fun recentSession(): SessionSummary?
|
||||||
fun pinnedCount(): Int
|
fun pinnedCount(): Int
|
||||||
fun markSessionOpened(sessionId: String)
|
fun markSessionOpened(sessionId: String)
|
||||||
|
|||||||
+28
-9
@@ -81,11 +81,21 @@ class RemoteOpenClawRepository(
|
|||||||
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
||||||
private val pendingTextQueue = mutableMapOf<String, PendingTextSend>()
|
private val pendingTextQueue = mutableMapOf<String, PendingTextSend>()
|
||||||
private val autoRetryMessageIds = mutableSetOf<String>()
|
private val autoRetryMessageIds = mutableSetOf<String>()
|
||||||
|
private var drainingSessionIds by mutableStateOf<Set<String>>(emptySet())
|
||||||
|
|
||||||
override fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId }
|
override fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId }
|
||||||
|
|
||||||
override fun messagesFor(sessionId: String): List<ChatMessage> = messageStore[sessionId].orEmpty()
|
override fun messagesFor(sessionId: String): List<ChatMessage> = messageStore[sessionId].orEmpty()
|
||||||
|
|
||||||
|
override fun pendingQueueStatus(sessionId: String?): PendingQueueStatus {
|
||||||
|
val items = pendingTextQueue.values.filter { sessionId == null || it.sessionId == sessionId }
|
||||||
|
return PendingQueueStatus(
|
||||||
|
totalCount = pendingTextQueue.size,
|
||||||
|
sessionCount = items.size,
|
||||||
|
isDraining = sessionId?.let { it in drainingSessionIds } ?: drainingSessionIds.isNotEmpty(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun streamStatusFor(sessionId: String): String? = streamStatusStore[sessionId]
|
override fun streamStatusFor(sessionId: String): String? = streamStatusStore[sessionId]
|
||||||
|
|
||||||
override fun hydrateOverview(snapshot: OverviewSnapshot) {
|
override fun hydrateOverview(snapshot: OverviewSnapshot) {
|
||||||
@@ -465,17 +475,26 @@ class RemoteOpenClawRepository(
|
|||||||
.map { it.messageId }
|
.map { it.messageId }
|
||||||
if (candidates.isEmpty()) return false
|
if (candidates.isEmpty()) return false
|
||||||
|
|
||||||
var drained = false
|
val targetSessionIds = pendingTextQueue.values
|
||||||
for (messageId in candidates) {
|
.filter { sessionId == null || it.sessionId == sessionId }
|
||||||
val payload = pendingTextQueue[messageId] ?: continue
|
.map { it.sessionId }
|
||||||
drained = true
|
.toSet()
|
||||||
runCatching {
|
drainingSessionIds = drainingSessionIds + targetSessionIds
|
||||||
retryMessageInternal(payload.sessionId, messageId, fromQueueDrain = true)
|
try {
|
||||||
}.onFailure {
|
var drained = false
|
||||||
return drained
|
for (messageId in candidates) {
|
||||||
|
val payload = pendingTextQueue[messageId] ?: continue
|
||||||
|
drained = true
|
||||||
|
runCatching {
|
||||||
|
retryMessageInternal(payload.sessionId, messageId, fromQueueDrain = true)
|
||||||
|
}.onFailure {
|
||||||
|
return drained
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return drained
|
||||||
|
} finally {
|
||||||
|
drainingSessionIds = drainingSessionIds - targetSessionIds
|
||||||
}
|
}
|
||||||
return drained
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearPendingTextMessage(sessionId: String, text: String) {
|
private fun clearPendingTextMessage(sessionId: String, text: String) {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ fun ChatScreen(
|
|||||||
isLoading: Boolean,
|
isLoading: Boolean,
|
||||||
errorMessage: String?,
|
errorMessage: String?,
|
||||||
streamStatus: String?,
|
streamStatus: String?,
|
||||||
|
pendingQueueStatus: String?,
|
||||||
cacheNotice: String?,
|
cacheNotice: String?,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onRetry: () -> Unit,
|
onRetry: () -> Unit,
|
||||||
@@ -133,6 +134,20 @@ fun ChatScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pendingQueueStatus != null) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.65f)),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = pendingQueueStatus,
|
||||||
|
modifier = Modifier.padding(12.dp),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ Android/iOS App
|
|||||||
- [x] 聊天页已显式区分“自动重试中”和普通手动发送中状态
|
- [x] 聊天页已显式区分“自动重试中”和普通手动发送中状态
|
||||||
- [x] 已有第一版本地文本发送队列雏形:待发送文本会独立持久化,App 重启后可恢复并继续进入自动补发/手动重试链路
|
- [x] 已有第一版本地文本发送队列雏形:待发送文本会独立持久化,App 重启后可恢复并继续进入自动补发/手动重试链路
|
||||||
- [x] 已收紧文本队列自动补发语义:仅“从缓存恢复出的旧 queued 文本”保留一次自动补发资格;queue drain / 手动重试失败后会回到手动可重试,不再在同一次进入会话时被连打两次
|
- [x] 已收紧文本队列自动补发语义:仅“从缓存恢复出的旧 queued 文本”保留一次自动补发资格;queue drain / 手动重试失败后会回到手动可重试,不再在同一次进入会话时被连打两次
|
||||||
|
- [x] 聊天页已新增轻量 pending queue 状态提示:可看到当前会话剩余待发条数,以及系统是否正在按本地队列继续发送
|
||||||
- [x] 已有保守版 queue drain:`openSession()` 会尝试继续发送当前会话的待发文本,`syncRemoteIfNeeded()` 会顺序尝试全局待发文本,失败即停
|
- [x] 已有保守版 queue drain:`openSession()` 会尝试继续发送当前会话的待发文本,`syncRemoteIfNeeded()` 会顺序尝试全局待发文本,失败即停
|
||||||
- [x] 聊天页已显式区分 queue drain 状态:队列自动处理中的文本会显示“队列发送中”
|
- [x] 聊天页已显式区分 queue drain 状态:队列自动处理中的文本会显示“队列发送中”
|
||||||
- [ ] 还没有完整的离线发送队列(目前先覆盖文本,不含附件)
|
- [ ] 还没有完整的离线发送队列(目前先覆盖文本,不含附件)
|
||||||
|
|||||||
Reference in new issue
Block a user