From 59564b710e76ada8472d1d3e419be377d2016326 Mon Sep 17 00:00:00 2001 From: NamH Date: Sun, 14 Jan 2024 16:22:29 +0700 Subject: [PATCH] fix(Thread): #1336 not allow creating too many unfinished thread (#1538) Signed-off-by: James Co-authored-by: James --- .../conversational-extension/src/index.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/conversational-extension/src/index.ts b/extensions/conversational-extension/src/index.ts index ac31351dff..a8ffd51dcd 100644 --- a/extensions/conversational-extension/src/index.ts +++ b/extensions/conversational-extension/src/index.ts @@ -95,10 +95,19 @@ export default class JSONConversationalExtension * @param threadId The ID of the thread to delete. */ async deleteThread(threadId: string): Promise { - return fs.rmdirSync( - await joinPath([JSONConversationalExtension._homeDir, `${threadId}`]), - { recursive: true } - ) + const path = await joinPath([ + JSONConversationalExtension._homeDir, + `${threadId}`, + ]) + try { + if (await fs.existsSync(path)) { + await fs.rmdirSync(path, { recursive: true }) + } else { + console.debug(`${path} does not exist`) + } + } catch (err) { + console.error(err) + } } async addNewMessage(message: ThreadMessage): Promise {