feat: add back streaming switch for web chat

This commit is contained in:
Junyan Qin
2025-12-11 18:54:16 +08:00
parent 173f9e9c30
commit b5b5d499e5
7 changed files with 34 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import { DialogContent } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Switch } from '@/components/ui/switch';
import { cn } from '@/lib/utils';
import {
Message,
@@ -60,6 +61,7 @@ export default function DebugDialog({
const [rawModeMessages, setRawModeMessages] = useState<Set<string>>(
new Set(),
);
const [streamOutput, setStreamOutput] = useState(true);
const messagesEndRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const popoverRef = useRef<HTMLDivElement>(null);
@@ -384,7 +386,7 @@ export default function DebugDialog({
// 通过WebSocket发送消息
// 不在本地添加消息等待后端广播回来带有正确的ID
wsClientRef.current.sendMessage(messageChain);
wsClientRef.current.sendMessage(messageChain, streamOutput);
} catch (error) {
console.error('Failed to send message:', error);
toast.error(t('pipelines.debugDialog.sendFailed'));
@@ -897,7 +899,18 @@ export default function DebugDialog({
)}
<div className="p-4 pb-0 bg-white dark:bg-black flex gap-2">
<div className="flex gap-2">
<div className="flex gap-2 items-center">
<div className="flex items-center gap-1">
<span className="text-xs text-gray-500 dark:text-gray-400">
{t('pipelines.debugDialog.streamOutput')}
</span>
<Switch
checked={streamOutput}
onCheckedChange={setStreamOutput}
disabled={!isConnected}
className="data-[state=checked]:bg-[#2288ee]"
/>
</div>
<input
ref={fileInputRef}
type="file"

View File

@@ -204,6 +204,7 @@ export class WebSocketClient {
*/
public sendMessage(
messageChain: Array<{ type: string; text?: string; target?: string }>,
stream: boolean = true,
) {
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
throw new Error('WebSocket未连接');
@@ -212,6 +213,7 @@ export class WebSocketClient {
const message = {
type: 'message',
message: messageChain,
stream: stream,
};
this.ws.send(JSON.stringify(message));

View File

@@ -535,6 +535,7 @@ const enUS = {
loadPipelinesFailed: 'Failed to load pipelines',
atTips: 'Mention the bot',
streaming: 'Streaming',
streamOutput: 'Stream',
connected: 'WebSocket connected',
disconnected: 'WebSocket disconnected',
connectionError: 'WebSocket connection error',

View File

@@ -538,6 +538,7 @@ const jaJP = {
loadPipelinesFailed: 'パイプラインの読み込みに失敗しました',
atTips: 'ボットをメンション',
streaming: 'ストリーミング',
streamOutput: 'ストリーム',
connected: 'WebSocket接続済み',
disconnected: 'WebSocket未接続',
connectionError: 'WebSocket接続エラー',

View File

@@ -517,6 +517,7 @@ const zhHans = {
loadPipelinesFailed: '加载流水线失败',
atTips: '提及机器人',
streaming: '流式传输',
streamOutput: '流式',
connected: 'WebSocket已连接',
disconnected: 'WebSocket未连接',
connectionError: 'WebSocket连接错误',

View File

@@ -515,6 +515,7 @@ const zhHant = {
loadPipelinesFailed: '載入流程線失敗',
atTips: '提及機器人',
streaming: '串流傳輸',
streamOutput: '串流',
connected: 'WebSocket已連接',
disconnected: 'WebSocket未連接',
connectionError: 'WebSocket連接錯誤',