feat: show per-stage timing (듣기/LLM/TTS) in the transcript channel

The transcript channel only showed STT and LLM seconds. Add wall-clock
start/end times and durations for listening, LLM and TTS so it's obvious
what takes long; STT surfaces as the gap between listening end and LLM start.

- bridge: emit llm_start_ms/llm_end_ms on meta and tts_*_ms on the end event
- bot: capture the listening window, assemble full timing after the stream,
  and render a per-stage breakdown in the transcript message

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-06-13 23:58:49 +09:00
parent ddebdd7542
commit de5384d166
6 changed files with 242 additions and 34 deletions

View File

@@ -50,6 +50,19 @@ export interface ConverseMeta {
/** Per-stage timing (seconds) for diagnosing latency. */
stt_sec?: number;
think_sec?: number;
/** Wall-clock LLM window (epoch ms) so the transcript channel can show when
* the reply engine started/finished. */
llm_start_ms?: number;
llm_end_ms?: number;
}
/** Final event of a streamed turn, carrying TTS timing (synthesis runs after
* the meta line, so it can't be reported there). */
export interface ConverseEnd {
tts_sec?: number;
/** Wall-clock TTS window (epoch ms). */
tts_start_ms?: number;
tts_end_ms?: number;
}
export interface ConverseStreamHandlers {
@@ -57,6 +70,8 @@ export interface ConverseStreamHandlers {
onMeta?: (meta: ConverseMeta) => void | Promise<void>;
/** Fired per sentence as its audio finishes synthesising (in order). */
onAudio?: (wav: Buffer) => void | Promise<void>;
/** Fired once after the last clip, with TTS timing. */
onEnd?: (end: ConverseEnd) => void | Promise<void>;
}
/** Parse a byte stream of newline-delimited JSON into objects, one per line. */
@@ -102,6 +117,8 @@ export async function converseStream(
} else if (ev.type === "audio" && ev.audio_b64) {
const clip = decodeWav(ev.audio_b64);
if (clip) await handlers.onAudio?.(clip);
} else if (ev.type === "end") {
await handlers.onEnd?.(ev as ConverseEnd);
}
}
}