{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chinaapi.ai/data/workflows/workflow.v1.schema.json",
  "title": "ChinaAPI Workflow v1",
  "description": "Static, evidence-aware task definition. A workflow is executable only when its runtime binding is verified.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "contract_status",
    "workflow_id",
    "slug",
    "title",
    "summary",
    "last_modified",
    "discovery",
    "inputs",
    "executor_query",
    "runtime_binding",
    "privacy_preflight",
    "recovery_policy",
    "acceptance_checks",
    "continue_action",
    "provenance"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "minLength": 1
    },
    "canonical_url": {
      "type": "string",
      "minLength": 1
    },
    "generated_by": {
      "const": "scripts/gen_workflows.py"
    },
    "schema_version": {
      "const": "chinaapi.workflow.v1"
    },
    "contract_status": {
      "enum": [
        "draft_unverified",
        "contract_locked_not_executable",
        "verified"
      ]
    },
    "workflow_id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "last_modified": {
      "type": "string",
      "format": "date"
    },
    "discovery": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "indexable",
        "sitemap",
        "locales"
      ],
      "properties": {
        "indexable": {
          "type": "boolean"
        },
        "sitemap": {
          "type": "boolean"
        },
        "locales": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z]{2}(?:-[a-z]{2})?$"
          }
        }
      }
    },
    "inputs": {
      "type": "array",
      "minItems": 2,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "type",
          "required",
          "description",
          "evidence_status",
          "default",
          "allowed_values",
          "cost_sensitive"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$"
          },
          "type": {
            "enum": [
              "asset",
              "string",
              "enum",
              "boolean",
              "integer"
            ]
          },
          "required": {
            "type": "boolean"
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "evidence_status": {
            "enum": [
              "semantic_stable",
              "runtime_contract_required"
            ]
          },
          "default": {
            "type": [
              "string",
              "boolean",
              "integer",
              "null"
            ]
          },
          "allowed_values": {
            "type": "array"
          },
          "cost_sensitive": {
            "type": "boolean"
          }
        }
      }
    },
    "executor_query": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "input_modalities",
        "output_modalities",
        "required_capabilities",
        "selection_policy"
      ],
      "properties": {
        "input_modalities": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        },
        "output_modalities": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        },
        "required_capabilities": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        },
        "selection_policy": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "runtime_binding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "contract_version",
        "dash_commit_sha",
        "openapi_path",
        "fixture_path",
        "endpoint",
        "operation_id",
        "operation_status",
        "workflow_version",
        "semantic_digest_sha256",
        "package_status",
        "capability_profile_version",
        "capability_evidence",
        "known_unimplemented_fields",
        "request_field_map",
        "model_ids",
        "price_source",
        "availability_source",
        "last_verified_at",
        "blocking_reason"
      ],
      "properties": {
        "status": {
          "enum": [
            "unavailable",
            "contract_only_not_executable",
            "verified"
          ]
        },
        "contract_version": {
          "type": [
            "string",
            "null"
          ]
        },
        "dash_commit_sha": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9a-f]{7,40}$"
        },
        "openapi_path": {
          "type": [
            "string",
            "null"
          ]
        },
        "fixture_path": {
          "type": [
            "string",
            "null"
          ]
        },
        "endpoint": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^/.*$"
        },
        "operation_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "operation_status": {
          "type": [
            "string",
            "null"
          ]
        },
        "workflow_version": {
          "type": [
            "string",
            "null"
          ]
        },
        "semantic_digest_sha256": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9a-f]{64}$"
        },
        "package_status": {
          "type": [
            "string",
            "null"
          ]
        },
        "capability_profile_version": {
          "type": [
            "string",
            "null"
          ]
        },
        "capability_evidence": {
          "type": [
            "string",
            "null"
          ]
        },
        "known_unimplemented_fields": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        },
        "request_field_map": {
          "type": "object"
        },
        "model_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        },
        "price_source": {
          "type": [
            "string",
            "null"
          ]
        },
        "availability_source": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_verified_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "blocking_reason": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "privacy_preflight": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "required_before_transfer",
        "processing_region",
        "retention",
        "training_use",
        "deletion",
        "commercial_use",
        "watermark"
      ],
      "properties": {
        "required_before_transfer": {
          "const": true
        },
        "processing_region": {
          "type": "string"
        },
        "retention": {
          "type": "string"
        },
        "training_use": {
          "type": "string"
        },
        "deletion": {
          "type": "string"
        },
        "commercial_use": {
          "type": "string"
        },
        "watermark": {
          "type": "string"
        }
      }
    },
    "recovery_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "resume_same_task_first",
        "automatic_fallback",
        "stop_when_charge_state_unknown",
        "confirmation_required_for"
      ],
      "properties": {
        "resume_same_task_first": {
          "const": true
        },
        "automatic_fallback": {
          "const": false
        },
        "stop_when_charge_state_unknown": {
          "const": true
        },
        "confirmation_required_for": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string"
          }
        }
      }
    },
    "acceptance_checks": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "continue_action": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "href",
        "reason"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "href": {
          "type": [
            "string",
            "null"
          ]
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "requirement_id",
        "source_kind",
        "runtime_evidence"
      ],
      "properties": {
        "requirement_id": {
          "type": "string",
          "pattern": "^CA-[0-9]{3}$"
        },
        "source_kind": {
          "type": "string",
          "minLength": 1
        },
        "runtime_evidence": {
          "enum": [
            "absent",
            "contract_only",
            "verified"
          ]
        }
      }
    }
  },
  "x-generated-by": "scripts/gen_workflows.py"
}
