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