MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / run

Method run

packages/components/nodes/agentflow/Tool/Tool.ts:185–350  ·  view source on GitHub ↗
(nodeData: INodeData, input: string, options: ICommonObject)

Source from the content-addressed store, hash-verified

183 }
184
185 async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {
186 const selectedTool = (nodeData.inputs?.selectedTool as string) || (nodeData.inputs?.toolAgentflowSelectedTool as string)
187 const selectedToolConfig =
188 (nodeData?.inputs?.selectedToolConfig as ICommonObject) ||
189 (nodeData?.inputs?.toolAgentflowSelectedToolConfig as ICommonObject) ||
190 {}
191
192 const toolInputArgs = nodeData.inputs?.toolInputArgs as IToolInputArgs[]
193 const _toolUpdateState = nodeData.inputs?.toolUpdateState
194
195 const state = options.agentflowRuntime?.state as ICommonObject
196 const chatId = options.chatId as string
197 const isLastNode = options.isLastNode as boolean
198 const isStreamable = isLastNode && options.sseStreamer !== undefined
199
200 const abortController = options.abortController as AbortController
201
202 // Update flow state if needed
203 let newState = { ...state }
204 if (_toolUpdateState && Array.isArray(_toolUpdateState) && _toolUpdateState.length > 0) {
205 newState = updateFlowState(state, _toolUpdateState)
206 }
207
208 if (!selectedTool) {
209 throw new Error('Tool not selected')
210 }
211
212 const nodeInstanceFilePath = options.componentNodes[selectedTool].filePath as string
213 const nodeModule = await import(nodeInstanceFilePath)
214 const newToolNodeInstance = new nodeModule.nodeClass()
215 const newNodeData = {
216 ...nodeData,
217 credential: selectedToolConfig['FLOWISE_CREDENTIAL_ID'],
218 inputs: {
219 ...nodeData.inputs,
220 ...selectedToolConfig
221 }
222 }
223 const toolInstance = (await newToolNodeInstance.init(newNodeData, '', options)) as Tool | Tool[]
224
225 let toolCallArgs: Record<string, any> = {}
226
227 const parseInputValue = (value: string): any => {
228 if (typeof value !== 'string') {
229 return value
230 }
231
232 // Remove escape characters (backslashes before special characters)
233 // ex: \["a", "b", "c", "d", "e"\]
234 let cleanedValue = value
235 .replace(/\\"/g, '"') // \" -> "
236 .replace(/\\\[/g, '[') // \[ -> [
237 .replace(/\\\]/g, ']') // \] -> ]
238 .replace(/\\\{/g, '{') // \{ -> {
239 .replace(/\\\}/g, '}') // \} -> }
240 .replace(/\\\\/g, '\\') // \\ -> \ (unescape backslash last)
241
242 // Try to parse as JSON if it looks like JSON/array

Callers

nothing calls this directly

Calls 8

updateFlowStateFunction · 0.90
processTemplateVariablesFunction · 0.90
stringifyMethod · 0.80
initMethod · 0.65
parseMethod · 0.65
streamTokenEventMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected