flutty-cli-agent
Version:
Flutty CLI Agent - AI-powered development assistant with web chat interface, context memory, and full tool integration using DeepSeek API
64 lines (53 loc) • 1.57 kB
text/typescript
import { NextRequest, NextResponse } from 'next/server'
// Reference to the same running servers map
declare global {
var runningServers: Map<number, any> | undefined
}
global.runningServers = global.runningServers || new Map()
const runningServers = global.runningServers
export async function POST(request: NextRequest) {
try {
const { code, port } = await request.json()
if (!runningServers.has(port)) {
return NextResponse.json(
{ success: false, error: 'No server running on this port' },
{ status: 400 }
)
}
const serverInfo = runningServers.get(port)
// Update the code in memory
serverInfo.code = code
return NextResponse.json({
success: true,
message: 'Preview updated successfully'
})
} catch (error) {
console.error('Error updating preview:', error)
return NextResponse.json(
{ success: false, error: 'Failed to update preview' },
{ status: 500 }
)
}
}
// Get status of all running servers
export async function GET() {
try {
const servers = Array.from(runningServers.entries()).map(([port, info]) => ({
port,
startTime: info.startTime,
uptime: Date.now() - info.startTime,
running: !!info.server
}))
return NextResponse.json({
success: true,
servers,
count: servers.length
})
} catch (error) {
console.error('Error getting server status:', error)
return NextResponse.json(
{ success: false, error: 'Failed to get server status' },
{ status: 500 }
)
}
}