Repository navigation
Clear the out-of-credits error once the account can pay again - #190
Merged
Merged
Conversation
The red "not enough credits" card stayed in the chat after the user upgraded or bought credits, above the build that went on, and came back on every reload since it is saved in the chat history. An upgrade, a top-up, or a plan change noticed when the tab regains focus now removes the out-of-credits and usage-limit cards from the chat, and marks the saved entries so a reload doesn't draw them again. The entries stay in the history the AI reads, so it still knows why the build stopped. New errors are tagged creditError; older ones are matched by their text.
A card whose text said out of credits, but whose error had no insufficient_funds code or 402, wasn't tagged credit-error. After an upgrade it stayed in the chat while its saved entry, told by its text, was marked cleared, so it only went on the next reload. The live card is now tagged by isCreditErrorEntry on the entry that is saved, the same test a reload uses. Adds test-clear-credit-errors.
Paying from a card's own Add credits or Upgrade button leaves focus on that button. clearCreditErrors removed the card, so focus fell to <body>: the next Tab started over from the top of the page, and the success dialog opened right after (completeUpgrade) remembered <body> as the element to hand focus back to. After keyboard use focus now moves to the composer. After a tap it isn't moved, so a phone's keyboard doesn't pop up.
consumePaidAfterLimit cleared the cards before it checked that no new limit hit was saved while it waited on Puter. A build that ran out again in that time had its new, current card removed and its entry marked cleared, though the account couldn't pay. The cards are now cleared only once the record the payment was measured against is the one consumed.
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.
The red "not enough credits" card stayed in the chat after the user upgraded or bought credits, above the build that went on. It is saved in the chat history, so it also came back on every reload.
Changes
clearCreditErrors()(app.js) removes the out-of-credits cards and the usage-limit "Upgrade / Add credits" cards from the chat, marks the saved entriescreditErrorClearedand saves the chat. During a running build, the build's next save writes the mark.completeUpgrade), a top-up completes (openTopUp), or the focus check finds a plan change or bought credit (consumePaidAfterLimit).loadChatskips cleared entries. They stay in the history the AI reads, so it still knows why the build stopped, and deleting them could leave two user messages in a row.creditError: true. Errors saved before this change are matched by their text. The live card gets acredit-errorclass from the same test a reload uses (isCreditErrorEntry), so an out-of-credits text without Puter's code also leaves the chat right away.<body>and the success dialog has something to return focus to. After a tap it isn't moved, so a phone's keyboard doesn't pop up.prepareHistoryForAIremoves both markers before the history goes to the AI.Limits
Testing
npm testpasses, including the newtest-clear-credit-errorsand the added paid-check cases intest-usage-limit-unblock.