| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- # -*- coding: utf-8 -*-
- """
- Feld-Registry fuer typ-spezifische Config-Editoren.
- Definiert Metadaten pro Config-Feld: Editor-Typ, Auswahlmoeglichkeiten,
- Wertebereiche und dynamische Quellen fuer Optionen.
- """
- from __future__ import annotations
- from dataclasses import dataclass, field
- from enum import Enum
- class EditorType(str, Enum):
- """Unterstuetzte Editor-Typen fuer Config-Felder."""
- SELECT = "select"
- BOOL = "bool"
- NUMBER_INT = "number_int"
- NUMBER_FLOAT = "number_float"
- TEXT = "text"
- IP_ADDRESS = "ip_address"
- PATH = "path"
- LIST_SELECT = "list_select"
- LIST_TEXT = "list_text"
- READONLY = "readonly"
- @dataclass
- class FieldMeta:
- """
- Metadaten fuer ein einzelnes Config-Feld.
- Bestimmt welcher Editor-Typ verwendet wird, welche
- Auswahlmoeglichkeiten existieren und wie validiert wird.
- """
- editor: EditorType
- choices: list[tuple[str, str]] | None = None
- min_value: float | None = None
- max_value: float | None = None
- step: float | None = None
- placeholder: str = ""
- requires_restart: bool = False
- dynamic_source: str | None = None
- hint: str = ""
- # --- Log-Level Auswahl (gemeinsam genutzt) ---
- _LOG_LEVEL_CHOICES: list[tuple[str, str]] = [
- ("DEBUG", "DEBUG"),
- ("INFO", "INFO"),
- ("WARNING", "WARNING"),
- ("ERROR", "ERROR"),
- ("CRITICAL", "CRITICAL"),
- ]
- # --- Audio Sample-Rate Auswahl ---
- _SAMPLE_RATE_CHOICES: list[tuple[str, str]] = [
- ("8000", "8000 Hz"),
- ("16000", "16000 Hz"),
- ("22050", "22050 Hz"),
- ("44100", "44100 Hz"),
- ("48000", "48000 Hz"),
- ]
- # --- Audio Channels Auswahl ---
- _CHANNELS_CHOICES: list[tuple[str, str]] = [
- ("1", "Mono"),
- ("2", "Stereo"),
- ]
- # --- Audio Bit-Depth Auswahl ---
- _BIT_DEPTH_CHOICES: list[tuple[str, str]] = [
- ("16", "16 Bit"),
- ("24", "24 Bit"),
- ("32", "32 Bit"),
- ]
- # --- Notification Auswahl ---
- _NOTIFICATION_CHOICES: list[tuple[str, str]] = [
- ("0", "Keine"),
- ("1", "TTS"),
- ("2", "Wave-Datei"),
- ("3", "TTS + Wave"),
- ]
- # --- STT-Korrektur Layer Auswahl ---
- _STT_LAYER_CHOICES: list[tuple[str, str]] = [
- ("symspell", "SymSpell"),
- ("phonetic", "Phonetisch"),
- ("kenlm", "KenLM"),
- ("jamspell", "JamSpell"),
- ("hunspell", "Hunspell"),
- ("languagetool", "LanguageTool"),
- ]
- # --- Port-Feld Defaults ---
- _PORT_META = FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1024,
- max_value=65535,
- requires_restart=True,
- hint="Port (1024-65535)",
- )
- def _port(hint: str = "") -> FieldMeta:
- """Erzeugt FieldMeta fuer ein Port-Feld."""
- return FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1024,
- max_value=65535,
- requires_restart=True,
- hint=hint or "Port (1024-65535)",
- )
- def build_server_registry() -> dict[str, FieldMeta]:
- """Baut die Feld-Registry fuer Server-Konfiguration."""
- return {
- # --- Logging ---
- "logging.level": FieldMeta(
- editor=EditorType.SELECT,
- choices=_LOG_LEVEL_CHOICES,
- hint="Log-Level fuer Konsolenausgabe",
- ),
- "logging.file_log_level": FieldMeta(
- editor=EditorType.SELECT,
- choices=_LOG_LEVEL_CHOICES,
- hint="Log-Level fuer Dateiausgabe",
- ),
- "logging.log_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="logs",
- hint="Verzeichnis fuer Log-Dateien",
- ),
- "logging.max_file_size_mb": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1,
- max_value=1000,
- hint="Maximale Log-Dateigroesse in MB",
- ),
- "logging.backup_count": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=0,
- max_value=100,
- hint="Anzahl der Log-Backup-Dateien",
- ),
- "logging.plugin_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=300.0,
- hint="Plugin-Timeout in Sekunden",
- ),
- "logging.plugin_max_failures": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1,
- max_value=100,
- hint="Maximale Plugin-Fehler vor Deaktivierung",
- ),
- # --- Security ---
- "security.encryption_enabled": FieldMeta(
- editor=EditorType.BOOL,
- requires_restart=True,
- hint="AES-256-GCM Verschluesselung aktivieren",
- ),
- "security.encryption_key_path": FieldMeta(
- editor=EditorType.PATH,
- placeholder="certs/encryption.key",
- requires_restart=True,
- ),
- "security.ssl_enabled": FieldMeta(
- editor=EditorType.BOOL,
- requires_restart=True,
- hint="SSL/TLS aktivieren",
- ),
- "security.ssl_cert_path": FieldMeta(
- editor=EditorType.PATH,
- placeholder="certs/server.crt",
- requires_restart=True,
- ),
- "security.ssl_key_path": FieldMeta(
- editor=EditorType.PATH,
- placeholder="certs/server.key",
- requires_restart=True,
- ),
- "security.allowed_mac_addresses": FieldMeta(
- editor=EditorType.LIST_TEXT,
- hint="Erlaubte MAC-Adressen (kommasepariert)",
- ),
- # --- Plugins ---
- "plugins.enabled": FieldMeta(
- editor=EditorType.BOOL,
- hint="Plugin-System aktivieren",
- ),
- "plugins.plugin_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="plugins",
- ),
- "plugins.auto_reload": FieldMeta(
- editor=EditorType.BOOL,
- hint="Plugins automatisch neu laden bei Aenderungen",
- ),
- # --- Network ---
- "network.command_port": _port("Command-Port"),
- "network.audio_input_port": _port("Audio-Input-Port"),
- "network.audio_output_port": _port("Audio-Output-Port"),
- "network.music_port": _port("Musik-Port"),
- "network.config_port": _port("Config-Port"),
- "network.bind_address": FieldMeta(
- editor=EditorType.IP_ADDRESS,
- requires_restart=True,
- placeholder="0.0.0.0",
- hint="Bind-Adresse fuer den Server",
- ),
- "network.max_connections": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1,
- max_value=1000,
- hint="Maximale gleichzeitige Verbindungen",
- ),
- # --- Audio ---
- "audio.sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- hint="Sprach-Audio Sample-Rate",
- ),
- "audio.channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- "audio.music_sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- hint="Musik-Audio Sample-Rate",
- ),
- "audio.music_channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.music_bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- # --- Wakeword ---
- "wakeword.models": FieldMeta(
- editor=EditorType.LIST_SELECT,
- dynamic_source="wakeword_models",
- hint="Aktive Wakeword-Modelle",
- ),
- "wakeword.threshold": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- step=0.05,
- hint="Erkennungsschwelle (0.0-1.0)",
- ),
- "wakeword.debounce_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=10.0,
- hint="Entprellzeit in Sekunden",
- ),
- "wakeword.arbitration_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=10.0,
- hint="Arbitrierungs-Timeout in Sekunden",
- ),
- "wakeword.min_audio_level": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- ),
- "wakeword.min_confidence": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- ),
- "wakeword.wakeword_trim_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=5.0,
- ),
- # --- Voice Recognition ---
- "voice_recognition.enabled": FieldMeta(
- editor=EditorType.BOOL,
- ),
- "voice_recognition.model": FieldMeta(
- editor=EditorType.TEXT,
- placeholder="default",
- ),
- "voice_recognition.threshold": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- ),
- # --- Conversation ---
- "conversation.max_silence_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.5,
- max_value=30.0,
- ),
- "conversation.max_duration_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=5.0,
- max_value=300.0,
- ),
- "conversation.timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=5.0,
- max_value=120.0,
- ),
- # --- Satellite Connection ---
- "satellite_connection.notification": FieldMeta(
- editor=EditorType.SELECT,
- choices=_NOTIFICATION_CHOICES,
- hint="Benachrichtigung bei Satellite-Verbindung",
- ),
- "satellite_connection.tts_text": FieldMeta(
- editor=EditorType.TEXT,
- placeholder="Verbunden",
- ),
- "satellite_connection.wave_file": FieldMeta(
- editor=EditorType.TEXT,
- placeholder="connected.wav",
- ),
- # --- STT Correction ---
- "stt_correction.enabled": FieldMeta(
- editor=EditorType.BOOL,
- hint="STT-Nachkorrektur aktivieren",
- ),
- "stt_correction.language": FieldMeta(
- editor=EditorType.TEXT,
- placeholder="de",
- ),
- "stt_correction.layers": FieldMeta(
- editor=EditorType.LIST_SELECT,
- choices=_STT_LAYER_CHOICES,
- hint="Aktive Korrektur-Layer",
- ),
- "stt_correction.protected_words": FieldMeta(
- editor=EditorType.LIST_TEXT,
- hint="Geschuetzte Woerter (kommasepariert)",
- ),
- "stt_correction.custom_aliases": FieldMeta(
- editor=EditorType.READONLY,
- hint="Benutzerdefinierte Aliase (nur Ansicht)",
- ),
- "stt_correction.symspell_max_edit_distance": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=1,
- max_value=5,
- ),
- "stt_correction.symspell_dictionary_path": FieldMeta(
- editor=EditorType.PATH,
- ),
- "stt_correction.kenlm_model_path": FieldMeta(
- editor=EditorType.PATH,
- ),
- "stt_correction.jamspell_model_path": FieldMeta(
- editor=EditorType.PATH,
- ),
- "stt_correction.hunspell_dict_path": FieldMeta(
- editor=EditorType.PATH,
- ),
- "stt_correction.languagetool_language": FieldMeta(
- editor=EditorType.TEXT,
- placeholder="de-DE",
- ),
- # --- Toplevel ---
- "satellites_directory": FieldMeta(editor=EditorType.PATH, placeholder="satellites"),
- "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
- "models_directory": FieldMeta(editor=EditorType.PATH, placeholder="models"),
- "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
- }
- def build_standalone_registry() -> dict[str, FieldMeta]:
- """Baut die Feld-Registry fuer Standalone-Konfiguration."""
- registry: dict[str, FieldMeta] = {}
- # Logging (gleich wie Server)
- server_reg = build_server_registry()
- for key in list(server_reg):
- if key.startswith("logging."):
- registry[key] = server_reg[key]
- # Security (gleich wie Server)
- for key in list(server_reg):
- if key.startswith("security."):
- registry[key] = server_reg[key]
- # Plugins (gleich wie Server)
- for key in list(server_reg):
- if key.startswith("plugins."):
- registry[key] = server_reg[key]
- # Voice Recognition, Conversation, STT Correction (gleich wie Server)
- for key in list(server_reg):
- if key.startswith(("voice_recognition.", "conversation.", "stt_correction.")):
- registry[key] = server_reg[key]
- # Audio (Standalone hat andere Struktur)
- registry.update({
- "audio.sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- ),
- "audio.channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- "audio.music_sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- ),
- "audio.music_channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.music_bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- "audio.buffer_size": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=64,
- max_value=8192,
- ),
- "audio.input_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
- "audio.output_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
- })
- # Wakeword (Client-Stil)
- registry.update({
- "wakeword.models": FieldMeta(
- editor=EditorType.LIST_SELECT,
- dynamic_source="wakeword_models",
- hint="Aktive Wakeword-Modelle",
- ),
- "wakeword.threshold": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- step=0.05,
- ),
- "wakeword.model_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="models/wakeword",
- ),
- "wakeword.use_onnx": FieldMeta(editor=EditorType.BOOL),
- "wakeword.enabled": FieldMeta(editor=EditorType.BOOL),
- "wakeword.silence_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.5,
- max_value=30.0,
- ),
- "wakeword.max_recording_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=5.0,
- max_value=300.0,
- ),
- "wakeword.no_speech_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=30.0,
- ),
- "wakeword.pre_buffer_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=5.0,
- ),
- "wakeword.wakeword_cooldown_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=30.0,
- ),
- })
- # Sync
- registry.update({
- "sync.enabled": FieldMeta(editor=EditorType.BOOL),
- "sync.server_host": FieldMeta(
- editor=EditorType.IP_ADDRESS,
- placeholder="Server-IP",
- ),
- "sync.server_port": _port("Sync-Server-Port"),
- "sync.probe_interval_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=5.0,
- max_value=600.0,
- ),
- "sync.sync_interval_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=10.0,
- max_value=3600.0,
- ),
- "sync.connect_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=60.0,
- ),
- "sync.sync_data_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="./sync_data",
- ),
- })
- # Toplevel
- registry.update({
- "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
- "models_directory": FieldMeta(editor=EditorType.PATH, placeholder="models"),
- "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
- "config_port": _port("Config-Port"),
- "room": FieldMeta(editor=EditorType.TEXT, placeholder="standalone"),
- "alias": FieldMeta(editor=EditorType.TEXT, placeholder="Trixy"),
- })
- return registry
- def build_client_registry() -> dict[str, FieldMeta]:
- """Baut die Feld-Registry fuer Client-Konfiguration."""
- registry: dict[str, FieldMeta] = {}
- # Server-Verbindung
- registry.update({
- "server.host": FieldMeta(
- editor=EditorType.IP_ADDRESS,
- placeholder="localhost",
- requires_restart=True,
- hint="Server-Adresse",
- ),
- "server.port": _port("Server-Port"),
- "server.reconnect_interval_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=60.0,
- ),
- "server.connection_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=60.0,
- ),
- })
- # Audio
- registry.update({
- "audio.sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- ),
- "audio.channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- "audio.music_sample_rate": FieldMeta(
- editor=EditorType.SELECT,
- choices=_SAMPLE_RATE_CHOICES,
- requires_restart=True,
- ),
- "audio.music_channels": FieldMeta(
- editor=EditorType.SELECT,
- choices=_CHANNELS_CHOICES,
- requires_restart=True,
- ),
- "audio.music_bit_depth": FieldMeta(
- editor=EditorType.SELECT,
- choices=_BIT_DEPTH_CHOICES,
- requires_restart=True,
- ),
- "audio.buffer_size": FieldMeta(
- editor=EditorType.NUMBER_INT,
- min_value=64,
- max_value=8192,
- ),
- "audio.input_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
- "audio.output_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
- })
- # Wakeword
- registry.update({
- "wakeword.models": FieldMeta(
- editor=EditorType.LIST_SELECT,
- dynamic_source="wakeword_models",
- hint="Aktive Wakeword-Modelle",
- ),
- "wakeword.threshold": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=1.0,
- step=0.05,
- ),
- "wakeword.model_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="models/wakeword",
- ),
- "wakeword.use_onnx": FieldMeta(editor=EditorType.BOOL),
- "wakeword.enabled": FieldMeta(editor=EditorType.BOOL),
- "wakeword.silence_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.5,
- max_value=30.0,
- ),
- "wakeword.max_recording_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=5.0,
- max_value=300.0,
- ),
- "wakeword.no_speech_timeout_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=1.0,
- max_value=30.0,
- ),
- "wakeword.pre_buffer_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=5.0,
- ),
- "wakeword.wakeword_cooldown_seconds": FieldMeta(
- editor=EditorType.NUMBER_FLOAT,
- min_value=0.0,
- max_value=30.0,
- ),
- })
- # Identity
- registry.update({
- "identity.room": FieldMeta(editor=EditorType.TEXT, placeholder="Raum-Name"),
- "identity.alias": FieldMeta(editor=EditorType.TEXT, placeholder="Alias"),
- "identity.mac_address": FieldMeta(
- editor=EditorType.READONLY,
- hint="Automatisch ermittelt",
- ),
- })
- # Logging
- registry.update({
- "logging.level": FieldMeta(
- editor=EditorType.SELECT,
- choices=_LOG_LEVEL_CHOICES,
- ),
- "logging.log_directory": FieldMeta(
- editor=EditorType.PATH,
- placeholder="logs",
- ),
- })
- # Toplevel
- registry.update({
- "config_port": _port("Config-Port"),
- "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
- "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
- })
- return registry
- def get_field_registry(instance_type: str) -> dict[str, FieldMeta]:
- """
- Factory: Gibt die passende Feld-Registry fuer den Instanz-Typ zurueck.
- Args:
- instance_type: "server", "standalone" oder "client"
- Returns:
- Dictionary mit Pfad -> FieldMeta Zuordnung
- """
- builders = {
- "server": build_server_registry,
- "standalone": build_standalone_registry,
- "client": build_client_registry,
- }
- builder = builders.get(instance_type)
- if builder:
- return builder()
- return {}
- def infer_field_meta(value: object) -> FieldMeta:
- """
- Inferiert FieldMeta aus dem Python-Typ des aktuellen Werts.
- Wird als Fallback verwendet wenn ein Feld nicht in der
- Registry eingetragen ist.
- Args:
- value: Aktueller Wert des Feldes
- Returns:
- Passendes FieldMeta basierend auf dem Typ
- """
- if isinstance(value, bool):
- return FieldMeta(editor=EditorType.BOOL)
- if isinstance(value, int):
- return FieldMeta(editor=EditorType.NUMBER_INT)
- if isinstance(value, float):
- return FieldMeta(editor=EditorType.NUMBER_FLOAT)
- if isinstance(value, list):
- return FieldMeta(editor=EditorType.LIST_TEXT)
- if isinstance(value, dict):
- return FieldMeta(editor=EditorType.READONLY)
- return FieldMeta(editor=EditorType.TEXT)
|