auto delete conversation

This commit is contained in:
Archeb
2024-06-25 15:14:41 +08:00
parent 71d4490164
commit 0aeb23f88c
+13 -6
View File
@@ -183,7 +183,7 @@ class YouProvider {
// expose function to receive youChatToken // expose function to receive youChatToken
var finalResponse = ""; var finalResponse = "";
page.exposeFunction("callback" + traceId.substring(0, 8), async (event, data) => { page.exposeFunction("callback" + traceId, async (event, data) => {
switch (event) { switch (event) {
case "youChatToken": case "youChatToken":
data = JSON.parse(data); data = JSON.parse(data);
@@ -232,7 +232,7 @@ class YouProvider {
page.evaluate( page.evaluate(
async (url, traceId) => { async (url, traceId) => {
var evtSource = new EventSource(url); var evtSource = new EventSource(url);
var callbackName = "callback" + traceId.substring(0, 8); var callbackName = "callback" + traceId;
evtSource.onerror = (error) => { evtSource.onerror = (error) => {
window[callbackName]("error", error); window[callbackName]("error", error);
evtSource.close(); evtSource.close();
@@ -250,6 +250,13 @@ class YouProvider {
(event) => { (event) => {
window[callbackName]("done", ""); window[callbackName]("done", "");
evtSource.close(); evtSource.close();
fetch("https://you.com/api/chat/deleteChat", {
headers: {
"content-type": "application/json",
},
body: JSON.stringify({ chatId: traceId }),
method: "DELETE",
});
}, },
false false
); );
@@ -261,17 +268,17 @@ class YouProvider {
} }
}; };
// 注册退出函数 // 注册退出函数
window["exit" + traceId.substring(0, 8)] = () => { window["exit" + traceId] = () => {
evtSource.close(); evtSource.close();
}; };
}, },
url, url,
traceId.substring(0, 8) traceId
); );
const cancel = () => { const cancel = () => {
page?.evaluate((traceId) => { page?.evaluate((traceId) => {
window["exit" + traceId.substring(0, 8)](); window["exit" + traceId]();
}, traceId.substring(0, 8)); }, traceId);
}; };
return { completion: emitter, cancel }; return { completion: emitter, cancel };
} }