fix(ui): handle headless execution in credits and upgrade dialogs (#21850)

This commit is contained in:
Gaurav
2026-03-10 07:54:15 -07:00
committed by GitHub
parent cb2aaa4fd4
commit 7dfb8b6e80
7 changed files with 129 additions and 7 deletions
@@ -14,6 +14,7 @@ import {
shouldShowOverageMenu,
shouldShowEmptyWalletMenu,
openBrowserSecurely,
shouldLaunchBrowser,
logBillingEvent,
OverageMenuShownEvent,
OverageOptionSelectedEvent,
@@ -159,10 +160,23 @@ async function handleOverageMenu(
case 'use_fallback':
return 'retry_always';
case 'manage':
case 'manage': {
logCreditPurchaseClick(config, 'manage', usageLimitReachedModel);
await openG1Url('activity', G1_UTM_CAMPAIGNS.MANAGE_ACTIVITY);
const manageUrl = await openG1Url(
'activity',
G1_UTM_CAMPAIGNS.MANAGE_ACTIVITY,
);
if (manageUrl) {
args.historyManager.addItem(
{
type: MessageType.INFO,
text: `Please open this URL in a browser: ${manageUrl}`,
},
Date.now(),
);
}
return 'stop';
}
case 'stop':
default:
@@ -205,13 +219,25 @@ async function handleEmptyWalletMenu(
failedModel: usageLimitReachedModel,
fallbackModel,
resetTime,
onGetCredits: () => {
onGetCredits: async () => {
logCreditPurchaseClick(
config,
'empty_wallet_menu',
usageLimitReachedModel,
);
void openG1Url('credits', G1_UTM_CAMPAIGNS.EMPTY_WALLET_ADD_CREDITS);
const creditsUrl = await openG1Url(
'credits',
G1_UTM_CAMPAIGNS.EMPTY_WALLET_ADD_CREDITS,
);
if (creditsUrl) {
args.historyManager.addItem(
{
type: MessageType.INFO,
text: `Please open this URL in a browser: ${creditsUrl}`,
},
Date.now(),
);
}
},
resolve,
});
@@ -272,11 +298,16 @@ function logCreditPurchaseClick(
async function openG1Url(
path: 'activity' | 'credits',
campaign: string,
): Promise<void> {
): Promise<string | undefined> {
try {
const userEmail = new UserAccountManager().getCachedGoogleAccount() ?? '';
await openBrowserSecurely(buildG1Url(path, userEmail, campaign));
const url = buildG1Url(path, userEmail, campaign);
if (!shouldLaunchBrowser()) {
return url;
}
await openBrowserSecurely(url);
} catch {
// Ignore browser open errors
}
return undefined;
}