{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:aiwu:schema:workflow:v1",
  "title": "AIWU Workflow v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "id", "name", "description", "nodes", "edges", "settings"],
  "properties": {
    "schema": {"const": "aiwu.workflow.v1"},
    "id": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$", "maxLength": 128},
    "name": {"type": "string", "maxLength": 200},
    "description": {"type": "string", "maxLength": 4000},
    "nodes": {
      "type": "array", "minItems": 1, "maxItems": 100,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["id", "type", "code", "position", "settings"],
        "properties": {
          "id": {"type": "string", "pattern": "^n:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},
          "type": {"enum": ["trigger", "logic", "action"]},
          "code": {"type": "string", "pattern": "^[a-z0-9_]{2,80}$"},
          "position": {"type": "object", "additionalProperties": false, "required": ["x", "y"], "properties": {"x": {"type": "number", "minimum": -1000000, "maximum": 1000000}, "y": {"type": "number", "minimum": -1000000, "maximum": 1000000}}},
          "settings": {"type": "object"}
        }
      }
    },
    "edges": {
      "type": "array", "maxItems": 200,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["id", "source", "target", "source_handle", "target_handle"],
        "properties": {
          "id": {"type": "string", "pattern": "^e:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},
          "source": {"type": "string", "pattern": "^n:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"}, "target": {"type": "string", "pattern": "^n:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"},
          "source_handle": {"type": "string", "pattern": "^[a-z][a-z0-9_.-]{0,63}$"}, "target_handle": {"type": "string", "pattern": "^[a-z][a-z0-9_.-]{0,63}$"}
        }
      }
    },
    "settings": {"type": "object", "additionalProperties": false}
  }
}
