File size: 2,551 Bytes
6993919
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/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

import httpx


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")