mirror of https://github.com/langgenius/dify.git
feat: enhance trigger metadata structure by adding type field and updating trigger_metadata handling
This commit is contained in:
parent
f1e513830c
commit
f0127ffc9a
|
|
@ -72,3 +72,6 @@ class AppTriggerType(StrEnum):
|
|||
TRIGGER_WEBHOOK = NodeType.TRIGGER_WEBHOOK.value
|
||||
TRIGGER_SCHEDULE = NodeType.TRIGGER_SCHEDULE.value
|
||||
TRIGGER_PLUGIN = NodeType.TRIGGER_PLUGIN.value
|
||||
|
||||
# for backward compatibility
|
||||
UNKNOWN = "unknown"
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class AsyncTriggerStatus(StrEnum):
|
|||
class TriggerMetadata(BaseModel):
|
||||
"""Trigger metadata"""
|
||||
|
||||
pass
|
||||
type: AppTriggerType = Field(default=AppTriggerType.UNKNOWN)
|
||||
|
||||
|
||||
class TriggerData(BaseModel):
|
||||
|
|
@ -36,7 +36,7 @@ class TriggerData(BaseModel):
|
|||
files: Sequence[Mapping[str, Any]] = Field(default_factory=list)
|
||||
trigger_type: AppTriggerType
|
||||
trigger_from: WorkflowRunTriggeredFrom
|
||||
trigger_metadata: TriggerMetadata = Field(default_factory=TriggerMetadata)
|
||||
trigger_metadata: TriggerMetadata | None = None
|
||||
|
||||
model_config = ConfigDict(use_enum_values=True)
|
||||
|
||||
|
|
@ -58,6 +58,8 @@ class ScheduleTriggerData(TriggerData):
|
|||
class PluginTriggerMetadata(TriggerMetadata):
|
||||
"""Plugin trigger metadata"""
|
||||
|
||||
type: AppTriggerType = AppTriggerType.TRIGGER_PLUGIN
|
||||
|
||||
endpoint_id: str
|
||||
plugin_unique_identifier: str
|
||||
provider_id: str
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ from sqlalchemy.orm import Session
|
|||
|
||||
from core.workflow.enums import WorkflowExecutionStatus
|
||||
from models import Account, App, EndUser, WorkflowAppLog, WorkflowRun
|
||||
from models.enums import CreatorUserRole
|
||||
from models.enums import AppTriggerType, CreatorUserRole
|
||||
from models.trigger import WorkflowTriggerLog
|
||||
from services.plugin.plugin_service import PluginService
|
||||
from services.workflow.entities import TriggerMetadata
|
||||
|
||||
|
||||
# Since the workflow_app_log table has exceeded 100 million records, we use an additional details field to extend it
|
||||
|
|
@ -169,14 +170,15 @@ class WorkflowAppService:
|
|||
metadata: dict[str, Any] | None = self._safe_json_loads(meta_val)
|
||||
if not metadata:
|
||||
return {}
|
||||
icon = metadata.get("icon_filename")
|
||||
icon_dark = metadata.get("icon_dark_filename")
|
||||
return {
|
||||
"icon": PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=icon) if icon else None,
|
||||
"icon_dark": PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=icon_dark)
|
||||
if icon_dark
|
||||
else None,
|
||||
}
|
||||
trigger_metadata = TriggerMetadata.model_validate(metadata)
|
||||
if trigger_metadata.type == AppTriggerType.TRIGGER_PLUGIN:
|
||||
icon = metadata.get("icon_filename")
|
||||
icon_dark = metadata.get("icon_dark_filename")
|
||||
metadata["icon"] = PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=icon) if icon else None
|
||||
metadata["icon_dark"] = (
|
||||
PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=icon_dark) if icon_dark else None
|
||||
)
|
||||
return metadata
|
||||
|
||||
@staticmethod
|
||||
def _safe_json_loads(val):
|
||||
|
|
|
|||
Loading…
Reference in New Issue