Skip to content

[codex] add api key quota limits#140

Open
hansaes wants to merge 3 commits intoqxcnm:mainfrom
hansaes:codex/api-key-quota-limits
Open

[codex] add api key quota limits#140
hansaes wants to merge 3 commits intoqxcnm:mainfrom
hansaes:codex/api-key-quota-limits

Conversation

@hansaes
Copy link
Copy Markdown

@hansaes hansaes commented Apr 17, 2026

变更摘要 / Summary

  • 为平台密钥增加总 Token、总金额(USD)和总请求次数三种累计限额,并持久化到独立存储表。
  • 在网关本地校验阶段拦截已超限的 key,避免继续向上游发送请求。
  • 为 API Key 页面和编辑弹窗补充限额配置、使用量展示与超限状态提示。
  • 修复桌面端创建/更新 API Key 时未透传限额字段的问题,并补上一条运行时回归测试。

范围 / Scope

  • storage: 新增 �pi_key_quota_limits 迁移、读写接口与 RPC 类型字段。
  • service: 在 create/update/list/usage 流程中接入限额,并在本地认证前做超限拒绝。
  • frontend: 在 API Key 列表展示 oken / cost / request 使用情况与阈值,在弹窗中支持编辑三类限额。
  • desktop bridge: 让 Tauri service_apikey_create / service_apikey_update_model 正确透传限额字段。
  • tests: 新增 �pps/tests/api-key-limits-forwarding.test.mjs 覆盖桌面桥接与 account-client 透传链路。

根因 / Root Cause

  • 之前的限额能力已经在核心存储、服务层和前端 UI 中接入,但桌面运行时的 Tauri 命令层没有把 otalTokenLimit、 otalCostUsdLimit、 otalRequestLimit 继续向后透传。
  • 结果是桌面端保存 API Key 时,限额字段会丢失,导致“限制无法保存/无法生效”的问题。

关键文件 / Key Files

  • crates/core/src/storage/api_key_quota_limits.rs
  • crates/service/src/apikey/apikey_quota_limits.rs
  • crates/service/src/gateway/local_validation/auth.rs
  • �pps/src/components/modals/api-key-modal.tsx
  • �pps/src/app/apikeys/page.tsx
  • �pps/src-tauri/src/commands/apikey.rs
  • �pps/src/lib/api/account-client.ts
  • �pps/tests/api-key-limits-forwarding.test.mjs

验证 / Validation

  • pnpm --dir apps run test:runtime
  • cargo check -p codexmanager-core -p codexmanager-service
  • pnpm --dir apps run build:desktop

风险 / Notes

  • 这个 PR 有意只包含 API Key 限额能力及其桌面透传修复,未带入本地 main 上其他团队管理、打包产物或 .run-logs 变更。
  • 本地执行 cargo test -p codexmanager-core migration_tests 时遇到 Windows 链接器环境问题:link.exe 无法解析 ___chkstk_ms 与 __isnan(来自 sqlite3 test linking)。因此这里用 cargo check 作为 Rust 侧可复现验证,并保留前端运行时测试与桌面构建结果。

@qxcnm qxcnm marked this pull request as ready for review April 17, 2026 12:37
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