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.
- 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 +941 -17
- package/dist/web/app.js +174 -22
- package/dist/web/index.html +7 -1
- package/package.json +13 -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,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev File Watcher Utilities
|
|
3
|
+
* Handles file system watching and automatic recompilation
|
|
4
|
+
*/
|
|
5
|
+
import { watch } from 'fs';
|
|
6
|
+
import { compileCommand } from '../commands/compile.js';
|
|
7
|
+
import { pushSkillsToSandbox } from './dev-api.js';
|
|
8
|
+
import { writeProgress } from './cli.js';
|
|
9
|
+
import { FILE_WATCH_CONFIG, WATCH_IGNORE_PATTERNS, WATCH_IGNORE_EXTENSIONS, } from '../config/dev.constants.js';
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a file should be ignored during watching.
|
|
12
|
+
*
|
|
13
|
+
* @param filename - The filename to check
|
|
14
|
+
* @returns True if file should be ignored, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export function shouldIgnoreFile(filename) {
|
|
17
|
+
if (!filename) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
// Check ignore patterns
|
|
21
|
+
for (const pattern of WATCH_IGNORE_PATTERNS) {
|
|
22
|
+
if (filename.includes(pattern)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Check ignore extensions
|
|
27
|
+
for (const ext of WATCH_IGNORE_EXTENSIONS) {
|
|
28
|
+
if (filename.endsWith(ext)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates and starts a file watcher for development mode.
|
|
36
|
+
* Watches for file changes and automatically recompiles and pushes to sandbox.
|
|
37
|
+
*
|
|
38
|
+
* @param config - File watcher configuration
|
|
39
|
+
* @returns The watcher instance
|
|
40
|
+
*/
|
|
41
|
+
export function createFileWatcher(config) {
|
|
42
|
+
const { apiKey, agentId, readDeployJson, broadcastLog } = config;
|
|
43
|
+
let isCompiling = false;
|
|
44
|
+
let pendingCompile = false;
|
|
45
|
+
let compileTimeout = null;
|
|
46
|
+
const watcher = watch(process.cwd(), { recursive: FILE_WATCH_CONFIG.RECURSIVE }, async (eventType, filename) => {
|
|
47
|
+
// Ignore changes in build artifacts and dependencies
|
|
48
|
+
if (shouldIgnoreFile(filename)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Debounce rapid changes
|
|
52
|
+
if (isCompiling) {
|
|
53
|
+
pendingCompile = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Clear any existing timeout
|
|
57
|
+
if (compileTimeout) {
|
|
58
|
+
clearTimeout(compileTimeout);
|
|
59
|
+
}
|
|
60
|
+
// Debounce file changes with configured delay
|
|
61
|
+
compileTimeout = setTimeout(async () => {
|
|
62
|
+
if (isCompiling) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
isCompiling = true;
|
|
66
|
+
pendingCompile = false;
|
|
67
|
+
try {
|
|
68
|
+
writeProgress(`🔄 File changed: ${filename} - Compiling and pushing...`);
|
|
69
|
+
broadcastLog(`🔄 File changed: ${filename} - Compiling and pushing...`, 'info');
|
|
70
|
+
// Compile the skill
|
|
71
|
+
await compileCommand();
|
|
72
|
+
broadcastLog("✅ Compilation completed", 'info');
|
|
73
|
+
// Read updated deploy.json
|
|
74
|
+
const updatedDeployData = readDeployJson();
|
|
75
|
+
if (!updatedDeployData) {
|
|
76
|
+
writeProgress("❌ Compilation failed, skipping push");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Verify updated deploy.json has skills
|
|
80
|
+
if (!updatedDeployData.skills || !Array.isArray(updatedDeployData.skills) || updatedDeployData.skills.length === 0) {
|
|
81
|
+
writeProgress("❌ No skills found in updated deploy.json, skipping push");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Push all skills to sandbox
|
|
85
|
+
const updatedSandboxIds = await pushSkillsToSandbox(apiKey, agentId, updatedDeployData, false);
|
|
86
|
+
if (Object.keys(updatedSandboxIds).length === 0) {
|
|
87
|
+
writeProgress("❌ Failed to push any skills to sandbox, will retry on next change");
|
|
88
|
+
broadcastLog("❌ Failed to push skills to sandbox, will retry on next change", 'error');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
broadcastLog(`✅ Successfully pushed ${Object.keys(updatedSandboxIds).length} skills to sandbox`, 'info');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
writeProgress(`❌ Error during auto-compile: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
isCompiling = false;
|
|
99
|
+
}
|
|
100
|
+
}, FILE_WATCH_CONFIG.DEBOUNCE_DELAY);
|
|
101
|
+
});
|
|
102
|
+
// Handle graceful shutdown
|
|
103
|
+
const cleanup = () => {
|
|
104
|
+
if (compileTimeout) {
|
|
105
|
+
clearTimeout(compileTimeout);
|
|
106
|
+
}
|
|
107
|
+
watcher.close();
|
|
108
|
+
};
|
|
109
|
+
return { watcher, cleanup };
|
|
110
|
+
}
|
package/dist/utils/files.js
CHANGED
|
@@ -49,11 +49,6 @@ function updatePackageJson(srcPath, destPath) {
|
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
51
|
// If we can't read any package.json, use the fallback version
|
|
52
|
-
// console.log(`Using fallback CLI version: ${currentCliVersion}`);
|
|
53
|
-
}
|
|
54
|
-
// Update the lua-cli dependency version
|
|
55
|
-
if (templatePackageJson.dependencies && templatePackageJson.dependencies['lua-cli']) {
|
|
56
|
-
// templatePackageJson.dependencies['lua-cli'] = `^${currentCliVersion}`;
|
|
57
52
|
}
|
|
58
53
|
// Write the updated package.json
|
|
59
54
|
fs.writeFileSync(destPath, JSON.stringify(templatePackageJson, null, 2) + '\n');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Agent Management Utilities
|
|
3
|
+
* Handles agent type selection, creation, and retrieval
|
|
4
|
+
*/
|
|
5
|
+
import { AgentType } from '../interfaces/agent.js';
|
|
6
|
+
import { AgentCreationResult, BusinessConfig } from '../interfaces/init.js';
|
|
7
|
+
/**
|
|
8
|
+
* Fetches available agent types from the API.
|
|
9
|
+
*
|
|
10
|
+
* @param apiKey - User's API key
|
|
11
|
+
* @returns Array of available agent types
|
|
12
|
+
*/
|
|
13
|
+
export declare function fetchAgentTypes(apiKey: string): Promise<AgentType[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Selects the Base Agent type from available types.
|
|
16
|
+
* Falls back to first available type if Base Agent is not found.
|
|
17
|
+
*
|
|
18
|
+
* @param agentTypes - Array of available agent types
|
|
19
|
+
* @returns Selected agent type
|
|
20
|
+
* @throws Error if no agent types are available
|
|
21
|
+
*/
|
|
22
|
+
export declare function selectBaseAgentType(agentTypes: AgentType[]): AgentType;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new agent with the provided configuration.
|
|
25
|
+
*
|
|
26
|
+
* @param apiKey - User's API key
|
|
27
|
+
* @param agentType - Selected agent type
|
|
28
|
+
* @param businessConfig - Business configuration
|
|
29
|
+
* @param metadata - Agent metadata
|
|
30
|
+
* @param features - Feature configuration
|
|
31
|
+
* @returns Agent creation result with agent and org details
|
|
32
|
+
* @throws Error if agent creation fails
|
|
33
|
+
*/
|
|
34
|
+
export declare function createNewAgent(apiKey: string, agentType: AgentType, businessConfig: BusinessConfig, metadata: Record<string, any>, features: Record<string, boolean>): Promise<AgentCreationResult>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Agent Management Utilities
|
|
3
|
+
* Handles agent type selection, creation, and retrieval
|
|
4
|
+
*/
|
|
5
|
+
import AgentApi from '../api/agent.api.service.js';
|
|
6
|
+
import { BASE_URLS } from '../config/constants.js';
|
|
7
|
+
import { writeProgress } from './cli.js';
|
|
8
|
+
import { AGENT_READY_WAIT_TIME, PREFERRED_AGENT_TYPES, } from '../config/init.constants.js';
|
|
9
|
+
/**
|
|
10
|
+
* Fetches available agent types from the API.
|
|
11
|
+
*
|
|
12
|
+
* @param apiKey - User's API key
|
|
13
|
+
* @returns Array of available agent types
|
|
14
|
+
*/
|
|
15
|
+
export async function fetchAgentTypes(apiKey) {
|
|
16
|
+
writeProgress("🔄 Fetching agent types...");
|
|
17
|
+
const agentApi = new AgentApi(BASE_URLS.API, apiKey);
|
|
18
|
+
const agentTypesResult = await agentApi.getAgentTypes();
|
|
19
|
+
const agentTypes = agentTypesResult.success ? agentTypesResult.data || [] : [];
|
|
20
|
+
writeProgress("✅ Agent types loaded");
|
|
21
|
+
return agentTypes;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Selects the Base Agent type from available types.
|
|
25
|
+
* Falls back to first available type if Base Agent is not found.
|
|
26
|
+
*
|
|
27
|
+
* @param agentTypes - Array of available agent types
|
|
28
|
+
* @returns Selected agent type
|
|
29
|
+
* @throws Error if no agent types are available
|
|
30
|
+
*/
|
|
31
|
+
export function selectBaseAgentType(agentTypes) {
|
|
32
|
+
// Try to find Base Agent by preferred names
|
|
33
|
+
let selectedAgentType = agentTypes.find((type) => PREFERRED_AGENT_TYPES.some(name => type.name === name || type.name.toLowerCase().includes(name.toLowerCase())));
|
|
34
|
+
// If not found, use the first available type
|
|
35
|
+
if (!selectedAgentType && agentTypes.length > 0) {
|
|
36
|
+
selectedAgentType = agentTypes[0];
|
|
37
|
+
writeProgress(`⚠️ baseAgent not found, using ${selectedAgentType.name} instead`);
|
|
38
|
+
}
|
|
39
|
+
if (!selectedAgentType) {
|
|
40
|
+
throw new Error("No agent types available. Please contact support.");
|
|
41
|
+
}
|
|
42
|
+
writeProgress(`✅ Using agent type: ${selectedAgentType.name}`);
|
|
43
|
+
return selectedAgentType;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new agent with the provided configuration.
|
|
47
|
+
*
|
|
48
|
+
* @param apiKey - User's API key
|
|
49
|
+
* @param agentType - Selected agent type
|
|
50
|
+
* @param businessConfig - Business configuration
|
|
51
|
+
* @param metadata - Agent metadata
|
|
52
|
+
* @param features - Feature configuration
|
|
53
|
+
* @returns Agent creation result with agent and org details
|
|
54
|
+
* @throws Error if agent creation fails
|
|
55
|
+
*/
|
|
56
|
+
export async function createNewAgent(apiKey, agentType, businessConfig, metadata, features) {
|
|
57
|
+
writeProgress("🔄 Creating agent...");
|
|
58
|
+
const agentData = {
|
|
59
|
+
id: `agent_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
60
|
+
type: agentType.id,
|
|
61
|
+
metadata,
|
|
62
|
+
persona: {
|
|
63
|
+
agentName: businessConfig.agentName,
|
|
64
|
+
businessType: businessConfig.businessType,
|
|
65
|
+
brandPersonality: businessConfig.brandPersonality,
|
|
66
|
+
brandTraits: businessConfig.brandTraits
|
|
67
|
+
},
|
|
68
|
+
features,
|
|
69
|
+
channels: [],
|
|
70
|
+
org: {
|
|
71
|
+
registeredName: businessConfig.businessName
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const agentApi = new AgentApi(BASE_URLS.API, apiKey);
|
|
75
|
+
const createAgentResult = await agentApi.createAgent(agentData);
|
|
76
|
+
if (!createAgentResult.success || !createAgentResult.data) {
|
|
77
|
+
throw new Error(createAgentResult.error?.message || "Failed to create agent");
|
|
78
|
+
}
|
|
79
|
+
writeProgress("✅ Agent created successfully!");
|
|
80
|
+
// Wait for agent to be ready
|
|
81
|
+
await waitForAgentReady();
|
|
82
|
+
// Validate required fields from API response
|
|
83
|
+
const agentId = createAgentResult.data?.data?.agentId;
|
|
84
|
+
const agentName = createAgentResult.data?.data?.name;
|
|
85
|
+
const orgId = createAgentResult.data?.data?.org?.id;
|
|
86
|
+
if (!agentId || !agentName || !orgId) {
|
|
87
|
+
throw new Error("Failed to create agent: Missing required fields in API response");
|
|
88
|
+
}
|
|
89
|
+
// Fetch agent details
|
|
90
|
+
const agentDetails = await fetchAgentDetails(agentApi, agentId);
|
|
91
|
+
return {
|
|
92
|
+
agent: {
|
|
93
|
+
agentId,
|
|
94
|
+
name: agentName
|
|
95
|
+
},
|
|
96
|
+
org: {
|
|
97
|
+
id: orgId
|
|
98
|
+
},
|
|
99
|
+
persona: agentDetails.persona,
|
|
100
|
+
welcomeMessage: agentDetails.welcomeMessage
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Waits for the agent to be ready after creation.
|
|
105
|
+
*/
|
|
106
|
+
async function waitForAgentReady() {
|
|
107
|
+
writeProgress("⏳ Waiting for agent to be ready...");
|
|
108
|
+
await new Promise(resolve => setTimeout(resolve, AGENT_READY_WAIT_TIME));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fetches detailed agent information.
|
|
112
|
+
*
|
|
113
|
+
* @param agentApi - Agent API instance
|
|
114
|
+
* @param agentId - Agent ID to fetch
|
|
115
|
+
* @returns Agent details including persona and welcome message
|
|
116
|
+
* @throws Error if fetch fails
|
|
117
|
+
*/
|
|
118
|
+
async function fetchAgentDetails(agentApi, agentId) {
|
|
119
|
+
writeProgress("🔄 Fetching agent details...");
|
|
120
|
+
const agentDetailsResult = await agentApi.getAgent(agentId);
|
|
121
|
+
if (!agentDetailsResult.success || !agentDetailsResult.data) {
|
|
122
|
+
throw new Error(agentDetailsResult.error?.message || "Failed to fetch agent details");
|
|
123
|
+
}
|
|
124
|
+
writeProgress("✅ Agent details loaded");
|
|
125
|
+
return {
|
|
126
|
+
persona: agentDetailsResult.data.persona,
|
|
127
|
+
welcomeMessage: agentDetailsResult.data.welcomeMessage
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Helper Utilities
|
|
3
|
+
* Helper functions for initialization process
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Gets the template directory path.
|
|
7
|
+
*
|
|
8
|
+
* @returns Absolute path to template directory
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTemplateDir(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the project by copying template files and creating YAML.
|
|
13
|
+
*
|
|
14
|
+
* @param agentId - Agent ID for configuration
|
|
15
|
+
* @param orgId - Organization ID for configuration
|
|
16
|
+
* @param persona - Optional persona configuration
|
|
17
|
+
* @param welcomeMessage - Optional welcome message
|
|
18
|
+
* @returns Current working directory
|
|
19
|
+
*/
|
|
20
|
+
export declare function initializeProject(agentId: string, orgId: string, persona?: string, welcomeMessage?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Installs npm dependencies for the project.
|
|
23
|
+
*
|
|
24
|
+
* @param projectDir - Directory to install dependencies in
|
|
25
|
+
*/
|
|
26
|
+
export declare function installDependencies(projectDir: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Counts total prompt lines to clear.
|
|
29
|
+
* This is a helper for managing terminal output cleanup.
|
|
30
|
+
*
|
|
31
|
+
* @param baseCount - Base number of lines
|
|
32
|
+
* @param additionalLines - Additional lines to add
|
|
33
|
+
* @returns Total line count
|
|
34
|
+
*/
|
|
35
|
+
export declare function calculatePromptLines(baseCount: number, additionalLines: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Clears terminal lines if count is greater than zero.
|
|
38
|
+
*
|
|
39
|
+
* @param lineCount - Number of lines to clear
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearLinesIfNeeded(lineCount: number): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Helper Utilities
|
|
3
|
+
* Helper functions for initialization process
|
|
4
|
+
*/
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { copyTemplateFiles, createSkillYaml } from "./files.js";
|
|
8
|
+
import { clearPromptLines, writeProgress } from "./cli.js";
|
|
9
|
+
import { execSync } from 'child_process';
|
|
10
|
+
/**
|
|
11
|
+
* Gets the template directory path.
|
|
12
|
+
*
|
|
13
|
+
* @returns Absolute path to template directory
|
|
14
|
+
*/
|
|
15
|
+
export function getTemplateDir() {
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const __dirname = path.dirname(__filename);
|
|
18
|
+
return path.join(__dirname, "..", "..", "template");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the project by copying template files and creating YAML.
|
|
22
|
+
*
|
|
23
|
+
* @param agentId - Agent ID for configuration
|
|
24
|
+
* @param orgId - Organization ID for configuration
|
|
25
|
+
* @param persona - Optional persona configuration
|
|
26
|
+
* @param welcomeMessage - Optional welcome message
|
|
27
|
+
* @returns Current working directory
|
|
28
|
+
*/
|
|
29
|
+
export function initializeProject(agentId, orgId, persona, welcomeMessage) {
|
|
30
|
+
const templateDir = getTemplateDir();
|
|
31
|
+
const currentDir = process.cwd();
|
|
32
|
+
copyTemplateFiles(templateDir, currentDir);
|
|
33
|
+
createSkillYaml(agentId, orgId, undefined, undefined, persona, welcomeMessage);
|
|
34
|
+
writeProgress("✅ Created lua.skill.yaml");
|
|
35
|
+
writeProgress("✅ Copied template files");
|
|
36
|
+
return currentDir;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Installs npm dependencies for the project.
|
|
40
|
+
*
|
|
41
|
+
* @param projectDir - Directory to install dependencies in
|
|
42
|
+
*/
|
|
43
|
+
export async function installDependencies(projectDir) {
|
|
44
|
+
writeProgress("📦 Installing dependencies...");
|
|
45
|
+
try {
|
|
46
|
+
execSync('npm install --force', { stdio: 'inherit', cwd: projectDir });
|
|
47
|
+
writeProgress("✅ Dependencies installed successfully");
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
writeProgress("⚠️ Warning: Failed to install dependencies automatically. Please run 'npm install' manually.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Counts total prompt lines to clear.
|
|
55
|
+
* This is a helper for managing terminal output cleanup.
|
|
56
|
+
*
|
|
57
|
+
* @param baseCount - Base number of lines
|
|
58
|
+
* @param additionalLines - Additional lines to add
|
|
59
|
+
* @returns Total line count
|
|
60
|
+
*/
|
|
61
|
+
export function calculatePromptLines(baseCount, additionalLines) {
|
|
62
|
+
return baseCount + additionalLines;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clears terminal lines if count is greater than zero.
|
|
66
|
+
*
|
|
67
|
+
* @param lineCount - Number of lines to clear
|
|
68
|
+
*/
|
|
69
|
+
export function clearLinesIfNeeded(lineCount) {
|
|
70
|
+
if (lineCount > 0) {
|
|
71
|
+
clearPromptLines(lineCount);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Command Prompt Utilities
|
|
3
|
+
* Handles all interactive prompts for agent initialization
|
|
4
|
+
*/
|
|
5
|
+
import { AgentChoiceType, SelectedAgent, SelectedOrg, OrganizationData, BusinessConfig } from '../interfaces/init.js';
|
|
6
|
+
import { AgentType } from '../interfaces/agent.js';
|
|
7
|
+
/**
|
|
8
|
+
* Prompts user to choose between existing or new agent.
|
|
9
|
+
*
|
|
10
|
+
* @returns Selected choice ('existing' or 'create')
|
|
11
|
+
*/
|
|
12
|
+
export declare function promptAgentChoice(): Promise<AgentChoiceType>;
|
|
13
|
+
/**
|
|
14
|
+
* Prompts user to select an organization from available options.
|
|
15
|
+
*
|
|
16
|
+
* @param orgs - Array of organizations to choose from
|
|
17
|
+
* @returns Selected organization
|
|
18
|
+
*/
|
|
19
|
+
export declare function promptOrganizationSelection(orgs: OrganizationData[]): Promise<SelectedOrg>;
|
|
20
|
+
/**
|
|
21
|
+
* Prompts user to select an agent from an organization.
|
|
22
|
+
*
|
|
23
|
+
* @param org - Organization containing agents
|
|
24
|
+
* @returns Selected agent
|
|
25
|
+
*/
|
|
26
|
+
export declare function promptAgentSelection(org: SelectedOrg): Promise<SelectedAgent>;
|
|
27
|
+
/**
|
|
28
|
+
* Prompts for metadata fields required by the agent type.
|
|
29
|
+
*
|
|
30
|
+
* @param requiredFields - Array of required metadata field names
|
|
31
|
+
* @returns Object containing collected metadata
|
|
32
|
+
*/
|
|
33
|
+
export declare function promptMetadataCollection(requiredFields: string[]): Promise<Record<string, any>>;
|
|
34
|
+
/**
|
|
35
|
+
* Prompts for feature configuration.
|
|
36
|
+
*
|
|
37
|
+
* @param agentType - Agent type containing available features
|
|
38
|
+
* @returns Object containing feature enable/disable status
|
|
39
|
+
*/
|
|
40
|
+
export declare function promptFeatureConfiguration(agentType: AgentType): Promise<Record<string, boolean>>;
|
|
41
|
+
/**
|
|
42
|
+
* Prompts for business and agent configuration.
|
|
43
|
+
* Collects business name, agent name, type, personality, and traits.
|
|
44
|
+
*
|
|
45
|
+
* @returns Complete business configuration
|
|
46
|
+
*/
|
|
47
|
+
export declare function promptBusinessConfiguration(): Promise<BusinessConfig>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Command Prompt Utilities
|
|
3
|
+
* Handles all interactive prompts for agent initialization
|
|
4
|
+
*/
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import { BUSINESS_TYPES, BRAND_PERSONALITIES, DEFAULT_BUSINESS_NAME, } from '../config/init.constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Prompts user to choose between existing or new agent.
|
|
9
|
+
*
|
|
10
|
+
* @returns Selected choice ('existing' or 'create')
|
|
11
|
+
*/
|
|
12
|
+
export async function promptAgentChoice() {
|
|
13
|
+
const { agentChoice } = await inquirer.prompt([
|
|
14
|
+
{
|
|
15
|
+
type: "list",
|
|
16
|
+
name: "agentChoice",
|
|
17
|
+
message: "What would you like to do?",
|
|
18
|
+
choices: [
|
|
19
|
+
{ name: "Select existing agent", value: "existing" },
|
|
20
|
+
{ name: "Create new agent", value: "create" }
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]);
|
|
24
|
+
return agentChoice;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Prompts user to select an organization from available options.
|
|
28
|
+
*
|
|
29
|
+
* @param orgs - Array of organizations to choose from
|
|
30
|
+
* @returns Selected organization
|
|
31
|
+
*/
|
|
32
|
+
export async function promptOrganizationSelection(orgs) {
|
|
33
|
+
const orgChoices = orgs.map((org) => ({
|
|
34
|
+
name: org.registeredName || org.name || 'Unknown Organization',
|
|
35
|
+
value: org
|
|
36
|
+
}));
|
|
37
|
+
const { selectedOrg } = await inquirer.prompt([
|
|
38
|
+
{
|
|
39
|
+
type: "list",
|
|
40
|
+
name: "selectedOrg",
|
|
41
|
+
message: "Select an organization:",
|
|
42
|
+
choices: orgChoices
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
return selectedOrg;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Prompts user to select an agent from an organization.
|
|
49
|
+
*
|
|
50
|
+
* @param org - Organization containing agents
|
|
51
|
+
* @returns Selected agent
|
|
52
|
+
*/
|
|
53
|
+
export async function promptAgentSelection(org) {
|
|
54
|
+
if (!org.agents || org.agents.length === 0) {
|
|
55
|
+
throw new Error("No agents found in the selected organization.");
|
|
56
|
+
}
|
|
57
|
+
const agentChoices = org.agents.map((agent) => ({
|
|
58
|
+
name: agent.name,
|
|
59
|
+
value: agent
|
|
60
|
+
}));
|
|
61
|
+
const { selectedAgent } = await inquirer.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: "list",
|
|
64
|
+
name: "selectedAgent",
|
|
65
|
+
message: "Select an agent:",
|
|
66
|
+
choices: agentChoices
|
|
67
|
+
}
|
|
68
|
+
]);
|
|
69
|
+
return selectedAgent;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Prompts for metadata fields required by the agent type.
|
|
73
|
+
*
|
|
74
|
+
* @param requiredFields - Array of required metadata field names
|
|
75
|
+
* @returns Object containing collected metadata
|
|
76
|
+
*/
|
|
77
|
+
export async function promptMetadataCollection(requiredFields) {
|
|
78
|
+
const metadata = {};
|
|
79
|
+
for (const field of requiredFields) {
|
|
80
|
+
const { [field]: value } = await inquirer.prompt([
|
|
81
|
+
{
|
|
82
|
+
type: "input",
|
|
83
|
+
name: field,
|
|
84
|
+
message: `Enter ${field}:`,
|
|
85
|
+
validate: (input) => input.trim().length > 0 || `${field} is required`
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
metadata[field] = value;
|
|
89
|
+
}
|
|
90
|
+
return metadata;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Prompts for feature configuration.
|
|
94
|
+
*
|
|
95
|
+
* @param agentType - Agent type containing available features
|
|
96
|
+
* @returns Object containing feature enable/disable status
|
|
97
|
+
*/
|
|
98
|
+
export async function promptFeatureConfiguration(agentType) {
|
|
99
|
+
const features = {};
|
|
100
|
+
const availableFeatures = Object.keys(agentType.features);
|
|
101
|
+
for (const feature of availableFeatures) {
|
|
102
|
+
const { [feature]: enabled } = await inquirer.prompt([
|
|
103
|
+
{
|
|
104
|
+
type: "confirm",
|
|
105
|
+
name: feature,
|
|
106
|
+
message: `Enable ${feature} feature?`,
|
|
107
|
+
default: agentType.features[feature]?.active || false
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
features[feature] = enabled;
|
|
111
|
+
}
|
|
112
|
+
return features;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Prompts for business and agent configuration.
|
|
116
|
+
* Collects business name, agent name, type, personality, and traits.
|
|
117
|
+
*
|
|
118
|
+
* @returns Complete business configuration
|
|
119
|
+
*/
|
|
120
|
+
export async function promptBusinessConfiguration() {
|
|
121
|
+
const { businessName } = await inquirer.prompt([
|
|
122
|
+
{
|
|
123
|
+
type: "input",
|
|
124
|
+
name: "businessName",
|
|
125
|
+
message: "Enter business name:",
|
|
126
|
+
default: DEFAULT_BUSINESS_NAME
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
const { agentName } = await inquirer.prompt([
|
|
130
|
+
{
|
|
131
|
+
type: "input",
|
|
132
|
+
name: "agentName",
|
|
133
|
+
message: "Enter agent name:",
|
|
134
|
+
validate: (input) => input.trim().length > 0 || "Agent name is required"
|
|
135
|
+
}
|
|
136
|
+
]);
|
|
137
|
+
const { businessType } = await inquirer.prompt([
|
|
138
|
+
{
|
|
139
|
+
type: "list",
|
|
140
|
+
name: "businessType",
|
|
141
|
+
message: "Select business type:",
|
|
142
|
+
choices: BUSINESS_TYPES
|
|
143
|
+
}
|
|
144
|
+
]);
|
|
145
|
+
const { brandPersonality } = await inquirer.prompt([
|
|
146
|
+
{
|
|
147
|
+
type: "list",
|
|
148
|
+
name: "brandPersonality",
|
|
149
|
+
message: "Select brand personality:",
|
|
150
|
+
choices: BRAND_PERSONALITIES
|
|
151
|
+
}
|
|
152
|
+
]);
|
|
153
|
+
const { brandTraits } = await inquirer.prompt([
|
|
154
|
+
{
|
|
155
|
+
type: "input",
|
|
156
|
+
name: "brandTraits",
|
|
157
|
+
message: "Enter brand traits (any traits the agent might have):",
|
|
158
|
+
default: ""
|
|
159
|
+
}
|
|
160
|
+
]);
|
|
161
|
+
return {
|
|
162
|
+
businessName,
|
|
163
|
+
agentName,
|
|
164
|
+
businessType,
|
|
165
|
+
brandPersonality,
|
|
166
|
+
brandTraits
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push API Utilities
|
|
3
|
+
* Handles API calls for pushing skill versions
|
|
4
|
+
*/
|
|
5
|
+
import { PushVersionResponse } from '../interfaces/push.js';
|
|
6
|
+
/**
|
|
7
|
+
* Pushes a skill version to the server.
|
|
8
|
+
*
|
|
9
|
+
* @param apiKey - User's API key
|
|
10
|
+
* @param agentId - Agent ID
|
|
11
|
+
* @param skillId - Skill ID
|
|
12
|
+
* @param versionData - Version data to push
|
|
13
|
+
* @returns Push version response
|
|
14
|
+
*/
|
|
15
|
+
export declare function pushVersion(apiKey: string, agentId: string, skillId: string, versionData: any): Promise<PushVersionResponse>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push API Utilities
|
|
3
|
+
* Handles API calls for pushing skill versions
|
|
4
|
+
*/
|
|
5
|
+
import SkillApi from '../api/skills.api.service.js';
|
|
6
|
+
import { BASE_URLS } from '../config/constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pushes a skill version to the server.
|
|
9
|
+
*
|
|
10
|
+
* @param apiKey - User's API key
|
|
11
|
+
* @param agentId - Agent ID
|
|
12
|
+
* @param skillId - Skill ID
|
|
13
|
+
* @param versionData - Version data to push
|
|
14
|
+
* @returns Push version response
|
|
15
|
+
*/
|
|
16
|
+
export async function pushVersion(apiKey, agentId, skillId, versionData) {
|
|
17
|
+
try {
|
|
18
|
+
const skillApi = new SkillApi(BASE_URLS.API, apiKey, agentId);
|
|
19
|
+
const response = await skillApi.pushSkill(skillId, versionData);
|
|
20
|
+
if (response.success) {
|
|
21
|
+
return {
|
|
22
|
+
success: true,
|
|
23
|
+
data: response.data
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return {
|
|
28
|
+
success: false,
|
|
29
|
+
error: {
|
|
30
|
+
message: response.error?.message || 'Unknown error',
|
|
31
|
+
error: response.error?.message || 'Unknown error',
|
|
32
|
+
statusCode: response.error?.statusCode || 500
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("❌ Error pushing version:", error);
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: {
|
|
42
|
+
message: "Network error",
|
|
43
|
+
error: "Failed to connect to server",
|
|
44
|
+
statusCode: 500
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|