Commit Graph
4052 Commits
Author SHA1 Message Date
erio 2f0175dc9f feat(monitor): switch headers input to key-value rows
- AdvancedRequestConfig 把 headers textarea 换成行式:每行 name 输入 + value 输入
  + 删除按钮,底部「+ 添加 Header」。直观区分名/值,不用再一行 "Key: Value" 自己拆。
- 校验下放到行级:name 含空格或冒号才报错,未填仅占位不报错(避免输入时频繁红字)。
- 外部 props 同值不回写,避免 commit 后行被重排。
- chore: 移除 CLAUDE.md 里 silentflower remote 行(不再追踪)。
2026-04-21 15:37:57 +08:00
erio 709279bab7 feat(monitor): 30-day raw retention + timeline 4-tier style + CC template seed + JSON format button
- History retention 1d → 30d(60s × 30d ≈ 43200 行/model,PG 无压力);
  ComputeAvailability* 不再 UNION rollup 表,直接扫 histories 精度更高。
- Timeline bar 四级高度+颜色双重编码:operational 高+绿 / degraded 中+黄 /
  failed+error 短+红 / 未测试 很短+灰。
- migration 113 seed「Claude Code 伪装」模板(ON CONFLICT DO NOTHING)。
  user_id 用 legacy 格式(user_<64hex>_account_<uuid>_session_<uuid>),
  避免新版 JSON 字符串内嵌 JSON 在编辑器里一长串 \" 难读。
- MonitorAdvancedRequestConfig 加「格式化」按钮 + white-space:pre
  让 body textarea 对长字符串不压扁。
2026-04-21 15:24:48 +08:00
erio cb655ea41c docs: add business remote to CLAUDE.md/AGENTS.md and sync AGENTS.md
新增 git remote 列表表格,记录 origin/upstream/business/silentflower 四个
remote 的仓库、权限、用途;明确 business (Sub2API-Devs/sub2api-pro) 有直接
推送权限,与 upstream (Wei-Shaw/sub2api) 仅 PR 区分。同步 AGENTS.md 与
CLAUDE.md 内容完全一致。

DO-NOT-UPSTREAM: 此 commit 仅用于 fork 内部,禁止 PR 到 Wei-Shaw/sub2api 上游。
CLAUDE.md / AGENTS.md 是我们 fork 的定制化开发文档,不属于上游通用功能。
2026-04-21 15:11:56 +08:00
erio 78986b294d feat(channel-monitor): apply template via subset picker; CC 2.1.114 baseline doc
Apply flow:
- POST /admin/channel-monitor-templates/:id/apply now requires monitor_ids
  (non-empty array). Service applies the template only to the selected
  subset, gated by AND template_id = :id (so users can't sneak in
  unrelated monitor IDs).
- New GET /admin/channel-monitor-templates/:id/monitors returns the
  associated monitor briefs (id/name/provider/enabled) for the picker.
- ApplyToMonitors signature gains monitorIDs []int64; empty list returns
  ErrChannelMonitorTemplateApplyEmpty.

Frontend:
- New MonitorTemplateApplyPickerDialog.vue: list of associated monitors
  with checkboxes (default all checked), 全选 / 全不选 shortcuts, live
  selected/total count. Submit calls apply(id, ids).
- MonitorTemplateManagerDialog replaces the old ConfirmDialog flow with
  the picker; onApplied refetches the list to refresh associated counts.

i18n: applyPicker* + common.selectAll keys.

chore: bump version to 0.1.114.33

The CC 2.1.114 (sdk-cli) UA / APIKeyBetaHeader / JSON metadata.user_id
baseline (already verified working via the in-process apply on prod
template id=1) is documented in internal/pkg/claude/constants.go and
is what the seed template in the manager UI should follow.
2026-04-21 14:39:19 +08:00
erio 05b5096cdb feat(channel-monitor): request templates with snapshot apply + headers/body override
Problem:
Upstream channels can reject monitor probes based on client fingerprint
(e.g. "only Claude Code clients allowed"). The monitor had no way to
customize the outgoing request to bypass such restrictions.

Solution:
Introduce reusable request templates that carry extra_headers plus an
optional body override; monitors reference a template and receive a
snapshot copy on apply. Template edits do NOT auto-propagate — users
must click "apply to associated monitors" to refresh snapshots, so a
bad template edit cannot instantly break all production monitors.

Data model (migration 112):
- channel_monitor_request_templates: id, name, provider, description,
  extra_headers jsonb, body_override_mode ('off'|'merge'|'replace'),
  body_override jsonb. Unique (provider, name).
- channel_monitors: +template_id (FK, ON DELETE SET NULL), +extra_headers,
  +body_override_mode, +body_override (the three runtime snapshot fields).

Checker (channel_monitor_checker.go):
- callProvider + runCheckForModel accept a CheckOptions carrying the
  snapshot fields. mergeHeaders applies user headers on top of adapter
  defaults (forbidden list: Host / Content-Length / Transfer-Encoding /
  Connection / Content-Encoding).
- buildRequestBody:
    off     -> adapter default body
    merge   -> shallow-merge over default; per-provider deny list
               (model/messages/contents) protects the challenge contract
    replace -> user body verbatim
- Replace mode skips challenge validation; instead HTTP 2xx + non-empty
  extracted response text = operational, empty = failed.
- 4 new unit tests cover all three modes + replace/empty-response case.

Admin API:
- /admin/channel-monitor-templates CRUD + /:id/apply (overwrite snapshot
  on all template_id=id monitors, returns affected count).
- channel_monitor request/response DTOs gain the 4 new fields.

Frontend:
- channelMonitorTemplate.ts API client.
- MonitorAdvancedRequestConfig.vue shared component for headers textarea
  + body mode radio + body JSON editor; used by both template and monitor
  forms.
- MonitorTemplateManagerDialog.vue: provider tabs, list/create/edit/
  delete/apply, live "associated monitors" count per row.
- MonitorFiltersBar: new 模板管理 button next to 新增监控.
- MonitorFormDialog: collapsible 高级 section with template dropdown
  (filtered by form.provider, clears on provider change) + embedded
  AdvancedRequestConfig. Picking a template copies its fields into the
  form (snapshot semantics mirrored on the client).
- i18n zh/en entries for all new copy.

chore: bump version to 0.1.114.32
2026-04-21 14:14:49 +08:00
erio 58c695d84f refactor(channel-status): drop breadcrumb + subtitle from MonitorHero
The "CHANNEL · STATUS" breadcrumb and the zh/en subtitles above the
window-picker were redundant with the existing "渠道状态" page title
shown in the layout header. Remove the left column and right-align the
7d/15d/30d tabs + overall chip.

Also drop the now-unreferenced channelStatus.hero.* i18n keys from both
locales (grep confirms no remaining usage).

chore: bump version to 0.1.114.31
2026-04-21 12:12:08 +08:00
erio 1d3b0418ac feat(channel-monitor): preserve upstream error body + log silent 503s
Monitor:
- callProvider now returns both textPath-extracted text and raw body;
  runCheckForModel uses rawBody on non-2xx so history.message stops being
  "upstream HTTP 503: " with empty body (gjson textPath produces "" for
  error responses like {"error":{"message":"No available accounts..."}})
- truncateForErrorBody collapses whitespace then caps at 300 bytes
  (monitorErrorBodySnippetMaxBytes); final truncateMessage still enforces
  the 500-byte DB column cap

Gateway:
- Add WARN log at 4 previously-silent 503 fast-paths in gateway_handler.go
  (gateway.select_account_no_available for first-selection failures,
   gateway.select_account_no_slot_no_wait_plan for concurrency misses).
  Before this, /v1/messages could 503 in <10ms with zero service-layer log
  lines, making upstream diagnostics reliant on body capture only.

Frontend:
- MonitorFormDialog: primary_model input text color and ModelTagInput tags
  now both track form.provider (via new getPlatformTextClass + existing
  getPlatformTagClass with platform prop).

chore: bump version to 0.1.114.30
2026-04-21 11:59:11 +08:00
erio 474eb6e7e5 fix(channel-monitor): drop soft delete, refactor feature flag to declarative form
### 后端修复:日志表不该用软删除

channel_monitor_histories / channel_monitor_daily_rollups 都是日志/聚合表,
没有恢复需求。110 里加的 SoftDeleteMixin 会让 DELETE 自动变成 UPDATE deleted_at,
导致行和索引只增不减,徒增磁盘占用和查询成本。

改回分批物理删(参考 OpsCleanupService.deleteOldRowsByID 模板):

- ent schema 移除 SoftDeleteMixin,重新 go generate
- repo 新增 deleteChannelMonitorBatched 辅助 + 两条 prune SQL 常量
  (WITH batch AS SELECT id LIMIT 5000 → DELETE IN batch)
- DeleteHistoryBefore / DeleteRollupsBefore 改调分批 raw SQL
- 移除 ComputeAvailability / ComputeAvailabilityForMonitors / UpsertDailyRollupsFor /
  ListLatestPerModel / ListLatestForMonitorIDs / ListRecentHistoryForMonitors 等
  raw SQL 中的 deleted_at IS NULL 过滤
- UpsertDailyRollupsFor 的 ON CONFLICT 去掉 deleted_at = NULL 重置
- migration 111 DROP COLUMN deleted_at + 对应索引(110 已部署但 maintenance
  首跑在次日 02:00,此时尚无业务数据在依赖软删除)

### 前端重构:feature flag 声明式 + 复用

AppSidebar.vue 里 7 处 `...(flag ? [item] : [])` 样板代码删光,改为 NavItem 加
featureFlag?: () => boolean | undefined 字段,加一个 applyFeatureFlags 递归
过滤(含 children)。语义统一为 `!== false`(宽容策略,undefined 时默认显示,
避免 public settings 未加载完成时菜单闪烁消失 — 对应用户反馈"刷新后菜单消失
要去保存设置才回来")。

- 集中声明 4 个 flag getter:flagChannelMonitor / flagPayment /
  flagOpsMonitoring / flagAdminPayment
- 提取 buildSelfNavItems 复用用户端主菜单和管理员"我的账户"子菜单
- 未来新增开关:在统一位置加一个 flag getter + 给对应 NavItem 加字段
  (不用再动渲染逻辑)

bump 0.1.114.29
2026-04-21 10:45:30 +08:00
erio dc6ac7572e feat(channel-monitor): aggregate history to daily rollups + soft delete
明细只保留 1 天,超过 1 天聚合到新表 channel_monitor_daily_rollups(按
monitor_id/model/bucket_date 维度),聚合保留 30 天。两张表都用 SoftDeleteMixin
软删除(DELETE 自动改为 UPDATE deleted_at = NOW())。

聚合 + 清理任务由 OpsCleanupService 的 cron 统一调度,与运维监控的清理共享
schedule(默认 0 2 * * *)和 leader lock。ChannelMonitorRunner 的 cleanupLoop
被移除,只保留 dueCheckLoop。

读取路径 ComputeAvailability* 改为 UNION 明细(今天 deleted_at IS NULL)+
聚合(过去 windowDays 天 deleted_at IS NULL),SUM(ok)/SUM(total) 自然加权
计算可用率,AVG latency 用 SUM(sum_latency_ms)/SUM(count_latency)。

watermark 表 channel_monitor_aggregation_watermark 单行(id=1),记录
last_aggregated_date,重启后从该日期 +1 继续聚合,首次为 nil 则从
today - 30d 开始回填,单次最多 35 天上限避免长事务。

raw SQL 的 ListLatestPerModel / ListLatestForMonitorIDs / ListRecentHistoryForMonitors
都补上 deleted_at IS NULL 过滤(SoftDeleteMixin interceptor 只对 ent query 生效)。

bump version to 0.1.114.28

GroupBadge 在 MonitorKeyPickerDialog 中复用平台主题色 + 倍率/专属倍率
(顺手优化)。
2026-04-21 10:10:56 +08:00
erio 5608afddae feat(channel-monitor): gate UI by feature switch + polish form UX
- AppSidebar 三处菜单项(管理端渠道监控、用户端/个人页渠道状态)按
  channel_monitor_enabled 条件展开,关闭时隐藏
- ChannelStatusView setInterval 随开关启停:关闭 clearInterval,
  开启/未知态自动启动,避免禁用功能后仍在轮询
- MonitorFormDialog provider Select 改为 3 色单选按钮
  (openai=emerald / anthropic=orange / gemini=sky),i18n 文案
  供应商 → 平台 / Provider → Platform
- MonitorKeyPickerDialog 按钮列表改为 name/key/group 三列表格 +
  搜索框,按 key.group.platform === provider 过滤,避免跨平台误选
- form.provider 变化时清空 api_key,修复切换平台仍保留旧 key 的
  错配 bug
- providerPickerClass 抽取到 useChannelMonitorFormat composable,
  统一 emerald/orange/sky 颜色语义,消除硬编码 Tailwind class 重复
- maskApiKey 工具函数统一(utils/maskApiKey.ts),KeysView 与
  MonitorKeyPickerDialog 共用 slice(0,6)...slice(-4) 策略
- bump version to 0.1.114.27
2026-04-21 01:42:58 +08:00
erio 164c03c863 test: update settings api contract for channel_monitor fields 2026-04-21 00:46:19 +08:00
erio 2031eaf78f fix(channel-monitor): gofmt struct field alignment 2026-04-21 00:40:54 +08:00
erio 7570650bb0 refactor(channel-monitor): remove INTELLIGENCE MONITOR hero title
Subtitle + breadcrumb already convey context; the giant h1 was visual
noise. Drops orphan i18n key `channelStatus.hero.title` and shrinks
hero section vertical padding accordingly.

Bump VERSION to 0.1.114.26
2026-04-21 00:27:07 +08:00
erio a7f4723de3 feat(channel-monitor): add feature switch settings + fix extra_models save
Settings:
- New "功能开关" tab between 通用设置 and 安全与认证
- ChannelMonitorEnabled toggle: runner skips scheduling when false,
  user-facing list returns empty
- ChannelMonitorDefaultIntervalSeconds (15-3600): pre-fills interval
  when creating a new monitor; each monitor can still override

Bug fix:
- ModelTagInput now commits pending input on blur, not just Enter/Tab.
  Previously clicking "save" with an un-Enter'd extra model would drop
  the value (DB stored extra_models=[] even when user typed entries).

Backend:
- domain_constants: SettingKeyChannelMonitor{Enabled,DefaultIntervalSeconds}
- SettingService.GetChannelMonitorRuntime: lightweight getter used by
  runner tick + user handler per-request (fail-open on DB error)
- Runner tickDueChecks: bails early when feature disabled
- ChannelMonitorUserHandler: checks feature flag before serving
- Comment on runner doc: scheduler state is implicit (every tick re-reads
  ListEnabled from DB), so CRUD ops on monitors self-maintain the schedule

Bump VERSION to 0.1.114.25
2026-04-21 00:21:29 +08:00
erio 3fcf68eaaf feat(channel-monitor): redesign user dashboard as card grid
Reference check-cx UI: INTELLIGENCE MONITOR hero + 3-column card grid
with 60-point timeline bars.

Backend:
- Add PrimaryPingLatencyMs + Timeline[60] to UserMonitorView
- ListRecentHistoryForMonitors: batch CTE + ROW_NUMBER() window query
- indexLatestByModel / indexAvailabilityByModel helpers

Frontend:
- 7 new components: ProviderIcon, MonitorMetricPair, MonitorAvailabilityRow,
  MonitorTimeline, MonitorHero, MonitorCard, MonitorCardGrid
- ChannelStatusView 381→~180 lines (delegated to subcomponents)
- AbortController reload concurrency protection
- HSL 0-120° availability color mapping
- Replace emoji with Icon component (bolt / globe)
- i18n: monitorCommon.* shared namespace, channelStatus.hero.*

Bump VERSION to 0.1.114.24
2026-04-20 23:38:59 +08:00
erio e68bffb573 chore: bump version to 0.1.114.23 2026-04-20 22:25:50 +08:00
erio ad6fadf07c fix(tls): pin default_profile Extensions in dialer_capture_test too
之前的 bde1dcd9 在 dialer_integration_test.go 给 TestJA3Fingerprint +
TestAllProfiles/default_node_v24 的 Profile 加了显式 Extensions 锁定 plain
变体,但漏了 dialer_capture_test.go 的 TestDialerAgainstCaptureServer/
default_profile — CI 上再次由 maybeEnrichExtensions 的 50% 概率翻车。

本次给同一位置加同样的 13-extension 显式列表 + WHY 注释指向
dialer_integration_test.go 的完整说明,避免重复文档。

本地 PASS。
2026-04-20 22:25:40 +08:00
erio 529e2d8fe8 chore: bump version to 0.1.114.22 2026-04-20 22:11:24 +08:00
erio bde1dcd9de fix(tls): stabilize JA3/JA4 integration tests by pinning plain variant
CI 一直挂在 TestJA3Fingerprint / TestAllProfiles/default_node_v24 — 调查发现根因不是
Go/Node 版本升级,而是生产 dialer 的 maybeEnrichExtensions() 以约 50% 概率
追加 ECH(65037) + padding(21) 扩展,产出 plain / rich 两种变体;测试断言单一
JA3 时天然 flaky。

修复:
- 两个 integration test 的 Profile 显式设置 Extensions(plain 13-extension 列表)
  锁定为 plain 变体,让 end-to-end 断言确定性
- expectedJA3Hash: 048900f5... → dc782a9d905fdcee1223a3d4e8108bc6
  (dialer.go 头部注释已文档化的 plain 变体值)
- expectedJA4CipherHash: b262b3658495 → 5b57614c22b0
  (与 dialer.go 的 17-cipher defaultCipherSuites + unit test 一致)
- 加详细 WHY 注释,说明 plain/rich 二态、原期望值是 2026-04-19 realign commit
  未经验证的猜测、为什么在此 pin extensions

probabilistic 行为本身由 maybeEnrichExtensions 的 unit test 覆盖,
end-to-end 不重复验证。

本地 PASS(直连 tls.peet.ws)。
2026-04-20 22:11:09 +08:00
erio a9fb750ed0 fix(openai): 移除已下线 Codex 模型并修复归一化兜底副作用
- backend: 删除 gpt-5 / 5.1 / 5.1-codex / 5.1-codex-max / 5.1-codex-mini / 5.2-codex / 5.4-nano 的内置映射与 DefaultModels 条目
- backend: normalizeCodexModel 默认兜底由 gpt-5.1 改为 gpt-5.4,gpt-5.3-codex-spark 独立保留映射
- backend: 修复 isOpenAIGPT54Model 与 shouldAutoInjectPromptCacheKeyForCompat 对 claude / gpt-4o 的误判(之前依赖 gpt-5.1 作为非 GPT 族的隐式 sentinel,改后需要显式前缀守卫)
- backend: 清理 billing_service 中已不可达的 fallback 价格与 switch 分支
- frontend: 从白名单、OpenCode 配置、预设映射中移除已下线模型
- 同步更新所有相关单测

Refs: #1758, parallels upstream #1759 but adds downstream guard fixes
2026-04-20 22:09:17 +08:00
erio c8a3aa5cb6 chore: bump version to 0.1.114.21 2026-04-20 20:52:09 +08:00
erio c089277f36 feat(monitor): admin channel monitor MVP with SSRF protection and batch aggregation
新增 admin「渠道监控」模块(参考 BingZi-233/check-cx),独立于现有 Channel 体系。
admin 配置 + 后台定时调用上游 LLM chat completions 健康检查 + 所有登录用户只读可见。

后端:
- ent: channel_monitor + channel_monitor_history(AES-256-GCM 加密 api_key)
- service 按职责拆分:service/aggregator/validate/checker/runner/ssrf
- provider strategy map 替代 switch(openai/anthropic/gemini)
- repository batch 聚合(ListLatestForMonitorIDs + ComputeAvailabilityForMonitors)消除 N+1
- runner: ticker(5s) + pond worker pool(5) + inFlight 防并发 + TrySubmit 防雪崩
  + 凌晨 3 点 cron 清理 30 天历史
- SSRF 防护:强制 https + 私网/loopback/云元数据 IP 拒绝(127/8、10/8、172.16/12、
  192.168/16、169.254/16、100.64/10、::1、fc00::/7、fe80::/10)+ DialContext
  在 socket 层防 DNS rebinding
- API key sanitize:擦除 url.Error 与上游响应 body 中的 sk-/sk-ant-/AIza/JWT 模式
- APIKeyDecryptFailed 标志位 + 单 monitor 路径检测,避免空 key 调用上游

handler:
- admin: CRUD + 手动触发 + 历史接口(api_key 脱敏)
- user: 只读列表 + 状态详情(去除 api_key/endpoint)
- ParseChannelMonitorID 共用 + dto.ChannelMonitorExtraModelStatus 共用

前端:
- 路由 /admin/channels/{pricing,monitor} + /monitor(用户只读)
- AppSidebar 父项 expandOnly 支持
- ChannelMonitorView 拆为 8 个子组件 + ChannelStatusView 拆出 detail dialog
- composables/useChannelMonitorFormat + constants/channelMonitor 共享
- i18n monitorCommon namespace 消除 admin/user 两 view 重复

合规:所有文件符合 CLAUDE.md(Go ≤ 500 行 / Vue ≤ 300 行 / 函数 ≤ 30 行)
CI: go build / gofmt / golangci-lint(0 issues) / make test-unit / pnpm build 全绿
2026-04-20 20:21:02 +08:00
erio 73c9b78279 chore: bump version to 0.1.114.20 2026-04-20 19:35:41 +08:00
erio fa00b9b79e feat(payment): wxpay pubkey mode only, eager PEM validation
微信从 2024-10 起强推公钥验签,新商户无法下载平台证书,老商户也陆续被迁移。日志里刚确认 beta 商户被微信 404 拒绝平台证书下载。彻底废弃老模式:

- wxpay.go:
  - publicKey / publicKeyId 加入 required 列表
  - NewWxpay 在保存时主动 parse PEM(privateKey 和 publicKey),格式错立即报 WXPAY_CONFIG_INVALID_KEY 带 {key}
  - ensureClient 只走新公钥验签(NewSHA256WithRSAPubkeyVerifier),移除 buildVerifier 和 downloader 分支
  - 清掉 crypto/rsa、auth、downloader 等不再使用的 import

- providerConfig.ts: publicKey / publicKeyId 两个字段去掉 optional:true → UI 加红星必填

- wxpay_test.go:
  - 引入 generateTestKeyPair 在每次用例动态生成有效 RSA 2048 PKCS8/PKIX PEM
  - 替换原先的 "fake-private-key" 字面量,现在 NewWxpay 会真实解析
  - 移除老模式相关用例(legacy/leftover/pair)
  - 新增 malformed PEM 用例覆盖 WXPAY_CONFIG_INVALID_KEY 分支

- i18n locales: 去掉 WXPAY_CONFIG_PAIR_VIOLATION;新增 WXPAY_CONFIG_INVALID_KEY「{key} 格式错误」中英文
2026-04-20 19:35:12 +08:00
erio c289d2da58 chore: bump version to 0.1.114.19 2026-04-20 19:16:08 +08:00
erio 9ed977dba2 feat(payment): validate provider config at save time + loosen wxpay pair rule
**保存时校验** — admin 保存 enabled 的 provider 时,调用 provider.CreateProvider 做一次构造器校验(只在 enabled 时),把原本只在创建订单才暴露的配置错误提前到保存那一刻。已有的结构化错误(WXPAY_CONFIG_MISSING_KEY 等)直接给前端 i18n 用。

**wxpay 校验放宽** — 之前 publicKey/publicKeyId "必须成对"的规则过于严格:DB 里可能残留历史 publicKey(没 publicKeyId),用户想走老平台证书模式但被 pair violation 拦住。改为:
- publicKeyId 非空 → 必须有 publicKey(报 WXPAY_CONFIG_MISSING_KEY key=publicKey)
- publicKeyId 空 → publicKey 视为历史残留,不使用也不报错

移除 WXPAY_CONFIG_PAIR_VIOLATION 错误码。

- payment_config_providers.go: CreateProviderInstance 和 UpdateProviderInstance 新增 validateProviderConfig;Update 要先取旧记录决定 finalEnabled 和 merged config
- wxpay.go: 去掉成对校验,换成"publicKeyId 非空才要求 publicKey"
- wxpay_test.go: 更新用例反映新语义
2026-04-20 19:15:38 +08:00
erio 44d521e2d2 chore: bump version to 0.1.114.18 2026-04-20 18:52:33 +08:00
erio 6dd578fe80 feat(payment): localize config-field names in error messages
之前错误提示里直接显示原始字段名(certSerial / apiV3Key),用户看不懂。

在 extractI18nErrorMessage 内加 localizeMetadata:自动把 metadata.key 和 metadata.keys(斜杠分隔)对应到 admin.settings.payment.field_<key> 的 i18n 标签,查不到才回退原文。

- 「微信支付配置缺少必填项:certSerial」 → 「微信支付配置缺少必填项:证书序列号」
- 「publicKey/publicKeyId must be provided together」 → 「公钥 / 公钥 ID 必须同时配置」
2026-04-20 18:52:20 +08:00
erio 89f1fe0b4e chore: bump version to 0.1.114.17 2026-04-20 18:45:55 +08:00
erio f2c6687cbf feat(payment): structured error codes + frontend i18n mapping
后端返回结构化错误码(reason + metadata 关键词),前端按 reason 查 i18n 文案并用 metadata 填充占位符,用户看到本地化提示而不是英文原始错误。

Backend:
- wxpay.go: 校验错误从 fmt.Errorf 改为 infraerrors.BadRequest 结构化,新增 reason 码:
  - WXPAY_CONFIG_MISSING_KEY (metadata: key)
  - WXPAY_CONFIG_INVALID_KEY_LENGTH (metadata: key, expected, actual)
  - WXPAY_CONFIG_PAIR_VIOLATION (metadata: keys)
- payment_order.go: invokeProvider 用 errors.As 识别 ApplicationError 透传(保留 wxpay 的 reason/metadata),只有非结构化 err 才 fallback 到 PAYMENT_PROVIDER_MISCONFIGURED;其他几个用户可见错误(TOO_MANY_PENDING / DAILY_LIMIT_EXCEEDED / PAYMENT_GATEWAY_ERROR / NO_AVAILABLE_INSTANCE)message 简化为关键词,参数放 metadata
- wxpay_test.go: 更新断言匹配新的 reason code

Frontend:
- apiError.ts: extractApiErrorCode 优先返回 reason(字符串错误码)而非 HTTP 数字;新增 extractI18nErrorMessage 按 namespace.reason 查 i18n 并以 metadata 作模板变量
- 12 个支付相关 Vue 文件(用户/管理/组件)统一改用 extractI18nErrorMessage('payment.errors', ...)
- i18n zh/en locales 下的 payment.errors 添加完整错误码文案(PAYMENT_DISABLED / INVALID_AMOUNT / TOO_MANY_PENDING / DAILY_LIMIT_EXCEEDED / WXPAY_CONFIG_* 等共 20+ 条,支持 {max}/{remaining}/{key} 等占位符)
- 移除 SettingsView 中已失效的 paymentErrorMap computed
2026-04-20 18:45:30 +08:00
erio 14bb922a92 chore: bump version to 0.1.114.16 2026-04-20 18:20:31 +08:00
erio d635b66c29 feat(payment): support wxpay legacy platform-certificate verifier mode
之前的改动只保留了微信支付"新公钥验签"路径,对仍在用平台证书的老商户不可用。

- wxpay.go: publicKeyId 从必填移除;buildVerifier 根据是否配置 publicKeyId 自动切换:
  - 有 → 新公钥方式(NewSHA256WithRSAPubkeyVerifier + 配置的 publicKey)
  - 无 → 平台证书方式(downloader 自动下载平台证书 + NewSHA256WithRSAVerifier)
  publicKey/publicKeyId 必须成对提供,单独一个视为配置错误
- providerConfig.ts: publicKey/publicKeyId 标记为 optional,certSerial 保留必填
- wxpay_test.go: 补 legacy 模式成功用例和成对校验错误用例
2026-04-20 18:19:56 +08:00
erio 7207c5553b chore: bump version to 0.1.114.15 2026-04-20 18:07:46 +08:00
erio 0130ee2422 fix(payment): mark wxpay publicKeyId/certSerial required, surface provider misconfig error
前端把 wxpay 的 publicKeyId 和 certSerial 标成 optional,但后端 NewWxpay 校验时两者都是必填,导致缺配置的实例在创建订单时落入 CreateProvider 失败分支,对外只抛出模糊的 "payment method is temporarily unavailable"。

- providerConfig.ts: 去掉两个字段的 optional: true,表单必填校验生效
- payment_order.go: CreateProvider 失败时改用 PAYMENT_PROVIDER_MISCONFIGURED 错误码,带底层原因和 provider/instance_id metadata,并加 slog.Error 便于定位
2026-04-20 18:07:37 +08:00
erio 2be60ac63a fix: suppress errcheck on recover() in harvester Read path 2026-04-20 01:29:23 +08:00
erio 089d14a2e3 fix(signature): isolate pool buckets by platform
OAuth/setup-token accounts now use per-platform buckets
(oauth:anthropic, oauth:antigravity) instead of a single shared
"oauth" bucket. Prevents cross-contamination between platforms
whose thinking signatures are incompatible.

BucketFor() now takes a platform parameter. All call sites
(harvester, rectifier factory, gateway service) updated.
2026-04-20 00:47:03 +08:00
erio 53b88213f0 feat(signature): add structured logging for pool signature replacement
Log when signatures are replaced from the pool during rectification,
including account_id, bucket, pool_size, and replacement count.
Helps operators verify the pool-replace strategy is working.
2026-04-20 00:24:27 +08:00
erio ade6684077 chore: remove temporary harvester diagnostic logging 2026-04-20 00:08:55 +08:00
erio 0f9c9e8b75 debug: add harvester diagnostic logging 2026-04-19 23:58:15 +08:00
erio 40976d5f08 fix(signature): async harvester with signature_delta support
Rewrite harvester to be fully decoupled from the main read path:
- Read() copies chunks to a buffered channel (non-blocking)
- Background goroutine parses for signatures independently
- sync.Once prevents double-close panic
- defer recover() in Read() guards send-on-closed-channel
- ctx.Done() arm prevents goroutine leaks on abandoned responses
- Panic recovery with slog.Warn logging

Fix signature extraction: the Anthropic API sends signatures via
content_block_delta with delta.type="signature_delta", not in
content_block_start (which has an empty signature field). Support
both shapes for compatibility.

Add 17 comprehensive tests including signature_delta, panic
isolation, double-close, context cancellation, text containing
"signature" word, and no-thinking streams.
2026-04-19 23:25:31 +08:00
erio 0ff3bfe5fa fix(signature): harvest from signature_delta events, not content_block_start
The Anthropic API sends thinking signatures via content_block_delta
with delta.type="signature_delta", not in the content_block_start
event (which has an empty signature field). The harvester was only
checking content_block_start, so it never captured any signatures
and the pool remained permanently empty.

Now handles both content_block_start (legacy compat) and
content_block_delta/signature_delta (current API behavior).
2026-04-19 23:05:10 +08:00
erio fb9c1323d0 debug: add temporary harvester/factory logging to diagnose empty signature pool 2026-04-19 22:56:30 +08:00
erio 26e7d969e8 fix(tlsfingerprint): realign TLS+headers to Claude Code 2.1.114 baseline
Merge hai/snapshot fingerprint update into release branch, preserving
our architectural optimizations (SOCKS5 ContextDialer, identity_service
refactoring, slog migration, capture_fingerprint multi-file structure).

TLS defaults: 52→17 ciphers, 5→3 curves (drop MLKEM768/P521),
2→1 key share (X25519 only), 3→1 point format, 26→9 sig algs.
New probabilistic ECH GREASE + padding (~50% per handshake).
Extension order realigned: server_name first, encrypt_then_mac removed,
status_request/SCT added.

Headers: UA 2.1.114, Runtime v24.3.0 (bundled Node), Timeout 600.
New BetaStructuredOutputs20251215 for Haiku title-sidecar requests.
2026-04-19 22:21:51 +08:00
erio e20a57f53e refactor(scheduled-test): switch to minimal PR 1753 approach
Replace the 4-file service-layer cleanup with the upstream PR's simpler
transaction-level DELETE in accountRepository.Delete.

Bump version to 0.1.114.13.
2026-04-19 20:44:19 +08:00
erio 91db3aabfe Merge remote-tracking branch 'origin/feat/fix-orphaned-scheduled-tests' into release/custom-0.1.114 2026-04-19 20:30:31 +08:00
erio f68894191b chore: bump version to 0.1.114.12 2026-04-19 20:30:01 +08:00
erio b51f20ea85 fix: add missing ScheduledTestPlanRepository arg in test 2026-04-19 20:29:01 +08:00
erio edf20829ba Merge remote-tracking branch 'origin/feat/fix-orphaned-scheduled-tests' into release/custom-0.1.114 2026-04-19 20:26:49 +08:00
erio 79e100a1cf fix: delete scheduled test plans when account is deleted
Accounts use soft-delete (setting deleted_at), so PostgreSQL's
ON DELETE CASCADE on scheduled_test_plans.account_id never fires.
This leaves orphaned plans that continue executing and cannot be
managed from the frontend since the account no longer exists.

Closes Wei-Shaw/sub2api#1728
2026-04-19 20:22:18 +08:00
erio cae8ed99fa test(tlsfingerprint): update expectations to Claude Code CLI default (X25519MLKEM768 + X25519) 2026-04-19 19:41:44 +08:00