mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Feature: Add support for accessing NodeData via json path
Supports `{{<variableNodeId>.data.instance.pathtokey}}`
This commit is contained in:
@@ -528,11 +528,40 @@ export const getVariableValue = (
|
|||||||
variableDict[`{{${variableFullPath}}}`] = handleEscapeCharacters(convertChatHistoryToText(chatHistory), false)
|
variableDict[`{{${variableFullPath}}}`] = handleEscapeCharacters(convertChatHistoryToText(chatHistory), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split by first occurrence of '.' to get just nodeId
|
// Resolve values with following case.
|
||||||
const [variableNodeId, _] = variableFullPath.split('.')
|
// 1: <variableNodeId>.data.instance
|
||||||
|
// 2: <variableNodeId>.data.instance.pathtokey
|
||||||
|
const variableFullPathParts = variableFullPath.split('.')
|
||||||
|
const variableNodeId = variableFullPathParts[0]
|
||||||
const executedNode = reactFlowNodes.find((nd) => nd.id === variableNodeId)
|
const executedNode = reactFlowNodes.find((nd) => nd.id === variableNodeId)
|
||||||
if (executedNode) {
|
if (executedNode) {
|
||||||
const variableValue = get(executedNode.data, 'instance')
|
let variableValue = get(executedNode.data, 'instance')
|
||||||
|
|
||||||
|
// Handle path such as `<variableNodeId>.data.instance.key`
|
||||||
|
if (variableFullPathParts.length > 3) {
|
||||||
|
let variableObj = null
|
||||||
|
switch (typeof variableValue) {
|
||||||
|
case 'string':
|
||||||
|
const unEscapedVariableValue = handleEscapeCharacters(variableValue, true)
|
||||||
|
if (unEscapedVariableValue.startsWith('{') && unEscapedVariableValue.endsWith('}')) {
|
||||||
|
try {
|
||||||
|
variableObj = JSON.parse(unEscapedVariableValue)
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'object':
|
||||||
|
variableObj = variableValue
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (variableObj) {
|
||||||
|
variableObj = get(variableObj, variableFullPathParts.slice(3))
|
||||||
|
variableValue = handleEscapeCharacters(JSON.stringify(variableObj), false)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isAcceptVariable) {
|
if (isAcceptVariable) {
|
||||||
variableDict[`{{${variableFullPath}}}`] = variableValue
|
variableDict[`{{${variableFullPath}}}`] = variableValue
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user