refactor: migrate to monorepo structure with Docker, PocketBase, and e2e tests
- Reorganize into apps/, packages/, docs/, e2e/, pocketbase/ directories - Add Dockerfiles for web, worker, and PocketBase services - Add docker-compose.yml for local orchestration - Add turbo.json for monorepo task management - Add Playwright e2e test infrastructure - Add PocketBase backend with migrations - Remove Vite/Next.js/ESLint/PostCSS config files - Update package.json with workspace dependencies - Add .env.example and .dockerignore
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthUser, createErrorResponse } from '@/lib/auth';
|
||||
import { createPocketBaseClient } from '@/lib/pocketbase';
|
||||
|
||||
type RouteContext = { params: Promise<{ id: string }> };
|
||||
|
||||
// POST /api/agent-activity/[id]/undo — Undo an agent action
|
||||
export async function POST(request: NextRequest, context: RouteContext) {
|
||||
const user = await getAuthUser(request);
|
||||
if (!user) {
|
||||
return NextResponse.json(
|
||||
{ error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const { id } = await context.params;
|
||||
|
||||
try {
|
||||
const pb = createPocketBaseClient();
|
||||
|
||||
// Get the activity record
|
||||
const activity = await pb.collection('agent_activity').getOne(id);
|
||||
|
||||
if (!activity.before_state) {
|
||||
return createErrorResponse('CANNOT_UNDO', 'This action cannot be undone', 400);
|
||||
}
|
||||
|
||||
// Restore the previous state
|
||||
const entityType = activity.entity_type;
|
||||
const entityId = activity.entity_id;
|
||||
const beforeState = activity.before_state;
|
||||
|
||||
await pb.collection(entityType).update(entityId, beforeState);
|
||||
|
||||
return NextResponse.json({ success: true, message: 'Action undone' });
|
||||
} catch (error) {
|
||||
console.error('Failed to undo activity:', error);
|
||||
return createErrorResponse('UNDO_FAILED', 'Failed to undo action', 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { withAuth } from '@/lib/auth';
|
||||
import { createPocketBaseClient } from '@/lib/pocketbase';
|
||||
|
||||
// GET /api/agent-activity — List agent activity
|
||||
export const GET = withAuth(async (request: NextRequest) => {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = parseInt(searchParams.get('page') || '1');
|
||||
const perPage = parseInt(searchParams.get('perPage') || '50');
|
||||
const sort = searchParams.get('sort') || '-created';
|
||||
|
||||
const pb = createPocketBaseClient();
|
||||
const result = await pb.collection('agent_activity').getList(page, perPage, {
|
||||
sort,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
items: result.items,
|
||||
totalItems: result.totalItems,
|
||||
totalPages: result.totalPages,
|
||||
page: result.page,
|
||||
perPage: result.perPage,
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user