projects -> scripts (#3123)

This commit is contained in:
Shuchang Zheng
2025-08-06 22:23:38 -07:00
committed by GitHub
parent 75eadef0e1
commit 1a4bf1df1a
17 changed files with 660 additions and 538 deletions

View File

@@ -238,38 +238,38 @@ class ArtifactManager:
path=path,
)
async def create_project_file_artifact(
async def create_script_file_artifact(
self,
*,
organization_id: str,
project_id: str,
project_version: int,
script_id: str,
script_version: int,
file_path: str,
data: bytes,
) -> str:
"""Create an artifact for a project file.
"""Create an artifact for a script file.
Args:
organization_id: The organization ID
project_id: The project ID
project_version: The project version
file_path: The file path relative to project root
script_id: The script ID
script_version: The script version
file_path: The file path relative to script root
data: The file content as bytes
Returns:
The artifact ID
"""
artifact_id = generate_artifact_id()
uri = app.STORAGE.build_project_file_uri(
uri = app.STORAGE.build_script_file_uri(
organization_id=organization_id,
project_id=project_id,
project_version=project_version,
script_id=script_id,
script_version=script_version,
file_path=file_path,
)
return await self._create_artifact(
aio_task_primary_key=f"{project_id}_{project_version}",
aio_task_primary_key=f"{script_id}_{script_version}",
artifact_id=artifact_id,
artifact_type=ArtifactType.PROJECT_FILE,
artifact_type=ArtifactType.SCRIPT_FILE,
uri=uri,
organization_id=organization_id,
data=data,

View File

@@ -49,8 +49,8 @@ class ArtifactType(StrEnum):
TRACE = "trace"
HAR = "har"
# Project files
PROJECT_FILE = "project_file"
# Script files
SCRIPT_FILE = "script_file"
class Artifact(BaseModel):

View File

@@ -82,8 +82,8 @@ class BaseStorage(ABC):
pass
@abstractmethod
def build_project_file_uri(
self, *, organization_id: str, project_id: str, project_version: int, file_path: str
def build_script_file_uri(
self, *, organization_id: str, script_id: str, script_version: int, file_path: str
) -> str:
pass

View File

@@ -78,10 +78,10 @@ class LocalStorage(BaseStorage):
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"file://{self.artifact_path}/{settings.ENV}/{organization_id}/ai_suggestions/{ai_suggestion.ai_suggestion_id}/{datetime.utcnow().isoformat()}_{artifact_id}_{artifact_type}.{file_ext}"
def build_project_file_uri(
self, *, organization_id: str, project_id: str, project_version: int, file_path: str
def build_script_file_uri(
self, *, organization_id: str, script_id: str, script_version: int, file_path: str
) -> str:
return f"file://{self.artifact_path}/{settings.ENV}/{organization_id}/projects/{project_id}/{project_version}/{file_path}"
return f"file://{self.artifact_path}/{settings.ENV}/{organization_id}/scripts/{script_id}/{script_version}/{file_path}"
async def store_artifact(self, artifact: Artifact, data: bytes) -> None:
file_path = None

View File

@@ -84,21 +84,21 @@ class S3Storage(BaseStorage):
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"{self._build_base_uri(organization_id)}/ai_suggestions/{ai_suggestion.ai_suggestion_id}/{datetime.utcnow().isoformat()}_{artifact_id}_{artifact_type}.{file_ext}"
def build_project_file_uri(
self, *, organization_id: str, project_id: str, project_version: int, file_path: str
def build_script_file_uri(
self, *, organization_id: str, script_id: str, script_version: int, file_path: str
) -> str:
"""Build the S3 URI for a project file.
"""Build the S3 URI for a script file.
Args:
organization_id: The organization ID
project_id: The project ID
project_version: The project version
file_path: The file path relative to project root
script_id: The script ID
script_version: The script version
file_path: The file path relative to script root
Returns:
The S3 URI for the project file
The S3 URI for the script file
"""
return f"{self._build_base_uri(organization_id)}/projects/{project_id}/{project_version}/{file_path}"
return f"{self._build_base_uri(organization_id)}/scripts/{script_id}/{script_version}/{file_path}"
async def store_artifact(self, artifact: Artifact, data: bytes) -> None:
sc = await self._get_storage_class_for_org(artifact.organization_id)