lua-cli 2.2.8-alpha.2 → 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.
- package/API_REFERENCE.md +1408 -0
- package/CLI_REFERENCE.md +818 -0
- package/GETTING_STARTED.md +1040 -0
- package/README.md +738 -424
- package/TEMPLATE_GUIDE.md +1398 -0
- package/dist/api/agent.api.service.d.ts +33 -6
- package/dist/api/agent.api.service.js +27 -0
- package/dist/api/auth.api.service.d.ts +31 -2
- package/dist/api/auth.api.service.js +29 -0
- package/dist/api/basket.api.service.d.ts +53 -11
- package/dist/api/basket.api.service.js +63 -14
- package/dist/api/chat.api.service.d.ts +15 -3
- package/dist/api/chat.api.service.js +12 -0
- package/dist/api/credentials.d.ts +24 -0
- package/dist/api/credentials.js +46 -0
- package/dist/api/custom.data.api.service.d.ts +45 -9
- package/dist/api/custom.data.api.service.js +43 -9
- package/dist/api/lazy-instances.d.ts +49 -0
- package/dist/api/lazy-instances.js +95 -0
- package/dist/api/order.api.service.d.ts +34 -4
- package/dist/api/order.api.service.js +41 -3
- package/dist/api/products.api.service.d.ts +39 -9
- package/dist/api/products.api.service.js +43 -5
- package/dist/api/skills.api.service.d.ts +49 -2
- package/dist/api/skills.api.service.js +47 -1
- package/dist/api/tool.api.service.d.ts +39 -1
- package/dist/api/tool.api.service.js +38 -0
- package/dist/api/user.data.api.service.d.ts +23 -1
- package/dist/api/user.data.api.service.js +22 -0
- package/dist/api-exports.d.ts +236 -5
- package/dist/api-exports.js +264 -81
- package/dist/cli/command-definitions.d.ts +30 -0
- package/dist/cli/command-definitions.js +71 -0
- package/dist/commands/agents.d.ts +20 -0
- package/dist/commands/agents.js +24 -2
- package/dist/commands/apiKey.d.ts +23 -0
- package/dist/commands/apiKey.js +23 -0
- package/dist/commands/compile.d.ts +24 -0
- package/dist/commands/compile.js +67 -759
- package/dist/commands/configure.d.ts +24 -0
- package/dist/commands/configure.js +31 -96
- package/dist/commands/deploy.d.ts +31 -19
- package/dist/commands/deploy.js +45 -74
- package/dist/commands/destroy.d.ts +27 -0
- package/dist/commands/destroy.js +27 -1
- package/dist/commands/dev.d.ts +25 -62
- package/dist/commands/dev.js +58 -878
- package/dist/commands/init.d.ts +27 -0
- package/dist/commands/init.js +98 -260
- package/dist/commands/push.d.ts +24 -21
- package/dist/commands/push.js +39 -92
- package/dist/commands/test.d.ts +26 -0
- package/dist/commands/test.js +41 -188
- package/dist/common/basket.instance.d.ts +54 -3
- package/dist/common/basket.instance.js +56 -3
- package/dist/common/data.entry.instance.d.ts +25 -2
- package/dist/common/data.entry.instance.js +24 -0
- package/dist/common/http.client.d.ts +51 -1
- package/dist/common/http.client.js +50 -0
- package/dist/common/order.instance.d.ts +22 -0
- package/dist/common/order.instance.js +31 -4
- package/dist/common/product.instance.d.ts +22 -1
- package/dist/common/product.instance.js +24 -6
- package/dist/common/product.pagination.instance.d.ts +22 -2
- package/dist/common/product.pagination.instance.js +22 -1
- package/dist/common/product.search.instance.d.ts +13 -3
- package/dist/common/product.search.instance.js +12 -1
- package/dist/common/user.instance.d.ts +27 -3
- package/dist/common/user.instance.js +28 -7
- package/dist/config/auth.constants.d.ts +11 -0
- package/dist/config/auth.constants.js +11 -0
- package/dist/config/compile.constants.d.ts +67 -0
- package/dist/config/compile.constants.js +99 -0
- package/dist/config/constants.d.ts +5 -0
- package/dist/config/constants.js +5 -0
- package/dist/config/dev.constants.d.ts +65 -0
- package/dist/config/dev.constants.js +79 -0
- package/dist/config/init.constants.d.ts +23 -0
- package/dist/config/init.constants.js +41 -0
- package/dist/index.d.ts +19 -3
- package/dist/index.js +28 -44
- package/dist/interfaces/admin.d.ts +56 -50
- package/dist/interfaces/admin.js +4 -0
- package/dist/interfaces/agent.d.ts +21 -0
- package/dist/interfaces/agent.js +4 -0
- package/dist/interfaces/baskets.d.ts +60 -0
- package/dist/interfaces/baskets.js +12 -0
- package/dist/interfaces/chat.d.ts +48 -4
- package/dist/interfaces/chat.js +4 -0
- package/dist/interfaces/common.d.ts +62 -0
- package/dist/interfaces/common.js +8 -0
- package/dist/interfaces/compile.d.ts +11 -0
- package/dist/interfaces/compile.js +4 -0
- package/dist/interfaces/custom.data.d.ts +49 -19
- package/dist/interfaces/custom.data.js +4 -0
- package/dist/interfaces/deploy.d.ts +29 -0
- package/dist/interfaces/deploy.js +4 -0
- package/dist/interfaces/dev.d.ts +53 -0
- package/dist/interfaces/dev.js +5 -0
- package/dist/interfaces/init.d.ts +60 -0
- package/dist/interfaces/init.js +4 -0
- package/dist/interfaces/orders.d.ts +37 -0
- package/dist/interfaces/orders.js +12 -0
- package/dist/interfaces/product.d.ts +38 -10
- package/dist/interfaces/product.js +4 -0
- package/dist/interfaces/push.d.ts +26 -0
- package/dist/interfaces/push.js +4 -0
- package/dist/interfaces/test.d.ts +36 -0
- package/dist/interfaces/test.js +4 -0
- package/dist/services/auth.d.ts +54 -99
- package/dist/services/auth.js +76 -12
- package/dist/types/api-contracts.d.ts +211 -0
- package/dist/types/api-contracts.js +8 -0
- package/dist/types/compile.types.d.ts +76 -0
- package/dist/types/compile.types.js +4 -0
- package/dist/types/index.d.ts +23 -121
- package/dist/types/index.js +25 -14
- package/dist/types/skill.d.ts +142 -0
- package/dist/{skill.js → types/skill.js} +66 -17
- package/dist/types/tool-validation.d.ts +34 -0
- package/dist/types/tool-validation.js +42 -0
- package/dist/utils/auth-flows.d.ts +26 -0
- package/dist/utils/auth-flows.js +141 -0
- package/dist/utils/bundling.d.ts +36 -0
- package/dist/utils/bundling.js +137 -0
- package/dist/utils/compile.d.ts +37 -0
- package/dist/utils/compile.js +242 -0
- package/dist/utils/deploy-api.d.ts +26 -0
- package/dist/utils/deploy-api.js +53 -0
- package/dist/utils/deploy-helpers.d.ts +46 -0
- package/dist/utils/deploy-helpers.js +86 -0
- package/dist/utils/deployment.d.ts +25 -0
- package/dist/utils/deployment.js +161 -0
- package/dist/utils/dev-api.d.ts +61 -0
- package/dist/utils/dev-api.js +262 -0
- package/dist/utils/dev-helpers.d.ts +46 -0
- package/dist/utils/dev-helpers.js +83 -0
- package/dist/utils/dev-server.d.ts +24 -0
- package/dist/utils/dev-server.js +555 -0
- package/dist/utils/dev-watcher.d.ts +31 -0
- package/dist/utils/dev-watcher.js +110 -0
- package/dist/utils/files.js +0 -5
- package/dist/utils/init-agent.d.ts +34 -0
- package/dist/utils/init-agent.js +129 -0
- package/dist/utils/init-helpers.d.ts +41 -0
- package/dist/utils/init-helpers.js +73 -0
- package/dist/utils/init-prompts.d.ts +47 -0
- package/dist/utils/init-prompts.js +168 -0
- package/dist/utils/push-api.d.ts +15 -0
- package/dist/utils/push-api.js +48 -0
- package/dist/utils/push-helpers.d.ts +38 -0
- package/dist/utils/push-helpers.js +84 -0
- package/dist/utils/sandbox-storage.d.ts +27 -0
- package/dist/utils/sandbox-storage.js +71 -0
- package/dist/utils/sandbox.js +78 -114
- package/dist/utils/skill-management.d.ts +14 -0
- package/dist/utils/skill-management.js +148 -0
- package/dist/utils/test-helpers.d.ts +40 -0
- package/dist/utils/test-helpers.js +92 -0
- package/dist/utils/test-prompts.d.ts +23 -0
- package/dist/utils/test-prompts.js +186 -0
- package/dist/utils/tool-detection.d.ts +18 -0
- package/dist/utils/tool-detection.js +110 -0
- package/dist/web/app.css +14 -9
- package/package.json +7 -4
- package/template/QUICKSTART.md +299 -144
- package/template/README.md +928 -349
- package/template/TOOL_EXAMPLES.md +655 -0
- package/template/package-lock.json +5 -5
- package/template/package.json +1 -1
- package/template/src/index.ts +147 -207
- package/template/src/tools/BasketTool.ts +128 -0
- package/template/src/tools/CustomDataTool.ts +7 -13
- package/template/src/tools/OrderTool.ts +54 -0
- package/template/src/tools/PaymentTool.ts +1 -1
- package/template/src/tools/ProductsTool.ts +56 -118
- package/template/src/tools/UserDataTool.ts +4 -26
- package/dist/common/config.d.ts +0 -5
- package/dist/common/config.js +0 -5
- package/dist/custom-data-api.d.ts +0 -72
- package/dist/custom-data-api.js +0 -174
- package/dist/product-api.d.ts +0 -189
- package/dist/product-api.js +0 -141
- package/dist/services/api.d.ts +0 -549
- package/dist/services/api.js +0 -596
- package/dist/skill.d.ts +0 -50
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
- package/dist/user-data-api.d.ts +0 -39
- package/dist/user-data-api.js +0 -50
- package/template/API.md +0 -604
- package/template/DEVELOPER.md +0 -771
- package/template/lua.skill.yaml +0 -7
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push Helper Utilities
|
|
3
|
+
* Helper functions for the push command
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Reads the version from skill configuration.
|
|
7
|
+
*
|
|
8
|
+
* @returns Version string or null if not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function readConfigVersion(): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Reads and parses deploy.json file.
|
|
13
|
+
*
|
|
14
|
+
* @returns Parsed deploy data or null if not found
|
|
15
|
+
*/
|
|
16
|
+
export declare function readDeployJson(): any | null;
|
|
17
|
+
/**
|
|
18
|
+
* Prompts user to confirm version push.
|
|
19
|
+
*
|
|
20
|
+
* @param version - Version to push
|
|
21
|
+
* @returns True if confirmed, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
export declare function confirmVersionPush(version: string): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Validates that configuration has required fields for push.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Skill configuration
|
|
28
|
+
* @throws Error if configuration is invalid
|
|
29
|
+
*/
|
|
30
|
+
export declare function validatePushConfig(config: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* Validates that deploy data matches configuration.
|
|
33
|
+
*
|
|
34
|
+
* @param deployData - Deploy data from deploy.json
|
|
35
|
+
* @param configVersion - Version from configuration
|
|
36
|
+
* @throws Error if deploy data is invalid or version mismatch
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateDeployData(deployData: any, configVersion: string): void;
|
|
@@ -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
|
+
}
|
package/dist/utils/sandbox.js
CHANGED
|
@@ -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,77 +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
|
-
|
|
62
|
-
};
|
|
63
|
-
const getUserData = async () => {
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
const linkUserData = async (data) => {
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
const createProduct = async (data) => {
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
const getProducts = async (page = 1, limit = 10) => {
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
const updateProduct = async (data, productId) => {
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
const deleteProduct = async (productId) => {
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
};
|
|
128
|
-
const deleteCustomData = async (collectionName, entryId) => {
|
|
129
|
-
return await CustomDataApi.deleteCustomData(apiKey, agentId, collectionName, entryId);
|
|
130
|
-
};
|
|
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
|
+
// };
|
|
131
132
|
// Create console object (use custom console if provided, otherwise default)
|
|
132
133
|
const consoleObj = customConsole || console;
|
|
133
134
|
// Create comprehensive polyfills for browser/Node.js APIs
|
|
@@ -256,48 +257,11 @@ export function createSandbox(options) {
|
|
|
256
257
|
null: null,
|
|
257
258
|
Infinity: Infinity,
|
|
258
259
|
NaN: NaN,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
product: {
|
|
267
|
-
data: {
|
|
268
|
-
create: createProduct, // DEPRECATED
|
|
269
|
-
get: getProducts, // DEPRECATED
|
|
270
|
-
update: updateProduct, // DEPRECATED
|
|
271
|
-
delete: deleteProduct, // DEPRECATED
|
|
272
|
-
search: searchProducts // DEPRECATED
|
|
273
|
-
},
|
|
274
|
-
create: createProduct,
|
|
275
|
-
get: getProducts,
|
|
276
|
-
update: updateProduct,
|
|
277
|
-
delete: deleteProduct,
|
|
278
|
-
search: searchProducts,
|
|
279
|
-
basket: {
|
|
280
|
-
create: createBasket,
|
|
281
|
-
get: getBaskets,
|
|
282
|
-
addItem: addItemToBasket,
|
|
283
|
-
removeItem: removeItemFromBasket,
|
|
284
|
-
clear: clearBasket,
|
|
285
|
-
updateStatus: updateBasketStatus
|
|
286
|
-
},
|
|
287
|
-
order: {
|
|
288
|
-
create: createOrder,
|
|
289
|
-
updateStatus: updateOrderStatus,
|
|
290
|
-
get: getUserOrders
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
customData: {
|
|
294
|
-
create: createCustomData,
|
|
295
|
-
get: getCustomData,
|
|
296
|
-
getEntry: getCustomDataEntry,
|
|
297
|
-
update: updateCustomData,
|
|
298
|
-
search: searchCustomData,
|
|
299
|
-
delete: deleteCustomData
|
|
300
|
-
},
|
|
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),
|
|
301
265
|
// Environment variables function
|
|
302
266
|
env: (key) => envVars[key]
|
|
303
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;
|