{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/percia-ai/json-schema/percia-ai-watch-schema.json",
  "title": "Watch",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/percia-ai-openapi.yml#/components/schemas/Watch",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "sourceUrl": {
      "type": "string",
      "description": "Credentials are redacted. A video file is percia-file://<uploadId>."
    },
    "sourceType": {
      "enum": [
        "rtsp",
        "video",
        "phone"
      ],
      "description": "phone = a paired phone, tablet or computer camera; sourceUrl is then percia-cam://<cameraId>."
    },
    "camera": {
      "type": [
        "object",
        "null"
      ],
      "description": "Only on phone-camera watches.",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "status": {
          "enum": [
            "online",
            "offline",
            "never"
          ]
        }
      }
    },
    "goal": {
      "type": "string",
      "description": "For a deployed watch, the agent's name."
    },
    "site": {
      "type": [
        "object",
        "null"
      ],
      "description": "The site this watch belongs to (shared memory), else null.",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "destinations": {
      "type": "array",
      "description": "Connected destinations (Slack, Discord ...) this watch alerts, from its integration rules. Empty while integrations are off.",
      "items": {
        "type": "object",
        "properties": {
          "connectionId": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "label": {
            "type": "string"
          }
        }
      }
    },
    "deliveryProblem": {
      "type": [
        "string",
        "null"
      ],
      "description": "One plain sentence for a watch whose newest settled delivery failed (\"Slack answered 500.\"), else null."
    },
    "events24h": {
      "type": "integer",
      "description": "Events in the last 24 hours."
    },
    "minutesThisMonth": {
      "type": "integer",
      "description": "Camera-minutes this UTC month on the stream this watch uses (watches on one camera share its minutes)."
    },
    "pendingQuestion": {
      "type": [
        "object",
        "null"
      ],
      "description": "Detail only. A converted watch that waits for an answer: the question, its options (may be empty), when it was asked and the draft to answer through POST /watches/draft/{draftId}/answer. Null otherwise.",
      "properties": {
        "question": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "askedAt": {
          "type": "string",
          "format": "date-time"
        },
        "draftId": {
          "type": "string"
        }
      }
    },
    "advanced": {
      "type": "object",
      "description": "Only on a watch made with `advanced` (Percia engine). `conditions` and `actions` as you sent them; `contextRequests` are what the engine asked you to supply (each has `how_to_supply`, a SiteContext path to PUT), `[]` when none or not yet known; `state` is `pending` until the engine reported them; `siteRev` is the revision of the site's context it runs on.",
      "properties": {
        "conditions": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "actions": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "contextRequests": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "siteRev": {
          "type": [
            "integer",
            "null"
          ]
        },
        "state": {
          "enum": [
            "pending",
            "ready"
          ]
        }
      }
    },
    "agent": {
      "type": [
        "object",
        "null"
      ],
      "description": "Only on watches deployed with an agent. version is the one it runs; followsLatest is true when it was not pinned.",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "version": {
          "type": [
            "integer",
            "null"
          ]
        },
        "followsLatest": {
          "type": "boolean"
        }
      }
    },
    "notify": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "email",
            "webhook"
          ]
        },
        "target": {
          "type": "string"
        }
      }
    },
    "status": {
      "enum": [
        "active",
        "paused"
      ]
    },
    "pausedReason": {
      "type": [
        "string",
        "null"
      ],
      "description": "Why a paused watch is paused: user (paused by the owner or an agent, or an older pause with no recorded reason), no_video (paused automatically after 60 minutes without video from the camera), needs_billing (free minutes and credits used, no card), spend_cap (the monthly cap was reached), payment_failed (a payment failed and the 48-hour grace is over; resumes by itself when the payment succeeds) ended (a short-term watch reached its end) testing (made with `startPaused` to be tested before going live; PATCH status active goes live) or test_ended (a 30-minute test run ended; PATCH status active goes live). Resume with PATCH status active."
    },
    "testUntil": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Set while the watch is in a live test run: when it ends (30 minutes after PATCH {status: \"active\", testRun: true}). Its events are marked `test: true`, its webhooks carry `test: true`, and the watch is paused by itself at this time (pausedReason test_ended). PATCH {status: \"active\"} goes live with no restart; null otherwise."
    },
    "noVideoSince": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When the camera stopped sending video, else null. An active watch is paused automatically 60 minutes after this time (pausedReason no_video). Kept on a no_video pause; cleared on resume."
    },
    "displayStatus": {
      "enum": [
        "active",
        "paused",
        "attention"
      ],
      "description": "Needs attention when syncError is set, the last delivery failed, a rule of the watch points at a broken integration, or an active watch gets no video (noVideoSince set)."
    },
    "eventCount": {
      "type": "integer"
    },
    "judging": {
      "type": "object",
      "description": "Whether the pool is judging this watch (read-only, additive). `state`: judging (a judge call in the last 10 minutes), waiting_for_change (video arrives and the picture is still, so nothing is judged; a state goal is still looked at about every 5 minutes), no_video, paused (see `reason`), over_budget (the hourly judge limit skipped calls), judge_unavailable, starting, not_running (no container reports) or unknown (core runtime). A confirmed no-alert is `judging` or `waiting_for_change` with a recent lastFrameAt: silence with state not_running or no_video means nothing was watched. `stalled` is true when video flows and a scheduled judge call is 15+ minutes overdue.",
      "properties": {
        "state": {
          "enum": [
            "judging",
            "waiting_for_change",
            "no_video",
            "paused",
            "over_budget",
            "judge_unavailable",
            "starting",
            "not_running",
            "unknown"
          ]
        },
        "reason": {
          "type": [
            "string",
            "null"
          ],
          "description": "pausedReason when paused."
        },
        "stalled": {
          "type": "boolean"
        },
        "lastFrameAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "lastJudgedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "Last successful judge call."
        },
        "lastDecisionAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "framesReceived": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Frames the current container has received."
        },
        "judgeCallsLastHour": {
          "type": [
            "integer",
            "null"
          ]
        },
        "judgeCallsToday": {
          "type": [
            "integer",
            "null"
          ],
          "description": "UTC day."
        },
        "limitPerHour": {
          "type": [
            "integer",
            "null"
          ]
        },
        "reportedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "When the container last reported (about every 30 s)."
        }
      }
    },
    "lastEvent": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "The newest event id; with hasKeyframe it addresses GET /watches/{id}/events/{eventId}/keyframe."
        },
        "hasKeyframe": {
          "type": "boolean",
          "description": "False when no keyframe was kept or it has passed its retention days."
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "type": {
          "type": "string"
        },
        "deliveryStatus": {
          "enum": [
            "pending",
            "delivered",
            "failed"
          ]
        }
      }
    },
    "lastDelivery": {
      "enum": [
        "delivered",
        "failed",
        null
      ],
      "description": "Status of the newest event that is not pending. displayStatus comes from this, so a pending event does not hide a failed one."
    },
    "runtime": {
      "enum": [
        "pool"
      ],
      "description": "Always pool (kept for older clients): every watch is judged on the Percia engine."
    },
    "syncedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "syncError": {
      "type": [
        "string",
        "null"
      ]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    }
  }
}