fengsilin
3fbf48313a
feat(pricing): support usage billing and endpoint fixes
Add KlingAiping usage-token settlement from upstream final_unit_deduction and duration fallback handling.
Normalize model endpoint config persistence and convert model pricing values between stored USD and display currency in the editor.
Co-Authored-By: Codex <noreply@anthropic.com>
1 day ago
fengsilin
678add297f
feat(channel): add tianyiyun seedance channel
Co-Authored-By: Codex <noreply@anthropic.com>
1 day ago
fengsilin
49ca8a6ae7
fix(kling): 修复原生路由和展示价格保存
- 避免仅编辑展示价格时写入默认真实计费规则
- 将 video-extend 纳入 KlingAiping 原生渠道约束
- 补充相关保存决策、渠道约束和计费展示测试
Co-Authored-By: Codex <noreply@anthropic.com>
4 days ago
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 week ago
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 week ago
fengsilin
ced4d7f323
feat: expose model display pricing
1 week ago
fengsilin
de117ac932
feat: add model display pricing admin api
1 week ago
fengsilin
c9988af52b
feat: 用户创建同步到从节点及 i18n 翻译
新建用户时异步同步到海外 slave 节点,确保跨区域用户数据一致。
补充前两个 commit 全部新功能的中英文翻译字符串。
Co-Authored-By: Claude <noreply@anthropic.com>
2 weeks ago
fengsilin
84d364d76a
feat: 使用日志计费详情展开与 completion_tokens 修复
前端新增 UsageLogExpandedDetail 点击展开面板和 BillingDetailSummary
hover 计费详情,后端修复 per_1m_tokens 任务结算日志的 completion_tokens
从零值改为写入 total_tokens 实际值。新增 taskBillingLogMerge 合并
任务预扣/结算日志。
Co-Authored-By: Claude <noreply@anthropic.com>
2 weeks ago
fengsilin
2e40bab478
feat: 模型定价矩阵价格取中位数展示
前端模型定价配置 UI 增强(Editor/GeneratorModal/PreviewPanel/PricingGrid),
后端新增 representativeMatrixPrice 取矩阵定价表中位数作为展示价格,
替代原来的 model_price=0 导致的价格展示为空问题。
Co-Authored-By: Claude <noreply@anthropic.com>
2 weeks ago
fengsilin
696c549a66
feat(video): add doubao aiping video pricing support
Co-Authored-By: Codex <noreply@anthropic.com>
2 weeks ago
fengsilin
3ac94e2e6f
test(task-pricing): cover model pricing api and remix snapshots
3 weeks ago
fengsilin
285323d765
feat(task-pricing): expose model pricing rules api
3 weeks ago
fengsilin
3a52f31608
feat(task-pricing): gate channels for matrix usage billing
3 weeks ago
fengsilin
db8eacd558
feat(task-pricing): persist matrix billing snapshots
3 weeks ago
fengsilin
8f89828ca3
fix(user-migration): 禁止冲突用户非法合并
- 前端冲突处理页面禁用 cn_already_synced_to_ov 场景的 merge 操作
- 后端 resolve 接口拒绝将已存在 synced copy 的 CN 用户作为 merge 目标
- 补充对应控制器测试
Co-Authored-By: Codex <noreply@anthropic.com>
4 weeks ago
fengsilin
65e6a82d34
feat(user-migration): support selective batches and cancellation
Add candidate user selection and explicit_ids batch creation flow for overseas migration. Also add cancellable batches to release selected-user locks and extend backend, frontend, and e2e coverage for the new flow.
Co-Authored-By: Codex <noreply@anthropic.com>
1 month ago
fengsilin
ca3f8765bb
test(user-migration): complete migration coverage and e2e flow
Co-Authored-By: Codex <noreply@anthropic.com>
1 month ago
fengsilin
e9d5d51b37
fix(sync): 修复 Slave 端编辑同步用户时误报余额不可修改的问题
前端对同步用户用 SyncedQuota 替代 Quota 展示,但后端比较时
用的是数据库真实 Quota 字段,导致两者不同而触发拦截。
改为比较 SyncedQuota,只有真正修改额度时才拦截。
1 month ago
fengsilin
3a78e9c93a
fix(user-migration): revalidate drift and verify synced quota
1 month ago
fengsilin
36b47379f7
test(user-migration): cover rescan and batch status regressions
1 month ago
fengsilin
7282142316
feat(user-migration): add root admin migration API
1 month ago
fengsilin
102b15ad41
feat(user-migration): add internal migration endpoints and client
1 month ago
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 month ago
fengsilin
23f9ed4ccd
fix(redemption): block synced users from redeeming
Reject redemption requests from synced users, surface a localized API message, and cover both model- and controller-level paths with tests.
Co-Authored-By: Codex <noreply@anthropic.com>
1 month ago
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 month ago
fengsilin
7ecedd8e57
fix: restore clean go test baseline
1 month ago
fengsilin
1c5e6d03d9
fix: 禁止修改同步用户余额
同步用户余额由主节点管理,从节点不应允许管理员修改其余额。
前端禁用额度输入和添加额度按钮,后端增加校验拦截。
1 month ago
fengsilin
fe62509b03
feat(metrics): 重试循环和错误处理中采集指标
1 month ago
fengsilin
c64afdc6c2
fix: 清理渠道选择删除后的代码质量问题
- router/api-router.go: 修复删除路由后的缩进异常
- model/channel_pricing.go: 清理 Insert/Update/Delete 中遗留空行
- controller/relay_test.go: newTestContext 接收 *testing.T 参数并调用 t.Helper()
1 month ago
fengsilin
631e030411
test: 添加渠道选择功能删除后的验证测试
验证 parseTokenKey 不再解析 channelId(sk-abc123:42 中的 :42
保留为 key 一部分),shouldRetry/shouldRetryTaskRelay 不再检查
specific_channel_id,所有请求都能正常重试。
1 month ago
fengsilin
baed9754d0
refactor: 完整删除渠道选择功能后端代码
删除了用户通过 sk-{key}:{channelId} 指定渠道、Playground 下拉框选择渠道、
以及管理员设置默认渠道 (is_default) 的所有后端代码。
涉及修改:
- middleware/auth.go: 简化 parseTokenKey,移除 specific_channel_id 设置
- middleware/distributor.go: 移除指定渠道分发逻辑、默认通道检查、ModelRequest.ChannelId
- constant/context_key.go: 移除 ContextKeyTokenSpecificChannelId
- controller/playground_channels.go: 整个文件删除
- controller/relay.go: 移除 shouldRetry/shouldRetryTaskRelay 中的指定渠道跳过
- controller/channel.go: 移除 GetUserChannelsForBinding
- controller/channel_pricing.go: 移除 SetDefaultChannel/ClearDefaultChannel
- model/ability.go: 移除 GetModelChannelsForGroup
- model/channel.go: 移除 GetAllChannelsForBinding
- model/channel_pricing.go: 移除默认通道缓存及所有相关函数
- model/pricing.go: 移除 DefaultChannelName 字段
- router/api-router.go: 移除 4 条路由
- i18n: 移除 channel.id_format_error 和 distributor.invalid_channel_id
1 month ago
fengsilin
714d8239d1
feat: Relay 请求抓包日志 + 用户模型 RPM 限流
两个独立功能:
1. Relay Capture:对开启 capture_relay 的用户记录完整请求/响应到本地文件
- 单 writer goroutine + 128 槽 channel 架构,无 OOM 风险
- 支持流式 SSE 和非流式请求
- 30s 超时保护
2. User-Model RPM Rate Limiting:按 用户+模型 维度的 RPM 限流
- Redis 令牌桶 + 内存滑动窗口双路径,Redis 故障自动降级
- 请求失败时退还令牌/配额(Redis Refund Lua 脚本 + 内存 Refund)
- Redis pipeline 错误处理:失败时清理缓存 key
- 前端用户编辑弹窗新增模型限流配置面板
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 month ago
fengsilin
e6b4a06557
feat(logs): 隐藏使用日志中的分组信息展示
使用注释方式隐藏分组列和分组倍率标签,便于后续恢复:
1. 注释 UsageLogsColumnDefs.jsx 中的分组列定义
2. 注释 useUsageLogsData.jsx 中的 COLUMN_KEYS.GROUP 和默认可见性配置
3. 将计费详情中的"分组倍率"改为"倍率"
后端计费逻辑不变,仍正常应用分组倍率。
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
2 months ago
fengsilin
f7ff684d0d
feat(pricing): 渠道定价展示用户折扣价格
登录用户查看渠道定价时,按用户分组倍率和渠道个人倍率计算实际折扣价
并在价格列展示划线原价与折扣价,新增 /pricing/user/*model 接口。
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
2 months ago
fengsilin
e1b6aff7e1
fix(log): 对普通用户隐藏 Chat ID 和 Upstream ID
后端 GetUserLogs 返回前清空 chat_id/upstream_id(omitempty 不输出),
前端搜索框和展开行详情加 isAdminUser 守卫。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
fengsilin
3e86f523db
feat(playground): temperature/top_p 参数互斥设置
部分上游模型不允许同时设置 temperature 和 top_p,新增管理员可配置的
模型前缀列表,匹配的模型在 Playground 中自动互斥切换两个参数。
- 后端新增 PlaygroundSetting 配置 + GET /api/playground/config 公开端点
- 运营设置页面新增 Playground 互斥模型前缀编辑 textarea
- Playground 自动检测模型名匹配,启用一个参数自动禁用另一个
- 默认包含 deepseek-v4-flash/pro、deepseek-reasoner、o1-/o3-/o4-、gpt-5
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
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 months ago
fengsilin
b2cb7bcf60
feat: record chat and upstream ids in usage logs
2 months ago
fengsilin
332d5a62f2
feat: support codex api key credentials
2 months ago
fengsilin
1c0898257c
feat: add redemption remarks
2 months ago
fengsilin
d8272e7707
feat(channel): 添加渠道"对外名称"(public_name)字段
为 Channel 模型新增 public_name 字段,让管理员可以为每个渠道
设置用户可见的友好名称(如"标准通道"、"高速通道"),替代前端
硬编码的"通道一/二/三"。Playground 通道选择器展示对外名称,
"渠道"统一改为"通道"。新建渠道时对外名称必填,编辑时可选。
Co-Authored-By: Claude <noreply@anthropic.com>
2 months ago
fengsilin
73d10b5799
feat: 错误日志记录上游 request-id 和响应体,Playground 渠道路由改为 header 传递
- 错误日志新增 upstream_request_id(从 Anthropic/OpenAI 响应 header 提取)和 upstream_body(截断 2KB)
- 修复 RelayErrorHandler 内部 WithOpenAIError/NewOpenAIError 分支丢失上游字段的 bug
- Playground 渠道和分组改为通过 X-Channel-Id/X-Group header 传递,而非 body 字段
- Distributor 中间件支持从 header 回退读取 channel_id 和 group
Co-Authored-By: Claude <noreply@anthropic.com>
2 months ago
fengsilin
74cc8c0d56
feat(playground): 添加渠道选择功能,支持指定渠道体验模型
- 新增 /api/user/model_channels 接口,返回模型可用渠道及默认渠道
- Playground 设置面板添加渠道选择下拉框
- Distribute 中间件支持从请求体读取 channel_id 指定渠道
- 支持 URL 参数 ?model=xxx 直接选择模型
Co-Authored-By: Claude <noreply@anthropic.com>
2 months ago
fengsilin
a34d44a824
fix(user): 修复从节点同步用户余额显示为 0 的问题
同步用户(synced)的实际余额存储在 synced_quota 字段,
但用户列表/详情接口返回的是 quota 字段(值为 0)。
新增 ApplySyncedQuota 方法,在 API 返回前将 synced_quota
赋值给 quota,使前端能正确显示余额。
同时优化 GetUserModels:map 去重替代 O(n) 线性扫描,
禁用模型查询移至 model 层,新增 StringsSubtract 工具函数。
Co-Authored-By: Claude <noreply@anthropic.com>
2 months ago
fengsilin
967309fb56
feat: 添加邮箱后缀注册额度规则功能
管理员可在用户管理页面配置「邮箱后缀→初始额度」映射规则,
用户注册时根据邮箱后缀自动匹配并发放对应额度(替代默认额度)。
- 新增 email_quota_rule 数据表 + CRUD API(管理员权限)
- 内存缓存匹配,启动时加载,增删改时刷新
- 注册流程 Insert/InsertWithTx/FinalizeOAuthUserCreation 同步支持
- 前端用户管理页新增 Tab 展示规则管理卡片
- 含 24 个测试(model 16 + controller 8)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
fengsilin
1912dd3b72
feat: 添加图片验证码功能,防止脚本批量注册
- 后端:新增 GET /api/captcha 接口,使用 base64Captcha 生成图片验证码
- 后端:发送邮箱验证码时校验图片验证码(CaptchaEnabled 开关控制)
- 前端:注册表单邮箱验证码前增加图片验证码输入,支持点击刷新
- 管理后台:系统设置新增「图片验证码」开关
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
fengsilin
934b4b10a7
feat: 法律文档双语配置(中/英)+ 精简语言支持至中英双语
- LegalSettings 字段拆分为 _zh/_en 双语对
- API 支持 ?lang= 参数返回对应语言内容
- 后台设置页每个文档配语言切换按钮(中文/English)
- 前端页面根据 UI 语言自动请求对应内容
- 移除 fr/ru/ja/vi/zh-TW 语言支持
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
fengsilin
1cc75aa9a2
feat: 服务条款和使用政策页面,支持后台 Markdown 配置
复用现有 LegalSettings 模式,新增 TermsOfService 和 UsagePolicy 字段,
添加 /terms 和 /usage-policy 前端页面及 API 端点。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago
fengsilin
749064932c
feat: 新增 PUT /api/vendors/reorder 和 /api/models/reorder 批量排序接口
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 months ago