Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
ACPAgentProfile,
AgentProfile,
AgentProfileDiagnostics,
AgentProfileInfo,
AgentProfileListResponse,
AgentProfileStore,
OpenHandsAgentProfile,
ProfileLimitExceeded,
Expand All @@ -73,22 +75,6 @@
ProfileId = Annotated[str, Path(min_length=1, max_length=128)]


class AgentProfileInfo(BaseModel):
"""Summary projection of a stored profile (no secret instantiation)."""

id: str | None = None
name: str
agent_kind: str = "openhands"
revision: int | None = None
llm_profile_ref: str | None = None
mcp_server_refs: list[str] | None = None


class AgentProfileListResponse(BaseModel):
profiles: list[AgentProfileInfo]
active_agent_profile_id: str | None = None


class AgentProfileDetailResponse(BaseModel):
name: str
profile: dict[str, Any]
Expand Down
72 changes: 72 additions & 0 deletions openhands-agent-server/openhands/agent_server/plugins_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PluginSkillSummary,
service_disable_plugin,
service_enable_plugin,
service_fetch_plugin,
service_get_installed_plugin,
service_get_plugins_marketplace_catalog,
service_install_plugin,
Expand All @@ -31,6 +32,13 @@
)
from openhands.sdk.extensions.fetch import ExtensionFetchError
from openhands.sdk.plugin import InstalledPluginInfo, Plugin, PluginFetchError
from openhands.sdk.plugin.strict_fetch import PluginSourceError
from openhands.sdk.secret import SecretSource


type JSONValue = (
str | int | float | bool | None | list[JSONValue] | dict[str, JSONValue]
)
Comment thread
malhotra5 marked this conversation as resolved.
Resolved


plugins_router = APIRouter(prefix="/plugins", tags=["Plugins"])
Expand Down Expand Up @@ -114,6 +122,34 @@ class InstallPluginRequest(BaseModel):
)


class FetchPluginRequest(BaseModel):
"""Request body for strictly fetching a plugin without installing it."""

source: str = Field(min_length=1, description="Plugin git source")
ref: str | None = Field(default=None, description="Branch, tag, or commit")
repo_path: str | None = Field(
default=None,
description="Subdirectory path within the repository (for monorepos)",
)
secrets: dict[str, SecretSource] = Field(
default_factory=dict,
description="Secrets used to expand ${VAR} placeholders in source and ref",
)
timeout: int = Field(default=60, ge=1, le=600, description="Git timeout seconds")


class FetchPluginResponse(BaseModel):
"""Response from strictly fetching a plugin source."""

path: str
resolved_ref: str | None
source: str
repo_path: str | None
manifest: dict[str, JSONValue]
skills: list[str]
commands: list[str]


class InstalledPluginResponse(BaseModel):
"""Response containing installed plugin information."""

Expand Down Expand Up @@ -237,6 +273,42 @@ def get_plugins(request: PluginsRequest) -> PluginsResponse:
return PluginsResponse(plugins=[_plugin_info(p) for p in plugins])


@plugins_router.post(
"/fetch",
response_model=FetchPluginResponse,
responses={
422: {"description": "Invalid plugin source, ref, path, or plugin"},
502: {"description": "Plugin source unavailable"},
504: {"description": "Plugin fetch timed out"},
},
)
def fetch_plugin_endpoint(request: FetchPluginRequest) -> FetchPluginResponse:
"""Fetch and pin a plugin source without installing or enabling it."""
try:
checked = service_fetch_plugin(
source=request.source,
ref=request.ref,
repo_path=request.repo_path,
secrets=request.secrets,
timeout=request.timeout,
)
except PluginSourceError as exc:
raise HTTPException(
status_code=exc.status_code,
detail={"code": exc.code, "message": exc.message},
) from exc

return FetchPluginResponse(
path=str(checked.path),
resolved_ref=checked.resolved_ref,
source=checked.source,
repo_path=checked.repo_path,
manifest=checked.manifest,
skills=checked.skills,
commands=checked.commands,
)


@plugins_router.post(
"/install",
response_model=InstalledPluginResponse,
Expand Down
23 changes: 23 additions & 0 deletions openhands-agent-server/openhands/agent_server/plugins_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import json
import os
from collections.abc import Mapping
from pathlib import Path
from time import monotonic

Expand All @@ -23,6 +24,7 @@
from openhands.sdk.logger import get_logger
from openhands.sdk.marketplace import Marketplace
from openhands.sdk.plugin import (
CheckedPlugin,
InstalledPluginInfo,
Plugin,
disable_plugin,
Expand All @@ -33,6 +35,8 @@
uninstall_plugin,
update_plugin,
)
from openhands.sdk.plugin.strict_fetch import fetch_plugin_strict
from openhands.sdk.secret import SecretValue
from openhands.sdk.skills.skill import (
DEFAULT_MARKETPLACE_PATH,
PUBLIC_SKILLS_REF,
Expand Down Expand Up @@ -70,6 +74,25 @@ def service_install_plugin(
)


def service_fetch_plugin(
source: str,
ref: str | None = None,
repo_path: str | None = None,
secrets: Mapping[str, SecretValue] | None = None,
timeout: int = 60,
) -> CheckedPlugin:
"""Strictly fetch a plugin into the immutable plugin cache."""
return fetch_plugin_strict(
source=source,
ref=ref,
repo_path=repo_path,
secrets=secrets,
timeout=timeout,
allow_local=True,
use_cache=True,
)


def service_uninstall_plugin(name: str, installed_dir: Path | None = None) -> bool:
"""Uninstall a plugin by name. Returns False if it wasn't installed."""
return uninstall_plugin(name, installed_dir=installed_dir)
Expand Down
8 changes: 8 additions & 0 deletions openhands-sdk/openhands/sdk/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
resolve_source_path,
validate_source_path,
)
from openhands.sdk.plugin.strict_fetch import (
CheckedPlugin,
PluginSourceError,
preflight_plugin,
)
from openhands.sdk.plugin.types import (
CommandDefinition,
PluginAuthor,
Expand All @@ -62,6 +67,8 @@
# Plugin classes
"Plugin",
"PluginFetchError",
"PluginSourceError",
"CheckedPlugin",
"PluginManifest",
"PluginAuthor",
"PluginSource",
Expand All @@ -75,6 +82,7 @@
# Plugin loading
"load_plugins",
"fetch_plugin_with_resolution",
"preflight_plugin",
# Local plugin discovery (ambient auto-load)
"load_user_plugins",
"load_project_plugins",
Expand Down
35 changes: 34 additions & 1 deletion openhands-sdk/openhands/sdk/plugin/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,50 @@

from __future__ import annotations

import re
from pathlib import Path

from openhands.sdk.extensions.fetch import (
ExtensionFetchError,
SourceType,
fetch_with_resolution as _ext_fetch_with_resolution,
parse_extension_source,
)
from openhands.sdk.git.cached_repo import GitHelper
from openhands.sdk.plugin.paths import get_pinned_plugin_cache_path
from openhands.sdk.utils.path import get_user_persistence_dir


DEFAULT_CACHE_DIR = get_user_persistence_dir() / "cache" / "plugins"
_FULL_SHA_RE = re.compile(r"^[0-9a-fA-F]{40}$")


class PluginFetchError(Exception):
"""Raised when fetching a plugin fails."""


def _cached_pinned_plugin(
source: str, cache_dir: Path, ref: str, repo_path: str | None
) -> Path | None:
try:
source_type, url = parse_extension_source(source)
except ExtensionFetchError:
return None
if source_type == SourceType.LOCAL:
return None

cached_root = get_pinned_plugin_cache_path(url, cache_dir, ref.lower())
if not cached_root.is_dir():
return None
if repo_path is None:
return cached_root

candidate = cached_root / repo_path.strip("/")
if candidate.is_dir() and candidate.resolve().is_relative_to(cached_root.resolve()):
return candidate
return None


def fetch_plugin(
source: str,
cache_dir: Path | None = None,
Expand Down Expand Up @@ -98,6 +125,11 @@ def fetch_plugin_with_resolution(
PluginFetchError: If fetching fails or repo_path doesn't exist.
"""
resolved_cache_dir = cache_dir if cache_dir is not None else DEFAULT_CACHE_DIR
if ref is not None and _FULL_SHA_RE.fullmatch(ref):
cached = _cached_pinned_plugin(source, resolved_cache_dir, ref, repo_path)
if cached is not None:
return cached, ref.lower()

try:
return _ext_fetch_with_resolution(
source=source,
Expand All @@ -108,5 +140,6 @@ def fetch_plugin_with_resolution(
git_helper=git_helper,
)
except ExtensionFetchError as exc:
msg = str(exc).replace("extension", "plugin")
msg = re.sub(r"\bextension\b", "plugin", str(exc))
msg = re.sub(r"\bExtension\b", "Plugin", msg)
raise PluginFetchError(msg) from exc
17 changes: 17 additions & 0 deletions openhands-sdk/openhands/sdk/plugin/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Filesystem paths shared by plugin fetch implementations."""

from __future__ import annotations

from pathlib import Path

from openhands.sdk.extensions.fetch import get_cache_path


PINNED_REFS_DIR = "resolved-refs"


def get_pinned_plugin_cache_path(
source_url: str, cache_dir: Path, resolved_ref: str
) -> Path:
"""Return the immutable cache path for a plugin source at a commit SHA."""
return get_cache_path(source_url, cache_dir) / PINNED_REFS_DIR / resolved_ref
Loading
Loading