feat(usage): add banked reset credits support#329
Open
bytemain wants to merge 4 commits into
Open
Conversation
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.
f9e5e87 to
7eea579
Compare
Contributor
|
不能看剩余重置次数吗? |
Author
现在点击重置后会有一个弹窗确认,你还有 xx 次 |
Contributor
|
我点击弹窗确认重置后,左上有个蓝色通知说取消重置了,然后又弹出绿色通知说重置成功。不应该出现这个取消重置的通知呀 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
本 PR 基于 @yao0507 提交的 #318 (banked reset credits support),感谢原作者的工作 🙏。在将其合并到本地
main进行使用的过程中,我们修复了一个让该功能在 Tauri 桌面端无法实际触发的 UI 问题。改动
本 PR 包含两个 commit,合并后等价于 PR #318 全文 + 一处额外修复:
181505b4feat(usage): add banked reset credits supportPR [codex] add banked reset credits support #318 的完整 cherry-pick(commit message 中已注明来源,保留原作者归属)。
f9e5e87cfix(usage): replace window.confirm with ConfirmDialog modal (本 PR 新增)将免费重置确认弹窗从浏览器原生
window.confirm替换为项目自带的ConfirmDialog组件。为什么需要这个修复
PR #318 在 free reset 流程中使用了
window.confirm()让用户确认是否消耗一次免费重置: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。sections/{en,ko,ru}-accounts.ts(原 PR 只改了顶层en.ts),pnpm run test:runtime现在 89/89 通过。验证
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 桌面端的一个落地问题。