From b1b43884b84c7ffcf69ea16880dba7040b006b56 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 9 Apr 2026 09:07:15 -0500 Subject: [PATCH] use abort signal --- web/src/utils/chatUtil.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/web/src/utils/chatUtil.ts b/web/src/utils/chatUtil.ts index dcb9d1d31c..a9eea753b3 100644 --- a/web/src/utils/chatUtil.ts +++ b/web/src/utils/chatUtil.ts @@ -25,6 +25,7 @@ export async function streamChatCompletion( headers: Record, apiMessages: { role: string; content: string }[], callbacks: StreamChatCallbacks, + signal?: AbortSignal, ): Promise { const { updateMessages, @@ -38,6 +39,7 @@ export async function streamChatCompletion( method: "POST", headers, body: JSON.stringify({ messages: apiMessages, stream: true }), + signal, }); if (!res.ok) { @@ -152,11 +154,15 @@ export async function streamChatCompletion( return next; }); } - } catch { - onError(defaultErrorMessage); - updateMessages((prev) => - prev.filter((m) => !(m.role === "assistant" && m.content === "")), - ); + } catch (err) { + if (err instanceof DOMException && err.name === "AbortError") { + // User stopped generation — not an error + } else { + onError(defaultErrorMessage); + updateMessages((prev) => + prev.filter((m) => !(m.role === "assistant" && m.content === "")), + ); + } } finally { onDone(); }