DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
feat(outputs): publish video lesson pages from a sandboxed origin
SeleiXidfe4f285a860
diff --git a/deeptutor/api/routers/outputs.py b/deeptutor/api/routers/outputs.pyindex 83ea96856..79e205175 100644--- a/deeptutor/api/routers/outputs.py+++ b/deeptutor/api/routers/outputs.py@@ -17,6 +17,11 @@ from deeptutor.services.path_service import PathServicerouter = APIRouter()+# Video lessons are pages of model-written script. Served under this CSP they+# run in an opaque origin even when opened directly, never with the API's+# cookies or same-origin access.+_SANDBOXED_PAGE_CSP = "sandbox allow-scripts allow-popups"+def _request_path_service() -> PathService:"""Resolve the workspace installed by ``require_auth`` without fallback.@@ -85,4 +90,6 @@ async def read_output(path = _resolve_partner_output(output_path)if path is None:raise+ if path.suffix.lower() == ".html" and "video_lesson" in path.parts:+ return FileResponse(path, headers={"Content-Security-Policy": _SANDBOXED_PAGE_CSP})return FileResponse(path)diff --git a/deeptutor/services/path_service.py b/deeptutor/services/path_service.pyindex 380c2671c..713146ca7 100644--- a/deeptutor/services/path_service.py+++ b/deeptutor/services/path_service.py@@ -39,6 +39,7 @@ AgentModule = Literal["exec_workspace","logs","math_animator",+ "video_lesson",]ChatWorkspaceFeature = Literal[@@ -47,6 +48,7 @@ ChatWorkspaceFeature = Literal["deep_question","deep_research","math_animator",+ "video_lesson","_detached_exec",]@@ -77,6 +79,7 @@ class PathService:"question": ("chat", "deep_question"),"research": ("chat", "deep_research"),"math_animator": ("chat", "math_animator"),+ "video_lesson": ("chat", "video_lesson"),"co-writer": ("co-writer", None),"exec_workspace": ("chat", "_detached_exec"),}@@ -194,6 +197,16 @@ class PathService:):return candidate+ # Video lessons publish only their self-contained player page; the+ # lesson source and build workspace beside it stay private.+ if (+ len(parts) == 6+ and parts[:3] == ("workspace", "chat", "video_lesson")+ and parts[4] == "artifacts"+ and parts[5] == "lesson.html"+ ):+ return candidate+if len(parts) >= 5 and parts[:2] == ("workspace", "chat") and "code_runs" in parts[3:]:return candidate@@ -264,6 +277,7 @@ class PathService:"deep_question","deep_research","math_animator",+ "video_lesson","_detached_exec",}:return self.get_chat_feature_dir(cast(ChatWorkspaceFeature, feature))@@ -504,6 +518,7 @@ class PathService:"deep_question","deep_research","math_animator",+ "video_lesson","_detached_exec",),):diff --git a/tests/agents/video_lesson/test_public_output.py b/tests/agents/video_lesson/test_public_output.pynew file mode 100644index 000000000..adbecd4b5--- /dev/null+++ b/tests/agents/video_lesson/test_public_output.py@@ -0,0 +1,51 @@+"""Only the lesson page is public, and it is served sandboxed."""++from __future__ import annotations++from pathlib import Path++import pytest++from deeptutor.services.path_service import PathService+++def test_only_the_lesson_page_is_public(tmp_path: Path) -> None:+ service = PathService(workspace_root=tmp_path / "data")+ turn = service.get_agent_dir("video_lesson") / "turn-1"+ page = turn / "artifacts" / "lesson.html"+ source = turn / "source" / "Lesson.tsx"+ stray = turn / "artifacts" / "notes.html"+ for path in (page, source, stray):+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text("x", encoding="utf-8")++ assert service.resolve_public_output_path(page) == page.resolve()+ assert service.resolve_public_output_path(source) is None+ assert service.resolve_public_output_path(stray) is None+++def test_lesson_page_is_served_sandboxed(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:+ from fastapi import FastAPI+ from fastapi.testclient import TestClient++ from deeptutor.api.routers import auth as auth_router+ from deeptutor.api.routers import outputs+ from deeptutor.multi_user import paths as multi_user_paths++ admin_root = tmp_path / "data"+ monkeypatch.setattr(multi_user_paths, "ADMIN_WORKSPACE_ROOT", admin_root)+ monkeypatch.setattr(multi_user_paths, "USERS_ROOT", admin_root / "users")+ monkeypatch.setattr(multi_user_paths, "_path_services", {})+ monkeypatch.setattr(auth_router, "AUTH_ENABLED", False)+ service = PathService(workspace_root=admin_root)+ page = service.get_agent_dir("video_lesson") / "turn-1" / "artifacts" / "lesson.html"+ page.parent.mkdir(parents=True)+ page.write_text("<!doctype html><script>1</script>", encoding="utf-8")++ app = FastAPI()+ app.include_router(outputs.router, prefix="/files/outputs")+ rel = page.relative_to(service.get_public_outputs_root()).as_posix()+ response = TestClient(app).get(f"/files/outputs/{rel}")++ assert response.status_code == 200+ assert response.headers["content-security-policy"].startswith("sandbox allow-scripts")