From de5707de2b68055cb138ad13b2af69e29bb40857 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 7 Mar 2023 12:14:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B6=85=E6=97=B6=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=B7=B2=E7=BB=8F=E6=9C=89=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=88=99=E8=BF=94=E5=9B=9E=E8=BF=99=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/SydneyAIClient.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/utils/SydneyAIClient.js b/utils/SydneyAIClient.js index add7f5d..fe885be 100644 --- a/utils/SydneyAIClient.js +++ b/utils/SydneyAIClient.js @@ -181,7 +181,8 @@ export default class SydneyAIClient { invocationId = 0, parentMessageId = invocationId || crypto.randomUUID(), onProgress, - abortController = new AbortController() + abortController = new AbortController(), + timeout = Config.defaultTimeoutMs } = opts if (typeof onProgress !== 'function') { onProgress = () => {} @@ -314,14 +315,26 @@ export default class SydneyAIClient { const messageTimeout = setTimeout(() => { this.cleanupWebSocketConnection(ws) - reject(new Error('Timed out waiting for response. Try enabling debug mode to see more information.')) - }, 120 * 1000) + if (replySoFar) { + resolve({ + message + }) + } else { + reject(new Error('Timed out waiting for response. Try enabling debug mode to see more information.')) + } + }, timeout) // abort the request if the abort controller is aborted abortController.signal.addEventListener('abort', () => { clearTimeout(messageTimeout) this.cleanupWebSocketConnection(ws) - reject('Request aborted') + if (replySoFar) { + resolve({ + message + }) + } else { + reject('Request aborted') + } }) ws.on('message', (data) => {