lua-cli 3.1.0-alpha.3 → 3.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/api/cdn.api.service.d.ts +18 -0
- package/dist/api/cdn.api.service.js +43 -0
- package/dist/api/custom.data.api.service.d.ts +4 -3
- package/dist/api/custom.data.api.service.js +4 -3
- package/dist/api/developer.api.service.d.ts +54 -1
- package/dist/api/developer.api.service.js +89 -0
- package/dist/api/job.api.service.d.ts +33 -100
- package/dist/api/job.api.service.js +27 -11
- package/dist/api/lazy-instances.d.ts +16 -0
- package/dist/api/lazy-instances.js +32 -0
- package/dist/api/postprocessor.api.service.d.ts +3 -13
- package/dist/api/postprocessor.api.service.js +2 -4
- package/dist/api/preprocessor.api.service.d.ts +1 -8
- package/dist/api/preprocessor.api.service.js +1 -2
- package/dist/api/webhook.api.service.d.ts +1 -3
- package/dist/api/webhook.api.service.js +1 -1
- package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
- package/dist/api/whatsapp-templates.api.service.js +78 -0
- package/dist/api-exports.d.ts +153 -6
- package/dist/api-exports.js +177 -21
- package/dist/cli/command-definitions.js +34 -7
- package/dist/commands/admin.js +1 -1
- package/dist/commands/channels.js +1 -1
- package/dist/commands/chat.js +2 -4
- package/dist/commands/compile.js +23 -4
- package/dist/commands/evals.d.ts +8 -0
- package/dist/commands/evals.js +41 -0
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.d.ts +10 -1
- package/dist/commands/init.js +23 -46
- package/dist/commands/jobs.js +5 -5
- package/dist/commands/mcp.d.ts +18 -0
- package/dist/commands/mcp.js +393 -0
- package/dist/commands/push.js +174 -23
- package/dist/common/data.entry.instance.d.ts +1 -1
- package/dist/common/data.entry.instance.js +4 -4
- package/dist/common/job.instance.d.ts +59 -7
- package/dist/common/job.instance.js +84 -19
- package/dist/config/constants.d.ts +1 -0
- package/dist/config/constants.js +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/agent.d.ts +0 -3
- package/dist/interfaces/cdn.d.ts +24 -0
- package/dist/interfaces/cdn.js +5 -0
- package/dist/interfaces/compile.d.ts +1 -0
- package/dist/interfaces/custom.data.d.ts +3 -3
- package/dist/interfaces/index.d.ts +2 -1
- package/dist/interfaces/init.d.ts +0 -1
- package/dist/interfaces/jobs.d.ts +88 -132
- package/dist/interfaces/jobs.js +1 -1
- package/dist/interfaces/mcp.d.ts +64 -0
- package/dist/interfaces/mcp.js +5 -0
- package/dist/interfaces/postprocessors.d.ts +0 -3
- package/dist/interfaces/preprocessors.d.ts +0 -3
- package/dist/interfaces/webhooks.d.ts +0 -5
- package/dist/interfaces/whatsapp-templates.d.ts +104 -0
- package/dist/interfaces/whatsapp-templates.js +5 -0
- package/dist/types/api-contracts.d.ts +68 -14
- package/dist/types/compile.types.d.ts +5 -6
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +3 -1
- package/dist/types/skill.d.ts +181 -103
- package/dist/types/skill.js +123 -91
- package/dist/utils/agent-management.d.ts +3 -5
- package/dist/utils/agent-management.js +6 -8
- package/dist/utils/bundling.d.ts +4 -11
- package/dist/utils/bundling.js +24 -33
- package/dist/utils/compile.d.ts +17 -9
- package/dist/utils/compile.js +72 -88
- package/dist/utils/deployment.js +13 -7
- package/dist/utils/dev-api.js +1 -4
- package/dist/utils/dev-server.js +1 -1
- package/dist/utils/files.d.ts +11 -4
- package/dist/utils/files.js +17 -14
- package/dist/utils/init-agent.d.ts +1 -2
- package/dist/utils/init-agent.js +4 -6
- package/dist/utils/init-helpers.d.ts +4 -4
- package/dist/utils/init-helpers.js +10 -11
- package/dist/utils/job-management.js +0 -2
- package/dist/utils/mcp-server-management.d.ts +23 -0
- package/dist/utils/mcp-server-management.js +212 -0
- package/dist/utils/postprocessor-management.js +2 -4
- package/dist/utils/preprocessor-management.js +2 -4
- package/dist/utils/sandbox.d.ts +4 -2
- package/dist/utils/sandbox.js +38 -9
- package/dist/utils/webhook-management.js +1 -3
- package/dist/web/app.css +1505 -14
- package/dist/web/app.js +79 -64
- package/package.json +2 -6
- package/template/QUICKSTART.md +57 -774
- package/template/README.md +80 -907
- package/template/examples/README.md +106 -0
- package/template/{src → examples}/jobs/AbandonedBasketProcessorJob.ts +67 -14
- package/template/{src → examples}/jobs/DailyCleanupJob.ts +0 -3
- package/template/{src → examples}/jobs/DataMigrationJob.ts +0 -3
- package/template/{src → examples}/jobs/HealthCheckJob.ts +0 -3
- package/template/{src → examples}/postprocessors/modifyResponse.ts +3 -4
- package/template/examples/preprocessors/messageMatching.ts +35 -0
- package/template/{src → examples}/skills/basket.skill.ts +0 -1
- package/template/{src → examples}/skills/product.skill.ts +0 -1
- package/template/{src → examples}/skills/tools/GameScoreTrackerTool.ts +11 -15
- package/template/{src → examples}/skills/tools/OrderTool.ts +25 -0
- package/template/examples/skills/tools/PremiumFeatureTool.ts +98 -0
- package/template/{src → examples}/skills/tools/UserDataTool.ts +34 -0
- package/template/{src → examples}/skills/user.skill.ts +0 -1
- package/template/examples/webhooks/FileUploadWebhook.ts +86 -0
- package/template/{src → examples}/webhooks/PaymentWebhook.ts +12 -9
- package/template/examples/webhooks/UserEventWebhook.ts +105 -0
- package/template/package-lock.json +7895 -0
- package/template/package.json +1 -1
- package/template/src/index.ts +40 -22
- package/template/src/preprocessors/messageMatching.ts +0 -22
- package/template/src/webhooks/UserEventWebhook.ts +0 -77
- /package/template/{src → examples}/services/ApiService.ts +0 -0
- /package/template/{src → examples}/services/GetWeather.ts +0 -0
- /package/template/{src → examples}/skills/tools/BasketTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/CreateInlineJob.ts +0 -0
- /package/template/{src → examples}/skills/tools/CreatePostTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/CustomDataTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/GetWeatherTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/PaymentTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/ProductsTool.ts +0 -0
- /package/template/{src → examples}/skills/tools/SmartBasketTool.ts +0 -0
package/template/QUICKSTART.md
CHANGED
|
@@ -1,827 +1,110 @@
|
|
|
1
1
|
# 🚀 Quick Start Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
You've initialized a minimal Lua AI Agent. Here's how to get started:
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- [Getting Started](#getting-started)
|
|
8
|
-
- [Essential Commands](#essential-commands)
|
|
9
|
-
- [Understanding LuaAgent](#understanding-luaagent)
|
|
10
|
-
- [Project Structure](#project-structure)
|
|
11
|
-
- [Next Steps](#next-steps)
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## 🎯 Getting Started
|
|
16
|
-
|
|
17
|
-
Your project has been initialized with everything you need to build and deploy an AI agent!
|
|
18
|
-
|
|
19
|
-
### What's Included
|
|
20
|
-
|
|
21
|
-
✅ **Example Skills** - Pre-built tools for weather, user data, products, baskets, orders
|
|
22
|
-
✅ **Example Webhooks** - HTTP endpoints that receive external events
|
|
23
|
-
✅ **Example Jobs** - Scheduled tasks that run automatically
|
|
24
|
-
✅ **Example Processors** - Pre/post-process chat messages
|
|
25
|
-
✅ **LuaAgent Configuration** - Unified agent setup in `src/index.ts`
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## 🛠️ Essential Commands
|
|
30
|
-
|
|
31
|
-
### 1. Test Your Tools & Skills
|
|
32
|
-
|
|
33
|
-
Test individual tools interactively before deploying:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
lua test
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**What it does:**
|
|
40
|
-
- Lets you select a tool/webhook/job to test
|
|
41
|
-
- Prompts for input values
|
|
42
|
-
- Executes in a local sandbox
|
|
43
|
-
- Shows the output
|
|
44
|
-
|
|
45
|
-
**Perfect for:**
|
|
46
|
-
- Testing tool logic before deployment
|
|
47
|
-
- Debugging input/output schemas
|
|
48
|
-
- Validating webhook handlers
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
### 2. Chat with Your Agent
|
|
53
|
-
|
|
54
|
-
Have a conversation with your agent to see tools in action:
|
|
5
|
+
## Step 1: Chat with Your Agent
|
|
55
6
|
|
|
56
7
|
```bash
|
|
57
8
|
lua chat
|
|
58
9
|
```
|
|
59
10
|
|
|
60
|
-
|
|
61
|
-
- **🔧 Sandbox** - Test with your local code (not deployed yet)
|
|
62
|
-
- **🚀 Production** - Chat with your deployed agent
|
|
63
|
-
|
|
64
|
-
**Try asking:**
|
|
65
|
-
- "What's the weather in London?"
|
|
66
|
-
- "Show me all products"
|
|
67
|
-
- "Create a basket for user 123"
|
|
68
|
-
|
|
69
|
-
**Pro tip:** Use sandbox mode to test changes before deploying!
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
### 3. Deploy to Production
|
|
74
|
-
|
|
75
|
-
When ready, push your skills to the server:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
# Interactive deployment (recommended for first time)
|
|
79
|
-
lua push
|
|
80
|
-
|
|
81
|
-
# Or push all components at once
|
|
82
|
-
lua push all --force
|
|
83
|
-
|
|
84
|
-
# Push and deploy to production in one command
|
|
85
|
-
lua push all --force --auto-deploy
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
**What happens:**
|
|
89
|
-
1. Compiles your code
|
|
90
|
-
2. Bundles all tools/webhooks/jobs
|
|
91
|
-
3. Pushes new version to server
|
|
92
|
-
4. Updates `lua.skill.yaml` with new version
|
|
93
|
-
5. Optionally deploys to production
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## 🤖 Understanding LuaAgent
|
|
98
|
-
|
|
99
|
-
The `LuaAgent` is the **central configuration** for your AI agent. It's defined in `src/index.ts`:
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
export const agent = new LuaAgent({
|
|
103
|
-
name: 'my-assistant',
|
|
104
|
-
persona: 'You are a helpful AI assistant...',
|
|
105
|
-
welcomeMessage: 'Hello! How can I help you today?',
|
|
106
|
-
skills: [generalSkill, userSkill, productSkill],
|
|
107
|
-
webhooks: [paymentWebhook],
|
|
108
|
-
jobs: [dailyCleanupJob],
|
|
109
|
-
preProcessors: [messageMatchingProcessor],
|
|
110
|
-
postProcessors: [responseModifierProcessor]
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Key Properties
|
|
115
|
-
|
|
116
|
-
#### `name` (string)
|
|
117
|
-
- Your agent's identifier
|
|
118
|
-
- Used for logging and organization
|
|
119
|
-
- Example: `'customer-support-agent'`
|
|
120
|
-
|
|
121
|
-
#### `persona` (string)
|
|
122
|
-
- Defines your agent's personality and behavior
|
|
123
|
-
- How the AI should respond to users
|
|
124
|
-
- What tone and style to use
|
|
125
|
-
|
|
126
|
-
**Example:**
|
|
127
|
-
```typescript
|
|
128
|
-
persona: `You are Emma, a friendly customer support agent for Acme Corp.
|
|
129
|
-
You're helpful, patient, and always prioritize customer satisfaction.
|
|
130
|
-
Use a warm, professional tone and offer solutions proactively.`
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
#### `welcomeMessage` (string, optional)
|
|
134
|
-
- First message users see when starting a chat
|
|
135
|
-
- Should be welcoming and set expectations
|
|
136
|
-
|
|
137
|
-
**Example:**
|
|
138
|
-
```typescript
|
|
139
|
-
welcomeMessage: "Hi! I'm Emma from Acme Corp. How can I assist you today?"
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
#### `skills` (array of LuaSkill)
|
|
143
|
-
- Collections of tools grouped by functionality
|
|
144
|
-
- Each skill contains multiple related tools
|
|
145
|
-
- Agents can use all tools from all skills
|
|
146
|
-
|
|
147
|
-
**Example:**
|
|
148
|
-
```typescript
|
|
149
|
-
skills: [
|
|
150
|
-
generalSkill, // Weather, posts, calculations
|
|
151
|
-
productSkill, // Product search, CRUD operations
|
|
152
|
-
basketSkill, // Shopping cart management
|
|
153
|
-
orderSkill // Order processing
|
|
154
|
-
]
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
#### `webhooks` (array of LuaWebhook, optional)
|
|
158
|
-
- HTTP endpoints that receive external events
|
|
159
|
-
- Trigger actions based on external systems
|
|
160
|
-
- Examples: Payment notifications, order updates
|
|
161
|
-
|
|
162
|
-
**Example:**
|
|
163
|
-
```typescript
|
|
164
|
-
webhooks: [
|
|
165
|
-
paymentWebhook, // Stripe payment confirmations
|
|
166
|
-
userEventWebhook // External system notifications
|
|
167
|
-
]
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
#### `jobs` (array of LuaJob, optional)
|
|
171
|
-
- Scheduled tasks that run automatically
|
|
172
|
-
- Can be one-time, recurring, or cron-based
|
|
173
|
-
- Examples: Daily cleanups, health checks, reminders
|
|
174
|
-
|
|
175
|
-
**Example:**
|
|
176
|
-
```typescript
|
|
177
|
-
jobs: [
|
|
178
|
-
dailyCleanupJob, // Runs every day at midnight
|
|
179
|
-
abandonedBasketProcessor // Checks for abandoned baskets hourly
|
|
180
|
-
]
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
#### `preProcessors` (array of PreProcessor, optional)
|
|
184
|
-
- Run **before** messages reach the agent
|
|
185
|
-
- Modify, filter, or enhance incoming messages
|
|
186
|
-
- Examples: Profanity filtering, intent detection, routing
|
|
187
|
-
|
|
188
|
-
**Example:**
|
|
189
|
-
```typescript
|
|
190
|
-
preProcessors: [
|
|
191
|
-
messageMatchingProcessor // Routes messages based on patterns
|
|
192
|
-
]
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
#### `postProcessors` (array of PostProcessor, optional)
|
|
196
|
-
- Run **after** the agent generates a response
|
|
197
|
-
- Modify, enhance, or format responses
|
|
198
|
-
- Examples: Add disclaimers, translate, format
|
|
199
|
-
|
|
200
|
-
**Example:**
|
|
201
|
-
```typescript
|
|
202
|
-
postProcessors: [
|
|
203
|
-
responseModifierProcessor // Adds custom formatting
|
|
204
|
-
]
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## 📁 Project Structure
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
your-project/
|
|
213
|
-
├── src/
|
|
214
|
-
│ ├── index.ts # 🎯 Main file - LuaAgent definition
|
|
215
|
-
│ ├── skills/ # Skills grouped by functionality
|
|
216
|
-
│ │ ├── tools/ # Individual tool implementations
|
|
217
|
-
│ │ │ ├── GetWeatherTool.ts
|
|
218
|
-
│ │ │ ├── ProductsTool.ts
|
|
219
|
-
│ │ │ └── BasketTool.ts
|
|
220
|
-
│ │ ├── product.skill.ts # Product skill (groups product tools)
|
|
221
|
-
│ │ └── basket.skill.ts # Basket skill (groups basket tools)
|
|
222
|
-
│ ├── webhooks/ # HTTP webhook handlers
|
|
223
|
-
│ │ ├── PaymentWebhook.ts
|
|
224
|
-
│ │ └── UserEventWebhook.ts
|
|
225
|
-
│ ├── jobs/ # Scheduled background tasks
|
|
226
|
-
│ │ ├── DailyCleanupJob.ts
|
|
227
|
-
│ │ └── HealthCheckJob.ts
|
|
228
|
-
│ ├── preprocessors/ # Message preprocessors
|
|
229
|
-
│ │ └── messageMatching.ts
|
|
230
|
-
│ ├── postprocessors/ # Response postprocessors
|
|
231
|
-
│ │ └── modifyResponse.ts
|
|
232
|
-
│ └── services/ # Shared utilities
|
|
233
|
-
│ ├── ApiService.ts
|
|
234
|
-
│ └── GetWeather.ts
|
|
235
|
-
├── lua.skill.yaml # 📝 Configuration & metadata
|
|
236
|
-
├── package.json
|
|
237
|
-
└── tsconfig.json
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## 🎓 Key Concepts
|
|
243
|
-
|
|
244
|
-
### Skills vs Tools
|
|
245
|
-
|
|
246
|
-
**Tools** are individual functions:
|
|
247
|
-
```typescript
|
|
248
|
-
export default class GetWeatherTool implements LuaTool {
|
|
249
|
-
name = "get_weather";
|
|
250
|
-
description = "Get weather for a city";
|
|
251
|
-
// ... implementation
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
**Skills** group related tools:
|
|
256
|
-
```typescript
|
|
257
|
-
export const weatherSkill = new LuaSkill({
|
|
258
|
-
name: 'weather-skill',
|
|
259
|
-
description: 'Weather information tools',
|
|
260
|
-
context: 'Use these tools to get weather data',
|
|
261
|
-
tools: [getWeatherTool, forecastTool]
|
|
262
|
-
});
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
**Why?** Skills help organize tools and provide context to the AI about when to use them.
|
|
266
|
-
|
|
267
|
-
### The LuaAgent Advantage
|
|
268
|
-
|
|
269
|
-
Instead of exporting individual skills, webhooks, and jobs separately, the **LuaAgent** provides a single, unified configuration:
|
|
270
|
-
|
|
271
|
-
**❌ Old Way (Legacy):**
|
|
272
|
-
```typescript
|
|
273
|
-
export const skill1 = new LuaSkill({...});
|
|
274
|
-
export const skill2 = new LuaSkill({...});
|
|
275
|
-
export const webhook1 = new LuaWebhook({...});
|
|
276
|
-
// Hard to manage, hard to see the big picture
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
**✅ New Way (LuaAgent):**
|
|
280
|
-
```typescript
|
|
281
|
-
export const agent = new LuaAgent({
|
|
282
|
-
name: 'my-agent',
|
|
283
|
-
persona: '...',
|
|
284
|
-
skills: [skill1, skill2],
|
|
285
|
-
webhooks: [webhook1],
|
|
286
|
-
jobs: [job1]
|
|
287
|
-
});
|
|
288
|
-
// Everything in one place, easy to understand
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
**Benefits:**
|
|
292
|
-
- 📦 Single source of truth
|
|
293
|
-
- 🎯 Clear agent configuration
|
|
294
|
-
- 🔄 Automatic YAML sync
|
|
295
|
-
- 📝 Better organization
|
|
296
|
-
|
|
297
|
-
---
|
|
298
|
-
|
|
299
|
-
## 🧪 Development Workflow
|
|
300
|
-
|
|
301
|
-
### Typical Development Flow
|
|
302
|
-
|
|
303
|
-
1. **Create/Modify Tools**
|
|
304
|
-
```bash
|
|
305
|
-
# Edit your tools in src/skills/tools/
|
|
306
|
-
vim src/skills/tools/MyNewTool.ts
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
2. **Test Locally**
|
|
310
|
-
```bash
|
|
311
|
-
# Test the specific tool
|
|
312
|
-
lua test
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
3. **Chat Test (Sandbox)**
|
|
316
|
-
```bash
|
|
317
|
-
# Chat with your agent using local code
|
|
318
|
-
lua chat
|
|
319
|
-
# Select: Sandbox
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
4. **Compile**
|
|
323
|
-
```bash
|
|
324
|
-
# Bundle everything
|
|
325
|
-
lua compile
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
5. **Push to Server**
|
|
329
|
-
```bash
|
|
330
|
-
# Upload new version
|
|
331
|
-
lua push
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
6. **Chat Test (Production)**
|
|
335
|
-
```bash
|
|
336
|
-
# Chat with deployed agent
|
|
337
|
-
lua chat
|
|
338
|
-
# Select: Production
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
## 🚀 Quick Examples
|
|
344
|
-
|
|
345
|
-
### Example 1: Adding a New Tool
|
|
346
|
-
|
|
347
|
-
Create a new tool file:
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
// src/skills/tools/GreetingTool.ts
|
|
351
|
-
import { LuaTool } from "lua-cli/skill";
|
|
352
|
-
import { z } from "zod";
|
|
353
|
-
|
|
354
|
-
export default class GreetingTool implements LuaTool {
|
|
355
|
-
name = "greet_user";
|
|
356
|
-
description = "Generate a personalized greeting";
|
|
357
|
-
|
|
358
|
-
inputSchema = z.object({
|
|
359
|
-
name: z.string(),
|
|
360
|
-
language: z.enum(['en', 'es', 'fr']).optional()
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
364
|
-
const greetings = {
|
|
365
|
-
en: `Hello, ${input.name}!`,
|
|
366
|
-
es: `¡Hola, ${input.name}!`,
|
|
367
|
-
fr: `Bonjour, ${input.name}!`
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const lang = input.language || 'en';
|
|
371
|
-
return { greeting: greetings[lang] };
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
Add it to your skill:
|
|
11
|
+
Select **Sandbox** mode. Your agent is empty but functional - try chatting!
|
|
377
12
|
|
|
378
|
-
|
|
379
|
-
// src/skills/general.skill.ts
|
|
380
|
-
import GreetingTool from './tools/GreetingTool';
|
|
13
|
+
## Step 2: Create Your First Tool
|
|
381
14
|
|
|
382
|
-
|
|
383
|
-
name: 'general-skill',
|
|
384
|
-
description: 'General purpose utilities',
|
|
385
|
-
context: 'Use these for common tasks',
|
|
386
|
-
tools: [
|
|
387
|
-
new GetWeatherTool(),
|
|
388
|
-
new GreetingTool(), // ✅ Add your new tool
|
|
389
|
-
]
|
|
390
|
-
});
|
|
391
|
-
```
|
|
15
|
+
### Create the folders and files:
|
|
392
16
|
|
|
393
|
-
Test it:
|
|
394
17
|
```bash
|
|
395
|
-
|
|
396
|
-
# Select: greet_user
|
|
397
|
-
# Input name: "Alice"
|
|
398
|
-
# Input language: "es"
|
|
399
|
-
# Output: { greeting: "¡Hola, Alice!" }
|
|
18
|
+
mkdir -p src/skills/tools
|
|
400
19
|
```
|
|
401
20
|
|
|
402
|
-
###
|
|
21
|
+
### Create a tool (`src/skills/tools/MyTool.ts`):
|
|
403
22
|
|
|
404
23
|
```typescript
|
|
405
|
-
|
|
406
|
-
import { LuaJob, User } from "lua-cli";
|
|
407
|
-
|
|
408
|
-
export default new LuaJob({
|
|
409
|
-
name: "daily-report",
|
|
410
|
-
version: "1.0.0",
|
|
411
|
-
description: "Send daily summary to admin",
|
|
412
|
-
|
|
413
|
-
schedule: {
|
|
414
|
-
type: "cron",
|
|
415
|
-
pattern: "0 9 * * *" // Every day at 9 AM
|
|
416
|
-
},
|
|
417
|
-
|
|
418
|
-
execute: async (job) => {
|
|
419
|
-
const user = await job.user();
|
|
420
|
-
|
|
421
|
-
// Generate report
|
|
422
|
-
const report = `Daily Summary for ${new Date().toDateString()}`;
|
|
423
|
-
|
|
424
|
-
// Send to user
|
|
425
|
-
await user.send([{
|
|
426
|
-
type: "text",
|
|
427
|
-
text: report
|
|
428
|
-
}]);
|
|
429
|
-
|
|
430
|
-
return { success: true, sent: true };
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
Add to LuaAgent:
|
|
436
|
-
```typescript
|
|
437
|
-
import dailyReportJob from './jobs/DailyReportJob';
|
|
438
|
-
|
|
439
|
-
export const agent = new LuaAgent({
|
|
440
|
-
// ...
|
|
441
|
-
jobs: [dailyReportJob]
|
|
442
|
-
});
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
### Example 3: Creating a Webhook
|
|
446
|
-
|
|
447
|
-
```typescript
|
|
448
|
-
// src/webhooks/OrderWebhook.ts
|
|
449
|
-
import { LuaWebhook, Orders } from "lua-cli";
|
|
24
|
+
import { LuaTool } from "lua-cli";
|
|
450
25
|
import { z } from "zod";
|
|
451
26
|
|
|
452
|
-
export default
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
description: "Receive order updates from external systems",
|
|
456
|
-
|
|
457
|
-
bodySchema: z.object({
|
|
458
|
-
orderId: z.string(),
|
|
459
|
-
status: z.string(),
|
|
460
|
-
amount: z.number()
|
|
461
|
-
}),
|
|
462
|
-
|
|
463
|
-
execute: async ({ body }) => {
|
|
464
|
-
// Update order in your system
|
|
465
|
-
await Orders.updateStatus(body.status, body.orderId);
|
|
27
|
+
export default class MyTool implements LuaTool {
|
|
28
|
+
name = "my_tool";
|
|
29
|
+
description = "Does something useful";
|
|
466
30
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
body: { success: true, orderId: body.orderId }
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
---
|
|
476
|
-
|
|
477
|
-
## 📚 Available APIs
|
|
478
|
-
|
|
479
|
-
Your tools and jobs have access to these powerful APIs:
|
|
480
|
-
|
|
481
|
-
### User Data
|
|
482
|
-
```typescript
|
|
483
|
-
const user = await User.get();
|
|
484
|
-
await user.update({ preferences: 'dark mode' });
|
|
485
|
-
await user.send([{ type: "text", text: "Hello!" }]);
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
### Products
|
|
489
|
-
```typescript
|
|
490
|
-
const products = await Products.get();
|
|
491
|
-
const product = await Products.create({ name: "Widget", price: 29.99 });
|
|
492
|
-
await product.update({ price: 24.99 });
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
### Baskets
|
|
496
|
-
```typescript
|
|
497
|
-
const basket = await Baskets.create();
|
|
498
|
-
await basket.addItem({ productId: "123", quantity: 2 });
|
|
499
|
-
await basket.placeOrder();
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
### Orders
|
|
503
|
-
```typescript
|
|
504
|
-
const orders = await Orders.get();
|
|
505
|
-
await Orders.updateStatus('confirmed', orderId);
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
### Custom Data
|
|
509
|
-
```typescript
|
|
510
|
-
const movies = await Data.get('movies');
|
|
511
|
-
await Data.create('movies', { title: "Inception", year: 2010 });
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### Jobs (Dynamic)
|
|
515
|
-
```typescript
|
|
516
|
-
const job = await Jobs.create({
|
|
517
|
-
name: "remind-user",
|
|
518
|
-
schedule: { type: "once", executeAt: new Date(Date.now() + 3600000) },
|
|
519
|
-
metadata: { message: "Time for your meeting!" },
|
|
520
|
-
execute: async (job) => {
|
|
521
|
-
const user = await job.user();
|
|
522
|
-
await user.send([{ type: "text", text: job.metadata.message }]);
|
|
523
|
-
return { success: true };
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
---
|
|
529
|
-
|
|
530
|
-
## 🔑 Key Features
|
|
531
|
-
|
|
532
|
-
### Auto-Sync Between Code and YAML
|
|
533
|
-
|
|
534
|
-
Your `lua.skill.yaml` and `LuaAgent` in `index.ts` stay synchronized automatically:
|
|
535
|
-
|
|
536
|
-
**When you run `lua init`:**
|
|
537
|
-
- ✅ Agent name, persona, and welcome message are added to both YAML and code
|
|
538
|
-
|
|
539
|
-
**When you run `lua compile`:**
|
|
540
|
-
- ✅ LuaAgent persona and welcome message sync to YAML
|
|
541
|
-
|
|
542
|
-
**Why?** This ensures your configuration is always consistent!
|
|
543
|
-
|
|
544
|
-
### Environment Variables
|
|
545
|
-
|
|
546
|
-
Use `.env` for API keys and sensitive data:
|
|
547
|
-
|
|
548
|
-
```bash
|
|
549
|
-
# .env
|
|
550
|
-
OPENAI_API_KEY=your-key-here
|
|
551
|
-
STRIPE_SECRET_KEY=your-stripe-key
|
|
552
|
-
PINECONE_API_KEY=your-pinecone-key
|
|
553
|
-
LUA_API_KEY=your-lua-api-key # Optional: for CI/CD
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
Access in your code:
|
|
557
|
-
```typescript
|
|
558
|
-
import { env } from "lua-cli/skill";
|
|
559
|
-
|
|
560
|
-
const apiKey = env('OPENAI_API_KEY');
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
---
|
|
564
|
-
|
|
565
|
-
## 📖 Common Patterns
|
|
566
|
-
|
|
567
|
-
### Pattern 1: Tool with External API
|
|
568
|
-
|
|
569
|
-
```typescript
|
|
570
|
-
import { LuaTool } from "lua-cli/skill";
|
|
571
|
-
import { z } from "zod";
|
|
572
|
-
import axios from "axios";
|
|
573
|
-
import { env } from "lua-cli/skill";
|
|
574
|
-
|
|
575
|
-
export default class WeatherTool implements LuaTool {
|
|
576
|
-
name = "get_weather";
|
|
577
|
-
description = "Get current weather for a city";
|
|
578
|
-
|
|
579
|
-
inputSchema = z.object({
|
|
580
|
-
city: z.string()
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
584
|
-
const apiKey = env('WEATHER_API_KEY');
|
|
585
|
-
|
|
586
|
-
const response = await axios.get(`https://api.weather.com/current`, {
|
|
587
|
-
params: { city: input.city, apiKey }
|
|
31
|
+
inputSchema = z.object({
|
|
32
|
+
input: z.string().describe("What to process")
|
|
588
33
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
city: input.city
|
|
594
|
-
};
|
|
595
|
-
}
|
|
34
|
+
|
|
35
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
36
|
+
return { result: `Processed: ${input.input}` };
|
|
37
|
+
}
|
|
596
38
|
}
|
|
597
39
|
```
|
|
598
40
|
|
|
599
|
-
###
|
|
41
|
+
### Create a skill (`src/skills/my.skill.ts`):
|
|
600
42
|
|
|
601
43
|
```typescript
|
|
602
|
-
import {
|
|
603
|
-
import
|
|
604
|
-
|
|
605
|
-
export default class ReminderTool implements LuaTool {
|
|
606
|
-
name = "set_reminder";
|
|
607
|
-
description = "Set a reminder for later";
|
|
608
|
-
|
|
609
|
-
inputSchema = z.object({
|
|
610
|
-
message: z.string(),
|
|
611
|
-
delayMinutes: z.number()
|
|
612
|
-
});
|
|
44
|
+
import { LuaSkill } from "lua-cli";
|
|
45
|
+
import MyTool from "./tools/MyTool";
|
|
613
46
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
message: input.message // ✅ Pass data via metadata
|
|
621
|
-
},
|
|
622
|
-
schedule: {
|
|
623
|
-
type: "once",
|
|
624
|
-
executeAt: new Date(Date.now() + input.delayMinutes * 60000)
|
|
625
|
-
},
|
|
626
|
-
execute: async (jobInstance: JobInstance) => {
|
|
627
|
-
const user = await jobInstance.user();
|
|
628
|
-
const message = jobInstance.metadata.message;
|
|
629
|
-
|
|
630
|
-
await user.send([{
|
|
631
|
-
type: "text",
|
|
632
|
-
text: `⏰ Reminder: ${message}`
|
|
633
|
-
}]);
|
|
634
|
-
|
|
635
|
-
return { success: true };
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
return {
|
|
640
|
-
success: true,
|
|
641
|
-
message: `Reminder set for ${input.delayMinutes} minutes from now`,
|
|
642
|
-
jobId: job.id
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
}
|
|
47
|
+
export default new LuaSkill({
|
|
48
|
+
name: "my-skill",
|
|
49
|
+
description: "My custom skill",
|
|
50
|
+
context: "Use these tools when...",
|
|
51
|
+
tools: [new MyTool()],
|
|
52
|
+
});
|
|
646
53
|
```
|
|
647
54
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
### Pattern 3: Webhook that Triggers Job
|
|
55
|
+
### Add to your agent (`src/index.ts`):
|
|
651
56
|
|
|
652
57
|
```typescript
|
|
653
|
-
import {
|
|
654
|
-
import
|
|
58
|
+
import { LuaAgent } from "lua-cli";
|
|
59
|
+
import mySkill from "./skills/my.skill";
|
|
655
60
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
bodySchema: z.object({
|
|
662
|
-
orderId: z.string(),
|
|
663
|
-
userId: z.string()
|
|
664
|
-
}),
|
|
665
|
-
|
|
666
|
-
execute: async ({ body }) => {
|
|
667
|
-
// Create a job to process the order in 5 minutes
|
|
668
|
-
await Jobs.create({
|
|
669
|
-
name: `process-order-${body.orderId}`,
|
|
670
|
-
metadata: { orderId: body.orderId },
|
|
671
|
-
schedule: {
|
|
672
|
-
type: "once",
|
|
673
|
-
executeAt: new Date(Date.now() + 300000)
|
|
674
|
-
},
|
|
675
|
-
execute: async (job) => {
|
|
676
|
-
// Process order logic here
|
|
677
|
-
return { success: true };
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
return {
|
|
682
|
-
status: 200,
|
|
683
|
-
body: { received: true, orderId: body.orderId }
|
|
684
|
-
};
|
|
685
|
-
}
|
|
61
|
+
const agent = new LuaAgent({
|
|
62
|
+
name: `My Agent`,
|
|
63
|
+
persona: `You are a helpful assistant.`,
|
|
64
|
+
skills: [mySkill],
|
|
686
65
|
});
|
|
687
66
|
```
|
|
688
67
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
## 🎯 Next Steps
|
|
692
|
-
|
|
693
|
-
### 1. Customize Your Agent
|
|
694
|
-
|
|
695
|
-
Edit `src/index.ts` and update:
|
|
696
|
-
- Agent name
|
|
697
|
-
- Persona (how your agent behaves)
|
|
698
|
-
- Welcome message
|
|
699
|
-
|
|
700
|
-
### 2. Explore Example Tools
|
|
701
|
-
|
|
702
|
-
Look in `src/skills/tools/` to see:
|
|
703
|
-
- `GetWeatherTool.ts` - External API integration
|
|
704
|
-
- `ProductsTool.ts` - CRUD operations with Products API
|
|
705
|
-
- `BasketTool.ts` - Shopping cart management
|
|
706
|
-
- `GameScoreTrackerTool.ts` - Complex state management
|
|
707
|
-
|
|
708
|
-
### 3. Test Everything
|
|
68
|
+
## Step 3: Test Your Tool
|
|
709
69
|
|
|
710
70
|
```bash
|
|
711
|
-
# Test individual tools
|
|
712
71
|
lua test
|
|
713
|
-
|
|
714
|
-
# Chat with your agent
|
|
715
|
-
lua chat
|
|
716
|
-
|
|
717
|
-
# Compile and check for errors
|
|
718
|
-
lua compile
|
|
719
72
|
```
|
|
720
73
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
```bash
|
|
724
|
-
# Push new version
|
|
725
|
-
lua push
|
|
726
|
-
|
|
727
|
-
# Or push everything at once
|
|
728
|
-
lua push all --force --auto-deploy
|
|
729
|
-
```
|
|
74
|
+
Select your tool and provide test inputs.
|
|
730
75
|
|
|
731
|
-
|
|
76
|
+
## Step 4: Deploy
|
|
732
77
|
|
|
733
78
|
```bash
|
|
734
|
-
|
|
735
|
-
lua production
|
|
736
|
-
|
|
737
|
-
# Manage environment variables
|
|
738
|
-
lua env production
|
|
739
|
-
|
|
740
|
-
# Update persona
|
|
741
|
-
lua persona production
|
|
742
|
-
|
|
743
|
-
# View logs
|
|
744
|
-
lua logs
|
|
79
|
+
lua push all --force --auto-deploy
|
|
745
80
|
```
|
|
746
81
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
## 💡 Tips & Best Practices
|
|
750
|
-
|
|
751
|
-
### Tool Design
|
|
752
|
-
✅ **Clear names** - Use descriptive tool names like `get_weather`, not `weather`
|
|
753
|
-
✅ **Validate inputs** - Use Zod schemas to ensure data quality
|
|
754
|
-
✅ **Good descriptions** - Help the AI understand when to use your tool
|
|
755
|
-
✅ **Handle errors** - Return error messages instead of throwing
|
|
82
|
+
## 🎓 Need Examples?
|
|
756
83
|
|
|
757
|
-
|
|
758
|
-
✅ **Self-contained** - Jobs should not depend on parent scope variables
|
|
759
|
-
✅ **Use metadata** - Pass data through `metadata` field
|
|
760
|
-
✅ **Proper scheduling** - Choose appropriate schedule types (once, cron, interval)
|
|
761
|
-
✅ **Idempotent** - Jobs should be safe to run multiple times
|
|
84
|
+
Initialize a project with full examples:
|
|
762
85
|
|
|
763
|
-
### Webhook Design
|
|
764
|
-
✅ **Validate inputs** - Use schemas for query, headers, and body
|
|
765
|
-
✅ **Return proper status** - Use HTTP status codes (200, 400, etc.)
|
|
766
|
-
✅ **Handle failures** - Return error responses gracefully
|
|
767
|
-
✅ **Security** - Validate signatures for production webhooks
|
|
768
|
-
|
|
769
|
-
### Agent Persona
|
|
770
|
-
✅ **Be specific** - Define personality, tone, and behavior clearly
|
|
771
|
-
✅ **Set boundaries** - Explain what the agent can and cannot do
|
|
772
|
-
✅ **Give examples** - Show how the agent should respond
|
|
773
|
-
✅ **Update regularly** - Refine based on user interactions
|
|
774
|
-
|
|
775
|
-
---
|
|
776
|
-
|
|
777
|
-
## 🆘 Need Help?
|
|
778
|
-
|
|
779
|
-
### Commands
|
|
780
86
|
```bash
|
|
781
|
-
|
|
782
|
-
lua
|
|
783
|
-
lua push --help # Deployment help
|
|
784
|
-
lua test --help # Testing help
|
|
87
|
+
mkdir my-examples && cd my-examples
|
|
88
|
+
lua init --with-examples
|
|
785
89
|
```
|
|
786
90
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
**Q: Tool not showing up in agent?**
|
|
790
|
-
- ✅ Make sure it's added to a skill
|
|
791
|
-
- ✅ Make sure the skill is added to LuaAgent
|
|
792
|
-
- ✅ Run `lua compile`
|
|
793
|
-
|
|
794
|
-
**Q: Job execute function has undefined variables?**
|
|
795
|
-
- ✅ Use `metadata` to pass data to the job
|
|
796
|
-
- ✅ Job functions must be self-contained
|
|
797
|
-
|
|
798
|
-
**Q: Changes not reflecting in production?**
|
|
799
|
-
- ✅ Run `lua compile` first
|
|
800
|
-
- ✅ Run `lua push` to upload
|
|
801
|
-
- ✅ Select the right environment in `lua chat`
|
|
802
|
-
|
|
803
|
-
---
|
|
804
|
-
|
|
805
|
-
## 🎉 You're Ready!
|
|
806
|
-
|
|
807
|
-
You now have everything you need to build powerful AI agents with Lua. Start by:
|
|
808
|
-
|
|
809
|
-
1. Testing the example tools with `lua test`
|
|
810
|
-
2. Chatting with your agent using `lua chat`
|
|
811
|
-
3. Exploring the code in `src/skills/tools/`
|
|
812
|
-
4. Customizing the agent persona in `src/index.ts`
|
|
813
|
-
|
|
814
|
-
Happy building! 🚀
|
|
815
|
-
|
|
816
|
-
---
|
|
817
|
-
|
|
818
|
-
## 📞 Support
|
|
91
|
+
Or check the documentation: https://docs.heylua.ai/examples
|
|
819
92
|
|
|
820
|
-
|
|
821
|
-
- **GitHub:** https://github.com/heylua/lua-cli
|
|
822
|
-
- **Email:** support@heylua.ai
|
|
93
|
+
## 📖 Commands Reference
|
|
823
94
|
|
|
824
|
-
|
|
95
|
+
| Command | What it does |
|
|
96
|
+
|---------|-------------|
|
|
97
|
+
| `lua test` | Test tools interactively |
|
|
98
|
+
| `lua chat` | Chat with your agent |
|
|
99
|
+
| `lua compile` | Compile your code |
|
|
100
|
+
| `lua push` | Upload to server |
|
|
101
|
+
| `lua deploy` | Deploy to production |
|
|
102
|
+
| `lua logs` | View logs |
|
|
103
|
+
| `lua env` | Manage environment variables |
|
|
104
|
+
| `lua persona` | Update agent persona |
|
|
825
105
|
|
|
826
|
-
|
|
106
|
+
## 🔗 Resources
|
|
827
107
|
|
|
108
|
+
- **Docs:** https://docs.heylua.ai
|
|
109
|
+
- **Examples:** https://docs.heylua.ai/examples
|
|
110
|
+
- **API:** https://docs.heylua.ai/api
|