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));