perf: 中断SSE、更换测试环境接口
This commit is contained in:
@ -2,11 +2,9 @@ import { fetchEventSource } from '@microsoft/fetch-event-source';
|
||||
import type { EventSourceMessage } from '@microsoft/fetch-event-source';
|
||||
import { useEnterpriseStore } from '@/stores/modules/enterprise';
|
||||
import { glsWithCatch } from '@/utils/stroage';
|
||||
import { BASE_PYTHON_URL } from '@/api/all/chat';
|
||||
|
||||
const customHost = 'https://agent.lvfunai.com';
|
||||
//
|
||||
// const customHost = 'http://localhost:3000';
|
||||
const DEFAULT_SSE_URL = `${customHost}/api/agent/runs`;
|
||||
const DEFAULT_SSE_URL = `${BASE_PYTHON_URL}/api/agent/runs`;
|
||||
|
||||
const SSE_HEADERS = {
|
||||
'Content-Type': 'application/json',
|
||||
@ -42,10 +40,10 @@ export default async (config: SSEConfig, url: string = DEFAULT_SSE_URL): Promise
|
||||
handleClose,
|
||||
} = config;
|
||||
const store = useEnterpriseStore();
|
||||
|
||||
|
||||
// 创建AbortController实例用于中断请求
|
||||
const abortController = new AbortController();
|
||||
|
||||
|
||||
fetchEventSource(url, {
|
||||
method,
|
||||
// credentials: 'include',
|
||||
@ -70,21 +68,21 @@ export default async (config: SSEConfig, url: string = DEFAULT_SSE_URL): Promise
|
||||
}
|
||||
},
|
||||
onerror(error: Error) {
|
||||
// console.error('SSE error:', error);
|
||||
// console.error('SSE error:', error);
|
||||
handleError?.(error);
|
||||
},
|
||||
onclose() {
|
||||
// console.log('SSE connection closed');
|
||||
// console.log('SSE connection closed');
|
||||
handleClose?.();
|
||||
},
|
||||
async onopen(response: Response) {
|
||||
// console.log('onopen', response);
|
||||
// console.log('onopen', response);
|
||||
handleOpen?.(response);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// 返回abort方法供外部调用
|
||||
return {
|
||||
abort: () => abortController.abort()
|
||||
abort: () => abortController.abort(),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user