mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
prevent multi-run issues
This commit is contained in:
@@ -1073,22 +1073,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
let chatController;
|
||||
let abortCallback;
|
||||
|
||||
function abortNow() {
|
||||
chatController?.abort();
|
||||
if (!abortCallback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
abortCallback();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function generate(cancel = false, noPush = false) {
|
||||
if (chatController) {
|
||||
chatController.abort();
|
||||
|
||||
if (cancel) {
|
||||
$chat.classList.remove("completing");
|
||||
|
||||
if (abortNow() && cancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (autoScrolling) {
|
||||
setFollowTail(true);
|
||||
@@ -1127,7 +1127,7 @@
|
||||
pushMessage();
|
||||
}
|
||||
|
||||
chatController = new AbortController();
|
||||
const controller = new AbortController();
|
||||
|
||||
$chat.classList.add("completing");
|
||||
|
||||
@@ -1151,20 +1151,27 @@
|
||||
messages: messages.map(message => message.getData()).filter(Boolean),
|
||||
};
|
||||
|
||||
let message, generationID, timeout;
|
||||
|
||||
function stopLoadingTimeout() {
|
||||
clearTimeout(timeout);
|
||||
|
||||
message?.setLoading(false);
|
||||
}
|
||||
let message, generationID, stopTimeout;
|
||||
|
||||
function startLoadingTimeout() {
|
||||
stopTimeout?.();
|
||||
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
const msg = message,
|
||||
timeout = setTimeout(() => {
|
||||
msg.setLoading(true);
|
||||
}, 1500);
|
||||
|
||||
stopTimeout = () => {
|
||||
stopTimeout = null;
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
message?.setLoading(true);
|
||||
}, 1500);
|
||||
msg?.setLoading(false);
|
||||
};
|
||||
}
|
||||
|
||||
function finish() {
|
||||
@@ -1199,6 +1206,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
let aborted;
|
||||
|
||||
abortCallback = () => {
|
||||
abortCallback = null;
|
||||
aborted = true;
|
||||
|
||||
controller.abort();
|
||||
|
||||
stopTimeout?.();
|
||||
|
||||
finish();
|
||||
|
||||
$chat.classList.remove("completing");
|
||||
|
||||
if (!chatTitle && !titleController) {
|
||||
refreshTitle();
|
||||
}
|
||||
};
|
||||
|
||||
start();
|
||||
|
||||
stream(
|
||||
@@ -1209,27 +1235,21 @@
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
signal: chatController.signal,
|
||||
signal: controller.signal,
|
||||
},
|
||||
chunk => {
|
||||
stopLoadingTimeout();
|
||||
|
||||
if (chunk === "aborted" || chunk === "done") {
|
||||
chatController = null;
|
||||
|
||||
finish();
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunk === "done") {
|
||||
$chat.classList.remove("completing");
|
||||
|
||||
if (!chatTitle && !titleController) {
|
||||
refreshTitle();
|
||||
}
|
||||
}
|
||||
abortCallback();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
stopTimeout?.();
|
||||
|
||||
if (!message && chunk.type !== "end") {
|
||||
start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user