import { NextResponse } from 'next/server'; import * as fs from 'fs'; import * as path from 'path'; const DATA_DIR = '/app/data'; // Tasks API export async function GET(request: Request) { const { searchParams } = new URL(request.url); const type = searchParams.get('type') || 'tasks'; try { if (type === 'tasks') { const tasksDir = path.join(DATA_DIR, 'shared-context/jelena-neo-tasks/archive'); const tasks: any[] = []; if (fs.existsSync(tasksDir)) { const files = fs.readdirSync(tasksDir).filter(f => f.endsWith('.md')); for (const file of files) { const content = fs.readFileSync(path.join(tasksDir, file), 'utf-8'); const title = content.match(/^# Task: (.+)$/m)?.[1] || file; const created = content.match(/Created: (.+)$/m)?.[1] || ''; const priority = content.match(/Priority: (.+)$/m)?.[1] || 'normal'; tasks.push({ id: file.replace('.md', ''), title, created, priority, status: 'done', assignee: 'neo' }); } } return NextResponse.json(tasks); } if (type === 'crons') { const cronFile = path.join(DATA_DIR, 'cron/jobs.json'); if (fs.existsSync(cronFile)) { const data = JSON.parse(fs.readFileSync(cronFile, 'utf-8')); const jobs = (data.jobs || []).map((job: any) => ({ name: job.name, enabled: job.enabled, status: job.state?.lastStatus || 'unknown', lastRun: job.state?.lastRunAtMs ? new Date(job.state.lastRunAtMs).toISOString() : null })); return NextResponse.json(jobs); } return NextResponse.json([]); } if (type === 'memory') { const memoryDir = path.join(DATA_DIR, 'memory'); const memories: any[] = []; if (fs.existsSync(memoryDir)) { const files = fs.readdirSync(memoryDir).filter(f => f.endsWith('.md')); for (const file of files.slice(0, 20)) { const content = fs.readFileSync(path.join(memoryDir, file), 'utf-8'); const title = content.match(/^# (.+)$/m)?.[1] || file; const preview = content.substring(0, 150).replace(/[#*]/g, ''); memories.push({ id: file.replace('.md', ''), title, date: file.substring(0, 10), preview }); } } return NextResponse.json(memories); } return NextResponse.json({ error: 'Unknown type' }, { status: 400 }); } catch (e: any) { return NextResponse.json({ error: e.message }, { status: 500 }); } }