lua-cli 2.3.2 โ†’ 2.4.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.
@@ -31,6 +31,7 @@ export default class ProductApi extends HttpClient {
31
31
  if (response.success) {
32
32
  return new ProductPaginationInstance(this, response);
33
33
  }
34
+ console.error(response);
34
35
  throw new Error(response.error?.message || 'Failed to get products');
35
36
  }
36
37
  /**
@@ -17,14 +17,6 @@ export declare function setupAuthCommands(program: Command): void;
17
17
  /**
18
18
  * Sets up skill management commands.
19
19
  *
20
- * Commands:
21
- * - `lua init` - Initialize new project
22
- * - `lua compile` - Compile skill
23
- * - `lua test` - Test tools interactively
24
- * - `lua push` - Push to server
25
- * - `lua deploy` - Deploy to production
26
- * - `lua dev` - Development mode with live reload
27
- *
28
20
  * @param program - Commander program instance
29
21
  */
30
22
  export declare function setupSkillCommands(program: Command): void;
@@ -2,7 +2,7 @@
2
2
  * Command Definitions
3
3
  * Centralized command structure for the CLI
4
4
  */
5
- import { configureCommand, initCommand, destroyCommand, apiKeyCommand, compileCommand, testCommand, pushCommand, deployCommand, devCommand } from "../commands/index.js";
5
+ import { configureCommand, initCommand, destroyCommand, apiKeyCommand, compileCommand, testCommand, pushCommand, deployCommand, chatCommand, chatClearCommand, envCommand, personaCommand, productionCommand, resourcesCommand } from "../commands/index.js";
6
6
  /**
7
7
  * Sets up authentication-related commands.
8
8
  *
@@ -16,7 +16,13 @@ import { configureCommand, initCommand, destroyCommand, apiKeyCommand, compileCo
16
16
  export function setupAuthCommands(program) {
17
17
  const authCommand = program
18
18
  .command("auth")
19
- .description("Authentication management commands");
19
+ .description("๐Ÿ” Authentication management")
20
+ .addHelpText('after', `
21
+ Examples:
22
+ $ lua auth configure Set up your API key for the first time
23
+ $ lua auth key View your current API key
24
+ $ lua auth logout Remove stored credentials
25
+ `);
20
26
  authCommand
21
27
  .command("configure")
22
28
  .description("Set up your API key")
@@ -33,39 +39,66 @@ export function setupAuthCommands(program) {
33
39
  /**
34
40
  * Sets up skill management commands.
35
41
  *
36
- * Commands:
37
- * - `lua init` - Initialize new project
38
- * - `lua compile` - Compile skill
39
- * - `lua test` - Test tools interactively
40
- * - `lua push` - Push to server
41
- * - `lua deploy` - Deploy to production
42
- * - `lua dev` - Development mode with live reload
43
- *
44
42
  * @param program - Commander program instance
45
43
  */
46
44
  export function setupSkillCommands(program) {
45
+ // Project Setup
47
46
  program
48
47
  .command("init")
49
- .description("Initialize a new Lua skill project")
48
+ .description("๐Ÿš€ Initialize a new Lua skill project")
50
49
  .action(initCommand);
50
+ // Development Commands
51
51
  program
52
52
  .command("compile")
53
- .description("Compile Lua skill to generate deployable format")
53
+ .description("๐Ÿ“ฆ Compile skill to deployable format")
54
54
  .action(compileCommand);
55
55
  program
56
56
  .command("test")
57
- .description("Test Lua skill tools interactively")
57
+ .description("๐Ÿงช Test skill tools interactively")
58
58
  .action(testCommand);
59
+ // Deployment Commands
59
60
  program
60
61
  .command("push")
61
- .description("Push compiled skill version to server")
62
+ .description("โ˜๏ธ Push skill version to server")
62
63
  .action(pushCommand);
63
64
  program
64
65
  .command("deploy")
65
- .description("Deploy a version to production")
66
+ .description("๐Ÿš€ Deploy version to production")
66
67
  .action(deployCommand);
68
+ // Temporarily disabled - will be released later
69
+ // program
70
+ // .command("dev")
71
+ // .description("๐Ÿ”ง Development mode with live reload")
72
+ // .action(devCommand);
73
+ // Chat Commands
74
+ const chatCmd = program
75
+ .command("chat")
76
+ .description("๐Ÿ’ฌ Interactive chat with your agent")
77
+ .addHelpText('after', `
78
+ Examples:
79
+ $ lua chat Start interactive chat session
80
+ $ lua chat clear Clear all conversation history
81
+ `)
82
+ .action(chatCommand);
83
+ chatCmd
84
+ .command("clear")
85
+ .description("Clear conversation history")
86
+ .action(chatClearCommand);
87
+ // Configuration Commands
88
+ program
89
+ .command("env")
90
+ .description("โš™๏ธ Manage environment variables")
91
+ .action(envCommand);
92
+ program
93
+ .command("persona")
94
+ .description("๐Ÿค– Manage agent persona")
95
+ .action(personaCommand);
96
+ program
97
+ .command("production")
98
+ .description("๐Ÿš€ View and manage production environment")
99
+ .action(productionCommand);
67
100
  program
68
- .command("dev")
69
- .description("Push compiled skill version to sandbox for development")
70
- .action(devCommand);
101
+ .command("resources")
102
+ .description("๐Ÿ“š Manage agent resources and knowledge base")
103
+ .action(resourcesCommand);
71
104
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Chat Command
3
+ * Interactive CLI chat interface with sandbox or production environment
4
+ */
5
+ /**
6
+ * Main chat command - starts interactive chat session
7
+ *
8
+ * Features:
9
+ * - Environment selection (sandbox or production)
10
+ * - Interactive chat loop
11
+ * - Skill and persona overrides for sandbox
12
+ * - Real-time conversation
13
+ * - Exit with Ctrl+C
14
+ *
15
+ * @returns Promise that resolves when chat session ends
16
+ */
17
+ export declare function chatCommand(): Promise<void>;
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Chat Command
3
+ * Interactive CLI chat interface with sandbox or production environment
4
+ */
5
+ import * as readline from 'readline';
6
+ import inquirer from 'inquirer';
7
+ import { loadApiKey, checkApiKey } from '../services/auth.js';
8
+ import { readSkillConfig } from '../utils/files.js';
9
+ import { withErrorHandling, writeProgress, writeSuccess } from '../utils/cli.js';
10
+ import { compileCommand } from './compile.js';
11
+ import { pushSkillsToSandbox } from '../utils/dev-api.js';
12
+ import { getAllSandboxSkillIds } from '../utils/sandbox-storage.js';
13
+ import ChatApi from '../api/chat.api.service.js';
14
+ import { BASE_URLS } from '../config/constants.js';
15
+ import { readDeployJson, validateConfig, validateDeployData, validateAgentConfig, } from '../utils/dev-helpers.js';
16
+ /**
17
+ * Main chat command - starts interactive chat session
18
+ *
19
+ * Features:
20
+ * - Environment selection (sandbox or production)
21
+ * - Interactive chat loop
22
+ * - Skill and persona overrides for sandbox
23
+ * - Real-time conversation
24
+ * - Exit with Ctrl+C
25
+ *
26
+ * @returns Promise that resolves when chat session ends
27
+ */
28
+ export async function chatCommand() {
29
+ return withErrorHandling(async () => {
30
+ // Step 1: Authenticate
31
+ const apiKey = await loadApiKey();
32
+ if (!apiKey) {
33
+ console.error("โŒ No API key found. Please run 'lua auth configure' to set up your API key.");
34
+ process.exit(1);
35
+ }
36
+ const userData = await checkApiKey(apiKey);
37
+ writeProgress("โœ… Authenticated");
38
+ // Step 2: Load configuration
39
+ const config = readSkillConfig();
40
+ validateConfig(config);
41
+ validateAgentConfig(config);
42
+ const agentId = config.agent.agentId;
43
+ // Step 3: Select environment
44
+ const { environment } = await inquirer.prompt([
45
+ {
46
+ type: 'list',
47
+ name: 'environment',
48
+ message: 'Select environment:',
49
+ choices: [
50
+ { name: '๐Ÿ”ง Sandbox (with skill overrides)', value: 'sandbox' },
51
+ { name: '๐Ÿš€ Production', value: 'production' }
52
+ ]
53
+ }
54
+ ]);
55
+ let chatEnv = {
56
+ type: environment,
57
+ agentId,
58
+ apiKey,
59
+ };
60
+ // Step 4: Setup sandbox if selected
61
+ if (environment === 'sandbox') {
62
+ await setupSandboxEnvironment(chatEnv, config);
63
+ }
64
+ // Step 5: Start interactive chat
65
+ await startChatLoop(chatEnv);
66
+ }, "chat");
67
+ }
68
+ /**
69
+ * Sets up the sandbox environment by compiling and pushing skills
70
+ */
71
+ async function setupSandboxEnvironment(chatEnv, config) {
72
+ writeProgress("๐Ÿ”„ Setting up sandbox environment...");
73
+ // Compile the skill
74
+ writeProgress("๐Ÿ”„ Compiling skill...");
75
+ await compileCommand();
76
+ // Read deploy data
77
+ const deployData = readDeployJson();
78
+ validateDeployData(deployData);
79
+ // Push skills to sandbox
80
+ writeProgress("๐Ÿ”„ Pushing skills to sandbox...");
81
+ const sandboxIds = await pushSkillsToSandbox(chatEnv.apiKey, chatEnv.agentId, deployData, true);
82
+ if (Object.keys(sandboxIds).length === 0) {
83
+ console.error("โŒ Failed to push any skills to sandbox. Cannot start chat.");
84
+ process.exit(1);
85
+ }
86
+ writeSuccess(`โœ… Pushed ${Object.keys(sandboxIds).length} skills to sandbox`);
87
+ // Store deploy data for skill overrides
88
+ chatEnv.deployData = deployData;
89
+ // Check for persona in config
90
+ if (config.agent?.persona) {
91
+ chatEnv.persona = config.agent.persona;
92
+ }
93
+ }
94
+ /**
95
+ * Starts the interactive chat loop
96
+ */
97
+ async function startChatLoop(chatEnv) {
98
+ console.log("\n" + "=".repeat(60));
99
+ console.log("๐ŸŒ™ Lua Chat Interface");
100
+ console.log(`Environment: ${chatEnv.type === 'sandbox' ? '๐Ÿ”ง Sandbox' : '๐Ÿš€ Production'}`);
101
+ console.log("Press Ctrl+C to exit");
102
+ console.log("=".repeat(60) + "\n");
103
+ // Welcome message
104
+ console.log("๐ŸŒ™ Assistant: Hi there! How can I help you today?\n");
105
+ // Create readline interface
106
+ const rl = readline.createInterface({
107
+ input: process.stdin,
108
+ output: process.stdout,
109
+ prompt: '๐Ÿ’ฌ You: '
110
+ });
111
+ // Handle Ctrl+C gracefully
112
+ rl.on('SIGINT', () => {
113
+ console.log("\n\n๐Ÿ‘‹ Goodbye!");
114
+ rl.close();
115
+ process.exit(0);
116
+ });
117
+ // Show prompt
118
+ rl.prompt();
119
+ // Handle user input
120
+ rl.on('line', async (input) => {
121
+ const message = input.trim();
122
+ if (!message) {
123
+ rl.prompt();
124
+ return;
125
+ }
126
+ try {
127
+ // Show typing indicator with animated dots
128
+ const typingInterval = startTypingIndicator();
129
+ let response = null;
130
+ if (chatEnv.type === 'sandbox') {
131
+ // Send to sandbox with skill overrides
132
+ response = await sendSandboxMessage(chatEnv, message);
133
+ }
134
+ else {
135
+ // Send to production
136
+ response = await sendProductionMessage(chatEnv, message);
137
+ }
138
+ // Stop typing indicator
139
+ stopTypingIndicator(typingInterval);
140
+ if (response) {
141
+ console.log(`๐ŸŒ™ Assistant: ${response}\n`);
142
+ }
143
+ else {
144
+ console.log("๐ŸŒ™ Assistant: โŒ Failed to get response. Please try again.\n");
145
+ }
146
+ }
147
+ catch (error) {
148
+ console.error(`\nโŒ Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`);
149
+ }
150
+ rl.prompt();
151
+ });
152
+ rl.on('close', () => {
153
+ console.log("\n๐Ÿ‘‹ Goodbye!");
154
+ process.exit(0);
155
+ });
156
+ }
157
+ /**
158
+ * Starts a typing indicator animation with dots
159
+ * @returns The interval ID to stop the animation later
160
+ */
161
+ function startTypingIndicator() {
162
+ const frames = [' ', '. ', '.. ', '...'];
163
+ let frameIndex = 0;
164
+ // Initial frame
165
+ process.stdout.write(`\r๐ŸŒ™ Assistant: ${frames[frameIndex]}`);
166
+ const interval = setInterval(() => {
167
+ frameIndex = (frameIndex + 1) % frames.length;
168
+ process.stdout.write(`\r๐ŸŒ™ Assistant: ${frames[frameIndex]}`);
169
+ }, 500);
170
+ return interval;
171
+ }
172
+ /**
173
+ * Stops the typing indicator animation and clears the line
174
+ * @param interval The interval ID from startTypingIndicator
175
+ */
176
+ function stopTypingIndicator(interval) {
177
+ clearInterval(interval);
178
+ // Clear the typing indicator line
179
+ process.stdout.write('\r\x1b[K');
180
+ }
181
+ /**
182
+ * Sends a message to the sandbox environment with skill overrides
183
+ */
184
+ async function sendSandboxMessage(chatEnv, message) {
185
+ if (!chatEnv.deployData) {
186
+ return "โŒ Sandbox environment not properly initialized.";
187
+ }
188
+ // Get all sandbox skill IDs for skill override
189
+ const allSkillOverrides = await getAllSandboxSkillIds(chatEnv.deployData);
190
+ if (allSkillOverrides.length === 0) {
191
+ return "โŒ No sandbox skills found. Please try running the command again.";
192
+ }
193
+ const chatRequest = {
194
+ messages: [
195
+ {
196
+ type: "text",
197
+ text: message
198
+ }
199
+ ],
200
+ navigate: true,
201
+ skillOverride: allSkillOverrides
202
+ };
203
+ // Add persona override if available
204
+ if (chatEnv.persona) {
205
+ chatRequest.personaOverride = chatEnv.persona;
206
+ }
207
+ const chatApi = new ChatApi(BASE_URLS.CHAT, chatEnv.apiKey);
208
+ const response = await chatApi.sendMessage(chatEnv.agentId, chatRequest);
209
+ if (!response.success) {
210
+ console.error(`โŒ Chat API error: ${response.error?.message || 'Unknown error'}`);
211
+ return null;
212
+ }
213
+ return response.data?.text || null;
214
+ }
215
+ /**
216
+ * Sends a message to the production environment
217
+ */
218
+ async function sendProductionMessage(chatEnv, message) {
219
+ const chatRequest = {
220
+ messages: [
221
+ {
222
+ type: "text",
223
+ text: message
224
+ }
225
+ ],
226
+ navigate: true,
227
+ skillOverride: []
228
+ };
229
+ const chatApi = new ChatApi(BASE_URLS.CHAT, chatEnv.apiKey);
230
+ const response = await chatApi.sendMessage(chatEnv.agentId, chatRequest);
231
+ if (!response.success) {
232
+ console.error(`โŒ Chat API error: ${response.error?.message || 'Unknown error'}`);
233
+ return null;
234
+ }
235
+ return response.data?.text || null;
236
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Chat Clear Command
3
+ * Clears conversation history for the agent
4
+ */
5
+ /**
6
+ * Chat clear command - clears conversation history
7
+ *
8
+ * Features:
9
+ * - Warning message about data loss
10
+ * - Confirmation prompt
11
+ * - Calls DELETE endpoint to clear history
12
+ *
13
+ * @returns Promise that resolves when history is cleared
14
+ */
15
+ export declare function chatClearCommand(): Promise<void>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Chat Clear Command
3
+ * Clears conversation history for the agent
4
+ */
5
+ import { loadApiKey, checkApiKey } from '../services/auth.js';
6
+ import { readSkillConfig } from '../utils/files.js';
7
+ import { withErrorHandling, writeProgress, writeSuccess } from '../utils/cli.js';
8
+ import { BASE_URLS } from '../config/constants.js';
9
+ import { safePrompt } from '../utils/prompt-handler.js';
10
+ import { validateConfig, validateAgentConfig, } from '../utils/dev-helpers.js';
11
+ /**
12
+ * Chat clear command - clears conversation history
13
+ *
14
+ * Features:
15
+ * - Warning message about data loss
16
+ * - Confirmation prompt
17
+ * - Calls DELETE endpoint to clear history
18
+ *
19
+ * @returns Promise that resolves when history is cleared
20
+ */
21
+ export async function chatClearCommand() {
22
+ return withErrorHandling(async () => {
23
+ // Step 1: Load configuration
24
+ const config = readSkillConfig();
25
+ validateConfig(config);
26
+ validateAgentConfig(config);
27
+ const agentId = config.agent.agentId;
28
+ // Step 2: Authenticate
29
+ const apiKey = await loadApiKey();
30
+ if (!apiKey) {
31
+ console.error("โŒ No API key found. Please run 'lua auth configure' to set up your API key.");
32
+ process.exit(1);
33
+ }
34
+ await checkApiKey(apiKey);
35
+ writeProgress("โœ… Authenticated");
36
+ // Step 3: Show warning and confirm
37
+ console.log("\nโš ๏ธ WARNING: This will clear ALL conversation history!");
38
+ console.log("โš ๏ธ This action cannot be undone.\n");
39
+ const confirmAnswer = await safePrompt([
40
+ {
41
+ type: 'confirm',
42
+ name: 'confirm',
43
+ message: 'Are you sure you want to clear the conversation history?',
44
+ default: false
45
+ }
46
+ ]);
47
+ if (!confirmAnswer || !confirmAnswer.confirm) {
48
+ console.log("\nโŒ Operation cancelled. History not cleared.\n");
49
+ return;
50
+ }
51
+ // Step 4: Clear history via API
52
+ writeProgress("๐Ÿ”„ Clearing conversation history...");
53
+ try {
54
+ const response = await fetch(`${BASE_URLS.API}/chat/history/${agentId}`, {
55
+ method: 'DELETE',
56
+ headers: {
57
+ 'accept': '*/*',
58
+ 'Authorization': `Bearer ${apiKey}`
59
+ }
60
+ });
61
+ if (!response.ok) {
62
+ const errorText = await response.text();
63
+ throw new Error(`HTTP error! status: ${response.status} - ${errorText}`);
64
+ }
65
+ writeSuccess("โœ… Conversation history cleared successfully");
66
+ console.log("๐Ÿ’ก The chat history has been completely removed.\n");
67
+ }
68
+ catch (error) {
69
+ console.error('โŒ Error clearing conversation history:', error);
70
+ if (error instanceof Error) {
71
+ console.error(` ${error.message}\n`);
72
+ }
73
+ }
74
+ }, "chat clear");
75
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Environment Variables Command
3
+ * Manages environment variables for sandbox and production environments
4
+ */
5
+ /**
6
+ * Main env command - manages environment variables
7
+ *
8
+ * Features:
9
+ * - Environment selection (sandbox or production)
10
+ * - List all environment variables
11
+ * - Add new variables
12
+ * - Update existing variables
13
+ * - Delete variables
14
+ * - Sandbox: manages .env file
15
+ * - Production: uses API endpoints
16
+ *
17
+ * @returns Promise that resolves when command completes
18
+ */
19
+ export declare function envCommand(): Promise<void>;