Skip to content

Commit 30d509b

Browse files
committed
refactor: route runtime toast helper directly
1 parent c478968 commit 30d509b

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

index.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,6 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
306306
MODEL_FAMILIES,
307307
});
308308

309-
const showToast = async (
310-
message: string,
311-
variant: "info" | "success" | "warning" | "error" = "success",
312-
options?: { title?: string; duration?: number },
313-
): Promise<void> => showRuntimeToast(client, message, variant, options);
314-
315309
const hydrateEmails = async (
316310
storage: AccountStorageV3 | null,
317311
): Promise<AccountStorageV3 | null> => {
@@ -630,7 +624,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
630624
await reloadAccountManagerFromDisk();
631625
}
632626

633-
await showToast(`Switched to account ${index + 1}`, "info");
627+
await showRuntimeToast(client, `Switched to account ${index + 1}`, "info");
634628
}
635629
}
636630
} catch (error) {
@@ -826,7 +820,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
826820
: null;
827821

828822
checkAndNotify(async (message, variant) => {
829-
await showToast(message, variant);
823+
await showRuntimeToast(client, message, variant);
830824
}).catch((err) => {
831825
logDebug(
832826
`Update check failed: ${err instanceof Error ? err.message : String(err)}`,
@@ -1039,7 +1033,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
10391033

10401034
const remaining = Math.max(0, endTime - Date.now());
10411035
const waitLabel = formatWaitTime(remaining);
1042-
await showToast(
1036+
await showRuntimeToast(client,
10431037
`${message} (${waitLabel} remaining)`,
10441038
"warning",
10451039
{
@@ -1206,7 +1200,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
12061200
accountManager.removeAccount(account);
12071201
sessionAffinityStore?.reindexAfterRemoval(removedIndex);
12081202
accountManager.saveToDiskDebounced();
1209-
await showToast(
1203+
await showRuntimeToast(client,
12101204
`Removed ${accountLabel} after ${failures} consecutive auth failures. Run 'codex login' to re-add.`,
12111205
"error",
12121206
{ duration: toastDurationMs * 2 },
@@ -1298,7 +1292,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
12981292
account,
12991293
account.index,
13001294
);
1301-
await showToast(
1295+
await showRuntimeToast(client,
13021296
`Using ${accountLabel} (${account.index + 1}/${accountCount})`,
13031297
"info",
13041298
);
@@ -1677,7 +1671,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
16771671
fallbackReason: "unsupported-model-entitlement",
16781672
},
16791673
);
1680-
await showToast(
1674+
await showRuntimeToast(client,
16811675
`Model ${previousModel} is not available for this account. Retrying with ${model}.`,
16821676
"warning",
16831677
{ duration: toastDurationMs },
@@ -1710,7 +1704,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
17101704
fallbackReason: "unsupported-model-entitlement",
17111705
},
17121706
);
1713-
await showToast(
1707+
await showRuntimeToast(client,
17141708
`Model ${blockedModel} is not available for this account. Strict policy blocked automatic fallback.`,
17151709
"warning",
17161710
{ duration: toastDurationMs },
@@ -1805,7 +1799,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
18051799

18061800
const newWorkspaceName =
18071801
nextWorkspace.name ?? nextWorkspace.id;
1808-
await showToast(
1802+
await showRuntimeToast(client,
18091803
`Workspace ${workspaceName} disabled. Switched to ${newWorkspaceName}.`,
18101804
"warning",
18111805
{ duration: toastDurationMs },
@@ -1830,7 +1824,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
18301824
);
18311825
accountManager.saveToDiskDebounced();
18321826

1833-
await showToast(
1827+
await showRuntimeToast(client,
18341828
`All workspaces disabled for account ${account.index + 1}. Switching to another account.`,
18351829
"warning",
18361830
{ duration: toastDurationMs },
@@ -1869,7 +1863,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
18691863
const errorType = detectErrorType(errorBody);
18701864
const toastContent =
18711865
getRecoveryToastContent(errorType);
1872-
await showToast(
1866+
await showRuntimeToast(client,
18731867
`${toastContent.title}: ${toastContent.message}`,
18741868
"warning",
18751869
{ duration: toastDurationMs },
@@ -1968,7 +1962,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
19681962
rateLimitToastDebounceMs,
19691963
)
19701964
) {
1971-
await showToast(
1965+
await showRuntimeToast(client,
19721966
`Rate limited. Retrying in ${waitLabel} (attempt ${attempt})...`,
19731967
"warning",
19741968
{ duration: toastDurationMs },
@@ -2011,7 +2005,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
20112005
rateLimitToastDebounceMs,
20122006
)
20132007
) {
2014-
await showToast(
2008+
await showRuntimeToast(client,
20152009
`Rate limited. Switching accounts (retry in ${waitLabel}).`,
20162010
"warning",
20172011
{ duration: toastDurationMs },
@@ -2361,7 +2355,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
23612355
logWarn(
23622356
`Empty response received (attempt ${emptyResponseRetries}/${emptyResponseMaxRetries}). Retrying...`,
23632357
);
2364-
await showToast(
2358+
await showRuntimeToast(client,
23652359
`Empty response. Retrying (${emptyResponseRetries}/${emptyResponseMaxRetries})...`,
23662360
"warning",
23672361
{ duration: toastDurationMs },
@@ -3547,7 +3541,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
35473541
logError(
35483542
`[${PLUGIN_NAME}] Failed to persist account: [${errorCode}] ${(err as Error)?.message ?? String(err)}`,
35493543
);
3550-
await showToast(hint, "error", {
3544+
await showRuntimeToast(client, hint, "error", {
35513545
title: "Account Persistence Failed",
35523546
duration: 10000,
35533547
});
@@ -3631,7 +3625,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
36313625
}
36323626

36333627
accounts.push(resolved);
3634-
await showToast(
3628+
await showRuntimeToast(client,
36353629
`Account ${accounts.length} authenticated`,
36363630
"success",
36373631
);
@@ -3651,7 +3645,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
36513645
logError(
36523646
`[${PLUGIN_NAME}] Failed to persist account: [${errorCode}] ${(err as Error)?.message ?? String(err)}`,
36533647
);
3654-
await showToast(hint, "error", {
3648+
await showRuntimeToast(client, hint, "error", {
36553649
title: "Account Persistence Failed",
36563650
duration: 10000,
36573651
});
@@ -3738,7 +3732,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
37383732
logError(
37393733
`[${PLUGIN_NAME}] Failed to persist account: [${errorCode}] ${(err as Error)?.message ?? String(err)}`,
37403734
);
3741-
await showToast(hint, "error", {
3735+
await showRuntimeToast(client, hint, "error", {
37423736
title: "Account Persistence Failed",
37433737
duration: 10000,
37443738
});

0 commit comments

Comments
 (0)