Skip to content

feat(account): 侧栏账户卡接 alpha-platform B 余额/会员/用量(+14天 sparkline) - #11

Merged
jinjunnn merged 2 commits into
alphafrom
feat/account-usage
Jun 24, 2026
Merged

jinjunnn merged 2 commits into
alphafrom
feat/account-usage

Conversation

@jinjunnn

@jinjunnn jinjunnn commented Jun 24, 2026 •

Copy link
Copy Markdown
Owner

为什么

让 alpha-code 真正显示账户用量/会员/余额。按 alpha-platform/docs/alpha-code-account-integration.md:登录拿 C 签发的 JWT → 直读 B 的境内 account-server account.tidelabs.click 的 GET /v1/account/summary。B 已实现并部署。

改了什么

  • shared/alpha-config:第三个域 ALPHA_ENDPOINTS.account + 路径 ALPHA_PATHS.{accountSummary,transactions}。
  • main:alpha-account.ts(Bearer JWT,401/network → typed error);account-ipc.ts(自包含 IPC,镜像 ext-ipc);alpha-auth.ts 加 getAccessToken()——main-only,token 不出 renderer。
  • preload:account.{summary,transactions} + 跨 bundle AccountSummary 类型。
  • renderer:侧栏账户弹层接真实数据(会员/余额/5h·7d 额度)+ 近 14 天 内联 Sparkline;loading/error/未订阅(按量计费)分支;header chip / footer / CTA 的会员显示统一优先用 summary(否则会出现卡片 Pro、顶部却"免费版")。

env 覆盖 ALPHA_ACCOUNT_URL,与 ALPHA_WEB_URL/ALPHA_PLATFORM_URL 一致。零改 upstream。

安全

JWT 仅 main 持有(getAccessToken 不经 IPC 暴露);renderer 只拿已解析 summary。账户读走境内 account-server(PII/金融驻留境内),不打模型 gateway。

测试(端到端,自验)

  • tsgo -b green。
  • 真实端点冒烟:curl account.tidelabs.click/v1/account/summary(无 token)→ 401 unauthorized(域名/路径/鉴权正确)。
  • 本地 dev account-server 端到端:起 alpha-platform/packages/gateway(dev 租户),alpha-code 以 ALPHA_ACCOUNT_URL=localhost:8787 + DEV_PLATFORM_TOKEN 起 → CDP 截图核验账户弹层:
    • 返回形状 100% 对上 AccountSummary 类型(balanceFen/plan{window5h,window7d,renewsAt,daysLeft}/usage/usageSeries[14])。
    • 弹层渲染:会员订阅 Pro · 可用余额 ¥499.97 · 5 小时额度 45/30 · 7 日额度 45/100.0K · 近 14 天 sparkline;header+footer = PRO;CTA = 充值/管理订阅。

备注

usageSeries 已返 14 天数组(dev 租户 tokens 全 0 → sparkline 平线);真实用量累积后自动点亮。

🤖 Generated with Claude Code

alpha-code 持 stored JWT 读 GET /v1/account/summary(境内 account.tidelabs.click),
填上侧栏账户弹层:会员订阅、可用余额、5h/7d 额度窗口、近 14 天用量 sparkline——
替换原「待接入」占位。

- shared/alpha-config:+ account host(ALPHA_ENDPOINTS.account)+ 路径
  (accountSummary /v1/account/summary、transactions /v1/billing/transactions)
- main:alpha-account.ts client(Bearer JWT,401/network → typed error)、
  account-ipc.ts 注册、alpha-auth 加 getAccessToken()(main-only,token 不出 renderer)
- preload:account.{summary,transactions} 命名空间 + 跨 bundle AccountSummary 类型
- renderer:账户卡接真实数据,带 loading/error/未订阅(按量计费)分支 + 内联 Sparkline(无图表库)

env 覆盖:ALPHA_ACCOUNT_URL(与 ALPHA_WEB_URL/ALPHA_PLATFORM_URL 一致)。
验证:tsgo -b green;真实端点冒烟 —— 无 token GET .../v1/account/summary 返回 401
unauthorized(域名/路径正确、服务在线、鉴权生效)。**尚未**用已登录 token 做像素核验
(需 DEV_PLATFORM_TOKEN 或 OAuth 登录)。usageSeries 空时 sparkline 显示「暂无数据」。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

让顶部 chip、底部 sub、升级/管理 CTA 都优先用 fetch 到的 summary plan(权威),
而非只看 JWT 的粗粒度 claim——截图核验时发现卡片显示「Pro」但顶部却是「免费版」。
summary 未到时回退到 JWT claim,所以两处永不矛盾。

端到端核验(本地 dev account-server,dev 租户):弹层 Pro / ¥499.97 / 45·30 /
45·100.0K / 14 天 sparkline;header+footer 现读 PRO;CTA 显示 充值/管理订阅。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jinjunnn
jinjunnn merged commit 6830837 into alpha Jun 24, 2026
4 of 8 checks passed
@jinjunnn
jinjunnn deleted the feat/account-usage branch June 24, 2026 09:47
jinjunnn pushed a commit that referenced this pull request Jun 24, 2026
PR #11 账户集成后核实:接口与 B 侧计量链均通,但默认 BYOK 直连绕过 B;
走 gateway 的 alpha provider 模型还是占位 alpha-default(alpha-models.ts:60 TODO)。
要让用量出数需平台模式 + 接真实模型 id。详见 docs/platform-integration.md。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant