lua-cli 2.1.0 → 2.2.1
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/commands/compile.js +42 -2
- package/dist/custom-data-api.d.ts +72 -0
- package/dist/custom-data-api.js +174 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/product-api.d.ts +141 -0
- package/dist/product-api.js +81 -1
- package/dist/services/api.d.ts +268 -0
- package/dist/services/api.js +268 -0
- package/dist/skill.js +4 -0
- package/dist/utils/sandbox.js +78 -6
- package/dist/web/app.css +58 -4
- package/dist/web/app.js +13 -13
- package/dist/web/index.html +2 -1
- package/package.json +3 -2
- package/template/lua.skill.yaml +14 -2
- package/template/package.json +1 -1
- package/template/src/index.ts +27 -2
- package/template/src/tools/CustomDataTool.ts +116 -0
- package/template/src/tools/ProductsTool.ts +117 -2
package/dist/services/api.d.ts
CHANGED
|
@@ -158,6 +158,165 @@ export interface SearchProductsResponse {
|
|
|
158
158
|
message: string;
|
|
159
159
|
data: Product[];
|
|
160
160
|
}
|
|
161
|
+
export interface BasketItem {
|
|
162
|
+
id: string;
|
|
163
|
+
price: number;
|
|
164
|
+
quantity: number;
|
|
165
|
+
SKU?: string;
|
|
166
|
+
addedAt?: string;
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
}
|
|
169
|
+
export interface Basket {
|
|
170
|
+
id: string;
|
|
171
|
+
userId: string;
|
|
172
|
+
agentId: string;
|
|
173
|
+
data: {
|
|
174
|
+
currency: string;
|
|
175
|
+
items: BasketItem[];
|
|
176
|
+
createdAt: string;
|
|
177
|
+
};
|
|
178
|
+
common: {
|
|
179
|
+
status: 'active' | 'checked_out' | 'abandoned' | 'expired';
|
|
180
|
+
totalAmount: string | number;
|
|
181
|
+
itemCount: number;
|
|
182
|
+
};
|
|
183
|
+
createdAt: string;
|
|
184
|
+
updatedAt: string;
|
|
185
|
+
__v: number;
|
|
186
|
+
}
|
|
187
|
+
export interface CreateBasketRequest {
|
|
188
|
+
currency: string;
|
|
189
|
+
}
|
|
190
|
+
export interface CreateBasketResponse {
|
|
191
|
+
success: boolean;
|
|
192
|
+
message: string;
|
|
193
|
+
data: Basket;
|
|
194
|
+
}
|
|
195
|
+
export interface GetBasketsResponse {
|
|
196
|
+
success: boolean;
|
|
197
|
+
message: string;
|
|
198
|
+
data: Basket[];
|
|
199
|
+
}
|
|
200
|
+
export interface AddItemToBasketRequest {
|
|
201
|
+
id: string;
|
|
202
|
+
price: number;
|
|
203
|
+
quantity: number;
|
|
204
|
+
[key: string]: any;
|
|
205
|
+
}
|
|
206
|
+
export interface AddItemToBasketResponse {
|
|
207
|
+
success: boolean;
|
|
208
|
+
message: string;
|
|
209
|
+
data: Basket;
|
|
210
|
+
}
|
|
211
|
+
export interface RemoveItemFromBasketResponse {
|
|
212
|
+
success: boolean;
|
|
213
|
+
message: string;
|
|
214
|
+
data: Basket;
|
|
215
|
+
}
|
|
216
|
+
export interface ClearBasketResponse {
|
|
217
|
+
success: boolean;
|
|
218
|
+
message: string;
|
|
219
|
+
data: Basket;
|
|
220
|
+
}
|
|
221
|
+
export interface UpdateBasketStatusResponse {
|
|
222
|
+
success: boolean;
|
|
223
|
+
message: string;
|
|
224
|
+
data: Basket;
|
|
225
|
+
}
|
|
226
|
+
export interface Order {
|
|
227
|
+
id: string;
|
|
228
|
+
userId: string;
|
|
229
|
+
agentId: string;
|
|
230
|
+
orderId: string;
|
|
231
|
+
data: {
|
|
232
|
+
currency: string;
|
|
233
|
+
items: BasketItem[];
|
|
234
|
+
createdAt: string;
|
|
235
|
+
basketId: string;
|
|
236
|
+
orderDate: string;
|
|
237
|
+
orderId: string;
|
|
238
|
+
[key: string]: any;
|
|
239
|
+
};
|
|
240
|
+
common: {
|
|
241
|
+
status: 'pending' | 'confirmed' | 'fulfilled' | 'cancelled';
|
|
242
|
+
totalAmount: string | number;
|
|
243
|
+
currency: string;
|
|
244
|
+
itemCount: number;
|
|
245
|
+
};
|
|
246
|
+
createdAt: string;
|
|
247
|
+
updatedAt: string;
|
|
248
|
+
__v: number;
|
|
249
|
+
}
|
|
250
|
+
export interface CreateOrderRequest {
|
|
251
|
+
basketId: string;
|
|
252
|
+
data: {
|
|
253
|
+
[key: string]: any;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export interface CreateOrderResponse {
|
|
257
|
+
success: boolean;
|
|
258
|
+
message: string;
|
|
259
|
+
data: Order;
|
|
260
|
+
}
|
|
261
|
+
export interface UpdateOrderStatusResponse {
|
|
262
|
+
success: boolean;
|
|
263
|
+
message: string;
|
|
264
|
+
data: Order;
|
|
265
|
+
}
|
|
266
|
+
export interface GetUserOrdersResponse {
|
|
267
|
+
success: boolean;
|
|
268
|
+
message: string;
|
|
269
|
+
data: Order[];
|
|
270
|
+
}
|
|
271
|
+
export type BasketStatus = 'active' | 'checked_out' | 'abandoned' | 'expired';
|
|
272
|
+
export type OrderStatus = 'pending' | 'confirmed' | 'fulfilled' | 'cancelled';
|
|
273
|
+
export interface CustomDataEntry {
|
|
274
|
+
id: string;
|
|
275
|
+
data: any;
|
|
276
|
+
createdAt: number;
|
|
277
|
+
updatedAt: number;
|
|
278
|
+
searchText?: string;
|
|
279
|
+
}
|
|
280
|
+
export interface CreateCustomDataRequest {
|
|
281
|
+
data: any;
|
|
282
|
+
searchText?: string;
|
|
283
|
+
}
|
|
284
|
+
export interface CreateCustomDataResponse {
|
|
285
|
+
id: string;
|
|
286
|
+
data: any;
|
|
287
|
+
createdAt: number;
|
|
288
|
+
updatedAt: number;
|
|
289
|
+
searchText?: string;
|
|
290
|
+
}
|
|
291
|
+
export interface GetCustomDataResponse {
|
|
292
|
+
data: CustomDataEntry[];
|
|
293
|
+
pagination: {
|
|
294
|
+
currentPage: number;
|
|
295
|
+
totalPages: number;
|
|
296
|
+
totalCount: number;
|
|
297
|
+
limit: number;
|
|
298
|
+
hasNextPage: boolean;
|
|
299
|
+
hasPrevPage: boolean;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export interface UpdateCustomDataRequest {
|
|
303
|
+
data: any;
|
|
304
|
+
searchText?: string;
|
|
305
|
+
}
|
|
306
|
+
export interface UpdateCustomDataResponse {
|
|
307
|
+
status: string;
|
|
308
|
+
message: string;
|
|
309
|
+
}
|
|
310
|
+
export interface SearchCustomDataResponse {
|
|
311
|
+
data: Array<CustomDataEntry & {
|
|
312
|
+
score: number;
|
|
313
|
+
}>;
|
|
314
|
+
count: number;
|
|
315
|
+
}
|
|
316
|
+
export interface DeleteCustomDataResponse {
|
|
317
|
+
status: string;
|
|
318
|
+
message: string;
|
|
319
|
+
}
|
|
161
320
|
/**
|
|
162
321
|
* Authentication API calls
|
|
163
322
|
*/
|
|
@@ -251,6 +410,69 @@ export declare class ProductApi {
|
|
|
251
410
|
success: false;
|
|
252
411
|
message: string;
|
|
253
412
|
}>;
|
|
413
|
+
/**
|
|
414
|
+
* Create a new user basket
|
|
415
|
+
*/
|
|
416
|
+
static createBasket(apiKey: string, agentId: string, basketData: CreateBasketRequest): Promise<CreateBasketResponse | {
|
|
417
|
+
success: false;
|
|
418
|
+
message: string;
|
|
419
|
+
}>;
|
|
420
|
+
/**
|
|
421
|
+
* Get all user baskets with optional status filter
|
|
422
|
+
*/
|
|
423
|
+
static getUserBaskets(apiKey: string, agentId: string, status?: BasketStatus): Promise<GetBasketsResponse | {
|
|
424
|
+
success: false;
|
|
425
|
+
message: string;
|
|
426
|
+
}>;
|
|
427
|
+
/**
|
|
428
|
+
* Add item to basket
|
|
429
|
+
*/
|
|
430
|
+
static addItemToBasket(apiKey: string, agentId: string, basketId: string, itemData: AddItemToBasketRequest): Promise<AddItemToBasketResponse | {
|
|
431
|
+
success: false;
|
|
432
|
+
message: string;
|
|
433
|
+
}>;
|
|
434
|
+
/**
|
|
435
|
+
* Remove item from basket
|
|
436
|
+
*/
|
|
437
|
+
static removeItemFromBasket(apiKey: string, agentId: string, basketId: string, itemId: string): Promise<RemoveItemFromBasketResponse | {
|
|
438
|
+
success: false;
|
|
439
|
+
message: string;
|
|
440
|
+
}>;
|
|
441
|
+
/**
|
|
442
|
+
* Clear basket (remove all items)
|
|
443
|
+
*/
|
|
444
|
+
static clearBasket(apiKey: string, agentId: string, basketId: string): Promise<ClearBasketResponse | {
|
|
445
|
+
success: false;
|
|
446
|
+
message: string;
|
|
447
|
+
}>;
|
|
448
|
+
/**
|
|
449
|
+
* Update basket status
|
|
450
|
+
*/
|
|
451
|
+
static updateBasketStatus(apiKey: string, agentId: string, basketId: string, status: BasketStatus): Promise<UpdateBasketStatusResponse | {
|
|
452
|
+
success: false;
|
|
453
|
+
message: string;
|
|
454
|
+
}>;
|
|
455
|
+
/**
|
|
456
|
+
* Create order from basket
|
|
457
|
+
*/
|
|
458
|
+
static createOrder(apiKey: string, agentId: string, orderData: CreateOrderRequest): Promise<CreateOrderResponse | {
|
|
459
|
+
success: false;
|
|
460
|
+
message: string;
|
|
461
|
+
}>;
|
|
462
|
+
/**
|
|
463
|
+
* Update order status
|
|
464
|
+
*/
|
|
465
|
+
static updateOrderStatus(apiKey: string, agentId: string, orderId: string, status: OrderStatus): Promise<UpdateOrderStatusResponse | {
|
|
466
|
+
success: false;
|
|
467
|
+
message: string;
|
|
468
|
+
}>;
|
|
469
|
+
/**
|
|
470
|
+
* Get user orders with optional status filter
|
|
471
|
+
*/
|
|
472
|
+
static getUserOrders(apiKey: string, agentId: string, userId: string, status?: OrderStatus): Promise<GetUserOrdersResponse | {
|
|
473
|
+
success: false;
|
|
474
|
+
message: string;
|
|
475
|
+
}>;
|
|
254
476
|
}
|
|
255
477
|
/**
|
|
256
478
|
* Tool API calls (for compile command)
|
|
@@ -268,6 +490,50 @@ export declare class UserDataApi {
|
|
|
268
490
|
static updateUserData(apiKey: string, agentId: string, data: any): Promise<ApiResponse<any>>;
|
|
269
491
|
static deleteUserData(apiKey: string, agentId: string): Promise<ApiResponse<any>>;
|
|
270
492
|
}
|
|
493
|
+
export declare class CustomDataApi {
|
|
494
|
+
/**
|
|
495
|
+
* Create a new custom data entry
|
|
496
|
+
*/
|
|
497
|
+
static createCustomData(apiKey: string, agentId: string, collectionName: string, data: CreateCustomDataRequest): Promise<CreateCustomDataResponse | {
|
|
498
|
+
success: false;
|
|
499
|
+
message: string;
|
|
500
|
+
}>;
|
|
501
|
+
/**
|
|
502
|
+
* Get custom data entries with optional filtering and pagination
|
|
503
|
+
*/
|
|
504
|
+
static getCustomData(apiKey: string, agentId: string, collectionName: string, filter?: any, page?: number, limit?: number): Promise<GetCustomDataResponse | {
|
|
505
|
+
success: false;
|
|
506
|
+
message: string;
|
|
507
|
+
}>;
|
|
508
|
+
/**
|
|
509
|
+
* Get a single custom data entry by ID
|
|
510
|
+
*/
|
|
511
|
+
static getCustomDataEntry(apiKey: string, agentId: string, collectionName: string, entryId: string): Promise<CustomDataEntry | {
|
|
512
|
+
success: false;
|
|
513
|
+
message: string;
|
|
514
|
+
}>;
|
|
515
|
+
/**
|
|
516
|
+
* Update a custom data entry
|
|
517
|
+
*/
|
|
518
|
+
static updateCustomData(apiKey: string, agentId: string, collectionName: string, entryId: string, data: UpdateCustomDataRequest): Promise<UpdateCustomDataResponse | {
|
|
519
|
+
success: false;
|
|
520
|
+
message: string;
|
|
521
|
+
}>;
|
|
522
|
+
/**
|
|
523
|
+
* Search custom data entries by text
|
|
524
|
+
*/
|
|
525
|
+
static searchCustomData(apiKey: string, agentId: string, collectionName: string, searchText: string, limit?: number, scoreThreshold?: number): Promise<SearchCustomDataResponse | {
|
|
526
|
+
success: false;
|
|
527
|
+
message: string;
|
|
528
|
+
}>;
|
|
529
|
+
/**
|
|
530
|
+
* Delete a custom data entry
|
|
531
|
+
*/
|
|
532
|
+
static deleteCustomData(apiKey: string, agentId: string, collectionName: string, entryId: string): Promise<DeleteCustomDataResponse | {
|
|
533
|
+
success: false;
|
|
534
|
+
message: string;
|
|
535
|
+
}>;
|
|
536
|
+
}
|
|
271
537
|
/**
|
|
272
538
|
* Main API service that exports all API classes
|
|
273
539
|
*/
|
|
@@ -278,4 +544,6 @@ export declare const ApiService: {
|
|
|
278
544
|
Chat: typeof ChatApi;
|
|
279
545
|
Product: typeof ProductApi;
|
|
280
546
|
Tool: typeof ToolApi;
|
|
547
|
+
UserData: typeof UserDataApi;
|
|
548
|
+
CustomData: typeof CustomDataApi;
|
|
281
549
|
};
|
package/dist/services/api.js
CHANGED
|
@@ -257,6 +257,161 @@ export class ProductApi {
|
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Create a new user basket
|
|
262
|
+
*/
|
|
263
|
+
static async createBasket(apiKey, agentId, basketData) {
|
|
264
|
+
const response = await httpClient.post(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket`, basketData, {
|
|
265
|
+
Authorization: `Bearer ${apiKey}`,
|
|
266
|
+
});
|
|
267
|
+
if (response.success) {
|
|
268
|
+
return response.data;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
message: response.error?.message || 'Failed to create basket'
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get all user baskets with optional status filter
|
|
279
|
+
*/
|
|
280
|
+
static async getUserBaskets(apiKey, agentId, status) {
|
|
281
|
+
const statusParam = status ? `?status=${status}` : '';
|
|
282
|
+
const response = await httpClient.get(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket/user${statusParam}`, {
|
|
283
|
+
Authorization: `Bearer ${apiKey}`,
|
|
284
|
+
});
|
|
285
|
+
if (response.success) {
|
|
286
|
+
return response.data;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
return {
|
|
290
|
+
success: false,
|
|
291
|
+
message: response.error?.message || 'Failed to get user baskets'
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Add item to basket
|
|
297
|
+
*/
|
|
298
|
+
static async addItemToBasket(apiKey, agentId, basketId, itemData) {
|
|
299
|
+
const response = await httpClient.post(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket/${basketId}/item`, itemData, {
|
|
300
|
+
Authorization: `Bearer ${apiKey}`,
|
|
301
|
+
});
|
|
302
|
+
if (response.success) {
|
|
303
|
+
return response.data;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return {
|
|
307
|
+
success: false,
|
|
308
|
+
message: response.error?.message || 'Failed to add item to basket'
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Remove item from basket
|
|
314
|
+
*/
|
|
315
|
+
static async removeItemFromBasket(apiKey, agentId, basketId, itemId) {
|
|
316
|
+
const response = await httpClient.delete(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket/${basketId}/item/${itemId}`, {
|
|
317
|
+
Authorization: `Bearer ${apiKey}`,
|
|
318
|
+
});
|
|
319
|
+
if (response.success) {
|
|
320
|
+
return response.data;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
return {
|
|
324
|
+
success: false,
|
|
325
|
+
message: response.error?.message || 'Failed to remove item from basket'
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Clear basket (remove all items)
|
|
331
|
+
*/
|
|
332
|
+
static async clearBasket(apiKey, agentId, basketId) {
|
|
333
|
+
const response = await httpClient.delete(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket/${basketId}/clear`, {
|
|
334
|
+
Authorization: `Bearer ${apiKey}`,
|
|
335
|
+
});
|
|
336
|
+
if (response.success) {
|
|
337
|
+
return response.data;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return {
|
|
341
|
+
success: false,
|
|
342
|
+
message: response.error?.message || 'Failed to clear basket'
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Update basket status
|
|
348
|
+
*/
|
|
349
|
+
static async updateBasketStatus(apiKey, agentId, basketId, status) {
|
|
350
|
+
const response = await httpClient.put(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/basket/${basketId}/${status}`, undefined, {
|
|
351
|
+
Authorization: `Bearer ${apiKey}`,
|
|
352
|
+
});
|
|
353
|
+
if (response.success) {
|
|
354
|
+
return response.data;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
return {
|
|
358
|
+
success: false,
|
|
359
|
+
message: response.error?.message || 'Failed to update basket status'
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Create order from basket
|
|
365
|
+
*/
|
|
366
|
+
static async createOrder(apiKey, agentId, orderData) {
|
|
367
|
+
const response = await httpClient.post(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/order`, orderData, {
|
|
368
|
+
Authorization: `Bearer ${apiKey}`,
|
|
369
|
+
});
|
|
370
|
+
if (response.success) {
|
|
371
|
+
return response.data;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
return {
|
|
375
|
+
success: false,
|
|
376
|
+
message: response.error?.message || 'Failed to create order'
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Update order status
|
|
382
|
+
*/
|
|
383
|
+
static async updateOrderStatus(apiKey, agentId, orderId, status) {
|
|
384
|
+
const response = await httpClient.put(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/order/${orderId}/${status}`, undefined, {
|
|
385
|
+
Authorization: `Bearer ${apiKey}`,
|
|
386
|
+
});
|
|
387
|
+
if (response.success) {
|
|
388
|
+
return response.data;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
return {
|
|
392
|
+
success: false,
|
|
393
|
+
message: response.error?.message || 'Failed to update order status'
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Get user orders with optional status filter
|
|
399
|
+
*/
|
|
400
|
+
static async getUserOrders(apiKey, agentId, userId, status) {
|
|
401
|
+
const statusParam = status ? `?status=${status}` : '';
|
|
402
|
+
const response = await httpClient.get(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/order/user/${userId}${statusParam}`, {
|
|
403
|
+
Authorization: `Bearer ${apiKey}`,
|
|
404
|
+
});
|
|
405
|
+
if (response.success) {
|
|
406
|
+
return response.data;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
return {
|
|
410
|
+
success: false,
|
|
411
|
+
message: response.error?.message || 'Failed to get user orders'
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
260
415
|
}
|
|
261
416
|
/**
|
|
262
417
|
* Tool API calls (for compile command)
|
|
@@ -315,6 +470,117 @@ export class UserDataApi {
|
|
|
315
470
|
return response;
|
|
316
471
|
}
|
|
317
472
|
}
|
|
473
|
+
// Custom Data API calls
|
|
474
|
+
export class CustomDataApi {
|
|
475
|
+
/**
|
|
476
|
+
* Create a new custom data entry
|
|
477
|
+
*/
|
|
478
|
+
static async createCustomData(apiKey, agentId, collectionName, data) {
|
|
479
|
+
const response = await httpClient.post(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}`, data, {
|
|
480
|
+
Authorization: `Bearer ${apiKey}`,
|
|
481
|
+
});
|
|
482
|
+
if (response.success) {
|
|
483
|
+
return response.data;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
return {
|
|
487
|
+
success: false,
|
|
488
|
+
message: response.error?.message || 'Failed to create custom data entry'
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Get custom data entries with optional filtering and pagination
|
|
494
|
+
*/
|
|
495
|
+
static async getCustomData(apiKey, agentId, collectionName, filter, page = 1, limit = 10) {
|
|
496
|
+
let url = `${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}?page=${page}&limit=${limit}`;
|
|
497
|
+
if (filter) {
|
|
498
|
+
const encodedFilter = encodeURIComponent(JSON.stringify(filter));
|
|
499
|
+
url += `&filter=${encodedFilter}`;
|
|
500
|
+
}
|
|
501
|
+
const response = await httpClient.get(url, {
|
|
502
|
+
Authorization: `Bearer ${apiKey}`,
|
|
503
|
+
});
|
|
504
|
+
if (response.success) {
|
|
505
|
+
return response.data;
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
return {
|
|
509
|
+
success: false,
|
|
510
|
+
message: response.error?.message || 'Failed to get custom data entries'
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Get a single custom data entry by ID
|
|
516
|
+
*/
|
|
517
|
+
static async getCustomDataEntry(apiKey, agentId, collectionName, entryId) {
|
|
518
|
+
const response = await httpClient.get(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}/${entryId}`, {
|
|
519
|
+
Authorization: `Bearer ${apiKey}`,
|
|
520
|
+
});
|
|
521
|
+
if (response.success) {
|
|
522
|
+
return response.data;
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
return {
|
|
526
|
+
success: false,
|
|
527
|
+
message: response.error?.message || 'Failed to get custom data entry'
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Update a custom data entry
|
|
533
|
+
*/
|
|
534
|
+
static async updateCustomData(apiKey, agentId, collectionName, entryId, data) {
|
|
535
|
+
const response = await httpClient.put(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}/${entryId}`, data, {
|
|
536
|
+
Authorization: `Bearer ${apiKey}`,
|
|
537
|
+
});
|
|
538
|
+
if (response.success) {
|
|
539
|
+
return response.data;
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
return {
|
|
543
|
+
success: false,
|
|
544
|
+
message: response.error?.message || 'Failed to update custom data entry'
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Search custom data entries by text
|
|
550
|
+
*/
|
|
551
|
+
static async searchCustomData(apiKey, agentId, collectionName, searchText, limit = 10, scoreThreshold = 0.6) {
|
|
552
|
+
const url = `${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}/search?searchText=${encodeURIComponent(searchText)}&limit=${limit}&scoreThreshold=${scoreThreshold}`;
|
|
553
|
+
const response = await httpClient.get(url, {
|
|
554
|
+
Authorization: `Bearer ${apiKey}`,
|
|
555
|
+
});
|
|
556
|
+
if (response.success) {
|
|
557
|
+
return response.data;
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
return {
|
|
561
|
+
success: false,
|
|
562
|
+
message: response.error?.message || 'Failed to search custom data entries'
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Delete a custom data entry
|
|
568
|
+
*/
|
|
569
|
+
static async deleteCustomData(apiKey, agentId, collectionName, entryId) {
|
|
570
|
+
const response = await httpClient.delete(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/custom-data/${collectionName}/${entryId}`, {
|
|
571
|
+
Authorization: `Bearer ${apiKey}`,
|
|
572
|
+
});
|
|
573
|
+
if (response.success) {
|
|
574
|
+
return response.data;
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
return {
|
|
578
|
+
success: false,
|
|
579
|
+
message: response.error?.message || 'Failed to delete custom data entry'
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
318
584
|
/**
|
|
319
585
|
* Main API service that exports all API classes
|
|
320
586
|
*/
|
|
@@ -325,4 +591,6 @@ export const ApiService = {
|
|
|
325
591
|
Chat: ChatApi,
|
|
326
592
|
Product: ProductApi,
|
|
327
593
|
Tool: ToolApi,
|
|
594
|
+
UserData: UserDataApi,
|
|
595
|
+
CustomData: CustomDataApi,
|
|
328
596
|
};
|
package/dist/skill.js
CHANGED
|
@@ -21,6 +21,10 @@ export const env = (key) => {
|
|
|
21
21
|
// Look for lua.skill.yaml in current directory and parent directories
|
|
22
22
|
let currentDir = process.cwd();
|
|
23
23
|
let yamlPath = null;
|
|
24
|
+
//check if in .env file
|
|
25
|
+
if (process.env[key]) {
|
|
26
|
+
return process.env[key];
|
|
27
|
+
}
|
|
24
28
|
while (currentDir !== path.dirname(currentDir)) {
|
|
25
29
|
const potentialPath = path.join(currentDir, 'lua.skill.yaml');
|
|
26
30
|
if (fs.existsSync(potentialPath)) {
|
package/dist/utils/sandbox.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "module";
|
|
|
2
2
|
import vm from "vm";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
|
-
import { UserDataApi, ProductApi } from "../services/api.js";
|
|
5
|
+
import { UserDataApi, ProductApi, CustomDataApi } from "../services/api.js";
|
|
6
6
|
import { readSkillConfig } from "./files.js";
|
|
7
7
|
/**
|
|
8
8
|
* Loads environment variables from multiple sources in priority order:
|
|
@@ -82,6 +82,52 @@ export function createSandbox(options) {
|
|
|
82
82
|
console.log('searchProducts', searchQuery);
|
|
83
83
|
return await ProductApi.searchProducts(apiKey, agentId, searchQuery);
|
|
84
84
|
};
|
|
85
|
+
const createBasket = async (data) => {
|
|
86
|
+
return await ProductApi.createBasket(apiKey, agentId, data);
|
|
87
|
+
};
|
|
88
|
+
const getBaskets = async (status) => {
|
|
89
|
+
return await ProductApi.getUserBaskets(apiKey, agentId, status);
|
|
90
|
+
};
|
|
91
|
+
const addItemToBasket = async (basketId, data) => {
|
|
92
|
+
return await ProductApi.addItemToBasket(apiKey, agentId, basketId, data);
|
|
93
|
+
};
|
|
94
|
+
const removeItemFromBasket = async (basketId, itemId) => {
|
|
95
|
+
return await ProductApi.removeItemFromBasket(apiKey, agentId, basketId, itemId);
|
|
96
|
+
};
|
|
97
|
+
const clearBasket = async (basketId) => {
|
|
98
|
+
return await ProductApi.clearBasket(apiKey, agentId, basketId);
|
|
99
|
+
};
|
|
100
|
+
const updateBasketStatus = async (basketId, status) => {
|
|
101
|
+
return await ProductApi.updateBasketStatus(apiKey, agentId, basketId, status);
|
|
102
|
+
};
|
|
103
|
+
const createOrder = async (data) => {
|
|
104
|
+
return await ProductApi.createOrder(apiKey, agentId, data);
|
|
105
|
+
};
|
|
106
|
+
const updateOrderStatus = async (orderId, status) => {
|
|
107
|
+
return await ProductApi.updateOrderStatus(apiKey, agentId, orderId, status);
|
|
108
|
+
};
|
|
109
|
+
const getUserOrders = async (userId) => {
|
|
110
|
+
return await ProductApi.getUserOrders(apiKey, agentId, userId);
|
|
111
|
+
};
|
|
112
|
+
// Custom Data API functions
|
|
113
|
+
const createCustomData = async (collectionName, data) => {
|
|
114
|
+
return await CustomDataApi.createCustomData(apiKey, agentId, collectionName, data);
|
|
115
|
+
};
|
|
116
|
+
const getCustomData = async (collectionName, filter, page = 1, limit = 10) => {
|
|
117
|
+
return await CustomDataApi.getCustomData(apiKey, agentId, collectionName, filter, page, limit);
|
|
118
|
+
};
|
|
119
|
+
const getCustomDataEntry = async (collectionName, entryId) => {
|
|
120
|
+
return await CustomDataApi.getCustomDataEntry(apiKey, agentId, collectionName, entryId);
|
|
121
|
+
};
|
|
122
|
+
const updateCustomData = async (collectionName, entryId, data) => {
|
|
123
|
+
return await CustomDataApi.updateCustomData(apiKey, agentId, collectionName, entryId, data);
|
|
124
|
+
};
|
|
125
|
+
const searchCustomData = async (collectionName, searchText, limit = 10, scoreThreshold = 0.6) => {
|
|
126
|
+
return await CustomDataApi.searchCustomData(apiKey, agentId, collectionName, searchText, limit, scoreThreshold);
|
|
127
|
+
};
|
|
128
|
+
const deleteCustomData = async (collectionName, entryId) => {
|
|
129
|
+
return await CustomDataApi.deleteCustomData(apiKey, agentId, collectionName, entryId);
|
|
130
|
+
};
|
|
85
131
|
// Create console object (use custom console if provided, otherwise default)
|
|
86
132
|
const consoleObj = customConsole || console;
|
|
87
133
|
// Create comprehensive polyfills for browser/Node.js APIs
|
|
@@ -219,13 +265,39 @@ export function createSandbox(options) {
|
|
|
219
265
|
},
|
|
220
266
|
product: {
|
|
221
267
|
data: {
|
|
222
|
-
create: createProduct,
|
|
223
|
-
get: getProducts,
|
|
224
|
-
update: updateProduct,
|
|
225
|
-
delete: deleteProduct,
|
|
226
|
-
search: searchProducts
|
|
268
|
+
create: createProduct, // DEPRECATED
|
|
269
|
+
get: getProducts, // DEPRECATED
|
|
270
|
+
update: updateProduct, // DEPRECATED
|
|
271
|
+
delete: deleteProduct, // DEPRECATED
|
|
272
|
+
search: searchProducts // DEPRECATED
|
|
273
|
+
},
|
|
274
|
+
create: createProduct,
|
|
275
|
+
get: getProducts,
|
|
276
|
+
update: updateProduct,
|
|
277
|
+
delete: deleteProduct,
|
|
278
|
+
search: searchProducts,
|
|
279
|
+
basket: {
|
|
280
|
+
create: createBasket,
|
|
281
|
+
get: getBaskets,
|
|
282
|
+
addItem: addItemToBasket,
|
|
283
|
+
removeItem: removeItemFromBasket,
|
|
284
|
+
clear: clearBasket,
|
|
285
|
+
updateStatus: updateBasketStatus
|
|
286
|
+
},
|
|
287
|
+
order: {
|
|
288
|
+
create: createOrder,
|
|
289
|
+
updateStatus: updateOrderStatus,
|
|
290
|
+
get: getUserOrders
|
|
227
291
|
}
|
|
228
292
|
},
|
|
293
|
+
customData: {
|
|
294
|
+
create: createCustomData,
|
|
295
|
+
get: getCustomData,
|
|
296
|
+
getEntry: getCustomDataEntry,
|
|
297
|
+
update: updateCustomData,
|
|
298
|
+
search: searchCustomData,
|
|
299
|
+
delete: deleteCustomData
|
|
300
|
+
},
|
|
229
301
|
// Environment variables function
|
|
230
302
|
env: (key) => envVars[key]
|
|
231
303
|
};
|