{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shruwd-io/json-schema/shruwd-io-workspace-schema.json",
  "title": "Workspace",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shruwd-io-openapi.json#/components/schemas/Workspace",
  "type": "object",
  "required": [
    "workspaceId",
    "planCode",
    "status",
    "role",
    "hold",
    "entitlements",
    "usage",
    "brands"
  ],
  "properties": {
    "workspaceId": {
      "type": "string"
    },
    "planCode": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "past_due",
        "canceled"
      ]
    },
    "role": {
      "type": "string",
      "enum": [
        "owner",
        "member"
      ],
      "description": "`owner`: the workspace's owner, with every brand. `member`: a member of the brands listed, with the role on each in that brand's `role`."
    },
    "hold": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "reason",
            "since"
          ],
          "properties": {
            "reason": {
              "type": "string"
            },
            "since": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            }
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when measurement is paused pending review (a cost guardrail, or an operator). Nothing runs while it is set; `POST …/cycles` answers `409 workspace_on_hold`. Null normally."
    },
    "entitlements": {
      "$ref": "#/$defs/Entitlements"
    },
    "usage": {
      "type": "object",
      "required": [
        "runsThisPeriod",
        "runsAllowance",
        "rechecksThisMonth",
        "rechecksAllowance",
        "activePrompts",
        "promptsAllowance"
      ],
      "properties": {
        "runsThisPeriod": {
          "type": "integer"
        },
        "runsAllowance": {
          "type": "integer"
        },
        "rechecksThisMonth": {
          "type": "integer"
        },
        "rechecksAllowance": {
          "type": "integer"
        },
        "activePrompts": {
          "type": "integer",
          "description": "Active prompts across every brand in the workspace, including brands the caller cannot reach: one pool."
        },
        "promptsAllowance": {
          "type": "integer"
        }
      }
    },
    "brands": {
      "type": "array",
      "description": "The brands the caller can reach.",
      "items": {
        "type": "object",
        "required": [
          "brandId",
          "slug",
          "name",
          "domain",
          "role"
        ],
        "properties": {
          "brandId": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "domain": {
            "type": "string"
          },
          "role": {
            "$ref": "#/$defs/BrandRole"
          }
        }
      }
    }
  },
  "$defs": {
    "BrandRole": {
      "type": "string",
      "enum": [
        "viewer",
        "editor",
        "admin",
        "owner"
      ],
      "description": "The caller's role on this brand: `owner` for the workspace's owner, else the role they were given on it. Reads need `viewer`, writes `editor`."
    },
    "Engine": {
      "type": "string",
      "enum": [
        "google_aio",
        "google_ai_mode",
        "chatgpt",
        "gemini",
        "perplexity"
      ],
      "description": "`google_aio` — Google AI Overviews. `google_ai_mode` — Google AI Mode, tracked since 2026-10-15. `chatgpt` — ChatGPT. `gemini` — Gemini, tracked since 2026-11-10. `perplexity` — Perplexity, asked through its Sonar API, tracked since 2026-11-11."
    },
    "Entitlements": {
      "type": "object",
      "description": "The limits in force for the workspace — the plan plus any one-off grant.",
      "required": [
        "planCode",
        "maxBrands",
        "maxPrompts",
        "maxMembers",
        "maxVisibleFindings",
        "repsPerCycle",
        "engines",
        "cadence",
        "snapshot",
        "rechecksPerMonth",
        "historyDays",
        "crawlerLinesPerMonth",
        "findingFamilies",
        "connections",
        "overageAllowed",
        "runsPerPeriod",
        "overridden"
      ],
      "properties": {
        "planCode": {
          "type": "string"
        },
        "maxBrands": {
          "type": "integer"
        },
        "maxPrompts": {
          "type": "integer",
          "description": "Active prompts across every brand in the workspace."
        },
        "maxMembers": {
          "type": "integer",
          "description": "People with access, the owner included. Open invites count toward it."
        },
        "maxVisibleFindings": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Findings shown in full, the first N in rank order. Null shows every finding. The rest are counted in a findings list's `locked`."
        },
        "repsPerCycle": {
          "type": "integer",
          "description": "Repetitions per prompt per engine per cycle."
        },
        "engines": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Engine"
          }
        },
        "cadence": {
          "type": "string",
          "enum": [
            "weekly",
            "none"
          ],
          "description": "`weekly` schedules a cycle per brand per week. `none` schedules nothing; see `snapshot`."
        },
        "snapshot": {
          "type": "boolean",
          "description": "True on the free tier — one measurement at setup, once per registrable domain."
        },
        "rechecksPerMonth": {
          "type": "integer"
        },
        "historyDays": {
          "type": "integer",
          "description": "How far back reads go. Older data is kept, not shown."
        },
        "crawlerLinesPerMonth": {
          "type": "integer"
        },
        "findingFamilies": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "ACCESS",
              "STRUCT",
              "CITE",
              "FACT",
              "COVERAGE"
            ]
          }
        },
        "connections": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "gsc",
              "ga4",
              "logdrain",
              "cloudflare_logpush"
            ]
          }
        },
        "overageAllowed": {
          "type": "boolean"
        },
        "runsPerPeriod": {
          "type": "integer",
          "description": "Hard ceiling on runs per billing period."
        },
        "overridden": {
          "type": "boolean",
          "description": "True when a one-off grant changed at least one limit."
        }
      }
    }
  }
}