pub struct ToolRouter { /* private fields */ }Expand description
Tool Router
Routes tool execution requests to the appropriate extension service. Uses the registry service to discover which services provide each tool.
Implementations§
Source§impl ToolRouter
impl ToolRouter
Sourcepub fn new(registry: Arc<RegistryService>) -> Self
pub fn new(registry: Arc<RegistryService>) -> Self
Create a new tool router with a registry service
Sourcepub fn with_timeout(self, timeout_ms: u64) -> Self
pub fn with_timeout(self, timeout_ms: u64) -> Self
Set default timeout for tool execution
Sourcepub async fn register_tool(
&self,
_service_id: ServiceId,
tool_def: ToolDefinition,
)
pub async fn register_tool( &self, _service_id: ServiceId, tool_def: ToolDefinition, )
Register a tool from a service
This updates the internal tool index for fast routing.
Sourcepub async fn unregister_service_tools(&self, service_id: &ServiceId)
pub async fn unregister_service_tools(&self, service_id: &ServiceId)
Unregister all tools from a service
Called when a service is unregistered or disconnected.
Sourcepub async fn rebuild_index(&self) -> Result<(), ToolRouterError>
pub async fn rebuild_index(&self) -> Result<(), ToolRouterError>
Rebuild the tool index from the registry
Useful after bulk registration changes.
Sourcepub async fn route(
&self,
tool_name: &str,
params: JsonValue,
request_id: JsonRpcId,
) -> Result<ToolRouteResult, ToolRouterError>
pub async fn route( &self, tool_name: &str, params: JsonValue, request_id: JsonRpcId, ) -> Result<ToolRouteResult, ToolRouterError>
Route a tool execution request
Given a tool name and parameters, find the appropriate service and return routing information.
Sourcepub async fn list_tools(&self) -> Vec<ToolDefinition>
pub async fn list_tools(&self) -> Vec<ToolDefinition>
List all available tools
Sourcepub async fn get_tool(&self, tool_name: &str) -> Option<ToolDefinition>
pub async fn get_tool(&self, tool_name: &str) -> Option<ToolDefinition>
Get tool definition
Sourcepub fn create_tool_request(
&self,
route_result: ToolRouteResult,
) -> JsonRpcRequest
pub fn create_tool_request( &self, route_result: ToolRouteResult, ) -> JsonRpcRequest
Create a JSON-RPC request for tool execution
Creates the proper request format for the extension service.
Sourcepub async fn create_error_response(
&self,
error: ToolRouterError,
request_id: JsonRpcId,
) -> JsonRpcResponse
pub async fn create_error_response( &self, error: ToolRouterError, request_id: JsonRpcId, ) -> JsonRpcResponse
Create an error response for routing failures
Sourcepub async fn get_timeout(&self, tool_name: &str) -> u64
pub async fn get_timeout(&self, tool_name: &str) -> u64
Get the default timeout for a tool
Sourcepub async fn tool_count(&self) -> usize
pub async fn tool_count(&self) -> usize
Get the count of registered tools