shivam-cli-generator 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/ai.js +21 -90
  2. package/package.json +2 -2
package/ai.js CHANGED
@@ -1,104 +1,41 @@
1
+ // Version 1.1.2
1
2
  import dotenv from 'dotenv';
2
3
  import { fileURLToPath } from 'url';
3
4
  import { dirname, join } from 'path';
4
5
 
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
-
8
- // Load .env from the package directory, not the current working directory
9
- const envPath = join(__dirname, '.env');
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
- }
18
6
  import Groq from "groq-sdk";
19
- import { HttpsProxyAgent } from "https-proxy-agent";
20
7
  import fs from "fs";
21
8
  import readline from "readline-sync";
22
- const apiKey = process.env.GROQ_API_KEY || "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";
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
- // }
9
+ import { HttpsProxyAgent } from "https-proxy-agent"; // ⭐ Fixed import
28
10
 
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
- }
37
-
38
- import { homedir } from 'os';
39
- import { join } from 'path';
40
-
41
- // ✅ Config File Logic
42
- const CONFIG_DIR = join(homedir(), '.shivam-ai');
43
- const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
44
13
 
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 {};
52
- }
14
+ // Load .env from the package directory
15
+ dotenv.config({ path: join(__dirname, '.env') });
53
16
 
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
- }
17
+ // 🌐 FIREWALL BYPASS PROXY URL (change if blocked)
18
+ const proxyUrl = "http://global.freeproxy.ai:80";
63
19
 
64
- const args = process.argv.slice(2);
20
+ // Create proxy agent
21
+ const proxyAgent = new HttpsProxyAgent(proxyUrl);
65
22
 
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
- }
23
+ const apiKey = process.env.GROQ_API_KEY;
80
24
 
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);
25
+ if (!apiKey) {
26
+ console.error("❌ GROQ_API_KEY is missing.\n👉 Please check your .env file or system environment variables.\n");
27
+ process.exit(1);
87
28
  }
88
29
 
89
- // Load Config
90
- const config = loadConfig();
91
- const savedRelayUrl = config.relayUrl;
92
-
93
- // ✅ Correct Groq client initialization
30
+ // Updated Groq client initialization WITH PROXY
94
31
  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
32
+ apiKey,
33
+ httpAgent: proxyAgent,
34
+ httpsAgent: proxyAgent
98
35
  });
99
36
 
100
37
  // ✅ Use the inputURL if provided
101
- const inputURL = (!args[0]?.startsWith('--')) ? args[0] : undefined;
38
+ const inputURL = process.argv[2];
102
39
 
103
40
  if (inputURL) {
104
41
  console.log("\n🔗 Context URL:", inputURL);
@@ -150,14 +87,8 @@ async function main() {
150
87
  }
151
88
 
152
89
  } catch (error) {
153
- // console.error("\n❌ Error communicating with AI:", error.message);
154
- if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.message.includes('Connection error') || error.message.includes('fetch failed')) {
155
- console.error("\n❌ NETWORK ERROR: Unable to connect to Groq API.");
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);
160
- }
90
+ console.error("\n❌ Error communicating with AI:", error.message);
91
+ console.error("👉 The firewall proxy may be blocked. Try changing proxy URL at the top.\n");
161
92
  }
162
93
  }
163
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shivam-cli-generator",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "ai.js",
6
6
  "type": "module",
@@ -19,4 +19,4 @@
19
19
  "https-proxy-agent": "^7.0.6",
20
20
  "readline-sync": "^1.4.10"
21
21
  }
22
- }
22
+ }