{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/andrewhuot/headless-chat-sdk/schemas/events.schema.json",
  "title": "TransportEvent",
  "description": "Discriminated union of SDK transport events. Mirrors packages/gecx-chat/src/messages/types.ts.",
  "definitions": {
    "Base": {
      "type": "object",
      "required": ["type", "requestId", "timestamp"],
      "properties": {
        "type": { "type": "string" },
        "requestId": { "type": "string" },
        "correlationId": { "type": "string" },
        "timestamp": { "type": "string", "format": "date-time" },
        "sequence": { "type": "integer", "minimum": 0, "description": "Monotonic per-responseId sequence used by the recovery loop to de-dupe redelivered frames. See docs/internal/transport-and-recovery-contract.md §4." }
      }
    }
  },
  "oneOf": [
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId"], "properties": { "type": { "const": "response.started" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "delta"], "properties": { "type": { "const": "text.delta" }, "delta": { "type": "string" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "text"], "properties": { "type": { "const": "text.completed" }, "text": { "type": "string" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "payloadType", "data"], "properties": { "type": { "const": "rich.payload" }, "payloadType": { "type": "string" }, "payloadVersion": { "type": "integer", "minimum": 1 }, "data": { "type": "object" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "toolCallId", "toolName", "input"], "properties": { "type": { "const": "tool.call" }, "toolCallId": { "type": "string" }, "toolName": { "type": "string" }, "input": { "type": "object" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "toolCallId", "output"], "properties": { "type": { "const": "tool.result" }, "toolCallId": { "type": "string" }, "output": { "type": "object" }, "error": { "type": "string" }, "status": { "type": "string", "enum": ["requested", "awaiting_approval", "pending_supervisor", "async_pending", "approved", "denied", "executing", "completed", "failed", "timed_out", "duplicate"] }, "idempotencyKey": { "type": "string" }, "duplicateDisposition": { "type": "string", "enum": ["replayed", "rejected", "conflict"] }, "approvalPolicy": { "type": "string", "enum": ["auto", "user_confirm", "supervisor_approve", "denied", "async_pending"] }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "title", "url"], "properties": { "type": { "const": "citation" }, "title": { "type": "string" }, "url": { "type": "string", "format": "uri" }, "snippet": { "type": "string" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "chips"], "properties": { "type": { "const": "suggestion.chips" }, "chips": { "type": "array" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "status"], "properties": { "type": { "const": "handoff.status" }, "status": { "type": "string" }, "transferType": { "type": "string", "enum": ["bot_to_human", "human_to_human", "supervisor_consult", "blind", "warm", "bot_to_bot"] }, "targetAgent": { "type": "string" }, "reason": { "type": "string" }, "queuePosition": { "type": "integer" }, "estimatedWaitTime": { "type": "string" }, "estimatedWaitMs": { "type": "integer" }, "failureReason": { "type": "string" }, "warmContext": { "type": "object" }, "voice": { "type": "object" }, "bundleId": { "type": "string" }, "routeDecision": { "type": "object" }, "graphPath": { "type": "array", "items": { "type": "string" } }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "category", "message"], "properties": { "type": { "const": "diagnostic" }, "category": { "type": "string" }, "message": { "type": "string" }, "details": { "type": "object" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["code", "message"], "properties": { "type": { "const": "error" }, "code": { "type": "string" }, "message": { "type": "string" }, "retryable": { "type": "boolean" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId", "signal", "source", "adapter"], "properties": { "type": { "const": "signal.update" }, "responseId": { "type": "string" }, "source": { "type": "string", "enum": ["model", "local", "server", "rule"] }, "adapter": { "type": "string" }, "scope": { "type": "string", "enum": ["message", "turn", "session"] }, "attributedMessageId": { "type": "string" }, "latencyMs": { "type": "number", "minimum": 0 }, "signal": { "oneOf": [ { "type": "object", "required": ["kind", "category", "score", "confidence"], "properties": { "kind": { "const": "sentiment" }, "category": { "type": "string", "enum": ["frustration", "anger", "confusion", "urgency", "satisfaction", "delight", "neutral"] }, "score": { "type": "number", "minimum": 0, "maximum": 1 }, "confidence": { "type": "number", "minimum": 0, "maximum": 1 }, "polarity": { "type": "string", "enum": ["positive", "neutral", "negative", "mixed"] } } }, { "type": "object", "required": ["kind", "intent", "score", "confidence"], "properties": { "kind": { "const": "intent" }, "intent": { "type": "string" }, "score": { "type": "number", "minimum": 0, "maximum": 1 }, "confidence": { "type": "number", "minimum": 0, "maximum": 1 }, "alternates": { "type": "array", "items": { "type": "object", "required": ["intent", "score"], "properties": { "intent": { "type": "string" }, "score": { "type": "number", "minimum": 0, "maximum": 1 } } } } } } ] } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["responseId"], "properties": { "type": { "const": "response.completed" }, "responseId": { "type": "string" } } } ] },
    { "allOf": [ { "$ref": "#/definitions/Base" }, { "type": "object", "required": ["reason"], "properties": { "type": { "const": "session.ended" }, "reason": { "type": "string" }, "responseId": { "type": "string" } } } ] }
  ]
}
