feat: invoke VedAstro for chart and rectification

This commit is contained in:
732642856
2026-07-18 04:15:19 +08:00
parent 145eadc5f5
commit f6fd53cca6
8 changed files with 53 additions and 12 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ def _bool_env(name: str) -> bool:
def _timeout_seconds() -> float:
raw = os.environ.get("VEDASTRO_TIMEOUT_SECONDS", "").strip()
if not raw:
return 4.0
return 20.0
try:
return float(raw)
except ValueError:
@@ -34,8 +34,8 @@ def _timeout_seconds() -> float:
def build_report() -> dict:
load_local_env(ROOT)
endpoint = os.environ.get("VEDASTRO_API_ENDPOINT", "").strip()
network_enabled = _bool_env("VEDASTRO_ENABLE_NETWORK")
endpoint = os.environ.get("VEDASTRO_API_ENDPOINT", "https://api.vedastro.org/api").strip()
network_enabled = os.environ.get("VEDASTRO_ENABLE_NETWORK", "1").strip().lower() in {"1", "true", "yes", "on"}
timeout_seconds = _timeout_seconds()
has_api_key = bool(os.environ.get("VEDASTRO_API_KEY", "").strip())
free_tier_queue_enabled = _bool_env("VEDASTRO_FREE_TIER_QUEUE") or _bool_env("VEDASTRO_FREE_TIER_QUEUE_ENABLED") or _bool_env("VEDASTRO_ENABLE_FREE_TIER_QUEUE")
+23
View File
@@ -648,6 +648,18 @@ def execute_consultation_workflow(
blind=bool(body.get('blind') or body.get('blind_technical_mode')),
)
vedastro_gateway = rectification.get('vedastro_gateway') if isinstance(rectification, dict) else None
if not isinstance(vedastro_gateway, dict):
try:
vedastro_gateway = handler._compute_vedastro_gateway_run(body)
except Exception as exc: # Gateway evidence must not block the local chart result.
vedastro_gateway = {
'scope': 'vedastro_gateway_run',
'status': 'official_blocked',
'official_closure_reason': 'gateway_invocation_error',
'error_type': type(exc).__name__,
}
result = {
'success': True,
'endpoint': 'consultation_workflow',
@@ -688,6 +700,7 @@ def execute_consultation_workflow(
'muhurta_panchanga': muhurta_panchanga,
'audited_remedies': audited_remedies,
'vedastro_official': vedastro_official,
'vedastro_gateway': vedastro_gateway,
'runtime_truth': runtime_truth,
'external_parity_gate': external_parity_gate,
'interpretation_source_runtime_coverage': interpretation_source_runtime_coverage,
@@ -6707,9 +6720,19 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
headline = '出生时间风险较低,可进入完整解盘'
next_action = '保留原始出生记录来源;重要预测仍建议用 Dasha/Transit/案例验证交叉确认。'
try:
vedastro_gateway = self._compute_vedastro_gateway_run(body)
except Exception as exc: # Keep rectification available when the external observation is down.
vedastro_gateway = {
'scope': 'vedastro_gateway_run',
'status': 'official_blocked',
'official_closure_reason': 'gateway_invocation_error',
'error_type': type(exc).__name__,
}
return {
'success': True,
'endpoint': 'rectification_gate',
'vedastro_gateway': vedastro_gateway,
'ascendant': {
'lon': asc_lon,
'sign': SIGNS[int(asc_lon / 30) % 12],
+8 -3
View File
@@ -15,12 +15,17 @@ from typing import Any
BACKEND_PRIORITY = ["self_host", "official", "cache", "queue", "local_fallback"]
BOUNDARY_TEXT = "Users never call VedAstro directly; backend gateway owns cache, queue, and fallback."
ROOT = Path(__file__).resolve().parents[1]
OFFICIAL_ENDPOINT = "https://api.vedastro.org/api"
def _bool_env(name: str) -> bool:
return os.environ.get(name, "").strip().lower() in {"1", "true", "yes", "on"}
def _official_network_enabled() -> bool:
return os.environ.get("VEDASTRO_ENABLE_NETWORK", "1").strip().lower() in {"1", "true", "yes", "on"}
def _int_env(name: str, default: int = 0) -> int:
raw = os.environ.get(name, "").strip()
if not raw:
@@ -32,9 +37,9 @@ def _int_env(name: str, default: int = 0) -> int:
def build_gateway_config() -> dict[str, Any]:
mode = os.environ.get("VEDASTRO_GATEWAY_MODE", "local_first").strip() or "local_first"
mode = os.environ.get("VEDASTRO_GATEWAY_MODE", "official_first").strip() or "official_first"
self_host = os.environ.get("VEDASTRO_SELF_HOST_ENDPOINT", "").strip()
official = os.environ.get("VEDASTRO_API_ENDPOINT", "").strip()
official = os.environ.get("VEDASTRO_API_ENDPOINT", OFFICIAL_ENDPOINT).strip()
return {
"mode": mode,
"self_host_endpoint_configured": bool(self_host),
@@ -49,7 +54,7 @@ def build_gateway_config() -> dict[str, Any]:
def _active_backend(config: dict[str, Any]) -> str:
if config["self_host_endpoint_configured"]:
return "self_host"
if config["official_endpoint_configured"] and _bool_env("VEDASTRO_ENABLE_NETWORK"):
if config["official_endpoint_configured"] and _official_network_enabled():
return "official"
if config["cache_ttl_seconds"] > 0:
return "cache"
+1 -1
View File
@@ -109,7 +109,7 @@ def _run_capability_catalog(case: dict[str, Any]) -> dict[str, Any]:
cwd=ROOT,
text=True,
capture_output=True,
timeout=max(5.0, float(os.environ.get("VEDASTRO_TIMEOUT_SECONDS", "5") or 5)),
timeout=max(5.0, float(os.environ.get("VEDASTRO_TIMEOUT_SECONDS", "20") or 20)),
check=False,
env=os.environ.copy(),
)