-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2272 from Agenta-AI/feat/project-checkpoint-4
[Feature]: Project-checkpoint-4
- Loading branch information
Showing
24 changed files
with
517 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,90 @@ | ||
from typing import Optional, List | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel | ||
|
||
from fastapi import Request, Query, HTTPException | ||
from fastapi.responses import JSONResponse | ||
|
||
from agenta_backend.utils.common import isCloudEE, isOss, APIRouter | ||
from agenta_backend.services import db_manager | ||
|
||
if isCloudEE(): | ||
from agenta_backend.commons.services import db_manager_ee | ||
|
||
|
||
class ProjectsResponse(BaseModel): | ||
workspace_id: Optional[UUID] = None | ||
workspace_name: Optional[str] = None | ||
# is_default_workspace: Optional[bool] = None | ||
project_id: UUID | ||
project_name: str | ||
# is_default_project: bool | ||
user_role: Optional[str] = None | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get( | ||
"/", | ||
operation_id="get_projects", | ||
response_model=List[ProjectsResponse], | ||
) | ||
async def get_projects( | ||
request: Request, | ||
): | ||
try: | ||
if isOss(): | ||
_project = await db_manager.fetch_project_by_id( | ||
project_id=request.state.project_id | ||
) | ||
|
||
projects = [ | ||
ProjectsResponse( | ||
project_id=_project.id, | ||
project_name=_project.project_name, | ||
) | ||
] | ||
|
||
return projects | ||
|
||
elif isCloudEE(): | ||
_project_memberships = ( | ||
await db_manager_ee.fetch_project_memberships_by_user_id( | ||
user_id=request.state.user_id | ||
) | ||
) | ||
|
||
if not _project_memberships: | ||
return JSONResponse( | ||
status_code=404, | ||
content={"message": "No projects found."}, | ||
) | ||
|
||
projects = [ | ||
ProjectsResponse( | ||
workspace_id=project_membership.project.workspace.id, | ||
workspace_name=project_membership.project.workspace.name, | ||
project_id=project_membership.project.id, | ||
project_name=project_membership.project.project_name, | ||
user_role=project_membership.role, | ||
) | ||
for project_membership in _project_memberships | ||
] | ||
|
||
return projects | ||
|
||
else: | ||
return JSONResponse( | ||
status_code=404, | ||
content={"message": "No projects found."}, | ||
) | ||
|
||
except Exception as exc: # pylint: disable=bare-except | ||
print(exc) | ||
|
||
return JSONResponse( | ||
status_code=404, | ||
content={"message": "No projects found."}, | ||
) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "agenta" | ||
version = "0.27.3" | ||
version = "0.27.7a0" | ||
description = "The SDK for agenta is an open-source LLMOps platform." | ||
readme = "README.md" | ||
authors = ["Mahmoud Mabrouk <[email protected]>"] | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,111 @@ | ||
import {useSession} from "@/hooks/useSession" | ||
import {PropsWithChildren, createContext, useState, useContext, useEffect, useCallback} from "react" | ||
import {fetchAllProjects} from "@/services/project" | ||
import useStateCallback from "@/hooks/useStateCallback" | ||
import {dynamicContext} from "@/lib/helpers/dynamic" | ||
import {isDemo} from "@/lib/helpers/utils" | ||
|
||
const DEFAULT_UUID = "00000000-0000-0000-0000-000000000000" | ||
|
||
type Project = { | ||
workspace_id: string | null | ||
workspace_name: string | null | ||
project_id: string | null | ||
project_name: string | null | ||
user_role: string | null | ||
} | ||
|
||
type ProjectContextType = { | ||
project: Project | null | ||
isProjectId: boolean | ||
projectId: string | ||
isLoading: boolean | ||
reset: () => void | ||
refetch: (onSuccess?: () => void) => void | ||
} | ||
|
||
const initialValues: ProjectContextType = { | ||
project: null, | ||
isProjectId: false, | ||
projectId: "", | ||
isLoading: false, | ||
reset: () => {}, | ||
refetch: () => {}, | ||
} | ||
|
||
export const ProjectContext = createContext<ProjectContextType>(initialValues) | ||
|
||
export const useProjectData = () => useContext(ProjectContext) | ||
|
||
const projectContextValues = {...initialValues} | ||
|
||
export const getCurrentProject = () => projectContextValues | ||
|
||
const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => { | ||
const [project, setProject] = useStateCallback<Project | null>(null) | ||
const [useOrgData, setUseOrgData] = useState<Function>(() => () => "") | ||
const [isLoading, setIsLoading] = useState(false) | ||
const {doesSessionExist} = useSession() | ||
|
||
useEffect(() => { | ||
dynamicContext("org.context", {useOrgData}).then((context) => { | ||
setUseOrgData(() => context.useOrgData) | ||
}) | ||
}, []) | ||
|
||
const {selectedOrg} = useOrgData() | ||
|
||
const workspaceId: string = selectedOrg?.default_workspace.id || DEFAULT_UUID | ||
|
||
const isProjectId = !isLoading && Boolean(project?.project_id) | ||
const projectId = (project?.project_id as string) || DEFAULT_UUID | ||
|
||
const fetcher = async (onSuccess?: () => void) => { | ||
setIsLoading(true) | ||
try { | ||
const data = await fetchAllProjects() | ||
|
||
const _project = isDemo() | ||
? data.find((p: {workspace_id: string}) => p.workspace_id === workspaceId) | ||
: data[0] | ||
|
||
setProject(_project, onSuccess) | ||
} catch (error) { | ||
console.error(error) | ||
} finally { | ||
setIsLoading(false) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (doesSessionExist) { | ||
fetcher() | ||
} | ||
}, [doesSessionExist, selectedOrg]) | ||
|
||
const reset = () => { | ||
setProject(initialValues.project) | ||
} | ||
|
||
projectContextValues.project = project | ||
projectContextValues.isLoading = isLoading | ||
projectContextValues.isProjectId = isProjectId | ||
projectContextValues.projectId = projectId | ||
|
||
return ( | ||
<ProjectContext.Provider | ||
value={{ | ||
project, | ||
isProjectId, | ||
projectId, | ||
isLoading, | ||
reset, | ||
refetch: fetcher, | ||
}} | ||
> | ||
{children} | ||
</ProjectContext.Provider> | ||
) | ||
} | ||
|
||
export default ProjectContextProvider |
This file contains 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.