{
    "$schema":  "https://json-schema.org/draft/2020-12/schema",
    "$id":  "https://uaix.org/schemas/uai-1-envelope.schema.json",
    "title":  "UAIX SPEC-01 Canonical Envelope v1",
    "description":  "Publication-envelope contract for portable evidence-bearing UAIX records, including payload, evidence, redaction, trust, signature status, verification, exceptions, and warnings. Uses the canonical UAI-1 transport envelope; UAIX records evidence and handoff boundaries but does not authorize execution.",
    "type":  "object",
    "additionalProperties":  false,
    "required":  [
                     "uai_version",
                     "profile",
                     "message_id",
                     "source",
                     "target",
                     "conversation",
                     "delivery",
                     "trust",
                     "body",
                     "provenance",
                     "integrity",
                     "extensions"
                 ],
    "properties":  {
                       "uai_version":  {
                                           "type":  "string",
                                           "const":  "1.0"
                                       },
                       "profile":  {
                                       "type":  "string",
                                       "const":  "uaix.spec-01.envelope.v1"
                                   },
                       "message_id":  {
                                          "type":  "string",
                                          "pattern":  "^msg_[a-z0-9][a-z0-9._-]{5,127}$"
                                      },
                       "source":  {
                                      "type":  "object",
                                      "additionalProperties":  true,
                                      "required":  [
                                                       "type",
                                                       "id",
                                                       "label",
                                                       "uri",
                                                       "role"
                                                   ],
                                      "properties":  {
                                                         "type":  {
                                                                      "type":  "string",
                                                                      "minLength":  1
                                                                  },
                                                         "id":  {
                                                                    "type":  "string",
                                                                    "minLength":  3
                                                                },
                                                         "label":  {
                                                                       "type":  "string",
                                                                       "minLength":  2
                                                                   },
                                                         "uri":  {
                                                                     "type":  "string",
                                                                     "format":  "uri"
                                                                 },
                                                         "role":  {
                                                                      "type":  "string",
                                                                      "minLength":  2
                                                                  },
                                                         "project":  {
                                                                         "type":  "string",
                                                                         "minLength":  1
                                                                     }
                                                     }
                                  },
                       "target":  {
                                      "type":  "object",
                                      "additionalProperties":  true,
                                      "required":  [
                                                       "type",
                                                       "id",
                                                       "label",
                                                       "uri",
                                                       "role"
                                                   ],
                                      "properties":  {
                                                         "type":  {
                                                                      "type":  "string",
                                                                      "minLength":  1
                                                                  },
                                                         "id":  {
                                                                    "type":  "string",
                                                                    "minLength":  3
                                                                },
                                                         "label":  {
                                                                       "type":  "string",
                                                                       "minLength":  2
                                                                   },
                                                         "uri":  {
                                                                     "type":  "string",
                                                                     "format":  "uri"
                                                                 },
                                                         "role":  {
                                                                      "type":  "string",
                                                                      "minLength":  2
                                                                  },
                                                         "project":  {
                                                                         "type":  "string",
                                                                         "minLength":  1
                                                                     }
                                                     }
                                  },
                       "conversation":  {
                                            "type":  "object",
                                            "additionalProperties":  true,
                                            "required":  [
                                                             "conversation_id",
                                                             "turn_id",
                                                             "correlation_id",
                                                             "sequence"
                                                         ],
                                            "properties":  {
                                                               "conversation_id":  {
                                                                                       "type":  "string",
                                                                                       "pattern":  "^conv_[a-z0-9][a-z0-9._-]{5,95}$"
                                                                                   },
                                                               "turn_id":  {
                                                                               "type":  "string",
                                                                               "pattern":  "^turn_[a-z0-9][a-z0-9._-]{2,63}$"
                                                                           },
                                                               "parent_message_id":  {
                                                                                         "type":  "string",
                                                                                         "minLength":  1
                                                                                     },
                                                               "correlation_id":  {
                                                                                      "type":  "string",
                                                                                      "pattern":  "^corr_[a-z0-9][a-z0-9._-]{8,95}$"
                                                                                  },
                                                               "traceparent":  {
                                                                                   "type":  "string",
                                                                                   "minLength":  1
                                                                               },
                                                               "sequence":  {
                                                                                "type":  "integer",
                                                                                "minimum":  1
                                                                            }
                                                           }
                                        },
                       "delivery":  {
                                        "type":  "object",
                                        "additionalProperties":  true,
                                        "required":  [
                                                         "mode",
                                                         "priority",
                                                         "expires_at",
                                                         "reply_requested",
                                                         "ack_required",
                                                         "idempotency_key",
                                                         "retry_count",
                                                         "sequence",
                                                         "lifecycle",
                                                         "timeout_ms",
                                                         "fallback_directive"
                                                     ],
                                        "properties":  {
                                                           "mode":  {
                                                                        "type":  "string",
                                                                        "enum":  [
                                                                                     "sync",
                                                                                     "async",
                                                                                     "event"
                                                                                 ]
                                                                    },
                                                           "priority":  {
                                                                            "type":  "string",
                                                                            "enum":  [
                                                                                         "routine",
                                                                                         "interactive",
                                                                                         "urgent"
                                                                                     ]
                                                                        },
                                                           "expires_at":  {
                                                                              "type":  "string",
                                                                              "format":  "date-time",
                                                                              "pattern":  "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                                                                          },
                                                           "reply_requested":  {
                                                                                   "type":  "boolean"
                                                                               },
                                                           "ack_required":  {
                                                                                "type":  "boolean"
                                                                            },
                                                           "idempotency_key":  {
                                                                                   "type":  "string",
                                                                                   "pattern":  "^idem_[a-z0-9][a-z0-9._-]{8,127}$"
                                                                               },
                                                           "retry_count":  {
                                                                               "type":  "integer",
                                                                               "minimum":  0
                                                                           },
                                                           "sequence":  {
                                                                            "type":  "integer",
                                                                            "minimum":  1
                                                                        },
                                                           "lifecycle":  {
                                                                             "type":  "string",
                                                                             "minLength":  1
                                                                         },
                                                           "timeout_ms":  {
                                                                              "type":  "integer",
                                                                              "minimum":  0
                                                                          },
                                                           "fallback_directive":  {
                                                                                      "type":  "string",
                                                                                      "minLength":  1
                                                                                  }
                                                       }
                                    },
                       "trust":  {
                                     "type":  "object",
                                     "additionalProperties":  true,
                                     "required":  [
                                                      "channel",
                                                      "auth_scheme",
                                                      "principal",
                                                      "signatureStatus",
                                                      "verification"
                                                  ],
                                     "properties":  {
                                                        "channel":  {
                                                                        "type":  "string",
                                                                        "enum":  [
                                                                                     "public-web",
                                                                                     "private-api",
                                                                                     "mtls",
                                                                                     "signed-envelope",
                                                                                     "credentialed"
                                                                                 ]
                                                                    },
                                                        "auth_scheme":  {
                                                                            "type":  "string",
                                                                            "minLength":  1
                                                                        },
                                                        "principal":  {
                                                                          "type":  "string",
                                                                          "minLength":  1
                                                                      },
                                                        "signatureStatus":  {
                                                                                "type":  "string",
                                                                                "enum":  [
                                                                                             "unsigned",
                                                                                             "not_applicable",
                                                                                             "reference-only-unsigned",
                                                                                             "signed-reference",
                                                                                             "verified",
                                                                                             "unknown",
                                                                                             "expired",
                                                                                             "revoked",
                                                                                             "disabled",
                                                                                             "untrusted"
                                                                                         ]
                                                                            },
                                                        "verification":  {
                                                                             "type":  "object",
                                                                             "additionalProperties":  true,
                                                                             "required":  [
                                                                                              "status",
                                                                                              "reason"
                                                                                          ],
                                                                             "properties":  {
                                                                                                "status":  {
                                                                                                               "type":  "string",
                                                                                                               "minLength":  1
                                                                                                           },
                                                                                                "reason":  {
                                                                                                               "type":  "string",
                                                                                                               "minLength":  1
                                                                                                           }
                                                                                            }
                                                                         }
                                                    }
                                 },
                       "body":  {
                                    "type":  "object",
                                    "additionalProperties":  false,
                                    "required":  [
                                                     "uaixVersion",
                                                     "spec",
                                                     "envelopeId",
                                                     "createdUtc",
                                                     "issuer",
                                                     "issuerDisplayName",
                                                     "issuerPublicUrl",
                                                     "issuerCapabilityLevel",
                                                     "audience",
                                                     "lifecycleState",
                                                     "trustPosture",
                                                     "payloadType",
                                                     "payloadSchema",
                                                     "payload",
                                                     "evidence",
                                                     "redactions",
                                                     "signature",
                                                     "signatureStatus",
                                                     "verification",
                                                     "exceptions",
                                                     "warnings",
                                                     "rules",
                                                     "supportBoundary",
                                                     "localPolicyWins"
                                                 ],
                                    "properties":  {
                                                       "uaixVersion":  {
                                                                           "type":  "string",
                                                                           "minLength":  1
                                                                       },
                                                       "spec":  {
                                                                    "type":  "string",
                                                                    "minLength":  1
                                                                },
                                                       "envelopeId":  {
                                                                          "type":  "string",
                                                                          "minLength":  1
                                                                      },
                                                       "createdUtc":  {
                                                                          "type":  "string",
                                                                          "format":  "date-time",
                                                                          "pattern":  "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                                                                      },
                                                       "issuer":  {
                                                                      "type":  "object",
                                                                      "additionalProperties":  true
                                                                  },
                                                       "issuerDisplayName":  {
                                                                                 "type":  "string",
                                                                                 "minLength":  1
                                                                             },
                                                       "issuerPublicUrl":  {
                                                                               "type":  "string",
                                                                               "minLength":  1
                                                                           },
                                                       "issuerCapabilityLevel":  {
                                                                                     "type":  "string",
                                                                                     "minLength":  1
                                                                                 },
                                                       "audience":  {
                                                                        "type":  "string",
                                                                        "minLength":  1
                                                                    },
                                                       "lifecycleState":  {
                                                                              "type":  "string",
                                                                              "minLength":  1
                                                                          },
                                                       "trustPosture":  {
                                                                            "type":  "string",
                                                                            "minLength":  1
                                                                        },
                                                       "payloadType":  {
                                                                           "type":  "string",
                                                                           "minLength":  1
                                                                       },
                                                       "payloadSchema":  {
                                                                             "type":  "object",
                                                                             "additionalProperties":  true
                                                                         },
                                                       "payload":  {
                                                                       "type":  "object",
                                                                       "additionalProperties":  true
                                                                   },
                                                       "evidence":  {
                                                                        "type":  "array",
                                                                        "items":  {

                                                                                  }
                                                                    },
                                                       "redactions":  {
                                                                          "type":  "array",
                                                                          "items":  {

                                                                                    }
                                                                      },
                                                       "signature":  {
                                                                         "type":  "object",
                                                                         "additionalProperties":  true
                                                                     },
                                                       "signatureStatus":  {
                                                                               "type":  "string",
                                                                               "minLength":  1
                                                                           },
                                                       "verification":  {
                                                                            "type":  "object",
                                                                            "additionalProperties":  true
                                                                        },
                                                       "exceptions":  {
                                                                          "type":  "array",
                                                                          "items":  {

                                                                                    }
                                                                      },
                                                       "warnings":  {
                                                                        "type":  "array",
                                                                        "items":  {

                                                                                  }
                                                                    },
                                                       "rules":  {
                                                                     "type":  "array",
                                                                     "items":  {

                                                                               }
                                                                 },
                                                       "supportBoundary":  {
                                                                               "type":  "string",
                                                                               "pattern":  "Agent runtimes execute"
                                                                           },
                                                       "localPolicyWins":  {
                                                                               "type":  "boolean"
                                                                           }
                                                   }
                                },
                       "provenance":  {
                                          "type":  "object",
                                          "additionalProperties":  true,
                                          "required":  [
                                                           "trace_id",
                                                           "issued_at",
                                                           "log_ref",
                                                           "agent_id",
                                                           "model_id",
                                                           "confidence",
                                                           "lineage"
                                                       ],
                                          "properties":  {
                                                             "trace_id":  {
                                                                              "type":  "string",
                                                                              "pattern":  "^trace_[a-z0-9][a-z0-9._-]{5,95}$"
                                                                          },
                                                             "issued_at":  {
                                                                               "type":  "string",
                                                                               "format":  "date-time",
                                                                               "pattern":  "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                                                                           },
                                                             "log_ref":  {
                                                                             "type":  "string",
                                                                             "minLength":  1
                                                                         },
                                                             "agent_id":  {
                                                                              "type":  "string",
                                                                              "minLength":  1
                                                                          },
                                                             "model_id":  {
                                                                              "type":  "string",
                                                                              "minLength":  1
                                                                          },
                                                             "confidence":  {
                                                                                "type":  "number",
                                                                                "minimum":  0,
                                                                                "maximum":  1
                                                                            },
                                                             "lineage":  {
                                                                             "type":  "array",
                                                                             "items":  {

                                                                                       }
                                                                         }
                                                         }
                                      },
                       "integrity":  {
                                         "type":  "object",
                                         "additionalProperties":  true,
                                         "required":  [
                                                          "version",
                                                          "algorithm",
                                                          "canonicalization",
                                                          "checksum"
                                                      ],
                                         "properties":  {
                                                            "version":  {
                                                                            "type":  "integer",
                                                                            "minimum":  1
                                                                        },
                                                            "algorithm":  {
                                                                              "type":  "string",
                                                                              "minLength":  1
                                                                          },
                                                            "canonicalization":  {
                                                                                     "type":  "string",
                                                                                     "minLength":  1
                                                                                 },
                                                            "checksum":  {
                                                                             "type":  "string",
                                                                             "minLength":  1
                                                                         }
                                                        }
                                     },
                       "extensions":  {
                                          "type":  "array",
                                          "items":  {
                                                        "type":  "object",
                                                        "additionalProperties":  true,
                                                        "required":  [
                                                                         "namespace",
                                                                         "purpose",
                                                                         "critical"
                                                                     ],
                                                        "properties":  {
                                                                           "namespace":  {
                                                                                             "type":  "string",
                                                                                             "minLength":  1
                                                                                         },
                                                                           "purpose":  {
                                                                                           "type":  "string",
                                                                                           "minLength":  1
                                                                                       },
                                                                           "critical":  {
                                                                                            "type":  "boolean"
                                                                                        }
                                                                       }
                                                    }
                                      }
                   }
}
