robit_chatbot/extensions.rs
1//! Extension keys for ToolContext.extensions map.
2//!
3//! Each key identifies a platform-specific extension that tools can access
4//! via `ctx.extensions.get(key)` and downcast to the appropriate trait.
5
6use std::any::Any;
7use std::sync::Arc;
8
9use crate::frontend::PlatformExt;
10
11/// Extension keys for ToolContext.extensions.
12pub mod keys {
13 /// Platform file/media operations (upload, send).
14 /// Value type: `Arc<PlatformExtWrapper>`
15 pub const PLATFORM_EXT: &str = "chatbot.platform_ext";
16}
17
18/// Wrapper that makes `Arc<dyn PlatformExt>` storable in the `Any`-based
19/// extensions map. Use `downcast_ref::<PlatformExtWrapper>()` to retrieve it.
20pub struct PlatformExtWrapper(pub Arc<dyn PlatformExt>);
21
22impl PlatformExtWrapper {
23 /// Wrap a `PlatformExt` implementation for storage in ToolContext.extensions.
24 pub fn new(ext: Arc<dyn PlatformExt>) -> Arc<dyn Any + Send + Sync> {
25 Arc::new(Self(ext))
26 }
27}