{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Server-Sent Events emitted on POST /sessions/{id}/messages. Each event is an object discriminated on `type`; all carry `turn_id`.",
  "discriminator": {
    "propertyName": "type"
  },
  "oneOf": [
    {
      "additionalProperties": true,
      "properties": {
        "phase": {
          "enum": [
            "BuildingPrompt",
            "CallingLLM",
            "ProcessingTools",
            "Streaming",
            "Finishing"
          ],
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "worker_phase"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "awaiting_llm_first_token"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "content": {
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "thinking"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "content": {
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "text"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "text_boundary"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "name": {
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "tool_start"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "name": {
          "type": "string"
        },
        "result": {},
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "tool_result"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "affect_update"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "done"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "phase": {
          "type": "string"
        },
        "reason": {
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "cancelled"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    },
    {
      "additionalProperties": true,
      "properties": {
        "error_code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "turn_id": {
          "description": "The turn this event belongs to.",
          "type": [
            "integer",
            "string"
          ]
        },
        "type": {
          "const": "error"
        }
      },
      "required": [
        "type",
        "turn_id"
      ],
      "type": "object"
    }
  ],
  "title": "Worldtree Conversation API — SSE turn-stream events"
}
