Compare commits

..
2 Commits
9 changed files with 114 additions and 9 deletions

No files matched your search

+1
View File
@@ -17,3 +17,4 @@ captures
!*.xcworkspace/contents.xcworkspacedata !*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings **/xcshareddata/WorkspaceSettings.xcsettings
node_modules/ node_modules/
/bff/
@@ -29,6 +29,7 @@ import cn.xiaobai.openclawapp.feature.status.StatusScreen
import cn.xiaobai.openclawapp.ui.OpenClawTheme import cn.xiaobai.openclawapp.ui.OpenClawTheme
import cn.xiaobai.openclawapp.ui.StatusPill import cn.xiaobai.openclawapp.ui.StatusPill
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
@@ -93,6 +94,14 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
} }
} }
LaunchedEffect(appState.isConfigured) {
if (!appState.isConfigured) return@LaunchedEffect
while (isActive) {
delay(30_000)
appState.refreshOverviewSilently()
}
}
Scaffold( Scaffold(
topBar = { topBar = {
CenterAlignedTopAppBar( CenterAlignedTopAppBar(
@@ -201,7 +210,11 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
currentModel = appState.repository.status.currentModel, currentModel = appState.repository.status.currentModel,
availableAgents = appState.repository.availableAgents, availableAgents = appState.repository.availableAgents,
currentTheme = appState.themeMode, currentTheme = appState.themeMode,
onSelectAgent = appState::updateDefaultAgent, onSelectAgent = { agent ->
coroutineScope.launch {
appState.updateDefaultAgent(agent)
}
},
onSelectTheme = appState::updateTheme, onSelectTheme = appState::updateTheme,
onDisconnect = appState::disconnect, onDisconnect = appState::disconnect,
) )
@@ -81,6 +81,19 @@ class OpenClawAppState(
isSyncing = false isSyncing = false
} }
suspend fun refreshOverviewSilently() {
val remote = repository as? RemoteOpenClawRepository ?: return
if (isSyncing || sendingSessionId != null) return
runCatching {
remote.refreshStatus()
remote.refreshAgents()
remote.refreshSessions()
}.onFailure {
syncError = it.message ?: "远程同步失败"
}
}
suspend fun openSession(sessionId: String) { suspend fun openSession(sessionId: String) {
repository.markSessionOpened(sessionId) repository.markSessionOpened(sessionId)
activeSessionId = sessionId activeSessionId = sessionId
@@ -111,11 +124,17 @@ class OpenClawAppState(
sendingSessionId = null sendingSessionId = null
} }
fun updateDefaultAgent(agent: String) { suspend fun updateDefaultAgent(agent: String) {
serverConfig = serverConfig.copy(defaultAgent = agent) runCatching {
preferences.saveServerConfig(serverConfig) repository.updateDefaultAgent(agent)
repository.status = repository.status.copy(defaultAgent = agent) serverConfig = serverConfig.copy(defaultAgent = agent)
feedbackMessage = "默认 Agent 已切换到 $agent" preferences.saveServerConfig(serverConfig)
repository.status = repository.status.copy(defaultAgent = agent)
feedbackMessage = "默认 Agent 已切换到 $agent"
}.onFailure {
syncError = it.message ?: "默认 Agent 切换失败"
feedbackMessage = "默认 Agent 切换失败"
}
} }
fun updateTheme(theme: AppThemeMode) { fun updateTheme(theme: AppThemeMode) {
@@ -12,4 +12,5 @@ interface OpenClawRepository {
fun markSessionOpened(sessionId: String) fun markSessionOpened(sessionId: String)
fun togglePinned(sessionId: String): Boolean fun togglePinned(sessionId: String): Boolean
fun sendMessage(sessionId: String, text: String) fun sendMessage(sessionId: String, text: String)
suspend fun updateDefaultAgent(agent: String)
} }
@@ -16,7 +16,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -113,6 +113,14 @@ class RemoteOpenClawRepository(
) )
} }
override suspend fun updateDefaultAgent(agent: String) {
val remote = api.updateDefaultAgent(agent)
status = status.copy(
defaultAgent = remote.defaultAgent,
updatedAt = remote.updatedAt,
)
}
suspend fun refreshStatus() { suspend fun refreshStatus() {
val remote = api.getStatus() val remote = api.getStatus()
status = ServerStatus( status = ServerStatus(
@@ -155,7 +163,7 @@ class RemoteOpenClawRepository(
streamJob = streamScope.launch { streamJob = streamScope.launch {
while (currentCoroutineContext().isActive) { while (currentCoroutineContext().isActive) {
try { try {
sseStream.connect(sessionId).collectLatest { event -> sseStream.connect(sessionId).collect { event ->
when (event) { when (event) {
is SessionStreamEvent.Snapshot -> { is SessionStreamEvent.Snapshot -> {
val localPending = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") } val localPending = messageStore[sessionId].orEmpty().filter { it.id.startsWith("local-") }
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@@ -222,6 +223,7 @@ private fun MessageBubble(
MessageRole.Assistant -> "OpenClaw" MessageRole.Assistant -> "OpenClaw"
MessageRole.System -> "系统" MessageRole.System -> "系统"
} }
val isThinking = message.status == "thinking"
var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) } var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) }
LaunchedEffect(message.id, animateText) { LaunchedEffect(message.id, animateText) {
@@ -260,7 +262,25 @@ private fun MessageBubble(
.padding(14.dp), .padding(14.dp),
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
) { ) {
Text(text = displayText, style = MaterialTheme.typography.bodyLarge) if (isThinking) {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically,
) {
CircularProgressIndicator(
modifier = Modifier.size(18.dp),
strokeWidth = 2.dp,
color = MaterialTheme.colorScheme.onSecondaryContainer,
)
Text(
text = "正在思考…",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
} else {
Text(text = displayText, style = MaterialTheme.typography.bodyLarge)
}
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
@@ -6,6 +6,7 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get import io.ktor.client.request.get
import io.ktor.client.request.header import io.ktor.client.request.header
import io.ktor.client.request.post import io.ktor.client.request.post
import io.ktor.client.request.put
import io.ktor.client.request.setBody import io.ktor.client.request.setBody
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders import io.ktor.http.HttpHeaders
@@ -60,6 +61,14 @@ class MobileGatewayApi(
}.body() }.body()
} }
suspend fun updateDefaultAgent(agentId: String): UpdateDefaultAgentResponseDto {
return client.put("${baseUrl.trimEnd('/')}/api/settings/default-agent") {
authHeader()
contentType(ContentType.Application.Json)
setBody(UpdateDefaultAgentRequestDto(agentId = agentId))
}.body()
}
private fun io.ktor.client.request.HttpRequestBuilder.authHeader() { private fun io.ktor.client.request.HttpRequestBuilder.authHeader() {
val token = tokenProvider().trim() val token = tokenProvider().trim()
if (token.isNotBlank()) { if (token.isNotBlank()) {
@@ -55,3 +55,15 @@ data class AgentDto(
val id: String, val id: String,
val name: String, val name: String,
) )
@Serializable
data class UpdateDefaultAgentRequestDto(
val agentId: String,
)
@Serializable
data class UpdateDefaultAgentResponseDto(
val accepted: Boolean,
val defaultAgent: String,
val updatedAt: String,
)
+22
View File
@@ -3,6 +3,14 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
pluginManagement { pluginManagement {
repositories { repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google { google {
mavenContent { mavenContent {
includeGroupAndSubgroups("androidx") includeGroupAndSubgroups("androidx")
@@ -10,6 +18,9 @@ pluginManagement {
includeGroupAndSubgroups("com.google") includeGroupAndSubgroups("com.google")
} }
} }
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()
} }
@@ -20,6 +31,14 @@ plugins {
dependencyResolutionManagement { dependencyResolutionManagement {
repositories { repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google { google {
mavenContent { mavenContent {
includeGroupAndSubgroups("androidx") includeGroupAndSubgroups("androidx")
@@ -27,6 +46,9 @@ dependencyResolutionManagement {
includeGroupAndSubgroups("com.google") includeGroupAndSubgroups("com.google")
} }
} }
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral() mavenCentral()
} }
} }