2026-05-23 11:46:25 +02:00
|
|
|
/**
|
2026-05-23 12:59:46 +02:00
|
|
|
* Planungs-KI Phase C3/E3: Ziel → Übungspfad vorschlagen → Lücken mit KI anlegen → in Graph speichern.
|
2026-05-23 11:46:25 +02:00
|
|
|
*/
|
2026-05-23 12:59:46 +02:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react'
|
2026-05-23 11:46:25 +02:00
|
|
|
import api from '../utils/api'
|
2026-05-23 12:59:46 +02:00
|
|
|
import ExerciseAiQuickCreateModal from './exercises/ExerciseAiQuickCreateModal'
|
|
|
|
|
import ExerciseAiSuggestPreviewModal from './ExerciseAiSuggestPreviewModal'
|
|
|
|
|
import {
|
|
|
|
|
aiPreviewToQuickCreateDraft,
|
|
|
|
|
buildQuickCreateAiPreview,
|
|
|
|
|
buildQuickCreateExercisePayloadFromDraft,
|
|
|
|
|
} from '../utils/exerciseAiQuickCreate'
|
2026-05-23 11:46:25 +02:00
|
|
|
|
|
|
|
|
function emptyPathStep() {
|
|
|
|
|
return { exerciseId: null, exerciseTitle: '', variantId: null, variants: [], reasons: [] }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mapApiStepToRow(step) {
|
|
|
|
|
const variants = Array.isArray(step?.variants) ? step.variants : []
|
|
|
|
|
const rawVid = step?.variant_id ?? step?.suggested_variant_id ?? null
|
|
|
|
|
const variantId =
|
|
|
|
|
rawVid != null && Number.isFinite(Number(rawVid)) && Number(rawVid) > 0 ? Number(rawVid) : null
|
2026-05-23 12:32:14 +02:00
|
|
|
const isAiProposal = Boolean(step?.is_ai_proposal) || step?.exercise_id == null
|
2026-05-23 11:46:25 +02:00
|
|
|
return {
|
|
|
|
|
exerciseId: step?.exercise_id != null ? Number(step.exercise_id) : null,
|
2026-05-23 12:32:14 +02:00
|
|
|
proposalKey: step?.proposal_key || null,
|
|
|
|
|
exerciseTitle:
|
|
|
|
|
(step?.title || '').trim() ||
|
|
|
|
|
(step?.exercise_id ? `Übung #${step.exercise_id}` : 'KI-Vorschlag'),
|
|
|
|
|
variantId: isAiProposal ? null : variantId,
|
|
|
|
|
variants: isAiProposal ? [] : variants,
|
2026-05-23 11:46:25 +02:00
|
|
|
reasons: Array.isArray(step?.reasons) ? step.reasons : [],
|
2026-05-23 12:02:57 +02:00
|
|
|
isBridge: Boolean(step?.is_bridge),
|
2026-05-23 12:32:14 +02:00
|
|
|
isAiProposal,
|
|
|
|
|
aiSuggestion: step?.ai_suggestion || null,
|
2026-05-23 12:02:57 +02:00
|
|
|
semanticScore: step?.semantic_score,
|
2026-05-23 12:59:46 +02:00
|
|
|
isOffTopic: false,
|
2026-05-23 11:46:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 12:59:46 +02:00
|
|
|
function mapCreatedExerciseToRow(ex, offer) {
|
|
|
|
|
return {
|
|
|
|
|
exerciseId: Number(ex.id),
|
|
|
|
|
proposalKey: null,
|
|
|
|
|
exerciseTitle: (ex.title || offer?.title_hint || '').trim() || `Übung #${ex.id}`,
|
|
|
|
|
variantId: null,
|
|
|
|
|
variants: [],
|
|
|
|
|
reasons: ['Neu angelegt zur Schließung einer Pfad-Lücke'],
|
|
|
|
|
isBridge: true,
|
|
|
|
|
isAiProposal: false,
|
|
|
|
|
aiSuggestion: null,
|
|
|
|
|
semanticScore: null,
|
|
|
|
|
isOffTopic: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const OFFER_SOURCE_LABELS = {
|
|
|
|
|
unfilled_gap: 'Lücke',
|
|
|
|
|
off_topic: 'Themenfremd',
|
|
|
|
|
llm_suggested: 'QS-Empfehlung',
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 11:46:25 +02:00
|
|
|
export default function ExerciseProgressionPathBuilder({
|
|
|
|
|
graphId,
|
|
|
|
|
disabled = false,
|
|
|
|
|
onSaved,
|
|
|
|
|
}) {
|
|
|
|
|
const [goalQuery, setGoalQuery] = useState('')
|
|
|
|
|
const [maxSteps, setMaxSteps] = useState(5)
|
|
|
|
|
const [segmentNotes, setSegmentNotes] = useState('')
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
const [saving, setSaving] = useState(false)
|
|
|
|
|
const [error, setError] = useState('')
|
|
|
|
|
const [targetSummary, setTargetSummary] = useState(null)
|
2026-05-23 12:02:57 +02:00
|
|
|
const [semanticBrief, setSemanticBrief] = useState(null)
|
|
|
|
|
const [pathQa, setPathQa] = useState(null)
|
2026-05-23 11:46:25 +02:00
|
|
|
const [pathSteps, setPathSteps] = useState([])
|
2026-05-23 12:59:46 +02:00
|
|
|
const [gapFillOffers, setGapFillOffers] = useState([])
|
|
|
|
|
const [focusAreas, setFocusAreas] = useState([])
|
|
|
|
|
|
|
|
|
|
const [quickCreateOpen, setQuickCreateOpen] = useState(false)
|
|
|
|
|
const [activeOffer, setActiveOffer] = useState(null)
|
|
|
|
|
const [quickTitle, setQuickTitle] = useState('')
|
|
|
|
|
const [quickSketch, setQuickSketch] = useState('')
|
|
|
|
|
const [quickFocusAreaId, setQuickFocusAreaId] = useState('')
|
|
|
|
|
const [quickCreateDraft, setQuickCreateDraft] = useState(null)
|
|
|
|
|
const [quickSaving, setQuickSaving] = useState(false)
|
|
|
|
|
const [quickAiError, setQuickAiError] = useState('')
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
let cancelled = false
|
|
|
|
|
api
|
|
|
|
|
.listFocusAreas({ status: 'active' })
|
|
|
|
|
.then((rows) => {
|
|
|
|
|
if (!cancelled) setFocusAreas(Array.isArray(rows) ? rows : [])
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) setFocusAreas([])
|
|
|
|
|
})
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
2026-05-23 11:46:25 +02:00
|
|
|
|
|
|
|
|
const patchStep = useCallback((idx, patch) => {
|
|
|
|
|
setPathSteps((prev) => prev.map((row, i) => (i === idx ? { ...row, ...patch } : row)))
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const removeStep = useCallback((idx) => {
|
|
|
|
|
setPathSteps((prev) => (prev.length <= 2 ? prev : prev.filter((_, i) => i !== idx)))
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const moveStep = useCallback((idx, dir) => {
|
|
|
|
|
setPathSteps((prev) => {
|
|
|
|
|
const j = idx + dir
|
|
|
|
|
if (j < 0 || j >= prev.length) return prev
|
|
|
|
|
const next = [...prev]
|
|
|
|
|
const t = next[idx]
|
|
|
|
|
next[idx] = next[j]
|
|
|
|
|
next[j] = t
|
|
|
|
|
return next
|
|
|
|
|
})
|
|
|
|
|
}, [])
|
|
|
|
|
|
2026-05-23 12:59:46 +02:00
|
|
|
const applyOffTopicFlags = (rows, qa) => {
|
|
|
|
|
const off = Array.isArray(qa?.off_topic_steps) ? qa.off_topic_steps : []
|
|
|
|
|
const indices = new Set(off.map((o) => Number(o.step_index)).filter(Number.isFinite))
|
|
|
|
|
return rows.map((row, idx) => ({ ...row, isOffTopic: indices.has(idx) }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const insertExerciseFromOffer = useCallback((created, offer) => {
|
|
|
|
|
const row = mapCreatedExerciseToRow(created, offer)
|
|
|
|
|
setPathSteps((prev) => {
|
|
|
|
|
let next = [...prev]
|
|
|
|
|
const afterIdx = Number(offer?.insert_after_index)
|
|
|
|
|
const replaceIdx =
|
|
|
|
|
offer?.replace_step_index != null ? Number(offer.replace_step_index) : null
|
|
|
|
|
|
|
|
|
|
if (Number.isFinite(replaceIdx) && replaceIdx >= 0 && replaceIdx < next.length) {
|
|
|
|
|
next.splice(replaceIdx, 1, row)
|
|
|
|
|
} else if (Number.isFinite(afterIdx) && afterIdx >= 0 && afterIdx < next.length) {
|
|
|
|
|
next.splice(afterIdx + 1, 0, row)
|
|
|
|
|
} else {
|
|
|
|
|
next.push(row)
|
|
|
|
|
}
|
|
|
|
|
return applyOffTopicFlags(next, pathQa)
|
|
|
|
|
})
|
|
|
|
|
setGapFillOffers((prev) => prev.filter((o) => o.offer_id !== offer?.offer_id))
|
|
|
|
|
}, [pathQa])
|
|
|
|
|
|
|
|
|
|
const closeQuickCreate = () => {
|
|
|
|
|
if (quickSaving) return
|
|
|
|
|
setQuickCreateOpen(false)
|
|
|
|
|
setActiveOffer(null)
|
|
|
|
|
setQuickCreateDraft(null)
|
|
|
|
|
setQuickAiError('')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const openOfferQuickCreate = (offer) => {
|
|
|
|
|
setActiveOffer(offer)
|
|
|
|
|
setQuickTitle((offer?.title_hint || '').trim())
|
|
|
|
|
setQuickSketch((offer?.sketch || '').trim())
|
|
|
|
|
setQuickFocusAreaId('')
|
|
|
|
|
setQuickCreateDraft(null)
|
|
|
|
|
setQuickAiError('')
|
|
|
|
|
|
|
|
|
|
if (offer?.has_ai_payload && offer?.ai_suggestion) {
|
|
|
|
|
const preview = buildQuickCreateAiPreview(offer.ai_suggestion, {
|
|
|
|
|
sketchPlain: (offer?.sketch || '').trim(),
|
|
|
|
|
})
|
|
|
|
|
if (preview.hasSummaryProposal || preview.hasSkillChoices || preview.hasInstructionChoices) {
|
|
|
|
|
const focusId = focusAreas[0]?.id ? String(focusAreas[0].id) : ''
|
|
|
|
|
setQuickFocusAreaId(focusId)
|
|
|
|
|
setQuickCreateDraft(
|
|
|
|
|
aiPreviewToQuickCreateDraft(preview, {
|
|
|
|
|
title: (offer?.title_hint || '').trim(),
|
|
|
|
|
focusAreaId: focusId ? Number(focusId) : '',
|
|
|
|
|
sketchPlain: (offer?.sketch || '').trim(),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
setQuickCreateOpen(false)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setQuickCreateOpen(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const runQuickCreateAiSuggest = async () => {
|
|
|
|
|
const title = (quickTitle || '').trim()
|
|
|
|
|
if (title.length < 3) {
|
|
|
|
|
alert('Titel: mindestens 3 Zeichen.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const sketch = (quickSketch || '').trim()
|
|
|
|
|
const focusId = parseInt(String(quickFocusAreaId).trim(), 10)
|
|
|
|
|
if (!Number.isFinite(focusId) || focusId < 1) {
|
|
|
|
|
alert('Bitte einen Fokusbereich wählen.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const focusRow = (focusAreas || []).find((x) => Number(x.id) === focusId)
|
|
|
|
|
const focusHint = (focusRow?.name || '').trim()
|
|
|
|
|
|
|
|
|
|
setQuickAiError('')
|
|
|
|
|
setQuickCreateDraft(null)
|
|
|
|
|
setQuickSaving(true)
|
|
|
|
|
try {
|
|
|
|
|
const aiRes = await api.suggestExerciseAi({
|
|
|
|
|
title,
|
|
|
|
|
goal: sketch || undefined,
|
|
|
|
|
execution: '',
|
|
|
|
|
preparation: '',
|
|
|
|
|
trainer_notes: '',
|
|
|
|
|
focus_area_hint: focusHint || undefined,
|
|
|
|
|
focus_areas_context: [{ focus_area_id: focusId, is_primary: true }],
|
|
|
|
|
include_summary: true,
|
|
|
|
|
include_skills: true,
|
|
|
|
|
include_instructions: true,
|
|
|
|
|
})
|
|
|
|
|
const preview = buildQuickCreateAiPreview(aiRes, { sketchPlain: sketch })
|
|
|
|
|
if (!preview.hasSummaryProposal && !preview.hasInstructionChoices && !preview.hasSkillChoices) {
|
|
|
|
|
throw new Error('Die KI lieferte keinen verwertbaren Vorschlag.')
|
|
|
|
|
}
|
|
|
|
|
setQuickCreateDraft(
|
|
|
|
|
aiPreviewToQuickCreateDraft(preview, { title, focusAreaId: focusId, sketchPlain: sketch }),
|
|
|
|
|
)
|
|
|
|
|
setQuickCreateOpen(false)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
const msg = e?.message || String(e)
|
|
|
|
|
setQuickAiError(msg)
|
|
|
|
|
alert(msg || 'KI-Vorschlag fehlgeschlagen')
|
|
|
|
|
} finally {
|
|
|
|
|
setQuickSaving(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const applyQuickCreateDraft = async () => {
|
|
|
|
|
if (!quickCreateDraft || !activeOffer) return
|
|
|
|
|
setQuickSaving(true)
|
|
|
|
|
setQuickAiError('')
|
|
|
|
|
try {
|
|
|
|
|
const payload = buildQuickCreateExercisePayloadFromDraft(quickCreateDraft)
|
|
|
|
|
const created = await api.createExercise(payload)
|
|
|
|
|
if (!created?.id) throw new Error('Anlegen fehlgeschlagen')
|
|
|
|
|
insertExerciseFromOffer(created, activeOffer)
|
|
|
|
|
setQuickCreateDraft(null)
|
|
|
|
|
setActiveOffer(null)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
const msg = e?.message || String(e)
|
|
|
|
|
setQuickAiError(msg)
|
|
|
|
|
alert(msg || 'Übung konnte nicht angelegt werden')
|
|
|
|
|
} finally {
|
|
|
|
|
setQuickSaving(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 11:46:25 +02:00
|
|
|
const suggestPath = async () => {
|
|
|
|
|
const q = (goalQuery || '').trim()
|
|
|
|
|
if (q.length < 3) {
|
|
|
|
|
alert('Ziel-Anfrage: mindestens 3 Zeichen.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (!graphId) {
|
|
|
|
|
alert('Zuerst einen Graphen wählen.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setLoading(true)
|
|
|
|
|
setError('')
|
|
|
|
|
try {
|
|
|
|
|
const res = await api.suggestProgressionPath({
|
|
|
|
|
query: q,
|
|
|
|
|
max_steps: Number(maxSteps),
|
|
|
|
|
include_llm_intent: true,
|
2026-05-23 12:02:57 +02:00
|
|
|
include_path_qa: true,
|
|
|
|
|
include_llm_path_qa: true,
|
2026-05-23 12:59:46 +02:00
|
|
|
include_path_reorder: true,
|
|
|
|
|
include_ai_gap_fill: true,
|
2026-05-23 11:46:25 +02:00
|
|
|
progression_graph_id: Number(graphId),
|
|
|
|
|
})
|
2026-05-23 12:59:46 +02:00
|
|
|
const qa = res?.path_qa || null
|
|
|
|
|
const rows = applyOffTopicFlags(
|
|
|
|
|
(Array.isArray(res?.steps) ? res.steps : []).map(mapApiStepToRow),
|
|
|
|
|
qa,
|
|
|
|
|
)
|
2026-05-23 11:46:25 +02:00
|
|
|
if (rows.length < 2) {
|
|
|
|
|
throw new Error('Zu wenig Schritte im Vorschlag.')
|
|
|
|
|
}
|
|
|
|
|
setPathSteps(rows)
|
|
|
|
|
setTargetSummary(res?.target_profile_summary || null)
|
2026-05-23 12:02:57 +02:00
|
|
|
setSemanticBrief(res?.semantic_brief_summary || null)
|
2026-05-23 12:59:46 +02:00
|
|
|
setPathQa(qa)
|
|
|
|
|
setGapFillOffers(
|
|
|
|
|
Array.isArray(res?.gap_fill_offers)
|
|
|
|
|
? res.gap_fill_offers
|
|
|
|
|
: Array.isArray(qa?.gap_fill_offers)
|
|
|
|
|
? qa.gap_fill_offers
|
|
|
|
|
: [],
|
|
|
|
|
)
|
2026-05-23 11:46:25 +02:00
|
|
|
if (!segmentNotes.trim() && q) setSegmentNotes(q.slice(0, 400))
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
setError(e.message || 'Pfad-Vorschlag fehlgeschlagen')
|
|
|
|
|
setPathSteps([])
|
|
|
|
|
setTargetSummary(null)
|
2026-05-23 12:02:57 +02:00
|
|
|
setSemanticBrief(null)
|
|
|
|
|
setPathQa(null)
|
2026-05-23 12:59:46 +02:00
|
|
|
setGapFillOffers([])
|
2026-05-23 11:46:25 +02:00
|
|
|
} finally {
|
|
|
|
|
setLoading(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const savePathToGraph = async () => {
|
|
|
|
|
if (!graphId) {
|
|
|
|
|
alert('Zuerst einen Graphen wählen.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const steps = pathSteps.filter((s) => s.exerciseId != null)
|
2026-05-23 12:32:14 +02:00
|
|
|
const skippedAi = pathSteps.filter((s) => s.isAiProposal).length
|
2026-05-23 11:46:25 +02:00
|
|
|
if (steps.length < 2) {
|
2026-05-23 12:32:14 +02:00
|
|
|
alert(
|
|
|
|
|
skippedAi > 0
|
|
|
|
|
? 'Mindestens zwei gespeicherte Übungen nötig. KI-Vorschläge zuerst als Übung anlegen.'
|
2026-05-23 12:59:46 +02:00
|
|
|
: 'Mindestens zwei Schritte mit Übung nötig.',
|
2026-05-23 12:32:14 +02:00
|
|
|
)
|
2026-05-23 11:46:25 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const n = steps.length - 1
|
|
|
|
|
const noteRaw = segmentNotes.trim()
|
|
|
|
|
const segment_notes = Array.from({ length: n }, (_, i) => {
|
|
|
|
|
const reasons = (steps[i + 1]?.reasons || []).slice(0, 2).join(' · ')
|
|
|
|
|
if (reasons) return reasons
|
|
|
|
|
return noteRaw || null
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setSaving(true)
|
|
|
|
|
setError('')
|
|
|
|
|
try {
|
|
|
|
|
await api.createExerciseProgressionSequence(Number(graphId), {
|
|
|
|
|
steps: steps.map((s) => ({
|
|
|
|
|
exercise_id: s.exerciseId,
|
|
|
|
|
variant_id: s.variantId || null,
|
|
|
|
|
})),
|
|
|
|
|
segment_notes,
|
|
|
|
|
})
|
|
|
|
|
setPathSteps([])
|
|
|
|
|
setTargetSummary(null)
|
2026-05-23 12:02:57 +02:00
|
|
|
setSemanticBrief(null)
|
|
|
|
|
setPathQa(null)
|
2026-05-23 12:59:46 +02:00
|
|
|
setGapFillOffers([])
|
2026-05-23 11:46:25 +02:00
|
|
|
if (typeof onSaved === 'function') await onSaved()
|
2026-05-23 12:32:14 +02:00
|
|
|
const msg =
|
|
|
|
|
skippedAi > 0
|
|
|
|
|
? `${n} Kante(n) gespeichert. ${skippedAi} KI-Vorschlag/Vorschläge nicht im Graph (noch nicht angelegt).`
|
|
|
|
|
: `${n} Nachfolger-Kante(n) aus KI-Pfad gespeichert.`
|
|
|
|
|
alert(msg)
|
2026-05-23 11:46:25 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
setError(e.message || 'Speichern fehlgeschlagen')
|
|
|
|
|
} finally {
|
|
|
|
|
setSaving(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="card"
|
|
|
|
|
style={{
|
|
|
|
|
marginBottom: '12px',
|
|
|
|
|
borderColor: 'color-mix(in srgb, var(--accent) 35%, var(--border))',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<h3 style={{ marginTop: 0, fontSize: '1rem' }}>KI: Pfad zum Ziel</h3>
|
|
|
|
|
<p style={{ fontSize: '12px', color: 'var(--text3)', marginTop: 0, lineHeight: 1.45 }}>
|
2026-05-23 12:02:57 +02:00
|
|
|
Ziel in Freitext formulieren — die Planungs-KI schlägt eine semantisch passende, aufbauende Reihenfolge vor,
|
2026-05-23 12:59:46 +02:00
|
|
|
prüft Lücken (ggf. Brücken-Übungen) und optional per LLM-QS. Fehlende Schritte können mit KI als Übung angelegt werden.
|
2026-05-23 11:46:25 +02:00
|
|
|
</p>
|
|
|
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px', alignItems: 'flex-end' }}>
|
|
|
|
|
<div className="form-row" style={{ flex: '2 1 240px', marginBottom: 0 }}>
|
|
|
|
|
<label className="form-label">Ziel / Entwicklungsrichtung</label>
|
|
|
|
|
<input
|
|
|
|
|
className="form-input"
|
|
|
|
|
value={goalQuery}
|
|
|
|
|
onChange={(e) => setGoalQuery(e.target.value)}
|
2026-05-23 12:59:46 +02:00
|
|
|
placeholder="z. B. Von Erlernen bis zur Perfektion des Fußtritts Mae Geri …"
|
2026-05-23 11:46:25 +02:00
|
|
|
disabled={disabled || loading || saving}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-row" style={{ flex: '0 1 120px', marginBottom: 0 }}>
|
|
|
|
|
<label className="form-label">Schritte</label>
|
|
|
|
|
<input
|
|
|
|
|
type="number"
|
|
|
|
|
min={2}
|
|
|
|
|
max={10}
|
|
|
|
|
className="form-input"
|
|
|
|
|
value={maxSteps}
|
|
|
|
|
onChange={(e) => setMaxSteps(Math.max(2, Math.min(10, Number(e.target.value) || 5)))}
|
|
|
|
|
disabled={disabled || loading || saving}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
disabled={disabled || loading || saving || !graphId}
|
|
|
|
|
onClick={suggestPath}
|
|
|
|
|
>
|
|
|
|
|
{loading ? 'Vorschlag …' : 'Pfad vorschlagen'}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{error ? (
|
|
|
|
|
<p className="form-error" style={{ marginTop: '10px' }}>
|
|
|
|
|
{error}
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
|
2026-05-23 12:02:57 +02:00
|
|
|
{(semanticBrief || targetSummary) && pathSteps.length > 0 ? (
|
2026-05-23 11:46:25 +02:00
|
|
|
<div style={{ marginTop: '10px', display: 'flex', flexWrap: 'wrap', gap: '6px' }}>
|
2026-05-23 12:02:57 +02:00
|
|
|
{semanticBrief?.primary_topic ? (
|
|
|
|
|
<span className="exercise-tag" style={{ borderColor: 'var(--accent)' }}>
|
|
|
|
|
Thema: {semanticBrief.primary_topic}
|
|
|
|
|
</span>
|
|
|
|
|
) : null}
|
|
|
|
|
{Array.isArray(semanticBrief?.development_arc) &&
|
|
|
|
|
semanticBrief.development_arc.slice(0, 3).map((phase) => (
|
|
|
|
|
<span key={phase} className="exercise-tag">
|
|
|
|
|
{phase}
|
|
|
|
|
</span>
|
|
|
|
|
))}
|
|
|
|
|
{Array.isArray(targetSummary?.focus_areas) &&
|
|
|
|
|
targetSummary.focus_areas.slice(0, 1).map((fa) => (
|
2026-05-23 11:46:25 +02:00
|
|
|
<span key={fa} className="exercise-tag">
|
|
|
|
|
Fokus: {fa}
|
|
|
|
|
</span>
|
|
|
|
|
))}
|
2026-05-23 12:02:57 +02:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{pathQa && pathSteps.length > 0 ? (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
marginTop: '10px',
|
|
|
|
|
padding: '10px 12px',
|
|
|
|
|
borderRadius: '8px',
|
|
|
|
|
background: pathQa.overall_ok ? 'color-mix(in srgb, var(--accent) 8%, var(--surface2))' : 'color-mix(in srgb, var(--danger) 8%, var(--surface2))',
|
|
|
|
|
fontSize: '12px',
|
|
|
|
|
lineHeight: 1.45,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<strong>
|
|
|
|
|
Pfad-QS: {pathQa.overall_ok ? 'OK' : 'Hinweise'}
|
|
|
|
|
{pathQa.quality_score != null ? ` (${Math.round(Number(pathQa.quality_score) * 100)} %)` : ''}
|
|
|
|
|
</strong>
|
|
|
|
|
{pathQa.topic_coverage ? (
|
|
|
|
|
<p style={{ margin: '6px 0 0', color: 'var(--text2)' }}>{pathQa.topic_coverage}</p>
|
|
|
|
|
) : null}
|
|
|
|
|
{Array.isArray(pathQa.issues) && pathQa.issues.length > 0 ? (
|
|
|
|
|
<ul style={{ margin: '6px 0 0', paddingLeft: '16px', color: 'var(--text2)' }}>
|
|
|
|
|
{pathQa.issues.slice(0, 4).map((issue) => (
|
|
|
|
|
<li key={issue}>{issue}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
) : null}
|
|
|
|
|
{Number(pathQa.bridge_insert_count) > 0 ? (
|
|
|
|
|
<p style={{ margin: '6px 0 0', color: 'var(--accent-dark)' }}>
|
2026-05-23 12:32:14 +02:00
|
|
|
{pathQa.bridge_insert_count} Brücken-Übung(en) aus der Bibliothek eingefügt.
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
2026-05-23 12:59:46 +02:00
|
|
|
{Number(pathQa.off_topic_count) > 0 ? (
|
|
|
|
|
<p style={{ margin: '6px 0 0', color: 'var(--danger)' }}>
|
|
|
|
|
{pathQa.off_topic_count} Schritt(e) ohne Bezug zum Pfad-Thema — siehe Lücken-Angebote unten.
|
2026-05-23 12:32:14 +02:00
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
{pathQa.reorder_applied ? (
|
|
|
|
|
<p style={{ margin: '6px 0 0', color: 'var(--text2)' }}>
|
|
|
|
|
Reihenfolge nach QS angepasst.
|
|
|
|
|
{Array.isArray(pathQa.reorder_notes) && pathQa.reorder_notes[0]
|
|
|
|
|
? ` ${pathQa.reorder_notes[0]}`
|
|
|
|
|
: ''}
|
2026-05-23 12:02:57 +02:00
|
|
|
</p>
|
|
|
|
|
) : null}
|
2026-05-23 12:59:46 +02:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{gapFillOffers.length > 0 ? (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
marginTop: '12px',
|
|
|
|
|
padding: '12px',
|
|
|
|
|
borderRadius: '8px',
|
|
|
|
|
border: '1px solid color-mix(in srgb, var(--accent) 40%, var(--border))',
|
|
|
|
|
background: 'color-mix(in srgb, var(--accent) 5%, var(--surface))',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<strong style={{ fontSize: '13px' }}>Fehlende Schritte — mit KI anlegen</strong>
|
|
|
|
|
<p style={{ fontSize: '12px', color: 'var(--text3)', margin: '6px 0 10px', lineHeight: 1.45 }}>
|
|
|
|
|
Die QS hat Lücken erkannt. Vorschlag prüfen, als Übung anlegen und in den Pfad einfügen.
|
|
|
|
|
</p>
|
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}>
|
|
|
|
|
{gapFillOffers.map((offer) => (
|
|
|
|
|
<div
|
|
|
|
|
key={offer.offer_id}
|
|
|
|
|
style={{
|
|
|
|
|
padding: '10px 12px',
|
|
|
|
|
borderRadius: '8px',
|
|
|
|
|
background: 'var(--surface2)',
|
|
|
|
|
border: '1px solid var(--border)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'flex-start' }}>
|
|
|
|
|
<div style={{ flex: '1 1 200px' }}>
|
|
|
|
|
<span className="exercise-tag" style={{ marginBottom: '6px', display: 'inline-block' }}>
|
|
|
|
|
{OFFER_SOURCE_LABELS[offer.source] || offer.source || 'Lücke'}
|
|
|
|
|
{offer.phase ? ` · ${offer.phase}` : ''}
|
|
|
|
|
</span>
|
|
|
|
|
<div style={{ fontSize: '13px', fontWeight: 600 }}>{offer.title_hint}</div>
|
|
|
|
|
{offer.rationale ? (
|
|
|
|
|
<p style={{ fontSize: '12px', color: 'var(--text2)', margin: '4px 0 0' }}>{offer.rationale}</p>
|
|
|
|
|
) : null}
|
|
|
|
|
{offer.from_title && offer.to_title ? (
|
|
|
|
|
<p style={{ fontSize: '11px', color: 'var(--text3)', margin: '4px 0 0' }}>
|
|
|
|
|
Zwischen „{offer.from_title}“ und „{offer.to_title}“
|
|
|
|
|
{offer.replace_step_index != null ? ' (ersetzt themenfremden Schritt)' : ''}
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
style={{ fontSize: '12px', flexShrink: 0 }}
|
|
|
|
|
disabled={quickSaving}
|
|
|
|
|
onClick={() => openOfferQuickCreate(offer)}
|
|
|
|
|
>
|
|
|
|
|
Mit KI anlegen
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-23 11:46:25 +02:00
|
|
|
))}
|
2026-05-23 12:59:46 +02:00
|
|
|
</div>
|
2026-05-23 11:46:25 +02:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{pathSteps.length > 0 ? (
|
|
|
|
|
<>
|
|
|
|
|
<div style={{ marginTop: '14px' }}>
|
|
|
|
|
{pathSteps.map((step, idx) => (
|
|
|
|
|
<div
|
2026-05-23 12:59:46 +02:00
|
|
|
key={`${step.exerciseId}-${step.proposalKey || ''}-${idx}`}
|
2026-05-23 11:46:25 +02:00
|
|
|
style={{
|
|
|
|
|
display: 'grid',
|
|
|
|
|
gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))',
|
|
|
|
|
gap: '10px',
|
|
|
|
|
alignItems: 'end',
|
|
|
|
|
marginBottom: '12px',
|
|
|
|
|
paddingBottom: '12px',
|
|
|
|
|
borderBottom: idx < pathSteps.length - 1 ? '1px dashed var(--border)' : 'none',
|
2026-05-23 12:59:46 +02:00
|
|
|
background: step.isOffTopic
|
|
|
|
|
? 'color-mix(in srgb, var(--danger) 6%, transparent)'
|
|
|
|
|
: undefined,
|
|
|
|
|
borderRadius: step.isOffTopic ? '8px' : undefined,
|
|
|
|
|
padding: step.isOffTopic ? '8px' : undefined,
|
2026-05-23 11:46:25 +02:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="form-row" style={{ marginBottom: 0 }}>
|
|
|
|
|
<label className="form-label">
|
|
|
|
|
Schritt {idx + 1}
|
2026-05-23 12:59:46 +02:00
|
|
|
{step.isOffTopic ? ' (themenfremd)' : ''}
|
2026-05-23 12:32:14 +02:00
|
|
|
{step.isAiProposal ? ' (KI-Neu)' : step.isBridge ? ' (Brücke)' : ''}
|
2026-05-23 12:59:46 +02:00
|
|
|
{!step.isAiProposal && !step.isOffTopic && idx === 0 ? ' (Einstieg)' : ''}
|
2026-05-23 12:32:14 +02:00
|
|
|
{!step.isAiProposal && idx === pathSteps.length - 1 ? ' (Zielnähe)' : ''}
|
2026-05-23 11:46:25 +02:00
|
|
|
</label>
|
|
|
|
|
<div style={{ fontSize: '13px' }}>
|
|
|
|
|
<strong>{step.exerciseTitle}</strong>
|
2026-05-23 12:32:14 +02:00
|
|
|
{step.exerciseId ? (
|
|
|
|
|
<span style={{ color: 'var(--text3)' }}> (#{step.exerciseId})</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span style={{ color: 'var(--text3)' }}> — noch nicht in Bibliothek</span>
|
|
|
|
|
)}
|
2026-05-23 11:46:25 +02:00
|
|
|
</div>
|
|
|
|
|
{step.reasons?.length ? (
|
|
|
|
|
<ul
|
|
|
|
|
style={{
|
|
|
|
|
margin: '6px 0 0',
|
|
|
|
|
paddingLeft: '16px',
|
|
|
|
|
fontSize: '11px',
|
|
|
|
|
color: 'var(--accent-dark)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{step.reasons.slice(0, 2).map((r) => (
|
|
|
|
|
<li key={r}>{r}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-row" style={{ marginBottom: 0 }}>
|
|
|
|
|
<label className="form-label">Variante</label>
|
2026-05-23 12:32:14 +02:00
|
|
|
{step.isAiProposal ? (
|
|
|
|
|
<p style={{ fontSize: '12px', color: 'var(--text3)', margin: 0 }}>
|
|
|
|
|
Nach Anlage der Übung im Graph wählbar.
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<select
|
|
|
|
|
className="form-input"
|
|
|
|
|
value={step.variantId ?? ''}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
patchStep(idx, {
|
|
|
|
|
variantId: e.target.value === '' ? null : parseInt(e.target.value, 10),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
disabled={!step.exerciseId}
|
|
|
|
|
>
|
|
|
|
|
<option value="">Gesamte Übung</option>
|
|
|
|
|
{(step.variants || []).map((v) => (
|
|
|
|
|
<option key={v.id} value={v.id}>
|
|
|
|
|
{v.variant_name || `Variante #${v.id}`}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
)}
|
2026-05-23 11:46:25 +02:00
|
|
|
</div>
|
|
|
|
|
<div style={{ display: 'flex', gap: '6px', flexWrap: 'wrap' }}>
|
|
|
|
|
<button type="button" className="btn" style={{ fontSize: '12px', padding: '4px 8px' }} onClick={() => moveStep(idx, -1)}>
|
|
|
|
|
↑
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" className="btn" style={{ fontSize: '12px', padding: '4px 8px' }} onClick={() => moveStep(idx, 1)}>
|
|
|
|
|
↓
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" className="btn" style={{ fontSize: '12px', padding: '4px 8px' }} onClick={() => removeStep(idx)}>
|
|
|
|
|
Entfernen
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-row">
|
|
|
|
|
<label className="form-label">Notiz für Kanten (Fallback, optional)</label>
|
|
|
|
|
<textarea
|
|
|
|
|
className="form-input"
|
|
|
|
|
rows={2}
|
|
|
|
|
value={segmentNotes}
|
|
|
|
|
onChange={(e) => setSegmentNotes(e.target.value)}
|
|
|
|
|
placeholder="Wird pro Kante genutzt, wenn keine KI-Begründung vorliegt."
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px' }}>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-primary"
|
|
|
|
|
disabled={disabled || saving || pathSteps.filter((s) => s.exerciseId).length < 2}
|
|
|
|
|
onClick={savePathToGraph}
|
|
|
|
|
>
|
|
|
|
|
{saving ? 'Speichern …' : 'Pfad in Graph speichern'}
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-secondary"
|
|
|
|
|
disabled={loading || saving}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setPathSteps([])
|
|
|
|
|
setTargetSummary(null)
|
2026-05-23 12:59:46 +02:00
|
|
|
setSemanticBrief(null)
|
|
|
|
|
setPathQa(null)
|
|
|
|
|
setGapFillOffers([])
|
2026-05-23 11:46:25 +02:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Vorschlag verwerfen
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
2026-05-23 12:59:46 +02:00
|
|
|
|
|
|
|
|
<ExerciseAiQuickCreateModal
|
|
|
|
|
open={quickCreateOpen}
|
|
|
|
|
onClose={closeQuickCreate}
|
|
|
|
|
searchLabel={activeOffer?.title_hint || goalQuery}
|
|
|
|
|
title={quickTitle}
|
|
|
|
|
onTitleChange={setQuickTitle}
|
|
|
|
|
sketch={quickSketch}
|
|
|
|
|
onSketchChange={setQuickSketch}
|
|
|
|
|
focusAreaId={quickFocusAreaId}
|
|
|
|
|
onFocusAreaChange={setQuickFocusAreaId}
|
|
|
|
|
focusAreas={focusAreas}
|
|
|
|
|
catalogsReady={focusAreas.length > 0}
|
|
|
|
|
busy={quickSaving}
|
|
|
|
|
error={quickAiError}
|
|
|
|
|
onRunAi={runQuickCreateAiSuggest}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<ExerciseAiSuggestPreviewModal
|
|
|
|
|
draft={quickCreateDraft}
|
|
|
|
|
onDraftChange={setQuickCreateDraft}
|
|
|
|
|
onDiscard={() => {
|
|
|
|
|
setQuickCreateDraft(null)
|
|
|
|
|
if (activeOffer) setQuickCreateOpen(true)
|
|
|
|
|
}}
|
|
|
|
|
onApply={applyQuickCreateDraft}
|
|
|
|
|
focusAreas={focusAreas}
|
|
|
|
|
skillsCatalog={[]}
|
|
|
|
|
dialogTitle="Pfad-Lücke — KI-Entwurf bearbeiten"
|
|
|
|
|
hint="Texte anpassen, dann als Übung speichern und in den Pfad einfügen."
|
|
|
|
|
applyLabel={quickSaving ? 'Wird angelegt …' : 'Anlegen und in Pfad einfügen'}
|
|
|
|
|
applyDisabled={quickSaving}
|
|
|
|
|
zIndex={2100}
|
|
|
|
|
/>
|
2026-05-23 11:46:25 +02:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|