mirror of https://github.com/kortix-ai/suna.git
wip
This commit is contained in:
parent
e38d8f327e
commit
aed291e7c3
|
@ -1,8 +1,10 @@
|
||||||
from fastapi import APIRouter, HTTPException, Depends
|
from fastapi import APIRouter, HTTPException, Depends
|
||||||
from typing import Optional
|
from typing import Optional, Dict
|
||||||
from utils.auth_utils import verify_admin_api_key
|
from utils.auth_utils import verify_admin_api_key
|
||||||
from utils.suna_default_agent_service import SunaDefaultAgentService
|
from utils.suna_default_agent_service import SunaDefaultAgentService
|
||||||
from utils.logger import logger
|
from utils.logger import logger
|
||||||
|
from utils.config import config, EnvMode
|
||||||
|
from dotenv import load_dotenv, set_key, find_dotenv, dotenv_values
|
||||||
|
|
||||||
router = APIRouter(prefix="/admin", tags=["admin"])
|
router = APIRouter(prefix="/admin", tags=["admin"])
|
||||||
|
|
||||||
|
@ -39,4 +41,42 @@ async def admin_install_suna_for_user(
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
detail=f"Failed to install Suna agent for user {account_id}"
|
detail=f"Failed to install Suna agent for user {account_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@router.get("/env-vars")
|
||||||
|
def get_env_vars() -> Dict[str, str]:
|
||||||
|
"""Get environment variables (local mode only)."""
|
||||||
|
if config.ENV_MODE != EnvMode.LOCAL:
|
||||||
|
raise HTTPException(status_code=403, detail="Env vars management only available in local mode")
|
||||||
|
|
||||||
|
try:
|
||||||
|
env_path = find_dotenv()
|
||||||
|
if not env_path:
|
||||||
|
logger.error("Could not find .env file")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return dotenv_values(env_path)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to get env vars: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"Failed to get env variables: {e}")
|
||||||
|
|
||||||
|
@router.post("/env-vars")
|
||||||
|
def save_env_vars(request: Dict[str, str]) -> Dict[str, str]:
|
||||||
|
"""Save environment variables (local mode only)."""
|
||||||
|
if config.ENV_MODE != EnvMode.LOCAL:
|
||||||
|
raise HTTPException(status_code=403, detail="Env vars management only available in local mode")
|
||||||
|
|
||||||
|
try:
|
||||||
|
env_path = find_dotenv()
|
||||||
|
if not env_path:
|
||||||
|
raise HTTPException(status_code=500, detail="Could not find .env file")
|
||||||
|
|
||||||
|
for key, value in request.items():
|
||||||
|
set_key(env_path, key, value)
|
||||||
|
|
||||||
|
load_dotenv(override=True)
|
||||||
|
logger.info(f"Env variables saved successfully: {request}")
|
||||||
|
return {"message": "Env variables saved successfully"}
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to save env variables: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"Failed to save env variables: {e}")
|
|
@ -189,8 +189,7 @@ api_router.include_router(pipedream_api.router)
|
||||||
|
|
||||||
# MFA functionality moved to frontend
|
# MFA functionality moved to frontend
|
||||||
|
|
||||||
from local_env_manager import api as local_env_manager_api
|
|
||||||
api_router.include_router(local_env_manager_api.router)
|
|
||||||
|
|
||||||
from admin import api as admin_api
|
from admin import api as admin_api
|
||||||
api_router.include_router(admin_api.router)
|
api_router.include_router(admin_api.router)
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
from fastapi import APIRouter
|
|
||||||
from utils.config import config, EnvMode
|
|
||||||
from fastapi import HTTPException
|
|
||||||
from typing import Dict
|
|
||||||
from dotenv import load_dotenv, set_key, find_dotenv, dotenv_values
|
|
||||||
from utils.logger import logger
|
|
||||||
|
|
||||||
router = APIRouter(tags=["local-env-manager"])
|
|
||||||
|
|
||||||
@router.get("/env-vars")
|
|
||||||
def get_env_vars() -> Dict[str, str]:
|
|
||||||
if config.ENV_MODE != EnvMode.LOCAL:
|
|
||||||
raise HTTPException(status_code=403, detail="Env vars management only available in local mode")
|
|
||||||
|
|
||||||
try:
|
|
||||||
env_path = find_dotenv()
|
|
||||||
if not env_path:
|
|
||||||
logger.error("Could not find .env file")
|
|
||||||
return {}
|
|
||||||
|
|
||||||
return dotenv_values(env_path)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to get env vars: {e}")
|
|
||||||
raise HTTPException(status_code=500, detail=f"Failed to get env variables: {e}")
|
|
||||||
|
|
||||||
@router.post("/env-vars")
|
|
||||||
def save_env_vars(request: Dict[str, str]) -> Dict[str, str]:
|
|
||||||
if config.ENV_MODE != EnvMode.LOCAL:
|
|
||||||
raise HTTPException(status_code=403, detail="Env vars management only available in local mode")
|
|
||||||
|
|
||||||
try:
|
|
||||||
env_path = find_dotenv()
|
|
||||||
if not env_path:
|
|
||||||
raise HTTPException(status_code=500, detail="Could not find .env file")
|
|
||||||
|
|
||||||
for key, value in request.items():
|
|
||||||
set_key(env_path, key, value)
|
|
||||||
|
|
||||||
load_dotenv(override=True)
|
|
||||||
logger.info(f"Env variables saved successfully: {request}")
|
|
||||||
return {"message": "Env variables saved successfully"}
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to save env variables: {e}")
|
|
||||||
raise HTTPException(status_code=500, detail=f"Failed to save env variables: {e}")
|
|
|
@ -8,8 +8,6 @@ import { CustomMCPDialog } from './custom-mcp-dialog';
|
||||||
import { PipedreamRegistry } from '@/components/agents/pipedream/pipedream-registry';
|
import { PipedreamRegistry } from '@/components/agents/pipedream/pipedream-registry';
|
||||||
import { ToolsManager } from './tools-manager';
|
import { ToolsManager } from './tools-manager';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
|
||||||
import { agentKeys } from '@/hooks/react-query/agents/keys';
|
|
||||||
|
|
||||||
export const MCPConfigurationNew: React.FC<MCPConfigurationProps> = ({
|
export const MCPConfigurationNew: React.FC<MCPConfigurationProps> = ({
|
||||||
configuredMCPs,
|
configuredMCPs,
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function LocalEnvManager() {
|
||||||
const {data: apiKeys, isLoading} = useQuery({
|
const {data: apiKeys, isLoading} = useQuery({
|
||||||
queryKey: ['api-keys'],
|
queryKey: ['api-keys'],
|
||||||
queryFn: async() => {
|
queryFn: async() => {
|
||||||
const response = await backendApi.get('/env-vars');
|
const response = await backendApi.get('/admin/env-vars');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
enabled: isLocalMode()
|
enabled: isLocalMode()
|
||||||
|
@ -82,7 +82,7 @@ export function LocalEnvManager() {
|
||||||
|
|
||||||
const updateApiKeys = useMutation({
|
const updateApiKeys = useMutation({
|
||||||
mutationFn: async (data: APIKeyForm) => {
|
mutationFn: async (data: APIKeyForm) => {
|
||||||
const response = await backendApi.post('/env-vars', data);
|
const response = await backendApi.post('/admin/env-vars', data);
|
||||||
await queryClient.invalidateQueries({ queryKey: ['api-keys'] });
|
await queryClient.invalidateQueries({ queryKey: ['api-keys'] });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue