Skip to content

Commit 7df2746

Browse files
author
Ope Olatunji
committed
fix: add GET /archive/:tab endpoint, fix archive loading spinner
- Added GET /polymarket/:agentId/archive/:tab endpoint (trades, exits, alerts, events) - Returns archived rows from *_archive tables with count - Gracefully returns empty result if archive table doesn't exist yet - Dashboard archive toggle now handles errors instead of spinning forever - Fixed archive API call using selectedAgent instead of agentId variable
1 parent c7f1bef commit 7df2746

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agenticmail/enterprise",
3-
"version": "0.5.530",
3+
"version": "0.5.531",
44
"description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
55
"type": "module",
66
"bin": {

src/admin/routes.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,6 +4286,33 @@ export function createAdminRoutes(db: DatabaseAdapter) {
42864286

42874287
// ── Archive System ──────────────────────────────────────────
42884288

4289+
// Get archived data for a specific tab
4290+
api.get('/polymarket/:agentId/archive/:tab', requireRole('admin'), async (c) => {
4291+
try {
4292+
const agentId = c.req.param('agentId');
4293+
const tab = c.req.param('tab');
4294+
const e = edb();
4295+
const limit = parseInt(c.req.query('limit') || '100');
4296+
4297+
let tableName = '';
4298+
if (tab === 'trades') tableName = 'poly_trade_log_archive';
4299+
else if (tab === 'exits') tableName = 'poly_exit_rules_archive';
4300+
else if (tab === 'alerts') tableName = 'poly_price_alerts_archive';
4301+
else if (tab === 'events') tableName = 'poly_watcher_events_archive';
4302+
else return c.json({ rows: [], total: 0, message: 'Unknown archive tab: ' + tab });
4303+
4304+
// Check if archive table exists
4305+
try {
4306+
const rows = await e?.all(`SELECT * FROM ${tableName} WHERE agent_id = ? ORDER BY created_at DESC LIMIT ?`, [agentId, limit]) || [];
4307+
const countRow = await e?.get(`SELECT COUNT(*) as cnt FROM ${tableName} WHERE agent_id = ?`, [agentId]) as any;
4308+
return c.json({ rows, total: countRow?.cnt || rows.length });
4309+
} catch {
4310+
// Archive table doesn't exist yet — no archived data
4311+
return c.json({ rows: [], total: 0, message: 'No archived data yet. Use the Archive action to move old data here.' });
4312+
}
4313+
} catch (e: any) { return c.json({ rows: [], total: 0, error: e.message }); }
4314+
});
4315+
42894316
// Create archive tables on first use (lazy init in the archive endpoint below)
42904317

42914318
// Archive completed/closed data for a specific tab

src/dashboard/pages/polymarket.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,9 +1624,11 @@ export function PolymarketPage() {
16241624
setShowArchive(next);
16251625
if (!next[tabKey]) return;
16261626
setArchiveLoading(true);
1627-
apiCall('/polymarket/' + agentId + '/archive/' + tabKey).then(function(r) {
1627+
apiCall('/polymarket/' + selectedAgent + '/archive/' + tabKey).then(function(r) {
16281628
var next2 = Object.assign({}, showArchive); next2[tabKey] = true; next2[tabKey + '_data'] = r; setShowArchive(next2); setArchiveLoading(false);
1629-
}).catch(function() { setArchiveLoading(false); });
1629+
}).catch(function(e) {
1630+
var next2 = Object.assign({}, showArchive); next2[tabKey] = true; next2[tabKey + '_data'] = { rows: [], total: 0, message: e.message || 'Failed to load archive' }; setShowArchive(next2); setArchiveLoading(false);
1631+
});
16301632
}
16311633
}, I('database'), isOpen ? ' Active' : ' Archive (' + (label || '') + ')');
16321634
};

0 commit comments

Comments
 (0)