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.
Files changed (125) hide show
  1. package/README.md +0 -4
  2. package/dist/api/cdn.api.service.d.ts +18 -0
  3. package/dist/api/cdn.api.service.js +43 -0
  4. package/dist/api/custom.data.api.service.d.ts +4 -3
  5. package/dist/api/custom.data.api.service.js +4 -3
  6. package/dist/api/developer.api.service.d.ts +54 -1
  7. package/dist/api/developer.api.service.js +89 -0
  8. package/dist/api/job.api.service.d.ts +33 -100
  9. package/dist/api/job.api.service.js +27 -11
  10. package/dist/api/lazy-instances.d.ts +16 -0
  11. package/dist/api/lazy-instances.js +32 -0
  12. package/dist/api/postprocessor.api.service.d.ts +3 -13
  13. package/dist/api/postprocessor.api.service.js +2 -4
  14. package/dist/api/preprocessor.api.service.d.ts +1 -8
  15. package/dist/api/preprocessor.api.service.js +1 -2
  16. package/dist/api/webhook.api.service.d.ts +1 -3
  17. package/dist/api/webhook.api.service.js +1 -1
  18. package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
  19. package/dist/api/whatsapp-templates.api.service.js +78 -0
  20. package/dist/api-exports.d.ts +153 -6
  21. package/dist/api-exports.js +177 -21
  22. package/dist/cli/command-definitions.js +34 -7
  23. package/dist/commands/admin.js +1 -1
  24. package/dist/commands/channels.js +1 -1
  25. package/dist/commands/chat.js +2 -4
  26. package/dist/commands/compile.js +23 -4
  27. package/dist/commands/evals.d.ts +8 -0
  28. package/dist/commands/evals.js +41 -0
  29. package/dist/commands/index.d.ts +2 -0
  30. package/dist/commands/index.js +2 -0
  31. package/dist/commands/init.d.ts +10 -1
  32. package/dist/commands/init.js +23 -46
  33. package/dist/commands/jobs.js +5 -5
  34. package/dist/commands/mcp.d.ts +18 -0
  35. package/dist/commands/mcp.js +393 -0
  36. package/dist/commands/push.js +174 -23
  37. package/dist/common/data.entry.instance.d.ts +1 -1
  38. package/dist/common/data.entry.instance.js +4 -4
  39. package/dist/common/job.instance.d.ts +59 -7
  40. package/dist/common/job.instance.js +84 -19
  41. package/dist/config/constants.d.ts +1 -0
  42. package/dist/config/constants.js +1 -0
  43. package/dist/index.js +1 -0
  44. package/dist/interfaces/agent.d.ts +0 -3
  45. package/dist/interfaces/cdn.d.ts +24 -0
  46. package/dist/interfaces/cdn.js +5 -0
  47. package/dist/interfaces/compile.d.ts +1 -0
  48. package/dist/interfaces/custom.data.d.ts +3 -3
  49. package/dist/interfaces/index.d.ts +2 -1
  50. package/dist/interfaces/init.d.ts +0 -1
  51. package/dist/interfaces/jobs.d.ts +88 -132
  52. package/dist/interfaces/jobs.js +1 -1
  53. package/dist/interfaces/mcp.d.ts +64 -0
  54. package/dist/interfaces/mcp.js +5 -0
  55. package/dist/interfaces/postprocessors.d.ts +0 -3
  56. package/dist/interfaces/preprocessors.d.ts +0 -3
  57. package/dist/interfaces/webhooks.d.ts +0 -5
  58. package/dist/interfaces/whatsapp-templates.d.ts +104 -0
  59. package/dist/interfaces/whatsapp-templates.js +5 -0
  60. package/dist/types/api-contracts.d.ts +68 -14
  61. package/dist/types/compile.types.d.ts +5 -6
  62. package/dist/types/index.d.ts +2 -2
  63. package/dist/types/index.js +3 -1
  64. package/dist/types/skill.d.ts +181 -103
  65. package/dist/types/skill.js +123 -91
  66. package/dist/utils/agent-management.d.ts +3 -5
  67. package/dist/utils/agent-management.js +6 -8
  68. package/dist/utils/bundling.d.ts +4 -11
  69. package/dist/utils/bundling.js +24 -33
  70. package/dist/utils/compile.d.ts +17 -9
  71. package/dist/utils/compile.js +72 -88
  72. package/dist/utils/deployment.js +13 -7
  73. package/dist/utils/dev-api.js +1 -4
  74. package/dist/utils/dev-server.js +1 -1
  75. package/dist/utils/files.d.ts +11 -4
  76. package/dist/utils/files.js +17 -14
  77. package/dist/utils/init-agent.d.ts +1 -2
  78. package/dist/utils/init-agent.js +4 -6
  79. package/dist/utils/init-helpers.d.ts +4 -4
  80. package/dist/utils/init-helpers.js +10 -11
  81. package/dist/utils/job-management.js +0 -2
  82. package/dist/utils/mcp-server-management.d.ts +23 -0
  83. package/dist/utils/mcp-server-management.js +212 -0
  84. package/dist/utils/postprocessor-management.js +2 -4
  85. package/dist/utils/preprocessor-management.js +2 -4
  86. package/dist/utils/sandbox.d.ts +4 -2
  87. package/dist/utils/sandbox.js +38 -9
  88. package/dist/utils/webhook-management.js +1 -3
  89. package/dist/web/app.css +1505 -14
  90. package/dist/web/app.js +79 -64
  91. package/package.json +2 -6
  92. package/template/QUICKSTART.md +57 -774
  93. package/template/README.md +80 -907
  94. package/template/examples/README.md +106 -0
  95. package/template/{src → examples}/jobs/AbandonedBasketProcessorJob.ts +67 -14
  96. package/template/{src → examples}/jobs/DailyCleanupJob.ts +0 -3
  97. package/template/{src → examples}/jobs/DataMigrationJob.ts +0 -3
  98. package/template/{src → examples}/jobs/HealthCheckJob.ts +0 -3
  99. package/template/{src → examples}/postprocessors/modifyResponse.ts +3 -4
  100. package/template/examples/preprocessors/messageMatching.ts +35 -0
  101. package/template/{src → examples}/skills/basket.skill.ts +0 -1
  102. package/template/{src → examples}/skills/product.skill.ts +0 -1
  103. package/template/{src → examples}/skills/tools/GameScoreTrackerTool.ts +11 -15
  104. package/template/{src → examples}/skills/tools/OrderTool.ts +25 -0
  105. package/template/examples/skills/tools/PremiumFeatureTool.ts +98 -0
  106. package/template/{src → examples}/skills/tools/UserDataTool.ts +34 -0
  107. package/template/{src → examples}/skills/user.skill.ts +0 -1
  108. package/template/examples/webhooks/FileUploadWebhook.ts +86 -0
  109. package/template/{src → examples}/webhooks/PaymentWebhook.ts +12 -9
  110. package/template/examples/webhooks/UserEventWebhook.ts +105 -0
  111. package/template/package-lock.json +7895 -0
  112. package/template/package.json +1 -1
  113. package/template/src/index.ts +40 -22
  114. package/template/src/preprocessors/messageMatching.ts +0 -22
  115. package/template/src/webhooks/UserEventWebhook.ts +0 -77
  116. /package/template/{src → examples}/services/ApiService.ts +0 -0
  117. /package/template/{src → examples}/services/GetWeather.ts +0 -0
  118. /package/template/{src → examples}/skills/tools/BasketTool.ts +0 -0
  119. /package/template/{src → examples}/skills/tools/CreateInlineJob.ts +0 -0
  120. /package/template/{src → examples}/skills/tools/CreatePostTool.ts +0 -0
  121. /package/template/{src → examples}/skills/tools/CustomDataTool.ts +0 -0
  122. /package/template/{src → examples}/skills/tools/GetWeatherTool.ts +0 -0
  123. /package/template/{src → examples}/skills/tools/PaymentTool.ts +0 -0
  124. /package/template/{src → examples}/skills/tools/ProductsTool.ts +0 -0
  125. /package/template/{src → examples}/skills/tools/SmartBasketTool.ts +0 -0
@@ -1,968 +1,141 @@
1
- # 🤖 Lua AI Agent Template
1
+ # 🤖 Lua AI Agent
2
2
 
3
- Welcome to your Lua AI Agent! This is a fully-featured template to help you build, test, and deploy intelligent AI agents with custom tools, webhooks, scheduled jobs, and message processors.
4
-
5
- ## 🎯 What You've Got
6
-
7
- This template includes **everything you need** to create a production-ready AI agent:
8
-
9
- - ✅ **LuaAgent Configuration** - Unified agent setup with persona and welcome message
10
- - ✅ **Example Skills & Tools** - 30+ pre-built tools demonstrating best practices
11
- - ✅ **Webhooks** - HTTP endpoints for external integrations
12
- - ✅ **Scheduled Jobs** - Automated background tasks
13
- - ✅ **Message Processors** - Pre/post-process conversations
14
- - ✅ **Type Safety** - Full TypeScript support with Zod validation
15
- - ✅ **Testing Suite** - Local testing before deployment
16
- - ✅ **CI/CD Ready** - Batch deployment commands
17
-
18
- ---
3
+ Welcome to your Lua AI Agent! This is a minimal project ready for you to build your custom agent.
19
4
 
20
5
  ## 🚀 Quick Start
21
6
 
22
- **New to Lua?** Start here:
23
-
24
7
  ```bash
25
- # 1. Test your tools locally
26
- lua test
27
-
28
- # 2. Chat with your agent (sandbox mode)
8
+ # 1. Test your agent (sandbox mode)
29
9
  lua chat
30
10
 
11
+ # 2. Create your first tool
12
+ # See "Creating Your First Tool" below
13
+
31
14
  # 3. Deploy to production
32
15
  lua push all --force --auto-deploy
33
16
  ```
34
17
 
35
- 👉 **[Read the Full Quick Start Guide →](QUICKSTART.md)**
36
-
37
- ---
38
-
39
- ## 📦 What's Inside
40
-
41
- ### Core Files
42
-
43
- | File | Purpose |
44
- |------|---------|
45
- | `src/index.ts` | **Main file** - LuaAgent configuration |
46
- | `lua.skill.yaml` | Agent metadata and component registry |
47
- | `.env` | Environment variables (API keys, secrets) |
48
-
49
- ### Directory Structure
50
-
51
- ```
52
- src/
53
- ├── index.ts # 🎯 LuaAgent - Your agent's configuration
54
- ├── skills/ # Tools grouped by functionality
55
- │ ├── tools/ # Individual tool implementations
56
- │ │ ├── GetWeatherTool.ts # Example: External API integration
57
- │ │ ├── ProductsTool.ts # Example: CRUD operations
58
- │ │ ├── BasketTool.ts # Example: Shopping cart
59
- │ │ └── SmartBasketTool.ts # Example: Complex tool with state
60
- │ ├── product.skill.ts # Skill that groups product tools
61
- │ └── basket.skill.ts # Skill that groups basket tools
62
- ├── webhooks/ # HTTP endpoints
63
- │ ├── PaymentWebhook.ts # Example: Payment notifications
64
- │ └── UserEventWebhook.ts # Example: External events
65
- ├── jobs/ # Scheduled tasks
66
- │ ├── DailyCleanupJob.ts # Example: Recurring cleanup
67
- │ └── HealthCheckJob.ts # Example: Monitoring job
68
- ├── preprocessors/ # Before-message processing
69
- │ └── messageMatching.ts # Example: Route messages
70
- └── postprocessors/ # After-response processing
71
- └── modifyResponse.ts # Example: Format responses
72
- ```
73
-
74
- ---
75
-
76
- ## 🤖 Your Agent at a Glance
77
-
78
- Your agent is configured in `src/index.ts`:
79
-
80
- ```typescript
81
- export const agent = new LuaAgent({
82
- name: 'your-agent-name',
83
- persona: 'Your agent personality and behavior...',
84
- welcomeMessage: 'First message users see',
85
-
86
- skills: [
87
- generalSkill, // Weather, posts, utils
88
- userSkill, // User data management
89
- productSkill, // Product operations
90
- basketSkill, // Shopping cart
91
- orderSkill, // Order processing
92
- customDataSkill, // Custom data storage
93
- paymentSkill // Payment processing
94
- ],
95
-
96
- webhooks: [
97
- // paymentWebhook, // Uncomment to enable
98
- ],
99
-
100
- jobs: [
101
- // dailyCleanupJob, // Uncomment to enable
102
- ],
103
-
104
- preProcessors: [
105
- // messageMatchingProcessor, // Uncomment to enable
106
- ],
107
-
108
- postProcessors: [
109
- // responseModifierProcessor, // Uncomment to enable
110
- ]
111
- });
112
- ```
113
-
114
- ---
115
-
116
- ## 🛠️ Example Tools Included
117
-
118
- ### General Purpose
119
- - **get_weather** - Fetch weather data from external API
120
- - **create_post** - Create posts with external service
121
- - **create_inline_job** - Demonstrates dynamic job creation
122
-
123
- ### User Management
124
- - **get_user_data** - Retrieve user information
125
- - **update_user_data** - Update user profiles
126
-
127
- ### E-commerce
128
- - **search_products** - Search product catalog
129
- - **create_product** - Add new products
130
- - **update_product** - Modify existing products
131
- - **delete_product** - Remove products
132
- - **create_basket** - Create shopping cart
133
- - **add_item_to_basket** - Add products to cart
134
- - **checkout_basket** - Complete purchase
135
- - **create_order** - Place orders
136
- - **update_order_status** - Track order progress
137
-
138
- ### Advanced Examples
139
- - **smart_basket_tool** - Complex state management with AI-powered recommendations
140
- - **game_score_tracker** - Multi-player game tracking with leaderboards
141
- - **create_payment_link** - Stripe integration for payments
142
-
143
- ---
144
-
145
- ## 🎓 Learning Path
146
-
147
- ### Beginner
148
- 1. ✅ Read [QUICKSTART.md](QUICKSTART.md)
149
- 2. ✅ Run `lua test` to try existing tools
150
- 3. ✅ Run `lua chat` to interact with your agent
151
- 4. ✅ Modify the agent persona in `src/index.ts`
152
-
153
- ### Intermediate
154
- 1. ✅ Create your first custom tool
155
- 2. ✅ Group tools into a skill
156
- 3. ✅ Add the skill to your LuaAgent
157
- 4. ✅ Test and deploy with `lua push`
158
-
159
- ### Advanced
160
- 1. ✅ Create webhooks for external integrations
161
- 2. ✅ Schedule jobs for automated tasks
162
- 3. ✅ Add preprocessors to route/filter messages
163
- 4. ✅ Use postprocessors to format responses
164
- 5. ✅ Implement complex tools with external APIs
165
-
166
- ---
167
-
168
- ## 🔑 Key Features
169
-
170
- ### Intelligent Tools
171
- Your agent can use tools to accomplish tasks:
172
- ```typescript
173
- // User: "What's the weather in Tokyo?"
174
- // Agent uses: get_weather tool
175
- // Response: "It's 72°F and sunny in Tokyo"
176
- ```
177
-
178
- ### External Integrations
179
- Connect to any API:
180
- ```typescript
181
- // Stripe, OpenAI, Pinecone, custom APIs
182
- const result = await axios.post(API_URL, data);
183
- ```
184
-
185
- ### User Context
186
- Access user data in every tool:
187
- ```typescript
188
- const user = await User.get();
189
- const preferences = user.preferences;
190
- ```
191
-
192
- ### Persistent Storage
193
- Store data across conversations:
194
- ```typescript
195
- await Data.create('notes', {
196
- title: "Meeting Notes",
197
- content: "..."
198
- });
199
- ```
200
-
201
- ### Scheduled Automation
202
- Run tasks on a schedule:
203
- ```typescript
204
- // Every day at 9 AM
205
- schedule: {
206
- type: "cron",
207
- pattern: "0 9 * * *"
208
- }
209
- ```
18
+ ## 📁 Project Structure
210
19
 
211
- ### Real-time Events
212
- Receive HTTP webhooks:
213
- ```typescript
214
- // POST /webhook/{webhookId}
215
- // Process payment confirmations, order updates, etc.
216
20
  ```
217
-
218
- ---
219
-
220
- ## 📊 Development Workflow
221
-
222
- ```mermaid
223
- graph LR
224
- A[Write Code] --> B[lua test]
225
- B --> C[lua chat sandbox]
226
- C --> D{Works?}
227
- D -->|No| A
228
- D -->|Yes| E[lua compile]
229
- E --> F[lua push]
230
- F --> G[lua chat production]
231
- G --> H{Deploy?}
232
- H -->|Yes| I[lua deploy]
233
- H -->|No| A
21
+ your-project/
22
+ ├── src/
23
+ │ └── index.ts # Your agent configuration
24
+ ├── lua.skill.yaml # Agent metadata (auto-managed)
25
+ ├── package.json # Dependencies
26
+ └── tsconfig.json # TypeScript config
234
27
  ```
235
28
 
236
- ### Commands Reference
29
+ ## 🛠️ Creating Your First Tool
237
30
 
238
- | Command | Purpose | When to Use |
239
- |---------|---------|-------------|
240
- | `lua test` | Test individual tools | During development |
241
- | `lua chat` | Interactive testing | Validate tool interactions |
242
- | `lua compile` | Bundle your code | Before pushing |
243
- | `lua push` | Upload to server | Ready to deploy |
244
- | `lua deploy` | Publish to production | Make live for users |
245
- | `lua push all --force` | Batch push all | CI/CD pipelines |
246
-
247
- ---
248
-
249
- ## 🔒 Environment Variables
250
-
251
- Store sensitive data in `.env`:
31
+ ### 1. Create the tool file
252
32
 
253
33
  ```bash
254
- # Copy from example
255
- cp env.example .env
256
-
257
- # Add your API keys
258
- OPENAI_API_KEY=sk-...
259
- STRIPE_SECRET_KEY=sk_live_...
260
- PINECONE_API_KEY=...
261
-
262
- # Optional: For CI/CD
263
- LUA_API_KEY=your-lua-api-key
264
- ```
265
-
266
- **Priority:**
267
- 1. System keychain (most secure)
268
- 2. `LUA_API_KEY` environment variable
269
- 3. `.env` file
270
-
271
- ---
272
-
273
- ## 🎨 Customization Guide
274
-
275
- ### 1. Update Agent Identity
276
-
277
- Edit `src/index.ts`:
278
-
279
- ```typescript
280
- export const agent = new LuaAgent({
281
- name: 'my-customer-support-bot', // ✏️ Change this
282
-
283
- persona: `You are Sarah, a friendly customer support agent...`, // ✏️ Customize
284
-
285
- welcomeMessage: 'Hi! I\'m Sarah. How can I help you today?', // ✏️ Personalize
286
-
287
- // ...
288
- });
34
+ mkdir -p src/skills/tools
289
35
  ```
290
36
 
291
- ### 2. Add Your Own Tool
292
-
293
- Create `src/skills/tools/MyTool.ts`:
37
+ Create `src/skills/tools/GreetingTool.ts`:
294
38
 
295
39
  ```typescript
296
- import { LuaTool } from "lua-cli/skill";
40
+ import { LuaTool } from "lua-cli";
297
41
  import { z } from "zod";
298
42
 
299
- export default class MyTool implements LuaTool {
300
- name = "my_tool";
301
- description = "What this tool does";
302
-
303
- inputSchema = z.object({
304
- param: z.string()
305
- });
306
-
307
- async execute(input: z.infer<typeof this.inputSchema>) {
308
- // Your logic here
309
- return { result: "success" };
310
- }
43
+ export default class GreetingTool implements LuaTool {
44
+ name = "greet_user";
45
+ description = "Generate a personalized greeting";
46
+
47
+ inputSchema = z.object({
48
+ name: z.string().describe("The name of the person to greet")
49
+ });
50
+
51
+ async execute(input: z.infer<typeof this.inputSchema>) {
52
+ return {
53
+ greeting: `Hello, ${input.name}! How can I help you today?`
54
+ };
55
+ }
311
56
  }
312
57
  ```
313
58
 
314
- Add to a skill in `src/index.ts`:
315
-
316
- ```typescript
317
- import MyTool from './skills/tools/MyTool';
318
-
319
- const mySkill = new LuaSkill({
320
- name: 'my-skill',
321
- description: 'My custom skill',
322
- context: 'Use these tools for...',
323
- tools: [new MyTool()]
324
- });
325
-
326
- export const agent = new LuaAgent({
327
- // ...
328
- skills: [...existingSkills, mySkill],
329
- });
330
- ```
331
-
332
- ### 3. Configure Webhooks
59
+ ### 2. Create a skill to group your tools
333
60
 
334
- Uncomment in `src/index.ts`:
61
+ Create `src/skills/greeting.skill.ts`:
335
62
 
336
63
  ```typescript
337
- import paymentWebhook from './webhooks/PaymentWebhook';
64
+ import { LuaSkill } from "lua-cli";
65
+ import GreetingTool from "./tools/GreetingTool";
338
66
 
339
- export const agent = new LuaAgent({
340
- // ...
341
- webhooks: [paymentWebhook], // Enabled
67
+ const greetingSkill = new LuaSkill({
68
+ name: "greeting-skill",
69
+ description: "Tools for greeting users",
70
+ context: "Use these tools when the user wants to be greeted",
71
+ tools: [new GreetingTool()],
342
72
  });
343
- ```
344
73
 
345
- Get your webhook URL after deployment:
346
- ```
347
- https://webhook.heylua.ai/{agentId}/{webhookId}
74
+ export default greetingSkill;
348
75
  ```
349
76
 
350
- ### 4. Schedule Jobs
77
+ ### 3. Add the skill to your agent
351
78
 
352
- Uncomment in `src/index.ts`:
79
+ Update `src/index.ts`:
353
80
 
354
81
  ```typescript
355
- import dailyCleanupJob from './jobs/DailyCleanupJob';
82
+ import { LuaAgent } from "lua-cli";
83
+ import greetingSkill from "./skills/greeting.skill";
356
84
 
357
- export const agent = new LuaAgent({
358
- // ...
359
- jobs: [dailyCleanupJob], // Enabled
85
+ const agent = new LuaAgent({
86
+ name: `My Agent`,
87
+ persona: `You are a friendly assistant.`,
88
+ skills: [greetingSkill],
360
89
  });
361
90
  ```
362
91
 
363
- ---
364
-
365
- ## 📚 Documentation
366
-
367
- ### Comprehensive Guides
368
- - **[Quick Start Guide](QUICKSTART.md)** - Step-by-step tutorial
369
- - **[Example Skills](src/skills/)** - Browse working examples
370
- - **[Example Webhooks](src/webhooks/)** - Webhook patterns
371
- - **[Example Jobs](src/jobs/)** - Job scheduling examples
372
-
373
- ### Official Documentation
374
- - **Lua Docs:** https://docs.heylua.ai
375
- - **CLI Reference:** https://github.com/heylua/lua-cli
376
- - **Community:** https://community.heylua.ai
377
-
378
- ---
379
-
380
- ## 🧪 Testing Strategy
381
-
382
- ### Local Testing (Recommended)
383
-
384
- ```bash
385
- # Test individual tools
386
- lua test
387
-
388
- # Interactive chat testing
389
- lua chat
390
- # Select: Sandbox
391
- ```
392
-
393
- **Why sandbox?**
394
- - ✅ Uses your local code (not deployed)
395
- - ✅ Safe for experimentation
396
- - ✅ Instant feedback
397
- - ✅ No production impact
398
-
399
- ### Production Testing
400
-
401
- ```bash
402
- lua chat
403
- # Select: Production
404
- ```
405
-
406
- **When to use:**
407
- - ✅ After deploying
408
- - ✅ Validate production behavior
409
- - ✅ Test with real data
410
-
411
- ---
412
-
413
- ## 🚀 Deployment Options
414
-
415
- ### Option 1: Interactive (Recommended for First Time)
416
-
417
- ```bash
418
- lua push
419
- # Select component type
420
- # Confirm version
421
- # Choose whether to deploy
422
- ```
423
-
424
- **Best for:**
425
- - Learning the deployment process
426
- - Reviewing changes before deploying
427
- - Fine-grained control
428
-
429
- ### Option 2: Batch Deployment (CI/CD)
92
+ ### 4. Test it!
430
93
 
431
94
  ```bash
432
- lua push all --force --auto-deploy
95
+ lua test # Test the tool directly
96
+ lua chat # Chat with your agent
433
97
  ```
434
98
 
435
- **What happens:**
436
- 1. Compiles all code
437
- 2. Auto-bumps patch versions
438
- 3. Pushes all skills, webhooks, jobs, processors
439
- 4. Deploys everything to production
440
-
441
- **Best for:**
442
- - CI/CD pipelines
443
- - Batch updates
444
- - Production deployments
99
+ ## 📖 Essential Commands
445
100
 
446
- ---
447
-
448
- ## 💡 Pro Tips
449
-
450
- ### Development
451
- - ✅ Use `lua test` frequently during development
452
- - Test in sandbox before deploying
453
- - Keep tools small and focused (single responsibility)
454
- - ✅ Use TypeScript for better error catching
455
-
456
- ### Tools
457
- - ✅ Validate all inputs with Zod schemas
458
- - ✅ Return structured objects (not just strings)
459
- - ✅ Handle errors gracefully
460
- - ✅ Use descriptive names and descriptions (the AI reads these!)
461
-
462
- ### Jobs
463
- - ✅ Always pass data via `metadata` field
464
- - ✅ Make execute functions self-contained
465
- - ✅ Use appropriate schedule types (once, cron, interval)
466
- - ✅ Test job logic in regular tools first
467
-
468
- ### Webhooks
469
- - ✅ Validate signatures in production
470
- - ✅ Return proper HTTP status codes
471
- - ✅ Handle retries and idempotency
472
- - ✅ Test with tools like Postman first
473
-
474
- ### Agent Persona
475
- - ✅ Be specific about personality and tone
476
- - ✅ Define what the agent can/cannot do
477
- - ✅ Give examples of good responses
478
- - ✅ Update based on user feedback
101
+ | Command | Purpose |
102
+ |---------|---------|
103
+ | `lua test` | Test individual tools interactively |
104
+ | `lua chat` | Interactive chat with your agent |
105
+ | `lua compile` | Compile your code |
106
+ | `lua push` | Upload to server |
107
+ | `lua deploy` | Deploy to production |
108
+ | `lua logs` | View execution logs |
479
109
 
480
- ---
110
+ ## 🎯 Want Examples?
481
111
 
482
- ## 🔄 Keeping Your Agent Updated
483
-
484
- ### When You Make Changes
112
+ Initialize a new project with example code:
485
113
 
486
114
  ```bash
487
- # 1. Test your changes
488
- lua test
489
-
490
- # 2. Compile
491
- lua compile
492
-
493
- # 3. Push new version
494
- lua push
495
-
496
- # 4. Deploy when ready
497
- lua deploy
498
- ```
499
-
500
- ### Sync Your Configuration
501
-
502
- The CLI automatically keeps your `lua.skill.yaml` and `LuaAgent` in sync:
503
-
504
- - **Run `lua init`** → Syncs agent name, persona, welcomeMessage to both files
505
- - **Run `lua compile`** → Syncs LuaAgent changes back to YAML
506
- - **Manual edit YAML** → Re-run `lua compile` to rebuild
507
-
508
- ---
509
-
510
- ## 🎨 Example Use Cases
511
-
512
- ### Customer Support Agent
513
- ```typescript
514
- persona: `You are Alex, a patient and knowledgeable customer support agent.
515
- You help customers with orders, returns, and product questions.
516
- Always be empathetic and solution-oriented.`
517
-
518
- skills: [productSkill, orderSkill, basketSkill]
519
- ```
520
-
521
- ### E-commerce Assistant
522
- ```typescript
523
- persona: `You are Sophia, an enthusiastic shopping assistant.
524
- You help customers find products, make recommendations, and complete purchases.
525
- Use a friendly, upbeat tone and be proactive with suggestions.`
526
-
527
- skills: [productSkill, basketSkill, paymentSkill]
115
+ mkdir my-project-with-examples && cd my-project-with-examples
116
+ lua init --with-examples
528
117
  ```
529
118
 
530
- ### Data Analysis Agent
531
- ```typescript
532
- persona: `You are DataBot, an analytical AI assistant.
533
- You help users query data, generate reports, and visualize insights.
534
- Be precise, data-driven, and thorough in your analysis.`
535
-
536
- skills: [customDataSkill, analyticsSkill, reportSkill]
537
- ```
538
-
539
- ---
540
-
541
- ## 🔐 Security Best Practices
119
+ This includes:
120
+ - ✅ 30+ example tools
121
+ - Example webhooks (HTTP endpoints)
122
+ - Example scheduled jobs
123
+ - Example pre/post processors
124
+ - ✅ Working e-commerce flow (products, baskets, orders)
542
125
 
543
- ### API Keys
544
- - ✅ Never commit `.env` file to version control
545
- - ✅ Use `.env.example` as a template
546
- - ✅ Rotate API keys regularly
547
- - ✅ Use environment-specific keys (sandbox vs production)
126
+ ## 📚 Learn More
548
127
 
549
- ### Webhooks
550
- - ✅ Validate webhook signatures in production
551
- - ✅ Use HTTPS endpoints only
552
- - ✅ Rate limit webhook handlers
553
- - ✅ Log all webhook events
554
-
555
- ### User Data
556
- - ✅ Only store necessary data
557
- - ✅ Encrypt sensitive information
558
- - ✅ Respect user privacy preferences
559
- - ✅ Implement data deletion on request
560
-
561
- ---
562
-
563
- ## 🐛 Troubleshooting
564
-
565
- ### Common Issues
566
-
567
- **"Tool not found by agent"**
568
- ```bash
569
- # Make sure tool is in a skill, skill is in LuaAgent
570
- lua compile # Rebuilds everything
571
- ```
572
-
573
- **"Cannot find module '../services/ApiService'"**
574
- ```bash
575
- # Make sure all dependencies are installed
576
- npm install
577
- ```
578
-
579
- **"Job execute function: ReferenceError: input is not defined"**
580
- ```typescript
581
- // ❌ Wrong: Accessing parent scope
582
- execute: async (job) => {
583
- const message = input.message; // Error!
584
- }
585
-
586
- // ✅ Correct: Use metadata
587
- metadata: { message: input.message },
588
- execute: async (job) => {
589
- const message = job.metadata.message; // Works!
590
- }
591
- ```
592
-
593
- **"Version not found when deploying"**
594
- ```bash
595
- # Server needs time to process. Wait 10 seconds, then:
596
- lua deploy
597
- ```
598
-
599
- ---
600
-
601
- ## 📈 Scaling Your Agent
602
-
603
- ### Add More Skills
604
-
605
- As your agent grows, organize tools into skills:
606
-
607
- ```typescript
608
- // src/skills/analytics.skill.ts
609
- export const analyticsSkill = new LuaSkill({
610
- name: 'analytics-skill',
611
- description: 'Data analytics and reporting',
612
- context: 'Use these tools for data analysis',
613
- tools: [
614
- new GenerateReportTool(),
615
- new ExportDataTool(),
616
- new VisualizeTool()
617
- ]
618
- });
619
- ```
620
-
621
- ### Add Background Processing
622
-
623
- Use jobs for heavy or scheduled work:
624
-
625
- ```typescript
626
- // Instead of making users wait
627
- // Create a job that processes in background
628
- const job = await Jobs.create({
629
- name: 'process-large-file',
630
- metadata: { fileId: input.fileId },
631
- schedule: { type: "once", executeAt: new Date() },
632
- execute: async (job) => {
633
- // Process file
634
- // Notify user when done
635
- }
636
- });
637
- ```
638
-
639
- ### Add External Integrations
640
-
641
- Use webhooks to receive events:
642
-
643
- ```typescript
644
- // Receive events from Stripe, Shopify, etc.
645
- export default new LuaWebhook({
646
- name: "shopify-order",
647
- execute: async ({ body }) => {
648
- // Process Shopify order
649
- // Update your system
650
- // Notify customer
651
- }
652
- });
653
- ```
654
-
655
- ---
656
-
657
- ## 🔧 Advanced Configuration
658
-
659
- ### Multiple Environments
660
-
661
- ```bash
662
- # Sandbox (testing)
663
- lua chat # Select Sandbox
664
- lua env sandbox
665
-
666
- # Production (live users)
667
- lua chat # Select Production
668
- lua env production
669
- ```
670
-
671
- ### Skill Overrides
672
-
673
- Test specific skill versions without deploying:
674
-
675
- ```typescript
676
- // In sandbox mode, test development versions
677
- // Production uses deployed versions
678
- ```
679
-
680
- ### Processor Chains
681
-
682
- Process messages in order:
683
-
684
- ```typescript
685
- preProcessors: [
686
- profanityFilter, // 1. Clean input
687
- intentClassifier, // 2. Detect intent
688
- messageRouter // 3. Route to handler
689
- ]
690
-
691
- postProcessors: [
692
- responseFormatter, // 1. Format output
693
- addDisclaimer, // 2. Add legal text
694
- translateResponse // 3. Translate if needed
695
- ]
696
- ```
697
-
698
- ---
699
-
700
- ## 📊 Monitoring & Management
701
-
702
- ### View Production Status
703
-
704
- ```bash
705
- lua production
706
- ```
707
-
708
- Shows:
709
- - Active skills and versions
710
- - Webhook URLs
711
- - Scheduled jobs
712
- - Environment variables
713
-
714
- ### View Logs
715
-
716
- ```bash
717
- lua logs
718
- ```
719
-
720
- Interactive filtering by primitive type:
721
- - **Skills** - Filter by specific skill or view all skill logs
722
- - **Jobs** - Filter by specific job (including dynamically created jobs) or view all job logs
723
- - **Webhooks** - Filter by specific webhook or view all webhook logs
724
- - **Preprocessors** - Filter by specific preprocessor or view all preprocessor logs
725
- - **Postprocessors** - Filter by specific postprocessor or view all postprocessor logs
726
-
727
- Each log entry displays:
728
- - Primitive type, name, and ID
729
- - Tool name (for skill-related logs)
730
- - Timestamp and log level
731
- - Full message content
732
-
733
- See:
734
- - Agent conversations
735
- - Tool executions
736
- - Errors and warnings
737
- - Performance metrics
738
-
739
- ### Manage Skills
740
-
741
- ```bash
742
- # List all skills
743
- lua skills
744
-
745
- # Push specific skill
746
- lua push skill
747
-
748
- # Deploy specific version
749
- lua deploy
750
- ```
751
-
752
- ---
753
-
754
- ## 🌐 CI/CD Integration
755
-
756
- ### GitHub Actions Example
757
-
758
- ```yaml
759
- # .github/workflows/deploy.yml
760
- name: Deploy Lua Agent
761
-
762
- on:
763
- push:
764
- branches: [main]
765
-
766
- jobs:
767
- deploy:
768
- runs-on: ubuntu-latest
769
- steps:
770
- - uses: actions/checkout@v3
771
-
772
- - name: Setup Node.js
773
- uses: actions/setup-node@v3
774
- with:
775
- node-version: '20'
776
-
777
- - name: Install dependencies
778
- run: npm install
779
-
780
- - name: Install Lua CLI
781
- run: npm install -g lua-cli@alpha
782
-
783
- - name: Deploy to production
784
- run: lua push all --force --auto-deploy
785
- env:
786
- LUA_API_KEY: ${{ secrets.LUA_API_KEY }}
787
- ```
788
-
789
- ### GitLab CI Example
790
-
791
- ```yaml
792
- # .gitlab-ci.yml
793
- deploy:
794
- stage: deploy
795
- image: node:20
796
- script:
797
- - npm install
798
- - npm install -g lua-cli@alpha
799
- - lua push all --force --auto-deploy
800
- only:
801
- - main
802
- variables:
803
- LUA_API_KEY: $LUA_API_KEY
804
- ```
805
-
806
- ---
807
-
808
- ## 🤝 Contributing
809
-
810
- ### Adding Examples
811
-
812
- Have a great tool example? Add it to the template:
813
-
814
- 1. Create the tool in `src/skills/tools/`
815
- 2. Add it to a skill
816
- 3. Test thoroughly
817
- 4. Document the use case
818
-
819
- ### Reporting Issues
820
-
821
- Found a bug or have a suggestion?
822
-
823
- - GitHub Issues: https://github.com/heylua/lua-cli/issues
824
- - Email: support@heylua.ai
825
-
826
- ---
827
-
828
- ## 📝 Important Notes
829
-
830
- ### About Jobs and Closures
831
-
832
- ⚠️ **Job execute functions must be self-contained**
833
-
834
- ```typescript
835
- // ❌ This will NOT work:
836
- async execute(input: any) {
837
- const userMessage = input.message;
838
-
839
- await Jobs.create({
840
- execute: async (job) => {
841
- // userMessage is undefined here!
842
- await user.send(userMessage);
843
- }
844
- });
845
- }
846
-
847
- // ✅ This WILL work:
848
- async execute(input: any) {
849
- await Jobs.create({
850
- metadata: { message: input.message }, // Pass via metadata
851
- execute: async (job) => {
852
- // Access from metadata
853
- await job.user().send(job.metadata.message);
854
- }
855
- });
856
- }
857
- ```
858
-
859
- **Why?** Jobs are serialized and executed in a sandbox. They can't access parent scope variables.
860
-
861
- ### About Bundling
862
-
863
- The CLI automatically:
864
- - ✅ Bundles all tool code and dependencies
865
- - ✅ Excludes lua-cli APIs (available in sandbox)
866
- - ✅ Compresses code for transmission
867
- - ✅ Handles imports and dependencies
868
-
869
- You don't need to worry about bundling - it just works!
870
-
871
- ---
872
-
873
- ## 🎯 What's Next?
874
-
875
- ### Immediate Actions
876
- 1. ✅ Test the example tools: `lua test`
877
- 2. ✅ Chat with your agent: `lua chat` (select Sandbox)
878
- 3. ✅ Read the [Quick Start Guide](QUICKSTART.md)
879
- 4. ✅ Customize the agent persona in `src/index.ts`
880
-
881
- ### Short Term
882
- 1. ✅ Create your first custom tool
883
- 2. ✅ Deploy to production: `lua push`
884
- 3. ✅ Test in production: `lua chat` (select Production)
885
-
886
- ### Long Term
887
- 1. ✅ Add webhooks for external integrations
888
- 2. ✅ Schedule jobs for automated tasks
889
- 3. ✅ Build advanced tools with AI/external APIs
890
- 4. ✅ Monitor and improve based on user feedback
891
-
892
- ---
893
-
894
- ## 🌟 Example Projects
895
-
896
- ### Simple Assistant
897
- - 3-5 basic tools
898
- - No webhooks or jobs
899
- - General Q&A and information retrieval
900
-
901
- ### E-commerce Bot
902
- - Product catalog management
903
- - Shopping cart tools
904
- - Payment webhooks
905
- - Abandoned cart jobs
906
-
907
- ### Support Agent
908
- - Knowledge base search
909
- - Ticket creation tools
910
- - Escalation webhooks
911
- - Daily summary jobs
912
-
913
- ### Data Platform
914
- - Custom data tools
915
- - Report generation
916
- - Scheduled analytics jobs
917
- - Webhook integrations
918
-
919
- ---
920
-
921
- ## 📞 Support & Resources
922
-
923
- ### Get Help
924
128
  - **Documentation:** https://docs.heylua.ai
925
- - **CLI Reference:** Run `lua --help`
926
- - **Email Support:** support@heylua.ai
927
- - **Community:** https://community.heylua.ai
928
-
929
- ### Stay Updated
930
- ```bash
931
- # Check your version
932
- lua --version
933
-
934
- # Update to latest alpha
935
- npm install -g lua-cli@alpha
936
- ```
937
-
938
- ---
129
+ - **Examples:** https://docs.heylua.ai/examples
130
+ - **API Reference:** https://docs.heylua.ai/api
939
131
 
940
- ## 📄 License
132
+ ## 💡 Tips
941
133
 
942
- This template is provided as part of lua-cli. See the main project license for details.
134
+ 1. **Use Zod schemas** - They provide type safety and help the AI understand your tool inputs
135
+ 2. **Write clear descriptions** - The AI reads these to decide when to use your tools
136
+ 3. **Test in sandbox first** - Use `lua chat` with sandbox mode before deploying
137
+ 4. **Keep tools focused** - Each tool should do one thing well
943
138
 
944
139
  ---
945
140
 
946
- ## 🎉 Happy Building!
947
-
948
- You're all set to build amazing AI agents with Lua!
949
-
950
- **Remember:**
951
- 1. Start small - test one tool at a time
952
- 2. Use sandbox mode liberally
953
- 3. Read the example code - it's full of patterns
954
- 4. Deploy often - iterate quickly
955
-
956
- **Need inspiration?** Check out the example tools in `src/skills/tools/` - they demonstrate:
957
- - External API calls
958
- - State management
959
- - Error handling
960
- - Complex business logic
961
- - AI integrations
962
-
963
- Build something awesome! 🚀
964
-
965
- ---
966
-
967
- *Template version: 3.0.0 | Last updated: October 2025*
968
-
141
+ *Built with [Lua CLI](https://www.npmjs.com/package/lua-cli)*