Skip to content

Commit b4db122

Browse files
Merge branch 'macae-v3-dev-v2-vip' into psl-waf-macaev3
2 parents 5082901 + 1af63fb commit b4db122

30 files changed

+2584
-1630
lines changed

src/backend/app_kernel.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
allow_origins=[
7474
"http://localhost:3000", # Add this for local development
7575
"https://localhost:3000", # Add this if using HTTPS locally
76-
"http://127.0.0.1:3000",
76+
"https://127.0.0.1:3000",
7777
"http://127.0.0.1:3001",
7878
], # Allow all origins for development; restrict in production
7979
allow_credentials=True,
@@ -598,9 +598,7 @@ async def approve_step_endpoint(
598598
@app.get("/api/plans")
599599
async def get_plans(
600600
request: Request,
601-
session_id: Optional[str] = Query(None),
602601
plan_id: Optional[str] = Query(None),
603-
team_id: Optional[str] = Query(None),
604602
):
605603
"""
606604
Retrieve plans for the current user.
@@ -673,20 +671,7 @@ async def get_plans(
673671

674672
# # Initialize memory context
675673
memory_store = await DatabaseFactory.get_database(user_id=user_id)
676-
if session_id:
677-
plan = await memory_store.get_plan_by_session(session_id=session_id)
678-
if not plan:
679-
track_event_if_configured(
680-
"GetPlanBySessionNotFound",
681-
{"status_code": 400, "detail": "Plan not found"},
682-
)
683-
raise HTTPException(status_code=404, detail="Plan not found")
684674

685-
# Use get_steps_by_plan to match the original implementation
686-
steps = await memory_store.get_steps_by_plan(plan_id=plan.id)
687-
plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps)
688-
plan_with_steps.update_step_counts()
689-
return [plan_with_steps]
690675
if plan_id:
691676
plan = await memory_store.get_plan_by_plan_id(plan_id=plan_id)
692677
if not plan:
@@ -712,7 +697,11 @@ async def get_plans(
712697

713698
return [plan_with_steps, formatted_messages]
714699

715-
all_plans = await memory_store.get_all_plans()
700+
current_team = await memory_store.get_current_team(user_id=user_id)
701+
if not current_team:
702+
return []
703+
704+
all_plans = await memory_store.get_all_plans_by_team_id(team_id=current_team.id)
716705
# Fetch steps for all plans concurrently
717706
steps_for_all_plans = await asyncio.gather(
718707
*[memory_store.get_steps_by_plan(plan_id=plan.id) for plan in all_plans]

src/backend/common/database/cosmosdb.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ async def get_all_plans(self) -> List[Plan]:
259259
]
260260
return await self.query_items(query, parameters, Plan)
261261

262+
async def get_all_plans_by_team_id(self, team_id: str) -> List[Plan]:
263+
"""Retrieve all plans for a specific team."""
264+
query = "SELECT * FROM c WHERE c.team_id=@team_id AND c.data_type=@data_type and c.user_id=@user_id"
265+
parameters = [
266+
{"name": "@user_id", "value": self.user_id},
267+
{"name": "@team_id", "value": team_id},
268+
{"name": "@data_type", "value": "plan"},
269+
]
270+
return await self.query_items(query, parameters, Plan)
271+
262272
# Step Operations
263273
async def add_step(self, step: Step) -> None:
264274
"""Add a step to CosmosDB."""
@@ -434,23 +444,22 @@ async def update_team(self, team: TeamConfiguration) -> None:
434444
"""
435445
await self.update_item(team)
436446

437-
async def get_current_team(self, user_id: str, team_id: str) -> UserCurrentTeam:
447+
async def get_current_team(self, user_id: str) -> Optional[UserCurrentTeam]:
438448
"""Retrieve the current team for a user."""
439449
await self._ensure_initialized()
440450
if self.container is None:
441451
return None
442452

443-
query = "SELECT * FROM c WHERE c.user_id=@user_id AND c.is_default=true"
453+
query = "SELECT * FROM c WHERE c.data_type=@data_type AND c.user_id=@user_id"
444454
parameters = [
455+
{"name": "@data_type", "value": "user_current_team"},
445456
{"name": "@user_id", "value": user_id},
446-
{"name": "@team_id", "value": team_id},
447457
]
448458

449-
items = self.container.query_items(query=query, parameters=parameters)
450-
async for item in items:
451-
return UserCurrentTeam(**item)
459+
# Get the appropriate model class
460+
teams = await self.query_items(query, parameters, UserCurrentTeam)
461+
return teams[0] if teams else None
452462

453-
return None
454463
async def set_current_team(self, current_team: UserCurrentTeam) -> None:
455464
"""Set the current team for a user."""
456465
await self._ensure_initialized()

src/backend/common/database/database_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ async def get_plan(self, plan_id: str) -> Optional[Plan]:
106106
async def get_all_plans(self) -> List[Plan]:
107107
"""Retrieve all plans for the user."""
108108
pass
109-
109+
@abstractmethod
110+
async def get_all_plans_by_team_id(self, team_id: str) -> List[Plan]:
111+
"""Retrieve all plans for a specific team."""
112+
pass
110113
@abstractmethod
111114
async def get_data_by_type_and_session_id(
112115
self, data_type: str, session_id: str
@@ -192,7 +195,7 @@ async def get_steps_for_plan(self, plan_id: str) -> List[Step]:
192195
pass
193196

194197
@abstractmethod
195-
async def get_current_team(self, user_id: str, team_id: str) -> UserCurrentTeam:
198+
async def get_current_team(self, user_id: str) -> Optional[UserCurrentTeam]:
196199
"""Retrieve the current team for a user."""
197200
pass
198201

src/backend/common/models/messages_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Plan(BaseDataModel):
119119
team_id: Optional[str] = None
120120
human_clarification_request: Optional[str] = None
121121
human_clarification_response: Optional[str] = None
122-
122+
123123

124124
class Step(BaseDataModel):
125125
"""Represents an individual step (task) within a plan."""

0 commit comments

Comments
 (0)