lua-cli 3.0.0-alpha.1 → 3.0.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 (61) hide show
  1. package/dist/api/job.api.service.d.ts +16 -7
  2. package/dist/api/job.api.service.js +21 -5
  3. package/dist/api/postprocessor.api.service.d.ts +61 -1
  4. package/dist/api/postprocessor.api.service.js +35 -0
  5. package/dist/api/preprocessor.api.service.d.ts +61 -1
  6. package/dist/api/preprocessor.api.service.js +35 -0
  7. package/dist/api-exports.d.ts +26 -6
  8. package/dist/api-exports.js +42 -29
  9. package/dist/cli/command-definitions.js +13 -6
  10. package/dist/commands/chat.js +32 -5
  11. package/dist/commands/compile.js +16 -2
  12. package/dist/commands/dev.js +23 -2
  13. package/dist/commands/push.d.ts +6 -2
  14. package/dist/commands/push.js +412 -6
  15. package/dist/commands/test.js +18 -2
  16. package/dist/common/job.instance.d.ts +3 -0
  17. package/dist/common/job.instance.js +8 -0
  18. package/dist/config/constants.d.ts +6 -5
  19. package/dist/config/constants.js +12 -10
  20. package/dist/interfaces/chat.d.ts +30 -1
  21. package/dist/interfaces/jobs.d.ts +21 -0
  22. package/dist/types/skill.d.ts +75 -56
  23. package/dist/types/skill.js +53 -59
  24. package/dist/utils/bundling.d.ts +13 -4
  25. package/dist/utils/bundling.js +83 -26
  26. package/dist/utils/compile.js +27 -6
  27. package/dist/utils/dev-api.d.ts +42 -2
  28. package/dist/utils/dev-api.js +177 -4
  29. package/dist/utils/dev-server.d.ts +1 -1
  30. package/dist/utils/dev-server.js +4 -4
  31. package/dist/utils/dynamic-job-bundler.d.ts +17 -0
  32. package/dist/utils/dynamic-job-bundler.js +143 -0
  33. package/dist/utils/pre-bundle-jobs.d.ts +26 -0
  34. package/dist/utils/pre-bundle-jobs.js +176 -0
  35. package/dist/utils/sandbox-storage.d.ts +48 -0
  36. package/dist/utils/sandbox-storage.js +114 -0
  37. package/dist/utils/sandbox.d.ts +2 -2
  38. package/dist/utils/sandbox.js +23 -7
  39. package/package.json +1 -1
  40. package/template/lua.skill.yaml +47 -0
  41. package/template/package-lock.json +10505 -0
  42. package/template/package.json +2 -1
  43. package/template/src/index.ts +65 -3
  44. package/template/src/tools/CreateInlineJob.ts +42 -0
  45. package/API_REFERENCE.md +0 -1408
  46. package/CHANGELOG.md +0 -236
  47. package/CLI_REFERENCE.md +0 -908
  48. package/GETTING_STARTED.md +0 -1040
  49. package/INSTANCE_TYPES.md +0 -1158
  50. package/README.md +0 -865
  51. package/TEMPLATE_GUIDE.md +0 -1398
  52. package/USER_DATA_INSTANCE.md +0 -621
  53. package/template/AGENT_CONFIGURATION.md +0 -251
  54. package/template/COMPLEX_JOB_EXAMPLES.md +0 -795
  55. package/template/DYNAMIC_JOB_CREATION.md +0 -371
  56. package/template/TOOL_EXAMPLES.md +0 -655
  57. package/template/WEBHOOKS_JOBS_QUICKSTART.md +0 -318
  58. package/template/WEBHOOK_JOB_EXAMPLES.md +0 -817
  59. package/template/src/index-agent-example.ts +0 -201
  60. package/template/src/postprocessors/ResponseFormatter.ts +0 -151
  61. package/template/src/preprocessors/MessageFilter.ts +0 -91
@@ -1,1040 +0,0 @@
1
- # Getting Started with Lua CLI
2
-
3
- Welcome! This guide will get you from zero to your first deployed AI skill in minutes.
4
-
5
- ---
6
-
7
- ## 🚀 Quick Start (5 Minutes)
8
-
9
- ```bash
10
- # 1. Install the CLI
11
- npm install -g lua-cli
12
-
13
- # 2. Set up authentication
14
- lua auth configure
15
- # Choose "Email" and follow prompts
16
-
17
- # 3. Create your first skill
18
- mkdir my-first-skill && cd my-first-skill
19
- lua init
20
- # Choose "Create new agent" and follow prompts
21
-
22
- # 4. Test it locally
23
- lua test
24
- # Select a tool and try it out
25
-
26
- # 5. Start development mode
27
- lua dev
28
- # Chat with your AI at http://localhost:3000
29
- ```
30
-
31
- **Congratulations! You now have a working AI skill!** 🎉
32
-
33
- ---
34
-
35
- ## 📚 What You Need to Know
36
-
37
- ### Core Concepts
38
-
39
- **Lua** is a platform for building AI agents with custom capabilities. Think of it like:
40
-
41
- ```
42
- AI Agent (ChatGPT-like)
43
- └── Skills (Custom capabilities you build)
44
- └── Tools (Specific functions the AI can call)
45
- ```
46
-
47
- **Example:**
48
- - **Agent**: "CoffeeBot" - Your coffee shop's AI assistant
49
- - **Skill**: "Coffee Shop Skill" - What your AI can do
50
- - **Tools**:
51
- - `show_menu` - Display menu items
52
- - `create_order` - Take customer orders
53
- - `check_loyalty` - Check rewards points
54
-
55
- ### How It Works
56
-
57
- 1. **You build tools** - Functions that do specific things
58
- 2. **You create a skill** - Collection of related tools
59
- 3. **The AI calls your tools** - When users ask questions
60
- 4. **Your tools return data** - The AI uses this to respond
61
-
62
- ---
63
-
64
- ## 🎯 Your First Hour
65
-
66
- ### Part 1: Setup (10 minutes)
67
-
68
- #### Install CLI
69
-
70
- ```bash
71
- npm install -g lua-cli
72
- ```
73
-
74
- #### Authenticate
75
-
76
- ```bash
77
- lua auth configure
78
- ```
79
-
80
- Choose **Email** option:
81
- 1. Enter your email
82
- 2. Check email for 6-digit code
83
- 3. Enter the code
84
- 4. Done! API key automatically generated and saved
85
-
86
- ---
87
-
88
- ### Part 2: Create Project (15 minutes)
89
-
90
- #### Initialize
91
-
92
- ```bash
93
- mkdir weather-skill
94
- cd weather-skill
95
- lua init
96
- ```
97
-
98
- **Prompts:**
99
- 1. **What would you like to do?** → "Create new agent"
100
- 2. **Enter business name:** → "My Weather Service"
101
- 3. **Enter agent name:** → "WeatherBot"
102
- 4. **Select business type:** → "Personal services"
103
- 5. **Select brand personality:** → "Friendly"
104
- 6. **Enter brand traits:** → "Helpful and informative"
105
-
106
- **What happens:**
107
- - Agent created on Lua platform
108
- - Template project copied
109
- - Dependencies installed
110
- - `lua.skill.yaml` configured
111
- - Ready to customize!
112
-
113
- ---
114
-
115
- ### Part 3: Explore the Template (15 minutes)
116
-
117
- #### Open in Your Editor
118
-
119
- ```bash
120
- code . # VS Code
121
- # or
122
- open . # Finder/Explorer
123
- ```
124
-
125
- #### Key Files to Explore
126
-
127
- **1. `src/index.ts`** - Your skills definition
128
- ```typescript
129
- const generalSkill = new LuaSkill({
130
- name: "general-skill",
131
- description: "...",
132
- context: "...",
133
- tools: [
134
- new GetWeatherTool(),
135
- // Add more tools here
136
- ]
137
- });
138
- ```
139
-
140
- **2. `src/tools/GetWeatherTool.ts`** - Example tool
141
- ```typescript
142
- export default class GetWeatherTool implements LuaTool {
143
- name = "get_weather";
144
- description = "Get weather for a city";
145
- inputSchema = z.object({ city: z.string() });
146
-
147
- async execute(input: any) {
148
- // Calls weather API
149
- return { temperature, condition, city };
150
- }
151
- }
152
- ```
153
-
154
- **3. `lua.skill.yaml`** - Configuration (auto-managed)
155
- ```yaml
156
- agent:
157
- agentId: agent_abc123
158
- orgId: org_xyz789
159
- ```
160
-
161
- ---
162
-
163
- ### Part 4: Test Your Skill (10 minutes)
164
-
165
- #### Test Individual Tools
166
-
167
- ```bash
168
- lua test
169
- ```
170
-
171
- 1. Select a tool (e.g., "get_weather")
172
- 2. Enter inputs (e.g., city: "London")
173
- 3. See the results!
174
-
175
- **Example:**
176
- ```bash
177
- $ lua test
178
- ? Select a tool to test: get_weather - Get the weather for a given city
179
- ? city (required): London
180
-
181
- 🚀 Executing tool...
182
- ✅ Tool execution successful!
183
- Output: {
184
- "city": "London",
185
- "temperature": 15.2,
186
- "windSpeed": 12.3
187
- }
188
- ```
189
-
190
- #### Test Conversationally
191
-
192
- ```bash
193
- lua dev
194
- ```
195
-
196
- Browser opens at http://localhost:3000
197
-
198
- **Try these in the chat:**
199
- - "What's the weather in London?"
200
- - "Show me all products"
201
- - "Create a shopping basket"
202
- - "Add product XYZ to my basket"
203
-
204
- ---
205
-
206
- ### Part 5: Make It Yours (10 minutes)
207
-
208
- #### Customize the Weather Tool
209
-
210
- Edit `src/tools/GetWeatherTool.ts`:
211
-
212
- ```typescript
213
- async execute(input: z.infer<typeof this.inputSchema>) {
214
- const { city } = input;
215
-
216
- // Add your custom logic
217
- const weather = await this.getWeather(city);
218
-
219
- // Return your custom format
220
- return {
221
- city: city,
222
- temperature: weather.temp,
223
- condition: weather.description,
224
- recommendation: this.getRecommendation(weather.temp)
225
- };
226
- }
227
-
228
- private getRecommendation(temp: number): string {
229
- if (temp < 10) return "Bring a jacket! ��️";
230
- if (temp < 20) return "Perfect weather! ☀️";
231
- return "Stay cool! 🥵";
232
- }
233
- ```
234
-
235
- #### Update the Skill Context
236
-
237
- Edit `src/index.ts`:
238
-
239
- ```typescript
240
- const weatherSkill = new LuaSkill({
241
- name: "weather-skill",
242
- version: "1.0.0",
243
- description: "Smart weather assistant with recommendations",
244
- context: `
245
- Use get_weather when users ask about weather.
246
- Always include clothing recommendations based on temperature.
247
- Mention wind conditions if windy (>20 km/h).
248
- `,
249
- tools: [new GetWeatherTool()]
250
- });
251
- ```
252
-
253
- ---
254
-
255
- ## 🛠️ Building Common Skills
256
-
257
- ### Recipe 1: Knowledge Base Skill
258
-
259
- **Use Case**: Company FAQ, documentation search
260
-
261
- **Tools Needed:**
262
- - `search_knowledge` - Search documentation
263
- - `create_article` - Add new articles
264
- - `update_article` - Update existing
265
-
266
- **APIs Used:** `Data` (vector search)
267
-
268
- **Implementation:**
269
- ```typescript
270
- export class SearchKnowledgeTool implements LuaTool {
271
- name = "search_knowledge";
272
- description = "Search company knowledge base";
273
- inputSchema = z.object({ query: z.string() });
274
-
275
- async execute(input: any) {
276
- const results = await Data.search('kb_articles', input.query, 5, 0.75);
277
-
278
- return {
279
- articles: results.data.map(entry => ({
280
- title: entry.data.title,
281
- content: entry.data.content,
282
- category: entry.data.category,
283
- relevance: entry.score
284
- }))
285
- };
286
- }
287
- }
288
- ```
289
-
290
- ---
291
-
292
- ### Recipe 2: E-commerce Assistant
293
-
294
- **Use Case**: Product search, shopping cart, checkout
295
-
296
- **Tools Needed:**
297
- - `search_products`
298
- - `add_to_cart`
299
- - `view_cart`
300
- - `checkout`
301
-
302
- **APIs Used:** `Products`, `Baskets`, `Orders`
303
-
304
- **Skill Definition:**
305
- ```typescript
306
- const ecommerceSkill = new LuaSkill({
307
- name: "ecommerce-skill",
308
- version: "1.0.0",
309
- description: "Complete shopping experience from browse to checkout",
310
- context: `
311
- Help users shop efficiently.
312
-
313
- Flow:
314
- 1. search_products - When users describe what they want
315
- 2. add_to_cart - When they decide to buy
316
- 3. view_cart - To review items before checkout
317
- 4. checkout - To complete purchase
318
-
319
- Always confirm items before adding to cart.
320
- Show total price before checkout.
321
- Ask about gift wrapping for orders > $50.
322
- `,
323
- tools: [
324
- new SearchProductsTool(),
325
- new AddToCartTool(),
326
- new ViewCartTool(),
327
- new CheckoutTool()
328
- ]
329
- });
330
- ```
331
-
332
- ---
333
-
334
- ### Recipe 3: CRM Assistant
335
-
336
- **Use Case**: Customer data management
337
-
338
- **Tools Needed:**
339
- - `find_customer` - Search customers
340
- - `create_customer` - Add new customer
341
- - `update_customer` - Update details
342
- - `get_customer_history` - View interactions
343
-
344
- **APIs Used:** `Data` (custom collections)
345
-
346
- **Collections:**
347
- - `customers` - Customer profiles
348
- - `interactions` - Interaction history
349
- - `notes` - Sales notes
350
-
351
- ---
352
-
353
- ### Recipe 4: Booking System
354
-
355
- **Use Case**: Appointments, reservations
356
-
357
- **Tools Needed:**
358
- - `check_availability`
359
- - `create_booking`
360
- - `cancel_booking`
361
- - `list_bookings`
362
-
363
- **APIs Used:** `Data` (bookings collection)
364
-
365
- ---
366
-
367
- ## 📖 Learning Path
368
-
369
- ### Day 1: Basics
370
- - ✅ Install CLI
371
- - ✅ Run `lua init`
372
- - ✅ Explore template
373
- - ✅ Run `lua test`
374
- - ✅ Run `lua dev`
375
-
376
- ### Day 2: Customization
377
- - ✅ Modify a template tool
378
- - ✅ Update skill context
379
- - ✅ Test changes
380
- - ✅ Understand data flow
381
-
382
- ### Day 3: Build Your Own
383
- - ✅ Create a custom tool
384
- - ✅ Integrate external API
385
- - ✅ Add environment variables
386
- - ✅ Test thoroughly
387
-
388
- ### Day 4: Deploy
389
- - ✅ Refine tool descriptions
390
- - ✅ Improve error handling
391
- - ✅ Push to server
392
- - ✅ Deploy to production
393
-
394
- ---
395
-
396
- ## 🎓 Key Concepts Deep Dive
397
-
398
- ### Tools vs Skills
399
-
400
- **Tool** = Single function
401
- ```typescript
402
- // One specific thing
403
- class GetWeatherTool {
404
- // Gets weather for a city
405
- }
406
- ```
407
-
408
- **Skill** = Collection of related tools
409
- ```typescript
410
- // Multiple related things
411
- new LuaSkill({
412
- tools: [
413
- new GetWeatherTool(),
414
- new GetForecastTool(),
415
- new GetAlertsIf Tool()
416
- ]
417
- });
418
- ```
419
-
420
- ---
421
-
422
- ### Input Schemas (Zod)
423
-
424
- Schemas validate and type inputs:
425
-
426
- ```typescript
427
- // Simple
428
- z.object({
429
- city: z.string()
430
- })
431
-
432
- // With validation
433
- z.object({
434
- age: z.number().min(0).max(120),
435
- email: z.string().email()
436
- })
437
-
438
- // Optional fields
439
- z.object({
440
- required: z.string(),
441
- optional: z.string().optional(),
442
- withDefault: z.string().default('default value')
443
- })
444
-
445
- // Nested objects
446
- z.object({
447
- user: z.object({
448
- name: z.string(),
449
- email: z.string().email()
450
- }),
451
- settings: z.object({
452
- notifications: z.boolean()
453
- })
454
- })
455
-
456
- // Enums
457
- z.object({
458
- status: z.enum(['pending', 'active', 'completed']),
459
- priority: z.enum(['low', 'medium', 'high'])
460
- })
461
- ```
462
-
463
- ---
464
-
465
- ### Context Writing
466
-
467
- Context guides the AI. Write it like instructions to a smart assistant:
468
-
469
- **Template:**
470
- ```
471
- [What this skill does]
472
-
473
- Tool Usage:
474
- - tool_1: [When to use] [What it returns]
475
- - tool_2: [When to use] [What it returns]
476
-
477
- Guidelines:
478
- - [Important rules]
479
- - [Edge cases]
480
- - [User experience tips]
481
- ```
482
-
483
- **Example:**
484
- ```
485
- This skill manages customer orders for a coffee shop.
486
-
487
- Tool Usage:
488
- - show_menu: Use when customers ask what's available. Returns drinks and food items.
489
- - create_order: Use when taking an order. Confirm items and sizes first.
490
- - modify_order: Use to add/remove items. Ask which item to modify.
491
- - finalize_order: Use when order is confirmed. Returns total and wait time.
492
-
493
- Guidelines:
494
- - Always ask about size for drinks (small/medium/large)
495
- - Mention daily special when showing menu
496
- - Confirm total before finalizing
497
- - Ask about dietary restrictions for food items
498
- ```
499
-
500
- ---
501
-
502
- ## 💡 Pro Tips
503
-
504
- ### Tip 1: Start Simple
505
-
506
- Don't build everything at once:
507
-
508
- **Week 1:** 1-3 core tools
509
- **Week 2:** Add 2-3 more tools
510
- **Week 3:** Refine based on usage
511
-
512
- ### Tip 2: Use the Template
513
-
514
- The template includes working examples of:
515
- - External API calls (`GetWeatherTool`)
516
- - Platform API usage (`UserDataTool`, `ProductsTool`)
517
- - Vector search (`CustomDataTool`)
518
- - E-commerce flow (`BasketTool`, `OrderTool`)
519
-
520
- Copy and modify instead of starting from scratch!
521
-
522
- ### Tip 3: Test in Dev Mode
523
-
524
- `lua dev` is your friend:
525
- - Real-time chat testing
526
- - Live reload on file changes
527
- - WebSocket logging
528
- - Tool testing interface
529
-
530
- Use it extensively before deploying!
531
-
532
- ### Tip 4: Descriptive Names
533
-
534
- Good tool names help the AI choose correctly:
535
-
536
- ✅ `search_products`, `create_order`, `cancel_booking`
537
- ❌ `do_search`, `make_thing`, `process`
538
-
539
- ### Tip 5: Detailed Descriptions
540
-
541
- ```typescript
542
- // ❌ Weak
543
- description = "Gets data"
544
-
545
- // ✅ Strong
546
- description = "Retrieves customer order history for the last 30 days"
547
- ```
548
-
549
- ---
550
-
551
- ## 🔧 Development Workflow
552
-
553
- ### Recommended Flow
554
-
555
- ```
556
- 1. Edit tool in src/tools/
557
-
558
- 2. Save file (auto-reload in dev mode)
559
-
560
- 3. Test in chat interface
561
-
562
- 4. Iterate until satisfied
563
-
564
- 5. Test with lua test (edge cases)
565
-
566
- 6. Push to server
567
-
568
- 7. Final testing in sandbox
569
-
570
- 8. Deploy to production
571
- ```
572
-
573
- ### Quick Commands
574
-
575
- ```bash
576
- # During development
577
- lua dev # Start, leave running
578
- # Edit files, test in browser, iterate
579
-
580
- # When ready to share
581
- lua push # Upload version
582
- lua deploy # Deploy to production
583
-
584
- # For quick local testing
585
- lua test # Test individual tools
586
- ```
587
-
588
- ---
589
-
590
- ## 🎯 Example: Building a Restaurant Skill
591
-
592
- Let's build a complete skill from scratch.
593
-
594
- ### Step 1: Initialize
595
-
596
- ```bash
597
- mkdir restaurant-skill
598
- cd restaurant-skill
599
- lua init
600
- ```
601
-
602
- ### Step 2: Plan Your Tools
603
-
604
- **What should your AI do?**
605
- - Show menu
606
- - Take orders
607
- - Check order status
608
- - Make reservations
609
-
610
- **Tools needed:**
611
- 1. `show_menu` - Display menu items
612
- 2. `create_order` - Place food order
613
- 3. `check_order` - Get order status
614
- 4. `make_reservation` - Book table
615
-
616
- ### Step 3: Create Menu Tool
617
-
618
- Create `src/tools/MenuTool.ts`:
619
-
620
- ```typescript
621
- import { LuaTool, Data } from "lua-cli";
622
- import { z } from "zod";
623
-
624
- export default class ShowMenuTool implements LuaTool {
625
- name = "show_menu";
626
- description = "Display restaurant menu with prices";
627
-
628
- inputSchema = z.object({
629
- category: z.enum(['appetizers', 'mains', 'desserts', 'drinks']).optional()
630
- });
631
-
632
- async execute(input: z.infer<typeof this.inputSchema>) {
633
- const filter = input.category ? { category: input.category } : {};
634
- const menuItems = await Data.get('menu_items', filter, 1, 50);
635
-
636
- return {
637
- items: menuItems.data.map(item => ({
638
- name: item.data.name,
639
- description: item.data.description,
640
- price: `$${item.data.price}`,
641
- category: item.data.category
642
- })),
643
- count: menuItems.pagination.totalCount
644
- };
645
- }
646
- }
647
- ```
648
-
649
- ### Step 4: Create Order Tool
650
-
651
- Create `src/tools/OrderTool.ts`:
652
-
653
- ```typescript
654
- import { LuaTool, Data } from "lua-cli";
655
- import { z } from "zod";
656
-
657
- export default class CreateOrderTool implements LuaTool {
658
- name = "create_order";
659
- description = "Place a food order";
660
-
661
- inputSchema = z.object({
662
- items: z.array(z.object({
663
- name: z.string(),
664
- quantity: z.number().min(1)
665
- })),
666
- specialInstructions: z.string().optional()
667
- });
668
-
669
- async execute(input: z.infer<typeof this.inputSchema>) {
670
- // Get menu items to calculate total
671
- const menuData = await Data.get('menu_items');
672
- const menu = menuData.data;
673
-
674
- let total = 0;
675
- const orderItems = input.items.map(item => {
676
- const menuItem = menu.find(m => m.data.name === item.name);
677
- if (!menuItem) {
678
- throw new Error(`Menu item not found: ${item.name}`);
679
- }
680
-
681
- const itemTotal = menuItem.data.price * item.quantity;
682
- total += itemTotal;
683
-
684
- return {
685
- name: item.name,
686
- quantity: item.quantity,
687
- price: menuItem.data.price,
688
- subtotal: itemTotal
689
- };
690
- });
691
-
692
- // Create order
693
- const order = await Data.create('orders', {
694
- items: orderItems,
695
- total,
696
- status: 'pending',
697
- specialInstructions: input.specialInstructions,
698
- orderedAt: new Date().toISOString()
699
- });
700
-
701
- return {
702
- orderId: order.id,
703
- items: orderItems,
704
- total: `$${total.toFixed(2)}`,
705
- estimatedTime: '20-30 minutes',
706
- message: 'Order placed successfully!'
707
- };
708
- }
709
- }
710
- ```
711
-
712
- ### Step 5: Create Reservation Tool
713
-
714
- Create `src/tools/ReservationTool.ts`:
715
-
716
- ```typescript
717
- import { LuaTool, Data, User } from "lua-cli";
718
- import { z } from "zod";
719
-
720
- export default class MakeReservationTool implements LuaTool {
721
- name = "make_reservation";
722
- description = "Book a table at the restaurant";
723
-
724
- inputSchema = z.object({
725
- date: z.string().describe("Date (YYYY-MM-DD)"),
726
- time: z.string().describe("Time (HH:MM)"),
727
- partySize: z.number().min(1).max(20),
728
- name: z.string().optional(),
729
- phone: z.string().optional()
730
- });
731
-
732
- async execute(input: z.infer<typeof this.inputSchema>) {
733
- // Get user info for contact
734
- const user = await User.get();
735
-
736
- const reservation = await Data.create('reservations', {
737
- date: input.date,
738
- time: input.time,
739
- partySize: input.partySize,
740
- contactName: input.name || user.name,
741
- contactPhone: input.phone || user.phone,
742
- status: 'confirmed',
743
- createdAt: new Date().toISOString()
744
- }, `${input.date} ${input.time} ${input.partySize} people`);
745
-
746
- return {
747
- reservationId: reservation.id,
748
- date: input.date,
749
- time: input.time,
750
- partySize: input.partySize,
751
- message: `Reservation confirmed for ${input.partySize} people on ${input.date} at ${input.time}`
752
- };
753
- }
754
- }
755
- ```
756
-
757
- ### Step 6: Update `src/index.ts`
758
-
759
- ```typescript
760
- import { LuaSkill } from "lua-cli";
761
- import ShowMenuTool from "./tools/MenuTool";
762
- import CreateOrderTool from "./tools/OrderTool";
763
- import MakeReservationTool from "./tools/ReservationTool";
764
-
765
- const restaurantSkill = new LuaSkill({
766
- name: "restaurant-skill",
767
- version: "1.0.0",
768
- description: "Complete restaurant assistant for menu, ordering, and reservations",
769
- context: `
770
- This skill helps customers interact with the restaurant.
771
-
772
- Tool Usage:
773
- - show_menu: Use when customers ask about food, menu, or what's available
774
- - create_order: Use when taking a food order. Confirm items before submitting.
775
- - make_reservation: Use for table bookings. Confirm date, time, and party size.
776
-
777
- Guidelines:
778
- - Always mention daily specials when showing menu
779
- - Confirm order details and total before submitting
780
- - For reservations, verify availability for party size
781
- - Be friendly and helpful
782
- `,
783
- tools: [
784
- new ShowMenuTool(),
785
- new CreateOrderTool(),
786
- new MakeReservationTool()
787
- ]
788
- });
789
- ```
790
-
791
- ### Step 7: Seed Menu Data
792
-
793
- Create `src/seed.ts`:
794
-
795
- ```typescript
796
- import { Data } from "lua-cli";
797
-
798
- async function seedMenu() {
799
- const menuItems = [
800
- { name: 'Caesar Salad', category: 'appetizers', price: 8.99, description: 'Fresh romaine lettuce with parmesan' },
801
- { name: 'Margherita Pizza', category: 'mains', price: 14.99, description: 'Classic tomato and mozzarella' },
802
- { name: 'Tiramisu', category: 'desserts', price: 7.99, description: 'Italian coffee-flavored dessert' },
803
- { name: 'Espresso', category: 'drinks', price: 3.50, description: 'Strong Italian coffee' }
804
- ];
805
-
806
- for (const item of menuItems) {
807
- await Data.create('menu_items', item, `${item.name} ${item.description}`);
808
- }
809
-
810
- console.log('Menu seeded successfully!');
811
- }
812
-
813
- seedMenu().catch(console.error);
814
- ```
815
-
816
- Run once:
817
- ```bash
818
- npx tsx src/seed.ts
819
- ```
820
-
821
- ### Step 8: Test!
822
-
823
- ```bash
824
- # Test tools individually
825
- lua test
826
-
827
- # Test conversationally
828
- lua dev
829
- ```
830
-
831
- **Try in chat:**
832
- - "Show me your menu"
833
- - "I'd like to order a Margherita Pizza and an Espresso"
834
- - "Book a table for 4 people tomorrow at 7pm"
835
-
836
- ### Step 9: Deploy
837
-
838
- ```bash
839
- # Push to server
840
- lua push
841
-
842
- # Deploy to production
843
- lua deploy
844
- ```
845
-
846
- ---
847
-
848
- ## 🎨 Customization Examples
849
-
850
- ### Customize Return Format
851
-
852
- ```typescript
853
- async execute(input: any) {
854
- const products = await Products.search(input.query);
855
-
856
- // Custom formatting for better AI responses
857
- return {
858
- summary: `Found ${products.data.length} matching products`,
859
- topResults: products.data.slice(0, 3).map(p => ({
860
- name: p.name,
861
- price: `$${p.price}`,
862
- description: p.description,
863
- availability: p.inStock ? '✅ Available' : '❌ Out of Stock'
864
- })),
865
- hasMore: products.data.length > 3
866
- };
867
- }
868
- ```
869
-
870
- ### Add Business Logic
871
-
872
- ```typescript
873
- async execute(input: any) {
874
- // Validate business rules
875
- if (input.age < 18 && input.category === 'alcohol') {
876
- throw new Error('Must be 18+ to purchase alcohol');
877
- }
878
-
879
- // Check inventory
880
- const product = await Products.getById(input.productId);
881
- if (!product.inStock) {
882
- return {
883
- success: false,
884
- message: `Sorry, ${product.name} is currently out of stock`,
885
- alternatives: await this.getSimilarProducts(product.category)
886
- };
887
- }
888
-
889
- // Process order...
890
- }
891
- ```
892
-
893
- ### Add Caching
894
-
895
- ```typescript
896
- export default class ExpensiveApiTool implements LuaTool {
897
- private cache = new Map<string, any>();
898
-
899
- async execute(input: any) {
900
- const cacheKey = JSON.stringify(input);
901
-
902
- // Check cache
903
- if (this.cache.has(cacheKey)) {
904
- return this.cache.get(cacheKey);
905
- }
906
-
907
- // Call API
908
- const result = await expensiveApi.call(input);
909
-
910
- // Cache result
911
- this.cache.set(cacheKey, result);
912
-
913
- return result;
914
- }
915
- }
916
- ```
917
-
918
- ---
919
-
920
- ## 📂 Template Directory Reference
921
-
922
- ### Included Examples
923
-
924
- | File | Tools | Purpose |
925
- |------|-------|---------|
926
- | `GetWeatherTool.ts` | 1 | External API integration |
927
- | `UserDataTool.ts` | 2 | User data management |
928
- | `ProductsTool.ts` | 6 | Product CRUD + search |
929
- | `BasketTool.ts` | 9 | Shopping cart operations |
930
- | `OrderTool.ts` | 4 | Order management |
931
- | `CustomDataTool.ts` | 6 | Vector search example |
932
- | `PaymentTool.ts` | 1 | Payment integration |
933
- | `CreatePostTool.ts` | 1 | Simple example |
934
-
935
- **Total: 30 example tools** covering all major use cases!
936
-
937
- ---
938
-
939
- ## 🚨 Common Mistakes
940
-
941
- ### Mistake 1: Unclear Context
942
-
943
- ❌ **Bad:**
944
- ```typescript
945
- context: "A skill with tools for stuff"
946
- ```
947
-
948
- ✅ **Good:**
949
- ```typescript
950
- context: `
951
- Use search_products when users want to find items.
952
- Use create_order when they're ready to buy.
953
- Always confirm details before creating orders.
954
- `
955
- ```
956
-
957
- ---
958
-
959
- ### Mistake 2: Poor Error Handling
960
-
961
- ❌ **Bad:**
962
- ```typescript
963
- async execute(input: any) {
964
- const result = await api.call(input);
965
- return result; // What if it fails?
966
- }
967
- ```
968
-
969
- ✅ **Good:**
970
- ```typescript
971
- async execute(input: any) {
972
- try {
973
- const result = await api.call(input);
974
- if (!result.success) {
975
- throw new Error(result.error || 'API call failed');
976
- }
977
- return result.data;
978
- } catch (error) {
979
- throw new Error(`Failed to fetch data: ${error.message}`);
980
- }
981
- }
982
- ```
983
-
984
- ---
985
-
986
- ### Mistake 3: Hardcoded Values
987
-
988
- ❌ **Bad:**
989
- ```typescript
990
- const apiKey = 'sk_abc123'; // Hardcoded!
991
- ```
992
-
993
- ✅ **Good:**
994
- ```typescript
995
- import { env } from 'lua-cli';
996
- const apiKey = env('API_KEY');
997
- ```
998
-
999
- ---
1000
-
1001
- ## 🎓 Next Steps
1002
-
1003
- After completing this guide:
1004
-
1005
- 1. **Read API Reference** - `API_REFERENCE.md` for detailed API docs
1006
- 2. **Read CLI Reference** - `CLI_REFERENCE.md` for all commands
1007
- 3. **Explore Examples** - Check all tools in `template/src/tools/`
1008
- 4. **Build Something** - Start with a simple skill
1009
- 5. **Join Community** - Share your skills and learn from others
1010
-
1011
- ---
1012
-
1013
- ## 📞 Getting Help
1014
-
1015
- - **Documentation**: https://docs.heylua.ai
1016
- - **Examples**: `template/src/tools/` directory
1017
- - **Issues**: https://github.com/lua-ai/lua-cli/issues
1018
- - **Email**: support@lua.ai
1019
-
1020
- ---
1021
-
1022
- ## ✨ You're Ready!
1023
-
1024
- You now know:
1025
- - ✅ How to set up the CLI
1026
- - ✅ How to create a project
1027
- - ✅ How to build tools
1028
- - ✅ How to test locally
1029
- - ✅ How to deploy to production
1030
- - ✅ Best practices and patterns
1031
-
1032
- **Go build something amazing!** 🚀
1033
-
1034
- ---
1035
-
1036
- **Quick Links:**
1037
- - [CLI Commands](CLI_REFERENCE.md) - All CLI commands
1038
- - [API Reference](API_REFERENCE.md) - Complete API docs
1039
- - [Developer Guide](DEVELOPER_GUIDE.md) - Advanced development
1040
-