Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: fetch app info in plugins (#18202)
Yeuoly358fd28c28a2
diff --git a/api/controllers/common/helpers.py b/api/controllers/common/helpers.pyindex 282708c037f..008f1f0f7a1 100644--- a/api/controllers/common/helpers.py+++ b/api/controllers/common/helpers.py@@ -4,14 +4,10 @@ import platformimport reimport urllib.parseimport warnings-from collections.abc import Mapping-from typing import Anyfrom uuid import uuid4import httpx-from constants import DEFAULT_FILE_NUMBER_LIMITS-try:import magicexcept ImportError:@@ -31,8 +27,6 @@ except ImportError:from pydantic import BaseModel-from configs import dify_config-class FileInfo(BaseModel):filename: str@@ -89,38 +83,3 @@ def guess_file_info_from_response(response: httpx.Response):mimetype=mimetype,size=int(response.headers.get("Content-Length", -1)),)---def get_parameters_from_feature_dict(*, features_dict: Mapping[str, Any], user_input_form: list[dict[str, Any]]):- return {- "opening_statement": features_dict.get("opening_statement"),- "suggested_questions": features_dict.get("suggested_questions", []),- "suggested_questions_after_answer": features_dict.get("suggested_questions_after_answer", {"enabled": False}),- "speech_to_text": features_dict.get("speech_to_text", {"enabled": False}),- "text_to_speech": features_dict.get("text_to_speech", {"enabled": False}),- "retriever_resource": features_dict.get("retriever_resource", {"enabled": False}),- "annotation_reply": features_dict.get("annotation_reply", {"enabled": False}),- "more_like_this": features_dict.get("more_like_this", {"enabled": False}),- "user_input_form": user_input_form,- "sensitive_word_avoidance": features_dict.get(- "sensitive_word_avoidance", {"enabled": False, "type": "", "configs": []}- ),- "file_upload": features_dict.get(- "file_upload",- {- "image": {- "enabled": False,- "number_limits": DEFAULT_FILE_NUMBER_LIMITS,- "detail": "high",- "transfer_methods": ["remote_url", "local_file"],- }- },- ),- "system_parameters": {- "image_file_size_limit": dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT,- "video_file_size_limit": dify_config.UPLOAD_VIDEO_FILE_SIZE_LIMIT,- "audio_file_size_limit": dify_config.UPLOAD_AUDIO_FILE_SIZE_LIMIT,- "file_size_limit": dify_config.UPLOAD_FILE_SIZE_LIMIT,- "workflow_file_upload_limit": dify_config.WORKFLOW_FILE_UPLOAD_LIMIT,- },- }diff --git a/api/controllers/console/explore/parameter.py b/api/controllers/console/explore/parameter.pyindex 5bc74d16e78..bf9f0d6b283 100644--- a/api/controllers/console/explore/parameter.py+++ b/api/controllers/console/explore/parameter.py@@ -1,10 +1,10 @@from flask_restful import marshal_with # type: ignorefrom controllers.common import fields-from controllers.common import helpers as controller_helpersfrom controllers.console import apifrom controllers.console.app.error import AppUnavailableErrorfrom controllers.console.explore.wraps import InstalledAppResource+from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dictfrom models.model import AppMode, InstalledAppfrom services.app_service import AppService@@ -36,9 +36,7 @@ class AppParameterApi(InstalledAppResource):user_input_form = features_dict.get("user_input_form", [])- return controller_helpers.get_parameters_from_feature_dict(- features_dict=features_dict, user_input_form=user_input_form- )+ return get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form)class ExploreAppMetaApi(InstalledAppResource):diff --git a/api/controllers/inner_api/plugin/plugin.py b/api/controllers/inner_api/plugin/plugin.pyindex fe892922e98..061ad62a4a2 100644--- a/api/controllers/inner_api/plugin/plugin.py+++ b/api/controllers/inner_api/plugin/plugin.py@@ -13,6 +13,7 @@ from core.plugin.backwards_invocation.model import PluginModelBackwardsInvocatiofrom core.plugin.backwards_invocation.node import PluginNodeBackwardsInvocationfrom core.plugin.backwards_invocation.tool import PluginToolBackwardsInvocationfrom core.plugin.entities.request import (+ RequestFetchAppInfo,RequestInvokeApp,RequestInvokeEncrypt,RequestInvokeLLM,@@ -278,6 +279,17 @@ class PluginUploadFileRequestApi(Resource):return BaseBackwardsInvocationResponse(data={"url": url}).model_dump()+class PluginFetchAppInfoApi(Resource):+ @setup_required+ @plugin_inner_api_only+ @get_user_tenant+ @plugin_data(payload_type=RequestFetchAppInfo)+ def post(self, user_model: Account | EndUser, tenant_model: Tenant, payload: RequestFetchAppInfo):+ return BaseBackwardsInvocationResponse(+ data=PluginAppBackwardsInvocation.fetch_app_info(payload.app_id, tenant_model.id)+ ).model_dump()++api.add_resource(PluginInvokeLLMApi, "/invoke/llm")api.add_resource(PluginInvokeTextEmbeddingApi, "/invoke/text-embedding")api.add_resource(PluginInvokeRerankApi, "/invoke/rerank")@@ -291,3 +303,4 @@ api.add_resource(PluginInvokeAppApi, "/invoke/app")api.add_resource(PluginInvokeEncryptApi, "/invoke/encrypt")api.add_resource(PluginInvokeSummaryApi, "/invoke/summary")api.add_resource(PluginUploadFileRequestApi, "/upload/file/request")+api.add_resource(PluginFetchAppInfoApi, "/fetch/app/info")diff --git a/api/controllers/service_api/app/app.py b/api/controllers/service_api/app/app.pyindex 8388e2045dd..7131e8a3104 100644--- a/api/controllers/service_api/app/app.py+++ b/api/controllers/service_api/app/app.py@@ -1,10 +1,10 @@from flask_restful import Resource, marshal_with # type: ignorefrom controllers.common import fields-from controllers.common import helpers as controller_helpersfrom controllers.service_api import apifrom controllers.service_api.app.error import AppUnavailableErrorfrom controllers.service_api.wraps import validate_app_token+from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dictfrom models.model import App, AppModefrom services.app_service import AppService@@ -32,9 +32,7 @@ class AppParameterApi(Resource):user_input_form = features_dict.get("user_input_form", [])- return controller_helpers.get_parameters_from_feature_dict(- features_dict=features_dict, user_input_form=user_input_form- )+ return get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form)class AppMetaApi(Resource):diff --git a/api/controllers/web/app.py b/api/controllers/web/app.pyindex 20e071c834a..a84b8461127 100644--- a/api/controllers/web/app.py+++ b/api/controllers/web/app.py@@ -1,10 +1,10 @@from flask_restful import marshal_with # type: ignorefrom controllers.common import fields-from controllers.common import helpers as controller_helpersfrom controllers.web import apifrom controllers.web.error import AppUnavailableErrorfrom controllers.web.wraps import WebApiResource+from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dictfrom models.model import App, AppModefrom services.app_service import AppService@@ -31,9 +31,7 @@ class AppParameterApi(WebApiResource):user_input_form = features_dict.get("user_input_form", [])- return controller_helpers.get_parameters_from_feature_dict(- features_dict=features_dict, user_input_form=user_input_form- )+ return get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form)class AppMeta(WebApiResource):diff --git a/api/core/app/app_config/common/parameters_mapping/__init__.py b/api/core/app/app_config/common/parameters_mapping/__init__.pynew file mode 100644index 00000000000..6f1a3bf0453--- /dev/null+++ b/api/core/app/app_config/common/parameters_mapping/__init__.py@@ -0,0 +1,45 @@+from collections.abc import Mapping+from typing import Any++from configs import dify_config+from constants import DEFAULT_FILE_NUMBER_LIMITS+++def get_parameters_from_feature_dict(+ *, features_dict: Mapping[str, Any], user_input_form: list[dict[str, Any]]+) -> Mapping[str, Any]:+ """+ Mapping from feature dict to webapp parameters+ """+ return {+ "opening_statement": features_dict.get("opening_statement"),+ "suggested_questions": features_dict.get("suggested_questions", []),+ "suggested_questions_after_answer": features_dict.get("suggested_questions_after_answer", {"enabled": False}),+ "speech_to_text": features_dict.get("speech_to_text", {"enabled": False}),+ "text_to_speech": features_dict.get("text_to_speech", {"enabled": False}),+ "retriever_resource": features_dict.get("retriever_resource", {"enabled": False}),+ "annotation_reply": features_dict.get("annotation_reply", {"enabled": False}),+ "more_like_this": features_dict.get("more_like_this", {"enabled": False}),+ "user_input_form": user_input_form,+ "sensitive_word_avoidance": features_dict.get(+ "sensitive_word_avoidance", {"enabled": False, "type": "", "configs": []}+ ),+ "file_upload": features_dict.get(+ "file_upload",+ {+ "image": {+ "enabled": False,+ "number_limits": DEFAULT_FILE_NUMBER_LIMITS,+ "detail": "high",+ "transfer_methods": ["remote_url", "local_file"],+ }+ },+ ),+ "system_parameters": {+ "image_file_size_limit": dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT,+ "video_file_size_limit": dify_config.UPLOAD_VIDEO_FILE_SIZE_LIMIT,+ "audio_file_size_limit": dify_config.UPLOAD_AUDIO_FILE_SIZE_LIMIT,+ "file_size_limit": dify_config.UPLOAD_FILE_SIZE_LIMIT,+ "workflow_file_upload_limit": dify_config.WORKFLOW_FILE_UPLOAD_LIMIT,+ },+ }diff --git a/api/core/plugin/backwards_invocation/app.py b/api/core/plugin/backwards_invocation/app.pyindex 29873b508fd..484f52e33c8 100644--- a/api/core/plugin/backwards_invocation/app.py+++ b/api/core/plugin/backwards_invocation/app.py@@ -2,6 +2,7 @@ from collections.abc import Generator, Mappingfrom typing import Optional, Unionfrom controllers.service_api.wraps import create_or_update_end_user_for_user_id+from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dictfrom core.app.apps.advanced_chat.app_generator import AdvancedChatAppGeneratorfrom core.app.apps.agent_chat.app_generator import AgentChatAppGeneratorfrom core.app.apps.chat.app_generator import ChatAppGenerator@@ -15,6 +16,34 @@ from models.model import App, AppMode, EndUserclass PluginAppBackwardsInvocation(BaseBackwardsInvocation):+ @classmethod+ def fetch_app_info(cls, app_id: str, tenant_id: str) -> Mapping:+ """+ Fetch app info+ """+ app = cls._get_app(app_id, tenant_id)++ """Retrieve app parameters."""+ if app.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:+ workflow = app.workflow+ if workflow is None:+ raise ValueError("unexpected app type")++ features_dict = workflow.features_dict+ user_input_form = workflow.user_input_form(to_old_structure=True)+ else:+ app_model_config = app.app_model_config+ if app_model_config is None:+ raise ValueError("unexpected app type")++ features_dict = app_model_config.to_dict()++ user_input_form = features_dict.get("user_input_form", [])++ return {+ "data": get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form),+ }+@classmethoddef invoke_app(cls,diff --git a/api/core/plugin/entities/request.py b/api/core/plugin/entities/request.pyindex 837dcf59c49..6c0c7f2868a 100644--- a/api/core/plugin/entities/request.py+++ b/api/core/plugin/entities/request.py@@ -204,3 +204,11 @@ class RequestRequestUploadFile(BaseModel):filename: strmimetype: str+++class RequestFetchAppInfo(BaseModel):+ """+ Request to fetch app info+ """++ app_id: str