fix:lsome bug

This commit is contained in:
fdc
2025-07-31 10:28:43 +08:00
committed by Junyan Qin
parent 70f23f24b0
commit d3ab16761d
2 changed files with 38 additions and 29 deletions

View File

@@ -42,7 +42,7 @@ import {
} from '@/app/infra/entities/api';
import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest';
import { GetBotLogsResponse } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse';
import {boolean} from "zod";
type JSONValue = string | number | boolean | JSONObject | JSONArray | null;
interface JSONObject {
@@ -379,13 +379,13 @@ class HttpClient {
sessionType: string,
messageChain: object[],
pipelineId: string,
onMessage: (data: any) => void,
onMessage: (data: ApiRespWebChatMessage) => void,
onComplete: () => void,
onError: (error: any) => void,
onError: (error: Error) => void,
): Promise<void> {
try {
const url = `${this.baseURL}/api/v1/pipelines/${pipelineId}/chat/send`;
// 使用fetch发送流式请求因为axios在浏览器环境中不直接支持流式响应
const response = await fetch(url, {
method: 'POST',
@@ -415,7 +415,7 @@ class HttpClient {
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
onComplete();
break;
@@ -423,23 +423,23 @@ class HttpClient {
// 解码数据
buffer += decoder.decode(value, { stream: true });
// 处理完整的JSON对象
const lines = buffer.split('\n\n');
buffer = lines.pop() || '';
for (const line of lines) {
if (line.startsWith('data: ')) {
try {
const data = JSON.parse(line.slice(6));
if (data.type === 'end') {
// 流传输结束
reader.cancel();
onComplete();
return;
}
if (data.message) {
// 处理消息数据
onMessage(data);
@@ -454,7 +454,7 @@ class HttpClient {
reader.releaseLock();
}
} catch (error) {
onError(error);
onError(error as Error);
}
}