# Robomotion Rust SDK

Official Rust SDK for building [Robomotion](https://robomotion.io) RPA packages.

## Overview

Robomotion is a Robotic Process Automation (RPA) platform that allows you to build automation workflows using visual flow designers. This SDK enables you to create custom nodes (packages) in Rust that can be used within Robomotion flows.

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
robomotion = "0.1"
tokio = { version = "1", features = ["full"] }
async-trait = "0.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
```

## Quick Start

### 1. Create a new node

```rust
use robomotion::prelude::*;
use robomotion::message::Context;

#[derive(Node, Default)]
#[node(id = "MyPackage.Hello", name = "Hello", icon = "mdiHand", color = "#3498db")]
pub struct HelloNode {
    #[serde(flatten)]
    pub node: NodeBase,

    #[input(title = "Name", var_type = "string", scope = "Message", name = "name")]
    pub in_name: InVariable<String>,

    #[output(title = "Greeting", var_type = "string", scope = "Message", name = "greeting")]
    pub out_greeting: OutVariable<String>,
}

#[async_trait]
impl MessageHandler for HelloNode {
    async fn on_create(&mut self) -> Result<()> {
        Ok(())
    }

    async fn on_message(&mut self, ctx: &mut Context) -> Result<()> {
        let name = self.in_name.get(ctx).await?;
        self.out_greeting.set(ctx, format!("Hello, {}!", name)).await?;
        Ok(())
    }

    async fn on_close(&mut self) -> Result<()> {
        Ok(())
    }
}
```

### 2. Register and start

```rust
use robomotion::prelude::*;

mod hello;

#[tokio::main]
async fn main() {
    register_node::<hello::HelloNode>();
    start().await;
}
```

### 3. Create config.json

```json
{
  "name": "My Package",
  "namespace": "MyPackage",
  "version": "1.0.0",
  "language": "Rust",
  "platforms": ["linux", "windows", "darwin"]
}
```

> **Important**: All node IDs must start with the namespace from config.json. If namespace is `MyPackage`, node IDs must be `MyPackage.NodeName`.

## Features

- **Strongly-typed variables**: `InVariable<T>`, `OutVariable<T>`, `OptVariable<T>`
- **Async lifecycle methods**: `on_create`, `on_message`, `on_close`
- **Credential/Vault access**: Secure access to stored credentials
- **Large Message Objects (LMO)**: Automatic handling of payloads >256KB
- **AI Tool support**: Expose nodes as AI-callable tools
- **OAuth2 support**: Browser-based authorization flows
- **Debug mode**: Attach mode for rapid development

## Variable Types

| Type | Usage | Access |
|------|-------|--------|
| `InVariable<T>` | Required input | `.get(ctx).await` |
| `OptVariable<T>` | Optional input | `.get(ctx).await` returns `Option<T>` |
| `OutVariable<T>` | Output | `.set(ctx, value).await` |
| `Credential` | Vault access | `.get(ctx).await` returns credentials |

## Node Attributes

```rust
#[derive(Node, Default)]
#[node(
    id = "Namespace.NodeName",  // Must match config.json namespace
    name = "Display Name",
    icon = "mdiIcon",
    color = "#3498db",
    inputs = 1,
    outputs = 1
)]
```

## Documentation

- [How to Write a Package](https://github.com/robomotionio/robomotion-rust/blob/main/docs/how-to-write-a-package.md)
- [API Documentation](https://docs.rs/robomotion)

## License

MIT License - see [LICENSE](LICENSE) for details.

## Links

- [Robomotion Website](https://robomotion.io)
- [GitHub Repository](https://github.com/robomotionio/robomotion-rust)
- [Go SDK](https://github.com/robomotionio/robomotion-go)
