refactor: using plugin id to dispatch request instead
This commit is contained in:
parent
2da32e49d0
commit
c3359a9291
@ -20,7 +20,13 @@ class PluginEncrypter:
|
||||
return {
|
||||
"data": encrypter.encrypt(payload.data),
|
||||
}
|
||||
else:
|
||||
elif payload.opt == "decrypt":
|
||||
return {
|
||||
"data": encrypter.decrypt(payload.data),
|
||||
}
|
||||
elif payload.opt == "clear":
|
||||
return {
|
||||
"data": encrypter.delete_tool_credentials_cache(),
|
||||
}
|
||||
else:
|
||||
raise ValueError(f"Invalid opt: {payload.opt}")
|
||||
|
@ -173,7 +173,7 @@ class RequestInvokeEncrypt(BaseModel):
|
||||
Request to encryption
|
||||
"""
|
||||
|
||||
opt: Literal["encrypt", "decrypt"]
|
||||
opt: Literal["encrypt", "decrypt", "clear"]
|
||||
namespace: Literal["endpoint"]
|
||||
identity: str
|
||||
data: dict = Field(default_factory=dict)
|
||||
|
@ -34,7 +34,7 @@ class PluginToolManager(BasePluginManager):
|
||||
self,
|
||||
tenant_id: str,
|
||||
user_id: str,
|
||||
plugin_unique_identifier: str,
|
||||
plugin_id: str,
|
||||
tool_provider: str,
|
||||
tool_name: str,
|
||||
credentials: dict[str, Any],
|
||||
@ -45,7 +45,6 @@ class PluginToolManager(BasePluginManager):
|
||||
f"plugin/{tenant_id}/dispatch/tool/invoke",
|
||||
ToolInvokeMessage,
|
||||
data={
|
||||
"plugin_unique_identifier": plugin_unique_identifier,
|
||||
"user_id": user_id,
|
||||
"data": {
|
||||
"provider": tool_provider,
|
||||
@ -55,14 +54,14 @@ class PluginToolManager(BasePluginManager):
|
||||
},
|
||||
},
|
||||
headers={
|
||||
"X-Plugin-Identifier": plugin_unique_identifier,
|
||||
"X-Plugin-ID": plugin_id,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
},
|
||||
)
|
||||
return response
|
||||
|
||||
def validate_provider_credentials(
|
||||
self, tenant_id: str, user_id: str, plugin_unique_identifier: str, provider: str, credentials: dict[str, Any]
|
||||
self, tenant_id: str, user_id: str, plugin_id: str, provider: str, credentials: dict[str, Any]
|
||||
) -> bool:
|
||||
"""
|
||||
validate the credentials of the provider
|
||||
@ -72,7 +71,6 @@ class PluginToolManager(BasePluginManager):
|
||||
f"plugin/{tenant_id}/dispatch/tool/validate_credentials",
|
||||
PluginBasicBooleanResponse,
|
||||
data={
|
||||
"plugin_unique_identifier": plugin_unique_identifier,
|
||||
"user_id": user_id,
|
||||
"data": {
|
||||
"provider": provider,
|
||||
@ -80,12 +78,12 @@ class PluginToolManager(BasePluginManager):
|
||||
},
|
||||
},
|
||||
headers={
|
||||
"X-Plugin-Identifier": plugin_unique_identifier,
|
||||
"X-Plugin-ID": plugin_id,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
for resp in response:
|
||||
return resp.result
|
||||
|
||||
|
||||
return False
|
||||
|
@ -11,12 +11,12 @@ from core.tools.plugin_tool.tool import PluginTool
|
||||
class PluginToolProviderController(BuiltinToolProviderController):
|
||||
entity: ToolProviderEntityWithPlugin
|
||||
tenant_id: str
|
||||
plugin_unique_identifier: str
|
||||
plugin_id: str
|
||||
|
||||
def __init__(self, entity: ToolProviderEntityWithPlugin, tenant_id: str, plugin_unique_identifier: str) -> None:
|
||||
def __init__(self, entity: ToolProviderEntityWithPlugin, tenant_id: str, plugin_id: str) -> None:
|
||||
self.entity = entity
|
||||
self.tenant_id = tenant_id
|
||||
self.plugin_unique_identifier = plugin_unique_identifier
|
||||
self.plugin_id = plugin_id
|
||||
|
||||
@property
|
||||
def provider_type(self) -> ToolProviderType:
|
||||
@ -35,7 +35,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
|
||||
if not manager.validate_provider_credentials(
|
||||
tenant_id=self.tenant_id,
|
||||
user_id=user_id,
|
||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||
plugin_id=self.plugin_id,
|
||||
provider=self.entity.identity.name,
|
||||
credentials=credentials,
|
||||
):
|
||||
@ -54,7 +54,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
|
||||
entity=tool_entity,
|
||||
runtime=ToolRuntime(tenant_id=self.tenant_id),
|
||||
tenant_id=self.tenant_id,
|
||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||
plugin_id=self.plugin_id,
|
||||
)
|
||||
|
||||
def get_tools(self) -> list[PluginTool]:
|
||||
@ -66,7 +66,7 @@ class PluginToolProviderController(BuiltinToolProviderController):
|
||||
entity=tool_entity,
|
||||
runtime=ToolRuntime(tenant_id=self.tenant_id),
|
||||
tenant_id=self.tenant_id,
|
||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||
plugin_id=self.plugin_id,
|
||||
)
|
||||
for tool_entity in self.entity.tools
|
||||
]
|
||||
|
@ -9,12 +9,12 @@ from core.tools.entities.tool_entities import ToolEntity, ToolInvokeMessage, Too
|
||||
|
||||
class PluginTool(Tool):
|
||||
tenant_id: str
|
||||
plugin_unique_identifier: str
|
||||
plugin_id: str
|
||||
|
||||
def __init__(self, entity: ToolEntity, runtime: ToolRuntime, tenant_id: str, plugin_unique_identifier: str) -> None:
|
||||
def __init__(self, entity: ToolEntity, runtime: ToolRuntime, tenant_id: str, plugin_id: str) -> None:
|
||||
super().__init__(entity, runtime)
|
||||
self.tenant_id = tenant_id
|
||||
self.plugin_unique_identifier = plugin_unique_identifier
|
||||
self.plugin_id = plugin_id
|
||||
|
||||
@property
|
||||
def tool_provider_type(self) -> ToolProviderType:
|
||||
@ -25,7 +25,7 @@ class PluginTool(Tool):
|
||||
return manager.invoke(
|
||||
tenant_id=self.tenant_id,
|
||||
user_id=user_id,
|
||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||
plugin_id=self.plugin_id,
|
||||
tool_provider=self.entity.identity.provider,
|
||||
tool_name=self.entity.identity.name,
|
||||
credentials=self.runtime.credentials,
|
||||
@ -37,5 +37,5 @@ class PluginTool(Tool):
|
||||
entity=self.entity,
|
||||
runtime=runtime,
|
||||
tenant_id=self.tenant_id,
|
||||
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||
plugin_id=self.plugin_id,
|
||||
)
|
||||
|
@ -85,7 +85,7 @@ class ToolManager:
|
||||
return PluginToolProviderController(
|
||||
entity=provider_entity.declaration,
|
||||
tenant_id=tenant_id,
|
||||
plugin_unique_identifier=provider_entity.plugin_unique_identifier,
|
||||
plugin_id=provider_entity.plugin_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@ -402,7 +402,7 @@ class ToolManager:
|
||||
PluginToolProviderController(
|
||||
entity=provider.declaration,
|
||||
tenant_id=tenant_id,
|
||||
plugin_unique_identifier=provider.plugin_unique_identifier,
|
||||
plugin_id=provider.plugin_id,
|
||||
)
|
||||
for provider in provider_entities
|
||||
]
|
||||
@ -527,13 +527,9 @@ class ToolManager:
|
||||
)
|
||||
|
||||
if isinstance(provider, PluginToolProviderController):
|
||||
result_providers[f"plugin_provider.{user_provider.name}.{provider.plugin_unique_identifier}"] = (
|
||||
user_provider
|
||||
)
|
||||
result_providers[f"plugin_provider.{user_provider.name}.{provider.plugin_id}"] = user_provider
|
||||
else:
|
||||
result_providers[f"builtin_provider.{user_provider.name}"] = (
|
||||
user_provider
|
||||
)
|
||||
result_providers[f"builtin_provider.{user_provider.name}"] = user_provider
|
||||
|
||||
# get db api providers
|
||||
|
||||
|
@ -155,7 +155,10 @@ class AppService:
|
||||
"""
|
||||
# get original app model config
|
||||
if app.mode == AppMode.AGENT_CHAT.value or app.is_agent:
|
||||
model_config: AppModelConfig = app.app_model_config
|
||||
model_config: AppModelConfig | None = app.app_model_config
|
||||
if not model_config:
|
||||
return app
|
||||
|
||||
agent_mode = model_config.agent_mode_dict
|
||||
# decrypt agent tool parameters if it's secret-input
|
||||
for tool in agent_mode.get("tools") or []:
|
||||
|
Loading…
Reference in New Issue
Block a user