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
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Tool source/label formatting shared by ``surfaces/cli`` and ``surfaces/interactive_shell``.
|
|
|
|
Both surfaces render the same live tool-call activity (a source badge like
|
|
``Grafana`` or ``SRE``, and a short human label with the source prefix
|
|
stripped) while an investigation runs. The two implementations were
|
|
identical, so this is the T-21 extraction: pure formatting with no
|
|
surface-specific state, safe to share.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from tools.registry import get_registered_tool_map, resolve_tool_display_name
|
|
|
|
|
|
def tool_source_label(tool_name: str) -> str:
|
|
"""Return a human-friendly source badge (e.g. ``Grafana``, ``SRE``) for a tool."""
|
|
tool = get_registered_tool_map().get(tool_name)
|
|
source = str(tool.source) if tool is not None else infer_tool_source(tool_name)
|
|
if source == "grafana":
|
|
return "Grafana"
|
|
if source == "knowledge":
|
|
return "SRE"
|
|
if source == "openclaw":
|
|
return "OpenClaw"
|
|
return source.replace("_", " ").title() if source else "Tools"
|
|
|
|
|
|
def infer_tool_source(tool_name: str) -> str:
|
|
"""Guess a tool's source from its name when the registry has no entry for it."""
|
|
lowered = tool_name.lower()
|
|
for source in ("grafana", "datadog", "cloudwatch", "sentry", "honeycomb", "openclaw"):
|
|
if source in lowered:
|
|
return source
|
|
if lowered.startswith("get_sre_"):
|
|
return "knowledge"
|
|
return "tools"
|
|
|
|
|
|
def tool_short_label(tool_name: str, source_label: str) -> str:
|
|
"""Return the tool's display name with its source prefix (if any) stripped."""
|
|
display = resolve_tool_display_name(tool_name)
|
|
label = display
|
|
for prefix in (
|
|
source_label,
|
|
source_label.lower(),
|
|
f"{source_label} ",
|
|
f"{source_label.lower()} ",
|
|
"query ",
|
|
"get ",
|
|
):
|
|
if label.startswith(prefix):
|
|
label = label[len(prefix) :].strip()
|
|
if source_label == "Grafana" and label.lower().startswith("grafana "):
|
|
label = label[len("grafana ") :].strip()
|
|
return label or display
|