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