{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentcall.smartycode.com/schemas/agentcall-agui-ws-client-0.1.schema.json",
  "title": "AgentCall AG-UI WebSocket binding: client message (0.1) - public NFC/photo profile",
  "description": "Public AgentCall 0.1 NFC/photo profile generated from canonical contracts. Only the reviewed dependency closure is published; see the release manifest and /ext/agentcall-agui/0.1 for negotiation and semantic validation duties.",
  "type": "object",
  "required": [
    "type"
  ],
  "properties": {
    "type": {
      "type": "string",
      "maxLength": 64
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/sessionStart"
    },
    {
      "$ref": "#/$defs/userTurn"
    },
    {
      "$ref": "#/$defs/userObservation"
    },
    {
      "$ref": "#/$defs/audioTurnStart"
    },
    {
      "$ref": "#/$defs/audioTurnCommit"
    },
    {
      "$ref": "#/$defs/audioTurnCancel"
    },
    {
      "$ref": "#/$defs/responseCancel"
    },
    {
      "$ref": "#/$defs/sessionEnd"
    },
    {
      "$ref": "#/$defs/ack"
    }
  ],
  "$defs": {
    "sessionStart": {
      "type": "object",
      "required": [
        "type",
        "sessionId"
      ],
      "properties": {
        "type": {
          "const": "session.start"
        },
        "sessionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "resumeFromSequence": {
          "type": "integer",
          "minimum": 0,
          "description": "Highest server sequence already processed. Meaningful only when the card declares agui.session.resume; servers without resume treat any value as 0."
        },
        "clientCapabilities": {
          "$ref": "#/$defs/clientCapabilities",
          "description": "Optional additive client capabilities. Agents request a client-owned physical action only after negotiating the matching modality."
        }
      }
    },
    "clientCapabilities": {
      "type": "object",
      "properties": {
        "physicalObservations": {
          "type": "object",
          "required": [
            "modalities"
          ],
          "properties": {
            "modalities": {
              "type": "array",
              "maxItems": 2,
              "uniqueItems": true,
              "items": {
                "enum": [
                  "nfc",
                  "photo"
                ]
              }
            }
          }
        },
        "audioTurnControl": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode"
          ],
          "properties": {
            "mode": {
              "const": "explicit"
            }
          },
          "description": "Session-scoped opt-in to explicit native-audio turns. Valid only when the card declared agui.webrtc.supportsExplicitTurns true."
        }
      }
    },
    "userTurn": {
      "type": "object",
      "required": [
        "type",
        "turn",
        "text"
      ],
      "properties": {
        "type": {
          "const": "user.turn"
        },
        "turn": {
          "type": "integer",
          "minimum": 1,
          "description": "Client-monotonic turn counter, starting at 1 per session."
        },
        "text": {
          "type": "string",
          "minLength": 1,
          "maxLength": 65536
        },
        "speechMetadata": {
          "$ref": "#/$defs/speechMetadata"
        },
        "context": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "$ref": "#/$defs/aguiContext"
          },
          "description": "AG-UI Context objects for this run/turn. Each item preserves the standard {description, value} string shape."
        }
      }
    },
    "userObservation": {
      "type": "object",
      "required": [
        "type",
        "turn",
        "observation"
      ],
      "properties": {
        "type": {
          "const": "user.observation"
        },
        "turn": {
          "type": "integer",
          "minimum": 1,
          "description": "Shares the client-monotonic turn counter with user.turn."
        },
        "interactionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "description": "When present, the observation answers the matching physical-action interaction."
        },
        "observation": {
          "$ref": "agentcall-physical-observation-0.1.schema.json"
        },
        "context": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "$ref": "#/$defs/aguiContext"
          }
        }
      }
    },
    "speechMetadata": {
      "type": "object",
      "description": "Optional local-recognition telemetry. Numeric metadata only; never raw audio.",
      "properties": {
        "recognitionEngine": {
          "type": "string",
          "maxLength": 64
        },
        "model": {
          "type": "string",
          "maxLength": 128
        },
        "localeIdentifier": {
          "type": "string",
          "maxLength": 32
        },
        "actionableRevisionMs": {
          "type": "integer",
          "minimum": 0
        },
        "stableFinalMs": {
          "type": "integer",
          "minimum": 0
        },
        "thermalState": {
          "type": "string",
          "maxLength": 32
        }
      }
    },
    "aguiContext": {
      "type": "object",
      "required": [
        "description",
        "value"
      ],
      "properties": {
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1024
        },
        "value": {
          "type": "string",
          "maxLength": 8192
        }
      },
      "description": "The standard AG-UI Context shape. Context is data supplied to the agent, not an instruction channel."
    },
    "audioTurnStart": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "turn"
      ],
      "properties": {
        "type": {
          "const": "audio.turn.start"
        },
        "turn": {
          "type": "integer",
          "minimum": 1
        }
      },
      "description": "Clears any uncommitted native audio and opens one correlated deliberate turn."
    },
    "audioTurnCommit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "turn"
      ],
      "properties": {
        "type": {
          "const": "audio.turn.commit"
        },
        "turn": {
          "type": "integer",
          "minimum": 1
        }
      },
      "description": "Commits the matching native-audio turn and requests agent processing immediately."
    },
    "audioTurnCancel": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "turn"
      ],
      "properties": {
        "type": {
          "const": "audio.turn.cancel"
        },
        "turn": {
          "type": "integer",
          "minimum": 1
        }
      },
      "description": "Discards the matching uncommitted native-audio turn without advancing the conversation."
    },
    "responseCancel": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "const": "response.cancel"
        }
      }
    },
    "sessionEnd": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "const": "session.end"
        }
      }
    },
    "ack": {
      "type": "object",
      "required": [
        "type",
        "sequence"
      ],
      "properties": {
        "type": {
          "const": "ack"
        },
        "sequence": {
          "type": "integer",
          "minimum": 1,
          "description": "Highest contiguous server sequence the client has durably processed. Servers without resume ignore acks."
        }
      }
    }
  }
}
