is_saved_task parameter for workflows (#526)
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
"""Add is_saved_task to workflows
|
||||||
|
|
||||||
|
Revision ID: 485667adef01
|
||||||
|
Revises: 2c163e606a3d
|
||||||
|
Create Date: 2024-06-27 19:49:41.506447+00:00
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "485667adef01"
|
||||||
|
down_revision: Union[str, None] = "2c163e606a3d"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column("workflows", sa.Column("is_saved_task", sa.Boolean(), server_default=sa.false(), nullable=False))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column("workflows", "is_saved_task")
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -774,6 +774,7 @@ class AgentDB:
|
|||||||
webhook_callback_url: str | None = None,
|
webhook_callback_url: str | None = None,
|
||||||
workflow_permanent_id: str | None = None,
|
workflow_permanent_id: str | None = None,
|
||||||
version: int | None = None,
|
version: int | None = None,
|
||||||
|
is_saved_task: bool = False,
|
||||||
) -> Workflow:
|
) -> Workflow:
|
||||||
async with self.Session() as session:
|
async with self.Session() as session:
|
||||||
workflow = WorkflowModel(
|
workflow = WorkflowModel(
|
||||||
@@ -783,6 +784,7 @@ class AgentDB:
|
|||||||
workflow_definition=workflow_definition,
|
workflow_definition=workflow_definition,
|
||||||
proxy_location=proxy_location,
|
proxy_location=proxy_location,
|
||||||
webhook_callback_url=webhook_callback_url,
|
webhook_callback_url=webhook_callback_url,
|
||||||
|
is_saved_task=is_saved_task,
|
||||||
)
|
)
|
||||||
if workflow_permanent_id:
|
if workflow_permanent_id:
|
||||||
workflow.workflow_permanent_id = workflow_permanent_id
|
workflow.workflow_permanent_id = workflow_permanent_id
|
||||||
@@ -838,6 +840,8 @@ class AgentDB:
|
|||||||
organization_id: str,
|
organization_id: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
page_size: int = 10,
|
page_size: int = 10,
|
||||||
|
only_saved_tasks: bool = False,
|
||||||
|
only_workflows: bool = False,
|
||||||
) -> list[Workflow]:
|
) -> list[Workflow]:
|
||||||
"""
|
"""
|
||||||
Get all workflows with the latest version for the organization.
|
Get all workflows with the latest version for the organization.
|
||||||
@@ -861,17 +865,18 @@ class AgentDB:
|
|||||||
)
|
)
|
||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
|
main_query = select(WorkflowModel).join(
|
||||||
|
subquery,
|
||||||
|
(WorkflowModel.organization_id == subquery.c.organization_id)
|
||||||
|
& (WorkflowModel.workflow_permanent_id == subquery.c.workflow_permanent_id)
|
||||||
|
& (WorkflowModel.version == subquery.c.max_version),
|
||||||
|
)
|
||||||
|
if only_saved_tasks:
|
||||||
|
main_query = main_query.where(WorkflowModel.is_saved_task.is_(True))
|
||||||
|
elif only_workflows:
|
||||||
|
main_query = main_query.where(WorkflowModel.is_saved_task.is_(False))
|
||||||
main_query = (
|
main_query = (
|
||||||
select(WorkflowModel)
|
main_query.order_by(WorkflowModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
|
||||||
.join(
|
|
||||||
subquery,
|
|
||||||
(WorkflowModel.organization_id == subquery.c.organization_id)
|
|
||||||
& (WorkflowModel.workflow_permanent_id == subquery.c.workflow_permanent_id)
|
|
||||||
& (WorkflowModel.version == subquery.c.max_version),
|
|
||||||
)
|
|
||||||
.order_by(WorkflowModel.created_at.desc()) # Example ordering by creation date
|
|
||||||
.limit(page_size)
|
|
||||||
.offset(db_page * page_size)
|
|
||||||
)
|
)
|
||||||
workflows = (await session.scalars(main_query)).all()
|
workflows = (await session.scalars(main_query)).all()
|
||||||
return [convert_to_workflow(workflow, self.debug_enabled) for workflow in workflows]
|
return [convert_to_workflow(workflow, self.debug_enabled) for workflow in workflows]
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ class WorkflowModel(Base):
|
|||||||
|
|
||||||
workflow_permanent_id = Column(String, nullable=False, default=generate_workflow_permanent_id, index=True)
|
workflow_permanent_id = Column(String, nullable=False, default=generate_workflow_permanent_id, index=True)
|
||||||
version = Column(Integer, default=1, nullable=False)
|
version = Column(Integer, default=1, nullable=False)
|
||||||
|
is_saved_task = Column(Boolean, default=False, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class WorkflowRunModel(Base):
|
class WorkflowRunModel(Base):
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ def convert_to_workflow(workflow_model: WorkflowModel, debug_enabled: bool = Fal
|
|||||||
webhook_callback_url=workflow_model.webhook_callback_url,
|
webhook_callback_url=workflow_model.webhook_callback_url,
|
||||||
proxy_location=(ProxyLocation(workflow_model.proxy_location) if workflow_model.proxy_location else None),
|
proxy_location=(ProxyLocation(workflow_model.proxy_location) if workflow_model.proxy_location else None),
|
||||||
version=workflow_model.version,
|
version=workflow_model.version,
|
||||||
|
is_saved_task=workflow_model.is_saved_task,
|
||||||
description=workflow_model.description,
|
description=workflow_model.description,
|
||||||
workflow_definition=WorkflowDefinition.model_validate(workflow_model.workflow_definition),
|
workflow_definition=WorkflowDefinition.model_validate(workflow_model.workflow_definition),
|
||||||
created_at=workflow_model.created_at,
|
created_at=workflow_model.created_at,
|
||||||
|
|||||||
@@ -654,16 +654,27 @@ async def delete_workflow(
|
|||||||
async def get_workflows(
|
async def get_workflows(
|
||||||
page: int = Query(1, ge=1),
|
page: int = Query(1, ge=1),
|
||||||
page_size: int = Query(10, ge=1),
|
page_size: int = Query(10, ge=1),
|
||||||
|
only_saved_tasks: bool = Query(False),
|
||||||
|
only_workflows: bool = Query(False),
|
||||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||||
) -> list[Workflow]:
|
) -> list[Workflow]:
|
||||||
"""
|
"""
|
||||||
Get all workflows with the latest version for the organization.
|
Get all workflows with the latest version for the organization.
|
||||||
"""
|
"""
|
||||||
analytics.capture("skyvern-oss-agent-workflows-get")
|
analytics.capture("skyvern-oss-agent-workflows-get")
|
||||||
|
|
||||||
|
if only_saved_tasks and only_workflows:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="only_saved_tasks and only_workflows cannot be used together",
|
||||||
|
)
|
||||||
|
|
||||||
return await app.WORKFLOW_SERVICE.get_workflows_by_organization_id(
|
return await app.WORKFLOW_SERVICE.get_workflows_by_organization_id(
|
||||||
organization_id=current_org.organization_id,
|
organization_id=current_org.organization_id,
|
||||||
page=page,
|
page=page,
|
||||||
page_size=page_size,
|
page_size=page_size,
|
||||||
|
only_saved_tasks=only_saved_tasks,
|
||||||
|
only_workflows=only_workflows,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class Workflow(BaseModel):
|
|||||||
title: str
|
title: str
|
||||||
workflow_permanent_id: str
|
workflow_permanent_id: str
|
||||||
version: int
|
version: int
|
||||||
|
is_saved_task: bool
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
workflow_definition: WorkflowDefinition
|
workflow_definition: WorkflowDefinition
|
||||||
proxy_location: ProxyLocation | None = None
|
proxy_location: ProxyLocation | None = None
|
||||||
|
|||||||
@@ -194,3 +194,4 @@ class WorkflowCreateYAMLRequest(BaseModel):
|
|||||||
proxy_location: ProxyLocation | None = None
|
proxy_location: ProxyLocation | None = None
|
||||||
webhook_callback_url: str | None = None
|
webhook_callback_url: str | None = None
|
||||||
workflow_definition: WorkflowDefinitionYAML
|
workflow_definition: WorkflowDefinitionYAML
|
||||||
|
is_saved_task: bool = False
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ class WorkflowService:
|
|||||||
webhook_callback_url: str | None = None,
|
webhook_callback_url: str | None = None,
|
||||||
workflow_permanent_id: str | None = None,
|
workflow_permanent_id: str | None = None,
|
||||||
version: int | None = None,
|
version: int | None = None,
|
||||||
|
is_saved_task: bool = False,
|
||||||
) -> Workflow:
|
) -> Workflow:
|
||||||
return await app.DATABASE.create_workflow(
|
return await app.DATABASE.create_workflow(
|
||||||
title=title,
|
title=title,
|
||||||
@@ -291,6 +292,7 @@ class WorkflowService:
|
|||||||
webhook_callback_url=webhook_callback_url,
|
webhook_callback_url=webhook_callback_url,
|
||||||
workflow_permanent_id=workflow_permanent_id,
|
workflow_permanent_id=workflow_permanent_id,
|
||||||
version=version,
|
version=version,
|
||||||
|
is_saved_task=is_saved_task,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_workflow(self, workflow_id: str, organization_id: str | None = None) -> Workflow:
|
async def get_workflow(self, workflow_id: str, organization_id: str | None = None) -> Workflow:
|
||||||
@@ -319,6 +321,8 @@ class WorkflowService:
|
|||||||
organization_id: str,
|
organization_id: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
page_size: int = 10,
|
page_size: int = 10,
|
||||||
|
only_saved_tasks: bool = False,
|
||||||
|
only_workflows: bool = False,
|
||||||
) -> list[Workflow]:
|
) -> list[Workflow]:
|
||||||
"""
|
"""
|
||||||
Get all workflows with the latest version for the organization.
|
Get all workflows with the latest version for the organization.
|
||||||
@@ -327,6 +331,8 @@ class WorkflowService:
|
|||||||
organization_id=organization_id,
|
organization_id=organization_id,
|
||||||
page=page,
|
page=page,
|
||||||
page_size=page_size,
|
page_size=page_size,
|
||||||
|
only_saved_tasks=only_saved_tasks,
|
||||||
|
only_workflows=only_workflows,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def update_workflow(
|
async def update_workflow(
|
||||||
@@ -773,6 +779,7 @@ class WorkflowService:
|
|||||||
webhook_callback_url=request.webhook_callback_url,
|
webhook_callback_url=request.webhook_callback_url,
|
||||||
workflow_permanent_id=workflow_permanent_id,
|
workflow_permanent_id=workflow_permanent_id,
|
||||||
version=existing_version + 1,
|
version=existing_version + 1,
|
||||||
|
is_saved_task=request.is_saved_task,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
workflow = await self.create_workflow(
|
workflow = await self.create_workflow(
|
||||||
@@ -782,6 +789,7 @@ class WorkflowService:
|
|||||||
organization_id=organization_id,
|
organization_id=organization_id,
|
||||||
proxy_location=request.proxy_location,
|
proxy_location=request.proxy_location,
|
||||||
webhook_callback_url=request.webhook_callback_url,
|
webhook_callback_url=request.webhook_callback_url,
|
||||||
|
is_saved_task=request.is_saved_task,
|
||||||
)
|
)
|
||||||
# Create parameters from the request
|
# Create parameters from the request
|
||||||
parameters: dict[str, PARAMETER_TYPE] = {}
|
parameters: dict[str, PARAMETER_TYPE] = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user