Conversation
- 支持从 Redis/数据库加载每个供应商独立的熔断器配置 - 缓存熔断器配置以减少 Redis 查询并提升性能 - 引入熔断器配置缓存清理功能 - 在服务商管理界面添加熔断器配置项 - 将熔断器状态判断改为异步支持 - 在服务商增删改操作中同步熔断器配置到 Redis - 增加数据库字段以存储熔断器相关配置
- 添加 claude-auth 类型至 Schema、枚举及表单 - 实现 claude-auth 类型的 x-api-key 去除逻辑以避免中转服务冲突 - 更新校验规则以支持 claude-auth 类型 - 在模型选择逻辑中处理 claude-auth 类型
- 支持允许用户清空输入框,在提交时使用默认值 - 更新初始化状态为 undefined,当用户未输入时采用默认值 - 修复表单输入框的 placeholder 适配 - 在提交表单时添加空值处理逻辑以避免错误
- 在健康状态检查中,自动检测并更新过期的熔断器状态 - 打开状态(open)超时后自动转为半开状态(half-open) - 添加日志以记录状态变化 - 优化 Redis 客户端重试日志格式,修复字符串模板问题 - 将 docker-compose 中的 redis 依赖状态从 service_started 更新为 service_healthy 以确保服务健康
- 将 CreateProviderSchema 和 UpdateProviderSchema 的 key 字段的最大长度限制从 255 扩大到 1024 - 支持更长的 API 密钥以满足更复杂的安全需求 - 更新相关校验规则,确保兼容性和一致性
- 实现熔断器告警通知功能,支持 Webhook 推送并防止重复推送(5 分钟内) - 添加每日排行榜通知及成本预警通知,支持定时任务调度 - 引入 Bull 队列管理通知发送及重试逻辑 - 在设置页面新增消息推送管理界面,支持 Webhook 测试及动态配置 - 更新开发环境和生产环境通知任务初始化逻辑,修复相关兼容性问题
- 为每日排行榜和成本预警通知任务引入动态数据生成逻辑 - 在任务执行时动态生成排行榜数据及成本预警数据,去除之前的占位符字段 - 当生成数据为空时跳过任务并新增日志记录以追踪此情况 - 优化 buildDailyLeaderboard 与 buildCostAlert 数据构造逻辑,支持动态输入 - 更新 NotificationJobData 接口,将 data 字段改为可选以支持动态任务
- 移除通知任务队列中的冗余 name 参数,使用 jobId 标识任务以便管理 - 简化每日排行榜、成本预警及熔断器告警消息模板内容,提升信息清晰度 - 调整消息格式,减少冗长说明,优化重要信息展示方式
* fix: 供应商管理列表增加类型筛选和图标显示, close #22 新功能: 1. 增加供应商类型筛选功能 - 支持按 Claude、Claude Auth、Codex、Gemini CLI、OpenAI Compatible 筛选 - 显示当前筛选结果数量 2. 供应商卡片名称增加类型图标和标签 - 类型图标(5 种不同颜色和图标) - 类型标签(文字说明) - 鼠标悬停显示类型描述 实现细节: - 新增 provider-type-utils.tsx:统一管理供应商类型配置 - 新增 provider-type-filter.tsx:类型筛选组件 - 修改 provider-manager.tsx:集成筛选功能和计数显示 - 修改 provider-list-item.tsx:添加类型图标和标签 Close #22 * feat: 添加 @lobehub/icons 依赖并更新供应商类型图标 - 新增 @lobehub/icons 依赖,支持更丰富的图标展示。 - 更新供应商类型配置,使用新的图标组件替代原有图标。 - 为 Anthropic 类型添加专用的橙色包装组件,提升视觉一致性。 影响范围: - 供应商管理界面图标展示更为美观,增强用户体验。 --------- Co-authored-by: Claude Code Bot <noreply@anthropic.com> Co-authored-by: ding113 <h.ding.262@gmail.com>
- 修复 sumUserCostToday 中 SQL JOIN 条件错误(message_request.key 应与 keys.key 关联,而非 keys.id) - 修复日志字符串插值未生效问题(单引号改为反引号) - 移除不必要的类型断言,利用 TypeScript 类型收窄 - 优化 Redis TTL 计算,使用配置时区而非服务器本地时区 - 添加 date-fns-tz 依赖用于时区处理 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts: # VERSION # drizzle/meta/_journal.json # src/lib/circuit-breaker.ts
- Modified `claude-assistant.yml` to reduce pull request event types and limit issue event types to only labeled events. - Updated `claude-ci-autofix.yml` to remove the requirement for associated pull requests, allowing CI fixes on any branch.
- 修复 src/repository/statistics.ts 中的 TypeScript any 类型错误(第 579 行) - 移除 src/app/dashboard/_components/user/key-limit-usage.tsx 中未使用的 err 变量 - 移除 src/app/settings/providers/_components/provider-list-item.tsx 中未使用的导入(ServerCog, AddProviderDialog) - 移除 src/app/usage-doc/page.tsx 中未使用的导入和变量(cn, lang, configDir) - 移除 src/lib/rate-limit/service.ts 中未使用的 now 变量 所有修复均为 ESLint 相关的代码质量改进,不影响功能逻辑。 相关 CI Run: https://github.com/ding113/claude-code-hub/actions/runs/18933737607
- Removed the requirement for the commit message in scenario B to include [skip ci], ensuring it triggers CI again. - Adjusted instructions for auto-fixing CI failures to reflect the new commit message policy. This change aims to streamline the CI process and improve clarity in the workflow documentation.
- Introduced a new environment variable ENABLE_CODEX_INSTRUCTIONS_INJECTION to control the injection of official Codex instructions into requests. - Updated .env.example and CLAUDE.md to document the new feature and its usage scenarios. - Modified request-sanitizer.ts to implement the logic for conditionally replacing instructions based on the new feature flag. This enhancement allows for better compatibility with certain Codex providers that require official instructions.
feat: 优化若干功能 主要变更: - ✅ 限额管理系统(前端页面 + API) - ✅ 时间算法优化(周/月限额改为自然时间窗口) - ✅ 通知告警系统(熔断器、成本预警、排行榜) - ✅ Session 缓存优化 - ✅ 熔断器增强 - ✅ 新增 81 个文件,修改多个核心模块 验证情况: - ✅ TypeScript 类型检查通过 - ✅ 生产构建成功 - ✅ ESLint 仅有预期的 3 个警告 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**Bug 描述:**
- cleanup-queue.ts 在模块加载时立即创建 Bull Queue 实例
- 配置 enableOfflineQueue: false 导致 Redis 未连接时抛出错误
- Promise rejection 未被捕获,导致 unhandledRejection 错误
**问题日志:**
```
{"level":"error","action":"schedule_auto_cleanup_error","error":"Stream isn't writeable and enableOfflineQueue options is false"}
[Error: Stream isn't writeable and enableOfflineQueue options is false]
⨯ unhandledRejection: [Er
```
**修复方案:**
- 将 cleanupQueue 从导出常量改为私有变量
- 添加 getCleanupQueue() 延迟初始化函数
- 更新所有使用 cleanupQueue 的地方调用 getter
- 参考 notification-queue.ts 的正确模式
**测试结果:**
✅ TypeScript 类型检查通过
✅ 生产构建成功
✅ Docker 容器启动正常
✅ 清理队列初始化成功(cleanup_queue_initialized)
✅ 自动清理任务调度成功(auto_cleanup_scheduled)
✅ 无 unhandledRejection 错误
✅ 无 "Stream isn't writeable" 错误
**关联 PR:** #29
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: 修复用户分组过滤功能 - 补全 providerGroup 字段查询 (#31) 修复问题: validateApiKeyAndGetUser 函数在查询用户信息时遗漏了 providerGroup 字段,导致 session.authState.user.providerGroup 始终为 undefined,供应商选择器中的用户分组过滤逻辑无法生效。 修改内容: - 在 SELECT 查询中添加 userProviderGroup: users.providerGroup - 在构建 User 对象时传递 providerGroup: row.userProviderGroup 影响范围: - 恢复用户分组过滤功能,使设置了 providerGroup 的用户请求能够正确过滤到对应 groupTag 的供应商 - 向后兼容,未设置 providerGroup 的用户行为不变 - 无需数据库迁移或环境变更" Co-authored-by: GuShenghua <gushenghua@sdesrd.com> * chore: sync VERSION file with release v0.2.13 [skip ci] * feat: 价格表页面增加分页功能,close #35 - 添加分页接口 PaginationParams 和 PaginatedResult - 新增 findAllLatestPricesPaginated 分页查询方法 - 新增 getModelPricesPaginated action 函数 - 新增 /api/prices API 端点支持分页查询 - 重构 PriceList 组件支持分页、页面大小选择、搜索 - 修改价格表页面支持分页参数和降级处理 - 支持URL参数同步分页状态 - 优化性能,避免一次性加载大量数据 * fix: 修复价格表分页功能的审查意见 主要改进: - 添加 /api/prices 端点权限检查,确保只有管理员可访问 - 实现 SQL 层面的搜索过滤,提升大数据量场景下的性能 - 添加搜索防抖机制(500ms),优化用户体验 - 移除客户端过滤逻辑,统一使用后端搜索 - 优化 useEffect 依赖,避免不必要的 API 请求 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: gsh <gushenghua@outlook.com> Co-authored-by: GuShenghua <gushenghua@sdesrd.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Assistant <noreply@github.com> Co-authored-by: ding113 <h.ding.262@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Ding <44717411+ding113@users.noreply.github.com>
- Added a new navigation item for the API documentation in the settings menu. - Updated package.json and pnpm-lock.yaml to include new dependencies: @hono/swagger-ui, @hono/zod-openapi, and @scalar/hono-api-reference.
- Add eslint-disable comments for necessary 'any' types in action-adapter-openapi.ts - Remove unused webhookUrl parameter from sendCircuitBreakerAlert function - Remove unused imports (systemConfigActions, KeyFormSchema) from actions route - Fix React hooks exhaustive-deps warning by wrapping loadSettings with useCallback - Remove unused settings state variable in notifications page These changes fix all ESLint errors that were blocking the Docker build in CI.
- Added automated API documentation generation using OpenAPI 3.1.0 with Swagger and Scalar UI, supporting 39 REST API endpoints. - Implemented pagination for the price list, optimizing performance for large datasets with SQL-level enhancements and search debounce. - Updated CLAUDE.md and README.md to reflect new features and usage instructions for API documentation and pagination. These changes improve usability and performance for managing API interactions and large data queries.
- 将优先级说明从 "(0最高)" 改为 "(数值越小优先级越高,0为最高)" - 消除用户对优先级排序规则的理解歧义 - 明确说明数值越小优先级越高,0为最高优先级 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements comprehensive proxy configuration for providers to improve connectivity from restricted networks (e.g., mainland China accessing overseas APIs). ## New Features ### Database Schema - Added `proxy_url` field (varchar 512) to providers table - Added `proxy_fallback_to_direct` boolean field with default false - Created migration file 0014_overconfident_mongu.sql ### Core Proxy Logic - Created `src/lib/proxy-agent.ts` with auto-detection of proxy protocols - HTTP/HTTPS: uses undici ProxyAgent - SOCKS4/SOCKS5: uses SocksProxyAgent - Includes proxy URL validation and password masking for logs - Integrated proxy support into request forwarding layer (forwarder.ts) - Applied dispatcher to fetch requests - Implemented fallback-to-direct logic on proxy failures - Added detailed proxy error logging ### Connection Testing - Created `testProviderProxy` Server Action - Uses HEAD request (no quota consumption) - 5-second timeout - Returns detailed results (status code, response time, proxy usage, errors) - Created ProxyTestButton component with real-time status display - Shows testing state (in-progress, success, failure) - Displays detailed results (status code, response time, connection method, error type) - Toast notifications integration ### UI Integration - Extended provider form with "Proxy Configuration" section - Proxy URL input with protocol examples - Fallback strategy switch - Test connection button - State management and form submission - Updated Server Actions to handle proxy fields (addProvider/editProvider/getProviders) ### Type Safety & Validation - Updated TypeScript interfaces (Provider, ProviderDisplay, CreateProviderData, UpdateProviderData) - Added Zod validation schemas with length limits - All type checks passing ### Documentation - Added "Proxy Support" section to CLAUDE.md - Configuration guide - Technical implementation details - Usage scenarios - Added "Proxy Connection Failure" troubleshooting section ## Dependencies - Added `socks-proxy-agent@8.0.5` - Added `undici@7.16.0` (dev dependency for types) ## Technical Details - Auto-protocol detection based on URL scheme - Per-provider configuration granularity - Optional fallback to direct connection on proxy failures - Security: automatic password masking in logs - Supports authenticated proxies (username:password@host:port) Closes #41 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This migration file was a duplicate entry created during PR #42 merge. It was never registered in _journal.json and the fields it added (allow_view_provider_info, non_admin_currency_display) were not included in schema.ts or used in the codebase. The official 0013 migration is 0013_outgoing_justin_hammer.sql which creates the notification_settings table. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts: - VERSION: Updated to 0.2.22 - public/seed/litellm-prices.json: Used main's version (more up-to-date) - drizzle/meta/_journal.json: Kept dev's migration 0014 - src/app/v1/_lib/proxy/forwarder.ts: Merged client abort detection with proxy error handling - Removed duplicate migration file 0013_optimal_darkhawk.sql Changes from main: - REST API support and notification system (PR #42) - Updated LiteLLM price data - Version bump to 0.2.22 Changes from dev: - Provider-level proxy support (HTTP/HTTPS/SOCKS4/SOCKS5) - API documentation enhancements - Price table pagination - Migration 0014 for proxy fields All type checks passed ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
src/app/v1/_lib/proxy/forwarder.ts
Outdated
|
|
||
| throw fetchError; | ||
| // 移除 dispatcher,重新发起请求 | ||
| delete init.dispatcher; |
There was a problem hiding this comment.
潜在问题:降级逻辑可能导致安全风险
当代理失败后自动降级到直连时,移除了 dispatcher 但没有重新创建 init 对象,这可能导致一些与代理相关的配置残留。
建议修改:
// 移除 dispatcher,重新发起请求
const fallbackInit = { ...init };
delete fallbackInit.dispatcher;
try {
response = await fetch(proxyUrl, fallbackInit);
logger.info("ProxyForwarder: Direct connection succeeded after proxy failure", {
providerId: provider.id,
providerName: provider.name,
});
} catch (directError) {
// ...
}这样可以确保降级请求是完全干净的,避免代理配置残留。
src/lib/config/env.schema.ts
Outdated
| AUTO_MIGRATE: z | ||
| .string() | ||
| .default("true") | ||
| .transform((s) => s !== "false" && s !== "0"), |
There was a problem hiding this comment.
改进建议:统一布尔值转换逻辑
当前每个布尔值字段都重复相同的 transform 逻辑,建议提取为公共函数:
// 在文件顶部添加
const booleanTransform = (s: string) => s !== "false" && s !== "0";
// 然后在 schema 中使用
AUTO_MIGRATE: z.string().default("true").transform(booleanTransform),
ENABLE_RATE_LIMIT: z.string().default("true").transform(booleanTransform),
ENABLE_SECURE_COOKIES: z.string().default("true").transform(booleanTransform),
// ...这样可以减少代码重复,提高可维护性。
src/lib/proxy-agent.ts
Outdated
|
|
||
| return { | ||
| agent, | ||
| fallbackToDirect: provider.proxyFallbackToDirect, |
There was a problem hiding this comment.
安全建议:默认值问题
fallbackToDirect 使用 provider.proxyFallbackToDirect 作为默认值,但如果该字段为 undefined,这里会返回 undefined 而不是 false。
建议修改:
return {
agent,
fallbackToDirect: provider.proxyFallbackToDirect ?? false, // 使用 ?? 确保默认为 false
proxyUrl: maskProxyUrl(proxyUrl),
};这样可以确保当字段为 undefined 或 null 时,默认不降级(更安全的策略)。
| if (response.data.success) { | ||
| const details = response.data.details; | ||
| const proxyUsed = details?.usedProxy ? "(通过代理)" : "(直连)"; | ||
| const responseTime = details?.responseTime ? `${details.responseTime}ms` : "N/A"; |
There was a problem hiding this comment.
UI 改进建议:添加超时提示
当前测试超时时只显示 "连接超时(5秒)",但用户可能不知道这是正常的代理连接测试超时时间。
建议改进:
toast.error("连接失败", {
description:
errorType === "Timeout"
? "连接超时(5秒)。请检查:\n1. 代理服务器是否可访问\n2. 代理地址和端口是否正确\n3. 代理认证信息是否正确"
: errorType === "ProxyError"
? `代理错误: ${errorMessage}`
: `网络错误: ${errorMessage}`,
duration: 5000, // 延长显示时间,让用户看清楚
});这样可以提供更友好的用户体验和诊断提示。
代码审查总结感谢你的贡献!这个 PR 包含了两个重要的修复和功能增强: ✅ 主要改进
📝 行内评论我已经在代码中添加了 4 条行内评论,主要关注:
🔍 其他观察
|
针对 claude bot 在 PR #49 中提出的 4 个改进建议进行修复: 1. proxy-agent.ts - 修复 fallbackToDirect 默认值处理 - 使用空值合并运算符 (??) 确保默认值为 false - 避免 undefined/null 导致降级逻辑失效 2. env.schema.ts - 提取布尔值转换逻辑为公共函数 - 减少代码重复,提高可维护性 - 5 处重复逻辑统一使用 booleanTransform 函数 3. forwarder.ts - 修复代理降级逻辑的配置残留问题 - 创建新的配置对象而非修改原对象 - 避免代理配置残留导致的潜在问题 4. proxy-test-button.tsx - 改进超时错误提示 - 提供详细的故障排查步骤 - 延长 toast 显示时间到 5 秒 所有修复已通过 typecheck 和 format 验证。 Ref: #49 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
这个 PR 的目标分支是 必须遵循的工作流:
解决方案:
请修正后我会继续进行代码审查。 |
📋 代码审查总结经过详细审查,PR #49 及其后续修复提交(7cdfdf4)实现了一个完整、安全且可维护的代理支持功能。 ✅ 主要功能
✅ 代码质量亮点PR #49 修复提交(7cdfdf4)成功应用了 4 项关键改进:
📊 评分
总体评分:9.0/10 🔍 关键审查结果✅ 安全性
✅ 类型安全
✅ 错误处理
✅ 文档完整性
💡 改进建议(可选)高优先级:
中优先级:
|
No description provided.