decharge-scout 4.7.0 β†’ 4.10.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/.env.example CHANGED
@@ -20,7 +20,8 @@ SOLANA_RPC_URL=https://api.devnet.solana.com
20
20
  ORACLE_ESCROW_ADDRESS=YourDevWalletPublicKeyHere
21
21
 
22
22
  # Dashboard API (Optional - for testing dashboard integration)
23
- DASHBOARD_API_URL=http://localhost:3000/submit
23
+ DASHBOARD_API_URL=http://localhost:3000/api/submit
24
+ DASHBOARD_FLEET_API_URL=http://localhost:3000/agentone/api/fleet-submit
24
25
 
25
26
  # Stake Amount (in SOL)
26
27
  STAKE_AMOUNT=0.01
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Vercel API Endpoint - Fleet Data Submission
3
+ *
4
+ * POST /agentone/api/fleet-submit
5
+ * Receives fleet optimization data and stores it in Supabase
6
+ */
7
+
8
+ import { createClient } from '@supabase/supabase-js';
9
+
10
+ export const config = {
11
+ runtime: 'edge',
12
+ };
13
+
14
+ export default async function handler(req) {
15
+ // CORS headers
16
+ const headers = {
17
+ 'Access-Control-Allow-Origin': '*',
18
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
19
+ 'Access-Control-Allow-Headers': 'Content-Type',
20
+ 'Content-Type': 'application/json',
21
+ };
22
+
23
+ // Handle OPTIONS request for CORS
24
+ if (req.method === 'OPTIONS') {
25
+ return new Response(null, { status: 200, headers });
26
+ }
27
+
28
+ // Only allow POST
29
+ if (req.method !== 'POST') {
30
+ return new Response(
31
+ JSON.stringify({ error: 'Method not allowed' }),
32
+ { status: 405, headers }
33
+ );
34
+ }
35
+
36
+ try {
37
+ const data = await req.json();
38
+
39
+ // Validate required fields for fleet submissions
40
+ if (!data.type || data.type !== 'fleet') {
41
+ return new Response(
42
+ JSON.stringify({ error: 'Invalid submission type. Expected "fleet"' }),
43
+ { status: 400, headers }
44
+ );
45
+ }
46
+
47
+ if (!data.agent_name || !data.location || !data.timestamp || !data.fleet_size || !data.summary) {
48
+ return new Response(
49
+ JSON.stringify({ error: 'Missing required fields for fleet submission' }),
50
+ { status: 400, headers }
51
+ );
52
+ }
53
+
54
+ // Initialize Supabase client
55
+ const supabase = createClient(
56
+ process.env.SUPABASE_URL,
57
+ process.env.SUPABASE_ANON_KEY
58
+ );
59
+
60
+ // Insert fleet submission
61
+ const { error: fleetError } = await supabase
62
+ .from('fleet_submissions')
63
+ .insert({
64
+ agent_name: data.agent_name,
65
+ wallet: data.wallet,
66
+ location: data.location,
67
+ timestamp: new Date(data.timestamp).toISOString(),
68
+ fleet_size: data.fleet_size,
69
+ total_distance_km: data.summary.total_distance_km,
70
+ total_cost_usd: data.summary.total_cost_usd,
71
+ savings_percent: data.summary.savings_percent,
72
+ co2_saved_kg: data.summary.co2_saved_kg,
73
+ duration_hours: data.summary.duration_hours,
74
+ route_geojson: data.route,
75
+ stops: data.stops,
76
+ simulation_basis: data.simulation_basis || 'weather-based simulation',
77
+ });
78
+
79
+ if (fleetError) throw fleetError;
80
+
81
+ // Update agent heartbeat (upsert)
82
+ const { error: heartbeatError } = await supabase
83
+ .from('agent_heartbeat')
84
+ .upsert(
85
+ {
86
+ agent_name: data.agent_name,
87
+ location: data.location,
88
+ last_seen: new Date().toISOString(),
89
+ },
90
+ { onConflict: 'agent_name' }
91
+ );
92
+
93
+ if (heartbeatError) throw heartbeatError;
94
+
95
+ return new Response(
96
+ JSON.stringify({
97
+ success: true,
98
+ message: 'Fleet data submitted successfully',
99
+ }),
100
+ { status: 200, headers }
101
+ );
102
+ } catch (error) {
103
+ console.error('Fleet submission error:', error);
104
+ return new Response(
105
+ JSON.stringify({
106
+ error: 'Internal server error',
107
+ message: error.message,
108
+ }),
109
+ { status: 500, headers }
110
+ );
111
+ }
112
+ }
@@ -14,6 +14,10 @@
14
14
  "src": "/api/agentone/fleet-submit",
15
15
  "dest": "/api/agentone/fleet-submit.js"
16
16
  },
17
+ {
18
+ "src": "/agentone/api/fleet-submit",
19
+ "dest": "/agentone/api/fleet-submit.js"
20
+ },
17
21
  {
18
22
  "src": "/(.*)",
19
23
  "dest": "/public/index.html"
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Debug Fleet API Call
5
+ *
6
+ * This script simulates what fleet.js sends to help debug why data isn't saving
7
+ */
8
+
9
+ import fetch from 'node-fetch';
10
+ import chalk from 'chalk';
11
+
12
+ const API_URL = 'https://decharge-scout.vercel.app/api/agentone/fleet-submit';
13
+
14
+ // Simulate the exact payload fleet.js sends
15
+ const testPayload = {
16
+ type: 'fleet',
17
+ agent_name: 'DebugAgent-' + Date.now(),
18
+ wallet: 'TestWallet123',
19
+ location: 'New York β†’ Boston',
20
+ timestamp: Date.now(),
21
+ fleet_size: 10,
22
+ route: {
23
+ type: 'LineString',
24
+ coordinates: [
25
+ [-74.0060, 40.7128], // New York
26
+ [-71.0589, 42.3601] // Boston
27
+ ]
28
+ },
29
+ stops: [
30
+ {
31
+ lat: 41.5,
32
+ lon: -72.5,
33
+ time: '3AM-4AM',
34
+ price: 0.025,
35
+ savings: 80,
36
+ location: 'Hartford, CT',
37
+ segmentId: 1
38
+ }
39
+ ],
40
+ summary: {
41
+ total_distance_km: 350,
42
+ total_cost_usd: 150.00,
43
+ savings_percent: 78,
44
+ co2_saved_kg: 45,
45
+ duration_hours: 4
46
+ },
47
+ simulation_basis: 'Task1 simulation + OSRM routing'
48
+ };
49
+
50
+ console.log(chalk.cyan('\nπŸ” Fleet API Debug Tool\n'));
51
+ console.log(chalk.blue('Testing endpoint:', API_URL));
52
+ console.log(chalk.gray('\nPayload being sent:'));
53
+ console.log(chalk.gray(JSON.stringify(testPayload, null, 2)));
54
+ console.log(chalk.gray('\n' + '='.repeat(60) + '\n'));
55
+
56
+ async function testAPI() {
57
+ try {
58
+ console.log(chalk.yellow('⏳ Sending request...'));
59
+
60
+ const response = await fetch(API_URL, {
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/json'
64
+ },
65
+ body: JSON.stringify(testPayload)
66
+ });
67
+
68
+ console.log(chalk.blue(`\nπŸ“‘ Response Status: ${response.status} ${response.statusText}`));
69
+
70
+ const responseText = await response.text();
71
+ console.log(chalk.blue('πŸ“„ Response Body:'));
72
+
73
+ try {
74
+ const responseJson = JSON.parse(responseText);
75
+ console.log(chalk.white(JSON.stringify(responseJson, null, 2)));
76
+ } catch (e) {
77
+ console.log(chalk.white(responseText));
78
+ }
79
+
80
+ if (response.ok) {
81
+ console.log(chalk.green('\nβœ… SUCCESS! Data should be in Supabase now.'));
82
+ console.log(chalk.gray('Check the fleet_submissions table in Supabase.'));
83
+ } else {
84
+ console.log(chalk.red('\n❌ FAILED! API rejected the request.'));
85
+ console.log(chalk.yellow('\nCommon issues:'));
86
+ console.log(chalk.gray('- 404: API endpoint not deployed to Vercel'));
87
+ console.log(chalk.gray('- 400: Validation error (check response body above)'));
88
+ console.log(chalk.gray('- 500: Server error (table missing, env vars, etc.)'));
89
+ }
90
+
91
+ // Show headers for debugging
92
+ console.log(chalk.gray('\nπŸ“‹ Response Headers:'));
93
+ response.headers.forEach((value, key) => {
94
+ console.log(chalk.gray(` ${key}: ${value}`));
95
+ });
96
+
97
+ } catch (error) {
98
+ console.log(chalk.red('\n❌ Network Error!'));
99
+ console.log(chalk.red('Error:', error.message));
100
+ console.log(chalk.yellow('\nThis usually means:'));
101
+ console.log(chalk.gray('- No internet connection'));
102
+ console.log(chalk.gray('- DNS resolution failed'));
103
+ console.log(chalk.gray('- Vercel deployment not accessible'));
104
+ }
105
+ }
106
+
107
+ testAPI().then(() => {
108
+ console.log(chalk.gray('\n' + '='.repeat(60) + '\n'));
109
+ });
package/index.js CHANGED
@@ -511,7 +511,7 @@ async function runQueryCycle(wallet, agentName, location, options) {
511
511
  // Submit to DeCharge Scout dashboard
512
512
  try {
513
513
  const dashboardSpinner = ora('Submitting to DeCharge Scout dashboard...').start();
514
- const apiUrl = 'https://decharge-scout.vercel.app/api/submit';
514
+ const apiUrl = process.env.DASHBOARD_API_URL || 'https://decharge-scout.vercel.app/api/submit';
515
515
 
516
516
  console.log(chalk.blue(`\n🌐 Dashboard API URL: ${apiUrl}`));
517
517
  console.log(chalk.gray(`πŸ“€ Submitting data...`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decharge-scout",
3
- "version": "4.7.0",
3
+ "version": "4.10.0",
4
4
  "description": "Global Energy Scout - Weather-powered intelligent energy price forecasting with Solana integration",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/fleet.js CHANGED
@@ -386,7 +386,7 @@ export async function runFleetOptimization(options) {
386
386
  // Submit to dashboard API
387
387
  try {
388
388
  const dashboardSpinner = ora('Submitting to AgentOne dashboard...').start();
389
- const apiUrl = process.env.DASHBOARD_API_URL || 'https://decharge-scout.vercel.app/api/agentone/fleet-submit';
389
+ const apiUrl = process.env.DASHBOARD_FLEET_API_URL || 'https://decharge-scout.vercel.app/agentone/api/fleet-submit';
390
390
 
391
391
  const dashboardPayload = {
392
392
  ...submissionPayload,
@@ -404,7 +404,9 @@ export async function runFleetOptimization(options) {
404
404
  console.log(chalk.cyan('\nπŸ—ΊοΈ Your fleet optimization has been added as a new layer on the AgentOne global map!'));
405
405
  console.log(chalk.blue(' View at: https://decharge-scout.vercel.app/agentone\n'));
406
406
  } else {
407
+ const errorBody = await response.text();
407
408
  dashboardSpinner.warn(chalk.yellow(`⚠️ Dashboard API returned: ${response.status}`));
409
+ console.log(chalk.red(` Error details: ${errorBody}`));
408
410
  }
409
411
  } catch (error) {
410
412
  console.log(chalk.yellow(`⚠️ Dashboard submission failed: ${error.message}`));