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    Rust,
18    Kotlin,
19    Swift,
20    Dart,
21    Gleam,
22    Zig,
23    /// C consumer of the FFI layer — e2e test target, not a generated binding.
24    C,
25}
26
27impl std::fmt::Display for Language {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        match self {
30            Self::Python => write!(f, "python"),
31            Self::Node => write!(f, "node"),
32            Self::Ruby => write!(f, "ruby"),
33            Self::Php => write!(f, "php"),
34            Self::Elixir => write!(f, "elixir"),
35            Self::Wasm => write!(f, "wasm"),
36            Self::Ffi => write!(f, "ffi"),
37            Self::Go => write!(f, "go"),
38            Self::Java => write!(f, "java"),
39            Self::Csharp => write!(f, "csharp"),
40            Self::R => write!(f, "r"),
41            Self::Rust => write!(f, "rust"),
42            Self::Kotlin => write!(f, "kotlin"),
43            Self::Swift => write!(f, "swift"),
44            Self::Dart => write!(f, "dart"),
45            Self::Gleam => write!(f, "gleam"),
46            Self::Zig => write!(f, "zig"),
47            Self::C => write!(f, "c"),
48        }
49    }
50}
51
52/// A parameter in an adapter function.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct AdapterParam {
55    pub name: String,
56    #[serde(rename = "type")]
57    pub ty: String,
58    #[serde(default)]
59    pub optional: bool,
60}
61
62/// The kind of adapter pattern.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(rename_all = "snake_case")]
65pub enum AdapterPattern {
66    SyncFunction,
67    AsyncMethod,
68    CallbackBridge,
69    Streaming,
70    ServerLifecycle,
71}
72
73/// Configuration for a single adapter.
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct AdapterConfig {
76    pub name: String,
77    pub pattern: AdapterPattern,
78    /// Full Rust path to the core function/method (e.g., "html_to_markdown_rs::convert")
79    pub core_path: String,
80    /// Parameters
81    #[serde(default)]
82    pub params: Vec<AdapterParam>,
83    /// Return type name
84    pub returns: Option<String>,
85    /// Error type name
86    pub error_type: Option<String>,
87    /// For async_method/streaming: the owning type name
88    pub owner_type: Option<String>,
89    /// For streaming: the item type
90    pub item_type: Option<String>,
91    /// For Python: release GIL during call
92    #[serde(default)]
93    pub gil_release: bool,
94    /// For callback_bridge: the Rust trait to implement (e.g., "MyHandler")
95    #[serde(default)]
96    pub trait_name: Option<String>,
97    /// For callback_bridge: the trait method name (e.g., "handle")
98    #[serde(default)]
99    pub trait_method: Option<String>,
100    /// For callback_bridge: whether to detect async callbacks at construction time
101    #[serde(default)]
102    pub detect_async: bool,
103}