shivam-cli-generator 1.0.9 → 1.1.0
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 +57 -2
- package/package.json +1 -1
package/ai.js
CHANGED
|
@@ -35,15 +35,70 @@ if (proxyUrl) {
|
|
|
35
35
|
httpAgent = new HttpsProxyAgent(proxyUrl);
|
|
36
36
|
}
|
|
37
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');
|
|
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 {};
|
|
52
|
+
}
|
|
53
|
+
|
|
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
|
+
|
|
38
93
|
// ✅ Correct Groq client initialization
|
|
39
94
|
const client = new Groq({
|
|
40
95
|
apiKey: apiKey.trim(),
|
|
41
96
|
httpAgent: httpAgent,
|
|
42
|
-
baseURL: process.env.GROQ_BASE_URL //
|
|
97
|
+
baseURL: process.env.GROQ_BASE_URL || savedRelayUrl // Prioritize env var, then config, then default
|
|
43
98
|
});
|
|
44
99
|
|
|
45
100
|
// ✅ Use the inputURL if provided
|
|
46
|
-
const inputURL =
|
|
101
|
+
const inputURL = (!args[0]?.startsWith('--')) ? args[0] : undefined;
|
|
47
102
|
|
|
48
103
|
if (inputURL) {
|
|
49
104
|
console.log("\n🔗 Context URL:", inputURL);
|