Spaces:
Running
Running
deploy(S4): Blender headless pipeline + WebAR client + backend fixes
Browse files
backend/routes/system_routes.py
CHANGED
|
@@ -62,3 +62,87 @@ async def handle_activation_event(payload: ActivationEventPayload):
|
|
| 62 |
import asyncio
|
| 63 |
asyncio.create_task(on_jarvis_friday_activated(payload.persona, payload.trigger_source))
|
| 64 |
return {"status": "ok", "message": "Activation sequence initiated"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
import asyncio
|
| 63 |
asyncio.create_task(on_jarvis_friday_activated(payload.persona, payload.trigger_source))
|
| 64 |
return {"status": "ok", "message": "Activation sequence initiated"}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@router.get("/key_diagnostics")
|
| 68 |
+
async def key_diagnostics(probe: bool = False):
|
| 69 |
+
"""Report, per key domain, whether this runtime can actually resolve its key.
|
| 70 |
+
|
| 71 |
+
Answers "does every key work *here*" rather than "is the key string valid" —
|
| 72 |
+
those are different questions, because get_secret() prefers the environment
|
| 73 |
+
(HF Space Secrets) and only falls back to the encrypted vault. A key can be
|
| 74 |
+
perfectly valid at the provider and still be unreachable from the process
|
| 75 |
+
that needs it.
|
| 76 |
+
|
| 77 |
+
Never returns a key value: only presence, length and a fingerprint. With
|
| 78 |
+
?probe=true it also makes one real upstream call per distinct key so the
|
| 79 |
+
result reflects live provider state, not just local resolution.
|
| 80 |
+
"""
|
| 81 |
+
import hashlib, os, json, urllib.request, urllib.error, urllib.parse
|
| 82 |
+
from backend.services.usb_vault import KeyDomain, KEY_DOMAIN_ENV_MAP, get_secret
|
| 83 |
+
|
| 84 |
+
def fingerprint(v: str) -> str:
|
| 85 |
+
return hashlib.sha256(v.encode()).hexdigest()[:10]
|
| 86 |
+
|
| 87 |
+
def probe_google(key: str):
|
| 88 |
+
url = ("https://generativelanguage.googleapis.com/v1beta/models?key="
|
| 89 |
+
+ urllib.parse.quote(key))
|
| 90 |
+
try:
|
| 91 |
+
with urllib.request.urlopen(url, timeout=20) as r:
|
| 92 |
+
return {"ok": True, "models": len(json.loads(r.read().decode()).get("models", []))}
|
| 93 |
+
except urllib.error.HTTPError as e:
|
| 94 |
+
return {"ok": False, "http": e.code}
|
| 95 |
+
except Exception as e:
|
| 96 |
+
return {"ok": False, "err": type(e).__name__}
|
| 97 |
+
|
| 98 |
+
domains, seen = [], {}
|
| 99 |
+
for domain, env_name in KEY_DOMAIN_ENV_MAP.items():
|
| 100 |
+
value = None
|
| 101 |
+
try:
|
| 102 |
+
value = get_secret(env_name)
|
| 103 |
+
except Exception:
|
| 104 |
+
value = None
|
| 105 |
+
entry = {
|
| 106 |
+
"domain": domain.value,
|
| 107 |
+
"env_var": env_name,
|
| 108 |
+
"resolved": bool(value),
|
| 109 |
+
"source": "env" if os.environ.get(env_name) else ("vault" if value else None),
|
| 110 |
+
"length": len(value) if value else 0,
|
| 111 |
+
"fingerprint": fingerprint(value) if value else None,
|
| 112 |
+
}
|
| 113 |
+
if probe and value:
|
| 114 |
+
fp = entry["fingerprint"]
|
| 115 |
+
if fp not in seen:
|
| 116 |
+
seen[fp] = probe_google(value)
|
| 117 |
+
entry["live"] = seen[fp]
|
| 118 |
+
domains.append(entry)
|
| 119 |
+
|
| 120 |
+
nvidia = []
|
| 121 |
+
for i in range(1, 16):
|
| 122 |
+
name = f"NVIDIA_API_KEY_{i}"
|
| 123 |
+
try:
|
| 124 |
+
v = get_secret(name)
|
| 125 |
+
except Exception:
|
| 126 |
+
v = None
|
| 127 |
+
nvidia.append({"env_var": name, "resolved": bool(v),
|
| 128 |
+
"source": "env" if os.environ.get(name) else ("vault" if v else None),
|
| 129 |
+
"fingerprint": fingerprint(v) if v else None})
|
| 130 |
+
|
| 131 |
+
others = {}
|
| 132 |
+
for name in ("GEMINI_API_KEY", "HF_API_TOKEN", "SKETCHFAB_TOKEN",
|
| 133 |
+
"BRAVE_SEARCH_API_KEY", "SERPAPI_KEY", "VAULT_MASTER_PASSWORD"):
|
| 134 |
+
try:
|
| 135 |
+
v = get_secret(name)
|
| 136 |
+
except Exception:
|
| 137 |
+
v = None
|
| 138 |
+
others[name] = {"resolved": bool(v),
|
| 139 |
+
"source": "env" if os.environ.get(name) else ("vault" if v else None)}
|
| 140 |
+
|
| 141 |
+
return {
|
| 142 |
+
"domains": domains,
|
| 143 |
+
"domains_resolved": sum(1 for d in domains if d["resolved"]),
|
| 144 |
+
"domains_total": len(domains),
|
| 145 |
+
"nvidia": nvidia,
|
| 146 |
+
"nvidia_resolved": sum(1 for n in nvidia if n["resolved"]),
|
| 147 |
+
"other": others,
|
| 148 |
+
}
|