[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6H89CBMP5R6SZNTQ7P2EHE6":3,"skill-same:01M6H89CBMP5R6SZNTQ7P2EHE6":83},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":41,"linkOnly":42,"markdownContent":43,"markdownBody":44,"frontMatter":45,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":49,"repositoryHtmlUrl":50,"repositoryHomepageUrl":6,"ownerHtmlUrl":51,"ownerBlogUrl":52,"ownerDescription":53,"updatedAt":54,"install":55,"resources":68},"01M6H89CBMP5R6SZNTQ7P2EHE6","api-designer",null,"Design RESTful and tRPC APIs with consistent patterns, error handling, and documentation. Define endpoint structure, response formats, and error codes. Use when designing APIs, creating endpoints, or when the user mentions API, endpoint, REST, tRPC, or response format.","rotifer-protocol\u002Frotifer-playground","rotifer-protocol","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F262854335?v=4","01M6H88XQBWNQXVGHBCGZZCQVX","Rotifer Protocol","01M6H88XVXE7GHR06H8E1SP311",6,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fgenes\u002Fapi-designer\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"api","designer","api designer","patterns","when","error codes","formats","with","trpc","designing apis","codes","error","define","structure","design","endpoints","use","user","format","REST","error handling","documentation","2026-11-10 10:12:30",false,"---\nname: api-designer\ndescription: Design RESTful and tRPC APIs with consistent patterns, error handling, and documentation. Define endpoint structure, response formats, and error codes. Use when designing APIs, creating endpoints, or when the user mentions API, endpoint, REST, tRPC, or response format.\n---\n\n# API Designer (API 设计师)\n\n**Goal**: 设计一致、可预测、易于使用的 API 接口。\n\n---\n\n## 1. RESTful API Design\n\n### URL 结构\n\n```\n# 资源命名 (名词复数)\nGET    \u002Fapi\u002Fusers           # 列表\nGET    \u002Fapi\u002Fusers\u002F:id       # 详情\nPOST   \u002Fapi\u002Fusers           # 创建\nPUT    \u002Fapi\u002Fusers\u002F:id       # 全量更新\nPATCH  \u002Fapi\u002Fusers\u002F:id       # 部分更新\nDELETE \u002Fapi\u002Fusers\u002F:id       # 删除\n\n# 嵌套资源\nGET    \u002Fapi\u002Fusers\u002F:id\u002Fposts\nPOST   \u002Fapi\u002Fusers\u002F:id\u002Fposts\n\n# 操作 (动词，仅在必要时)\nPOST   \u002Fapi\u002Fusers\u002F:id\u002Factivate\nPOST   \u002Fapi\u002Fchat\u002Fcompletions\n```\n\n### HTTP 方法语义\n\n| Method | 幂等 | 安全 | 用途 |\n|--------|------|------|------|\n| GET | ✅ | ✅ | 读取资源 |\n| POST | ❌ | ❌ | 创建资源\u002F执行操作 |\n| PUT | ✅ | ❌ | 全量替换 |\n| PATCH | ❌ | ❌ | 部分更新 |\n| DELETE | ✅ | ❌ | 删除资源 |\n\n### HTTP 状态码\n\n```typescript\n\u002F\u002F 成功\n200 OK              \u002F\u002F 通用成功\n201 Created         \u002F\u002F 创建成功\n204 No Content      \u002F\u002F 删除成功\n\n\u002F\u002F 客户端错误\n400 Bad Request     \u002F\u002F 请求格式错误\n401 Unauthorized    \u002F\u002F 未认证\n403 Forbidden       \u002F\u002F 无权限\n404 Not Found       \u002F\u002F 资源不存在\n409 Conflict        \u002F\u002F 冲突 (如重复创建)\n422 Unprocessable   \u002F\u002F 验证失败\n429 Too Many Reqs   \u002F\u002F 限流\n\n\u002F\u002F 服务端错误\n500 Internal Error  \u002F\u002F 服务器错误\n502 Bad Gateway     \u002F\u002F 上游错误\n503 Unavailable     \u002F\u002F 服务不可用\n```\n\n---\n\n## 2. Response Format\n\n### 成功响应\n\n```typescript\n\u002F\u002F 单个资源\n{\n  \"data\": {\n    \"id\": \"123\",\n    \"type\": \"user\",\n    \"attributes\": {\n      \"name\": \"张三\",\n      \"email\": \"zhang@example.com\"\n    }\n  }\n}\n\n\u002F\u002F 简化版 (推荐 OPC)\n{\n  \"id\": \"123\",\n  \"name\": \"张三\",\n  \"email\": \"zhang@example.com\"\n}\n```\n\n### 列表响应\n\n```typescript\n{\n  \"data\": [...],\n  \"pagination\": {\n    \"page\": 1,\n    \"pageSize\": 20,\n    \"total\": 100,\n    \"totalPages\": 5\n  }\n}\n```\n\n### 错误响应\n\n```typescript\n{\n  \"error\": {\n    \"code\": \"VALIDATION_ERROR\",\n    \"message\": \"请求参数验证失败\",\n    \"details\": [\n      { \"field\": \"email\", \"message\": \"邮箱格式不正确\" },\n      { \"field\": \"password\", \"message\": \"密码至少 8 位\" }\n    ]\n  }\n}\n```\n\n---\n\n## 3. Error Code System\n\n### 错误码设计\n\n```typescript\n\u002F\u002F types\u002Ferrors.ts\nexport const ERROR_CODES = {\n  \u002F\u002F 认证 (1xxx)\n  AUTH_REQUIRED: { code: 1001, status: 401, message: '请先登录' },\n  AUTH_EXPIRED: { code: 1002, status: 401, message: '登录已过期' },\n  AUTH_INVALID: { code: 1003, status: 401, message: '认证信息无效' },\n  \n  \u002F\u002F 权限 (2xxx)\n  FORBIDDEN: { code: 2001, status: 403, message: '无权限访问' },\n  \n  \u002F\u002F 资源 (3xxx)\n  NOT_FOUND: { code: 3001, status: 404, message: '资源不存在' },\n  ALREADY_EXISTS: { code: 3002, status: 409, message: '资源已存在' },\n  \n  \u002F\u002F 验证 (4xxx)\n  VALIDATION_ERROR: { code: 4001, status: 422, message: '参数验证失败' },\n  INVALID_FORMAT: { code: 4002, status: 400, message: '请求格式错误' },\n  \n  \u002F\u002F 限流 (5xxx)\n  RATE_LIMITED: { code: 5001, status: 429, message: '请求过于频繁' },\n  \n  \u002F\u002F AI 相关 (6xxx)\n  AI_TOKEN_LIMIT: { code: 6001, status: 400, message: 'Token 超出限制' },\n  AI_TIMEOUT: { code: 6002, status: 504, message: 'AI 响应超时' },\n  AI_UNAVAILABLE: { code: 6003, status: 503, message: 'AI 服务不可用' },\n  \n  \u002F\u002F Web3 相关 (7xxx)\n  WALLET_NOT_CONNECTED: { code: 7001, status: 400, message: '钱包未连接' },\n  INVALID_SIGNATURE: { code: 7002, status: 401, message: '签名验证失败' },\n  INSUFFICIENT_BALANCE: { code: 7003, status: 400, message: '余额不足' },\n  \n  \u002F\u002F 服务器 (9xxx)\n  INTERNAL_ERROR: { code: 9001, status: 500, message: '服务器错误' },\n} as const\n```\n\n### 错误处理工具\n\n```typescript\n\u002F\u002F lib\u002Fapi\u002Ferror.ts\nimport { ERROR_CODES } from '@\u002Ftypes\u002Ferrors'\n\nexport class APIError extends Error {\n  constructor(\n    public code: keyof typeof ERROR_CODES,\n    public details?: unknown\n  ) {\n    super(ERROR_CODES[code].message)\n  }\n  \n  toResponse() {\n    const { code: errorCode, status, message } = ERROR_CODES[this.code]\n    return Response.json(\n      { error: { code: this.code, message, details: this.details } },\n      { status }\n    )\n  }\n}\n\n\u002F\u002F 使用\nthrow new APIError('VALIDATION_ERROR', [\n  { field: 'email', message: '邮箱格式不正确' }\n])\n```\n\n---\n\n## 4. Query Parameters\n\n### 分页\n\n```\nGET \u002Fapi\u002Fusers?page=1&pageSize=20\nGET \u002Fapi\u002Fusers?cursor=abc123&limit=20  # 游标分页\n```\n\n### 过滤\n\n```\nGET \u002Fapi\u002Fusers?status=active\nGET \u002Fapi\u002Fusers?role=admin,user\nGET \u002Fapi\u002Fusers?createdAt[gte]=2024-01-01\n```\n\n### 排序\n\n```\nGET \u002Fapi\u002Fusers?sort=createdAt       # 升序\nGET \u002Fapi\u002Fusers?sort=-createdAt      # 降序\nGET \u002Fapi\u002Fusers?sort=-createdAt,name # 多字段\n```\n\n### 字段选择\n\n```\nGET \u002Fapi\u002Fusers?fields=id,name,email\nGET \u002Fapi\u002Fusers?include=posts,comments\n```\n\n---\n\n## 5. API Versioning\n\n### URL 版本 (推荐)\n\n```\n\u002Fapi\u002Fv1\u002Fusers\n\u002Fapi\u002Fv2\u002Fusers\n```\n\n### 版本迁移策略\n\n```typescript\n\u002F\u002F 同时支持多版本\n\u002F\u002F app\u002Fapi\u002Fv1\u002Fusers\u002Froute.ts\nexport async function GET() {\n  return formatV1Response(users)\n}\n\n\u002F\u002F app\u002Fapi\u002Fv2\u002Fusers\u002Froute.ts\nexport async function GET() {\n  return formatV2Response(users)\n}\n```\n\n---\n\n## 6. Next.js API Routes\n\n### 基础结构\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fusers\u002Froute.ts\nimport { NextRequest } from 'next\u002Fserver'\nimport { z } from 'zod'\nimport { APIError } from '@\u002Flib\u002Fapi\u002Ferror'\n\nconst CreateUserSchema = z.object({\n  name: z.string().min(1),\n  email: z.string().email(),\n})\n\nexport async function POST(request: NextRequest) {\n  try {\n    const body = await request.json()\n    const data = CreateUserSchema.parse(body)\n    \n    const user = await createUser(data)\n    \n    return Response.json(user, { status: 201 })\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      return new APIError('VALIDATION_ERROR', error.errors).toResponse()\n    }\n    if (error instanceof APIError) {\n      return error.toResponse()\n    }\n    return new APIError('INTERNAL_ERROR').toResponse()\n  }\n}\n```\n\n### 动态路由\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fusers\u002F[id]\u002Froute.ts\nexport async function GET(\n  request: NextRequest,\n  { params }: { params: { id: string } }\n) {\n  const user = await findUser(params.id)\n  \n  if (!user) {\n    return new APIError('NOT_FOUND').toResponse()\n  }\n  \n  return Response.json(user)\n}\n```\n\n### 中间件模式\n\n```typescript\n\u002F\u002F lib\u002Fapi\u002Fmiddleware.ts\ntype Handler = (req: NextRequest, ctx: any) => Promise\u003CResponse>\n\nexport function withAuth(handler: Handler): Handler {\n  return async (req, ctx) => {\n    const token = req.headers.get('authorization')?.replace('Bearer ', '')\n    \n    if (!token) {\n      return new APIError('AUTH_REQUIRED').toResponse()\n    }\n    \n    const user = await verifyToken(token)\n    if (!user) {\n      return new APIError('AUTH_INVALID').toResponse()\n    }\n    \n    \u002F\u002F 注入用户信息\n    ;(req as any).user = user\n    \n    return handler(req, ctx)\n  }\n}\n\n\u002F\u002F 使用\nexport const GET = withAuth(async (req) => {\n  const user = (req as any).user\n  return Response.json({ user })\n})\n```\n\n---\n\n## 7. tRPC Design (Alternative)\n\n### 定义 Router\n\n```typescript\n\u002F\u002F server\u002Frouters\u002Fuser.ts\nimport { z } from 'zod'\nimport { router, publicProcedure, protectedProcedure } from '..\u002Ftrpc'\n\nexport const userRouter = router({\n  list: publicProcedure\n    .input(z.object({\n      page: z.number().default(1),\n      pageSize: z.number().default(20),\n    }))\n    .query(async ({ input }) => {\n      return getUsers(input)\n    }),\n    \n  create: protectedProcedure\n    .input(z.object({\n      name: z.string(),\n      email: z.string().email(),\n    }))\n    .mutation(async ({ input, ctx }) => {\n      return createUser(input, ctx.user)\n    }),\n})\n```\n\n### 合并 Router\n\n```typescript\n\u002F\u002F server\u002Frouters\u002F_app.ts\nexport const appRouter = router({\n  user: userRouter,\n  chat: chatRouter,\n  wallet: walletRouter,\n})\n\nexport type AppRouter = typeof appRouter\n```\n\n---\n\n## 8. Streaming API (AI)\n\n### Server-Sent Events\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fchat\u002Froute.ts\nexport async function POST(request: NextRequest) {\n  const { messages } = await request.json()\n  \n  const stream = new ReadableStream({\n    async start(controller) {\n      const encoder = new TextEncoder()\n      \n      for await (const chunk of streamChat(messages)) {\n        controller.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}\\n\\n`))\n      }\n      \n      controller.enqueue(encoder.encode('data: [DONE]\\n\\n'))\n      controller.close()\n    },\n  })\n  \n  return new Response(stream, {\n    headers: {\n      'Content-Type': 'text\u002Fevent-stream',\n      'Cache-Control': 'no-cache',\n      'Connection': 'keep-alive',\n    },\n  })\n}\n```\n\n---\n\n## Quick Reference\n\n### 端点命名\n\n```\n✅ \u002Fapi\u002Fusers           (复数名词)\n✅ \u002Fapi\u002Fuser-profiles   (kebab-case)\n❌ \u002Fapi\u002FgetUsers        (不用动词)\n❌ \u002Fapi\u002Fuser            (不用单数)\n```\n\n### 状态码速查\n\n```\n200 - 成功 (读取\u002F更新)\n201 - 创建成功\n204 - 删除成功\n400 - 请求错误\n401 - 未认证\n403 - 无权限\n404 - 不存在\n422 - 验证失败\n429 - 限流\n500 - 服务器错误\n```\n\n### 推荐库\n\n```\nzod         - 验证\n@trpc\u002Fserver - tRPC\n@upstash\u002Fratelimit - 限流\n```\n","# API Designer (API 设计师)\n\n**Goal**: 设计一致、可预测、易于使用的 API 接口。\n\n---\n\n## 1. RESTful API Design\n\n### URL 结构\n\n```\n# 资源命名 (名词复数)\nGET    \u002Fapi\u002Fusers           # 列表\nGET    \u002Fapi\u002Fusers\u002F:id       # 详情\nPOST   \u002Fapi\u002Fusers           # 创建\nPUT    \u002Fapi\u002Fusers\u002F:id       # 全量更新\nPATCH  \u002Fapi\u002Fusers\u002F:id       # 部分更新\nDELETE \u002Fapi\u002Fusers\u002F:id       # 删除\n\n# 嵌套资源\nGET    \u002Fapi\u002Fusers\u002F:id\u002Fposts\nPOST   \u002Fapi\u002Fusers\u002F:id\u002Fposts\n\n# 操作 (动词，仅在必要时)\nPOST   \u002Fapi\u002Fusers\u002F:id\u002Factivate\nPOST   \u002Fapi\u002Fchat\u002Fcompletions\n```\n\n### HTTP 方法语义\n\n| Method | 幂等 | 安全 | 用途 |\n|--------|------|------|------|\n| GET | ✅ | ✅ | 读取资源 |\n| POST | ❌ | ❌ | 创建资源\u002F执行操作 |\n| PUT | ✅ | ❌ | 全量替换 |\n| PATCH | ❌ | ❌ | 部分更新 |\n| DELETE | ✅ | ❌ | 删除资源 |\n\n### HTTP 状态码\n\n```typescript\n\u002F\u002F 成功\n200 OK              \u002F\u002F 通用成功\n201 Created         \u002F\u002F 创建成功\n204 No Content      \u002F\u002F 删除成功\n\n\u002F\u002F 客户端错误\n400 Bad Request     \u002F\u002F 请求格式错误\n401 Unauthorized    \u002F\u002F 未认证\n403 Forbidden       \u002F\u002F 无权限\n404 Not Found       \u002F\u002F 资源不存在\n409 Conflict        \u002F\u002F 冲突 (如重复创建)\n422 Unprocessable   \u002F\u002F 验证失败\n429 Too Many Reqs   \u002F\u002F 限流\n\n\u002F\u002F 服务端错误\n500 Internal Error  \u002F\u002F 服务器错误\n502 Bad Gateway     \u002F\u002F 上游错误\n503 Unavailable     \u002F\u002F 服务不可用\n```\n\n---\n\n## 2. Response Format\n\n### 成功响应\n\n```typescript\n\u002F\u002F 单个资源\n{\n  \"data\": {\n    \"id\": \"123\",\n    \"type\": \"user\",\n    \"attributes\": {\n      \"name\": \"张三\",\n      \"email\": \"zhang@example.com\"\n    }\n  }\n}\n\n\u002F\u002F 简化版 (推荐 OPC)\n{\n  \"id\": \"123\",\n  \"name\": \"张三\",\n  \"email\": \"zhang@example.com\"\n}\n```\n\n### 列表响应\n\n```typescript\n{\n  \"data\": [...],\n  \"pagination\": {\n    \"page\": 1,\n    \"pageSize\": 20,\n    \"total\": 100,\n    \"totalPages\": 5\n  }\n}\n```\n\n### 错误响应\n\n```typescript\n{\n  \"error\": {\n    \"code\": \"VALIDATION_ERROR\",\n    \"message\": \"请求参数验证失败\",\n    \"details\": [\n      { \"field\": \"email\", \"message\": \"邮箱格式不正确\" },\n      { \"field\": \"password\", \"message\": \"密码至少 8 位\" }\n    ]\n  }\n}\n```\n\n---\n\n## 3. Error Code System\n\n### 错误码设计\n\n```typescript\n\u002F\u002F types\u002Ferrors.ts\nexport const ERROR_CODES = {\n  \u002F\u002F 认证 (1xxx)\n  AUTH_REQUIRED: { code: 1001, status: 401, message: '请先登录' },\n  AUTH_EXPIRED: { code: 1002, status: 401, message: '登录已过期' },\n  AUTH_INVALID: { code: 1003, status: 401, message: '认证信息无效' },\n  \n  \u002F\u002F 权限 (2xxx)\n  FORBIDDEN: { code: 2001, status: 403, message: '无权限访问' },\n  \n  \u002F\u002F 资源 (3xxx)\n  NOT_FOUND: { code: 3001, status: 404, message: '资源不存在' },\n  ALREADY_EXISTS: { code: 3002, status: 409, message: '资源已存在' },\n  \n  \u002F\u002F 验证 (4xxx)\n  VALIDATION_ERROR: { code: 4001, status: 422, message: '参数验证失败' },\n  INVALID_FORMAT: { code: 4002, status: 400, message: '请求格式错误' },\n  \n  \u002F\u002F 限流 (5xxx)\n  RATE_LIMITED: { code: 5001, status: 429, message: '请求过于频繁' },\n  \n  \u002F\u002F AI 相关 (6xxx)\n  AI_TOKEN_LIMIT: { code: 6001, status: 400, message: 'Token 超出限制' },\n  AI_TIMEOUT: { code: 6002, status: 504, message: 'AI 响应超时' },\n  AI_UNAVAILABLE: { code: 6003, status: 503, message: 'AI 服务不可用' },\n  \n  \u002F\u002F Web3 相关 (7xxx)\n  WALLET_NOT_CONNECTED: { code: 7001, status: 400, message: '钱包未连接' },\n  INVALID_SIGNATURE: { code: 7002, status: 401, message: '签名验证失败' },\n  INSUFFICIENT_BALANCE: { code: 7003, status: 400, message: '余额不足' },\n  \n  \u002F\u002F 服务器 (9xxx)\n  INTERNAL_ERROR: { code: 9001, status: 500, message: '服务器错误' },\n} as const\n```\n\n### 错误处理工具\n\n```typescript\n\u002F\u002F lib\u002Fapi\u002Ferror.ts\nimport { ERROR_CODES } from '@\u002Ftypes\u002Ferrors'\n\nexport class APIError extends Error {\n  constructor(\n    public code: keyof typeof ERROR_CODES,\n    public details?: unknown\n  ) {\n    super(ERROR_CODES[code].message)\n  }\n  \n  toResponse() {\n    const { code: errorCode, status, message } = ERROR_CODES[this.code]\n    return Response.json(\n      { error: { code: this.code, message, details: this.details } },\n      { status }\n    )\n  }\n}\n\n\u002F\u002F 使用\nthrow new APIError('VALIDATION_ERROR', [\n  { field: 'email', message: '邮箱格式不正确' }\n])\n```\n\n---\n\n## 4. Query Parameters\n\n### 分页\n\n```\nGET \u002Fapi\u002Fusers?page=1&pageSize=20\nGET \u002Fapi\u002Fusers?cursor=abc123&limit=20  # 游标分页\n```\n\n### 过滤\n\n```\nGET \u002Fapi\u002Fusers?status=active\nGET \u002Fapi\u002Fusers?role=admin,user\nGET \u002Fapi\u002Fusers?createdAt[gte]=2024-01-01\n```\n\n### 排序\n\n```\nGET \u002Fapi\u002Fusers?sort=createdAt       # 升序\nGET \u002Fapi\u002Fusers?sort=-createdAt      # 降序\nGET \u002Fapi\u002Fusers?sort=-createdAt,name # 多字段\n```\n\n### 字段选择\n\n```\nGET \u002Fapi\u002Fusers?fields=id,name,email\nGET \u002Fapi\u002Fusers?include=posts,comments\n```\n\n---\n\n## 5. API Versioning\n\n### URL 版本 (推荐)\n\n```\n\u002Fapi\u002Fv1\u002Fusers\n\u002Fapi\u002Fv2\u002Fusers\n```\n\n### 版本迁移策略\n\n```typescript\n\u002F\u002F 同时支持多版本\n\u002F\u002F app\u002Fapi\u002Fv1\u002Fusers\u002Froute.ts\nexport async function GET() {\n  return formatV1Response(users)\n}\n\n\u002F\u002F app\u002Fapi\u002Fv2\u002Fusers\u002Froute.ts\nexport async function GET() {\n  return formatV2Response(users)\n}\n```\n\n---\n\n## 6. Next.js API Routes\n\n### 基础结构\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fusers\u002Froute.ts\nimport { NextRequest } from 'next\u002Fserver'\nimport { z } from 'zod'\nimport { APIError } from '@\u002Flib\u002Fapi\u002Ferror'\n\nconst CreateUserSchema = z.object({\n  name: z.string().min(1),\n  email: z.string().email(),\n})\n\nexport async function POST(request: NextRequest) {\n  try {\n    const body = await request.json()\n    const data = CreateUserSchema.parse(body)\n    \n    const user = await createUser(data)\n    \n    return Response.json(user, { status: 201 })\n  } catch (error) {\n    if (error instanceof z.ZodError) {\n      return new APIError('VALIDATION_ERROR', error.errors).toResponse()\n    }\n    if (error instanceof APIError) {\n      return error.toResponse()\n    }\n    return new APIError('INTERNAL_ERROR').toResponse()\n  }\n}\n```\n\n### 动态路由\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fusers\u002F[id]\u002Froute.ts\nexport async function GET(\n  request: NextRequest,\n  { params }: { params: { id: string } }\n) {\n  const user = await findUser(params.id)\n  \n  if (!user) {\n    return new APIError('NOT_FOUND').toResponse()\n  }\n  \n  return Response.json(user)\n}\n```\n\n### 中间件模式\n\n```typescript\n\u002F\u002F lib\u002Fapi\u002Fmiddleware.ts\ntype Handler = (req: NextRequest, ctx: any) => Promise\u003CResponse>\n\nexport function withAuth(handler: Handler): Handler {\n  return async (req, ctx) => {\n    const token = req.headers.get('authorization')?.replace('Bearer ', '')\n    \n    if (!token) {\n      return new APIError('AUTH_REQUIRED').toResponse()\n    }\n    \n    const user = await verifyToken(token)\n    if (!user) {\n      return new APIError('AUTH_INVALID').toResponse()\n    }\n    \n    \u002F\u002F 注入用户信息\n    ;(req as any).user = user\n    \n    return handler(req, ctx)\n  }\n}\n\n\u002F\u002F 使用\nexport const GET = withAuth(async (req) => {\n  const user = (req as any).user\n  return Response.json({ user })\n})\n```\n\n---\n\n## 7. tRPC Design (Alternative)\n\n### 定义 Router\n\n```typescript\n\u002F\u002F server\u002Frouters\u002Fuser.ts\nimport { z } from 'zod'\nimport { router, publicProcedure, protectedProcedure } from '..\u002Ftrpc'\n\nexport const userRouter = router({\n  list: publicProcedure\n    .input(z.object({\n      page: z.number().default(1),\n      pageSize: z.number().default(20),\n    }))\n    .query(async ({ input }) => {\n      return getUsers(input)\n    }),\n    \n  create: protectedProcedure\n    .input(z.object({\n      name: z.string(),\n      email: z.string().email(),\n    }))\n    .mutation(async ({ input, ctx }) => {\n      return createUser(input, ctx.user)\n    }),\n})\n```\n\n### 合并 Router\n\n```typescript\n\u002F\u002F server\u002Frouters\u002F_app.ts\nexport const appRouter = router({\n  user: userRouter,\n  chat: chatRouter,\n  wallet: walletRouter,\n})\n\nexport type AppRouter = typeof appRouter\n```\n\n---\n\n## 8. Streaming API (AI)\n\n### Server-Sent Events\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fchat\u002Froute.ts\nexport async function POST(request: NextRequest) {\n  const { messages } = await request.json()\n  \n  const stream = new ReadableStream({\n    async start(controller) {\n      const encoder = new TextEncoder()\n      \n      for await (const chunk of streamChat(messages)) {\n        controller.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}\\n\\n`))\n      }\n      \n      controller.enqueue(encoder.encode('data: [DONE]\\n\\n'))\n      controller.close()\n    },\n  })\n  \n  return new Response(stream, {\n    headers: {\n      'Content-Type': 'text\u002Fevent-stream',\n      'Cache-Control': 'no-cache',\n      'Connection': 'keep-alive',\n    },\n  })\n}\n```\n\n---\n\n## Quick Reference\n\n### 端点命名\n\n```\n✅ \u002Fapi\u002Fusers           (复数名词)\n✅ \u002Fapi\u002Fuser-profiles   (kebab-case)\n❌ \u002Fapi\u002FgetUsers        (不用动词)\n❌ \u002Fapi\u002Fuser            (不用单数)\n```\n\n### 状态码速查\n\n```\n200 - 成功 (读取\u002F更新)\n201 - 创建成功\n204 - 删除成功\n400 - 请求错误\n401 - 未认证\n403 - 无权限\n404 - 不存在\n422 - 验证失败\n429 - 限流\n500 - 服务器错误\n```\n\n### 推荐库\n\n```\nzod         - 验证\n@trpc\u002Fserver - tRPC\n@upstash\u002Fratelimit - 限流\n```\n",{"name":5,"description":7},"main","4a618da5d2528627c4728e9aab7d602f9d00b649","genes\u002Fapi-designer",1,"https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground","https:\u002F\u002Fgithub.com\u002Frotifer-protocol","https:\u002F\u002Frotifer.dev","Open-source evolution framework for AI agents","2026-11-12 13:46:27",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add rotifer-protocol\u002Frotifer-playground --skill api-designer",{"tool":61,"command":62},"bunx","bunx skills add rotifer-protocol\u002Frotifer-playground --skill api-designer",{"tool":64,"command":65},"pnpm","pnpm dlx skills add rotifer-protocol\u002Frotifer-playground --skill api-designer","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fgenes\u002Fapi-designer\u002FSKILL.md",true,[69,75,79],{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},".cloud-manifest.json","REFERENCE","参考文档",156,"https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fgenes\u002Fapi-designer\u002F.cloud-manifest.json",{"path":76,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":77,"sourceHtmlUrl":78},".gene-manifest.json",259,"https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fgenes\u002Fapi-designer\u002F.gene-manifest.json",{"path":80,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":81,"sourceHtmlUrl":82},"phenotype.json",2796,"https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fgenes\u002Fapi-designer\u002Fphenotype.json",[84,98,124,149,169,188],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":41},"01M6H8FTYPK400JGQDW57GM49R","fixture-skill","A synthetic ClawHub skill for wrap --from-clawhub tests","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fclawhub\u002Ffixture-skill\u002FSKILL.md",[],[91,92,93,94,95,96,97],"fixture","fixture skill","wrap","tests","clawhub","for","synthetic",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":41},"01M6H8FPX91FF5FH8PPEW7HQSZ","rotifer-self-evolving-agent","Rank an Agent's Rotifer Genes against the Arena and swap in stronger ones, and create and run the local Agents built from those Genes. Invoked explicitly via \u002Fevolve — scan local capabilities, compare Genes, inspect fitness scores, replace weak ones with user approval (each replacement can be rolled back), write an Agent definition into the project (\u002Fevolve create-agent), and execute a local Agent's Genes in the WASM sandbox (\u002Fevolve run-agent). Not for capabilities outside Rotifer.","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fskills\u002Frotifer-self-evolving-agent\u002FSKILL.md",[],[105,106,107,108,109,110,111,112,113,114,115,116,117,118,96,119,58,120,121,26,122,123],"rotifer self evolving agent","self","self evolving","inspect","local","MCP","access","capabilities","server","run","gene","evolve","network","arena","scan","compare","swap","mcp-server","fitness",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":41},"01M6H8FGNKE933Q2JAAB7JY43V","rotifer-guide","Entry point for Rotifer Protocol. Onboards a user to Rotifer Genes, scaffolds a Gene from a description, diagnoses a Gene's F(g) score or compile failure, searches the Rotifer Gene registry, upgrades a Gene's fidelity from Wrapped to Native, and submits a Gene to the Arena and follows its ranking. It works by proposing `rotifer` CLI commands; the ones that install software, send work to Rotifer's servers, publish a Gene or overwrite files wait for the user's approval. Meant to be invoked explicitly when working with Rotifer, or when unsure which Rotifer capability fits. Its scope is Rotifer Genes and the Rotifer CLI; onboarding, tutorials, troubleshooting or search for anything else are outside it.","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fskills\u002Frotifer-guide\u002FSKILL.md",[],[131,132,133,134,135,136,137,115,138,139,96,140,141,35,26,142,143,144,145,146,23,147,148],"rotifer guide","guide","which","scaffolding","search","cli","native","registry","do","compile","general","protocol","troubleshooting","onboarding","rotifer gene","invoke","capability","point",{"skillNo":150,"name":151,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":155,"publishedAt":41},"01M6H8FBXGQM2RH27G0S6XMQ34","rotifer-gene","The Gene manual for Rotifer Protocol — write a Gene's express function and phenotype schema, run the four-layer security audit before publishing, and migrate a Gene's fidelity from Wrapped to Hybrid or Native. Invoke explicitly when building, auditing, or upgrading a Rotifer Gene. Do NOT use for general code review, dependency auditing, or framework migration — every procedure here operates on Rotifer Genes, their phenotype schemas, and the Rotifer CLI, and nothing else.","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fskills\u002Frotifer-gene\u002FSKILL.md",[],[145,115,139,118,156,96,157,158,141,159,160,161,58,35,111,162,163,164,165,166,167,168,146,23],"security audit","code review","manual","publishing","yes","schema","version","migrate","code","express","review","hybrid","submission",{"skillNo":170,"name":171,"nameZh":6,"description":172,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":173,"categories":174,"keywords":175,"publishedAt":41},"01M6H8F7DZPN54N2AQC32BWEKV","rotifer-arena","Benchmark Rotifer Genes against each other in the Arena — import from ClawHub \u002F local \u002F scratch, compile, match opponents, run Arena evaluation, and produce a Markdown report with F(g) fitness and V(g) security grades. Invoke explicitly to compare or benchmark Rotifer Genes. Do NOT use for general benchmarking, load testing, or comparing anything that is not a Rotifer Gene or Agent.","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fskills\u002Frotifer-arena\u002FSKILL.md",[],[176,118,139,177,96,140,178,109,141,95,179,35,180,120,26,181,182,183,114,115,145,146,184,185,123,186,187],"rotifer arena","import","testing","produce","load","benchmarking","load testing","markdown","Evaluation","benchmark","security","scratch",{"skillNo":189,"name":190,"nameZh":6,"description":191,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":192,"categories":193,"keywords":194,"publishedAt":41},"01M6H8F0WWXMTDWXQMQYC3PGPW","rotifer-agent","Build a Rotifer Agent from Genes — decompose intent into capability units, pick Genes by Arena F(g), compose a Rotifer Genome, create the Agent and test it. Use when the user is working with Rotifer specifically: \"Rotifer Agent\", \"compose Genes\", \"Rotifer Genome\", \"Gene composition\", \"rotifer agent create\". Do NOT use for general agent frameworks, or when the words Seq \u002F Par \u002F Cond \u002F Try appear as ordinary programming terms — in Rotifer those name Genome composition strategies, and this Skill applies only when the user is composing Rotifer Genes.","https:\u002F\u002Fgithub.com\u002Frotifer-protocol\u002Frotifer-playground\u002Fblob\u002Fmain\u002Fskills\u002Frotifer-agent\u002FSKILL.md",[],[195,196,197,198,199,200,201,115,202,203,204,139,118,205,96,206,141,35,207,26,23,208,147],"rotifer agent","Composition","pick","only","create","strategies","intent","seq","decompose","as","compose","frameworks","programming","agent frameworks"]