feat(iace): Phase 1 — Haftungs-Fixes, Massnahmen-Verkabelung, Explainability Engine
Phase 1A — Haftungs-kritische Fixes: - SIL/PL-Badges als "Vorab-Einschaetzung" mit Tooltip gekennzeichnet - Coverage-Disclaimer in CE-Akte, Projekt-Uebersicht und Print-Export - Norm-Referenzen: 42 Kapitelverweise durch Themen-Deskriptoren ersetzt Phase 1B — Massnahmen-Verkabelung: - 16 neue Massnahmen (M201-M216) fuer bisher unabgedeckte Kategorien (communication_failure, hmi_error, firmware_corruption, maintenance, sensor_fault, mode_confusion) - Kategorie-Fallback im Initialize-Endpoint: ordnet Massnahmen aus der Bibliothek automatisch per HazardCategory zu (max 8 pro Kategorie) - Total: 225 → 241 Massnahmen, 0 Kategorien ohne Massnahmen Phase 1C — Explainability Engine: - MatchReason Struct in PatternMatch (type, tag, met) - Pattern Engine schreibt fuer jeden Match strukturierte Begruendungen - Frontend zeigt "Erkannt weil: Komponente X, Energie Y, Kein Ausschluss Z" Weitere Aenderungen: - BAuA/OSHA Regulatory Hints: 3 Enrich-Endpoints (per Hazard, per Measure, Batch) - Dokumente-Tab in IACE-Bibliothek (36.708 Chunks aus Qdrant) - Varianten-UX: Basis-Projekt-Summary auf Varianten-Seite - Projekt-Initialisierung: POST /initialize kettet Parse→Komponenten→Patterns→Hazards→Massnahmen→Normen - 18 pre-existing TS-Fehler gefixt, Route-Konflikt behoben - Component-Library + Measures-Library Tests aktualisiert Tests: Go alle bestanden, TS 0 Fehler, Playwright 141+ bestanden Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/breakpilot/ai-compliance-sdk/internal/ucca"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Cached CE corpus document index — built once on first request.
|
||||
var (
|
||||
ceCorpusOnce sync.Once
|
||||
ceCorpusDocs []ucca.CEDocumentInfo
|
||||
ceCorpusErr error
|
||||
)
|
||||
|
||||
// ListCECorpusDocuments returns the deduplicated document index from bp_compliance_ce.
|
||||
// GET /iace/ce-corpus-documents
|
||||
func (h *IACEHandler) ListCECorpusDocuments(c *gin.Context) {
|
||||
ceCorpusOnce.Do(func() {
|
||||
ceCorpusDocs, ceCorpusErr = h.ragClient.ScrollDocumentIndex(
|
||||
c.Request.Context(), "bp_compliance_ce",
|
||||
)
|
||||
if ceCorpusErr == nil {
|
||||
sort.Slice(ceCorpusDocs, func(i, j int) bool {
|
||||
if ceCorpusDocs[i].Category != ceCorpusDocs[j].Category {
|
||||
return ceCorpusDocs[i].Category < ceCorpusDocs[j].Category
|
||||
}
|
||||
return ceCorpusDocs[i].RegulationID < ceCorpusDocs[j].RegulationID
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if ceCorpusErr != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "failed to load CE corpus index: " + ceCorpusErr.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Optional search filter
|
||||
query := strings.ToLower(c.Query("q"))
|
||||
category := c.Query("category")
|
||||
|
||||
filtered := ceCorpusDocs
|
||||
if query != "" || category != "" {
|
||||
filtered = make([]ucca.CEDocumentInfo, 0, len(ceCorpusDocs))
|
||||
for _, d := range ceCorpusDocs {
|
||||
if category != "" && d.Category != category {
|
||||
continue
|
||||
}
|
||||
if query != "" {
|
||||
haystack := strings.ToLower(d.RegulationID + " " + d.NameDE + " " + d.NameEN + " " + d.SourceOrg)
|
||||
if !strings.Contains(haystack, query) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, d)
|
||||
}
|
||||
}
|
||||
|
||||
// Group by category for the response
|
||||
groups := make(map[string][]ucca.CEDocumentInfo)
|
||||
for _, d := range filtered {
|
||||
cat := d.Category
|
||||
if cat == "" {
|
||||
cat = "other"
|
||||
}
|
||||
groups[cat] = append(groups[cat], d)
|
||||
}
|
||||
|
||||
totalChunks := 0
|
||||
for _, d := range filtered {
|
||||
totalChunks += d.ChunkCount
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"documents": filtered,
|
||||
"groups": groups,
|
||||
"total": len(filtered),
|
||||
"total_chunks": totalChunks,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user