Skip to content

Commit c478968

Browse files
committed
refactor: extract runtime toast helper
1 parent f6dd8e3 commit c478968

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import {
180180
sanitizeResponseHeadersForLog,
181181
} from "./lib/runtime/metrics.js";
182182
import { runOAuthBrowserFlow } from "./lib/runtime/oauth-browser-flow.js";
183+
import { showRuntimeToast } from "./lib/runtime/toast.js";
183184
import { SessionAffinityStore } from "./lib/session-affinity.js";
184185
import { registerCleanup } from "./lib/shutdown.js";
185186
import {
@@ -309,20 +310,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
309310
message: string,
310311
variant: "info" | "success" | "warning" | "error" = "success",
311312
options?: { title?: string; duration?: number },
312-
): Promise<void> => {
313-
try {
314-
await client.tui.showToast({
315-
body: {
316-
message,
317-
variant,
318-
...(options?.title && { title: options.title }),
319-
...(options?.duration && { duration: options.duration }),
320-
},
321-
});
322-
} catch {
323-
// Ignore when TUI is not available.
324-
}
325-
};
313+
): Promise<void> => showRuntimeToast(client, message, variant, options);
326314

327315
const hydrateEmails = async (
328316
storage: AccountStorageV3 | null,

lib/runtime/toast.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export async function showRuntimeToast(
2+
client: {
3+
tui?: {
4+
showToast?: (payload: {
5+
body: {
6+
message: string;
7+
variant: "info" | "success" | "warning" | "error";
8+
title?: string;
9+
duration?: number;
10+
};
11+
}) => Promise<void>;
12+
};
13+
},
14+
message: string,
15+
variant: "info" | "success" | "warning" | "error" = "success",
16+
options?: { title?: string; duration?: number },
17+
): Promise<void> {
18+
try {
19+
await client.tui?.showToast?.({
20+
body: {
21+
message,
22+
variant,
23+
...(options?.title && { title: options.title }),
24+
...(options?.duration && { duration: options.duration }),
25+
},
26+
});
27+
} catch {
28+
// Ignore when TUI is not available.
29+
}
30+
}

0 commit comments

Comments
 (0)