* feat(#125): fix clarification input pre-filling and parse/route clarify_id * fix(#156): fix ktlint violations in ChatViewModelTest.kt --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
4544d88f8d
commit
03cfcf8504
5 files changed
+38
-7
No files matched your search
@@ -82,10 +82,11 @@ object EventParser {
|
||||
"clarify.request" -> {
|
||||
val text = payload?.get("text") as? String
|
||||
val rawOptions = payload?.get("options")
|
||||
val clarifyId = payload?.get("clarify_id") as? String ?: payload?.get("request_id") as? String
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val options = (rawOptions as? List<*>)?.filterIsInstance<String>()
|
||||
WsEvent.ClarifyRequest(text, options)
|
||||
WsEvent.ClarifyRequest(text, options, clarifyId)
|
||||
}
|
||||
|
||||
"status.update" -> {
|
||||
|
||||
@@ -56,6 +56,7 @@ sealed class WsEvent {
|
||||
data class ClarifyRequest(
|
||||
val text: String?,
|
||||
val options: List<String>?,
|
||||
val clarifyId: String? = null,
|
||||
) : WsEvent()
|
||||
|
||||
// ── Status ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -824,7 +824,7 @@ private fun ClarifyDialog(
|
||||
onOptionSelected: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var typedText by rememberSaveable(clarify) { mutableStateOf(clarify.text) }
|
||||
var typedText by rememberSaveable(clarify.text) { mutableStateOf(clarify.text) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
|
||||
@@ -70,6 +70,7 @@ data class SessionUi(
|
||||
data class ClarifyUi(
|
||||
val text: String,
|
||||
val options: List<String>,
|
||||
val clarifyId: String? = null,
|
||||
)
|
||||
|
||||
class ChatViewModel(
|
||||
@@ -164,6 +165,7 @@ class ChatViewModel(
|
||||
ClarifyUi(
|
||||
text = event.text.orEmpty(),
|
||||
options = event.options.orEmpty(),
|
||||
clarifyId = event.clarifyId,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -888,6 +890,7 @@ class ChatViewModel(
|
||||
|
||||
fun respondToClarify(option: String) {
|
||||
val sessionId = _uiState.value.currentSessionId ?: return
|
||||
val clarifyId = _uiState.value.clarifyRequest?.clarifyId
|
||||
_uiState.update { it.copy(clarifyRequest = null) }
|
||||
|
||||
val userMessage =
|
||||
@@ -908,9 +911,19 @@ class ChatViewModel(
|
||||
}
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val params =
|
||||
mutableMapOf<String, Any>(
|
||||
"session_id" to sessionId,
|
||||
"response" to option,
|
||||
"answer" to option,
|
||||
)
|
||||
if (clarifyId != null) {
|
||||
params["clarify_id"] = clarifyId
|
||||
params["request_id"] = clarifyId
|
||||
}
|
||||
wsClient.send(
|
||||
method = WsMethods.CLARIFY_RESPOND,
|
||||
params = mapOf("session_id" to sessionId, "response" to option),
|
||||
params = params,
|
||||
onSent = { id -> trackRequest(id, WsMethods.CLARIFY_RESPOND) },
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user