fix: statut IA — suppression endpoint redondant + lecture runtime des clés API
Problème: l'indicateur affichait 'IA non configurée' alors que les actions AI fonctionnaient. Causes: 1. Deux endpoints /api/ai/status en conflit (main.py + ai_routes.py) 2. ai_routes.py lisait PROVIDERS évalué à l'import (os.getenv figé) 3. Cache côté frontend (_aiStatusChecked) empêchait de re-vérifier Fixes: - Suppression de l'endpoint redondant dans main.py - ai_routes.py: lecture os.getenv au runtime (pas depuis PROVIDERS) - sync.js: _checkAIStatus() appelée à chaque ouverture du panneau
This commit is contained in:
+15
-4
@@ -19,12 +19,23 @@ router = APIRouter(prefix="/api/ai", tags=["AI"])
|
||||
|
||||
@router.get("/status")
|
||||
async def api_status():
|
||||
"""Check if AI is configured and which providers are available."""
|
||||
"""Check if AI is configured and which providers are available.
|
||||
|
||||
Reads environment variables at runtime so that changes to
|
||||
.env or Docker environment are reflected immediately.
|
||||
"""
|
||||
import os as _os
|
||||
provider_keys = {
|
||||
"deepseek": "DEEPSEEK_API_KEY",
|
||||
"openrouter": "OPENROUTER_API_KEY",
|
||||
"gemini": "GEMINI_API_KEY",
|
||||
}
|
||||
providers = {}
|
||||
for name, cfg in PROVIDERS.items():
|
||||
for name, env_var in provider_keys.items():
|
||||
has_key = bool(_os.getenv(env_var, "").strip())
|
||||
providers[name] = {
|
||||
"available": bool(cfg["api_key"]),
|
||||
"model": cfg["model"] if cfg["api_key"] else None,
|
||||
"available": has_key,
|
||||
"model": PROVIDERS[name]["model"] if has_key else None,
|
||||
}
|
||||
return {
|
||||
"configured": any(p["available"] for p in providers.values()),
|
||||
|
||||
@@ -2165,21 +2165,6 @@ async def api_file_restore(
|
||||
raise HTTPException(status_code=500, detail=f"Error restoring file: {str(e)}")
|
||||
|
||||
|
||||
@app.get("/api/ai/status")
|
||||
async def api_ai_status(current_user=Depends(require_auth)):
|
||||
"""Return the AI configuration status.
|
||||
|
||||
Checks whether any AI provider API key is configured.
|
||||
Does NOT expose the key itself, only a boolean 'configured' flag.
|
||||
"""
|
||||
providers = ["DEEPSEEK_API_KEY", "OPENROUTER_API_KEY", "GEMINI_API_KEY"]
|
||||
configured = any(
|
||||
os.environ.get(env_var, "").strip()
|
||||
for env_var in providers
|
||||
)
|
||||
return {"configured": configured, "providers_checked": providers}
|
||||
|
||||
|
||||
@app.get("/api/file/{vault_name}/backlinks")
|
||||
async def api_file_backlinks(
|
||||
vault_name: str,
|
||||
|
||||
Reference in New Issue
Block a user