Files
DeepTutor/web/lib/stream.ts
Bingxi Zhao (Frank) e347c0c2e0 fix: preserve tutoring replies and stabilize preview runtime
Keep learner-facing explanations visible across finish checks, persistence, and replay. Remove mastery prose heuristics and prioritize learner objections.

Coordinate service shutdown and descendant cleanup, and preserve video lesson identity and playable results across chat completion and reload.
2026-10-27 17:58:46 +08:00

33 lines
1.0 KiB
TypeScript

import type { StreamEvent } from '@/features/chat/model/protocol'
type ContentMeta = {
call_id?: string
call_kind?: string
call_state?: string
call_role?: string
answer_visible?: boolean
trace_kind?: string
}
function eventMeta(event: StreamEvent): ContentMeta {
return (event.metadata ?? {}) as ContentMeta
}
export function shouldAppendEventContent(event: StreamEvent): boolean {
if (event.type !== 'content') return false
const meta = eventMeta(event)
if (!meta.call_id) return true
// The chat agent loop streams every round's text as `content`, and all of
// it is the answer — the commentary a round wrote before calling a tool
// included. Completion markers cannot retract published prose.
return meta.call_kind === 'llm_final_response' || meta.call_kind === 'agent_loop_round'
}
/** Replay every published answer chunk in order. */
export function recomputeAnswerContent(events: StreamEvent[]): string {
return events
.filter(shouldAppendEventContent)
.map(event => event.content)
.join('')
}