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