Skip to content

Commit

Permalink
Add browser session id to workflow runs
Browse files Browse the repository at this point in the history
  • Loading branch information
satansdeer committed Dec 16, 2024
1 parent 4966d58 commit 9b6f0f3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion skyvern-frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export type CreateTaskRequest = {
totp_verification_url?: string | null;
totp_identifier?: string | null;
application?: string | null;
reuse_browser_session?: string | null;
};

export type User = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ function createTaskRequestObject(
totp_verification_url: transform(formValues.totpVerificationUrl),
totp_identifier: transform(formValues.totpIdentifier),
error_code_mapping: errorCodeMapping,
reuse_browser_session:
(window.devCommands?.getValue("browserSessionId") as unknown as string) ??
null,
};
}

Expand Down
7 changes: 7 additions & 0 deletions skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type RunWorkflowRequestBody = {
data: Record<string, unknown>; // workflow parameters and values
proxy_location: ProxyLocation | null;
webhook_callback_url?: string | null;
browser_session_id?: string | null;
};

function getRunWorkflowRequestBody(
Expand All @@ -88,6 +89,12 @@ function getRunWorkflowRequestBody(
proxy_location: proxyLocation,
};

if (window.devCommands?.getValue("browserSessionId")) {
body.browser_session_id = window.devCommands.getValue(
"browserSessionId",
) as unknown as string;
}

if (webhookCallbackUrl) {
body.webhook_callback_url = webhookCallbackUrl;
}
Expand Down
8 changes: 8 additions & 0 deletions skyvern/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,11 @@ def __init__(self, reason: str | None, error_type: str | None):
class UnsupportedTaskType(SkyvernException):
def __init__(self, task_type: str):
super().__init__(f"Not supported task type [{task_type}]")


class BrowserSessionNotFound(SkyvernHTTPException):
def __init__(self, browser_session_id: str):
super().__init__(
f"Browser session not found. browser_session_id={browser_session_id}",
status_code=status.HTTP_404_NOT_FOUND,
)
1 change: 1 addition & 0 deletions skyvern/forge/sdk/workflow/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WorkflowRequestBody(BaseModel):
webhook_callback_url: str | None = None
totp_verification_url: str | None = None
totp_identifier: str | None = None
browser_session_id: str | None = None

@field_validator("webhook_callback_url", "totp_verification_url")
@classmethod
Expand Down
11 changes: 11 additions & 0 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SkyvernException,
WorkflowNotFound,
WorkflowRunNotFound,
BrowserSessionNotFound,
)
from skyvern.forge import app
from skyvern.forge.sdk.artifact.models import ArtifactType
Expand Down Expand Up @@ -114,6 +115,15 @@ async def setup_workflow_run(
LOG.error(f"Workflow {workflow_permanent_id} not found", workflow_version=version)
raise WorkflowNotFound(workflow_permanent_id=workflow_permanent_id, version=version)
workflow_id = workflow.workflow_id
if workflow_request.browser_session_id:
reusable_browser_session = app.PERSISTENT_SESSIONS_MANAGER.get_session(
organization_id=organization_id,
session_id=workflow_request.browser_session_id,
)
if reusable_browser_session is None:
raise BrowserSessionNotFound(browser_session_id=workflow_request.browser_session_id)
reusable_browser_session.reset_timeout()

if workflow_request.proxy_location is None and workflow.proxy_location is not None:
workflow_request.proxy_location = workflow.proxy_location
if workflow_request.webhook_callback_url is None and workflow.webhook_callback_url is not None:
Expand All @@ -140,6 +150,7 @@ async def setup_workflow_run(
workflow_id=workflow_id,
workflow_run_id=workflow_run.workflow_run_id,
max_steps_override=max_steps_override,
reuse_browser_session=workflow_request.browser_session_id,
)
)

Expand Down

0 comments on commit 9b6f0f3

Please sign in to comment.