lua-cli 2.0.6 → 2.1.0-alpha.14

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.
@@ -227,7 +227,7 @@ async function bundleTool(tool, distDir) {
227
227
  platform: 'node',
228
228
  target: 'node16',
229
229
  outfile: outputPath,
230
- external: ['lua-cli/skill', 'lua-cli/user-data-api', 'zod'], // Exclude lua-cli modules and zod - injected into VM
230
+ external: ['lua-cli/skill', 'lua-cli/user-data-api', 'lua-cli/product-api', 'zod', 'keytar', 'esbuild', 'commander', 'inquirer', 'node-fetch', 'ws', 'socket.io-client', 'ts-morph'], // Exclude lua-cli modules, zod, and native modules
231
231
  minify: true, // Minify for smaller file sizes
232
232
  sourcemap: false,
233
233
  resolveExtensions: ['.ts', '.js', '.json'],
@@ -272,6 +272,19 @@ async function wrapToolForVM(outputPath, tool) {
272
272
  }
273
273
  }
274
274
  };
275
+
276
+ // Mock lua-cli/product-api module
277
+ const luaCliProductApi = {
278
+ product: typeof product !== 'undefined' ? product : {
279
+ data: {
280
+ get: async (page = 1, limit = 10) => ({ success: true, data: [], pagination: { currentPage: page, totalPages: 1, totalCount: 0, limit, hasNextPage: false, hasPrevPage: false, nextPage: null, prevPage: null } }),
281
+ update: async (data, productId) => ({ updated: true, isNew: false, product: data }),
282
+ create: async (data) => ({ updated: false, isNew: true, product: data }),
283
+ delete: async (productId) => ({ deleted: true }),
284
+ search: async (searchQuery) => ({ success: true, message: \`Found 0 products for "\${searchQuery}"\`, data: [] })
285
+ }
286
+ }
287
+ };
275
288
 
276
289
  // Mock zod module
277
290
  const zodModule = (() => {
@@ -313,6 +326,9 @@ async function wrapToolForVM(outputPath, tool) {
313
326
  if (id === 'lua-cli/user-data-api') {
314
327
  return luaCliUserDataApi;
315
328
  }
329
+ if (id === 'lua-cli/product-api') {
330
+ return luaCliProductApi;
331
+ }
316
332
  if (id === 'zod') {
317
333
  return zodModule;
318
334
  }
@@ -344,7 +360,7 @@ async function bundleMainIndex(indexPath, distDir) {
344
360
  platform: 'node',
345
361
  target: 'node16',
346
362
  outfile: path.join(distDir, 'index.js'),
347
- external: ['lua-cli/skill', 'lua-cli/user-data-api', 'zod'], // Exclude lua-cli modules and zod
363
+ external: ['lua-cli/skill', 'lua-cli/user-data-api', 'lua-cli/product-api', 'zod', 'keytar', 'esbuild', 'commander', 'inquirer', 'node-fetch', 'ws', 'socket.io-client', 'ts-morph'], // Exclude lua-cli modules, zod, and native modules
348
364
  minify: true, // Minify for smaller file sizes
349
365
  sourcemap: false,
350
366
  resolveExtensions: ['.ts', '.js', '.json'],
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  export { user, UserDataAPI } from './user-data-api.js';
3
+ export { product, ProductAPI } from './product-api.js';
package/dist/index.js CHANGED
@@ -45,3 +45,4 @@ program
45
45
  program.parse(process.argv);
46
46
  // Export user data API for use in projects
47
47
  export { user, UserDataAPI } from './user-data-api.js';
48
+ export { product, ProductAPI } from './product-api.js';
@@ -0,0 +1,48 @@
1
+ export interface Product {
2
+ id: string;
3
+ [key: string]: any;
4
+ }
5
+ export interface ProductsResponse {
6
+ success: boolean;
7
+ data: Product[];
8
+ pagination: {
9
+ currentPage: number;
10
+ totalPages: number;
11
+ totalCount: number;
12
+ limit: number;
13
+ hasNextPage: boolean;
14
+ hasPrevPage: boolean;
15
+ nextPage: number | null;
16
+ prevPage: number | null;
17
+ };
18
+ }
19
+ export interface CreateProductResponse {
20
+ updated: boolean;
21
+ isNew: boolean;
22
+ product: Product;
23
+ }
24
+ export interface UpdateProductResponse {
25
+ updated: boolean;
26
+ isNew: boolean;
27
+ product: Product;
28
+ }
29
+ export interface DeleteProductResponse {
30
+ deleted: boolean;
31
+ }
32
+ export interface SearchProductsResponse {
33
+ success: boolean;
34
+ message: string;
35
+ data: Product[];
36
+ }
37
+ export declare class ProductAPI {
38
+ products: Product[];
39
+ constructor();
40
+ get(page?: number, limit?: number): Promise<ProductsResponse>;
41
+ create(data: Record<string, any>): Promise<CreateProductResponse>;
42
+ update(data: Record<string, any>, productId: string): Promise<UpdateProductResponse>;
43
+ delete(productId: string): Promise<DeleteProductResponse>;
44
+ search(searchQuery: string): Promise<SearchProductsResponse>;
45
+ }
46
+ export declare const product: {
47
+ data: ProductAPI;
48
+ };
@@ -0,0 +1,61 @@
1
+ export class ProductAPI {
2
+ constructor() {
3
+ this.products = [];
4
+ }
5
+ async get(page = 1, limit = 10) {
6
+ return {
7
+ success: true,
8
+ data: this.products,
9
+ pagination: {
10
+ currentPage: page,
11
+ totalPages: 1,
12
+ totalCount: this.products.length,
13
+ limit: limit,
14
+ hasNextPage: false,
15
+ hasPrevPage: false,
16
+ nextPage: null,
17
+ prevPage: null
18
+ }
19
+ };
20
+ }
21
+ async create(data) {
22
+ const product = data;
23
+ const existingIndex = this.products.findIndex(p => p.id === product.id);
24
+ if (existingIndex >= 0) {
25
+ this.products[existingIndex] = product;
26
+ return { updated: true, isNew: false, product };
27
+ }
28
+ else {
29
+ this.products.push(product);
30
+ return { updated: false, isNew: true, product };
31
+ }
32
+ }
33
+ async update(data, productId) {
34
+ const product = data;
35
+ const existingIndex = this.products.findIndex(p => p.id === productId);
36
+ if (existingIndex >= 0) {
37
+ this.products[existingIndex] = { ...this.products[existingIndex], ...product };
38
+ return { updated: true, isNew: false, product: this.products[existingIndex] };
39
+ }
40
+ else {
41
+ this.products.push(product);
42
+ return { updated: false, isNew: true, product };
43
+ }
44
+ }
45
+ async delete(productId) {
46
+ const initialLength = this.products.length;
47
+ this.products = this.products.filter((product) => product.id !== productId);
48
+ return { deleted: this.products.length < initialLength };
49
+ }
50
+ async search(searchQuery) {
51
+ const results = this.products.filter(product => Object.values(product).some(value => String(value).toLowerCase().includes(searchQuery.toLowerCase())));
52
+ return {
53
+ success: true,
54
+ message: `Successfully found ${results.length} products for "${searchQuery}"`,
55
+ data: results
56
+ };
57
+ }
58
+ }
59
+ export const product = {
60
+ data: new ProductAPI()
61
+ };
@@ -219,23 +219,38 @@ export declare class ProductApi {
219
219
  /**
220
220
  * Get all products for an agent with pagination
221
221
  */
222
- static getProducts(apiKey: string, agentId: string, page?: number, limit?: number): Promise<ApiResponse<ProductsResponse>>;
222
+ static getProducts(apiKey: string, agentId: string, page?: number, limit?: number): Promise<ProductsResponse | {
223
+ success: false;
224
+ message: string;
225
+ }>;
223
226
  /**
224
227
  * Create a new product
225
228
  */
226
- static createProduct(apiKey: string, agentId: string, productData: Product): Promise<ApiResponse<CreateProductResponse>>;
229
+ static createProduct(apiKey: string, agentId: string, productData: Product): Promise<CreateProductResponse | {
230
+ success: false;
231
+ message: string;
232
+ }>;
227
233
  /**
228
234
  * Update an existing product
229
235
  */
230
- static updateProduct(apiKey: string, agentId: string, productData: Product): Promise<ApiResponse<UpdateProductResponse>>;
236
+ static updateProduct(apiKey: string, agentId: string, productData: Product): Promise<UpdateProductResponse | {
237
+ success: false;
238
+ message: string;
239
+ }>;
231
240
  /**
232
241
  * Delete a product
233
242
  */
234
- static deleteProduct(apiKey: string, agentId: string, productId: string): Promise<ApiResponse<DeleteProductResponse>>;
243
+ static deleteProduct(apiKey: string, agentId: string, productId: string): Promise<DeleteProductResponse | {
244
+ success: false;
245
+ message: string;
246
+ }>;
235
247
  /**
236
248
  * Search products by text query
237
249
  */
238
- static searchProducts(apiKey: string, agentId: string, searchQuery: string): Promise<ApiResponse<SearchProductsResponse>>;
250
+ static searchProducts(apiKey: string, agentId: string, searchQuery: string): Promise<SearchProductsResponse | {
251
+ success: false;
252
+ message: string;
253
+ }>;
239
254
  }
240
255
  /**
241
256
  * Tool API calls (for compile command)
@@ -176,41 +176,86 @@ 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
+ }
214
259
  }
215
260
  }
216
261
  /**
@@ -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 } from "../services/api.js";
5
+ import { UserDataApi, ProductApi } from "../services/api.js";
6
6
  import { readSkillConfig } from "./files.js";
7
7
  /**
8
8
  * Loads environment variables from multiple sources in priority order:
@@ -66,6 +66,22 @@ export function createSandbox(options) {
66
66
  const linkUserData = async (data) => {
67
67
  return await UserDataApi.createUserData(apiKey, agentId, data);
68
68
  };
69
+ const createProduct = async (data) => {
70
+ return await ProductApi.createProduct(apiKey, agentId, data);
71
+ };
72
+ const getProducts = async (page = 1, limit = 10) => {
73
+ return await ProductApi.getProducts(apiKey, agentId, page, limit);
74
+ };
75
+ const updateProduct = async (data, productId) => {
76
+ return await ProductApi.updateProduct(apiKey, agentId, { ...data, id: productId });
77
+ };
78
+ const deleteProduct = async (productId) => {
79
+ return await ProductApi.deleteProduct(apiKey, agentId, productId);
80
+ };
81
+ const searchProducts = async (searchQuery) => {
82
+ console.log('searchProducts', searchQuery);
83
+ return await ProductApi.searchProducts(apiKey, agentId, searchQuery);
84
+ };
69
85
  // Create console object (use custom console if provided, otherwise default)
70
86
  const consoleObj = customConsole || console;
71
87
  // Create comprehensive polyfills for browser/Node.js APIs
@@ -201,6 +217,15 @@ export function createSandbox(options) {
201
217
  create: linkUserData
202
218
  }
203
219
  },
220
+ product: {
221
+ data: {
222
+ create: createProduct,
223
+ get: getProducts,
224
+ update: updateProduct,
225
+ delete: deleteProduct,
226
+ search: searchProducts
227
+ }
228
+ },
204
229
  // Environment variables function
205
230
  env: (key) => envVars[key]
206
231
  };