lua-cli 3.0.0-alpha.7 → 3.0.0-alpha.8

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.
@@ -13,9 +13,15 @@ import { UserData } from "../interfaces/admin.js";
13
13
  */
14
14
  export declare function saveApiKey(apiKey: string): Promise<void>;
15
15
  /**
16
- * Loads API key from secure system keychain.
16
+ * Loads API key from multiple sources in priority order:
17
+ * 1. Secure system keychain (macOS Keychain, Windows Credential Vault, Linux libsecret)
18
+ * 2. LUA_API_KEY environment variable
19
+ * 3. LUA_API_KEY from .env file
17
20
  *
18
- * @returns Promise resolving to API key or null if not found
21
+ * This fallback mechanism allows the CLI to work in CI/CD environments where
22
+ * keychain access isn't available.
23
+ *
24
+ * @returns Promise resolving to API key or null if not found in any source
19
25
  */
20
26
  export declare function loadApiKey(): Promise<string | null>;
21
27
  /**
@@ -22,12 +22,44 @@ export async function saveApiKey(apiKey) {
22
22
  await keytar.setPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT, apiKey);
23
23
  }
24
24
  /**
25
- * Loads API key from secure system keychain.
25
+ * Loads API key from multiple sources in priority order:
26
+ * 1. Secure system keychain (macOS Keychain, Windows Credential Vault, Linux libsecret)
27
+ * 2. LUA_API_KEY environment variable
28
+ * 3. LUA_API_KEY from .env file
26
29
  *
27
- * @returns Promise resolving to API key or null if not found
30
+ * This fallback mechanism allows the CLI to work in CI/CD environments where
31
+ * keychain access isn't available.
32
+ *
33
+ * @returns Promise resolving to API key or null if not found in any source
28
34
  */
29
35
  export async function loadApiKey() {
30
- return keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
36
+ // Priority 1: Check secure system keychain
37
+ const keychainKey = await keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
38
+ if (keychainKey) {
39
+ return keychainKey;
40
+ }
41
+ // Priority 2: Check environment variable
42
+ if (process.env.LUA_API_KEY) {
43
+ return process.env.LUA_API_KEY;
44
+ }
45
+ // Priority 3: Check .env file
46
+ try {
47
+ const fs = await import('fs');
48
+ const path = await import('path');
49
+ const envPath = path.join(process.cwd(), '.env');
50
+ if (fs.existsSync(envPath)) {
51
+ const envContent = fs.readFileSync(envPath, 'utf8');
52
+ const match = envContent.match(/^LUA_API_KEY=(.+)$/m);
53
+ if (match && match[1]) {
54
+ // Remove quotes if present
55
+ return match[1].trim().replace(/^["']|["']$/g, '');
56
+ }
57
+ }
58
+ }
59
+ catch (error) {
60
+ // Silently fail if .env file can't be read
61
+ }
62
+ return null;
31
63
  }
32
64
  /**
33
65
  * Deletes API key from secure system keychain.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lua-cli",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "Command-line interface for Lua AI platform - develop, test, and deploy LuaSkills with custom tools",
5
5
  "readmeFilename": "README.md",
6
6
  "main": "dist/api-exports.js",
@@ -1,6 +1,11 @@
1
1
  # Example environment variables file
2
2
  # Copy this to .env and update with your actual API keys
3
3
 
4
+ # Lua API Key (optional - fallback if not in keychain)
5
+ # Use this for CI/CD environments or if you prefer .env over keychain
6
+ # Priority: 1. Keychain, 2. Environment variable, 3. .env file
7
+ # LUA_API_KEY=your-lua-api-key-here
8
+
4
9
  # OpenAI API Key (for AI tools)
5
10
  OPENAI_API_KEY=your-openai-api-key-here
6
11