{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pipelinexlab.com/contracts/pxflow-direct.v2.schema.json",
  "title": "PipelineXLab PXFLOW direct document v2",
  "description": "Flow v1 calculation graph with versioned host result viewers. V1 documents remain unchanged.",
  "$comment": "The existing v1 definitions remain authoritative for calculation nodes, ports, and types. Viewers only reference public result keys and never execute.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "flowKey",
    "label",
    "description",
    "inputs",
    "results",
    "nodes",
    "groups",
    "externalSubflows",
    "presentation",
    "dependencies",
    "authoring"
  ],
  "properties": {
    "schemaVersion": {
      "const": 2
    },
    "flowKey": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/flowKey"
    },
    "label": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/label"
    },
    "description": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/description"
    },
    "typeDefinitions": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/typeDefinitions"
    },
    "inputs": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/inputs"
    },
    "results": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/results"
    },
    "nodes": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/nodes"
    },
    "groups": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/groups"
    },
    "externalSubflows": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/externalSubflows"
    },
    "presentation": {
      "$ref": "#/$defs/presentation"
    },
    "dependencies": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/dependencies"
    },
    "authoring": {
      "$ref": "pxflow-direct.v1.schema.json#/properties/authoring"
    }
  },
  "$defs": {
    "presentation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "viewers"
      ],
      "properties": {
        "nodes": {
          "$ref": "pxflow-direct.v1.schema.json#/$defs/presentation/properties/nodes"
        },
        "viewers": {
          "type": "object",
          "maxProperties": 100000,
          "propertyNames": {
            "$ref": "pxflow-direct.v1.schema.json#/$defs/semanticKey"
          },
          "additionalProperties": {
            "$ref": "#/$defs/resultViewer"
          }
        }
      }
    },
    "resultViewer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "renderer",
        "results",
        "position"
      ],
      "properties": {
        "renderer": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "key",
            "version"
          ],
          "properties": {
            "key": {
              "const": "core.result"
            },
            "version": {
              "const": 1
            }
          }
        },
        "results": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100000,
          "uniqueItems": true,
          "items": {
            "$ref": "pxflow-direct.v1.schema.json#/$defs/semanticKey"
          }
        },
        "position": {
          "$ref": "pxflow-direct.v1.schema.json#/$defs/nodePosition"
        }
      }
    }
  }
}
