2828import static modelengine .fit .jober .aipp .util .UsefulUtils .doIfNull ;
2929import static modelengine .fitframework .util .ObjectUtils .cast ;
3030
31+ import com .alibaba .fastjson .JSON ;
32+
3133import lombok .Getter ;
3234import modelengine .fel .tool .service .ToolService ;
3335import modelengine .fit .jade .aipp .model .dto .ModelAccessInfo ;
8082import modelengine .fit .jober .aipp .dto .export .AppExportFlowGraph ;
8183import modelengine .fit .jober .aipp .dto .template .TemplateAppCreateDto ;
8284import modelengine .fit .jober .aipp .dto .template .TemplateInfoDto ;
85+ import modelengine .fit .jober .aipp .entity .AippInstLog ;
8386import modelengine .fit .jober .aipp .entity .ChatSession ;
8487import modelengine .fit .jober .aipp .enums .AippMetaStatusEnum ;
8588import modelengine .fit .jober .aipp .enums .AippTypeEnum ;
@@ -578,6 +581,10 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,
578581 OperationContext context , Consumer <RunContext > onFinished ) {
579582 List <AppLog > instanceLogs = instance .getLogs ();
580583 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+ }
581588
582589 // 合并参数.
583590 AppLog appLog = instanceLogs .iterator ().next ();
@@ -586,21 +593,37 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,
586593
587594 RunContext runContext = new RunContext (new HashMap <>(), context );
588595 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 ());
591600 runContext .setUserContext (mergedRestartParams );
592601 runContext .putAllToBusiness (mergedRestartParams );
593- runContext .setQuestion (appLog .getLogData (). getQuestion ( ));
602+ runContext .setQuestion (this . getQuestion ( appLog .getLogData ()));
594603 if (chatList .size () == 2 ) {
595604 runContext .setAtChatId (chatList .get (1 ).getChatId ());
596605 }
597606 if (runContext .isOverWriteMode ()) {
598607 instance .overWrite ();
599608 }
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+ }
601616 onFinished .accept (runContext );
602617 }
603618
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+
604627 /**
605628 * 获取 icon.
606629 *
0 commit comments