oclaw/runtime/tools/skills_runtime/materialize_skill_tools.py
oliver dbbe3add6a 重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
2026-04-26 08:34:33 +08:00

63 lines
2.3 KiB
Python

from __future__ import annotations
from typing import Any
from oclaw.runtime.skills import discover_workspace_skill_manifests
from oclaw.runtime.tools.base import ToolSpec
def materialize_executable_skill_tools(*, store: Any | None = None) -> list[ToolSpec]:
"""Convert installed skill manifests with runtime into ToolSpec.
Tool name equals skill name so the model can call it directly.
"""
_ = store
out: list[ToolSpec] = []
for m in discover_workspace_skill_manifests():
rt = dict(m.runtime or {}) if isinstance(m.runtime, dict) else {}
if not rt:
continue
tp = str(rt.get("type") or "").strip().lower()
entry = str(rt.get("entry") or "").strip()
if not tp or not entry:
continue
schema = rt.get("schema") if isinstance(rt.get("schema"), dict) else {"type": "object", "additionalProperties": True}
name = str(m.name or "").strip()
if not name:
continue
def _handler(args: dict[str, Any], *, _manifest=m, _rt=rt) -> dict[str, Any]:
from oclaw.runtime.tools.skills_runtime.subprocess_exec import run_skill_runtime_entry
source_meta = {}
if isinstance(getattr(_manifest, "metadata_oclaw", None), dict):
source_raw = _manifest.metadata_oclaw.get("source")
if isinstance(source_raw, dict):
source_meta = {
"provider": str(source_raw.get("provider") or ""),
"version": str(source_raw.get("version") or ""),
"kind": str(source_raw.get("kind") or ""),
}
return run_skill_runtime_entry(
skill_name=str(_manifest.name or ""),
skill_dir=str(_manifest.skill_dir or ""),
runtime={**dict(_rt), "__source_meta": source_meta},
args=dict(args or {}),
)
out.append(
ToolSpec(
name=name,
description=str(m.description or ""),
parameters=dict(schema),
handler=_handler,
tags=frozenset({"skill", "oclaw", "runtime"}),
risk_level="high",
timeout_s=60.0,
)
)
return out
__all__ = ["materialize_executable_skill_tools"]