SDK INSTALLATION

    Install the xBPP SDK and start evaluating agent transactions.

    v0.1.0-beta.1 - The SDK implements core policy checks (spending limits, rate limiting, recipient controls, pattern detection). Advanced features defined in the spec (9-phase pipeline, two-phase commit, chain rules) are on the roadmap.

    INSTALL

    terminal
    npm install @vanar/xbpp

    The package ships both CommonJS and ESM builds with full TypeScript type definitions.

    Zero runtime dependencies.

    QUICK START

    agent.ts
    import { evaluate, balanced } from '@vanar/xbpp'
    
    // Evaluate a payment request against a policy
    const verdict = evaluate(
      { amount: 50, currency: 'USDC', recipient: 'api.openai.com' },
      balanced
    )
    
    console.log(verdict.decision)  // 'ALLOW'
    console.log(verdict.reasons)   // []
    console.log(verdict.message)   // 'Payment approved'

    WITH X402 INTEGRATION

    Wrap any fetch-compatible HTTP client to automatically evaluate payments before they execute.

    x402-agent.ts
    import { wrap, balanced } from '@vanar/xbpp'
    
    // Wrap fetch with xBPP policy guard
    const safeFetch = wrap(fetch, balanced)
    
    // Free endpoints pass through (zero overhead)
    const data = await safeFetch('https://api.example.com/data')
    
    // Payment endpoints are evaluated before execution
    try {
      await safeFetch('https://api.example.com/premium', {
        headers: { 'x-payment-amount': '500', 'x-payment-currency': 'USDC' }
      })
    } catch (err) {
      if (err.name === 'EscalateError') {
        // Amount exceeds escalation threshold - ask human
        const approved = await askHuman(err.verdict)
        if (approved) await err.onApprove()
      }
    }

    WHAT'S INCLUDED

    evaluate()

    Core evaluation function - checks request against policy

    wrap()

    Fetch wrapper for x402 payment interception

    3 policy presets

    Aggressive, Balanced, Risk-Averse - ready to use

    12 policy checks

    Limits, rate limiting, recipients, patterns, temporal

    Error classes

    BlockedError and EscalateError with verdict context

    Full TypeScript

    Complete type definitions for Policy, Verdict, Decision