mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 03:16:14 +00:00
fix: frontend bug
This commit is contained in:
@@ -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 { useTranslation } from 'react-i18next';
|
||||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
import { httpClient } from '@/app/infra/http/HttpClient';
|
||||||
import { DialogContent } from '@/components/ui/dialog';
|
import { DialogContent } from '@/components/ui/dialog';
|
||||||
@@ -46,7 +46,7 @@ export default function DebugDialog({
|
|||||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadMessages = async (pipelineId: string) => {
|
const loadMessages = useCallback(async (pipelineId: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await httpClient.getWebChatHistoryMessages(
|
const response = await httpClient.getWebChatHistoryMessages(
|
||||||
pipelineId,
|
pipelineId,
|
||||||
@@ -56,7 +56,7 @@ export default function DebugDialog({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load messages:', error);
|
console.error('Failed to load messages:', error);
|
||||||
}
|
}
|
||||||
};
|
}, [sessionType]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
@@ -160,12 +160,12 @@ export default function DebugDialog({
|
|||||||
text_content = '@webchatbot' + text_content;
|
text_content = '@webchatbot' + text_content;
|
||||||
}
|
}
|
||||||
const userMessage: Message = {
|
const userMessage: Message = {
|
||||||
id: -1,
|
id: -1,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: text_content,
|
content: text_content,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
message_chain: messageChain,
|
message_chain: messageChain,
|
||||||
};
|
};
|
||||||
// 根据isStreaming状态决定使用哪种传输方式
|
// 根据isStreaming状态决定使用哪种传输方式
|
||||||
if (isStreaming) {
|
if (isStreaming) {
|
||||||
// 创建初始bot消息
|
// 创建初始bot消息
|
||||||
@@ -199,7 +199,7 @@ export default function DebugDialog({
|
|||||||
// 处理流式响应数据
|
// 处理流式响应数据
|
||||||
if (data.message) {
|
if (data.message) {
|
||||||
accumulatedContent += data.message;
|
accumulatedContent += data.message;
|
||||||
|
|
||||||
// 更新bot消息
|
// 更新bot消息
|
||||||
setMessages((prevMessages) => {
|
setMessages((prevMessages) => {
|
||||||
const updatedMessages = [...prevMessages];
|
const updatedMessages = [...prevMessages];
|
||||||
@@ -207,18 +207,18 @@ export default function DebugDialog({
|
|||||||
(msg) =>
|
(msg) =>
|
||||||
msg.id === botMessageId && msg.role === 'assistant',
|
msg.id === botMessageId && msg.role === 'assistant',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (botMessageIndex !== -1) {
|
if (botMessageIndex !== -1) {
|
||||||
const updatedBotMessage = {
|
const updatedBotMessage = {
|
||||||
...updatedMessages[botMessageIndex],
|
...updatedMessages[botMessageIndex],
|
||||||
content: accumulatedContent,
|
content: accumulatedContent,
|
||||||
message_chain: [
|
message_chain: [
|
||||||
{ type: 'Plain', text: accumulatedContent },
|
{ type: 'Plain', text: accumulatedContent },
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
updatedMessages[botMessageIndex] = updatedBotMessage;
|
updatedMessages[botMessageIndex] = updatedBotMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatedMessages;
|
return updatedMessages;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -434,12 +434,12 @@ export default function DebugDialog({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={sendMessage}
|
onClick={sendMessage}
|
||||||
disabled={!inputValue.trim() && !hasAt}
|
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"
|
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')}</>
|
<>{t('pipelines.debugDialog.send')}</>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import {
|
|||||||
import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest';
|
import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest';
|
||||||
import { GetBotLogsResponse } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse';
|
import { GetBotLogsResponse } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse';
|
||||||
|
|
||||||
|
|
||||||
type JSONValue = string | number | boolean | JSONObject | JSONArray | null;
|
type JSONValue = string | number | boolean | JSONObject | JSONArray | null;
|
||||||
interface JSONObject {
|
interface JSONObject {
|
||||||
[key: string]: JSONValue;
|
[key: string]: JSONValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user