Implement Phase C3 Enhancements for Progression Path Suggestion
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
- Incremented version to 0.8.185, reflecting the implementation of Phase C3 features. - Introduced the `POST /api/planning/progression-path-suggest` endpoint for generating exercise progression paths. - Enhanced the ExerciseProgressionGraphPanel with a new ExerciseProgressionPathBuilder for reviewing and saving paths. - Updated changelog to document the new capabilities in planning AI functionality.
This commit is contained in:
1 parent
a34e748be5
commit
a19ed02300
9 files changed
+655
-13
No files matched your search
@@ -84,6 +84,14 @@ export async function suggestPlanningExercises(body = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
/** Planungs-KI Phase C3: aufbauender Übungspfad für Progressionsgraphen. */
|
||||
export async function suggestProgressionPath(body = {}) {
|
||||
return request('/api/planning/progression-path-suggest', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
/** Rahmen-Slot → geplante Einheit (tiefe Kopie, origin_framework_slot_id). */
|
||||
export async function createTrainingUnitFromFrameworkSlot(data) {
|
||||
return request('/api/training-units/from-framework-slot', {
|
||||
|
||||
@@ -9,6 +9,7 @@ import SkillProfilePanel from './skills/SkillProfilePanel'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import { getTenantClubDependencyKey } from '../utils/activeClub'
|
||||
import ExercisePickerModal from './ExercisePickerModal'
|
||||
import ExerciseProgressionPathBuilder from './ExerciseProgressionPathBuilder'
|
||||
import { EXERCISE_VISIBILITY_FIELD_LABEL } from '../constants/exerciseGovernanceLabels'
|
||||
|
||||
const VIS_OPTIONS = [
|
||||
@@ -696,6 +697,13 @@ export default function ExerciseProgressionGraphPanel({
|
||||
defaultExpanded
|
||||
artifactType="progression_graph"
|
||||
/>
|
||||
<ExerciseProgressionPathBuilder
|
||||
graphId={selectedGraphId}
|
||||
disabled={busy}
|
||||
onSaved={async () => {
|
||||
await refreshEdges(selectedGraphId)
|
||||
}}
|
||||
/>
|
||||
<div className="card" style={{ marginBottom: '12px' }}>
|
||||
<h3 style={{ marginTop: 0, fontSize: '1rem' }}>Sequenz / Reihe anlegen</h3>
|
||||
<p style={{ fontSize: '12px', color: 'var(--text3)', marginTop: 0 }}>
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
/**
|
||||
* Planungs-KI Phase C3: Ziel → Übungspfad vorschlagen → in Progressionsgraph speichern.
|
||||
*/
|
||||
import React, { useCallback, useState } from 'react'
|
||||
import api from '../utils/api'
|
||||
|
||||
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
|
||||
return {
|
||||
exerciseId: step?.exercise_id != null ? Number(step.exercise_id) : null,
|
||||
exerciseTitle: (step?.title || '').trim() || (step?.exercise_id ? `Übung #${step.exercise_id}` : ''),
|
||||
variantId,
|
||||
variants,
|
||||
reasons: Array.isArray(step?.reasons) ? step.reasons : [],
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
const [pathSteps, setPathSteps] = useState([])
|
||||
|
||||
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
|
||||
})
|
||||
}, [])
|
||||
|
||||
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,
|
||||
progression_graph_id: Number(graphId),
|
||||
})
|
||||
const rows = (Array.isArray(res?.steps) ? res.steps : []).map(mapApiStepToRow)
|
||||
if (rows.length < 2) {
|
||||
throw new Error('Zu wenig Schritte im Vorschlag.')
|
||||
}
|
||||
setPathSteps(rows)
|
||||
setTargetSummary(res?.target_profile_summary || null)
|
||||
if (!segmentNotes.trim() && q) setSegmentNotes(q.slice(0, 400))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setError(e.message || 'Pfad-Vorschlag fehlgeschlagen')
|
||||
setPathSteps([])
|
||||
setTargetSummary(null)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const savePathToGraph = async () => {
|
||||
if (!graphId) {
|
||||
alert('Zuerst einen Graphen wählen.')
|
||||
return
|
||||
}
|
||||
const steps = pathSteps.filter((s) => s.exerciseId != null)
|
||||
if (steps.length < 2) {
|
||||
alert('Mindestens zwei Schritte mit Übung nötig.')
|
||||
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)
|
||||
if (typeof onSaved === 'function') await onSaved()
|
||||
alert(`${n} Nachfolger-Kante(n) aus KI-Pfad gespeichert.`)
|
||||
} 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 }}>
|
||||
Ziel in Freitext formulieren — die Planungs-KI schlägt eine aufbauende Übungsreihe vor. Nach Review als
|
||||
Nachfolger-Ketten in den aktiven Graph speichern (über mehrere Trainingspläne hinweg nutzbar).
|
||||
</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)}
|
||||
placeholder="z. B. sichere Reaktion im Partnertraining aufbauen …"
|
||||
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}
|
||||
|
||||
{targetSummary && pathSteps.length > 0 ? (
|
||||
<div style={{ marginTop: '10px', display: 'flex', flexWrap: 'wrap', gap: '6px' }}>
|
||||
{Array.isArray(targetSummary.focus_areas) &&
|
||||
targetSummary.focus_areas.slice(0, 2).map((fa) => (
|
||||
<span key={fa} className="exercise-tag">
|
||||
Fokus: {fa}
|
||||
</span>
|
||||
))}
|
||||
{Array.isArray(targetSummary.top_skills) &&
|
||||
targetSummary.top_skills.slice(0, 2).map((sk) => (
|
||||
<span key={sk.skill_id} className="exercise-tag">
|
||||
{sk.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{pathSteps.length > 0 ? (
|
||||
<>
|
||||
<div style={{ marginTop: '14px' }}>
|
||||
{pathSteps.map((step, idx) => (
|
||||
<div
|
||||
key={`${step.exerciseId}-${idx}`}
|
||||
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',
|
||||
}}
|
||||
>
|
||||
<div className="form-row" style={{ marginBottom: 0 }}>
|
||||
<label className="form-label">
|
||||
Schritt {idx + 1}
|
||||
{idx === 0 ? ' (Einstieg)' : idx === pathSteps.length - 1 ? ' (Zielnähe)' : ''}
|
||||
</label>
|
||||
<div style={{ fontSize: '13px' }}>
|
||||
<strong>{step.exerciseTitle}</strong>
|
||||
<span style={{ color: 'var(--text3)' }}> (#{step.exerciseId})</span>
|
||||
</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>
|
||||
<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>
|
||||
</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)
|
||||
}}
|
||||
>
|
||||
Vorschlag verwerfen
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user