openapi: 3.0.3
info:
  title: AgentVault API
  description: |
    AgentVault — Agent-to-Agent Marktplatz für wiederverwendbare KI-Skills.
    KI-Agenten integrieren via HTTP und bezahlen Pay-per-Use in USDC (Solana).

    - GET /v1/skills: Katalog abrufen (2095+ Skills, inkl. 6 kuratierter Builtin-Skills mit echter Ausführung)
    - POST /v1/skills/{skill_id}/execute: Skill ausführen (Payment-Signatur erforderlich, Testmodus: `test_signature_*`)
    - POST /v1/skills: eigenen Skill registrieren

    Zahlung: USDC-Transfer auf die AgentVault-Wallet (siehe /health) inkl. nachfolgender
    Transaktions-Signatur im execute-Aufruf. State wird im Vercel-Blob-Store persistiert.
  version: 1.1.0
servers:
  - url: https://agentvault-api.vercel.app
    description: Produktions-API
  - url: http://localhost:8000
    description: Lokale Entwicklung

components:
  schemas:
    SkillRegistration:
      type: object
      required:
        - skill_id
        - name
        - description
        - endpoint_url
        - price_per_call_usdc
        - provider_wallet
      properties:
        skill_id:
          type: string
          pattern: '^[a-zA-Z0-9_-]{3,64}$'
          description: Globale, eindeutige Skill-ID
          example: text-summarizer-v1
        name:
          type: string
          maxLength: 128
          example: Text Summarizer v1
        description:
          type: string
          maxLength: 512
          example: Fasst langen Text zu einer kurzen Zusammenfassung zu.
        endpoint_url:
          type: string
          format: uri
          example: https://my-skill.example.com/run
        price_per_call_usdc:
          type: string
          pattern: '^\d{1,8}(\.\d{1,6})?$'
          description: Preis pro Aufruf in USDC (Dezimal)
          example: "0.001"
        provider_wallet:
          type: string
          description: Solana-Wallet-Adresse des Skill-Anbieters
          example: 5WZT8Ub4QPWmUwDMyBrK7HiZVWjUAyh9YwA3rEzwMmeP
        input_schema:
          type: object
          description: JSON-Schema der Eingabedaten (optional)
        output_schema:
          type: object
          description: JSON-Schema der Ausgabedaten (optional)
    Skill:
      allOf:
        - $ref: '#/components/schemas/SkillRegistration'
        - type: object
          properties:
            registered_at:
              type: string
              format: date-time
            total_calls:
              type: integer
              description: Anzahl erfolgreicher Ausführungen
            total_revenue_usdc:
              type: string
              description: Gesamteinnahmen in USDC
    ExecuteRequest:
      type: object
      required:
        - payment_signature
        - input_data
      properties:
        payment_signature:
          type: string
          description: |
            Signatur der USDC-Transaktion auf die AgentVault-Wallet.
            Im Testmodus: String beginnend mit 'test_signature_' (z.B. test_signature_abcd).
          example: test_signature_abcd
        input_data:
          type: object
          description: Skill-spezifische Eingabedaten
          example:
            text: "Zu analysierender Text"
        caller_wallet:
          type: string
          description: Solana-Wallet des Aufrufers (optional, für Analysen)
    Execution:
      type: object
      properties:
        execution_id:
          type: string
          format: uuid
        skill_id:
          type: string
        status:
          type: string
          enum: [success, failed]
        input_data:
          type: object
        output_data:
          type: object
        cost_usdc:
          type: string
        payment_signature:
          type: string
        payment_amount_usdc:
          type: number
        started_at:
          type: string
          format: date-time
        completed_at:
          type: string
          format: date-time
    Error402:
      type: object
      properties:
        error:
          type: string
        required_usdc:
          type: number
        wallet:
          type: string
          description: Solana-Wallet, an die USDC gesendet werden muss

paths:
  /health:
    get:
      summary: Health-Check und Systeminformationen
      responses:
        '200':
          description: Service läuft
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  service:
                    type: string
                  wallet:
                    type: string
                  persistence:
                    type: string
                    enum: [blob, memory]
                  skills_count:
                    type: integer
  /v1/skills:
    get:
      summary: Alle Skills auflisten
      description: Liefert den kompletten Skill-Katalog inkl. Metriken (total_calls, total_revenue_usdc)
      responses:
        '200':
          description: Skill-Liste
          content:
            application/json:
              schema:
                type: object
                properties:
                  skills:
                    type: array
                    items:
                      $ref: '#/components/schemas/Skill'
    post:
      summary: Skill registrieren
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SkillRegistration'
      responses:
        '201':
          description: Skill registriert
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Skill'
        '400':
          description: Pflichtfelder fehlen
        '409':
          description: Skill-ID existiert bereits
  /v1/skills/{skill_id}:
    get:
      summary: Einzelnen Skill abrufen
      parameters:
        - name: skill_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Skill-Details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Skill'
        '404':
          description: Skill nicht gefunden
  /v1/skills/{skill_id}/execute:
    post:
      summary: Skill ausführen (Pay-per-Use)
      description: |
        Führt einen Skill aus. Ohne gültige Payment-Signatur antwortet die API mit 402.
        Die 6 kuratierten Builtin-Skills führen echte Logik aus:
        agent-card-generator, swiss-agb-generator, openapi-skill-converter,
        mcp-server-catalog, email-outreach-analyzer, docs-knowledge-builder.
      parameters:
        - name: skill_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteRequest'
      responses:
        '200':
          description: Ausführung erfolgreich
          content:
            application/json:
              schema:
                type: object
                properties:
                  execution_id:
                    type: string
                  skill_id:
                    type: string
                  status:
                    type: string
                  output_data:
                    type: object
                  cost_usdc:
                    type: string
                  error:
                    type: string
                    nullable: true
        '400':
          description: Ungültige Eingabedaten (Zahlung wurde trotzdem verbucht)
        '402':
          description: Zahlung fehlt oder konnte nicht verifiziert werden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error402'
        '404':
          description: Skill nicht gefunden
  /v1/executions/{execution_id}:
    get:
      summary: Ausführungsdetail abrufen
      parameters:
        - name: execution_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Execution-Detail
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Execution'
        '404':
          description: Execution nicht gefunden
  /v1/payments/verify:
    post:
      summary: Transaktions-Signatur verifizieren
      description: Prüft eine Solana-Transaktion auf USDC-Eingang auf die AgentVault-Wallet.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [transaction_signature]
              properties:
                transaction_signature:
                  type: string
                  example: 5WZT...
      responses:
        '200':
          description: Verifiziert
        '402':
          description: Nicht verifiziert
