(nodeData: INodeData, _: string, options: ICommonObject)
| 102 | } |
| 103 | |
| 104 | async run(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { |
| 105 | const loopBackToNode = nodeData.inputs?.loopBackToNode as string |
| 106 | const _maxLoopCount = nodeData.inputs?.maxLoopCount as string |
| 107 | const fallbackMessage = nodeData.inputs?.fallbackMessage as string |
| 108 | const _loopUpdateState = nodeData.inputs?.loopUpdateState |
| 109 | |
| 110 | const state = options.agentflowRuntime?.state as ICommonObject |
| 111 | |
| 112 | const loopBackToNodeId = loopBackToNode.split('-')[0] |
| 113 | const loopBackToNodeLabel = loopBackToNode.split('-')[1] |
| 114 | |
| 115 | const data = { |
| 116 | nodeID: loopBackToNodeId, |
| 117 | maxLoopCount: _maxLoopCount ? parseInt(_maxLoopCount) : 5 |
| 118 | } |
| 119 | |
| 120 | const finalOutput = 'Loop back to ' + `${loopBackToNodeLabel} (${loopBackToNodeId})` |
| 121 | |
| 122 | // Update flow state if needed |
| 123 | let newState = { ...state } |
| 124 | if (_loopUpdateState && Array.isArray(_loopUpdateState) && _loopUpdateState.length > 0) { |
| 125 | newState = updateFlowState(state, _loopUpdateState) |
| 126 | } |
| 127 | |
| 128 | // Process template variables in state |
| 129 | if (newState && Object.keys(newState).length > 0) { |
| 130 | for (const key in newState) { |
| 131 | if (newState[key].toString().includes('{{ output }}')) { |
| 132 | newState[key] = finalOutput |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | const returnOutput = { |
| 138 | id: nodeData.id, |
| 139 | name: this.name, |
| 140 | input: data, |
| 141 | output: { |
| 142 | content: finalOutput, |
| 143 | nodeID: loopBackToNodeId, |
| 144 | maxLoopCount: _maxLoopCount ? parseInt(_maxLoopCount) : 5, |
| 145 | fallbackMessage |
| 146 | }, |
| 147 | state: newState |
| 148 | } |
| 149 | |
| 150 | return returnOutput |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | module.exports = { nodeClass: Loop_Agentflow } |
nothing calls this directly
no test coverage detected