use caliban_provider::{ContentBlock, Message, Role, TextBlock};
const DEFERRED_BLOCK_TEMPLATE: &str = "Some MCP tools are deferred to keep your tool palette lean. \
Use the `ToolSearch` tool with a substring query to discover \
and activate them when needed; activated tools persist for the \
rest of the session. {N} MCP tools are currently deferred.";
fn format_block(dropped: usize) -> String {
DEFERRED_BLOCK_TEMPLATE.replace("{N}", &dropped.to_string())
}
pub fn splice_into_messages(messages: &mut Vec<Message>, lazy_mcp: bool, dropped: usize) {
if !lazy_mcp || dropped == 0 {
return;
}
let block = format_block(dropped);
if let Some(first) = messages.first_mut()
&& matches!(first.role, Role::System)
{
if let Some(ContentBlock::Text(t)) = first.content.first_mut() {
t.text.push_str("\n\n");
t.text.push_str(&block);
} else {
first.content.insert(
0,
ContentBlock::Text(TextBlock {
text: block.clone(),
cache_control: None,
}),
);
}
return;
}
messages.insert(
0,
Message {
role: Role::System,
content: vec![ContentBlock::Text(TextBlock {
text: block,
cache_control: None,
})],
},
);
}