{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mobster.dev/schema/webhooks/run.finished.json",
  "title": "A task's result",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "type",
    "runId",
    "status",
    "answer",
    "data",
    "reason",
    "startedAt",
    "finishedAt",
    "workflow",
    "text"
  ],
  "properties": {
    "type": {
      "const": "run.finished",
      "description": "The event, as the Mobster-Event header names it."
    },
    "runId": {
      "type": "string",
      "description": "The task's id."
    },
    "status": {
      "type": "string",
      "description": "completed, or how the task ended: completion_not_confirmed, blocked, max_steps, timeout, spend_cap, approval_denied, approval_timeout, stopped, interrupted or error."
    },
    "answer": {
      "type": [
        "string",
        "null"
      ],
      "description": "The whole answer as text. Null when the task had none."
    },
    "data": {
      "description": "The structured answer, when the task asked for one and Mobster checked that it fits. Null for a text answer."
    },
    "reason": {
      "type": [
        "string",
        "null"
      ],
      "description": "Why the task didn't finish. Null when it did."
    },
    "startedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "UTC, ISO 8601. Null when unknown."
    },
    "finishedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "UTC, ISO 8601. Null when unknown."
    },
    "workflow": {
      "anyOf": [
        {
          "type": "object",
          "description": "The workflow the task ran from. Null for a task you started yourself.",
          "additionalProperties": false,
          "required": [
            "id",
            "name",
            "blanks"
          ],
          "properties": {
            "id": {
              "type": [
                "string",
                "null"
              ],
              "description": "The workflow's id."
            },
            "name": {
              "type": "string",
              "description": "The workflow's name."
            },
            "blanks": {
              "type": "object",
              "description": "Each blank's value, by the blank's name."
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "text": {
      "type": "string",
      "description": "One line for chat tools: Mobster: …, or Mobster › <workflow>: …"
    },
    "screenshot": {
      "type": "object",
      "description": "Only with Send the last screen on: the task's last screen, at most 1,280 pixels on its long side.",
      "additionalProperties": false,
      "required": [
        "contentType",
        "base64"
      ],
      "properties": {
        "contentType": {
          "const": "image/jpeg"
        },
        "base64": {
          "type": "string"
        }
      }
    }
  }
}
