fix(chat): support batch clarify.request payload and route question_id on respond (fixes #1045) (#1046)
This commit is contained in:
6 files changed
+159
-1
No files matched your search
@@ -134,17 +134,33 @@ object EventParser {
|
||||
"clarify.request" -> {
|
||||
// Gateway sends "question"/"choices" — fall back to "text"/"options" for any
|
||||
// older client or test that still uses the legacy field names. (Issue #206)
|
||||
// Batch clarify (issue #18450): gateway sends "questions" array of {qid, question, choices, multi_select}.
|
||||
val rawQuestions = payload?.get("questions") as? List<*>
|
||||
val firstQuestion = rawQuestions?.firstOrNull() as? Map<*, *>
|
||||
|
||||
val text =
|
||||
payload?.get("question") as? String
|
||||
?: payload?.get("text") as? String
|
||||
?: if (rawQuestions != null && rawQuestions.size > 1) {
|
||||
rawQuestions
|
||||
.mapIndexedNotNull { index, item ->
|
||||
val q = (item as? Map<*, *>)?.get("question") as? String
|
||||
q?.let { "${index + 1}. $it" }
|
||||
}.joinToString("\n\n")
|
||||
} else {
|
||||
firstQuestion?.get("question") as? String
|
||||
}
|
||||
|
||||
val rawOptions =
|
||||
payload?.get("choices")
|
||||
?: payload?.get("options")
|
||||
?: firstQuestion?.get("choices")
|
||||
val clarifyId = payload?.get("clarify_id") as? String ?: payload?.get("request_id") as? String
|
||||
val questionId = firstQuestion?.get("qid") as? String
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val options = (rawOptions as? List<*>)?.filterIsInstance<String>()
|
||||
WsEvent.ClarifyRequest(text, options, clarifyId, sessionId)
|
||||
WsEvent.ClarifyRequest(text, options, clarifyId, sessionId, questionId)
|
||||
}
|
||||
|
||||
"status.update" -> {
|
||||
|
||||
@@ -140,6 +140,7 @@ sealed class WsEvent {
|
||||
val options: List<String>?,
|
||||
val clarifyId: String? = null,
|
||||
val sessionId: String? = null,
|
||||
val questionId: String? = null,
|
||||
) : WsEvent()
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user