Skip to main content

Available APIs

Lua CLI v3.0.0 provides a comprehensive set of APIs for building AI agents:

Core Classes

LuaAgent, LuaSkill, LuaTool - Agent configuration and building blocks

Automation

LuaJob, LuaWebhook - Scheduled tasks and HTTP endpoints

Message Processing

PreProcessor, PostProcessor - Filter and format messages

External Tools

LuaMCPServer - Connect MCP servers for external tool integrations

Platform APIs

AI, User, Data, CDN, Products, Baskets, Orders, Jobs, Templates - Built-in services

Environment

env() - Secure configuration management
New in v3.0.0: LuaAgent, LuaJob, LuaWebhook, PreProcessor, PostProcessor, and Jobs API for comprehensive agent development.

Installation

npm install lua-cli zod
zod is a peer dependency required for schema validation

Quick Start

Import APIs

// Core classes (v3.0.0)
import { 
  LuaAgent, 
  LuaSkill, 
  LuaTool, 
  LuaWebhook, 
  LuaJob,
  LuaMCPServer,
  PreProcessor,
  PostProcessor
} from 'lua-cli';

// Platform APIs
import { AI, User, Data, CDN, Products, Baskets, Orders, Jobs, Templates } from 'lua-cli';

// Utilities
import { env } from 'lua-cli';

// Type definitions
import { BasketStatus, OrderStatus } from 'lua-cli';

// Schema validation
import { z } from 'zod';

Create an Agent (v3.0.0 Pattern)

import { LuaAgent, LuaSkill, LuaTool } from 'lua-cli';
import { z } from 'zod';

// Define a tool
class MyTool implements LuaTool {
  name = "my_tool";
  description = "What the tool does";
  inputSchema = z.object({
    param: z.string()
  });

  async execute(input: any) {
    return { result: "success" };
  }
}

// Create a skill
const skill = new LuaSkill({
  name: "my-skill",
  description: "My custom skill",
  context: "When to use this skill and its tools",
  tools: [new MyTool()]
});

// Create agent (v3.0.0)
export const agent = new LuaAgent({
  name: "my-agent",
  persona: "You are a helpful assistant...",
  skills: [skill]
});

Core Classes

Agent Configuration

LuaAgent

New in v3.0.0 - Unified agent configuration
new LuaAgent({
  name: "my-agent",
  persona: "...",
  skills: [...],
  webhooks: [...],
  jobs: [...]
})

Building Blocks

LuaSkill

Collection of related tools
new LuaSkill({
  name: "skill-name",
  tools: [...]
})

LuaTool

Individual function the AI can call
class MyTool implements LuaTool {
  name = "tool_name"
  execute(input) { ... }
}

Automation

LuaWebhook

New in v3.0.0 - HTTP endpoints for external events
new LuaWebhook({
  name: "payment-webhook",
  execute: async (event) => { ... }
})

LuaJob

New in v3.0.0 - Scheduled tasks
new LuaJob({
  name: "daily-report",
  schedule: { type: "cron", pattern: "0 9 * * *" },
  execute: async (job) => { ... }
})

Message Processing

PreProcessor

New in v3.0.0 - Filter messages before agent
new PreProcessor({
  name: "profanity-filter",
  execute: async (message, user) => { ... }
})

PostProcessor

New in v3.0.0 - Format responses after agent
new PostProcessor({
  name: "add-disclaimer",
  execute: async (user, message, response, channel) => { ... }
})

Platform APIs

AI API

New! Generate AI responses with custom context in your tools:
import { AI } from 'lua-cli';

const response = await AI.generate(
  'You are a helpful sales assistant.',
  [{ type: 'text', text: 'What products do you recommend?' }]
);
Use cases:
  • Product descriptions
  • Image analysis
  • Content summarization
  • Translation
  • Recommendations
  • Document Q&A

Full Documentation

User API

Access user information:
import { User } from 'lua-cli';

// Get current user (from conversation context)
const user = await User.get();

// Get specific user by ID (useful in webhooks/jobs)
const specificUser = await User.get(userId);

// Direct property access
console.log(user.name);
console.log(user.email);
Use cases:
  • Get current user in tools
  • Get specific user in webhooks (payment notifications)
  • Send messages to specific users in jobs
  • Update user profiles

Full Documentation

Data API

Custom data storage with vector search:
import { Data } from 'lua-cli';

// Create
await Data.create('collection', data, searchText);

// Search semantically
const results = await Data.search('collection', 'query', 10, 0.7);

// Get/Update/Delete
await Data.get('collection', filter);
await Data.update('collection', id, data);
await Data.delete('collection', id);

Full Documentation

CDN API

Upload and retrieve files from the CDN:
import { CDN } from 'lua-cli';

// Upload a file
const file = new File([buffer], 'image.png', { type: 'image/png' });
const fileId = await CDN.upload(file);

// Get file by ID
const retrievedFile = await CDN.get(fileId);
console.log(retrievedFile.name, retrievedFile.type);
Use cases:
  • Store user uploads
  • Image storage for AI analysis
  • Document management
  • Asset management

Full Documentation

Products API

E-commerce product catalog:
import { Products } from 'lua-cli';

// Search
const products = await Products.search('laptop');

// CRUD
await Products.create({ name, price });
await Products.update({ price }, id);
await Products.getById(id);
await Products.delete(id);

Full Documentation

Baskets API

Shopping cart management:
import { Baskets, BasketStatus } from 'lua-cli';

// Create basket
const basket = await Baskets.create({ currency: 'USD' });

// Add items
await Baskets.addItem(basket.id, {
  id: productId,
  price: 29.99,
  quantity: 2
});

// Checkout
const order = await Baskets.placeOrder(orderData, basket.id);

Full Documentation

Orders API

Order processing and tracking:
import { Orders, OrderStatus } from 'lua-cli';

// Create order
const order = await Orders.create({
  basketId,
  data: { shippingAddress, paymentMethod }
});

// Update status
await Orders.updateStatus(OrderStatus.FULFILLED, orderId);

Full Documentation

Jobs API

New in v3.0.0 - Dynamically create scheduled tasks from tools:
import { Jobs } from 'lua-cli';

// Create a reminder job
const job = await Jobs.create({
  name: 'user-reminder',
  metadata: { message: 'Meeting in 10 minutes' },
  schedule: {
    type: 'once',
    executeAt: new Date(Date.now() + 600000)
  },
  execute: async (jobInstance) => {
    const user = await jobInstance.user();
    await user.send([{
      type: 'text',
      text: jobInstance.metadata.message
    }]);
  }
});

Full Documentation

Templates API

Send template messages across different channels:
import { Templates } from 'lua-cli';

// List WhatsApp templates
const result = await Templates.whatsapp.list(channelId);

// Send template message
await Templates.whatsapp.send(channelId, templateId, {
  phoneNumbers: ['+447551166594'],
  values: {
    body: { name: 'John', order_number: '12345' }
  }
});
Supported template types:
  • Templates.whatsapp - WhatsApp Business templates

Full Documentation

Environment Variables

Secure configuration management:
import { env } from 'lua-cli';

const apiKey = env('EXTERNAL_API_KEY');
const baseUrl = env('API_BASE_URL') || 'https://default.com';

Full Documentation

Type Definitions

All APIs are fully typed for TypeScript:
import { 
  LuaSkill, 
  LuaTool, 
  BasketStatus, 
  OrderStatus 
} from 'lua-cli';

// Autocomplete and type checking work everywhere
const user = await User.get();  // user is typed
const products = await Products.get(); // products is typed

Common Patterns

External API Integration

export class WeatherTool implements LuaTool {
  name = "get_weather";
  description = "Get current weather";
  inputSchema = z.object({ city: z.string() });

  async execute(input: any) {
    const response = await fetch(
      `https://api.weather.com?city=${input.city}`
    );
    return await response.json();
  }
}

Using Platform APIs

export class ShoppingTool implements LuaTool {
  async execute(input: any) {
    // Search products
    const products = await Products.search(input.query);
    
    // Create basket
    const basket = await Baskets.create({ currency: 'USD' });
    
    // Add item
    await Baskets.addItem(basket.id, {
      id: products.data[0].id,
      price: products.data[0].price,
      quantity: 1
    });
    
    return { basketId: basket.id };
  }
}
export class CreateNoteTool implements LuaTool {
  async execute(input: any) {
    // Create with search indexing
    const note = await Data.create('notes', {
      title: input.title,
      content: input.content
    }, `${input.title} ${input.content}`);
    
    return { noteId: note.id };
  }
}

export class SearchNotesTool implements LuaTool {
  async execute(input: any) {
    // Semantic search
    const results = await Data.search(
      'notes',
      input.query,
      10,
      0.7
    );
    
    return { notes: results.data };
  }
}

API Reference Pages

Core Classes

LuaAgent

v3.0.0 Agent configuration

LuaSkill

Skill class API

LuaTool

Tool interface

LuaWebhook

v3.0.0 HTTP webhooks

LuaJob

v3.0.0 Scheduled tasks

LuaMCPServer

MCP external tools

PreProcessor

v3.0.0 Message filtering

PostProcessor

v3.0.0 Response formatting

Runtime APIs

Lua

NEW Request context API

AI

NEW AI generation API

User

User data API

Data

Custom data API

CDN

File storage API

Products

Products API

Baskets

Baskets API

Orders

Orders API

Jobs

v3.0.0 Jobs API

Templates

NEW Template messaging

Utilities

Environment

Environment utilities

Best Practices

All APIs are fully typed. Use TypeScript for:
  • Autocomplete
  • Type checking
  • Better IDE support
Always use Zod schemas for input validation:
inputSchema = z.object({
  email: z.string().email(),
  age: z.number().min(0)
});
Implement proper error handling:
try {
  const result = await api.call();
  return result;
} catch (error) {
  throw new Error(`Operation failed: ${error.message}`);
}
Never hardcode secrets:
const apiKey = env('API_KEY');
if (!apiKey) {
  throw new Error('API_KEY not configured');
}

Next Steps

1

Explore Core Classes

Learn about LuaSkill and LuaTool
2

Study Platform APIs

Explore User, Data, Products, etc.
3

See Examples

Check out Tool Examples for working code
4

Build Something