feat: Add GET /api/status endpoint with job stats and update PROJECT.md
This commit is contained in:
@@ -12,6 +12,8 @@ import { ToolContext } from './tools';
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
|
||||
const startTime = new Date();
|
||||
|
||||
// Raw body capture for webhook HMAC — must come before express.json()
|
||||
app.use('/webhook/gitea', express.raw({ type: '*/*' }));
|
||||
|
||||
@@ -87,6 +89,33 @@ app.get('/api/agents', (_req: Request, res: Response) => {
|
||||
res.json(agents);
|
||||
});
|
||||
|
||||
// Get server status and job statistics
|
||||
app.get('/api/status', (_req: Request, res: Response) => {
|
||||
const allJobs = listJobs(Infinity);
|
||||
const total_jobs = allJobs.length;
|
||||
|
||||
const by_status: { [key: string]: number } = {
|
||||
queued: 0,
|
||||
running: 0,
|
||||
completed: 0,
|
||||
failed: 0,
|
||||
};
|
||||
for (const job of allJobs) {
|
||||
by_status[job.status] = (by_status[job.status] || 0) + 1;
|
||||
}
|
||||
|
||||
const uptime_seconds = Math.floor((new Date().getTime() - startTime.getTime()) / 1000);
|
||||
|
||||
const agents = Object.values(AGENTS).map(a => a.name);
|
||||
|
||||
res.json({
|
||||
total_jobs,
|
||||
by_status,
|
||||
uptime_seconds,
|
||||
agents,
|
||||
});
|
||||
});
|
||||
|
||||
// Submit a new job
|
||||
app.post('/api/agent/run', async (req: Request, res: Response) => {
|
||||
const { agent: agentName, task, repo } = req.body as { agent?: string; task?: string; repo?: string };
|
||||
|
||||
Reference in New Issue
Block a user