const fs = require('fs');
let code = fs.readFileSync('src/server.ts', 'utf8');

code = code.replace(
`app.post('/agent/stop', (req: Request, res: Response) => {
    const { sessionId } = req.body as { sessionId?: string };
    if (!sessionId) { res.status(400).json({ error: 'sessionId required' });`,
`app.post('/agent/stop', (req: Request, res: Response) => {
    const { sessionId } = req.body as { sessionId?: string };
    if (!sessionId) { res.status(400).json({ error: 'sessionId required' }); return; }
    const session = activeSessions.get(sessionId);
    if (session) {
        session.stopped = true;
        res.json({ status: 'stopped' });
    } else {
        res.status(404).json({ error: 'session not found or not running' });
    }
});`
);

fs.writeFileSync('src/server.ts', code);
