{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "v": {
      "type": "number",
      "const": 1,
      "description": "Protocol major version."
    },
    "type": {
      "type": "string",
      "const": "run.requested"
    },
    "id": {
      "type": "string",
      "pattern": "^evt_[0-7][0-9A-HJKMNP-TV-Z]{25}$",
      "description": "The event's own id. Stable across a retry of the same event."
    },
    "ts": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
      "description": "When it happened, by Chips' clock. Stamped on the way in; a value the sender writes is replaced."
    },
    "workspace_id": {
      "type": "string",
      "pattern": "^ws_[0-7][0-9A-HJKMNP-TV-Z]{25}$",
      "description": "A workspace identifier: `ws_` followed by a ULID."
    },
    "space_id": {
      "description": "The space, when the event belongs to one.",
      "type": "string",
      "pattern": "^spc_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "run_id": {
      "description": "The run, when the event belongs to one.",
      "type": "string",
      "pattern": "^run_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "seq": {
      "description": "Assigned by the server on append, monotonic per workspace. Absent on the way in.",
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "idempotency_key": {
      "description": "Required on every client-originated write. Sending the same key twice is a no-op.",
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "actor": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "person",
            "harness",
            "agent",
            "system"
          ],
          "description": "Whether a person, a harness, one of a harness's agents or Chips itself acted."
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "The participant id, or `system` for Chips."
        },
        "harness_id": {
          "description": "For an agent: the harness it speaks through, whose budget and runs are the agent's (ADR 0087). Filled in by Chips.",
          "type": "string",
          "pattern": "^hrn_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
        }
      },
      "required": [
        "kind",
        "id"
      ],
      "description": "The participant an event is attributed to."
    },
    "lane_id": {
      "type": "string",
      "pattern": "^lane_[0-7][0-9A-HJKMNP-TV-Z]{25}$",
      "description": "A lane identifier: `lane_` followed by a ULID."
    },
    "goal": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000,
      "description": "What is being asked."
    },
    "constraints": {
      "description": "Bounds on how to do it.",
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 500
      }
    },
    "deadline": {
      "description": "When it is needed by.",
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "on_behalf_of": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "description": "The person the work is ultimately for."
    },
    "requested_by": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "description": "The lead that routed it."
    },
    "specialist_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "description": "The harness this lane runs on, which the run in the envelope belongs to. A lead may name an ephemeral child, which Chips has minted by the time this arrives."
    },
    "agent_id": {
      "description": "The agent of that harness that works the lane (ADR 0087): its one agent in the lane's room, the one the lead named, a lead's hand-off to one of its own, or a child minted for this lane.",
      "type": "string",
      "pattern": "^agt_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "trail": {
      "maxItems": 8,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "participant_id": {
            "type": "string",
            "minLength": 1,
            "description": "Who handled this hop."
          },
          "run_id": {
            "description": "The run this hop belongs to.",
            "type": "string",
            "pattern": "^run_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "goal": {
            "description": "What was asked at this hop.",
            "type": "string",
            "maxLength": 2000
          }
        },
        "required": [
          "participant_id"
        ],
        "description": "One hop in the chain that led to this work."
      },
      "description": "How the work got here. Lanes deeper than three are flattened into steps, not rejected."
    },
    "autonomy": {
      "anyOf": [
        {
          "type": "number",
          "const": 0
        },
        {
          "type": "number",
          "const": 1
        },
        {
          "type": "number",
          "const": 2
        },
        {
          "type": "number",
          "const": 3
        }
      ],
      "description": "The level for this lane."
    },
    "link_to": {
      "description": "The lead spaces this lane is linked into, where its route card appears.",
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^spc_[0-7][0-9A-HJKMNP-TV-Z]{25}$",
        "description": "A space identifier: `spc_` followed by a ULID."
      }
    },
    "origin": {
      "description": "The message that caused the routing, quoted in the specialist's task card.",
      "type": "string",
      "pattern": "^msg_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "attachments": {
      "description": "Anything the specialist needs.",
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "attachment_id": {
            "type": "string",
            "pattern": "^att_[0-7][0-9A-HJKMNP-TV-Z]{25}$",
            "description": "A attachment identifier: `att_` followed by a ULID."
          },
          "filename": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "The name to show. Never trusted for its type."
          },
          "mime_type": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "Sniffed from the bytes on upload, not taken from the client."
          },
          "byte_size": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991,
            "description": "Size in bytes."
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$",
            "description": "Lowercase hex digest. The store is content-addressed."
          },
          "width": {
            "description": "Pixels, for images and video.",
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "height": {
            "description": "Pixels, for images and video.",
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "duration_ms": {
            "description": "Milliseconds, for audio and video.",
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "transcript": {
            "description": "What was said, for a voice note the server transcribed when it arrived (ADR 0054). Machine-heard: the person's words as best the server could make them out.",
            "type": "string",
            "minLength": 1,
            "maxLength": 50000
          },
          "replaces": {
            "description": "The version of the room's file of this name that this one was made from (ADR 0099), from the post's `replaces`. Filled in by Chips; a value the sender writes is replaced.",
            "type": "string",
            "pattern": "^att_[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "A signed URL, bound to the requesting token: fetch it with that token as the bearer, since the URL alone is refused."
          },
          "url_expires_at": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
            "description": "Ten minutes from issue, by default (decision 10)."
          }
        },
        "required": [
          "attachment_id",
          "filename",
          "mime_type",
          "byte_size",
          "sha256",
          "url",
          "url_expires_at"
        ],
        "description": "An attachment with a short-lived, token-bound URL."
      }
    },
    "label": {
      "description": "What the lead calls the specialist on this lane, when that is not its participant name: a Space's name, a subagent's type.",
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    }
  },
  "required": [
    "v",
    "type",
    "id",
    "ts",
    "workspace_id",
    "actor",
    "lane_id",
    "goal",
    "on_behalf_of",
    "requested_by",
    "specialist_id",
    "trail",
    "autonomy"
  ],
  "description": "A lane arrived from a lead, with the trail that led to it.",
  "$id": "https://chipschat.ai/schema/v1/run.requested.json",
  "title": "RunRequested"
}
