Files
DeepTutor/web/features/notes/model/learning-kinds.ts
Bingxi Zhao (Frank) 28c11e2ae8 feat: update notes, chat interactions and workspace UI on preview
Remove course pages, APIs and the course_study capability. Add anchored note
threads and reviewed learning-block generation, queued and withdrawable chat
messages, quote attachments, side chats, and the calendar/favorites/navigation
updates.

Keep preview's existing backend architecture. Wire the new features through
its Python application and existing chat engine, retain legacy selected-text
requests, persist mid-turn messages in replay, and restore note context when
regenerating. Leave stored user data intact.

Validate frontend contracts, dependency boundaries, types, 1290 node tests,
840 rendered tests, lint, localization and the production build. Exercise
session/notes/API regressions, 53 chat-engine tests and 20 Python/native
integration tests with isolated runtime data.
2026-10-26 22:13:34 +08:00

169 lines
3.9 KiB
TypeScript

import {
BookOpen,
CheckSquare,
Image as ImageIcon,
Layers,
ListOrdered,
ListTodo,
Music,
Network,
Play,
Shapes,
Sigma,
Waypoints,
type LucideIcon,
} from 'lucide-react'
/** What a learning block can be made into. One list for the insert menu, a
* block's own kind switcher and Dito's "generate here" menu, so the three
* never offer different things. */
export interface LearningKind {
kind: string
label: string
alias: string
Icon: LucideIcon
/** What the prompt box asks for. */
placeholder: string
}
export const LEARNING_KINDS: LearningKind[] = [
{
kind: 'mermaid',
label: 'Diagram',
alias: '图解',
Icon: Network,
placeholder: 'What should the diagram show?',
},
{
kind: 'timeline',
label: 'Timeline',
alias: '时间线',
Icon: ListOrdered,
placeholder: 'Which events, in what span?',
},
{
kind: 'concept_map',
label: 'Concept map',
alias: '概念图',
Icon: Waypoints,
placeholder: 'Which concepts should it connect?',
},
{
kind: 'quiz',
label: 'Quiz me',
alias: '测验',
Icon: CheckSquare,
placeholder: 'What should the questions check?',
},
{
kind: 'flashcards',
label: 'Flash Cards',
alias: '闪卡',
Icon: Layers,
placeholder: 'What should the cards help you remember?',
},
{
kind: 'image',
label: 'Generate image',
alias: '生成图片',
Icon: ImageIcon,
placeholder: 'Describe the picture',
},
{
kind: 'animation',
label: 'Animation',
alias: '动画',
Icon: Play,
placeholder: 'What should the animation explain?',
},
{
kind: 'geogebra',
label: 'Geometry',
alias: '几何',
Icon: Sigma,
placeholder: 'Which figure or construction?',
},
{
kind: 'audio',
label: 'Podcast',
alias: '播客',
Icon: Music,
placeholder: 'What should the episode cover?',
},
{
kind: 'research',
label: 'Research',
alias: '研究',
Icon: BookOpen,
placeholder: 'What should be researched?',
},
{
kind: 'task',
label: 'Linked task',
alias: '任务',
Icon: ListTodo,
placeholder: 'What needs doing?',
},
]
/** Kinds a block can only be filled with, never picked from a menu. */
const LEGACY: Record<string, { label: string; Icon: LucideIcon }> = {
visualization: { label: 'Visualization', Icon: Shapes },
media: { label: 'Media', Icon: ImageIcon },
code: { label: 'Code', Icon: Sigma },
}
export function learningKind(kind: string): LearningKind {
return (
LEARNING_KINDS.find(k => k.kind === kind) ?? {
kind,
alias: '',
placeholder: 'What should this block teach?',
...(LEGACY[kind] ?? { label: kind, Icon: Shapes }),
}
)
}
/** Whether a block already holds generated material (and its prompt can fold away). */
export function hasLearningContent(
kind: string,
markdown: string,
payload: Record<string, unknown>
) {
if (kind === 'task') return Boolean(payload.taskId)
return Boolean(
markdown.trim() ||
[
'questions',
'cards',
'events',
'nodes',
'commands',
'sub_topics',
'artifacts',
'workspace_items',
].some(key => Array.isArray(payload[key]) && (payload[key] as unknown[]).length) ||
payload.graph ||
payload.renderer
)
}
/** The settings a block's own Generate sends besides its prompt. */
export function learningGenerationConfig(
kind: string,
data: string
): Record<string, unknown> | undefined {
if (kind !== 'audio') return undefined
let generation: Record<string, unknown> = {}
try {
generation = (JSON.parse(data || '{}').generation || {}) as Record<string, unknown>
} catch {
/* Malformed data keeps the defaults. */
}
return {
target_minutes: Number(generation.target_minutes) || 1,
...(generation.host_voice ? { host_voice: generation.host_voice } : {}),
...(generation.expert_voice ? { expert_voice: generation.expert_voice } : {}),
}
}