fengsilin
678add297f
feat(channel): add tianyiyun seedance channel
Co-Authored-By: Codex <noreply@anthropic.com>
1 giorno fa
fengsilin
49ca8a6ae7
fix(kling): 修复原生路由和展示价格保存
- 避免仅编辑展示价格时写入默认真实计费规则
- 将 video-extend 纳入 KlingAiping 原生渠道约束
- 补充相关保存决策、渠道约束和计费展示测试
Co-Authored-By: Codex <noreply@anthropic.com>
4 giorni fa
fengsilin
6f805a6177
refactor: update aiping doubao upstream API paths to multimodal/sd endpoints
- Asset: /api/v1/volcengine/asset → /api/v1/multimodal/sd/assets
- Create video task: /api/v1/videos → /api/v1/multimodal/sd/videos/contents/generations/tasks
- Query video task: /api/v1/videos/{id} → /api/v1/multimodal/sd/videos/contents/generations/tasks/{id}
Co-Authored-By: Claude <noreply@anthropic.com>
1 settimana fa
fengsilin
56400b6c61
feat: KlingAiping 渠道适配 + 展示价格管理后台
- 新增 KlingAiping 渠道 (ChannelTypeKlingAiping = 59)
- 新增 KlingAiping 原生路由 (text2video/image2video/omni-video 等)
- 新增 KlingAiping adaptor (relay/channel/task/kling/aiping/)
- 前端模型定价页面新增「真实计费 / 展示价格」Tab 切换
- 新增 DisplayPricing 组件,支持模型展示价格的增删改
- 新增 displayPricingConfig 工具函数及测试
- 修复 KlingAiping 路由路径匹配与 task 错误响应
Co-Authored-By: Claude <noreply@anthropic.com>
1 settimana fa
fengsilin
84d364d76a
feat: 使用日志计费详情展开与 completion_tokens 修复
前端新增 UsageLogExpandedDetail 点击展开面板和 BillingDetailSummary
hover 计费详情,后端修复 per_1m_tokens 任务结算日志的 completion_tokens
从零值改为写入 total_tokens 实际值。新增 taskBillingLogMerge 合并
任务预扣/结算日志。
Co-Authored-By: Claude <noreply@anthropic.com>
2 settimane fa
fengsilin
2e40bab478
feat: 模型定价矩阵价格取中位数展示
前端模型定价配置 UI 增强(Editor/GeneratorModal/PreviewPanel/PricingGrid),
后端新增 representativeMatrixPrice 取矩阵定价表中位数作为展示价格,
替代原来的 model_price=0 导致的价格展示为空问题。
Co-Authored-By: Claude <noreply@anthropic.com>
2 settimane fa
fengsilin
0e3b98efe0
chore: commit relay SSE error handling fixes and E2E mock server
- relay: SSE stream error exposure improvements (Claude/Gemini/OpenAI)
- test: add mock capture server for E2E relay capture testing
Co-Authored-By: Claude <noreply@anthropic.com>
2 settimane fa
fengsilin
1d01c4cd64
feat: 增强流式响应错误处理,SSE内嵌错误正确曝光为API错误
- Gemini stream: 捕获 promptFeedback.blockReason 后停止流并返回 OpenAPI 错误
- OpenAI stream: 检测 SSE 帧中的 error 响应,在首帧写入前转换为 API 错误
- Responses stream: 处理 response.error / response.failed / error 类型帧
- 新增 ClearEventStreamHeadersIfNotWritten 工具方法,错误转换时清除流式头
- 新增 streamOpenAIErrorFromData,从 SSE data 帧提取 OpenAPI 错误结构
- 上游错误体会截断后存入 UpstreamBody 供排障
Co-Authored-By: Claude <noreply@anthropic.com>
2 settimane fa
fengsilin
696c549a66
feat(video): add doubao aiping video pricing support
Co-Authored-By: Codex <noreply@anthropic.com>
2 settimane fa
fengsilin
3ac94e2e6f
test(task-pricing): cover model pricing api and remix snapshots
3 settimane fa
fengsilin
19bdae5509
fix(stream): default non-positive streaming timeout
3 settimane fa
fengsilin
f3778e3931
test(task-pricing): cover doubao usage parsing
3 settimane fa
fengsilin
3a52f31608
feat(task-pricing): gate channels for matrix usage billing
3 settimane fa
fengsilin
db8eacd558
feat(task-pricing): persist matrix billing snapshots
3 settimane fa
fengsilin
8f2b014366
feat(task-pricing): add matrix lookup decisions
3 settimane fa
fengsilin
ae1e68792a
feat(task-pricing): resolve pricing dimensions from task requests
3 settimane fa
fengsilin
87a0f94975
refactor: remove user-channel-ratio feature
删除用户渠道倍率(UserChannelRatio)功能,清理全链路相关代码:
后端删除 model/controller/router 层实现,前端删除 UI 组件和计费展示逻辑。
同时恢复 Token 分组选择和价格侧边栏分组过滤器的注释代码。
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 mese fa
fengsilin
6ad0524172
test: add comprehensive pricing and channel selection tests
Add unit tests for group ratio, cross-group retry, and price calculation:
- Group ratio CRUD and special ratio override (12 tests)
- HandleGroupRatio with auto-group and special ratios (5 tests)
- ModelPriceHelper with group ratio in price/ratio modes (3 tests)
- Channel selection priority, groups, weighted LB (6 tests)
- RetryParam and AutoGroup service logic (7 tests)
Also restore the group pricing card in model detail SideSheet.
1 mese fa
fengsilin
7a2f584317
fix(claude): use gjson/sjson for reliable thinking.type replacement
Replace bytes.Replace with gjson.GetBytes+sjson.SetBytes in passthrough
mode to correctly handle JSON whitespace variations and avoid silently
sending empty body on read errors. Also add log search count limit to
prevent slow COUNT queries on large log tables.
1 mese fa
fengsilin
481b43cfc5
fix(claude): send adaptive thinking type
Use adaptive thinking for Claude requests and rewrite passthrough bodies that still contain the legacy enabled type.
Co-Authored-By: Codex <noreply@anthropic.com>
1 mese fa
fengsilin
2af3a9301d
fix(pricing): remove stale channel pricing backend
Delete leftover channel pricing controllers and routes after removing channel pricing, and align relay price helpers with global pricing plus user channel ratio only.
Co-Authored-By: Codex <noreply@anthropic.com>
1 mese fa
fengsilin
6479883ddc
fix: handle object-type arguments in Responses API stream
gpt-5.4 returns `arguments` as a JSON object for some tools (e.g.
apply_patch, tool_search), but ResponsesOutput.Arguments was typed as
string, causing json.Unmarshal to fail on every such SSE event.
The failure silently dropped all output_item events and the
response.completed event from the forwarded stream, so:
- the client never received tool call content
- usage/token counts could not be extracted (billed as 0)
- client reported "stream closed before response.completed"
Fix: change Arguments to json.RawMessage and add GetArguments() which
normalises both forms to a plain string (unescapes JSON strings,
returns raw bytes for objects).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 mese fa
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.
1 mese fa
fengsilin
6434a523a1
feat: passthrough model mapping
1 mese fa
fengsilin
e51a66c5f9
feat(metrics): postConsumeQuota 中采集 token/配额/延迟指标
1 mese fa
fengsilin
f1a68027f1
Revert "feat(cache): OpenAI→Claude 转换自动注入 prompt caching"
This reverts commit ff14caed7c .
1 mese fa
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>
1 mese fa
fengsilin
e6b4a06557
feat(logs): 隐藏使用日志中的分组信息展示
使用注释方式隐藏分组列和分组倍率标签,便于后续恢复:
1. 注释 UsageLogsColumnDefs.jsx 中的分组列定义
2. 注释 useUsageLogsData.jsx 中的 COLUMN_KEYS.GROUP 和默认可见性配置
3. 将计费详情中的"分组倍率"改为"倍率"
后端计费逻辑不变,仍正常应用分组倍率。
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
2 mesi fa
fengsilin
2d1a8d2f28
fix: 设置 chat_id + 优化日志查询参数构建
- Claude 和 OpenAI Responses 转发中设置 RelayChatID
- 日志查询使用 URLSearchParams 替代手动字符串拼接
- 日志查询日期范围改为可选,不再强制默认今天
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 mesi fa
fengsilin
b026f6bc04
feat: 用户倍率前端展示 + 渠道下拉选择 + 上游调试日志
- UserRatioSection 渠道 ID 输入改为带搜索的下拉选择器
- 使用日志详情、计费过程、展开行均显示用户倍率
- renderLogContent suffix 统一追加,消除 4 处重复
- 提取 dumpUpstreamRequest 辅助函数,debug 日志走 SysLog
Co-Authored-By: Claude <noreply@anthropic.com>
2 mesi fa
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>
2 mesi fa
fengsilin
8945f8c39e
fix: synced 用户剩余额度取 synced_quota + 记录 chat ID
- 前端用户列表:synced 用户显式取 synced_quota 字段作为剩余额度
- 各 OpenAI handler 中记录 relayChatID 用于日志追踪
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 mesi fa
fengsilin
e41f2951f7
fix: preserve relay body and capture invalid responses body
2 mesi fa
fengsilin
b2cb7bcf60
feat: record chat and upstream ids in usage logs
2 mesi fa
fengsilin
caf457ce9e
feat: 错误时记录上游响应体,支持流式
- 提取 TruncateBody 公共函数,截断到 2KB 避免日志过大
- 新增 handleResponsesStreamError 统一 SSE 错误提取逻辑
- 流式/非流式 Responses API 错误路径均捕获 UpstreamBody
- 添加 upstream_body 和 truncate_body 单元测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 mesi fa
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>
2 mesi fa
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>
2 mesi fa
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>
2 mesi fa
fengsilin
387f6c1ae0
feat(pricing): 定价数据源切换到渠道表,新增缓存价格展示
- 后端 pricing API 从 channel_pricings 表获取实际定价,选取最便宜渠道
- 提取 applyGlobalDefault 辅助函数消除全局回退逻辑重复
- price.go 重构扩展比率为局部变量,简化回退逻辑
- 定价卡片新增缓存读取/创建价格,改为两行布局防止溢出
- ChannelPricingCard 缓存列显示实际价格而非倍率
- 修复移动端 hero 区域 padding 过大
- 默认标签页标题改为 Loading...
- 新增缓存读取/创建 i18n 翻译(7 语言)
Co-Authored-By: Claude <noreply@anthropic.com>
2 mesi fa
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>
2 mesi fa
fengsilin
3a24fd598f
feat(channel-pricing): ModelPriceHelper + UpdatePriceDataForChannelPricing 适配新签名,支持扩展比率覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 mesi fa
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>
3 mesi fa
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>
3 mesi fa
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>
3 mesi fa
fengsilin
b99337dab7
fix(pricing): 修复渠道定价优先级问题
当模型配置了渠道定价但全局定价未设置时,不再提前报错。
将全局定价检查延迟到渠道选择后执行。
Co-Authored-By: Claude <noreply@anthropic.com>
3 mesi fa
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>
3 mesi fa
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>
3 mesi fa
winter
08164cd0ae
fix
4 mesi fa