@layer-ai/core 0.5.3 → 0.5.4
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/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/logs.js +31 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/routes/logs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAIpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/routes/logs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAIpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAsLpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/logs.js
CHANGED
|
@@ -117,4 +117,35 @@ router.get('/overview', async (req, res) => {
|
|
|
117
117
|
res.status(500).json({ error: 'internal_error', message: 'Failed to fetch analytics' });
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
+
// GET /v1/logs/gate/:gateId - Get metrics for a specific gate
|
|
121
|
+
router.get('/gate/:gateId', async (req, res) => {
|
|
122
|
+
try {
|
|
123
|
+
const userId = req.userId;
|
|
124
|
+
const { gateId } = req.params;
|
|
125
|
+
// Verify gate ownership
|
|
126
|
+
const gateCheck = await db.query('SELECT id FROM gates WHERE id = $1 AND user_id = $2', [gateId, userId]);
|
|
127
|
+
if (gateCheck.rows.length === 0) {
|
|
128
|
+
return res.status(404).json({ error: 'not_found', message: 'Gate not found' });
|
|
129
|
+
}
|
|
130
|
+
// Get gate metrics
|
|
131
|
+
const metricsResult = await db.query(`SELECT
|
|
132
|
+
COUNT(*) as requests,
|
|
133
|
+
COALESCE(SUM(cost_usd), 0) as cost,
|
|
134
|
+
COALESCE(AVG(latency_ms), 0) as latency,
|
|
135
|
+
MAX(created_at) as last_request
|
|
136
|
+
FROM requests
|
|
137
|
+
WHERE gate_id = $1`, [gateId]);
|
|
138
|
+
const metrics = metricsResult.rows[0];
|
|
139
|
+
res.json({
|
|
140
|
+
requests: parseInt(metrics.requests) || 0,
|
|
141
|
+
cost: parseFloat(metrics.cost) || 0,
|
|
142
|
+
latency: Math.round(parseFloat(metrics.latency)) || 0,
|
|
143
|
+
lastRequest: metrics.last_request,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('Gate metrics error:', error);
|
|
148
|
+
res.status(500).json({ error: 'internal_error', message: 'Failed to fetch gate metrics' });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
120
151
|
export default router;
|