mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(core): Implement Dynamic Parameters within regular nodes used as AI Tools (#10862)
This commit is contained in:
@@ -961,6 +961,43 @@ export class WorkflowDataProxy {
|
||||
return taskData.data!.main[previousNodeOutput]![pairedItem.item];
|
||||
};
|
||||
|
||||
const handleFromAi = (
|
||||
name: string,
|
||||
_description?: string,
|
||||
_type: string = 'string',
|
||||
defaultValue?: unknown,
|
||||
) => {
|
||||
if (!name || name === '') {
|
||||
throw new ExpressionError('Please provide a key', {
|
||||
runIndex: that.runIndex,
|
||||
itemIndex: that.itemIndex,
|
||||
});
|
||||
}
|
||||
const nameValidationRegex = /^[a-zA-Z0-9_-]{0,64}$/;
|
||||
if (!nameValidationRegex.test(name)) {
|
||||
throw new ExpressionError(
|
||||
'Invalid parameter key, must be between 1 and 64 characters long and only contain lowercase letters, uppercase letters, numbers, underscores, and hyphens',
|
||||
{
|
||||
runIndex: that.runIndex,
|
||||
itemIndex: that.itemIndex,
|
||||
},
|
||||
);
|
||||
}
|
||||
const placeholdersDataInputData =
|
||||
that.runExecutionData?.resultData.runData[that.activeNodeName]?.[0].inputOverride?.[
|
||||
NodeConnectionType.AiTool
|
||||
]?.[0]?.[0].json;
|
||||
|
||||
if (Boolean(!placeholdersDataInputData)) {
|
||||
throw new ExpressionError('No execution data available', {
|
||||
runIndex: that.runIndex,
|
||||
itemIndex: that.itemIndex,
|
||||
type: 'no_execution_data',
|
||||
});
|
||||
}
|
||||
return placeholdersDataInputData?.[name] ?? defaultValue;
|
||||
};
|
||||
|
||||
const base = {
|
||||
$: (nodeName: string) => {
|
||||
if (!nodeName) {
|
||||
@@ -1303,6 +1340,10 @@ export class WorkflowDataProxy {
|
||||
);
|
||||
return dataProxy.getDataProxy();
|
||||
},
|
||||
$fromAI: handleFromAi,
|
||||
// Make sure mis-capitalized $fromAI is handled correctly even though we don't auto-complete it
|
||||
$fromai: handleFromAi,
|
||||
$fromAi: handleFromAi,
|
||||
$items: (nodeName?: string, outputIndex?: number, runIndex?: number) => {
|
||||
if (nodeName === undefined) {
|
||||
nodeName = (that.prevNodeGetter() as { name: string }).name;
|
||||
|
||||
Reference in New Issue
Block a user