Skip to main content

lash_plugin_tool_discovery/
plugin.rs

1use std::sync::Arc;
2
3use lash_core::ToolProvider;
4use lash_core::plugin::{
5    PluginError, PluginFactory, PluginSessionContext, PluginSpec, SessionPlugin,
6    StaticPluginFactory,
7};
8
9use crate::service::tool_discovery_provider;
10use crate::surface::rlm_tool_surface;
11
12/// Plugin factory for the `search_tools` discovery surface.
13///
14/// Declares its provider and tool-surface contribution through a
15/// [`PluginSpec`] driven by [`StaticPluginFactory`], so it does not
16/// hand-roll the `SessionPlugin` + `register` ceremony.
17pub struct ToolDiscoveryPluginFactory {
18    inner: StaticPluginFactory,
19}
20
21impl ToolDiscoveryPluginFactory {
22    pub fn new() -> Self {
23        let spec = PluginSpec::new()
24            .with_tool_provider(Arc::new(tool_discovery_provider()) as Arc<dyn ToolProvider>)
25            .with_tool_surface_contributor(Arc::new(rlm_tool_surface));
26        Self {
27            inner: StaticPluginFactory::new("tool_discovery", spec),
28        }
29    }
30}
31
32impl Default for ToolDiscoveryPluginFactory {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38impl PluginFactory for ToolDiscoveryPluginFactory {
39    fn id(&self) -> &'static str {
40        self.inner.id()
41    }
42
43    fn build(&self, ctx: &PluginSessionContext) -> Result<Arc<dyn SessionPlugin>, PluginError> {
44        self.inner.build(ctx)
45    }
46}