"""One switch for every VedAstro call (BUG-2427, issue #327). Owner decision 2026-11-26: the product stops using VedAstro. Since July every call had failed and users only ever saw the local engine's results; a half-fixed request could also have swapped in the API's own sample chart. VedAstro is therefore OFF unless ``VEDASTRO_ENABLED`` is set to 1/true/yes/on. While it is off: - no network call, subprocess bridge, wait, timeout or cache write happens; - every entry point returns :func:`disabled_packet` at once; - the packet is backstage-only. Consumers must not turn it into a user-facing or model-visible "external check blocked / not done" line. ``VEDASTRO_API_KEY`` is no longer required anywhere; it is read only when the switch is on. """ from __future__ import annotations import os from typing import Any ENABLED_ENV = "VEDASTRO_ENABLED" DISABLED_STATUS = "disabled" DISABLED_REASON = "vedastro_disabled_by_owner_decision" DISABLED_DECISION = "owner_decision_2026_11_26" _TRUE = {"1", "true", "yes", "on"} def vedastro_enabled() -> bool: """True only when ``VEDASTRO_ENABLED`` is explicitly switched on.""" return os.environ.get(ENABLED_ENV, "").strip().lower() in _TRUE def disabled_packet(scope: str = "vedastro", **extra: Any) -> dict[str, Any]: """The answer every VedAstro entry point gives while the switch is off.""" packet: dict[str, Any] = { "scope": scope, "backend": "vedastro_disabled", "available": False, "status": DISABLED_STATUS, "official_closure_state": DISABLED_STATUS, "official_closure_reason": DISABLED_REASON, "reason": DISABLED_REASON, "decision": DISABLED_DECISION, "enable_env": ENABLED_ENV, "user_visibility": "backstage_only", } packet.update(extra) return packet def is_disabled_packet(value: Any) -> bool: return isinstance(value, dict) and ( value.get("official_closure_reason") == DISABLED_REASON or value.get("reason") == DISABLED_REASON ) class VedastroDisabledError(RuntimeError): """Raised by a low-level transport that was reached while the switch is off.""" def __init__(self) -> None: super().__init__(DISABLED_REASON) def require_enabled() -> None: """Hard stop for network/subprocess transports (defence in depth).""" if not vedastro_enabled(): raise VedastroDisabledError()