@n8n/n8n-nodes-langchain
Version:
40 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeEngineAction = executeEngineAction;
const omit_1 = __importDefault(require("lodash/omit"));
const n8n_workflow_1 = require("n8n-workflow");
const EMPTY_TASK_DATA_SHELL = { executionTime: 0, startTime: 0, executionIndex: 0, source: [] };
async function executeEngineAction(node, action, tools) {
const tool = tools.find((t) => t.name === action.metadata?.toolName);
if (!tool) {
return errorResult(node, action, `Sub-agent could not find a connected tool for node "${action.nodeName}".`);
}
try {
const output = await tool.invoke((0, omit_1.default)(action.input, 'tool'));
return {
action,
data: {
...EMPTY_TASK_DATA_SHELL,
executionStatus: 'success',
data: { ai_tool: [[{ json: { output } }]] },
},
};
}
catch (error) {
return errorResult(node, action, error instanceof Error ? error.message : String(error));
}
}
function errorResult(node, action, message) {
return {
action,
data: {
...EMPTY_TASK_DATA_SHELL,
executionStatus: 'error',
error: new n8n_workflow_1.NodeOperationError(node, message),
},
};
}
//# sourceMappingURL=executeEngineAction.js.map