Update Planning Exercise Suggestion and Context Handling
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Test Suite / pytest-backend (pull_request) Successful in 37s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 13s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m15s
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Test Suite / pytest-backend (pull_request) Successful in 37s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 13s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m15s
- Incremented version to 0.8.183, reflecting the implementation of Phase C1 enhancements. - Added support for progression graph auto-matching and variant-aware successors in exercise suggestions. - Updated request and response structures to include `anchor_exercise_variant_id`, `progression_graph_name`, and `suggested_variant_id`. - Enhanced frontend components to integrate planning AI search capabilities, including a new modal for exercise creation and improved context display in the exercise list. - Updated changelog to document these significant improvements in planning AI functionality.
This commit is contained in:
1 parent
50aff849d8
commit
b2157d8a40
16 files changed
+985
-136
No files matched your search
@@ -6,7 +6,7 @@ Siehe .claude/docs/working/PLANNING_EXERCISE_SUGGEST_CONTEXT.md
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple
|
||||
from typing import Any, Dict, List, Mapping, Optional, Sequence, Set, Tuple
|
||||
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -15,6 +15,7 @@ from tenant_context import TenantContext, library_content_visibility_sql
|
||||
from planning_exercise_profiles import skill_profile_summary_from_exercise_ids
|
||||
from planning_exercise_retrieval import run_multistage_planning_retrieval
|
||||
from planning_exercise_llm_rank import try_llm_rerank_planning_hits
|
||||
from planning_exercise_progression import apply_progression_context_to_pack
|
||||
from planning_exercise_target_pipeline import (
|
||||
build_planning_target_with_query_pipeline,
|
||||
compose_retrieval_phase,
|
||||
@@ -53,6 +54,7 @@ class PlanningExerciseSuggestRequest(BaseModel):
|
||||
phase_order_index: Optional[int] = Field(default=None, ge=0)
|
||||
parallel_stream_order_index: Optional[int] = Field(default=None, ge=0)
|
||||
anchor_exercise_id: Optional[int] = Field(default=None, ge=1)
|
||||
anchor_exercise_variant_id: Optional[int] = Field(default=None, ge=1)
|
||||
progression_graph_id: Optional[int] = Field(default=None, ge=1)
|
||||
query: Optional[str] = ""
|
||||
intent_hint: Optional[str] = None
|
||||
@@ -169,31 +171,62 @@ def _load_skill_ids_for_exercise(cur, exercise_id: Optional[int]) -> Set[int]:
|
||||
return {int(r["skill_id"]) for r in cur.fetchall() if r.get("skill_id")}
|
||||
|
||||
|
||||
def _load_progression_successors(
|
||||
def _resolve_anchor_variant_id(
|
||||
pack: Mapping[str, Any],
|
||||
body: PlanningExerciseSuggestRequest,
|
||||
sections: Optional[Sequence[Dict[str, Any]]] = None,
|
||||
) -> Optional[int]:
|
||||
raw = body.anchor_exercise_variant_id
|
||||
if raw is not None:
|
||||
try:
|
||||
vid = int(raw)
|
||||
except (TypeError, ValueError):
|
||||
vid = 0
|
||||
if vid > 0:
|
||||
return vid
|
||||
anchor_id = pack.get("anchor_exercise_id")
|
||||
if not anchor_id or not sections:
|
||||
return None
|
||||
sec = _section_for_context(sections, pack.get("section_order_index"))
|
||||
if not sec:
|
||||
return None
|
||||
target = int(anchor_id)
|
||||
for it in sorted(sec.get("items") or [], key=lambda x: int(x.get("order_index") or 0), reverse=True):
|
||||
if str(it.get("item_type") or "").strip().lower() == "note":
|
||||
continue
|
||||
try:
|
||||
eid = int(it.get("exercise_id"))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid != target:
|
||||
continue
|
||||
raw_v = it.get("exercise_variant_id")
|
||||
if raw_v is None:
|
||||
return None
|
||||
try:
|
||||
vid = int(raw_v)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
return vid if vid > 0 else None
|
||||
return None
|
||||
|
||||
|
||||
def _finalize_progression_context(
|
||||
cur,
|
||||
graph_id: Optional[int],
|
||||
from_exercise_id: Optional[int],
|
||||
) -> Tuple[Set[int], Dict[int, str]]:
|
||||
if not graph_id or not from_exercise_id:
|
||||
return set(), {}
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT to_exercise_id, notes
|
||||
FROM exercise_progression_edges
|
||||
WHERE graph_id = %s AND from_exercise_id = %s
|
||||
AND LOWER(TRIM(edge_type)) = 'next_exercise'
|
||||
""",
|
||||
(int(graph_id), int(from_exercise_id)),
|
||||
tenant: TenantContext,
|
||||
pack: Dict[str, Any],
|
||||
body: PlanningExerciseSuggestRequest,
|
||||
*,
|
||||
sections: Optional[Sequence[Dict[str, Any]]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
anchor_variant = _resolve_anchor_variant_id(pack, body, sections)
|
||||
return apply_progression_context_to_pack(
|
||||
cur,
|
||||
tenant,
|
||||
pack,
|
||||
explicit_graph_id=body.progression_graph_id,
|
||||
anchor_variant_id=anchor_variant,
|
||||
)
|
||||
ids: Set[int] = set()
|
||||
notes: Dict[int, str] = {}
|
||||
for row in cur.fetchall():
|
||||
tid = int(row["to_exercise_id"])
|
||||
ids.add(tid)
|
||||
n = (row.get("notes") or "").strip()
|
||||
if n:
|
||||
notes[tid] = n
|
||||
return ids, notes
|
||||
|
||||
|
||||
def _load_group_recent_exercise_ids(
|
||||
@@ -469,9 +502,6 @@ def build_planning_exercise_context_pack(
|
||||
planned_ids = _collect_planned_exercise_ids(sections)
|
||||
anchor_id = _resolve_anchor_from_plan(planned_ids, body.anchor_exercise_id)
|
||||
anchor_skills = _load_skill_ids_for_exercise(cur, anchor_id)
|
||||
progression_ids, progression_notes = _load_progression_successors(
|
||||
cur, body.progression_graph_id, anchor_id
|
||||
)
|
||||
group_recent = _load_group_recent_exercise_ids(cur, unit.get("group_id"), int(body.unit_id))
|
||||
|
||||
titles = _load_exercise_titles(cur, [x for x in [anchor_id] if x])
|
||||
@@ -493,9 +523,6 @@ def build_planning_exercise_context_pack(
|
||||
"anchor_exercise_id": anchor_id,
|
||||
"anchor_title": anchor_title,
|
||||
"anchor_skill_ids": sorted(anchor_skills),
|
||||
"progression_graph_id": body.progression_graph_id,
|
||||
"progression_successor_ids": sorted(progression_ids),
|
||||
"progression_edge_notes": progression_notes,
|
||||
"group_recent_exercise_ids": sorted(group_recent),
|
||||
}
|
||||
return _attach_planning_context_details(cur, pack, sections=sections, body=body)
|
||||
@@ -527,9 +554,6 @@ def build_client_planning_context_pack(
|
||||
|
||||
anchor_id = _resolve_anchor_from_plan(planned_ids, body.anchor_exercise_id)
|
||||
anchor_skills = _load_skill_ids_for_exercise(cur, anchor_id)
|
||||
progression_ids, progression_notes = _load_progression_successors(
|
||||
cur, body.progression_graph_id, anchor_id
|
||||
)
|
||||
|
||||
group_id = body.group_id
|
||||
group_name = None
|
||||
@@ -559,9 +583,6 @@ def build_client_planning_context_pack(
|
||||
"anchor_exercise_id": anchor_id,
|
||||
"anchor_title": anchor_title,
|
||||
"anchor_skill_ids": sorted(anchor_skills),
|
||||
"progression_graph_id": body.progression_graph_id,
|
||||
"progression_successor_ids": sorted(progression_ids),
|
||||
"progression_edge_notes": progression_notes,
|
||||
"group_recent_exercise_ids": sorted(group_recent),
|
||||
"context_mode": "client_free",
|
||||
}
|
||||
@@ -580,6 +601,12 @@ def suggest_planning_exercises(
|
||||
pack = build_client_planning_context_pack(cur, tenant=tenant, body=body)
|
||||
pack = _apply_client_planned_override(cur, pack, body)
|
||||
pack = _attach_planning_context_details(cur, pack, body=body)
|
||||
sections_for_variant = None
|
||||
if body.unit_id and not (body.anchor_exercise_variant_id and int(body.anchor_exercise_variant_id) > 0):
|
||||
sections_for_variant = _fetch_sections(cur, int(body.unit_id))
|
||||
pack = _finalize_progression_context(
|
||||
cur, tenant, pack, body, sections=sections_for_variant
|
||||
)
|
||||
query = _normalize_query(body.query)
|
||||
heuristic_intent = resolve_planning_exercise_intent(query, body.intent_hint)
|
||||
|
||||
@@ -713,6 +740,9 @@ def suggest_planning_exercises(
|
||||
"anchor_exercise_id": pack.get("anchor_exercise_id"),
|
||||
"last_section_exercise_title": pack.get("last_section_exercise_title"),
|
||||
"progression_graph_id": pack.get("progression_graph_id"),
|
||||
"progression_graph_name": pack.get("progression_graph_name"),
|
||||
"progression_graph_auto_resolved": pack.get("progression_graph_auto_resolved"),
|
||||
"anchor_exercise_variant_id": pack.get("anchor_exercise_variant_id"),
|
||||
"context_mode": pack.get("context_mode") or ("unit" if pack.get("unit_id") else "client_free"),
|
||||
"unit_skill_profile": pack.get("unit_skill_profile_summary"),
|
||||
"section_skill_profile": pack.get("section_skill_profile_summary"),
|
||||
|
||||
Reference in new issue
Block a user