{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mobilerun-ai/json-schema/mobilerun-ai-flow-schema.json",
  "title": "Flow",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mobilerun-ai-openapi.json#/components/schemas/Flow",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "userId": {
      "type": "string",
      "format": "uuid",
      "deprecated": true,
      "description": "Deprecated: use ownerId (tenancy) / createdBy (actor)."
    },
    "ownerId": {
      "type": "string",
      "format": "uuid"
    },
    "agentId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "createdBy": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "triggerId": {
      "type": "string",
      "format": "uuid"
    },
    "enabled": {
      "type": "boolean",
      "description": "Compatibility projection of lifecycleStatus; true only when lifecycleStatus is enabled."
    },
    "lifecycleStatus": {
      "$ref": "#/$defs/AgentLifecycleStatus"
    },
    "archivedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "deviceIds": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "uuid"
      }
    },
    "cooldownSeconds": {
      "type": [
        "integer",
        "null"
      ]
    },
    "cooldownScope": {
      "type": "string",
      "enum": [
        "flow",
        "device"
      ]
    },
    "notifyWebhookId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "notifyOnSuccess": {
      "type": "boolean"
    },
    "notifyOnFailure": {
      "type": "boolean"
    },
    "ownerWake": {
      "$ref": "#/$defs/OwnerWake"
    },
    "lastTriggeredAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "status": {
      "$ref": "#/$defs/FlowStatus"
    },
    "templateResolutionVersion": {
      "type": "integer",
      "minimum": 1,
      "maximum": 3,
      "description": "Template-resolver semantics this flow runs under. 1 = legacy (missing/forbidden/null all resolve to ''). 2 = typed (missing/forbidden throw, a whole-token null stays JSON null). 3 = typed, key-based (steps are addressed as {{steps.<key>...}} instead of by name; trigger.payload is not available). Existing flows stay 1; new flows default to the current version."
    },
    "consecutiveFailures": {
      "type": "integer",
      "minimum": 0
    },
    "lastFailureCode": {
      "$ref": "#/$defs/FlowFailureCode"
    },
    "lastFailureAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "blockedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "healthMonitoringEnabled": {
      "type": "boolean"
    },
    "selfHealingEnabled": {
      "type": "boolean"
    },
    "selfHealingMaxAttempts": {
      "type": "integer",
      "minimum": 1,
      "maximum": 5
    },
    "recordingEnabled": {
      "type": "boolean",
      "deprecated": true,
      "description": "Deprecated: use recordingPolicy.mode (\"flow\" = recordingEnabled=true, \"off\" = recordingEnabled=false)."
    },
    "recordingPolicy": {
      "$ref": "#/$defs/RecordingPolicy"
    },
    "delivery": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "destination": {
          "type": "string",
          "enum": [
            "mobilerun",
            "one_drive",
            "google_drive"
          ]
        },
        "folder": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1024,
          "description": "Absolute destination folder; not allowed when destination is mobilerun. May contain {{meta.<name>}} (for example {{meta.shortDate}} = YYMMDD, {{meta.fileTime}} = HH-mm, in the trigger timezone) and {{event.payload.<field>}} placeholders, resolved once per run so every artifact of that run lands in the same folder. Each substituted value must be a single safe folder name (no \"/\", \"\\\", \"..\", control characters); otherwise delivery fails with invalid_delivery_folder. With a placeholder folder, screenshots are delivered directly into the resolved folder; with a static folder they go into a per-run \"<flow>-<timestamp>-<id>-screenshots\" subfolder."
        },
        "recording": {
          "type": "object",
          "properties": {
            "filename": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            }
          },
          "required": [
            "filename"
          ],
          "additionalProperties": false
        },
        "screenshots": {
          "type": "object",
          "properties": {},
          "additionalProperties": false
        }
      },
      "required": [
        "destination"
      ],
      "additionalProperties": false
    },
    "resultDelivery": {
      "allOf": [
        {
          "$ref": "#/$defs/ResultDelivery"
        },
        {
          "description": "Effective routine result delivery: the stored setting, else message for a chat sink, else none."
        }
      ]
    },
    "createdAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "updatedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "userId",
    "ownerId",
    "agentId",
    "createdBy",
    "name",
    "description",
    "triggerId",
    "enabled",
    "lifecycleStatus",
    "archivedAt",
    "deviceIds",
    "cooldownSeconds",
    "cooldownScope",
    "notifyWebhookId",
    "notifyOnSuccess",
    "notifyOnFailure",
    "ownerWake",
    "lastTriggeredAt",
    "status",
    "templateResolutionVersion",
    "consecutiveFailures",
    "lastFailureCode",
    "lastFailureAt",
    "blockedAt",
    "healthMonitoringEnabled",
    "selfHealingEnabled",
    "selfHealingMaxAttempts",
    "recordingEnabled",
    "recordingPolicy",
    "delivery",
    "resultDelivery",
    "createdAt",
    "updatedAt"
  ],
  "$defs": {
    "AgentLifecycleStatus": {
      "type": "string",
      "enum": [
        "enabled",
        "disabled",
        "archived"
      ]
    },
    "FlowFailureCode": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "device_not_found",
        "device_unavailable",
        "permission_denied",
        "client_error",
        "transient",
        "logic",
        "invalid_config",
        null
      ],
      "description": "Curated flow failure class. device_unavailable blocks immediately for a terminated device or a device confirmed gone; event deviceState=\"gone\" is triggers-defined for a deleted/not-found device."
    },
    "FlowStatus": {
      "type": "string",
      "enum": [
        "healthy",
        "failing",
        "blocked"
      ]
    },
    "OwnerWake": {
      "type": "string",
      "enum": [
        "final",
        "off"
      ],
      "default": "final"
    },
    "RecordingPolicy": {
      "type": "object",
      "properties": {
        "mode": {
          "$ref": "#/$defs/RecordingPolicyMode"
        }
      },
      "required": [
        "mode"
      ]
    },
    "RecordingPolicyMode": {
      "type": "string",
      "enum": [
        "off",
        "flow",
        "selected_steps"
      ]
    },
    "ResultDelivery": {
      "type": "string",
      "enum": [
        "none",
        "message",
        "wake"
      ]
    }
  }
}