feat(core): Implement wrapping of regular nodes as AI Tools (#10641)

Co-authored-by: JP van Oosten <jp@n8n.io>
This commit is contained in:
oleg
2024-09-04 12:06:17 +02:00
committed by GitHub
parent f114035a6b
commit da44fe4b89
13 changed files with 615 additions and 18 deletions

View File

@@ -159,6 +159,7 @@ import { InstanceSettings } from './InstanceSettings';
import { ScheduledTaskManager } from './ScheduledTaskManager';
import { SSHClientsManager } from './SSHClientsManager';
import { binaryToBuffer } from './BinaryData/utils';
import { getNodeAsTool } from './CreateNodeAsTool';
axios.defaults.timeout = 300000;
// Prevent axios from adding x-form-www-urlencoded headers by default
@@ -2780,12 +2781,6 @@ async function getInputConnectionData(
connectedNode.typeVersion,
);
if (!nodeType.supplyData) {
throw new ApplicationError('Node does not have a `supplyData` method defined', {
extra: { nodeName: connectedNode.name },
});
}
const context = Object.assign({}, this);
context.getNodeParameter = (
@@ -2853,6 +2848,18 @@ async function getInputConnectionData(
}
};
if (!nodeType.supplyData) {
if (nodeType.description.outputs.includes(NodeConnectionType.AiTool)) {
nodeType.supplyData = async function (this: IExecuteFunctions) {
return getNodeAsTool(this, nodeType, this.getNode().parameters);
};
} else {
throw new ApplicationError('Node does not have a `supplyData` method defined', {
extra: { nodeName: connectedNode.name },
});
}
}
try {
const response = await nodeType.supplyData.call(context, itemIndex);
if (response.closeFunction) {