Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
37d8665
feat(mcp): 实现 MCP 透传功能
flintttan Nov 21, 2025
3af58b6
Merge branch 'ding113:main' into feature/mcp-passthrough
flintttan Nov 21, 2025
e9a0c1f
chore: format code (feature-mcp-passthrough-3af58b6)
github-actions[bot] Nov 21, 2025
2fe8c96
feat(mcp): 支持 GLM MCP 透传功能及多语言配置
flintttan Nov 22, 2025
5365e1d
Merge branch 'feature/mcp-passthrough' with GLM MCP support
flintttan Nov 22, 2025
8d59f3a
chore: format code (feature-mcp-passthrough-5365e1d)
github-actions[bot] Nov 22, 2025
4553d5a
Fix: Address PR review comments
flintttan Nov 22, 2025
206eff1
Merge upstream/dev and resolve conflicts (rename migration to 0024)
flintttan Nov 22, 2025
f54e9b3
chore: fix lint warnings
flintttan Nov 22, 2025
ef35782
Merge branch 'feature/mcp-passthrough' of github.com:flintttan/claude…
flintttan Nov 22, 2025
8a1c899
chore: format code (feature-mcp-passthrough-ef35782)
github-actions[bot] Nov 22, 2025
3cea385
feat(providers): 改进 API 测试以支持流式响应检测与处理
Silentely Nov 22, 2025
4576c53
fix(providers): 移除max_output_tokens 参数以兼容中转服务
Silentely Nov 22, 2025
35276ea
feat(providers): 支持解析和处理流式响应数据
Silentely Nov 22, 2025
867ad77
feat(api-test): 增加流式响应信息展示功能
Silentely Nov 22, 2025
d1bee4c
fix(settings): 调整供应商模型测试提示文本
Silentely Nov 22, 2025
b2945a5
style: 修复代码格式以通过 Prettier 检查
Silentely Nov 22, 2025
0531057
fix: 修复代码审查中发现的关键问题
Silentely Nov 22, 2025
47537a7
Merge pull request #185 from Silentely/fix-provider-test
ding113 Nov 22, 2025
07267a5
fix: 优化供应商测试和日志系统
Silentely Nov 22, 2025
93d4b7b
Merge branch 'fix/provider-test-and-logs' into dev
Silentely Nov 22, 2025
cc3e30c
refactor: 根据代码审查优化实现
Silentely Nov 22, 2025
c175285
fix: resolve Docker build failure by excluding Node.js modules
github-actions[bot] Nov 22, 2025
a178d13
fix: 根据 ding113 审查意见完成修复
Silentely Nov 22, 2025
53b09cc
fix: add webpack externals for Node.js built-in modules
github-actions[bot] Nov 22, 2025
22062f4
fix: 修复 log-time-formatter 的 null 安全问题并添加文档
Silentely Nov 22, 2025
25cf1c3
refactor: 删除未使用代码并优化错误处理
Silentely Nov 22, 2025
dddcaf9
Merge pull request #186 from Silentely/dev
ding113 Nov 22, 2025
d0d5cce
fix: 修复 Gemini 模型重定向无效的问题
ding113 Nov 23, 2025
19b3d49
Merge remote-tracking branch 'upstream/dev' into feature/mcp-passthrough
flintttan Nov 23, 2025
417b9eb
Merge branch 'feature/mcp-passthrough' of github.com:flintttan/claude…
flintttan Nov 23, 2025
229f447
fix: enhance MCP passthrough with security and stability improvements
flintttan Nov 23, 2025
4ff7a5c
chore: format code (feature-mcp-passthrough-229f447)
github-actions[bot] Nov 23, 2025
dfa8db5
Merge pull request #157 from flintttan/feature/mcp-passthrough
ding113 Nov 23, 2025
f932424
fix: 修复供应商 API 测试返回 520 错误的问题
Silentely Nov 24, 2025
30b0911
fix: 修复代理降级时 Body has already been read 错误
Silentely Nov 24, 2025
2918043
chore: 增加 API 测试超时时间到 15 秒
Silentely Nov 24, 2025
5409736
feat: 改进供应商 API 测试体验
Silentely Nov 24, 2025
e2a8ff8
fix: Anthropic API 测试同时发送两种认证头
Silentely Nov 24, 2025
d592091
fix: 修复 Codex API 测试请求体格式
Silentely Nov 24, 2025
be3cd1c
fix: 修正 Pino 日志时间戳配置位置
Silentely Nov 24, 2025
2ad3dd8
chore: 移除重复的 API 测试注意事项
Silentely Nov 24, 2025
a3a007e
chore(i18n): remove unused notice field from apiTest section
Silentely Nov 24, 2025
26a112f
feat(i18n): add disclaimer translations for API test feature
Silentely Nov 24, 2025
e320e54
feat(providers): 增强 API 测试错误解析逻辑
Silentely Nov 24, 2025
bdb2041
fix: 修复供应商多标签匹配问题 (#190)
ding113 Nov 24, 2025
d0dd669
fix: 修复 Codex 供应商 API 测试失败问题 (#189)
ding113 Nov 24, 2025
71f59d6
feat: 优化使用记录状态码颜色显示 (#188)
ding113 Nov 24, 2025
4e3402d
feat: 调整流式静默期超时默认值从 10 秒改为 300 秒
ding113 Nov 24, 2025
3a2ef7a
fix: 修复模型重定向日志记录问题
ding113 Nov 24, 2025
79061a7
fix: 修复错误规则正则匹配问题并增强刷新缓存功能
ding113 Nov 24, 2025
ebc05ff
fix(i18n): 修复 API 测试免责声明翻译键路径错误
Silentely Nov 24, 2025
9bdba4f
Merge branch 'dev' into fix/provider-api-test-520-error
Silentely Nov 24, 2025
0d0cce6
fix: harden provider api test diagnostics
Silentely Nov 24, 2025
7e0faf3
Merge pull request #194 from Silentely/fix/provider-api-test-520-error
ding113 Nov 24, 2025
743605d
chore: format code (dev-7e0faf3)
github-actions[bot] Nov 24, 2025
fa93f48
fix: clarify provider response model label
Silentely Nov 24, 2025
410048b
Merge pull request #197 from Silentely/chore/update-response-model-label
ding113 Nov 25, 2025
806e1c4
fix: 修复 PR review 中发现的多个问题
ding113 Nov 25, 2025
1f1592b
chore: revert db schema
ding113 Nov 25, 2025
ab26956
Merge branch 'dev' into feat/mcp-passthrough
ding113 Nov 25, 2025
10c0898
Merge pull request #193 from ding113/feat/mcp-passthrough
ding113 Nov 25, 2025
8656657
docs: update changelog for PR #193
github-actions[bot] Nov 25, 2025
eddbe88
fix: resolve migration snapshot conflict and add MCP passthrough fields
ding113 Nov 25, 2025
817fa74
feat: 更新供应商超时配置默认值为不限制
ding113 Nov 25, 2025
33a47aa
fix: 修复数据导入跨版本兼容性和错误提示问题
ding113 Nov 25, 2025
b4c47ec
chore: format code (dev-33a47aa)
github-actions[bot] Nov 25, 2025
7060ec3
fix: 修复 errorRules.cacheStats i18n 参数不匹配问题
ding113 Nov 25, 2025
ea103ac
fix: 恢复被错误删除的 i18n 字段(descriptionFull/Warning)
ding113 Nov 25, 2025
c70f871
fix: 修复错误规则版本更新后无法自动同步的问题
ding113 Nov 25, 2025
6e36cb1
chore: update doc
ding113 Nov 25, 2025
477409f
chore: format code (dev-6e36cb1)
github-actions[bot] Nov 25, 2025
129d565
fix: 修复模型重定向信息未保存到数据库的问题
ding113 Nov 25, 2025
3aadc90
docs: 补充 CLAUDE.md 遗漏的 gemini provider 类型
ding113 Nov 25, 2025
08db1b7
fix: 修复 ErrorRuleDetector 懒初始化的竞态条件
ding113 Nov 25, 2025
eecd4f7
Merge branch 'main' into dev
ding113 Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ APP_PORT=23000
APP_URL= # 应用访问地址(留空自动检测,生产环境建议显式配置)
# 示例:https://your-domain.com 或 http://192.168.1.100:23000

# API 测试配置
# API 测试请求超时时间(毫秒),范围 5000-120000。未设置时默认 15000。
API_TEST_TIMEOUT_MS=15000

# Cookie 安全策略
# 功能说明:控制是否强制 HTTPS Cookie(设置 cookie 的 secure 属性)
# - true (默认):仅允许 HTTPS 传输 Cookie,浏览器会自动放行 localhost 的 HTTP
Expand Down
177 changes: 145 additions & 32 deletions AGENTS.md
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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Missing Provider Type: gemini not listed in Provider Types section

Problem: The Provider Types section lists 5 provider types but omits gemini. According to the database schema in src/drizzle/schema.ts:105, the providerType field supports 6 types including gemini:

.$type<'claude' | 'claude-auth' | 'codex' | 'gemini-cli' | 'gemini' | 'openai-compatible'>()

Impact: Developers may not know that gemini (distinct from gemini-cli) is a valid provider type, leading to confusion when configuring providers.

Suggested Fix:

### 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` - Gemini API
- `gemini-cli` - Gemini CLI
- `openai-compatible` - OpenAI Compatible APIs

Note: The same issue exists in CLAUDE.md (which correctly includes gemini in the PR version), but this file (AGENTS.md) is missing it.

- `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)
7 changes: 1 addition & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ All notable changes to this project will be documented in this file.

- Add real-time monitoring big screen dashboard with live metrics, 24h trends, provider slots status, and activity stream (#184) @ding113
- Add dark mode support with theme switcher in Dashboard and settings pages (#171) @ding113
- Add dark mode support to provider quota management page (#170) @ding113

### Changed

- Merge dev to main with internationalization improvements (Japanese, Russian, Traditional Chinese) and UI enhancements for daily limit dialogs (#182) @ding113
- Refactor provider quota management page from card layout to compact list layout with circular progress indicators, search, and sorting capabilities (#170) @ding113
- Add MCP (Model Context Protocol) passthrough functionality to forward tool calls to third-party AI services (#193) @ding113

### Changed

Expand Down
Loading
Loading