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
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
Building Blocks
Automation
Message Processing
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
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
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 );
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
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 );
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 );
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 );
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
}]);
}
});
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
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' ;
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 ();
}
}
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 };
}
}
Custom Data with Search
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
Runtime APIs
Utilities
Best Practices
All APIs are fully typed. Use TypeScript for:
Autocomplete
Type checking
Better IDE support
Implement proper error handling: try {
const result = await api . call ();
return result ;
} catch ( error ) {
throw new Error ( `Operation failed: ${ error . message } ` );
}
Use Environment Variables
Never hardcode secrets: const apiKey = env ( 'API_KEY' );
if ( ! apiKey ) {
throw new Error ( 'API_KEY not configured' );
}
Next Steps