mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 09:28:04 +08:00
optimize: TriggerDispatchResponse
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import binascii
|
||||
from collections.abc import Mapping
|
||||
from typing import Any, Literal, Optional
|
||||
|
||||
@ -15,6 +16,7 @@ from core.model_runtime.entities.message_entities import (
|
||||
UserPromptMessage,
|
||||
)
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from core.plugin.utils.http_parser import deserialize_response
|
||||
from core.workflow.nodes.parameter_extractor.entities import (
|
||||
ModelConfig as ParameterExtractorModelConfig,
|
||||
)
|
||||
@ -246,17 +248,6 @@ class TriggerInvokeEventResponse(BaseModel):
|
||||
cancelled: Optional[bool] = False
|
||||
|
||||
|
||||
class PluginTriggerDispatchResponse(BaseModel):
|
||||
"""
|
||||
Original response from plugin daemon
|
||||
"""
|
||||
|
||||
user_id: str
|
||||
events: list[str]
|
||||
raw_http_response: str
|
||||
payload: Mapping[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class TriggerSubscriptionResponse(BaseModel):
|
||||
subscription: dict[str, Any]
|
||||
|
||||
@ -272,3 +263,11 @@ class TriggerDispatchResponse(BaseModel):
|
||||
payload: Mapping[str, Any] = Field(default_factory=dict)
|
||||
|
||||
model_config = ConfigDict(protected_namespaces=(), arbitrary_types_allowed=True)
|
||||
|
||||
@field_validator("response", mode="before")
|
||||
@classmethod
|
||||
def convert_response(cls, v: str):
|
||||
try:
|
||||
return deserialize_response(binascii.unhexlify(v.encode()))
|
||||
except Exception as e:
|
||||
raise ValueError("Failed to deserialize response from hex string") from e
|
||||
|
||||
Reference in New Issue
Block a user