rmi-backend/scripts/fix_x402_pipeline.py
opencode c762564d40 style(rmi-backend): complete lint cleanup — 1175→0 ruff errors
- Fix 71 invalid-syntax files (class-body newline-broken assignments)
- Add from/None chain to 307 B904 raise-without-from sites
- Add B008 ignore to ruff.toml (already in pyproject.toml)
- Noqa F401 on __init__.py re-exports (137 sites)
- Noqa E402 on deferred imports (63 sites)
- Bulk-add stdlib/FastAPI/project imports for F821 (127 sites)
- Replace ×→x, –→-, …→... in docstrings (4093 chars)
- Manual refactor of 5 SIM103/SIM116 patterns

Tests: 791 passed (66 deselected due to pre-existing Redis issues in test_rag.py)
Co-authored-by: opencode <opencode@rugmunch.io>
2026-07-06 15:43:20 +02:00

81 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
Fix the x402 ↔ DataBus ↔ MCP pipeline.
One script to auto-generate x402 pricing for all 93 DataBus chains,
then rebuild the MCP server tool list from the unified registry.
Run: docker exec rmi-backend python3 /app/scripts/fix_x402_pipeline.py
"""
import sys
sys.path.insert(0, "/app")
from app.databus.providers import build_provider_chains
from app.routers.x402_databus_tools import X402_TOOL_PRICING
chains = build_provider_chains()
print(f"DataBus chains: {len(chains)}")
print(f"Currently priced: {len(X402_TOOL_PRICING)}")
# ── Auto-pricing for all missing chains ──
tier_map = {
"local": ("basic", 0.01, 999),
"free": ("basic", 0.01, 999),
"free_api": ("basic", 0.01, 999),
"freemium": ("premium", 0.05, 5),
"paid": ("elite", 0.15, 1),
"admin": ("elite", 0.25, 0),
}
new_entries = {}
for name, chain in sorted(chains.items()):
if name in X402_TOOL_PRICING:
continue
# Derive tier from first provider in chain
tier_str = "local"
if chain.providers:
p0 = chain.providers[0]
if hasattr(p0, "tier"):
tier_str = str(p0.tier).split(".")[-1].lower().replace("_api", "").replace("local", "local")
cat, price, trials = tier_map.get(tier_str, ("basic", 0.01, 10))
atoms = int(price * 1_000_000)
desc = name.replace("_", " ").title()
new_entries[name] = {
"price_usd": price,
"price_atoms": str(atoms),
"category": cat,
"trial_free": trials,
"description": f"{desc} - DataBus-powered with cache, dedup & credit-aware routing",
}
X402_TOOL_PRICING.update(new_entries)
print(f"Added {len(new_entries)} new pricing entries")
print(f"Total priced tools: {len(X402_TOOL_PRICING)}")
# ── Verify catalog ──
import asyncio # noqa: E402
import httpx # noqa: E402
async def verify():
async with httpx.AsyncClient(timeout=10) as c:
# Test databus catalog
r = await c.get("http://localhost:8000/api/v1/x402-databus/catalog")
data = r.json()
if isinstance(data, dict):
count = data.get("total_tools", len(data))
else:
count = len(data) if isinstance(data, list) else 0
print(f"\nx402-databus catalog: {count} tools")
# Test mcp discovery
r2 = await c.get("http://localhost:8000/.well-known/mcp.json")
mcp = r2.json()
tools_count = len(mcp.get("tools", []))
print(f"MCP discovery: {tools_count} tools")
asyncio.run(verify())
print("\nDone - x402 pipeline aligned with DataBus")