Skip to main content

alef_core/config/
extras.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
4#[serde(rename_all = "lowercase")]
5pub enum Language {
6    Python,
7    Node,
8    Ruby,
9    Php,
10    Elixir,
11    Wasm,
12    Ffi,
13    Go,
14    Java,
15    Csharp,
16    R,
17}
18
19impl std::fmt::Display for Language {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            Self::Python => write!(f, "python"),
23            Self::Node => write!(f, "node"),
24            Self::Ruby => write!(f, "ruby"),
25            Self::Php => write!(f, "php"),
26            Self::Elixir => write!(f, "elixir"),
27            Self::Wasm => write!(f, "wasm"),
28            Self::Ffi => write!(f, "ffi"),
29            Self::Go => write!(f, "go"),
30            Self::Java => write!(f, "java"),
31            Self::Csharp => write!(f, "csharp"),
32            Self::R => write!(f, "r"),
33        }
34    }
35}
36
37/// A parameter in an adapter function.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct AdapterParam {
40    pub name: String,
41    #[serde(rename = "type")]
42    pub ty: String,
43    #[serde(default)]
44    pub optional: bool,
45}
46
47/// The kind of adapter pattern.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(rename_all = "snake_case")]
50pub enum AdapterPattern {
51    SyncFunction,
52    AsyncMethod,
53    CallbackBridge,
54    Streaming,
55    ServerLifecycle,
56}
57
58/// Configuration for a single adapter.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct AdapterConfig {
61    pub name: String,
62    pub pattern: AdapterPattern,
63    /// Full Rust path to the core function/method (e.g., "html_to_markdown_rs::convert")
64    pub core_path: String,
65    /// Parameters
66    #[serde(default)]
67    pub params: Vec<AdapterParam>,
68    /// Return type name
69    pub returns: Option<String>,
70    /// Error type name
71    pub error_type: Option<String>,
72    /// For async_method/streaming: the owning type name
73    pub owner_type: Option<String>,
74    /// For streaming: the item type
75    pub item_type: Option<String>,
76    /// For Python: release GIL during call
77    #[serde(default)]
78    pub gil_release: bool,
79    /// For callback_bridge: the Rust trait to implement (e.g., "SpikardHandler")
80    #[serde(default)]
81    pub trait_name: Option<String>,
82    /// For callback_bridge: the trait method name (e.g., "handle")
83    #[serde(default)]
84    pub trait_method: Option<String>,
85    /// For callback_bridge: whether to detect async callbacks at construction time
86    #[serde(default)]
87    pub detect_async: bool,
88}