{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mere.run/contracts/graph-node-provider.v1.schema.json",
  "title": "mere.run Plugin Graph Node Provider v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["contract_version", "provider_id", "provider_version", "nodes"],
  "properties": {
    "contract_version": {"const": "mere.run/plugin-graph-provider.v1"},
    "provider_id": {"$ref": "#/$defs/provider_id"},
    "provider_version": {"$ref": "#/$defs/version"},
    "nodes": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/node"}
    }
  },
  "$defs": {
    "provider_id": {"type": "string", "pattern": "^mere-[a-z0-9-]+$"},
    "version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([.-][A-Za-z0-9.-]+)?$"},
    "id": {"type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$"},
    "node_kind": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}(\\.[a-z][a-z0-9-]{0,63})+$"},
    "value": {
      "anyOf": [
        {"type": "null"},
        {"type": "string"},
        {"type": "integer"},
        {"type": "number"},
        {"type": "boolean"},
        {"type": "array", "items": {"$ref": "#/$defs/value"}},
        {"type": "object", "additionalProperties": {"$ref": "#/$defs/value"}}
      ]
    },
    "port_type": {
      "enum": ["string", "integer", "number", "boolean", "enum", "json", "asset", "asset_directory", "asset_collection"]
    },
    "value_schema": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": {
        "type": {"enum": ["object", "array", "string", "integer", "number", "boolean", "enum", "json"]},
        "title": {"type": "string"},
        "description": {"type": "string"},
        "default": {"$ref": "#/$defs/value"},
        "values": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string"}},
        "properties": {"type": "object", "additionalProperties": {"$ref": "#/$defs/value_schema"}},
        "required": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/id"}},
        "items": {"$ref": "#/$defs/value_schema"},
        "additional_properties": {"$ref": "#/$defs/value_schema"},
        "minimum": {"type": "number"},
        "maximum": {"type": "number"},
        "step": {"type": "number", "exclusiveMinimum": 0},
        "multiline": {"type": "boolean"}
      }
    },
    "input": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "type", "required"],
      "properties": {
        "name": {"$ref": "#/$defs/id"},
        "type": {"$ref": "#/$defs/port_type"},
        "required": {"type": "boolean"},
        "description": {"type": "string"},
        "default": {"$ref": "#/$defs/value"},
        "values": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string"}},
        "content_types": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "minimum": {"type": "number"},
        "maximum": {"type": "number"},
        "step": {"type": "number", "exclusiveMinimum": 0},
        "multiline": {"type": "boolean"},
        "secret": {"type": "boolean"},
        "advanced": {"type": "boolean"},
        "value_schema": {"$ref": "#/$defs/value_schema"}
      }
    },
    "output": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "type", "optional"],
      "properties": {
        "name": {"$ref": "#/$defs/id"},
        "type": {"$ref": "#/$defs/port_type"},
        "optional": {"type": "boolean"},
        "description": {"type": "string"},
        "content_types": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}}
      }
    },
    "requirements": {
      "type": "object",
      "additionalProperties": false,
      "required": ["model_ids", "accelerator_backends"],
      "properties": {
        "model_ids": {"type": "array", "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "accelerator_backends": {"type": "array", "uniqueItems": true, "items": {"enum": ["metal", "cuda", "rocm", "cpu"]}},
        "minimum_accelerator_memory_bytes": {"type": ["integer", "null"], "minimum": 0},
        "minimum_system_memory_bytes": {"type": ["integer", "null"], "minimum": 0},
        "minimum_disk_bytes": {"type": ["integer", "null"], "minimum": 0},
        "minimum_cpu_cores": {"type": ["integer", "null"], "minimum": 1},
        "network_access": {"type": ["boolean", "null"]}
      }
    },
    "traits": {
      "type": "object",
      "additionalProperties": false,
      "required": ["deterministic", "cacheable", "side_effects", "supports_progress", "supports_previews"],
      "properties": {
        "deterministic": {"type": "boolean"},
        "cacheable": {"type": "boolean"},
        "side_effects": {"enum": ["none", "local", "external"]},
        "supports_progress": {"type": "boolean"},
        "supports_previews": {"type": "boolean"}
      }
    },
    "presentation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["style"],
      "properties": {
        "style": {"const": "material"},
        "primary_argument": {"$ref": "#/$defs/id"}
      }
    },
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "title", "description", "category", "inputs", "outputs", "requirements", "traits"],
      "properties": {
        "kind": {"$ref": "#/$defs/node_kind"},
        "title": {"type": "string", "minLength": 1},
        "description": {"type": "string", "minLength": 1},
        "category": {"type": "string", "minLength": 1},
        "inputs": {"type": "array", "items": {"$ref": "#/$defs/input"}},
        "outputs": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/output"}},
        "requirements": {"$ref": "#/$defs/requirements"},
        "traits": {"$ref": "#/$defs/traits"},
        "presentation": {"$ref": "#/$defs/presentation"}
      }
    }
  }
}
