shivam-cli-generator 1.1.0 → 1.1.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/ai.js +11 -91
- package/package.json +1 -1
package/ai.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Version 1.0.5
|
|
1
2
|
import dotenv from 'dotenv';
|
|
2
3
|
import { fileURLToPath } from 'url';
|
|
3
4
|
import { dirname, join } from 'path';
|
|
@@ -6,99 +7,22 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
6
7
|
const __dirname = dirname(__filename);
|
|
7
8
|
|
|
8
9
|
// Load .env from the package directory, not the current working directory
|
|
9
|
-
|
|
10
|
-
const result = dotenv.config({ path: envPath, override: true });
|
|
11
|
-
|
|
12
|
-
if (result.error) {
|
|
13
|
-
console.error("⚠️ Error loading .env from:", envPath, result.error);
|
|
14
|
-
} else {
|
|
15
|
-
// console.log("✅ Loaded .env from:", envPath);
|
|
16
|
-
// console.log("✅ Loaded .env from:", envPath);
|
|
17
|
-
}
|
|
10
|
+
dotenv.config({ path: join(__dirname, '.env') });
|
|
18
11
|
import Groq from "groq-sdk";
|
|
19
|
-
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
20
12
|
import fs from "fs";
|
|
21
13
|
import readline from "readline-sync";
|
|
22
|
-
const apiKey = process.env.GROQ_API_KEY
|
|
23
|
-
|
|
24
|
-
// if (!apiKey) {
|
|
25
|
-
// console.error("❌ GROQ_API_KEY is missing.\n👉 Please check your .env file or system environment variables.\n");
|
|
26
|
-
// process.exit(1);
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// ✅ Proxy Configuration
|
|
30
|
-
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
31
|
-
let httpAgent = undefined;
|
|
32
|
-
|
|
33
|
-
if (proxyUrl) {
|
|
34
|
-
console.log(`Using Proxy: ${proxyUrl}`);
|
|
35
|
-
httpAgent = new HttpsProxyAgent(proxyUrl);
|
|
36
|
-
}
|
|
14
|
+
const apiKey = process.env.GROQ_API_KEY;
|
|
37
15
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// ✅ Config File Logic
|
|
42
|
-
const CONFIG_DIR = join(homedir(), '.shivam-ai');
|
|
43
|
-
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
44
|
-
|
|
45
|
-
function loadConfig() {
|
|
46
|
-
try {
|
|
47
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
48
|
-
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
|
|
49
|
-
}
|
|
50
|
-
} catch (e) { }
|
|
51
|
-
return {};
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
console.error("❌ GROQ_API_KEY is missing.\n👉 Please check your .env file or system environment variables.\n");
|
|
18
|
+
process.exit(1);
|
|
52
19
|
}
|
|
53
20
|
|
|
54
|
-
function saveConfig(config) {
|
|
55
|
-
try {
|
|
56
|
-
if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR);
|
|
57
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
58
|
-
console.log("✅ Configuration saved.");
|
|
59
|
-
} catch (e) {
|
|
60
|
-
console.error("❌ Failed to save config:", e.message);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const args = process.argv.slice(2);
|
|
65
|
-
|
|
66
|
-
// Handle Configuration Commands
|
|
67
|
-
if (args[0] === '--set-relay') {
|
|
68
|
-
const url = args[1];
|
|
69
|
-
if (!url) {
|
|
70
|
-
console.error("❌ Error: Please provide a URL. Example: shivam-ai --set-relay https://my-proxy.vercel.app");
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
const config = loadConfig();
|
|
74
|
-
config.relayUrl = url;
|
|
75
|
-
saveConfig(config);
|
|
76
|
-
console.log(`\n🔗 Relay URL set to: ${url}`);
|
|
77
|
-
console.log("You can now generally use the tool without setting environment variables.");
|
|
78
|
-
process.exit(0);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (args[0] === '--remove-relay') {
|
|
82
|
-
const config = loadConfig();
|
|
83
|
-
delete config.relayUrl;
|
|
84
|
-
saveConfig(config);
|
|
85
|
-
console.log("\n🗑️ Relay URL removed. Using direct connection.");
|
|
86
|
-
process.exit(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Load Config
|
|
90
|
-
const config = loadConfig();
|
|
91
|
-
const savedRelayUrl = config.relayUrl;
|
|
92
|
-
|
|
93
21
|
// ✅ Correct Groq client initialization
|
|
94
|
-
const client = new Groq({
|
|
95
|
-
apiKey: apiKey.trim(),
|
|
96
|
-
httpAgent: httpAgent,
|
|
97
|
-
baseURL: process.env.GROQ_BASE_URL || savedRelayUrl // Prioritize env var, then config, then default
|
|
98
|
-
});
|
|
22
|
+
const client = new Groq({ apiKey });
|
|
99
23
|
|
|
100
24
|
// ✅ Use the inputURL if provided
|
|
101
|
-
const inputURL =
|
|
25
|
+
const inputURL = process.argv[2];
|
|
102
26
|
|
|
103
27
|
if (inputURL) {
|
|
104
28
|
console.log("\n🔗 Context URL:", inputURL);
|
|
@@ -150,13 +74,9 @@ async function main() {
|
|
|
150
74
|
}
|
|
151
75
|
|
|
152
76
|
} catch (error) {
|
|
153
|
-
|
|
154
|
-
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND'
|
|
155
|
-
console.error("
|
|
156
|
-
console.error("👉 CAUSE: Your network (Office WiFi/Firewall) is likely blocking access to AI services.");
|
|
157
|
-
console.error("💡 SOLUTION: Please use a **VPN** (as you found works) or a personal hotspot.");
|
|
158
|
-
} else {
|
|
159
|
-
console.error("\n❌ Error communicating with AI:", error.message);
|
|
77
|
+
console.error("\n❌ Error communicating with AI:", error.message);
|
|
78
|
+
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND') {
|
|
79
|
+
console.error("👉 Check your internet connection.\n");
|
|
160
80
|
}
|
|
161
81
|
}
|
|
162
82
|
}
|