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