2025-08-25 09:26:54 +08:00
|
|
|
from flask_restx import Resource
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
from controllers.common.fields import build_parameters_model
|
|
|
|
|
from controllers.service_api import service_api_ns
|
2024-04-08 18:51:46 +08:00
|
|
|
from controllers.service_api.app.error import AppUnavailableError
|
2024-02-28 16:09:56 +08:00
|
|
|
from controllers.service_api.wraps import validate_app_token
|
2025-04-16 20:27:29 +08:00
|
|
|
from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dict
|
2024-04-10 22:34:43 +08:00
|
|
|
from models.model import App, AppMode
|
2024-04-08 18:51:46 +08:00
|
|
|
from services.app_service import AppService
|
2024-01-23 19:58:23 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.route("/parameters")
|
2024-02-28 16:09:56 +08:00
|
|
|
class AppParameterApi(Resource):
|
2023-05-15 08:51:32 +08:00
|
|
|
"""Resource for app variables."""
|
|
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.doc("get_app_parameters")
|
|
|
|
|
@service_api_ns.doc(description="Retrieve application input parameters and configuration")
|
|
|
|
|
@service_api_ns.doc(
|
|
|
|
|
responses={
|
|
|
|
|
200: "Parameters retrieved successfully",
|
|
|
|
|
401: "Unauthorized - invalid API token",
|
|
|
|
|
404: "Application not found",
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-02-28 16:09:56 +08:00
|
|
|
@validate_app_token
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.marshal_with(build_parameters_model(service_api_ns))
|
2024-02-28 16:09:56 +08:00
|
|
|
def get(self, app_model: App):
|
2025-08-25 09:26:54 +08:00
|
|
|
"""Retrieve app parameters.
|
|
|
|
|
|
|
|
|
|
Returns the input form parameters and configuration for the application.
|
|
|
|
|
"""
|
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-15 08:51:32 +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-15 08:51:32 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.route("/meta")
|
2024-02-28 16:09:56 +08:00
|
|
|
class AppMetaApi(Resource):
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.doc("get_app_meta")
|
|
|
|
|
@service_api_ns.doc(description="Get application metadata")
|
|
|
|
|
@service_api_ns.doc(
|
|
|
|
|
responses={
|
|
|
|
|
200: "Metadata retrieved successfully",
|
|
|
|
|
401: "Unauthorized - invalid API token",
|
|
|
|
|
404: "Application not found",
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-02-28 16:09:56 +08:00
|
|
|
@validate_app_token
|
|
|
|
|
def get(self, app_model: App):
|
2025-08-25 09:26:54 +08:00
|
|
|
"""Get app metadata.
|
|
|
|
|
|
|
|
|
|
Returns metadata about the application including configuration and settings.
|
|
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
return AppService().get_app_meta(app_model)
|
2024-01-23 19:58:23 +08:00
|
|
|
|
2024-08-26 15:29:10 +08:00
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.route("/info")
|
2024-04-10 22:34:43 +08:00
|
|
|
class AppInfoApi(Resource):
|
2025-08-25 09:26:54 +08:00
|
|
|
@service_api_ns.doc("get_app_info")
|
|
|
|
|
@service_api_ns.doc(description="Get basic application information")
|
|
|
|
|
@service_api_ns.doc(
|
|
|
|
|
responses={
|
|
|
|
|
200: "Application info retrieved successfully",
|
|
|
|
|
401: "Unauthorized - invalid API token",
|
|
|
|
|
404: "Application not found",
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-04-10 22:34:43 +08:00
|
|
|
@validate_app_token
|
|
|
|
|
def get(self, app_model: App):
|
2025-08-25 09:26:54 +08:00
|
|
|
"""Get app information.
|
|
|
|
|
|
|
|
|
|
Returns basic information about the application including name, description, tags, and mode.
|
|
|
|
|
"""
|
2024-12-02 11:25:01 +09:00
|
|
|
tags = [tag.name for tag in app_model.tags]
|
2025-06-13 16:17:35 +08:00
|
|
|
return {
|
|
|
|
|
"name": app_model.name,
|
|
|
|
|
"description": app_model.description,
|
|
|
|
|
"tags": tags,
|
|
|
|
|
"mode": app_model.mode,
|
|
|
|
|
"author_name": app_model.author_name,
|
|
|
|
|
}
|