{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:agent.external-runtime.product:v1",
  "title": "Agent External Runtime Product v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema", "product/ref", "product/digest", "turn/ref", "passage/ref", "binding/ref",
    "agent/id", "kind", "parent-product/refs", "content/digest", "content/size-bytes",
    "retained", "output-schema/ref", "producer/snapshot", "budget/used", "visibility",
    "classification", "committed/at", "committed/by"
  ],
  "properties": {
    "schema": { "const": "agent.external-runtime.product.v1" },
    "product/ref": { "$ref": "#/$defs/ref" },
    "product/digest": { "$ref": "#/$defs/digest" },
    "turn/ref": { "$ref": "#/$defs/ref" },
    "passage/ref": { "$ref": "#/$defs/ref" },
    "binding/ref": { "$ref": "#/$defs/ref" },
    "agent/id": { "$ref": "#/$defs/ref" },
    "kind": { "enum": ["draft", "critique", "revision", "final"] },
    "parent-product/refs": { "type": "array", "maxItems": 8, "uniqueItems": true, "items": { "$ref": "#/$defs/ref" } },
    "content/digest": { "$ref": "#/$defs/digest" },
    "content/size-bytes": { "type": "integer", "minimum": 1, "maximum": 1048576 },
    "artifact/ref": { "$ref": "#/$defs/ref" },
    "retained": { "type": "boolean" },
    "output-schema/ref": { "$ref": "#/$defs/ref" },
    "producer/snapshot": { "$ref": "#/$defs/ref" },
    "budget/used": { "$ref": "#/$defs/usage-value" },
    "visibility": { "enum": ["private", "operator", "shared"] },
    "classification": { "$ref": "classification.v1.schema.json" },
    "committed/at": { "type": "string", "format": "date-time" },
    "committed/by": { "$ref": "#/$defs/ref" }
  },
  "allOf": [
    { "if": { "properties": { "retained": { "const": true } } }, "then": { "required": ["artifact/ref"] } },
    { "if": { "properties": { "retained": { "const": false } } }, "then": { "not": { "required": ["artifact/ref"] } } }
  ],
  "$defs": {
    "ref": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^[^\\s\\u0000-\\u001f\\u007f]+$" },
    "digest": { "type": "string", "pattern": "^sha256:[A-Za-z0-9_-]{43}$" },
    "usage-value": {
      "type": "object", "additionalProperties": false,
      "required": ["max_tokens", "max_cost_micros", "max_wall_time_ms", "max_steps"],
      "properties": {
        "max_tokens": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "max_cost_micros": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "max_wall_time_ms": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "max_steps": { "type": "integer", "minimum": 0, "maximum": 4294967295 }
      }
    }
  }
}
