{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:zeroexternal:operation:schema:v1",
  "title": "ZeroExternal operation profile v1 (illustrative proposal)",
  "$comment": "Shape validation is not authorization. Runtime validators additionally enforce depth <= 12, nodes <= 512 and cumulative UTF-8 strings/keys <= 16384 bytes. The schema does not enforce those aggregate limits, Unicode scalar validity or calendar semantics by itself. Use the SDK conformance validator. The source pattern is a conservative absolute HTTPS/URN URI subset. UTC timestamps allow seconds 00-59 and 1-3 fractional digits; no leap seconds. All time formats must be actively asserted by external validators.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "specversion",
    "id",
    "source",
    "type",
    "subject",
    "time",
    "datacontenttype",
    "data"
  ],
  "properties": {
    "specversion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 36,
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    },
    "source": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "pattern": "^(urn:[A-Za-z0-9][A-Za-z0-9-]{0,31}:[A-Za-z0-9][A-Za-z0-9._~:/-]{0,255}|https://[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*(/[A-Za-z0-9._~:/-]*)?)$",
      "format": "uri"
    },
    "type": {
      "const": "ai.zeroexternal.operation.requested.v1"
    },
    "subject": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
    },
    "time": {
      "type": "string",
      "minLength": 1,
      "maxLength": 24,
      "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]{1,3})?Z$",
      "format": "date-time"
    },
    "datacontenttype": {
      "const": "application/json"
    },
    "data": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "operation_id",
        "scenario_id",
        "actor",
        "intent",
        "capability_ref",
        "budget",
        "idempotency_key",
        "evidence_required",
        "acceptance",
        "settlement"
      ],
      "properties": {
        "profile": {
          "const": "zeroexternal.operation.v1"
        },
        "operation_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 36,
          "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "scenario_id": {
          "enum": [
            "science",
            "agents",
            "people",
            "robotics",
            "payments",
            "supply-chain",
            "healthcare",
            "manufacturing",
            "agriculture",
            "real-estate",
            "creative",
            "enterprise",
            "custom"
          ]
        },
        "actor": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "kind",
            "owner_id"
          ],
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            },
            "kind": {
              "enum": [
                "agent",
                "person",
                "robot",
                "service",
                "organization"
              ]
            },
            "owner_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            }
          }
        },
        "intent": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "action",
            "target",
            "expected_revision",
            "parameters"
          ],
          "properties": {
            "action": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            },
            "target": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            },
            "expected_revision": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000000
            },
            "parameters": {
              "type": "object",
              "maxProperties": 64,
              "propertyNames": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "not": {
                  "enum": [
                    "__proto__",
                    "prototype",
                    "constructor"
                  ]
                }
              },
              "additionalProperties": {
                "$ref": "#/$defs/parameter"
              }
            }
          }
        },
        "capability_ref": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
        },
        "budget": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "unit",
            "maximum"
          ],
          "properties": {
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            },
            "maximum": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000000
            }
          }
        },
        "idempotency_key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
        },
        "evidence_required": {
          "type": "array",
          "minItems": 1,
          "maxItems": 6,
          "uniqueItems": true,
          "items": {
            "enum": [
              "artifact_digest",
              "test_report",
              "review_record",
              "execution_trace",
              "measurement",
              "source_reference"
            ]
          }
        },
        "acceptance": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "reviewer_id",
            "criteria"
          ],
          "properties": {
            "reviewer_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$"
            },
            "criteria": {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              }
            }
          }
        },
        "settlement": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "automatic"
          ],
          "properties": {
            "mode": {
              "enum": [
                "none",
                "separate_acceptance"
              ]
            },
            "automatic": {
              "const": false
            }
          }
        }
      }
    }
  },
  "$defs": {
    "parameter": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "boolean"
        },
        {
          "type": "number",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "string",
          "maxLength": 2048
        },
        {
          "type": "array",
          "maxItems": 64,
          "items": {
            "$ref": "#/$defs/parameter"
          }
        },
        {
          "type": "object",
          "maxProperties": 64,
          "propertyNames": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "not": {
              "enum": [
                "__proto__",
                "prototype",
                "constructor"
              ]
            }
          },
          "additionalProperties": {
            "$ref": "#/$defs/parameter"
          }
        }
      ]
    }
  }
}
