decharge-scout 4.8.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"
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.8.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,