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.
- package/dist/api/job.api.service.d.ts +16 -7
- package/dist/api/job.api.service.js +21 -5
- package/dist/api/postprocessor.api.service.d.ts +61 -1
- package/dist/api/postprocessor.api.service.js +35 -0
- package/dist/api/preprocessor.api.service.d.ts +61 -1
- package/dist/api/preprocessor.api.service.js +35 -0
- package/dist/api-exports.d.ts +26 -6
- package/dist/api-exports.js +42 -29
- package/dist/cli/command-definitions.js +13 -6
- package/dist/commands/chat.js +32 -5
- package/dist/commands/compile.js +16 -2
- package/dist/commands/dev.js +23 -2
- package/dist/commands/push.d.ts +6 -2
- package/dist/commands/push.js +412 -6
- package/dist/commands/test.js +18 -2
- package/dist/common/job.instance.d.ts +3 -0
- package/dist/common/job.instance.js +8 -0
- package/dist/config/constants.d.ts +6 -5
- package/dist/config/constants.js +12 -10
- package/dist/interfaces/chat.d.ts +30 -1
- package/dist/interfaces/jobs.d.ts +21 -0
- package/dist/types/skill.d.ts +75 -56
- package/dist/types/skill.js +53 -59
- package/dist/utils/bundling.d.ts +13 -4
- package/dist/utils/bundling.js +83 -26
- package/dist/utils/compile.js +27 -6
- package/dist/utils/dev-api.d.ts +42 -2
- package/dist/utils/dev-api.js +177 -4
- package/dist/utils/dev-server.d.ts +1 -1
- package/dist/utils/dev-server.js +4 -4
- package/dist/utils/dynamic-job-bundler.d.ts +17 -0
- package/dist/utils/dynamic-job-bundler.js +143 -0
- package/dist/utils/pre-bundle-jobs.d.ts +26 -0
- package/dist/utils/pre-bundle-jobs.js +176 -0
- package/dist/utils/sandbox-storage.d.ts +48 -0
- package/dist/utils/sandbox-storage.js +114 -0
- package/dist/utils/sandbox.d.ts +2 -2
- package/dist/utils/sandbox.js +23 -7
- package/package.json +1 -1
- package/template/lua.skill.yaml +47 -0
- package/template/package-lock.json +10505 -0
- package/template/package.json +2 -1
- package/template/src/index.ts +65 -3
- package/template/src/tools/CreateInlineJob.ts +42 -0
- package/API_REFERENCE.md +0 -1408
- package/CHANGELOG.md +0 -236
- package/CLI_REFERENCE.md +0 -908
- package/GETTING_STARTED.md +0 -1040
- package/INSTANCE_TYPES.md +0 -1158
- package/README.md +0 -865
- package/TEMPLATE_GUIDE.md +0 -1398
- package/USER_DATA_INSTANCE.md +0 -621
- package/template/AGENT_CONFIGURATION.md +0 -251
- package/template/COMPLEX_JOB_EXAMPLES.md +0 -795
- package/template/DYNAMIC_JOB_CREATION.md +0 -371
- package/template/TOOL_EXAMPLES.md +0 -655
- package/template/WEBHOOKS_JOBS_QUICKSTART.md +0 -318
- package/template/WEBHOOK_JOB_EXAMPLES.md +0 -817
- package/template/src/index-agent-example.ts +0 -201
- package/template/src/postprocessors/ResponseFormatter.ts +0 -151
- package/template/src/preprocessors/MessageFilter.ts +0 -91
|
@@ -1,655 +0,0 @@
|
|
|
1
|
-
# Tool Examples - Learn by Example
|
|
2
|
-
|
|
3
|
-
Detailed explanation of every tool in the template.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 📋 Table of Contents
|
|
8
|
-
|
|
9
|
-
- [Weather Tool](#weather-tool)
|
|
10
|
-
- [User Data Tools](#user-data-tools)
|
|
11
|
-
- [Product Tools](#product-tools)
|
|
12
|
-
- [Basket Tools](#basket-tools)
|
|
13
|
-
- [Order Tools](#order-tools)
|
|
14
|
-
- [Custom Data Tools](#custom-data-tools)
|
|
15
|
-
- [Payment Tool](#payment-tool)
|
|
16
|
-
- [Post Tool](#post-tool)
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## Weather Tool
|
|
21
|
-
|
|
22
|
-
### File: `src/tools/GetWeatherTool.ts`
|
|
23
|
-
|
|
24
|
-
**What it does:** Fetches real-time weather for any city using Open-Meteo API.
|
|
25
|
-
|
|
26
|
-
**Key Features:**
|
|
27
|
-
- ✅ External API integration
|
|
28
|
-
- ✅ No API key required (free service)
|
|
29
|
-
- ✅ Two-step process (geocoding + weather)
|
|
30
|
-
- ✅ Error handling for invalid cities
|
|
31
|
-
|
|
32
|
-
**Code Walkthrough:**
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
async execute(input: { city: string }) {
|
|
36
|
-
// Step 1: Convert city name to coordinates
|
|
37
|
-
const geoUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(input.city)}&count=1`;
|
|
38
|
-
const geoRes = await fetch(geoUrl);
|
|
39
|
-
const geoData = await geoRes.json();
|
|
40
|
-
|
|
41
|
-
if (!geoData.results?.[0]) {
|
|
42
|
-
throw new Error(`City not found: ${input.city}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { latitude, longitude, name } = geoData.results[0];
|
|
46
|
-
|
|
47
|
-
// Step 2: Get weather for coordinates
|
|
48
|
-
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true`;
|
|
49
|
-
const weatherRes = await fetch(weatherUrl);
|
|
50
|
-
const weatherData = await weatherRes.json();
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
city: name,
|
|
54
|
-
temperature: weatherData.current_weather.temperature,
|
|
55
|
-
windSpeed: weatherData.current_weather.windspeed
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
**Learn from this:**
|
|
61
|
-
- How to call external APIs
|
|
62
|
-
- How to handle API responses
|
|
63
|
-
- How to chain multiple API calls
|
|
64
|
-
- How to handle errors gracefully
|
|
65
|
-
|
|
66
|
-
**Use it for:**
|
|
67
|
-
- Weather information
|
|
68
|
-
- Location services
|
|
69
|
-
- Any external API integration
|
|
70
|
-
|
|
71
|
-
**Customize:**
|
|
72
|
-
```typescript
|
|
73
|
-
// Add weather recommendations
|
|
74
|
-
return {
|
|
75
|
-
...weather,
|
|
76
|
-
recommendation: weather.temperature < 10
|
|
77
|
-
? "Bring a jacket!"
|
|
78
|
-
: "Perfect weather!"
|
|
79
|
-
};
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## User Data Tools
|
|
85
|
-
|
|
86
|
-
### File: `src/tools/UserDataTool.ts`
|
|
87
|
-
|
|
88
|
-
Contains 2 tools for user management.
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
### Tool 1: GetUserDataTool
|
|
93
|
-
|
|
94
|
-
**What it does:** Retrieves current user's data from Lua platform.
|
|
95
|
-
|
|
96
|
-
**Code:**
|
|
97
|
-
```typescript
|
|
98
|
-
async execute(input: {}) {
|
|
99
|
-
return User.get();
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Returns:**
|
|
104
|
-
```typescript
|
|
105
|
-
{
|
|
106
|
-
id: string;
|
|
107
|
-
email: string;
|
|
108
|
-
name: string;
|
|
109
|
-
// ... other user fields
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**Learn from this:**
|
|
114
|
-
- Simplest possible tool
|
|
115
|
-
- Platform API usage
|
|
116
|
-
- No input required
|
|
117
|
-
|
|
118
|
-
**Use it for:**
|
|
119
|
-
- Displaying user profile
|
|
120
|
-
- Personalizing responses
|
|
121
|
-
- User verification
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
### Tool 2: UpdateUserDataTool
|
|
126
|
-
|
|
127
|
-
**What it does:** Updates user's data.
|
|
128
|
-
|
|
129
|
-
**Code:**
|
|
130
|
-
```typescript
|
|
131
|
-
async execute(input: { data: { name?: string; age?: number } }) {
|
|
132
|
-
const user = await User.get();
|
|
133
|
-
return await user.update(input.data);
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Learn from this:**
|
|
138
|
-
- Getting instance first
|
|
139
|
-
- Partial updates (optional fields)
|
|
140
|
-
- Chaining operations
|
|
141
|
-
|
|
142
|
-
**Use it for:**
|
|
143
|
-
- Profile updates
|
|
144
|
-
- Preference changes
|
|
145
|
-
- User data management
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## Product Tools
|
|
150
|
-
|
|
151
|
-
### File: `src/tools/ProductsTool.ts`
|
|
152
|
-
|
|
153
|
-
Contains 6 tools for complete product management.
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
-
### 1. SearchProductsTool
|
|
158
|
-
|
|
159
|
-
**What it does:** Searches product catalog.
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
async execute(input: { query: string }) {
|
|
163
|
-
return await Products.search(input.query);
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
**Use when:** Users describe what they're looking for
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
### 2. GetAllProductsTool
|
|
172
|
-
|
|
173
|
-
**What it does:** Lists all products with pagination.
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
async execute(input: { page?: number; limit?: number }) {
|
|
177
|
-
return await Products.get(input.page, input.limit);
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
**Use when:** Browsing catalog, showing inventory
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
### 3. CreateProductTool
|
|
186
|
-
|
|
187
|
-
**What it does:** Adds new product to catalog.
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
async execute(input: {
|
|
191
|
-
product: { name: string; description: string; price: number }
|
|
192
|
-
}) {
|
|
193
|
-
return Products.create({
|
|
194
|
-
...input.product,
|
|
195
|
-
id: uuidv4() // Generate unique ID
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
**Use when:** Admin adding new products
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
### 4. UpdateProductTool
|
|
205
|
-
|
|
206
|
-
**What it does:** Modifies existing product.
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
async execute(input: {
|
|
210
|
-
product: { id: string; name: string; description: string; price: number }
|
|
211
|
-
}) {
|
|
212
|
-
return Products.update(input.product, input.product.id);
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**Use when:** Updating prices, descriptions, etc.
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
### 5. GetProductByIdTool
|
|
221
|
-
|
|
222
|
-
**What it does:** Gets specific product details.
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
async execute(input: { id: string }) {
|
|
226
|
-
return Products.getById(input.id);
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
**Use when:** Need full product details
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
### 6. DeleteProductTool
|
|
235
|
-
|
|
236
|
-
**What it does:** Removes product from catalog.
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
async execute(input: { id: string }) {
|
|
240
|
-
return Products.delete(input.id);
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
**Use when:** Discontinuing products
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## Basket Tools
|
|
249
|
-
|
|
250
|
-
### File: `src/tools/BasketTool.ts`
|
|
251
|
-
|
|
252
|
-
Contains 9 tools for complete shopping cart flow.
|
|
253
|
-
|
|
254
|
-
---
|
|
255
|
-
|
|
256
|
-
### The Complete Shopping Flow
|
|
257
|
-
|
|
258
|
-
```
|
|
259
|
-
create_basket
|
|
260
|
-
↓
|
|
261
|
-
add_to_basket (multiple items)
|
|
262
|
-
↓
|
|
263
|
-
update_basket_metadata (shipping info, etc.)
|
|
264
|
-
↓
|
|
265
|
-
checkout_basket
|
|
266
|
-
↓
|
|
267
|
-
Order created!
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
### Tool Breakdown
|
|
273
|
-
|
|
274
|
-
**1. CreateBasketTool** - Start shopping
|
|
275
|
-
```typescript
|
|
276
|
-
async execute(input: { currency: string }) {
|
|
277
|
-
return Baskets.create({ currency: input.currency });
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
**2. AddItemToBasketTool** - Add products
|
|
282
|
-
```typescript
|
|
283
|
-
async execute(input: { basketId, productId, quantity }) {
|
|
284
|
-
const product = await Products.getById(input.productId);
|
|
285
|
-
return Baskets.addItem(input.basketId, {
|
|
286
|
-
id: input.productId,
|
|
287
|
-
price: product.price,
|
|
288
|
-
quantity: input.quantity
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
**3. RemoveItemFromBasketTool** - Remove products
|
|
294
|
-
**4. ClearBasketTool** - Empty cart
|
|
295
|
-
**5. UpdateBasketStatusTool** - Change status
|
|
296
|
-
**6. UpdateBasketMetadataTool** - Add notes, shipping info
|
|
297
|
-
**7. CheckoutBasketTool** - Convert to order
|
|
298
|
-
**8. GetBasketByIdTool** - View specific basket
|
|
299
|
-
**9. GetBasketsTool** - List all baskets
|
|
300
|
-
|
|
301
|
-
**Learn from this:**
|
|
302
|
-
- Multi-step workflows
|
|
303
|
-
- State management
|
|
304
|
-
- Business logic
|
|
305
|
-
- API chaining
|
|
306
|
-
|
|
307
|
-
---
|
|
308
|
-
|
|
309
|
-
## Order Tools
|
|
310
|
-
|
|
311
|
-
### File: `src/tools/OrderTool.ts`
|
|
312
|
-
|
|
313
|
-
Contains 4 tools for order management.
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
### Tool Breakdown
|
|
318
|
-
|
|
319
|
-
**1. CreateOrderTool** - Create from basket
|
|
320
|
-
```typescript
|
|
321
|
-
async execute(input: { basketId, data }) {
|
|
322
|
-
return Orders.create({
|
|
323
|
-
basketId: input.basketId,
|
|
324
|
-
data: input.data
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
**2. UpdateOrderStatusTool** - Update fulfillment status
|
|
330
|
-
```typescript
|
|
331
|
-
async execute(input: { orderId, status }) {
|
|
332
|
-
return Orders.updateStatus(input.status, input.orderId);
|
|
333
|
-
}
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Statuses: `pending` → `confirmed` → `fulfilled` or `cancelled`
|
|
337
|
-
|
|
338
|
-
**3. GetOrderByIdTool** - Get order details
|
|
339
|
-
**4. GetUserOrdersTool** - List user's orders
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
## Custom Data Tools
|
|
344
|
-
|
|
345
|
-
### File: `src/tools/CustomDataTool.ts`
|
|
346
|
-
|
|
347
|
-
Contains 6 tools for movie database (demonstrates custom data + vector search).
|
|
348
|
-
|
|
349
|
-
---
|
|
350
|
-
|
|
351
|
-
### The Power of Vector Search
|
|
352
|
-
|
|
353
|
-
**Traditional search:**
|
|
354
|
-
- Query: "Inception" → Finds "Inception" ✅
|
|
355
|
-
- Query: "dream movie" → Finds nothing ❌
|
|
356
|
-
|
|
357
|
-
**Vector search:**
|
|
358
|
-
- Query: "Inception" → Finds "Inception" ✅
|
|
359
|
-
- Query: "dream movie" → Finds "Inception"! ✅ (semantic understanding)
|
|
360
|
-
|
|
361
|
-
---
|
|
362
|
-
|
|
363
|
-
### Tool Breakdown
|
|
364
|
-
|
|
365
|
-
**1. CreateMovieTool** - Add movie with search indexing
|
|
366
|
-
|
|
367
|
-
```typescript
|
|
368
|
-
async execute(input: { title, director, year, genre }) {
|
|
369
|
-
// Create searchable text
|
|
370
|
-
const searchText = `${input.title} ${input.director} ${input.genre}`;
|
|
371
|
-
|
|
372
|
-
return Data.create('movies', input, searchText);
|
|
373
|
-
}
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
**Key:** The `searchText` parameter enables vector search!
|
|
377
|
-
|
|
378
|
-
---
|
|
379
|
-
|
|
380
|
-
**2. SearchMoviesTool** - Semantic search
|
|
381
|
-
|
|
382
|
-
```typescript
|
|
383
|
-
async execute(input: { query: string }) {
|
|
384
|
-
return Data.search('movies', input.query, 10, 0.7);
|
|
385
|
-
}
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
**Try:**
|
|
389
|
-
- "sci-fi thriller about dreams" → Finds Inception!
|
|
390
|
-
- "Christopher Nolan movies" → Finds his films!
|
|
391
|
-
- "mind-bending" → Finds similar themes!
|
|
392
|
-
|
|
393
|
-
**Scores:**
|
|
394
|
-
- `1.0` = Perfect match
|
|
395
|
-
- `0.8-0.9` = Very similar
|
|
396
|
-
- `0.7-0.8` = Somewhat similar
|
|
397
|
-
- `<0.7` = Different
|
|
398
|
-
|
|
399
|
-
---
|
|
400
|
-
|
|
401
|
-
**3. GetMoviesTool** - List all
|
|
402
|
-
**4. GetMovieByIdTool** - Get specific
|
|
403
|
-
**5. UpdateMovieTool** - Modify details
|
|
404
|
-
**6. DeleteMovieTool** - Remove movie
|
|
405
|
-
|
|
406
|
-
**Learn from this:**
|
|
407
|
-
- Vector search implementation
|
|
408
|
-
- Custom data collections
|
|
409
|
-
- Semantic similarity
|
|
410
|
-
- CRUD patterns
|
|
411
|
-
|
|
412
|
-
**Use it for:**
|
|
413
|
-
- Knowledge bases
|
|
414
|
-
- FAQs
|
|
415
|
-
- Documentation search
|
|
416
|
-
- Product recommendations
|
|
417
|
-
- Content discovery
|
|
418
|
-
|
|
419
|
-
---
|
|
420
|
-
|
|
421
|
-
## Payment Tool
|
|
422
|
-
|
|
423
|
-
### File: `src/tools/PaymentTool.ts`
|
|
424
|
-
|
|
425
|
-
**What it does:** Creates Stripe payment links.
|
|
426
|
-
|
|
427
|
-
**Code:**
|
|
428
|
-
```typescript
|
|
429
|
-
async execute(input: {
|
|
430
|
-
amount: number;
|
|
431
|
-
currency: string;
|
|
432
|
-
description: string
|
|
433
|
-
}) {
|
|
434
|
-
const stripeKey = env('STRIPE_API_KEY');
|
|
435
|
-
|
|
436
|
-
if (!stripeKey) {
|
|
437
|
-
throw new Error('Stripe not configured');
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Call Stripe API...
|
|
441
|
-
return { paymentUrl: "https://checkout.stripe.com/..." };
|
|
442
|
-
}
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
**Learn from this:**
|
|
446
|
-
- Environment variables
|
|
447
|
-
- API key management
|
|
448
|
-
- Payment integration
|
|
449
|
-
- Security best practices
|
|
450
|
-
|
|
451
|
-
**Requires:**
|
|
452
|
-
- `.env` file with `STRIPE_API_KEY=sk_test_...`
|
|
453
|
-
- Stripe account
|
|
454
|
-
|
|
455
|
-
---
|
|
456
|
-
|
|
457
|
-
## Post Tool
|
|
458
|
-
|
|
459
|
-
### File: `src/tools/CreatePostTool.ts`
|
|
460
|
-
|
|
461
|
-
**What it does:** Simple example of creating a post.
|
|
462
|
-
|
|
463
|
-
**Code:**
|
|
464
|
-
```typescript
|
|
465
|
-
async execute(input: { title: string; content: string }) {
|
|
466
|
-
return {
|
|
467
|
-
id: Math.random().toString(36),
|
|
468
|
-
title: input.title,
|
|
469
|
-
content: input.content,
|
|
470
|
-
createdAt: new Date().toISOString()
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
**Learn from this:**
|
|
476
|
-
- Simplest tool pattern
|
|
477
|
-
- ID generation
|
|
478
|
-
- Timestamp handling
|
|
479
|
-
- Returning structured data
|
|
480
|
-
|
|
481
|
-
**Use it for:**
|
|
482
|
-
- Starting point for new tools
|
|
483
|
-
- Simple data creation
|
|
484
|
-
- Learning the basics
|
|
485
|
-
|
|
486
|
-
---
|
|
487
|
-
|
|
488
|
-
## 🎯 Recommended Learning Order
|
|
489
|
-
|
|
490
|
-
### 1. Start Simple
|
|
491
|
-
**Read:** `CreatePostTool.ts`
|
|
492
|
-
**Why:** Simplest example, easy to understand
|
|
493
|
-
|
|
494
|
-
### 2. External API
|
|
495
|
-
**Read:** `GetWeatherTool.ts`
|
|
496
|
-
**Why:** Shows API integration pattern
|
|
497
|
-
|
|
498
|
-
### 3. Platform API
|
|
499
|
-
**Read:** `UserDataTool.ts`
|
|
500
|
-
**Why:** Shows platform API usage
|
|
501
|
-
|
|
502
|
-
### 4. CRUD Pattern
|
|
503
|
-
**Read:** `ProductsTool.ts`
|
|
504
|
-
**Why:** Complete CRUD operations
|
|
505
|
-
|
|
506
|
-
### 5. Vector Search
|
|
507
|
-
**Read:** `CustomDataTool.ts`
|
|
508
|
-
**Why:** Advanced feature, very powerful
|
|
509
|
-
|
|
510
|
-
### 6. Complex Workflow
|
|
511
|
-
**Read:** `BasketTool.ts`
|
|
512
|
-
**Why:** Multi-step business logic
|
|
513
|
-
|
|
514
|
-
---
|
|
515
|
-
|
|
516
|
-
## 💡 How to Use These Examples
|
|
517
|
-
|
|
518
|
-
### Approach 1: Copy and Modify
|
|
519
|
-
|
|
520
|
-
1. Find similar tool (e.g., `CustomDataTool.ts` for searchable data)
|
|
521
|
-
2. Copy the file
|
|
522
|
-
3. Rename (e.g., `ArticleTool.ts`)
|
|
523
|
-
4. Update names, descriptions
|
|
524
|
-
5. Modify logic for your domain
|
|
525
|
-
|
|
526
|
-
**Time:** 15-30 minutes per tool
|
|
527
|
-
|
|
528
|
-
---
|
|
529
|
-
|
|
530
|
-
### Approach 2: Learn Pattern, Build New
|
|
531
|
-
|
|
532
|
-
1. Read an example tool
|
|
533
|
-
2. Understand the pattern
|
|
534
|
-
3. Close the file
|
|
535
|
-
4. Build your own from memory
|
|
536
|
-
5. Refer back if stuck
|
|
537
|
-
|
|
538
|
-
**Time:** 30-60 minutes per tool
|
|
539
|
-
**Learning:** Deeper understanding
|
|
540
|
-
|
|
541
|
-
---
|
|
542
|
-
|
|
543
|
-
### Approach 3: Mix and Match
|
|
544
|
-
|
|
545
|
-
1. Keep useful examples as-is
|
|
546
|
-
2. Delete irrelevant ones
|
|
547
|
-
3. Add your custom tools alongside
|
|
548
|
-
4. Deploy mix of examples + custom
|
|
549
|
-
|
|
550
|
-
**Time:** Variable
|
|
551
|
-
**Best for:** Quick prototyping
|
|
552
|
-
|
|
553
|
-
---
|
|
554
|
-
|
|
555
|
-
## 🔧 Customization Examples
|
|
556
|
-
|
|
557
|
-
### Make Weather More Useful
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
async execute(input: { city: string }) {
|
|
561
|
-
const weather = await this.getWeather(input.city);
|
|
562
|
-
|
|
563
|
-
// Add recommendations
|
|
564
|
-
const temp = weather.temperature;
|
|
565
|
-
let advice = "";
|
|
566
|
-
if (temp < 10) advice = "🧥 Wear a warm jacket";
|
|
567
|
-
else if (temp < 20) advice = "👕 Light jacket recommended";
|
|
568
|
-
else advice = "☀️ T-shirt weather!";
|
|
569
|
-
|
|
570
|
-
return {
|
|
571
|
-
...weather,
|
|
572
|
-
clothingAdvice: advice,
|
|
573
|
-
emoji: temp < 10 ? "❄️" : temp < 20 ? "🌤️" : "☀️"
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
---
|
|
579
|
-
|
|
580
|
-
### Add Business Logic to Products
|
|
581
|
-
|
|
582
|
-
```typescript
|
|
583
|
-
async execute(input: { query: string; maxPrice?: number }) {
|
|
584
|
-
const results = await Products.search(input.query);
|
|
585
|
-
|
|
586
|
-
// Filter by price if specified
|
|
587
|
-
let products = results.data;
|
|
588
|
-
if (input.maxPrice) {
|
|
589
|
-
products = products.filter(p => p.price <= input.maxPrice);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// Add availability message
|
|
593
|
-
return {
|
|
594
|
-
products: products.map(p => ({
|
|
595
|
-
...p,
|
|
596
|
-
message: p.inStock
|
|
597
|
-
? "✅ Available for immediate delivery"
|
|
598
|
-
: "⏰ Back in stock in 2 weeks"
|
|
599
|
-
})),
|
|
600
|
-
total: products.length
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
```
|
|
604
|
-
|
|
605
|
-
---
|
|
606
|
-
|
|
607
|
-
### Enhance Search with Scoring
|
|
608
|
-
|
|
609
|
-
```typescript
|
|
610
|
-
async execute(input: { query: string }) {
|
|
611
|
-
const results = await Data.search('movies', input.query, 10, 0.6);
|
|
612
|
-
|
|
613
|
-
return {
|
|
614
|
-
movies: results.data.map(entry => ({
|
|
615
|
-
...entry.data,
|
|
616
|
-
matchQuality: entry.score > 0.9 ? "🌟 Excellent match" :
|
|
617
|
-
entry.score > 0.8 ? "✅ Good match" :
|
|
618
|
-
entry.score > 0.7 ? "👍 Fair match" :
|
|
619
|
-
"🤔 Possible match"
|
|
620
|
-
})),
|
|
621
|
-
tip: "Higher scores = better matches"
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
---
|
|
627
|
-
|
|
628
|
-
## 🎯 Quick Reference
|
|
629
|
-
|
|
630
|
-
| Tool | File | API Used | Complexity | Start Here? |
|
|
631
|
-
|------|------|----------|------------|-------------|
|
|
632
|
-
| Create Post | CreatePostTool.ts | None | ⭐ Easy | ✅ Yes |
|
|
633
|
-
| Get Weather | GetWeatherTool.ts | External | ⭐⭐ Medium | ✅ Yes |
|
|
634
|
-
| User Data | UserDataTool.ts | User | ⭐ Easy | ✅ Yes |
|
|
635
|
-
| Products | ProductsTool.ts | Products | ⭐⭐ Medium | After basics |
|
|
636
|
-
| Custom Data | CustomDataTool.ts | Data | ⭐⭐⭐ Advanced | After CRUD |
|
|
637
|
-
| Baskets | BasketTool.ts | Baskets | ⭐⭐⭐ Complex | After APIs |
|
|
638
|
-
| Orders | OrderTool.ts | Orders | ⭐⭐ Medium | With Baskets |
|
|
639
|
-
| Payment | PaymentTool.ts | External + env | ⭐⭐⭐ Advanced | Last |
|
|
640
|
-
|
|
641
|
-
---
|
|
642
|
-
|
|
643
|
-
## 🚀 Next Steps
|
|
644
|
-
|
|
645
|
-
1. **Read** the code for 2-3 tools
|
|
646
|
-
2. **Test** them with `lua test`
|
|
647
|
-
3. **Modify** one tool slightly
|
|
648
|
-
4. **Test** your changes
|
|
649
|
-
5. **Build confidence** to create your own
|
|
650
|
-
|
|
651
|
-
---
|
|
652
|
-
|
|
653
|
-
**For complete API reference, see `../API_REFERENCE.md`**
|
|
654
|
-
**For project guide, see `README.md`**
|
|
655
|
-
|