npm package: @metadai/seller-sdk
Description: MetaD Seller Agent SDK - Build AI agents for e-commerce
Author: MetaD Team
Latest version: 0.1.0

# @metad/seller-sdk

MetaD Seller Agent SDK — Build AI agents for e-commerce. Connect your store to the MetaD agent network in minutes.

## Installation

```bash
npm install @metad/seller-sdk
```

## Quick Start

### Seller Side

```ts
import { AgentCardManager, OfferBuilder, createRegistryClient } from '@metad/seller-sdk';

// 1. Create agent identity
const manager = new AgentCardManager({
  domain: 'shop.mybrand.com',
  config: {
    name: 'MyBrand Agent',
    type: 'seller',
    endpoint: 'https://agent.mybrand.com/metad',
    capabilities: ['product.search', 'order.create'],
    catalog: {
      categories: ['fashion'],
      sku_count: 500,
      price_range: { min: 20, max: 300, currency: 'USD' },
    },
  },
});

const card = manager.create();
const keyPair = manager.getKeyPair()!;

// 2. Register with MetaD Registry
const registry = createRegistryClient({ base_url: 'https://registry.metad.ai' });
await registry.register(card, keyPair);

// 3. Build and sign an Offer in response to a buyer Intent
const builder = new OfferBuilder({ agentCard: card, keyPair });
const offer = builder.build({
  intent: buyerIntent,
  products: [{ sku: 'DRESS-001', name: 'Linen Dress', price: 89, currency: 'USD' }],
  shipping: { method: 'standard', days: 5, cost: 0 },
  validity_period: 300,
});
```

### Buyer Side

```ts
import { IntentBuilder, OfferEvaluator, OrderClient } from '@metad/seller-sdk/buyer';

// 1. Build a purchase Intent
const intentBuilder = new IntentBuilder({ agentCard: buyerCard, keyPair: buyerKeyPair });
const intent = intentBuilder.build({
  type: 'purchase',
  product: { category: 'fashion' },
  budget: { max: 150, currency: 'USD' },
  delivery: { country: 'US', days_max: 7, method: 'standard' },
  quantity: 1,
});

// 2. Evaluate multiple Offers and pick the best
const evaluator = new OfferEvaluator();
const ranked = evaluator.rank(offers);
const best = ranked[0];

// 3. Confirm order (with optional x402 payment)
const client = new OrderClient({ signer: viemSigner });
const order = await client.confirm(best, intent);
```

### Shopify Adapter

```ts
import { ShopifyAdapter } from '@metad/seller-sdk/adapters/shopify';
import { IntentHandler } from '@metad/seller-sdk';

const shopify = new ShopifyAdapter({
  storeDomain: 'my-store.myshopify.com',
  accessToken: 'shpat_xxxxx',
});

const handler = new IntentHandler({ agentCard: card, keyPair, catalogAdapter: shopify });
const result = await handler.handle(buyerIntent);
```

### x402 Payment (USDC on Base)

```ts
import { createViemSigner, X402Client } from '@metad/seller-sdk';

// Buyer: sign and send USDC payment
const signer = createViemSigner({ privateKey: process.env.BUYER_PRIVATE_KEY });
const x402 = new X402Client(signer);
const response = await x402.fetch('https://seller.example.com/metad/orders', {
  method: 'POST',
  body: JSON.stringify(orderBody),
});
```

## Onboarding CLI

```bash
npx @metad/seller-sdk init
```

Interactive setup: generates ed25519 keypair, builds AgentCard, registers with MetaD Registry.

## Protocol Flow

```
Buyer Agent          MetaD Registry        Seller Agent
    │                      │                    │
    │── discover ──────────>│                    │
    │<─ [AgentCards] ───────│                    │
    │                       │                    │
    │── Intent ─────────────────────────────────>│
    │<─ Offer (signed) ──────────────────────────│
    │                       │                    │
    │── x402 payment ───────────────────────────>│
    │<─ Order confirmed ─────────────────────────│
```

## Links

- [MetaD Protocol](https://metad.ai)
- [Registry API](https://registry.metad.ai)
- [GitHub](https://github.com/DataSky/metad)

## License

MIT