{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://omni.local/contracts/event-envelope.schema.json",
  "title": "OMNI Event Envelope v1",
  "description": "Durable, replayable envelope shared by the conductor, Hermes bridge, media manager and UI event stream.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol_version",
    "type",
    "event_id",
    "seq",
    "timestamp",
    "session_id",
    "turn_id",
    "operation_id",
    "trace_id",
    "source",
    "payload"
  ],
  "properties": {
    "protocol_version": {
      "const": "1.0"
    },
    "type": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[a-z][a-z0-9_.-]*$"
    },
    "event_id": {
      "type": "string",
      "minLength": 5,
      "maxLength": 160,
      "pattern": "^evt_[A-Za-z0-9_-]+$"
    },
    "seq": {
      "type": "integer",
      "minimum": 1
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "session_id": {
      "$ref": "#/$defs/id"
    },
    "turn_id": {
      "$ref": "#/$defs/id"
    },
    "operation_id": {
      "$ref": "#/$defs/id"
    },
    "trace_id": {
      "$ref": "#/$defs/id"
    },
    "causation_id": {
      "oneOf": [
        {
          "$ref": "#/$defs/id"
        },
        {
          "type": "null"
        }
      ],
      "default": null
    },
    "source": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "pattern": "^[a-z][a-z0-9_.-]*$"
    },
    "payload": {
      "type": "object"
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
    }
  },
  "examples": [
    {
      "protocol_version": "1.0",
      "type": "operation.started",
      "event_id": "evt_01J00000000000000000000000",
      "seq": 17,
      "timestamp": "2026-08-23T18:00:00Z",
      "session_id": "session_demo",
      "turn_id": "turn_7",
      "operation_id": "op_9",
      "trace_id": "trace_9",
      "causation_id": "evt_01J0000000000000000000000A",
      "source": "hermes",
      "payload": {
        "kind": "computer_use"
      }
    }
  ]
}
