robomotion 0.1.3

Official Rust SDK for building Robomotion RPA packages
Documentation
//! Base node types and traits.

use serde::{Deserialize, Serialize};

/// Base node struct containing common properties.
///
/// All nodes embed this struct to inherit common functionality.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NodeBase {
    /// The scope of the node
    #[serde(default)]
    pub scope: String,

    /// Unique identifier for this node instance
    #[serde(default)]
    pub guid: String,

    /// Display name of the node
    #[serde(default)]
    pub name: String,

    /// Delay before executing the node (in seconds)
    #[serde(default, rename = "delayBefore")]
    pub delay_before: f32,

    /// Delay after executing the node (in seconds)
    #[serde(default, rename = "delayAfter")]
    pub delay_after: f32,

    /// Whether to continue flow execution on error
    #[serde(default, rename = "continueOnError")]
    pub continue_on_error: bool,
}

impl NodeBase {
    /// Create a new NodeBase with default values.
    pub fn new() -> Self {
        Self::default()
    }

    /// Get the GUID of this node.
    pub fn guid(&self) -> &str {
        &self.guid
    }
}

/// Trait for types that have a NodeBase.
pub trait HasNodeBase {
    /// Get a reference to the NodeBase.
    fn node_base(&self) -> &NodeBase;

    /// Get a mutable reference to the NodeBase.
    fn node_base_mut(&mut self) -> &mut NodeBase;
}

/// Trait for types that can be initialized as nodes.
pub trait Node: HasNodeBase + Send + Sync + 'static {
    /// Initialize the node with the runtime helper.
    fn init(&mut self) -> crate::runtime::Result<()> {
        Ok(())
    }
}

/// Marker trait for nodes that support AI tool functionality.
pub trait ToolNode: Node {}