mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Allows CustomFunction to be set as an Ending Node
This commit is contained in:
@@ -52,11 +52,19 @@ class CustomFunction_Utilities implements INode {
|
||||
label: 'Output',
|
||||
name: 'output',
|
||||
baseClasses: ['string', 'number', 'boolean', 'json', 'array']
|
||||
},
|
||||
{
|
||||
label: 'Ending Node',
|
||||
name: 'EndingNode',
|
||||
baseClasses: [this.type]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {
|
||||
const isEndingNode = nodeData?.outputs?.output === 'EndingNode'
|
||||
if (isEndingNode && !options.isRun) return // prevent running both init and run twice
|
||||
|
||||
const javascriptFunction = nodeData.inputs?.javascriptFunction as string
|
||||
const functionInputVariablesRaw = nodeData.inputs?.functionInputVariables
|
||||
const appDataSource = options.appDataSource as DataSource
|
||||
@@ -123,7 +131,8 @@ class CustomFunction_Utilities implements INode {
|
||||
const vm = new NodeVM(nodeVMOptions)
|
||||
try {
|
||||
const response = await vm.run(`module.exports = async function() {${javascriptFunction}}()`, __dirname)
|
||||
if (typeof response === 'string') {
|
||||
|
||||
if (typeof response === 'string' && !isEndingNode) {
|
||||
return handleEscapeCharacters(response, false)
|
||||
}
|
||||
return response
|
||||
@@ -131,6 +140,10 @@ class CustomFunction_Utilities implements INode {
|
||||
throw new Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||
return await this.init(nodeData, input, { ...options, isRun: true })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: CustomFunction_Utilities }
|
||||
|
||||
Reference in New Issue
Block a user