55 lines
2.7 KiB
Python
55 lines
2.7 KiB
Python
"""AITURK adapter for the upstream catalog and existing pinned installer.
|
||
|
||
Catalog parsing/cache comes from NousResearch/hermes-agent ad12263a5ed4.
|
||
The catalog supplies the repository and immutable revision, never the client.
|
||
"""
|
||
from dataclasses import asdict
|
||
import sys
|
||
|
||
from hermes_cli import plugin_catalog as catalog
|
||
|
||
|
||
def catalog_payload():
|
||
from hermes_cli.plugins_cmd import _discover_all_plugins, _read_install_metadata
|
||
|
||
installed = {row[0] for row in _discover_all_plugins()}
|
||
metadata = _read_install_metadata()
|
||
removed = catalog.resolved_removed_entries()
|
||
entries = []
|
||
for entry in catalog.load_catalog_live():
|
||
if catalog.match_removed(entry.name, removed) or catalog.match_removed(entry.repo, removed):
|
||
continue
|
||
row = entry.to_dict()
|
||
record = metadata.get(entry.name, {})
|
||
revision = record.get("revision")
|
||
row.update(installed=entry.name in installed, installed_sha=revision,
|
||
update_available=bool(revision and revision != entry.sha),
|
||
sha_short=entry.sha[:12], capability_summary=catalog.entry_capability_summary(entry))
|
||
entries.append(row)
|
||
return {"entries": entries, "removed": [asdict(row) for row in removed]}
|
||
|
||
|
||
def install_catalog_plugin(name, *, force=False, enable=True):
|
||
from hermes_cli.plugins_cmd import dashboard_install_plugin
|
||
|
||
entry = catalog.get_live_catalog_entry(name)
|
||
if entry is None:
|
||
return {"ok": False, "error": "Eklenti katalogda bulunamadı."}
|
||
removed = catalog.resolved_removed_entries()
|
||
if catalog.match_removed(name, removed) or catalog.match_removed(entry.repo, removed):
|
||
return {"ok": False, "error": "Bu eklenti katalogdan kaldırılmış."}
|
||
platform = {"win32": "windows", "darwin": "macos"}.get(sys.platform, sys.platform)
|
||
supported = {"win": "windows", "win32": "windows", "darwin": "macos", "mac": "macos"}
|
||
if entry.platforms and platform not in {supported.get(p.lower(), p.lower()) for p in entry.platforms}:
|
||
return {"ok": False, "error": "Bu eklenti bilgisayarın işletim sistemini desteklemiyor."}
|
||
if entry.requires_hermes:
|
||
from packaging.specifiers import InvalidSpecifier, SpecifierSet
|
||
from hermes_cli import __version__
|
||
try:
|
||
compatible = __version__ in SpecifierSet(entry.requires_hermes)
|
||
except InvalidSpecifier:
|
||
return {"ok": False, "error": "Katalogdaki sürüm koşulu geçersiz; eklenti kurulmadı."}
|
||
if not compatible:
|
||
return {"ok": False, "error": f"Bu eklenti Hermes {entry.requires_hermes} gerektiriyor."}
|
||
return dashboard_install_plugin(entry.install_identifier, force=force, enable=enable, ref=entry.sha)
|