mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-29 16:57:03 +03:00
feat: provide closeStream (#6659)
Upstream https://github.com/toeverything/blocksuite/pull/6836
This commit is contained in:
parent
6ec97b27c4
commit
a20a3fbbf8
@ -100,13 +100,15 @@ export class CopilotClient {
|
||||
async chatText({
|
||||
sessionId,
|
||||
messageId,
|
||||
signal,
|
||||
}: {
|
||||
sessionId: string;
|
||||
messageId: string;
|
||||
signal?: AbortSignal;
|
||||
}) {
|
||||
const url = new URL(`${this.backendUrl}/api/copilot/chat/${sessionId}`);
|
||||
url.searchParams.set('messageId', messageId);
|
||||
const response = await fetch(url.toString());
|
||||
const response = await fetch(url.toString(), { signal });
|
||||
return response.text();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ export type TextToTextOptions = {
|
||||
params?: Record<string, string>;
|
||||
timeout?: number;
|
||||
stream?: boolean;
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
||||
export function createChatSession({
|
||||
@ -102,6 +103,7 @@ export function textToText({
|
||||
params,
|
||||
sessionId,
|
||||
stream,
|
||||
signal,
|
||||
timeout = TIMEOUT,
|
||||
}: TextToTextOptions) {
|
||||
if (stream) {
|
||||
@ -120,6 +122,15 @@ export function textToText({
|
||||
sessionId: message.sessionId,
|
||||
messageId: message.messageId,
|
||||
});
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
eventSource.close();
|
||||
return;
|
||||
}
|
||||
signal.onabort = () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}
|
||||
for await (const event of toTextStream(eventSource, { timeout })) {
|
||||
if (event.type === 'message') {
|
||||
yield event.data;
|
||||
|
Loading…
Reference in New Issue
Block a user