mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
refactor: better typing
This commit is contained in:
parent
8a18b6e13b
commit
a711a8e759
@ -24,7 +24,7 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
Fetch trigger providers for the given tenant.
|
Fetch trigger providers for the given tenant.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def transformer(json_response: dict[str, Any]) -> dict:
|
def transformer(json_response: dict[str, Any]) -> dict[str, Any]:
|
||||||
for provider in json_response.get("data", []):
|
for provider in json_response.get("data", []):
|
||||||
declaration = provider.get("declaration", {}) or {}
|
declaration = provider.get("declaration", {}) or {}
|
||||||
provider_id = provider.get("plugin_id") + "/" + provider.get("provider")
|
provider_id = provider.get("plugin_id") + "/" + provider.get("provider")
|
||||||
@ -55,7 +55,7 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
Fetch trigger provider for the given tenant and plugin.
|
Fetch trigger provider for the given tenant and plugin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def transformer(json_response: dict[str, Any]) -> dict:
|
def transformer(json_response: dict[str, Any]) -> dict[str, Any]:
|
||||||
data = json_response.get("data")
|
data = json_response.get("data")
|
||||||
if data:
|
if data:
|
||||||
for event in data.get("declaration", {}).get("events", []):
|
for event in data.get("declaration", {}).get("events", []):
|
||||||
@ -90,6 +90,7 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
request: Request,
|
request: Request,
|
||||||
parameters: Mapping[str, Any],
|
parameters: Mapping[str, Any],
|
||||||
subscription: Subscription,
|
subscription: Subscription,
|
||||||
|
payload: Mapping[str, Any],
|
||||||
) -> TriggerInvokeEventResponse:
|
) -> TriggerInvokeEventResponse:
|
||||||
"""
|
"""
|
||||||
Invoke a trigger with the given parameters.
|
Invoke a trigger with the given parameters.
|
||||||
@ -109,6 +110,7 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
"subscription": subscription.model_dump(),
|
"subscription": subscription.model_dump(),
|
||||||
"raw_http_request": binascii.hexlify(serialize_request(request)).decode(),
|
"raw_http_request": binascii.hexlify(serialize_request(request)).decode(),
|
||||||
"parameters": parameters,
|
"parameters": parameters,
|
||||||
|
"payload": payload,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
headers={
|
headers={
|
||||||
@ -166,25 +168,23 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
Dispatch an event to triggers.
|
Dispatch an event to triggers.
|
||||||
"""
|
"""
|
||||||
provider_id = TriggerProviderID(provider)
|
provider_id = TriggerProviderID(provider)
|
||||||
response: Generator[PluginTriggerDispatchResponse, None, None] = (
|
response = self._request_with_plugin_daemon_response_stream(
|
||||||
self._request_with_plugin_daemon_response_stream(
|
method="POST",
|
||||||
method="POST",
|
path=f"plugin/{tenant_id}/dispatch/trigger/dispatch_event",
|
||||||
path=f"plugin/{tenant_id}/dispatch/trigger/dispatch_event",
|
type_=PluginTriggerDispatchResponse,
|
||||||
type_=PluginTriggerDispatchResponse,
|
data={
|
||||||
data={
|
"data": {
|
||||||
"data": {
|
"provider": provider_id.provider_name,
|
||||||
"provider": provider_id.provider_name,
|
"subscription": subscription,
|
||||||
"subscription": subscription,
|
"credentials": credentials,
|
||||||
"credentials": credentials,
|
"credential_type": credential_type,
|
||||||
"credential_type": credential_type,
|
"raw_http_request": binascii.hexlify(serialize_request(request)).decode(),
|
||||||
"raw_http_request": binascii.hexlify(serialize_request(request)).decode(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
headers={
|
},
|
||||||
"X-Plugin-ID": provider_id.plugin_id,
|
headers={
|
||||||
"Content-Type": "application/json",
|
"X-Plugin-ID": provider_id.plugin_id,
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
)
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
for resp in response:
|
for resp in response:
|
||||||
@ -192,6 +192,7 @@ class PluginTriggerManager(BasePluginClient):
|
|||||||
user_id=resp.user_id or "",
|
user_id=resp.user_id or "",
|
||||||
events=resp.events,
|
events=resp.events,
|
||||||
response=deserialize_response(binascii.unhexlify(resp.raw_http_response.encode())),
|
response=deserialize_response(binascii.unhexlify(resp.raw_http_response.encode())),
|
||||||
|
payload=resp.payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
raise ValueError("No response received from plugin daemon for dispatch event")
|
raise ValueError("No response received from plugin daemon for dispatch event")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user