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,242 @@
1
+ /**
2
+ * Utility functions for compile command
3
+ */
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import { gzipSync } from "zlib";
7
+ import { Node } from "ts-morph";
8
+ /**
9
+ * Compresses code using gzip and returns base64 encoded string
10
+ */
11
+ export function compressCode(code) {
12
+ const compressed = gzipSync(code);
13
+ return compressed.toString('base64');
14
+ }
15
+ /**
16
+ * Finds the index.ts file in the project
17
+ */
18
+ export function findIndexFile() {
19
+ // Check for index.ts in current directory
20
+ let indexPath = path.join(process.cwd(), "index.ts");
21
+ if (fs.existsSync(indexPath)) {
22
+ return indexPath;
23
+ }
24
+ // Check for index.ts in src directory
25
+ indexPath = path.join(process.cwd(), "src", "index.ts");
26
+ if (fs.existsSync(indexPath)) {
27
+ return indexPath;
28
+ }
29
+ throw new Error("index.ts not found in current directory or src/ directory");
30
+ }
31
+ /**
32
+ * Resolves import path from module specifier
33
+ */
34
+ export function resolveImportPath(moduleSpecifier, currentFilePath) {
35
+ if (moduleSpecifier.startsWith('./') || moduleSpecifier.startsWith('../')) {
36
+ // Relative import - resolve relative to current file
37
+ const currentDir = path.dirname(currentFilePath);
38
+ return path.resolve(currentDir, moduleSpecifier + '.ts');
39
+ }
40
+ else {
41
+ // Absolute import - assume it's in the project
42
+ return path.resolve(process.cwd(), 'src', moduleSpecifier + '.ts');
43
+ }
44
+ }
45
+ /**
46
+ * Creates execute function wrapper from bundled code
47
+ */
48
+ export function createExecuteFunction(bundledCode, tool) {
49
+ // The bundled code is already wrapped for VM execution by wrapToolForVM
50
+ // Just return it directly since it's already an async function
51
+ return bundledCode;
52
+ }
53
+ /**
54
+ * Evaluates Zod schema code and converts it to JSON Schema
55
+ */
56
+ export async function evaluateZodSchemaToJsonSchema(zodSchemaCode) {
57
+ try {
58
+ // Import zod and zod-to-json-schema dynamically
59
+ const { z } = await import('zod');
60
+ const { zodToJsonSchema } = await import('zod-to-json-schema');
61
+ // Create a safe evaluation context using Function constructor
62
+ const evalFunction = new Function('z', `return ${zodSchemaCode}`);
63
+ const zodSchema = evalFunction(z);
64
+ // Convert to JSON Schema using the library
65
+ const jsonSchema = zodToJsonSchema(zodSchema, 'schema');
66
+ // Extract just the core schema, removing JSON Schema references and definitions
67
+ if (jsonSchema.$ref && jsonSchema.definitions && jsonSchema.definitions.schema) {
68
+ // Return just the schema definition without the wrapper
69
+ return jsonSchema.definitions.schema;
70
+ }
71
+ // Remove the top-level $schema and title properties that we don't need
72
+ const { $schema, title, definitions, $ref, ...cleanSchema } = jsonSchema;
73
+ return cleanSchema;
74
+ }
75
+ catch (error) {
76
+ console.warn('Warning: Could not evaluate Zod schema, falling back to basic parsing:', error);
77
+ // Fallback to basic parsing for simple cases
78
+ if (zodSchemaCode.includes('z.object({')) {
79
+ return { type: 'object' };
80
+ }
81
+ if (zodSchemaCode.includes('z.string()'))
82
+ return { type: 'string' };
83
+ if (zodSchemaCode.includes('z.number()'))
84
+ return { type: 'number' };
85
+ if (zodSchemaCode.includes('z.boolean()'))
86
+ return { type: 'boolean' };
87
+ return { type: 'object' };
88
+ }
89
+ }
90
+ /**
91
+ * Wraps bundled tool code for VM execution
92
+ */
93
+ export async function wrapToolForVM(outputPath, tool) {
94
+ const bundledCode = fs.readFileSync(outputPath, 'utf8');
95
+ // Create a wrapper that's compatible with the existing sandbox.ts VM system
96
+ // The sandbox expects: const executeFunction = ${toolCode}; module.exports = async (input) => { return await executeFunction(input); };
97
+ const wrappedCode = `async (input) => {
98
+
99
+ // Execute the bundled tool code
100
+ ${bundledCode}
101
+
102
+ // Get the tool class from exports
103
+ const ToolClass = module.exports.default || module.exports.${tool.className} || module.exports;
104
+
105
+ // Create and execute the tool
106
+ const toolInstance = new ToolClass();
107
+ return await toolInstance.execute(input);
108
+ }`;
109
+ fs.writeFileSync(outputPath, wrappedCode);
110
+ }
111
+ /**
112
+ * Extracts tool information from a new expression in the AST
113
+ */
114
+ export function extractToolFromNewExpressionSync(newExpr, project) {
115
+ try {
116
+ const expression = newExpr.getExpression();
117
+ const className = expression.getText();
118
+ // Find the import declaration for this class
119
+ const sourceFile = newExpr.getSourceFile();
120
+ const imports = sourceFile.getImportDeclarations();
121
+ for (const importDecl of imports) {
122
+ const namedImports = importDecl.getNamedImports();
123
+ const defaultImport = importDecl.getDefaultImport();
124
+ let toolFilePath = null;
125
+ // Check named imports
126
+ for (const namedImport of namedImports) {
127
+ if (namedImport.getName() === className) {
128
+ toolFilePath = resolveImportPath(importDecl.getModuleSpecifierValue(), sourceFile.getFilePath());
129
+ break;
130
+ }
131
+ }
132
+ // Check default import
133
+ if (!toolFilePath && defaultImport && defaultImport.getText() === className) {
134
+ toolFilePath = resolveImportPath(importDecl.getModuleSpecifierValue(), sourceFile.getFilePath());
135
+ }
136
+ if (toolFilePath && fs.existsSync(toolFilePath)) {
137
+ // Extract tool metadata from the class file
138
+ try {
139
+ const toolSourceFile = project.addSourceFileAtPath(toolFilePath);
140
+ const classDecl = toolSourceFile.getClass(className);
141
+ if (classDecl) {
142
+ const nameProperty = classDecl.getProperty('name');
143
+ const descProperty = classDecl.getProperty('description');
144
+ let toolName = className.replace(/Tool$/, '').toLowerCase();
145
+ let description = '';
146
+ // Extract name from property if available
147
+ if (nameProperty && nameProperty.getInitializer()) {
148
+ const nameValue = nameProperty.getInitializer()?.getText();
149
+ if (nameValue) {
150
+ toolName = nameValue.replace(/['"]/g, '');
151
+ }
152
+ }
153
+ // Extract description from property if available
154
+ if (descProperty && descProperty.getInitializer()) {
155
+ const descValue = descProperty.getInitializer()?.getText();
156
+ if (descValue) {
157
+ description = descValue.replace(/['"]/g, '');
158
+ }
159
+ }
160
+ const toolInfo = {
161
+ name: toolName,
162
+ className,
163
+ filePath: toolFilePath,
164
+ description
165
+ };
166
+ return toolInfo;
167
+ }
168
+ }
169
+ catch (fileError) {
170
+ console.warn(`Warning: Could not load tool file ${toolFilePath}:`, fileError);
171
+ }
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+ catch (error) {
177
+ console.warn(`Warning: Could not extract tool info for ${newExpr.getText()}:`, error);
178
+ return null;
179
+ }
180
+ }
181
+ /**
182
+ * Extracts skills metadata from index file
183
+ */
184
+ export function extractSkillsMetadata(indexFile) {
185
+ const skills = [];
186
+ // Find all LuaSkill constructor calls
187
+ indexFile.forEachDescendant((node) => {
188
+ if (Node.isNewExpression(node)) {
189
+ const expression = node.getExpression();
190
+ if (expression.getText() === 'LuaSkill') {
191
+ const args = node.getArguments();
192
+ if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {
193
+ const configObj = args[0];
194
+ let skillName = '';
195
+ let skillVersion = '';
196
+ let description = '';
197
+ let context = '';
198
+ let constructorTools = [];
199
+ // Extract properties
200
+ configObj.getProperties().forEach((prop) => {
201
+ if (Node.isPropertyAssignment(prop)) {
202
+ const name = prop.getName();
203
+ const value = prop.getInitializer();
204
+ if (name === 'name' && value) {
205
+ skillName = value.getText().replace(/['"]/g, '');
206
+ }
207
+ else if (name === 'version' && value) {
208
+ skillVersion = value.getText().replace(/['"]/g, '');
209
+ }
210
+ else if (name === 'description' && value) {
211
+ description = value.getText().replace(/['"]/g, '');
212
+ }
213
+ else if (name === 'context' && value) {
214
+ context = value.getText().replace(/['"]/g, '');
215
+ }
216
+ else if (name === 'tools' && value && Node.isArrayLiteralExpression(value)) {
217
+ // Extract tools from constructor array
218
+ const toolsArray = value;
219
+ constructorTools = toolsArray.getElements().map((element) => {
220
+ if (Node.isNewExpression(element)) {
221
+ return element.getExpression().getText();
222
+ }
223
+ return '';
224
+ }).filter(name => name);
225
+ }
226
+ }
227
+ });
228
+ if (skillName) {
229
+ skills.push({
230
+ name: skillName,
231
+ version: skillVersion || '1.0.0',
232
+ description,
233
+ context,
234
+ constructorTools
235
+ });
236
+ }
237
+ }
238
+ }
239
+ }
240
+ });
241
+ return skills;
242
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Deploy API Utilities
3
+ * Handles API calls for deployment operations
4
+ */
5
+ import { VersionsResponse, PublishResponse } from '../interfaces/deploy.js';
6
+ /**
7
+ * Fetches available versions for a skill.
8
+ *
9
+ * @param apiKey - User's API key
10
+ * @param agentId - Agent ID
11
+ * @param skillId - Skill ID
12
+ * @returns Versions response containing array of versions
13
+ * @throws Error if API call fails
14
+ */
15
+ export declare function fetchVersions(apiKey: string, agentId: string, skillId: string): Promise<VersionsResponse>;
16
+ /**
17
+ * Publishes a specific version to production.
18
+ *
19
+ * @param apiKey - User's API key
20
+ * @param agentId - Agent ID
21
+ * @param skillId - Skill ID
22
+ * @param version - Version to publish
23
+ * @returns Publish response with deployment details
24
+ * @throws Error if API call fails
25
+ */
26
+ export declare function publishVersion(apiKey: string, agentId: string, skillId: string, version: string): Promise<PublishResponse>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Deploy API Utilities
3
+ * Handles API calls for deployment operations
4
+ */
5
+ import SkillApi from '../api/skills.api.service.js';
6
+ import { BASE_URLS } from '../config/constants.js';
7
+ /**
8
+ * Fetches available versions for a skill.
9
+ *
10
+ * @param apiKey - User's API key
11
+ * @param agentId - Agent ID
12
+ * @param skillId - Skill ID
13
+ * @returns Versions response containing array of versions
14
+ * @throws Error if API call fails
15
+ */
16
+ export async function fetchVersions(apiKey, agentId, skillId) {
17
+ try {
18
+ const skillApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
19
+ const response = await skillApi.getSkillVersions(skillId);
20
+ if (!response.success) {
21
+ throw new Error(`Failed to fetch versions: ${response.error?.message || 'Unknown error'}`);
22
+ }
23
+ return response.data;
24
+ }
25
+ catch (error) {
26
+ console.error("❌ Error fetching versions:", error);
27
+ throw error;
28
+ }
29
+ }
30
+ /**
31
+ * Publishes a specific version to production.
32
+ *
33
+ * @param apiKey - User's API key
34
+ * @param agentId - Agent ID
35
+ * @param skillId - Skill ID
36
+ * @param version - Version to publish
37
+ * @returns Publish response with deployment details
38
+ * @throws Error if API call fails
39
+ */
40
+ export async function publishVersion(apiKey, agentId, skillId, version) {
41
+ try {
42
+ const skillApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
43
+ const response = await skillApi.publishSkillVersion(skillId, version);
44
+ if (!response.success) {
45
+ throw new Error(`Failed to publish version: ${response.error?.message || 'Unknown error'}`);
46
+ }
47
+ return response.data;
48
+ }
49
+ catch (error) {
50
+ console.error("❌ Error publishing version:", error);
51
+ throw error;
52
+ }
53
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Deploy Helper Utilities
3
+ * Helper functions for deployment operations
4
+ */
5
+ import { VersionInfo } from '../interfaces/deploy.js';
6
+ /**
7
+ * Formats a version for display in the selection list.
8
+ *
9
+ * @param version - Version information to format
10
+ * @returns Formatted string for display
11
+ */
12
+ export declare function formatVersionChoice(version: VersionInfo): string;
13
+ /**
14
+ * Sorts versions by creation date (newest first).
15
+ *
16
+ * @param versions - Array of versions to sort
17
+ * @returns Sorted array of versions
18
+ */
19
+ export declare function sortVersionsByDate(versions: VersionInfo[]): VersionInfo[];
20
+ /**
21
+ * Prompts user to select a version from available versions.
22
+ *
23
+ * @param versions - Array of available versions
24
+ * @returns Selected version string
25
+ */
26
+ export declare function promptVersionSelection(versions: VersionInfo[]): Promise<string>;
27
+ /**
28
+ * Prompts user to confirm deployment with warning.
29
+ *
30
+ * @returns True if confirmed, false otherwise
31
+ */
32
+ export declare function confirmDeployment(): Promise<boolean>;
33
+ /**
34
+ * Validates that configuration has required fields for deployment.
35
+ *
36
+ * @param config - Skill configuration
37
+ * @throws Error if configuration is invalid
38
+ */
39
+ export declare function validateDeployConfig(config: any): void;
40
+ /**
41
+ * Validates that versions are available for deployment.
42
+ *
43
+ * @param versions - Array of versions
44
+ * @throws Error if no versions are available
45
+ */
46
+ export declare function validateVersionsAvailable(versions: VersionInfo[] | undefined): void;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Deploy Helper Utilities
3
+ * Helper functions for deployment operations
4
+ */
5
+ import inquirer from 'inquirer';
6
+ import { clearPromptLines } from './cli.js';
7
+ /**
8
+ * Formats a version for display in the selection list.
9
+ *
10
+ * @param version - Version information to format
11
+ * @returns Formatted string for display
12
+ */
13
+ export function formatVersionChoice(version) {
14
+ const currentIndicator = version.isCurrent ? ' (CURRENT)' : '';
15
+ const date = new Date(version.createdDate).toLocaleDateString();
16
+ return `${version.version}${currentIndicator} - Created: ${date} by ${version.createdByEmail}`;
17
+ }
18
+ /**
19
+ * Sorts versions by creation date (newest first).
20
+ *
21
+ * @param versions - Array of versions to sort
22
+ * @returns Sorted array of versions
23
+ */
24
+ export function sortVersionsByDate(versions) {
25
+ return versions.sort((a, b) => new Date(b.createdDate).getTime() - new Date(a.createdDate).getTime());
26
+ }
27
+ /**
28
+ * Prompts user to select a version from available versions.
29
+ *
30
+ * @param versions - Array of available versions
31
+ * @returns Selected version string
32
+ */
33
+ export async function promptVersionSelection(versions) {
34
+ const { selectedVersion } = await inquirer.prompt([
35
+ {
36
+ type: "list",
37
+ name: "selectedVersion",
38
+ message: "Select a version to deploy:",
39
+ choices: versions.map(version => ({
40
+ name: formatVersionChoice(version),
41
+ value: version.version
42
+ }))
43
+ }
44
+ ]);
45
+ clearPromptLines(2);
46
+ return selectedVersion;
47
+ }
48
+ /**
49
+ * Prompts user to confirm deployment with warning.
50
+ *
51
+ * @returns True if confirmed, false otherwise
52
+ */
53
+ export async function confirmDeployment() {
54
+ const { confirmed } = await inquirer.prompt([
55
+ {
56
+ type: "confirm",
57
+ name: "confirmed",
58
+ message: "⚠️ Warning: This version will be deployed to all users. Do you want to proceed?",
59
+ default: false
60
+ }
61
+ ]);
62
+ clearPromptLines(2);
63
+ return confirmed;
64
+ }
65
+ /**
66
+ * Validates that configuration has required fields for deployment.
67
+ *
68
+ * @param config - Skill configuration
69
+ * @throws Error if configuration is invalid
70
+ */
71
+ export function validateDeployConfig(config) {
72
+ if (!config || !config.agent?.agentId || !config.skill?.skillId) {
73
+ throw new Error("No lua.skill.yaml found or missing agentId/skillId. Please run this command from a skill directory.");
74
+ }
75
+ }
76
+ /**
77
+ * Validates that versions are available for deployment.
78
+ *
79
+ * @param versions - Array of versions
80
+ * @throws Error if no versions are available
81
+ */
82
+ export function validateVersionsAvailable(versions) {
83
+ if (!versions || versions.length === 0) {
84
+ throw new Error("No versions found for this skill.");
85
+ }
86
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Deployment Data Generation Utilities
3
+ * Handles creation of deployment files in both new and legacy formats
4
+ */
5
+ import { ToolInfo } from '../interfaces/compile.js';
6
+ import { TypeScriptSourceFile } from '../types/compile.types.js';
7
+ /**
8
+ * Creates deployment data in the new format.
9
+ * This format includes skill metadata and tool references.
10
+ * Output: dist/deployment.json
11
+ *
12
+ * @param tools - Array of detected tools
13
+ * @param distDir - Distribution directory for output
14
+ */
15
+ export declare function createDeploymentData(tools: ToolInfo[], distDir: string): Promise<void>;
16
+ /**
17
+ * Creates deployment data in the legacy format.
18
+ * This format includes compressed tool code and is used for backwards compatibility.
19
+ * Output: .lua/deploy.json and individual tool files
20
+ *
21
+ * @param tools - Array of detected tools
22
+ * @param luaDir - Legacy .lua directory for output
23
+ * @param indexFile - The TypeScript source file for the index
24
+ */
25
+ export declare function createLegacyDeploymentData(tools: ToolInfo[], luaDir: string, indexFile: TypeScriptSourceFile): Promise<void>;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Deployment Data Generation Utilities
3
+ * Handles creation of deployment files in both new and legacy formats
4
+ */
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import { Node } from "ts-morph";
8
+ import { readSkillConfig } from './files.js';
9
+ import { COMPILE_DIRS, COMPILE_FILES, SKILL_DEFAULTS, DEFAULT_INPUT_SCHEMA, JSON_FORMAT, } from '../config/compile.constants.js';
10
+ import { compressCode, extractSkillsMetadata, } from './compile.js';
11
+ import { ensureSkillsExistInYaml } from './skill-management.js';
12
+ /**
13
+ * Creates deployment data in the new format.
14
+ * This format includes skill metadata and tool references.
15
+ * Output: dist/deployment.json
16
+ *
17
+ * @param tools - Array of detected tools
18
+ * @param distDir - Distribution directory for output
19
+ */
20
+ export async function createDeploymentData(tools, distDir) {
21
+ const config = readSkillConfig();
22
+ const packageJson = readPackageJson();
23
+ const deploymentData = {
24
+ name: config?.skill?.name || packageJson.name || SKILL_DEFAULTS.NAME,
25
+ version: config?.skill?.version || packageJson.version || SKILL_DEFAULTS.VERSION,
26
+ skillId: config?.skill?.skillId || '',
27
+ description: config?.skill?.description || packageJson.description || SKILL_DEFAULTS.DESCRIPTION,
28
+ context: config?.skill?.context || SKILL_DEFAULTS.CONTEXT,
29
+ tools: tools.map(tool => ({
30
+ name: tool.name,
31
+ className: tool.className,
32
+ description: tool.description || '',
33
+ filePath: `${COMPILE_DIRS.TOOLS}/${tool.className}.js`
34
+ }))
35
+ };
36
+ fs.writeFileSync(path.join(distDir, COMPILE_FILES.DEPLOYMENT_JSON), JSON.stringify(deploymentData, null, JSON_FORMAT.INDENT));
37
+ }
38
+ /**
39
+ * Reads and parses the package.json file.
40
+ *
41
+ * @returns The parsed package.json content
42
+ */
43
+ function readPackageJson() {
44
+ const packageJsonPath = path.join(process.cwd(), COMPILE_FILES.PACKAGE_JSON);
45
+ return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
46
+ }
47
+ /**
48
+ * Creates deployment data in the legacy format.
49
+ * This format includes compressed tool code and is used for backwards compatibility.
50
+ * Output: .lua/deploy.json and individual tool files
51
+ *
52
+ * @param tools - Array of detected tools
53
+ * @param luaDir - Legacy .lua directory for output
54
+ * @param indexFile - The TypeScript source file for the index
55
+ */
56
+ export async function createLegacyDeploymentData(tools, luaDir, indexFile) {
57
+ const config = readSkillConfig();
58
+ const skillsMetadata = extractSkillsMetadata(indexFile);
59
+ // Map tools to their parent skills
60
+ const skillToTools = mapToolsToSkills(indexFile);
61
+ // Build skills array with their associated tools
62
+ const skillsArray = buildSkillsArray(skillsMetadata, skillToTools, tools);
63
+ // Ensure all skills exist in YAML config and have valid IDs
64
+ const updatedSkillsArray = await ensureSkillsExistInYaml(skillsArray, config);
65
+ // Write deployment data
66
+ const deployData = {
67
+ skills: updatedSkillsArray
68
+ };
69
+ fs.writeFileSync(path.join(luaDir, COMPILE_FILES.DEPLOY_JSON), JSON.stringify(deployData, null, JSON_FORMAT.INDENT));
70
+ // Write individual tool files (uncompressed for debugging)
71
+ writeIndividualToolFiles(tools, luaDir);
72
+ }
73
+ /**
74
+ * Maps tools to their parent skills by analyzing addTools calls in the source code.
75
+ *
76
+ * @param indexFile - The TypeScript source file to analyze
77
+ * @returns Map of skill variable names to their tool class names
78
+ */
79
+ function mapToolsToSkills(indexFile) {
80
+ const skillToTools = new Map();
81
+ indexFile.forEachDescendant((node) => {
82
+ if (Node.isCallExpression(node)) {
83
+ const expression = node.getExpression();
84
+ if (Node.isPropertyAccessExpression(expression) && expression.getName() === 'addTools') {
85
+ const object = expression.getExpression();
86
+ const objectName = object.getText();
87
+ const args = node.getArguments();
88
+ if (args.length > 0 && Node.isArrayLiteralExpression(args[0])) {
89
+ const toolsArray = args[0];
90
+ const toolNames = toolsArray.getElements()
91
+ .map((element) => {
92
+ if (Node.isNewExpression(element)) {
93
+ return element.getExpression().getText();
94
+ }
95
+ return '';
96
+ })
97
+ .filter(name => name);
98
+ skillToTools.set(objectName, toolNames);
99
+ }
100
+ }
101
+ }
102
+ });
103
+ return skillToTools;
104
+ }
105
+ /**
106
+ * Builds the skills array with their associated tools.
107
+ * Associates tools with skills based on constructor tools or variable name matching.
108
+ *
109
+ * @param skillsMetadata - Extracted skill metadata from source code
110
+ * @param skillToTools - Map of skill variables to tool class names
111
+ * @param tools - Array of all detected tools
112
+ * @returns Array of skills with their tools embedded
113
+ */
114
+ function buildSkillsArray(skillsMetadata, skillToTools, tools) {
115
+ return skillsMetadata.map(skillMeta => {
116
+ let skillTools = [];
117
+ // Strategy 1: Check for tools from constructor
118
+ if (skillMeta.constructorTools && skillMeta.constructorTools.length > 0) {
119
+ skillTools = tools.filter(tool => skillMeta.constructorTools.includes(tool.className) ||
120
+ skillMeta.constructorTools.includes(tool.name));
121
+ }
122
+ else {
123
+ // Strategy 2: Match tools by variable name heuristic
124
+ for (const [varName, toolNames] of skillToTools.entries()) {
125
+ const skillNameLower = skillMeta.name.toLowerCase().replace('-skill', '');
126
+ if (varName.toLowerCase().includes(skillNameLower) ||
127
+ varName.toLowerCase().includes(skillMeta.name.toLowerCase())) {
128
+ skillTools = tools.filter(tool => toolNames.includes(tool.className) || toolNames.includes(tool.name));
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ return {
134
+ name: skillMeta.name,
135
+ version: skillMeta.version,
136
+ description: skillMeta.description,
137
+ context: skillMeta.context,
138
+ tools: skillTools.map(tool => ({
139
+ name: tool.name,
140
+ description: tool.description || '',
141
+ inputSchema: tool.inputSchema || DEFAULT_INPUT_SCHEMA,
142
+ execute: compressCode(tool.executeCode || '')
143
+ }))
144
+ };
145
+ });
146
+ }
147
+ /**
148
+ * Writes individual tool files to the .lua directory for debugging.
149
+ * These are uncompressed versions of the tool code.
150
+ *
151
+ * @param tools - Array of tools to write
152
+ * @param luaDir - Directory to write tool files to
153
+ */
154
+ function writeIndividualToolFiles(tools, luaDir) {
155
+ for (const tool of tools) {
156
+ if (tool.executeCode) {
157
+ const toolFilePath = path.join(luaDir, `${tool.name}.js`);
158
+ fs.writeFileSync(toolFilePath, tool.executeCode);
159
+ }
160
+ }
161
+ }