Compare commits

...
2 Commits
9 changed files with 109 additions and 4 deletions

No files matched your search

+1
View File
@@ -17,3 +17,4 @@ captures
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
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.StatusPill
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
@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(
topBar = {
CenterAlignedTopAppBar(
@@ -201,7 +210,11 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
currentModel = appState.repository.status.currentModel,
availableAgents = appState.repository.availableAgents,
currentTheme = appState.themeMode,
onSelectAgent = appState::updateDefaultAgent,
onSelectAgent = { agent ->
coroutineScope.launch {
appState.updateDefaultAgent(agent)
}
},
onSelectTheme = appState::updateTheme,
onDisconnect = appState::disconnect,
)
@@ -81,6 +81,19 @@ class OpenClawAppState(
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) {
repository.markSessionOpened(sessionId)
activeSessionId = sessionId
@@ -111,11 +124,17 @@ class OpenClawAppState(
sendingSessionId = null
}
fun updateDefaultAgent(agent: String) {
suspend fun updateDefaultAgent(agent: String) {
runCatching {
repository.updateDefaultAgent(agent)
serverConfig = serverConfig.copy(defaultAgent = 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) {
@@ -12,4 +12,5 @@ interface OpenClawRepository {
fun markSessionOpened(sessionId: String)
fun togglePinned(sessionId: String): Boolean
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.currentCoroutineContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.isActive
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() {
val remote = api.getStatus()
status = ServerStatus(
@@ -155,7 +163,7 @@ class RemoteOpenClawRepository(
streamJob = streamScope.launch {
while (currentCoroutineContext().isActive) {
try {
sseStream.connect(sessionId).collectLatest { event ->
sseStream.connect(sessionId).collect { event ->
when (event) {
is SessionStreamEvent.Snapshot -> {
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.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
@@ -222,6 +223,7 @@ private fun MessageBubble(
MessageRole.Assistant -> "OpenClaw"
MessageRole.System -> "系统"
}
val isThinking = message.status == "thinking"
var visibleChars by remember(message.id) { mutableIntStateOf(if (animateText) 0 else message.text.length) }
LaunchedEffect(message.id, animateText) {
@@ -260,7 +262,25 @@ private fun MessageBubble(
.padding(14.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
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(
modifier = Modifier.fillMaxWidth(),
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.header
import io.ktor.client.request.post
import io.ktor.client.request.put
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
@@ -60,6 +61,14 @@ class MobileGatewayApi(
}.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() {
val token = tokenProvider().trim()
if (token.isNotBlank()) {
@@ -55,3 +55,15 @@ data class AgentDto(
val id: 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 {
repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google {
mavenContent {
includeGroupAndSubgroups("androidx")
@@ -10,6 +18,9 @@ pluginManagement {
includeGroupAndSubgroups("com.google")
}
}
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral()
gradlePluginPortal()
}
@@ -20,6 +31,14 @@ plugins {
dependencyResolutionManagement {
repositories {
maven("https://maven.aliyun.com/repository/google") {
name = "AliyunGoogle"
mavenContent {
includeGroupAndSubgroups("androidx")
includeGroupAndSubgroups("com.android")
includeGroupAndSubgroups("com.google")
}
}
google {
mavenContent {
includeGroupAndSubgroups("androidx")
@@ -27,6 +46,9 @@ dependencyResolutionManagement {
includeGroupAndSubgroups("com.google")
}
}
maven("https://maven.aliyun.com/repository/public") {
name = "AliyunPublic"
}
mavenCentral()
}
}