Ships the combined filesystem/Supabase storage adapter + MCP scene lifecycle tools + Next.js API routes + editor /scene/[id] route, so an MCP save is directly openable at /scene/<id> without any injection hack. End-to-end verified: 10/10 e2e steps pass. Storage (A1/A2/A3): - SceneStore interface + error classes + slug helpers - FilesystemSceneStore at $PASCAL_DATA_DIR (defaults XDG/~/.pascal) with atomic writes, .index sidecar, optimistic locking - SupabaseSceneStore with scenes + scene_revisions tables, RLS migration SQL, mock-backed unit tests - createSceneStore(env) auto-selects based on SUPABASE_URL + SUPABASE_SERVICE_ROLE_KEY MCP tools (A4, A8, A9, A10): - save_scene / load_scene / list_scenes / delete_scene / rename_scene - list_templates / create_from_template (3 seed templates: empty-studio, two-bedroom, garden-house) - generate_variants (7 mutation kinds, seeded RNG, save=true|false) - photo_to_scene (vision sampling → scene graph → save) Editor (A5, A6): - /api/scenes + /api/scenes/[id] with RFC 7232 If-Match locking - /scene/[id] and /scenes route pages with save button, SceneLoader - Removed the window.__pascalScene dev injection hack Security + UX edges (A7, A8): - AssetUrl Zod validator: asset:// blob: data:image/ /path https: (http://localhost for dev) + PASCAL_ALLOWED_ASSET_ORIGINS env allowlist. Hardens scan.url, guide.url, item.asset.src, material.texture.url, MaterialMaps.*Map - Auto-frame camera on empty→non-empty scene transition (camera-controls:fit-scene emitter event) Shared utilities: - rehydrateSiteChildren() extracted to packages/mcp/src/lib/ and used by both create-from-template and generate-variants to work around the SiteNode.children-as-objects vs. ids inconsistency (CROSS_CUTTING §2) - Storage + MCP subpath exports added to packages/mcp/package.json (CROSS_CUTTING §4) Tests: 293 pass / 0 fail across 40 files (was 142 pre-Phase-7). Biome: clean. Phase-7 e2e script at packages/mcp/test-reports/phase7-e2e.ts: MCP HTTP + editor Next.js both point at $PASCAL_DATA_DIR = /tmp/pascal-e2e, save_scene from MCP, GET /api/scenes/<id> from editor server, /scenes list page renders all saved scenes, scene page renders SceneLoader, delete_scene works. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
118 lines
4.2 KiB
TypeScript
118 lines
4.2 KiB
TypeScript
import { headers } from 'next/headers'
|
|
import Link from 'next/link'
|
|
import { CreateSceneButton } from '@/components/save-button'
|
|
import type { SceneMeta } from '@/components/scene-loader'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
async function resolveBaseUrl(): Promise<string> {
|
|
if (process.env.NEXT_PUBLIC_APP_URL) {
|
|
return process.env.NEXT_PUBLIC_APP_URL
|
|
}
|
|
const h = await headers()
|
|
const host = h.get('x-forwarded-host') ?? h.get('host')
|
|
const proto = h.get('x-forwarded-proto') ?? 'http'
|
|
if (!host) {
|
|
return 'http://localhost:3000'
|
|
}
|
|
return `${proto}://${host}`
|
|
}
|
|
|
|
async function fetchScenes(): Promise<SceneMeta[]> {
|
|
const base = await resolveBaseUrl()
|
|
const response = await fetch(`${base}/api/scenes?limit=50`, {
|
|
cache: 'no-store',
|
|
})
|
|
if (!response.ok) {
|
|
return []
|
|
}
|
|
const payload = (await response.json()) as { scenes?: SceneMeta[] } | SceneMeta[]
|
|
if (Array.isArray(payload)) {
|
|
return payload
|
|
}
|
|
return payload.scenes ?? []
|
|
}
|
|
|
|
function formatDate(iso: string): string {
|
|
try {
|
|
return new Date(iso).toLocaleString()
|
|
} catch {
|
|
return iso
|
|
}
|
|
}
|
|
|
|
export default async function ScenesPage() {
|
|
const scenes = await fetchScenes()
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<header className="sticky top-0 z-10 border-border border-b bg-background/95 backdrop-blur">
|
|
<div className="container mx-auto flex items-center justify-between gap-4 px-6 py-4">
|
|
<nav className="flex items-center gap-4 text-sm">
|
|
<Link
|
|
className="text-muted-foreground transition-colors hover:text-foreground"
|
|
href="/"
|
|
>
|
|
Home
|
|
</Link>
|
|
<span className="text-muted-foreground">/</span>
|
|
<span className="font-medium text-foreground">Scenes</span>
|
|
</nav>
|
|
<CreateSceneButton />
|
|
</div>
|
|
</header>
|
|
|
|
<main className="container mx-auto max-w-5xl px-6 py-12">
|
|
<h1 className="mb-2 font-bold text-3xl">Your scenes</h1>
|
|
<p className="mb-8 text-muted-foreground text-sm">
|
|
{scenes.length === 0
|
|
? 'No scenes yet. Create one to get started.'
|
|
: `${scenes.length} scene${scenes.length === 1 ? '' : 's'}.`}
|
|
</p>
|
|
|
|
{scenes.length === 0 ? (
|
|
<div className="rounded-xl border border-border/60 border-dashed bg-background p-12 text-center">
|
|
<p className="text-muted-foreground text-sm">You haven't saved any scenes yet.</p>
|
|
<div className="mt-4 flex justify-center">
|
|
<CreateSceneButton />
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<ul className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
{scenes.map((scene) => (
|
|
<li key={scene.id}>
|
|
<Link
|
|
className="group block rounded-xl border border-border/60 bg-background p-4 transition-colors hover:border-border hover:bg-accent/30"
|
|
href={`/scene/${scene.id}`}
|
|
>
|
|
<div className="flex aspect-video items-center justify-center overflow-hidden rounded-lg bg-accent/30">
|
|
{scene.thumbnailUrl ? (
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img
|
|
alt={scene.name}
|
|
className="h-full w-full object-cover"
|
|
src={scene.thumbnailUrl}
|
|
/>
|
|
) : (
|
|
<span className="text-muted-foreground text-xs">No thumbnail</span>
|
|
)}
|
|
</div>
|
|
<div className="mt-3">
|
|
<h2 className="truncate font-semibold text-sm group-hover:text-foreground">
|
|
{scene.name}
|
|
</h2>
|
|
<div className="mt-1 flex items-center justify-between text-muted-foreground text-xs">
|
|
<span>{scene.nodeCount} nodes</span>
|
|
<time dateTime={scene.updatedAt}>{formatDate(scene.updatedAt)}</time>
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</main>
|
|
</div>
|
|
)
|
|
}
|