{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://skoolbus.dev/schema/v1/workflow.json",
  "$defs": {
    "Link": {
      "properties": {
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "from",
        "to"
      ]
    },
    "Step": {
      "properties": {
        "runtime": {
          "type": "string",
          "enum": [
            "python@3.12",
            "bun@1",
            "shell",
            "custom"
          ]
        },
        "entry": {
          "type": "string",
          "description": "Entry file relative to the step folder; required unless runtime is custom"
        },
        "command": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "description": "custom only; overrides the image CMD"
        },
        "description": {
          "type": "string"
        },
        "connectors": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "description": "Connector names this step may use; resolved by the credential proxy"
        },
        "model": {
          "type": "string",
          "description": "LLM model alias resolved by the gateway"
        },
        "timeout": {
          "type": "string",
          "description": "Go duration between 1s and 1h"
        },
        "memory": {
          "type": "string",
          "pattern": "^[0-9]+(Ki|Mi|Gi)$",
          "description": "Between 64Mi and 8Gi"
        },
        "cpu": {
          "type": "number",
          "maximum": 8,
          "minimum": 0.1
        },
        "env": {
          "additionalProperties": {
            "type": "string"
          },
          "propertyNames": {
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
          },
          "type": "object",
          "description": "Literal non-secret environment variables; BUS_ prefix is reserved"
        },
        "volumes": {
          "items": {
            "$ref": "#/$defs/StepVolume"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "runtime"
      ]
    },
    "StepVolume": {
      "properties": {
        "name": {
          "type": "string",
          "description": "A key under the workflow's volumes:"
        },
        "mount": {
          "type": "string",
          "pattern": "^/storage/",
          "description": "Mount path; default /storage/\u003cname\u003e"
        },
        "mode": {
          "type": "string",
          "enum": [
            "ro",
            "rw",
            "exclusive",
            "scratch"
          ],
          "description": "default rw"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "name"
      ]
    },
    "Trigger": {
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "cron",
            "http",
            "manual"
          ]
        },
        "step": {
          "type": "string",
          "description": "The entry step"
        },
        "schedule": {
          "type": "string",
          "description": "cron only; five fields; UTC"
        },
        "path": {
          "type": "string",
          "pattern": "^/",
          "description": "http only; must start with /"
        },
        "method": {
          "type": "string",
          "enum": [
            "GET",
            "POST",
            "PUT",
            "PATCH",
            "DELETE"
          ],
          "description": "http only; default POST"
        },
        "auth": {
          "type": "string",
          "enum": [
            "members",
            "tenant",
            "sso",
            "public"
          ],
          "description": "http only; default members"
        },
        "respond_with": {
          "type": "string",
          "description": "http only; the step whose output is the HTTP response"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "type",
        "step"
      ]
    },
    "Volume": {
      "oneOf": [
        {
          "additionalProperties": false,
          "type": "object"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "properties": {
    "version": {
      "type": "integer",
      "maximum": 1,
      "minimum": 1,
      "description": "Manifest schema version; must be 1"
    },
    "name": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
      "description": "Workflow name; must equal the folder name"
    },
    "id": {
      "type": "string",
      "pattern": "^wf_[0-9a-hjkmnp-tv-z]{26}$",
      "description": "Generated by bus new workflow; never edited"
    },
    "description": {
      "type": "string"
    },
    "triggers": {
      "items": {
        "$ref": "#/$defs/Trigger"
      },
      "type": "array",
      "description": "What starts a run; declared here and fired by the server"
    },
    "steps": {
      "additionalProperties": {
        "$ref": "#/$defs/Step"
      },
      "propertyNames": {
        "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
      },
      "type": "object",
      "description": "Steps keyed by folder name under steps/"
    },
    "links": {
      "items": {
        "$ref": "#/$defs/Link"
      },
      "type": "array",
      "description": "Directed edges; upstream stdout becomes downstream stdin"
    },
    "volumes": {
      "additionalProperties": {
        "$ref": "#/$defs/Volume"
      },
      "propertyNames": {
        "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
      },
      "type": "object",
      "description": "Named persistent directories steps may mount under /storage"
    }
  },
  "additionalProperties": false,
  "type": "object",
  "required": [
    "version",
    "name",
    "id",
    "steps"
  ],
  "title": "skoolbus workflow",
  "description": "workflow.yaml: the triggers, steps, links, and volumes of one workflow. Unknown keys are errors."
}
