import { NextResponse } from "next/server"; export function GET(request: Request) { const origin = new URL(request.url).origin; return NextResponse.json({ openapi: "3.1.0", info: { title: "Rednote Content Studio API", version: "0.2.0", description: "小红书内容生成工作台的起步接口。项目是最高层级,每个项目保存一套共用的内容生成方法;写操作使用 revision 进行乐观并发控制。" }, servers: [{ url: origin }], security: [{ basicAuth: [] }], paths: { "/api/health": { get: { operationId: "health", summary: "无需认证的容器健康检查", security: [], responses: { "200": { description: "服务健康" } } } }, "/api/projects": { get: { operationId: "listProjects", summary: "列出项目", responses: { "200": { description: "项目列表" } } }, post: { operationId: "createProject", summary: "创建顶层内容项目", requestBody: { required: true, content: { "application/json": { schema: { type: "object", properties: { name: { type: "string" }, description: { type: "string" }, recipe: { $ref: "#/components/schemas/ProjectRecipe" } } } } } }, responses: { "201": { description: "已创建" } } }, }, "/api/projects/{id}": { get: { operationId: "getProject", summary: "读取项目与生成方法", parameters: [{ $ref: "#/components/parameters/ProjectId" }], responses: { "200": { description: "项目详情" } } }, put: { operationId: "updateProject", summary: "更新项目与生成方法", parameters: [{ $ref: "#/components/parameters/ProjectId" }], requestBody: { required: true, content: { "application/json": { schema: { type: "object", properties: { name: { type: "string" }, description: { type: "string" }, revision: { type: "integer" }, recipe: { $ref: "#/components/schemas/ProjectRecipe" } } } } } }, responses: { "200": { description: "已更新" }, "409": { description: "revision 冲突" } } }, }, "/api/projects/{id}/files/{path}": { get: { operationId: "readProjectFile", summary: "读取 UTF-8 源文件", parameters: [{ $ref: "#/components/parameters/ProjectId" }, { $ref: "#/components/parameters/FilePath" }], responses: { "200": { description: "文件内容" } } }, put: { operationId: "writeProjectFile", summary: "写入单个源文件", parameters: [{ $ref: "#/components/parameters/ProjectId" }, { $ref: "#/components/parameters/FilePath" }], requestBody: { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/FileWrite" } } } }, responses: { "200": { description: "已保存" }, "409": { description: "revision 冲突" } } }, }, "/api/projects/{id}/patch": { post: { operationId: "patchProjectFiles", summary: "原子地写入多个文件", parameters: [{ $ref: "#/components/parameters/ProjectId" }], requestBody: { required: true, content: { "application/json": { schema: { type: "object", required: ["revision", "changes"], properties: { revision: { type: "integer" }, changes: { type: "array", items: { type: "object", required: ["path", "content"], properties: { path: { type: "string" }, content: { type: "string" } } } } } } } } }, responses: { "200": { description: "已更新" }, "409": { description: "revision 冲突" } } } }, "/api/projects/{id}/build": { post: { operationId: "buildProject", summary: "构建 ES2017 / Chrome 61 离线产物", parameters: [{ $ref: "#/components/parameters/ProjectId" }], responses: { "200": { description: "构建结果和预览地址" } } } }, "/api/projects/{id}/dependencies/install": { post: { operationId: "installProjectDependencies", summary: "根据 package.json 安装项目依赖;禁用生命周期脚本", parameters: [{ $ref: "#/components/parameters/ProjectId" }], responses: { "200": { description: "安装日志" } } } }, "/api/projects/{id}/validate": { post: { operationId: "validateProject", summary: "构建并运行语义检查与 skill 审计", parameters: [{ $ref: "#/components/parameters/ProjectId" }], responses: { "200": { description: "结构化校验报告" } } } }, "/api/projects/{id}/package": { post: { operationId: "packageProject", summary: "校验并生成 ZIP", parameters: [{ $ref: "#/components/parameters/ProjectId" }], responses: { "200": { description: "校验报告和 artifactUrl;失败时不生成 ZIP" } } } }, "/api/projects/{id}/preview/{path}": { get: { operationId: "previewArtifact", summary: "读取预览产物", parameters: [{ $ref: "#/components/parameters/ProjectId" }, { $ref: "#/components/parameters/FilePath" }], responses: { "200": { description: "静态产物" } } } }, "/api/maintenance/cleanup": { post: { operationId: "cleanupIdleNodeModules", summary: "清理闲置项目 node_modules", requestBody: { content: { "application/json": { schema: { type: "object", properties: { idleHours: { type: "number", minimum: 0, default: 24 } } } } } }, responses: { "200": { description: "清理结果" } } } }, }, components: { securitySchemes: { basicAuth: { type: "http", scheme: "basic" } }, parameters: { ProjectId: { name: "id", in: "path", required: true, schema: { type: "string" } }, FilePath: { name: "path", in: "path", required: true, schema: { type: "string" }, description: "项目相对路径,例如 src/App.jsx" }, }, schemas: { ProjectRecipe: { type: "object", properties: { positioning: { type: "string" }, audience: { type: "string" }, tone: { type: "string" }, contentFormat: { type: "string" }, titleMethod: { type: "string" }, bodyStructure: { type: "string" }, defaultTags: { type: "array", items: { type: "string" } } } }, FileWrite: { type: "object", required: ["content", "revision"], properties: { content: { type: "string" }, revision: { type: "integer", description: "来自项目元数据的当前 revision" } } }, }, }, }); }