lua-cli 2.1.0-alpha.6 → 2.2.0

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.
@@ -4,10 +4,10 @@
4
4
  */
5
5
  // Base URLs for different environments
6
6
  const BASE_URLS = {
7
- LOCAL: 'https://api.lua.dev',
8
- API: 'https://api.lua.dev',
9
- AUTH: 'https://auth.lua.dev',
10
- CHAT: 'https://api.lua.dev'
7
+ LOCAL: 'https://api.heylua.ai',
8
+ API: 'https://api.heylua.ai',
9
+ AUTH: 'https://auth.heylua.ai',
10
+ CHAT: 'https://api.heylua.ai'
11
11
  };
12
12
  /**
13
13
  * Generic HTTP client with common error handling
@@ -176,41 +176,241 @@ export class ProductApi {
176
176
  * Get all products for an agent with pagination
177
177
  */
178
178
  static async getProducts(apiKey, agentId, page = 1, limit = 10) {
179
- return httpClient.get(`${BASE_URLS.API}/developer/agents/${agentId}/products?page=${page}&limit=${limit}`, {
179
+ const response = await httpClient.get(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/products?page=${page}&limit=${limit}`, {
180
180
  Authorization: `Bearer ${apiKey}`,
181
181
  });
182
+ if (response.success) {
183
+ return response.data;
184
+ }
185
+ else {
186
+ return {
187
+ success: false,
188
+ message: response.error?.message || 'Failed to get products'
189
+ };
190
+ }
182
191
  }
183
192
  /**
184
193
  * Create a new product
185
194
  */
186
195
  static async createProduct(apiKey, agentId, productData) {
187
- return httpClient.post(`${BASE_URLS.API}/developer/agents/${agentId}/products`, productData, {
196
+ const response = await httpClient.post(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/products`, productData, {
188
197
  Authorization: `Bearer ${apiKey}`,
189
198
  });
199
+ if (response.success) {
200
+ return response.data;
201
+ }
202
+ else {
203
+ return {
204
+ success: false,
205
+ message: response.error?.message || 'Failed to create product'
206
+ };
207
+ }
190
208
  }
191
209
  /**
192
210
  * Update an existing product
193
211
  */
194
212
  static async updateProduct(apiKey, agentId, productData) {
195
- return httpClient.put(`${BASE_URLS.API}/developer/agents/${agentId}/products`, productData, {
213
+ const response = await httpClient.put(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/products`, productData, {
196
214
  Authorization: `Bearer ${apiKey}`,
197
215
  });
216
+ if (response.success) {
217
+ return response.data;
218
+ }
219
+ else {
220
+ return {
221
+ success: false,
222
+ message: response.error?.message || 'Failed to update product'
223
+ };
224
+ }
198
225
  }
199
226
  /**
200
227
  * Delete a product
201
228
  */
202
229
  static async deleteProduct(apiKey, agentId, productId) {
203
- return httpClient.delete(`${BASE_URLS.API}/developer/agents/${agentId}/products/${productId}`, {
230
+ const response = await httpClient.delete(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/products/${productId}`, {
204
231
  Authorization: `Bearer ${apiKey}`,
205
232
  });
233
+ if (response.success) {
234
+ return response.data;
235
+ }
236
+ else {
237
+ return {
238
+ success: false,
239
+ message: response.error?.message || 'Failed to delete product'
240
+ };
241
+ }
206
242
  }
207
243
  /**
208
244
  * Search products by text query
209
245
  */
210
246
  static async searchProducts(apiKey, agentId, searchQuery) {
211
- return httpClient.get(`${BASE_URLS.API}/developer/agents/${agentId}/products/search?searchQuery=${encodeURIComponent(searchQuery)}`, {
247
+ const response = await httpClient.get(`${BASE_URLS.LOCAL}/developer/agents/${agentId}/products/search?searchQuery=${encodeURIComponent(searchQuery)}`, {
212
248
  Authorization: `Bearer ${apiKey}`,
213
249
  });
250
+ if (response.success) {
251
+ return response.data;
252
+ }
253
+ else {
254
+ return {
255
+ success: false,
256
+ message: response.error?.message || 'Failed to search products'
257
+ };
258
+ }
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
+ }
214
414
  }
215
415
  }
216
416
  /**
@@ -270,6 +470,117 @@ export class UserDataApi {
270
470
  return response;
271
471
  }
272
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
+ }
273
584
  /**
274
585
  * Main API service that exports all API classes
275
586
  */
@@ -280,4 +591,6 @@ export const ApiService = {
280
591
  Chat: ChatApi,
281
592
  Product: ProductApi,
282
593
  Tool: ToolApi,
594
+ UserData: UserDataApi,
595
+ CustomData: CustomDataApi,
283
596
  };
@@ -49,11 +49,11 @@ function updatePackageJson(srcPath, destPath) {
49
49
  }
50
50
  catch (error) {
51
51
  // If we can't read any package.json, use the fallback version
52
- console.log(`Using fallback CLI version: ${currentCliVersion}`);
52
+ // console.log(`Using fallback CLI version: ${currentCliVersion}`);
53
53
  }
54
54
  // Update the lua-cli dependency version
55
55
  if (templatePackageJson.dependencies && templatePackageJson.dependencies['lua-cli']) {
56
- templatePackageJson.dependencies['lua-cli'] = `^${currentCliVersion}`;
56
+ // templatePackageJson.dependencies['lua-cli'] = `^${currentCliVersion}`;
57
57
  }
58
58
  // Write the updated package.json
59
59
  fs.writeFileSync(destPath, JSON.stringify(templatePackageJson, null, 2) + '\n');
@@ -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:
@@ -79,8 +79,55 @@ export function createSandbox(options) {
79
79
  return await ProductApi.deleteProduct(apiKey, agentId, productId);
80
80
  };
81
81
  const searchProducts = async (searchQuery) => {
82
+ console.log('searchProducts', searchQuery);
82
83
  return await ProductApi.searchProducts(apiKey, agentId, searchQuery);
83
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
+ };
84
131
  // Create console object (use custom console if provided, otherwise default)
85
132
  const consoleObj = customConsole || console;
86
133
  // Create comprehensive polyfills for browser/Node.js APIs
@@ -217,11 +264,39 @@ export function createSandbox(options) {
217
264
  }
218
265
  },
219
266
  product: {
267
+ data: {
268
+ create: createProduct, // DEPRECATED
269
+ get: getProducts, // DEPRECATED
270
+ update: updateProduct, // DEPRECATED
271
+ delete: deleteProduct, // DEPRECATED
272
+ search: searchProducts // DEPRECATED
273
+ },
220
274
  create: createProduct,
221
275
  get: getProducts,
222
276
  update: updateProduct,
223
277
  delete: deleteProduct,
224
- search: searchProducts
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
291
+ }
292
+ },
293
+ customData: {
294
+ create: createCustomData,
295
+ get: getCustomData,
296
+ getEntry: getCustomDataEntry,
297
+ update: updateCustomData,
298
+ search: searchCustomData,
299
+ delete: deleteCustomData
225
300
  },
226
301
  // Environment variables function
227
302
  env: (key) => envVars[key]