Skip to main content

a2ui_base/catalog/
function_api.rs

1//! Function API and implementation traits for A2UI client-side functions.
2
3use std::collections::HashMap;
4
5use crate::error::A2uiError;
6use crate::model::data_context::DataContext;
7
8/// The return type of a function.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ReturnType {
11    String,
12    Number,
13    Boolean,
14    Array,
15    Object,
16    Any,
17    Void,
18}
19
20/// A function implementation that can be executed by the A2UI runtime.
21pub trait FunctionImplementation: Send + Sync + 'static {
22    /// The function name as it appears in the catalog.
23    fn name(&self) -> &'static str;
24
25    /// The return type of this function.
26    fn return_type(&self) -> ReturnType;
27
28    /// Execute the function with resolved arguments.
29    ///
30    /// Args are already resolved (dynamic values evaluated) by the DataContext.
31    fn execute(
32        &self,
33        args: &HashMap<String, serde_json::Value>,
34        context: &DataContext,
35    ) -> Result<serde_json::Value, A2uiError>;
36}