Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

feat(web): play video lessons in chat

SeleiXi78877ee2ba7b
diff --git a/web/components/video-lesson/VideoLessonViewer.tsx b/web/components/video-lesson/VideoLessonViewer.tsx
new file mode 100644
index 000000000..3b0639dc8
--- /dev/null
+++ b/web/components/video-lesson/VideoLessonViewer.tsx
@@ -0,0 +1,78 @@
+"use client";
+
+import { Clapperboard, Code2, ExternalLink, Timer } from "lucide-react";
+import { useTranslation } from "react-i18next";
+import { apiUrl } from "@/lib/api";
+import type { VideoLessonResult } from "@/lib/video-lesson-types";
+
+export default function VideoLessonViewer({
+ result,
+}: {
+ result: VideoLessonResult;
+}) {
+ const { t } = useTranslation();
+ const url = result.page.url;
+ const src =
+ url.startsWith("http://") || url.startsWith("https://")
+ ? url
+ : apiUrl(url);
+
+ return (
+ <div className="mb-3 space-y-3 rounded-2xl border border-[var(--border)] bg-[var(--card)]/70 p-3">
+ <div className="flex items-center justify-between gap-2">
+ <div className="flex min-w-0 items-center gap-2 text-[12px] font-medium text-[var(--foreground)]">
+ <Clapperboard size={14} className="shrink-0" />
+ <span className="truncate">{result.title || t("Video Lesson")}</span>
+ </div>
+ <a
+ href={src}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[11px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--muted)] hover:text-[var(--foreground)]"
+ >
+ <ExternalLink size={12} />
+ {t("Open in new tab")}
+ </a>
+ </div>
+
+ {/* The page runs model-written code: scripts yes, same-origin access no. */}
+ <iframe
+ src={src}
+ title={result.title || t("Video Lesson")}
+ sandbox="allow-scripts"
+ allow="fullscreen"
+ allowFullScreen
+ loading="lazy"
+ className="aspect-video w-full rounded-xl border border-[var(--border)] bg-[#fdfcf9]"
+ />
+
+ {result.durationSeconds || result.attempts > 1 ? (
+ <div className="flex flex-wrap items-center gap-2 text-[11px] text-[var(--muted-foreground)]">
+ {result.durationSeconds ? (
+ <span className="inline-flex items-center gap-1 rounded-full border border-[var(--border)] px-2 py-0.5">
+ <Timer size={12} />
+ {t("{{seconds}} s", { seconds: result.durationSeconds })}
+ </span>
+ ) : null}
+ {result.attempts > 1 ? (
+ <span className="rounded-full border border-[var(--border)] px-2 py-0.5">
+ {t("Fixed after {{count}} checks", { count: result.attempts })}
+ </span>
+ ) : null}
+ </div>
+ ) : null}
+
+ {result.code ? (
+ <details className="overflow-hidden rounded-xl border border-[var(--border)] bg-[var(--background)]">
+ <summary className="flex cursor-pointer items-center gap-2 px-3 py-2 text-[12px] font-medium text-[var(--foreground)]">
+ <Code2 size={14} />
+ {t("View Remotion Code")}
+ </summary>
+ <pre className="max-h-[360px] overflow-auto border-t border-[var(--border)] px-3 py-3 font-mono text-[11px] leading-[1.6] text-[var(--foreground)]">
+ {result.code}
+ </pre>
+ </details>
+ ) : null}
+ </div>
+ );
+}
diff --git a/web/features/capabilities/presentation.tsx b/web/features/capabilities/presentation.tsx
index 64f641ea3..f8562657f 100644
--- a/web/features/capabilities/presentation.tsx
+++ b/web/features/capabilities/presentation.tsx
@@ -135,6 +135,14 @@ export const CHAT_CAPABILITIES: ChatCapabilityDef[] = [
allowedTools: [],
defaultTools: [],
},
+ {
+ value: "video_lesson",
+ label: "Video Lesson",
+ description: "Turn a question into an animated explainer you can play",
+ icon: Clapperboard,
+ allowedTools: [],
+ defaultTools: [],
+ },
{
value: "course_study",
label: "Course Study",
diff --git a/web/features/chat/messages/ChatMessageList.tsx b/web/features/chat/messages/ChatMessageList.tsx
index 6e3ef7f1f..ad8556fa0 100644
--- a/web/features/chat/messages/ChatMessageList.tsx
+++ b/web/features/chat/messages/ChatMessageList.tsx
@@ -59,6 +59,7 @@ import {
SPEECH_TIMEOUT_MESSAGE,
} from "@/lib/voice-settings";
import { extractMathAnimatorResult } from "@/lib/math-animator-types";
+import { extractVideoLessonResult } from "@/lib/video-lesson-types";
import {
extractQuizQuestions,
extractQuizTurnId,
@@ -150,6 +151,10 @@ const VisualizationViewer = dynamic(
() => import("@/components/visualize/VisualizationViewer"),
{ ssr: false },
);
+const VideoLessonViewer = dynamic(
+ () => import("@/components/video-lesson/VideoLessonViewer"),
+ { ssr: false },
+);
interface ChatMessageItem {
@@ -182,6 +187,7 @@ const MODE_BADGE_LABELS: Record<string, string> = {
deep_question: "Quiz Generation",
deep_research: "Deep Research",
math_animator: "Math Animator",
+ video_lesson: "Video Lesson",
visualize: "Visualize",
mastery_path: "Mastery Path",
immersive_reading: "Immersive Reading",
@@ -798,6 +804,11 @@ export const AssistantMessage = memo(function AssistantMessage({
return extractVisualizeResult(resultEvent.metadata);
}, [msg.capability, resultEvent]);
+ const videoLessonResult = useMemo(() => {
+ if (msg.capability !== "video_lesson" || !resultEvent) return null;
+ return extractVideoLessonResult(resultEvent.metadata);
+ }, [msg.capability, resultEvent]);
+
// Detect the ``ask_user`` terminator payload: when the assistant turn
// ended via the ``ask_user`` tool, this is the question the user is
// expected to answer next. Render option chips below the message.
@@ -1123,6 +1134,20 @@ export const AssistantMessage = memo(function AssistantMessage({
<MathAnimatorViewer result={mathAnimatorResult} />
) : visualizeResult ? (
<VisualizationViewer result={visualizeResult} />
+ ) : videoLessonResult ? (
+ <>
+ <VideoLessonViewer result={videoLessonResult} />
+ {msg.content ? (
+ <AssistantResponse
+ content={msg.content}
+ language={language}
+ isStreaming={isStreaming}
+ readingMaterialId={readingMaterialId}
+ readingMaterialRevision={readingMaterialRevision}
+ events={events}
+ />
+ ) : null}
+ </>
) : quizQuestions && quizQuestions.length > 0 ? (
<>
{/* The quiz preface (the "I researched X, now let me quiz you on Y"
diff --git a/web/lib/video-lesson-types.ts b/web/lib/video-lesson-types.ts
new file mode 100644
index 000000000..03a4cf2de
--- /dev/null
+++ b/web/lib/video-lesson-types.ts
@@ -0,0 +1,51 @@
+export interface VideoLessonArtifact {
+ type: "html";
+ url: string;
+ filename: string;
+ content_type?: string;
+ label?: string;
+}
+
+export interface VideoLessonResult {
+ response: string;
+ title: string;
+ page: VideoLessonArtifact;
+ code: string;
+ durationSeconds: number | null;
+ attempts: number;
+}
+
+/** The lesson page and its metadata from a ``video_lesson`` result event, or null. */
+export function extractVideoLessonResult(
+ resultMetadata: Record<string, unknown> | undefined,
+): VideoLessonResult | null {
+ if (!resultMetadata) return null;
+ const artifacts = Array.isArray(resultMetadata.artifacts)
+ ? resultMetadata.artifacts
+ : [];
+ const page = artifacts.find(
+ (item): item is VideoLessonArtifact =>
+ Boolean(item) &&
+ typeof item === "object" &&
+ (item as Record<string, unknown>).type === "html" &&
+ typeof (item as Record<string, unknown>).url === "string",
+ );
+ if (!page) return null;
+ const code =
+ resultMetadata.code && typeof resultMetadata.code === "object"
+ ? String((resultMetadata.code as Record<string, unknown>).content ?? "")
+ : "";
+ const render =
+ resultMetadata.render && typeof resultMetadata.render === "object"
+ ? (resultMetadata.render as Record<string, unknown>)
+ : {};
+ const duration = Number(render.duration_seconds);
+ return {
+ response: String(resultMetadata.response ?? ""),
+ title: String(resultMetadata.title ?? page.label ?? ""),
+ page,
+ code,
+ durationSeconds: Number.isFinite(duration) && duration > 0 ? duration : null,
+ attempts: Array.isArray(render.attempts) ? render.attempts.length : 0,
+ };
+}
diff --git a/web/locales/de/app.json b/web/locales/de/app.json
index 62d0c9b30..e4d81c917 100644
--- a/web/locales/de/app.json
+++ b/web/locales/de/app.json
@@ -5520,5 +5520,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "Gilt für Chat, Problemlösung, Rückfragen, geführtes Lernen, Lesen, Kurslernen und Standardvisualisierungen. Änderungen gelten ab der nächsten Runde.",
"Clear instructions": "Anweisungen leeren",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} Zeichen",
- "contextBudget.segment.workspace_instructions": "Arbeitsbereichsanweisungen"
+ "contextBudget.segment.workspace_instructions": "Arbeitsbereichsanweisungen",
+ "Video Lesson": "Video-Lektion",
+ "Turn a question into an animated explainer you can play": "Verwandle eine Frage in ein abspielbares Erklär-Video",
+ "View Remotion Code": "Remotion-Code anzeigen",
+ "{{seconds}} s": "{{seconds}} s",
+ "Fixed after {{count}} checks": "Nach {{count}} Prüfungen korrigiert"
}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 7b2f05434..ea84bc452 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -5520,5 +5520,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.",
"Clear instructions": "Clear instructions",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} characters",
- "contextBudget.segment.workspace_instructions": "Workspace instructions"
+ "contextBudget.segment.workspace_instructions": "Workspace instructions",
+ "Video Lesson": "Video Lesson",
+ "Turn a question into an animated explainer you can play": "Turn a question into an animated explainer you can play",
+ "View Remotion Code": "View Remotion Code",
+ "{{seconds}} s": "{{seconds}} s",
+ "Fixed after {{count}} checks": "Fixed after {{count}} checks"
}
diff --git a/web/locales/fr/app.json b/web/locales/fr/app.json
index e0f5eb00a..9ee7f890c 100644
--- a/web/locales/fr/app.json
+++ b/web/locales/fr/app.json
@@ -5899,5 +5899,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "S’applique au chat, à la résolution, aux questions, à l’apprentissage guidé, à la lecture, aux cours et aux visualisations standard. Les changements prennent effet au prochain tour.",
"Clear instructions": "Effacer les instructions",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} caractères",
- "contextBudget.segment.workspace_instructions": "Instructions de l’espace de travail"
+ "contextBudget.segment.workspace_instructions": "Instructions de l’espace de travail",
+ "Video Lesson": "Leçon vidéo",
+ "Turn a question into an animated explainer you can play": "Transformer une question en animation explicative à regarder",
+ "View Remotion Code": "Voir le code Remotion",
+ "{{seconds}} s": "{{seconds}} s",
+ "Fixed after {{count}} checks": "Corrigé après {{count}} vérifications"
}
diff --git a/web/locales/pl/app.json b/web/locales/pl/app.json
index 7b7b81c31..81b617d85 100644
--- a/web/locales/pl/app.json
+++ b/web/locales/pl/app.json
@@ -5536,5 +5536,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "Dotyczy czatu, rozwiązywania, pytań, nauki z przewodnikiem, czytania, kursów i standardowych wizualizacji. Zmiany obowiązują od następnej tury.",
"Clear instructions": "Wyczyść instrukcje",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} znaków",
- "contextBudget.segment.workspace_instructions": "Instrukcje obszaru roboczego"
+ "contextBudget.segment.workspace_instructions": "Instrukcje obszaru roboczego",
+ "Video Lesson": "Lekcja wideo",
+ "Turn a question into an animated explainer you can play": "Zamień pytanie w animowane wyjaśnienie do odtworzenia",
+ "View Remotion Code": "Pokaż kod Remotion",
+ "{{seconds}} s": "{{seconds}} s",
+ "Fixed after {{count}} checks": "Poprawiono po {{count}} sprawdzeniach"
}
diff --git a/web/locales/uk/app.json b/web/locales/uk/app.json
index 87c30d86c..b1e1857ed 100644
--- a/web/locales/uk/app.json
+++ b/web/locales/uk/app.json
@@ -5536,5 +5536,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "Застосовується до чату, розв’язування, запитань, керованого навчання, читання, курсів і стандартних візуалізацій. Зміни діють із наступного ходу.",
"Clear instructions": "Очистити інструкції",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} символів",
- "contextBudget.segment.workspace_instructions": "Інструкції робочого простору"
+ "contextBudget.segment.workspace_instructions": "Інструкції робочого простору",
+ "Video Lesson": "Відеоурок",
+ "Turn a question into an animated explainer you can play": "Перетворіть запитання на анімоване пояснення, яке можна відтворити",
+ "View Remotion Code": "Переглянути код Remotion",
+ "{{seconds}} s": "{{seconds}} с",
+ "Fixed after {{count}} checks": "Виправлено після {{count}} перевірок"
}
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 66791710c..d6740f0d2 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -5520,5 +5520,10 @@
"Applies to Chat, Solve, Ask Questions, Guided Learning, Reading, Course Study and standard visualizations. Changes take effect on the next turn.": "适用于对话、解题、主动提问、引导学习、沉浸式阅读、课程学习和常规可视化。从下一轮开始生效。",
"Clear instructions": "清空提示词",
"{{used}} / {{limit}} characters": "{{used}} / {{limit}} 字符",
- "contextBudget.segment.workspace_instructions": "工作区提示词"
+ "contextBudget.segment.workspace_instructions": "工作区提示词",
+ "Video Lesson": "视频讲解",
+ "Turn a question into an animated explainer you can play": "把问题做成可以播放的讲解动画",
+ "View Remotion Code": "查看 Remotion 代码",
+ "{{seconds}} s": "{{seconds}} 秒",
+ "Fixed after {{count}} checks": "经 {{count}} 轮检查修复"
}