UNPKG

flutty-cli-agent

Version:

Flutty CLI Agent - AI-powered development assistant with web chat interface, context memory, and full tool integration using DeepSeek API

54 lines (44 loc) 1.58 kB
import { NextRequest, NextResponse } from 'next/server' import { ChatSession, ChatSessionOptions } from '../../../../src/lib/chat-session' // Global session store declare global { var chatSessions: Map<string, ChatSession> | undefined } global.chatSessions = global.chatSessions || new Map() const chatSessions = global.chatSessions export async function POST(request: NextRequest) { try { const body = await request.json() const { workingDirectory, sessionId: customSessionId, options = {} } = body const sessionOptions: ChatSessionOptions = { workingDirectory: workingDirectory || process.cwd(), sessionId: customSessionId, maxTurns: options.maxTurns || 50, maxLoopIterations: options.maxLoopIterations || 20, allowedTools: options.allowedTools, verbose: options.verbose || false } // Create new chat session const chatSession = new ChatSession(sessionOptions) // Start the session await chatSession.start() const sessionInfo = chatSession.getSessionInfo() // Store session globally chatSessions.set(sessionInfo.sessionId, chatSession) return NextResponse.json({ success: true, sessionId: sessionInfo.sessionId, workingDirectory: sessionInfo.workingDirectory, message: 'Chat session started successfully' }) } catch (error: any) { console.error('Error starting chat session:', error) return NextResponse.json( { success: false, error: error.message || 'Failed to start chat session' }, { status: 500 } ) } }