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