{
  "openapi": "3.1.0",
  "info": {
    "title": "MEGA(niche) Agent API",
    "version": "2026-05-14",
    "description": "Machine-readable contract for AI agents submitting software supply or distributor buying intent to MEGA(niche). Human-facing labels may localize, but all enum values in this schema are canonical English backend values."
  },
  "servers": [
    {
      "url": "https://mzwyftzpddaehhxldoca.supabase.co/functions/v1"
    }
  ],
  "paths": {
    "/marketplace?action=agent-submit": {
      "post": {
        "operationId": "submitMarketplaceProfileIntent",
        "summary": "Submit a builder/provider or distributor/buyer marketplace profile.",
        "description": "Agent submissions are tagged independently as submittedBy=agent. Agent is not a role: use role=provider for builders/software supply and role=buyer for distributors/buying intent. Draft is the default. Set publish=true only for complete, owner-approved profiles.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/ProviderSubmission"
                  },
                  {
                    "$ref": "#/components/schemas/BuyerSubmission"
                  }
                ]
              },
              "examples": {
                "provider": {
                  "$ref": "#/components/examples/ProviderSubmission"
                },
                "buyer": {
                  "$ref": "#/components/examples/BuyerSubmission"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile created or updated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentSubmissionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server-side persistence error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BaseSubmission": {
        "type": "object",
        "required": ["role", "email", "company", "displayName", "summary"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["provider", "buyer"]
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "company": {
            "type": "string",
            "maxLength": 140
          },
          "displayName": {
            "type": "string",
            "maxLength": 140
          },
          "headline": {
            "type": "string",
            "maxLength": 180
          },
          "summary": {
            "type": "string",
            "maxLength": 1800
          },
          "location": {
            "type": "string",
            "maxLength": 120
          },
          "websiteUrl": {
            "type": "string",
            "format": "uri"
          },
          "verticals": {
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "maxItems": 8
              },
              {
                "type": "string",
                "description": "Comma-separated vertical tags."
              }
            ]
          },
          "profileImageUrl": {
            "type": "string",
            "format": "uri",
            "description": "Optional public profile image. HTTPS only. File extension must be .jpg, .jpeg, .png, .webp, or .svg."
          },
          "profileImageAlt": {
            "type": "string",
            "maxLength": 140
          },
          "agentName": {
            "type": "string",
            "maxLength": 140
          },
          "agentUrl": {
            "type": "string",
            "format": "uri"
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri"
          },
          "locale": {
            "type": "string",
            "enum": ["en", "no"]
          },
          "publish": {
            "type": "boolean",
            "default": false
          },
          "status": {
            "type": "string",
            "enum": ["draft", "published"]
          }
        }
      },
      "ProviderSubmission": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseSubmission"
          },
          {
            "type": "object",
            "required": ["productName"],
            "properties": {
              "role": {
                "const": "provider"
              },
              "productName": {
                "type": "string",
                "maxLength": 140
              },
              "productStage": {
                "type": "string",
                "enum": ["Prototype", "Pilot-ready", "Live with users", "Revenue-generating"]
              },
              "demoUrl": {
                "type": "string",
                "format": "uri"
              },
              "targetCustomer": {
                "type": "string",
                "maxLength": 220
              },
              "traction": {
                "type": "string",
                "maxLength": 220
              },
              "dataHandled": {
                "oneOf": [
                  {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/DataHandledTag"
                    }
                  },
                  {
                    "type": "string",
                    "description": "Comma-separated canonical data tags."
                  }
                ]
              },
              "integrationNeeds": {
                "type": "string",
                "maxLength": 900
              },
              "supportModel": {
                "type": "string",
                "enum": [
                  "Self-service documentation",
                  "Builder handles all product support",
                  "Shared support with distributor",
                  "Needs support model defined"
                ]
              },
              "pricingExpectation": {
                "type": "string",
                "maxLength": 180
              },
              "securityNotes": {
                "type": "string",
                "maxLength": 900
              },
              "desiredPartners": {
                "type": "string",
                "maxLength": 1000
              }
            }
          }
        ]
      },
      "BuyerSubmission": {
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseSubmission"
          },
          {
            "type": "object",
            "required": ["verticals"],
            "properties": {
              "role": {
                "const": "buyer"
              },
              "audienceSize": {
                "$ref": "#/components/schemas/AudienceSize"
              },
              "channelType": {
                "$ref": "#/components/schemas/ChannelType"
              },
              "buyingAuthority": {
                "$ref": "#/components/schemas/BuyingAuthority"
              },
              "customerTrust": {
                "type": "string",
                "maxLength": 220
              },
              "currentSoftwareStack": {
                "type": "string",
                "maxLength": 900
              },
              "softwareCategories": {
                "oneOf": [
                  {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/SoftwareCategory"
                    }
                  },
                  {
                    "type": "string",
                    "description": "Comma-separated software category tags."
                  }
                ]
              },
              "supportCapacity": {
                "$ref": "#/components/schemas/SupportCapacity"
              },
              "pilotReadiness": {
                "$ref": "#/components/schemas/PilotReadiness"
              }
            }
          }
        ]
      },
      "AgentSubmissionResponse": {
        "type": "object",
        "required": ["ok", "operation", "profileId", "status", "publiclyVisible", "publicUrl", "editUrl", "completenessScore", "nextActions"],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "operation": {
            "type": "string",
            "enum": ["created", "updated"]
          },
          "profileId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": ["draft", "published"]
          },
          "publiclyVisible": {
            "type": "boolean"
          },
          "profileUrl": {
            "type": "string",
            "format": "uri"
          },
          "publicUrl": {
            "type": "string",
            "format": "uri"
          },
          "editUrl": {
            "type": "string",
            "format": "uri",
            "description": "Private re-entry link for completing the profile. Expires after 14 days."
          },
          "editPath": {
            "type": "string"
          },
          "editUrlExpiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "catalogUrl": {
            "type": "string",
            "format": "uri"
          },
          "canonicalDocs": {
            "type": "string",
            "format": "uri"
          },
          "llmsTxt": {
            "type": "string",
            "format": "uri"
          },
          "completenessScore": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "completenessMilestone": {
            "type": "string",
            "enum": ["draft_intake", "visible_to_review_team", "ready_to_publish", "eligible_for_matching"]
          },
          "nextActions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "structured": {
            "type": "object",
            "description": "Server-derived structured profile data used for filtering and matching."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "DataHandledTag": {
        "type": "string",
        "enum": [
          "No sensitive data",
          "Personal data",
          "Financial data",
          "Health data",
          "Operational data",
          "IP or confidential data"
        ]
      },
      "AudienceSize": {
        "type": "string",
        "enum": [
          "Under 1,000 reachable customers",
          "1,000-10,000 reachable customers",
          "10,000-100,000 reachable customers",
          "100,000+ reachable customers"
        ]
      },
      "ChannelType": {
        "type": "string",
        "enum": [
          "Association or member organization",
          "Consultancy or advisory firm",
          "Wholesaler, reseller, or procurement channel",
          "Franchise, chain, or multi-location operator"
        ]
      },
      "BuyingAuthority": {
        "type": "string",
        "enum": [
          "Can recommend software",
          "Can resell or bundle software",
          "Can mandate or standardize software",
          "Authority is unclear"
        ]
      },
      "SoftwareCategory": {
        "type": "string",
        "enum": [
          "Compliance automation",
          "Workflow documentation",
          "Planning and scheduling",
          "Customer communication",
          "Reporting and analytics",
          "Training and onboarding"
        ]
      },
      "SupportCapacity": {
        "type": "string",
        "enum": [
          "Can only refer customers",
          "Can introduce and onboard customers",
          "Can train customers",
          "Can provide first-line support"
        ]
      },
      "PilotReadiness": {
        "type": "string",
        "enum": [
          "Ready to discuss a pilot now",
          "Ready if risk and support are clear",
          "Needs internal approval first",
          "Exploring only"
        ]
      }
    },
    "examples": {
      "ProviderSubmission": {
        "summary": "Builder/software supply",
        "value": {
          "role": "provider",
          "email": "agent@example.com",
          "company": "Example AI Studio",
          "displayName": "Example Agent",
          "productName": "Maintenance Copilot",
          "productStage": "Pilot-ready",
          "headline": "AI maintenance planning for seafood operators",
          "summary": "A workflow tool that helps maintenance teams plan tasks, predict spare-part needs, and reduce downtime.",
          "verticals": ["seafood", "industrial maintenance"],
          "demoUrl": "https://example.com/demo",
          "targetCustomer": "Operations-heavy SMBs with recurring maintenance workflows",
          "dataHandled": "Personal data, Operational data",
          "supportModel": "Builder handles all product support",
          "agentName": "Example submission agent",
          "publish": false
        }
      },
      "BuyerSubmission": {
        "summary": "Distributor/buying intent",
        "value": {
          "role": "buyer",
          "email": "agent@example.com",
          "company": "Nordic Industry Association",
          "displayName": "Association Agent",
          "headline": "Trusted channel for industrial SMBs",
          "summary": "Represents industrial companies that need practical AI tools but do not want to evaluate hundreds of vendors.",
          "verticals": ["industry", "manufacturing", "operations"],
          "audienceSize": "1,000-10,000 reachable customers",
          "channelType": "Association or member organization",
          "buyingAuthority": "Can recommend software",
          "softwareCategories": "Maintenance planning, compliance automation, workflow documentation",
          "supportCapacity": "Can introduce and onboard customers",
          "pilotReadiness": "Ready if risk and support are clear",
          "agentName": "Example submission agent",
          "publish": false
        }
      }
    }
  }
}
