10 files changed
+502
-10
No files matched your search
@@ -29,6 +29,8 @@ data class ConnectionOperationTarget(
|
||||
val requiredEnv: List<ConnectionEnvField>,
|
||||
val tools: List<String>,
|
||||
val hint: String?,
|
||||
/** Catalog facts for [ConnectionTargetKind.PLUGIN] / [ConnectionTargetKind.SKILL] rows only. */
|
||||
val catalog: ConnectionCatalogInfo? = null,
|
||||
) {
|
||||
/** Safe validated browser URL. OAuth query parameters stay redacted from [toString]. */
|
||||
val safeConnectUrl: String?
|
||||
@@ -40,9 +42,32 @@ data class ConnectionOperationTarget(
|
||||
"instructions=$instructions, discoveryError=$discoveryError, " +
|
||||
"connectUrl=${if (connectUrl == null) "null" else "[REDACTED]"}, " +
|
||||
"connectionId=$connectionId, attempt=$attempt, requiredEnv=$requiredEnv, " +
|
||||
"tools=$tools, hint=$hint)"
|
||||
"tools=$tools, hint=$hint, catalog=$catalog)"
|
||||
}
|
||||
|
||||
/** Host-resolved catalog row facts (hermes-agent `manage_catalog`); the model supplies only the id. */
|
||||
data class ConnectionCatalogInfo(
|
||||
val display: String,
|
||||
val description: String?,
|
||||
val tier: String?,
|
||||
val platforms: List<String>,
|
||||
val repo: String?,
|
||||
val sha: String?,
|
||||
val subdir: String?,
|
||||
val scan: ConnectionCatalogScan?,
|
||||
val requirements: List<String>,
|
||||
val targetProfile: String,
|
||||
/** On an installed row: the skill the model can now load. */
|
||||
val skill: String?,
|
||||
)
|
||||
|
||||
data class ConnectionCatalogScan(
|
||||
val status: CatalogScanStatus,
|
||||
val summary: String?,
|
||||
)
|
||||
|
||||
enum class CatalogScanStatus { PASSED, WARNINGS, FAILED, UNKNOWN }
|
||||
|
||||
data class ConnectionEnvField(
|
||||
val name: String,
|
||||
val required: Boolean,
|
||||
@@ -51,7 +76,16 @@ data class ConnectionEnvField(
|
||||
val prompt: String?,
|
||||
)
|
||||
|
||||
enum class ConnectionTargetKind { CONNECTOR, MCP, UNKNOWN }
|
||||
enum class ConnectionTargetKind {
|
||||
CONNECTOR,
|
||||
MCP,
|
||||
PLUGIN,
|
||||
SKILL,
|
||||
UNKNOWN,
|
||||
;
|
||||
|
||||
val isCatalog: Boolean get() = this == PLUGIN || this == SKILL
|
||||
}
|
||||
|
||||
enum class ConnectionTargetAction {
|
||||
AUTHORIZE,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.m57.hermescontrol.data.ws
|
||||
|
||||
import com.m57.hermescontrol.data.model.CatalogScanStatus
|
||||
import com.m57.hermescontrol.data.model.ConnectionCatalogInfo
|
||||
import com.m57.hermescontrol.data.model.ConnectionCatalogScan
|
||||
import com.m57.hermescontrol.data.model.ConnectionEnvField
|
||||
import com.m57.hermescontrol.data.model.ConnectionOperationSnapshot
|
||||
import com.m57.hermescontrol.data.model.ConnectionOperationTarget
|
||||
@@ -58,14 +61,15 @@ object ConnectionOperationParser {
|
||||
val map = raw ?: return null
|
||||
val name = (map["name"] as? String)?.trim() ?: return null
|
||||
if (name.isBlank()) return null
|
||||
val kind =
|
||||
enumValue(
|
||||
map["kind"] as? String,
|
||||
ConnectionTargetKind.values(),
|
||||
ConnectionTargetKind.UNKNOWN,
|
||||
)
|
||||
return ConnectionOperationTarget(
|
||||
name = name,
|
||||
kind =
|
||||
enumValue(
|
||||
map["kind"] as? String,
|
||||
ConnectionTargetKind.values(),
|
||||
ConnectionTargetKind.UNKNOWN,
|
||||
),
|
||||
kind = kind,
|
||||
action =
|
||||
enumValue(
|
||||
map["action"] as? String,
|
||||
@@ -90,9 +94,50 @@ object ConnectionOperationParser {
|
||||
?: emptyList(),
|
||||
tools = (map["tools"] as? List<*>)?.filterIsInstance<String>() ?: emptyList(),
|
||||
hint = map["hint"] as? String,
|
||||
catalog = if (kind.isCatalog) parseCatalog(map, name) else null,
|
||||
)
|
||||
}
|
||||
|
||||
private fun parseCatalog(
|
||||
map: Map<*, *>,
|
||||
name: String,
|
||||
): ConnectionCatalogInfo =
|
||||
ConnectionCatalogInfo(
|
||||
display = map.text("display") ?: name,
|
||||
description = map.text("description"),
|
||||
tier = map.text("tier"),
|
||||
platforms = map.strings("platforms"),
|
||||
repo = map.text("repo"),
|
||||
sha = map.text("sha"),
|
||||
subdir = map.text("subdir"),
|
||||
scan =
|
||||
(map["scan"] as? Map<*, *>)?.let { scan ->
|
||||
ConnectionCatalogScan(
|
||||
status =
|
||||
enumValue(
|
||||
scan["status"] as? String,
|
||||
CatalogScanStatus.values(),
|
||||
CatalogScanStatus.UNKNOWN,
|
||||
),
|
||||
summary = scan.text("summary"),
|
||||
)
|
||||
},
|
||||
requirements = map.strings("requirements"),
|
||||
targetProfile = map.text("target_profile") ?: DEFAULT_PROFILE,
|
||||
skill = map.text("skill"),
|
||||
)
|
||||
|
||||
private fun Map<*, *>.text(key: String): String? = (this[key] as? String)?.trim()?.takeIf { it.isNotEmpty() }
|
||||
|
||||
private fun Map<*, *>.strings(key: String): List<String> =
|
||||
(this[key] as? List<*>)
|
||||
?.filterIsInstance<String>()
|
||||
?.map(String::trim)
|
||||
?.filter(String::isNotEmpty)
|
||||
?: emptyList()
|
||||
|
||||
private const val DEFAULT_PROFILE = "default"
|
||||
|
||||
private fun parseEnv(raw: Map<*, *>?): ConnectionEnvField? {
|
||||
val map = raw ?: return null
|
||||
val name = (map["name"] as? String)?.trim() ?: return null
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.m57.hermescontrol.ui.chat.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.m57.hermescontrol.R
|
||||
import com.m57.hermescontrol.data.model.CatalogScanStatus
|
||||
import com.m57.hermescontrol.data.model.ConnectionCatalogInfo
|
||||
import com.m57.hermescontrol.data.model.ConnectionTargetKind
|
||||
import com.m57.hermescontrol.theme.LocalHermesStatusColors
|
||||
|
||||
private const val SHORT_SHA_LENGTH = 12
|
||||
|
||||
/** What a plugin/skill install row would bring in: source, pin, scan and requirements (#1287). */
|
||||
@Composable
|
||||
internal fun ConnectionCatalogDetails(
|
||||
kind: ConnectionTargetKind,
|
||||
catalog: ConnectionCatalogInfo,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val muted = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
Column(
|
||||
modifier = modifier.testTag("connection_catalog_details"),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
val kindLabel =
|
||||
stringResource(
|
||||
if (kind == ConnectionTargetKind.SKILL) {
|
||||
R.string.connection_catalog_kind_skill
|
||||
} else {
|
||||
R.string.connection_catalog_kind_plugin
|
||||
},
|
||||
)
|
||||
val tierLabel =
|
||||
when (catalog.tier) {
|
||||
null -> null
|
||||
"official" -> stringResource(R.string.connection_catalog_tier_official)
|
||||
"community" -> stringResource(R.string.connection_catalog_tier_community)
|
||||
else -> catalog.tier
|
||||
}
|
||||
Text(
|
||||
text = listOfNotNull(kindLabel, tierLabel).joinToString(" · "),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = muted,
|
||||
)
|
||||
catalog.description?.let { Text(it) }
|
||||
catalog.repo?.let { repo ->
|
||||
val source = catalog.subdir?.let { "$repo/$it" } ?: repo
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_source, source),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_source"),
|
||||
)
|
||||
}
|
||||
catalog.sha?.let { sha ->
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_pin, sha.take(SHORT_SHA_LENGTH)),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_pin"),
|
||||
)
|
||||
}
|
||||
if (catalog.platforms.isNotEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_platforms, catalog.platforms.joinToString(", ")),
|
||||
color = muted,
|
||||
)
|
||||
}
|
||||
CatalogScanLine(catalog)
|
||||
if (catalog.requirements.isNotEmpty()) {
|
||||
Text(
|
||||
text =
|
||||
stringResource(
|
||||
R.string.connection_catalog_requirements,
|
||||
catalog.requirements.joinToString(", "),
|
||||
),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_requirements"),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_target_profile, catalog.targetProfile),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_profile"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CatalogScanLine(catalog: ConnectionCatalogInfo) {
|
||||
val status = LocalHermesStatusColors.current
|
||||
val scan = catalog.scan
|
||||
val (label, color) =
|
||||
when (scan?.status) {
|
||||
CatalogScanStatus.PASSED -> {
|
||||
R.string.connection_catalog_scan_passed to status.success
|
||||
}
|
||||
|
||||
CatalogScanStatus.WARNINGS -> {
|
||||
R.string.connection_catalog_scan_warnings to status.warning
|
||||
}
|
||||
|
||||
CatalogScanStatus.FAILED -> {
|
||||
R.string.connection_catalog_scan_failed to status.error
|
||||
}
|
||||
|
||||
CatalogScanStatus.UNKNOWN, null -> {
|
||||
R.string.connection_catalog_scan_unreported to MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
}
|
||||
val summary = scan?.summary
|
||||
Text(
|
||||
text = stringResource(label) + if (summary != null) " · $summary" else "",
|
||||
color = color,
|
||||
modifier = Modifier.testTag("connection_catalog_scan"),
|
||||
)
|
||||
}
|
||||
@@ -102,8 +102,14 @@ internal fun ConnectionSetupContent(
|
||||
.padding(horizontal = 20.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
val catalog = target.catalog
|
||||
Text(
|
||||
text = stringResource(R.string.connection_setup_target_title, target.name),
|
||||
text =
|
||||
if (catalog != null) {
|
||||
stringResource(R.string.connection_catalog_title, catalog.display)
|
||||
} else {
|
||||
stringResource(R.string.connection_setup_target_title, target.name)
|
||||
},
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.testTag("connection_setup_title"),
|
||||
)
|
||||
@@ -120,6 +126,7 @@ internal fun ConnectionSetupContent(
|
||||
target.instructions?.takeIf { it.isNotBlank() }?.let { instructions ->
|
||||
Text(instructions, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
catalog?.let { ConnectionCatalogDetails(kind = target.kind, catalog = it) }
|
||||
|
||||
when {
|
||||
target.state == ConnectionTargetState.CONNECTED && !target.discoveryError.isNullOrBlank() -> {
|
||||
@@ -141,6 +148,12 @@ internal fun ConnectionSetupContent(
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
catalog?.skill?.let { skill ->
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_skill_ready, skill),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
target.detail?.takeIf { it.isNotBlank() }?.let { detail ->
|
||||
Text(detail, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
@@ -167,6 +180,21 @@ internal fun ConnectionSetupContent(
|
||||
}
|
||||
}
|
||||
|
||||
catalog != null && target.state == ConnectionTargetState.INITIATED -> {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.testTag("connection_catalog_installing"),
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
Text(
|
||||
text =
|
||||
target.detail?.takeIf { it.isNotBlank() }
|
||||
?: stringResource(R.string.connection_catalog_installing),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
target.state == ConnectionTargetState.UNKNOWN ||
|
||||
(target.state == ConnectionTargetState.INITIATED && target.connectUrl != null) -> {
|
||||
Text(
|
||||
@@ -220,7 +248,15 @@ internal fun ConnectionSetupContent(
|
||||
.fillMaxWidth()
|
||||
.testTag("connection_setup_connect"),
|
||||
) {
|
||||
Text(stringResource(R.string.connection_setup_connect))
|
||||
Text(
|
||||
stringResource(
|
||||
when {
|
||||
catalog == null -> R.string.connection_setup_connect
|
||||
target.state == ConnectionTargetState.FAILED -> R.string.connection_catalog_retry
|
||||
else -> R.string.connection_catalog_install
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user