Compare commits

...

3 Commits

Author SHA1 Message Date
GareArc
080e40c496 fix: update env in docker configs 2025-02-02 20:07:55 -05:00
GareArc
2fe55da3a8 fix: format 2025-02-02 19:58:45 -05:00
GareArc
1f8d9eaf67 feat: add position config for workflow tools 2025-02-02 15:15:29 -05:00
6 changed files with 83 additions and 0 deletions

View File

@@ -422,6 +422,11 @@ POSITION_PROVIDER_PINS=
POSITION_PROVIDER_INCLUDES=
POSITION_PROVIDER_EXCLUDES=
POSITION_WORKFLOW_PINS=
POSITION_WORKFLOW_INCLUDES=
POSITION_WORKFLOW_EXCLUDES=
# Reset password token expiry minutes
RESET_PASSWORD_TOKEN_EXPIRY_MINUTES=5

View File

@@ -723,6 +723,21 @@ class PositionConfig(BaseSettings):
default="",
)
POSITION_WORKFLOW_PINS: str = Field(
description="Comma-separated list of pinned workflows",
default="",
)
POSITION_WORKFLOW_INCLUDES: str = Field(
description="Comma-separated list of included workflows",
default="",
)
POSITION_WORKFLOW_EXCLUDES: str = Field(
description="Comma-separated list of excluded workflows",
default="",
)
@property
def POSITION_PROVIDER_PINS_LIST(self) -> list[str]:
return [item.strip() for item in self.POSITION_PROVIDER_PINS.split(",") if item.strip() != ""]
@@ -747,6 +762,18 @@ class PositionConfig(BaseSettings):
def POSITION_TOOL_EXCLUDES_SET(self) -> set[str]:
return {item.strip() for item in self.POSITION_TOOL_EXCLUDES.split(",") if item.strip() != ""}
@property
def POSITION_WORKFLOW_PINS_LIST(self) -> list[str]:
return [item.strip() for item in self.POSITION_WORKFLOW_PINS.split(",") if item.strip() != ""]
@property
def POSITION_WORKFLOW_INCLUDES_SET(self) -> set[str]:
return {item.strip() for item in self.POSITION_WORKFLOW_INCLUDES.split(",") if item.strip() != ""}
@property
def POSITION_WORKFLOW_EXCLUDES_SET(self) -> set[str]:
return {item.strip() for item in self.POSITION_WORKFLOW_EXCLUDES.split(",") if item.strip() != ""}
class LoginConfig(BaseSettings):
ENABLE_EMAIL_CODE_LOGIN: bool = Field(

View File

@@ -120,6 +120,30 @@ def sort_by_position_map(
return sorted(data, key=lambda x: position_map.get(name_func(x), float("inf")))
def sort_by_pin_list_only(
pin_list: list[str],
data: list[Any],
name_func: Callable[[Any], str],
) -> list[Any]:
"""
Sort the objects by the pin list, order within the pin list is perserved.
If the name of the object is not in the pin list, it will be put at the end.
:param pin_list: the list of names to be pinned
:param name_func: the function to get the name of the object
:param data: the data to be sorted
:return: the sorted objects
"""
if not pin_list or not data:
return data
pin_set = set(pin_list)
data_name_map = {name_func(item): data for item in data}
pinned = [data_name_map[name] for name in pin_list if name in data_name_map]
rest = [item for item in data if name_func(item) not in pin_set]
return pinned + rest
def sort_to_dict_by_position_map(
position_map: dict[str, int],
data: list[Any],

View File

@@ -5,6 +5,8 @@ from typing import Any, Optional
from sqlalchemy import or_
from configs import dify_config
from core.helper.position_helper import is_filtered, sort_by_pin_list_only
from core.model_runtime.utils.encoders import jsonable_encoder
from core.tools.entities.api_entities import UserTool, UserToolProvider
from core.tools.provider.tool_provider import ToolProviderController
@@ -203,6 +205,14 @@ class WorkflowToolManageService:
user_tool_provider = ToolTransformService.workflow_provider_to_user_provider(
provider_controller=tool, labels=labels.get(tool.provider_id, [])
)
if is_filtered(
include_set=dify_config.POSITION_WORKFLOW_INCLUDES_SET,
exclude_set=dify_config.POSITION_WORKFLOW_EXCLUDES_SET,
data=user_tool_provider,
name_func=lambda x: x.name,
):
continue
ToolTransformService.repack_provider(user_tool_provider)
to_user_tool: Optional[list[Tool]] = tool.get_tools(user_id, tenant_id)
if to_user_tool is None or len(to_user_tool) == 0:
@@ -212,6 +222,13 @@ class WorkflowToolManageService:
]
result.append(user_tool_provider)
# sort by pinned position
result = sort_by_pin_list_only(
pin_list=dify_config.POSITION_PROVIDER_PINS_LIST,
data=result,
name_func=lambda x: x.name,
)
return result
@classmethod

View File

@@ -921,6 +921,13 @@ POSITION_PROVIDER_PINS=
POSITION_PROVIDER_INCLUDES=
POSITION_PROVIDER_EXCLUDES=
# Pin, include, and exclude workflow tools
# Use comma-separated values with no spaces between items.
# Example: POSITION_WORKFLOW_PINS=myworkflow1,myworkflow2
POSITION_WORKFLOW_PINS=
POSITION_WORKFLOW_INCLUDES=
POSITION_WORKFLOW_EXCLUDES=
# CSP https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
CSP_WHITELIST=

View File

@@ -385,6 +385,9 @@ x-shared-env: &shared-api-worker-env
POSITION_PROVIDER_PINS: ${POSITION_PROVIDER_PINS:-}
POSITION_PROVIDER_INCLUDES: ${POSITION_PROVIDER_INCLUDES:-}
POSITION_PROVIDER_EXCLUDES: ${POSITION_PROVIDER_EXCLUDES:-}
POSITION_WORKFLOW_PINS: ${POSITION_WORKFLOW_PINS:-}
POSITION_WORKFLOW_INCLUDES: ${POSITION_WORKFLOW_INCLUDES:-}
POSITION_WORKFLOW_EXCLUDES: ${POSITION_WORKFLOW_EXCLUDES:-}
CSP_WHITELIST: ${CSP_WHITELIST:-}
CREATE_TIDB_SERVICE_JOB_ENABLED: ${CREATE_TIDB_SERVICE_JOB_ENABLED:-false}
MAX_SUBMIT_COUNT: ${MAX_SUBMIT_COUNT:-100}