mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
* refactor(core): reorganize the ReMe runtime and shared helpers * test(status): import the base component from its canonical module * test: remove redundant unit checks * refactor(core): use canonical runtime imports and shared CLI discovery Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service. * fix(cli): honor caller config when service replay is incomplete Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
"""Parse the small, declarative contract shared by plugin runtime and CLI."""
|
|
|
|
from dataclasses import dataclass
|
|
from importlib import resources
|
|
from typing import Any
|
|
|
|
import yaml
|
|
|
|
PLUGIN_MANIFEST = "plugin.yaml"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PluginManifest:
|
|
"""The two contributions an installed plugin may declare."""
|
|
|
|
backends: dict[str, str]
|
|
application_defaults: dict[str, Any]
|
|
|
|
|
|
def parse_plugin_manifest(text: str, *, plugin_name: str) -> PluginManifest:
|
|
"""Parse and validate plugin.yaml without importing backend modules."""
|
|
try:
|
|
value = yaml.safe_load(text)
|
|
except yaml.YAMLError as exc:
|
|
raise ValueError(f"Plugin '{plugin_name}' manifest is invalid YAML") from exc
|
|
if not isinstance(value, dict):
|
|
raise ValueError(f"Plugin '{plugin_name}' manifest root must be a mapping")
|
|
|
|
unknown = set(value) - {"backends", "application_defaults"}
|
|
if unknown:
|
|
raise ValueError(f"Plugin '{plugin_name}' manifest has unknown keys: {', '.join(sorted(unknown))}")
|
|
|
|
backends = value.get("backends")
|
|
application_defaults = value.get("application_defaults")
|
|
backends = {} if backends is None else backends
|
|
application_defaults = {} if application_defaults is None else application_defaults
|
|
if not isinstance(backends, dict):
|
|
raise TypeError(f"Plugin '{plugin_name}' manifest 'backends' must be a mapping")
|
|
if not isinstance(application_defaults, dict):
|
|
raise TypeError(f"Plugin '{plugin_name}' manifest 'application_defaults' must be a mapping")
|
|
for name, target in backends.items():
|
|
if not isinstance(name, str) or not name:
|
|
raise TypeError(f"Plugin '{plugin_name}' backend names must be non-empty strings")
|
|
if not isinstance(target, str) or not target:
|
|
raise TypeError(f"Plugin '{plugin_name}' backend target for '{name}' must be a non-empty string")
|
|
return PluginManifest(backends=dict(backends), application_defaults=dict(application_defaults))
|
|
|
|
|
|
def load_package_manifest(package: str, *, plugin_name: str) -> PluginManifest:
|
|
"""Read plugin.yaml from an importable package."""
|
|
try:
|
|
path = resources.files(package).joinpath(PLUGIN_MANIFEST)
|
|
text = path.read_text(encoding="utf-8")
|
|
except (ModuleNotFoundError, FileNotFoundError, TypeError) as exc:
|
|
raise ValueError(f"Plugin '{plugin_name}' does not provide {package}/{PLUGIN_MANIFEST}") from exc
|
|
return parse_plugin_manifest(text, plugin_name=plugin_name)
|