mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:39:47 +08:00
Add rich text and learning blocks, media uploads, page trees, and revisioned notebook storage. Present AI suggestions at their target blocks with durable accept and dismiss actions. Unify saved outputs as Favorites with typed expandable blocks, stable source links, atomic batch insertion, nesting, dragging, and undo/redo. Validation: 99 frontend tests and 99 backend tests pass in an isolated snapshot, along with TypeScript, scoped ESLint, dependency architecture, and locale parity checks.
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type { NoteBlock } from '@/lib/notes-api'
|
|
|
|
export function resultLearningBlock(
|
|
result: Record<string, unknown>,
|
|
response = ''
|
|
): NoteBlock | undefined {
|
|
let kind = ''
|
|
let payload = result
|
|
const summary = result.summary as
|
|
{ results?: { qa_pair?: Record<string, unknown> }[] } | undefined
|
|
if (result.outline_preview && Array.isArray(result.sub_topics)) kind = 'research'
|
|
else if (Array.isArray(summary?.results)) {
|
|
kind = 'quiz'
|
|
payload = { questions: summary.results.flatMap(row => (row.qa_pair ? [row.qa_pair] : [])) }
|
|
} else if (result.renderer && result.payload) kind = 'visualization'
|
|
else if (Array.isArray(result.artifacts) && result.artifacts.length) kind = 'animation'
|
|
else if (Array.isArray(result.workspace_items) && result.workspace_items.length) kind = 'media'
|
|
if (!kind) return undefined
|
|
const questions = payload.questions as { question?: string; explanation?: string }[] | undefined
|
|
const markdown = questions
|
|
? questions
|
|
.map((q, i) => `${i + 1}. ${q.question || ''}\n\n${q.explanation || ''}`)
|
|
.join('\n\n')
|
|
: response || String(result.response || '')
|
|
return {
|
|
id: crypto.randomUUID(),
|
|
type: 'learning',
|
|
props: { kind, prompt: '', markdown, data: JSON.stringify(payload), sourceUrl: '' },
|
|
children: [],
|
|
}
|
|
}
|