fix(tui): keep stream cadence responsive while typing

This commit is contained in:
Brooklyn Nicholson 2026-04-26 04:32:55 -05:00
parent 381121025e
commit bbd950efcf
4 changed files with 19 additions and 13 deletions

View file

@ -1,5 +1,6 @@
import { type MutableRefObject, useCallback, useEffect, useRef } from 'react'
import { TYPING_IDLE_MS } from '../config/timing.js'
import { attachedImageNotice } from '../domain/messages.js'
import { looksLikeSlashCommand } from '../domain/slash.js'
import type { GatewayClient } from '../gatewayClient.js'
@ -10,7 +11,6 @@ import { PASTE_SNIPPET_RE } from '../protocol/paste.js'
import type { Msg } from '../types.js'
import type { ComposerActions, ComposerRefs, ComposerState, PasteSnippet } from './interfaces.js'
import { markTyping } from './interactionMode.js'
import { turnController } from './turnController.js'
import { getUiState, patchUiState } from './uiStore.js'
@ -48,13 +48,28 @@ export function useSubmission(opts: UseSubmissionOptions) {
} = opts
const lastEmptyAt = useRef(0)
const typingIdleTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
useEffect(() => {
if (composerState.input || composerState.inputBuf.length) {
markTyping()
if (getUiState().busy) {
turnController.boostStreamingForTyping()
}
if (typingIdleTimer.current) {
clearTimeout(typingIdleTimer.current)
}
typingIdleTimer.current = setTimeout(() => {
typingIdleTimer.current = null
turnController.relaxStreaming()
}, TYPING_IDLE_MS)
}
return () => {
if (typingIdleTimer.current) {
clearTimeout(typingIdleTimer.current)
}
}
}, [composerState.input, composerState.inputBuf])