Skip to content

Commit db97226

Browse files
committed
Sandbox start conversation
1 parent 875e1f7 commit db97226

File tree

11 files changed

+321
-164
lines changed

11 files changed

+321
-164
lines changed

openhands_server/database.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from fastapi import Request
77
from google.cloud.sql.connector import Connector
8-
from sqlalchemy import create_engine
8+
from sqlalchemy import create_engine, select
99
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
1010
from sqlalchemy.orm import DeclarativeBase
1111
from sqlalchemy.util import await_only
@@ -175,6 +175,18 @@ async def create_tables() -> None:
175175
await conn.run_sync(Base.metadata.create_all)
176176
await conn.run_sync(SQLModel.metadata.create_all)
177177

178+
# TODO: Find a better way to add this fixture
179+
from openhands_server.user.user_models import UserInfo, UserScope
180+
181+
async with get_async_session_local()() as session:
182+
query = select(UserInfo).where(UserInfo.id == "root") # pyright: ignore
183+
result = await session.execute(query)
184+
user_info = result.scalar_one_or_none()
185+
if not user_info:
186+
user_info = UserInfo(id="root", user_scopes=[UserScope.SUPER_ADMIN]) # pyright: ignore
187+
session.add(user_info)
188+
await session.commit()
189+
178190

179191
async def drop_tables() -> None:
180192
"""Drop all database tables."""

openhands_server/dependency.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from dataclasses import dataclass
3-
from unittest.mock import MagicMock
3+
4+
import httpx
45

56
from openhands_server.config import get_global_config
67
from openhands_server.event.event_service import EventServiceResolver
@@ -58,6 +59,17 @@ def get_dependency_resolver():
5859
return _dependency_resolver
5960

6061

62+
# TODO: have this initialize as part of the app lifespan
63+
_httpx_client: httpx.AsyncClient | None
64+
65+
66+
def get_httpx_client() -> httpx.AsyncClient:
67+
global _httpx_client
68+
if _httpx_client is None:
69+
_httpx_client = httpx.AsyncClient()
70+
return _httpx_client
71+
72+
6173
def _get_event_service_factory():
6274
from openhands_server.event.filesystem_event_service import (
6375
FilesystemEventServiceResolver,
@@ -99,7 +111,7 @@ def _get_sandbox_spec_service_factory():
99111

100112

101113
def _get_sandboxed_conversation_service_factory():
102-
from openhands_server.sandboxed_conversation.sql_sandboxed_conversation_service import (
114+
from openhands_server.sandboxed_conversation.sql_sandboxed_conversation_service import ( # noqa: E501
103115
SQLSandboxedConversationServiceResolver,
104116
)
105117

openhands_server/errors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ class OpenHandsError(Exception):
33

44

55
class AuthError(OpenHandsError):
6-
"""Execution in authentication"""
6+
"""Error in authentication"""
77

88

99
class PermissionsError(OpenHandsError):
10-
"""Execution in permissions"""
10+
"""Error in permissions"""
11+
12+
13+
class SandboxError(OpenHandsError):
14+
"""Error in Sandbox"""

openhands_server/sandboxed_conversation/sandboxed_conversation_models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
from pydantic import BaseModel, Field
66
from sqlmodel import Field as SQLField, SQLModel
77

8-
from openhands.core.schema import AgentState
8+
from openhands.agent_server.models import SendMessageRequest
9+
from openhands.sdk.conversation.state import AgentExecutionStatus
910
from openhands_server.event_callback.event_callback_models import EventCallbackProcessor
1011
from openhands_server.sandbox.sandbox_models import SandboxStatus
1112
from openhands_server.utils.date_utils import utc_now
1213

1314

1415
class StoredConversationInfo(SQLModel):
1516
id: UUID = SQLField(default=uuid4, primary_key=True)
16-
title: str | None
17+
title: str | None = None
1718

1819
# I'm removing this for now because I am not sure if events include metrics anymore
1920
# metrics: MetricsSnapshot | None = None
@@ -25,7 +26,7 @@ class StoredConversationInfo(SQLModel):
2526

2627
class SandboxedConversationResponse(StoredConversationInfo):
2728
sandbox_status: SandboxStatus
28-
agent_status: AgentState | None
29+
agent_status: AgentExecutionStatus | None
2930

3031

3132
class SandboxedConversationResponseSortOrder(Enum):
@@ -52,4 +53,5 @@ class StartSandboxedConversationRequest(BaseModel):
5253
# Removed for now - just use value from UserInfo
5354
# model: str | None = None
5455

56+
initial_message: SendMessageRequest | None = None
5557
processors: list[EventCallbackProcessor] = Field(default_factory=list)

openhands_server/sandboxed_conversation/sandboxed_database_models.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)