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