77package modelengine .fit .jober .aipp .controller ;
88
99import io .opentelemetry .api .trace .Span ;
10- import modelengine .fit .http .annotation .DeleteMapping ;
11- import modelengine .fit .http .annotation .GetMapping ;
12- import modelengine .fit .http .annotation .PatchMapping ;
13- import modelengine .fit .http .annotation .PathVariable ;
14- import modelengine .fit .http .annotation .PostMapping ;
15- import modelengine .fit .http .annotation .PutMapping ;
16- import modelengine .fit .http .annotation .RequestBean ;
17- import modelengine .fit .http .annotation .RequestBody ;
18- import modelengine .fit .http .annotation .RequestMapping ;
19- import modelengine .fit .http .annotation .RequestParam ;
10+ import modelengine .fit .http .annotation .*;
2011import modelengine .fit .http .entity .PartitionedEntity ;
2112import modelengine .fit .http .server .HttpClassicServerRequest ;
2213import modelengine .fit .jane .common .controller .AbstractController ;
2718import modelengine .fit .jober .aipp .common .exception .AippException ;
2819import modelengine .fit .jober .aipp .common .exception .AippParamException ;
2920import modelengine .fit .jober .aipp .common .exception .AippTaskNotFoundException ;
30- import modelengine .fit .jober .aipp .dto .AippCreateDto ;
31- import modelengine .fit .jober .aipp .dto .AppBuilderAppDto ;
32- import modelengine .fit .jober .aipp .dto .AppBuilderPromptCategoryDto ;
33- import modelengine .fit .jober .aipp .dto .AppBuilderPromptDto ;
34- import modelengine .fit .jober .aipp .dto .FileRspDto ;
35- import modelengine .fit .jober .aipp .dto .ResumeAippDto ;
21+ import modelengine .fit .jober .aipp .constants .AippConst ;
22+ import modelengine .fit .jober .aipp .dto .*;
3623import modelengine .fit .jober .aipp .dto .aipplog .AippInstLogDataDto ;
3724import modelengine .fit .jober .aipp .dto .chat .CreateAppChatRequest ;
3825import modelengine .fit .jober .aipp .dto .chat .QueryChatRequest ;
3926import modelengine .fit .jober .aipp .dto .chat .QueryChatRspDto ;
4027import modelengine .fit .jober .aipp .genericable .AppBuilderAppService ;
41- import modelengine .fit .jober .aipp .service .AippChatService ;
42- import modelengine .fit .jober .aipp .service .AippLogService ;
43- import modelengine .fit .jober .aipp .service .AippRunTimeService ;
44- import modelengine .fit .jober .aipp .service .AppBuilderPromptService ;
45- import modelengine .fit .jober .aipp .service .AppChatService ;
46- import modelengine .fit .jober .aipp .service .FileService ;
28+ import modelengine .fit .jober .aipp .service .*;
4729import modelengine .fit .jober .aipp .util .AippFileUtils ;
4830import modelengine .fit .jober .aipp .util .ConvertUtils ;
31+ import modelengine .fit .jober .aipp .validation .GuestValidator ;
4932import modelengine .fit .jober .common .RangedResultSet ;
5033import modelengine .fitframework .annotation .Component ;
5134import modelengine .fitframework .annotation .Property ;
@@ -84,6 +67,7 @@ public class AppBuilderGuestController extends AbstractController {
8467 private final AppBuilderRecommendService recommendService ;
8568 private final FileService fileService ;
8669 private final AippChatService aippChatService ;
70+ private final GuestValidator guestValidator ;
8771
8872 /**
8973 * 用限校验认的证器对象 {@link Authenticator}, 应用通用服务 {@link AppBuilderAppService},对话服务 {@link AppChatService},实例历史记录服务
@@ -102,12 +86,13 @@ public class AppBuilderGuestController extends AbstractController {
10286 * @param recommendService 表示猜你想问服务的 {@link AppBuilderRecommendService}。
10387 * @param fileService 表示文件服务的 {@link FileService}。
10488 * @param aippChatService 表示应用聊天服务的 {@link AippChatService}。
89+ * @param guestValidator 表示游客模式的校验器的 {@link GuestValidator}。
10590 */
10691 public AppBuilderGuestController (Authenticator authenticator , AppBuilderAppService appGenericable ,
10792 AppChatService appChatService , AippLogService aippLogService ,
10893 AppBuilderPromptService appBuilderPromptService , AippRunTimeService aippRunTimeService ,
10994 UserFeedbackService userFeedbackService , AppBuilderRecommendService recommendService , FileService fileService ,
110- AippChatService aippChatService ) {
95+ AippChatService aippChatService , GuestValidator guestValidator ) {
11196 super (authenticator );
11297 this .appGenericable = appGenericable ;
11398 this .appChatService = appChatService ;
@@ -118,6 +103,7 @@ public AppBuilderGuestController(Authenticator authenticator, AppBuilderAppServi
118103 this .recommendService = recommendService ;
119104 this .fileService = fileService ;
120105 this .aippChatService = aippChatService ;
106+ this .guestValidator = guestValidator ;
121107 }
122108
123109 /**
@@ -158,6 +144,8 @@ public Rsp<AppBuilderAppDto> queryByPath(HttpClassicServerRequest httpRequest, @
158144 public Choir <Object > chat (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
159145 @ RequestBody CreateAppChatRequest body ) throws AippTaskNotFoundException {
160146 this .validateChat (httpRequest , body );
147+ this .guestValidator .validateByAppId (body .getAppId ());
148+ body .getContext ().setGuest (true );
161149 return this .appChatService .chat (body , this .contextOf (httpRequest , tenantId ), false );
162150 }
163151
@@ -175,6 +163,7 @@ public Choir<Object> chat(HttpClassicServerRequest httpRequest, @PathVariable("t
175163 public Rsp <List <AippInstLogDataDto >> queryChatRecentChatLog (HttpClassicServerRequest httpRequest ,
176164 @ PathVariable ("tenant_id" ) String tenantId , @ PathVariable ("app_id" ) String appId ,
177165 @ PathVariable ("chat_id" ) String chatId ) {
166+ this .guestValidator .validateByAppId (appId );
178167 return Rsp .ok (this .aippLogService .queryChatRecentChatLog (chatId , appId , this .contextOf (httpRequest , tenantId )));
179168 }
180169
@@ -189,6 +178,7 @@ public Rsp<List<AippInstLogDataDto>> queryChatRecentChatLog(HttpClassicServerReq
189178 @ GetMapping (path = "/{tenant_id}/app/{app_id}/latest_published" , description = "获取 app 最新发布版本信息" )
190179 public Rsp <AippCreateDto > latestPublished (HttpClassicServerRequest httpRequest ,
191180 @ PathVariable ("tenant_id" ) String tenantId , @ PathVariable ("app_id" ) String appId ) {
181+ this .guestValidator .validateByAppId (appId );
192182 return Rsp .ok (ConvertUtils .toAippCreateDto (this .appGenericable .queryLatestPublished (appId ,
193183 this .contextOf (httpRequest , tenantId ))));
194184 }
@@ -204,6 +194,7 @@ public Rsp<AippCreateDto> latestPublished(HttpClassicServerRequest httpRequest,
204194 @ GetMapping (value = "/{tenant_id}/{app_id}" , description = "查询 app " )
205195 public Rsp <AppBuilderAppDto > query (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
206196 @ PathVariable ("app_id" ) String appId ) {
197+ this .guestValidator .validateByAppId (appId );
207198 return Rsp .ok (this .appGenericable .query (appId , this .contextOf (httpRequest , tenantId )));
208199 }
209200
@@ -220,6 +211,7 @@ public Rsp<AppBuilderAppDto> query(HttpClassicServerRequest httpRequest, @PathVa
220211 public Rsp <List <AppBuilderPromptCategoryDto >> listCategories (HttpClassicServerRequest httpRequest ,
221212 @ PathVariable ("tenant_id" ) String tenantId , @ PathVariable ("app_id" ) String appId ,
222213 @ RequestParam (value = "isDebug" , defaultValue = "true" , required = false ) boolean isDebug ) {
214+ this .guestValidator .validateByAppId (appId );
223215 return this .appBuilderPromptService .listPromptCategories (appId , this .contextOf (httpRequest , tenantId ), isDebug );
224216 }
225217
@@ -238,6 +230,7 @@ public Rsp<AppBuilderPromptDto> queryInspirations(HttpClassicServerRequest httpR
238230 @ PathVariable ("tenant_id" ) String tenantId , @ PathVariable ("app_id" ) String appId ,
239231 @ PathVariable ("category_id" ) String categoryId ,
240232 @ RequestParam (value = "isDebug" , defaultValue = "true" , required = false ) boolean isDebug ) {
233+ this .guestValidator .validateByAppId (appId );
241234 return this .appBuilderPromptService .queryInspirations (appId ,
242235 categoryId ,
243236 this .contextOf (httpRequest , tenantId ),
@@ -259,6 +252,7 @@ public Rsp<AppBuilderPromptDto> queryInspirations(HttpClassicServerRequest httpR
259252 public Rsp <Void > addMyInspiration (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
260253 @ PathVariable ("parent_id" ) String parentId , @ SpanAttr ("app_id" ) @ PathVariable ("app_id" ) String appId ,
261254 @ RequestBody AppBuilderPromptDto .AppBuilderInspirationDto inspirationDto ) {
255+ this .guestValidator .validateByAppId (appId );
262256 this .appBuilderPromptService .addCustomInspiration (appId ,
263257 parentId ,
264258 inspirationDto ,
@@ -284,6 +278,7 @@ public Rsp<Void> updateMyInspiration(HttpClassicServerRequest httpRequest,
284278 @ SpanAttr ("app_id" ) @ PathVariable ("app_id" ) String appId ,
285279 @ SpanAttr ("inspiration_id" ) @ PathVariable ("inspiration_id" ) String inspirationId ,
286280 @ RequestBody AppBuilderPromptDto .AppBuilderInspirationDto inspirationDto ) {
281+ this .guestValidator .validateByAppId (appId );
287282 this .appBuilderPromptService .updateCustomInspiration (appId ,
288283 categoryId ,
289284 inspirationId ,
@@ -308,6 +303,7 @@ public Rsp<Void> deleteMyInspiration(HttpClassicServerRequest httpRequest,
308303 @ PathVariable ("tenant_id" ) String tenantId , @ PathVariable ("category_id" ) String categoryId ,
309304 @ SpanAttr ("app_id" ) @ PathVariable ("app_id" ) String appId ,
310305 @ SpanAttr ("inspiration_id" ) @ PathVariable ("inspiration_id" ) String inspirationId ) {
306+ this .guestValidator .validateByAppId (appId );
311307 this .appBuilderPromptService .deleteCustomInspiration (appId ,
312308 categoryId ,
313309 inspirationId ,
@@ -330,6 +326,7 @@ public Rsp<String> terminateAippInstance(HttpClassicServerRequest httpRequest,
330326 @ PathVariable ("tenant_id" ) String tenantId ,
331327 @ PathVariable ("instance_id" ) @ SpanAttr ("instance_id" ) String instanceId ,
332328 @ RequestBody Map <String , Object > msgArgs ) {
329+ this .guestValidator .validateByInstanceId (instanceId );
333330 return Rsp .ok (this .aippRunTimeService .terminateInstance (instanceId ,
334331 msgArgs ,
335332 this .contextOf (httpRequest , tenantId )));
@@ -352,6 +349,7 @@ public Rsp<String> terminateAippInstance(HttpClassicServerRequest httpRequest,
352349 @ PathVariable ("tenant_id" ) String tenantId ,
353350 @ PathVariable ("instance_id" ) @ SpanAttr ("instance_id" ) String instanceId ,
354351 @ RequestBody Map <String , Object > msgArgs , @ PathVariable ("log_id" ) Long logId ) {
352+ this .guestValidator .validateByInstanceId (instanceId );
355353 return Rsp .ok (this .aippRunTimeService .terminateInstance (instanceId ,
356354 msgArgs ,
357355 logId ,
@@ -366,7 +364,8 @@ public Rsp<String> terminateAippInstance(HttpClassicServerRequest httpRequest,
366364 */
367365 @ CarverSpan (value = "operation.aippLog.deleteHistory" )
368366 @ DeleteMapping (path = "/{app_id}/log/logs" , description = "删除指定的应用对话记录" )
369- public Rsp <Void > deleteLogs (@ RequestBody List <Long > logIds ) {
367+ public Rsp <Void > deleteLogs (@ RequestBody List <Long > logIds , @ PathVariable ("app_id" ) String appId ) {
368+ this .guestValidator .validateByAppId (appId );
370369 Span .current ().setAttribute ("logIds" , logIds .toString ());
371370 this .aippLogService .deleteLogs (logIds );
372371 return Rsp .ok ();
@@ -391,6 +390,7 @@ public void createUserFeedback(@RequestBody UserFeedbackDto userFeedbackDto) {
391390 @ PatchMapping ("/feedback/{instanceId}" )
392391 public void updateUserFeedback (@ PathVariable ("instanceId" ) String instanceId ,
393392 @ RequestBody UserFeedbackDto userFeedbackDto ) {
393+ this .guestValidator .validateByInstanceId (instanceId );
394394 this .userFeedbackService .updateOne (instanceId , userFeedbackDto );
395395 }
396396
@@ -401,6 +401,7 @@ public void updateUserFeedback(@PathVariable("instanceId") String instanceId,
401401 */
402402 @ DeleteMapping ("/feedback/{instanceId}" )
403403 public void deleteByLogId (@ PathVariable ("instanceId" ) String instanceId ) {
404+ this .guestValidator .validateByInstanceId (instanceId );
404405 this .userFeedbackService .deleteByLogId (instanceId );
405406 }
406407
@@ -422,6 +423,7 @@ public List<UserFeedbackDto> getAllUserFeedbacks() {
422423 */
423424 @ GetMapping ("/feedback/{instanceId}" )
424425 public UserFeedbackDto getAllAnswerByInstanceId (@ PathVariable ("instanceId" ) String instanceId ) {
426+ this .guestValidator .validateByInstanceId (instanceId );
425427 return this .userFeedbackService .getUserFeedbackByInstanceId (instanceId );
426428 }
427429
@@ -440,6 +442,8 @@ public UserFeedbackDto getAllAnswerByInstanceId(@PathVariable("instanceId") Stri
440442 public Choir <Object > restartChat (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
441443 @ PathVariable ("current_instance_id" ) @ SpanAttr ("current_instance_id" ) String currentInstanceId ,
442444 @ RequestBody Map <String , Object > additionalContext ) {
445+ this .guestValidator .validateByInstanceId (currentInstanceId );
446+ additionalContext .put (AippConst .CONTEXT_IS_GUEST , true );
443447 return this .appChatService .restartChat (currentInstanceId ,
444448 additionalContext ,
445449 this .contextOf (httpRequest , tenantId ));
@@ -472,6 +476,7 @@ public Rsp<List<String>> queryRecommends(HttpClassicServerRequest request,
472476 public Rsp <List <FileRspDto >> batchUploadFile (HttpClassicServerRequest httpRequest ,
473477 @ PathVariable ("tenant_id" ) String tenantId , @ RequestParam (value = "app_id" , required = false ) String appId ,
474478 PartitionedEntity receivedFiles ) {
479+ this .guestValidator .validateByAppId (appId );
475480 OperationContext context = this .contextOf (httpRequest , tenantId );
476481 List <FileRspDto > fileRspDtos = AippFileUtils .getFileEntity (receivedFiles ).stream ().map (fileEntity -> {
477482 try {
@@ -497,6 +502,7 @@ public Rsp<List<FileRspDto>> batchUploadFile(HttpClassicServerRequest httpReques
497502 public Rsp <Void > deleteChat (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
498503 @ RequestParam (value = "app_id" , required = false ) String appId ,
499504 @ RequestBody (value = "chat_id" , required = false ) @ SpanAttr ("chat_id" ) String chatIds ) {
505+ this .guestValidator .validateByAppId (appId );
500506 this .aippChatService .deleteChat (chatIds , appId , this .contextOf (httpRequest , tenantId ));
501507 return Rsp .ok ();
502508 }
@@ -534,11 +540,12 @@ public Choir<Object> resumeAndUpdateAippInstance(HttpClassicServerRequest httpRe
534540 @ RequestBean ResumeAippDto resumeAippDto ,
535541 @ Property (description = "用户填写的表单信息" , example = "用户选择的大模型信息" ) @ RequestBody
536542 Map <String , Object > formArgs ) {
543+ this .guestValidator .validateByInstanceId (resumeAippDto .getInstanceId ());
537544 return this .aippRunTimeService .resumeAndUpdateAippInstance (resumeAippDto .getInstanceId (),
538545 formArgs ,
539546 resumeAippDto .getLogId (),
540547 this .contextOf (httpRequest , resumeAippDto .getTenantId ()),
541- resumeAippDto .isDebug ());
548+ resumeAippDto .isDebug (), true );
542549 }
543550
544551 /**
@@ -554,6 +561,7 @@ public Choir<Object> resumeAndUpdateAippInstance(HttpClassicServerRequest httpRe
554561 @ DeleteMapping (path = "/{tenant_id}/log/app/{app_id}" , description = "清除appId查询实例的全部历史记录" )
555562 public Rsp <Void > deleteInstanceLog (HttpClassicServerRequest httpRequest , @ PathVariable ("tenant_id" ) String tenantId ,
556563 @ PathVariable ("app_id" ) @ SpanAttr ("app_id" ) String appId , @ RequestParam ("type" ) String type ) {
564+ this .guestValidator .validateByAppId (appId );
557565 this .aippLogService .deleteAippInstLog (appId , type , this .contextOf (httpRequest , tenantId ));
558566 return Rsp .ok ();
559567 }
0 commit comments