Implement Primary Topic Resolution in Path Logic
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m22s

- Introduced `resolve_path_primary_topic` function to enhance the determination of primary topics from goal queries and semantic briefs, improving exercise relevance.
- Updated `_match_roadmap_slot` and `detect_off_topic_steps` functions to utilize the new primary topic resolution logic, ensuring accurate topic identification.
- Enhanced tests to validate the functionality of primary topic resolution and its impact on exercise selection and off-topic detection.
- Improved handling of primary topics in the `ExerciseProgressionPathBuilder` and related components for better integration with the overall path-building process.
This commit is contained in:
Lars committed 2026-06-11 11:06:38 +02:00
1 parent f63b09fc9c
commit 044ce2ee60
7 files changed
+128 -16

No files matched your search

@@ -142,8 +142,10 @@ function normalizeTitleKey(text) {
.replace(/\s+/g, ' ')
}
function mergeGraphIntoPathSteps(pathRows, graphNodes) {
if (!Array.isArray(graphNodes) || !graphNodes.length || !pathRows.length) return pathRows
function mergeGraphIntoPathSteps(pathRows, graphNodes, { skipGraphMerge = false } = {}) {
if (skipGraphMerge || !Array.isArray(graphNodes) || !graphNodes.length || !pathRows.length) {
return pathRows
}
return pathRows.map((row, i) => {
const node = graphNodes[i]
if (!node?.exercise_id) return row
@@ -1019,14 +1021,14 @@ export default function ExerciseProgressionPathBuilder({
}
}
const applyPathMatchResponse = (res, q) => {
const applyPathMatchResponse = (res, q, { skipGraphMerge = true } = {}) => {
const qa = res?.path_qa || null
const rawRows = (Array.isArray(res?.steps) ? res.steps : []).map(mapApiStepToRow)
const rows = applyOffTopicFlags(rawRows, qa)
const mergedRows = mergeGraphIntoPathSteps(rows, graphChainNodes, { skipGraphMerge })
if (rows.length < 2) {
throw new Error('Zu wenig Schritte im Vorschlag.')
}
const mergedRows = mergeGraphIntoPathSteps(rows, graphChainNodes)
const rawGaps = Array.isArray(res?.gap_fill_offers)
? res.gap_fill_offers
: Array.isArray(qa?.gap_fill_offers)
+13 -5
View File
@@ -785,7 +785,7 @@ export function applyMatchStepsToSlots(draft, apiSteps) {
}
/** Lücken-Angebote in leere Slots legen; Panel nur für verbleibende Lücken. */
export function applyGapOffersFromResponse(draft, res) {
export function applyGapOffersFromResponse(draft, res, { replaceOffTopicSlots = false } = {}) {
let next = draft
if (res?.progression_roadmap) {
next = syncSlotPhasesFromRoadmap(next, res.progression_roadmap)
@@ -798,8 +798,14 @@ export function applyGapOffersFromResponse(draft, res) {
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
const isOffTopicReplace =
replaceOffTopicSlots &&
offer?.source === 'off_topic' &&
offer?.replace_step_index != null
if (!isOffTopicReplace) {
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)
@@ -817,7 +823,7 @@ export function applyGapOffersFromResponse(draft, res) {
}
/** Match-Antwort: Schritte + Lücken-Angebote direkt in Slots (wie früher im Pfad-Wizard sichtbar). */
export function applyMatchResponseToDraft(draft, res) {
export function applyMatchResponseToDraft(draft, res, { replaceOffTopicSlots = true } = {}) {
let next = applyMatchStepsToSlots(draft, res?.steps)
if (res?.progression_roadmap) {
next = {
@@ -825,7 +831,9 @@ export function applyMatchResponseToDraft(draft, res) {
pathSkillExpectations: res?.path_skill_expectations || next.pathSkillExpectations,
}
}
const { draft: withOffers, remainingOffers } = applyGapOffersFromResponse(next, res)
const { draft: withOffers, remainingOffers } = applyGapOffersFromResponse(next, res, {
replaceOffTopicSlots,
})
return { draft: withOffers, remainingOffers }
}