UNPKG

@n8n/n8n-nodes-langchain

Version:
71 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PendingCallsManager = void 0; const belongsToSession = (callId, sessionId) => callId.startsWith(`${sessionId}_`); class PendingCallsManager { constructor() { this.pendingCalls = {}; } async waitForResult(callId, toolName, args, timeoutMs) { return await new Promise((resolve, reject) => { const timer = setTimeout(() => { if (this.pendingCalls[callId]) { this.reject(callId, new Error('Worker tool execution timeout')); } }, timeoutMs); this.pendingCalls[callId] = { toolName, arguments: args, resolve, reject, timer, }; }); } resolve(callId, result) { const pending = this.pendingCalls[callId]; if (pending) { clearTimeout(pending.timer); pending.resolve(result); delete this.pendingCalls[callId]; return true; } return false; } reject(callId, error) { const pending = this.pendingCalls[callId]; if (pending) { clearTimeout(pending.timer); pending.reject(error); delete this.pendingCalls[callId]; return true; } return false; } get(callId) { return this.pendingCalls[callId]; } has(callId) { return callId in this.pendingCalls; } hasForSession(sessionId) { return Object.keys(this.pendingCalls).some((callId) => belongsToSession(callId, sessionId)); } remove(callId) { delete this.pendingCalls[callId]; } cleanupBySessionId(sessionId) { for (const callId of Object.keys(this.pendingCalls)) { if (belongsToSession(callId, sessionId)) { const pending = this.pendingCalls[callId]; if (pending) { clearTimeout(pending.timer); pending.resolve(undefined); } delete this.pendingCalls[callId]; } } } } exports.PendingCallsManager = PendingCallsManager; //# sourceMappingURL=PendingCallsManager.js.map