lua-cli 2.2.8-alpha.1 → 2.3.0-alpha.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.
Files changed (191) hide show
  1. package/API_REFERENCE.md +1408 -0
  2. package/CLI_REFERENCE.md +818 -0
  3. package/GETTING_STARTED.md +1040 -0
  4. package/README.md +738 -424
  5. package/TEMPLATE_GUIDE.md +1398 -0
  6. package/dist/api/agent.api.service.d.ts +45 -0
  7. package/dist/api/agent.api.service.js +57 -0
  8. package/dist/api/auth.api.service.d.ts +48 -0
  9. package/dist/api/auth.api.service.js +54 -0
  10. package/dist/api/basket.api.service.d.ts +85 -0
  11. package/dist/api/basket.api.service.js +164 -0
  12. package/dist/api/chat.api.service.d.ts +21 -0
  13. package/dist/api/chat.api.service.js +24 -0
  14. package/dist/api/credentials.d.ts +24 -0
  15. package/dist/api/credentials.js +46 -0
  16. package/dist/api/custom.data.api.service.d.ts +69 -0
  17. package/dist/api/custom.data.api.service.js +125 -0
  18. package/dist/api/lazy-instances.d.ts +49 -0
  19. package/dist/api/lazy-instances.js +95 -0
  20. package/dist/api/order.api.service.d.ts +53 -0
  21. package/dist/api/order.api.service.js +95 -0
  22. package/dist/api/products.api.service.d.ts +66 -0
  23. package/dist/api/products.api.service.js +112 -0
  24. package/dist/api/skills.api.service.d.ts +77 -0
  25. package/dist/api/skills.api.service.js +88 -0
  26. package/dist/api/tool.api.service.d.ts +52 -0
  27. package/dist/api/tool.api.service.js +73 -0
  28. package/dist/api/user.data.api.service.d.ts +33 -0
  29. package/dist/api/user.data.api.service.js +59 -0
  30. package/dist/api-exports.d.ts +271 -0
  31. package/dist/api-exports.js +372 -0
  32. package/dist/cli/command-definitions.d.ts +30 -0
  33. package/dist/cli/command-definitions.js +71 -0
  34. package/dist/commands/agents.d.ts +20 -0
  35. package/dist/commands/agents.js +24 -2
  36. package/dist/commands/apiKey.d.ts +23 -0
  37. package/dist/commands/apiKey.js +23 -0
  38. package/dist/commands/compile.d.ts +24 -0
  39. package/dist/commands/compile.js +67 -759
  40. package/dist/commands/configure.d.ts +24 -0
  41. package/dist/commands/configure.js +31 -96
  42. package/dist/commands/deploy.d.ts +31 -19
  43. package/dist/commands/deploy.js +45 -74
  44. package/dist/commands/destroy.d.ts +27 -0
  45. package/dist/commands/destroy.js +27 -1
  46. package/dist/commands/dev.d.ts +25 -62
  47. package/dist/commands/dev.js +58 -873
  48. package/dist/commands/init.d.ts +27 -0
  49. package/dist/commands/init.js +98 -260
  50. package/dist/commands/push.d.ts +24 -21
  51. package/dist/commands/push.js +39 -92
  52. package/dist/commands/test.d.ts +26 -0
  53. package/dist/commands/test.js +41 -188
  54. package/dist/common/basket.instance.d.ts +78 -0
  55. package/dist/common/basket.instance.js +132 -0
  56. package/dist/common/data.entry.instance.d.ts +39 -0
  57. package/dist/common/data.entry.instance.js +76 -0
  58. package/dist/common/http.client.d.ts +64 -0
  59. package/dist/common/http.client.js +133 -0
  60. package/dist/common/order.instance.d.ts +40 -0
  61. package/dist/common/order.instance.js +79 -0
  62. package/dist/common/product.instance.d.ts +33 -0
  63. package/dist/common/product.instance.js +63 -0
  64. package/dist/common/product.pagination.instance.d.ts +43 -0
  65. package/dist/common/product.pagination.instance.js +74 -0
  66. package/dist/common/product.search.instance.d.ts +22 -0
  67. package/dist/common/product.search.instance.js +40 -0
  68. package/dist/common/user.instance.d.ts +41 -0
  69. package/dist/common/user.instance.js +84 -0
  70. package/dist/config/auth.constants.d.ts +11 -0
  71. package/dist/config/auth.constants.js +11 -0
  72. package/dist/config/compile.constants.d.ts +67 -0
  73. package/dist/config/compile.constants.js +99 -0
  74. package/dist/config/constants.d.ts +5 -0
  75. package/dist/config/constants.js +5 -0
  76. package/dist/config/dev.constants.d.ts +65 -0
  77. package/dist/config/dev.constants.js +79 -0
  78. package/dist/config/init.constants.d.ts +23 -0
  79. package/dist/config/init.constants.js +41 -0
  80. package/dist/index.d.ts +19 -3
  81. package/dist/index.js +28 -44
  82. package/dist/interfaces/admin.d.ts +101 -0
  83. package/dist/interfaces/admin.js +5 -0
  84. package/dist/interfaces/agent.d.ts +107 -0
  85. package/dist/interfaces/agent.js +5 -0
  86. package/dist/interfaces/baskets.d.ts +135 -0
  87. package/dist/interfaces/baskets.js +19 -0
  88. package/dist/interfaces/chat.d.ts +61 -0
  89. package/dist/interfaces/chat.js +5 -0
  90. package/dist/interfaces/common.d.ts +62 -0
  91. package/dist/interfaces/common.js +8 -0
  92. package/dist/interfaces/compile.d.ts +11 -0
  93. package/dist/interfaces/compile.js +4 -0
  94. package/dist/interfaces/custom.data.d.ts +82 -0
  95. package/dist/interfaces/custom.data.js +5 -0
  96. package/dist/interfaces/deploy.d.ts +29 -0
  97. package/dist/interfaces/deploy.js +4 -0
  98. package/dist/interfaces/dev.d.ts +53 -0
  99. package/dist/interfaces/dev.js +5 -0
  100. package/dist/interfaces/init.d.ts +60 -0
  101. package/dist/interfaces/init.js +4 -0
  102. package/dist/interfaces/orders.d.ts +91 -0
  103. package/dist/interfaces/orders.js +19 -0
  104. package/dist/interfaces/product.d.ts +65 -0
  105. package/dist/interfaces/product.js +5 -0
  106. package/dist/interfaces/push.d.ts +26 -0
  107. package/dist/interfaces/push.js +4 -0
  108. package/dist/interfaces/test.d.ts +36 -0
  109. package/dist/interfaces/test.js +4 -0
  110. package/dist/services/auth.d.ts +54 -99
  111. package/dist/services/auth.js +76 -12
  112. package/dist/types/api-contracts.d.ts +211 -0
  113. package/dist/types/api-contracts.js +8 -0
  114. package/dist/types/compile.types.d.ts +76 -0
  115. package/dist/types/compile.types.js +4 -0
  116. package/dist/types/index.d.ts +23 -85
  117. package/dist/types/index.js +25 -14
  118. package/dist/types/skill.d.ts +142 -0
  119. package/dist/{skill.js → types/skill.js} +66 -19
  120. package/dist/types/tool-validation.d.ts +34 -0
  121. package/dist/types/tool-validation.js +42 -0
  122. package/dist/utils/auth-flows.d.ts +26 -0
  123. package/dist/utils/auth-flows.js +141 -0
  124. package/dist/utils/bundling.d.ts +36 -0
  125. package/dist/utils/bundling.js +137 -0
  126. package/dist/utils/compile.d.ts +37 -0
  127. package/dist/utils/compile.js +242 -0
  128. package/dist/utils/deploy-api.d.ts +26 -0
  129. package/dist/utils/deploy-api.js +53 -0
  130. package/dist/utils/deploy-helpers.d.ts +46 -0
  131. package/dist/utils/deploy-helpers.js +86 -0
  132. package/dist/utils/deployment.d.ts +25 -0
  133. package/dist/utils/deployment.js +161 -0
  134. package/dist/utils/dev-api.d.ts +61 -0
  135. package/dist/utils/dev-api.js +262 -0
  136. package/dist/utils/dev-helpers.d.ts +46 -0
  137. package/dist/utils/dev-helpers.js +83 -0
  138. package/dist/utils/dev-server.d.ts +24 -0
  139. package/dist/utils/dev-server.js +555 -0
  140. package/dist/utils/dev-watcher.d.ts +31 -0
  141. package/dist/utils/dev-watcher.js +110 -0
  142. package/dist/utils/files.js +0 -5
  143. package/dist/utils/init-agent.d.ts +34 -0
  144. package/dist/utils/init-agent.js +129 -0
  145. package/dist/utils/init-helpers.d.ts +41 -0
  146. package/dist/utils/init-helpers.js +73 -0
  147. package/dist/utils/init-prompts.d.ts +47 -0
  148. package/dist/utils/init-prompts.js +168 -0
  149. package/dist/utils/push-api.d.ts +15 -0
  150. package/dist/utils/push-api.js +48 -0
  151. package/dist/utils/push-helpers.d.ts +38 -0
  152. package/dist/utils/push-helpers.js +84 -0
  153. package/dist/utils/sandbox-storage.d.ts +27 -0
  154. package/dist/utils/sandbox-storage.js +71 -0
  155. package/dist/utils/sandbox.js +78 -118
  156. package/dist/utils/skill-management.d.ts +14 -0
  157. package/dist/utils/skill-management.js +148 -0
  158. package/dist/utils/test-helpers.d.ts +40 -0
  159. package/dist/utils/test-helpers.js +92 -0
  160. package/dist/utils/test-prompts.d.ts +23 -0
  161. package/dist/utils/test-prompts.js +186 -0
  162. package/dist/utils/tool-detection.d.ts +18 -0
  163. package/dist/utils/tool-detection.js +110 -0
  164. package/dist/web/app.css +14 -9
  165. package/package.json +11 -12
  166. package/template/QUICKSTART.md +299 -144
  167. package/template/README.md +928 -349
  168. package/template/TOOL_EXAMPLES.md +655 -0
  169. package/template/package-lock.json +3781 -0
  170. package/template/package.json +1 -1
  171. package/template/src/index.ts +81 -40
  172. package/template/src/tools/BasketTool.ts +128 -0
  173. package/template/src/tools/CustomDataTool.ts +7 -13
  174. package/template/src/tools/OrderTool.ts +54 -0
  175. package/template/src/tools/PaymentTool.ts +1 -1
  176. package/template/src/tools/ProductsTool.ts +56 -118
  177. package/template/src/tools/UserDataTool.ts +4 -27
  178. package/dist/custom-data-api.d.ts +0 -72
  179. package/dist/custom-data-api.js +0 -174
  180. package/dist/product-api.d.ts +0 -197
  181. package/dist/product-api.js +0 -152
  182. package/dist/services/api.d.ts +0 -569
  183. package/dist/services/api.js +0 -625
  184. package/dist/skill.d.ts +0 -50
  185. package/dist/types.d.ts +0 -1
  186. package/dist/types.js +0 -2
  187. package/dist/user-data-api.d.ts +0 -39
  188. package/dist/user-data-api.js +0 -50
  189. package/template/API.md +0 -604
  190. package/template/DEVELOPER.md +0 -771
  191. package/template/lua.skill.yaml +0 -16
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Push Helper Utilities
3
+ * Helper functions for the push command
4
+ */
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import inquirer from 'inquirer';
8
+ import { readSkillConfig } from './files.js';
9
+ import { clearPromptLines } from './cli.js';
10
+ /**
11
+ * Reads the version from skill configuration.
12
+ *
13
+ * @returns Version string or null if not found
14
+ */
15
+ export function readConfigVersion() {
16
+ const config = readSkillConfig();
17
+ return config?.skill?.version || null;
18
+ }
19
+ /**
20
+ * Reads and parses deploy.json file.
21
+ *
22
+ * @returns Parsed deploy data or null if not found
23
+ */
24
+ export function readDeployJson() {
25
+ const deployPath = path.join(process.cwd(), '.lua', 'deploy.json');
26
+ if (!fs.existsSync(deployPath)) {
27
+ return null;
28
+ }
29
+ const deployContent = fs.readFileSync(deployPath, 'utf8');
30
+ return JSON.parse(deployContent);
31
+ }
32
+ /**
33
+ * Prompts user to confirm version push.
34
+ *
35
+ * @param version - Version to push
36
+ * @returns True if confirmed, false otherwise
37
+ */
38
+ export async function confirmVersionPush(version) {
39
+ const { confirmed } = await inquirer.prompt([
40
+ {
41
+ type: "confirm",
42
+ name: "confirmed",
43
+ message: `Are you sure you want to push version ${version}?`,
44
+ default: false
45
+ }
46
+ ]);
47
+ clearPromptLines(2);
48
+ return confirmed;
49
+ }
50
+ /**
51
+ * Validates that configuration has required fields for push.
52
+ *
53
+ * @param config - Skill configuration
54
+ * @throws Error if configuration is invalid
55
+ */
56
+ export function validatePushConfig(config) {
57
+ if (!config) {
58
+ throw new Error("No lua.skill.yaml found. Please run this command from a skill directory.");
59
+ }
60
+ if (!config.skill?.version) {
61
+ throw new Error("No version found in skill configuration");
62
+ }
63
+ if (!config.agent?.agentId) {
64
+ throw new Error("Missing agentId in skill configuration");
65
+ }
66
+ if (!config.skill?.skillId) {
67
+ throw new Error("Missing skillId in skill configuration");
68
+ }
69
+ }
70
+ /**
71
+ * Validates that deploy data matches configuration.
72
+ *
73
+ * @param deployData - Deploy data from deploy.json
74
+ * @param configVersion - Version from configuration
75
+ * @throws Error if deploy data is invalid or version mismatch
76
+ */
77
+ export function validateDeployData(deployData, configVersion) {
78
+ if (!deployData) {
79
+ throw new Error("No deploy.json found. Compilation may have failed.");
80
+ }
81
+ if (deployData.version !== configVersion) {
82
+ throw new Error(`Version mismatch: config has ${configVersion}, deploy.json has ${deployData.version}`);
83
+ }
84
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Sandbox Storage Utilities
3
+ * Handles secure storage and retrieval of sandbox skill IDs using keytar
4
+ */
5
+ import { SkillOverride } from '../interfaces/dev.js';
6
+ /**
7
+ * Retrieves sandbox skill ID from secure storage.
8
+ *
9
+ * @param skillName - Optional skill name for multi-skill projects
10
+ * @returns The sandbox skill ID or null if not found
11
+ */
12
+ export declare function getSandboxSkillId(skillName?: string): Promise<string | null>;
13
+ /**
14
+ * Stores sandbox skill ID in secure storage.
15
+ *
16
+ * @param sandboxId - The sandbox skill ID to store
17
+ * @param skillName - Optional skill name for multi-skill projects
18
+ */
19
+ export declare function setSandboxSkillId(sandboxId: string, skillName?: string): Promise<void>;
20
+ /**
21
+ * Retrieves all sandbox skill IDs for all skills in the project.
22
+ * Reads the deploy.json file to discover all skills and their sandbox IDs.
23
+ *
24
+ * @param deployData - The deploy.json data containing skill information
25
+ * @returns Array of skill overrides with skillId and sandboxId pairs
26
+ */
27
+ export declare function getAllSandboxSkillIds(deployData: any): Promise<SkillOverride[]>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Sandbox Storage Utilities
3
+ * Handles secure storage and retrieval of sandbox skill IDs using keytar
4
+ */
5
+ import keytar from 'keytar';
6
+ import { SANDBOX_STORAGE } from '../config/dev.constants.js';
7
+ /**
8
+ * Retrieves sandbox skill ID from secure storage.
9
+ *
10
+ * @param skillName - Optional skill name for multi-skill projects
11
+ * @returns The sandbox skill ID or null if not found
12
+ */
13
+ export async function getSandboxSkillId(skillName) {
14
+ try {
15
+ const account = skillName
16
+ ? `${SANDBOX_STORAGE.ACCOUNT}_${skillName}`
17
+ : SANDBOX_STORAGE.ACCOUNT;
18
+ return await keytar.getPassword(SANDBOX_STORAGE.SERVICE, account);
19
+ }
20
+ catch (error) {
21
+ return null;
22
+ }
23
+ }
24
+ /**
25
+ * Stores sandbox skill ID in secure storage.
26
+ *
27
+ * @param sandboxId - The sandbox skill ID to store
28
+ * @param skillName - Optional skill name for multi-skill projects
29
+ */
30
+ export async function setSandboxSkillId(sandboxId, skillName) {
31
+ try {
32
+ const account = skillName
33
+ ? `${SANDBOX_STORAGE.ACCOUNT}_${skillName}`
34
+ : SANDBOX_STORAGE.ACCOUNT;
35
+ await keytar.setPassword(SANDBOX_STORAGE.SERVICE, account, sandboxId);
36
+ }
37
+ catch (error) {
38
+ // Ignore storage errors
39
+ }
40
+ }
41
+ /**
42
+ * Retrieves all sandbox skill IDs for all skills in the project.
43
+ * Reads the deploy.json file to discover all skills and their sandbox IDs.
44
+ *
45
+ * @param deployData - The deploy.json data containing skill information
46
+ * @returns Array of skill overrides with skillId and sandboxId pairs
47
+ */
48
+ export async function getAllSandboxSkillIds(deployData) {
49
+ const skillOverrides = [];
50
+ try {
51
+ if (!deployData || !deployData.skills || !Array.isArray(deployData.skills)) {
52
+ return skillOverrides;
53
+ }
54
+ // For each skill, get its sandbox ID
55
+ for (const skill of deployData.skills) {
56
+ if (skill.skillId && skill.name) {
57
+ const sandboxId = await getSandboxSkillId(skill.name);
58
+ if (sandboxId) {
59
+ skillOverrides.push({
60
+ skillId: skill.skillId,
61
+ sandboxId: sandboxId
62
+ });
63
+ }
64
+ }
65
+ }
66
+ }
67
+ catch (error) {
68
+ console.error('Error getting sandbox skill IDs:', error);
69
+ }
70
+ return skillOverrides;
71
+ }
@@ -2,8 +2,13 @@ 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, CustomDataApi } from "../services/api.js";
6
5
  import { readSkillConfig } from "./files.js";
6
+ import UserDataApiService from "../api/user.data.api.service.js";
7
+ import { BASE_URLS } from "../config/constants.js";
8
+ import ProductApiService from "../api/products.api.service.js";
9
+ import BasketApiService from "../api/basket.api.service.js";
10
+ import OrderApiService from "../api/order.api.service.js";
11
+ import CustomDataApiService from "../api/custom.data.api.service.js";
7
12
  /**
8
13
  * Loads environment variables from multiple sources in priority order:
9
14
  * 1. process.env (lowest priority)
@@ -57,80 +62,73 @@ export function createSandbox(options) {
57
62
  const envVars = loadEnvironmentVariables();
58
63
  // Create a CommonJS context for execution
59
64
  const require = createRequire(process.cwd() + '/package.json');
60
- const updateUserData = async (data) => {
61
- return await UserDataApi.updateUserData(apiKey, agentId, data);
62
- };
63
- const getUserData = async () => {
64
- return await UserDataApi.getUserData(apiKey, agentId);
65
- };
66
- const linkUserData = async (data) => {
67
- return await UserDataApi.createUserData(apiKey, agentId, data);
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
- };
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 updateBasketMetadata = async (basketId, metadata) => {
104
- return await ProductApi.updateBasketMetadata(apiKey, agentId, basketId, metadata);
105
- };
106
- const createOrder = async (data) => {
107
- return await ProductApi.createOrder(apiKey, agentId, data);
108
- };
109
- const updateOrderStatus = async (orderId, status) => {
110
- return await ProductApi.updateOrderStatus(apiKey, agentId, orderId, status);
111
- };
112
- const getUserOrders = async () => {
113
- return await ProductApi.getUserOrders(apiKey, agentId);
114
- };
115
- // Custom Data API functions
116
- const createCustomData = async (collectionName, data) => {
117
- return await CustomDataApi.createCustomData(apiKey, agentId, collectionName, data);
118
- };
119
- const getCustomData = async (collectionName, filter, page = 1, limit = 10) => {
120
- return await CustomDataApi.getCustomData(apiKey, agentId, collectionName, filter, page, limit);
121
- };
122
- const getCustomDataEntry = async (collectionName, entryId) => {
123
- return await CustomDataApi.getCustomDataEntry(apiKey, agentId, collectionName, entryId);
124
- };
125
- const updateCustomData = async (collectionName, entryId, data) => {
126
- return await CustomDataApi.updateCustomData(apiKey, agentId, collectionName, entryId, data);
127
- };
128
- const searchCustomData = async (collectionName, searchText, limit = 10, scoreThreshold = 0.6) => {
129
- return await CustomDataApi.searchCustomData(apiKey, agentId, collectionName, searchText, limit, scoreThreshold);
130
- };
131
- const deleteCustomData = async (collectionName, entryId) => {
132
- return await CustomDataApi.deleteCustomData(apiKey, agentId, collectionName, entryId);
133
- };
65
+ // const updateUserData = async (data: any) => {
66
+ // return await UserDataApi.updateUserData(apiKey, agentId, data);
67
+ // };
68
+ // const getUserData = async () => {
69
+ // return await UserDataApi.getUserData(apiKey, agentId);
70
+ // };
71
+ // const linkUserData = async (data: any) => {
72
+ // return await UserDataApi.createUserData(apiKey, agentId, data);
73
+ // };
74
+ // const createProduct = async (data: any) => {
75
+ // return await ProductApi.createProduct(apiKey, agentId, data);
76
+ // };
77
+ // const getProducts = async (page: number = 1, limit: number = 10) => {
78
+ // return await ProductApi.getProducts(apiKey, agentId, page, limit);
79
+ // };
80
+ // const updateProduct = async (data: any, productId: string) => {
81
+ // return await ProductApi.updateProduct(apiKey, agentId, { ...data, id: productId });
82
+ // };
83
+ // const deleteProduct = async (productId: string) => {
84
+ // return await ProductApi.deleteProduct(apiKey, agentId, productId);
85
+ // };
86
+ // const createBasket = async (data: any) => {
87
+ // return await ProductApi.createBasket(apiKey, agentId, data);
88
+ // };
89
+ // const getBaskets = async (status?: BasketStatus) => {
90
+ // return await ProductApi.getUserBaskets(apiKey, agentId, status);
91
+ // };
92
+ // const addItemToBasket = async (basketId: string, data: any) => {
93
+ // return await ProductApi.addItemToBasket(apiKey, agentId, basketId, data);
94
+ // };
95
+ // const removeItemFromBasket = async (basketId: string, itemId: string) => {
96
+ // return await ProductApi.removeItemFromBasket(apiKey, agentId, basketId, itemId);
97
+ // };
98
+ // const clearBasket = async (basketId: string) => {
99
+ // return await ProductApi.clearBasket(apiKey, agentId, basketId);
100
+ // };
101
+ // const updateBasketStatus = async (basketId: string, status: BasketStatus) => {
102
+ // return await ProductApi.updateBasketStatus(apiKey, agentId, basketId, status);
103
+ // };
104
+ // const createOrder = async (data: any) => {
105
+ // return await ProductApi.createOrder(apiKey, agentId, data);
106
+ // };
107
+ // const updateOrderStatus = async (orderId: string, status: OrderStatus) => {
108
+ // return await ProductApi.updateOrderStatus(apiKey, agentId, orderId, status);
109
+ // };
110
+ // const getUserOrders = async (userId: string) => {
111
+ // return await ProductApi.getUserOrders(apiKey, agentId, userId);
112
+ // };
113
+ // // Custom Data API functions
114
+ // const createCustomData = async (collectionName: string, data: any) => {
115
+ // return await CustomDataApi.createCustomData(apiKey, agentId, collectionName, data);
116
+ // };
117
+ // const getCustomData = async (collectionName: string, filter?: any, page: number = 1, limit: number = 10) => {
118
+ // return await CustomDataApi.getCustomData(apiKey, agentId, collectionName, filter, page, limit);
119
+ // };
120
+ // const getCustomDataEntry = async (collectionName: string, entryId: string) => {
121
+ // return await CustomDataApi.getCustomDataEntry(apiKey, agentId, collectionName, entryId);
122
+ // };
123
+ // const updateCustomData = async (collectionName: string, entryId: string, data: any) => {
124
+ // return await CustomDataApi.updateCustomData(apiKey, agentId, collectionName, entryId, data);
125
+ // };
126
+ // const searchCustomData = async (collectionName: string, searchText: string, limit: number = 10, scoreThreshold: number = 0.6) => {
127
+ // return await CustomDataApi.searchCustomData(apiKey, agentId, collectionName, searchText, limit, scoreThreshold);
128
+ // };
129
+ // const deleteCustomData = async (collectionName: string, entryId: string) => {
130
+ // return await CustomDataApi.deleteCustomData(apiKey, agentId, collectionName, entryId);
131
+ // };
134
132
  // Create console object (use custom console if provided, otherwise default)
135
133
  const consoleObj = customConsole || console;
136
134
  // Create comprehensive polyfills for browser/Node.js APIs
@@ -259,49 +257,11 @@ export function createSandbox(options) {
259
257
  null: null,
260
258
  Infinity: Infinity,
261
259
  NaN: NaN,
262
- user: {
263
- data: {
264
- update: updateUserData,
265
- get: getUserData,
266
- create: linkUserData
267
- }
268
- },
269
- product: {
270
- data: {
271
- create: createProduct, // DEPRECATED
272
- get: getProducts, // DEPRECATED
273
- update: updateProduct, // DEPRECATED
274
- delete: deleteProduct, // DEPRECATED
275
- search: searchProducts // DEPRECATED
276
- },
277
- create: createProduct,
278
- get: getProducts,
279
- update: updateProduct,
280
- delete: deleteProduct,
281
- search: searchProducts,
282
- basket: {
283
- create: createBasket,
284
- get: getBaskets,
285
- addItem: addItemToBasket,
286
- removeItem: removeItemFromBasket,
287
- clear: clearBasket,
288
- updateStatus: updateBasketStatus,
289
- updateMetadata: updateBasketMetadata
290
- },
291
- order: {
292
- create: createOrder,
293
- updateStatus: updateOrderStatus,
294
- get: getUserOrders
295
- }
296
- },
297
- customData: {
298
- create: createCustomData,
299
- get: getCustomData,
300
- getEntry: getCustomDataEntry,
301
- update: updateCustomData,
302
- search: searchCustomData,
303
- delete: deleteCustomData
304
- },
260
+ User: new UserDataApiService(BASE_URLS.API, apiKey, agentId),
261
+ Product: new ProductApiService(BASE_URLS.API, apiKey, agentId),
262
+ CustomData: new CustomDataApiService(BASE_URLS.API, apiKey, agentId),
263
+ Basket: new BasketApiService(BASE_URLS.API, apiKey, agentId),
264
+ Order: new OrderApiService(BASE_URLS.API, apiKey, agentId),
305
265
  // Environment variables function
306
266
  env: (key) => envVars[key]
307
267
  };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Skill Management Utilities
3
+ * Handles skill creation via API and YAML configuration management
4
+ */
5
+ import { SkillConfig } from '../types/compile.types.js';
6
+ /**
7
+ * Ensures all detected skills exist in the YAML config with valid skill IDs.
8
+ * If a skill doesn't exist or has no ID, creates it via the API.
9
+ *
10
+ * @param skillsArray - Array of skills detected from source code
11
+ * @param config - The skill configuration from lua.skill.yaml
12
+ * @returns Updated skills array with valid skill IDs
13
+ */
14
+ export declare function ensureSkillsExistInYaml(skillsArray: any[], config: SkillConfig): Promise<any[]>;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Skill Management Utilities
3
+ * Handles skill creation via API and YAML configuration management
4
+ */
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import yaml from "js-yaml";
8
+ import SkillApi from '../api/skills.api.service.js';
9
+ import { BASE_URLS } from '../config/constants.js';
10
+ import { loadApiKey } from '../services/auth.js';
11
+ import { COMPILE_FILES, SKILL_DEFAULTS, YAML_FORMAT, } from '../config/compile.constants.js';
12
+ /**
13
+ * Ensures all detected skills exist in the YAML config with valid skill IDs.
14
+ * If a skill doesn't exist or has no ID, creates it via the API.
15
+ *
16
+ * @param skillsArray - Array of skills detected from source code
17
+ * @param config - The skill configuration from lua.skill.yaml
18
+ * @returns Updated skills array with valid skill IDs
19
+ */
20
+ export async function ensureSkillsExistInYaml(skillsArray, config) {
21
+ const updatedSkillsArray = [];
22
+ let yamlUpdated = false;
23
+ const existingSkills = config?.skills || [];
24
+ const existingSkillsMap = createSkillsMap(existingSkills);
25
+ // Process each detected skill
26
+ for (const skill of skillsArray) {
27
+ const existingSkill = existingSkillsMap.get(skill.name);
28
+ if (existingSkill && existingSkill.skillId && existingSkill.skillId !== '') {
29
+ // Skill exists with valid skillId - reuse it
30
+ updatedSkillsArray.push({
31
+ ...skill,
32
+ skillId: existingSkill.skillId
33
+ });
34
+ }
35
+ else {
36
+ // Skill doesn't exist or missing skillId - create via API
37
+ const createdSkill = await createSkillViaApi(skill, config, existingSkills, existingSkill);
38
+ updatedSkillsArray.push(createdSkill);
39
+ yamlUpdated = true;
40
+ }
41
+ }
42
+ // Update YAML file if any changes were made
43
+ if (yamlUpdated) {
44
+ await updateYamlWithSkills(existingSkills, config);
45
+ }
46
+ return updatedSkillsArray;
47
+ }
48
+ /**
49
+ * Creates a map of existing skills for quick lookup by name.
50
+ *
51
+ * @param existingSkills - Array of skills from YAML config
52
+ * @returns Map of skill names to skill objects
53
+ */
54
+ function createSkillsMap(existingSkills) {
55
+ const map = new Map();
56
+ existingSkills.forEach((skill) => {
57
+ map.set(skill.name, skill);
58
+ });
59
+ return map;
60
+ }
61
+ /**
62
+ * Creates a new skill via the Lua API and updates the config.
63
+ *
64
+ * @param skill - The skill to create
65
+ * @param config - The skill configuration
66
+ * @param existingSkills - Array of existing skills (mutated)
67
+ * @param existingSkill - The existing skill entry if one exists (may be without ID)
68
+ * @returns The skill with its new ID
69
+ */
70
+ async function createSkillViaApi(skill, config, existingSkills, existingSkill) {
71
+ try {
72
+ // Validate prerequisites
73
+ const apiKey = await loadApiKey();
74
+ if (!apiKey) {
75
+ throw new Error("No API key found. Run 'lua auth configure' first.");
76
+ }
77
+ const agentId = config?.agent?.agentId;
78
+ if (!agentId) {
79
+ throw new Error("No agent ID found in lua.skill.yaml. Run 'lua init' first.");
80
+ }
81
+ // Create skill via API
82
+ const skillPayload = {
83
+ name: skill.name,
84
+ description: skill.description || `A Lua skill for ${skill.name}`,
85
+ context: skill.context || ''
86
+ };
87
+ const skillApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
88
+ const result = await skillApi.createSkill(skillPayload);
89
+ if (result.success && result.data && result.data.id) {
90
+ const newSkillId = result.data.id;
91
+ // Update YAML config with new skill ID
92
+ if (!existingSkill) {
93
+ existingSkills.push({
94
+ name: skill.name || '',
95
+ version: skill.version || SKILL_DEFAULTS.VERSION,
96
+ skillId: newSkillId
97
+ });
98
+ }
99
+ else {
100
+ existingSkill.skillId = newSkillId;
101
+ }
102
+ return {
103
+ ...skill,
104
+ skillId: newSkillId
105
+ };
106
+ }
107
+ else {
108
+ console.error(`❌ Failed to create skill ${skill.name}:`, result.error);
109
+ throw new Error(result.error?.message || 'Failed to create skill - no ID returned from API');
110
+ }
111
+ }
112
+ catch (error) {
113
+ console.error(`❌ Failed to create skill ${skill.name}:`, error);
114
+ throw error;
115
+ }
116
+ }
117
+ /**
118
+ * Updates the lua.skill.yaml file with the current skills array.
119
+ * Ensures no undefined values are written to the YAML file.
120
+ *
121
+ * @param skills - Array of skills to write
122
+ * @param config - Current skill configuration to merge with
123
+ */
124
+ async function updateYamlWithSkills(skills, config) {
125
+ // Clean skills array to ensure no undefined values
126
+ const cleanedSkills = skills.map(skill => ({
127
+ name: skill.name || '',
128
+ version: skill.version || SKILL_DEFAULTS.VERSION,
129
+ skillId: skill.skillId || ''
130
+ }));
131
+ // Update config with cleaned skills array
132
+ const updatedConfig = {
133
+ ...config,
134
+ skills: cleanedSkills
135
+ };
136
+ // Write updated YAML with consistent formatting
137
+ const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
138
+ const yamlContent = yaml.dump(updatedConfig, {
139
+ indent: YAML_FORMAT.INDENT,
140
+ lineWidth: YAML_FORMAT.LINE_WIDTH,
141
+ noRefs: YAML_FORMAT.NO_REFS,
142
+ replacer: (key, value) => {
143
+ // Replace undefined values with empty strings
144
+ return value === undefined ? '' : value;
145
+ }
146
+ });
147
+ fs.writeFileSync(yamlPath, yamlContent);
148
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Test Command Helper Utilities
3
+ * Handles tool extraction, decompression, and schema processing
4
+ */
5
+ import { ToolData } from '../interfaces/test.js';
6
+ /**
7
+ * Decompresses gzip-compressed base64 encoded code.
8
+ *
9
+ * @param compressedCode - Base64 encoded compressed code
10
+ * @returns Decompressed code string
11
+ */
12
+ export declare function decompressCode(compressedCode: string): string;
13
+ /**
14
+ * Reads and parses deploy.json file.
15
+ *
16
+ * @returns Parsed deploy data
17
+ * @throws Error if deploy.json is not found
18
+ */
19
+ export declare function readDeployJson(): any;
20
+ /**
21
+ * Extracts all tools from deploy.json (handles both new and legacy formats).
22
+ *
23
+ * @param deployData - Parsed deploy.json data
24
+ * @returns Array of tools with their metadata
25
+ * @throws Error if no tools are found
26
+ */
27
+ export declare function extractToolsFromDeployData(deployData: any): ToolData[];
28
+ /**
29
+ * Checks if .env file exists.
30
+ *
31
+ * @returns True if .env file exists
32
+ */
33
+ export declare function hasEnvFile(): boolean;
34
+ /**
35
+ * Checks if config has environment variables defined.
36
+ *
37
+ * @param config - Skill configuration
38
+ * @returns True if config has environment variables
39
+ */
40
+ export declare function hasConfigEnvVars(config: any): boolean;