{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-automation-manifest-schema.json",
  "title": "AutomationManifest",
  "description": "Документ akeda.automation.manifest версии 1 (AUTOMATION.md § 10.1).",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-automation-api-openapi.yml#/components/schemas/AutomationManifest",
  "type": "object",
  "required": [
    "format",
    "version",
    "revision",
    "locale",
    "detail",
    "events",
    "conditions",
    "actions",
    "references",
    "placeholders",
    "limits"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "type": "string",
      "enum": [
        "akeda.automation.manifest"
      ]
    },
    "version": {
      "type": "integer"
    },
    "revision": {
      "type": "string",
      "description": "Отпечаток содержимого sha256:…"
    },
    "locale": {
      "type": "string",
      "enum": [
        "ru",
        "en"
      ]
    },
    "detail": {
      "type": "string",
      "enum": [
        "full",
        "brief"
      ]
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AutomationManifestEvent"
      }
    },
    "conditions": {
      "type": "object",
      "required": [
        "combinator",
        "operators",
        "max_clauses",
        "max_value_length"
      ],
      "properties": {
        "combinator": {
          "type": "string",
          "enum": [
            "all"
          ]
        },
        "operators": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "op",
              "label",
              "field_types",
              "needs_value",
              "case_insensitive"
            ],
            "properties": {
              "op": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "field_types": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "needs_value": {
                "type": "boolean"
              },
              "case_insensitive": {
                "type": "boolean"
              }
            }
          }
        },
        "max_clauses": {
          "type": "integer"
        },
        "max_value_length": {
          "type": "integer"
        }
      }
    },
    "actions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AutomationManifestAction"
      }
    },
    "timing": {
      "type": "object",
      "description": "Блок «Когда выполнить» (ERP-1928): виды, единицы, повторы расписания, события отмены; отборы записей по расписанию — selections (ERP-1939). Полная схема — docs/architecture/automation/manifest.schema.json",
      "additionalProperties": true,
      "properties": {
        "max_selection_records": {
          "type": "integer",
          "description": "Сколько записей отбора берёт один запуск расписания"
        },
        "selections": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "module",
              "object",
              "entity",
              "label",
              "status",
              "params",
              "fields"
            ],
            "additionalProperties": true,
            "properties": {
              "key": {
                "type": "string"
              },
              "module": {
                "type": "string"
              },
              "object": {
                "type": "string",
                "description": "Объект записи: действия над записью события берутся по нему"
              },
              "entity": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "live",
                  "unavailable"
                ]
              },
              "params": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "fields": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "references": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "kind",
          "module",
          "label",
          "lookup_tool",
          "parameter_kind",
          "status"
        ],
        "properties": {
          "kind": {
            "type": "string"
          },
          "module": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "lookup_tool": {
            "type": "string",
            "description": "MCP-инструмент поиска значения по имени"
          },
          "parameter_kind": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "live",
              "unavailable"
            ]
          }
        }
      }
    },
    "placeholders": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "syntax",
          "meaning",
          "status"
        ],
        "properties": {
          "syntax": {
            "type": "string"
          },
          "meaning": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      }
    },
    "blocks": {
      "type": "object",
      "description": "Ветки «Если ещё / Иначе», пауза «Подождать» и ссылки на результаты шагов (ERP-1932)",
      "additionalProperties": true
    },
    "limits": {
      "type": "object",
      "required": [
        "max_actions",
        "max_conditions",
        "max_condition_length",
        "chain_depth",
        "runs_per_tenant_per_minute",
        "max_attempts"
      ],
      "properties": {
        "max_actions": {
          "type": "integer"
        },
        "max_conditions": {
          "type": "integer"
        },
        "max_condition_length": {
          "type": "integer"
        },
        "chain_depth": {
          "type": "integer"
        },
        "runs_per_tenant_per_minute": {
          "type": "integer"
        },
        "max_attempts": {
          "type": "integer"
        }
      }
    }
  },
  "$defs": {
    "AutomationManifestAction": {
      "type": "object",
      "required": [
        "command",
        "module",
        "label_key",
        "label",
        "description",
        "when_to_use",
        "status",
        "permission",
        "reversible",
        "danger",
        "idempotency",
        "target"
      ],
      "properties": {
        "command": {
          "type": "string"
        },
        "module": {
          "type": "string"
        },
        "label_key": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "when_to_use": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "live",
            "declared",
            "unavailable"
          ]
        },
        "unavailable_reason": {
          "type": "string"
        },
        "permission": {
          "type": "string"
        },
        "reversible": {
          "type": "boolean"
        },
        "danger": {
          "type": "string",
          "enum": [
            "none",
            "external",
            "posting",
            "irreversible"
          ]
        },
        "idempotency": {
          "type": "string"
        },
        "target": {
          "type": "string",
          "enum": [
            "new",
            "event_entity"
          ]
        },
        "event_entities": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "mcp_twin": {
          "type": "string"
        },
        "inputs": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "type",
              "required",
              "label",
              "accepts_placeholders"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "bool",
                  "reference",
                  "datetime",
                  "choice",
                  "event_date",
                  "time",
                  "json",
                  "headers",
                  "code",
                  "reference_list"
                ],
                "description": "reference_list — несколько значений справочника ref через запятую, например группа распределения ответственного (ERP-1938)"
              },
              "required": {
                "type": "boolean"
              },
              "label": {
                "type": "string"
              },
              "options": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/AutomationManifestOption"
                }
              },
              "ref": {
                "type": "string"
              },
              "accepts_placeholders": {
                "type": "boolean"
              }
            }
          }
        },
        "example_inputs": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "outputs": {
          "type": "array",
          "description": "Результаты шага для следующих шагов пути: {{step:<id шага>.<key>}} (ERP-1932)",
          "items": {
            "type": "object",
            "required": [
              "key",
              "type",
              "label"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "reference"
                ]
              },
              "ref": {
                "type": "string"
              },
              "label": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "AutomationManifestEvent": {
      "type": "object",
      "required": [
        "topic",
        "module",
        "entity",
        "fact",
        "label_key",
        "label",
        "description",
        "when_to_use",
        "status",
        "source_visibility"
      ],
      "properties": {
        "topic": {
          "type": "string"
        },
        "module": {
          "type": "string"
        },
        "entity": {
          "type": "string"
        },
        "fact": {
          "type": "string"
        },
        "label_key": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "when_to_use": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "live",
            "unavailable"
          ]
        },
        "unavailable_reason": {
          "type": "string"
        },
        "source_visibility": {
          "type": "boolean",
          "description": "Правило сработает, только если исполнитель видит источник"
        },
        "fields": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "type",
              "label",
              "operators"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "bool",
                  "timestamp"
                ]
              },
              "label": {
                "type": "string"
              },
              "options": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/AutomationManifestOption"
                }
              },
              "ref": {
                "type": "string"
              },
              "operators": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "group": {
                "type": "string",
                "enum": [
                  "custom",
                  "webhook",
                  "selection"
                ],
                "description": "custom — своё поле кабинета, webhook — поле тела входящего вебхука body.<путь> (ERP-1938), selection — поле записи отбора по расписанию (ERP-1939)"
              },
              "hooks": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "У поля тела вебхука — вебхуки, в образце которых оно есть"
              }
            }
          }
        },
        "example_payload": {
          "type": "object",
          "additionalProperties": true
        }
      }
    },
    "AutomationManifestOption": {
      "type": "object",
      "required": [
        "value",
        "label"
      ],
      "properties": {
        "value": {
          "type": "string"
        },
        "label": {
          "type": "string"
        }
      }
    }
  }
}