08feae8bef
落地 H5 Session 架构 Patch 1–5(Broker 收口、Router decision、SSE taxonomy、goosed 边界检查), 并新增可选 MEMIND_RUN_STREAM_REPLAY run 事件回放与 H5 假交付 guard;修复 Finish 先于 agent-run gate 导致 UI 永久 loading 的竞态,接入 verify:h5-session-patches 回归脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
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';
|
|
}
|