2026-06-25 18:24:33 +02:00
|
|
|
|
import re
|
|
|
|
|
|
from datetime import date
|
2026-06-17 01:48:56 +02:00
|
|
|
|
from typing import Literal
|
2026-06-25 18:24:33 +02:00
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
2026-06-17 01:48:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EndpointCapabilities(BaseModel):
|
|
|
|
|
|
id: str
|
|
|
|
|
|
kind: str
|
|
|
|
|
|
direction: Literal["input", "output"]
|
|
|
|
|
|
sample_rate: int = 16000
|
|
|
|
|
|
channels: int = 1
|
|
|
|
|
|
latency_class: Literal["low", "medium", "high"] = "medium"
|
|
|
|
|
|
supports_aec: bool = False
|
|
|
|
|
|
supports_barge_in: bool = False
|
|
|
|
|
|
networked: bool = False
|
|
|
|
|
|
bluetooth: bool = False
|
|
|
|
|
|
mobile: bool = False
|
|
|
|
|
|
default: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AudioChunk(BaseModel):
|
|
|
|
|
|
data: bytes
|
|
|
|
|
|
sample_rate: int = 16000
|
|
|
|
|
|
channels: int = 1
|
|
|
|
|
|
format: str = "wav"
|
|
|
|
|
|
timestamp_ms: int = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PipelineTrace(BaseModel):
|
|
|
|
|
|
raw_transcript: str | None = None
|
|
|
|
|
|
cleaned_transcript: str | None = None
|
|
|
|
|
|
semantic_response: str | None = None
|
|
|
|
|
|
spoken_response: str | None = None
|
|
|
|
|
|
tts_ready_text: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SpeakRequest(BaseModel):
|
|
|
|
|
|
text: str = Field(min_length=1)
|
|
|
|
|
|
voice: str | None = None
|
|
|
|
|
|
language: str | None = None
|
|
|
|
|
|
output_endpoint: str | None = None
|
|
|
|
|
|
tts_provider: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatRequest(BaseModel):
|
|
|
|
|
|
text: str = Field(min_length=1)
|
|
|
|
|
|
input_endpoint: str | None = None
|
|
|
|
|
|
output_endpoint: str | None = None
|
|
|
|
|
|
language: str | None = None
|
|
|
|
|
|
voice: str | None = None
|
|
|
|
|
|
stt_provider: str | None = None
|
|
|
|
|
|
llm_provider: str | None = None
|
|
|
|
|
|
tts_provider: str | None = None
|
feat: Geräte-TTS, native Stimmen, Favicon, Auth-Gate, UI-Fixes
Web-UI / TTS:
- Geräte-TTS ("📱 Gerät"): Antwort wird on-device vorgelesen (Web Speech
API), Server sendet nur Text (text_only) -> spart Bandbreite/Kosten.
Mobil-Default, geräte-lokale Speicherung, iOS-Autoplay-Freischaltung.
- Vorlese-Symbol (🔊) je Bubble: Hybrid-Replay (Assistent-PCM gecacht,
Eingabe via /api/speak); SVG-Icon mit kontrastreicher Farbe.
- Kombiniertes Sprachmenü (Flex + feste Sprachen) statt separatem Modus-Menü.
- "Neues Gespräch"-Button (frische Session gegen Sprach-Trägheit).
- Dark-Mode: lesbare <option>-Popups (Kontrast-Fix).
- Favicon (SVG + PNG-Fallbacks) aus mund.png.
TTS-Backend:
- Sprache wird an alle TTS-Provider durchgereicht; Piper-Stimme folgt der
Sprache; Chatterbox mehrsprachig + cross-lingual.
- Native Referenz-Stimmen je Sprache (config/voices/<lang>.wav, FLEURS CC-BY),
loudness-normalisiert.
LLM-Sprache:
- Antwort folgt zuverlässig der gewählten Sprache (verstärkte Anweisung +
Erinnerung an der letzten Nutzer-Nachricht gegen History-Trägheit).
Admin / Auth:
- Wörterbuch: alle 8 Sprachen, Zeilen editierbar, alphabetische Sortierung.
- Web-UI hinter Auth-Gate (Redirect auf SSO_LOGIN_URL / 401); Favicons offen.
- Log-Tab: Hinweis, wenn der systemd-Dienst nicht aktiv ist.
- Einstellungen: Hinweis "pro Nutzer überschreibbar" bei Sprache/Modus/Qualität.
Doku (BEDIENUNGSANLEITUNG.md): Geräte-TTS §6.5.0, Fix/Flex §6.6, native
Stimmen §6.5.3, llama.cpp<->Ollama-Wechsel §4.7, Auth/SSO §7.4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 13:12:04 +02:00
|
|
|
|
text_only: bool | None = None # True -> kein Server-Audio (Geräte-TTS spricht selbst)
|
2026-06-17 01:48:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SessionRouteRequest(BaseModel):
|
|
|
|
|
|
input_endpoint: str | None = None
|
|
|
|
|
|
output_endpoint: str | None = None
|
|
|
|
|
|
stt_provider: str | None = None
|
|
|
|
|
|
llm_provider: str | None = None
|
|
|
|
|
|
tts_provider: str | None = None
|
|
|
|
|
|
language: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RouteInfo(BaseModel):
|
|
|
|
|
|
input_endpoint: str
|
|
|
|
|
|
output_endpoint: str
|
|
|
|
|
|
stt_provider: str
|
|
|
|
|
|
llm_provider: str
|
|
|
|
|
|
tts_provider: str
|
|
|
|
|
|
language: str
|
|
|
|
|
|
|
2026-06-17 02:14:25 +02:00
|
|
|
|
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
|
|
|
|
display_name: str = Field(min_length=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserCreated(BaseModel):
|
|
|
|
|
|
user_id: str
|
|
|
|
|
|
display_name: str
|
|
|
|
|
|
token: str # nur bei Erstellung sichtbar
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-18 17:55:05 +02:00
|
|
|
|
class UserUpdate(BaseModel):
|
|
|
|
|
|
display_name: str = Field(min_length=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-17 02:14:25 +02:00
|
|
|
|
class UserPrefs(BaseModel):
|
|
|
|
|
|
input_endpoint: str | None = None
|
|
|
|
|
|
output_endpoint: str | None = None
|
|
|
|
|
|
stt_provider: str | None = None
|
|
|
|
|
|
llm_provider: str | None = None
|
|
|
|
|
|
tts_provider: str | None = None
|
|
|
|
|
|
language: str | None = None
|
|
|
|
|
|
|
2026-06-17 04:26:55 +02:00
|
|
|
|
|
|
|
|
|
|
class MemoryCreate(BaseModel):
|
|
|
|
|
|
content: str = Field(min_length=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MemoryOut(BaseModel):
|
|
|
|
|
|
id: int
|
|
|
|
|
|
content: str
|
|
|
|
|
|
created_at: str
|
|
|
|
|
|
|
2026-06-25 03:02:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
feat: Notruf mit Kontaktdaten + Geoposition anreichern (Backend, Phase 1+3)
Notruf-Meldungen tragen jetzt das Notfall-Profil der auslösenden Person und —
falls vom Gerät mitgeschickt — die Geoposition. Kanal-Rollen:
- E-Mail: Voll-Dossier (Name, Adresse, Telefone, Geburtsdatum, med. Hinweise,
Koordinaten + Karten-Link + Genauigkeit + Zeit; sonst "nicht verfügbar")
- SMS: kompakt, Name + Adresse + Karten-Link
- Anruf (TTS): Name + Wohnadresse gesprochen, KEINE URL/Koordinaten, Verweis
auf SMS/E-Mail
- schemas: GeoFix + EmergencyRequest.geo; AdminUserPrefsUpdate um Profilfelder
erweitert (full_name, Adresse, Telefone, birth_date, medical_notes,
emergency_contacts/_phones, location_consent) — in user.prefs (keine Migration)
- api/chat: geo an record_manual_emergency durchgereicht
- api/admin: list_users gibt Profilfelder mit zurück (für die spätere Admin-UI)
- emergency.py: _profile/_geo_fields/_maps_link/_location_block/_email_body,
kanal-spezifische _emergency_texts; record_manual_emergency(..., geo=...)
- Tests: 9 neue (Profil-Injektion, SMS/Call/E-Mail-Texte, Geo→Map-Link,
ohne-Geo-Fallback, Payload). Suite 237 grün.
Frontend (Phase 2: Browser-Geolocation beim 🆘 + Admin-Profil-UI) steht noch aus.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 15:33:58 +02:00
|
|
|
|
class GeoFix(BaseModel):
|
|
|
|
|
|
"""Geoposition des auslösenden Geräts (One-Shot, vom Browser erfasst)."""
|
|
|
|
|
|
lat: float
|
|
|
|
|
|
lon: float
|
|
|
|
|
|
accuracy: float | None = None # geschätzte Genauigkeit in Metern
|
|
|
|
|
|
ts: str | None = None # ISO-Zeitstempel des Fixes
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-25 17:24:36 +02:00
|
|
|
|
class DeviceInfo(BaseModel):
|
|
|
|
|
|
"""Geräteart/Plattform des auslösenden Geräts (aus Browser-Daten)."""
|
|
|
|
|
|
mobile: bool | None = None
|
|
|
|
|
|
platform: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-25 03:02:52 +02:00
|
|
|
|
class EmergencyRequest(BaseModel):
|
|
|
|
|
|
"""Vom Nutzer ausgelöster Notruf (Knopf). language für den Hinweistext."""
|
|
|
|
|
|
language: str | None = None
|
feat: Notruf mit Kontaktdaten + Geoposition anreichern (Backend, Phase 1+3)
Notruf-Meldungen tragen jetzt das Notfall-Profil der auslösenden Person und —
falls vom Gerät mitgeschickt — die Geoposition. Kanal-Rollen:
- E-Mail: Voll-Dossier (Name, Adresse, Telefone, Geburtsdatum, med. Hinweise,
Koordinaten + Karten-Link + Genauigkeit + Zeit; sonst "nicht verfügbar")
- SMS: kompakt, Name + Adresse + Karten-Link
- Anruf (TTS): Name + Wohnadresse gesprochen, KEINE URL/Koordinaten, Verweis
auf SMS/E-Mail
- schemas: GeoFix + EmergencyRequest.geo; AdminUserPrefsUpdate um Profilfelder
erweitert (full_name, Adresse, Telefone, birth_date, medical_notes,
emergency_contacts/_phones, location_consent) — in user.prefs (keine Migration)
- api/chat: geo an record_manual_emergency durchgereicht
- api/admin: list_users gibt Profilfelder mit zurück (für die spätere Admin-UI)
- emergency.py: _profile/_geo_fields/_maps_link/_location_block/_email_body,
kanal-spezifische _emergency_texts; record_manual_emergency(..., geo=...)
- Tests: 9 neue (Profil-Injektion, SMS/Call/E-Mail-Texte, Geo→Map-Link,
ohne-Geo-Fallback, Payload). Suite 237 grün.
Frontend (Phase 2: Browser-Geolocation beim 🆘 + Admin-Profil-UI) steht noch aus.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 15:33:58 +02:00
|
|
|
|
geo: GeoFix | None = None
|
2026-06-25 17:24:36 +02:00
|
|
|
|
geo_error: str | None = None # Grund, falls die Geo-Erfassung scheiterte
|
|
|
|
|
|
device: DeviceInfo | None = None
|
2026-06-25 04:06:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
2026-06-25 18:24:33 +02:00
|
|
|
|
# Format-Validierung der Notfall-Profilfelder (spiegelt die Frontend-Prüfung).
|
|
|
|
|
|
_PLZ_RE = re.compile(r"^\d{5}$")
|
|
|
|
|
|
_PHONE_RE = re.compile(r"^\+?[\d\s/().\-]{6,20}$")
|
|
|
|
|
|
_EMAIL_RE = re.compile(r"^[^\s@]+@[^\s@]+\.[^\s@]+$")
|
|
|
|
|
|
_DATE_RE = re.compile(r"^(\d{2})\.(\d{2})\.(\d{4})$")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _valid_german_date(v: str) -> bool:
|
|
|
|
|
|
m = _DATE_RE.match(v)
|
|
|
|
|
|
if not m:
|
|
|
|
|
|
return False
|
|
|
|
|
|
d, mo, y = int(m.group(1)), int(m.group(2)), int(m.group(3))
|
|
|
|
|
|
if not (1900 <= y <= 2100):
|
|
|
|
|
|
return False
|
|
|
|
|
|
try:
|
|
|
|
|
|
date(y, mo, d)
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
return False
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _csv_all(v: str, rx: "re.Pattern") -> bool:
|
|
|
|
|
|
return all(rx.match(p.strip()) for p in v.split(",") if p.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-25 04:06:09 +02:00
|
|
|
|
class AdminUserPrefsUpdate(BaseModel):
|
2026-06-25 18:24:33 +02:00
|
|
|
|
"""Admin setzt Nutzer-Einstellungen: erlaubte Sprachen + Notfall-Profil.
|
|
|
|
|
|
|
|
|
|
|
|
Optionale Felder dürfen leer/None sein; nicht-leere Werte werden auf ihr
|
|
|
|
|
|
Format geprüft (serverseitige Härtung zusätzlich zur Frontend-Validierung).
|
|
|
|
|
|
"""
|
2026-06-25 04:06:09 +02:00
|
|
|
|
allowed_languages: str | None = None
|
feat: Notruf mit Kontaktdaten + Geoposition anreichern (Backend, Phase 1+3)
Notruf-Meldungen tragen jetzt das Notfall-Profil der auslösenden Person und —
falls vom Gerät mitgeschickt — die Geoposition. Kanal-Rollen:
- E-Mail: Voll-Dossier (Name, Adresse, Telefone, Geburtsdatum, med. Hinweise,
Koordinaten + Karten-Link + Genauigkeit + Zeit; sonst "nicht verfügbar")
- SMS: kompakt, Name + Adresse + Karten-Link
- Anruf (TTS): Name + Wohnadresse gesprochen, KEINE URL/Koordinaten, Verweis
auf SMS/E-Mail
- schemas: GeoFix + EmergencyRequest.geo; AdminUserPrefsUpdate um Profilfelder
erweitert (full_name, Adresse, Telefone, birth_date, medical_notes,
emergency_contacts/_phones, location_consent) — in user.prefs (keine Migration)
- api/chat: geo an record_manual_emergency durchgereicht
- api/admin: list_users gibt Profilfelder mit zurück (für die spätere Admin-UI)
- emergency.py: _profile/_geo_fields/_maps_link/_location_block/_email_body,
kanal-spezifische _emergency_texts; record_manual_emergency(..., geo=...)
- Tests: 9 neue (Profil-Injektion, SMS/Call/E-Mail-Texte, Geo→Map-Link,
ohne-Geo-Fallback, Payload). Suite 237 grün.
Frontend (Phase 2: Browser-Geolocation beim 🆘 + Admin-Profil-UI) steht noch aus.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 15:33:58 +02:00
|
|
|
|
# Notfall-Profil (in user.prefs gespeichert, fließt in die Notruf-Meldungen ein)
|
|
|
|
|
|
full_name: str | None = None
|
|
|
|
|
|
street: str | None = None
|
|
|
|
|
|
postal_code: str | None = None
|
|
|
|
|
|
city: str | None = None
|
|
|
|
|
|
phone_landline: str | None = None
|
|
|
|
|
|
phone_mobile: str | None = None
|
|
|
|
|
|
birth_date: str | None = None
|
|
|
|
|
|
medical_notes: str | None = None
|
|
|
|
|
|
emergency_contacts: str | None = None # Kontakt-E-Mail(s), CSV
|
|
|
|
|
|
emergency_phones: str | None = None # Kontakt-Telefon(e), CSV
|
|
|
|
|
|
location_consent: bool | None = None # Standort im Notfall mitsenden?
|
2026-06-26 17:10:12 +02:00
|
|
|
|
# Alarmpause pro Nutzer (ganze Minuten, als String). Leer = globaler Standard,
|
|
|
|
|
|
# "0" = aus. Präzedenz: dieser Wert > globale Einstellung > 5.
|
|
|
|
|
|
emergency_cooldown_minutes: str | None = None
|
2026-06-25 04:33:33 +02:00
|
|
|
|
|
2026-06-25 18:24:33 +02:00
|
|
|
|
@field_validator("postal_code")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_plz(cls, v):
|
|
|
|
|
|
if v and not _PLZ_RE.match(v.strip()):
|
|
|
|
|
|
raise ValueError("PLZ muss genau 5 Ziffern sein")
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
@field_validator("phone_mobile", "phone_landline")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_phone(cls, v):
|
|
|
|
|
|
if v and not _PHONE_RE.match(v.strip()):
|
|
|
|
|
|
raise ValueError("ungültige Telefonnummer")
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
@field_validator("birth_date")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_date(cls, v):
|
|
|
|
|
|
if v and not _valid_german_date(v.strip()):
|
|
|
|
|
|
raise ValueError("Geburtsdatum muss TT.MM.JJJJ (gültiges Datum) sein")
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
@field_validator("emergency_contacts")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_emails(cls, v):
|
|
|
|
|
|
if v and not _csv_all(v, _EMAIL_RE):
|
|
|
|
|
|
raise ValueError("Kontakt-E-Mail(s): ungültige Adresse")
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
@field_validator("emergency_phones")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_phones_csv(cls, v):
|
|
|
|
|
|
if v and not _csv_all(v, _PHONE_RE):
|
|
|
|
|
|
raise ValueError("Kontakt-Telefon(e): ungültige Nummer")
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
2026-06-26 17:10:12 +02:00
|
|
|
|
@field_validator("emergency_cooldown_minutes")
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def _check_cooldown(cls, v):
|
|
|
|
|
|
if v is None or str(v).strip() == "":
|
|
|
|
|
|
return v # leer = globaler Standard (erben)
|
|
|
|
|
|
s = str(v).strip()
|
|
|
|
|
|
if not s.isdigit():
|
|
|
|
|
|
raise ValueError("Pause: nur ganze Minuten (0–60)")
|
|
|
|
|
|
if int(s) > 60:
|
|
|
|
|
|
raise ValueError("Pause: höchstens 60 Minuten")
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
2026-06-25 04:33:33 +02:00
|
|
|
|
|
|
|
|
|
|
class UserAdminUpdate(BaseModel):
|
|
|
|
|
|
"""Admin schaltet Admin-Rechte für einen Nutzer ein/aus."""
|
|
|
|
|
|
is_admin: bool
|