oclaw/interfaces/gateway/server_methods/commands.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

62 lines
1.8 KiB
Python

from __future__ import annotations
from typing import Any
from .shared_types import GatewayRequestHandlers
from .validation import error_shape
def _validate_commands_list_params(params: Any) -> bool:
if not isinstance(params, dict):
return False
for k in ("agentId", "provider", "scope"):
if k in params and params[k] is not None and not isinstance(params[k], str):
return False
if "includeArgs" in params and params["includeArgs"] is not None and not isinstance(params["includeArgs"], bool):
return False
return True
def build_commands_list_result(
*,
cfg: dict[str, Any],
agent_id: str,
provider: str | None = None,
scope: str | None = None,
include_args: bool | None = None,
) -> dict[str, Any]:
_ = cfg, agent_id, provider, scope, include_args
return {"commands": []}
def _commands_list_handler(opts: dict[str, Any]) -> None:
respond = opts.get("respond")
params = opts.get("params")
if not callable(respond):
return
if not _validate_commands_list_params(params):
respond(False, None, error_shape("INVALID_REQUEST", "invalid commands.list params"), None)
return
p = params if isinstance(params, dict) else {}
agent_id = str(p.get("agentId") or "main").strip() or "main"
provider = str(p.get("provider") or "").strip() or None
scope = str(p.get("scope") or "").strip() or None
include_args = p.get("includeArgs")
include_args = bool(include_args) if include_args is not None else None
respond(
True,
build_commands_list_result(
cfg={},
agent_id=agent_id,
provider=provider,
scope=scope,
include_args=include_args,
),
None,
None,
)
commands_handlers: GatewayRequestHandlers = {
"commands.list": _commands_list_handler,
}