mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-08 17:43:40 +00:00

Fix issue here in this discussion - https://github.com/microsoft/autogen/discussions/4208#discussioncomment-12394408 <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Fix bug in AGS UI where frontend crashes because the default team config is null - update /teams endpoint to always return a default team if none is found for the user - update UI to check for team before rendering - also update run_id type to be autoincrement int (similar to team id) instead of uuid. This helps side step the migration failed errors related to UUID type when using an sqlite backend <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed. --------- Co-authored-by: Ryan Sweet <rysweet@microsoft.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
# api/routes/teams.py
|
|
from typing import Dict
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ...datamodel import Team
|
|
from ...gallery.builder import create_default_gallery
|
|
from ..deps import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/")
|
|
async def list_teams(user_id: str, db=Depends(get_db)) -> Dict:
|
|
"""List all teams for a user"""
|
|
response = db.get(Team, filters={"user_id": user_id})
|
|
if not response.data or len(response.data) == 0:
|
|
default_gallery = create_default_gallery()
|
|
default_team = Team(user_id=user_id, component=default_gallery.components.teams[0].model_dump())
|
|
|
|
db.upsert(default_team)
|
|
response = db.get(Team, filters={"user_id": user_id})
|
|
|
|
return {"status": True, "data": response.data}
|
|
|
|
|
|
@router.get("/{team_id}")
|
|
async def get_team(team_id: int, user_id: str, db=Depends(get_db)) -> Dict:
|
|
"""Get a specific team"""
|
|
response = db.get(Team, filters={"id": team_id, "user_id": user_id})
|
|
if not response.status or not response.data:
|
|
raise HTTPException(status_code=404, detail="Team not found")
|
|
return {"status": True, "data": response.data[0]}
|
|
|
|
|
|
@router.post("/")
|
|
async def create_team(team: Team, db=Depends(get_db)) -> Dict:
|
|
"""Create a new team"""
|
|
response = db.upsert(team)
|
|
if not response.status:
|
|
raise HTTPException(status_code=400, detail=response.message)
|
|
return {"status": True, "data": response.data}
|
|
|
|
|
|
@router.delete("/{team_id}")
|
|
async def delete_team(team_id: int, user_id: str, db=Depends(get_db)) -> Dict:
|
|
"""Delete a team"""
|
|
db.delete(filters={"id": team_id, "user_id": user_id}, model_class=Team)
|
|
return {"status": True, "message": "Team deleted successfully"}
|