feat: provision dedicated per-project Theia workspaces

- lib/coolify-workspace.ts: creates a Coolify docker-image app at
  {slug}.ide.vibnai.com for each project, patches in vibn-auth Traefik
  labels, sets env vars, and starts deployment
- create/route.ts: provisions Theia workspace after Gitea repo creation;
  stores theiaWorkspaceUrl + theiaAppUuid on the project record
- theia-auth/route.ts: for *.ide.vibnai.com hosts, verifies the
  authenticated user is the project owner (slug → fs_projects lookup)
- overview/page.tsx: Open IDE always links (dedicated URL or shared fallback)
- project-creation-modal.tsx: shows dedicated workspace URL in success screen

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-19 13:14:21 -08:00
parent 4678928ee0
commit a22d5a0f18
5 changed files with 237 additions and 41 deletions

View File

@@ -4,6 +4,7 @@ import { authOptions } from '@/lib/auth/authOptions';
import { query } from '@/lib/db-postgres';
import { randomUUID } from 'crypto';
import { createRepo, createWebhook, GITEA_ADMIN_USER_EXPORT } from '@/lib/gitea';
import { provisionTheiaWorkspace } from '@/lib/coolify-workspace';
import type { ProjectPhaseData, ProjectPhaseScores } from '@/lib/types/project-artifacts';
const GITEA_ADMIN_USER = GITEA_ADMIN_USER_EXPORT;
@@ -90,7 +91,24 @@ export async function POST(request: Request) {
}
// ──────────────────────────────────────────────
// 3. Save project record
// 3. Provision dedicated Theia workspace
// ──────────────────────────────────────────────
let theiaWorkspaceUrl: string | null = null;
let theiaAppUuid: string | null = null;
let theiaError: string | null = null;
try {
const workspace = await provisionTheiaWorkspace(slug, projectId, giteaRepo);
theiaWorkspaceUrl = workspace.workspaceUrl;
theiaAppUuid = workspace.appUuid;
console.log(`[API] Theia workspace provisioned: ${theiaWorkspaceUrl}`);
} catch (err) {
theiaError = err instanceof Error ? err.message : String(err);
console.error('[API] Theia workspace provisioning failed (non-fatal):', theiaError);
}
// ──────────────────────────────────────────────
// 4. Save project record
// ──────────────────────────────────────────────
const projectData = {
id: projectId,
@@ -127,6 +145,10 @@ export async function POST(request: Request) {
giteaSshUrl,
giteaWebhookId,
giteaError,
// Theia workspace
theiaWorkspaceUrl,
theiaAppUuid,
theiaError,
// Context snapshot (kept fresh by webhooks)
contextSnapshot: null,
createdAt: now,
@@ -163,6 +185,8 @@ export async function POST(request: Request) {
? { repo: giteaRepo, repoUrl: giteaRepoUrl, cloneUrl: giteaCloneUrl, sshUrl: giteaSshUrl }
: null,
giteaError: giteaError ?? undefined,
theiaWorkspaceUrl,
theiaError: theiaError ?? undefined,
});
} catch (error) {
console.error('[POST /api/projects/create] Error:', error);