improvements for folders and parameters (#3918)
Co-authored-by: Jonathan Dobson <jon.m.dobson@gmail.com>
This commit is contained in:
@@ -1436,6 +1436,23 @@ class AgentDB:
|
||||
if version:
|
||||
workflow.version = version
|
||||
session.add(workflow)
|
||||
|
||||
# Update folder's modified_at if folder_id is provided
|
||||
if folder_id:
|
||||
# Validate folder exists and belongs to the same organization
|
||||
folder_stmt = (
|
||||
select(FolderModel)
|
||||
.where(FolderModel.folder_id == folder_id)
|
||||
.where(FolderModel.organization_id == organization_id)
|
||||
.where(FolderModel.deleted_at.is_(None))
|
||||
)
|
||||
folder_model = await session.scalar(folder_stmt)
|
||||
if not folder_model:
|
||||
raise ValueError(
|
||||
f"Folder {folder_id} not found or does not belong to organization {organization_id}"
|
||||
)
|
||||
folder_model.modified_at = datetime.utcnow()
|
||||
|
||||
await session.commit()
|
||||
await session.refresh(workflow)
|
||||
return convert_to_workflow(workflow, self.debug_enabled)
|
||||
|
||||
@@ -484,6 +484,7 @@ async def cancel_run(
|
||||
)
|
||||
async def create_workflow_legacy(
|
||||
request: Request,
|
||||
folder_id: str | None = Query(None, description="Optional folder ID to assign the workflow to"),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> Workflow:
|
||||
analytics.capture("skyvern-oss-agent-workflow-create-legacy")
|
||||
@@ -495,6 +496,9 @@ async def create_workflow_legacy(
|
||||
|
||||
try:
|
||||
workflow_create_request = WorkflowCreateYAMLRequest.model_validate(workflow_yaml)
|
||||
# Override folder_id if provided as query parameter
|
||||
if folder_id is not None:
|
||||
workflow_create_request.folder_id = folder_id
|
||||
return await app.WORKFLOW_SERVICE.create_workflow_from_request(
|
||||
organization=current_org, request=workflow_create_request
|
||||
)
|
||||
@@ -535,6 +539,7 @@ async def create_workflow_legacy(
|
||||
)
|
||||
async def create_workflow(
|
||||
data: WorkflowRequest,
|
||||
folder_id: str | None = Query(None, description="Optional folder ID to assign the workflow to"),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> Workflow:
|
||||
analytics.capture("skyvern-oss-agent-workflow-create")
|
||||
@@ -549,6 +554,9 @@ async def create_workflow(
|
||||
status_code=422,
|
||||
detail="Invalid workflow definition. Workflow should be provided in either yaml or json format.",
|
||||
)
|
||||
# Override folder_id if provided as query parameter
|
||||
if folder_id is not None:
|
||||
workflow_definition.folder_id = folder_id
|
||||
return await app.WORKFLOW_SERVICE.create_workflow_from_request(
|
||||
organization=current_org,
|
||||
request=workflow_definition,
|
||||
@@ -669,6 +677,7 @@ async def _validate_file_size(file: UploadFile) -> UploadFile:
|
||||
async def import_workflow_from_pdf(
|
||||
background_tasks: BackgroundTasks,
|
||||
file: UploadFile = Depends(_validate_file_size),
|
||||
folder_id: str | None = Query(None, description="Optional folder ID to assign the imported workflow to"),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> dict[str, Any]:
|
||||
"""Import a workflow from a PDF file containing Standard Operating Procedures."""
|
||||
@@ -702,6 +711,7 @@ async def import_workflow_from_pdf(
|
||||
workflow_definition={"parameters": [], "blocks": []},
|
||||
organization_id=current_org.organization_id,
|
||||
status=WorkflowStatus.importing,
|
||||
folder_id=folder_id,
|
||||
)
|
||||
|
||||
# Process PDF import in background (LLM call is the slow part)
|
||||
|
||||
@@ -2771,6 +2771,7 @@ class WorkflowService:
|
||||
ai_fallback=request.ai_fallback,
|
||||
run_sequentially=request.run_sequentially,
|
||||
sequential_key=request.sequential_key,
|
||||
folder_id=request.folder_id,
|
||||
)
|
||||
# Keeping track of the new workflow id to delete it if an error occurs during the creation process
|
||||
new_workflow_id = potential_workflow.workflow_id
|
||||
|
||||
Reference in New Issue
Block a user