add new utilties - customfunction, setter/getter, replace code editor

This commit is contained in:
Henry
2023-12-15 17:15:00 +00:00
parent 1b0b1f13fa
commit 911b4fe7fb
22 changed files with 543 additions and 710 deletions
+22
View File
@@ -281,6 +281,28 @@ export class App {
}
})
// execute custom function node
this.app.post('/api/v1/node-custom-function', async (req: Request, res: Response) => {
const body = req.body
const nodeData = { inputs: body }
if (Object.prototype.hasOwnProperty.call(this.nodesPool.componentNodes, 'customFunction')) {
try {
const nodeInstanceFilePath = this.nodesPool.componentNodes['customFunction'].filePath as string
const nodeModule = await import(nodeInstanceFilePath)
const newNodeInstance = new nodeModule.nodeClass()
const returnOptions: INodeOptionsValue[] = await newNodeInstance.init(nodeData)
return res.json(returnOptions)
} catch (error) {
return res.status(500).send(`Error running custom function: ${error}`)
}
} else {
res.status(404).send(`Node customFunction not found`)
return
}
})
// ----------------------------------------
// Chatflows
// ----------------------------------------
+20 -3
View File
@@ -231,6 +231,7 @@ export const buildLangchain = async (
// Create a Queue and add our initial node in it
const nodeQueue = [] as INodeQueue[]
const exploredNode = {} as IExploredNode
const dynamicVariables = {} as Record<string, unknown>
// In the case of infinite loop, only max 3 loops will be executed
const maxLoop = 3
@@ -267,20 +268,36 @@ export const buildLangchain = async (
appDataSource,
databaseEntities,
logger,
cachePool
cachePool,
dynamicVariables
})
logger.debug(`[server]: Finished upserting ${reactFlowNode.data.label} (${reactFlowNode.data.id})`)
break
} else {
logger.debug(`[server]: Initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`)
flowNodes[nodeIndex].data.instance = await newNodeInstance.init(reactFlowNodeData, question, {
let outputResult = await newNodeInstance.init(reactFlowNodeData, question, {
chatId,
chatflowid,
appDataSource,
databaseEntities,
logger,
cachePool
cachePool,
dynamicVariables
})
// Save dynamic variables
if (reactFlowNode.data.name === 'setVariable') {
const dynamicVars = outputResult?.dynamicVariables ?? {}
for (const variableKey in dynamicVars) {
dynamicVariables[variableKey] = dynamicVars[variableKey]
}
outputResult = outputResult?.output
}
flowNodes[nodeIndex].data.instance = outputResult
logger.debug(`[server]: Finished initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`)
}
} catch (e: any) {