{
  "openapi": "3.1.0",
  "info": {
    "title": "秩一宣发｜AI-Native 文案宪法与审校平台 API",
    "version": "1.1.0",
    "description": "面向外部 AI Agent 与人类审校工作台的统一 HTTP 接口（含用户登录、个人 Agent API Key、SQLite 数据库与历史审计事件）。"
  },
  "servers": [
    {
      "url": "https://studio.z1x-ai.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "在工作台「账号与 Agent Key」面板生成的个人密钥（z1x_...）"
      },
      "SessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "z1x_session"
      }
    }
  },
  "paths": {
    "/llms.txt": {
      "get": {
        "summary": "获取 AI Agent 启动说明（Markdown）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/spec": {
      "get": {
        "summary": "获取字数、时长、占比与评分计算公式规范",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/auth/status": {
      "get": {
        "summary": "获取当前登录用户、是否需初始化管理员与数据库统计",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/auth/register": {
      "post": {
        "summary": "注册账号（首个账号自动成为 admin）",
        "responses": {
          "201": {
            "description": "注册并登录成功"
          }
        }
      }
    },
    "/api/auth/login": {
      "post": {
        "summary": "用户名密码登录，签发 HttpOnly 会话 Cookie",
        "responses": {
          "200": {
            "description": "登录成功"
          }
        }
      }
    },
    "/api/auth/logout": {
      "post": {
        "summary": "登出并吊销当前会话",
        "responses": {
          "200": {
            "description": "已登出"
          }
        }
      }
    },
    "/api/auth/me": {
      "get": {
        "summary": "获取当前认证用户身份",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "未登录"
          }
        }
      }
    },
    "/api/auth/change-password": {
      "post": {
        "summary": "修改当前登录用户密码",
        "responses": {
          "200": {
            "description": "修改成功"
          }
        }
      }
    },
    "/api/auth/api-keys": {
      "get": {
        "summary": "列出当前用户的 Agent API Keys",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "生成新的个人 Agent API Key（明文仅返回一次）",
        "responses": {
          "201": {
            "description": "创建成功"
          }
        }
      }
    },
    "/api/auth/api-keys/{keyId}": {
      "delete": {
        "summary": "吊销指定 Agent API Key",
        "responses": {
          "200": {
            "description": "已吊销"
          }
        }
      }
    },
    "/api/users": {
      "get": {
        "summary": "（管理员）列出团队全部用户",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "（管理员）新建团队成员账号",
        "responses": {
          "201": {
            "description": "创建成功"
          }
        }
      }
    },
    "/api/users/{userId}": {
      "put": {
        "summary": "（管理员）修改用户角色、启用状态或重置密码",
        "responses": {
          "200": {
            "description": "更新成功"
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "summary": "查询历史审计事件流（支持 eventType/resourceType/resourceId/limit/offset）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/lint-runs": {
      "get": {
        "summary": "查询历史文案体检记录与得分趋势",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/revisions/constitutions": {
      "get": {
        "summary": "查询宪法历史版本快照",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/revisions/constitutions/{revId}/restore": {
      "post": {
        "summary": "回滚到指定历史宪法版本",
        "responses": {
          "200": {
            "description": "回滚成功"
          }
        }
      }
    },
    "/api/revisions/workflows": {
      "get": {
        "summary": "查询节点画布历史版本快照",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/revisions/workflows/{revId}/restore": {
      "post": {
        "summary": "回滚到指定历史画布版本",
        "responses": {
          "200": {
            "description": "回滚成功"
          }
        }
      }
    },
    "/api/constitutions": {
      "get": {
        "summary": "获取全局宪法与全部项目宪法",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "新建项目群专属宪法",
        "responses": {
          "201": {
            "description": "创建成功"
          }
        }
      }
    },
    "/api/constitutions/{projectId}": {
      "get": {
        "summary": "读取指定项目宪法（传 global 读取全局宪法）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "put": {
        "summary": "更新宪法并自动写入历史快照",
        "responses": {
          "200": {
            "description": "更新成功"
          }
        }
      }
    },
    "/api/lint": {
      "post": {
        "summary": "对口播文稿执行宪法品味与结构占比体检（自动按画布拓扑执行并记入 lint_runs）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "projectId"
                ],
                "properties": {
                  "projectId": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "body": {
                    "type": "string"
                  },
                  "raw": {
                    "type": "string"
                  },
                  "draftId": {
                    "type": "string"
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "ui",
                      "api",
                      "agent"
                    ]
                  },
                  "projectOverride": {
                    "type": "object"
                  },
                  "globalOverride": {
                    "type": "object"
                  },
                  "workflowOverride": {
                    "type": "object",
                    "description": "可选：临时传入节点画布拓扑 JSON，后端按蓝线+紫线真拓扑执行"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "返回 report + handoffText + revisePrompt + lintRunId"
          }
        }
      }
    },
    "/api/drafts": {
      "get": {
        "summary": "列出团队共享稿件库（SQLite）",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "提交新稿件到共享审校台并返回 reviewUrl",
        "responses": {
          "201": {
            "description": "创建成功"
          }
        }
      }
    },
    "/api/drafts/{draftId}": {
      "get": {
        "summary": "获取单篇稿件、最新体检报告与历史版本数",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "put": {
        "summary": "更新稿件正文或审批状态（approved 需 boss/admin 权限）",
        "responses": {
          "200": {
            "description": "更新成功"
          }
        }
      },
      "delete": {
        "summary": "删除指定稿件（需 boss/admin 权限）",
        "responses": {
          "200": {
            "description": "已删除"
          }
        }
      }
    },
    "/api/drafts/{draftId}/revisions": {
      "get": {
        "summary": "获取指定稿件的全部历史版本快照",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/workflows/{projectId}": {
      "get": {
        "summary": "读取该项目的节点式工作流画布 JSON",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "put": {
        "summary": "保存/更新节点画布拓扑并写入版本历史",
        "responses": {
          "200": {
            "description": "保存成功"
          }
        }
      },
      "delete": {
        "summary": "重置项目画布为默认预设",
        "responses": {
          "200": {
            "description": "已重置"
          }
        }
      }
    },
    "/api/workflows/{projectId}/merged-constitution": {
      "get": {
        "summary": "获取当前工作流紫色连线实时合成后的最终 Markdown 宪法",
        "responses": {
          "200": {
            "description": "Markdown 宪法"
          }
        }
      }
    }
  }
}