@@ -8,12 +8,13 @@ import complexNode from './compute/complexnode';
88import assertNode from './compute/assertnode' ;
99import requestNode from './compute/requestnode' ;
1010import setVarNode from './compute/setvarnode' ;
11+ import { LogLevel } from './GraphLogger' ;
1112
1213class Graph {
13- constructor ( nodes , edges , startTime , initialEnvVars , initialLogs ) {
14+ constructor ( nodes , edges , startTime , initialEnvVars , logger ) {
1415 this . nodes = nodes ;
1516 this . edges = edges ;
16- this . logs = initialLogs ;
17+ this . logger = logger ;
1718 this . timeout = useCanvasStore . getState ( ) . timeout ;
1819 this . startTime = startTime ;
1920 this . graphRunNodeOutput = { } ;
@@ -67,7 +68,8 @@ class Graph {
6768 console . debug ( 'Executing node: ' , node ) ;
6869
6970 if ( node . type === 'outputNode' ) {
70- this . logs . push ( `Output: ${ JSON . stringify ( prevNodeOutputData ) } ` ) ;
71+ //this.logs.push(`Output: ${JSON.stringify(prevNodeOutputData)}`);
72+ this . logger . add ( LogLevel . INFO , '' , { type : 'outputNode' , data : prevNodeOutputData } ) ;
7173 useCanvasStore . getState ( ) . setOutputNode ( node . id , prevNodeOutputData ) ;
7274 result = {
7375 status : 'Success' ,
@@ -81,17 +83,15 @@ class Graph {
8183 node . data . variables ,
8284 prevNodeOutputData ,
8385 this . envVariables ,
84- this . logs ,
86+ this . logger ,
8587 ) ;
8688 if ( eNode . evaluate ( ) ) {
87- this . logs . push ( 'Result: true' ) ;
8889 result = {
8990 status : 'Success' ,
9091 data : prevNodeOutputData ,
9192 output : true ,
9293 } ;
9394 } else {
94- this . logs . push ( 'Result: false' ) ;
9595 result = {
9696 status : 'Success' ,
9797 data : prevNodeOutputData ,
@@ -106,7 +106,7 @@ class Graph {
106106 return new Promise ( ( resolve ) => setTimeout ( resolve , Math . min ( ms , this . timeout ) ) ) ;
107107 } ;
108108 await wait ( delay ) ;
109- this . logs . push ( `Wait for: ${ delay } ms` ) ;
109+ this . logger . add ( LogLevel . INFO , '' , { type : 'delayNode' , data : delay } ) ;
110110 result = {
111111 status : 'Success' ,
112112 } ;
@@ -121,7 +121,7 @@ class Graph {
121121 }
122122
123123 if ( node . type === 'requestNode' ) {
124- const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth , this . logs ) ;
124+ const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth , this . logger ) ;
125125 result = await rNode . evaluate ( ) ;
126126 // add post response variables if any
127127 if ( result . postRespVars ) {
@@ -140,7 +140,7 @@ class Graph {
140140 cloneDeep ( flowData . edges ) ,
141141 this . startTime ,
142142 this . envVariables ,
143- this . logs ,
143+ this . logger ,
144144 ) ;
145145 result = await cNode . evaluate ( ) ;
146146 this . envVariables = result . envVars ;
@@ -155,7 +155,13 @@ class Graph {
155155 const sNode = new setVarNode ( node . data , prevNodeOutputData , this . envVariables ) ;
156156 const newVariable = sNode . evaluate ( ) ;
157157 if ( newVariable != undefined ) {
158- this . logs . push ( `Evaluate variable: ${ JSON . stringify ( newVariable ) } ` ) ;
158+ this . logger . add ( LogLevel . INFO , 'Set Variable' , {
159+ type : 'setVarNode' ,
160+ data : {
161+ name : Object . keys ( newVariable ) [ 0 ] ,
162+ value : newVariable [ Object . keys ( newVariable ) [ 0 ] ] ,
163+ } ,
164+ } ) ;
159165 this . envVariables = {
160166 ...this . envVariables ,
161167 ...newVariable ,
@@ -167,17 +173,18 @@ class Graph {
167173 }
168174
169175 if ( this . #checkTimeout( ) ) {
176+ this . logger . add ( LogLevel . ERROR , `Timeout of ${ this . timeout } ms exceeded, stopping graph run` , node ) ;
170177 throw `Timeout of ${ this . timeout } ms exceeded, stopping graph run` ;
171178 }
172179 } catch ( err ) {
173- this . logs . push ( `Flow failed at: ${ JSON . stringify ( node ) } due to ${ err } ` ) ;
180+ this . logger . add ( LogLevel . ERROR , `Flow failed due to ${ err } ` , node ) ;
174181 return {
175182 status : 'Failed' ,
176183 } ;
177184 }
178185
179186 if ( result === undefined ) {
180- this . logs . push ( ` Flow failed at: ${ JSON . stringify ( node ) } ` ) ;
187+ this . logger . add ( LogLevel . ERROR , ' Flow failed due to failure to evaluate result' , node ) ;
181188 return {
182189 status : 'Failed' ,
183190 } ;
@@ -208,11 +215,11 @@ class Graph {
208215 } ) ;
209216 this . graphRunNodeOutput = { } ;
210217
211- this . logs . push ( 'Start Flowtest' ) ;
218+ this . logger . add ( LogLevel . INFO , 'Start Flowtest' ) ;
212219 const startNode = this . nodes . find ( ( node ) => node . type === 'startNode' ) ;
213220 if ( startNode == undefined ) {
214- this . logs . push ( 'No start node found' ) ;
215- this . logs . push ( 'End Flowtest' ) ;
221+ this . logger . add ( LogLevel . INFO , 'No start node found' ) ;
222+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
216223 return {
217224 status : 'Success' ,
218225 logs : this . logs ,
@@ -228,18 +235,14 @@ class Graph {
228235 // if (result.status == 'Failed') {
229236 // console.debug('Flow failed at: ', result.node);
230237 // }
231- this . logs . push ( 'End Flowtest' ) ;
238+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
232239 return {
233240 status : result . status ,
234- logs : this . logs ,
235- envVars : this . envVariables ,
236241 } ;
237242 } else {
238- this . logs . push ( 'End Flowtest' ) ;
243+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
239244 return {
240245 status : 'Success' ,
241- logs : this . logs ,
242- envVars : this . envVariables ,
243246 } ;
244247 }
245248 }
0 commit comments