diff --git a/lib/node.d.ts b/lib/node.d.ts index c23d73a9b..84608871b 100644 --- a/lib/node.d.ts +++ b/lib/node.d.ts @@ -16,6 +16,7 @@ export declare class ComputedNode extends Node { readonly graphId: string; readonly isResult: boolean; readonly params: NodeDataParams; + private readonly dynamicParams; readonly nestedGraph?: GraphData; readonly retryLimit: number; retryCount: number; diff --git a/lib/node.js b/lib/node.js index 72ddc3d3b..f27476299 100644 --- a/lib/node.js +++ b/lib/node.js @@ -61,6 +61,18 @@ class ComputedNode extends Node { (0, utils_2.assert)(!!this.ifSource.nodeId, `Invalid data source ${data.if}`); this.pendings.add(this.ifSource.nodeId); } + const regex = /^\$\{([^{}]+)\}$/; + this.dynamicParams = Object.keys(this.params).reduce((tmp, key) => { + const value = this.params[key]; + const match = typeof value === "string" ? value.match(regex) : null; + if (match) { + const dataSource = (0, utils_2.parseNodeName)(match[1]); + tmp[key] = dataSource; + (0, utils_2.assert)(!!dataSource.nodeId, `Invalid data source ${key}:${value}`); + this.pendings.add(dataSource.nodeId); + } + return tmp; + }, {}); this.log.initForComputedNode(this); } getAgentId() { @@ -190,8 +202,13 @@ class ComputedNode extends Node { try { const callback = this.agentFunction ?? this.graph.getCallback(this.agentId); const localLog = []; + const params = Object.keys(this.dynamicParams).reduce((tmp, key) => { + const [result] = this.graph.resultsOf([this.dynamicParams[key]]); + tmp[key] = result; + return tmp; + }, { ...this.params }); const context = { - params: this.params, + params: params, inputs: previousResults, debugInfo: { nodeId: this.nodeId,