Просмотр исходного кода

feat(speaking): broadcast session_updated on chat start/complete

jimmylee 2 дней назад
Родитель
Сommit
b1eaaf54f8
1 измененных файлов с 21 добавлено и 1 удалено
  1. 21 1
      src/views/Editor/EnglishSpeaking/preview/TopicDiscussionPreview.vue

+ 21 - 1
src/views/Editor/EnglishSpeaking/preview/TopicDiscussionPreview.vue

@@ -83,7 +83,7 @@
 </template>
 </template>
 
 
 <script lang="ts" setup>
 <script lang="ts" setup>
-import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
+import { ref, computed, watch, onMounted, onUnmounted, inject } from 'vue'
 import type { DialogueReport, OverallEvaluation, PreviewAIRole, PreviewDialogueState, SessionStartInfo } from '@/types/englishSpeaking'
 import type { DialogueReport, OverallEvaluation, PreviewAIRole, PreviewDialogueState, SessionStartInfo } from '@/types/englishSpeaking'
 import { useSpeakingStore } from '@/store/speaking'
 import { useSpeakingStore } from '@/store/speaking'
 import { getSpeakingConfig } from '@/services/speaking'
 import { getSpeakingConfig } from '@/services/speaking'
@@ -108,6 +108,12 @@ const props = withDefaults(defineProps<Props>(), {
   configId: '',
   configId: '',
 })
 })
 
 
+type SpeakingNotify = (
+  status: 'active' | 'completed',
+  payload: { configId: string; sessionId: string },
+) => void
+const notifySpeakingProgress = inject<SpeakingNotify>('notifySpeakingProgress', () => {})
+
 const speakingStore = useSpeakingStore()
 const speakingStore = useSpeakingStore()
 
 
 // 让组件按 DESIGN_WIDTH 设计宽度等比放大到任意槽位尺寸:
 // 让组件按 DESIGN_WIDTH 设计宽度等比放大到任意槽位尺寸:
@@ -325,6 +331,10 @@ async function startDialogue() {
       currentRound: info.currentRound,
       currentRound: info.currentRound,
     }
     }
     dialogueState.value = 'chatting'
     dialogueState.value = 'chatting'
+    notifySpeakingProgress('active', {
+      configId: props.configId || '',
+      sessionId: preparedSession.value?.sessionId || '',
+    })
   } catch (err: unknown) {
   } catch (err: unknown) {
     if (err instanceof DialogueApiError) {
     if (err instanceof DialogueApiError) {
       sessionError.value = `创建会话失败(${err.status}),请重试`
       sessionError.value = `创建会话失败(${err.status}),请重试`
@@ -414,6 +424,10 @@ async function loadLatestStudentSession(token = nextHistoryLoadToken()) {
     }
     }
 
 
     dialogueState.value = 'chatting'
     dialogueState.value = 'chatting'
+    notifySpeakingProgress('active', {
+      configId: props.configId || '',
+      sessionId: preparedSession.value?.sessionId || '',
+    })
   } catch (err: unknown) {
   } catch (err: unknown) {
     if (!isHistoryTokenCurrent(token)) return
     if (!isHistoryTokenCurrent(token)) return
     console.error('[speaking] load latest session failed:', err)
     console.error('[speaking] load latest session failed:', err)
@@ -435,6 +449,12 @@ function handleDialogueComplete(report: DialogueReport | null) {
   else if (report?.status === 'incomplete') reportError.value = '本次练习没有足够的有效回答生成报告。'
   else if (report?.status === 'incomplete') reportError.value = '本次练习没有足够的有效回答生成报告。'
   else reportError.value = ''
   else reportError.value = ''
   dialogueState.value = 'completed'
   dialogueState.value = 'completed'
+  if (preparedSession.value?.sessionId) {
+    notifySpeakingProgress('completed', {
+      configId: props.configId || '',
+      sessionId: preparedSession.value.sessionId,
+    })
+  }
 }
 }
 
 
 function resetPreview() {
 function resetPreview() {