decharge-scout 4.7.0 β 4.8.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/debug-fleet-api.js +109 -0
- package/package.json +1 -1
- package/src/fleet.js +2 -0
|
@@ -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/package.json
CHANGED
package/src/fleet.js
CHANGED
|
@@ -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}`));
|