openhands-agent-server 1.60.2__tar.gz → 1.61.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/PKG-INFO +2 -2
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/_secrets_exposure.py +20 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/api.py +37 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/auth_router.py +17 -3
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions/bridge.py +1 -1
- openhands_agent_server-1.61.0/openhands/agent_server/code_server_proxy.cjs +270 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/conversation_router.py +12 -3
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/conversation_service.py +16 -13
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker/Dockerfile +71 -76
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/provisioning.py +2 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/proxy.py +29 -7
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/registry.py +33 -2
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/routers.py +67 -11
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/event_router.py +108 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/event_service.py +54 -25
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/file_router.py +1 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/git_provider_service.py +1 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/git_router.py +12 -5
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/mcp_router.py +1 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/openai/router.py +8 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/openai/service.py +140 -9
- openhands_agent_server-1.61.0/openhands/agent_server/openai/usage.py +21 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/persistence/models.py +4 -2
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/profiles_router.py +13 -3
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/pub_sub.py +17 -4
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/session_socket.py +45 -8
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/settings_router.py +10 -3
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/skills_service.py +10 -6
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/sockets.py +41 -6
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/utils.py +9 -8
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/vscode_service.py +58 -34
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/PKG-INFO +2 -2
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/SOURCES.txt +4 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/requires.txt +1 -1
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/pyproject.toml +3 -2
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/__main__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/_secret_redaction.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/acp_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/agent_profiles_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/bash_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/bash_service.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions/backend.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions/installed.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions/manifest.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions_bridge_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/canvas_extensions_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/config.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/conversation_lease.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/conversation_registry.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/credential_binding.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/dependencies.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker/build.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/hybrid.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/mediation.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/docker_runtime/storage.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/env_parser.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/hooks_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/hooks_service.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/init_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/launch.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/llm_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/local_secret_resolver.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/local_storage.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/logging_config.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/managed_llm_key.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/mcp_oauth_store.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/meta_profiles_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/middleware.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/models.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/openai/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/openai/models.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/openapi.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/persistence/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/persistence/store.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/plugins_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/plugins_service.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/provider_connections_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/py.typed +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/runtime_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/server_details_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/session_protocol.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/skills_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/storage/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/storage/model.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/storage/reclaimer.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/storage/selectors.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/storage/trash.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/sub_agents_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/__init__.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/factory.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/http_exporter.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/models.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/policy.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/posthog_exporter.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/sanitizer.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/service.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/sink.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry/subscriber.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/telemetry_types.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/tool_preload_service.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/tool_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/vscode_extensions/openhands-settings/extension.js +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/vscode_extensions/openhands-settings/package.json +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/vscode_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/workspace_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/workspaces_router.py +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/dependency_links.txt +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/entry_points.txt +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands_agent_server.egg-info/top_level.txt +0 -0
- {openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openhands-agent-server
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.61.0
|
|
4
4
|
Summary: OpenHands Agent Server - REST/WebSocket interface for OpenHands AI Agent
|
|
5
5
|
Project-URL: Source, https://github.com/OpenHands/software-agent-sdk
|
|
6
6
|
Project-URL: Homepage, https://github.com/OpenHands/software-agent-sdk
|
|
@@ -10,7 +10,7 @@ Requires-Python: >=3.12
|
|
|
10
10
|
Requires-Dist: aiosqlite>=0.22.1
|
|
11
11
|
Requires-Dist: alembic>=1.20.1
|
|
12
12
|
Requires-Dist: certifi>=2026.10.19
|
|
13
|
-
Requires-Dist: docker<8,>=7.
|
|
13
|
+
Requires-Dist: docker<8,>=7.2.0
|
|
14
14
|
Requires-Dist: fastapi>=0.104
|
|
15
15
|
Requires-Dist: openhands-sdk
|
|
16
16
|
Requires-Dist: openhands-tools
|
|
@@ -11,8 +11,15 @@ from pydantic_core import PydanticSerializationError
|
|
|
11
11
|
from openhands.sdk.llm import LLM
|
|
12
12
|
from openhands.sdk.llm.llm import LLM_SECRET_FIELDS
|
|
13
13
|
from openhands.sdk.llm.provider_connection_store import ProviderConnectionNotFound
|
|
14
|
+
from openhands.sdk.logger import get_logger
|
|
14
15
|
from openhands.sdk.utils.cipher import FERNET_TOKEN_PREFIX, Cipher
|
|
15
|
-
from openhands.sdk.utils.pydantic_secrets import
|
|
16
|
+
from openhands.sdk.utils.pydantic_secrets import (
|
|
17
|
+
MissingCipherError,
|
|
18
|
+
SecretDecryptionError,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_logger = get_logger(__name__)
|
|
16
23
|
|
|
17
24
|
|
|
18
25
|
ExposeSecretsMode = Literal["encrypted", "plaintext"]
|
|
@@ -123,6 +130,18 @@ def translate_missing_cipher() -> Iterator[None]:
|
|
|
123
130
|
raise
|
|
124
131
|
|
|
125
132
|
|
|
133
|
+
def profile_key_mismatch(name: str, error: SecretDecryptionError) -> HTTPException:
|
|
134
|
+
"""409 for a profile whose stored key the current cipher cannot decrypt."""
|
|
135
|
+
_logger.error(f"Refusing to use profile '{name}': {error}")
|
|
136
|
+
return HTTPException(
|
|
137
|
+
status_code=status.HTTP_409_CONFLICT,
|
|
138
|
+
detail=(
|
|
139
|
+
f"Profile '{name}' is encrypted with a different key: restore that "
|
|
140
|
+
"key as OH_SECRET_KEY or add it to OH_PREVIOUS_SECRET_KEYS"
|
|
141
|
+
),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
126
145
|
@contextmanager
|
|
127
146
|
def store_errors() -> Iterator[None]:
|
|
128
147
|
"""Map profile-store errors (``LLMProfileStore``/``AgentProfileStore``) to
|
{openhands_agent_server-1.60.2 → openhands_agent_server-1.61.0}/openhands/agent_server/api.py
RENAMED
|
@@ -3,9 +3,11 @@ import os
|
|
|
3
3
|
import shutil
|
|
4
4
|
import sys
|
|
5
5
|
import tempfile
|
|
6
|
+
import threading
|
|
6
7
|
import traceback
|
|
7
8
|
import uuid
|
|
8
9
|
from collections.abc import AsyncIterator, Sequence
|
|
10
|
+
from concurrent.futures import Future
|
|
9
11
|
from contextlib import asynccontextmanager, suppress
|
|
10
12
|
from importlib.metadata import version
|
|
11
13
|
from pathlib import Path
|
|
@@ -17,6 +19,8 @@ from fastapi import APIRouter, Depends, FastAPI, HTTPException
|
|
|
17
19
|
from fastapi.exceptions import RequestValidationError
|
|
18
20
|
from fastapi.responses import JSONResponse, RedirectResponse
|
|
19
21
|
from fastapi.staticfiles import StaticFiles
|
|
22
|
+
from opentelemetry import trace
|
|
23
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
20
24
|
from starlette.requests import Request
|
|
21
25
|
from starlette.types import ASGIApp
|
|
22
26
|
|
|
@@ -263,6 +267,38 @@ def _cleanup_stale_tmux_sessions() -> None:
|
|
|
263
267
|
_reclaim_stale_tmux_sockets(socket_dir)
|
|
264
268
|
|
|
265
269
|
|
|
270
|
+
TRACE_FLUSH_TIMEOUT_MILLIS = 5000
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
async def _flush_trace_export() -> None:
|
|
274
|
+
provider = trace.get_tracer_provider()
|
|
275
|
+
if not isinstance(provider, TracerProvider):
|
|
276
|
+
return
|
|
277
|
+
outcome: Future[bool] = Future()
|
|
278
|
+
outcome.set_running_or_notify_cancel()
|
|
279
|
+
|
|
280
|
+
def flush() -> None:
|
|
281
|
+
try:
|
|
282
|
+
outcome.set_result(provider.force_flush(TRACE_FLUSH_TIMEOUT_MILLIS))
|
|
283
|
+
except Exception as exc:
|
|
284
|
+
outcome.set_exception(exc)
|
|
285
|
+
|
|
286
|
+
threading.Thread(target=flush, name="shutdown-trace-flush", daemon=True).start()
|
|
287
|
+
try:
|
|
288
|
+
flushed = await asyncio.wait_for(
|
|
289
|
+
asyncio.wrap_future(outcome), TRACE_FLUSH_TIMEOUT_MILLIS / 1000
|
|
290
|
+
)
|
|
291
|
+
except TimeoutError:
|
|
292
|
+
flushed = False
|
|
293
|
+
except Exception:
|
|
294
|
+
logger.warning("Shutdown trace flush failed", exc_info=True)
|
|
295
|
+
return
|
|
296
|
+
if not flushed:
|
|
297
|
+
logger.warning(
|
|
298
|
+
"Shutdown trace flush timed out after %d ms", TRACE_FLUSH_TIMEOUT_MILLIS
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
|
|
266
302
|
@asynccontextmanager
|
|
267
303
|
async def api_lifespan(api: FastAPI) -> AsyncIterator[None]:
|
|
268
304
|
original_tmux_tmpdir = os.environ.get("TMUX_TMPDIR")
|
|
@@ -439,6 +475,7 @@ async def api_lifespan(api: FastAPI) -> AsyncIterator[None]:
|
|
|
439
475
|
await backend_manager.shutdown()
|
|
440
476
|
emit_server_stopped()
|
|
441
477
|
await shutdown_telemetry_sink()
|
|
478
|
+
await _flush_trace_export()
|
|
442
479
|
|
|
443
480
|
if tmux_tmpdir_was_defaulted:
|
|
444
481
|
if os.environ.get("TMUX_TMPDIR") == str(tmux_tmpdir):
|
|
@@ -29,9 +29,21 @@ auth_router = APIRouter(prefix="/auth", tags=["Auth"])
|
|
|
29
29
|
_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 365 * 10 # 10 years
|
|
30
30
|
|
|
31
31
|
# Path scope: only sent on workspace-router URLs. Other /api/* endpoints
|
|
32
|
-
# never see the cookie.
|
|
32
|
+
# never see the cookie. Prefixed with the app's ``root_path`` per request.
|
|
33
33
|
_COOKIE_PATH = "/api/conversations"
|
|
34
34
|
|
|
35
|
+
|
|
36
|
+
def _cookie_path(request: Request) -> str:
|
|
37
|
+
"""Cookie path for the URLs the browser uses, including ``root_path``.
|
|
38
|
+
|
|
39
|
+
Behind a path prefix (``OH_WEB_URL`` with a path) the browser requests
|
|
40
|
+
``{root_path}/api/conversations/...``; a cookie scoped to the bare
|
|
41
|
+
``/api/conversations`` would never be sent back on those URLs.
|
|
42
|
+
"""
|
|
43
|
+
root_path = request.scope.get("root_path", "").rstrip("/")
|
|
44
|
+
return f"{root_path}{_COOKIE_PATH}"
|
|
45
|
+
|
|
46
|
+
|
|
35
47
|
# Hostnames the browser treats as "secure contexts" even over plain HTTP, so
|
|
36
48
|
# we can issue ``Secure`` cookies against them in local development without
|
|
37
49
|
# requiring TLS. Matches the platform-secure-contexts list in the WHATWG
|
|
@@ -67,7 +79,7 @@ def _request_is_secure_context(request: Request) -> bool:
|
|
|
67
79
|
|
|
68
80
|
|
|
69
81
|
def _set_workspace_cookie(
|
|
70
|
-
response: Response, *, value: str, secure: bool, max_age: int
|
|
82
|
+
response: Response, *, value: str, path: str, secure: bool, max_age: int
|
|
71
83
|
) -> None:
|
|
72
84
|
"""Issue the workspace session cookie.
|
|
73
85
|
|
|
@@ -87,7 +99,7 @@ def _set_workspace_cookie(
|
|
|
87
99
|
key=WORKSPACE_SESSION_COOKIE_NAME,
|
|
88
100
|
value=value,
|
|
89
101
|
max_age=max_age,
|
|
90
|
-
path=
|
|
102
|
+
path=path,
|
|
91
103
|
secure=secure,
|
|
92
104
|
httponly=True,
|
|
93
105
|
samesite="none",
|
|
@@ -141,6 +153,7 @@ async def create_workspace_session(request: Request, response: Response) -> Resp
|
|
|
141
153
|
_set_workspace_cookie(
|
|
142
154
|
response,
|
|
143
155
|
value=session_api_key,
|
|
156
|
+
path=_cookie_path(request),
|
|
144
157
|
secure=_request_is_secure_context(request),
|
|
145
158
|
max_age=_COOKIE_MAX_AGE_SECONDS,
|
|
146
159
|
)
|
|
@@ -164,6 +177,7 @@ async def delete_workspace_session(request: Request, response: Response) -> Resp
|
|
|
164
177
|
_set_workspace_cookie(
|
|
165
178
|
response,
|
|
166
179
|
value="",
|
|
180
|
+
path=_cookie_path(request),
|
|
167
181
|
secure=_request_is_secure_context(request),
|
|
168
182
|
max_age=0,
|
|
169
183
|
)
|
|
@@ -514,12 +514,12 @@ async def proxy_app_backend_websocket(
|
|
|
514
514
|
upstream_path = f"/{path}" if path else "/"
|
|
515
515
|
if query:
|
|
516
516
|
upstream_path = f"{upstream_path}?{query}"
|
|
517
|
-
await websocket.accept()
|
|
518
517
|
try:
|
|
519
518
|
await bridge_websocket(
|
|
520
519
|
websocket,
|
|
521
520
|
_target(endpoint),
|
|
522
521
|
upstream_path=upstream_path,
|
|
522
|
+
accept_client=True,
|
|
523
523
|
)
|
|
524
524
|
finally:
|
|
525
525
|
await store.detach_socket(session, task)
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
const http = require("node:http");
|
|
2
|
+
const net = require("node:net");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const os = require("node:os");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const crypto = require("node:crypto");
|
|
7
|
+
const { spawn } = require("node:child_process");
|
|
8
|
+
|
|
9
|
+
let input = "";
|
|
10
|
+
process.stdin.setEncoding("utf8");
|
|
11
|
+
process.stdin.on("data", (chunk) => {
|
|
12
|
+
input += chunk;
|
|
13
|
+
});
|
|
14
|
+
process.stdin.on("end", () => start(JSON.parse(input)));
|
|
15
|
+
|
|
16
|
+
function start(config) {
|
|
17
|
+
const prefix = config.basePath
|
|
18
|
+
? "/" + config.basePath.replace(/^\/+|\/+$/g, "")
|
|
19
|
+
: "";
|
|
20
|
+
// Only the authenticated adapter has a TCP listener. Unix permissions keep
|
|
21
|
+
// the auth-none upstream inaccessible to other users on a shared host.
|
|
22
|
+
const directory = fs.mkdtempSync(
|
|
23
|
+
path.join(os.tmpdir(), "openhands-code-server-"),
|
|
24
|
+
);
|
|
25
|
+
fs.chmodSync(directory, 0o700);
|
|
26
|
+
const socketPath = path.join(directory, "editor.sock");
|
|
27
|
+
const digest = crypto
|
|
28
|
+
.createHmac("sha256", config.token)
|
|
29
|
+
.update("editor-session")
|
|
30
|
+
.digest("hex");
|
|
31
|
+
const cookieName =
|
|
32
|
+
"openhands_editor_" +
|
|
33
|
+
crypto
|
|
34
|
+
.createHash("sha256")
|
|
35
|
+
.update(String(config.port) + prefix)
|
|
36
|
+
.digest("hex")
|
|
37
|
+
.slice(0, 16);
|
|
38
|
+
const equal = (a, b) => {
|
|
39
|
+
const left = Buffer.from(a || "");
|
|
40
|
+
const right = Buffer.from(b);
|
|
41
|
+
return left.length === right.length && crypto.timingSafeEqual(left, right);
|
|
42
|
+
};
|
|
43
|
+
const validCookie = (req) =>
|
|
44
|
+
(req.headers.cookie || "").split(";").some((value) => {
|
|
45
|
+
const [name, ...rest] = value.trim().split("=");
|
|
46
|
+
return name === cookieName && equal(rest.join("="), digest);
|
|
47
|
+
});
|
|
48
|
+
const validOrigin = (req) => {
|
|
49
|
+
if (!req.headers.origin) return true;
|
|
50
|
+
try {
|
|
51
|
+
const host = (req.headers["x-forwarded-host"] || req.headers.host || "")
|
|
52
|
+
.split(",")[0]
|
|
53
|
+
.trim();
|
|
54
|
+
return new URL(req.headers.origin).host === host;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const route = (req) => {
|
|
60
|
+
if (!req.url.startsWith("/") || req.url.startsWith("//")) return null;
|
|
61
|
+
let url;
|
|
62
|
+
try {
|
|
63
|
+
url = new URL(req.url, "http://editor.invalid");
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (
|
|
68
|
+
prefix &&
|
|
69
|
+
url.pathname !== prefix &&
|
|
70
|
+
!url.pathname.startsWith(prefix + "/")
|
|
71
|
+
)
|
|
72
|
+
return null;
|
|
73
|
+
return url;
|
|
74
|
+
};
|
|
75
|
+
const upstreamPath = (url) =>
|
|
76
|
+
(url.pathname.slice(prefix.length) || "/") + url.search;
|
|
77
|
+
const upstreamHeaders = (req) => {
|
|
78
|
+
const headers = { ...req.headers };
|
|
79
|
+
delete headers.cookie;
|
|
80
|
+
delete headers.authorization;
|
|
81
|
+
delete headers["x-session-api-key"];
|
|
82
|
+
return headers;
|
|
83
|
+
};
|
|
84
|
+
const server = http.createServer((req, res) => {
|
|
85
|
+
res.setHeader("Referrer-Policy", "no-referrer");
|
|
86
|
+
const url = route(req);
|
|
87
|
+
if (!url) {
|
|
88
|
+
res.writeHead(404).end();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!validOrigin(req)) {
|
|
92
|
+
res.writeHead(403).end();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Exchange the existing public token URL for a scoped, token-derived cookie.
|
|
96
|
+
// Restarting with a rotated token invalidates every previous cookie.
|
|
97
|
+
if (url.searchParams.has("tkn")) {
|
|
98
|
+
if (!equal(url.searchParams.get("tkn"), config.token)) {
|
|
99
|
+
res.writeHead(401).end();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
url.searchParams.delete("tkn");
|
|
103
|
+
const secure =
|
|
104
|
+
(req.headers["x-forwarded-proto"] || "").split(",")[0].trim() ===
|
|
105
|
+
"https";
|
|
106
|
+
res.setHeader(
|
|
107
|
+
"Set-Cookie",
|
|
108
|
+
`${cookieName}=${digest}; Path=${prefix || "/"}; HttpOnly; ${secure ? "Secure; SameSite=None" : "SameSite=Lax"}`,
|
|
109
|
+
);
|
|
110
|
+
res.setHeader("Cache-Control", "no-store");
|
|
111
|
+
res
|
|
112
|
+
.writeHead(303, {
|
|
113
|
+
Location:
|
|
114
|
+
(url.pathname === prefix ? prefix + "/" : url.pathname) +
|
|
115
|
+
url.search,
|
|
116
|
+
})
|
|
117
|
+
.end();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!validCookie(req)) {
|
|
121
|
+
res.writeHead(401).end();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (prefix && url.pathname === prefix) {
|
|
125
|
+
res.writeHead(308, { Location: prefix + "/" + url.search }).end();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const upstream = http.request(
|
|
129
|
+
{
|
|
130
|
+
socketPath,
|
|
131
|
+
path: upstreamPath(url),
|
|
132
|
+
method: req.method,
|
|
133
|
+
headers: upstreamHeaders(req),
|
|
134
|
+
},
|
|
135
|
+
(response) => {
|
|
136
|
+
const headers = {
|
|
137
|
+
...response.headers,
|
|
138
|
+
"referrer-policy": "no-referrer",
|
|
139
|
+
};
|
|
140
|
+
delete headers["set-cookie"];
|
|
141
|
+
res.writeHead(response.statusCode, headers);
|
|
142
|
+
response.pipe(res);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
upstream.on("error", () => {
|
|
146
|
+
if (!res.headersSent) res.writeHead(502);
|
|
147
|
+
res.end();
|
|
148
|
+
});
|
|
149
|
+
req.on("aborted", () => upstream.destroy());
|
|
150
|
+
res.on("close", () => upstream.destroy());
|
|
151
|
+
req.pipe(upstream);
|
|
152
|
+
});
|
|
153
|
+
const connections = new Set();
|
|
154
|
+
server.on("connection", (socket) => {
|
|
155
|
+
connections.add(socket);
|
|
156
|
+
socket.on("close", () => connections.delete(socket));
|
|
157
|
+
});
|
|
158
|
+
server.on("upgrade", (req, socket, head) => {
|
|
159
|
+
const url = route(req);
|
|
160
|
+
if (!url || !validCookie(req) || !validOrigin(req)) {
|
|
161
|
+
socket.end("HTTP/1.1 401 Unauthorized\r\nConnection: close\r\n\r\n");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const upstream = http.request({
|
|
165
|
+
socketPath,
|
|
166
|
+
path: upstreamPath(url),
|
|
167
|
+
headers: upstreamHeaders(req),
|
|
168
|
+
});
|
|
169
|
+
upstream.on("upgrade", (response, peer, upstreamHead) => {
|
|
170
|
+
const lines = [
|
|
171
|
+
`HTTP/1.1 ${response.statusCode} ${response.statusMessage}`,
|
|
172
|
+
];
|
|
173
|
+
for (let i = 0; i < response.rawHeaders.length; i += 2)
|
|
174
|
+
lines.push(`${response.rawHeaders[i]}: ${response.rawHeaders[i + 1]}`);
|
|
175
|
+
socket.write(lines.join("\r\n") + "\r\n\r\n");
|
|
176
|
+
if (upstreamHead.length) socket.write(upstreamHead);
|
|
177
|
+
if (head.length) peer.write(head);
|
|
178
|
+
socket.pipe(peer).pipe(socket);
|
|
179
|
+
peer.on("error", () => socket.destroy());
|
|
180
|
+
socket.on("error", () => peer.destroy());
|
|
181
|
+
socket.on("close", () => peer.destroy());
|
|
182
|
+
peer.on("close", () => socket.destroy());
|
|
183
|
+
});
|
|
184
|
+
upstream.on("response", (response) => {
|
|
185
|
+
socket.end(
|
|
186
|
+
`HTTP/1.1 ${response.statusCode} Rejected\r\nConnection: close\r\n\r\n`,
|
|
187
|
+
);
|
|
188
|
+
response.resume();
|
|
189
|
+
});
|
|
190
|
+
upstream.on("error", () => socket.destroy());
|
|
191
|
+
socket.on("close", () => upstream.destroy());
|
|
192
|
+
upstream.end();
|
|
193
|
+
});
|
|
194
|
+
const env = { ...process.env };
|
|
195
|
+
delete env.PASSWORD;
|
|
196
|
+
delete env.HASHED_PASSWORD;
|
|
197
|
+
delete env.NODE_OPTIONS;
|
|
198
|
+
const child = spawn(
|
|
199
|
+
path.join(config.root, "bin/code-server"),
|
|
200
|
+
[
|
|
201
|
+
"--config",
|
|
202
|
+
"/dev/null",
|
|
203
|
+
"--auth",
|
|
204
|
+
"none",
|
|
205
|
+
"--socket",
|
|
206
|
+
socketPath,
|
|
207
|
+
"--socket-mode",
|
|
208
|
+
"0600",
|
|
209
|
+
"--session-socket",
|
|
210
|
+
path.join(directory, "session.sock"),
|
|
211
|
+
"--disable-telemetry",
|
|
212
|
+
"--disable-update-check",
|
|
213
|
+
"--disable-proxy",
|
|
214
|
+
"--disable-workspace-trust",
|
|
215
|
+
"--user-data-dir",
|
|
216
|
+
path.join(
|
|
217
|
+
os.homedir(),
|
|
218
|
+
".local/share/openhands-code-server",
|
|
219
|
+
String(config.port),
|
|
220
|
+
),
|
|
221
|
+
],
|
|
222
|
+
{ env, stdio: ["ignore", "pipe", "pipe"] },
|
|
223
|
+
);
|
|
224
|
+
child.stdout.pipe(process.stdout);
|
|
225
|
+
child.stderr.pipe(process.stderr);
|
|
226
|
+
const cleanup = () => {
|
|
227
|
+
clearInterval(timer);
|
|
228
|
+
server.close();
|
|
229
|
+
for (const socket of connections) socket.destroy();
|
|
230
|
+
child.kill();
|
|
231
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
232
|
+
};
|
|
233
|
+
let listening = false;
|
|
234
|
+
const timer = setInterval(() => {
|
|
235
|
+
if (!fs.existsSync(socketPath)) return;
|
|
236
|
+
const probe = net.connect(socketPath);
|
|
237
|
+
probe.on("error", () => {});
|
|
238
|
+
probe.on("connect", () => {
|
|
239
|
+
probe.destroy();
|
|
240
|
+
if (listening) return;
|
|
241
|
+
listening = true;
|
|
242
|
+
clearInterval(timer);
|
|
243
|
+
server.listen(config.port, "0.0.0.0", () =>
|
|
244
|
+
console.log("OpenHands editor ready"),
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
}, 100);
|
|
248
|
+
server.on("error", (error) => {
|
|
249
|
+
console.error(error.message);
|
|
250
|
+
cleanup();
|
|
251
|
+
process.exit(1);
|
|
252
|
+
});
|
|
253
|
+
child.on("error", (error) => {
|
|
254
|
+
console.error(error.message);
|
|
255
|
+
cleanup();
|
|
256
|
+
process.exit(1);
|
|
257
|
+
});
|
|
258
|
+
child.on("exit", (code) => {
|
|
259
|
+
cleanup();
|
|
260
|
+
process.exit(code || 1);
|
|
261
|
+
});
|
|
262
|
+
process.on("SIGTERM", () => {
|
|
263
|
+
cleanup();
|
|
264
|
+
process.exit(0);
|
|
265
|
+
});
|
|
266
|
+
process.on("SIGINT", () => {
|
|
267
|
+
cleanup();
|
|
268
|
+
process.exit(0);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
@@ -592,7 +592,7 @@ async def set_conversation_security_analyzer(
|
|
|
592
592
|
@conversation_router.post(
|
|
593
593
|
"/{conversation_id}/switch_profile",
|
|
594
594
|
responses={
|
|
595
|
-
400: {"description": "Invalid or corrupted profile"},
|
|
595
|
+
400: {"description": "Invalid or corrupted profile, or an ACP agent"},
|
|
596
596
|
404: {"description": "Conversation or profile not found"},
|
|
597
597
|
},
|
|
598
598
|
)
|
|
@@ -623,7 +623,10 @@ async def switch_conversation_profile(
|
|
|
623
623
|
|
|
624
624
|
@conversation_router.post(
|
|
625
625
|
"/{conversation_id}/switch_llm",
|
|
626
|
-
responses={
|
|
626
|
+
responses={
|
|
627
|
+
400: {"description": "Agent is ACP (use switch_acp_model)"},
|
|
628
|
+
404: {"description": "Conversation not found"},
|
|
629
|
+
},
|
|
627
630
|
)
|
|
628
631
|
async def switch_conversation_llm(
|
|
629
632
|
request: Request,
|
|
@@ -654,7 +657,13 @@ async def switch_conversation_llm(
|
|
|
654
657
|
# byte-identical to the old path.
|
|
655
658
|
with store_errors():
|
|
656
659
|
llm = get_llm_profile_store().resolve_provider_connection(llm, cipher=cipher)
|
|
657
|
-
|
|
660
|
+
try:
|
|
661
|
+
conversation.switch_llm(llm)
|
|
662
|
+
except ValueError as e:
|
|
663
|
+
raise HTTPException(
|
|
664
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
|
665
|
+
detail=str(e),
|
|
666
|
+
)
|
|
658
667
|
return Success()
|
|
659
668
|
|
|
660
669
|
|
|
@@ -273,18 +273,21 @@ def _worktree_start_point(repo_root: Path, options: ConversationWorktreeOptions)
|
|
|
273
273
|
|
|
274
274
|
def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
|
|
275
275
|
repo_root = plan.repo_root
|
|
276
|
-
plan.worktree_root
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
276
|
+
worktree_root = plan.worktree_root
|
|
277
|
+
worktree_root.parent.mkdir(parents=True, exist_ok=True)
|
|
278
|
+
|
|
279
|
+
# Other containers' worktrees are not mounted here. Global pruning would
|
|
280
|
+
# unregister those live siblings, so remove only this conversation's entry.
|
|
281
|
+
registered_worktrees = run_git_command(
|
|
282
|
+
["git", "worktree", "list", "--porcelain", "-z"], repo_root
|
|
283
|
+
).split("\0")
|
|
284
|
+
if f"worktree {worktree_root}" in registered_worktrees:
|
|
285
|
+
run_git_command(
|
|
286
|
+
["git", "worktree", "remove", "--force", str(worktree_root)],
|
|
287
|
+
repo_root,
|
|
288
|
+
)
|
|
289
|
+
elif worktree_root.exists():
|
|
290
|
+
safe_rmtree(worktree_root)
|
|
288
291
|
|
|
289
292
|
if run_git_command(["git", "branch", "--list", plan.branch], repo_root):
|
|
290
293
|
run_git_command(["git", "branch", "-D", plan.branch], repo_root)
|
|
@@ -514,7 +517,7 @@ def _read_execution_status_sync(
|
|
|
514
517
|
Validating the full ``ConversationState`` costs an agent, LLM config,
|
|
515
518
|
workspace, secret registry and stats blob to reach one enum field.
|
|
516
519
|
"""
|
|
517
|
-
with suppress(OSError, ValueError):
|
|
520
|
+
with suppress(OSError, ValueError, AttributeError):
|
|
518
521
|
with open(base_state_path, "rb") as f:
|
|
519
522
|
payload = json.loads(f.read())
|
|
520
523
|
return ConversationExecutionStatus(
|