{
  "openapi": "3.1.0",
  "info": {
    "title": "SybilSight Local Integration API",
    "version": "1.0",
    "description": "Loopback API for querying and controlling the SybilSight iOS app. The listener is available at 127.0.0.1 while the app process is active."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8766",
      "description": "SybilSight on-device loopback server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Check local API health",
        "security": [],
        "responses": {
          "200": {
            "description": "API health and version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiscoveryStub"
                }
              }
            }
          }
        }
      }
    },
    "/.well-known/sybilsight-api": {
      "get": {
        "summary": "Discover the local SybilSight API",
        "security": [],
        "responses": {
          "200": {
            "description": "Local discovery document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiscoveryStub"
                }
              }
            }
          }
        }
      }
    },
    "/v1": {
      "get": {
        "summary": "Discover all Integration API capabilities",
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "summary": "Discover all Integration API capabilities",
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/query/{resource}": {
      "get": {
        "summary": "Query any SybilSight resource",
        "parameters": [
          {
            "name": "resource",
            "in": "path",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/ResourceName"
            }
          },
          {
            "name": "requestId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/actions/{action}": {
      "post": {
        "summary": "Perform any SybilSight action",
        "parameters": [
          {
            "name": "action",
            "in": "path",
            "required": true,
            "description": "Use the dot name or replace dots with slashes in the path.",
            "schema": {
              "$ref": "#/components/schemas/ActionName"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/components/schemas/IntegrationValue"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/requests": {
      "post": {
        "summary": "Execute a universal Integration API request",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IntegrationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/schedules": {
      "get": {
        "summary": "List scheduled actions",
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      },
      "post": {
        "summary": "Create a scheduled action",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScheduleInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/v1/schedules/{id}": {
      "delete": {
        "summary": "Delete a scheduled action",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationID"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/v1/schedules/{id}/run": {
      "post": {
        "summary": "Run a scheduled action now",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationID"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/v1/polls": {
      "get": {
        "summary": "List automated polls",
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      },
      "post": {
        "summary": "Create an automated resource poll",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PollInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/v1/polls/{id}": {
      "delete": {
        "summary": "Delete an automated poll",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationID"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/v1/polls/{id}/run": {
      "post": {
        "summary": "Run an automated poll now",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationID"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/IntegrationResponse"
          },
          "400": {
            "$ref": "#/components/responses/IntegrationResponse"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "summary": "Call the local MCP Streamable HTTP endpoint",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jsonrpc",
                  "method"
                ],
                "properties": {
                  "jsonrpc": {
                    "const": "2.0"
                  },
                  "id": {},
                  "method": {
                    "type": "string"
                  },
                  "params": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "MCP JSON-RPC result"
          },
          "204": {
            "description": "Accepted MCP notification"
          }
        }
      }
    }
  },
  "webhooks": {
    "integrationCallback": {
      "post": {
        "summary": "Universal response delivered to callbackURL",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IntegrationResponse"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Callback accepted"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Token returned by the locally authenticated Get Integration API Token App Intent."
      }
    },
    "parameters": {
      "AutomationID": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "responses": {
      "IntegrationResponse": {
        "description": "Universal Integration API response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/IntegrationResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid Integration API bearer token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    },
    "schemas": {
      "DiscoveryStub": {
        "type": "object",
        "required": [
          "name",
          "apiVersion",
          "local",
          "authentication"
        ],
        "properties": {
          "name": {
            "const": "SybilSight Integration API"
          },
          "apiVersion": {
            "const": "1.0"
          },
          "local": {
            "const": true
          },
          "authentication": {
            "const": "Bearer"
          }
        }
      },
      "IntegrationValue": {
        "description": "Any JSON value.",
        "oneOf": [
          {
            "type": "null"
          },
          {
            "type": "boolean"
          },
          {
            "type": "number"
          },
          {
            "type": "string"
          },
          {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          },
          {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          }
        ]
      },
      "ResourceName": {
        "type": "string",
        "enum": [
          "capabilities",
          "status",
          "apps",
          "running-apps",
          "shows",
          "current-show",
          "routines",
          "current-routine",
          "lists",
          "quicklist",
          "variables",
          "queues",
          "peek-queue",
          "tasks",
          "settings",
          "devices",
          "captions",
          "gallery",
          "integrations",
          "schedules",
          "polls",
          "callbacks",
          "navigation",
          "events"
        ]
      },
      "ActionName": {
        "type": "string",
        "enum": [
          "app.start",
          "app.stop",
          "app.foreground",
          "app.hide",
          "app.show",
          "app.display-access",
          "show.open",
          "show.close",
          "show.control",
          "routine.start",
          "routine.stop",
          "routine.rearm",
          "routine.enable",
          "routine.branch",
          "routine.reveal",
          "quicklist.add",
          "quicklist.rename",
          "quicklist.toggle",
          "quicklist.remove",
          "quicklist.clear",
          "quicklist.present",
          "variable.set",
          "variable.delete",
          "variable.clear",
          "queue.enqueue",
          "queue.load",
          "queue.select",
          "queue.next",
          "queue.previous",
          "queue.clear",
          "peek.text",
          "peek.clear",
          "captions.start",
          "captions.stop",
          "captions.search",
          "translation.set",
          "status-bar.set",
          "status-bar.template",
          "glasses.connect",
          "glasses.disconnect",
          "glasses.brightness",
          "assistant.ask",
          "assistant.activate",
          "recording.set",
          "display.reveal",
          "display.notify",
          "display.clear",
          "camera.start",
          "navigation.open",
          "settings.set",
          "callback.test",
          "schedule.create",
          "schedule.delete",
          "schedule.run",
          "poll.create",
          "poll.delete",
          "poll.run"
        ]
      },
      "IntegrationRequest": {
        "type": "object",
        "required": [
          "method"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "method": {
            "type": "string",
            "enum": [
              "discover",
              "query",
              "action",
              "schedule",
              "poll",
              "subscribe",
              "unsubscribe",
              "schedule.create",
              "schedule.delete",
              "schedule.run",
              "poll.create",
              "poll.delete",
              "poll.run"
            ]
          },
          "resource": {
            "$ref": "#/components/schemas/ResourceName"
          },
          "action": {
            "$ref": "#/components/schemas/ActionName"
          },
          "parameters": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          },
          "callbackURL": {
            "type": "string",
            "format": "uri"
          },
          "callbackHeaders": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "IntegrationError": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          }
        }
      },
      "IntegrationResponse": {
        "type": "object",
        "required": [
          "type",
          "requestId",
          "ok",
          "timestamp"
        ],
        "properties": {
          "type": {
            "const": "integration_response"
          },
          "requestId": {
            "type": "string"
          },
          "ok": {
            "type": "boolean"
          },
          "result": {
            "$ref": "#/components/schemas/IntegrationValue"
          },
          "error": {
            "$ref": "#/components/schemas/IntegrationError"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": [
          "ok",
          "error"
        ],
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "$ref": "#/components/schemas/IntegrationError"
          }
        }
      },
      "ScheduleInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "action": {
            "$ref": "#/components/schemas/ActionName"
          },
          "request": {
            "$ref": "#/components/schemas/IntegrationRequest"
          },
          "parameters": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          },
          "runAt": {
            "type": "string",
            "format": "date-time"
          },
          "intervalSeconds": {
            "type": "number",
            "minimum": 0
          },
          "repeatCount": {
            "type": "integer",
            "minimum": 0
          },
          "callbackURL": {
            "type": "string",
            "format": "uri"
          },
          "callbackHeaders": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "PollInput": {
        "type": "object",
        "required": [
          "resource",
          "intervalSeconds"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "resource": {
            "$ref": "#/components/schemas/ResourceName"
          },
          "parameters": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/IntegrationValue"
            }
          },
          "intervalSeconds": {
            "type": "number",
            "minimum": 1
          },
          "changedOnly": {
            "type": "boolean",
            "default": false
          },
          "callbackURL": {
            "type": "string",
            "format": "uri"
          },
          "callbackHeaders": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "x-sybilsight-websocket": {
    "url": "ws://127.0.0.1:8766/v1/ws?token={integrationApiToken}",
    "requestSchema": {
      "$ref": "#/components/schemas/IntegrationRequest"
    },
    "responseSchema": {
      "$ref": "#/components/schemas/IntegrationResponse"
    }
  },
  "x-sybilsight-mcp": {
    "url": "http://127.0.0.1:8766/mcp",
    "protocolVersion": "2025-06-18",
    "tools": [
      "sybilsight_capabilities",
      "sybilsight_query",
      "sybilsight_action",
      "sybilsight_schedule",
      "sybilsight_poll"
    ]
  }
}
