import type { HostApiContext } from '../context'; import type { NormalizedHostApiRequest } from '../route-utils'; import { fail, ok } from '../route-utils'; export async function handleGatewayRoutes( request: NormalizedHostApiRequest, ctx: HostApiContext, ) { const { pathname, method } = request; if (pathname === '/api/app/gateway-info' && method === 'GET') { const status = ctx.gatewayManager.getStatus(); return ok({ transport: 'ipc-bridge', rpcChannel: 'gateway:rpc', eventChannel: 'gateway:event', ...status, }); } if (pathname === '/api/gateway/status' && method === 'GET') { return ok(ctx.gatewayManager.getStatus()); } if (pathname === '/api/gateway/health' && method === 'GET') { return ok(await ctx.gatewayManager.checkHealth()); } if (pathname === '/api/gateway/start' && method === 'POST') { await ctx.gatewayManager.start(); return ok({ success: true }); } if (pathname === '/api/gateway/stop' && method === 'POST') { await ctx.gatewayManager.stop(); return ok({ success: true }); } if (pathname === '/api/gateway/restart' && method === 'POST') { try { await ctx.gatewayManager.restart(); return ok({ success: true }); } catch (error) { return fail(500, error instanceof Error ? error.message : String(error)); } } return null; }