agent-ecosystem/src/main/http/projects.ts
matt 7fa2f96ed4 feat(http): implement HTTP server and route handlers for configuration, notifications, projects, sessions, and SSH management
- Introduced an HTTP server to facilitate communication with the application.
- Added route handlers for managing application configuration, including getting and updating settings.
- Implemented notification operations with routes for retrieving, marking, and deleting notifications.
- Created project and session management routes to list projects, sessions, and their details.
- Developed SSH connection management routes for connecting, disconnecting, and retrieving SSH state and configuration.
- Enhanced the application architecture to support real-time event streaming via Server-Sent Events (SSE).

This commit significantly expands the application's capabilities by integrating an HTTP server and various management routes, improving user interaction and functionality.
2026-02-12 15:04:56 +09:00

55 lines
1.7 KiB
TypeScript

/**
* HTTP route handlers for Project Operations.
*
* Routes:
* - GET /api/projects - List all projects
* - GET /api/repository-groups - List projects grouped by git repository
* - GET /api/worktrees/:id/sessions - List sessions for a worktree
*/
import { createLogger } from '@shared/utils/logger';
import { validateProjectId } from '../ipc/guards';
import type { HttpServices } from './index';
import type { FastifyInstance } from 'fastify';
const logger = createLogger('HTTP:projects');
export function registerProjectRoutes(app: FastifyInstance, services: HttpServices): void {
app.get('/api/projects', async () => {
try {
const projects = await services.projectScanner.scan();
return projects;
} catch (error) {
logger.error('Error in GET /api/projects:', error);
return [];
}
});
app.get('/api/repository-groups', async () => {
try {
const groups = await services.projectScanner.scanWithWorktreeGrouping();
return groups;
} catch (error) {
logger.error('Error in GET /api/repository-groups:', error);
return [];
}
});
app.get<{ Params: { id: string } }>('/api/worktrees/:id/sessions', async (request) => {
try {
const validated = validateProjectId(request.params.id);
if (!validated.valid) {
logger.error(`GET /api/worktrees/:id/sessions rejected: ${validated.error ?? 'unknown'}`);
return [];
}
const sessions = await services.projectScanner.listWorktreeSessions(validated.value!);
return sessions;
} catch (error) {
logger.error(`Error in GET /api/worktrees/${request.params.id}/sessions:`, error);
return [];
}
});
}