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>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import type { SceneGraph } from '@pascal-app/editor'
|
|
import { headers } from 'next/headers'
|
|
import Link from 'next/link'
|
|
import { SceneLoader, type SceneMeta } from '@/components/scene-loader'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
interface SceneWithGraph extends SceneMeta {
|
|
graph: SceneGraph
|
|
}
|
|
|
|
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 fetchScene(id: string): Promise<SceneWithGraph | null> {
|
|
const base = await resolveBaseUrl()
|
|
const response = await fetch(`${base}/api/scenes/${encodeURIComponent(id)}`, {
|
|
cache: 'no-store',
|
|
})
|
|
if (response.status === 404) {
|
|
return null
|
|
}
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to load scene: ${response.status}`)
|
|
}
|
|
return (await response.json()) as SceneWithGraph
|
|
}
|
|
|
|
export default async function ScenePage({ params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params
|
|
const scene = await fetchScene(id)
|
|
|
|
if (!scene) {
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-background p-6">
|
|
<div className="w-full max-w-md rounded-2xl border border-border/60 bg-background p-6 text-center shadow-xl">
|
|
<p className="font-mono text-muted-foreground text-xs uppercase tracking-wide">404</p>
|
|
<h1 className="mt-2 font-semibold text-lg">Scene not found</h1>
|
|
<p className="mt-2 text-muted-foreground text-sm">
|
|
We couldn't find a scene with id <code className="font-mono">{id}</code>.
|
|
</p>
|
|
<div className="mt-4 flex items-center justify-center gap-2">
|
|
<Link
|
|
className="rounded-md border border-border bg-accent px-3 py-2 font-medium text-sm hover:bg-accent/80"
|
|
href="/scenes"
|
|
>
|
|
Browse scenes
|
|
</Link>
|
|
<Link
|
|
className="rounded-md border border-border bg-background px-3 py-2 font-medium text-sm hover:bg-accent/40"
|
|
href="/"
|
|
>
|
|
Back to editor
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const { graph, ...meta } = scene
|
|
return <SceneLoader initialScene={graph} meta={meta} />
|
|
}
|