-
-
Notifications
You must be signed in to change notification settings - Fork 187
release #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
release #199
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
37d8665
feat(mcp): 实现 MCP 透传功能
flintttan 3af58b6
Merge branch 'ding113:main' into feature/mcp-passthrough
flintttan e9a0c1f
chore: format code (feature-mcp-passthrough-3af58b6)
github-actions[bot] 2fe8c96
feat(mcp): 支持 GLM MCP 透传功能及多语言配置
flintttan 5365e1d
Merge branch 'feature/mcp-passthrough' with GLM MCP support
flintttan 8d59f3a
chore: format code (feature-mcp-passthrough-5365e1d)
github-actions[bot] 4553d5a
Fix: Address PR review comments
flintttan 206eff1
Merge upstream/dev and resolve conflicts (rename migration to 0024)
flintttan f54e9b3
chore: fix lint warnings
flintttan ef35782
Merge branch 'feature/mcp-passthrough' of github.com:flintttan/claude…
flintttan 8a1c899
chore: format code (feature-mcp-passthrough-ef35782)
github-actions[bot] 3cea385
feat(providers): 改进 API 测试以支持流式响应检测与处理
Silentely 4576c53
fix(providers): 移除max_output_tokens 参数以兼容中转服务
Silentely 35276ea
feat(providers): 支持解析和处理流式响应数据
Silentely 867ad77
feat(api-test): 增加流式响应信息展示功能
Silentely d1bee4c
fix(settings): 调整供应商模型测试提示文本
Silentely b2945a5
style: 修复代码格式以通过 Prettier 检查
Silentely 0531057
fix: 修复代码审查中发现的关键问题
Silentely 47537a7
Merge pull request #185 from Silentely/fix-provider-test
ding113 07267a5
fix: 优化供应商测试和日志系统
Silentely 93d4b7b
Merge branch 'fix/provider-test-and-logs' into dev
Silentely cc3e30c
refactor: 根据代码审查优化实现
Silentely c175285
fix: resolve Docker build failure by excluding Node.js modules
github-actions[bot] a178d13
fix: 根据 ding113 审查意见完成修复
Silentely 53b09cc
fix: add webpack externals for Node.js built-in modules
github-actions[bot] 22062f4
fix: 修复 log-time-formatter 的 null 安全问题并添加文档
Silentely 25cf1c3
refactor: 删除未使用代码并优化错误处理
Silentely dddcaf9
Merge pull request #186 from Silentely/dev
ding113 d0d5cce
fix: 修复 Gemini 模型重定向无效的问题
ding113 19b3d49
Merge remote-tracking branch 'upstream/dev' into feature/mcp-passthrough
flintttan 417b9eb
Merge branch 'feature/mcp-passthrough' of github.com:flintttan/claude…
flintttan 229f447
fix: enhance MCP passthrough with security and stability improvements
flintttan 4ff7a5c
chore: format code (feature-mcp-passthrough-229f447)
github-actions[bot] dfa8db5
Merge pull request #157 from flintttan/feature/mcp-passthrough
ding113 f932424
fix: 修复供应商 API 测试返回 520 错误的问题
Silentely 30b0911
fix: 修复代理降级时 Body has already been read 错误
Silentely 2918043
chore: 增加 API 测试超时时间到 15 秒
Silentely 5409736
feat: 改进供应商 API 测试体验
Silentely e2a8ff8
fix: Anthropic API 测试同时发送两种认证头
Silentely d592091
fix: 修复 Codex API 测试请求体格式
Silentely be3cd1c
fix: 修正 Pino 日志时间戳配置位置
Silentely 2ad3dd8
chore: 移除重复的 API 测试注意事项
Silentely a3a007e
chore(i18n): remove unused notice field from apiTest section
Silentely 26a112f
feat(i18n): add disclaimer translations for API test feature
Silentely e320e54
feat(providers): 增强 API 测试错误解析逻辑
Silentely bdb2041
fix: 修复供应商多标签匹配问题 (#190)
ding113 d0dd669
fix: 修复 Codex 供应商 API 测试失败问题 (#189)
ding113 71f59d6
feat: 优化使用记录状态码颜色显示 (#188)
ding113 4e3402d
feat: 调整流式静默期超时默认值从 10 秒改为 300 秒
ding113 3a2ef7a
fix: 修复模型重定向日志记录问题
ding113 79061a7
fix: 修复错误规则正则匹配问题并增强刷新缓存功能
ding113 ebc05ff
fix(i18n): 修复 API 测试免责声明翻译键路径错误
Silentely 9bdba4f
Merge branch 'dev' into fix/provider-api-test-520-error
Silentely 0d0cce6
fix: harden provider api test diagnostics
Silentely 7e0faf3
Merge pull request #194 from Silentely/fix/provider-api-test-520-error
ding113 743605d
chore: format code (dev-7e0faf3)
github-actions[bot] fa93f48
fix: clarify provider response model label
Silentely 410048b
Merge pull request #197 from Silentely/chore/update-response-model-label
ding113 806e1c4
fix: 修复 PR review 中发现的多个问题
ding113 1f1592b
chore: revert db schema
ding113 ab26956
Merge branch 'dev' into feat/mcp-passthrough
ding113 10c0898
Merge pull request #193 from ding113/feat/mcp-passthrough
ding113 8656657
docs: update changelog for PR #193
github-actions[bot] eddbe88
fix: resolve migration snapshot conflict and add MCP passthrough fields
ding113 817fa74
feat: 更新供应商超时配置默认值为不限制
ding113 33a47aa
fix: 修复数据导入跨版本兼容性和错误提示问题
ding113 b4c47ec
chore: format code (dev-33a47aa)
github-actions[bot] 7060ec3
fix: 修复 errorRules.cacheStats i18n 参数不匹配问题
ding113 ea103ac
fix: 恢复被错误删除的 i18n 字段(descriptionFull/Warning)
ding113 c70f871
fix: 修复错误规则版本更新后无法自动同步的问题
ding113 6e36cb1
chore: update doc
ding113 477409f
chore: format code (dev-6e36cb1)
github-actions[bot] 129d565
fix: 修复模型重定向信息未保存到数据库的问题
ding113 3aadc90
docs: 补充 CLAUDE.md 遗漏的 gemini provider 类型
ding113 08db1b7
fix: 修复 ErrorRuleDetector 懒初始化的竞态条件
ding113 eecd4f7
Merge branch 'main' into dev
ding113 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,157 @@ | ||
| # Repository Guidelines | ||
| # CLAUDE.md | ||
|
|
||
| ## Project Structure & Module Organization | ||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| - `src/app` holds Next.js routes and API handlers; UI primitives live in `src/components`. | ||
| - Shared server logic sits in `src/actions`, `src/lib`, and `src/repository`. | ||
| - Drizzle migrations and schema snapshots live under `drizzle/` with settings in `drizzle.config.ts`. | ||
| - Static assets stay in `public/`; deployment helpers live in `deploy/`, `docker-compose.yaml`, and the `Makefile`. | ||
| - Docker volumes write into `data/`; treat it as runtime-only. | ||
| ## Project Overview | ||
|
|
||
| ## Build, Test, and Development Commands | ||
| Claude Code Hub is an AI API proxy platform built with Next.js 15 + Hono + PostgreSQL + Redis. It provides multi-provider management, intelligent load balancing, real-time monitoring, and OpenAPI documentation for Claude/OpenAI compatible APIs. | ||
|
|
||
| - `bun run dev` — starts Next.js (port 13500) with Turbo for local work. | ||
| - `bun run build` / `bun run start` — compiles the standalone production bundle and serves it. | ||
| - `bun run lint`, `bun run typecheck`, `bun run format:check` — run ESLint 9, TypeScript `--noEmit`, and Prettier verification; treat failures as blockers. | ||
| - `bun run db:generate`, `bun run db:migrate`, `bun run db:push`, `bun run db:studio` — Drizzle Kit for schema evolution. | ||
| - `docker compose up -d` — spins up the full stack (app, Postgres, Redis) for parity testing. | ||
| ## Development Commands | ||
|
|
||
| ## Coding Style & Naming Conventions | ||
| ```bash | ||
| # Install dependencies | ||
| bun install | ||
|
|
||
| - 2-space indentation, trailing commas, and single quotes follow Prettier and `eslint.config.mjs`. | ||
| - React components use PascalCase (`UsageChart.tsx`); hooks and utilities stay camelCase; route folders remain kebab-case. | ||
| - Prefer `async/await`, keep server actions inside `src/actions`, and co-locate Tailwind classes with the JSX they style. | ||
| - Run `bun run format` before submitting wide-ranging edits. | ||
| # Development server (port 13500 with Turbo) | ||
| bun run dev | ||
|
|
||
| ## Testing Guidelines | ||
| # Build for production | ||
| bun run build | ||
|
|
||
| - Today we rely on `bun run lint` and `bun run typecheck` plus manual checks through `/admin`. | ||
| - Smoke API changes with `curl -H "Authorization: Bearer <ADMIN_TOKEN>" http://localhost:13500/api/providers`. | ||
| - New automated tests should follow `*.spec.ts` naming, live next to the feature, and wire into `package.json` scripts. | ||
| - Note any seed data or feature flags in the PR description so reviewers can reproduce your scenario. | ||
| # Type checking | ||
| bun run typecheck | ||
|
|
||
| ## Commit & Pull Request Guidelines | ||
| # Linting | ||
| bun run lint | ||
|
|
||
| - Follow Conventional commits (`fix:`, `chore:`, `feat:`) as seen in `git log`; keep subjects under 72 characters. | ||
| - Body text should note user impact plus migration or environment changes. | ||
| - PRs must include a short summary, screenshots or JSON samples for UI/API updates, links to issues, and migration callouts. | ||
| - Rebase onto `main`, run `bun run lint && bun run typecheck`, and flag anything that blocks deploy parity. | ||
| # Format code | ||
| bun run format | ||
|
|
||
| ## Security & Configuration Tips | ||
| # Database commands | ||
| bun run db:generate # Generate Drizzle migrations | ||
| bun run db:migrate # Run migrations | ||
| bun run db:push # Push schema changes | ||
| bun run db:studio # Open Drizzle Studio | ||
| ``` | ||
|
|
||
| - Start from `.env.example`, rotate `ADMIN_TOKEN` before sharing previews, and scope provider keys to least privilege. | ||
| - Keep Redis, Postgres, and upstream tokens in secrets management—never in Git commits. | ||
| - Prefer `bun run dev` with mock providers when debugging rather than production credentials. | ||
| ### Local Development with Docker | ||
|
|
||
| ```bash | ||
| cd dev | ||
| make dev # Start PostgreSQL + Redis + bun dev | ||
| make db # Start only database and Redis | ||
| make migrate # Run database migrations | ||
| make clean # Clean all resources | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Request Flow | ||
|
|
||
| ``` | ||
| Client Request → Next.js API Route (/v1) | ||
| → ProxySession (context creation) | ||
| → GuardPipeline (auth → version → session → sensitive → rateLimit → provider) | ||
| → ProxyForwarder (request forwarding with format conversion) | ||
| → ResponseHandler (streaming/non-streaming response) | ||
| ``` | ||
|
|
||
| ### Key Directories | ||
|
|
||
| - `src/app/v1/_lib/` - Proxy core: handlers, guards, converters, forwarders | ||
| - `src/actions/` - Server Actions (business logic, exposed via OpenAPI) | ||
| - `src/repository/` - Database queries (Drizzle ORM) | ||
| - `src/lib/` - Shared utilities: rate-limit, circuit-breaker, session, logger | ||
| - `src/drizzle/` - Database schema and migrations | ||
| - `src/app/api/actions/` - OpenAPI documentation generation | ||
|
|
||
| ### Provider Types | ||
|
|
||
| The system supports multiple provider types via `providerType` field: | ||
|
|
||
| - `claude` - Anthropic API (standard) | ||
| - `claude-auth` - Claude relay services (Bearer auth only) | ||
| - `codex` - Codex CLI (Response API) | ||
| - `gemini-cli` - Gemini CLI | ||
| - `openai-compatible` - OpenAI Compatible APIs | ||
|
|
||
| ### Format Converters | ||
|
|
||
| Located in `src/app/v1/_lib/converters/`, these handle bidirectional conversion between: | ||
|
|
||
| - Claude Messages API | ||
| - OpenAI Chat Completions API | ||
| - Codex Response API | ||
| - Gemini CLI format | ||
|
|
||
| ### Guard Pipeline | ||
|
|
||
| The `GuardPipelineBuilder` in `src/app/v1/_lib/proxy/guard-pipeline.ts` orchestrates request processing: | ||
|
|
||
| 1. `auth` - API key validation | ||
| 2. `version` - Client version check | ||
| 3. `probe` - Handle probe requests | ||
| 4. `session` - Session management (5-min context caching) | ||
| 5. `sensitive` - Content filtering | ||
| 6. `rateLimit` - Multi-dimensional rate limiting (RPM, USD limits) | ||
| 7. `provider` - Provider selection (weight + priority + circuit breaker) | ||
| 8. `messageContext` - Request logging | ||
|
|
||
| ### Database Schema | ||
|
|
||
| Core tables in `src/drizzle/schema.ts`: | ||
|
|
||
| - `users` - User accounts with quota limits | ||
| - `keys` - API keys with per-key limits | ||
| - `providers` - Upstream provider configurations | ||
| - `messageRequest` - Request logs with token/cost tracking | ||
| - `modelPrices` - Model pricing data (LiteLLM sync) | ||
| - `errorRules` - Error classification rules | ||
| - `sensitiveWords` - Content filtering rules | ||
|
|
||
| ### OpenAPI Documentation | ||
|
|
||
| Server Actions are automatically exposed as REST endpoints via `src/app/api/actions/[...route]/route.ts`: | ||
|
|
||
| - Swagger UI: `/api/actions/docs` | ||
| - Scalar UI: `/api/actions/scalar` | ||
| - OpenAPI JSON: `/api/actions/openapi.json` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Key environment variables (see `.env.example`): | ||
|
|
||
| - `ADMIN_TOKEN` - Admin login token (required) | ||
| - `DSN` - PostgreSQL connection string | ||
| - `REDIS_URL` - Redis for rate limiting and sessions | ||
| - `AUTO_MIGRATE` - Enable automatic DB migrations | ||
| - `ENABLE_RATE_LIMIT` - Enable rate limiting features | ||
| - `SESSION_TTL` - Session cache duration (default 300s) | ||
|
|
||
| ## Important Patterns | ||
|
|
||
| ### Path Alias | ||
|
|
||
| All imports use `@/*` alias mapping to `./src/*`. | ||
|
|
||
| ### i18n | ||
|
|
||
| Internationalization via `next-intl` with messages in `/messages/{locale}/`. | ||
|
|
||
| ### Rate Limiting | ||
|
|
||
| Redis Lua scripts ensure atomic operations. Fail-open strategy when Redis unavailable. | ||
|
|
||
| ### Circuit Breaker | ||
|
|
||
| Per-provider circuit breaker with configurable thresholds. States: CLOSED → OPEN → HALF_OPEN. | ||
|
|
||
| ### Session Stickiness | ||
|
|
||
| 5-minute session caching to maintain provider consistency within conversations. | ||
|
|
||
| ## PR Guidelines | ||
|
|
||
| - All PRs must target `dev` branch (never `main` directly) | ||
| - Run `bun run lint && bun run typecheck` before committing | ||
| - Follow Conventional Commits format (feat/fix/chore/refactor/test) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Missing Provider Type:
gemininot listed in Provider Types sectionProblem: The Provider Types section lists 5 provider types but omits
gemini. According to the database schema insrc/drizzle/schema.ts:105, theproviderTypefield supports 6 types includinggemini:Impact: Developers may not know that
gemini(distinct fromgemini-cli) is a valid provider type, leading to confusion when configuring providers.Suggested Fix:
Note: The same issue exists in CLAUDE.md (which correctly includes
geminiin the PR version), but this file (AGENTS.md) is missing it.