Adopt session.redirect (issue #710) (#714)

* Add session.redirect affordance (issue #710)

Route send through session.redirect while a turn is streaming and the prompt
is plain text (no attachments, not a /command); otherwise prompt.submit.
Adds WsMethods.SESSION_REDIRECT + HermesWsClient.sendRedirect. No separate
button — the composer already sends mid-turn, so send just does the redirect.

* fix(chat): capture typing state before sendMessage for redirect

Capture wasStreaming state before updating uiState.isAgentTyping so normal sends call prompt.submit.

---------

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-07-25 18:15:39 +03:00
1 parent 4e2fb05077
commit c181d1d593
4 files changed
+55 -5

No files matched your search

@@ -765,6 +765,8 @@ class ChatViewModel(
val attachments = _uiState.value.pendingAttachments.toList()
clearAttachments()
val wasStreaming = _uiState.value.isAgentTyping
val userMessage =
ChatMessage(
role = MessageRole.USER,
@@ -857,11 +859,24 @@ class ChatViewModel(
if (text.isNotBlank()) "\n\n$text" else ""
}
wsClient.sendMessage(
agentSessionId,
fullText,
onSent = { id -> trackRequest(id, WsMethods.PROMPT_SUBMIT) },
)
// While a turn is actively streaming and this is a plain text prompt
// (no attachments — session.redirect carries text only), steer the
// in-flight turn via session.redirect instead of queueing a fresh
// prompt.submit. The backend rewrites the live turn when it can, or
// queues the correction as the next turn otherwise (issue #710).
if (wasStreaming && attachments.isEmpty()) {
wsClient.sendRedirect(
agentSessionId,
fullText,
onSent = { id -> trackRequest(id, WsMethods.SESSION_REDIRECT) },
)
} else {
wsClient.sendMessage(
agentSessionId,
fullText,
onSent = { id -> trackRequest(id, WsMethods.PROMPT_SUBMIT) },
)
}
}
}