11package ai.openclaw.wear
22
3+ import ai.openclaw.wear.shared.WearAgentSummary
34import ai.openclaw.wear.shared.WearChatMessage
45import ai.openclaw.wear.shared.WearChatRole
56import ai.openclaw.wear.shared.WearConversationSnapshot
@@ -267,6 +268,8 @@ internal fun buildConversationSnapshot(
267268 selected = key == activeSessionKey,
268269 )
269270 }
271+ val activeAgentId = activeSessionKey.agentIdFromSessionKey()
272+ val agents = projectedSessions.mapNotNull { session -> session.id.agentIdFromSessionKey() }.distinct()
270273 val messages =
271274 ((history?.get(" messages" ) as ? JsonArray ).orEmpty()).mapIndexedNotNull { index, element ->
272275 val row = element.objectOrNull() ? : return @mapIndexedNotNull null
@@ -300,6 +303,15 @@ internal fun buildConversationSnapshot(
300303 } else {
301304 WearGatewayState .DISCONNECTED
302305 },
306+ activeAgentId = activeAgentId,
307+ agents =
308+ agents.map { agentId ->
309+ WearAgentSummary (
310+ id = agentId,
311+ name = agentId,
312+ selected = agentId == activeAgentId,
313+ )
314+ },
303315 activeSessionId = activeSessionKey,
304316 sessions = projectedSessions,
305317 messages = messages,
@@ -310,6 +322,16 @@ internal fun buildConversationSnapshot(
310322
311323private fun incompatible (): WearConversationClientResult = WearConversationClientResult (failure = WearConversationFailure .INCOMPATIBLE )
312324
325+ private fun String?.agentIdFromSessionKey (): String? {
326+ val key = this ?.trim().orEmpty()
327+ if (! key.startsWith(" agent:" )) return null
328+ return key
329+ .removePrefix(" agent:" )
330+ .substringBefore(' :' )
331+ .trim()
332+ .ifEmpty { null }
333+ }
334+
313335private fun JsonElement?.objectOrNull (): JsonObject ? = this as ? JsonObject
314336
315337private fun JsonObject.string (name : String ): String? = (this [name] as ? JsonPrimitive )?.takeIf { it.isString }?.contentOrNull
0 commit comments