lua-cli 1.3.2-alpha.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +2 -2
- package/dist/commands/agents.js +1 -1
- package/dist/commands/apiKey.js +2 -4
- package/dist/commands/compile.js +280 -216
- package/dist/commands/deploy.js +1 -1
- package/dist/commands/dev.js +352 -81
- package/dist/commands/init.js +43 -79
- package/dist/commands/push.js +1 -1
- package/dist/commands/test.js +49 -11
- package/dist/index.js +7 -9
- package/dist/services/api.d.ts +4 -1
- package/dist/services/api.js +7 -6
- package/dist/services/auth.d.ts +0 -4
- package/dist/services/auth.js +2 -129
- package/dist/skill.d.ts +5 -0
- package/dist/skill.js +6 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/utils/files.d.ts +1 -1
- package/dist/utils/files.js +12 -25
- package/dist/utils/sandbox.d.ts +7 -0
- package/dist/utils/sandbox.js +44 -8
- package/dist/web/app.css +4709 -796
- package/dist/web/app.js +22 -20
- package/dist/web/tools-page.css +0 -13
- package/package.json +3 -2
- package/template/env.example +17 -0
- package/template/lua.skill.yaml +14 -16
- package/template/package.json +1 -1
- package/template/src/index.ts +42 -13
- package/template/src/tools/PaymentTool.ts +2 -3
- package/dist/commands/deploy-new.d.ts +0 -0
- package/dist/commands/deploy-new.js +0 -130
- package/template/create-test.cjs +0 -39
- package/template/package-lock.json +0 -1555
package/dist/utils/files.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import pkg from 'js-yaml';
|
|
4
|
-
const { load } = pkg;
|
|
4
|
+
const { load, dump } = pkg;
|
|
5
5
|
export function copyTemplateFiles(templateDir, targetDir) {
|
|
6
6
|
const files = fs.readdirSync(templateDir);
|
|
7
7
|
for (const file of files) {
|
|
@@ -59,7 +59,6 @@ function updatePackageJson(srcPath, destPath) {
|
|
|
59
59
|
fs.writeFileSync(destPath, JSON.stringify(templatePackageJson, null, 2) + '\n');
|
|
60
60
|
}
|
|
61
61
|
export function createSkillYaml(agentId, orgId, skillName, skillId, persona, welcomeMessage) {
|
|
62
|
-
const skillIdSection = skillId ? ` skillId: "${skillId}"\n` : '';
|
|
63
62
|
// Handle multiline strings properly for YAML
|
|
64
63
|
const personaSection = persona ? ` persona: |\n${persona.split('\n').map(line => ` ${line}`).join('\n')}\n` : '';
|
|
65
64
|
const welcomeMessageSection = welcomeMessage ? ` welcomeMessage: "${welcomeMessage}"\n` : '';
|
|
@@ -67,16 +66,9 @@ export function createSkillYaml(agentId, orgId, skillName, skillId, persona, wel
|
|
|
67
66
|
agentId: "${agentId}"
|
|
68
67
|
orgId: "${orgId}"
|
|
69
68
|
${personaSection}${welcomeMessageSection}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
${skillIdSection} env:
|
|
74
|
-
# Example environment variables - customize these for your skill
|
|
75
|
-
PINECONE_API_KEY: "pcsk_5iFtQD_xxxxx"
|
|
76
|
-
OPENAI_API_KEY: "sk-proj--xxxx"
|
|
77
|
-
STRIPE_SECRET_KEY: "sk_test_xxxx"
|
|
78
|
-
# Add your own environment variables below
|
|
79
|
-
# CUSTOM_VAR: "custom-value"`;
|
|
69
|
+
skills:
|
|
70
|
+
# Skills will be auto-generated during compilation
|
|
71
|
+
`;
|
|
80
72
|
fs.writeFileSync("lua.skill.yaml", yamlContent);
|
|
81
73
|
}
|
|
82
74
|
export function readSkillYaml() {
|
|
@@ -108,18 +100,13 @@ export function updateSkillYamlPersona(persona, welcomeMessage) {
|
|
|
108
100
|
if (welcomeMessage) {
|
|
109
101
|
data.agent.welcomeMessage = welcomeMessage;
|
|
110
102
|
}
|
|
111
|
-
//
|
|
112
|
-
const updatedYamlContent =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
skill:
|
|
120
|
-
name: "${data.skill.name}"
|
|
121
|
-
version: "${data.skill.version}"
|
|
122
|
-
skillId: "${data.skill.skillId || ''}"
|
|
123
|
-
`;
|
|
103
|
+
// Use yaml.dump to properly handle both old and new formats
|
|
104
|
+
const updatedYamlContent = dump(data, {
|
|
105
|
+
indent: 2,
|
|
106
|
+
lineWidth: -1,
|
|
107
|
+
noRefs: true,
|
|
108
|
+
quotingType: '"',
|
|
109
|
+
forceQuotes: false
|
|
110
|
+
});
|
|
124
111
|
fs.writeFileSync(yamlPath, updatedYamlContent);
|
|
125
112
|
}
|
package/dist/utils/sandbox.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export interface ExecuteToolOptions extends SandboxOptions {
|
|
|
8
8
|
toolCode: string;
|
|
9
9
|
inputs: any;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Loads environment variables from multiple sources in priority order:
|
|
13
|
+
* 1. process.env (lowest priority)
|
|
14
|
+
* 2. .env file (medium priority)
|
|
15
|
+
* 3. lua.skill.yaml env section (highest priority)
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadEnvironmentVariables(): Record<string, string>;
|
|
11
18
|
/**
|
|
12
19
|
* Creates a VM sandbox context with all necessary globals and utilities
|
|
13
20
|
*/
|
package/dist/utils/sandbox.js
CHANGED
|
@@ -1,28 +1,60 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
2
|
import vm from "vm";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import fs from "fs";
|
|
4
5
|
import { UserDataApi } from "../services/api.js";
|
|
5
6
|
import { readSkillConfig } from "./files.js";
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Loads environment variables from multiple sources in priority order:
|
|
9
|
+
* 1. process.env (lowest priority)
|
|
10
|
+
* 2. .env file (medium priority)
|
|
11
|
+
* 3. lua.skill.yaml env section (highest priority)
|
|
8
12
|
*/
|
|
9
|
-
export function
|
|
10
|
-
const { apiKey, agentId, customConsole, broadcastLog } = options;
|
|
11
|
-
// Extract environment variables from YAML config and merge with process.env
|
|
12
|
-
const config = readSkillConfig();
|
|
13
|
+
export function loadEnvironmentVariables() {
|
|
13
14
|
const envVars = {};
|
|
14
|
-
//
|
|
15
|
+
// 1. Start with process.env
|
|
15
16
|
for (const [key, value] of Object.entries(process.env)) {
|
|
16
17
|
if (value !== undefined) {
|
|
17
18
|
envVars[key] = value;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
//
|
|
21
|
+
// 2. Load from .env file if it exists
|
|
22
|
+
const envFilePath = path.join(process.cwd(), '.env');
|
|
23
|
+
if (fs.existsSync(envFilePath)) {
|
|
24
|
+
try {
|
|
25
|
+
const envFileContent = fs.readFileSync(envFilePath, 'utf8');
|
|
26
|
+
const envLines = envFileContent.split('\n');
|
|
27
|
+
for (const line of envLines) {
|
|
28
|
+
const trimmedLine = line.trim();
|
|
29
|
+
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
30
|
+
const [key, ...valueParts] = trimmedLine.split('=');
|
|
31
|
+
if (key && valueParts.length > 0) {
|
|
32
|
+
const value = valueParts.join('=').replace(/^["']|["']$/g, ''); // Remove quotes
|
|
33
|
+
envVars[key.trim()] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.warn('Warning: Could not read .env file:', error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// 3. Override with YAML config values (highest priority)
|
|
43
|
+
const config = readSkillConfig();
|
|
21
44
|
if (config?.skill?.env) {
|
|
22
45
|
for (const [key, value] of Object.entries(config.skill.env)) {
|
|
23
46
|
envVars[key] = value;
|
|
24
47
|
}
|
|
25
48
|
}
|
|
49
|
+
return envVars;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a VM sandbox context with all necessary globals and utilities
|
|
53
|
+
*/
|
|
54
|
+
export function createSandbox(options) {
|
|
55
|
+
const { apiKey, agentId, customConsole, broadcastLog } = options;
|
|
56
|
+
// Load environment variables from multiple sources (same logic as test command)
|
|
57
|
+
const envVars = loadEnvironmentVariables();
|
|
26
58
|
// Create a CommonJS context for execution
|
|
27
59
|
const require = createRequire(process.cwd() + '/package.json');
|
|
28
60
|
const updateUserData = async (data) => {
|
|
@@ -125,7 +157,6 @@ export function createSandbox(options) {
|
|
|
125
157
|
clearTimeout,
|
|
126
158
|
clearInterval,
|
|
127
159
|
process: {
|
|
128
|
-
...process,
|
|
129
160
|
env: envVars
|
|
130
161
|
},
|
|
131
162
|
global: globalThis,
|
|
@@ -188,7 +219,12 @@ const executeFunction = ${toolCode};
|
|
|
188
219
|
|
|
189
220
|
// Export the function for testing
|
|
190
221
|
module.exports = async (input) => {
|
|
222
|
+
try{
|
|
191
223
|
return await executeFunction(input);
|
|
224
|
+
}catch(e){
|
|
225
|
+
console.error(e);
|
|
226
|
+
return { status: 'error', error: e.message };
|
|
227
|
+
}
|
|
192
228
|
};
|
|
193
229
|
`;
|
|
194
230
|
// Execute the code in the sandbox
|