mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:29:37 +08:00
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.
33 lines
1.0 KiB
TypeScript
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('')
|
|
}
|