chore: upgrade ktlint to 1.8.0 and format codebase (#1024)
Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
3f3b853758
commit
cfe3e736fd
66 files changed
+1287
-541
No files matched your search
@@ -62,7 +62,12 @@ data class BotsUiState(
|
||||
profiles.find { it.is_default == true || it.name == "default" }
|
||||
?: profiles.firstOrNull()
|
||||
val syncSnapshot = defaultProfile?.groupChatSyncSnapshot()
|
||||
val deletedKeys = syncSnapshot?.deleted?.keys.orEmpty().map { it.lowercase() }
|
||||
val deletedKeys =
|
||||
syncSnapshot
|
||||
?.deleted
|
||||
?.keys
|
||||
.orEmpty()
|
||||
.map { it.lowercase() }
|
||||
|
||||
val groupNameMap = linkedMapOf<String, String>()
|
||||
|
||||
@@ -101,61 +106,63 @@ data class BotsUiState(
|
||||
}
|
||||
}
|
||||
|
||||
return groupNameMap.values.map { gName ->
|
||||
val lower = gName.lowercase()
|
||||
val matchingRoom =
|
||||
snapshotRooms[gName]
|
||||
?: snapshotRooms["name:$gName"]
|
||||
?: snapshotRooms["id:$gName"]
|
||||
?: snapshotRooms.values.find { it.name.equals(gName, ignoreCase = true) }
|
||||
return groupNameMap.values
|
||||
.map { gName ->
|
||||
val lower = gName.lowercase()
|
||||
val matchingRoom =
|
||||
snapshotRooms[gName]
|
||||
?: snapshotRooms["name:$gName"]
|
||||
?: snapshotRooms["id:$gName"]
|
||||
?: snapshotRooms.values.find { it.name.equals(gName, ignoreCase = true) }
|
||||
|
||||
val roomMemberNames = matchingRoom?.memberNames.orEmpty().map { it.lowercase() }
|
||||
val roomMemberNames = matchingRoom?.memberNames.orEmpty().map { it.lowercase() }
|
||||
|
||||
val matchedProfiles =
|
||||
profiles.filter { profile ->
|
||||
val botGroups = profile.botMeta()?.allGroups.orEmpty()
|
||||
botGroups.any { it.equals(gName, ignoreCase = true) } ||
|
||||
roomMemberNames.contains(profile.name.lowercase()) ||
|
||||
roomMemberNames.contains(profile.effectiveTitle.lowercase())
|
||||
}.toMutableList()
|
||||
val matchedProfiles =
|
||||
profiles
|
||||
.filter { profile ->
|
||||
val botGroups = profile.botMeta()?.allGroups.orEmpty()
|
||||
botGroups.any { it.equals(gName, ignoreCase = true) } ||
|
||||
roomMemberNames.contains(profile.name.lowercase()) ||
|
||||
roomMemberNames.contains(profile.effectiveTitle.lowercase())
|
||||
}.toMutableList()
|
||||
|
||||
// If room listed members (e.g. remote bots or bots not in local profiles), ensure they are seated
|
||||
if (matchingRoom != null && roomMemberNames.isNotEmpty()) {
|
||||
for (mName in matchingRoom.memberNames) {
|
||||
val exists =
|
||||
matchedProfiles.any {
|
||||
it.name.equals(mName, ignoreCase = true) ||
|
||||
it.effectiveTitle.equals(mName, ignoreCase = true)
|
||||
// If room listed members (e.g. remote bots or bots not in local profiles), ensure they are seated
|
||||
if (matchingRoom != null && roomMemberNames.isNotEmpty()) {
|
||||
for (mName in matchingRoom.memberNames) {
|
||||
val exists =
|
||||
matchedProfiles.any {
|
||||
it.name.equals(mName, ignoreCase = true) ||
|
||||
it.effectiveTitle.equals(mName, ignoreCase = true)
|
||||
}
|
||||
if (!exists) {
|
||||
val local = profiles.find { it.name.equals(mName, ignoreCase = true) }
|
||||
matchedProfiles.add(local ?: ProfileInfo(name = mName))
|
||||
}
|
||||
if (!exists) {
|
||||
val local = profiles.find { it.name.equals(mName, ignoreCase = true) }
|
||||
matchedProfiles.add(local ?: ProfileInfo(name = mName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var groupMembers: List<ProfileInfo> = matchedProfiles
|
||||
var groupMembers: List<ProfileInfo> = matchedProfiles
|
||||
|
||||
// Fallback: If group name was composed from bot names (e.g. "default, scoutbot")
|
||||
if (groupMembers.isEmpty() && gName.contains(",")) {
|
||||
val targetNames = gName.split(",").map { it.trim().lowercase() }
|
||||
groupMembers = profiles.filter { targetNames.contains(it.name.lowercase()) }
|
||||
}
|
||||
// Fallback: If group name was composed from bot names (e.g. "default, scoutbot")
|
||||
if (groupMembers.isEmpty() && gName.contains(",")) {
|
||||
val targetNames = gName.split(",").map { it.trim().lowercase() }
|
||||
groupMembers = profiles.filter { targetNames.contains(it.name.lowercase()) }
|
||||
}
|
||||
|
||||
val lastAt =
|
||||
matchingRoom?.log?.lastOrNull()?.at
|
||||
?: matchingRoom?.updatedAt
|
||||
?: 0L
|
||||
val lastAt =
|
||||
matchingRoom?.log?.lastOrNull()?.at
|
||||
?: matchingRoom?.updatedAt
|
||||
?: 0L
|
||||
|
||||
GroupInfo(
|
||||
name = gName,
|
||||
members = groupMembers,
|
||||
lastActivity = lastAt,
|
||||
GroupInfo(
|
||||
name = gName,
|
||||
members = groupMembers,
|
||||
lastActivity = lastAt,
|
||||
)
|
||||
}.sortedWith(
|
||||
compareByDescending<GroupInfo> { it.lastActivity }
|
||||
.thenBy { it.name },
|
||||
)
|
||||
}.sortedWith(
|
||||
compareByDescending<GroupInfo> { it.lastActivity }
|
||||
.thenBy { it.name },
|
||||
)
|
||||
}
|
||||
|
||||
val displayGroups: List<GroupInfo>
|
||||
@@ -193,15 +200,13 @@ data class BotsUiState(
|
||||
profile.name.lowercase().contains(query) ||
|
||||
profile.effectiveTitle.lowercase().contains(query) ||
|
||||
profile.effectiveDescription.lowercase().contains(query)
|
||||
}
|
||||
.sortedWith(
|
||||
}.sortedWith(
|
||||
compareByDescending<ProfileInfo> { it.name == activeProfileName }
|
||||
.thenByDescending {
|
||||
it.canonical_session?.last_active
|
||||
?: it.last_session?.last_active
|
||||
?: 0.0
|
||||
}
|
||||
.thenBy { it.name },
|
||||
}.thenBy { it.name },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -464,13 +469,14 @@ class BotsViewModel(
|
||||
rooms = updatedRooms,
|
||||
deleted = updatedDeleted,
|
||||
)
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to mapOf("hermes-bots-groups" to newSnapshot.toMap()),
|
||||
),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to mapOf("hermes-bots-groups" to newSnapshot.toMap()),
|
||||
),
|
||||
).await()
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
@@ -528,13 +534,14 @@ class BotsViewModel(
|
||||
rooms = updatedRooms,
|
||||
deleted = deletedMap,
|
||||
)
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to mapOf("hermes-bots-groups" to newSnapshot.toMap()),
|
||||
),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to mapOf("hermes-bots-groups" to newSnapshot.toMap()),
|
||||
),
|
||||
).await()
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
|
||||
@@ -100,8 +100,7 @@ fun CreateGroupChatDialog(
|
||||
} else {
|
||||
selectedBots + bot.name
|
||||
}
|
||||
}
|
||||
.padding(vertical = 4.dp),
|
||||
}.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Checkbox(
|
||||
|
||||
@@ -303,12 +303,13 @@ class GroupChatViewModel(
|
||||
val roomMemberNames = matchingRoom?.memberNames.orEmpty().map { it.lowercase() }
|
||||
|
||||
val matchedProfiles =
|
||||
allProfiles.filter {
|
||||
val botGroups = it.botMeta()?.allGroups.orEmpty()
|
||||
botGroups.any { g -> g.equals(groupName, ignoreCase = true) } ||
|
||||
roomMemberNames.contains(it.name.lowercase()) ||
|
||||
roomMemberNames.contains(it.effectiveTitle.lowercase())
|
||||
}.toMutableList()
|
||||
allProfiles
|
||||
.filter {
|
||||
val botGroups = it.botMeta()?.allGroups.orEmpty()
|
||||
botGroups.any { g -> g.equals(groupName, ignoreCase = true) } ||
|
||||
roomMemberNames.contains(it.name.lowercase()) ||
|
||||
roomMemberNames.contains(it.effectiveTitle.lowercase())
|
||||
}.toMutableList()
|
||||
|
||||
// If room listed members (e.g. remote bots or bots not in local profiles), ensure they are seated
|
||||
if (matchingRoom != null && roomMemberNames.isNotEmpty()) {
|
||||
@@ -350,7 +351,11 @@ class GroupChatViewModel(
|
||||
initialMessages =
|
||||
syncedLog.map { entry ->
|
||||
val isUser = entry.from?.kind != "member"
|
||||
val senderName = entry.from?.name.orEmpty().ifBlank { if (isUser) "user" else "bot" }
|
||||
val senderName =
|
||||
entry.from
|
||||
?.name
|
||||
.orEmpty()
|
||||
.ifBlank { if (isUser) "user" else "bot" }
|
||||
val memberProfile =
|
||||
allProfiles.find {
|
||||
it.name.equals(senderName, ignoreCase = true) ||
|
||||
@@ -465,13 +470,14 @@ class GroupChatViewModel(
|
||||
|
||||
val uiMetaPayload = mapOf("hermes-bots-groups" to newSnapshot.toMap())
|
||||
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
} catch (e: Exception) {
|
||||
Log.w("GroupChatViewModel", "updateGroupLimits failed: ${e.message}")
|
||||
}
|
||||
@@ -559,13 +565,14 @@ class GroupChatViewModel(
|
||||
val newSnapshot = existingSnapshot.copy(version = 3, updatedAt = now, rooms = updatedRooms)
|
||||
val uiMetaPayload = mapOf("hermes-bots-groups" to newSnapshot.toMap())
|
||||
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
@@ -629,10 +636,11 @@ class GroupChatViewModel(
|
||||
storedId?.let { inFlightTurns[it] = turnDeferred }
|
||||
|
||||
try {
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROMPT_SUBMIT,
|
||||
mapOf("session_id" to runtimeId, "text" to prompt),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROMPT_SUBMIT,
|
||||
mapOf("session_id" to runtimeId, "text" to prompt),
|
||||
).await()
|
||||
} catch (submitErr: Exception) {
|
||||
Log.w(
|
||||
"GroupChatViewModel",
|
||||
@@ -662,10 +670,11 @@ class GroupChatViewModel(
|
||||
storedId?.let { inFlightTurns[it] = turnDeferred }
|
||||
|
||||
try {
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROMPT_SUBMIT,
|
||||
mapOf("session_id" to runtimeId, "text" to prompt),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROMPT_SUBMIT,
|
||||
mapOf("session_id" to runtimeId, "text" to prompt),
|
||||
).await()
|
||||
} catch (retryErr: Exception) {
|
||||
Log.e("GroupChatViewModel", "Retry prompt.submit failed for ${bot.name}: ${retryErr.message}")
|
||||
return null
|
||||
@@ -880,7 +889,10 @@ class GroupChatViewModel(
|
||||
|
||||
val bot = remainingInitial.removeAt(0)
|
||||
val reply = executeBotTurn(bot, epoch, members)
|
||||
val nonSystemSize = _uiState.value.messages.filter { !it.isSystem }.size
|
||||
val nonSystemSize =
|
||||
_uiState.value.messages
|
||||
.filter { !it.isSystem }
|
||||
.size
|
||||
memberWatermarks[bot.name] = nonSystemSize
|
||||
|
||||
if (reply != null) {
|
||||
@@ -931,7 +943,10 @@ class GroupChatViewModel(
|
||||
|
||||
val bot = continuationResponders.removeAt(0)
|
||||
val reply = executeBotTurn(bot, epoch, members)
|
||||
val nonSystemSize = _uiState.value.messages.filter { !it.isSystem }.size
|
||||
val nonSystemSize =
|
||||
_uiState.value.messages
|
||||
.filter { !it.isSystem }
|
||||
.size
|
||||
memberWatermarks[bot.name] = nonSystemSize
|
||||
|
||||
if (reply != null) {
|
||||
@@ -1055,13 +1070,14 @@ class GroupChatViewModel(
|
||||
|
||||
val uiMetaPayload = mapOf("hermes-bots-groups" to newSnapshot.toMap())
|
||||
|
||||
HermesWsClient.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
HermesWsClient
|
||||
.request(
|
||||
WsMethods.PROFILES_CONFIGURE,
|
||||
mapOf(
|
||||
"name" to defaultProfile.name,
|
||||
"ui_meta" to uiMetaPayload,
|
||||
),
|
||||
).await()
|
||||
} catch (e: Exception) {
|
||||
Log.w("GroupChatViewModel", "persistSyncSnapshot failed: ${e.message}")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user