{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/activity-chat.schema.json",
  "title": "Agent chat page",
  "description": "What GET /v1/agents/{sessionId}/{agentId}/chat returns and `activity-snapshot.mjs chat` prints: one page of an agent's transcript read from its end, oldest first, at most `limit` messages. Only user and assistant records are read; api-request records are never parsed and thinking blocks are never emitted. Every text has been through the redactor; a text the outbound gate still flags is replaced by a marker. `before` is the byte offset to send back for the previous page, null at the start of the file.",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion", "sessionId", "agentId", "messages", "before", "redacted"],
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "sessionId": { "type": "string", "x-sensitivity": "none" },
    "agentId": {
      "type": ["string", "null"],
      "description": "null for the session's own transcript (the orchestrator).",
      "x-sensitivity": "none"
    },
    "messages": {
      "type": "array",
      "x-sensitivity": "none",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["offset", "role", "at", "blocks"],
        "properties": {
          "offset": { "type": "integer", "minimum": 0 },
          "role": { "enum": ["user", "assistant"] },
          "at": { "type": ["string", "null"] },
          "blocks": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["kind", "text"],
                  "properties": { "kind": { "const": "text" }, "text": { "type": "string" } }
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["kind", "name", "summary", "toolUseId"],
                  "properties": {
                    "kind": { "const": "tool" },
                    "name": { "type": "string" },
                    "summary": { "type": "string" },
                    "toolUseId": { "type": ["string", "null"] }
                  }
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["kind", "toolUseId", "text", "isError"],
                  "properties": {
                    "kind": { "const": "result" },
                    "toolUseId": { "type": ["string", "null"] },
                    "text": { "type": "string" },
                    "isError": { "type": "boolean" }
                  }
                }
              ]
            }
          }
        }
      }
    },
    "before": { "type": ["integer", "null"], "minimum": 0, "x-sensitivity": "none" },
    "redacted": {
      "type": "integer",
      "minimum": 0,
      "description": "How many items the redactor replaced on this page.",
      "x-sensitivity": "none"
    }
  }
}
