Skip to content

Automate browser based workflows with AI

[SKY-6] Frontend: 2FA verification code UI and notifications (#4787)

Aaron Perezc330a9b2cbd9
diff --git a/skyvern-frontend/.env.example b/skyvern-frontend/.env.example
index 4a6db699a..c125b069a 100644
--- a/skyvern-frontend/.env.example
+++ b/skyvern-frontend/.env.example
@@ -15,3 +15,7 @@ VITE_ENABLE_LOG_ARTIFACTS=false
# Enable code block node
VITE_ENABLE_CODE_BLOCK=true
+
+# Enable 2FA verification code notifications (toasts, sounds, OS notifications, WebSocket streaming)
+# Set to "false" to disable for orgs with high task/workflow volume
+VITE_ENABLE_2FA_NOTIFICATIONS=true
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts
index fb49527be..9d21e2a45 100644
--- a/skyvern-frontend/src/api/types.ts
+++ b/skyvern-frontend/src/api/types.ts
@@ -151,6 +151,9 @@ export type TaskApiResponse = {
task_v2: TaskV2 | null;
workflow_run_id: string | null;
browser_session_id: string | null;
+ waiting_for_verification_code?: boolean;
+ verification_code_identifier?: string | null;
+ verification_code_polling_started_at?: string | null;
};
export type CreateTaskRequest = {
@@ -416,6 +419,9 @@ export type WorkflowRunStatusApiResponse = {
workflow_title: string | null;
browser_session_id: string | null;
max_screenshot_scrolls: number | null;
+ waiting_for_verification_code?: boolean;
+ verification_code_identifier?: string | null;
+ verification_code_polling_started_at?: string | null;
};
export type WorkflowRunStatusApiResponseWithWorkflow = {
@@ -442,6 +448,9 @@ export type WorkflowRunStatusApiResponseWithWorkflow = {
browser_session_id: string | null;
max_screenshot_scrolls: number | null;
workflow: WorkflowApiResponse;
+ waiting_for_verification_code?: boolean;
+ verification_code_identifier?: string | null;
+ verification_code_polling_started_at?: string | null;
};
export type TaskGenerationApiResponse = {
diff --git a/skyvern-frontend/src/components/GlobalNotificationListener.tsx b/skyvern-frontend/src/components/GlobalNotificationListener.tsx
new file mode 100644
index 000000000..ad0bd7b5d
--- /dev/null
+++ b/skyvern-frontend/src/components/GlobalNotificationListener.tsx
@@ -0,0 +1,57 @@
+import { useVerificationCodeAlert } from "@/hooks/useVerificationCodeAlert";
+import {
+ useNotificationStream,
+ type VerificationRequest,
+} from "@/hooks/useNotificationStream";
+import { enable2faNotifications } from "@/util/env";
+
+function notificationLabel(req: VerificationRequest): string {
+ if (req.task_id) return `Task "${req.task_id}"`;
+ if (req.workflow_run_id) return `Workflow run "${req.workflow_run_id}"`;
+ return "Run";
+}
+
+function notificationNavigateUrl(req: VerificationRequest): string | undefined {
+ if (req.workflow_run_id) return `/runs/${req.workflow_run_id}/overview`;
+ if (req.task_id) return `/runs/${req.task_id}/actions`;
+ return undefined;
+}
+
+/**
+ * Invisible component that fires toast / browser notification / sound
+ * for a single active 2FA request. No banner UI — that lives on the
+ * per-page detail components only.
+ */
+function VerificationCodeHandler({ req }: { req: VerificationRequest }) {
+ const key = req.task_id ?? req.workflow_run_id ?? "";
+ useVerificationCodeAlert({
+ isWaitingForCode: true,
+ pollingStartedAt: req.polling_started_at ?? null,
+ label: notificationLabel(req),
+ notificationTag: `2fa-required-${key}`,
+ navigateUrl: notificationNavigateUrl(req),
+ });
+ return null;
+}
+
+function GlobalNotificationListener() {
+ if (!enable2faNotifications) return null;
+ return <GlobalNotificationListenerInner />;
+}
+
+function GlobalNotificationListenerInner() {
+ const { verificationRequests } = useNotificationStream();
+
+ if (verificationRequests.length === 0) return null;
+
+ return (
+ <>
+ {verificationRequests.map((req) => {
+ const key = req.task_id ?? req.workflow_run_id ?? "";
+ return <VerificationCodeHandler key={key} req={req} />;
+ })}
+ </>
+ );
+}
+
+export { GlobalNotificationListener };
diff --git a/skyvern-frontend/src/components/VerificationCodeBanner.tsx b/skyvern-frontend/src/components/VerificationCodeBanner.tsx
new file mode 100644
index 000000000..bfdcf9077
--- /dev/null
+++ b/skyvern-frontend/src/components/VerificationCodeBanner.tsx
@@ -0,0 +1,114 @@
+import { useState } from "react";
+import { LockClosedIcon, ClockIcon } from "@radix-ui/react-icons";
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogTitle,
+ DialogDescription,
+} from "@/components/ui/dialog";
+import { PushTotpCodeForm } from "@/components/PushTotpCodeForm";
+import { formatTimeRemaining } from "@/util/timeFormat";
+import { useVerificationCodeAlert } from "@/hooks/useVerificationCodeAlert";
+
+type VerificationCodeBannerProps = {
+ isWaitingForCode: boolean;
+ pollingStartedAt: string | null | undefined;
+ label: string;
+ notificationTag: string;
+ navigateUrl?: string;
+ defaultIdentifier: string | null | undefined;
+ defaultWorkflowRunId?: string | null;
+ defaultWorkflowId?: string | null;
+ defaultTaskId?: string | null;
+ onCodeSent?: () => void;
+};
+
+function VerificationCodeBanner({
+ isWaitingForCode,
+ pollingStartedAt,
+ label,
+ notificationTag,
+ navigateUrl,
+ defaultIdentifier,
+ defaultWorkflowRunId,
+ defaultWorkflowId,
+ defaultTaskId,
+ onCodeSent,
+}: VerificationCodeBannerProps) {
+ const [dialogOpen, setDialogOpen] = useState(false);
+ const { timeRemaining, isTimeCritical, isTimedOut } =
+ useVerificationCodeAlert({
+ isWaitingForCode,
+ pollingStartedAt,
+ label,
+ notificationTag,
+ navigateUrl,
+ });
+
+ if (!isWaitingForCode) return null;
+
+ const handleSuccess = () => {
+ setDialogOpen(false);
+ onCodeSent?.();
+ };
+
+ return (
+ <>
+ {/* Slim persistent banner — Figma Option C */}
+ <div className="flex items-center justify-between border-b border-amber-500/30 bg-amber-500/10 px-4 py-2.5">
+ <div className="flex min-w-0 flex-1 items-center gap-2">
+ <LockClosedIcon className="h-3.5 w-3.5 flex-shrink-0 text-amber-400" />
+ <p className="truncate text-xs text-slate-200">
+ <span className="text-slate-100">{label}</span> needs 2FA
+ </p>
+ {timeRemaining !== null && (
+ <span
+ className={`ml-2 flex items-center gap-1 text-xs font-medium ${
+ isTimeCritical ? "text-red-300" : "text-slate-400"
+ }`}
+ >
+ <ClockIcon className="h-3 w-3" />
+ {formatTimeRemaining(timeRemaining)}
+ </span>
+ )}
+ </div>
+ <div className="flex flex-shrink-0 items-center gap-2">
+ {isTimedOut && (
+ <span className="text-xs text-red-300">Timed out</span>
+ )}
+ <button
+ type="button"
+ onClick={() => setDialogOpen(true)}
+ className="rounded bg-amber-500/20 px-2 py-1 text-xs font-medium text-amber-400 transition-colors hover:bg-amber-500/30"
+ >
+ Enter Code
+ </button>
+ </div>
+ </div>
+
+ {/* Dialog with PushTotpCodeForm */}
+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Enter 2FA Verification Code</DialogTitle>
+ <DialogDescription>
+ Enter the code you received (6-digit code or magic link URL) to
+ continue.
+ </DialogDescription>
+ </DialogHeader>
+ <PushTotpCodeForm
+ defaultIdentifier={defaultIdentifier}
+ defaultWorkflowRunId={defaultWorkflowRunId}
+ defaultWorkflowId={defaultWorkflowId}
+ defaultTaskId={defaultTaskId}
+ showAdvancedFields={false}
+ onSuccess={handleSuccess}
+ />
+ </DialogContent>
+ </Dialog>
+ </>
+ );
+}
+
+export { VerificationCodeBanner };
diff --git a/skyvern-frontend/src/components/VerificationToast.tsx b/skyvern-frontend/src/components/VerificationToast.tsx
new file mode 100644
index 000000000..dee0658b3
--- /dev/null
+++ b/skyvern-frontend/src/components/VerificationToast.tsx
@@ -0,0 +1,32 @@
+import { LockClosedIcon, ExternalLinkIcon } from "@radix-ui/react-icons";
+import { Link } from "react-router-dom";
+
+type ToastContentProps = {
+ label: string;
+ navigateUrl?: string;
+};
+
+function VerificationToastContent({ label, navigateUrl }: ToastContentProps) {
+ return (
+ <div className="space-y-2">
+ <div className="flex items-start gap-2 font-medium">
+ <LockClosedIcon className="mt-0.5 h-4 w-4 flex-shrink-0 text-warning" />
+ <span>2FA Code Required</span>
+ </div>
+ <p className="text-muted-foreground">
+ {label} needs verification to continue.
+ </p>
+ {navigateUrl && (
+ <Link
+ to={navigateUrl}
+ className="inline-flex items-center gap-1 text-xs text-blue-400 hover:text-blue-300"
+ >
+ Go to workflow
+ <ExternalLinkIcon className="h-3 w-3" />
+ </Link>
+ )}
+ </div>
+ );
+}
+
+export { VerificationToastContent };
diff --git a/skyvern-frontend/src/components/ui/use-toast.ts b/skyvern-frontend/src/components/ui/use-toast.ts
index 5a03b78a0..ed6a594d1 100644
--- a/skyvern-frontend/src/components/ui/use-toast.ts
+++ b/skyvern-frontend/src/components/ui/use-toast.ts
@@ -6,7 +6,7 @@ import type { ToastActionElement, ToastProps } from "@/components/ui/toast";
const TOAST_LIMIT = 1;
const TOAST_REMOVE_DELAY = 1000000;
-type ToasterToast = ToastProps & {
+type ToasterToast = Omit<ToastProps, "title"> & {
id: string;
title?: React.ReactNode;
description?: React.ReactNode;
diff --git a/skyvern-frontend/src/hooks/useNotificationStream.ts b/skyvern-frontend/src/hooks/useNotificationStream.ts
new file mode 100644
index 000000000..764ee8cf2
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useNotificationStream.ts
@@ -0,0 +1,153 @@
+import { useEffect, useRef, useState } from "react";
+import { useCredentialGetter } from "@/hooks/useCredentialGetter";
+import { getRuntimeApiKey, newWssBaseUrl } from "@/util/env";
+
+export type VerificationRequest = {
+ type: "verification_code";
+ task_id?: string;
+ workflow_run_id?: string;
+ identifier?: string | null;
+ polling_started_at?: string | null;
+};
+
+// Aliased for future-proofing if more event types are added
+export type NotificationEvent = VerificationRequest;
+
+type NotificationMessage = Omit<NotificationEvent, "type"> & {
+ type: string;
+};
+
+const getRequestKey = (msg: Partial<NotificationMessage>) =>
+ msg.task_id ?? msg.workflow_run_id ?? "";
+
+export function useNotificationStream() {
+ // Use a Record (object) instead of a Map for easier immutable state updates
+ const [events, setEvents] = useState<Record<string, NotificationEvent>>({});
+
+ const credentialGetter = useCredentialGetter();
+ const socketRef = useRef<WebSocket | null>(null);
+ const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const reconnectDelayRef = useRef<number>(3000);
+ const authFailedRef = useRef<boolean>(false);
+
+ useEffect(() => {
+ let isCancelled = false;
+
+ const connect = async () => {
+ // Prevent connecting if tab is hidden, auth failed, or unmounted
+ if (isCancelled || authFailedRef.current || document.hidden) return;
+
+ // Flatten authorization query building
+ let authQuery = "";
+ if (credentialGetter) {
+ authQuery = `?token=Bearer ${await credentialGetter()}`;
+ } else if (getRuntimeApiKey()) {
+ authQuery = `?apikey=${getRuntimeApiKey()}`;
+ }
+
+ if (!authQuery || isCancelled) return;
+
+ // Clean up existing socket before opening a new one
+ socketRef.current?.close();
+
+ const socket = new WebSocket(
+ `${newWssBaseUrl}/stream/notifications${authQuery}`,
+ );
+ socketRef.current = socket;
+ let connectionOpened = false;
+
+ // Use direct event handlers (onopen) instead of addEventListener for readability
+ socket.onopen = () => {
+ connectionOpened = true;
+ reconnectDelayRef.current = 3000; // Reset backoff on success
+ };
+
+ socket.onmessage = ({ data }) => {
+ try {
+ const msg: NotificationMessage = JSON.parse(data);
+ if (["heartbeat", "timeout"].includes(msg.type)) return;
+
+ const key = getRequestKey(msg);
+ if (!key) return;
+
+ setEvents((prev) => {
+ const next = { ...prev }; // Easier to mutate a shallow copy than a Map
+
+ if (msg.type === "verification_code_required") {
+ next[key] = {
+ type: "verification_code",
+ task_id: msg.task_id,
+ workflow_run_id: msg.workflow_run_id,
+ identifier: msg.identifier,
+ polling_started_at: msg.polling_started_at,
+ };
+ } else if (msg.type === "verification_code_resolved") {
+ delete next[key];
+ }
+ return next;
+ });
+ } catch {
+ // Ignore malformed JSON
+ }
+ };
+
+ socket.onclose = (event) => {
+ if (socketRef.current !== socket || isCancelled) return;
+
+ const isAuthFailure =
+ event.code === 1002 || (!connectionOpened && event.code === 1006);
+
+ if (isAuthFailure) {
+ console.warn("WebSocket auth failed. Stopping reconnects.", {
+ code: event.code,
+ });
+ authFailedRef.current = true;
+ return;
+ }
+
+ // Exponential backoff for normal disconnections
+ reconnectTimerRef.current = setTimeout(
+ connect,
+ reconnectDelayRef.current,
+ );
+ reconnectDelayRef.current = Math.min(
+ reconnectDelayRef.current * 2,
+ 30000,
+ );
+ };
+
+ socket.onerror = () => {
+ if (socketRef.current === socket) socket.close();
+ };
+ };
+
+ const handleVisibilityChange = () => {
+ if (document.hidden) {
+ if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
+ socketRef.current?.close();
+ socketRef.current = null;
+ } else {
+ reconnectDelayRef.current = 3000;
+ connect();
+ }
+ };
+
+ document.addEventListener("visibilitychange", handleVisibilityChange);
+ connect();
+
+ return () => {
+ isCancelled = true;
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
+ if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
+ socketRef.current?.close();
+ };
+ }, [credentialGetter]);
+
+ // Derive final arrays from the object state
+ const eventList = Object.values(events);
+ const verificationRequests = eventList.filter(
+ (e): e is VerificationRequest => e.type === "verification_code",
+ );
+
+ return { events: eventList, verificationRequests };
+}
diff --git a/skyvern-frontend/src/hooks/useVerificationCodeAlert.test.ts b/skyvern-frontend/src/hooks/useVerificationCodeAlert.test.ts
new file mode 100644
index 000000000..66bea148c
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useVerificationCodeAlert.test.ts
@@ -0,0 +1,24 @@
+import { describe, it, expect } from "vitest";
+import { formatTimeRemaining } from "@/util/timeFormat";
+
+describe("formatTimeRemaining", () => {
+ it("formats 0 seconds as 0:00", () => {
+ expect(formatTimeRemaining(0)).toBe("0:00");
+ });
+
+ it("formats negative seconds as 0:00", () => {
+ expect(formatTimeRemaining(-5)).toBe("0:00");
+ });
+
+ it("formats 65 seconds as 1:05", () => {
+ expect(formatTimeRemaining(65)).toBe("1:05");
+ });
+
+ it("formats 600 seconds as 10:00", () => {
+ expect(formatTimeRemaining(600)).toBe("10:00");
+ });
+
+ it("formats 59 seconds as 0:59", () => {
+ expect(formatTimeRemaining(59)).toBe("0:59");
+ });
+});
diff --git a/skyvern-frontend/src/hooks/useVerificationCodeAlert.ts b/skyvern-frontend/src/hooks/useVerificationCodeAlert.ts
new file mode 100644
index 000000000..66d41c94c
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useVerificationCodeAlert.ts
@@ -0,0 +1,123 @@
+import { useState, useEffect, useRef, createElement } from "react";
+import { toast } from "@/components/ui/use-toast";
+import { VerificationToastContent } from "@/components/VerificationToast";
+import { enable2faNotifications } from "@/util/env";
+
+/** How long (minutes) before we consider the 2FA request timed out */
+const VERIFICATION_TIMEOUT_MINS = 15;
+/** Seconds remaining at which the countdown turns "critical" (red) */
+const CRITICAL_TIME_THRESHOLD_SEC = 60;
+/** How long the in-app toast stays visible (ms) */
+const TOAST_AUTO_DISMISS_MS = 15_000;
+/** Timer tick interval (ms) */
+const TIMER_TICK_MS = 1_000;
+
+// Module-level set to track which notification tags have already fired,
+// preventing re-notification when navigating to a workflow page that
+// remounts the hook while isWaitingForCode is still true.
+const notifiedTags = new Set<string>();
+
+type UseVerificationCodeAlertOptions = {
+ isWaitingForCode: boolean;
+ pollingStartedAt: string | null | undefined;
+ label: string;
+ notificationTag: string;
+ navigateUrl?: string;
+};
+
+type UseVerificationCodeAlertReturn = {
+ timeRemaining: number | null;
+ isTimeCritical: boolean;
+ isTimedOut: boolean;
+};
+
+function useVerificationCodeAlert({
+ isWaitingForCode,
+ pollingStartedAt,
+ label,
+ notificationTag,
+ navigateUrl,
+}: UseVerificationCodeAlertOptions): UseVerificationCodeAlertReturn {
+ const [timeRemaining, setTimeRemaining] = useState<number | null>(null);
+ const toastDismissRef = useRef<(() => void) | null>(null);
+
+ // Countdown timer — reset when waiting state changes
+ useEffect(() => {
+ if (!isWaitingForCode || !pollingStartedAt) {
+ setTimeRemaining(null);
+ if (!isWaitingForCode) {
+ notifiedTags.delete(notificationTag);
+ }
+ // Dismiss toast immediately when no longer waiting for code
+ toastDismissRef.current?.();
+ toastDismissRef.current = null;
+ return;
+ }
+
+ const startTime = new Date(pollingStartedAt).getTime();
+ const timeoutMs = VERIFICATION_TIMEOUT_MINS * 60 * TIMER_TICK_MS;
+
+ const updateTimer = () => {
+ const now = Date.now();
+ const elapsed = now - startTime;
+ const remaining = Math.max(0, Math.ceil((timeoutMs - elapsed) / 1000));
+ setTimeRemaining(remaining);
+ };
+
+ updateTimer();
+ const interval = setInterval(updateTimer, TIMER_TICK_MS);
+ return () => clearInterval(interval);
+ }, [isWaitingForCode, pollingStartedAt, notificationTag]);
+
+ // Browser notification + in-app toast (fire once per waiting transition)
+ useEffect(() => {
+ if (!enable2faNotifications) return;
+ if (!isWaitingForCode || notifiedTags.has(notificationTag)) return;
+ notifiedTags.add(notificationTag);
+
+ // OS-level browser notification
+ if (typeof Notification !== "undefined") {
+ if (Notification.permission === "default") {
+ Notification.requestPermission();
+ }
+ if (Notification.permission === "granted") {
+ try {
+ const notification = new Notification("2FA Code Required", {
+ body: `${label} needs a verification code to continue.`,
+ icon: "/favicon.png",
+ tag: notificationTag,
+ requireInteraction: true,
+ });
+ notification.onclick = () => {
+ window.focus();
+ notification.close();
+ };
+ } catch (e) {
+ console.error("Failed to create notification:", e);
+ }
+ }
+ }
+
+ // In-app toast — uses VerificationToastContent for clean JSX rendering
+ const result = toast({
+ variant: "default",
+ className: "border-warning/50",
+ duration: TOAST_AUTO_DISMISS_MS,
+ description: createElement(VerificationToastContent, {
+ label,
+ navigateUrl,
+ }),
+ });
+
+ toastDismissRef.current = result.dismiss;
+ }, [isWaitingForCode, label, notificationTag, navigateUrl]);
+
+ const isTimeCritical =
+ timeRemaining !== null && timeRemaining <= CRITICAL_TIME_THRESHOLD_SEC;
+ const isTimedOut = timeRemaining !== null && timeRemaining <= 0;
+
+ return { timeRemaining, isTimeCritical, isTimedOut };
+}
+
+export { useVerificationCodeAlert };
+export type { UseVerificationCodeAlertOptions, UseVerificationCodeAlertReturn };
diff --git a/skyvern-frontend/src/index.css b/skyvern-frontend/src/index.css
index 0cf3cabad..30adce7e0 100644
--- a/skyvern-frontend/src/index.css
+++ b/skyvern-frontend/src/index.css
@@ -31,6 +31,9 @@
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
+ --warning: 32.1 94.6% 43.7%; /* amber-600 */
+ --warning-foreground: 36 100% 97.1%; /* amber-50 */
+
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
diff --git a/skyvern-frontend/src/routes/root/RootLayout.tsx b/skyvern-frontend/src/routes/root/RootLayout.tsx
index 33bfffa52..d97a14518 100644
--- a/skyvern-frontend/src/routes/root/RootLayout.tsx
+++ b/skyvern-frontend/src/routes/root/RootLayout.tsx
@@ -5,6 +5,7 @@ import { Outlet } from "react-router-dom";
import { Header } from "./Header";
import { Sidebar } from "./Sidebar";
import { useDebugStore } from "@/store/useDebugStore";
+import { GlobalNotificationListener } from "@/components/GlobalNotificationListener";
import { SelfHealApiKeyBanner } from "@/components/SelfHealApiKeyBanner";
function RootLayout() {
@@ -24,6 +25,7 @@ function RootLayout() {
<div className="h-full w-full">
<div className={horizontalPadding}>
<SelfHealApiKeyBanner />
+ <GlobalNotificationListener />
</div>
<Header />
<main
diff --git a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx
index 492075721..538b933e6 100644
--- a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx
+++ b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx
@@ -41,6 +41,7 @@ import { MAX_STEPS_DEFAULT } from "../constants";
import { useTaskQuery } from "./hooks/useTaskQuery";
import { useFirstParam } from "@/hooks/useFirstParam";
import * as env from "@/util/env";
+import { TaskRunVerificationCodeForm } from "./TaskRunVerificationCodeForm";
function createTaskRequestObject(values: TaskApiResponse) {
return {
@@ -321,6 +322,8 @@ function TaskDetails() {
)}
</div>
</header>
+ {/* 2FA Verification Code Form - shown when task is waiting for a code */}
+ <TaskRunVerificationCodeForm />
{taskIsLoading ? (
<Skeleton className="h-32 w-full" />
diff --git a/skyvern-frontend/src/routes/tasks/detail/TaskRunVerificationCodeForm.tsx b/skyvern-frontend/src/routes/tasks/detail/TaskRunVerificationCodeForm.tsx
new file mode 100644
index 000000000..fce4fb776
--- /dev/null
+++ b/skyvern-frontend/src/routes/tasks/detail/TaskRunVerificationCodeForm.tsx
@@ -0,0 +1,32 @@
+import { VerificationCodeBanner } from "@/components/VerificationCodeBanner";
+import { statusIsFinalized } from "@/routes/tasks/types";
+import { useTaskQuery } from "./hooks/useTaskQuery";
+import { useQueryClient } from "@tanstack/react-query";
+import { useFirstParam } from "@/hooks/useFirstParam";
+
+function TaskRunVerificationCodeForm() {
+ const queryClient = useQueryClient();
+ const taskId = useFirstParam("taskId", "runId");
+ const { data: task } = useTaskQuery({ id: taskId ?? undefined });
+
+ const isTaskFinalized = task ? statusIsFinalized(task) : false;
+ const isWaitingForCode =
+ !isTaskFinalized && (task?.waiting_for_verification_code ?? false);
+
+ const navigateUrl = taskId ? `/tasks/${taskId}` : undefined;
+
+ return (
+ <VerificationCodeBanner
+ isWaitingForCode={isWaitingForCode}
+ pollingStartedAt={task?.verification_code_polling_started_at ?? null}
+ label={`Task "${taskId}"`}
+ notificationTag={`2fa-required-${taskId}`}
+ navigateUrl={navigateUrl}
+ defaultIdentifier={task?.verification_code_identifier ?? null}
+ defaultTaskId={taskId}
+ onCodeSent={() => queryClient.invalidateQueries({ queryKey: ["task"] })}
+ />
+ );
+}
+
+export { TaskRunVerificationCodeForm };
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
index baa6fe09c..40c2e4f90 100644
--- a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
+++ b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
@@ -51,6 +51,7 @@ import { useBlockScriptsQuery } from "@/routes/workflows/hooks/useBlockScriptsQu
import { constructCacheKeyValue } from "@/routes/workflows/editor/utils";
import { useCacheKeyValuesQuery } from "@/routes/workflows/hooks/useCacheKeyValuesQuery";
import { WorkflowRunStatusAlert } from "@/routes/workflows/workflowRun/WorkflowRunStatusAlert";
+import { WorkflowRunVerificationCodeForm } from "@/routes/workflows/workflowRun/WorkflowRunVerificationCodeForm";
function WorkflowRun() {
const [searchParams, setSearchParams] = useSearchParams();
@@ -448,6 +449,8 @@ function WorkflowRun() {
</div>
</header>
)}
+ {/* 2FA Verification Code Form - shown when workflow is waiting for a code */}
+ <WorkflowRunVerificationCodeForm />
{showOutputSection && (
<div
className={cn("grid gap-4 rounded-lg bg-slate-elevation1 p-4", {
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunVerificationCodeForm.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunVerificationCodeForm.tsx
new file mode 100644
index 000000000..a0ac8fccce6
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunVerificationCodeForm.tsx
@@ -0,0 +1,38 @@
+import { VerificationCodeBanner } from "@/components/VerificationCodeBanner";
+import { statusIsFinalized } from "@/routes/tasks/types";
+import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";
+import { useQueryClient } from "@tanstack/react-query";
+
+function WorkflowRunVerificationCodeForm() {
+ const queryClient = useQueryClient();
+ const { data: workflowRun } = useWorkflowRunWithWorkflowQuery();
+
+ const isRunFinalized = workflowRun ? statusIsFinalized(workflowRun) : false;
+ const isWaitingForCode =
+ !isRunFinalized && (workflowRun?.waiting_for_verification_code ?? false);
+
+ const navigateUrl =
+ workflowRun?.workflow?.workflow_permanent_id && workflowRun?.workflow_run_id
+ ? `/workflows/${workflowRun.workflow.workflow_permanent_id}/${workflowRun.workflow_run_id}`
+ : undefined;
+
+ return (
+ <VerificationCodeBanner
+ isWaitingForCode={isWaitingForCode}
+ pollingStartedAt={
+ workflowRun?.verification_code_polling_started_at ?? null
+ }
+ label={`Workflow "${workflowRun?.workflow?.title ?? "Run"}"`}
+ notificationTag={`2fa-required-${workflowRun?.workflow_run_id}`}
+ navigateUrl={navigateUrl}
+ defaultIdentifier={workflowRun?.verification_code_identifier ?? null}
+ defaultWorkflowRunId={workflowRun?.workflow_run_id}
+ defaultWorkflowId={workflowRun?.workflow?.workflow_permanent_id}
+ onCodeSent={() =>
+ queryClient.invalidateQueries({ queryKey: ["workflowRun"] })
+ }
+ />
+ );
+}
+
+export { WorkflowRunVerificationCodeForm };
diff --git a/skyvern-frontend/src/util/env.ts b/skyvern-frontend/src/util/env.ts
index 6170b31e6..dbcfb1da0 100644
--- a/skyvern-frontend/src/util/env.ts
+++ b/skyvern-frontend/src/util/env.ts
@@ -96,6 +96,9 @@ function clearRuntimeApiKey(): void {
const useNewRunsUrl = true as const;
+const enable2faNotifications =
+ import.meta.env.VITE_ENABLE_2FA_NOTIFICATIONS?.toLowerCase() === "true";
+
export {
apiBaseUrl,
runsApiBaseUrl,
@@ -109,4 +112,5 @@ export {
persistRuntimeApiKey,
clearRuntimeApiKey,
useNewRunsUrl,
+ enable2faNotifications,
};
diff --git a/skyvern-frontend/src/util/timeFormat.ts b/skyvern-frontend/src/util/timeFormat.ts
index 62a574607..ac2ce53c1 100644
--- a/skyvern-frontend/src/util/timeFormat.ts
+++ b/skyvern-frontend/src/util/timeFormat.ts
@@ -67,9 +67,17 @@ function localTimeFormatWithShortDate(time: string): string {
return `${dateString} at ${timeString}`;
}
+function formatTimeRemaining(seconds: number): string {
+ if (seconds <= 0) return "0:00";
+ const mins = Math.floor(seconds / 60);
+ const secs = seconds % 60;
+ return `${mins}:${secs.toString().padStart(2, "0")}`;
+}
+
export {
basicLocalTimeFormat,
basicTimeFormat,
timeFormatWithShortDate,
localTimeFormatWithShortDate,
+ formatTimeRemaining,
};