{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Voice API UAT realtime protocol",
  "definitions": {
    "client": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "text.input"
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000
            }
          },
          "required": [
            "type",
            "text"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "session.start"
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "session.end"
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "audio.commit"
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "audio.interrupt"
            },
            "itemId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000
            },
            "playedMs": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "audio.append"
            },
            "audio": {
              "type": "string",
              "maxLength": 64000,
              "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
            }
          },
          "required": [
            "type",
            "audio"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "tool.result"
            },
            "actionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000
            },
            "status": {
              "enum": [
                "rejected",
                "completed",
                "failed"
              ]
            },
            "message": {
              "type": "string",
              "maxLength": 2000
            }
          },
          "required": [
            "type",
            "actionId",
            "status"
          ],
          "additionalProperties": false
        }
      ]
    },
    "server": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "session.started"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "tenantId": {
              "type": "string"
            },
            "agentId": {
              "type": "string"
            },
            "mode": {
              "enum": [
                "voice",
                "transcription"
              ]
            },
            "status": {
              "const": "ready"
            },
            "audioFormat": {
              "type": "object",
              "properties": {
                "encoding": {
                  "const": "pcm16le"
                },
                "channels": {
                  "const": 1
                },
                "sampleRate": {
                  "const": 24000
                }
              },
              "required": [
                "encoding",
                "channels",
                "sampleRate"
              ],
              "additionalProperties": false
            },
            "websocketPath": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "id",
            "tenantId",
            "agentId",
            "mode",
            "status",
            "audioFormat",
            "websocketPath"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "audio.delta"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "audio": {
              "type": "string"
            },
            "itemId": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "audio"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "audio.clear"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "transcript.partial"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "text": {
              "type": "string"
            },
            "itemId": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "text"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "transcript.final"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "text": {
              "type": "string"
            },
            "itemId": {
              "type": "string"
            },
            "startedAt": {
              "type": "string",
              "format": "date-time"
            },
            "endedAt": {
              "type": "string",
              "format": "date-time"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "text",
            "endedAt"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "agent.text"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "text"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "agent.done"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "status": {
              "enum": [
                "completed",
                "failed",
                "incomplete",
                "cancelled"
              ]
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "status"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "tool.request"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "actionId": {
              "type": "string"
            },
            "status": {
              "const": "requested"
            },
            "name": {
              "enum": [
                "call.requestTransfer",
                "call.requestCallback"
              ]
            },
            "tenantId": {
              "type": "string"
            },
            "payload": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "targetType": {
                      "enum": [
                        "extension",
                        "number"
                      ]
                    },
                    "target": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "targetType",
                    "target"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "callerName": {
                      "type": "string"
                    },
                    "callerNumber": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "for": {
                      "type": "string"
                    },
                    "priority": {
                      "enum": [
                        "low",
                        "normal",
                        "high"
                      ]
                    }
                  },
                  "required": [
                    "callerName",
                    "callerNumber",
                    "message",
                    "for",
                    "priority"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            "timeoutMs": {
              "const": 5000
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "actionId",
            "status",
            "name",
            "tenantId",
            "payload",
            "timeoutMs"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "tool.completed"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "actionId": {
              "type": "string"
            },
            "status": {
              "enum": [
                "rejected",
                "completed",
                "failed"
              ]
            },
            "message": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "actionId",
            "status",
            "message"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "session.error"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "requestId": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "message"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "error"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "const": "session.ended"
            },
            "sessionId": {
              "type": "string"
            },
            "callId": {
              "type": "string"
            },
            "reason": {
              "enum": [
                "completed",
                "media_disconnected",
                "SESSION_EXPIRED",
                "AI_UNAVAILABLE",
                "INTERNAL_ERROR"
              ]
            }
          },
          "required": [
            "type",
            "sessionId",
            "callId",
            "reason"
          ],
          "additionalProperties": false
        }
      ]
    }
  }
}
