feat: add interactive mock session behaviors
This commit is contained in:
1 parent
5c2ae565c8
commit
4acc08e2f8
8 files changed
+147
-12
No files matched your search
@@ -119,7 +119,10 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
||||||
modifier = contentModifier,
|
modifier = contentModifier,
|
||||||
sessions = appState.repository.sessions,
|
sessions = appState.repository.sessions,
|
||||||
|
recentSession = appState.repository.recentSession(),
|
||||||
|
pinnedCount = appState.repository.pinnedCount(),
|
||||||
onOpenSession = appState::openSession,
|
onOpenSession = appState::openSession,
|
||||||
|
onTogglePin = appState::togglePin,
|
||||||
)
|
)
|
||||||
|
|
||||||
appState.selectedTab == MainTab.Status -> StatusScreen(
|
appState.selectedTab == MainTab.Status -> StatusScreen(
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class OpenClawAppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openSession(sessionId: String) {
|
fun openSession(sessionId: String) {
|
||||||
|
repository.markSessionOpened(sessionId)
|
||||||
activeSessionId = sessionId
|
activeSessionId = sessionId
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,10 @@ class OpenClawAppState {
|
|||||||
serverConfig = serverConfig.copy(defaultAgent = agent)
|
serverConfig = serverConfig.copy(defaultAgent = agent)
|
||||||
repository.status = repository.status.copy(defaultAgent = agent)
|
repository.status = repository.status.copy(defaultAgent = agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun togglePin(sessionId: String) {
|
||||||
|
repository.togglePinned(sessionId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MainTab {
|
enum class MainTab {
|
||||||
|
|||||||
+55
-3
@@ -15,18 +15,21 @@ class MockOpenClawRepository {
|
|||||||
title = "主会话",
|
title = "主会话",
|
||||||
lastMessage = "先把移动端的接入方案定下来。",
|
lastMessage = "先把移动端的接入方案定下来。",
|
||||||
updatedAt = "刚刚",
|
updatedAt = "刚刚",
|
||||||
|
isPinned = true,
|
||||||
),
|
),
|
||||||
SessionSummary(
|
SessionSummary(
|
||||||
id = "agent:main:rd-lead",
|
id = "agent:main:rd-lead",
|
||||||
title = "rd-lead",
|
title = "rd-lead",
|
||||||
lastMessage = "架构方案已经同步。",
|
lastMessage = "架构方案已经同步。",
|
||||||
updatedAt = "10 分钟前",
|
updatedAt = "10 分钟前",
|
||||||
|
unreadCount = 2,
|
||||||
),
|
),
|
||||||
SessionSummary(
|
SessionSummary(
|
||||||
id = "agent:main:pm",
|
id = "agent:main:pm",
|
||||||
title = "pm",
|
title = "pm",
|
||||||
lastMessage = "MVP 范围保持克制。",
|
lastMessage = "MVP 范围保持克制。",
|
||||||
updatedAt = "1 小时前",
|
updatedAt = "1 小时前",
|
||||||
|
unreadCount = 1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -41,6 +44,9 @@ class MockOpenClawRepository {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var recentSessionId by mutableStateOf("agent:main:main")
|
||||||
|
private set
|
||||||
|
|
||||||
private var messageStore by mutableStateOf(
|
private var messageStore by mutableStateOf(
|
||||||
mapOf(
|
mapOf(
|
||||||
"agent:main:main" to listOf(
|
"agent:main:main" to listOf(
|
||||||
@@ -62,8 +68,31 @@ class MockOpenClawRepository {
|
|||||||
|
|
||||||
fun messagesFor(sessionId: String): List<ChatMessage> = messageStore[sessionId].orEmpty()
|
fun messagesFor(sessionId: String): List<ChatMessage> = messageStore[sessionId].orEmpty()
|
||||||
|
|
||||||
|
fun recentSession(): SessionSummary? = findSession(recentSessionId)
|
||||||
|
|
||||||
|
fun pinnedCount(): Int = sessions.count { it.isPinned }
|
||||||
|
|
||||||
|
fun markSessionOpened(sessionId: String) {
|
||||||
|
recentSessionId = sessionId
|
||||||
|
sessions = resortSessions(
|
||||||
|
sessions.map {
|
||||||
|
if (it.id == sessionId) it.copy(unreadCount = 0, updatedAt = "刚刚") else it
|
||||||
|
},
|
||||||
|
prioritizeId = sessionId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun togglePinned(sessionId: String) {
|
||||||
|
sessions = resortSessions(
|
||||||
|
sessions.map {
|
||||||
|
if (it.id == sessionId) it.copy(isPinned = !it.isPinned) else it
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun sendMessage(sessionId: String, text: String) {
|
fun sendMessage(sessionId: String, text: String) {
|
||||||
val currentMessages = messageStore[sessionId].orEmpty()
|
val currentMessages = messageStore[sessionId].orEmpty()
|
||||||
|
val assistantReply = mockAssistantReply(text)
|
||||||
val newMessages = currentMessages + ChatMessage(
|
val newMessages = currentMessages + ChatMessage(
|
||||||
id = Random.nextInt().toString(),
|
id = Random.nextInt().toString(),
|
||||||
role = MessageRole.User,
|
role = MessageRole.User,
|
||||||
@@ -72,14 +101,37 @@ class MockOpenClawRepository {
|
|||||||
) + ChatMessage(
|
) + ChatMessage(
|
||||||
id = Random.nextInt().toString(),
|
id = Random.nextInt().toString(),
|
||||||
role = MessageRole.Assistant,
|
role = MessageRole.Assistant,
|
||||||
text = "Mock 回复:后面这里会替换成真实 BFF 流式消息。",
|
text = assistantReply,
|
||||||
createdAt = "现在",
|
createdAt = "现在",
|
||||||
status = "stream-complete",
|
status = "stream-complete",
|
||||||
)
|
)
|
||||||
|
|
||||||
messageStore = messageStore + (sessionId to newMessages)
|
messageStore = messageStore + (sessionId to newMessages)
|
||||||
sessions = sessions.map {
|
recentSessionId = sessionId
|
||||||
if (it.id == sessionId) it.copy(lastMessage = text, updatedAt = "现在") else it
|
sessions = resortSessions(
|
||||||
|
sessions.map {
|
||||||
|
if (it.id == sessionId) it.copy(lastMessage = text, updatedAt = "现在", unreadCount = 0) else it
|
||||||
|
},
|
||||||
|
prioritizeId = sessionId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resortSessions(items: List<SessionSummary>, prioritizeId: String? = null): List<SessionSummary> {
|
||||||
|
val prioritized = items.firstOrNull { it.id == prioritizeId }
|
||||||
|
val others = items.filterNot { it.id == prioritizeId }
|
||||||
|
val base = buildList {
|
||||||
|
if (prioritized != null) add(prioritized)
|
||||||
|
addAll(others)
|
||||||
|
}
|
||||||
|
return base.sortedWith(compareByDescending<SessionSummary> { it.isPinned }.thenByDescending { it.id == prioritizeId })
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mockAssistantReply(text: String): String {
|
||||||
|
return when {
|
||||||
|
text.contains("总结") -> "Mock 回复:当前会话重点是先把 App 体验打磨好,再接 BFF 和真实 OpenClaw。"
|
||||||
|
text.contains("状态") -> "Mock 回复:当前链路状态正常,默认模型是 cliproxy/gpt-5.4。"
|
||||||
|
text.contains("下一步") -> "Mock 回复:建议下一步开始定义 Repository 接口和 BFF API DTO。"
|
||||||
|
else -> "Mock 回复:后面这里会替换成真实 BFF 流式消息。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,8 @@ data class SessionSummary(
|
|||||||
val title: String,
|
val title: String,
|
||||||
val lastMessage: String,
|
val lastMessage: String,
|
||||||
val updatedAt: String,
|
val updatedAt: String,
|
||||||
|
val isPinned: Boolean = false,
|
||||||
|
val unreadCount: Int = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ChatMessage(
|
data class ChatMessage(
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
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.weight
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
@@ -70,6 +70,19 @@ fun ChatScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") }
|
||||||
|
QuickActionButton("看状态") { onSend("看一下当前状态") }
|
||||||
|
QuickActionButton("下一步") { onSend("下一步建议做什么") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (messages.isEmpty()) {
|
if (messages.isEmpty()) {
|
||||||
EmptyStateCard(
|
EmptyStateCard(
|
||||||
title = "还没有消息",
|
title = "还没有消息",
|
||||||
@@ -127,6 +140,13 @@ fun ChatScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QuickActionButton(text: String, onClick: () -> Unit) {
|
||||||
|
Button(onClick = onClick, modifier = Modifier.weight(1f)) {
|
||||||
|
Text(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun MessageBubble(message: ChatMessage) {
|
private fun MessageBubble(message: ChatMessage) {
|
||||||
val alignment = when (message.role) {
|
val alignment = when (message.role) {
|
||||||
@@ -157,7 +177,7 @@ private fun MessageBubble(message: ChatMessage) {
|
|||||||
)
|
)
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clip(RoundedCornerShape(20.dp))
|
.clip(androidx.compose.foundation.shape.RoundedCornerShape(20.dp))
|
||||||
.background(bubbleColor)
|
.background(bubbleColor)
|
||||||
.padding(14.dp),
|
.padding(14.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
|||||||
+58
-7
@@ -6,8 +6,10 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
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.weight
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -31,7 +33,10 @@ import cn.xiaobai.openclawapp.ui.StatusPill
|
|||||||
fun SessionListScreen(
|
fun SessionListScreen(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
sessions: List<SessionSummary>,
|
sessions: List<SessionSummary>,
|
||||||
|
recentSession: SessionSummary?,
|
||||||
|
pinnedCount: Int,
|
||||||
onOpenSession: (String) -> Unit,
|
onOpenSession: (String) -> Unit,
|
||||||
|
onTogglePin: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
var query by remember { mutableStateOf("") }
|
var query by remember { mutableStateOf("") }
|
||||||
val filteredSessions = sessions.filter {
|
val filteredSessions = sessions.filter {
|
||||||
@@ -56,10 +61,40 @@ fun SessionListScreen(
|
|||||||
item {
|
item {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
MetricCard(title = "总会话", value = sessions.size.toString(), modifier = Modifier.weight(1f))
|
MetricCard(title = "总会话", value = sessions.size.toString(), modifier = Modifier.weight(1f))
|
||||||
|
MetricCard(title = "已置顶", value = pinnedCount.toString(), modifier = Modifier.weight(1f))
|
||||||
MetricCard(title = "筛选结果", value = filteredSessions.size.toString(), modifier = Modifier.weight(1f))
|
MetricCard(title = "筛选结果", value = filteredSessions.size.toString(), modifier = Modifier.weight(1f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (recentSession != null) {
|
||||||
|
item {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
Text("最近访问", style = MaterialTheme.typography.labelLarge)
|
||||||
|
Text(recentSession.title, style = MaterialTheme.typography.titleMedium)
|
||||||
|
Text(
|
||||||
|
recentSession.lastMessage,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Button(onClick = { onOpenSession(recentSession.id) }) {
|
||||||
|
Text("继续查看")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = query,
|
value = query,
|
||||||
@@ -81,9 +116,7 @@ fun SessionListScreen(
|
|||||||
} else {
|
} else {
|
||||||
items(filteredSessions, key = { it.id }) { session ->
|
items(filteredSessions, key = { it.id }) { session ->
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable { onOpenSession(session.id) },
|
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceContainerLow,
|
containerColor = MaterialTheme.colorScheme.surfaceContainerLow,
|
||||||
),
|
),
|
||||||
@@ -91,18 +124,28 @@ fun SessionListScreen(
|
|||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
.clickable { onOpenSession(session.id) }
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
Text(
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
text = session.title,
|
Text(
|
||||||
style = MaterialTheme.typography.titleMedium,
|
text = session.title,
|
||||||
)
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
)
|
||||||
|
if (session.isPinned) {
|
||||||
|
StatusPill(text = "置顶")
|
||||||
|
}
|
||||||
|
if (session.unreadCount > 0) {
|
||||||
|
StatusPill(text = "${session.unreadCount} 未读", highlighted = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
Text(
|
Text(
|
||||||
text = session.id,
|
text = session.id,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
@@ -116,6 +159,14 @@ fun SessionListScreen(
|
|||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
|
Button(onClick = { onOpenSession(session.id) }) {
|
||||||
|
Text("打开")
|
||||||
|
}
|
||||||
|
Button(onClick = { onTogglePin(session.id) }) {
|
||||||
|
Text(if (session.isPinned) "取消置顶" else "置顶")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cn.xiaobai.openclawapp.feature.status
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.weight
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
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.weight
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
|
|||||||
Reference in new issue
Block a user