50 lines
1.6 KiB
Rust
50 lines
1.6 KiB
Rust
use std::collections::BTreeSet;
|
|
|
|
use akode_features::Features;
|
|
use akode_protocol::models::ResponseItem;
|
|
|
|
use crate::context::ContextualUserFragment;
|
|
use crate::context::PluginInstructions;
|
|
use crate::plugins::PluginCapabilitySummary;
|
|
use crate::plugins::render_explicit_plugin_instructions;
|
|
use akode_mcp::ToolInfo;
|
|
|
|
pub(crate) fn build_plugin_injections(
|
|
mentioned_plugins: &[PluginCapabilitySummary],
|
|
mcp_tools: &[ToolInfo],
|
|
features: &Features,
|
|
model_messages: akode_prompts::ResolvedModelMessages<'_>,
|
|
) -> Vec<ResponseItem> {
|
|
if mentioned_plugins.is_empty() {
|
|
return Vec::new();
|
|
}
|
|
|
|
let messages = model_messages.selected_plugin();
|
|
// Turn each explicit plugin mention with available capabilities into a developer hint.
|
|
mentioned_plugins
|
|
.iter()
|
|
.filter_map(|plugin| {
|
|
let available_mcp_servers = mcp_tools
|
|
.iter()
|
|
.filter(|tool| {
|
|
tool.plugin_display_names
|
|
.iter()
|
|
.any(|plugin_name| plugin_name == &plugin.display_name)
|
|
})
|
|
.map(|tool| tool.server_name.clone())
|
|
.collect::<BTreeSet<String>>()
|
|
.into_iter()
|
|
.collect::<Vec<_>>();
|
|
render_explicit_plugin_instructions(
|
|
plugin,
|
|
&available_mcp_servers,
|
|
/*available_apps*/ &[],
|
|
features,
|
|
&messages,
|
|
)
|
|
.map(PluginInstructions::new)
|
|
.map(ContextualUserFragment::into)
|
|
})
|
|
.collect()
|
|
}
|