fix(conflicts): 语音支持

This commit is contained in:
sophie committed 2026-06-01 19:43:33 +08:00
1 parent 7f126cfd52
commit 2a036764e3
4 files changed
+276 -8

No files matched your search

+35 -8
View File
@@ -1,4 +1,4 @@
<script setup lang="ts">
<script setup lang="ts">
/**
* ChatView.vue
* 文件用途:单个 Agent 的对话界面
@@ -21,6 +21,7 @@ import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue';
import { useMessage } from '../composables/useMessage';
import { useIsMobile } from '../composables/useIsMobile';
import { getVoiceUnavailableErrorKey, useSpeechRecognition } from '../composables/useSpeechRecognition';
import { useTheme } from '../composables/useTheme';
import { getAuthHeaders, getStoredAuthUser, logoutAuth } from '../utils/auth';
import { copyTextToClipboard } from '../utils/clipboard';
@@ -128,10 +129,6 @@ watch(locale, (newLang) => {
localStorage.setItem('hxops_lang', String(newLang));
});
const handleVoiceFeatureClick = () => {
msg.info(t('chat.devComingSoon'));
};
const stripReasoningPrelude = (text: string) => {
if (!text) return '';
let cleaned = text
@@ -621,6 +618,34 @@ const copiedIndex = ref<number | null>(null);
// 从 useChat 中解构出消息列表、思考状态、会话 ID 与发送函数
const { messages, isThinking, conversationId, runs, activeRunId, activateRun, createNewChatView, sendMessage } = useChat();
const input = ref('');
const {
isListening: isVoiceListening,
toggle: toggleVoiceInput,
stop: stopVoiceInput,
} = useSpeechRecognition({
lang: locale,
onResult: (text) => {
input.value = text;
},
onError: (key) => {
msg.warning(t(key));
},
});
const handleVoiceFeatureClick = () => {
if (isThinking.value) return;
const unavailable = getVoiceUnavailableErrorKey();
if (unavailable) {
msg.warning(t(unavailable));
return;
}
toggleVoiceInput(input.value);
};
watch(isThinking, (thinking) => {
if (thinking) stopVoiceInput();
});
const currentAgent = ref<any>(null);
const userAgents = ref<Array<{ id: number; name: string; description: string; icon_url?: string; dify_app_type?: 'chatflow' | 'workflow' }>>([]);
const showGeneralFeedbackDialog = ref(false);
@@ -2781,7 +2806,7 @@ const showChatRating = ref(false);
v-model="input"
@keydown.enter.prevent="handleSend"
rows="1"
:placeholder="$t('chat.askAnything')"
:placeholder="isVoiceListening ? $t('chat.voiceListening') : $t('chat.askAnything')"
class="w-full resize-none border-none bg-transparent px-3 py-2 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:outline-none focus:ring-0 focus:border-transparent"
style="min-height: 44px; max-height: 220px;"
:disabled="isThinking"
@@ -2795,8 +2820,10 @@ const showChatRating = ref(false);
<button
@click="handleVoiceFeatureClick"
type="button"
:title="$t('chat.voiceFeature')"
class="text-muted transition-colors hover:text-brand-600"
:disabled="isThinking"
:title="isVoiceListening ? $t('chat.voiceStop') : $t('chat.voiceFeature')"
class="transition-colors disabled:cursor-not-allowed disabled:opacity-50"
:class="isVoiceListening ? 'text-red-500 animate-pulse' : 'text-muted hover:text-brand-600'"
>
<Mic class="h-5 w-5" />
</button>