Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions openhands-agent-server/openhands/agent_server/vscode_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""VSCode service for managing OpenVSCode Server in the agent server."""

import asyncio
import uuid
import os
from pathlib import Path

from openhands.sdk.logger import get_logger
Expand All @@ -16,6 +16,7 @@ class VSCodeService:
def __init__(
self,
port: int = 8001,
connection_token: str | None = None,
):
"""Initialize VSCode service.

Expand All @@ -26,7 +27,7 @@ def __init__(
exist
"""
self.port: int = port
self.connection_token: str | None = None
self.connection_token: str | None = connection_token
self.process: asyncio.subprocess.Process | None = None
self.openvscode_server_root: Path = Path("/openhands/.openvscode-server")
self.extensions_dir: Path = self.openvscode_server_root / "extensions"
Expand All @@ -45,8 +46,9 @@ async def start(self) -> bool:
)
return False

# Generate connection token
self.connection_token = str(uuid.uuid4())
# Generate connection token if not already set
if self.connection_token is None:
self.connection_token = os.urandom(32).hex()

# Check if port is available
if not await self._is_port_available():
Expand Down Expand Up @@ -95,7 +97,7 @@ def get_vscode_url(
Returns:
VSCode URL with token, or None if not available
"""
if not self.connection_token:
if self.connection_token is None:
return None

if base_url is None:
Expand Down Expand Up @@ -221,5 +223,10 @@ def get_vscode_service() -> VSCodeService | None:
logger.info("VSCode is disabled in configuration")
return None
else:
_vscode_service = VSCodeService(port=config.vscode_port)
connection_token = None
if config.session_api_keys:
connection_token = config.session_api_keys[0]
_vscode_service = VSCodeService(
port=config.vscode_port, connection_token=connection_token
)
return _vscode_service