2026-03-06 01:42:54 +02:00
|
|
|
from typing import Any, cast
|
|
|
|
|
|
2026-06-12 22:25:53 +08:00
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
2024-11-04 15:55:34 +08:00
|
|
|
from controllers.common import fields
|
2026-06-12 22:25:53 +08:00
|
|
|
from controllers.common.schema import register_response_schema_models
|
2025-10-10 17:23:39 +09:00
|
|
|
from controllers.console import console_ns
|
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
|
2026-07-08 12:07:27 +09:00
|
|
|
from extensions.ext_database import db
|
2026-07-15 14:48:28 +08:00
|
|
|
from models.model import AppMode, InstalledApp, load_annotation_reply_config
|
2024-04-08 18:51:46 +08:00
|
|
|
from services.app_service import AppService
|
2023-07-27 13:08:57 +08:00
|
|
|
|
2023-05-25 15:54:45 +08:00
|
|
|
|
2026-06-12 22:25:53 +08:00
|
|
|
class ExploreAppMetaResponse(BaseModel):
|
2026-07-02 11:32:02 +08:00
|
|
|
"""Metadata consumed by the installed-app chat UI.
|
|
|
|
|
|
|
|
|
|
Built-in tool icons are URL strings; API-based tool icons are provider-defined payload objects.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
tool_icons: dict[str, str | dict[str, Any]] = Field(default_factory=dict)
|
2026-06-12 22:25:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
register_response_schema_models(console_ns, fields.Parameters, ExploreAppMetaResponse)
|
|
|
|
|
|
|
|
|
|
|
2025-10-10 17:23:39 +09:00
|
|
|
@console_ns.route("/installed-apps/<uuid:installed_app_id>/parameters", endpoint="installed_app_parameters")
|
2023-05-25 15:54:45 +08:00
|
|
|
class AppParameterApi(InstalledAppResource):
|
|
|
|
|
"""Resource for app variables."""
|
2024-08-26 15:29:10 +08:00
|
|
|
|
2026-06-12 22:25:53 +08:00
|
|
|
@console_ns.response(200, "Success", console_ns.models[fields.Parameters.__name__])
|
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."""
|
2026-07-15 14:48:28 +08:00
|
|
|
session = db.session()
|
|
|
|
|
app_model = installed_app.app_with_session(session=session)
|
2024-04-08 18:51:46 +08:00
|
|
|
|
2024-11-04 15:55:34 +08:00
|
|
|
if app_model is None:
|
|
|
|
|
raise AppUnavailableError()
|
|
|
|
|
|
2025-09-12 21:14:26 +08:00
|
|
|
if app_model.mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:
|
2026-07-15 14:48:28 +08:00
|
|
|
workflow = app_model.workflow_with_session(session=session)
|
2024-04-08 18:51:46 +08:00
|
|
|
if workflow is None:
|
|
|
|
|
raise AppUnavailableError()
|
|
|
|
|
|
2026-03-06 01:42:54 +02:00
|
|
|
features_dict: dict[str, Any] = workflow.features_dict
|
2024-04-08 18:51:46 +08:00
|
|
|
user_input_form = workflow.user_input_form(to_old_structure=True)
|
|
|
|
|
else:
|
2026-07-15 14:48:28 +08:00
|
|
|
app_model_config = app_model.app_model_config_with_session(session=session)
|
2024-11-04 15:55:34 +08:00
|
|
|
if app_model_config is None:
|
|
|
|
|
raise AppUnavailableError()
|
|
|
|
|
|
2026-07-15 14:48:28 +08:00
|
|
|
annotation_reply = load_annotation_reply_config(session, app_model.id)
|
|
|
|
|
features_dict = cast(
|
|
|
|
|
dict[str, Any],
|
|
|
|
|
app_model_config.to_dict(annotation_reply=annotation_reply),
|
|
|
|
|
)
|
2024-04-08 18:51:46 +08:00
|
|
|
|
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
|
|
|
|
2026-01-01 01:38:12 +09:00
|
|
|
parameters = get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form)
|
|
|
|
|
return fields.Parameters.model_validate(parameters).model_dump(mode="json")
|
2023-05-25 15:54:45 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
|
2025-10-10 17:23:39 +09:00
|
|
|
@console_ns.route("/installed-apps/<uuid:installed_app_id>/meta", endpoint="installed_app_meta")
|
2024-01-23 19:58:23 +08:00
|
|
|
class ExploreAppMetaApi(InstalledAppResource):
|
2026-06-12 22:25:53 +08:00
|
|
|
@console_ns.response(200, "Success", console_ns.models[ExploreAppMetaResponse.__name__])
|
2024-01-23 19:58:23 +08:00
|
|
|
def get(self, installed_app: InstalledApp):
|
|
|
|
|
"""Get app meta"""
|
2026-07-15 14:48:28 +08:00
|
|
|
app_model = installed_app.app_with_session(session=db.session())
|
2025-09-08 09:42:27 +08:00
|
|
|
if not app_model:
|
|
|
|
|
raise ValueError("App not found")
|
2026-07-08 12:07:27 +09:00
|
|
|
return AppService().get_app_meta(app_model, session=db.session())
|