Skip to content

Agentic payments demo + swap visualization + installable PWA#131

Open
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/switchboard-agentic-demo-pwa
Open

Agentic payments demo + swap visualization + installable PWA#131
Pattermesh wants to merge 1 commit into
mainfrom
pattermesh/switchboard-agentic-demo-pwa

Conversation

@Pattermesh

Copy link
Copy Markdown
Collaborator

Makes SWITCHBOARD demo-ready for agentic payments, adds a focused UI visualization, and ships an installable PWA with a plugin proposal. All additive; the existing lab and tests are untouched.

(1) Agentic payments demo — examples/agentic_demo/

A runnable scenario where Agent A pays Agent B for work via the x402 middleware + on-chain escrow, then Agent B routes the received token through SafeSwap.

Flow: 402 offer -> validate (cap/allowlist/gas budget) -> lock in escrow -> deliver -> confirm/release -> SafeSwap quote -> execute.

  • Drives the real switchboard.x402_middleware.X402Middleware + switchboard.gas_tracker.GasTracker against an in-memory chain (MockChain / MockPaymentClient) that implements the PaymentClient + AgentEscrow surface — so it runs node/RPC-free.
  • safeswap.py is a SafeSwapClient against the orchestrator API (/v1/quote, /v1/execute) with an in-process MockSafeSwapOrchestrator. Point SafeSwapClient(base_url=...) at the live orchestrator for real routing.
  • Run it:
    PYTHONPATH=. python examples/agentic_demo/run.py
    PYTHONPATH=. python examples/agentic_demo/run.py --swap-to LUX --price 8 --json
  • tests/test_agentic_demo.py asserts the full flow: the 402 offer carries the escrow scheme + price, the escrow ends Released (not just Locked), funds move payer -> escrow -> payee, the SafeSwap orchestrator is genuinely called (quote then execute), and the swap routes.

Note: X402Middleware._validate_offer calls gas_tracker.can_send_transaction(wallet, amount) but the stdlib GasTracker takes a single arg and is a process singleton. The demo wraps it in a small BudgetGuard adapter (and reset_all()s the singleton) rather than changing shared middleware behavior — see scenario.py.

(2) UI — web/lab/swap.html

A new lab page that visualizes the A2A pay + swap demo: an animated canvas (payer / escrow / payee / SafeSwap nodes with in-flight packets), a step-by-step flow ledger, and live balances, with swap-into / job-price controls. Reuses the lab's shared.css / shared.js and the Luxury-Observatory aesthetic. Wired into the lab dashboard, sidebar, and _build.js. The strict agents-demo.html scene engine is not touched.

(3) PWA — web/manifest.json + web/sw.js + docs/PWA.md

  • Installable + offline-capable: manifest (standalone, icons any+maskable, shortcuts), service worker (app-shell precache, network-first navigations with offline fallback, stale-while-revalidate assets, cross-origin font cache).
  • Registration injected via shared.js (every lab page) and web/index.html (root, scope ./).
  • docs/PWA.md proposes the "switchboard plugin" PWA: install/consent flow, offline architecture, and how a host PWA embeds switchboard payments (402 interception -> budget-gated pay -> retry with proof, optional SafeSwap rebalance), reusing the same wire types as the Python library.
  • tests/test_pwa.py validates the manifest + icons + start_url/shortcut targets, that sw.js is valid JS precaching a real on-disk shell with an offline fallback, and that registration is wired into root + lab pages. swap.html JS is node --checked too.

Gate

PYTHONPATH=. python3 -m pytest -q
245 passed, 62 skipped, 6 subtests passed

(baseline was 223 passed; +22 new tests across the demo + PWA). swap.html and sw.js pass node --check.

🤖 Generated with Claude Code

DEMO-READY agentic payments + light UI + PWA proposal.

(1) examples/agentic_demo/ — runnable A2A scenario: Agent A pays Agent B for
    work via the x402 middleware + on-chain escrow (402 offer -> validate ->
    lock -> deliver -> confirm/release), then an AGENTIC SWAP step where B routes
    the received USDC through SafeSwap. Node/RPC-free: drives the real
    X402Middleware + GasTracker against an in-memory chain (MockChain /
    MockPaymentClient) and a mockable SafeSwap orchestrator. Runs with
    `python examples/agentic_demo/run.py` (+ --json, --swap-to, --price).
    tests/test_agentic_demo.py asserts the full flow: 402 -> pay -> settle
    (escrow Released) and the SafeSwap swap routes (quote -> execute).

(2) web/lab/swap.html — a focused lab page visualizing the A2A pay + swap demo:
    animated canvas (payer / escrow / payee / SafeSwap nodes + in-flight
    packets), a step-by-step flow ledger, and live balances. Reuses the lab's
    shared.css/shared.js; wired into the lab dashboard + sidebar + _build.js.
    Does not touch the strict agents-demo.html scene engine.

(3) PWA — web/manifest.json + web/sw.js make the lab installable + offline-
    capable (app-shell precache, network-first navigations w/ offline fallback,
    stale-while-revalidate assets). Registration injected via shared.js (lab)
    and web/index.html (root). docs/PWA.md proposes the "switchboard plugin"
    PWA: install/consent flow, offline architecture, and how a host PWA embeds
    switchboard payments (402 interception -> pay -> retry, budget-gated).
    tests/test_pwa.py validates manifest, icons, SW shell, and registration.

GATE: PYTHONPATH=. python3 -m pytest -q -> 245 passed, 62 skipped (was 223;
+22 new). swap.html + sw.js pass node --check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
"""Minimal transport SafeSwapClient drives. The real impl is HTTP; the test
impl is :class:`MockSafeSwapOrchestrator`."""

def post(self, path: str, body: dict) -> dict: ...
from __future__ import annotations

import hashlib
import time
import hashlib
import time
import uuid
from dataclasses import dataclass, field
@abhicris

Copy link
Copy Markdown
Contributor

🤖 Audit skipped — diff is 96KB (limit 64KB). Labelling for human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants