From 37793f9688660b841247431ef93f13239c9043c9 Mon Sep 17 00:00:00 2001 From: shadowlin Date: Fri, 3 May 2024 21:09:51 +0800 Subject: [PATCH] feat: can break the stream when st does --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 4648bc4..76d715c 100644 --- a/index.js +++ b/index.js @@ -240,6 +240,14 @@ app.post("/v1/messages", (req, res) => { console.log(e); } }); + + res.on("close", function () { + console.log(" > [Client closed]"); + if (stream && typeof stream.destroy === 'function') { + stream.destroy(); + } + }); + stream.on("end", () => { // send ending res.write(createEvent("content_block_stop", { type: "content_block_stop", index: 0 }));