feat: add voice session confirmation guardrails

This commit is contained in:
2026-04-20 12:29:14 +08:00
parent 4ecf0c09c0
commit dbb512719d
8 changed files with 406 additions and 50 deletions

View File

@@ -8,6 +8,10 @@ export interface VoiceTurnSummary {
transcription_provider: string | null
detected_intent: string
intent_confidence: number | null
understanding_summary: string | null
requires_confirmation: boolean
confirmation_reason: string | null
confirmation_message: string | null
assistant_text: string | null
assistant_audio_ready: boolean
assistant_audio_url: string | null
@@ -43,6 +47,9 @@ export interface VoiceSessionSummary {
latest_user_transcript: string | null
latest_assistant_text: string | null
latest_detected_intent: string | null
latest_understanding_summary: string | null
latest_requires_confirmation: boolean
latest_confirmation_message: string | null
latest_assistant_audio_ready: boolean
last_turn_status: string | null
transcription_mode_hint: string | null

View File

@@ -162,6 +162,13 @@ function formatDate(dateStr: string) {
})
}
function formatConfidence(value: number | null | undefined) {
if (typeof value !== 'number') {
return 'n/a'
}
return `${Math.round(value * 100)}%`
}
function revokeRecordedAudioUrl() {
if (recordedAudioUrl.value) {
URL.revokeObjectURL(recordedAudioUrl.value)
@@ -718,6 +725,19 @@ onBeforeUnmount(() => {
<div class="mt-6 grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]">
<div class="space-y-6">
<div
v-if="activeSession.latest_requires_confirmation"
class="rounded-2xl border border-amber-200 bg-amber-50 p-4 text-amber-800"
>
<div class="text-sm font-semibold">建议先确认这一轮理解</div>
<p class="mt-2 text-sm">
{{ activeSession.latest_confirmation_message || '系统对这一轮的理解还不够确定,建议家长先确认后再继续。' }}
</p>
<p v-if="activeSession.latest_understanding_summary" class="mt-2 text-xs text-amber-700">
{{ activeSession.latest_understanding_summary }}
</p>
</div>
<div class="rounded-2xl border border-gray-100 bg-white p-4">
<div class="flex items-center justify-between">
<h3 class="font-semibold text-gray-900">文本共创回合</h3>
@@ -839,6 +859,22 @@ onBeforeUnmount(() => {
<span class="font-medium text-gray-900">孩子</span>
{{ turn.user_transcript || '暂无转写内容' }}
</div>
<div v-if="turn.understanding_summary" class="mt-3 text-sm text-slate-600">
{{ turn.understanding_summary }}
</div>
<div
v-if="turn.requires_confirmation"
class="mt-3 rounded-2xl border border-amber-200 bg-amber-50 px-3 py-3 text-sm text-amber-800"
>
<div class="font-medium">建议家长确认后再继续</div>
<p class="mt-1">
{{ turn.confirmation_message || '系统对这一轮的理解还不够确定,建议换一种说法再试一次。' }}
</p>
<p class="mt-2 text-xs text-amber-700">
转写置信度{{ formatConfidence(turn.transcript_confidence) }} ·
意图置信度{{ formatConfidence(turn.intent_confidence) }}
</p>
</div>
<div v-if="turn.user_audio_url" class="mt-3">
<audio class="w-full" :src="turn.user_audio_url" controls></audio>
</div>