lua-cli 2.2.8-alpha.2 → 2.3.0-alpha.2

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 (195) 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 +33 -6
  7. package/dist/api/agent.api.service.js +27 -0
  8. package/dist/api/auth.api.service.d.ts +31 -2
  9. package/dist/api/auth.api.service.js +29 -0
  10. package/dist/api/basket.api.service.d.ts +53 -11
  11. package/dist/api/basket.api.service.js +63 -14
  12. package/dist/api/chat.api.service.d.ts +15 -3
  13. package/dist/api/chat.api.service.js +12 -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 +45 -9
  17. package/dist/api/custom.data.api.service.js +43 -9
  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 +34 -4
  21. package/dist/api/order.api.service.js +41 -3
  22. package/dist/api/products.api.service.d.ts +39 -9
  23. package/dist/api/products.api.service.js +43 -5
  24. package/dist/api/skills.api.service.d.ts +49 -2
  25. package/dist/api/skills.api.service.js +47 -1
  26. package/dist/api/tool.api.service.d.ts +39 -1
  27. package/dist/api/tool.api.service.js +38 -0
  28. package/dist/api/user.data.api.service.d.ts +23 -1
  29. package/dist/api/user.data.api.service.js +22 -0
  30. package/dist/api-exports.d.ts +236 -5
  31. package/dist/api-exports.js +264 -81
  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 -878
  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 +54 -3
  55. package/dist/common/basket.instance.js +56 -3
  56. package/dist/common/data.entry.instance.d.ts +25 -2
  57. package/dist/common/data.entry.instance.js +24 -0
  58. package/dist/common/http.client.d.ts +51 -1
  59. package/dist/common/http.client.js +50 -0
  60. package/dist/common/order.instance.d.ts +22 -0
  61. package/dist/common/order.instance.js +31 -4
  62. package/dist/common/product.instance.d.ts +22 -1
  63. package/dist/common/product.instance.js +24 -6
  64. package/dist/common/product.pagination.instance.d.ts +22 -2
  65. package/dist/common/product.pagination.instance.js +22 -1
  66. package/dist/common/product.search.instance.d.ts +13 -3
  67. package/dist/common/product.search.instance.js +12 -1
  68. package/dist/common/user.instance.d.ts +27 -3
  69. package/dist/common/user.instance.js +28 -7
  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 +56 -50
  83. package/dist/interfaces/admin.js +4 -0
  84. package/dist/interfaces/agent.d.ts +21 -0
  85. package/dist/interfaces/agent.js +4 -0
  86. package/dist/interfaces/baskets.d.ts +60 -0
  87. package/dist/interfaces/baskets.js +12 -0
  88. package/dist/interfaces/chat.d.ts +48 -4
  89. package/dist/interfaces/chat.js +4 -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 +49 -19
  95. package/dist/interfaces/custom.data.js +4 -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 +37 -0
  103. package/dist/interfaces/orders.js +12 -0
  104. package/dist/interfaces/product.d.ts +38 -10
  105. package/dist/interfaces/product.js +4 -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 -121
  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 -17
  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 -114
  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 +941 -17
  165. package/dist/web/app.js +174 -22
  166. package/dist/web/index.html +7 -1
  167. package/package.json +13 -4
  168. package/template/QUICKSTART.md +299 -144
  169. package/template/README.md +928 -349
  170. package/template/TOOL_EXAMPLES.md +655 -0
  171. package/template/package-lock.json +5 -5
  172. package/template/package.json +1 -1
  173. package/template/src/index.ts +147 -207
  174. package/template/src/tools/BasketTool.ts +128 -0
  175. package/template/src/tools/CustomDataTool.ts +7 -13
  176. package/template/src/tools/OrderTool.ts +54 -0
  177. package/template/src/tools/PaymentTool.ts +1 -1
  178. package/template/src/tools/ProductsTool.ts +56 -118
  179. package/template/src/tools/UserDataTool.ts +4 -26
  180. package/dist/common/config.d.ts +0 -5
  181. package/dist/common/config.js +0 -5
  182. package/dist/custom-data-api.d.ts +0 -72
  183. package/dist/custom-data-api.js +0 -174
  184. package/dist/product-api.d.ts +0 -189
  185. package/dist/product-api.js +0 -141
  186. package/dist/services/api.d.ts +0 -549
  187. package/dist/services/api.js +0 -596
  188. package/dist/skill.d.ts +0 -50
  189. package/dist/types.d.ts +0 -1
  190. package/dist/types.js +0 -2
  191. package/dist/user-data-api.d.ts +0 -39
  192. package/dist/user-data-api.js +0 -50
  193. package/template/API.md +0 -604
  194. package/template/DEVELOPER.md +0 -771
  195. package/template/lua.skill.yaml +0 -7
@@ -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
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Dev API Utilities
3
+ * Handles all API calls for dev mode (chat, push, update)
4
+ */
5
+ import { DevVersionResponse, UpdateDevVersionResponse, SandboxIdsMap } from '../interfaces/dev.js';
6
+ /**
7
+ * Sends a chat message to the API with skill override for sandbox testing.
8
+ *
9
+ * @param apiKey - User's API key
10
+ * @param agentId - Agent ID
11
+ * @param skillId - Skill ID
12
+ * @param sandboxId - Sandbox skill ID
13
+ * @param message - Message to send
14
+ * @param persona - Optional persona override
15
+ * @param deployData - Deploy data containing all skills
16
+ * @returns The chat response text or null if failed
17
+ */
18
+ export declare function sendChatMessage(apiKey: string, agentId: string, skillId: string, sandboxId: string, message: string, persona: string | undefined, deployData: any): Promise<string | null>;
19
+ /**
20
+ * Updates an existing sandbox version.
21
+ *
22
+ * @param apiKey - User's API key
23
+ * @param agentId - Agent ID
24
+ * @param skillId - Skill ID
25
+ * @param sandboxVersionId - Existing sandbox version ID
26
+ * @param versionData - Version data to update
27
+ * @returns Update response
28
+ */
29
+ export declare function updateDevVersion(apiKey: string, agentId: string, skillId: string, sandboxVersionId: string, versionData: any): Promise<UpdateDevVersionResponse>;
30
+ /**
31
+ * Creates a new sandbox version.
32
+ *
33
+ * @param apiKey - User's API key
34
+ * @param agentId - Agent ID
35
+ * @param skillId - Skill ID
36
+ * @param versionData - Version data to create
37
+ * @returns Dev version response
38
+ */
39
+ export declare function pushDevVersion(apiKey: string, agentId: string, skillId: string, versionData: any): Promise<DevVersionResponse>;
40
+ /**
41
+ * Pushes a single skill to the sandbox.
42
+ * Attempts to update existing sandbox version, creates new one if update fails.
43
+ *
44
+ * @param apiKey - User's API key
45
+ * @param agentId - Agent ID
46
+ * @param skillId - Skill ID
47
+ * @param skillData - Skill data to push
48
+ * @param isInitial - Whether this is the initial push (affects logging)
49
+ * @returns True if successful, false otherwise
50
+ */
51
+ export declare function pushSingleSkillToSandbox(apiKey: string, agentId: string, skillId: string, skillData: any, isInitial?: boolean): Promise<boolean>;
52
+ /**
53
+ * Pushes multiple skills to the sandbox.
54
+ *
55
+ * @param apiKey - User's API key
56
+ * @param agentId - Agent ID
57
+ * @param deployData - Deploy data containing all skills
58
+ * @param isInitial - Whether this is the initial push
59
+ * @returns Map of skill names to their sandbox IDs
60
+ */
61
+ export declare function pushSkillsToSandbox(apiKey: string, agentId: string, deployData: any, isInitial?: boolean): Promise<SandboxIdsMap>;
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Dev API Utilities
3
+ * Handles all API calls for dev mode (chat, push, update)
4
+ */
5
+ import ChatApi from '../api/chat.api.service.js';
6
+ import SkillApi from '../api/skills.api.service.js';
7
+ import { BASE_URLS } from '../config/constants.js';
8
+ import { writeProgress, writeSuccess } from './cli.js';
9
+ import { loadEnvironmentVariables } from './sandbox.js';
10
+ import { getSandboxSkillId, setSandboxSkillId, getAllSandboxSkillIds } from './sandbox-storage.js';
11
+ /**
12
+ * Sends a chat message to the API with skill override for sandbox testing.
13
+ *
14
+ * @param apiKey - User's API key
15
+ * @param agentId - Agent ID
16
+ * @param skillId - Skill ID
17
+ * @param sandboxId - Sandbox skill ID
18
+ * @param message - Message to send
19
+ * @param persona - Optional persona override
20
+ * @param deployData - Deploy data containing all skills
21
+ * @returns The chat response text or null if failed
22
+ */
23
+ export async function sendChatMessage(apiKey, agentId, skillId, sandboxId, message, persona, deployData) {
24
+ try {
25
+ // Get all sandbox skill IDs for skill override
26
+ const allSkillOverrides = await getAllSandboxSkillIds(deployData);
27
+ // If no skills found, fallback to the provided skillId and sandboxId
28
+ const skillOverride = allSkillOverrides.length > 0 ? allSkillOverrides : [
29
+ {
30
+ skillId: skillId,
31
+ sandboxId: sandboxId
32
+ }
33
+ ];
34
+ const chatRequest = {
35
+ messages: [
36
+ {
37
+ type: "text",
38
+ text: message
39
+ }
40
+ ],
41
+ navigate: true,
42
+ skillOverride: skillOverride
43
+ };
44
+ // Add persona override if provided
45
+ if (persona) {
46
+ chatRequest.personaOverride = persona;
47
+ }
48
+ const chatApi = new ChatApi(BASE_URLS.CHAT, apiKey);
49
+ const response = await chatApi.sendMessage(agentId, chatRequest);
50
+ if (!response.success) {
51
+ console.error(`āŒ Chat API error: ${response.error?.message || 'Unknown error'}`);
52
+ return null;
53
+ }
54
+ return response.data?.text || null;
55
+ }
56
+ catch (error) {
57
+ console.error("āŒ Error sending chat message:", error);
58
+ return null;
59
+ }
60
+ }
61
+ /**
62
+ * Updates an existing sandbox version.
63
+ *
64
+ * @param apiKey - User's API key
65
+ * @param agentId - Agent ID
66
+ * @param skillId - Skill ID
67
+ * @param sandboxVersionId - Existing sandbox version ID
68
+ * @param versionData - Version data to update
69
+ * @returns Update response
70
+ */
71
+ export async function updateDevVersion(apiKey, agentId, skillId, sandboxVersionId, versionData) {
72
+ try {
73
+ const skillsApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
74
+ const response = await skillsApi.updateDevSkill(skillId, sandboxVersionId, versionData);
75
+ if (response.success) {
76
+ return {
77
+ success: true,
78
+ data: response.data
79
+ };
80
+ }
81
+ else {
82
+ return {
83
+ success: false,
84
+ error: {
85
+ message: response.error?.message || 'Unknown error',
86
+ error: response.error?.message || 'Unknown error',
87
+ statusCode: response.error?.statusCode || 500
88
+ }
89
+ };
90
+ }
91
+ }
92
+ catch (error) {
93
+ console.error("Network error updating dev version:", error);
94
+ return {
95
+ success: false,
96
+ error: {
97
+ message: "Network error",
98
+ error: error instanceof Error ? error.message : "Failed to connect to server",
99
+ statusCode: 500
100
+ }
101
+ };
102
+ }
103
+ }
104
+ /**
105
+ * Creates a new sandbox version.
106
+ *
107
+ * @param apiKey - User's API key
108
+ * @param agentId - Agent ID
109
+ * @param skillId - Skill ID
110
+ * @param versionData - Version data to create
111
+ * @returns Dev version response
112
+ */
113
+ export async function pushDevVersion(apiKey, agentId, skillId, versionData) {
114
+ try {
115
+ const skillsApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
116
+ const response = await skillsApi.pushDevSkill(skillId, versionData);
117
+ if (response.success) {
118
+ return {
119
+ success: true,
120
+ data: response.data
121
+ };
122
+ }
123
+ else {
124
+ return {
125
+ success: false,
126
+ error: {
127
+ message: response.error?.message || 'Unknown error',
128
+ error: response.error?.message || 'Unknown error',
129
+ statusCode: response.error?.statusCode || 500
130
+ }
131
+ };
132
+ }
133
+ }
134
+ catch (error) {
135
+ console.error("āŒ Network error pushing dev version:", error);
136
+ return {
137
+ success: false,
138
+ error: {
139
+ message: "Network error",
140
+ error: error instanceof Error ? error.message : "Failed to connect to server",
141
+ statusCode: 500
142
+ }
143
+ };
144
+ }
145
+ }
146
+ /**
147
+ * Pushes a single skill to the sandbox.
148
+ * Attempts to update existing sandbox version, creates new one if update fails.
149
+ *
150
+ * @param apiKey - User's API key
151
+ * @param agentId - Agent ID
152
+ * @param skillId - Skill ID
153
+ * @param skillData - Skill data to push
154
+ * @param isInitial - Whether this is the initial push (affects logging)
155
+ * @returns True if successful, false otherwise
156
+ */
157
+ export async function pushSingleSkillToSandbox(apiKey, agentId, skillId, skillData, isInitial = false) {
158
+ const skillName = skillData.name || 'Unknown Skill';
159
+ const sandboxSkillId = await getSandboxSkillId(skillName);
160
+ // Load environment variables
161
+ const envVars = loadEnvironmentVariables();
162
+ const payloadWithNameAndEnv = {
163
+ ...skillData,
164
+ name: skillName,
165
+ env: envVars
166
+ };
167
+ if (sandboxSkillId) {
168
+ // Try to update existing sandbox version
169
+ if (!isInitial) {
170
+ writeProgress("šŸ”„ Updating existing sandbox version...");
171
+ }
172
+ const updateResult = await updateDevVersion(apiKey, agentId, skillId, sandboxSkillId, payloadWithNameAndEnv);
173
+ if (updateResult.success && updateResult.data) {
174
+ if (!isInitial) {
175
+ // writeSuccess(`āœ… Version ${updateResult.data.version} updated in sandbox successfully`);
176
+ // writeSuccess(`šŸ”‘ Sandbox Skill ID: ${updateResult.data.skillId}`);
177
+ }
178
+ return true;
179
+ }
180
+ else if (updateResult.error) {
181
+ writeProgress("āš ļø Failed to update existing sandbox, creating new one...");
182
+ console.error(`āŒ Sandbox update failed: ${updateResult.error.message}`);
183
+ if (updateResult.error.error) {
184
+ console.error(` Details: ${updateResult.error.error}`);
185
+ }
186
+ // If skill not found during update, give helpful guidance before trying to create
187
+ if (updateResult.error.message.includes('Skill not found') || updateResult.error.statusCode === 400 || updateResult.error.statusCode === 404) {
188
+ console.error('\nšŸ’” The skill doesn\'t exist on the server.');
189
+ console.error(' Please run "lua push" first to deploy your skill, then try "lua dev" again.\n');
190
+ }
191
+ // Fall through to create new sandbox
192
+ }
193
+ }
194
+ // Create new sandbox version (either no existing ID or update failed)
195
+ if (!isInitial) {
196
+ writeProgress("šŸ”„ Creating new sandbox version...");
197
+ }
198
+ const result = await pushDevVersion(apiKey, agentId, skillId, payloadWithNameAndEnv);
199
+ if (result.success && result.data) {
200
+ // Store the new sandbox skill ID
201
+ await setSandboxSkillId(result.data.skillId, skillName);
202
+ if (!isInitial) {
203
+ writeSuccess(`āœ… Version ${result.data.version} pushed to sandbox successfully`);
204
+ writeSuccess(`šŸ”‘ Sandbox Skill ID: ${result.data.skillId}`);
205
+ }
206
+ return true;
207
+ }
208
+ else if (result.error) {
209
+ console.error(`āŒ Sandbox creation failed: ${result.error.message}`);
210
+ if (result.error.error) {
211
+ console.error(` Details: ${result.error.error}`);
212
+ }
213
+ if (result.error.statusCode) {
214
+ console.error(` Status Code: ${result.error.statusCode}`);
215
+ }
216
+ // If skill not found, give helpful guidance
217
+ if (result.error.message.includes('Skill not found') || result.error.statusCode === 400 || result.error.statusCode === 404) {
218
+ console.error('\nšŸ’” The skill hasn\'t been deployed to the server yet.');
219
+ console.error(' Please run "lua push" first to deploy your skill, then try "lua dev" again.');
220
+ }
221
+ return false;
222
+ }
223
+ else {
224
+ console.error("āŒ Failed to push version to sandbox. Please try again.");
225
+ return false;
226
+ }
227
+ }
228
+ /**
229
+ * Pushes multiple skills to the sandbox.
230
+ *
231
+ * @param apiKey - User's API key
232
+ * @param agentId - Agent ID
233
+ * @param deployData - Deploy data containing all skills
234
+ * @param isInitial - Whether this is the initial push
235
+ * @returns Map of skill names to their sandbox IDs
236
+ */
237
+ export async function pushSkillsToSandbox(apiKey, agentId, deployData, isInitial = false) {
238
+ const sandboxIds = {};
239
+ if (!deployData.skills || !Array.isArray(deployData.skills)) {
240
+ throw new Error("No skills found in deploy data");
241
+ }
242
+ for (const skill of deployData.skills) {
243
+ if (!skill.skillId) {
244
+ console.warn(`āš ļø Skipping skill ${skill.name} - no skillId found`);
245
+ continue;
246
+ }
247
+ try {
248
+ const success = await pushSingleSkillToSandbox(apiKey, agentId, skill.skillId, skill, isInitial);
249
+ if (success) {
250
+ // Get the sandbox ID for this skill
251
+ const sandboxId = await getSandboxSkillId(skill.name);
252
+ if (sandboxId) {
253
+ sandboxIds[skill.name] = sandboxId;
254
+ }
255
+ }
256
+ }
257
+ catch (error) {
258
+ console.error(`āŒ Failed to push skill ${skill.name}:`, error);
259
+ }
260
+ }
261
+ return sandboxIds;
262
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Dev Helper Utilities
3
+ * Small helper functions for dev mode
4
+ */
5
+ /**
6
+ * Reads the version from config (handles both old and new formats).
7
+ *
8
+ * @param config - The skill configuration
9
+ * @returns The version string
10
+ */
11
+ export declare function readConfigVersion(config: any): string;
12
+ /**
13
+ * Reads the deploy.json file from .lua directory.
14
+ *
15
+ * @returns Parsed deploy data or null if not found
16
+ */
17
+ export declare function readDeployJson(): any | null;
18
+ /**
19
+ * Extracts skill ID from config (handles both old and new formats).
20
+ * For multi-skill projects, returns the first skill's ID.
21
+ *
22
+ * @param config - The skill configuration
23
+ * @returns The skill ID or null if not found
24
+ */
25
+ export declare function extractSkillId(config: any): string | null;
26
+ /**
27
+ * Validates that the configuration has required fields.
28
+ *
29
+ * @param config - The skill configuration to validate
30
+ * @throws Error if configuration is invalid
31
+ */
32
+ export declare function validateConfig(config: any): void;
33
+ /**
34
+ * Validates that deploy data has skills.
35
+ *
36
+ * @param deployData - The deploy data to validate
37
+ * @throws Error if deploy data is invalid
38
+ */
39
+ export declare function validateDeployData(deployData: any): void;
40
+ /**
41
+ * Validates that config has required agent information.
42
+ *
43
+ * @param config - The skill configuration
44
+ * @throws Error if agent info is missing
45
+ */
46
+ export declare function validateAgentConfig(config: any): void;