Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const exampleFunc = `/*
* You can use properties specified in Input Variables with the prefix $. For example: $foo
* You can get default flow config: $flow.sessionId, $flow.chatId, $flow.chatflowId, $flow.input, $flow.state
* You can get global variables: $vars.<variable-name>
* Must return a string value at the end of function
* You can return a string value or a JSON object at the end of function
*/

const fetch = require('node-fetch');
Expand All @@ -32,6 +32,7 @@ const options = {
'Content-Type': 'application/json'
}
};

try {
const response = await fetch(url, options);
const text = await response.text();
Expand Down Expand Up @@ -60,7 +61,7 @@ class CustomFunction_Agentflow implements INode {
constructor() {
this.label = 'Custom Function'
this.name = 'customFunctionAgentflow'
this.version = 1.1
this.version = 1.2
this.type = 'CustomFunction'
this.category = 'Agent Flows'
this.description = 'Execute custom function'
Expand Down Expand Up @@ -107,7 +108,8 @@ class CustomFunction_Agentflow implements INode {
label: 'Key',
name: 'key',
type: 'asyncOptions',
loadMethod: 'listRuntimeStateKeys'
loadMethod: 'listRuntimeStateKeys',
freeSolo: true
},
{
label: 'Value',
Expand Down Expand Up @@ -183,18 +185,16 @@ class CustomFunction_Agentflow implements INode {
streamOutput
})

let finalOutput = response
if (typeof response === 'object') {
finalOutput = JSON.stringify(response, null, 2)
}
const finalOutput = response

// Update flow state if needed
let newState = { ...state }
if (_customFunctionUpdateState && Array.isArray(_customFunctionUpdateState) && _customFunctionUpdateState.length > 0) {
newState = updateFlowState(state, _customFunctionUpdateState)
}

newState = processTemplateVariables(newState, finalOutput)
const outputForState = typeof finalOutput === 'object' && finalOutput !== null ? JSON.stringify(finalOutput, null, 2) : finalOutput
newState = processTemplateVariables(newState, outputForState)

const returnOutput = {
id: nodeData.id,
Expand Down