fengsilin
6e81faa698
perf: lazy-read body in DoApiRequest for passthrough model mapping
DoApiRequest previously called io.ReadAll on every request body to apply
passthrough model mapping, even when the feature was disabled. This
caused unnecessary memory pressure for large request bodies (long
conversations, multipart image uploads).
Split the guard logic into needsPassthroughModelMapping() so that
ReadAll is only called when all conditions are met (feature enabled +
passthrough mode + model mapped). Non-passthrough requests now pass
the original io.Reader directly to http.NewRequest without buffering.
Rewrite tests to verify combined guard + modify behavior.
2 недель назад
fengsilin
6434a523a1
feat: passthrough model mapping
2 недель назад
fengsilin
e51a66c5f9
feat(metrics): postConsumeQuota 中采集 token/配额/延迟指标
3 недель назад
fengsilin
f1a68027f1
Revert "feat(cache): OpenAI→Claude 转换自动注入 prompt caching"
This reverts commit ff14caed7c .
4 недель назад
fengsilin
ff14caed7c
feat(cache): OpenAI→Claude 转换自动注入 prompt caching
- ClaudeRequest 新增 CacheControl 字段
- RequestOpenAI2ClaudeMessage 自动注入顶层 cache_control: {"type":"ephemeral"}
- System 复合内容和普通消息 content block 的 CacheControl 透传
- ParseContent 新增 []MediaContent 类型断言,修复透传路径
- 新增 8 个单元测试覆盖自动注入、透传、序列化等场景
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 недель назад
fengsilin
e6b4a06557
feat(logs): 隐藏使用日志中的分组信息展示
使用注释方式隐藏分组列和分组倍率标签,便于后续恢复:
1. 注释 UsageLogsColumnDefs.jsx 中的分组列定义
2. 注释 useUsageLogsData.jsx 中的 COLUMN_KEYS.GROUP 和默认可见性配置
3. 将计费详情中的"分组倍率"改为"倍率"
后端计费逻辑不变,仍正常应用分组倍率。
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
1 месяц назад
fengsilin
2d1a8d2f28
fix: 设置 chat_id + 优化日志查询参数构建
- Claude 和 OpenAI Responses 转发中设置 RelayChatID
- 日志查询使用 URLSearchParams 替代手动字符串拼接
- 日志查询日期范围改为可选,不再强制默认今天
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 месяц назад
fengsilin
b026f6bc04
feat: 用户倍率前端展示 + 渠道下拉选择 + 上游调试日志
- UserRatioSection 渠道 ID 输入改为带搜索的下拉选择器
- 使用日志详情、计费过程、展开行均显示用户倍率
- renderLogContent suffix 统一追加,消除 4 处重复
- 提取 dumpUpstreamRequest 辅助函数,debug 日志走 SysLog
Co-Authored-By: Claude <noreply@anthropic.com>
1 месяц назад
fengsilin
9dbf3365fe
feat(pricing): 添加用户-模型-渠道倍率功能
为每个用户添加独立于全局定价的倍率乘数,支持按 (userId, model, channel) 三维
精确控制用户级别定价。倍率以乘法叠加在现有 modelRatio × groupRatio 之上。
- 新增 user_channel_ratios 表,写入内存缓存(写穿透模式)
- 新增 /api/user_channel_ratio/ CRUD API(AdminAuth)
- 计费路径集成:compatible_handler、PostClaudeConsumeQuota、
PostWssConsumeQuota、PostAudioConsumeQuota、calculateAudioQuota
- 前端:EditUserModal 内嵌 UserRatioSection 组件
- 修复 Update() 缓存 key 零值 bug(先加载再更新)
- 修复 PreWssConsumeQuota 缺少 UserChannelRatio 导致归零
- 修复 ModelPriceHelperPerCall 缺少默认值 1.0
Co-Authored-By: Claude <noreply@anthropic.com>
1 месяц назад
fengsilin
8945f8c39e
fix: synced 用户剩余额度取 synced_quota + 记录 chat ID
- 前端用户列表:synced 用户显式取 synced_quota 字段作为剩余额度
- 各 OpenAI handler 中记录 relayChatID 用于日志追踪
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 месяц назад
fengsilin
e41f2951f7
fix: preserve relay body and capture invalid responses body
1 месяц назад
fengsilin
b2cb7bcf60
feat: record chat and upstream ids in usage logs
1 месяц назад
fengsilin
caf457ce9e
feat: 错误时记录上游响应体,支持流式
- 提取 TruncateBody 公共函数,截断到 2KB 避免日志过大
- 新增 handleResponsesStreamError 统一 SSE 错误提取逻辑
- 流式/非流式 Responses API 错误路径均捕获 UpstreamBody
- 添加 upstream_body 和 truncate_body 单元测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 месяц назад
fengsilin
575f84064e
feat: codex API key 模式 + 前端凭证回显修复
- codex adaptor 支持 API key 和 OAuth 两种认证模式
- 提取 setupOAuthHeader 和 shouldUseChatCompletionsViaResponses
- 修复编辑页 codex_credential_mode 切换/回显不同步问题
- ResponsesStreamResponse 添加 Error 字段支持独立错误事件
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 месяц назад
fengsilin
a0ac37b2a9
fix: 替换 println 为 SysLog,修复 logger nil context 崩溃
- logger: 增加 ctx nil 检查,避免系统级日志 panic
- relay: 将 DebugEnabled 下的 println 替换为 SysLog
- price: 修复渠道定价在 ChannelMeta 未初始化时的获取失败问题
Co-Authored-By: Claude <noreply@anthropic.com>
1 месяц назад
fengsilin
f0f0215b20
fix(pricing): 修复缓存倍率写入默认值1和缓存创建token丢失
1. CopyGlobalPricing 检查 ratio 查找的 bool 返回值,未找到时写 0
而非写入 fallback 值 1,避免覆盖全局正确的 0.1
2. Claude 响应使用 GetCacheCreationTotalTokens() 替代直接读
CacheCreationInputTokens,兼容新版本子对象格式
3. 新增 GetAudioRatioV2/GetAudioCompletionRatioV2 带 bool 返回
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 месяц назад
fengsilin
387f6c1ae0
feat(pricing): 定价数据源切换到渠道表,新增缓存价格展示
- 后端 pricing API 从 channel_pricings 表获取实际定价,选取最便宜渠道
- 提取 applyGlobalDefault 辅助函数消除全局回退逻辑重复
- price.go 重构扩展比率为局部变量,简化回退逻辑
- 定价卡片新增缓存读取/创建价格,改为两行布局防止溢出
- ChannelPricingCard 缓存列显示实际价格而非倍率
- 修复移动端 hero 区域 padding 过大
- 默认标签页标题改为 Loading...
- 新增缓存读取/创建 i18n 翻译(7 语言)
Co-Authored-By: Claude <noreply@anthropic.com>
1 месяц назад
fengsilin
00058cd671
refactor(channel-pricing): 提取辅助方法消除重复代码,修复缓存一致性
- 提取 PriceData.ApplyChannelPricingRatios 消除 ModelPriceHelper 和
UpdatePriceDataForChannelPricing 中重复的 ~30 行比率回退逻辑
- 提取 ChannelPricing.ApplyFields 消除 controller 中 4 处相同的字段赋值
- 提取 setCache/removeCache 辅助函数统一写穿透缓存操作
- 将 claudeCacheCreation1hMultiplier 常量移至 types 包避免循环依赖
- 修复 BatchUpsertChannelPricing 成功后未刷新内存缓存的 bug
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 месяц назад
fengsilin
3a24fd598f
feat(channel-pricing): ModelPriceHelper + UpdatePriceDataForChannelPricing 适配新签名,支持扩展比率覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 месяц назад
fengsilin
97485bfede
feat: 移植上游 Param Override 增强系统
从上游移植 override.go 的完整增强功能(603行→2057行),包括:
新增 9 种 Operation Mode:
- return_error: 规则直接返回 HTTP 错误中断请求
- prune_objects: 按 JSON Schema 过滤数组元素
- set_header / delete_header / copy_header / move_header: 动态管理上游请求头
- pass_headers: 透传下游请求头到上游
- sync_fields: 请求体不同路径间同步字段值
- 通配符路径支持: messages.*.role 等
新增核心模块:
- Header Override 系统:从上下文取值、正则匹配、列表追加
- Audit 审计系统:关键操作自动记录到 RelayInfo.ParamOverrideAudit
- Return Error 机制:含状态码/错误类型/跳过重试控制
- Legacy 兼容层:同时执行旧格式和新格式 param override
- RelayInfo 集成:丰富上下文(retry_index、last_error、request_headers 等)
RelayInfo 新增字段:RetryIndex, LastError, RequestHeaders,
RuntimeHeadersOverride, UseRuntimeHeadersOverride, ParamOverrideAudit
所有 handler 统一使用 ApplyParamOverrideWithRelayInfo,
全部测试通过(100+ test cases)。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 месяцев назад
fengsilin
296edf0f71
fix: 移植上游关键 bug 修复
从 QuantumNous/new-api 上游移植以下修复:
- fix(ssrf): 加固视频代理和 MJ 图片代理的 SSRF 防护,FetchModels 提权至 RootAuth
- fix(claude): 流式断流时不再整份覆盖 usage,保留 cache 计费字段
- fix(pricing): 定价接口增加用户可用分组过滤
- fix(ratio): compact 模型优先匹配精确定价再回退通配符
- fix(ali): 接受 task polling 返回的字符串类型 usage 值
- fix(gemini): 从 URL 路径 :streamGenerateContent 检测流式请求
- fix(zhipu_4v): coding plan 图片生成使用正确的 OpenAI endpoint
- fix(openai): MessageImageUrl.Detail 字段添加 omitempty
- fix(channel-affinity): skip_retry_on_failure 配置项为 false 时不再丢失
- fix(document-renderer): 使用 useMemo 替代 useState 处理 HTML payload
- fix(fetch-setting): ApplyIPFilterForDomain 默认值改为 true
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 месяцев назад
fengsilin
1cecd5349d
feat: 跨区域配额同步(Master-Slave Region Sync)
实现 Master-Slave 架构的跨区域用户和配额同步功能,支持国内主节点与
海外从节点之间的用户创建推送、余额同步、预扣费批量回传。
主要变更:
- 新增 region_sync 服务层(SyncManager/SyncClient/推送逻辑)
- User 模型扩展 Source/RemoteUserId/SyncedQuota/LastSyncAt 字段
- BillingSession 支持 SyncedUserFunding 资金来源
- 新增 SyncAuth 中间件(X-Sync-API-Key + 常量时间比较)
- 新增 PendingSyncRecord/QuotaSyncLog 数据模型
- 前端新增区域同步配置面板
- 支持 SESSION_NAME 环境变量避免多节点 cookie 冲突
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 месяцев назад
fengsilin
b99337dab7
fix(pricing): 修复渠道定价优先级问题
当模型配置了渠道定价但全局定价未设置时,不再提前报错。
将全局定价检查延迟到渠道选择后执行。
Co-Authored-By: Claude <noreply@anthropic.com>
2 месяцев назад
fengsilin
15a99da48e
fix: channel pricing not working correctly
This PR fixes three issues:
1. Token bound_channel_id not updating: Add bound field to Update() method
2. Channel pricing quota_type detection: Use QuotaTypeByCall constant instead of magic number 1
3. Log display for ratio-based pricing: Set ModelPrice=-1 for ratio-based pricing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 месяцев назад
fengsilin
db939deb79
feat: integrate channel pricing into ModelPriceHelper
Integrate channel-specific pricing into the billing logic.
- First tries to get channel pricing using model.GetEffectivePricing
- If found, uses channel pricing (modelRatio, completionRatio, modelPrice, usePrice)
- If not found, falls back to global pricing from ratio_setting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 месяцев назад
winter
08164cd0ae
fix
3 месяцев назад