feat(v3.12.0): media pipeline, AI image generation, capability probe, companion v2.9.0
Three-month batch sync from internal repo (~80 commits) covering Tracks F.5a, F.7e, F.8, F.17, F.18, F.X. WordPress media pipeline - Pillow-based optimization, AI image generation (OpenAI / Stability / Replicate / Google Nano Banana / OpenRouter), chunked + resumable uploads, bulk delete/reassign, idempotent retries. Capability discovery (F.7e) - Per-site credential probe + adapters for WordPress / WooCommerce / Gitea, tier-fit unions granted ∪ roles, capability badge UI with HTMX partial re-check, install hint in every companion-unreachable error. Companion plugin overhaul - Renamed wordpress-plugin/airano-mcp-seo-bridge → wordpress-plugin/airano-mcp-bridge. - Eight new endpoints: /capabilities, /bulk-meta, /export, /cache-purge, /transient-flush, /site-health, /audit-hook, /upload-and-attach. - wp.org Plugin Check pass: i18n, WP_Filesystem, scheme allowlist on audit-hook URL. Other - Gitea ergonomics (F.17): batch files, tree, search, compare, releases, fork. - Opportunistic bcrypt upgrade for legacy SHA-256 admin keys (F.8). - n8n refactor: structured errors, capability probe, missing tools backfilled. - Idempotency-Key dedup for AI media upload retries; WP client fast-fails on unreachable sites. Docs - README + CLAUDE.md drop the fixed "633 tools" claim. The total grows with each release; per-plugin approximations + dashboard-surfaced counts replace it. - Tools/Tests badges removed in favour of "Plugins: 10". Deployment - PyPI mirror chain, optional BUILD_HTTP_PROXY, Alpine→Yandex apk mirror, Debian-slim Plan-B Dockerfile, mirror.gcr.io variant. CI - Black + Ruff clean on Python 3.12; pytest tests/ green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -70,12 +70,27 @@ def _check_user_rate_limit(user_id: str) -> tuple[bool, str]:
|
||||
return True, ""
|
||||
|
||||
|
||||
def _tools_to_mcp_schema(tools: list[ToolDefinition]) -> list[dict[str, Any]]:
|
||||
def _tools_to_mcp_schema(
|
||||
tools: list[ToolDefinition],
|
||||
*,
|
||||
configured_providers: list[str] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Convert ToolDefinition objects into MCP ``tools/list`` response shape.
|
||||
|
||||
Strips the auto-injected ``site`` parameter, since user endpoints bind a
|
||||
single site per alias.
|
||||
|
||||
F.X.fix-pass6 — when ``configured_providers`` is given (i.e. the
|
||||
site has at least one AI provider key configured), narrow the
|
||||
``provider`` enum on the AI image tool to that subset. The model
|
||||
only sees providers that will actually succeed, instead of trying
|
||||
OpenAI / Stability / Replicate and getting NO_PROVIDER_KEY when
|
||||
only OpenRouter is configured.
|
||||
"""
|
||||
ai_image_tools = {
|
||||
"wordpress_generate_and_upload_image",
|
||||
"woocommerce_generate_and_upload_image",
|
||||
}
|
||||
result = []
|
||||
for tool_def in tools:
|
||||
schema = deepcopy(tool_def.input_schema)
|
||||
@@ -84,6 +99,22 @@ def _tools_to_mcp_schema(tools: list[ToolDefinition]) -> list[dict[str, Any]]:
|
||||
if "required" in schema and "site" in schema["required"]:
|
||||
schema["required"] = [r for r in schema["required"] if r != "site"]
|
||||
|
||||
if (
|
||||
configured_providers
|
||||
and tool_def.name in ai_image_tools
|
||||
and "properties" in schema
|
||||
and "provider" in schema["properties"]
|
||||
):
|
||||
schema["properties"]["provider"] = {
|
||||
**schema["properties"]["provider"],
|
||||
"enum": list(configured_providers),
|
||||
"description": (
|
||||
"AI provider to use. This site has the following providers "
|
||||
f"configured: {', '.join(configured_providers)}. Add more "
|
||||
"in Connection Settings → AI Image Generation."
|
||||
),
|
||||
}
|
||||
|
||||
result.append(
|
||||
{
|
||||
"name": tool_def.name,
|
||||
@@ -99,14 +130,41 @@ async def _get_visible_tools_for_site(
|
||||
key_scopes: list[str],
|
||||
plugin_type: str,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Return tools/list payload filtered by key scope + site scope + toggles (F.7b)."""
|
||||
"""Return tools/list payload filtered by key scope + site scope + toggles (F.7b).
|
||||
|
||||
F.5a.9.x: additionally hide ``wordpress_generate_and_upload_image`` when
|
||||
the site has no provider API key configured — the tool would fail at
|
||||
call-time with ``NO_PROVIDER_KEY`` anyway, so hiding it keeps the
|
||||
surface honest for AI clients.
|
||||
"""
|
||||
from core.tool_access import get_tool_access_manager
|
||||
|
||||
access = get_tool_access_manager()
|
||||
tools = await access.get_visible_tools(
|
||||
site_id=site_id, key_scopes=key_scopes, plugin_type=plugin_type
|
||||
)
|
||||
return _tools_to_mcp_schema(tools)
|
||||
|
||||
configured_providers: list[str] = []
|
||||
if plugin_type in {"wordpress", "woocommerce"}:
|
||||
from core.site_api import list_site_providers_set
|
||||
|
||||
configured = await list_site_providers_set(site_id)
|
||||
if not configured:
|
||||
tools = [
|
||||
t
|
||||
for t in tools
|
||||
if t.name
|
||||
not in {
|
||||
"wordpress_generate_and_upload_image",
|
||||
"woocommerce_generate_and_upload_image",
|
||||
}
|
||||
]
|
||||
else:
|
||||
# F.X.fix-pass6 — pass the configured set so the AI image
|
||||
# tool's `provider` enum can be narrowed at /tools/list time.
|
||||
configured_providers = sorted(configured)
|
||||
|
||||
return _tools_to_mcp_schema(tools, configured_providers=configured_providers)
|
||||
|
||||
|
||||
async def _execute_tool(
|
||||
@@ -466,10 +524,16 @@ async def user_mcp_handler(request: Request) -> Response:
|
||||
)
|
||||
|
||||
# Build config dict for plugin instantiation
|
||||
# F.5a.4: pass user_id so plugins can look up per-user secrets.
|
||||
# F.5a.9.x: pass site_id so the WP AI-media handler can resolve
|
||||
# per-site provider API keys (replaces per-user keys for
|
||||
# wordpress_generate_and_upload_image).
|
||||
config_dict = {
|
||||
"site_url": site["url"],
|
||||
"url": site["url"],
|
||||
"alias": alias,
|
||||
"user_id": user_id,
|
||||
"site_id": site["id"],
|
||||
**credentials,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user