@@ -28,6 +28,7 @@ import androidx.compose.material.icons.Icons
2828import androidx.compose.material.icons.filled.Close
2929import androidx.compose.material.icons.filled.Home
3030import androidx.compose.material.icons.filled.KeyboardArrowDown
31+ import androidx.compose.material.icons.filled.KeyboardArrowUp
3132import androidx.compose.material.icons.filled.Settings
3233import androidx.compose.material.icons.filled.Storage
3334import androidx.compose.material.icons.outlined.AccessTime
@@ -40,6 +41,7 @@ import androidx.compose.material3.Icon
4041import androidx.compose.material3.IconButton
4142import androidx.compose.material3.Text
4243import androidx.compose.runtime.Composable
44+ import androidx.compose.runtime.collectAsState
4345import androidx.compose.runtime.getValue
4446import androidx.compose.runtime.mutableStateOf
4547import androidx.compose.runtime.remember
@@ -109,9 +111,15 @@ internal fun sidebarAgentRoster(
109111 )
110112}
111113
114+ private const val SIDEBAR_SESSION_LIMIT = 8
115+
116+ internal data class SidebarSessionPresentation (
117+ val sections : List <SessionSection >,
118+ val canExpand : Boolean ,
119+ )
120+
112121internal fun sidebarRecentSessions (
113122 sessions : List <ChatSessionEntry >,
114- limit : Int = 8,
115123): List <ChatSessionEntry > =
116124 sessions
117125 .asSequence()
@@ -120,8 +128,21 @@ internal fun sidebarRecentSessions(
120128 compareByDescending<ChatSessionEntry > { it.pinned == true }
121129 .thenByDescending { it.lastActivityAt ? : it.updatedAtMs ? : 0L }
122130 .thenBy { it.key },
123- ).take(limit.coerceAtLeast(0 ))
124- .toList()
131+ ).toList()
132+
133+ internal fun sidebarSessionPresentation (
134+ sessions : List <ChatSessionEntry >,
135+ knownGroups : List <String >,
136+ expanded : Boolean ,
137+ ): SidebarSessionPresentation {
138+ val recentSessions = sidebarRecentSessions(sessions)
139+ val visibleSessions =
140+ if (expanded) recentSessions else recentSessions.take(SIDEBAR_SESSION_LIMIT )
141+ return SidebarSessionPresentation (
142+ sections = groupSessionEntries(visibleSessions, knownGroups).filter { it.entries.isNotEmpty() },
143+ canExpand = recentSessions.size > SIDEBAR_SESSION_LIMIT ,
144+ )
145+ }
125146
126147internal fun sessionPresentationTitle (
127148 session : ChatSessionEntry ,
@@ -193,9 +214,16 @@ internal fun OpenClawSidebar(
193214) {
194215 val palette = sidebarPalette()
195216 val roster = sidebarAgentRoster(agents, selectedAgentId)
217+ val storedGroups by viewModel.sessionCustomGroups.collectAsState()
196218 var query by rememberSaveable { mutableStateOf(" " ) }
197219 var agentsExpanded by remember { mutableStateOf(false ) }
198- val recentSessions = sidebarRecentSessions(sessions)
220+ var sessionsExpanded by rememberSaveable { mutableStateOf(false ) }
221+ val recentPresentation =
222+ sidebarSessionPresentation(
223+ sessions = sessions,
224+ knownGroups = storedGroups,
225+ expanded = sessionsExpanded,
226+ )
199227 val connectionLabel = gatewayStatusLabel(connection)
200228 // Canonical debounced gateway search shared with the Sessions browser; the
201229 // controller falls back to filtering cached rows when the gateway is offline.
@@ -355,24 +383,40 @@ internal fun OpenClawSidebar(
355383 }
356384
357385 SidebarSectionTitle (nativeString(" Recent sessions" ), palette, modifier = Modifier .padding(top = 12 .dp))
358- if (recentSessions .isEmpty()) {
386+ if (recentPresentation.sections .isEmpty()) {
359387 Text (
360388 text = nativeString(" No recent sessions" ),
361389 style = ClawTheme .type.caption,
362390 color = palette.muted,
363391 modifier = Modifier .padding(horizontal = 12 .dp, vertical = 12 .dp),
364392 )
365393 } else {
366- Column (verticalArrangement = Arrangement .spacedBy(2 .dp)) {
367- recentSessions.forEach { session ->
368- SidebarSessionRow (
369- session = session,
370- selected = session.key == activeSessionKey,
371- palette = palette,
372- onClick = { onSelectSession(session) },
373- )
394+ recentPresentation.sections.forEach { section ->
395+ section.title?.let { title -> SidebarSectionTitle (title, palette) }
396+ Column (verticalArrangement = Arrangement .spacedBy(2 .dp)) {
397+ section.entries.forEach { session ->
398+ SidebarSessionRow (
399+ session = session,
400+ selected = session.key == activeSessionKey,
401+ palette = palette,
402+ onClick = { onSelectSession(session) },
403+ )
404+ }
374405 }
375406 }
407+ if (recentPresentation.canExpand) {
408+ SidebarActionRow (
409+ label = nativeString(if (sessionsExpanded) " Show less" else " Show more" ),
410+ icon =
411+ if (sessionsExpanded) {
412+ Icons .Default .KeyboardArrowUp
413+ } else {
414+ Icons .Default .KeyboardArrowDown
415+ },
416+ palette = palette,
417+ onClick = { sessionsExpanded = ! sessionsExpanded },
418+ )
419+ }
376420 }
377421 }
378422 }
0 commit comments