{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/crevio-co/json-schema/crevio-co-ai-task-schema.json",
  "title": "AiTask",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/crevio-co-openapi.json#/components/schemas/AiTask",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "kind": {
      "type": "string",
      "enum": [
        "agent",
        "script"
      ]
    },
    "prompt": {
      "type": [
        "string",
        "null"
      ]
    },
    "success_criteria": {
      "type": [
        "string",
        "null"
      ]
    },
    "trigger_type": {
      "type": "string",
      "enum": [
        "immediate",
        "cron",
        "interval",
        "once",
        "event"
      ]
    },
    "cron_expression": {
      "type": [
        "string",
        "null"
      ]
    },
    "interval_seconds": {
      "type": [
        "integer",
        "null"
      ]
    },
    "scheduled_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "event_conditions": {
      "type": [
        "object",
        "null"
      ]
    },
    "condition_script": {
      "type": [
        "string",
        "null"
      ]
    },
    "pre_run_script": {
      "type": [
        "string",
        "null"
      ]
    },
    "script": {
      "type": [
        "string",
        "null"
      ]
    },
    "timezone": {
      "type": "string"
    },
    "delivery_methods": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "notification",
          "email",
          "telegram",
          "discord",
          "slack"
        ]
      }
    },
    "approval_mode": {
      "type": "string",
      "enum": [
        "autonomous",
        "supervised",
        "read_only"
      ]
    },
    "model_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "agent": {
      "type": "string",
      "enum": [
        "business",
        "engineering"
      ]
    },
    "visibility": {
      "type": "string",
      "enum": [
        "account",
        "personal"
      ]
    },
    "active": {
      "type": "boolean"
    },
    "expires_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "next_run_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "last_run_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "total_runs_count": {
      "type": "integer"
    },
    "consecutive_failure_count": {
      "type": "integer"
    },
    "total_credits_consumed": {
      "type": "integer"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "max_runs_per_day": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Event tasks: the most event-started runs per day (account time zone); later events are skipped as `rate_limited`."
    },
    "min_interval_seconds": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Event tasks: the cooldown after an event-started run; events inside it are skipped as `rate_limited`."
    },
    "slack_sender_name": {
      "type": [
        "string",
        "null"
      ],
      "description": "The name Slack shows on this task's posted results. Null posts as the task's bot, else Crevio."
    },
    "site_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "source": {
      "type": "string",
      "description": "How the task came to exist: `user` (a person made it in the dashboard), `agent` (the agent made it inside the chat `origin_chat_id`, whose person is `created_by_id`), or `system` (a built-in task).",
      "enum": [
        "user",
        "agent",
        "system"
      ]
    },
    "created_by_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "The person (`user_...`) who made the task or asked for it. Null for built-in tasks."
    },
    "created_by_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "origin_chat_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "The chat (`aichat_...`) the task was set up in. A member's chat opens only for that member."
    },
    "recent_runs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AiTaskRunSummary"
      },
      "description": "The task's newest executed runs (at most 5, newest first; skipped and test runs excluded)."
    }
  },
  "required": [
    "id",
    "object",
    "name",
    "description",
    "kind",
    "prompt",
    "success_criteria",
    "trigger_type",
    "cron_expression",
    "interval_seconds",
    "scheduled_at",
    "event_conditions",
    "condition_script",
    "pre_run_script",
    "script",
    "timezone",
    "delivery_methods",
    "approval_mode",
    "model_id",
    "agent",
    "visibility",
    "active",
    "expires_at",
    "next_run_at",
    "last_run_at",
    "total_runs_count",
    "consecutive_failure_count",
    "total_credits_consumed",
    "created_at",
    "updated_at",
    "max_runs_per_day",
    "min_interval_seconds",
    "slack_sender_name",
    "site_id",
    "source",
    "created_by_id",
    "created_by_name",
    "origin_chat_id",
    "recent_runs"
  ],
  "$defs": {
    "AiTaskRunSummary": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "pending",
            "running",
            "completed",
            "failed",
            "needs_input",
            "timed_out",
            "unknown",
            "skipped",
            "cancelled"
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "completed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "error_message": {
          "type": [
            "string",
            "null"
          ]
        },
        "chat_id": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "id",
        "status",
        "created_at",
        "completed_at",
        "error_message",
        "chat_id"
      ]
    }
  }
}