| 
									
										
										
										
											2025-05-06 11:58:49 +08:00
										 |  |  | from flask_restful import marshal_with | 
					
						
							| 
									
										
										
										
											2024-02-06 13:21:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-04 15:55:34 +08:00
										 |  |  | from controllers.common import fields | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | from controllers.console import api | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | from controllers.console.app.error import AppUnavailableError | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | from controllers.console.explore.wraps import InstalledAppResource | 
					
						
							| 
									
										
										
										
											2025-04-16 20:27:29 +08:00
										 |  |  | from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dict | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | from models.model import AppMode, InstalledApp | 
					
						
							|  |  |  | from services.app_service import AppService | 
					
						
							| 
									
										
										
										
											2023-07-27 13:08:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class AppParameterApi(InstalledAppResource): | 
					
						
							|  |  |  |     """Resource for app variables.""" | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-04 15:55:34 +08:00
										 |  |  |     @marshal_with(fields.parameters_fields) | 
					
						
							| 
									
										
										
										
											2023-07-27 13:08:57 +08:00
										 |  |  |     def get(self, installed_app: InstalledApp): | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  |         """Retrieve app parameters.""" | 
					
						
							|  |  |  |         app_model = installed_app.app | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-04 15:55:34 +08:00
										 |  |  |         if app_model is None: | 
					
						
							|  |  |  |             raise AppUnavailableError() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-13 22:42:08 +08:00
										 |  |  |         if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}: | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             workflow = app_model.workflow | 
					
						
							|  |  |  |             if workflow is None: | 
					
						
							|  |  |  |                 raise AppUnavailableError() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             features_dict = workflow.features_dict | 
					
						
							|  |  |  |             user_input_form = workflow.user_input_form(to_old_structure=True) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             app_model_config = app_model.app_model_config | 
					
						
							| 
									
										
										
										
											2024-11-04 15:55:34 +08:00
										 |  |  |             if app_model_config is None: | 
					
						
							|  |  |  |                 raise AppUnavailableError() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             features_dict = app_model_config.to_dict() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  |             user_input_form = features_dict.get("user_input_form", []) | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 20:27:29 +08:00
										 |  |  |         return get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form) | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:58:23 +08:00
										 |  |  | class ExploreAppMetaApi(InstalledAppResource): | 
					
						
							|  |  |  |     def get(self, installed_app: InstalledApp): | 
					
						
							|  |  |  |         """Get app meta""" | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         app_model = installed_app.app | 
					
						
							|  |  |  |         return AppService().get_app_meta(app_model) | 
					
						
							| 
									
										
										
										
											2024-01-23 19:58:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 15:54:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 15:29:10 +08:00
										 |  |  | api.add_resource( | 
					
						
							|  |  |  |     AppParameterApi, "/installed-apps/<uuid:installed_app_id>/parameters", endpoint="installed_app_parameters" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | api.add_resource(ExploreAppMetaApi, "/installed-apps/<uuid:installed_app_id>/meta", endpoint="installed_app_meta") |