{
  "openapi": "3.1.0",
  "info": {
    "title": "X-Pages Publishing API",
    "version": "2.2.1",
    "description": "X-Pages personal publishing with Feishu sign-in. New HTML and ZIP assets are stored in private COS; historical inline HTML remains readable from KV. New publication URLs use /app/{siteName}/. Legacy root HTML links remain available. Browser login completes authorization in the OAuth callback, with no second confirmation step."
  },
  "servers": [
    {
      "url": "/",
      "description": "Use the origin serving this document (production or HTTPS preview)."
    }
  ],
  "security": [
    {
      "adminToken": []
    },
    {
      "personalToken": []
    }
  ],
  "components": {
    "securitySchemes": {
      "adminToken": {
        "type": "apiKey",
        "in": "header",
        "name": "x-token",
        "description": "Administrator token; never publish in skill instructions."
      },
      "personalToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Opaque X-Pages credential issued after company Feishu sign-in."
      },
      "browserSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-xpages_session",
        "description": "30-day Secure HttpOnly browser session. Used only for profile, own applications and browser logout; never accepted by publishing endpoints."
      }
    }
  },
  "paths": {
    "/html/deploy": {
      "post": {
        "summary": "Publish HTML",
        "description": "Publish UTF-8 HTML to private COS and store its mapping in KV. The returned deployUrl uses /app/{siteName}/. Existing same-type sites are updated only by the owner or administrator. Legacy /{siteName} HTML links remain accessible.",
        "parameters": [
          {
            "name": "htmlkey",
            "in": "header",
            "required": false,
            "description": "Optional site ID; omitted on a new request to generate a UUID. For updates or later ZIP batches, reuse returned siteName. Requires ownership (or administrator access). A site with a recorded type cannot switch between HTML and ZIP. Reserved route names are rejected.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional at the API level; the client sends a stable key per request. With CloudBase, identical completed retries return the saved result without uploading; running operations or changed input return 409. Without this header, each request gets a new key and is not deduplicated.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}$"
            }
          },
          {
            "name": "title",
            "in": "header",
            "required": false,
            "description": "UTF-8 percent-encoded metadata",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "description",
            "in": "header",
            "required": false,
            "description": "UTF-8 percent-encoded metadata",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "text/html": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "siteName": {
                          "type": "string"
                        },
                        "deployUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "deployedAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "siteName",
                        "deployUrl"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks. For a personal caller, error=\"Legacy ownership import required\" means the administrator has not completed legacy ownership registration. Keep the existing login and pending request; retry after administration is complete.",
            "content": {
              "application/json": {
                "example": {
                  "error": "Legacy ownership import required",
                  "code": 503
                }
              }
            }
          }
        }
      }
    },
    "/html/deploy-zip": {
      "post": {
        "summary": "Publish a ZIP application",
        "description": "Publish ZIP assets into COS and store an app mapping in KV. Requires index.html or index.htm at the root, or inside a single enclosing directory stripped by the server. The bundled client sends batches of at most 8 files including the entry; this is a client batching policy, not a server file-count check. Batches are incremental and not an atomic whole-site replacement. Retain the returned siteName for every subsequent batch. URLs use /app/{siteName}/.",
        "parameters": [
          {
            "name": "htmlkey",
            "in": "header",
            "required": false,
            "description": "Optional site ID; omitted on a new request to generate a UUID. For updates or later ZIP batches, reuse returned siteName. Requires ownership (or administrator access). A site with a recorded type cannot switch between HTML and ZIP. Reserved route names are rejected.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional at the API level; the client sends a stable key per request. With CloudBase, identical completed retries return the saved result without uploading; running operations or changed input return 409. Without this header, each request gets a new key and is not deduplicated.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}$"
            }
          },
          {
            "name": "title",
            "in": "header",
            "required": false,
            "description": "UTF-8 percent-encoded metadata",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "description",
            "in": "header",
            "required": false,
            "description": "UTF-8 percent-encoded metadata",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-zip-encoding",
            "in": "header",
            "required": false,
            "description": "Omit for raw binary ZIP with Content-Type application/zip (recommended; used by the bundled client). Legacy Base64 requires base64 here and Content-Type text/plain, and is limited to 4 MiB decoded ZIP; larger Base64 requests return 413 with instructions to use binary. Do not use JSON, multipart or Content-Encoding: base64.",
            "schema": {
              "type": "string",
              "enum": [
                "base64"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/zip": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "text/plain": {
              "schema": {
                "type": "string",
                "contentEncoding": "base64"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "siteName": {
                          "type": "string"
                        },
                        "deployUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "deployedAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "siteName",
                        "deployUrl"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "415": {
            "description": "Multipart uploads are unsupported. Send raw ZIP bytes or Base64 text."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "500": {
            "description": "COS storage configuration is missing."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks. For a personal caller, error=\"Legacy ownership import required\" means the administrator has not completed legacy ownership registration. Keep the existing login and pending request; retry after administration is complete.",
            "content": {
              "application/json": {
                "example": {
                  "error": "Legacy ownership import required",
                  "code": 503
                }
              }
            }
          }
        }
      }
    },
    "/html/delete": {
      "delete": {
        "summary": "Delete a page owned by the caller (admin can delete any page)",
        "description": "Removes public KV mappings. Retains ownership tombstone; does not physically remove COS objects.",
        "parameters": [
          {
            "name": "siteName",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional at the API level; the client sends a stable key per request. With CloudBase, identical completed retries return the saved result without uploading; running operations or changed input return 409. Without this header, each request gets a new key and is not deduplicated.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks. For a personal caller, error=\"Legacy ownership import required\" means the administrator has not completed legacy ownership registration. Keep the existing login and pending request; retry after administration is complete.",
            "content": {
              "application/json": {
                "example": {
                  "error": "Legacy ownership import required",
                  "code": 503
                }
              }
            }
          }
        }
      }
    },
    "/auth/device": {
      "post": {
        "summary": "Start a tool login request",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "maxProperties": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "device_code": {
                      "type": "string"
                    },
                    "user_code": {
                      "type": "string"
                    },
                    "verification_uri": {
                      "type": "string",
                      "format": "uri"
                    },
                    "verification_uri_complete": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "interval": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "device_code",
                    "user_code",
                    "verification_uri_complete",
                    "expires_at",
                    "interval"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        },
        "description": "Creates a 10-minute login request. Keep device_code private; show verification_uri_complete and user_code to the user. The browser link and callback use the current request origin, which must be HTTPS and registered in the Feishu redirect allowlist. Successful Feishu login automatically authorizes this tool request; no /auth/confirm step is used."
      }
    },
    "/auth/token": {
      "post": {
        "summary": "Poll a login request after successful Feishu login",
        "description": "Keep device_code private. Poll no faster than every 5 seconds. X-Pages credentials last 30 days, with no automatic refresh. This is a private login bridge, not an advertised OAuth device-grant endpoint. The browser callback completes approval after checking OAuth state, the bound HttpOnly cookie and the returned identity. Browser cookies are not publishing credentials.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "device_code": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "device_code"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access_token": {
                      "type": "string"
                    },
                    "token_type": {
                      "const": "Bearer"
                    },
                    "user": {
                      "type": "object"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "access_token",
                    "token_type",
                    "user",
                    "expires_at"
                  ]
                }
              }
            }
          },
          "202": {
            "description": "authorization_pending: Feishu login has not completed. Poll no faster than the returned interval (5 seconds). No second browser confirmation is required."
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "410": {
            "description": "Login request expired; create another request"
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "summary": "Current user and credential expiry",
        "responses": {
          "200": {
            "description": "Success; Cache-Control: no-store.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "avatar_url": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "uri"
                        }
                      }
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        },
        "security": [
          {
            "adminToken": []
          },
          {
            "personalToken": []
          },
          {
            "browserSession": []
          }
        ],
        "description": "Reads the current profile including Feishu avatar. Explicit Authorization or x-token takes precedence over cookies. Browser and Agent sessions are separate."
      }
    },
    "/auth/logout": {
      "post": {
        "summary": "Revoke the current personal credential",
        "security": [
          {
            "personalToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        }
      }
    },
    "/auth/admin/import-legacy": {
      "post": {
        "summary": "Import one page of legacy KV identifiers as administrator-owned",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prefix": {
                    "type": "string",
                    "enum": [
                      "html:",
                      "html-cos:",
                      "app:"
                    ]
                  },
                  "cursor": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "prefix"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "count",
                    "complete",
                    "prefix"
                  ],
                  "properties": {
                    "count": {
                      "type": "integer",
                      "description": "Number of IDs scanned in this batch; not necessarily newly inserted."
                    },
                    "cursor": {
                      "type": "string",
                      "description": "Pass back unchanged for the next page when complete is false."
                    },
                    "complete": {
                      "type": "boolean"
                    },
                    "prefix": {
                      "type": "string",
                      "enum": [
                        "html:",
                        "html-cos:",
                        "app:"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        },
        "description": "Administrator-only write: scan one KV page for html:, html-cos: or app:, register IDs without a personal owner, and record html or zip type. Repeat with cursor until complete for all three prefixes. An ID with both HTML and ZIP records becomes legacy_mixed and remains administrator-only. Existing personal ownership and active operations are not overwritten. No KV/COS content or URL is changed. Does not mark the migration complete."
      }
    },
    "/auth/admin/enable-personal": {
      "post": {
        "summary": "Mark legacy import complete after all three prefixes have been fully scanned",
        "security": [
          {
            "adminToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, site name, metadata, encoding or archive."
          },
          "401": {
            "description": "Missing, expired or revoked credential. Sign in again only for an invalid personal credential."
          },
          "403": {
            "description": "Invalid administrator token, disabled user, or a page owned by another user. Signing in again does not grant ownership."
          },
          "409": {
            "description": "Conflicting or in-progress operation, reuse of an idempotency key with different input, or a change to a recorded page type. Preserve the original request for uncertain retries."
          },
          "413": {
            "description": "Request body or declared uncompressed ZIP size exceeds configured limits."
          },
          "429": {
            "description": "Too many login requests. Retry later."
          },
          "502": {
            "description": "Upstream failure. A publication may have partially written data; preserve the request and idempotency key."
          },
          "503": {
            "description": "Service configuration or dependency unavailable. Preserve the request; do not bypass ownership or operation locks."
          }
        },
        "description": "Administrator-only migration completion marker. Rejects any untyped registered sites; does not itself scan KV or verify coverage, and does not change XPAGES_PERSONAL_ENABLED. Verify all three prefixes against the serving namespace and ensure old publishers no longer bypass CloudBase before calling. Do not bypass the Legacy ownership import required check."
      }
    },
    "/auth/login": {
      "get": {
        "summary": "Browser login entry (also available at /auth and /auth/)",
        "security": [],
        "description": "Browser entry for an Agent device link. Until its 10-minute expiry and first successful completion, the original X-Pages URL can be opened repeatedly in different browsers; each attempt gets an independent state/cookie binding. A valid website session renders a same-origin auto-POST page to /auth/reuse; otherwise redirects to Feishu. No extra confirmation is needed. Share the original X-Pages link, not the redirected Feishu URL.",
        "parameters": [
          {
            "name": "user_code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Fa-f0-9]{8}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Code-entry form, or automatic session-reuse page for an already signed-in user."
          },
          "302": {
            "description": "Redirect to Feishu; preserve the browser cookie through the callback."
          },
          "400": {
            "description": "Invalid code or non-HTTPS request; HTML error page."
          },
          "410": {
            "description": "Login link expired or already opened; generate a new link."
          },
          "503": {
            "description": "Login configuration or backend unavailable; HTML error page."
          }
        }
      }
    },
    "/auth/callback": {
      "get": {
        "summary": "Feishu callback for Agent or website login",
        "security": [],
        "description": "Validates the one-use state and the matching browser-attempt cookie. Agent login atomically authorizes the device and creates a separate 30-day website session; its success page links to / and /my. Website login creates a session and redirects to /my or /. Only the first successful attempt can bind the device identity; parallel or repeated completions are rejected. Cookies and Agent credentials remain separate; no credentials appear in HTML or URLs.",
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "HTML page; never includes a personal credential.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "302": {
            "description": "Website login succeeded; sets browser session and clears binding cookie."
          },
          "400": {
            "description": "Missing/invalid callback state, code or browser cookie."
          },
          "403": {
            "description": "User is disabled."
          },
          "410": {
            "description": "Login request expired or already used; replay rejected."
          },
          "502": {
            "description": "Feishu request failed or did not return a complete identity."
          },
          "503": {
            "description": "Backend unavailable; authorization was not confirmed."
          }
        }
      }
    },
    "/app/{siteName}/": {
      "get": {
        "summary": "Read a published site (public)",
        "security": [],
        "description": "If app:{siteName} exists in KV, serves the COS ZIP entry. Otherwise serves the single HTML page via its html-cos:{siteName} mapping or, for historical pages, the inline KV record. With both legacy records present, ZIP takes precedence here and root /{siteName} still serves HTML. A missing trailing slash redirects to this URL. All content uses Cache-Control: no-store and checks site policy. Hidden/deleted sites return 404. Protected HTML shows an unlock form; child resources return 401 without a visitor cookie. Legacy root HTML uses the same policy. When requireLogin is enabled, application documents redirect to /auth/web/login with a safe return path; static resources return 401. Valid browser sessions of enabled users allow viewing. Password restrictions still apply after login; owner management permissions do not change.",
        "parameters": [
          {
            "name": "siteName",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "HTML page; never includes a personal credential.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Site or ZIP entry not found."
          },
          "401": {
            "description": "Access password required."
          },
          "503": {
            "description": "Policy store unavailable; access is not bypassed."
          },
          "302": {
            "description": "Visitor Feishu login required."
          }
        }
      }
    },
    "/app/{siteName}/{path}": {
      "get": {
        "summary": "Read an application asset (public)",
        "security": [],
        "description": "Reads the relative asset path from COS when an app mapping exists. For single HTML sites, only index.html/index.htm can alias the page; other asset paths return 404. All content uses Cache-Control: no-store and checks site policy. Hidden/deleted sites return 404. Protected HTML shows an unlock form; child resources return 401 without a visitor cookie. Legacy root HTML uses the same policy. When requireLogin is enabled, application documents redirect to /auth/web/login with a safe return path; static resources return 401. Valid browser sessions of enabled users allow viewing. Password restrictions still apply after login; owner management permissions do not change.",
        "parameters": [
          {
            "name": "siteName",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Relative resource path, possibly containing subdirectories.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resource bytes with the resource Content-Type."
          },
          "404": {
            "description": "Site or resource not found."
          },
          "401": {
            "description": "Access password required."
          },
          "503": {
            "description": "Policy store unavailable; access is not bypassed."
          },
          "302": {
            "description": "Visitor Feishu login required."
          }
        }
      }
    },
    "/auth/web/login": {
      "get": {
        "summary": "Sign into the website with Feishu",
        "security": [],
        "description": "Creates a 10-minute browser-bound OAuth state and redirects to Feishu. No tool verification code is needed. Uses the current HTTPS origin and the shared /auth/callback allowlisted in Feishu. If a valid website session already exists, redirects straight to the allowed local destination without starting OAuth.",
        "parameters": [
          {
            "in": "query",
            "name": "next",
            "schema": {
              "type": "string",
              "default": "/my",
              "maxLength": 2048
            },
            "description": "Same-origin /, /my or /app/{siteName}/... including query parameters. External or invalid destinations become /my."
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to Feishu and set the HttpOnly login binding cookie."
          },
          "400": {
            "description": "Invalid request or HTTPS required."
          },
          "401": {
            "description": "Browser session missing, expired or revoked."
          },
          "403": {
            "description": "Disabled user or unauthorized operation."
          },
          "429": {
            "description": "Too many login attempts."
          },
          "503": {
            "description": "Authentication configuration or database unavailable."
          }
        }
      }
    },
    "/auth/web/logout": {
      "post": {
        "summary": "Revoke the current browser session",
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Requires the custom X-XPages-Action header. If Origin is present it must match the request origin. Clears the browser cookie; does not revoke an Agent credential.",
        "parameters": [
          {
            "in": "header",
            "name": "X-XPages-Action",
            "required": true,
            "schema": {
              "type": "string",
              "const": "logout"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; Cache-Control: no-store.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or HTTPS required."
          },
          "401": {
            "description": "Browser session missing, expired or revoked."
          },
          "403": {
            "description": "Disabled user or unauthorized operation."
          },
          "503": {
            "description": "Authentication configuration or database unavailable."
          }
        }
      }
    },
    "/auth/sites": {
      "get": {
        "summary": "List applications published by the current user",
        "security": [
          {
            "personalToken": []
          },
          {
            "browserSession": []
          }
        ],
        "description": "Only the authenticated user’s successfully published, non-deleted applications. Sorted by latest successful update descending, then site ID descending. Failed updates preserve the last successful entry. Administrator tokens are rejected. No owner ID filter is accepted.",
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "in": "query",
            "name": "cursor",
            "schema": {
              "type": "string"
            },
            "description": "Opaque next_cursor from the previous response."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; Cache-Control: no-store.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items",
                    "next_cursor"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "siteName",
                          "title",
                          "kind",
                          "deployUrl",
                          "publishedAt",
                          "updatedAt",
                          "hidden",
                          "hasPassword"
                        ],
                        "properties": {
                          "siteName": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "html",
                              "zip"
                            ]
                          },
                          "deployUrl": {
                            "type": "string",
                            "format": "uri"
                          },
                          "publishedAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "hidden": {
                            "type": "boolean",
                            "description": "Paused for visitors; still included in the owner list."
                          },
                          "hasPassword": {
                            "type": "boolean",
                            "description": "Shared access password is configured; password is never returned."
                          },
                          "previewUrl": {
                            "type": "string",
                            "format": "uri",
                            "description": "Browser owner only: read-only sandboxed preview. Never share this URL."
                          },
                          "previewExpiresAt": {
                            "type": "integer",
                            "description": "Browser owner only: preview expiry as Unix milliseconds."
                          },
                          "requireLogin": {
                            "type": "boolean",
                            "description": "Visitors need a valid Feishu website session. Does not grant management rights."
                          }
                        }
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or HTTPS required."
          },
          "401": {
            "description": "Browser session missing, expired or revoked."
          },
          "403": {
            "description": "Disabled user or unauthorized operation."
          },
          "503": {
            "description": "Authentication configuration or database unavailable."
          }
        }
      }
    },
    "/my": {
      "get": {
        "summary": "My applications card page",
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Private no-store HTML portal with avatar and paginated app cards. Sandboxed lazy iframe previews do not permit same-origin access, top navigation or forms. Preview restrictions can affect applications that require cookies, storage or CORS; open the app to use it normally.",
        "responses": {
          "200": {
            "description": "HTML portal."
          },
          "302": {
            "description": "Sign-in required; redirects to /auth/web/login?next=/my."
          },
          "503": {
            "description": "Authentication or database unavailable."
          }
        }
      }
    },
    "/auth/reuse": {
      "post": {
        "summary": "Complete Agent authorization using the current website session",
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Browser-only form POST generated by /auth/login. Requires an exact same-origin Origin, valid website session and the attempt-specific HttpOnly binding cookie matching the hidden state. GET does not complete authorization. Atomically binds the current user only once; does not renew the existing website session. Returns the success HTML with homepage and My Applications links.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "state"
                ],
                "properties": {
                  "state": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authorization succeeded; return to the Agent or use / and /my links."
          },
          "400": {
            "description": "Invalid state or missing binding cookie."
          },
          "401": {
            "description": "Browser session expired, revoked or missing."
          },
          "403": {
            "description": "Wrong Origin or disabled account."
          },
          "410": {
            "description": "Request expired or already completed."
          },
          "503": {
            "description": "Backend unavailable; do not bypass checks."
          }
        }
      }
    },
    "/auth/sites/manage": {
      "post": {
        "summary": "Manage your own published application",
        "security": [
          {
            "personalToken": []
          },
          {
            "browserSession": []
          }
        ],
        "description": "Manage only applications owned by the caller. Accepts a personal Feishu-issued Bearer credential, or a browser session with exact same-origin Origin and X-XPages-Action: manage. Explicit invalid credentials never fall back to a browser session; administrator tokens are rejected. Send exactly one of hidden, requireLogin (boolean), password (6–128 characters or null to clear), or delete:true. Settings survive redeployment. Access policy is enforced by the application. Management never calls COS or changes ACLs; deletion retains ownership and COS files. COS must have a fixed private-read configuration to prevent direct-URL bypass. Reuse Idempotency-Key after network errors.",
        "parameters": [
          {
            "in": "header",
            "name": "X-XPages-Action",
            "required": false,
            "schema": {
              "const": "manage"
            },
            "description": "Required only for browser-session requests, together with a same-origin Origin header. Not required for personal Bearer requests."
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "siteName"
                ],
                "additionalProperties": false,
                "properties": {
                  "siteName": {
                    "type": "string"
                  },
                  "hidden": {
                    "type": "boolean"
                  },
                  "password": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "minLength": 6,
                    "maxLength": 128
                  },
                  "delete": {
                    "const": true
                  },
                  "requireLogin": {
                    "type": "boolean",
                    "description": "Require visitor Feishu website login. False removes only this requirement; hidden and password settings are preserved."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved or idempotent result replayed."
          },
          "400": {
            "description": "Invalid setting; change one field at a time."
          },
          "401": {
            "description": "Personal credential or browser session is missing, expired or revoked."
          },
          "403": {
            "description": "Not the owner, administrator token supplied, or invalid browser origin."
          },
          "409": {
            "description": "Operation in progress or request ID reused with different data."
          },
          "503": {
            "description": "Storage unavailable."
          }
        }
      }
    },
    "/auth/access": {
      "post": {
        "summary": "Unlock a password-protected application",
        "security": [],
        "description": "HTTPS same-origin visitor form; no Feishu login required. Issues an HttpOnly Secure 24-hour cookie bound to the site and current policy version. Up to 10 attempts per site/IP per 10 minutes. Hidden/deleted sites cannot be unlocked.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "siteName",
                  "password"
                ],
                "properties": {
                  "siteName": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  },
                  "next": {
                    "type": "string",
                    "description": "Same-site /app/{siteName}/... or legacy /{siteName} return path."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "303": {
            "description": "Unlocked; redirect to requested site."
          },
          "401": {
            "description": "Invalid password."
          },
          "403": {
            "description": "Invalid origin."
          },
          "404": {
            "description": "Hidden or deleted."
          },
          "409": {
            "description": "Policy changed; retry."
          },
          "429": {
            "description": "Too many attempts."
          }
        }
      }
    },
    "/auth/sites/preview": {
      "get": {
        "summary": "Renew an owner-only preview",
        "description": "Browser session only. Returns a read-only sandboxed preview URL valid for 15 minutes. Every preview request rechecks the active owner session. Never use this URL for sharing.",
        "parameters": [
          {
            "name": "siteName",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Preview grant"
          },
          "401": {
            "description": "Browser login required"
          },
          "404": {
            "description": "Site not owned by the current active user"
          }
        }
      }
    },
    "/auth/sites/password": {
      "get": {
        "summary": "Read the current access password as the application owner",
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Browser-only, owner-only request with X-XPages-Action: password. An Origin header, if present, must match the request origin. Bearer and administrator credentials are rejected. The enabled owner must have a valid website session and the application must be published and not deleted; hidden applications are supported. Returns Cache-Control: no-store. New passwords are stored as AES-GCM ciphertext and decrypted only here. Historical hash-only passwords return hasPassword:true, recoverable:false, password:null and require resetting once. No password or ciphertext appears in application lists or public access responses.",
        "parameters": [
          {
            "in": "query",
            "name": "siteName",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-XPages-Action",
            "required": true,
            "schema": {
              "const": "password"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Owner password state; plaintext only when recoverable.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "hasPassword",
                    "recoverable",
                    "password"
                  ],
                  "properties": {
                    "hasPassword": {
                      "type": "boolean"
                    },
                    "recoverable": {
                      "type": "boolean"
                    },
                    "password": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Browser session missing, expired or revoked."
          },
          "403": {
            "description": "Invalid request origin, unsupported credential or disabled user."
          },
          "404": {
            "description": "Application unavailable or not owned by this user."
          },
          "503": {
            "description": "Encrypted password cannot be read; existing visitor password verification remains separate."
          }
        }
      }
    }
  }
}
