Skip to content

Commit 5d57a6c

Browse files
committed
Refactor team selection to remove session_id and add user default team support
Removed session_id from TeamSelectionRequest and related API logic, simplifying team selection. Added support for setting and deleting a user's default team in backend services and database interfaces. Updated frontend TeamService to match new API contract.
1 parent 6316745 commit 5d57a6c

File tree

6 files changed

+70
-16
lines changed

6 files changed

+70
-16
lines changed

src/backend/common/database/cosmosdb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
AgentMessage,
3131
TeamConfiguration,
3232
DataType,
33+
UserCurrentTeam,
3334
)
3435

3536

@@ -431,3 +432,7 @@ async def update_team(self, team: TeamConfiguration) -> None:
431432
team: The TeamConfiguration to update
432433
"""
433434
await self.update_item(team)
435+
436+
async def set_user_default_team(current_team: UserCurrentTeam) -> bool:
437+
438+

src/backend/common/database/database_base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Plan,
1010
Step,
1111
TeamConfiguration,
12+
UserCurrentTeam,
1213
)
1314

1415

@@ -80,6 +81,7 @@ async def add_plan(self, plan: Plan) -> None:
8081
"""Add a plan to the database."""
8182
pass
8283

84+
8385
@abstractmethod
8486
async def update_plan(self, plan: Plan) -> None:
8587
"""Update a plan in the database."""
@@ -184,7 +186,13 @@ async def __aexit__(self, exc_type, exc, tb):
184186
"""Async context manager exit."""
185187
await self.close()
186188

187-
# Convenience aliases
189+
@abstractmethod
188190
async def get_steps_for_plan(self, plan_id: str) -> List[Step]:
189191
"""Convenience method aliasing get_steps_by_plan for compatibility."""
190192
pass
193+
194+
@abstractmethod
195+
async def set_user_default_team(self, UserCurrentTeam: UserCurrentTeam) -> bool:
196+
"""Set the default team for a user."""
197+
pass
198+

src/backend/common/models/messages_kernel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ class StartingTask(KernelBaseModel):
188188
class TeamSelectionRequest(KernelBaseModel):
189189
"""Request model for team selection."""
190190
team_id: str
191-
session_id: Optional[str] = None
192191

193192
class TeamConfiguration(BaseDataModel):
194193
"""Represents a team configuration stored in the database."""

src/backend/v3/api/router.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from common.database.database_factory import DatabaseFactory
1111
from common.models.messages_kernel import (GeneratePlanRequest, InputTask,
1212
Plan, PlanStatus,
13-
TeamSelectionRequest)
13+
TeamSelectionRequest, UserCurrentTeam)
1414
from common.utils.event_utils import track_event_if_configured
1515
from common.utils.utils_kernel import rai_success, rai_validate_team_config
1616
from fastapi import (APIRouter, BackgroundTasks, Depends, FastAPI, File,
@@ -763,9 +763,15 @@ async def select_team_endpoint(selection: TeamSelectionRequest, request: Request
763763
status_code=404,
764764
detail=f"Team configuration '{selection.team_id}' not found or access denied"
765765
)
766-
767-
# Generate session ID if not provided
768-
session_id = selection.session_id or str(uuid.uuid4())
766+
current_team = await team_service.get_user_current_team(user_id=user_id)
767+
if current_team and current_team.team_id != selection.team_id:
768+
current_team.team_id = selection.team_id
769+
await team_service.set_user_current_team(user_id=user_id, current_team=current_team, )
770+
else:
771+
current_team = UserCurrentTeam(
772+
user_id=user_id,
773+
team_id=selection.team_id
774+
)
769775

770776
# save to in-memory config for current user
771777
team_config.set_current_team(user_id=user_id, team_configuration=team_configuration)
@@ -777,8 +783,7 @@ async def select_team_endpoint(selection: TeamSelectionRequest, request: Request
777783
"status": "success",
778784
"team_id": selection.team_id,
779785
"team_name": team_configuration.name,
780-
"user_id": user_id,
781-
"session_id": session_id,
786+
"user_id": user_id
782787
},
783788
)
784789

@@ -787,7 +792,6 @@ async def select_team_endpoint(selection: TeamSelectionRequest, request: Request
787792
"message": f"Team '{team_configuration.name}' selected successfully",
788793
"team_id": selection.team_id,
789794
"team_name": team_configuration.name,
790-
"session_id": session_id,
791795
"agents_count": len(team_configuration.agents),
792796
"team_description": team_configuration.description,
793797
}

src/backend/v3/common/services/team_service.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,45 @@ async def get_team_configuration(
218218
self.logger.error("Error retrieving team configuration: %s", str(e))
219219
return None
220220

221+
async def delete_user_current_team(self, user_id: str) -> bool:
222+
"""
223+
Delete the current team for a user.
224+
225+
Args:
226+
user_id: User ID to delete the current team for
227+
228+
Returns:
229+
True if successful, False otherwise
230+
"""
231+
try:
232+
await self.memory_context.delete_user_current_team(user_id)
233+
self.logger.info("Successfully deleted current team for user %s", user_id)
234+
return True
235+
236+
except Exception as e:
237+
self.logger.error("Error deleting current team: %s", str(e))
238+
return False
239+
240+
async def set_default_team(self, user_id: str, team_id: str) -> bool:
241+
"""
242+
Set a default team for a user.
243+
244+
Args:
245+
user_id: User ID to set the default team for
246+
team_id: Team ID to set as default
247+
248+
Returns:
249+
True if successful, False otherwise
250+
"""
251+
try:
252+
await self.memory_context.set_user_default_team(user_id, team_id)
253+
self.logger.info("Successfully set default team for user %s: %s", user_id, team_id)
254+
return True
255+
256+
except Exception as e:
257+
self.logger.error("Error setting default team: %s", str(e))
258+
return False
259+
221260
async def get_all_team_configurations(
222261
self, user_id: str
223262
) -> List[TeamConfiguration]:

src/frontend/src/services/TeamService.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ export class TeamService {
3434
try {
3535
console.log('Calling /v3/init_team endpoint...');
3636
const response = await apiClient.get('/v3/init_team');
37-
37+
3838
console.log('Team initialization response:', response);
39-
39+
4040
return {
4141
success: true,
4242
data: response
4343
};
4444
} catch (error: any) {
4545
console.error('Team initialization failed:', error);
46-
46+
4747
let errorMessage = 'Failed to initialize team';
48-
48+
4949
if (error.response?.data?.detail) {
5050
errorMessage = error.response.data.detail;
5151
} else if (error.message) {
@@ -170,15 +170,14 @@ export class TeamService {
170170
/**
171171
* Select a team for a plan/session
172172
*/
173-
static async selectTeam(teamId: string, sessionId?: string): Promise<{
173+
static async selectTeam(teamId: string): Promise<{
174174
success: boolean;
175175
data?: any;
176176
error?: string;
177177
}> {
178178
try {
179179
const response = await apiClient.post('/v3/select_team', {
180180
team_id: teamId,
181-
session_id: sessionId
182181
});
183182

184183
return {
@@ -187,7 +186,7 @@ export class TeamService {
187186
};
188187
} catch (error: any) {
189188
let errorMessage = 'Failed to select team';
190-
189+
191190
if (error.response?.data?.detail) {
192191
errorMessage = error.response.data.detail;
193192
} else if (error.message) {

0 commit comments

Comments
 (0)