Theia rip-out: - Delete app/api/theia-auth/route.ts (Traefik ForwardAuth shim) - Delete app/api/projects/[projectId]/workspace/route.ts and app/api/projects/prewarm/route.ts (Cloud Run Theia provisioning) - Delete lib/cloud-run-workspace.ts and lib/coolify-workspace.ts - Strip provisionTheiaWorkspace + theiaWorkspaceUrl/theiaAppUuid/ theiaError from app/api/projects/create/route.ts response - Remove Theia callbackUrl branch in app/auth/page.tsx - Drop "Open in Theia" button + xterm/Theia PTY copy in build/page.tsx - Drop theiaWorkspaceUrl from deployment/page.tsx Project type - Strip Theia IDE line + theia-code-os from advisor + agent-chat context strings - Scrub Theia mention from lib/auth/workspace-auth.ts comment P5.1 (custom apex domains + DNS): - lib/coolify.ts + lib/opensrs.ts: nameserver normalization, OpenSRS XML auth, Cloud DNS plumbing - scripts/smoke-attach-e2e.ts: full prod GCP + sandbox OpenSRS + prod Coolify smoke covering register/zone/A/NS/PATCH/cleanup In-progress (Justine onboarding/build, MVP setup, agent telemetry): - New (justine)/stories, project (home) layouts, mvp-setup, run, tasks routes + supporting components - Project shell + sidebar + nav refactor for the Stackless palette - Agent session API hardening (sessions, events, stream, approve, retry, stop) + atlas-chat, advisor, design-surfaces refresh - New scripts/sync-db-url-from-coolify.mjs + scripts/prisma-db-push.mjs + docker-compose.local-db.yml for local Prisma workflows - lib/dev-bypass.ts, lib/chat-context-refs.ts, lib/prd-sections.ts - Misc: stories CSS, debug/prisma route, modal-theme, BuildLivePlanPanel Made-with: Cursor
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { authSession } from "@/lib/auth/session-server";
|
|
import { query } from '@/lib/db-postgres';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const session = await authSession();
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const email = session.user.email;
|
|
|
|
// Fetch projects joined on user email
|
|
const projects = await query<any>(`
|
|
SELECT p.id, p.data, p.workspace, p.slug
|
|
FROM fs_projects p
|
|
JOIN fs_users u ON u.id = p.user_id
|
|
WHERE u.data->>'email' = $1
|
|
ORDER BY (p.data->>'updatedAt') DESC NULLS LAST
|
|
`, [email]);
|
|
|
|
// Fetch session stats per project
|
|
const sessionStats = await query<any>(`
|
|
SELECT
|
|
s.data->>'projectId' AS project_id,
|
|
COUNT(*)::int AS session_count,
|
|
COALESCE(SUM((s.data->>'cost')::float), 0) AS total_cost
|
|
FROM fs_sessions s
|
|
JOIN fs_users u ON u.id = s.user_id
|
|
WHERE u.data->>'email' = $1
|
|
GROUP BY s.data->>'projectId'
|
|
`, [email]);
|
|
|
|
const statsByProject = new Map(sessionStats.map((s: any) => [s.project_id, s]));
|
|
|
|
const result = projects.map((p: any) => {
|
|
const stats = statsByProject.get(p.id) || { session_count: 0, total_cost: 0 };
|
|
return {
|
|
id: p.id,
|
|
...p.data,
|
|
stats: {
|
|
sessions: stats.session_count || 0,
|
|
costs: parseFloat(stats.total_cost) || 0,
|
|
},
|
|
};
|
|
});
|
|
|
|
return NextResponse.json({ projects: result });
|
|
} catch (error) {
|
|
console.error('[GET /api/projects] Error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch projects', details: error instanceof Error ? error.message : String(error) },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|