pub struct ToolHandlerRouter { /* private fields */ }Expand description
A SessionHandler that dispatches tool calls to registered
ToolHandler implementations by name.
For tool calls matching a registered handler, the handler is invoked directly. All other events (permissions, user input, unrecognized tools) are forwarded to the inner handler.
§Example
use std::sync::Arc;
use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::tool::ToolHandlerRouter;
let router = ToolHandlerRouter::new(
vec![/* Box::new(MyTool), ... */],
Arc::new(ApproveAllHandler),
);
// Use router.tools() in SessionConfig
// Use Arc::new(router) as the session handlerImplementations§
Source§impl ToolHandlerRouter
impl ToolHandlerRouter
Sourcepub fn new(
tools: Vec<Box<dyn ToolHandler>>,
inner: Arc<dyn SessionHandler>,
) -> Self
pub fn new( tools: Vec<Box<dyn ToolHandler>>, inner: Arc<dyn SessionHandler>, ) -> Self
Create a router from tool handler impls and a fallback handler.
Call tools() to get the tool definitions for
SessionConfig::tools.
Sourcepub fn tools(&self) -> Vec<Tool>
pub fn tools(&self) -> Vec<Tool>
Tool definitions for SessionConfig::tools.
Trait Implementations§
Source§impl Debug for ToolHandlerRouter
impl Debug for ToolHandlerRouter
Source§impl SessionHandler for ToolHandlerRouter
impl SessionHandler for ToolHandlerRouter
Source§fn on_external_tool<'life0, 'async_trait>(
&'life0 self,
invocation: ToolInvocation,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_external_tool<'life0, 'async_trait>(
&'life0 self,
invocation: ToolInvocation,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI wants to invoke a client-defined (“external”) tool. Read more
Source§fn on_session_event<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
event: SessionEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_session_event<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
event: SessionEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Informational timeline event (assistant messages, tool execution
markers, session idle, etc.). Fire-and-forget — the return value is
ignored. Read more
Source§fn on_permission_request<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
request_id: RequestId,
data: PermissionRequestData,
) -> Pin<Box<dyn Future<Output = PermissionResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_permission_request<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
request_id: RequestId,
data: PermissionRequestData,
) -> Pin<Box<dyn Future<Output = PermissionResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI is asking whether the agent may perform a privileged action. Read more
Source§fn on_user_input<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
question: String,
choices: Option<Vec<String>>,
allow_freeform: Option<bool>,
) -> Pin<Box<dyn Future<Output = Option<UserInputResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_user_input<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
question: String,
choices: Option<Vec<String>>,
allow_freeform: Option<bool>,
) -> Pin<Box<dyn Future<Output = Option<UserInputResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI is asking the user a question (optionally with a list of
choices). Read more
Source§fn on_elicitation<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
request_id: RequestId,
request: ElicitationRequest,
) -> Pin<Box<dyn Future<Output = ElicitationResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_elicitation<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
request_id: RequestId,
request: ElicitationRequest,
) -> Pin<Box<dyn Future<Output = ElicitationResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI is requesting an elicitation (structured form / URL prompt). Read more
Source§fn on_exit_plan_mode<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
data: ExitPlanModeData,
) -> Pin<Box<dyn Future<Output = ExitPlanModeResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_exit_plan_mode<'life0, 'async_trait>(
&'life0 self,
session_id: SessionId,
data: ExitPlanModeData,
) -> Pin<Box<dyn Future<Output = ExitPlanModeResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI is asking the user whether to exit plan mode. Read more
Source§fn on_event<'life0, 'async_trait>(
&'life0 self,
event: HandlerEvent,
) -> Pin<Box<dyn Future<Output = HandlerResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_event<'life0, 'async_trait>(
&'life0 self,
event: HandlerEvent,
) -> Pin<Box<dyn Future<Output = HandlerResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle an event from the session. Read more
Source§fn on_auto_mode_switch<'life0, 'async_trait>(
&'life0 self,
_session_id: SessionId,
_error_code: Option<String>,
_retry_after_seconds: Option<u64>,
) -> Pin<Box<dyn Future<Output = AutoModeSwitchResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_auto_mode_switch<'life0, 'async_trait>(
&'life0 self,
_session_id: SessionId,
_error_code: Option<String>,
_retry_after_seconds: Option<u64>,
) -> Pin<Box<dyn Future<Output = AutoModeSwitchResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The CLI is asking whether to switch to auto model after an eligible
rate limit. Read more
Auto Trait Implementations§
impl Freeze for ToolHandlerRouter
impl !RefUnwindSafe for ToolHandlerRouter
impl Send for ToolHandlerRouter
impl Sync for ToolHandlerRouter
impl Unpin for ToolHandlerRouter
impl UnsafeUnpin for ToolHandlerRouter
impl !UnwindSafe for ToolHandlerRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more