This commit is contained in:
7 files changed
+165
-18
No files matched your search
@@ -24,7 +24,7 @@ object ConnectionOperationParser {
|
||||
return null
|
||||
}
|
||||
return ConnectionOperationSnapshot(
|
||||
sessionId = (sessionId ?: payload["session_id"] as? String)?.takeIf { it.isNotBlank() },
|
||||
sessionId = resolveSessionId(payload, sessionId),
|
||||
opId = opId,
|
||||
seq = seq,
|
||||
deadlineAt = deadlineAt,
|
||||
@@ -39,6 +39,21 @@ object ConnectionOperationParser {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Session that owns the operation. Since hermes-agent v0.21.5 updates carry `owner` (#1281):
|
||||
* session-owned ones name their session; account-owned ones never bind to a chat.
|
||||
*/
|
||||
private fun resolveSessionId(
|
||||
payload: Map<String, Any?>,
|
||||
envelopeSessionId: String?,
|
||||
): String? {
|
||||
val owner = payload["owner"] as? Map<*, *>
|
||||
if (owner?.get("type") == "account") return null
|
||||
val ownerSessionId = (owner?.get("session_id") as? String).takeIf { owner?.get("type") == "session" }
|
||||
return listOf(envelopeSessionId, ownerSessionId, payload["session_id"] as? String)
|
||||
.firstOrNull { !it.isNullOrBlank() }
|
||||
}
|
||||
|
||||
private fun parseTarget(raw: Map<*, *>?): ConnectionOperationTarget? {
|
||||
val map = raw ?: return null
|
||||
val name = (map["name"] as? String)?.trim() ?: return null
|
||||
|
||||
@@ -32,6 +32,9 @@ interface ConnectorRepository {
|
||||
if (slug.isNullOrBlank()) return false
|
||||
return SLUG_REGEX.matches(slug)
|
||||
}
|
||||
|
||||
/** `owner` discriminated union required by connector RPCs since hermes-agent v0.21.5 (#1281). */
|
||||
fun sessionOwner(sessionId: String): Map<String, String> = mapOf("type" to "session", "session_id" to sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +64,7 @@ class HermesConnectorRepository(
|
||||
}
|
||||
|
||||
return try {
|
||||
val params = mapOf("session_id" to sessionId)
|
||||
val params = mapOf("owner" to ConnectorRepository.sessionOwner(sessionId))
|
||||
val result = rpcRequest(WsMethods.CONNECTORS_LIST, params)
|
||||
ConnectorParser.parseListResult(result)
|
||||
} catch (e: CancellationException) {
|
||||
@@ -105,7 +108,7 @@ class HermesConnectorRepository(
|
||||
return try {
|
||||
val params =
|
||||
mapOf(
|
||||
"session_id" to sessionId,
|
||||
"owner" to ConnectorRepository.sessionOwner(sessionId),
|
||||
"connectors" to connectors,
|
||||
"reconnect" to reconnect,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user