Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-9578): swap ScrollableActionList + add view-mode toggle behind flag (#6008)
Celal Zamanoğlu46be557be088
diff --git a/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.test.tsx b/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.test.tsxnew file mode 100644index 000000000..49fbba6e4--- /dev/null+++ b/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.test.tsx@@ -0,0 +1,92 @@+// @vitest-environment jsdom++import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import { type ActionsApiResponse, Status } from "@/api/types";+import { ActionCardCompact } from "./ActionCardCompact";++function buildAction(+ overrides: Partial<ActionsApiResponse> = {},+): ActionsApiResponse {+ return {+ action_id: "act_1",+ action_type: "click",+ status: Status.Completed,+ task_id: "task_1",+ step_id: "step_1",+ step_order: 0,+ action_order: 0,+ confidence_float: 0.87,+ description: null,+ reasoning: "Click the submit button",+ intention: null,+ response: null,+ created_by: null,+ text: null,+ ...overrides,+ };+}++afterEach(() => {+ cleanup();+});++describe("ActionCardCompact", () => {+ it("renders the action type label and reasoning preview", () => {+ render(+ <ActionCardCompact+ action={buildAction()}+ index={3}+ active={false}+ expanded={false}+ onSelect={() => {}}+ onToggleExpanded={() => {}}+ />,+ );++ expect(screen.getByText("Click")).toBeDefined();+ expect(screen.getByText("#3")).toBeDefined();+ expect(screen.getByText("Click the submit button")).toBeDefined();+ });++ it("fires onToggleExpanded when the chevron is clicked and does not fire onSelect", () => {+ const onSelect = vi.fn();+ const onToggleExpanded = vi.fn();+ render(+ <ActionCardCompact+ action={buildAction()}+ index={1}+ active={false}+ expanded={false}+ onSelect={onSelect}+ onToggleExpanded={onToggleExpanded}+ />,+ );++ fireEvent.click(screen.getByRole("button", { name: /expand details/i }));++ expect(onToggleExpanded).toHaveBeenCalledTimes(1);+ expect(onSelect).not.toHaveBeenCalled();+ });++ it("fires onSelect when the row body is clicked", () => {+ const onSelect = vi.fn();+ const onToggleExpanded = vi.fn();+ render(+ <ActionCardCompact+ action={buildAction()}+ index={1}+ active={false}+ expanded={false}+ onSelect={onSelect}+ onToggleExpanded={onToggleExpanded}+ />,+ );++ fireEvent.click(screen.getByText("Click"));++ expect(onSelect).toHaveBeenCalledTimes(1);+ expect(onToggleExpanded).not.toHaveBeenCalled();+ });+});diff --git a/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.tsx b/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.tsxnew file mode 100644index 000000000..68c1299f4--- /dev/null+++ b/skyvern-frontend/src/routes/tasks/detail/ActionCardCompact.tsx@@ -0,0 +1,186 @@+import {+ type ActionsApiResponse,+ type ActionType,+ ActionTypes,+ ReadableActionTypes,+ Status,+} from "@/api/types";+import { Collapsible, CollapsibleContent } from "@/components/ui/collapsible";+import {+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from "@/components/ui/tooltip";+import { cn } from "@/util/utils";+import {+ ChevronDownIcon,+ ChevronRightIcon,+ CursorArrowIcon,+ DownloadIcon,+ HandIcon,+ InputIcon,+ LightningBoltIcon,+} from "@radix-ui/react-icons";++const actionIcons: Partial<Record<ActionType, React.ReactNode>> = {+ click: <CursorArrowIcon className="h-4 w-4" />,+ hover: <HandIcon className="h-4 w-4" />,+ input_text: <InputIcon className="h-4 w-4" />,+ download_file: <DownloadIcon className="h-4 w-4" />,+};++type Props = {+ action: ActionsApiResponse;+ index: number;+ active: boolean;+ expanded: boolean;+ onSelect: () => void;+ onToggleExpanded: () => void;+ cardClassName?: string;+};++function ActionCardCompact({+ action,+ index,+ active,+ expanded,+ onSelect,+ onToggleExpanded,+ cardClassName,+}: Props) {+ // Wait actions always succeed — they intentionally return ActionFailure+ // from the backend but completing a wait is expected, not a failure.+ const success =+ action.action_type === ActionTypes.wait ||+ action.status === Status.Completed ||+ action.status === Status.Skipped;++ const reasoningPreview = action.reasoning?.trim() ?? "";+ const fromScript = action.created_by === "script";+ const icon = actionIcons[action.action_type] ?? null;+ const label = ReadableActionTypes[action.action_type];+ const confidencePct =+ action.confidence_float != null+ ? Math.round(action.confidence_float * 100)+ : null;+ const inputValue =+ action.action_type === ActionTypes.InputText+ ? (action.text ?? action.response)+ : null;++ return (+ <Collapsible open={expanded} asChild>+ <div+ data-slot="action-card-compact"+ data-active={active ? "true" : "false"}+ data-status={success ? "success" : "failure"}+ className={cn(+ "group rounded-md border-l-2 bg-slate-elevation4 ring-1 ring-transparent transition-all duration-200",+ {+ "border-l-success": success && !active,+ "border-l-destructive": !success && !active,+ "border-l-transparent ring-2 ring-white/55 hover:ring-white/55":+ active,+ "hover:ring-white/25": !active,+ },+ cardClassName,+ )}+ >+ <div className="flex items-center">+ <button+ type="button"+ onClick={onSelect}+ className="flex min-h-[36px] flex-1 cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-left outline-none focus-visible:ring-1 focus-visible:ring-white/40"+ >+ <span+ aria-hidden="true"+ className={cn("h-2 w-2 shrink-0 rounded-full", {+ "bg-success": success,+ "bg-destructive": !success,+ })}+ />+ <span className="shrink-0 text-xs tabular-nums text-slate-500">+ #{index}+ </span>+ {icon && (+ <span className="shrink-0 text-slate-300" aria-hidden="true">+ {icon}+ </span>+ )}+ <span className="shrink-0 text-xs font-semibold text-slate-200">+ {label}+ </span>+ {reasoningPreview.length > 0 && (+ <span className="min-w-0 flex-1 truncate text-xs text-slate-400">+ {reasoningPreview}+ </span>+ )}+ {reasoningPreview.length === 0 && <span className="flex-1" />}+ {fromScript && (+ <TooltipProvider>+ <Tooltip delayDuration={300}>+ <TooltipTrigger asChild>+ <span className="shrink-0" aria-label="Code Execution">+ <LightningBoltIcon className="h-4 w-4 text-[gold]" />+ </span>+ </TooltipTrigger>+ <TooltipContent className="max-w-[250px]">+ Code Execution+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ )}+ </button>+ <button+ type="button"+ aria-label={expanded ? "Collapse details" : "Expand details"}+ aria-expanded={expanded}+ onClick={onToggleExpanded}+ className="mr-2 shrink-0 rounded p-0.5 text-slate-400 outline-none hover:bg-slate-elevation3 hover:text-slate-200 focus-visible:ring-1 focus-visible:ring-white/40"+ >+ {expanded ? (+ <ChevronDownIcon className="h-4 w-4" />+ ) : (+ <ChevronRightIcon className="h-4 w-4" />+ )}+ </button>+ </div>+ <CollapsibleContent className="space-y-2 px-3 pb-3 pt-1 text-xs text-slate-400">+ {action.reasoning && (+ <div className="rounded bg-slate-elevation3 p-2">+ <div className="mb-1 text-[10px] uppercase tracking-wide text-slate-500">+ Reasoning+ </div>+ <div className="whitespace-pre-wrap break-words text-slate-300">+ {action.reasoning}+ </div>+ </div>+ )}+ {inputValue != null && inputValue.length > 0 && (+ <div className="rounded bg-slate-elevation3 p-2">+ <div className="mb-1 text-[10px] uppercase tracking-wide text-slate-500">+ Input+ </div>+ <div className="whitespace-pre-wrap break-words font-mono text-slate-300">+ {inputValue}+ </div>+ </div>+ )}+ {confidencePct != null && (+ <div className="flex items-center gap-2">+ <span className="text-[10px] uppercase tracking-wide text-slate-500">+ Confidence+ </span>+ <span className="tabular-nums text-slate-300">+ {confidencePct}%+ </span>+ </div>+ )}+ </CollapsibleContent>+ </div>+ </Collapsible>+ );+}++export { ActionCardCompact };diff --git a/skyvern-frontend/src/routes/tasks/detail/RunViewingModeToggle.tsx b/skyvern-frontend/src/routes/tasks/detail/RunViewingModeToggle.tsxnew file mode 100644index 000000000..9bf425ffc--- /dev/null+++ b/skyvern-frontend/src/routes/tasks/detail/RunViewingModeToggle.tsx@@ -0,0 +1,73 @@+import {+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from "@/components/ui/tooltip";+import { useRunViewingPreferenceStore } from "@/store/RunViewingPreferenceStore";+import { cn } from "@/util/utils";+import { RowsIcon, ViewVerticalIcon } from "@radix-ui/react-icons";++type ModeButtonProps = {+ active: boolean;+ label: string;+ onClick: () => void;+ children: React.ReactNode;+};++function ModeButton({ active, label, onClick, children }: ModeButtonProps) {+ return (+ <Tooltip>+ <TooltipTrigger asChild>+ <button+ type="button"+ aria-label={label}+ aria-pressed={active}+ onClick={onClick}+ className={cn(+ "flex h-6 w-7 items-center justify-center rounded-sm text-slate-400 outline-none transition-colors hover:text-slate-100 focus-visible:ring-1 focus-visible:ring-white/40",+ {+ "bg-slate-600 text-slate-50": active,+ },+ )}+ >+ {children}+ </button>+ </TooltipTrigger>+ <TooltipContent>{label}</TooltipContent>+ </Tooltip>+ );+}++function RunViewingModeToggle() {+ const viewMode = useRunViewingPreferenceStore((s) => s.viewMode);+ const setViewMode = useRunViewingPreferenceStore((s) => s.setViewMode);++ return (+ <TooltipProvider delayDuration={300}>+ <div+ role="group"+ aria-label="Action list view density"+ data-slot="run-viewing-mode-toggle"+ className="flex h-7 items-center gap-0.5 rounded-md border border-slate-700 bg-slate-elevation2 p-0.5"+ >+ <ModeButton+ active={viewMode === "compact"}+ label="Compact view"+ onClick={() => setViewMode("compact")}+ >+ <RowsIcon className="h-3.5 w-3.5" />+ </ModeButton>+ <ModeButton+ active={viewMode === "detailed"}+ label="Detailed view"+ onClick={() => setViewMode("detailed")}+ >+ <ViewVerticalIcon className="h-3.5 w-3.5" />+ </ModeButton>+ </div>+ </TooltipProvider>+ );+}++export { RunViewingModeToggle };diff --git a/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.test.tsx b/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.test.tsxnew file mode 100644index 000000000..e968d6fcd--- /dev/null+++ b/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.test.tsx@@ -0,0 +1,129 @@+// @vitest-environment jsdom++import { cleanup, render, screen } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";++const { storage } = vi.hoisted(() => {+ const storage = new Map<string, string>();+ const localStorageMock = {+ getItem: (key: string) => storage.get(key) ?? null,+ setItem: (key: string, value: string) => {+ storage.set(key, value);+ },+ removeItem: (key: string) => {+ storage.delete(key);+ },+ clear: () => {+ storage.clear();+ },+ key: (index: number) => Array.from(storage.keys())[index] ?? null,+ get length() {+ return storage.size;+ },+ };+ Object.defineProperty(globalThis, "localStorage", {+ value: localStorageMock,+ configurable: true,+ writable: true,+ });+ return { storage };+});++vi.mock("@/api/AxiosClient", () => ({+ getClient: async () => ({+ get: async () => ({ data: null }),+ }),+}));++vi.mock("@/hooks/useCredentialGetter", () => ({+ useCredentialGetter: () => undefined,+}));++const { isViewingV2Mock } = vi.hoisted(() => ({+ isViewingV2Mock: vi.fn(() => false),+}));++vi.mock("@/hooks/useWorkflowRunViewingV2", () => ({+ useWorkflowRunViewingV2: () => isViewingV2Mock(),+}));++import { Action, ActionTypes } from "@/api/types";+import {+ RUN_VIEWING_STORAGE_KEY,+ useRunViewingPreferenceStore,+} from "@/store/RunViewingPreferenceStore";+import { ScrollableActionList } from "./ScrollableActionList";++function buildAction(overrides: Partial<Action> = {}): Action {+ return {+ reasoning: "Click the submit button",+ confidence: 0.9,+ type: ActionTypes.Click,+ input: "",+ success: true,+ stepId: "step_1",+ index: 0,+ created_by: null,+ screenshotArtifactId: null,+ ...overrides,+ };+}++function renderList(extraProps?: { activeIndex?: number | "stream" }) {+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ return render(+ <QueryClientProvider client={client}>+ <ScrollableActionList+ data={[buildAction()]}+ activeIndex={extraProps?.activeIndex ?? 0}+ onActiveIndexChange={() => {}}+ showStreamOption={false}+ taskDetails={{ actions: 1, steps: 1 }}+ />+ </QueryClientProvider>,+ );+}++beforeEach(() => {+ storage.clear();+ useRunViewingPreferenceStore.setState({ viewMode: "compact" }, false);+ isViewingV2Mock.mockReset();+ isViewingV2Mock.mockReturnValue(false);+});++afterEach(() => {+ cleanup();+});++describe("ScrollableActionList view-mode swap", () => {+ it("renders the legacy detailed card when the v2 flag is off", () => {+ renderList();++ expect(screen.queryByLabelText("Compact view")).toBeNull();+ expect(screen.queryByLabelText("Detailed view")).toBeNull();+ expect(+ document.querySelector('[data-slot="action-card-compact"]'),+ ).toBeNull();+ // getByText throws if not found, so reaching this line means it rendered+ screen.getByText("Click the submit button");+ });++ it("renders compact cards and the toggle when v2 flag on + viewMode=compact", () => {+ isViewingV2Mock.mockReturnValue(true);+ useRunViewingPreferenceStore.setState({ viewMode: "compact" }, false);++ renderList();++ // getByLabelText throws if not found+ screen.getByLabelText("Compact view");+ screen.getByLabelText("Detailed view");+ expect(+ document.querySelector('[data-slot="action-card-compact"]'),+ ).not.toBeNull();+ // sanity: persistence path is wired+ expect(RUN_VIEWING_STORAGE_KEY).toBe("skyvern.runViewing");+ });+});diff --git a/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.tsx b/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.tsxindex 500488be2..81329600c 100644--- a/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.tsx+++ b/skyvern-frontend/src/routes/tasks/detail/ScrollableActionList.tsx@@ -1,5 +1,5 @@import { getClient } from "@/api/AxiosClient";-import { Action, ActionTypes } from "@/api/types";+import { Action, ActionsApiResponse, ActionTypes, Status } from "@/api/types";import { StatusPill } from "@/components/ui/status-pill";import {Tooltip,@@ -10,6 +10,8 @@ import {import { ScrollArea, ScrollAreaViewport } from "@/components/ui/scroll-area";import { Separator } from "@/components/ui/separator";import { useCredentialGetter } from "@/hooks/useCredentialGetter";+import { useWorkflowRunViewingV2 } from "@/hooks/useWorkflowRunViewingV2";+import { useRunViewingPreferenceStore } from "@/store/RunViewingPreferenceStore";import { cn } from "@/util/utils";import {CheckCircledIcon,@@ -18,8 +20,33 @@ import {LightningBoltIcon,} from "@radix-ui/react-icons";import { useQueryClient } from "@tanstack/react-query";-import { ReactNode, useRef } from "react";+import { ReactNode, useRef, useState } from "react";+import { ActionCardCompact } from "./ActionCardCompact";import { ActionTypePill } from "./ActionTypePill";+import { RunViewingModeToggle } from "./RunViewingModeToggle";++function toActionsApiResponse(+ action: Action,+ index: number,+): ActionsApiResponse {+ return {+ action_id: `${action.stepId}-${index}`,+ action_type: action.type,+ status: action.success ? Status.Completed : Status.Failed,+ task_id: null,+ step_id: action.stepId,+ step_order: null,+ action_order: index,+ confidence_float: action.confidence ?? null,+ description: null,+ reasoning: action.reasoning,+ intention: null,+ response: null,+ created_by: action.created_by,+ text: action.input ?? null,+ screenshot_artifact_id: action.screenshotArtifactId ?? null,+ };+}type Props = {data: Array<Action | null>;@@ -42,10 +69,27 @@ function ScrollableActionList({}: Props) {const queryClient = useQueryClient();const credentialGetter = useCredentialGetter();+ const isViewingV2 = useWorkflowRunViewingV2();+ const viewMode = useRunViewingPreferenceStore((s) => s.viewMode);+ const [expandedActionId, setExpandedActionId] = useState<string | null>(null);const refs = useRef<Array<HTMLDivElement | null>>(Array.from({ length: data.length + 1 }),);+ const useCompact = isViewingV2 && viewMode === "compact";++ function prefetchStepArtifacts(stepId: string) {+ queryClient.prefetchQuery({+ queryKey: ["step", stepId, "artifacts"],+ queryFn: async () => {+ const client = await getClient(credentialGetter);+ return client+ .get(`/step/${stepId}/artifacts`)+ .then((response) => response.data);+ },+ });+ }+function getReverseActions() {const elements: ReactNode[] = [];for (let i = data.length - 1; i >= 0; i--) {@@ -54,6 +98,34 @@ function ScrollableActionList({continue;}const selected = activeIndex === i;+ if (useCompact) {+ const compactAction = toActionsApiResponse(action, i);+ elements.push(+ <div+ key={i}+ ref={(element) => {+ refs.current[i] = element;+ }}+ onMouseEnter={() => prefetchStepArtifacts(action.stepId)}+ >+ <ActionCardCompact+ action={compactAction}+ index={i + 1}+ active={selected}+ expanded={expandedActionId === compactAction.action_id}+ onSelect={() => onActiveIndexChange(i)}+ onToggleExpanded={() =>+ setExpandedActionId((current) =>+ current === compactAction.action_id+ ? null+ : compactAction.action_id,+ )+ }+ />+ </div>,+ );+ continue;+ }elements.push(<divkey={i}@@ -69,17 +141,7 @@ function ScrollableActionList({},)}onClick={() => onActiveIndexChange(i)}- onMouseEnter={() => {- queryClient.prefetchQuery({- queryKey: ["step", action.stepId, "artifacts"],- queryFn: async () => {- const client = await getClient(credentialGetter);- return client- .get(`/step/${action.stepId}/artifacts`)- .then((response) => response.data);- },- });- }}+ onMouseEnter={() => prefetchStepArtifacts(action.stepId)}><div className="flex-1 space-y-2 p-4 pl-5"><div className="flex justify-between">@@ -135,13 +197,14 @@ function ScrollableActionList({return (<div className="h-[40rem] w-1/3 rounded border bg-slate-elevation1">- <div className="grid grid-cols-2 gap-2 p-4">- <div className="flex h-8 items-center justify-center rounded-sm bg-slate-700 px-3 text-xs text-gray-50">+ <div className="flex items-center gap-2 p-4">+ <div className="flex h-8 flex-1 items-center justify-center rounded-sm bg-slate-700 px-3 text-xs text-gray-50">Actions: {taskDetails.actions}</div>- <div className="flex h-8 items-center justify-center rounded-sm bg-slate-700 px-3 text-xs text-gray-50">+ <div className="flex h-8 flex-1 items-center justify-center rounded-sm bg-slate-700 px-3 text-xs text-gray-50">Steps: {taskDetails.steps}</div>+ {isViewingV2 && <RunViewingModeToggle />}</div><Separator /><ScrollArea className="p-4">@@ -154,7 +217,9 @@ function ScrollableActionList({refs.current[data.length] = element;}}className={cn(- "flex cursor-pointer rounded-lg border-2 bg-slate-elevation3 p-4 hover:border-slate-50",+ useCompact+ ? "flex cursor-pointer items-center gap-2 rounded-md border-2 bg-slate-elevation3 px-3 py-2 text-xs hover:border-slate-50"+ : "flex cursor-pointer rounded-lg border-2 bg-slate-elevation3 p-4 hover:border-slate-50",{"border-slate-50": activeIndex === "stream",},@@ -162,8 +227,15 @@ function ScrollableActionList({onClick={() => onActiveIndexChange("stream")}><div className="flex items-center gap-2">- <DotFilledIcon className="h-6 w-6 text-destructive" />- Live+ <DotFilledIcon+ className={cn(+ "text-destructive",+ useCompact ? "h-3 w-3 animate-pulse" : "h-6 w-6",+ )}+ />+ <span className={cn(useCompact && "text-xs text-slate-200")}>+ Live+ </span></div></div>)}