Skip to content

Commit

Permalink
Add persistent browser session model
Browse files Browse the repository at this point in the history
  • Loading branch information
satansdeer committed Dec 17, 2024
1 parent dac6002 commit 33c15ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion skyvern/forge/sdk/db/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
TASK_GENERATION_PREFIX = "tg"
OBSERVER_CRUISE_ID = "oc"
OBSERVER_THOUGHT_ID = "ot"

PERSISTENT_BROWSER_SESSION_ID = "pbs"

def generate_workflow_id() -> str:
int_id = generate_id()
Expand Down Expand Up @@ -153,6 +153,11 @@ def generate_observer_thought_id() -> str:
return f"{OBSERVER_THOUGHT_ID}_{int_id}"


def generate_persistent_browser_session_id() -> str:
int_id = generate_id()
return f"{PERSISTENT_BROWSER_SESSION_ID}_{int_id}"


def generate_id() -> int:
"""
generate a 64-bit int ID
Expand Down
11 changes: 11 additions & 0 deletions skyvern/forge/sdk/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
generate_workflow_permanent_id,
generate_workflow_run_block_id,
generate_workflow_run_id,
generate_persistent_browser_session_id,
)
from skyvern.forge.sdk.schemas.tasks import ProxyLocation

Expand Down Expand Up @@ -540,3 +541,13 @@ class ObserverThoughtModel(Base):

created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)

class PersistentBrowserSessionModel(Base):
__tablename__ = "persistent_browser_sessions"

persistent_browser_session_id = Column(String, primary_key=True, default=generate_persistent_browser_session_id)
organization_id = Column(String, ForeignKey("organizations.organization_id"), nullable=False)
runnable_type = Column(String, nullable=False)
runnable_id = Column(String, nullable=False)
created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)
4 changes: 2 additions & 2 deletions skyvern/webeye/persistent_sessions_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

import uuid
from typing import Dict, List, Optional, Tuple

import structlog
from playwright.async_api import async_playwright

from skyvern.forge.sdk.db.id import generate_persistent_browser_session_id
from skyvern.forge.sdk.schemas.tasks import ProxyLocation
from skyvern.webeye.browser_factory import BrowserContextFactory, BrowserState
from skyvern.webeye.models import BrowserSessionResponse
Expand Down Expand Up @@ -37,7 +37,7 @@ async def create_session(
url: str | None = None,
) -> Tuple[str, BrowserState]:
"""Create a new browser session for an organization and return its ID with the browser state."""
session_id = str(uuid.uuid4())
session_id = generate_persistent_browser_session_id()

LOG.info(
"Creating new browser session",
Expand Down

0 comments on commit 33c15ac

Please sign in to comment.