add generation cancellation middleware and refactor chat/message workflows to support HTTP client disconnections
CI / check (22) (push) Failing after 4m54s
CI / check (24) (push) Failing after 4m54s

This commit is contained in:
2026-10-05 23:21:42 +02:00
parent c48e1b17c4
commit 1c0f06716e
17 changed files with 620 additions and 172 deletions
+13
View File
@@ -0,0 +1,13 @@
/** Cancel generation when its HTTP client disconnects, for JSON and streamed replies. */
export function generationCancellation(req, res, next) {
const controller = new AbortController();
const onClose = () => {
if (!res.writableEnded) controller.abort();
res.removeListener("finish", onFinish);
};
const onFinish = () => res.removeListener("close", onClose);
res.once("close", onClose);
res.once("finish", onFinish);
req.generationSignal = controller.signal;
next();
}