refactor: replace BuiltinToolManageService with RagPipelineManageService for datasource management and remove unused datasource engine and related code

This commit is contained in:
Yeuoly
2025-05-16 18:42:07 +08:00
parent 8bea88c8cc
commit c5a2f43ceb
22 changed files with 390 additions and 1496 deletions

View File

@ -3,10 +3,9 @@ from typing import Any, Optional
from pydantic import BaseModel
from core.plugin.entities.plugin import DatasourceProviderID, GenericProviderID, ToolProviderID
from core.plugin.entities.plugin import GenericProviderID, ToolProviderID
from core.plugin.entities.plugin_daemon import (
PluginBasicBooleanResponse,
PluginDatasourceProviderEntity,
PluginToolProviderEntity,
)
from core.plugin.impl.base import BasePluginClient
@ -45,67 +44,6 @@ class PluginToolManager(BasePluginClient):
return response
def fetch_datasources(self, tenant_id: str) -> list[PluginDatasourceProviderEntity]:
"""
Fetch datasources for the given tenant.
"""
def transformer(json_response: dict[str, Any]) -> dict:
for provider in json_response.get("data", []):
declaration = provider.get("declaration", {}) or {}
provider_name = declaration.get("identity", {}).get("name")
for tool in declaration.get("tools", []):
tool["identity"]["provider"] = provider_name
return json_response
response = self._request_with_plugin_daemon_response(
"GET",
f"plugin/{tenant_id}/management/datasources",
list[PluginToolProviderEntity],
params={"page": 1, "page_size": 256},
transformer=transformer,
)
for provider in response:
provider.declaration.identity.name = f"{provider.plugin_id}/{provider.declaration.identity.name}"
# override the provider name for each tool to plugin_id/provider_name
for tool in provider.declaration.tools:
tool.identity.provider = provider.declaration.identity.name
return response
def fetch_datasource_provider(self, tenant_id: str, provider: str) -> PluginDatasourceProviderEntity:
"""
Fetch datasource provider for the given tenant and plugin.
"""
datasource_provider_id = DatasourceProviderID(provider)
def transformer(json_response: dict[str, Any]) -> dict:
data = json_response.get("data")
if data:
for tool in data.get("declaration", {}).get("tools", []):
tool["identity"]["provider"] = datasource_provider_id.provider_name
return json_response
response = self._request_with_plugin_daemon_response(
"GET",
f"plugin/{tenant_id}/management/datasource",
PluginDatasourceProviderEntity,
params={"provider": datasource_provider_id.provider_name, "plugin_id": datasource_provider_id.plugin_id},
transformer=transformer,
)
response.declaration.identity.name = f"{response.plugin_id}/{response.declaration.identity.name}"
# override the provider name for each tool to plugin_id/provider_name
for tool in response.declaration.tools:
tool.identity.provider = response.declaration.identity.name
return response
def fetch_tool_provider(self, tenant_id: str, provider: str) -> PluginToolProviderEntity:
"""
Fetch tool provider for the given tenant and plugin.