Skip to content

feat(usage): add banked reset credits support#329

Open
bytemain wants to merge 4 commits into
qxcnm:mainfrom
bytemain:feat/banked-reset-credits-with-confirm-fix
Open

feat(usage): add banked reset credits support#329
bytemain wants to merge 4 commits into
qxcnm:mainfrom
bytemain:feat/banked-reset-credits-with-confirm-fix

Conversation

@bytemain

Copy link
Copy Markdown

背景

本 PR 基于 @yao0507 提交的 #318 (banked reset credits support),感谢原作者的工作 🙏。在将其合并到本地 main 进行使用的过程中,我们修复了一个让该功能在 Tauri 桌面端无法实际触发的 UI 问题。

改动

本 PR 包含两个 commit,合并后等价于 PR #318 全文 + 一处额外修复:

  1. 181505b4 feat(usage): add banked reset credits support
    PR [codex] add banked reset credits support #318 的完整 cherry-pick(commit message 中已注明来源,保留原作者归属)。
  2. f9e5e87c fix(usage): replace window.confirm with ConfirmDialog modal (本 PR 新增)
    将免费重置确认弹窗从浏览器原生 window.confirm 替换为项目自带的 ConfirmDialog 组件。

为什么需要这个修复

PR #318 在 free reset 流程中使用了 window.confirm() 让用户确认是否消耗一次免费重置:

const confirmed =
  typeof window === "undefined" ||
  window.confirm(t("当前账号有 {count} 次免费重置可用,..."));

window.confirm() 在 Tauri webview 中不能可靠弹出 —— 多数情况下被静默忽略、被视为 false(用户取消)。结果就是:点击「触发免费重置」按钮,只会显示「已取消免费重置」toast,reset credits 从未真正被消耗。这个 bug 仅出现在桌面 Tauri 窗口里,浏览器/Web 模式下不太容易触发,但作为桌面端主要入口,影响所有桌面用户。

修复内容

  • apps/src/hooks/useAccounts.ts: 把原来的 resetCreditsMutation 拆成两步:
    • readResetCreditsMutation: 读取剩余次数,成功后将 { accountId, availableCount } 写入 pendingReset 状态;
    • consumeResetCreditsMutation: 仅在用户点击确认后才真正消耗一次 reset credit。
  • apps/src/app/accounts/accounts-page-view.tsx: 新增一个 ConfirmDialog,由 pendingReset 驱动,onOpenChange=false 调用 cancelPendingReset,onConfirm 调用 confirmPendingReset
  • apps/src/app/accounts/page.tsx: 把 hook 新增字段透传到 view。
  • i18n:

验证

  • pnpm run build:desktop —— TypeScript 类型检查 + 16/16 静态页生成通过
  • pnpm run test:runtime —— 89/89 通过(含 i18n-page-coverage)
  • cargo test -p codexmanager-service --test rpc —— 36/36 通过(含 PR [codex] add banked reset credits support #318 新增的两个 account_usage_reset_credits_* 测试)
  • cargo test -p codexmanager-core --lib usage::* —— 15/15 通过

致谢

再次感谢 @yao0507 在 PR #318 中的设计与实现,本 PR 仅修复其 UI 在 Tauri 桌面端的一个落地问题。

Ubuntu and others added 2 commits June 28, 2026 02:57
The free-reset flow in the accounts dashboard was using
window.confirm() to ask the user whether to consume a banked reset
credit. window.confirm() does not reliably render inside a Tauri
webview (the dialog is silently dismissed and treated as a cancel),
which meant clicking 'Trigger free reset' would only ever show the
'Free reset canceled' toast and never actually trigger a reset.

This commit refactors the flow to use the project's shared
ConfirmDialog component instead:

Frontend (apps/src/):
- apps/src/hooks/useAccounts.ts: split the previous combined
  resetCreditsMutation into a read step (readRateLimitResetCredits)
  and a consume step (consumeRateLimitResetCredits). The read step
  populates a pendingReset state which the UI uses to render the
  modal; the consume step runs only after the user clicks confirm.
- apps/src/app/accounts/accounts-page-view.tsx: render a
  ConfirmDialog driven by pendingReset; route its onOpenChange /
  onConfirm to the new cancel/confirm handlers.
- apps/src/app/accounts/page.tsx: thread the new hook fields
  through to the view.

i18n:
- apps/src/lib/i18n/messages/en.ts: add the
  '查询免费重置次数失败' key used by the read failure toast.
- apps/src/lib/i18n/messages/sections/en-accounts.ts,
  ko-accounts.ts, ru-accounts.ts: complete the free-reset key set
  introduced in PR qxcnm#318. Those keys were only added to the top-level
  en.ts bundle and were missing from the per-section locale files,
  causing the i18n coverage test to fail.
@bytemain bytemain changed the title feat(usage): cherry-pick #318 + 修复 Tauri 桌面端 confirm 弹窗失效 feat(usage): add banked reset credits support Jun 28, 2026
@bytemain bytemain force-pushed the feat/banked-reset-credits-with-confirm-fix branch from f9e5e87 to 7eea579 Compare June 28, 2026 10:21
@CHANTXU64

Copy link
Copy Markdown
Contributor

不能看剩余重置次数吗?

@bytemain

bytemain commented Jul 2, 2026

Copy link
Copy Markdown
Author

不能看剩余重置次数吗?

现在点击重置后会有一个弹窗确认,你还有 xx 次

@CHANTXU64

Copy link
Copy Markdown
Contributor

我点击弹窗确认重置后,左上有个蓝色通知说取消重置了,然后又弹出绿色通知说重置成功。不应该出现这个取消重置的通知呀

bytemain added 2 commits July 2, 2026 19:38
OpenAI/chatgpt.com intermittently returns 404 as a traffic downgrade.
Treat official upstream 404 like 429: mark the account cooldown and
failover to other candidates when available. Last candidate still
returns the 404 upstream response to preserve semantics.

Also update docs/issues/openai-upstream-404.md to reflect the fix.
ConfirmDialog calls onOpenChange(false) after onConfirm, so the
accounts-page onOpenChange handler was treating a confirm close as a
cancel and showing the blue cancel toast before the success toast.

Add an onCancel callback to ConfirmDialog and move the cancel toast
there; use dismissPendingReset in onOpenChange so confirm/overlay/Esc
close only clears state without toasting.
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.

2 participants