UNPKG

n8n-nodes-query-retriever-rerank

Version:

Advanced n8n community node for intelligent document retrieval with multi-step reasoning, reranking, and comprehensive debugging

85 lines (84 loc) 3.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.logWrapper = logWrapper; const n8n_workflow_1 = require("n8n-workflow"); async function callMethodAsync(parameters) { try { return await parameters.method.call(this, ...parameters.arguments); } catch (error) { const connectedNode = parameters.executeFunctions.getNode(); throw new n8n_workflow_1.NodeOperationError(connectedNode, error); } } function logAiEvent(executeFunctions, eventType) { try { if ('logAiEvent' in executeFunctions && typeof executeFunctions.logAiEvent === 'function') { executeFunctions.logAiEvent({ type: eventType, }); } } catch { // Silently fail if logAiEvent is not available } } function logWrapper(originalInstance, executeFunctions) { return new Proxy(originalInstance, { get(target, prop, receiver) { const originalValue = Reflect.get(target, prop, receiver); // Handle Tool - check for _call method (standard tool interface) if ('_call' in target || 'call' in target) { if (prop === '_call' && '_call' in target) { return async (input) => { const connectionType = "ai_tool" /* NodeConnectionType.AiTool */; // Log input data const { index } = executeFunctions.addInputData(connectionType, [ [{ json: { input } }], ]); // Call the original method with proper error handling const response = (await callMethodAsync.call(target, { executeFunctions, connectionType, currentNodeRunIndex: index, method: target[prop], arguments: [input], })); // Log AI event logAiEvent(executeFunctions, 'ai-tool-called'); // Log output data executeFunctions.addOutputData(connectionType, index, [ [{ json: { response } }], ]); return response; }; } if (prop === 'call' && 'call' in target) { return async (input) => { const connectionType = "ai_tool" /* NodeConnectionType.AiTool */; // Log input data const { index } = executeFunctions.addInputData(connectionType, [ [{ json: { input } }], ]); // Call the original method with proper error handling const response = (await callMethodAsync.call(target, { executeFunctions, connectionType, currentNodeRunIndex: index, method: target[prop], arguments: [input], })); // Log AI event logAiEvent(executeFunctions, 'ai-tool-called'); // Log output data executeFunctions.addOutputData(connectionType, index, [ [{ json: { response } }], ]); return response; }; } } return originalValue; }, }); }