Add AI Suggestion Handling for Roadmap Gaps and Enhance Progression Graph Components
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m17s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 45s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m17s
- Implemented functions to resolve neighboring steps based on major indices and build AI context for unfilled roadmap stages. - Enhanced `try_suggest_ai_stage_step` to generate AI proposals for empty roadmap stages, improving user experience in gap filling. - Updated `build_gap_fill_offer` to utilize major step neighbors for better context in offers related to unfilled slots. - Added tests to ensure correct functionality of AI suggestion handling in the context of roadmap gaps. - Incremented application version to reflect these updates.
This commit is contained in:
1 parent
ee22b22970
commit
e0ddfa6ce5
5 files changed
+490
-48
No files matched your search
@@ -161,21 +161,76 @@ export function offerCanExpandSlots(draft, offer) {
|
||||
return (draft.slots?.length || 0) < SLOT_MAX
|
||||
}
|
||||
|
||||
const GAP_OFFER_SOURCE_PRIORITY = {
|
||||
roadmap_unfilled: 0,
|
||||
unfilled_gap: 1,
|
||||
llm_suggested: 2,
|
||||
off_topic: 3,
|
||||
}
|
||||
|
||||
export function collectGapOffersFromApiResponse(res) {
|
||||
const top = Array.isArray(res?.gap_fill_offers) ? res.gap_fill_offers : []
|
||||
if (top.length) return top
|
||||
const qa = res?.path_qa || {}
|
||||
const merged = [
|
||||
...(Array.isArray(res?.gap_fill_offers) ? res.gap_fill_offers : []),
|
||||
...(Array.isArray(qa?.gap_fill_offers) ? qa.gap_fill_offers : []),
|
||||
]
|
||||
const seen = new Set()
|
||||
return merged.filter((offer) => {
|
||||
const key = offer?.offer_id || `${offer?.source}-${offer?.title_hint}`
|
||||
if (!key || seen.has(key)) return false
|
||||
seen.add(key)
|
||||
return Array.isArray(qa?.gap_fill_offers) ? qa.gap_fill_offers : []
|
||||
}
|
||||
|
||||
/** Maximal ein Angebot pro Slot — Roadmap-Lücken vor Brücken/QS. */
|
||||
export function dedupeGapOffersBySlot(offers, draft) {
|
||||
const bySlot = new Map()
|
||||
for (const offer of offers || []) {
|
||||
const idx = resolveOfferSlotIndex(draft, offer)
|
||||
if (idx == null || !Number.isFinite(idx) || idx < 0) continue
|
||||
const existing = bySlot.get(idx)
|
||||
const prio = GAP_OFFER_SOURCE_PRIORITY[offer?.source] ?? 9
|
||||
const existingPrio = existing ? (GAP_OFFER_SOURCE_PRIORITY[existing?.source] ?? 9) : 99
|
||||
if (!existing || prio < existingPrio) {
|
||||
bySlot.set(idx, offer)
|
||||
}
|
||||
}
|
||||
return Array.from(bySlot.entries())
|
||||
.sort(([a], [b]) => a - b)
|
||||
.map(([, offer]) => offer)
|
||||
}
|
||||
|
||||
/** Angebote nur für Slots ohne belegte Primary (Bibliothek oder KI-Entwurf). */
|
||||
export function filterGapOffersForUnfilledSlots(draft, offers) {
|
||||
return (offers || []).filter((offer) => {
|
||||
const idx = resolveOfferSlotIndex(draft, offer)
|
||||
if (idx == null || idx < 0 || idx >= (draft?.slots?.length || 0)) return true
|
||||
const p = draft.slots[idx]?.primary
|
||||
if (p?.kind === 'library' && p.exerciseId != null) return false
|
||||
if (p?.kind === 'proposal') return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
export function syncSlotPhasesFromRoadmap(draft, progressionRoadmap) {
|
||||
if (!progressionRoadmap) return draft
|
||||
const majors = mapMajorStepsFromApi(progressionRoadmap)
|
||||
if (!majors.length) return draft
|
||||
const slots = (draft.slots || []).map((slot, i) => {
|
||||
const m = majors[i]
|
||||
if (!m) return slot
|
||||
return {
|
||||
...slot,
|
||||
phase: m.phase || slot.phase,
|
||||
learning_goal: m.learning_goal || slot.learning_goal,
|
||||
load_profile: m.load_profile?.length ? m.load_profile : slot.load_profile,
|
||||
success_criteria: m.success_criteria?.length ? m.success_criteria : slot.success_criteria,
|
||||
anti_patterns: m.anti_patterns?.length ? m.anti_patterns : slot.anti_patterns,
|
||||
exercise_type: m.exercise_type || slot.exercise_type,
|
||||
}
|
||||
})
|
||||
return syncProgressionRoadmapFromSlots({
|
||||
...draft,
|
||||
slots,
|
||||
progressionRoadmap,
|
||||
majorSteps: majors,
|
||||
maxSteps: Math.max(slots.length, majors.length),
|
||||
})
|
||||
}
|
||||
|
||||
export function slotsAsPathStepRows(draft) {
|
||||
return (draft.slots || []).map((slot) => ({
|
||||
exerciseId: slot.primary?.exerciseId ?? null,
|
||||
@@ -644,19 +699,23 @@ export function slotsToEvaluateSteps(draft) {
|
||||
|
||||
export function applyMatchStepsToSlots(draft, apiSteps) {
|
||||
const steps = Array.isArray(apiSteps) ? apiSteps : []
|
||||
const nextSlots = (draft.slots || []).map((slot) => ({ ...slot, primary: { ...slot.primary }, siblings: [...(slot.siblings || [])] }))
|
||||
const nextSlots = (draft.slots || []).map((slot) => ({
|
||||
...slot,
|
||||
primary: { ...slot.primary },
|
||||
siblings: [...(slot.siblings || [])],
|
||||
}))
|
||||
|
||||
for (const step of steps) {
|
||||
const idx =
|
||||
step.roadmap_major_step_index != null
|
||||
? Number(step.roadmap_major_step_index)
|
||||
: steps.indexOf(step)
|
||||
if (!Number.isFinite(idx) || idx < 0 || idx >= nextSlots.length) continue
|
||||
if (step.roadmap_major_step_index == null || !Number.isFinite(Number(step.roadmap_major_step_index))) {
|
||||
continue
|
||||
}
|
||||
const idx = Number(step.roadmap_major_step_index)
|
||||
if (idx < 0 || idx >= nextSlots.length) continue
|
||||
|
||||
const isProposal = Boolean(step.is_ai_proposal) || step.exercise_id == null
|
||||
if (isProposal) {
|
||||
nextSlots[idx].primary = proposalSlotExercise({
|
||||
title: step.title,
|
||||
title: step.title || nextSlots[idx].learning_goal,
|
||||
proposalKey: step.proposal_key,
|
||||
aiSuggestion: step.ai_suggestion,
|
||||
})
|
||||
@@ -672,6 +731,72 @@ export function applyMatchStepsToSlots(draft, apiSteps) {
|
||||
return syncProgressionRoadmapFromSlots({ ...draft, slots: nextSlots, dirty: true })
|
||||
}
|
||||
|
||||
/** Lücken-Angebote in leere Slots legen; Panel nur für verbleibende Lücken. */
|
||||
export function applyGapOffersFromResponse(draft, res) {
|
||||
let next = draft
|
||||
if (res?.progression_roadmap) {
|
||||
next = syncSlotPhasesFromRoadmap(next, res.progression_roadmap)
|
||||
}
|
||||
|
||||
const offers = dedupeGapOffersBySlot(collectGapOffersFromApiResponse(res), next)
|
||||
const placedIds = new Set()
|
||||
|
||||
for (const offer of offers) {
|
||||
const idx = resolveOfferSlotIndex(next, offer)
|
||||
if (idx == null || idx < 0 || idx >= (next.slots?.length || 0)) continue
|
||||
const primary = next.slots[idx]?.primary
|
||||
if (primary?.kind === 'library' && primary.exerciseId != null) continue
|
||||
if (primary?.kind === 'proposal') continue
|
||||
|
||||
next = applyGapOfferToSlot(next, idx, offer)
|
||||
if (offer?.offer_id) placedIds.add(offer.offer_id)
|
||||
}
|
||||
|
||||
const remainingOffers = filterGapOffersForUnfilledSlots(
|
||||
next,
|
||||
dedupeGapOffersBySlot(
|
||||
collectGapOffersFromApiResponse(res).filter((o) => !placedIds.has(o?.offer_id)),
|
||||
next,
|
||||
),
|
||||
)
|
||||
|
||||
return { draft: { ...next, dirty: true }, remainingOffers }
|
||||
}
|
||||
|
||||
/** Match-Antwort: Schritte + Lücken-Angebote direkt in Slots (wie früher im Pfad-Wizard sichtbar). */
|
||||
export function applyMatchResponseToDraft(draft, res) {
|
||||
let next = applyMatchStepsToSlots(draft, res?.steps)
|
||||
if (res?.progression_roadmap) {
|
||||
next = {
|
||||
...syncSlotPhasesFromRoadmap(next, res.progression_roadmap),
|
||||
pathSkillExpectations: res?.path_skill_expectations || next.pathSkillExpectations,
|
||||
}
|
||||
}
|
||||
const { draft: withOffers, remainingOffers } = applyGapOffersFromResponse(next, res)
|
||||
return { draft: withOffers, remainingOffers }
|
||||
}
|
||||
|
||||
/** Evaluate-Antwort: KI-Angebote in leere Slots (ohne Schritte neu zu matchen). */
|
||||
export function applyEvaluateResponseToDraft(draft, res) {
|
||||
return applyGapOffersFromResponse(draft, res)
|
||||
}
|
||||
|
||||
export function setSlotPrimaryLibrary(draft, slotIndex, exercise) {
|
||||
if (!exercise?.id) return draft
|
||||
const slots = (draft.slots || []).map((s, i) =>
|
||||
i === slotIndex
|
||||
? {
|
||||
...s,
|
||||
primary: librarySlotExercise({
|
||||
exerciseId: exercise.id,
|
||||
exerciseTitle: exercise.title || `Übung #${exercise.id}`,
|
||||
}),
|
||||
}
|
||||
: s,
|
||||
)
|
||||
return syncProgressionRoadmapFromSlots({ ...draft, slots, dirty: true })
|
||||
}
|
||||
|
||||
export function applyGapOfferToSlot(draft, slotIndex, offer, aiSuggestion = null) {
|
||||
const nextSlots = (draft.slots || []).map((s) => ({ ...s, primary: { ...s.primary }, siblings: [...(s.siblings || [])] }))
|
||||
if (slotIndex < 0 || slotIndex >= nextSlots.length) return draft
|
||||
|
||||
Reference in new issue
Block a user