-
Notifications
You must be signed in to change notification settings - Fork 930
Add session participants routes #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
creatorrr
wants to merge
2
commits into
dev
Choose a base branch
from
codex/add-route-to-find-users-by-session-id
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
agents-api/agents_api/queries/sessions/get_session_agents.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""SQL query to fetch agents for a given session.""" | ||
|
||
from uuid import UUID | ||
|
||
from beartype import beartype | ||
|
||
from ...autogen.openapi_model import Agent | ||
from ...common.utils.db_exceptions import common_db_exceptions | ||
from ...metrics.counters import query_metrics | ||
from ..utils import pg_query, rewrap_exceptions, wrap_in_class | ||
|
||
query = """ | ||
SELECT | ||
a.agent_id, | ||
a.developer_id, | ||
a.name, | ||
a.canonical_name, | ||
a.about, | ||
a.instructions, | ||
a.model, | ||
a.metadata, | ||
a.default_settings, | ||
a.default_system_template, | ||
a.created_at, | ||
a.updated_at, | ||
p.canonical_name AS project | ||
FROM session_lookup sl | ||
JOIN agents a ON sl.participant_id = a.agent_id | ||
AND sl.developer_id = a.developer_id | ||
LEFT JOIN project_agents pa ON a.agent_id = pa.agent_id | ||
AND a.developer_id = pa.developer_id | ||
LEFT JOIN projects p ON pa.project_id = p.project_id | ||
AND pa.developer_id = p.developer_id | ||
WHERE sl.developer_id = $1 | ||
AND sl.session_id = $2 | ||
AND sl.participant_type = 'agent'; | ||
""" | ||
|
||
|
||
@rewrap_exceptions(common_db_exceptions("session", ["get_agents"])) | ||
@wrap_in_class(Agent, transform=lambda d: {**d, "id": d["agent_id"]}) | ||
@query_metrics("get_session_agents") | ||
@pg_query | ||
@beartype | ||
async def get_session_agents(*, developer_id: UUID, session_id: UUID) -> tuple[str, list]: | ||
"""Return SQL query to retrieve agents of a session.""" | ||
|
||
return ( | ||
query, | ||
[developer_id, session_id], | ||
) |
46 changes: 46 additions & 0 deletions
46
agents-api/agents_api/queries/sessions/get_session_users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""SQL query to fetch users for a given session.""" | ||
|
||
from uuid import UUID | ||
|
||
from beartype import beartype | ||
|
||
from ...autogen.openapi_model import User | ||
from ...common.utils.db_exceptions import common_db_exceptions | ||
from ...metrics.counters import query_metrics | ||
from ..utils import pg_query, rewrap_exceptions, wrap_in_class | ||
|
||
query = """ | ||
SELECT | ||
u.user_id, | ||
u.developer_id, | ||
u.name, | ||
u.about, | ||
u.metadata, | ||
u.created_at, | ||
u.updated_at, | ||
p.canonical_name AS project | ||
FROM session_lookup sl | ||
JOIN users u ON sl.participant_id = u.user_id | ||
AND sl.developer_id = u.developer_id | ||
LEFT JOIN project_users pu ON u.user_id = pu.user_id | ||
AND u.developer_id = pu.developer_id | ||
LEFT JOIN projects p ON pu.project_id = p.project_id | ||
AND pu.developer_id = p.developer_id | ||
WHERE sl.developer_id = $1 | ||
AND sl.session_id = $2 | ||
AND sl.participant_type = 'user'; | ||
""" | ||
|
||
|
||
@rewrap_exceptions(common_db_exceptions("session", ["get_users"])) | ||
@wrap_in_class(User, transform=lambda d: {**d, "id": d["user_id"]}) | ||
@query_metrics("get_session_users") | ||
@pg_query | ||
@beartype | ||
async def get_session_users(*, developer_id: UUID, session_id: UUID) -> tuple[str, list]: | ||
"""Return SQL query to retrieve users of a session.""" | ||
|
||
return ( | ||
query, | ||
[developer_id, session_id], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
agents-api/agents_api/routers/sessions/get_session_agents.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""API endpoint to list agents for a session.""" | ||
|
||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
|
||
from ...autogen.openapi_model import Agent, ListResponse | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...queries.sessions.get_session_agents import ( | ||
get_session_agents as get_session_agents_query, | ||
) | ||
from .router import router | ||
|
||
|
||
@router.get("/sessions/{session_id}/agents", tags=["sessions"]) | ||
async def get_session_agents( | ||
session_id: UUID, | ||
x_developer_id: Annotated[UUID, Depends(get_developer_id)], | ||
) -> ListResponse[Agent]: | ||
"""Return agents associated with the session.""" | ||
|
||
agents = await get_session_agents_query( | ||
developer_id=x_developer_id, | ||
session_id=session_id, | ||
) | ||
return ListResponse[Agent](items=agents) |
25 changes: 25 additions & 0 deletions
25
agents-api/agents_api/routers/sessions/get_session_users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""API endpoint to list users for a session.""" | ||
|
||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
|
||
from ...autogen.openapi_model import ListResponse, User | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...queries.sessions.get_session_users import get_session_users as get_session_users_query | ||
from .router import router | ||
|
||
|
||
@router.get("/sessions/{session_id}/users", tags=["sessions"]) | ||
async def get_session_users( | ||
session_id: UUID, | ||
x_developer_id: Annotated[UUID, Depends(get_developer_id)], | ||
) -> ListResponse[User]: | ||
"""Return users associated with the session.""" | ||
|
||
users = await get_session_users_query( | ||
developer_id=x_developer_id, | ||
session_id=session_id, | ||
) | ||
return ListResponse[User](items=users) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add pagination parameters