This commit is contained in:
7 files changed
+165
-18
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package com.m57.hermescontrol.ui.chat
|
||||
|
||||
import com.m57.hermescontrol.data.model.ConnectionOperationSnapshot
|
||||
import com.m57.hermescontrol.data.model.ConnectorError
|
||||
import com.m57.hermescontrol.data.ws.ConnectorParser
|
||||
import com.m57.hermescontrol.data.ws.ConnectorRepository
|
||||
import com.m57.hermescontrol.data.ws.HermesWsClient
|
||||
import com.m57.hermescontrol.data.ws.WsMethods
|
||||
import kotlinx.coroutines.CancellationException
|
||||
@@ -167,7 +170,7 @@ class ChatConnectionOperationDelegate(
|
||||
method = WsMethods.CONNECTION_RESPOND,
|
||||
params =
|
||||
mapOf(
|
||||
"session_id" to requireSessionId(),
|
||||
"owner" to ConnectorRepository.sessionOwner(requireSessionId()),
|
||||
"op_id" to snapshot.opId,
|
||||
"result" to mapOf("targets" to listOf(answer)),
|
||||
),
|
||||
@@ -180,7 +183,7 @@ class ChatConnectionOperationDelegate(
|
||||
method = WsMethods.CONNECTION_RESPOND,
|
||||
params =
|
||||
mapOf(
|
||||
"session_id" to requireSessionId(),
|
||||
"owner" to ConnectorRepository.sessionOwner(requireSessionId()),
|
||||
"op_id" to snapshot.opId,
|
||||
"result" to mapOf("settled_by" to "continue"),
|
||||
),
|
||||
@@ -193,7 +196,7 @@ class ChatConnectionOperationDelegate(
|
||||
val snapshot = begin(ConnectionPendingAction.Wake(current.opId, current.seq)) ?: return
|
||||
dispatch(
|
||||
method = WsMethods.CONNECTORS_OPERATION_WAKE,
|
||||
params = mapOf("session_id" to requireSessionId(), "op_id" to snapshot.opId),
|
||||
params = mapOf("owner" to ConnectorRepository.sessionOwner(requireSessionId()), "op_id" to snapshot.opId),
|
||||
clearOnSuccess = true,
|
||||
unknownOperationSettles = true,
|
||||
)
|
||||
@@ -225,7 +228,7 @@ class ChatConnectionOperationDelegate(
|
||||
_state.value =
|
||||
_state.value.copy(
|
||||
pendingAction = null,
|
||||
error = ConnectionOperationError("request_failed"),
|
||||
error = operationError(error),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -245,6 +248,16 @@ class ChatConnectionOperationDelegate(
|
||||
return current
|
||||
}
|
||||
|
||||
/** Typed, sanitized error: ownership/runtime failures cannot succeed on retry (#1281). */
|
||||
private fun operationError(error: Exception): ConnectionOperationError {
|
||||
val rpc = error as? HermesWsClient.HermesRpcException ?: return ConnectionOperationError(REQUEST_FAILED)
|
||||
return when (ConnectorParser.mapRpcError(code = rpc.code, data = rpc.data)) {
|
||||
is ConnectorError.NotOwner -> ConnectionOperationError(NOT_OWNER, retryable = false)
|
||||
is ConnectorError.UnsupportedRuntime -> ConnectionOperationError(UNSUPPORTED_RUNTIME, retryable = false)
|
||||
else -> ConnectionOperationError(REQUEST_FAILED)
|
||||
}
|
||||
}
|
||||
|
||||
private fun matchesSession(snapshot: ConnectionOperationSnapshot): Boolean =
|
||||
!sessionId.isNullOrBlank() && snapshot.sessionId == sessionId
|
||||
|
||||
@@ -263,7 +276,10 @@ class ChatConnectionOperationDelegate(
|
||||
_state.value = ConnectionOperationUiState()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MAX_SETTLED_IDS = 32
|
||||
companion object {
|
||||
private const val MAX_SETTLED_IDS = 32
|
||||
const val REQUEST_FAILED = "request_failed"
|
||||
const val NOT_OWNER = "not_owner"
|
||||
const val UNSUPPORTED_RUNTIME = "unsupported_runtime"
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.m57.hermescontrol.R
|
||||
import com.m57.hermescontrol.data.model.ConnectionOperationTarget
|
||||
import com.m57.hermescontrol.data.model.ConnectionTargetState
|
||||
import com.m57.hermescontrol.ui.chat.ChatConnectionOperationDelegate
|
||||
import com.m57.hermescontrol.ui.chat.ConnectionOperationUiState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -224,9 +225,24 @@ internal fun ConnectionSetupContent(
|
||||
}
|
||||
}
|
||||
|
||||
state.error?.let {
|
||||
state.error?.let { error ->
|
||||
Text(
|
||||
text = stringResource(R.string.connection_setup_request_failed),
|
||||
text =
|
||||
stringResource(
|
||||
when (error.message) {
|
||||
ChatConnectionOperationDelegate.NOT_OWNER -> {
|
||||
R.string.session_integrations_err_not_owner
|
||||
}
|
||||
|
||||
ChatConnectionOperationDelegate.UNSUPPORTED_RUNTIME -> {
|
||||
R.string.session_integrations_err_unsupported_runtime
|
||||
}
|
||||
|
||||
else -> {
|
||||
R.string.connection_setup_request_failed
|
||||
}
|
||||
},
|
||||
),
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
modifier = Modifier.testTag("connection_setup_error"),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user