"""Aegis client — the trusted agent-commerce hub, in ~3 lines. pip install httpx x402 eth-account from aegis_client import Aegis ag = Aegis(private_key="0x...") hits = ag.discover("live crypto prices") # free data = ag.route("crypto-data") # pay once, best verified service, failover Docs: https://aegis.borisinc.com/quickstart MCP: https://aegis-mcp.borisinc.com/mcp""" from __future__ import annotations import uuid, json, httpx from eth_account import Account from x402 import x402ClientSync from x402.http import x402HTTPClientSync, PaymentRoundTripper from x402.mechanisms.evm import EthAccountSigner from x402.mechanisms.evm.exact import ExactEvmScheme BASE="https://aegis.borisinc.com"; NETWORK="eip155:8453" class Aegis: def __init__(self, private_key=None, base=BASE, network=NETWORK): self.base=base.rstrip("/"); self._rt=None if private_key: c=x402ClientSync(); c.register(network, ExactEvmScheme(EthAccountSigner(Account.from_key(private_key)))) self._rt=PaymentRoundTripper(x402HTTPClientSync(c)) def discover(self, query="", category="", min_trust=0): return httpx.get(f"{self.base}/discover", params={"query":query,"category":category,"min_trust":min_trust}, timeout=30).json().get("results",[]) def _pay(self, method, path, **kw): if not self._rt: raise RuntimeError("Paid call — construct Aegis(private_key=...) with a funded Base wallet.") url=f"{self.base}{path}" with httpx.Client(timeout=120) as s: first=s.request(method,url,**kw) fin=self._rt.handle_response(str(uuid.uuid4()),first.status_code,dict(first.headers),first.content,lambda h:s.request(method,url,headers=h,**kw)) return json.loads(getattr(fin,"text",None) or fin.content.decode()) def smart_discover(self, query): return self._pay("GET","/discover/smart",params={"q":query}) def trust(self, url): return self._pay("GET","/trust",params={"url":url}) def route(self, target, **params): key="url" if target.startswith("http") else "capability" return self._pay("GET","/route",params={key:target,**params}) def route_batch(self, items): return self._pay("POST","/route/batch",json={"items":items}) def monitor(self, url, callback, days=30): return self._pay("POST","/monitor",json={"url":url,"callback":callback,"days":days})