Files
Eugenius Naumenko e274eaab2b Adaptiven A1-Kurs und statistisches Aussprachetraining integrieren
Direkte DeepSeek- und Mistral-Anbindung mit versionierten Aktionsprofilen,
Budgetreservierung, Tokenabrechnung und administrativen Qualitätsprüfungen
ersetzen die Flowise-Abhängigkeit im regulären Betrieb.

840 geprüfte A1-Aufgaben mit geschützter Testauswertung und konkreten offenen
Arbeitsaufträgen ergänzen den Kurs. Inhalts- und Sprachbewertung bleiben von
Azure-Aussprachewerten getrennt; historische Aufgaben und Antworten bleiben erhalten.

Echte Wort- und Phonemmessungen werden mit Herkunft, Aktualität und Nachweisdichte
gebündelt. Go bestimmt Trainingsziele und Wiederholungen, das Modell formuliert
dazu passende Nachsprechübungen. Profilansicht und Auswahlgründe werden angezeigt.

Validierung: Go-Race-Tests mit lokaler PostgreSQL-Integration, go vet,
Web-Build, Audit aller 840 Aufgaben und drei Browser-Smokes mit lokalen
Modell-/Speech-Fixtures bestanden. Keine Produktionsänderungen oder Live-Aufrufe.
2026-11-01 23:23:20 +00:00

137 lines
4.3 KiB
Go

package httpapi
import (
"context"
"net/http"
"os"
"runtime"
"time"
)
type debugCheck struct {
OK bool `json:"ok"`
Status string `json:"status"`
DurationMS int64 `json:"duration_ms,omitempty"`
HTTPStatus int `json:"http_status,omitempty"`
Error string `json:"error,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
func (s *Server) debugStatus(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{
"request_id": requestID(r),
"debug": map[string]any{
"enabled": true,
"verbose": s.cfg.DebugVerbose,
"log_level": s.cfg.LogLevel.String(),
},
"config": s.debugConfig(),
"checks": map[string]any{
"db": s.store.DebugStatus(r.Context()),
"azure": s.azureStatus(),
"ai": s.aiStatus(r.Context()),
"flowise": s.aiStatus(r.Context()),
},
})
}
func (s *Server) debugDB(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{
"request_id": requestID(r),
"db": s.store.DebugStatus(r.Context()),
})
}
func (s *Server) debugFlowise(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{
"request_id": requestID(r),
"flowise": s.flowiseStatus(r.Context()),
})
}
func (s *Server) debugAzure(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{
"request_id": requestID(r),
"azure": s.azureStatus(),
})
}
func (s *Server) debugRuntime(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
writeJSON(w, http.StatusOK, map[string]any{
"request_id": requestID(r),
"runtime": map[string]any{
"hostname": hostname,
"go_version": runtime.Version(),
"go_os": runtime.GOOS,
"go_arch": runtime.GOARCH,
"goroutines": runtime.NumGoroutine(),
"uptime_seconds": int64(time.Since(s.started).Seconds()),
"started_at": s.started.UTC().Format(time.RFC3339),
},
})
}
func (s *Server) debugConfig() map[string]any {
return map[string]any{
"api_port": s.cfg.Port,
"cors_origins": s.cfg.CORSOrigins,
"azure_mock": s.cfg.AzureMock,
"azure_region": valueOr(s.cfg.AzureRegion, "not-set"),
"azure_speech_key_set": s.cfg.AzureSpeechKey != "",
"ai_provider": "direct",
"deepseek_api_key_set": s.cfg.DeepSeekAPIKey != "",
"mistral_api_key_set": s.cfg.MistralAPIKey != "",
"jwt_secret_configured": s.cfg.JWTSecret != "" && s.cfg.JWTSecret != "dev-secret-change-me",
}
}
func (s *Server) azureStatus() debugCheck {
details := map[string]any{
"mock_enabled": s.cfg.AzureMock,
"region": valueOr(s.cfg.AzureRegion, "not-set"),
"speech_key_set": s.cfg.AzureSpeechKey != "",
}
if s.cfg.AzureMock {
return debugCheck{OK: true, Status: "mock", Details: details}
}
if s.cfg.AzureSpeechKey == "" || s.cfg.AzureRegion == "" {
return debugCheck{OK: false, Status: "not_configured", Details: details}
}
details["stt_endpoint"] = "https://" + s.cfg.AzureRegion + ".stt.speech.microsoft.com"
details["tts_endpoint"] = "https://" + s.cfg.AzureRegion + ".tts.speech.microsoft.com"
return debugCheck{OK: true, Status: "configured", Details: details}
}
func (s *Server) flowiseStatus(ctx context.Context) debugCheck {
return s.aiStatus(ctx)
}
func (s *Server) aiStatus(ctx context.Context) debugCheck {
if s.ai == nil {
return debugCheck{Status: "not_configured"}
}
b, err := s.ai.Repo.Budget(ctx)
if err != nil {
return debugCheck{Status: "database_unavailable"}
}
profiles, err := s.ai.Repo.Profiles(ctx)
if err != nil {
return debugCheck{Status: "database_unavailable"}
}
active := 0
for _, p := range profiles {
if p.Enabled && s.ai.Configured(p.Provider) {
active++
}
}
ok := active > 0 && b.MonthlyLimit > 0 && b.MonthCommitted < b.MonthlyLimit && (b.DailyLimit == 0 || b.DayCommitted < b.DailyLimit)
status := "setup_required"
if ok {
status = "configured"
}
return debugCheck{OK: ok, Status: status, Details: map[string]any{"active_profiles": active, "deepseek_configured": s.ai.Configured("deepseek"), "mistral_configured": s.ai.Configured("mistral"), "budget": b}}
}
func (s *Server) debugAI(w http.ResponseWriter, r *http.Request) {
writeJSON(w, 200, map[string]any{"request_id": requestID(r), "ai": s.aiStatus(r.Context())})
}