{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:lap:schema:1.0:manifest",
  "title": "LAP manifest (/.well-known/lap.json)",
  "description": "Machine-readable description of a Provider's actions. See spec/PROTOCOL.md section 8.",
  "type": "object",
  "required": ["lap", "updated", "provider", "actions"],
  "properties": {
    "lap": { "type": "string", "pattern": "^1\\.[0-9]+$", "description": "Protocol version major.minor." },
    "updated": { "type": "string", "format": "date-time" },
    "provider": {
      "type": "object",
      "required": ["name", "url"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "url": { "type": "string" },
        "description": { "type": "string" },
        "locale": { "type": "string" },
        "timezone": { "type": "string" },
        "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "legal_name": { "type": "string" },
        "contact": { "type": "string" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },
    "docs": {
      "type": "object",
      "properties": {
        "llms_txt": { "type": "string" },
        "spec": { "type": "string" },
        "human": { "type": "string" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },
    "rules": { "type": "array", "items": { "type": "string", "minLength": 1 } },
    "profiles": { "type": "array", "items": { "$ref": "#/$defs/profile" } },
    "data": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "required": ["url"],
        "properties": {
          "url": { "type": "string" },
          "describes": { "type": "string" },
          "note": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "execute": {
      "type": "object",
      "required": ["endpoint", "algs"],
      "properties": {
        "endpoint": { "type": "string" },
        "algs": { "type": "array", "items": { "enum": ["EdDSA", "ES256"] }, "contains": { "const": "EdDSA" } }
      },
      "additionalProperties": false
    },
    "keys": {
      "type": "object",
      "required": ["jwks"],
      "properties": { "jwks": { "type": "string", "description": "URL of the provider's public keys (RFC 7517), used to verify signed receipts." } },
      "additionalProperties": false
    },
    "actions": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/action" } }
  },
  "patternProperties": { "^x-": {} },
  "additionalProperties": false,
  "allOf": [
    {
      "if": { "properties": { "actions": { "contains": { "properties": { "kind": { "const": "execute" } } } } } },
      "then": { "required": ["execute"] }
    },
    {
      "if": { "properties": { "actions": { "contains": { "properties": { "receipt": { "properties": { "signed": { "const": true } }, "required": ["signed"] } }, "required": ["receipt"] } } } },
      "then": { "required": ["keys"] }
    }
  ],
  "$defs": {
    "profile": { "type": "string", "pattern": "^(render|publish|device|x-[a-z0-9-]+)$" },
    "risk": { "enum": ["R0", "R1", "R2", "R3"] },
    "param": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "enum": ["string", "integer", "number", "boolean", "date", "time", "enum", "code", "list", "text"] },
        "required": { "type": "boolean" },
        "description": { "type": "string" },
        "enum": { "type": "array", "minItems": 1 },
        "default": {},
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "pattern": { "type": "string" },
        "format": { "type": "string" },
        "source": { "type": "string", "description": "Pointer into a data source, e.g. catalog#/products/*/code" },
        "trusted": { "type": "boolean", "default": true },
        "case_insensitive": { "type": "boolean" },
        "meaning": { "type": "object", "additionalProperties": { "type": "string" } }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false,
      "allOf": [
        { "if": { "properties": { "type": { "const": "enum" } } }, "then": { "required": ["enum"] } }
      ]
    },
    "fragment": {
      "type": "object",
      "properties": {
        "keys": { "type": "object", "additionalProperties": { "$ref": "#/$defs/param" } },
        "prefill": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "phone": { "type": "string" },
            "email": { "type": "string" },
            "address": { "type": "string" },
            "note": { "type": "string" }
          },
          "additionalProperties": false
        },
        "consent_required": { "type": "boolean" },
        "max_length": { "type": "integer", "minimum": 1 },
        "uploads": { "type": "string", "description": "Destination the page may send the payload to. Absent means the payload never leaves the browser." }
      },
      "additionalProperties": false
    },
    "action": {
      "type": "object",
      "required": ["id", "kind", "risk", "summary", "url_template", "params", "examples"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)+$" },
        "kind": { "enum": ["read", "render", "propose", "execute"] },
        "risk": { "$ref": "#/$defs/risk" },
        "profile": { "$ref": "#/$defs/profile" },
        "summary": { "type": "string", "minLength": 5 },
        "url_template": { "type": "string", "minLength": 1 },
        "params": { "type": "object", "additionalProperties": { "$ref": "#/$defs/param" } },
        "fragment": { "$ref": "#/$defs/fragment" },
        "resolve": {
          "type": "object",
          "properties": { "json": { "type": "boolean" } },
          "additionalProperties": false
        },
        "commit": {
          "type": "object",
          "required": ["consent"],
          "properties": {
            "consent": { "enum": ["interactive", "strong", "signed_or_interactive"] },
            "idempotency": { "type": "boolean" }
          },
          "additionalProperties": false
        },
        "receipt": {
          "type": "object",
          "required": ["url_template"],
          "properties": {
            "url_template": { "type": "string" },
            "json": { "type": "boolean" },
            "signed": { "type": "boolean", "description": "Receipts carry a JWS signature verifiable with keys.jwks (PROTOCOL 5.5)." }
          },
          "additionalProperties": false
        },
        "examples": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["utterance", "url"],
            "properties": { "utterance": { "type": "string" }, "url": { "type": "string" } },
            "additionalProperties": false
          }
        },
        "safety": { "type": "object" },
        "undo_seconds": { "type": "integer", "minimum": 0, "description": "Older shorthand for a cancel window on the receipt; prefer undo." },
        "undo": {
          "type": "object",
          "required": ["action"],
          "properties": {
            "action": { "type": "string", "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)+$", "description": "Id of the action in this manifest that reverses the effect (PROTOCOL 5.7)." },
            "within_seconds": { "type": "integer", "minimum": 1 }
          },
          "additionalProperties": false
        }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false,
      "allOf": [
        {
          "if": { "properties": { "kind": { "enum": ["propose", "execute"] } } },
          "then": { "required": ["commit", "receipt"] }
        },
        {
          "if": { "properties": { "kind": { "enum": ["read", "render"] } } },
          "then": { "properties": { "risk": { "const": "R0" } } }
        },
        {
          "if": { "properties": { "kind": { "const": "execute" } } },
          "then": {
            "properties": {
              "risk": { "enum": ["R0", "R1", "R2"] },
              "commit": { "properties": { "consent": { "const": "signed_or_interactive" } } }
            }
          }
        },
        {
          "if": { "properties": { "risk": { "const": "R3" } } },
          "then": { "properties": { "commit": { "properties": { "consent": { "const": "strong" } } } } }
        }
      ]
    }
  }
}
