diff --git a/src/ai_typewriter/config.py b/src/ai_typewriter/config.py index cef092b..f661699 100644 --- a/src/ai_typewriter/config.py +++ b/src/ai_typewriter/config.py @@ -15,7 +15,7 @@ class AppConfig: api_key: str = "" server_url: str = "http://localhost:11434" hotkey: str = "ctrl+alt+a" - request_timeout_seconds: float = 120.0 + request_timeout_seconds: float | None = 300.0 copy_wait_seconds: float = 1.0 type_delay_seconds: float = 0.0 restore_clipboard: bool = True @@ -33,6 +33,13 @@ def _coerce_provider(value: Any) -> Provider: return provider # type: ignore[return-value] +def _coerce_timeout(value: Any) -> float | None: + timeout = float(value) + if timeout <= 0: + return None + return timeout + + def load_config(path: str | Path = "config.json") -> AppConfig: cfg_path = Path(path) if not cfg_path.exists(): @@ -46,7 +53,7 @@ def load_config(path: str | Path = "config.json") -> AppConfig: api_key=str(data.get("api_key", "")), server_url=str(data.get("server_url", "http://localhost:11434")).rstrip("/"), hotkey=str(data.get("hotkey", "ctrl+alt+a")).lower(), - request_timeout_seconds=float(data.get("request_timeout_seconds", 120)), + request_timeout_seconds=_coerce_timeout(data.get("request_timeout_seconds", 300)), copy_wait_seconds=float(data.get("copy_wait_seconds", 1)), type_delay_seconds=float(data.get("type_delay_seconds", 0)), restore_clipboard=bool(data.get("restore_clipboard", True)),