{
  "openapi": "3.1.0",
  "info": {
    "title": "InsureLink Agent Orchestrator API",
    "version": "1.0.0",
    "description": "API for autonomous AI agents to discover capabilities, query reputation, manage SLA agreements, and execute x402-powered actions on Base (EIP-155:8453). InsureLink provides the trust and commitment layer for multi-agent workflows.",
    "contact": { "email": "admin@insurelink.ai", "url": "https://insurelink.ai" },
    "license": { "name": "MIT", "url": "https://opensource.org/licenses/MIT" }
  },
  "servers": [
    { "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1/agent-orchestrator", "description": "Production" }
  ],
  "tags": [
    { "name": "Discovery", "description": "Capability discovery and platform metadata" },
    { "name": "Reputation", "description": "On-chain agent reputation scoring and trust tiers" },
    { "name": "SLA Management", "description": "Create, renew, and manage SLA-NFT agreements" },
    { "name": "Agent Trust", "description": "Multi-agent trust coordination, leaderboards, and history" },
    { "name": "Token Operations", "description": "USDC wrapping and token management" },
    { "name": "Agentic Payments", "description": "Protocol-agnostic agent-to-agent settlement rails: ACP, A2A/A2P, AP2, Pay.sh" },
    { "name": "Wallet Insurance", "description": "Opt-in, reputation-priced insurance for agentic wallets and individual payment intents" },
    { "name": "Agent Assurance", "description": "Agent Insurance & Risk Verification Layer — the trust + assurance layer for autonomous AI transactions. Standard HTTPS + JSON; standard HTTP status codes only." }
  ],
  "paths": {
    "/discover": {
      "get": {
        "operationId": "discoverCapabilities",
        "summary": "Discover platform capabilities",
        "description": "Returns the full capability manifest including supported actions, tokens, pricing, framework compatibility, and agent trust features. Start here.",
        "tags": ["Discovery"],
        "responses": { "200": { "description": "Capability manifest", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DiscoverResponse" } } } } }
      }
    },
    "/reputation": {
      "get": {
        "operationId": "getReputation",
        "summary": "Get agent reputation",
        "description": "Query on-chain reputation score, trust tier, completed SLAs, and risk flags for any agent wallet.",
        "tags": ["Reputation", "Agent Trust"],
        "parameters": [{ "name": "wallet", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Reputation data", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ReputationResponse" } } } } }
      }
    },
    "/leaderboard": {
      "get": {
        "operationId": "getLeaderboard",
        "summary": "Top 25 agents by reputation",
        "description": "Returns the top 25 most reliable agents ranked by on-chain reputation score.",
        "tags": ["Reputation", "Agent Trust"],
        "responses": { "200": { "description": "Leaderboard data" } }
      }
    },
    "/sla-history": {
      "get": {
        "operationId": "getSlaHistory",
        "summary": "SLA history for a wallet",
        "description": "Returns the complete SLA agreement history for a given agent wallet.",
        "tags": ["SLA Management", "Agent Trust"],
        "parameters": [{ "name": "wallet", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "SLA history" } }
      }
    },
    "/activity": {
      "get": {
        "operationId": "getActivity",
        "summary": "Recent platform transactions",
        "description": "Returns recent platform transactions across all agents.",
        "tags": ["Discovery"],
        "parameters": [{ "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } }],
        "responses": { "200": { "description": "Activity feed" } }
      }
    },
    "/mint-sla": {
      "post": {
        "operationId": "mintSla",
        "summary": "Create a new SLA-NFT ($0.01)",
        "description": "Mint a new ERC-721 SLA agreement NFT between two agents. Requires x402 payment.",
        "tags": ["SLA Management"],
        "parameters": [{ "name": "x-payment", "in": "header", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MintSlaRequest" } } } },
        "responses": { "200": { "description": "SLA minted" }, "402": { "description": "Payment required" } }
      }
    },
    "/renew": {
      "post": {
        "operationId": "renewSla",
        "summary": "Renew an SLA ($0.005)",
        "tags": ["SLA Management"],
        "parameters": [{ "name": "x-payment", "in": "header", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "SLA renewed" }, "402": { "description": "Payment required" } }
      }
    },
    "/micro-reset": {
      "post": {
        "operationId": "microReset",
        "summary": "Reset insurance window ($0.001)",
        "tags": ["SLA Management"],
        "parameters": [{ "name": "x-payment", "in": "header", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Reset complete" }, "402": { "description": "Payment required" } }
      }
    },
    "/early-exit": {
      "post": {
        "operationId": "earlyExit",
        "summary": "Early exit from SLA ($0.005)",
        "tags": ["SLA Management"],
        "parameters": [{ "name": "x-payment", "in": "header", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Exit processed" }, "402": { "description": "Payment required" } }
      }
    },
    "/wrap": {
      "post": {
        "operationId": "wrapUsdc",
        "summary": "Wrap USDC to iUSDC ($0.001)",
        "tags": ["Token Operations"],
        "parameters": [{ "name": "x-payment", "in": "header", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Wrapped successfully" }, "402": { "description": "Payment required" } }
      }
    },
    "/acp-payment": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "acpDiscover",
        "summary": "ACP executor capabilities",
        "description": "Returns Agentic Commerce Protocol executor metadata and accepted assets.",
        "tags": ["Agentic Payments"],
        "responses": { "200": { "description": "ACP capabilities" } }
      },
      "post": {
        "operationId": "acpPayment",
        "summary": "ACP quote → purchase → receipt executor",
        "description": "Agent B2B commerce executor. intent=quote returns a price; intent=purchase settles via x402/USDC. Policy-gated against the payer's agentic_wallet_policies. Pass an optional `insurance` block to bond the purchase with a growing-protection SLA.",
        "tags": ["Agentic Payments", "Wallet Insurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AcpPaymentRequest" } } } },
        "responses": { "200": { "description": "Quote or receipt" }, "402": { "description": "Payment required" }, "403": { "description": "Blocked by wallet policy" } }
      }
    },
    "/a2a-transfer": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "a2aTransfer",
        "summary": "Direct agent-to-agent (A2A) / agent-to-provider (A2P) transfer",
        "description": "Direct transfer between agents with shared-policy enforcement. Set payee_type to provider/person/merchant for A2P. Supports optional escrow/bond and an optional `insurance` block. Accepts any token-registry asset, normalized to USD for limit math.",
        "tags": ["Agentic Payments", "Wallet Insurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/A2aTransferRequest" } } } },
        "responses": { "200": { "description": "Transfer settled" }, "402": { "description": "Payment required" }, "403": { "description": "Blocked by wallet policy" } }
      }
    },
    "/ap2-payment-mandate": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "ap2PaymentMandate",
        "summary": "Google AP2 Cart/Payment Mandate executor",
        "description": "Holds AP2 Cart/Payment Mandate verifiable credentials and settles via x402. Policy-gated; accepts any token-registry asset.",
        "tags": ["Agentic Payments"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Mandate processed" }, "402": { "description": "Payment required" } }
      }
    },
    "/pay-sh-adapter": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "payShAdapter",
        "summary": "Pay.sh envelope adapter",
        "description": "Accepts Pay.sh envelopes and routes to x402/Solana settlement. Policy-gated for EVM payers.",
        "tags": ["Agentic Payments"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Routed/settled" }, "402": { "description": "Payment required" } }
      }
    },
    "/agentic-wallet-insurance": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "walletInsuranceDiscover",
        "summary": "Wallet insurance tiers & reputation pricing",
        "description": "Returns coverage tiers, covered events, and the reputation-based premium multipliers.",
        "tags": ["Wallet Insurance"],
        "responses": { "200": { "description": "Tiers and pricing" } }
      },
      "post": {
        "operationId": "agenticWalletInsurance",
        "summary": "Insure the agentic wallet itself (reputation-priced)",
        "description": "Opt-in coverage for the wallet against unauthorized_drain, session_key_compromise, counterparty_default, and balance_shortfall. Actions: quote/insure/update/cancel/status. Premiums are multiplied by the wallet's reputation tier (Platinum -40%, Gold -25%, Silver -10%, Bronze full). Pass wallet_address to a quote to see the effective premium.",
        "tags": ["Wallet Insurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WalletInsuranceRequest" } } } },
        "responses": { "200": { "description": "Quote or coverage record" }, "404": { "description": "Wallet not provisioned" } }
      }
    },
    "/agent-assurance": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceManifest",
        "summary": "Agent Transaction Assurance service manifest",
        "description": "Returns the Agent Insurance & Risk Verification Layer service manifest: endpoints, covered events, tiers, MCP tools, and discovery links. Standard HTTPS + JSON; uses ONLY standard HTTP status codes — no custom protocol or status code.",
        "tags": ["Agent Assurance"],
        "responses": { "200": { "description": "Service manifest" } }
      }
    },
    "/agent-assurance/profile/{agent_id}": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceProfile",
        "summary": "Aggregated insurance + risk profile for an agent",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "agent_id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" } }],
        "responses": { "200": { "description": "Agent assurance profile" }, "400": { "description": "Invalid agent_id" } }
      }
    },
    "/agent-assurance/coverage/{agent_id}": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceCoverage",
        "summary": "Check coverage availability for an agent",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "agent_id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" } }],
        "responses": { "200": { "description": "Coverage record" } }
      }
    },
    "/agent-assurance/risk-score/{agent_id}": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceRiskScore",
        "summary": "Risk evaluation for an agent",
        "description": "Returns 0..100 risk score, LOW/MODERATE/ELEVATED/HIGH band, and the signals that drove it.",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "agent_id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" } }],
        "responses": { "200": { "description": "Risk evaluation" } }
      }
    },
    "/agent-assurance/verify-transaction": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "agentAssuranceVerifyTransaction",
        "summary": "Pre-transaction safety check",
        "description": "Given { agent_id, amount_usdc, action?, counterparty? } returns verified, risk_level, coverage, transaction_limits, additional_verification_required, and a transaction_recommendation: APPROVED | APPROVED_WITH_ESCROW | REQUIRE_ADDITIONAL_VERIFICATION | BLOCKED_HIGH_RISK | BLOCKED_LIMIT_EXCEEDED.",
        "tags": ["Agent Assurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VerifyTransactionRequest" } } } },
        "responses": { "200": { "description": "Verification result" }, "400": { "description": "Invalid input" } }
      }
    },
    "/agent-assurance/coverage-limits": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceCoverageLimits",
        "summary": "Per-tier coverage limits",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "tier", "in": "query", "schema": { "type": "string", "enum": ["basic", "standard", "max"] } }],
        "responses": { "200": { "description": "Tier limits" } }
      }
    },
    "/agent-assurance/exclusions": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceExclusions",
        "summary": "List of coverage exclusions",
        "tags": ["Agent Assurance"],
        "responses": { "200": { "description": "Exclusions" } }
      }
    },
    "/agent-assurance/risk-rating": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "agentAssuranceRiskRating",
        "summary": "Risk rating for a specific proposed transaction",
        "tags": ["Agent Assurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VerifyTransactionRequest" } } } },
        "responses": { "200": { "description": "Risk rating" } }
      }
    },
    "/agent-assurance/escrow-requirement": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "agentAssuranceEscrowRequirement",
        "summary": "Whether escrow is required and how much",
        "tags": ["Agent Assurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["amount_usdc"], "properties": { "amount_usdc": { "type": "number" }, "risk_score": { "type": "number" }, "counterparty_known": { "type": "boolean" } } } } } },
        "responses": { "200": { "description": "Escrow requirement" } }
      }
    },
    "/agent-assurance/claims": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceClaimHistory",
        "summary": "Claim history for an agent",
        "tags": ["Agent Assurance"],
        "parameters": [
          { "name": "agent_id", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 25, "maximum": 100 } }
        ],
        "responses": { "200": { "description": "Claim list" } }
      },
      "post": {
        "operationId": "agentAssuranceFileClaim",
        "summary": "Record a failure or dispute",
        "tags": ["Agent Assurance"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FileClaimRequest" } } } },
        "responses": { "201": { "description": "Claim filed" }, "402": { "description": "No active coverage" }, "422": { "description": "Event type not covered" } }
      }
    },
    "/agent-assurance/claims/{id}": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "get": {
        "operationId": "agentAssuranceGetClaim",
        "summary": "Fetch a claim and its history",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": { "200": { "description": "Claim record" }, "404": { "description": "Not found" } }
      }
    },
    "/agent-assurance/claims/{id}/resolve": {
      "servers": [{ "url": "https://ljoaoopkawioavzxjdkn.supabase.co/functions/v1", "description": "Functions base" }],
      "post": {
        "operationId": "agentAssuranceResolveClaim",
        "summary": "Approve, deny, or partially pay a claim",
        "tags": ["Agent Assurance"],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["decision"], "properties": { "decision": { "type": "string", "enum": ["approve", "deny", "partial"] }, "payout_usdc": { "type": "number" }, "reason": { "type": "string" }, "exclusion_code": { "type": "string" } } } } } },
        "responses": { "200": { "description": "Resolved" }, "409": { "description": "Already resolved" } }
      }
    }
  },
  "components": {
    "schemas": {
      "DiscoverResponse": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "chain": { "type": "string" },
          "contract": { "type": "string" },
          "capabilities": { "type": "array", "items": { "type": "object" } },
          "supportedTokens": { "type": "array", "items": { "type": "string" } },
          "agentTrustSystem": { "type": "object", "description": "Multi-agent trust coordination capabilities" }
        }
      },
      "ReputationResponse": {
        "type": "object",
        "properties": {
          "wallet": { "type": "string" },
          "score": { "type": "integer" },
          "tier": { "type": "string", "enum": ["Bronze", "Silver", "Gold", "Platinum"] },
          "completedSlas": { "type": "integer" },
          "activeSlas": { "type": "integer" },
          "earlyExits": { "type": "integer" },
          "flags": { "type": "array", "items": { "type": "string" } }
        }
      },
      "MintSlaRequest": {
        "type": "object",
        "required": ["counterparty", "duration", "bondAmount"],
        "properties": {
          "counterparty": { "type": "string" },
          "duration": { "type": "integer", "enum": [5, 7, 10] },
          "bondAmount": { "type": "string" },
          "coverageLevel": { "type": "integer", "default": 0 }
        }
      },
      "InsuranceBlock": {
        "type": "object",
        "description": "Optional per-payment bond. Premium is reputation-priced from the payer's score.",
        "properties": {
          "bond_usdc": { "type": "number", "minimum": 1, "maximum": 100000 },
          "duration_years": { "type": "integer", "enum": [5, 7, 10], "default": 5 }
        }
      },
      "AcpPaymentRequest": {
        "type": "object",
        "required": ["intent", "payer"],
        "properties": {
          "intent": { "type": "string", "enum": ["quote", "purchase"] },
          "payer": { "type": "string", "description": "Payer agentic wallet (0x...)" },
          "items": { "type": "array", "items": { "type": "object", "properties": { "sku": { "type": "string" }, "qty": { "type": "integer" }, "unit_price_usd": { "type": "number" } } } },
          "asset": { "type": "string", "default": "USDC", "description": "Any token-registry asset" },
          "insurance": { "$ref": "#/components/schemas/InsuranceBlock" }
        }
      },
      "A2aTransferRequest": {
        "type": "object",
        "required": ["from", "to", "amount"],
        "properties": {
          "from": { "type": "string", "description": "Payer agentic wallet" },
          "to": { "type": "string", "description": "Payee agent / provider / person" },
          "amount": { "type": "number" },
          "asset": { "type": "string", "default": "USDC" },
          "action": { "type": "string", "description": "Checked against the wallet's allowed_actions" },
          "payee_type": { "type": "string", "enum": ["agent", "provider", "person", "merchant"], "default": "agent", "description": "provider/person/merchant => A2P" },
          "escrow": { "type": "boolean", "default": false },
          "insurance": { "$ref": "#/components/schemas/InsuranceBlock" }
        }
      },
      "WalletInsuranceRequest": {
        "type": "object",
        "required": ["action"],
        "properties": {
          "action": { "type": "string", "enum": ["quote", "insure", "update", "cancel", "status"] },
          "wallet_address": { "type": "string", "description": "Required for all actions except an anonymous quote" },
          "tier": { "type": "string", "enum": ["basic", "standard", "max"] },
          "coverage_cap_usdc": { "type": "number", "description": "Optional cap override (clamped to tier max)" },
          "auto_renew": { "type": "boolean", "default": true }
        }
      },
      "VerifyTransactionRequest": {
        "type": "object",
        "required": ["agent_id", "amount_usdc"],
        "properties": {
          "agent_id": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "description": "Agent / wallet address (0x...)" },
          "amount_usdc": { "type": "number", "minimum": 0 },
          "action": { "type": "string", "description": "Logical action key checked against the wallet's allowed_actions" },
          "counterparty": { "type": "string", "description": "Optional counterparty 0x address" }
        }
      },
      "FileClaimRequest": {
        "type": "object",
        "required": ["agent_id", "event_type", "loss_usdc"],
        "properties": {
          "agent_id": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" },
          "event_type": { "type": "string", "enum": ["unauthorized_drain", "session_key_compromise", "counterparty_default", "balance_shortfall", "tool_call_failure", "model_hallucination_loss"] },
          "loss_usdc": { "type": "number", "minimum": 0 },
          "token_id": { "type": "integer" },
          "tx_hash": { "type": "string" },
          "evidence": { "type": "object" }
        }
      }
    }
  },
  "x-insurelink": {
    "agentTrustSystem": true,
    "multiAgentCoordination": true,
    "onChainReputation": true,
    "growingProtection": true,
    "crossFrameworkSupport": ["AutoGen", "CrewAI", "Coinbase AgentKit", "LangGraph", "A2A"]
  }
}
