Skip to main content

sim_lib_skill/
manifest.rs

1use sim_kernel::{AbiVersion, Lib, LibManifest, LibTarget, Linker, Result, Symbol, Version};
2
3use crate::{SKILL_LIB_ID, SkillFunction, SkillRegistry, ops::SkillFunctionKind};
4
5/// Loadable library that registers the `skill/*` operations and registry.
6///
7/// Loading `SkillLib` installs the [`SkillRegistry`] value and binds the
8/// install, bind, list, card, and call functions, plus the feature-gated
9/// audit, tool, runner, and serve surfaces.
10pub struct SkillLib;
11
12impl Lib for SkillLib {
13    fn manifest(&self) -> LibManifest {
14        LibManifest {
15            id: manifest_name(),
16            version: Version(env!("CARGO_PKG_VERSION").to_owned()),
17            abi: AbiVersion { major: 0, minor: 1 },
18            target: LibTarget::HostRegistered,
19            requires: Vec::new(),
20            capabilities: Vec::new(),
21            exports: crate::ops::skill_exports(),
22        }
23    }
24
25    fn load(&self, cx: &mut sim_kernel::LoadCx, linker: &mut Linker<'_>) -> Result<()> {
26        linker.value(
27            crate::skill_registry_symbol(),
28            cx.factory()
29                .opaque(std::sync::Arc::new(SkillRegistry::default()))?,
30        )?;
31        for kind in [
32            SkillFunctionKind::Install,
33            SkillFunctionKind::Bind,
34            SkillFunctionKind::List,
35            SkillFunctionKind::Card,
36            SkillFunctionKind::Call,
37            #[cfg(any(feature = "cache", feature = "cassette"))]
38            SkillFunctionKind::Audit,
39            #[cfg(feature = "agent")]
40            SkillFunctionKind::AsTool,
41            #[cfg(feature = "mcp")]
42            SkillFunctionKind::McpTools,
43            #[cfg(feature = "mcp")]
44            SkillFunctionKind::McpCall,
45            #[cfg(feature = "openai")]
46            SkillFunctionKind::OpenAiTool,
47            #[cfg(feature = "openai")]
48            SkillFunctionKind::OpenAiTools,
49            #[cfg(feature = "runner")]
50            SkillFunctionKind::AsRunner,
51            #[cfg(feature = "serve")]
52            SkillFunctionKind::ServeMcp,
53        ] {
54            let function = SkillFunction::value(kind);
55            linker.function_value(function.symbol(), cx.factory().opaque(function)?)?;
56        }
57        Ok(())
58    }
59}
60
61/// Returns the manifest identifier symbol for [`SkillLib`].
62pub fn manifest_name() -> Symbol {
63    Symbol::new(SKILL_LIB_ID)
64}
65
66pub use crate::ops::skill_exports;