Thank you for your interest in contributing to Metapi! / 感谢您对 Metapi 项目的贡献!
Metapi is a meta-aggregation layer for AI API platforms (New API, One API, OneHub, etc.), providing unified proxy, intelligent routing, and centralized management.
Metapi 是 AI API 聚合平台(New API、One API、OneHub 等)的元聚合层,提供统一代理、智能路由和集中管理。
- Check existing Issues and Pull Requests to avoid duplicates. / 检查现有的 Issues 和 Pull Requests 以避免重复。
- For major changes, open an issue first to discuss your proposal. / 对于重大更改,请先开启 issue 讨论您的提案。
- Read our Code of Conduct. / 阅读我们的行为准则。
- Node.js 20+ / Node.js 20 或更高版本
- npm or compatible package manager / npm 或兼容的包管理器
- Fork and clone the repository / Fork 并克隆仓库
git clone https://github.com/YOUR_USERNAME/metapi.git
cd metapi- Install dependencies / 安装依赖
npm install- Create environment file / 创建环境文件
# Windows PowerShell
Copy-Item .env.example .env
# Linux/macOS/Git Bash
cp .env.example .envEdit .env and set your tokens / 编辑 .env 并设置您的令牌:
AUTH_TOKEN=your-dev-admin-token
PROXY_TOKEN=your-dev-proxy-token- Initialize database / 初始化数据库
npm run db:migrate- Start development server / 启动开发服务器
npm run devThe app will be available at http://localhost:4000 (backend) and http://localhost:5173 (frontend).
应用将在 http://localhost:4000(后端)和 http://localhost:5173(前端)可用。
npm run dev # Start backend + frontend with hot reload / 启动后端 + 前端热更新
npm run dev:server # Start backend only / 仅启动后端
npm run build # Build all (web + server + desktop) / 构建全部
npm run build:web # Build frontend only / 仅构建前端
npm run build:server # Build backend only / 仅构建后端npm run dev:desktop # Start desktop app in dev mode / 开发模式启动桌面应用
npm run build:desktop # Build desktop app / 构建桌面应用
npm run dist:desktop # Package desktop app / 打包桌面应用
npm run dist:desktop:mac:intel # Package for macOS Intel / 打包 macOS Intel 版本npm run docs:dev # Start VitePress dev server / 启动 VitePress 开发服务器
npm run docs:build # Build documentation / 构建文档
npm run docs:preview # Preview built docs / 预览构建的文档npm test # Run all tests / 运行所有测试
npm run test:watch # Run tests in watch mode / 监听模式运行测试
npm run smoke:db # Database smoke test (SQLite) / 数据库冒烟测试(SQLite)
npm run smoke:db:mysql # MySQL smoke test / MySQL 冒烟测试
npm run smoke:db:postgres # PostgreSQL smoke test / PostgreSQL 冒烟测试npm run db:generate # Generate Drizzle migration files / 生成 Drizzle 迁移文件
npm run db:migrate # Run database migrations / 运行数据库迁移
npm run schema:generate # Generate schema artifacts / 生成 schema 构件metapi/
├── src/
│ ├── server/ # Backend (Fastify) / 后端(Fastify)
│ │ ├── routes/ # API routes / API 路由
│ │ ├── services/ # Business logic / 业务逻辑
│ │ ├── db/ # Database & ORM / 数据库与 ORM
│ │ └── middleware/ # Middleware / 中间件
│ ├── web/ # Frontend (React + Vite) / 前端(React + Vite)
│ └── desktop/ # Electron desktop app / Electron 桌面应用
├── docs/ # VitePress documentation / VitePress 文档
├── drizzle/ # Database migrations / 数据库迁移
└── scripts/ # Build & dev scripts / 构建与开发脚本
-
Keep PRs focused and small / 保持 PR 专注且小巧
- One feature or fix per PR / 每个 PR 一个功能或修复
- Split large changes into multiple PRs / 将大型更改拆分为多个 PR
-
Write tests / 编写测试
- Add tests for new features / 为新功能添加测试
- Update tests for behavior changes / 为行为变更更新测试
- Ensure all tests pass:
npm test/ 确保所有测试通过:npm test
-
Update documentation / 更新文档
- Update README if adding user-facing features / 如果添加面向用户的功能,请更新 README
- Update docs/ for configuration or API changes / 配置或 API 更改请更新 docs/
- Add JSDoc comments for new functions / 为新函数添加 JSDoc 注释
-
Run checks / 运行检查
- Documentation changes:
npm run docs:build/ 文档更改:npm run docs:build - Code changes:
npm test && npm run build/ 代码更改:npm test && npm run build - Database changes:
npm run smoke:db/ 数据库更改:npm run smoke:db - Architecture / repo drift changes:
npm run repo:drift-check/ 架构与仓库漂移检查:npm run repo:drift-check
- Documentation changes:
-
Follow code style / 遵循代码风格
- Use TypeScript for type safety / 使用 TypeScript 确保类型安全
- Follow existing code patterns / 遵循现有代码模式
- Follow repo-level engineering rules in
AGENTS.md/ 遵循仓库根目录AGENTS.md中的工程规则 - Keep functions small and focused / 保持函数小而专注
Use conventional commit format / 使用约定式提交格式:
<type>: <description>
[optional body]
Types / 类型:
feat: New feature / 新功能fix: Bug fix / 错误修复docs: Documentation / 文档refactor: Code refactoring / 代码重构test: Tests / 测试chore: Build/tooling / 构建/工具
Examples / 示例:
feat: add AnyRouter platform adapter
fix: handle empty model list in dashboard
docs: update Docker deployment guide
refactor: extract route selection logic
test: add tests for checkin reward parser
chore: upgrade Vite to 6.0
- Runtime data:
data/,tmp// 运行时数据:data/、tmp/ - Environment files:
.env(only.env.exampleis tracked) / 环境文件:.env(仅跟踪.env.example) - Build artifacts:
dist/,node_modules// 构建产物:dist/、node_modules/ - IDE-specific files (unless beneficial to all contributors) / IDE 特定文件(除非对所有贡献者有益)
If you're adding support for a new AI API platform / 如果您要添加对新 AI API 平台的支持:
- Create adapter in
src/server/services/platforms// 在src/server/services/platforms/中创建适配器 - Implement required interfaces: login, balance, models, proxy / 实现必需接口:登录、余额、模型、代理
- Add platform tests / 添加平台测试
- Update documentation with platform details / 更新文档说明平台详情
- Use
restart.batto restart dev server (clears port locks) / 使用restart.bat重启开发服务器(清除端口锁定) - Use PowerShell
Copy-Iteminstead ofcp/ 使用 PowerShell 的Copy-Item而不是cp - If Node.js upgrade breaks scripts, run
npm installagain / 如果 Node.js 升级导致脚本损坏,请重新运行npm install
- 📖 Documentation / 文档
- 💬 GitHub Discussions / GitHub 讨论区
- 🐛 Issue Tracker / Issue 跟踪
By contributing, you agree that your contributions will be licensed under the MIT License.
通过贡献,您同意您的贡献将根据 MIT 许可证 授权。