Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor: move openhands.utils to openhands.app_server.utils (#14223)

Tim O'Farrell18460a3461ac
diff --git a/enterprise/integrations/github/github_view.py b/enterprise/integrations/github/github_view.py
index 832ff2bbf1..b5cce6f2a7 100644
--- a/enterprise/integrations/github/github_view.py
+++ b/enterprise/integrations/github/github_view.py
@@ -40,9 +40,9 @@ from openhands.app_server.integrations.service_types import Comment
from openhands.app_server.services.injector import InjectorState
from openhands.app_server.user.specifiy_user_context import USER_CONTEXT_ATTR
from openhands.app_server.user_auth.user_auth import UserAuth
+from openhands.app_server.utils.async_utils import call_sync_from_async
from openhands.core.logger import openhands_logger as logger
from openhands.sdk import TextContent
-from openhands.utils.async_utils import call_sync_from_async
OH_LABEL, INLINE_OH_LABEL = get_oh_labels(HOST)
diff --git a/enterprise/integrations/jira/jira_manager.py b/enterprise/integrations/jira/jira_manager.py
index 6701f4feb0..417e962ce7 100644
--- a/enterprise/integrations/jira/jira_manager.py
+++ b/enterprise/integrations/jira/jira_manager.py
@@ -43,13 +43,13 @@ from storage.jira_user import JiraUser
from storage.jira_workspace import JiraWorkspace
from openhands.app_server.user_auth.user_auth import UserAuth
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
from openhands.server.types import (
LLMAuthenticationError,
MissingSettingsError,
SessionExpiredError,
)
-from openhands.utils.http_session import httpx_verify_option
JIRA_CLOUD_API_URL = 'https://api.atlassian.com/ex/jira'
diff --git a/enterprise/integrations/jira/jira_v1_callback_processor.py b/enterprise/integrations/jira/jira_v1_callback_processor.py
index 04b4697291..4278f5458e 100644
--- a/enterprise/integrations/jira/jira_v1_callback_processor.py
+++ b/enterprise/integrations/jira/jira_v1_callback_processor.py
@@ -19,9 +19,9 @@ from openhands.app_server.event_callback.util import (
ensure_running_sandbox,
get_agent_server_url_from_sandbox,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.sdk import Event
from openhands.sdk.event import ConversationStateUpdateEvent
-from openhands.utils.http_session import httpx_verify_option
_logger = logging.getLogger(__name__)
diff --git a/enterprise/integrations/jira/jira_view.py b/enterprise/integrations/jira/jira_view.py
index 3c93537f74..61ce44174a 100644
--- a/enterprise/integrations/jira/jira_view.py
+++ b/enterprise/integrations/jira/jira_view.py
@@ -42,9 +42,9 @@ from openhands.app_server.integrations.provider import ProviderHandler, Provider
from openhands.app_server.services.injector import InjectorState
from openhands.app_server.user.specifiy_user_context import USER_CONTEXT_ATTR
from openhands.app_server.user_auth.user_auth import UserAuth
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
from openhands.sdk import TextContent
-from openhands.utils.http_session import httpx_verify_option
JIRA_CLOUD_API_URL = 'https://api.atlassian.com/ex/jira'
diff --git a/enterprise/integrations/jira_dc/jira_dc_manager.py b/enterprise/integrations/jira_dc/jira_dc_manager.py
index 5ac0447dd1..97329fbae8 100644
--- a/enterprise/integrations/jira_dc/jira_dc_manager.py
+++ b/enterprise/integrations/jira_dc/jira_dc_manager.py
@@ -32,6 +32,7 @@ from storage.jira_dc_workspace import JiraDcWorkspace
from openhands.app_server.integrations.provider import ProviderHandler
from openhands.app_server.integrations.service_types import Repository
from openhands.app_server.user_auth.user_auth import UserAuth
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
from openhands.server.shared import server_config
from openhands.server.types import (
@@ -39,7 +40,6 @@ from openhands.server.types import (
MissingSettingsError,
SessionExpiredError,
)
-from openhands.utils.http_session import httpx_verify_option
class JiraDcManager(Manager[JiraDcViewInterface]):
diff --git a/enterprise/integrations/jira_dc/jira_dc_v1_callback_processor.py b/enterprise/integrations/jira_dc/jira_dc_v1_callback_processor.py
index a65ee933b1..51c0388b53 100644
--- a/enterprise/integrations/jira_dc/jira_dc_v1_callback_processor.py
+++ b/enterprise/integrations/jira_dc/jira_dc_v1_callback_processor.py
@@ -25,9 +25,9 @@ from openhands.app_server.event_callback.util import (
ensure_running_sandbox,
get_agent_server_url_from_sandbox,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.sdk import Event
from openhands.sdk.event import ConversationStateUpdateEvent
-from openhands.utils.http_session import httpx_verify_option
_logger = logging.getLogger(__name__)
diff --git a/enterprise/integrations/slack/slack_view.py b/enterprise/integrations/slack/slack_view.py
index deb560f058..b0c99591fe 100644
--- a/enterprise/integrations/slack/slack_view.py
+++ b/enterprise/integrations/slack/slack_view.py
@@ -35,9 +35,9 @@ from openhands.app_server.sandbox.sandbox_models import SandboxStatus
from openhands.app_server.services.injector import InjectorState
from openhands.app_server.user.specifiy_user_context import USER_CONTEXT_ATTR
from openhands.app_server.user_auth.user_auth import UserAuth
+from openhands.app_server.utils.async_utils import GENERAL_TIMEOUT
from openhands.core.logger import openhands_logger as logger
from openhands.sdk import TextContent
-from openhands.utils.async_utils import GENERAL_TIMEOUT
# =================================================
# SECTION: Slack view types
diff --git a/enterprise/server/auth/token_manager.py b/enterprise/server/auth/token_manager.py
index 4bbbcd3667..dd25c09b3a 100644
--- a/enterprise/server/auth/token_manager.py
+++ b/enterprise/server/auth/token_manager.py
@@ -52,8 +52,8 @@ from storage.offline_token_store import OfflineTokenStore
from tenacity import RetryCallState, retry, retry_if_exception_type, stop_after_attempt
from openhands.app_server.integrations.service_types import ProviderType
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.server.types import SessionExpiredError
-from openhands.utils.http_session import httpx_verify_option
class KeycloakUserInfo(BaseModel):
diff --git a/enterprise/server/routes/bitbucket_dc_proxy.py b/enterprise/server/routes/bitbucket_dc_proxy.py
index aae25d823f..25e8155d32 100644
--- a/enterprise/server/routes/bitbucket_dc_proxy.py
+++ b/enterprise/server/routes/bitbucket_dc_proxy.py
@@ -3,7 +3,7 @@ from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse
from server.auth.constants import BITBUCKET_DATA_CENTER_HOST
-from openhands.utils.http_session import httpx_verify_option
+from openhands.app_server.utils.http_session import httpx_verify_option
router = APIRouter(prefix='/bitbucket-dc-proxy')
diff --git a/enterprise/server/routes/github_proxy.py b/enterprise/server/routes/github_proxy.py
index 22cb0f2352..96091ddcae 100644
--- a/enterprise/server/routes/github_proxy.py
+++ b/enterprise/server/routes/github_proxy.py
@@ -11,8 +11,8 @@ from fastapi import FastAPI, Request, Response
from fastapi.responses import RedirectResponse
from server.logger import logger
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.server.shared import config
-from openhands.utils.http_session import httpx_verify_option
GITHUB_PROXY_ENDPOINTS = bool(os.environ.get('GITHUB_PROXY_ENDPOINTS'))
diff --git a/enterprise/server/routes/org_models.py b/enterprise/server/routes/org_models.py
index 6965a3d440..610a328605 100644
--- a/enterprise/server/routes/org_models.py
+++ b/enterprise/server/routes/org_models.py
@@ -14,8 +14,8 @@ from storage.org import Org
from storage.org_member import OrgMember
from storage.role import Role
+from openhands.app_server.utils.llm import MASKED_API_KEY, resolve_llm_base_url
from openhands.sdk.settings import AgentSettings, ConversationSettings
-from openhands.utils.llm import MASKED_API_KEY, resolve_llm_base_url
class OrgCreationError(Exception):
diff --git a/enterprise/server/sharing/shared_event_router.py b/enterprise/server/sharing/shared_event_router.py
index 1a16f6b96b..c936bf28a8 100644
--- a/enterprise/server/sharing/shared_event_router.py
+++ b/enterprise/server/sharing/shared_event_router.py
@@ -20,9 +20,9 @@ from server.sharing.shared_event_service import (
from openhands.agent_server.models import EventPage, EventSortOrder
from openhands.app_server.event_callback.event_callback_models import EventKind
+from openhands.app_server.utils.environment import StorageProvider, get_storage_provider
from openhands.sdk import Event
from openhands.sdk.event.conversation_state import ConversationStateUpdateEvent
-from openhands.utils.environment import StorageProvider, get_storage_provider
def _is_viewable(event: Event) -> bool:
@@ -34,7 +34,7 @@ def get_shared_event_service_injector() -> SharedEventServiceInjector:
"""Get the appropriate SharedEventServiceInjector based on configuration.
Uses get_storage_provider() to determine the storage backend.
- See openhands.utils.environment for supported environment variables.
+ See openhands.app_server.utils.environment for supported environment variables.
Note: Shared events only support AWS and GCP storage. Filesystem storage
falls back to GCP for shared events.
diff --git a/enterprise/server/verified_models/verified_model_router.py b/enterprise/server/verified_models/verified_model_router.py
index bc4f6ef6ec..3c7cb625e3 100644
--- a/enterprise/server/verified_models/verified_model_router.py
+++ b/enterprise/server/verified_models/verified_model_router.py
@@ -17,7 +17,7 @@ from server.verified_models.verified_model_service import (
from openhands.app_server.config import get_db_session
from openhands.app_server.config_api.config_router import get_llm_models_dependency
-from openhands.utils.llm import ModelsResponse, get_supported_llm_models
+from openhands.app_server.utils.llm import ModelsResponse, get_supported_llm_models
api_router = APIRouter(prefix='/api/admin/verified-models', tags=['Verified Models'])
diff --git a/enterprise/storage/lite_llm_manager.py b/enterprise/storage/lite_llm_manager.py
index 8b8f64306a..9982db2969 100644
--- a/enterprise/storage/lite_llm_manager.py
+++ b/enterprise/storage/lite_llm_manager.py
@@ -20,7 +20,7 @@ from server.logger import logger
from storage.user_settings import UserSettings
from openhands.app_server.settings.settings_models import Settings
-from openhands.utils.http_session import httpx_verify_option
+from openhands.app_server.utils.http_session import httpx_verify_option
# Timeout in seconds for key verification requests to LiteLLM
KEY_VERIFICATION_TIMEOUT = 5.0
diff --git a/enterprise/storage/maintenance_task.py b/enterprise/storage/maintenance_task.py
index 3a6169f431..39f9ad229e 100644
--- a/enterprise/storage/maintenance_task.py
+++ b/enterprise/storage/maintenance_task.py
@@ -12,7 +12,7 @@ from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import Mapped, mapped_column
from storage.base import Base
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class MaintenanceTaskProcessor(BaseModel, ABC):
diff --git a/enterprise/storage/org_app_settings_store.py b/enterprise/storage/org_app_settings_store.py
index 52308b3f9b..4819c5d7be 100644
--- a/enterprise/storage/org_app_settings_store.py
+++ b/enterprise/storage/org_app_settings_store.py
@@ -16,7 +16,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from storage.org import Org
from storage.user import User
-from openhands.utils.jsonpatch_compat import deep_merge
+from openhands.app_server.utils.jsonpatch_compat import deep_merge
@dataclass
diff --git a/enterprise/storage/org_member_store.py b/enterprise/storage/org_member_store.py
index ba772bac8f..4b5af1768e 100644
--- a/enterprise/storage/org_member_store.py
+++ b/enterprise/storage/org_member_store.py
@@ -15,7 +15,7 @@ from storage.user import User
from storage.user_settings import UserSettings
from openhands.app_server.settings.settings_models import Settings
-from openhands.utils.jsonpatch_compat import deep_merge
+from openhands.app_server.utils.jsonpatch_compat import deep_merge
class OrgMemberStore:
diff --git a/enterprise/storage/org_store.py b/enterprise/storage/org_store.py
index 1813dabe3a..c1862a2ffa 100644
--- a/enterprise/storage/org_store.py
+++ b/enterprise/storage/org_store.py
@@ -25,10 +25,10 @@ from storage.user import User
from storage.user_settings import UserSettings
from openhands.app_server.settings.settings_models import Settings
+from openhands.app_server.utils.jsonpatch_compat import deep_merge
+from openhands.app_server.utils.llm import is_openhands_model
from openhands.core.logger import openhands_logger as logger
from openhands.sdk.settings import AgentSettings, ConversationSettings
-from openhands.utils.jsonpatch_compat import deep_merge
-from openhands.utils.llm import is_openhands_model
_ORG_SETTINGS_EXCLUDED_FIELDS = {
'id',
diff --git a/enterprise/storage/saas_settings_store.py b/enterprise/storage/saas_settings_store.py
index 1aae3e4342..1cdcb43e5c 100644
--- a/enterprise/storage/saas_settings_store.py
+++ b/enterprise/storage/saas_settings_store.py
@@ -23,9 +23,9 @@ from storage.user_store import UserStore
from openhands.app_server.settings.settings_models import Settings
from openhands.app_server.settings.settings_store import SettingsStore
+from openhands.app_server.utils.jsonpatch_compat import deep_merge
+from openhands.app_server.utils.llm import is_openhands_model
from openhands.core.config.openhands_config import OpenHandsConfig
-from openhands.utils.jsonpatch_compat import deep_merge
-from openhands.utils.llm import is_openhands_model
@dataclass
diff --git a/enterprise/tests/unit/server/routes/test_org_defaults_settings.py b/enterprise/tests/unit/server/routes/test_org_defaults_settings.py
index ca05000ee1..f3861639a6 100644
--- a/enterprise/tests/unit/server/routes/test_org_defaults_settings.py
+++ b/enterprise/tests/unit/server/routes/test_org_defaults_settings.py
@@ -112,7 +112,7 @@ def test_from_org_denormalizes_litellm_proxy_prefix_and_returns_base_url_as_stor
def test_from_org_returns_provider_default_base_url_as_stored_for_non_managed_models():
"""BYOR provider-default base URLs should round-trip unchanged."""
- from openhands.utils.llm import get_provider_api_base as _provider_base
+ from openhands.app_server.utils.llm import get_provider_api_base as _provider_base
anthropic_default = _provider_base('anthropic/claude-3-opus-20240229')
assert anthropic_default is not None
diff --git a/openhands/app_server/app_conversation/app_conversation_service_base.py b/openhands/app_server/app_conversation/app_conversation_service_base.py
index 70fc940b8f..d9a561fc40 100644
--- a/openhands/app_server/app_conversation/app_conversation_service_base.py
+++ b/openhands/app_server/app_conversation/app_conversation_service_base.py
@@ -28,6 +28,7 @@ from openhands.app_server.app_conversation.skill_loader import (
)
from openhands.app_server.sandbox.sandbox_models import SandboxInfo
from openhands.app_server.user.user_context import UserContext
+from openhands.app_server.utils.git import ensure_valid_git_branch_name
from openhands.sdk import Agent, LLMSummarizingCondenser
from openhands.sdk.context import AgentContext
from openhands.sdk.context.skills import Skill
@@ -41,7 +42,6 @@ from openhands.sdk.security import (
SecurityAnalyzerBase,
)
from openhands.sdk.workspace.remote.async_remote_workspace import AsyncRemoteWorkspace
-from openhands.utils.git import ensure_valid_git_branch_name
_logger = logging.getLogger(__name__)
PRE_COMMIT_HOOK = '.git/hooks/pre-commit'
diff --git a/openhands/app_server/app_conversation/live_status_app_conversation_service.py b/openhands/app_server/app_conversation/live_status_app_conversation_service.py
index ef8dd45eab..37d75f00ea 100644
--- a/openhands/app_server/app_conversation/live_status_app_conversation_service.py
+++ b/openhands/app_server/app_conversation/live_status_app_conversation_service.py
@@ -87,13 +87,16 @@ from openhands.app_server.services.injector import InjectorState
from openhands.app_server.services.jwt_service import JwtService
from openhands.app_server.user.user_context import UserContext
from openhands.app_server.user.user_models import UserInfo
+from openhands.app_server.utils._redact_compat import sanitize_config
from openhands.app_server.utils.docker_utils import (
replace_localhost_hostname_for_docker,
)
+from openhands.app_server.utils.git import ensure_valid_git_branch_name
from openhands.app_server.utils.llm_metadata import (
get_llm_metadata,
should_set_litellm_extra_body,
)
+from openhands.app_server.utils.sdk_settings_compat import ACPAgentSettings
from openhands.sdk import Agent, AgentContext, LocalWorkspace
from openhands.sdk.agent.acp_agent import ACPAgent
from openhands.sdk.hooks import HookConfig
@@ -110,9 +113,6 @@ from openhands.tools.preset.planning import (
format_plan_structure,
get_planning_tools,
)
-from openhands.utils._redact_compat import sanitize_config
-from openhands.utils.git import ensure_valid_git_branch_name
-from openhands.utils.sdk_settings_compat import ACPAgentSettings
_conversation_info_type_adapter = TypeAdapter(list[ConversationInfo | None])
_acp_conversation_info_type_adapter = TypeAdapter(list[ACPConversationInfo | None])
diff --git a/openhands/app_server/config.py b/openhands/app_server/config.py
index cb66158242..df4517308c 100644
--- a/openhands/app_server/config.py
+++ b/openhands/app_server/config.py
@@ -52,6 +52,7 @@ from openhands.app_server.services.httpx_client_injector import HttpxClientInjec
from openhands.app_server.services.injector import InjectorState
from openhands.app_server.services.jwt_service import JwtService, JwtServiceInjector
from openhands.app_server.user.user_context import UserContext, UserContextInjector
+from openhands.app_server.utils.environment import StorageProvider, get_storage_provider
from openhands.app_server.web_client.default_web_client_config_injector import (
DefaultWebClientConfigInjector,
)
@@ -60,7 +61,6 @@ from openhands.app_server.web_client.web_client_config_injector import (
)
from openhands.sdk.utils.models import OpenHandsModel
from openhands.server.types import AppMode
-from openhands.utils.environment import StorageProvider, get_storage_provider
def get_default_persistence_dir() -> Path:
diff --git a/openhands/app_server/config_api/config_router.py b/openhands/app_server/config_api/config_router.py
index 9e1715b643..4e3e87ec3d 100644
--- a/openhands/app_server/config_api/config_router.py
+++ b/openhands/app_server/config_api/config_router.py
@@ -15,12 +15,12 @@ from openhands.app_server.config_api.config_models import (
ProviderPage,
)
from openhands.app_server.utils.dependencies import get_dependencies
+from openhands.app_server.utils.llm import ModelsResponse, get_supported_llm_models
from openhands.app_server.utils.paging_utils import (
paginate_results,
)
from openhands.sdk.llm.utils.verified_models import VERIFIED_MODELS
from openhands.server.shared import config
-from openhands.utils.llm import ModelsResponse, get_supported_llm_models
async def get_llm_models_dependency(request: Request) -> ModelsResponse:
diff --git a/openhands/app_server/event_callback/event_callback_models.py b/openhands/app_server/event_callback/event_callback_models.py
index c032977b06..545f90644a 100644
--- a/openhands/app_server/event_callback/event_callback_models.py
+++ b/openhands/app_server/event_callback/event_callback_models.py
@@ -15,6 +15,9 @@ from openhands.app_server.event_callback.event_callback_result_models import (
EventCallbackResult,
EventCallbackResultStatus,
)
+
+# TODO(OpenHands/evaluation#418): import from openhands.sdk.utils.redact
+from openhands.app_server.utils._redact_compat import redact_text_secrets
from openhands.sdk import Event
from openhands.sdk.utils.models import (
DiscriminatedUnionMixin,
@@ -22,9 +25,6 @@ from openhands.sdk.utils.models import (
get_known_concrete_subclasses,
)
-# TODO(OpenHands/evaluation#418): import from openhands.sdk.utils.redact
-from openhands.utils._redact_compat import redact_text_secrets
-
_logger = logging.getLogger(__name__)
if TYPE_CHECKING:
EventKind = str
diff --git a/openhands/app_server/event_callback/set_title_callback_processor.py b/openhands/app_server/event_callback/set_title_callback_processor.py
index 53d0f16826..d2dc3dfe26 100644
--- a/openhands/app_server/event_callback/set_title_callback_processor.py
+++ b/openhands/app_server/event_callback/set_title_callback_processor.py
@@ -18,14 +18,14 @@ from openhands.app_server.event_callback.event_callback_result_models import (
)
from openhands.app_server.services.injector import InjectorState
from openhands.app_server.user.specifiy_user_context import ADMIN, USER_CONTEXT_ATTR
+
+# TODO(OpenHands/evaluation#418): import from openhands.sdk.utils.redact
+from openhands.app_server.utils._redact_compat import redact_text_secrets
from openhands.app_server.utils.docker_utils import (
replace_localhost_hostname_for_docker,
)
from openhands.sdk import Event, MessageEvent
-# TODO(OpenHands/evaluation#418): import from openhands.sdk.utils.redact
-from openhands.utils._redact_compat import redact_text_secrets
-
_logger = logging.getLogger(__name__)
# Delay between attempts to poll title
diff --git a/openhands/app_server/integrations/azure_devops/azure_devops_service.py b/openhands/app_server/integrations/azure_devops/azure_devops_service.py
index 766098463f..8fdba80620 100644
--- a/openhands/app_server/integrations/azure_devops/azure_devops_service.py
+++ b/openhands/app_server/integrations/azure_devops/azure_devops_service.py
@@ -29,7 +29,7 @@ from openhands.app_server.integrations.service_types import (
ProviderType,
RequestMethod,
)
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class AzureDevOpsService(
diff --git a/openhands/app_server/integrations/bitbucket/bitbucket_service.py b/openhands/app_server/integrations/bitbucket/bitbucket_service.py
index ce89cd9d64..90e25c02e8 100644
--- a/openhands/app_server/integrations/bitbucket/bitbucket_service.py
+++ b/openhands/app_server/integrations/bitbucket/bitbucket_service.py
@@ -13,7 +13,7 @@ from openhands.app_server.integrations.service_types import (
InstallationsService,
ProviderType,
)
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class BitBucketService(
diff --git a/openhands/app_server/integrations/bitbucket/service/base.py b/openhands/app_server/integrations/bitbucket/service/base.py
index a46ee64c70..06c7a99a85 100644
--- a/openhands/app_server/integrations/bitbucket/service/base.py
+++ b/openhands/app_server/integrations/bitbucket/service/base.py
@@ -13,8 +13,8 @@ from openhands.app_server.integrations.service_types import (
RequestMethod,
User,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
-from openhands.utils.http_session import httpx_verify_option
class BitBucketMixinBase(BaseGitService, HTTPClient):
diff --git a/openhands/app_server/integrations/bitbucket_data_center/bitbucket_dc_service.py b/openhands/app_server/integrations/bitbucket_data_center/bitbucket_dc_service.py
index 404bb9c8f6..77aed30c52 100644
--- a/openhands/app_server/integrations/bitbucket_data_center/bitbucket_dc_service.py
+++ b/openhands/app_server/integrations/bitbucket_data_center/bitbucket_dc_service.py
@@ -13,7 +13,7 @@ from openhands.app_server.integrations.service_types import (
InstallationsService,
ProviderType,
)
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class BitbucketDCService(
diff --git a/openhands/app_server/integrations/bitbucket_data_center/service/base.py b/openhands/app_server/integrations/bitbucket_data_center/service/base.py
index 7270a6357b..3329dda421 100644
--- a/openhands/app_server/integrations/bitbucket_data_center/service/base.py
+++ b/openhands/app_server/integrations/bitbucket_data_center/service/base.py
@@ -14,8 +14,8 @@ from openhands.app_server.integrations.service_types import (
RequestMethod,
User,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
-from openhands.utils.http_session import httpx_verify_option
class BitbucketDCMixinBase(BaseGitService, HTTPClient):
diff --git a/openhands/app_server/integrations/forgejo/forgejo_service.py b/openhands/app_server/integrations/forgejo/forgejo_service.py
index 6f32d8e04d..35b3958ac8 100644
--- a/openhands/app_server/integrations/forgejo/forgejo_service.py
+++ b/openhands/app_server/integrations/forgejo/forgejo_service.py
@@ -13,7 +13,7 @@ from openhands.app_server.integrations.forgejo.service import (
ForgejoResolverMixin,
)
from openhands.app_server.integrations.service_types import GitService
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class ForgejoService(
diff --git a/openhands/app_server/integrations/forgejo/service/base.py b/openhands/app_server/integrations/forgejo/service/base.py
index bfd422c58c..65841aa29d 100644
--- a/openhands/app_server/integrations/forgejo/service/base.py
+++ b/openhands/app_server/integrations/forgejo/service/base.py
@@ -17,8 +17,8 @@ from openhands.app_server.integrations.service_types import (
UnknownException,
User,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
-from openhands.utils.http_session import httpx_verify_option
class ForgejoMixinBase(BaseGitService, HTTPClient):
diff --git a/openhands/app_server/integrations/github/github_service.py b/openhands/app_server/integrations/github/github_service.py
index 4c453efe91..aead5fe126 100644
--- a/openhands/app_server/integrations/github/github_service.py
+++ b/openhands/app_server/integrations/github/github_service.py
@@ -15,7 +15,7 @@ from openhands.app_server.integrations.service_types import (
InstallationsService,
ProviderType,
)
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class GitHubService(
diff --git a/openhands/app_server/integrations/github/service/base.py b/openhands/app_server/integrations/github/service/base.py
index bf8b834c31..2b222250e1 100644
--- a/openhands/app_server/integrations/github/service/base.py
+++ b/openhands/app_server/integrations/github/service/base.py
@@ -11,8 +11,8 @@ from openhands.app_server.integrations.service_types import (
UnknownException,
User,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
-from openhands.utils.http_session import httpx_verify_option
class GitHubMixinBase(BaseGitService, HTTPClient):
diff --git a/openhands/app_server/integrations/gitlab/gitlab_service.py b/openhands/app_server/integrations/gitlab/gitlab_service.py
index 1a34518f87..a49f306604 100644
--- a/openhands/app_server/integrations/gitlab/gitlab_service.py
+++ b/openhands/app_server/integrations/gitlab/gitlab_service.py
@@ -15,7 +15,7 @@ from openhands.app_server.integrations.service_types import (
GitService,
ProviderType,
)
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class GitLabService(
diff --git a/openhands/app_server/integrations/gitlab/service/base.py b/openhands/app_server/integrations/gitlab/service/base.py
index ee0ad66a9d..5f727ae577 100644
--- a/openhands/app_server/integrations/gitlab/service/base.py
+++ b/openhands/app_server/integrations/gitlab/service/base.py
@@ -10,7 +10,7 @@ from openhands.app_server.integrations.service_types import (
UnknownException,
User,
)
-from openhands.utils.http_session import httpx_verify_option
+from openhands.app_server.utils.http_session import httpx_verify_option
class GitLabMixinBase(BaseGitService, HTTPClient):
diff --git a/openhands/app_server/integrations/provider.py b/openhands/app_server/integrations/provider.py
index 6f86ecd901..59974b2b58 100644
--- a/openhands/app_server/integrations/provider.py
+++ b/openhands/app_server/integrations/provider.py
@@ -40,9 +40,9 @@ from openhands.app_server.integrations.service_types import (
TokenResponse,
User,
)
+from openhands.app_server.utils.http_session import httpx_verify_option
from openhands.core.logger import openhands_logger as logger
from openhands.server.types import AppMode
-from openhands.utils.http_session import httpx_verify_option
class ProviderToken(BaseModel):
diff --git a/openhands/app_server/secrets/file_secrets_store.py b/openhands/app_server/secrets/file_secrets_store.py
index 5859af4eaf..277170f60c 100644
--- a/openhands/app_server/secrets/file_secrets_store.py
+++ b/openhands/app_server/secrets/file_secrets_store.py
@@ -7,8 +7,8 @@ from openhands.app_server.file_store import get_file_store
from openhands.app_server.file_store.files import FileStore
from openhands.app_server.secrets.secrets_models import Secrets
from openhands.app_server.secrets.secrets_store import SecretsStore
+from openhands.app_server.utils.async_utils import call_sync_from_async
from openhands.core.config.openhands_config import OpenHandsConfig
-from openhands.utils.async_utils import call_sync_from_async
@dataclass
diff --git a/openhands/app_server/settings/file_settings_store.py b/openhands/app_server/settings/file_settings_store.py
index ddf0206b92..a40a5936c2 100644
--- a/openhands/app_server/settings/file_settings_store.py
+++ b/openhands/app_server/settings/file_settings_store.py
@@ -7,8 +7,8 @@ from openhands.app_server.file_store import get_file_store
from openhands.app_server.file_store.files import FileStore
from openhands.app_server.settings.settings_models import Settings
from openhands.app_server.settings.settings_store import SettingsStore
+from openhands.app_server.utils.async_utils import call_sync_from_async
from openhands.core.config.openhands_config import OpenHandsConfig
-from openhands.utils.async_utils import call_sync_from_async
@dataclass
diff --git a/openhands/app_server/settings/settings_models.py b/openhands/app_server/settings/settings_models.py
index 859b380a68..88c7815214 100644
--- a/openhands/app_server/settings/settings_models.py
+++ b/openhands/app_server/settings/settings_models.py
@@ -27,18 +27,18 @@ from pydantic import (
from openhands.app_server.integrations.provider import ProviderToken
from openhands.app_server.integrations.service_types import ProviderType
from openhands.app_server.settings.llm_profiles import LLMProfiles
-from openhands.core.config.llm_config import LLMConfig
-from openhands.core.config.mcp_config import MCPConfig
-from openhands.core.config.utils import load_openhands_config
-from openhands.sdk.settings import ConversationSettings
-from openhands.utils.jsonpatch_compat import deep_merge
-from openhands.utils.sdk_settings_compat import (
+from openhands.app_server.utils.jsonpatch_compat import deep_merge
+from openhands.app_server.utils.sdk_settings_compat import (
ACPAgentSettings,
AgentSettingsConfig,
LLMAgentSettings,
default_agent_settings,
validate_agent_settings,
)
+from openhands.core.config.llm_config import LLMConfig
+from openhands.core.config.mcp_config import MCPConfig
+from openhands.core.config.utils import load_openhands_config
+from openhands.sdk.settings import ConversationSettings
def _coerce_value(value: Any) -> Any:
@@ -437,7 +437,7 @@ class Settings(BaseModel):
Secrets are masked by Pydantic's default serialiser.
"""
from openhands.app_server.settings.settings_router import LITE_LLM_API_URL
- from openhands.utils.llm import is_openhands_model
+ from openhands.app_server.utils.llm import is_openhands_model
data = self.agent_settings.model_dump(mode='json')
llm = data.get('llm')
diff --git a/openhands/app_server/settings/settings_router.py b/openhands/app_server/settings/settings_router.py
index 9b09f4b3d4..428fbc2436 100644
--- a/openhands/app_server/settings/settings_router.py
+++ b/openhands/app_server/settings/settings_router.py
@@ -37,19 +37,19 @@ from openhands.app_server.user_auth import (
get_user_settings_store,
)
from openhands.app_server.utils.dependencies import get_dependencies
-from openhands.core.logger import openhands_logger as logger
-from openhands.sdk.llm import LLM
-from openhands.sdk.settings import ConversationSettings
-from openhands.server.shared import config
-from openhands.utils.llm import (
+from openhands.app_server.utils.llm import (
get_provider_api_base,
is_openhands_model,
resolve_llm_base_url,
)
-from openhands.utils.sdk_settings_compat import (
+from openhands.app_server.utils.sdk_settings_compat import (
LLMAgentSettings,
export_agent_settings_schema,
)
+from openhands.core.logger import openhands_logger as logger
+from openhands.sdk.llm import LLM
+from openhands.sdk.settings import ConversationSettings
+from openhands.server.shared import config
LITE_LLM_API_URL = os.environ.get(
'LITE_LLM_API_URL', 'https://llm-proxy.app.all-hands.dev'
@@ -67,7 +67,7 @@ def _post_merge_llm_fixups(settings: Settings) -> None:
"""Apply LLM-specific fixups after merging settings.
Delegates the empty-string β†’ cleared and provider-default inference
- rules to :func:`openhands.utils.llm.resolve_llm_base_url` so the
+ rules to :func:`openhands.app_server.utils.llm.resolve_llm_base_url` so the
personal-save and enterprise org-defaults paths stay in lockstep.
"""
if not isinstance(settings.agent_settings, LLMAgentSettings):
diff --git a/openhands/app_server/user_auth/user_auth.py b/openhands/app_server/user_auth/user_auth.py
index 8c8a94e6d5..45ab56d324 100644
--- a/openhands/app_server/user_auth/user_auth.py
+++ b/openhands/app_server/user_auth/user_auth.py
@@ -23,8 +23,8 @@ from openhands.app_server.secrets.secrets_models import Secrets
from openhands.app_server.secrets.secrets_store import SecretsStore
from openhands.app_server.settings.settings_models import Settings
from openhands.app_server.settings.settings_store import SettingsStore
+from openhands.app_server.utils.import_utils import get_impl
from openhands.server.shared import server_config
-from openhands.utils.import_utils import get_impl
class AuthType(Enum):
diff --git a/openhands/app_server/utils/README.md b/openhands/app_server/utils/README.md
index 9d4d50d9e9..ce7204e6ef 100644
--- a/openhands/app_server/utils/README.md
+++ b/openhands/app_server/utils/README.md
@@ -1,20 +1,120 @@
-# Utilities
+# OpenHands Utilities
-Common utility functions and helpers for the OpenHands app server.
+Common utility functions and helpers for OpenHands app server.
## Overview
-This module provides utility functions that are used across the app server for common operations like date handling, SQL operations, and dynamic imports.
+This module provides utility functions that are used across OpenHands for common operations like date handling, SQL operations, dynamic imports, async utilities, LLM integration, and more.
## Key Components
-- **date_utils**: Date and time utilities
-- **sql_utils**: SQL database operation helpers
+- **async_utils**: Async/sync interoperability utilities
+- **chunk_localizer**: File chunk localization for code edits
+- **environment**: Environment detection (Docker, storage providers)
+- **git**: Git branch validation utilities
+- **http_session**: HTTP session configuration
- **import_utils**: Dynamic module import utilities
+- **jsonpatch_compat**: JSON patch compatibility utilities
+- **llm**: LLM model management and configuration
+- **sdk_settings_compat**: SDK settings compatibility layer
+- **search_utils**: Pagination and search utilities
+- **shutdown_listener**: Graceful shutdown signal handling
+- **sql_utils**: SQL database operation helpers
+- **docker_utils**: Docker environment utilities
+- **encryption_key**: Encryption key utilities
+
+## Runtime Implementation Substitution
+
+OpenHands provides an extensibility mechanism through the `get_impl` and `import_from` functions in `import_utils.py`. This mechanism allows applications built on OpenHands to customize behavior by providing their own implementations of OpenHands base classes.
+
+### How It Works
+
+1. Base classes define interfaces through abstract methods and properties
+2. Default implementations are provided by OpenHands
+3. Applications can provide custom implementations by:
+ - Creating a class that inherits from the base class
+ - Implementing all required methods
+ - Configuring OpenHands to use the custom implementation via configuration
+
+### Example
+
+```python
+# In OpenHands base code:
+class ConversationManager:
+ @abstractmethod
+ async def attach_to_conversation(self, sid: str) -> Conversation:
+ """Attach to an existing conversation."""
+
+# Default implementation in OpenHands:
+class StandaloneConversationManager(ConversationManager):
+ async def attach_to_conversation(self, sid: str) -> Conversation:
+ # Single-server implementation
+ ...
+
+# In your application:
+class ClusteredConversationManager(ConversationManager):
+ async def attach_to_conversation(self, sid: str) -> Conversation:
+ # Custom distributed implementation
+ ...
+
+# In configuration:
+server_config.conversation_manager_class = 'myapp.ClusteredConversationManager'
+```
+
+### Common Extension Points
+
+OpenHands provides several components that can be extended:
+
+1. Server Components:
+ - `ConversationManager`: Manages conversation lifecycles
+ - `UserAuth`: Handles user authentication
+ - `MonitoringListener`: Provides monitoring capabilities
+
+2. Storage:
+ - `ConversationStore`: Stores conversation data
+ - `SettingsStore`: Manages user settings
+ - `SecretsStore`: Handles sensitive data
+
+3. Service Integrations:
+ - GitHub service
+ - GitLab service
+ - Azure DevOps service
+
+### Implementation Details
+
+The mechanism is implemented through two key functions:
+
+1. `import_from(qual_name: str)`: Imports any Python value from its fully qualified name
+ ```python
+ UserAuth = import_from('openhands.app_server.user_auth.UserAuth')
+ ```
+
+2. `get_impl(cls: type[T], impl_name: str | None) -> type[T]`: Imports and validates a class implementation
+ ```python
+ ConversationManagerImpl = get_impl(
+ ConversationManager,
+ server_config.conversation_manager_class
+ )
+ ```
+
+The `get_impl` function ensures type safety by validating that the imported class is either the same as or a subclass of the specified base class. It also caches results to avoid repeated imports.
+
+## Migration Guide
+
+If upgrading from a version where these utilities were in `openhands.utils`, update your imports:
+
+```python
+# Before
+from openhands.utils.async_utils import call_sync_from_async
+from openhands.utils.llm import get_supported_llm_models
+from openhands.utils.import_utils import get_impl
+from openhands.utils.environment import is_running_in_docker
-## Key Functions
+# After
+from openhands.app_server.utils.async_utils import call_sync_from_async
+from openhands.app_server.utils.llm import get_supported_llm_models
+from openhands.app_server.utils.import_utils import get_impl
+from openhands.app_server.utils.environment import is_running_in_docker
+```
-- **utc_now()**: Returns current UTC timestamp (replaces deprecated datetime.utcnow)
-- Database connection and query helpers
-- Dynamic module loading utilities
-- Safe import error handling
+All utilities previously in `openhands.utils.*` are now available at `openhands.app_server.utils.*`.
diff --git a/openhands/utils/_redact_compat.py b/openhands/app_server/utils/_redact_compat.py
similarity index 100%
rename from openhands/utils/_redact_compat.py
rename to openhands/app_server/utils/_redact_compat.py
diff --git a/openhands/utils/async_utils.py b/openhands/app_server/utils/async_utils.py
similarity index 100%
rename from openhands/utils/async_utils.py
rename to openhands/app_server/utils/async_utils.py
diff --git a/openhands/utils/chunk_localizer.py b/openhands/app_server/utils/chunk_localizer.py
similarity index 100%
rename from openhands/utils/chunk_localizer.py
rename to openhands/app_server/utils/chunk_localizer.py
diff --git a/openhands/app_server/utils/docker_utils.py b/openhands/app_server/utils/docker_utils.py
index 03821c3974..9fc69f801e 100644
--- a/openhands/app_server/utils/docker_utils.py
+++ b/openhands/app_server/utils/docker_utils.py
@@ -1,6 +1,6 @@
from urllib.parse import urlparse, urlunparse
-from openhands.utils.environment import is_running_in_docker
+from openhands.app_server.utils.environment import is_running_in_docker
def replace_localhost_hostname_for_docker(
diff --git a/openhands/utils/environment.py b/openhands/app_server/utils/environment.py
similarity index 100%
rename from openhands/utils/environment.py
rename to openhands/app_server/utils/environment.py
diff --git a/openhands/utils/git.py b/openhands/app_server/utils/git.py
similarity index 100%
rename from openhands/utils/git.py
rename to openhands/app_server/utils/git.py
diff --git a/openhands/utils/http_session.py b/openhands/app_server/utils/http_session.py
similarity index 100%
rename from openhands/utils/http_session.py
rename to openhands/app_server/utils/http_session.py
diff --git a/openhands/utils/jsonpatch_compat.py b/openhands/app_server/utils/jsonpatch_compat.py
similarity index 100%
rename from openhands/utils/jsonpatch_compat.py
rename to openhands/app_server/utils/jsonpatch_compat.py
diff --git a/openhands/utils/llm.py b/openhands/app_server/utils/llm.py
similarity index 100%
rename from openhands/utils/llm.py
rename to openhands/app_server/utils/llm.py
diff --git a/openhands/utils/sdk_settings_compat.py b/openhands/app_server/utils/sdk_settings_compat.py
similarity index 100%
rename from openhands/utils/sdk_settings_compat.py
rename to openhands/app_server/utils/sdk_settings_compat.py
diff --git a/openhands/utils/search_utils.py b/openhands/app_server/utils/search_utils.py
similarity index 100%
rename from openhands/utils/search_utils.py
rename to openhands/app_server/utils/search_utils.py
diff --git a/openhands/utils/shutdown_listener.py b/openhands/app_server/utils/shutdown_listener.py
similarity index 100%
rename from openhands/utils/shutdown_listener.py
rename to openhands/app_server/utils/shutdown_listener.py
diff --git a/openhands/core/logger.py b/openhands/core/logger.py
index dc79a7c462..6079dbe110 100644
--- a/openhands/core/logger.py
+++ b/openhands/core/logger.py
@@ -548,7 +548,7 @@ class RedactURLParamsFilter(logging.Filter):
_URL_WITH_QS_RE = re.compile(r'\S+\?\S+')
def filter(self, record: logging.LogRecord) -> bool:
- from openhands.utils._redact_compat import redact_url_params
+ from openhands.app_server.utils._redact_compat import redact_url_params
if record.args:
if isinstance(record.args, (tuple, list)):
diff --git a/openhands/server/config/server_config.py b/openhands/server/config/server_config.py
index 8ba442ef68..312b7f9b8b 100644
--- a/openhands/server/config/server_config.py
+++ b/openhands/server/config/server_config.py
@@ -8,9 +8,9 @@
# This module belongs to the old V0 web server. The V1 application server lives under openhands/app_server/.
import os
+from openhands.app_server.utils.import_utils import get_impl
from openhands.core.logger import openhands_logger as logger
from openhands.server.types import AppMode, ServerConfigInterface
-from openhands.utils.import_utils import get_impl
class ServerConfig(ServerConfigInterface):
diff --git a/openhands/server/shared.py b/openhands/server/shared.py
index 2a871ac4c9..431a273102 100644
--- a/openhands/server/shared.py
+++ b/openhands/server/shared.py
@@ -11,11 +11,11 @@ from dotenv import load_dotenv
from openhands.app_server.secrets.secrets_store import SecretsStore
from openhands.app_server.settings.settings_store import SettingsStore
+from openhands.app_server.utils.import_utils import get_impl
from openhands.core.config import load_openhands_config
from openhands.core.config.openhands_config import OpenHandsConfig
from openhands.server.config.server_config import ServerConfig, load_server_config
from openhands.server.types import ServerConfigInterface
-from openhands.utils.import_utils import get_impl
load_dotenv()
diff --git a/openhands/utils/README.md b/openhands/utils/README.md
deleted file mode 100644
index 37b208dcf5..0000000000
--- a/openhands/utils/README.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# OpenHands Utilities
-
-This directory contains various utility functions and classes used throughout OpenHands.
-
-## Runtime Implementation Substitution
-
-OpenHands provides an extensibility mechanism through the `get_impl` and `import_from` functions in `import_utils.py`. This mechanism allows applications built on OpenHands to customize behavior by providing their own implementations of OpenHands base classes.
-
-### How It Works
-
-1. Base classes define interfaces through abstract methods and properties
-2. Default implementations are provided by OpenHands
-3. Applications can provide custom implementations by:
- - Creating a class that inherits from the base class
- - Implementing all required methods
- - Configuring OpenHands to use the custom implementation via configuration
-
-### Example
-
-```python
-# In OpenHands base code:
-class ConversationManager:
- @abstractmethod
- async def attach_to_conversation(self, sid: str) -> Conversation:
- """Attach to an existing conversation."""
-
-# Default implementation in OpenHands:
-class StandaloneConversationManager(ConversationManager):
- async def attach_to_conversation(self, sid: str) -> Conversation:
- # Single-server implementation
- ...
-
-# In your application:
-class ClusteredConversationManager(ConversationManager):
- async def attach_to_conversation(self, sid: str) -> Conversation:
- # Custom distributed implementation
- ...
-
-# In configuration:
-server_config.conversation_manager_class = 'myapp.ClusteredConversationManager'
-```
-
-### Common Extension Points
-
-OpenHands provides several components that can be extended:
-
-1. Server Components:
- - `ConversationManager`: Manages conversation lifecycles
- - `UserAuth`: Handles user authentication
- - `MonitoringListener`: Provides monitoring capabilities
-
-2. Storage:
- - `ConversationStore`: Stores conversation data
- - `SettingsStore`: Manages user settings
- - `SecretsStore`: Handles sensitive data
-
-3. Service Integrations:
- - GitHub service
- - GitLab service
- - Azure DevOps service
-
-### Implementation Details
-
-The mechanism is implemented through two key functions:
-
-1. `import_from(qual_name: str)`: Imports any Python value from its fully qualified name
- ```python
- UserAuth = import_from('openhands.server.user_auth.UserAuth')
- ```
-
-2. `get_impl(cls: type[T], impl_name: str | None) -> type[T]`: Imports and validates a class implementation
- ```python
- ConversationManagerImpl = get_impl(
- ConversationManager,
- server_config.conversation_manager_class
- )
- ```
-
-The `get_impl` function ensures type safety by validating that the imported class is either the same as or a subclass of the specified base class. It also caches results to avoid repeated imports.
diff --git a/openhands/utils/import_utils.py b/openhands/utils/import_utils.py
deleted file mode 100644
index 1c6f751abf..0000000000
--- a/openhands/utils/import_utils.py
+++ /dev/null
@@ -1,73 +0,0 @@
-import importlib
-from functools import lru_cache
-from typing import TypeVar
-
-T = TypeVar('T')
-
-
-def import_from(qual_name: str):
- """Import a value from its fully qualified name.
-
- This function is a utility to dynamically import any Python value (class, function, variable)
- from its fully qualified name. For example, 'openhands.app_server.user_auth.UserAuth' would
- import the UserAuth class from the openhands.app_server.user_auth module.
-
- Args:
- qual_name: A fully qualified name in the format 'module.submodule.name'
- e.g. 'openhands.app_server.user_auth.UserAuth'
-
- Returns:
- The imported value (class, function, or variable)
-
- Example:
- >>> UserAuth = import_from('openhands.app_server.user_auth.UserAuth')
- >>> auth = UserAuth()
- """
- parts = qual_name.split('.')
- module_name = '.'.join(parts[:-1])
- module = importlib.import_module(module_name)
- result = getattr(module, parts[-1])
- return result
-
-
-@lru_cache()
-def _get_impl(cls: type[T], impl_name: str | None) -> type[T]:
- if impl_name is None:
- return cls
- impl_class = import_from(impl_name)
- assert cls == impl_class or issubclass(impl_class, cls)
- return impl_class
-
-
-def get_impl(cls: type[T], impl_name: str | None) -> type[T]:
- """Import and validate a named implementation of a base class.
-
- This function is an extensibility mechanism in OpenHands that allows runtime substitution
- of implementations. It enables applications to customize behavior by providing their own
- implementations of OpenHands base classes.
-
- The function ensures type safety by validating that the imported class is either the same as
- or a subclass of the specified base class.
-
- Args:
- cls: The base class that defines the interface
- impl_name: Fully qualified name of the implementation class, or None to use the base class
- e.g. 'openhands.app_server.settings.file_settings_store.FileSettingsStore'
-
- Returns:
- The implementation class, which is guaranteed to be a subclass of cls
-
- Example:
- >>> # Get default implementation
- >>> SettingsStore = get_impl(SettingsStore, None)
- >>> # Get custom implementation
- >>> CustomStore = get_impl(SettingsStore, 'myapp.CustomSettingsStore')
-
- Common Use Cases:
- - Server components (UserAuth, etc.)
- - Storage implementations (SettingsStore, SecretsStore, etc.)
- - Service integrations (GitHub, GitLab, Bitbucket, Azure DevOps services)
-
- The implementation is cached to avoid repeated imports of the same class.
- """
- return _get_impl(cls, impl_name) # type: ignore
diff --git a/tests/unit/app_server/test_config_router.py b/tests/unit/app_server/test_config_router.py
index f388619afd..b142f57f4a 100644
--- a/tests/unit/app_server/test_config_router.py
+++ b/tests/unit/app_server/test_config_router.py
@@ -15,9 +15,9 @@ from openhands.app_server.config_api.config_router import (
router,
)
from openhands.app_server.utils.dependencies import check_session_api_key
+from openhands.app_server.utils.llm import get_supported_llm_models
from openhands.app_server.utils.paging_utils import encode_page_id, paginate_results
from openhands.server.shared import config
-from openhands.utils.llm import get_supported_llm_models
class TestLLMModel:
diff --git a/tests/unit/utils/test_async_utils.py b/tests/unit/utils/test_async_utils.py
index 568cf31e21..9c9e77012d 100644
--- a/tests/unit/utils/test_async_utils.py
+++ b/tests/unit/utils/test_async_utils.py
@@ -3,7 +3,7 @@ import concurrent.futures
import pytest
-from openhands.utils.async_utils import (
+from openhands.app_server.utils.async_utils import (
AsyncException,
call_async_from_sync,
call_sync_from_async,
diff --git a/tests/unit/utils/test_chunk_localizer.py b/tests/unit/utils/test_chunk_localizer.py
index d63da22488..0bffe19054 100644
--- a/tests/unit/utils/test_chunk_localizer.py
+++ b/tests/unit/utils/test_chunk_localizer.py
@@ -1,6 +1,6 @@
import pytest
-from openhands.utils.chunk_localizer import (
+from openhands.app_server.utils.chunk_localizer import (
Chunk,
create_chunks,
get_top_k_chunk_matches,
diff --git a/tests/unit/utils/test_environment.py b/tests/unit/utils/test_environment.py
index 45610ff61a..7a2e7e47f9 100644
--- a/tests/unit/utils/test_environment.py
+++ b/tests/unit/utils/test_environment.py
@@ -1,7 +1,7 @@
import pytest
-from openhands.utils import environment
-from openhands.utils.environment import StorageProvider, get_storage_provider
+from openhands.app_server.utils import environment
+from openhands.app_server.utils.environment import StorageProvider, get_storage_provider
@pytest.fixture(autouse=True)
diff --git a/tests/unit/utils/test_git.py b/tests/unit/utils/test_git.py
index b4569248bd..636873aa1b 100644
--- a/tests/unit/utils/test_git.py
+++ b/tests/unit/utils/test_git.py
@@ -1,6 +1,9 @@
import pytest
-from openhands.utils.git import ensure_valid_git_branch_name, is_valid_git_branch_name
+from openhands.app_server.utils.git import (
+ ensure_valid_git_branch_name,
+ is_valid_git_branch_name,
+)
def test_is_valid_git_branch_name_accepts_common_hosted_git_branch_names():
diff --git a/tests/unit/utils/test_import_utils.py b/tests/unit/utils/test_import_utils.py
index 876c37d27b..d38558679e 100644
--- a/tests/unit/utils/test_import_utils.py
+++ b/tests/unit/utils/test_import_utils.py
@@ -1,7 +1,7 @@
from abc import abstractmethod
from dataclasses import dataclass
-from openhands.utils.import_utils import get_impl
+from openhands.app_server.utils.import_utils import get_impl
class Shape:
diff --git a/tests/unit/utils/test_llm_utils.py b/tests/unit/utils/test_llm_utils.py
index 6bd0b99c65..80d43debbf 100644
--- a/tests/unit/utils/test_llm_utils.py
+++ b/tests/unit/utils/test_llm_utils.py
@@ -1,7 +1,7 @@
-"""Tests for openhands.utils.llm module."""
+"""Tests for openhands.app_server.utils.llm module."""
-from openhands.utils import llm as llm_utils
-from openhands.utils.llm import (
+from openhands.app_server.utils import llm as llm_utils
+from openhands.app_server.utils.llm import (
_assign_provider,
_derive_verified_models,
get_provider_api_base,
diff --git a/tests/unit/utils/test_redact_compat.py b/tests/unit/utils/test_redact_compat.py
index 69f73f8cf5..df065481fb 100644
--- a/tests/unit/utils/test_redact_compat.py
+++ b/tests/unit/utils/test_redact_compat.py
@@ -1,9 +1,9 @@
-"""Tests for openhands.utils._redact_compat redaction utilities.
+"""Tests for openhands.app_server.utils._redact_compat redaction utilities.
These tests verify that MCP config secrets are properly redacted before logging.
"""
-from openhands.utils._redact_compat import (
+from openhands.app_server.utils._redact_compat import (
redact_api_key_literals,
redact_text_secrets,
redact_url_params,
diff --git a/tests/unit/utils/test_sdk_settings_compat.py b/tests/unit/utils/test_sdk_settings_compat.py
index 8795a39cca..585237ab91 100644
--- a/tests/unit/utils/test_sdk_settings_compat.py
+++ b/tests/unit/utils/test_sdk_settings_compat.py
@@ -2,7 +2,7 @@
import pytest
-from openhands.utils.sdk_settings_compat import (
+from openhands.app_server.utils.sdk_settings_compat import (
_HAS_DISCRIMINATED_UNION,
ACPAgentSettings,
AgentSettingsConfig,
diff --git a/tests/unit/utils/test_search_utils.py b/tests/unit/utils/test_search_utils.py
index 0de05ab0cd..664dde875d 100644
--- a/tests/unit/utils/test_search_utils.py
+++ b/tests/unit/utils/test_search_utils.py
@@ -2,7 +2,11 @@ from dataclasses import dataclass
import pytest
-from openhands.utils.search_utils import iterate, offset_to_page_id, page_id_to_offset
+from openhands.app_server.utils.search_utils import (
+ iterate,
+ offset_to_page_id,
+ page_id_to_offset,
+)
@dataclass
diff --git a/tests/unit/utils/test_shutdown_listener.py b/tests/unit/utils/test_shutdown_listener.py
index a4317c6b76..a5cd798240 100644
--- a/tests/unit/utils/test_shutdown_listener.py
+++ b/tests/unit/utils/test_shutdown_listener.py
@@ -7,8 +7,8 @@ from uuid import UUID
import pytest
-from openhands.utils import shutdown_listener
-from openhands.utils.shutdown_listener import (
+from openhands.app_server.utils import shutdown_listener
+from openhands.app_server.utils.shutdown_listener import (
add_shutdown_listener,
remove_shutdown_listener,
should_continue,
@@ -59,7 +59,7 @@ def test_remove_shutdown_listener():
def test_signal_handler_calls_listeners():
mock_signal = MockSignal()
- with patch('openhands.utils.shutdown_listener.signal', mock_signal):
+ with patch('openhands.app_server.utils.shutdown_listener.signal', mock_signal):
mock_callable1 = MagicMock()
mock_callable2 = MagicMock()
add_shutdown_listener(mock_callable1)
@@ -79,7 +79,7 @@ def test_signal_handler_calls_listeners():
def test_listeners_called_only_once():
mock_signal = MockSignal()
- with patch('openhands.utils.shutdown_listener.signal', mock_signal):
+ with patch('openhands.app_server.utils.shutdown_listener.signal', mock_signal):
mock_callable = MagicMock()
add_shutdown_listener(mock_callable)
@@ -94,7 +94,7 @@ def test_listeners_called_only_once():
def test_remove_listener_during_shutdown():
mock_signal = MockSignal()
- with patch('openhands.utils.shutdown_listener.signal', mock_signal):
+ with patch('openhands.app_server.utils.shutdown_listener.signal', mock_signal):
mock_callable1 = MagicMock()
mock_callable2 = MagicMock()