From cb88da7f02e336fecc514cf898f2675e2f7b3809 Mon Sep 17 00:00:00 2001 From: fdc <2213070223@qq.com> Date: Thu, 31 Jul 2025 10:34:36 +0800 Subject: [PATCH] fix: frontend bug --- .../components/debug-dialog/DebugDialog.tsx | 38 +++++++++---------- web/src/app/infra/http/HttpClient.ts | 1 - 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/web/src/app/home/pipelines/components/debug-dialog/DebugDialog.tsx b/web/src/app/home/pipelines/components/debug-dialog/DebugDialog.tsx index 0a6330dc..45bf8b38 100644 --- a/web/src/app/home/pipelines/components/debug-dialog/DebugDialog.tsx +++ b/web/src/app/home/pipelines/components/debug-dialog/DebugDialog.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect, useRef, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { httpClient } from '@/app/infra/http/HttpClient'; import { DialogContent } from '@/components/ui/dialog'; @@ -46,7 +46,7 @@ export default function DebugDialog({ messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; - const loadMessages = async (pipelineId: string) => { + const loadMessages = useCallback(async (pipelineId: string) => { try { const response = await httpClient.getWebChatHistoryMessages( pipelineId, @@ -56,7 +56,7 @@ export default function DebugDialog({ } catch (error) { console.error('Failed to load messages:', error); } - }; + }, [sessionType]); useEffect(() => { scrollToBottom(); @@ -160,12 +160,12 @@ export default function DebugDialog({ text_content = '@webchatbot' + text_content; } const userMessage: Message = { - id: -1, - role: 'user', - content: text_content, - timestamp: new Date().toISOString(), - message_chain: messageChain, - }; + id: -1, + role: 'user', + content: text_content, + timestamp: new Date().toISOString(), + message_chain: messageChain, + }; // 根据isStreaming状态决定使用哪种传输方式 if (isStreaming) { // 创建初始bot消息 @@ -199,7 +199,7 @@ export default function DebugDialog({ // 处理流式响应数据 if (data.message) { accumulatedContent += data.message; - + // 更新bot消息 setMessages((prevMessages) => { const updatedMessages = [...prevMessages]; @@ -207,18 +207,18 @@ export default function DebugDialog({ (msg) => msg.id === botMessageId && msg.role === 'assistant', ); - + if (botMessageIndex !== -1) { const updatedBotMessage = { ...updatedMessages[botMessageIndex], content: accumulatedContent, message_chain: [ { type: 'Plain', text: accumulatedContent }, - ] + ], }; updatedMessages[botMessageIndex] = updatedBotMessage; } - + return updatedMessages; }); } @@ -434,12 +434,12 @@ export default function DebugDialog({ + onClick={sendMessage} + disabled={!inputValue.trim() && !hasAt} + className="rounded-md bg-[#2288ee] hover:bg-[#2288ee] w-20 text-white px-6 py-2 text-base font-medium transition-none flex items-center gap-2 shadow-none" + > + <>{t('pipelines.debugDialog.send')} + diff --git a/web/src/app/infra/http/HttpClient.ts b/web/src/app/infra/http/HttpClient.ts index a6e0c172..c3d887b8 100644 --- a/web/src/app/infra/http/HttpClient.ts +++ b/web/src/app/infra/http/HttpClient.ts @@ -35,7 +35,6 @@ import { import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest'; import { GetBotLogsResponse } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse'; - type JSONValue = string | number | boolean | JSONObject | JSONArray | null; interface JSONObject { [key: string]: JSONValue;