decharge-scout 1.3.0 → 1.4.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/index.js CHANGED
@@ -373,8 +373,9 @@ async function runQueryCycle(wallet, agentName, location, options) {
373
373
  let energyData;
374
374
 
375
375
  try {
376
- energyData = await fetchEnergyData();
377
- dataSpinner.succeed(chalk.green(`Fetched ${energyData.length} data points from EIA (ERCOT)`));
376
+ energyData = await fetchEnergyData(location);
377
+ const gridRegion = energyData[0]?.source?.split('-')[1] || 'Unknown';
378
+ dataSpinner.succeed(chalk.green(`Fetched ${energyData.length} data points from ${energyData[0]?.source || 'EIA'}`));
378
379
  } catch (error) {
379
380
  dataSpinner.warn(chalk.yellow(`EIA API failed, trying Electricity Maps...`));
380
381
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decharge-scout",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "AI-powered energy grid data scout with Solana integration",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -13,15 +13,48 @@ const EIA_API_KEY = process.env.EIA_API_KEY;
13
13
  const EIA_BASE_URL = 'https://api.eia.gov/v2';
14
14
 
15
15
  /**
16
- * Fetch energy data from EIA API (ERCOT)
16
+ * Map location to EIA grid region codes
17
17
  */
18
- export async function fetchEnergyData() {
18
+ function getGridRegionForLocation(location) {
19
+ const locationLower = location.toLowerCase();
20
+
21
+ // Map states/regions to grid operators
22
+ if (locationLower.includes('texas') || locationLower.includes('tx') || locationLower.includes('dallas') || locationLower.includes('houston') || locationLower.includes('austin')) {
23
+ return 'ERCT'; // ERCOT (Texas)
24
+ } else if (locationLower.includes('california') || locationLower.includes('ca')) {
25
+ return 'CISO'; // California ISO
26
+ } else if (locationLower.includes('new york') || locationLower.includes('ny')) {
27
+ return 'NYIS'; // New York ISO
28
+ } else if (locationLower.includes('new england') || locationLower.includes('massachusetts') || locationLower.includes('ma')) {
29
+ return 'ISNE'; // ISO New England
30
+ } else if (locationLower.includes('pjm') || locationLower.includes('pennsylvania') || locationLower.includes('pa')) {
31
+ return 'PJM'; // PJM Interconnection
32
+ } else if (locationLower.includes('miso') || locationLower.includes('midwest')) {
33
+ return 'MISO'; // Midcontinent ISO
34
+ }
35
+
36
+ // Default to ERCOT if unknown
37
+ return 'ERCT';
38
+ }
39
+
40
+ /**
41
+ * Fetch energy data from EIA API
42
+ */
43
+ export async function fetchEnergyData(location = 'Texas, USA') {
19
44
  if (!EIA_API_KEY || EIA_API_KEY === 'your_eia_api_key_here' || EIA_API_KEY.length < 20) {
20
45
  console.warn('⚠️ EIA_API_KEY not configured or invalid');
21
46
  console.warn(' Get a free key: https://www.eia.gov/opendata/register.php');
22
47
  throw new Error('EIA_API_KEY not configured');
23
48
  }
24
49
 
50
+ // Debug logging (show first 6 and last 4 chars of API key)
51
+ const keyPreview = `${EIA_API_KEY.substring(0, 6)}...${EIA_API_KEY.substring(EIA_API_KEY.length - 4)}`;
52
+ console.log(`📡 Using EIA API key: ${keyPreview}`);
53
+
54
+ // Determine grid region from location
55
+ const gridRegion = getGridRegionForLocation(location);
56
+ console.log(`🗺️ Location: ${location} → Grid Region: ${gridRegion}`);
57
+
25
58
  try {
26
59
  // Calculate time range (last 24 hours to next 24 hours for forecast)
27
60
  const now = new Date();
@@ -29,12 +62,12 @@ export async function fetchEnergyData() {
29
62
  const startDate = yesterday.toISOString().split('T')[0] + 'T00';
30
63
  const endDate = now.toISOString().split('T')[0] + 'T23';
31
64
 
32
- // EIA API endpoint for ERCOT real-time data
65
+ // EIA API endpoint for regional real-time data
33
66
  const url = `${EIA_BASE_URL}/electricity/rto/region-data/data/?` +
34
67
  `api_key=${EIA_API_KEY}` +
35
68
  `&frequency=hourly` +
36
69
  `&data[0]=value` +
37
- `&facets[respondent][]=ERCT` +
70
+ `&facets[respondent][]=${gridRegion}` +
38
71
  `&facets[type][]=D` + // Demand
39
72
  `&start=${startDate}` +
40
73
  `&end=${endDate}` +
@@ -42,6 +75,8 @@ export async function fetchEnergyData() {
42
75
  `&sort[0][direction]=desc` +
43
76
  `&length=48`;
44
77
 
78
+ console.log(`🔗 EIA API URL: ${url.replace(EIA_API_KEY, keyPreview)}`);
79
+
45
80
  const response = await fetch(url, {
46
81
  headers: {
47
82
  'Accept': 'application/json'
@@ -74,7 +109,7 @@ export async function fetchEnergyData() {
74
109
  hour: new Date(item.period).getHours(),
75
110
  demand: demand,
76
111
  price: Math.max(0.03, Math.min(0.15, price)), // Clamp between 3-15 cents
77
- source: 'EIA-ERCOT'
112
+ source: `EIA-${gridRegion}`
78
113
  };
79
114
  });
80
115