32 lines
931 B
JavaScript
32 lines
931 B
JavaScript
|
|
/**
|
||
|
|
* Agent-run gate vs session Finish ordering (regression guard).
|
||
|
|
*
|
||
|
|
* Context (2026-07): session SSE Finish can arrive before agent-run SSE reports
|
||
|
|
* succeeded. Re-entering streaming after the run gate completes leaves the UI stuck
|
||
|
|
* on typing dots even though the assistant reply is already visible.
|
||
|
|
*
|
||
|
|
* Tests: chat-agent-run-gate.test.mjs
|
||
|
|
* Consumer: src/hooks/useTKMindChat.ts
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param {{ chatState?: string; finishedViaPortalDirectChat?: boolean }} input
|
||
|
|
* @returns {'idle' | 'streaming'}
|
||
|
|
*/
|
||
|
|
export function resolvePostAgentRunChatState({
|
||
|
|
chatState = 'waiting',
|
||
|
|
finishedViaPortalDirectChat = false,
|
||
|
|
} = {}) {
|
||
|
|
if (finishedViaPortalDirectChat) return 'idle';
|
||
|
|
if (chatState === 'idle') return 'idle';
|
||
|
|
return 'streaming';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param {string | undefined | null} chatState
|
||
|
|
* @returns {boolean}
|
||
|
|
*/
|
||
|
|
export function shouldPromoteSessionIdToStreaming(chatState) {
|
||
|
|
return chatState !== 'idle';
|
||
|
|
}
|