{
  "openapi": "3.0.3",
  "info": {"title": "AI Deploy Agent API", "version": "0.1.0", "description": "项目专属部署口令。仅向管理员指定的平台发送口令。上传静态站 ZIP 或包含单个 Linux Docker 镜像的 ZIP。服务器不构建源码。"},
  "servers": [{"url": "https://deploy.2158.net"}],
  "security": [{"DeployToken": []}],
  "paths": {
    "/api/projects/{project}/deployments": {
      "post": {
        "operationId": "uploadDeployment",
        "summary": "上传发布包并创建持久化任务",
        "description": "根清单 deploy.json。静态：kind=static, spa=boolean，公开文件在 site/ 下且含 index.html。后端：kind=container, port=1024..65535, health=/health，另含 image.tar.gz（docker save 单镜像 gzip）；根目录不得有其他文件。最多300MiB，解压内容及镜像层另有限额。相同项目和幂等键重试返回原任务，不重复扣次数；同一幂等键对应不同SHA会409。已接收任务即消耗一次授权，失败也计次。",
        "parameters": [
          {"name":"project","in":"path","required":true,"schema":{"type":"string","pattern":"^[a-f0-9]{24}$"}},
          {"name":"X-Artifact-SHA256","in":"header","required":true,"schema":{"type":"string","pattern":"^[a-f0-9]{64}$"}},
          {"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":8,"maxLength":80},"description":"建议UUID；同一请求重试保持不变"}
        ],
        "requestBody":{"required":true,"content":{"application/zip":{"schema":{"type":"string","format":"binary"}}}},
        "responses":{
          "202":{"description":"已接收，按id查询状态","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},
          "200":{"description":"同一幂等请求已有任务","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},
          "400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},
          "409":{"$ref":"#/components/responses/Error"},"413":{"$ref":"#/components/responses/Error"},
          "429":{"$ref":"#/components/responses/Error"},"507":{"$ref":"#/components/responses/Error"}
        }
      }
    },
    "/api/jobs/{id}": {
      "get": {
        "operationId":"getDeployment","summary":"查询部署进度与结果",
        "description":"每3秒查询直到succeeded或failed；次数耗尽后仍可查询，口令到期或撤销则失效。仅能查询该口令所属项目。只有succeeded代表入口和证书配置完成。",
        "parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","pattern":"^[a-f0-9]{24}$"}}],
        "responses":{"200":{"description":"任务状态","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}
      }
    },
    "/health":{"get":{"operationId":"platformHealth","security":[],"responses":{"200":{"description":"控制API可用，不代表worker、证书或全部应用均健康"}}}}
  },
  "components": {
    "securitySchemes":{"DeployToken":{"type":"http","scheme":"bearer","description":"管理员生成的aideploy_前缀口令，通过环境变量注入，不使用查询参数"}},
    "schemas":{"Job":{"type":"object","required":["id","status"],"properties":{"id":{"type":"string"},"project":{"type":"string"},"status":{"type":"string","enum":["queued","running","succeeded","failed"]},"phase":{"type":"string"},"url":{"type":"string","format":"uri"},"error":{"type":"string","nullable":true},"created":{"type":"number"},"action":{"type":"string"},"sha256":{"type":"string","nullable":true}}},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}},
    "responses":{"Error":{"description":"请求失败；429可有界重试，其他错误先修正原因","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}
  }
}
