main.py
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from fastapi import FastAPI
from app.api.v1.router import api_router
from app.config.loader import ConfigLoader
from app.service.session_service import SessionService
from app.service.im_service import IMService
from app.service.agent_hub import AgentHub
from app.infrastructure.database import SessionLocal
app = FastAPI(title="Agent管理后台 API", version="1.0.0")
app.include_router(api_router)
agent_hub_instance = None
@app.on_event("startup")
async def startup_event():
global agent_hub_instance
config_loader = ConfigLoader()
db = SessionLocal()
session_service = SessionService(db)
im_service = IMService(
base_url="http://localhost:8080",
api_key="your-api-key"
)
agent_hub_instance = AgentHub(
config_loader=config_loader,
session_service=session_service,
im_service=im_service
)
@app.on_event("shutdown")
async def shutdown_event():
global agent_hub_instance
if agent_hub_instance:
await agent_hub_instance.close()
@app.get("/health")
def health_check():
return {"status": "ok"}