1use std::future::Future;
2
3use futures::Stream;
4use rmcp::model::{CallToolResult, ErrorData, ServerNotification};
5use tokio::sync::mpsc;
6
7use oi_kit_provider_types::conversation::message::Message;
8
9pub type ToolResult<T> = Result<T, ErrorData>;
10
11#[derive(Clone)]
12pub struct ToolCallNotificationEmitter {
13 sender: mpsc::Sender<ServerNotification>,
14}
15
16impl ToolCallNotificationEmitter {
17 pub fn new(sender: mpsc::Sender<ServerNotification>) -> Self {
18 Self { sender }
19 }
20
21 pub fn emit_best_effort(&self, notification: ServerNotification) {
22 let _ = self.sender.try_send(notification);
24 }
25}
26
27pub struct ToolCallResult {
30 pub result: Box<dyn Future<Output = ToolResult<CallToolResult>> + Send + Unpin>,
31 pub notification_stream: Option<Box<dyn Stream<Item = ServerNotification> + Send + Unpin>>,
32 pub action_required_stream: Option<Box<dyn Stream<Item = Message> + Send + Unpin>>,
33}
34
35impl From<ToolResult<CallToolResult>> for ToolCallResult {
36 fn from(result: ToolResult<CallToolResult>) -> Self {
37 Self {
38 result: Box::new(futures::future::ready(result)),
39 notification_stream: None,
40 action_required_stream: None,
41 }
42 }
43}