mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
refactoring the api endpoints to be separate files to reduce context usage
This commit is contained in:
21
apps/server/src/routes/running-agents/common.ts
Normal file
21
apps/server/src/routes/running-agents/common.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Common utilities for running-agents routes
|
||||
*/
|
||||
|
||||
import { createLogger } from "../../lib/logger.js";
|
||||
|
||||
const logger = createLogger("RunningAgents");
|
||||
|
||||
/**
|
||||
* Get error message from error object
|
||||
*/
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : "Unknown error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error details consistently
|
||||
*/
|
||||
export function logError(error: unknown, context: string): void {
|
||||
logger.error(`❌ ${context}:`, error);
|
||||
}
|
||||
17
apps/server/src/routes/running-agents/index.ts
Normal file
17
apps/server/src/routes/running-agents/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Running Agents routes - HTTP API for tracking active agent executions
|
||||
*/
|
||||
|
||||
import { Router } from "express";
|
||||
import type { AutoModeService } from "../../services/auto-mode-service.js";
|
||||
import { createIndexHandler } from "./routes/index.js";
|
||||
|
||||
export function createRunningAgentsRoutes(
|
||||
autoModeService: AutoModeService
|
||||
): Router {
|
||||
const router = Router();
|
||||
|
||||
router.get("/", createIndexHandler(autoModeService));
|
||||
|
||||
return router;
|
||||
}
|
||||
26
apps/server/src/routes/running-agents/routes/index.ts
Normal file
26
apps/server/src/routes/running-agents/routes/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* GET / endpoint - Get all running agents
|
||||
*/
|
||||
|
||||
import type { Request, Response } from "express";
|
||||
import type { AutoModeService } from "../../../services/auto-mode-service.js";
|
||||
import { getErrorMessage, logError } from "../common.js";
|
||||
|
||||
export function createIndexHandler(autoModeService: AutoModeService) {
|
||||
return async (_req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const runningAgents = autoModeService.getRunningAgents();
|
||||
const status = autoModeService.getStatus();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
runningAgents,
|
||||
totalCount: runningAgents.length,
|
||||
autoLoopRunning: status.autoLoopRunning,
|
||||
});
|
||||
} catch (error) {
|
||||
logError(error, "Get running agents failed");
|
||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user