feat: 添加文字输入对话功能

- 后端 WsQuery 添加 text 字段,支持文本输入模式
- Pipeline 支持文本查询时跳过 STT 直接使用输入文本
- 前端 ChatPanel 添加文字输入框,连接状态下可用
- useVisionSession 添加 sendTextMessage 方法
- 更新接口文档,添加文本输入模式说明
This commit is contained in:
2026-06-14 12:52:39 +08:00
parent 563ca12790
commit 51ed6aa563
8 changed files with 252 additions and 73 deletions

View File

@@ -363,6 +363,44 @@ export function useVisionSession() {
setIsProcessing(false);
}, [send, currentReply]);
/** 发送文本消息(手动输入) */
const sendTextMessage = useCallback(
(text: string) => {
if (!text.trim() || isProcessingRef.current) return;
// 停止上一轮的 TTS 播放
ttsPlayerRef.current?.stop();
setIsAudioPlaying(false);
// 捕获当前摄像头画面
const frame = captureFrame();
const requestId = uuidv4();
send({
type: "query",
request_id: requestId,
image: frame ? dataUrlToBase64(frame) : "",
audio: "", // 文本输入无音频
text: text.trim(),
});
// 更新请求统计
setStats((prev) => ({ ...prev, queryCount: prev.queryCount + 1 }));
// 添加用户消息
setMessages((prev) => [
...prev,
{ role: "user", content: text.trim(), timestamp: Date.now() },
]);
// 记录到对话历史
historyRef.current.push({ role: "user", content: text.trim() });
setIsProcessing(true);
},
[captureFrame, send],
);
return {
messages,
currentReply,
@@ -387,5 +425,6 @@ export function useVisionSession() {
isMicOn,
toggleCamera,
toggleMic,
sendTextMessage,
};
}