Skip to content

Feature/20260529 opus 4.8 - #5188

Closed
gladhu wants to merge 25 commits into
QuantumNous:mainfrom
gladhu:feature/20260529_opus_4.8
Closed

Feature/20260529 opus 4.8#5188
gladhu wants to merge 25 commits into
QuantumNous:mainfrom
gladhu:feature/20260529_opus_4.8

Conversation

@gladhu

@gladhu gladhu commented May 30, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added channel consumption statistics viewer with optional user filtering
    • Added CSV export functionality for usage logs and user billing
    • Expanded integration documentation guides for multiple AI development tools
    • Enhanced dashboard time-range handling with calendar-day alignment
  • Enhancements

    • Changed default data export granularity from hourly to daily
    • Updated playground default settings (temperature and top_p now disabled)
    • Improved documentation navigation with smart internal/external link resolution
  • Model Support

    • Added Claude Opus 4.8 model variants with caching and ratio configurations
  • Localization

    • Updated translations across all supported languages for new features and UI elements

gladhu added 25 commits April 12, 2026 17:26
…ge 并强化 VChart key。

- 经典主题:generateChartTimePoints 按筛选区间生成刻度并与聚合 showYear 对齐;刷新/搜索传入区间;请求前将起止时间归一到当日 00:00 与 23:59:59。
- 筛选默认值:快捷范围改为自然日(首尾整日);应用筛选时将起止对齐到整天。
- 全局默认时间粒度改为 day(common.DataExportDefaultTime、默认主题常量与经典本地兜底/后台表单初始值)。
Dockerfile
增加构建参数 RESERVE_CPU_CORES(默认 1),表示给宿主机预留的 CPU 个数。
builder / builder-classic(两次 bun run build):BuildKit 常会并行跑这两个 stage,因此每个 stage 里设
GOMAXPROCS = max(1, ⌊(nproc − RESERVE) / 2⌋),
两个一起跑时大致不会超过「全部核心 − 预留」。
builder2(go build):单独跑,使用
GOMAXPROCS = max(1, nproc − RESERVE)。
Dockerfile.dev
同样支持 RESERVE_CPU_CORES,仅在 go build 前设置 GOMAXPROCS(没有两个前端并行的问题)。
用法示例
docker build -t "new-api:$(cat VERSION)" .
# 预留 2 个核给宿主机:
docker build --build-arg RESERVE_CPU_CORES=2 -t "new-api:$(cat VERSION)" .
你需要知道的限制
GOMAXPROCS 主要约束 Go 编译器和会读它的工具(例如 esbuild);Rspack/Bun 其它线程不保证完全被压住。
若机器核心很少(例如 2 核还要预留 1 核),并行前端仍可能偏紧;这时可加大 RESERVE_CPU_CORES,或给 BuildKit 配 max-parallelism = 1 让 stage 串行。
对 未成功解析为已登录用户 的请求(匿名访客):

不再按可用分组过滤定价列表,返回完整目录(仅浏览,不调 API)。
usable_group 用 ratio_setting 里所有分组倍率键 构造(便于侧边栏筛选);若没有配置倍率分组,则从定价条目里的 enable_groups 推导。
已登录用户逻辑保持不变,仍按其实际可用分组过滤。
后端 API
接口:GET /api/channel/:id/consumption(需管理员权限)

查询参数:

参数	说明
start_timestamp
开始时间(Unix 秒)
end_timestamp
结束时间(Unix 秒)
user_id
可选,筛选某用户在该渠道的消费
username
可选,与 user_id 二选一
未传时间时,默认统计本月 1 日 00:00 至当前。

示例:

# 渠道 5 在 2026 年 3 月的总消费
GET /api/channel/5/consumption?start_timestamp=1740787200&end_timestamp=1743465599
# 用户 alice 在渠道 5 上某段时间的消费
GET /api/channel/5/consumption?start_timestamp=...&end_timestamp=...&username=alice
响应字段:quota(区间内消耗额度,按站点配置展示为金额)、request_count、prompt_tokens、completion_tokens、lifetime_used_quota(渠道历史总消耗,仅在不按用户筛选时参考)。

数据来源为 logs 表中 type=消费 的记录聚合;需开启消费日志(LogConsumeEnabled)。

管理后台 UI
在 渠道管理 页面,渠道行操作菜单中新增 「渠道消费统计」:

时间范围:支持今天、近 7 天、本周、近 30 天、本月及自定义起止时间
渠道总消费:不填用户即为该渠道在选定时间段内的总消耗
用户 + 渠道:填写用户 ID 或用户名后点「应用用户筛选」,查看该用户在该渠道上的消耗
定义在 relay/common/override.go:delete_header 会从参数覆盖上下文里的 header_override 映射中 删除 对应键,并通过 syncRuntimeHeaderOverrideFromContext 同步到 RelayInfo.RuntimeHeadersOverride。
在 claude_handler.go 等路径中,请求体 JSON 会先经过 ApplyParamOverrideWithRelayInfo,再交给各渠道 adaptor。
AWS Claude 的特殊处理
AWS Bedrock(AK/SK 模式)不走普通 HTTP 转发,而在 relay/channel/aws/relay-aws.go 的 doAwsClientRequest 中:

SetupRequestHeader → CommonClaudeHeadersOperation 会把客户端的 anthropic-beta 复制 到内部 requestHeader
ResolveHeaderOverride 根据运行时 override 设置 头
formatRequest 读取 requestHeader.Get("anthropic-beta"),写入 Bedrock JSON 的 anthropic_beta 字段
原先第 2 步只会 Set override 里存在的头,不会删除 第 1 步已写入的头。因此即使用 delete_header 从 RuntimeHeadersOverride 里移除了 anthropic-beta,formatRequest 仍能从 requestHeader 读到客户端传来的值。

根因
delete_header 只更新了“应发送的头”映射,没有在最终 http.Header 上执行删除。AWS Claude 在 SetupRequestHeader 之后合并 override,导致被删的 anthropic-beta 仍留在 header 中并进入 Bedrock payload。

修复方案
RelayInfo.RuntimeHeadersDeleted:记录 delete_header(及 move_header 删除源头等)显式删除的头名。
deleteHeaderOverrideInContext:删除时写入 header_deleted 上下文。
ApplyResolvedHeaderOverrides(relay/channel/api_request.go):在应用 override 后,对 RuntimeHeadersDeleted 调用 Header.Del。
AWS 路径:doAwsClientRequest 改用 ApplyResolvedHeaderOverrides,不再只做 Set 循环。
变更文件
文件	变更
relay/common/relay_info.go
新增 RuntimeHeadersDeleted
relay/common/override.go
跟踪/同步已删除头
relay/channel/api_request.go
ApplyResolvedHeaderOverrides + 删除逻辑
relay/channel/aws/relay-aws.go
使用新合并函数
relay/common/override_test.go
断言删除跟踪
relay/channel/api_request_test.go
删除头行为测试
relay/channel/aws/relay_aws_test.go
AWS + 完整 param override 集成测试
相关测试已通过。

修复后行为
配置:

{
  "operations": [
    { "mode": "delete_header", "path": "anthropic-beta" }
  ]
}
流程变为:

ApplyParamOverrideWithRelayInfo 记录 anthropic-beta 在 RuntimeHeadersDeleted
doAwsClientRequest 先 SetupRequestHeader(可能暂时带上客户端 beta)
ApplyResolvedHeaderOverrides 应用 override 并 Del anthropic-beta
formatRequest 读不到该头 → Bedrock 请求体 不含 anthropic_beta
限制与说明
仅作用于 HTTP 头链路:delete_header 删除的是请求头;若请求 JSON 体里直接带有 anthropic_beta(少见),不会被此操作移除。
透传 body 模式:开启 PassThroughRequestEnabled 或渠道 PassThroughBodyEnabled 时,可能绕过 formatRequest,行为取决于原始 body。
不仅 AWS:所有经 DoApiRequest / DoFormRequest / WebSocket 的路径都会受益;AWS Claude AK/SK 是本次报告的场景。
AWS API Key 模式(ClientModeApiKey):走 DoApiRequest,同样会应用删除逻辑。
全局 Claude 设置:WriteHeaders 若在 SetupRequestHeader 里添加了 beta,删除发生在其后,仍会生效。
若你需要,我可以再补一条:在透传 body 模式下也从 JSON 中剥离 anthropic_beta 的增强逻辑。
…tle-sub),并微调字号、字间距与行高。整体更克制统一,更符合科技感,且仅改动 home-custom.html 内相关 CSS 与 class 名。
@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 20e651a6-9d56-4fcf-a8ad-f0fc1d4d6914

📥 Commits

Reviewing files that changed from the base of the PR and between 1588027 and 1e62338.

⛔ Files ignored due to path filters (3)
  • web/classic/bun.lock is excluded by !**/*.lock
  • web/classic/public/logo.png is excluded by !**/*.png
  • web/default/public/logo.png is excluded by !**/*.png
📒 Files selected for processing (144)
  • Dockerfile
  • Dockerfile.dev
  • VERSION
  • common/constants.go
  • controller/channel_consumption.go
  • controller/log.go
  • controller/log_export.go
  • controller/log_export_test.go
  • controller/pricing.go
  • docker-compose.local-build.yml
  • model/log.go
  • model/log_consumption_test.go
  • model/log_export_test.go
  • model/user.go
  • relay/channel/api_request.go
  • relay/channel/api_request_test.go
  • relay/channel/aws/constants.go
  • relay/channel/aws/relay-aws.go
  • relay/channel/aws/relay_aws_test.go
  • relay/channel/claude/constants.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/vertex/adaptor.go
  • relay/claude_handler.go
  • relay/common/override.go
  • relay/common/override_test.go
  • relay/common/relay_info.go
  • router/api-router.go
  • setting/ratio_setting/cache_ratio.go
  • setting/ratio_setting/model_ratio.go
  • web/classic/public/home-custom.html
  • web/classic/src/App.jsx
  • web/classic/src/components/dashboard/index.jsx
  • web/classic/src/components/docs/integration/DocCallout.jsx
  • web/classic/src/components/docs/integration/DocCodeBlock.jsx
  • web/classic/src/components/docs/integration/DocSection.jsx
  • web/classic/src/components/docs/integration/IntegrationHome.jsx
  • web/classic/src/components/docs/integration/IntegrationLayout.jsx
  • web/classic/src/components/docs/integration/constants.js
  • web/classic/src/components/docs/integration/pages/ClaudeCodePage.jsx
  • web/classic/src/components/docs/integration/pages/CodeBuddyPage.jsx
  • web/classic/src/components/docs/integration/pages/CodexPage.jsx
  • web/classic/src/components/docs/integration/pages/GeminiCliPage.jsx
  • web/classic/src/components/docs/integration/pages/OpenCodePage.jsx
  • web/classic/src/components/docs/integration/pages/TracePage.jsx
  • web/classic/src/components/layout/headerbar/index.jsx
  • web/classic/src/components/playground/configStorage.js
  • web/classic/src/components/settings/DashboardSetting.jsx
  • web/classic/src/components/table/channels/ChannelsColumnDefs.jsx
  • web/classic/src/components/table/channels/modals/ChannelConsumptionModal.jsx
  • web/classic/src/components/table/usage-logs/UsageLogsFilters.jsx
  • web/classic/src/components/table/users/UsersColumnDefs.jsx
  • web/classic/src/components/table/users/UsersTable.jsx
  • web/classic/src/components/table/users/modals/UserBillExportModal.jsx
  • web/classic/src/constants/playground.constants.js
  • web/classic/src/helpers/dashboard.jsx
  • web/classic/src/helpers/docsNavLink.js
  • web/classic/src/helpers/index.js
  • web/classic/src/helpers/playgroundParameter.js
  • web/classic/src/helpers/usageLogsExport.js
  • web/classic/src/helpers/userBillExport.js
  • web/classic/src/hooks/common/useNavigation.js
  • web/classic/src/hooks/dashboard/useDashboardCharts.jsx
  • web/classic/src/hooks/dashboard/useDashboardData.js
  • web/classic/src/hooks/playground/usePlaygroundState.js
  • web/classic/src/hooks/usage-logs/useUsageLogsData.jsx
  • web/classic/src/i18n/locales/en.json
  • web/classic/src/i18n/locales/fr.json
  • web/classic/src/i18n/locales/ja.json
  • web/classic/src/i18n/locales/ru.json
  • web/classic/src/i18n/locales/vi.json
  • web/classic/src/i18n/locales/zh-CN.json
  • web/classic/src/i18n/locales/zh-TW.json
  • web/classic/src/i18n/locales/zh.json
  • web/classic/src/pages/Docs/IntegrationClaudeCode.jsx
  • web/classic/src/pages/Docs/IntegrationCodeBuddy.jsx
  • web/classic/src/pages/Docs/IntegrationCodex.jsx
  • web/classic/src/pages/Docs/IntegrationGeminiCli.jsx
  • web/classic/src/pages/Docs/IntegrationHome.jsx
  • web/classic/src/pages/Docs/IntegrationOpenCode.jsx
  • web/classic/src/pages/Docs/IntegrationTrace.jsx
  • web/classic/src/pages/Docs/Redirect.jsx
  • web/classic/src/pages/Docs/withIntegrationLayout.jsx
  • web/classic/src/pages/Home/index.jsx
  • web/default/public/home-custom.html
  • web/default/src/features/channels/api.ts
  • web/default/src/features/channels/components/channels-dialogs.tsx
  • web/default/src/features/channels/components/channels-provider.tsx
  • web/default/src/features/channels/components/data-table-row-actions.tsx
  • web/default/src/features/channels/components/dialogs/channel-consumption-dialog.tsx
  • web/default/src/features/dashboard/components/models/consumption-distribution-chart.tsx
  • web/default/src/features/dashboard/components/models/model-charts.tsx
  • web/default/src/features/dashboard/components/models/models-filter-dialog.tsx
  • web/default/src/features/dashboard/constants.ts
  • web/default/src/features/dashboard/index.tsx
  • web/default/src/features/dashboard/lib/charts.ts
  • web/default/src/features/dashboard/lib/filters.ts
  • web/default/src/features/dashboard/lib/index.ts
  • web/default/src/features/docs/integration/components/doc-callout.tsx
  • web/default/src/features/docs/integration/components/doc-code-block.tsx
  • web/default/src/features/docs/integration/components/doc-section.tsx
  • web/default/src/features/docs/integration/constants.ts
  • web/default/src/features/docs/integration/index.tsx
  • web/default/src/features/docs/integration/integration-layout.tsx
  • web/default/src/features/docs/integration/pages/claude-code.tsx
  • web/default/src/features/docs/integration/pages/code-buddy.tsx
  • web/default/src/features/docs/integration/pages/codex.tsx
  • web/default/src/features/docs/integration/pages/gemini-cli.tsx
  • web/default/src/features/docs/integration/pages/open-code.tsx
  • web/default/src/features/docs/integration/pages/trace.tsx
  • web/default/src/features/playground/constants.ts
  • web/default/src/features/playground/hooks/use-playground-state.ts
  • web/default/src/features/playground/lib/index.ts
  • web/default/src/features/playground/lib/parameter-enabled.ts
  • web/default/src/features/usage-logs/api.ts
  • web/default/src/features/usage-logs/components/common-logs-filter-bar.tsx
  • web/default/src/features/usage-logs/lib/export.ts
  • web/default/src/features/users/api.ts
  • web/default/src/features/users/components/data-table-row-actions.tsx
  • web/default/src/features/users/components/dialogs/user-bill-export-dialog.tsx
  • web/default/src/hooks/use-top-nav-links.ts
  • web/default/src/i18n/locales/_reports/_sync-report.json
  • web/default/src/i18n/locales/_reports/fr.untranslated.json
  • web/default/src/i18n/locales/_reports/ja.untranslated.json
  • web/default/src/i18n/locales/_reports/ru.untranslated.json
  • web/default/src/i18n/locales/_reports/vi.untranslated.json
  • web/default/src/i18n/locales/_reports/zh.untranslated.json
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
  • web/default/src/lib/docs-nav-link.ts
  • web/default/src/lib/time.ts
  • web/default/src/routeTree.gen.ts
  • web/default/src/routes/docs/index.tsx
  • web/default/src/routes/docs/integration/claude-code.tsx
  • web/default/src/routes/docs/integration/code-buddy.tsx
  • web/default/src/routes/docs/integration/codex.tsx
  • web/default/src/routes/docs/integration/gemini-cli.tsx
  • web/default/src/routes/docs/integration/index.tsx
  • web/default/src/routes/docs/integration/open-code.tsx
  • web/default/src/routes/docs/integration/route.tsx
  • web/default/src/routes/docs/integration/trace.tsx

Walkthrough

Adds admin/user CSV/ZIP export endpoints, channel consumption aggregation and endpoint, extends Claude Opus 4.8 support, updates dashboards to day-based ranges, introduces docs/integration UI and consumption dialogs, centralizes relay header override deletions, and refines Docker build parallelism.

Changes

Core Feature Slice

Layer / File(s) Summary
Handlers and queries
controller/channel_consumption.go, controller/log_export.go, controller/log.go, model/log.go, model/*_test.go
Implements channel consumption handler with user/time filters, admin/user CSV exports and ZIP, month range helpers, export filters, aggregations, and tests.
Relay header and Claude 4.8
relay/channel/*, relay/common/*, relay/claude_handler.go, relay/channel/claude/*, setting/ratio_setting/*, tests
Centralizes runtime header overrides and deletions; adds Claude Opus 4.8 model support across mappings and logic with tests.
Router and settings
router/api-router.go, common/constants.go, web/*/dashboard/constants.ts, web/classic/*DashboardSetting.jsx
Wires new endpoints and switches default time granularity to day.
Build and versioning
Dockerfile*, docker-compose.local-build.yml, VERSION
Adds CPU reservation for builds, local compose, and sets version.
Web Classic UI
web/classic/**
Adds integration docs pages/layout, resolves docs links, dashboard time-range normalization, usage logs export, channel consumption modal, and users bill export modal.
Web Default UI
web/default/**
Adds channel consumption dialog/API, model charts time range, integration docs shell/pages/components, usage logs export, and user bill export dialog.
Model ratios and settings
setting/ratio_setting/*
Defines default ratios for claude-opus-4-8 variants.
Static landing pages
web/*/public/home-custom.html
Adds themed landing pages with server address auto-fill and copy helpers.
Pricing behavior
controller/pricing.go
Visitor requests see unfiltered pricing; usable groups built for visitors.

Sequence Diagram(s)

sequenceDiagram
  participant AdminUI
  participant API
  participant ExportCtrl
  participant Model

  AdminUI->>API: GET /api/log/admin/export/monthly_bill?user_id&year&month&timezone
  API->>ExportCtrl: Route to ExportAdminUserMonthlyBill
  ExportCtrl->>Model: AdminUserMonthRangeSeconds(year, month)
  ExportCtrl->>Model: GetUserLogTypeAggregatesForRange(user, start, end)
  ExportCtrl->>Model: GetUserConsumeSummaryByModelForRange(user, start, end)
  Model-->>ExportCtrl: aggregates, model summaries
  ExportCtrl->>AdminUI: CSV (UTF-8 BOM) download
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

A rabbit tallies tokens by the moon,
Zips up the logs—download soon!
Channels whisper quotas in a chart,
Headers vanish with a sleight-of-heart.
Opus learns a new 4.8 tune,
Dashboards march by day—not noon.
Hop—export done! 🐇📊✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feature/20260529_opus_4.8

@gladhu gladhu closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant