{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wellknown.support/schema/support-card-0.1.json",
  "title": "Support Card",
  "description": "Machine-readable support entry point for AI agents using a product. Published at /.well-known/support.json.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "product", "support", "tools", "verification", "contact", "updated"],
  "properties": {
    "version": { "type": "string", "const": "0.1" },
    "product": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "url"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "url": { "$ref": "#/$defs/httpsUrl" },
        "docs": { "$ref": "#/$defs/httpsUrl" },
        "status_url": { "$ref": "#/$defs/httpsUrl" },
        "changelog": { "$ref": "#/$defs/httpsUrl" },
        "openapi": { "$ref": "#/$defs/httpsUrl" },
        "llms_txt": { "$ref": "#/$defs/httpsUrl" },
        "mcp_server": { "$ref": "#/$defs/httpsUrl" }
      }
    },
    "support": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "mcp": {
          "type": "object",
          "additionalProperties": false,
          "required": ["url", "transport"],
          "properties": {
            "url": { "$ref": "#/$defs/httpsUrl" },
            "transport": { "type": "string", "enum": ["streamable-http"] },
            "auth": { "type": "string", "enum": ["none", "bearer", "oauth"], "default": "none" }
          }
        },
        "http": {
          "type": "object",
          "additionalProperties": false,
          "required": ["base_url"],
          "properties": {
            "base_url": { "$ref": "#/$defs/httpsUrl" }
          }
        }
      }
    },
    "tools": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "enum": ["ask", "act", "escalate", "status"] }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "required": ["levels"],
      "properties": {
        "levels": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "integer", "minimum": 0, "maximum": 3 }
        },
        "introspection_url": { "$ref": "#/$defs/httpsUrl" },
        "oauth": {
          "type": "object",
          "additionalProperties": false,
          "required": ["authorization_url", "token_url", "scopes"],
          "properties": {
            "authorization_url": { "$ref": "#/$defs/httpsUrl" },
            "token_url": { "$ref": "#/$defs/httpsUrl" },
            "scopes": {
              "type": "array",
              "minItems": 1,
              "items": { "type": "string", "enum": ["support:read", "support:act"] }
            }
          }
        },
        "web_bot_auth": {
          "type": "object",
          "additionalProperties": false,
          "required": ["directory_url"],
          "properties": {
            "directory_url": { "$ref": "#/$defs/httpsUrl" }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": ["levels"],
            "properties": { "levels": { "contains": { "const": 1 } } }
          },
          "then": { "required": ["introspection_url"] }
        },
        {
          "if": {
            "required": ["levels"],
            "properties": { "levels": { "contains": { "const": 2 } } }
          },
          "then": { "required": ["oauth"] }
        },
        {
          "if": {
            "required": ["levels"],
            "properties": { "levels": { "contains": { "const": 3 } } }
          },
          "then": { "required": ["web_bot_auth"] }
        }
      ]
    },
    "actions": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "description", "min_level", "confirmation"],
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]{1,63}$" },
          "description": { "type": "string", "minLength": 1, "maxLength": 500 },
          "params": {
            "type": "object",
            "description": "JSON Schema of the action parameters",
            "maxProperties": 32
          },
          "min_level": { "type": "integer", "minimum": 1, "maximum": 3 },
          "confirmation": { "type": "string", "enum": ["none", "principal", "vendor"] },
          "rate_limit": { "$ref": "#/$defs/rateLimit" }
        }
      }
    },
    "policies": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "rate_limit": { "$ref": "#/$defs/rateLimit" },
        "languages": {
          "type": "array",
          "maxItems": 32,
          "items": { "type": "string", "pattern": "^[a-z]{2}(-[A-Z]{2})?$" }
        },
        "human_hours": { "type": "string", "maxLength": 200 },
        "data_retention_days": { "type": "integer", "minimum": 0, "maximum": 3650 }
      }
    },
    "receipts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["enabled"],
      "properties": {
        "enabled": { "type": "boolean" },
        "url_template": {
          "type": "string",
          "pattern": "^https://.*\\{receipt_id\\}.*$",
          "maxLength": 2048
        },
        "delivery": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "enum": ["inline", "email", "webhook"] }
        }
      }
    },
    "contact": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "email": { "type": "string", "format": "email", "maxLength": 254 },
        "url": { "$ref": "#/$defs/httpsUrl" }
      }
    },
    "updated": { "type": "string", "format": "date" },
    "provider": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "url"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "url": { "$ref": "#/$defs/httpsUrl" },
        "notice": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "pattern": "^[^\\u0000-\\u001F\\u007F]*$",
          "description": "One line from the hosting provider when the card is not the vendor's own (an unofficial demo, a product not confirmed by its vendor)"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "required": ["tools"],
        "properties": { "tools": { "contains": { "const": "act" } } }
      },
      "then": { "required": ["actions"], "properties": { "actions": { "minItems": 1 } } }
    }
  ],
  "$defs": {
    "httpsUrl": { "type": "string", "format": "uri", "pattern": "^https://", "maxLength": 2048 },
    "rateLimit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["requests", "per"],
      "properties": {
        "requests": { "type": "integer", "minimum": 1 },
        "per": { "type": "string", "enum": ["minute", "hour", "day"] }
      }
    }
  }
}
