import type { NextRequest } from 'next/server'; import { authorizeLearningRuntime, runtimeUnauthorized } from '@/lib/makelore-runtime/auth'; import { loadMakeloreCourse, parseLearningBinding } from '@/lib/makelore-runtime/course-store'; import { isRuntimeOpenRequest } from '@/lib/makelore-runtime/protocol'; export async function POST(request: NextRequest) { if (!authorizeLearningRuntime(request)) return runtimeUnauthorized(); const body: unknown = await request.json().catch(() => null); if (!isRuntimeOpenRequest(body)) return Response.json({ error: 'invalid_request' }, { status: 400 }); const binding = parseLearningBinding(body.binding.key); if (!binding) return Response.json({ error: 'invalid_binding' }, { status: 400 }); const course = await loadMakeloreCourse(binding.courseId, binding.contentHash); if (!course) return Response.json({ error: 'course_not_found' }, { status: 404 }); return Response.json({ type: 'learning.course.snapshot', schema_version: 1, binding_source_sequence: 0, payload: { courseId: course.courseId, contentHash: course.contentHash, title: course.title, sceneCount: course.sceneCount, }, }); }