refactor(plugins): migrate endpoint queries to generated contracts (#42685)

This commit is contained in:
yyh
2026-09-22 05:54:58 +00:00
committed by GitHub
parent f7dbed5d86
commit 6d358eb680
26 changed files with 1240 additions and 1689 deletions
+26 -11
View File
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Literal
from core.plugin.entities.endpoint import EndpointEntityWithInstance
from core.plugin.impl.base import BasePluginClient
@@ -13,13 +13,13 @@ class PluginEndpointClient(BasePluginClient):
plugin_unique_identifier: str,
name: str,
settings: dict[str, Any],
) -> bool:
) -> Literal[True]:
"""
Create an endpoint for the given plugin.
Errors will be raised if any error occurs.
"""
return self._request_with_plugin_daemon_response(
success = self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/setup",
bool,
@@ -33,6 +33,9 @@ class PluginEndpointClient(BasePluginClient):
"name": name,
},
)
if not success:
raise PluginDaemonInternalServerError("Plugin daemon failed to create the endpoint")
return success
def list_endpoints(self, tenant_id: str, user_id: str, page: int, page_size: int):
"""
@@ -64,11 +67,11 @@ class PluginEndpointClient(BasePluginClient):
def update_endpoint(
self, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict[str, Any]
) -> bool:
) -> Literal[True]:
"""
Update the settings of the given endpoint.
"""
return self._request_with_plugin_daemon_response(
success = self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/update",
bool,
@@ -82,8 +85,11 @@ class PluginEndpointClient(BasePluginClient):
"Content-Type": "application/json",
},
)
if not success:
raise PluginDaemonInternalServerError("Plugin daemon failed to update the endpoint")
return success
def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str) -> Literal[True]:
"""
Delete the given endpoint.
@@ -91,7 +97,7 @@ class PluginEndpointClient(BasePluginClient):
it will return True instead of raising an error.
"""
try:
return self._request_with_plugin_daemon_response(
success = self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/remove",
bool,
@@ -107,12 +113,15 @@ class PluginEndpointClient(BasePluginClient):
if "record not found" in str(e.description).lower():
return True
raise
if not success:
raise PluginDaemonInternalServerError("Plugin daemon failed to delete the endpoint")
return success
def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str) -> Literal[True]:
"""
Enable the given endpoint.
"""
return self._request_with_plugin_daemon_response(
success = self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/enable",
bool,
@@ -123,12 +132,15 @@ class PluginEndpointClient(BasePluginClient):
"Content-Type": "application/json",
},
)
if not success:
raise PluginDaemonInternalServerError("Plugin daemon failed to enable the endpoint")
return success
def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str) -> Literal[True]:
"""
Disable the given endpoint.
"""
return self._request_with_plugin_daemon_response(
success = self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/disable",
bool,
@@ -139,3 +151,6 @@ class PluginEndpointClient(BasePluginClient):
"Content-Type": "application/json",
},
)
if not success:
raise PluginDaemonInternalServerError("Plugin daemon failed to disable the endpoint")
return success