From 49976e739b26b980c39790cc8c9f43b9000cf062 Mon Sep 17 00:00:00 2001 From: samanhappy Date: Sat, 25 Nov 2023 16:06:22 +0800 Subject: [PATCH] clear context when spark return error --- src/bots/SparkBot.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bots/SparkBot.js b/src/bots/SparkBot.js index 39baba07f8..36edca7631 100644 --- a/src/bots/SparkBot.js +++ b/src/bots/SparkBot.js @@ -86,11 +86,14 @@ export default class SparkBot extends Bot { ); let text = ""; + let error = false; source.addEventListener("message", (event) => { if (event.data === "") { onUpdateResponse(callbackParam, { done: true }); source.close(); resolve(); + } else if (event.data === "[error]") { + error = true; } else if (event.data.slice(-5) === "") { // ignore message return; @@ -111,6 +114,11 @@ export default class SparkBot extends Bot { } text += partialText; onUpdateResponse(callbackParam, { content: text, done: false }); + + // clear context if error + if (error) { + this.setChatContext(null); + } } });