4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""Action-surface helpers backed by the canonical tool registry."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable
|
|
from typing import Any, Protocol
|
|
|
|
from core.tool_framework.registered_tool import RegisteredTool
|
|
from core.tool_framework.utils.integration_sources import availability_view
|
|
from platform.harness_ports import get_surface_tool_map, get_surface_tools
|
|
from platform.observability.trace.redaction import redact_sensitive
|
|
|
|
_ACTION_SESSION_SOURCE = "_action_session"
|
|
|
|
|
|
class _IntegrationContextSession(Protocol):
|
|
@property
|
|
def configured_integrations(self) -> Iterable[str]:
|
|
raise NotImplementedError
|
|
|
|
@property
|
|
def configured_integrations_known(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
|
|
class IntegrationsContext(Protocol):
|
|
@property
|
|
def session(self) -> _IntegrationContextSession:
|
|
raise NotImplementedError
|
|
|
|
|
|
def _sources_for_context(
|
|
ctx: IntegrationsContext,
|
|
resolved_integrations: dict[str, Any] | None,
|
|
) -> dict[str, dict[str, Any]]:
|
|
raw_sources = availability_view(resolved_integrations or {})
|
|
sources = dict(raw_sources)
|
|
sources[_ACTION_SESSION_SOURCE] = {
|
|
"session": ctx.session,
|
|
"configured_integrations": tuple(ctx.session.configured_integrations),
|
|
"configured_integrations_known": ctx.session.configured_integrations_known,
|
|
"available_capabilities": getattr(ctx.session, "available_capabilities", {}),
|
|
}
|
|
return sources
|
|
|
|
|
|
def get_action_tools_from_integrations_context(
|
|
ctx: IntegrationsContext,
|
|
*,
|
|
resolved_integrations: dict[str, Any] | None = None,
|
|
) -> list[RegisteredTool]:
|
|
"""Return canonical registered tools available to the action agent."""
|
|
sources = _sources_for_context(ctx, resolved_integrations)
|
|
tools: list[RegisteredTool] = []
|
|
for candidate in get_surface_tools("action"):
|
|
try:
|
|
if not candidate.is_available(sources):
|
|
continue
|
|
except Exception as exc:
|
|
safe_sources = redact_sensitive(sources)
|
|
raise RuntimeError(
|
|
f"{candidate.name} availability check failed for sources {safe_sources!r}: {exc}"
|
|
) from exc
|
|
tools.append(candidate)
|
|
return tools
|
|
|
|
|
|
def get_action_tool(name: str) -> RegisteredTool | None:
|
|
"""Return a registered action tool by name."""
|
|
return get_surface_tool_map("action").get(name)
|
|
|
|
|
|
def action_tool_names(tools: Iterable[RegisteredTool]) -> tuple[str, ...]:
|
|
return tuple(tool.name for tool in tools)
|
|
|
|
|
|
__all__ = [
|
|
"IntegrationsContext",
|
|
"action_tool_names",
|
|
"get_action_tool",
|
|
"get_action_tools_from_integrations_context",
|
|
]
|