feat(core): Implement Dynamic Parameters within regular nodes used as AI Tools (#10862)

This commit is contained in:
oleg
2024-10-02 13:31:22 +02:00
committed by GitHub
parent ae37035aad
commit ef5b7cf9b7
34 changed files with 1101 additions and 320 deletions

View File

@@ -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;