diff --git a/nodejs/src/session.ts b/nodejs/src/session.ts index ba6b42d2..19da9bd1 100644 --- a/nodejs/src/session.ts +++ b/nodejs/src/session.ts @@ -167,11 +167,12 @@ export class CopilotSession { } }); + let timeoutId: ReturnType | undefined; try { await this.send(options); const timeoutPromise = new Promise((_, reject) => { - setTimeout( + timeoutId = setTimeout( () => reject( new Error( @@ -185,6 +186,9 @@ export class CopilotSession { return lastAssistantMessage; } finally { + if (timeoutId !== undefined) { + clearTimeout(timeoutId); + } unsubscribe(); } }