{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://super-calendar.io/agents/gateway.schema.json",
  "title": "Super Calendar Interaction Gateway",
  "description": "Request and response schema for deterministic guided agent/human interaction.",
  "type": "object",
  "$defs": {
    "request": {
      "type": "object",
      "required": [
        "intent"
      ],
      "properties": {
        "intent": {
          "type": "string",
          "description": "User or agent intent, such as create_feed, preview_feed, import_feed, read_io_field, or explain_capability."
        },
        "domain": {
          "type": "string"
        },
        "surface": {
          "type": "string"
        },
        "language": {
          "type": "string"
        },
        "direction": {
          "type": "string",
          "enum": [
            "ltr",
            "rtl",
            "auto"
          ]
        },
        "parameters": {
          "type": "object",
          "additionalProperties": true
        },
        "user_choices": {
          "type": "object",
          "additionalProperties": true
        },
        "privacy_context": {
          "type": "object",
          "properties": {
            "authenticated": {
              "type": "boolean"
            },
            "contains_private_data": {
              "type": "boolean"
            },
            "allow_private_link_in_response": {
              "type": "boolean",
              "default": false
            }
          },
          "additionalProperties": true
        },
        "client": {
          "type": "object",
          "properties": {
            "supports_mcp": {
              "type": "boolean"
            },
            "supports_webcal": {
              "type": "boolean"
            },
            "supports_json": {
              "type": "boolean"
            },
            "supports_io": {
              "type": "boolean"
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    },
    "option": {
      "type": "object",
      "required": [
        "id",
        "label",
        "kind"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "domain",
            "surface",
            "parameter",
            "action",
            "language",
            "error_recovery"
          ]
        },
        "description": {
          "type": "string"
        },
        "requires": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "next_state": {
          "type": "string"
        },
        "safe": {
          "type": "boolean",
          "default": true
        }
      },
      "additionalProperties": true
    },
    "action": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "preview",
            "copy_link",
            "import",
            "open_url",
            "call_http",
            "call_mcp",
            "read_io",
            "ask_user",
            "report_error"
          ]
        },
        "label": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "method": {
          "type": "string",
          "enum": [
            "GET",
            "POST",
            "PUT",
            "PATCH",
            "DELETE"
          ]
        },
        "body": {
          "type": "object",
          "additionalProperties": true
        },
        "requires_confirmation": {
          "type": "boolean",
          "default": false
        }
      },
      "additionalProperties": true
    },
    "response": {
      "type": "object",
      "required": [
        "status",
        "state"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "ok",
            "needs_input",
            "unsupported",
            "error"
          ]
        },
        "state": {
          "type": "string"
        },
        "intent": {
          "type": "string"
        },
        "domain": {
          "type": "string"
        },
        "surface": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/option"
          }
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/action"
          }
        },
        "missing_parameters": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "contracts_checked": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "error": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "safe_next_action": {
              "type": "string"
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/request"
    },
    {
      "$ref": "#/$defs/response"
    }
  ]
}
