@@ -252,15 +252,6 @@ def _node_finished(cpn_obj):
252
252
"created_at" : cpn_obj .output ("_created_time" ),
253
253
})
254
254
255
- def _append_path (cpn_id ):
256
- if self .path [- 1 ] == cpn_id :
257
- return
258
- self .path .append (cpn_id )
259
-
260
- def _extend_path (cpn_ids ):
261
- for cpn_id in cpn_ids :
262
- _append_path (cpn_id )
263
-
264
255
self .error = ""
265
256
idx = len (self .path ) - 1
266
257
partials = []
@@ -279,10 +270,11 @@ def _extend_path(cpn_ids):
279
270
# post processing of components invocation
280
271
for i in range (idx , to ):
281
272
cpn = self .get_component (self .path [i ])
282
- if cpn ["obj" ].component_name .lower () == "message" :
283
- if isinstance (cpn ["obj" ].output ("content" ), partial ):
273
+ cpn_obj = self .get_component_obj (self .path [i ])
274
+ if cpn_obj .component_name .lower () == "message" :
275
+ if isinstance (cpn_obj .output ("content" ), partial ):
284
276
_m = ""
285
- for m in cpn [ "obj" ] .output ("content" )():
277
+ for m in cpn_obj .output ("content" )():
286
278
if not m :
287
279
continue
288
280
if m == "<think>" :
@@ -292,48 +284,65 @@ def _extend_path(cpn_ids):
292
284
else :
293
285
yield decorate ("message" , {"content" : m })
294
286
_m += m
295
- cpn [ "obj" ] .set_output ("content" , _m )
287
+ cpn_obj .set_output ("content" , _m )
296
288
else :
297
- yield decorate ("message" , {"content" : cpn [ "obj" ] .output ("content" )})
289
+ yield decorate ("message" , {"content" : cpn_obj .output ("content" )})
298
290
yield decorate ("message_end" , {"reference" : self .get_reference ()})
299
291
300
292
while partials :
301
- _cpn = self .get_component (partials [0 ])
302
- if isinstance (_cpn [ "obj" ] .output ("content" ), partial ):
293
+ _cpn_obj = self .get_component_obj (partials [0 ])
294
+ if isinstance (_cpn_obj .output ("content" ), partial ):
303
295
break
304
- yield _node_finished (_cpn [ "obj" ] )
296
+ yield _node_finished (_cpn_obj )
305
297
partials .pop (0 )
306
298
307
- if cpn ["obj" ].error ():
308
- ex = cpn ["obj" ].exception_handler ()
309
- if ex and ex ["comment" ]:
310
- yield decorate ("message" , {"content" : ex ["comment" ]})
311
- yield decorate ("message_end" , {})
299
+ other_branch = False
300
+ if cpn_obj .error ():
301
+ ex = cpn_obj .exception_handler ()
312
302
if ex and ex ["goto" ]:
313
- self .path .append (ex ["goto" ])
314
- elif not ex or not ex ["default_value" ]:
315
- self .error = cpn ["obj" ].error ()
303
+ self .path .extend (ex ["goto" ])
304
+ other_branch = True
305
+ elif ex and ex ["default_value" ]:
306
+ yield decorate ("message" , {"content" : ex ["default_value" ]})
307
+ yield decorate ("message_end" , {})
308
+ else :
309
+ self .error = cpn_obj .error ()
316
310
317
- if cpn [ "obj" ] .component_name .lower () != "iteration" :
318
- if isinstance (cpn [ "obj" ] .output ("content" ), partial ):
311
+ if cpn_obj .component_name .lower () != "iteration" :
312
+ if isinstance (cpn_obj .output ("content" ), partial ):
319
313
if self .error :
320
- cpn [ "obj" ] .set_output ("content" , None )
321
- yield _node_finished (cpn [ "obj" ] )
314
+ cpn_obj .set_output ("content" , None )
315
+ yield _node_finished (cpn_obj )
322
316
else :
323
317
partials .append (self .path [i ])
324
318
else :
325
- yield _node_finished (cpn ["obj" ])
326
-
327
- if cpn ["obj" ].component_name .lower () == "iterationitem" and cpn ["obj" ].end ():
328
- iter = cpn ["obj" ].get_parent ()
319
+ yield _node_finished (cpn_obj )
320
+
321
+ def _append_path (cpn_id ):
322
+ nonlocal other_branch
323
+ if other_branch :
324
+ return
325
+ if self .path [- 1 ] == cpn_id :
326
+ return
327
+ self .path .append (cpn_id )
328
+
329
+ def _extend_path (cpn_ids ):
330
+ nonlocal other_branch
331
+ if other_branch :
332
+ return
333
+ for cpn_id in cpn_ids :
334
+ _append_path (cpn_id )
335
+
336
+ if cpn_obj .component_name .lower () == "iterationitem" and cpn_obj .end ():
337
+ iter = cpn_obj .get_parent ()
329
338
yield _node_finished (iter )
330
339
_extend_path (self .get_component (cpn ["parent_id" ])["downstream" ])
331
- elif cpn [ "obj" ] .component_name .lower () in ["categorize" , "switch" ]:
332
- _extend_path (cpn [ "obj" ] .output ("_next" ))
333
- elif cpn [ "obj" ] .component_name .lower () == "iteration" :
334
- _append_path (cpn [ "obj" ] .get_start ())
335
- elif not cpn ["downstream" ] and cpn [ "obj" ] .get_parent ():
336
- _append_path (cpn [ "obj" ] .get_parent ().get_start ())
340
+ elif cpn_obj .component_name .lower () in ["categorize" , "switch" ]:
341
+ _extend_path (cpn_obj .output ("_next" ))
342
+ elif cpn_obj .component_name .lower () == "iteration" :
343
+ _append_path (cpn_obj .get_start ())
344
+ elif not cpn ["downstream" ] and cpn_obj .get_parent ():
345
+ _append_path (cpn_obj .get_parent ().get_start ())
337
346
else :
338
347
_extend_path (cpn ["downstream" ])
339
348
@@ -342,13 +351,13 @@ def _extend_path(cpn_ids):
342
351
break
343
352
idx = to
344
353
345
- if any ([self .get_component (c )[ "obj" ] .component_name .lower () == "userfillup" for c in self .path [idx :]]):
354
+ if any ([self .get_component_obj (c ).component_name .lower () == "userfillup" for c in self .path [idx :]]):
346
355
path = [c for c in self .path [idx :] if self .get_component (c )["obj" ].component_name .lower () == "userfillup" ]
347
356
path .extend ([c for c in self .path [idx :] if self .get_component (c )["obj" ].component_name .lower () != "userfillup" ])
348
357
another_inputs = {}
349
358
tips = ""
350
359
for c in path :
351
- o = self .get_component (c )[ "obj" ]
360
+ o = self .get_component_obj (c )
352
361
if o .component_name .lower () == "userfillup" :
353
362
another_inputs .update (o .get_input_elements ())
354
363
if o .get_param ("enable_tips" ):
0 commit comments