decharge-scout 2.5.4 → 2.5.6
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/index.js +24 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -26,8 +26,8 @@ import path from 'path';
|
|
|
26
26
|
import { fileURLToPath } from 'url';
|
|
27
27
|
import { dirname } from 'path';
|
|
28
28
|
|
|
29
|
-
// Load environment variables
|
|
30
|
-
dotenv.config();
|
|
29
|
+
// Load environment variables from current working directory (not package dir)
|
|
30
|
+
dotenv.config({ path: path.join(process.cwd(), '.env') });
|
|
31
31
|
|
|
32
32
|
// Import modules
|
|
33
33
|
import { startWalletServer, openWalletConnection, waitForWalletConnection, getConnectedWallet } from './src/wallet-server.js';
|
|
@@ -71,16 +71,29 @@ function generateAgentName() {
|
|
|
71
71
|
* Auto-configure .env if needed
|
|
72
72
|
*/
|
|
73
73
|
async function ensureEnvironment() {
|
|
74
|
-
|
|
74
|
+
// Use current working directory for .env (so npx works correctly)
|
|
75
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
75
76
|
|
|
76
77
|
// Create .env from example if missing
|
|
77
78
|
if (!existsSync(envPath)) {
|
|
79
|
+
// Look for .env.example in package directory
|
|
78
80
|
const examplePath = path.join(__dirname, '.env.example');
|
|
79
81
|
if (existsSync(examplePath)) {
|
|
80
82
|
console.log(chalk.yellow('⚠️ .env file not found, creating from template...'));
|
|
81
83
|
const example = readFileSync(examplePath, 'utf-8');
|
|
82
84
|
writeFileSync(envPath, example);
|
|
83
|
-
console.log(chalk.green(
|
|
85
|
+
console.log(chalk.green(`✓ .env file created at ${envPath}`));
|
|
86
|
+
} else {
|
|
87
|
+
// Create a basic .env file if no example exists
|
|
88
|
+
const basicEnv = `# EIA API Key (Required - Get from https://www.eia.gov/opendata/register.php)
|
|
89
|
+
EIA_API_KEY=your_eia_api_key_here
|
|
90
|
+
|
|
91
|
+
# Solana Configuration
|
|
92
|
+
SOLANA_NETWORK=devnet
|
|
93
|
+
SOLANA_RPC_URL=https://api.devnet.solana.com
|
|
94
|
+
`;
|
|
95
|
+
writeFileSync(envPath, basicEnv);
|
|
96
|
+
console.log(chalk.green(`✓ .env file created at ${envPath}`));
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
|
|
@@ -172,13 +185,13 @@ async function main(options) {
|
|
|
172
185
|
// Ask user to confirm or override (with timeout)
|
|
173
186
|
console.log(chalk.blue('\nYou can use this location or enter a custom one.'));
|
|
174
187
|
console.log(chalk.gray('(Press Enter to use detected location, or type custom location)'));
|
|
175
|
-
console.log(chalk.gray('You have
|
|
188
|
+
console.log(chalk.gray('You have 60 seconds to respond...'));
|
|
176
189
|
|
|
177
190
|
try {
|
|
178
191
|
let timeoutId;
|
|
179
192
|
let hasResolved = false;
|
|
180
193
|
|
|
181
|
-
// Create a promise that auto-resolves after
|
|
194
|
+
// Create a promise that auto-resolves after 60 seconds
|
|
182
195
|
const timeoutPromise = new Promise((resolve) => {
|
|
183
196
|
timeoutId = setTimeout(() => {
|
|
184
197
|
if (!hasResolved) {
|
|
@@ -186,7 +199,7 @@ async function main(options) {
|
|
|
186
199
|
console.log(chalk.yellow('\n⏱️ Timeout - using detected location...'));
|
|
187
200
|
resolve('__TIMEOUT__');
|
|
188
201
|
}
|
|
189
|
-
},
|
|
202
|
+
}, 60000); // 60 seconds for npx readline delay
|
|
190
203
|
});
|
|
191
204
|
|
|
192
205
|
const questionPromise = question('Enter custom location (or press Enter): ').then(answer => {
|
|
@@ -347,7 +360,7 @@ async function runQueryCycle(wallet, agentName, location, options) {
|
|
|
347
360
|
headers: { 'Content-Type': 'application/json' },
|
|
348
361
|
body: JSON.stringify({
|
|
349
362
|
...submissionData,
|
|
350
|
-
wallet:
|
|
363
|
+
wallet: wallet, // wallet parameter from runQueryCycle
|
|
351
364
|
run_number: totalRuns
|
|
352
365
|
})
|
|
353
366
|
});
|
|
@@ -373,8 +386,8 @@ async function runQueryCycle(wallet, agentName, location, options) {
|
|
|
373
386
|
const bonusPoints = savings > 15 ? 2 : 0; // Bonus for good savings
|
|
374
387
|
const totalPointsEarned = basePoints + bonusPoints;
|
|
375
388
|
|
|
376
|
-
awardPoints(
|
|
377
|
-
const currentPoints = getPoints(
|
|
389
|
+
awardPoints(wallet, totalPointsEarned);
|
|
390
|
+
const currentPoints = getPoints(wallet);
|
|
378
391
|
|
|
379
392
|
console.log(chalk.magenta(`\n⭐ Earned ${totalPointsEarned} points! (${basePoints} base${bonusPoints > 0 ? ` + ${bonusPoints} bonus` : ''})`));
|
|
380
393
|
console.log(chalk.magenta(`⭐ Total Points: ${currentPoints}`));
|
|
@@ -383,7 +396,7 @@ async function runQueryCycle(wallet, agentName, location, options) {
|
|
|
383
396
|
if (options.premium && totalRuns % 3 === 0) {
|
|
384
397
|
console.log(chalk.yellow('\n🔒 Premium Feature Available!'));
|
|
385
398
|
try {
|
|
386
|
-
const premiumData = await purchasePremiumData(
|
|
399
|
+
const premiumData = await purchasePremiumData(wallet);
|
|
387
400
|
console.log(chalk.green(`Premium forecast data: ${JSON.stringify(premiumData)}`));
|
|
388
401
|
} catch (error) {
|
|
389
402
|
console.log(chalk.red(`Premium purchase failed: ${error.message}`));
|