28
28
import static modelengine .fit .jober .aipp .util .UsefulUtils .doIfNull ;
29
29
import static modelengine .fitframework .util .ObjectUtils .cast ;
30
30
31
+ import com .alibaba .fastjson .JSON ;
32
+
31
33
import lombok .Getter ;
32
34
import modelengine .fel .tool .service .ToolService ;
33
35
import modelengine .fit .jade .aipp .model .dto .ModelAccessInfo ;
80
82
import modelengine .fit .jober .aipp .dto .export .AppExportFlowGraph ;
81
83
import modelengine .fit .jober .aipp .dto .template .TemplateAppCreateDto ;
82
84
import modelengine .fit .jober .aipp .dto .template .TemplateInfoDto ;
85
+ import modelengine .fit .jober .aipp .entity .AippInstLog ;
83
86
import modelengine .fit .jober .aipp .entity .ChatSession ;
84
87
import modelengine .fit .jober .aipp .enums .AippMetaStatusEnum ;
85
88
import modelengine .fit .jober .aipp .enums .AippTypeEnum ;
@@ -578,6 +581,10 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,
578
581
OperationContext context , Consumer <RunContext > onFinished ) {
579
582
List <AppLog > instanceLogs = instance .getLogs ();
580
583
List <QueryChatRsp > chatList = instance .getChats ();
584
+ if (CollectionUtils .isEmpty (chatList )) {
585
+ LOGGER .error ("ChatList is empty. [InstanceId={}]" , instance .getId ());
586
+ throw new AippParamException (AippErrCode .RE_CHAT_FAILED );
587
+ }
581
588
582
589
// 合并参数.
583
590
AppLog appLog = instanceLogs .iterator ().next ();
@@ -586,21 +593,37 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,
586
593
587
594
RunContext runContext = new RunContext (new HashMap <>(), context );
588
595
runContext .setRestartMode (cast (mergedRestartParams .getOrDefault (RESTART_MODE , OVERWRITE .getMode ())));
589
- runContext .setAppId (chatList .get (0 ).getAppId ());
590
- runContext .setChatId (chatList .get (0 ).getChatId ());
596
+
597
+ QueryChatRsp mostRecentRsp = chatList .get (0 );
598
+ runContext .setAppId (mostRecentRsp .getAppId ());
599
+ runContext .setChatId (mostRecentRsp .getChatId ());
591
600
runContext .setUserContext (mergedRestartParams );
592
601
runContext .putAllToBusiness (mergedRestartParams );
593
- runContext .setQuestion (appLog .getLogData (). getQuestion ( ));
602
+ runContext .setQuestion (this . getQuestion ( appLog .getLogData ()));
594
603
if (chatList .size () == 2 ) {
595
604
runContext .setAtChatId (chatList .get (1 ).getChatId ());
596
605
}
597
606
if (runContext .isOverWriteMode ()) {
598
607
instance .overWrite ();
599
608
}
600
- this .run (runContext , session );
609
+ boolean isDebug =
610
+ StringUtils .equals (AppState .INACTIVE .getName (), this .getState (mostRecentRsp .getAttributes ()));
611
+ if (isDebug ) {
612
+ this .debug (runContext , session );
613
+ } else {
614
+ this .run (runContext , session );
615
+ }
601
616
onFinished .accept (runContext );
602
617
}
603
618
619
+ private String getState (String attributes ) {
620
+ return ObjectUtils .cast (JsonUtils .parseObject (attributes ).get (AippConst .ATTR_CHAT_STATE_KEY ));
621
+ }
622
+
623
+ private String getQuestion (AippInstLog instLog ) {
624
+ return JSON .parseObject (instLog .getLogData ()).getString ("msg" );
625
+ }
626
+
604
627
/**
605
628
* 获取 icon.
606
629
*
0 commit comments