Skip to content

Commit e05fe3e

Browse files
committed
makes server init timeout configurable
1 parent 9de421a commit e05fe3e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/chat-cli/src/cli/chat/tool_manager.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ impl ToolManagerBuilder {
229229
self
230230
}
231231

232-
#[allow(dead_code)]
233232
pub fn interactive(mut self, is_interactive: bool) -> Self {
234233
self.is_interactive = is_interactive;
235234
self
@@ -715,7 +714,7 @@ impl ToolManager {
715714
});
716715
// We need to cast it to erase the type otherwise the compiler will default to static
717716
// dispatch, which would result in an error of inconsistent match arm return type.
718-
let display_future: Pin<Box<dyn Future<Output = ()>>> = match display_task {
717+
let display_fut: Pin<Box<dyn Future<Output = ()>>> = match display_task {
719718
Some(display_task) => {
720719
let fut = async move {
721720
if let Err(e) = display_task.await {
@@ -729,10 +728,19 @@ impl ToolManager {
729728
Box::pin(fut)
730729
},
731730
};
731+
// TODO: make this timeout configurable
732+
let timeout_fut: Pin<Box<dyn Future<Output = ()>>> = if self.is_interactive {
733+
let init_timeout = crate::settings::settings::get_int("mcp.initTimeout")
734+
.map_or(5000_u64, |s| s.map_or(5000_u64, |n| n as u64));
735+
error!("## timeout: {init_timeout}");
736+
Box::pin(tokio::time::sleep(std::time::Duration::from_millis(init_timeout)))
737+
} else {
738+
let fut = async { future::pending::<()>().await };
739+
Box::pin(fut)
740+
};
732741
tokio::select! {
733-
_ = display_future => {},
734-
// TODO: make this timeout configurable
735-
_ = tokio::time::sleep(std::time::Duration::from_secs(10)) => {
742+
_ = display_fut => {},
743+
_ = timeout_fut => {
736744
if let Some(tx) = tx {
737745
let _ = tx.send(LoadingMsg::Terminate);
738746
}

0 commit comments

Comments
 (0)