Skip to content

Commit 5aadbcd

Browse files
committed
handles tool call rejection structured event
1 parent 506d25a commit 5aadbcd

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

crates/chat-cli-ui/src/conduit.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::legacy_ui_util::ThemeSource;
1515
use crate::protocol::{
1616
Event,
1717
LegacyPassThroughOutput,
18+
ToolCallRejection,
1819
ToolCallStart,
1920
};
2021

@@ -153,7 +154,22 @@ impl ViewEnd {
153154
Event::ReasoningMessageChunk(_reasoning_message_chunk) => {},
154155
Event::ReasoningEnd(_reasoning_end) => {},
155156
Event::MetaEvent(_meta_event) => {},
156-
Event::ToolCallRejection(tool_call_rejection) => todo!(),
157+
Event::ToolCallRejection(tool_call_rejection) => {
158+
let ToolCallRejection { reason, name, .. } = tool_call_rejection;
159+
160+
execute!(
161+
stderr,
162+
theme_source.error_fg(),
163+
Print("Command "),
164+
theme_source.warning_fg(),
165+
Print(name),
166+
theme_source.error_fg(),
167+
Print(" is rejected because it matches one or more rules on the denied list:"),
168+
Print(reason),
169+
Print("\n"),
170+
theme_source.reset(),
171+
)?;
172+
},
157173
}
158174
}
159175

crates/chat-cli-ui/src/protocol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub struct ToolCallResult {
171171
#[serde(rename_all = "camelCase")]
172172
pub struct ToolCallRejection {
173173
pub tool_call_id: String,
174+
pub name: String,
174175
pub reason: String,
175176
}
176177

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ impl ChatSession {
22032203
} else {
22042204
let event = ToolCallRejection {
22052205
tool_call_id: tool.id.clone(),
2206+
name: tool.name.clone(),
22062207
reason: formatted_set,
22072208
};
22082209
self.stderr.send(Event::ToolCallRejection(event))?;
@@ -2227,7 +2228,10 @@ impl ChatSession {
22272228

22282229
// TODO: Control flow is hacky here because of borrow rules
22292230
let _ = tool;
2231+
22302232
self.print_tool_description(os, i, allowed).await?;
2233+
self.stdout.flush()?;
2234+
22312235
let tool = &mut self.tool_uses[i];
22322236

22332237
if allowed {
@@ -3255,7 +3259,20 @@ impl ChatSession {
32553259
async fn print_tool_description(&mut self, os: &Os, tool_index: usize, trusted: bool) -> Result<(), ChatError> {
32563260
let tool_use = &self.tool_uses[tool_index];
32573261

3258-
if !self.stderr.should_send_structured_event {
3262+
if self.stderr.should_send_structured_event {
3263+
let tool_call_start = ToolCallStart {
3264+
tool_call_id: tool_use.id.clone(),
3265+
tool_call_name: tool_use.name.clone(),
3266+
mcp_server_name: if let Tool::Custom(ref tool) = tool_use.tool {
3267+
Some(tool.server_name.clone())
3268+
} else {
3269+
None
3270+
},
3271+
is_trusted: trusted,
3272+
parent_message_id: None,
3273+
};
3274+
self.stdout.send(Event::ToolCallStart(tool_call_start))?;
3275+
} else {
32593276
queue!(
32603277
self.stdout,
32613278
StyledText::emphasis_fg(),
@@ -3284,19 +3301,6 @@ impl ChatSession {
32843301
style::Print("\n"),
32853302
style::Print(TOOL_BULLET)
32863303
)?;
3287-
} else {
3288-
let tool_call_start = ToolCallStart {
3289-
tool_call_id: tool_use.id.clone(),
3290-
tool_call_name: tool_use.name.clone(),
3291-
mcp_server_name: if let Tool::Custom(ref tool) = tool_use.tool {
3292-
Some(tool.server_name.clone())
3293-
} else {
3294-
None
3295-
},
3296-
is_trusted: trusted,
3297-
parent_message_id: None,
3298-
};
3299-
self.stdout.send(Event::ToolCallStart(tool_call_start))?;
33003304
}
33013305

33023306
tool_use

crates/chat-cli/src/mcp_client/oauth_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub struct HttpServiceBuilder<'a> {
201201
}
202202

203203
impl<'a> HttpServiceBuilder<'a> {
204+
#[allow(clippy::too_many_arguments)]
204205
pub fn new(
205206
server_name: &'a str,
206207
os: &'a Os,
@@ -527,7 +528,7 @@ async fn get_auth_manager_impl(
527528
.and_then(|cfg| cfg.redirect_uri.as_ref())
528529
.and_then(|uri| {
529530
// Parse port from redirect_uri like "127.0.0.1:7778" or ":7778"
530-
uri.split(':').last().and_then(|p| p.parse::<u16>().ok())
531+
uri.split(':').next_back().and_then(|p| p.parse::<u16>().ok())
531532
})
532533
.unwrap_or(0); // Port 0 = OS assigns random available port
533534

0 commit comments

Comments
 (0)