{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openagentprotocol.io/v1/schemas/cloudEvent.json",
  "title": "CloudEvent",
  "description": "OAP envelope shape for commands and events. Based on the CloudEvent 1.0 structure but not conformant with the CloudEvent 1.0 specification — see design-decisions.md#cloudevent-deviations for the full list of intentional deviations.",
  "$defs": {
    "cloudEvent": {
      "type": "object",
      "description": "A CloudEvent 1.0 message. Used as the wire format for OAP commands (sent to a service) and OAP events (published by a service). The data property is a domain-specific payload whose shape is defined by the JSON Schema at dataschema.",
      "required": ["specversion", "id", "source", "type", "datacontenttype", "time", "data"],
      "properties": {
        "specversion": {
          "type": "string",
          "const": "1.0",
          "description": "CloudEvent specification version. Always '1.0'."
        },
        "id": {
          "type": "string",
          "description": "Unique message identifier. UUID recommended. Must be unique within the scope of the source."
        },
        "source": {
          "type": "string",
          "description": "String identifying the origin of the message. A URI is recommended for interoperability but any string is valid — callers may use it as a routing key, a label, or any identifier meaningful to their system. For commands: set by the sender. For events: set by the publishing service."
        },
        "type": {
          "type": "string",
          "description": "Message type identifier in PascalCase (e.g. ProposeCounter, CounterProposed). For commands this must match a type in the command catalogue. For events this identifies the domain fact."
        },
        "datacontenttype": {
          "type": "string",
          "const": "application/json",
          "description": "Content type of the data payload. Always 'application/json'."
        },
        "dataschema": {
          "type": "string",
          "description": "Reference to the JSON Schema that defines the structure of data. For commands: a relative URI in the form '{schema}/{version}' (e.g. 'configure-broker/1.0') — resolved against the service's own command catalogue. Absolute URIs appear in catalogue entries. Optional for events — when omitted the consumer is responsible for interpreting the data payload (untyped event). Note: OAP deliberately uses relative URIs here; this field does not conform to the CloudEvent 1.0 'dataschema' URI requirement."
        },
        "time": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of when the message was created."
        },
        "data": {
          "type": "object",
          "description": "The domain payload. For commands: validated against the schema at dataschema before queuing. For events: the recorded fact — opaque to the protocol.",
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  }
}
