Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-10837): code-first code block frontend (editor views, highlights, run timeline) (#6604)
Aaron Perez03c9981d9546
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.tsindex 86a86dca2..bf8988eb3 100644--- a/skyvern-frontend/src/api/types.ts+++ b/skyvern-frontend/src/api/types.ts@@ -696,6 +696,11 @@ export type ActionsApiResponse = {created_by: string | null;text: string | null;screenshot_artifact_id?: string | null;+ // Code block recorded actions carry code_line and duration_ms here.+ output?:+ | { code_line?: number | null; duration_ms?: number | null }+ | Record<string, unknown>+ | null;};export type TaskV2 = {diff --git a/skyvern-frontend/src/routes/workflows/components/actionTypeIcons.tsx b/skyvern-frontend/src/routes/workflows/components/actionTypeIcons.tsxnew file mode 100644index 000000000..0afef22d8--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/components/actionTypeIcons.tsx@@ -0,0 +1,66 @@+import {+ CheckCircledIcon,+ CrossCircledIcon,+ CursorArrowIcon,+ Cross2Icon,+ DotFilledIcon,+ DoubleArrowDownIcon,+ DropdownMenuIcon,+ FileTextIcon,+ HandIcon,+ InputIcon,+ KeyboardIcon,+ MagicWandIcon,+ ReloadIcon,+} from "@radix-ui/react-icons";+import type { ReactNode } from "react";++import { type ActionType, ActionTypes } from "@/api/types";++import { WorkflowBlockIcon } from "../editor/nodes/WorkflowBlockIcon";++export const actionTypeIcons: Record<ActionType, ReactNode> = {+ [ActionTypes.Click]: (+ <WorkflowBlockIcon workflowBlockType="action" className="size-3.5" />+ ),+ [ActionTypes.Hover]: <HandIcon className="size-3.5" />,+ [ActionTypes.InputText]: <InputIcon className="size-3.5" />,+ [ActionTypes.DownloadFile]: (+ <WorkflowBlockIcon workflowBlockType="file_download" className="size-3.5" />+ ),+ [ActionTypes.UploadFile]: (+ <WorkflowBlockIcon workflowBlockType="file_upload" className="size-3.5" />+ ),+ [ActionTypes.SelectOption]: <DropdownMenuIcon className="size-3.5" />,+ [ActionTypes.complete]: <CheckCircledIcon className="size-3.5" />,+ [ActionTypes.wait]: (+ <WorkflowBlockIcon workflowBlockType="wait" className="size-3.5" />+ ),+ [ActionTypes.terminate]: <CrossCircledIcon className="size-3.5" />,+ [ActionTypes.SolveCaptcha]: <MagicWandIcon className="size-3.5" />,+ [ActionTypes.extract]: (+ <WorkflowBlockIcon workflowBlockType="extraction" className="size-3.5" />+ ),+ [ActionTypes.ReloadPage]: <ReloadIcon className="size-3.5" />,+ [ActionTypes.Scroll]: <DoubleArrowDownIcon className="size-3.5" />,+ [ActionTypes.KeyPress]: <KeyboardIcon className="size-3.5" />,+ [ActionTypes.Move]: <CursorArrowIcon className="size-3.5" />,+ [ActionTypes.NullAction]: <FileTextIcon className="size-3.5" />,+ [ActionTypes.VerificationCode]: <KeyboardIcon className="size-3.5" />,+ [ActionTypes.Drag]: <HandIcon className="size-3.5" />,+ [ActionTypes.LeftMouse]: (+ <WorkflowBlockIcon workflowBlockType="action" className="size-3.5" />+ ),+ [ActionTypes.GotoUrl]: (+ <WorkflowBlockIcon workflowBlockType="goto_url" className="size-3.5" />+ ),+ [ActionTypes.ClosePage]: <Cross2Icon className="size-3.5" />,+};++export function getActionTypeIcon(actionType: string): ReactNode {+ return (+ actionTypeIcons[actionType as ActionType] ?? (+ <DotFilledIcon className="size-3.5" />+ )+ );+}diff --git a/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.test.ts b/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.test.tsnew file mode 100644index 000000000..f0c4a1579--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.test.ts@@ -0,0 +1,64 @@+// @vitest-environment jsdom++import { EditorState } from "@codemirror/state";+import { EditorView } from "@codemirror/view";+import { afterEach, describe, expect, test } from "vitest";++import { jinjaHighlight } from "./jinjaHighlight";++let view: EditorView | null = null;++afterEach(() => {+ view?.destroy();+ view = null;+ document.body.innerHTML = "";+});++function renderDoc(doc: string) {+ view = new EditorView({+ state: EditorState.create({ doc, extensions: [jinjaHighlight] }),+ parent: document.body,+ });+ return view;+}++function markedTexts(renderedView: EditorView) {+ return Array.from(+ renderedView.contentDOM.querySelectorAll(".cm-jinja-param"),+ (el) => el.textContent,+ );+}++describe("jinjaHighlight", () => {+ test("marks jinja parameter expressions, including dotted paths", () => {+ const rendered = renderDoc("Open {{ url }} as {{ user.name }}");++ expect(markedTexts(rendered)).toEqual(["{{ url }}", "{{ user.name }}"]);+ });++ test("marks parameters written without inner spacing", () => {+ const rendered = renderDoc("Go to {{url}}");++ expect(markedTexts(rendered)).toEqual(["{{url}}"]);+ });++ test("leaves plain text, single braces, and unclosed braces unmarked", () => {+ const rendered = renderDoc("Open { url } and {{ unclosed");++ expect(markedTexts(rendered)).toEqual([]);+ });++ test("keeps marks in sync as the document changes", () => {+ const rendered = renderDoc("no params yet");++ rendered.dispatch({+ changes: {+ from: 0,+ to: rendered.state.doc.length,+ insert: "now {{ filled }}",+ },+ });++ expect(markedTexts(rendered)).toEqual(["{{ filled }}"]);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.ts b/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.tsnew file mode 100644index 000000000..b1a8553e7--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/components/jinjaHighlight.ts@@ -0,0 +1,37 @@+import {+ Decoration,+ type DecorationSet,+ EditorView,+ MatchDecorator,+ ViewPlugin,+ type ViewUpdate,+} from "@codemirror/view";++const jinjaMatcher = new MatchDecorator({+ regexp: /\{\{\s*[\w.]+\s*\}\}/g,+ decoration: Decoration.mark({ class: "cm-jinja-param" }),+});++const jinjaTheme = EditorView.baseTheme({+ ".cm-jinja-param": {+ color: "#7dd3fc",+ backgroundColor: "rgba(125, 211, 252, 0.12)",+ borderRadius: "3px",+ fontWeight: "600",+ },+});++const jinjaPlugin = ViewPlugin.fromClass(+ class {+ decorations: DecorationSet;+ constructor(view: EditorView) {+ this.decorations = jinjaMatcher.createDeco(view);+ }+ update(update: ViewUpdate) {+ this.decorations = jinjaMatcher.updateDeco(update, this.decorations);+ }+ },+ { decorations: (v) => v.decorations },+);++export const jinjaHighlight = [jinjaPlugin, jinjaTheme];diff --git a/skyvern-frontend/src/routes/workflows/components/lineHighlight.test.ts b/skyvern-frontend/src/routes/workflows/components/lineHighlight.test.tsnew file mode 100644index 000000000..495f5addd--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/components/lineHighlight.test.ts@@ -0,0 +1,68 @@+// @vitest-environment jsdom++import { EditorState } from "@codemirror/state";+import { EditorView } from "@codemirror/view";+import { afterEach, describe, expect, test } from "vitest";++import { lineHighlight } from "./lineHighlight";++let view: EditorView | null = null;++afterEach(() => {+ view?.destroy();+ view = null;+ document.body.innerHTML = "";+});++function renderDoc(doc: string, extension: ReturnType<typeof lineHighlight>) {+ view = new EditorView({+ state: EditorState.create({ doc, extensions: [extension] }),+ parent: document.body,+ });+ return view;+}++function highlightedTexts(rendered: EditorView, className: string) {+ return Array.from(+ rendered.contentDOM.querySelectorAll(`.${className}`),+ (el) => el.textContent,+ );+}++describe("lineHighlight", () => {+ test("paints the requested 1-based inclusive line range as active", () => {+ const rendered = renderDoc(+ "line one\nline two\nline three",+ lineHighlight([{ from: 2, to: 3 }]),+ );++ expect(highlightedTexts(rendered, "cm-line-highlight-active")).toEqual([+ "line two",+ "line three",+ ]);+ });++ test("uses the error variant class for error ranges", () => {+ const rendered = renderDoc(+ "alpha\nbeta\ngamma",+ lineHighlight([{ from: 2, to: 2, variant: "error" }]),+ );++ expect(highlightedTexts(rendered, "cm-line-highlight-error")).toEqual([+ "beta",+ ]);+ });++ test("clamps ranges that fall outside the document", () => {+ const rendered = renderDoc(+ "only line",+ lineHighlight([{ from: 5, to: 9 }]),+ );++ expect(highlightedTexts(rendered, "cm-line-highlight-active")).toEqual([]);+ });++ test("returns no extension for an empty range list", () => {+ expect(lineHighlight([])).toEqual([]);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/components/lineHighlight.ts b/skyvern-frontend/src/routes/workflows/components/lineHighlight.tsnew file mode 100644index 000000000..a0c42f694--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/components/lineHighlight.ts@@ -0,0 +1,61 @@+import { type EditorState, type Range, StateField } from "@codemirror/state";+import { Decoration, type DecorationSet, EditorView } from "@codemirror/view";+import type { Extension } from "@uiw/react-codemirror";++export type LineHighlightRange = {+ from: number;+ to: number;+ variant?: "active" | "error";+};++const activeLineDecoration = Decoration.line({+ class: "cm-line-highlight-active",+});+const errorLineDecoration = Decoration.line({+ class: "cm-line-highlight-error",+});++const lineHighlightTheme = EditorView.baseTheme({+ ".cm-line-highlight-active": {+ backgroundColor: "rgba(125, 211, 252, 0.14)",+ },+ ".cm-line-highlight-error": {+ backgroundColor: "rgba(248, 113, 113, 0.16)",+ },+});++function buildDecorations(+ state: EditorState,+ ranges: Array<LineHighlightRange>,+): DecorationSet {+ const lineCount = state.doc.lines;+ const decorations: Array<Range<Decoration>> = [];+ for (const range of ranges) {+ const start = Math.max(1, Math.min(range.from, range.to));+ const end = Math.min(lineCount, Math.max(range.from, range.to));+ const decoration =+ range.variant === "error" ? errorLineDecoration : activeLineDecoration;+ for (let lineNumber = start; lineNumber <= end; lineNumber++) {+ decorations.push(decoration.range(state.doc.line(lineNumber).from));+ }+ }+ return Decoration.set(decorations, true);+}++export function lineHighlight(ranges: Array<LineHighlightRange>): Extension {+ if (ranges.length === 0) {+ return [];+ }+ const field = StateField.define<DecorationSet>({+ create(state) {+ return buildDecorations(state, ranges);+ },+ update(decorations, transaction) {+ return transaction.docChanged+ ? buildDecorations(transaction.state, ranges)+ : decorations;+ },+ provide: (self) => EditorView.decorations.from(self),+ });+ return [field, lineHighlightTheme];+}diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.queue.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.queue.test.tsxindex fbc499d02..1db6db441 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.queue.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.queue.test.tsx@@ -8,6 +8,8 @@ import {} from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { useCopilotActionStore } from "@/store/useCopilotActionStore";+import type { WorkflowCopilotStreamResponseUpdate } from "./workflowCopilotTypes";// Capture every postStreaming call so a test can assert how many streams@@ -211,6 +213,11 @@ beforeEach(() => {proposed_workflow: null,auto_accept: false,};+ useCopilotActionStore.setState({+ pendingBuild: null,+ generatingBlockLabel: null,+ cancelNonce: 0,+ });});afterEach(() => {@@ -298,6 +305,145 @@ describe("WorkflowCopilotChat — keep the chat live during a turn", () => {expect(screen.getByRole("button", { name: "Cancel run" })).toBeTruthy();});+ it("clears the queued block-build target on cancel so it cannot leak into the next message", async () => {+ await renderChat();+ await submit("first message");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ // Arm a block-level Generate while the turn is in flight: it queues behind+ // the active turn, capturing the target block label in a ref.+ await act(async () => {+ useCopilotActionStore+ .getState()+ .requestBuild({ blockLabel: "open_page", prompt: "open the page" });+ });+ expect(postStreaming).toHaveBeenCalledTimes(1);++ // Cancel the queued block-build before it sends.+ await act(async () => {+ fireEvent.keyDown(window, { key: "Escape" });+ });++ // Finish the original turn and send an unrelated follow-up.+ await completeOldestStream("first done");+ await submit("a normal follow-up");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(2));++ const followUp = streamCalls.find(+ (call) => call.body.message === "a normal follow-up",+ );+ expect(followUp).toBeTruthy();+ expect(+ (followUp!.body as unknown as { target_block_label: string | null })+ .target_block_label,+ ).toBeNull();+ });++ it("keeps the block generating label set while its build waits behind an in-flight turn", async () => {+ await renderChat();+ await submit("first message");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ // Arm a block-level Generate while a turn is in flight: it queues behind it.+ await act(async () => {+ useCopilotActionStore+ .getState()+ .requestBuild({ blockLabel: "open_page", prompt: "open the page" });+ });+ expect(postStreaming).toHaveBeenCalledTimes(1);+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBe(+ "open_page",+ );++ // The unrelated turn ends; the queued block build then drains into its own+ // stream. The generating label must survive both events.+ await completeOldestStream("first done");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(2));+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBe(+ "open_page",+ );+ expect(+ (streamCalls[1]!.body as unknown as { target_block_label: string | null })+ .target_block_label,+ ).toBe("open_page");++ // The label clears only once the block-build turn itself finishes.+ await act(async () => {+ streamCalls[1]!.onMessage(terminalResponse("block rebuilt"));+ streamCalls[1]!.resolve();+ });+ await waitFor(() =>+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBeNull(),+ );+ });++ it("does not arm a block-build target when its generate no-ops behind a queued prompt", async () => {+ await renderChat();+ await submit("first message");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ // Queue a normal follow-up behind the in-flight turn.+ await submit("second message");+ expect(postStreaming).toHaveBeenCalledTimes(1);++ // A block Generate now no-ops (a prompt is already queued); it must neither+ // arm the block target nor leave the block stuck generating.+ await act(async () => {+ useCopilotActionStore+ .getState()+ .requestBuild({ blockLabel: "open_page", prompt: "open the page" });+ });+ await waitFor(() =>+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBeNull(),+ );+ expect(postStreaming).toHaveBeenCalledTimes(1);++ // The queued follow-up drains normally, unscoped to any block.+ await completeOldestStream("first done");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(2));+ const drained = streamCalls.find(+ (call) => call.body.message === "second message",+ );+ expect(drained).toBeTruthy();+ expect(+ (drained!.body as unknown as { target_block_label: string | null })+ .target_block_label,+ ).toBeNull();+ });++ it("drops a queued block build when its Stop is pressed, sparing the active turn", async () => {+ await renderChat();+ await submit("first message");+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ // Arm a block Generate while the turn is in flight: it queues behind it.+ await act(async () => {+ useCopilotActionStore+ .getState()+ .requestBuild({ blockLabel: "open_page", prompt: "open the page" });+ });+ expect(postStreaming).toHaveBeenCalledTimes(1);+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBe(+ "open_page",+ );++ // Press the block's Stop: drop the queued build without cancelling the+ // unrelated in-flight turn.+ await act(async () => {+ useCopilotActionStore.getState().requestCancel();+ });+ expect(useCopilotActionStore.getState().generatingBlockLabel).toBeNull();+ expect(cancelPost).not.toHaveBeenCalledWith(+ "/workflow/copilot/cancel",+ expect.anything(),+ );++ // The original turn completes; the dropped build must not drain into a stream.+ await completeOldestStream("first done");+ await act(async () => {});+ expect(postStreaming).toHaveBeenCalledTimes(1);+ });+it("resets the live narrative when a stream throws without a terminal", async () => {await renderChat();await submit("build me a workflow");diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsxindex 684b955e9..e5b21723c 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx@@ -18,6 +18,7 @@ import {} from "@radix-ui/react-icons";import { stringify as convertToYAML } from "yaml";import { useWorkflowHasChangesStore } from "@/store/WorkflowHasChangesStore";+import { useCopilotActionStore } from "@/store/useCopilotActionStore";import { WorkflowCreateYAMLRequest } from "@/routes/workflows/types/workflowYamlTypes";import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";import { toast } from "@/components/ui/use-toast";@@ -1008,6 +1009,8 @@ export function WorkflowCopilotChat({}updateQueuedPrompt(null);+ // Discard the queued block-build's target so it can't leak into the next normal message.+ blockBuildTargetLabelRef.current = null;setMessages((prev) =>prev.filter((message) => message.id !== queuedPrompt.id),);@@ -1038,6 +1041,11 @@ export function WorkflowCopilotChat({};}, [cancelQueuedPrompt, cancelSend, isLoading, isOpen, queuedPrompt]);+ // Set by a block's "Generate" arm step so the next send scopes regeneration to that block.+ const blockBuildTargetLabelRef = useRef<string | null>(null);+ // True only while a block-build turn is actually in flight (not a turn it queued behind).+ const blockGenInFlightRef = useRef(false);+const handleSend = useCallback(async (messageOverride?: string, options: SendOptions = {}) => {const candidate = messageOverride ?? inputValue;@@ -1360,6 +1368,11 @@ export function WorkflowCopilotChat({};const client = await getSseClient(credentialGetter);+ const targetBlockLabel = blockBuildTargetLabelRef.current;+ blockBuildTargetLabelRef.current = null;+ if (targetBlockLabel != null) {+ blockGenInFlightRef.current = true;+ }await client.postStreaming<WorkflowCopilotSsePayload>("/workflow/copilot/chat-post",{@@ -1374,6 +1387,7 @@ export function WorkflowCopilotChat({mode: copilotV2Enabled ? composerMode : null,code_block: isBuild && codeBlockModeEnabled ? codeWorkflow : null,cancel_token: cancelToken,+ target_block_label: targetBlockLabel,} as WorkflowCopilotChatRequest,(payload) => {switch (payload.type) {@@ -1503,6 +1517,93 @@ export function WorkflowCopilotChat({],);+ // A code block's "Generate" button asks the copilot to (re)build that one block+ // from its goal. Force build + code mode, then fire the send on the next tick.+ const pendingBlockBuild = useCopilotActionStore(+ (state) => state.pendingBuild,+ );+ const clearPendingBlockBuild = useCopilotActionStore(+ (state) => state.clearPendingBuild,+ );+ const finishBlockGenerating = useCopilotActionStore(+ (state) => state.finishGenerating,+ );+ const blockCancelNonce = useCopilotActionStore((state) => state.cancelNonce);+ const blockBuildMessageRef = useRef<string | null>(null);+ const [blockBuildArmNonce, setBlockBuildArmNonce] = useState(0);++ useEffect(() => {+ if (!pendingBlockBuild) {+ return;+ }+ blockBuildMessageRef.current =+ `Rebuild the "${pendingBlockBuild.blockLabel}" code block so it accomplishes ` ++ `this goal, and update its code and steps accordingly: ${pendingBlockBuild.prompt}`;+ blockBuildTargetLabelRef.current = pendingBlockBuild.blockLabel;+ setComposerMode("build");+ setCodeWorkflow(true);+ setBlockBuildArmNonce((nonce) => nonce + 1);+ clearPendingBlockBuild();+ }, [pendingBlockBuild, clearPendingBlockBuild]);++ useEffect(() => {+ if (blockBuildArmNonce === 0 || blockBuildMessageRef.current === null) {+ return;+ }+ if (composerMode !== "build" || !codeWorkflow) {+ return;+ }+ const message = blockBuildMessageRef.current;+ blockBuildMessageRef.current = null;+ // A prompt is already queued, so this send no-ops. Disarm the block target+ // (else the queued drain inherits it) and clear the stuck generating state.+ if (queuedPromptRef.current) {+ blockBuildTargetLabelRef.current = null;+ finishBlockGenerating();+ return;+ }+ void handleSend(message);+ }, [+ blockBuildArmNonce,+ composerMode,+ codeWorkflow,+ handleSend,+ finishBlockGenerating,+ ]);++ const blockGenLoadingRef = useRef(isLoading);+ useEffect(() => {+ if (+ blockGenLoadingRef.current &&+ !isLoading &&+ blockGenInFlightRef.current+ ) {+ blockGenInFlightRef.current = false;+ finishBlockGenerating();+ }+ blockGenLoadingRef.current = isLoading;+ }, [isLoading, finishBlockGenerating]);++ const blockCancelNonceRef = useRef(blockCancelNonce);+ useEffect(() => {+ if (blockCancelNonce !== blockCancelNonceRef.current) {+ blockCancelNonceRef.current = blockCancelNonce;+ const queued = queuedPromptRef.current;+ // A queued block build hasn't streamed yet, so cancelSend would no-op and+ // let it drain later. Drop it (and its bubble), leaving any unrelated+ // in-flight turn untouched.+ if (queued && blockBuildTargetLabelRef.current != null) {+ blockBuildTargetLabelRef.current = null;+ updateQueuedPrompt(null);+ setMessages((prev) =>+ prev.filter((message) => message.id !== queued.id),+ );+ return;+ }+ void cancelSend();+ }+ }, [blockCancelNonce, cancelSend, updateQueuedPrompt]);+const handleKeyPress = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {if (e.key === "Enter" && !e.shiftKey) {e.preventDefault();diff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.tsindex b2e34449c..3ee0cb177 100644--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts@@ -42,6 +42,7 @@ export interface WorkflowCopilotChatRequest {mode?: "ask" | "build" | null;code_block?: boolean | null;cancel_token?: string;+ target_block_label?: string | null;}export interface WorkflowCopilotCancelRequest {diff --git a/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunTimeline.tsx b/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunTimeline.tsxindex 2815fa896..1463719a8 100644--- a/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunTimeline.tsx+++ b/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunTimeline.tsx@@ -1,9 +1,13 @@+import { useMemo } from "react";+import { ScrollArea, ScrollAreaViewport } from "@/components/ui/scroll-area";import { Skeleton } from "@/components/ui/skeleton";import { statusIsFinalized } from "@/routes/tasks/types";import { cn } from "@/util/utils";import { useWorkflowRunQuery } from "../hooks/useWorkflowRunQuery";+import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";import { useWorkflowRunTimelineQuery } from "../hooks/useWorkflowRunTimelineQuery";+import { buildCodeStepsByLabel } from "../workflowBlockUtils";import {countActionsInTimeline,isBlockItem,@@ -38,6 +42,15 @@ function DebuggerRunTimeline({const { data: workflowRunTimeline, isLoading: workflowRunTimelineIsLoading } =useWorkflowRunTimelineQuery();+ const { data: workflowRunWithWorkflow } = useWorkflowRunWithWorkflowQuery();+ const codeStepsByLabel = useMemo(+ () =>+ buildCodeStepsByLabel(+ workflowRunWithWorkflow?.workflow?.workflow_definition?.blocks ?? [],+ ),+ [workflowRunWithWorkflow],+ );+if (workflowRunIsLoading || workflowRunTimelineIsLoading) {return <Skeleton className="h-full w-full" />;}@@ -101,6 +114,7 @@ function DebuggerRunTimeline({subItems={timelineItem.children}activeItem={activeItem}block={timelineItem.block}+ codeStepsByLabel={codeStepsByLabel}onActionClick={onActionItemSelected}onBlockItemClick={onBlockItemSelected}onThoughtClick={onObserverThoughtCardSelected}diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsxindex 5f5da207c..6bcb9e6eb 100644--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx@@ -52,6 +52,7 @@ import { useBlockScriptStore } from "@/store/BlockScriptStore";import { useBlockSidebarWidthStore } from "@/store/BlockSidebarWidthStore";import { useCacheKeyValueStore } from "@/store/CacheKeyValueStore";import { useRecordingStore } from "@/store/useRecordingStore";+import { useCopilotActionStore } from "@/store/useCopilotActionStore";import { useShowAllCodeStore } from "@/store/ShowAllCodeStore";import { useSidebarSaveStateStore } from "@/store/SidebarSaveStateStore";import { useWorkflowHistoryAccessStore } from "@/store/WorkflowHistoryAccessStore";@@ -408,6 +409,16 @@ function Workspace({const [isCopilotOpen, setIsCopilotOpen] = useState(() => !!initialCopilotMessage || !initialNodes.some(isWorkflowBlockNode),);+ // Open the copilot panel when a code block requests a goal-driven (re)build,+ // so the user can watch the scout and the generated block apply.+ const copilotPendingBuild = useCopilotActionStore(+ (state) => state.pendingBuild,+ );+ useEffect(() => {+ if (copilotPendingBuild) {+ setIsCopilotOpen(true);+ }+ }, [copilotPendingBuild]);const [copilotMessageCount, setCopilotMessageCount] = useState(0);const copilotButtonRef = useRef<HTMLButtonElement>(null);const [readyBrowserSessionId, setReadyBrowserSessionId] = useState<diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.test.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.test.tsxindex 744aa78bf..6d122f986 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.test.tsx@@ -1,20 +1,41 @@// @vitest-environment jsdom-import { cleanup, render, screen } from "@testing-library/react";-import { afterEach, describe, expect, test, vi } from "vitest";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { WorkflowScopeContext } from "@/routes/workflows/editor/WorkflowScopeContext";import { CodeBlockEditor } from "./CodeBlockEditor";+import { codeBlockNodeDefaultData, type CodeBlockNodeData } from "./types";++const baseData: CodeBlockNodeData = {+ debuggable: true,+ editable: true,+ label: "code_block",+ code: "print(1)",+ continueOnFailure: false,+ parameterKeys: [],+ prompt: null,+ steps: null,+ model: null,+};const node = {id: "cb1",type: "codeBlock",- data: { editable: true, code: "print(1)", parameterKeys: [] },+ data: { ...baseData },};+const updateNodeData = vi.fn();+let codeBlockAccess = true;+vi.mock("@xyflow/react", () => ({- useReactFlow: () => ({ getNode: () => node, updateNodeData: vi.fn() }),+ useReactFlow: () => ({ getNode: () => node, updateNodeData }),+}));++vi.mock("@/hooks/useFeatureFlag", () => ({+ useFeatureFlag: (flag: string) =>+ flag === "CODE_BLOCK_ACCESS" ? codeBlockAccess : undefined,}));vi.mock("..", () => ({@@ -25,22 +46,59 @@ vi.mock("@/components/WorkflowBlockInputSet", () => ({WorkflowBlockInputSet: () => null,}));+vi.mock("@/components/WorkflowBlockInputTextarea", () => ({+ WorkflowBlockInputTextarea: ({+ value,+ onChange,+ }: {+ value?: string;+ onChange: (value: string) => void;+ }) => (+ <textarea+ data-testid="block-input-textarea"+ value={value ?? ""}+ onChange={(event) => onChange(event.target.value)}+ />+ ),+}));+vi.mock("@/routes/workflows/components/CodeEditor", () => ({- CodeEditor: ({ readOnly }: { readOnly?: boolean }) => (- <div data-testid="code-editor" data-readonly={String(Boolean(readOnly))} />+ CodeEditor: ({+ readOnly,+ extraExtensions,+ }: {+ readOnly?: boolean;+ extraExtensions?: Array<unknown>;+ }) => (+ <div+ data-testid="code-editor"+ data-readonly={String(Boolean(readOnly))}+ data-extension-count={String(extraExtensions?.length ?? 0)}+ />),}));+beforeEach(() => {+ node.data = { ...baseData };+ updateNodeData.mockClear();+ codeBlockAccess = true;+});+afterEach(cleanup);-function renderEditor(readOnly: boolean) {+function renderEditor(readOnly: boolean = false, view?: "plain" | "code") {return render(<WorkflowScopeContext.Provider value={{ workflowId: "w", readOnly }}>- <CodeBlockEditor blockId="cb1" />+ <CodeBlockEditor blockId="cb1" view={view} /></WorkflowScopeContext.Provider>,);}+const codeFirstData: Partial<CodeBlockNodeData> = {+ prompt: "Open {{ url }}",+ steps: [{ description: "Open the page", action_type: "goto_url" }],+};+describe("CodeBlockEditor in a read-only scope", () => {test("keeps the code editor editable in the live editor scope", () => {renderEditor(false);@@ -59,3 +117,258 @@ describe("CodeBlockEditor in a read-only scope", () => {).toBe("true");});});++test("wires the jinja highlight into the code editor", () => {+ renderEditor();++ // jinjaHighlight contributes 2 extensions (plugin + theme).+ expect(+ screen.getByTestId("code-editor").getAttribute("data-extension-count"),+ ).toBe("2");+});++describe("CodeBlockEditor for a code-first block", () => {+ test("renders goal, steps, and code panel in order", () => {+ node.data = { ...baseData, ...codeFirstData };+ const { container } = renderEditor();++ expect(screen.getByText("Goal")).toBeTruthy();+ expect(screen.getByText("Steps (1)")).toBeTruthy();+ expect(screen.getByText("Open the page")).toBeTruthy();+ expect(screen.getByText("goto_url")).toBeTruthy();++ const text = container.textContent ?? "";+ const order = ["Goal", "Steps (1)", "Code Input"].map((label) =>+ text.indexOf(label),+ );+ expect(order).toEqual([...order].sort((a, b) => a - b));+ expect(order.every((index) => index >= 0)).toBe(true);+ });++ test("renders the inputs selector alongside the code panel", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor();++ expect(screen.getByText("Inputs")).toBeTruthy();+ expect(screen.getByText("Code Input")).toBeTruthy();+ });++ test("uses the parameter-autocomplete textarea for the goal", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor();++ const textareas = screen.getAllByTestId<HTMLTextAreaElement>(+ "block-input-textarea",+ );+ expect(textareas.map((textarea) => textarea.value)).toEqual([+ "Open {{ url }}",+ ]);+ });++ test("persists goal edits to the node data", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor();++ const [goalTextarea] = screen.getAllByTestId("block-input-textarea");+ fireEvent.change(goalTextarea!, { target: { value: "Open {{ link }}" } });++ expect(updateNodeData).toHaveBeenCalledWith("cb1", {+ prompt: "Open {{ link }}",+ });+ });++ test("collapses and expands the step list", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor();++ const toggle = () => screen.getByRole("button", { name: /Steps \(1\)/ });+ expect(screen.getByText("Open the page")).toBeTruthy();+ expect(toggle().getAttribute("aria-expanded")).toBe("true");++ fireEvent.click(toggle());+ expect(screen.queryByText("Open the page")).toBeNull();+ expect(toggle().getAttribute("aria-expanded")).toBe("false");++ fireEvent.click(toggle());+ expect(screen.getByText("Open the page")).toBeTruthy();+ expect(toggle().getAttribute("aria-expanded")).toBe("true");+ });++ test("omits the step list when the block has no steps", () => {+ node.data = { ...baseData, ...codeFirstData, steps: [] };+ renderEditor();++ expect(screen.getByText("Goal")).toBeTruthy();+ expect(screen.queryByText(/Steps \(/)).toBeNull();+ });+});++describe("CodeBlockEditor step-to-code highlighting", () => {+ const steppedData: Partial<CodeBlockNodeData> = {+ prompt: "Search and open",+ steps: [+ {+ description: "Open the page",+ action_type: "goto_url",+ line_start: 2,+ line_end: 3,+ },+ {+ description: "Read the title",+ action_type: "extract",+ line_start: 5,+ line_end: 5,+ },+ ],+ };++ test("shows each step's line range", () => {+ node.data = { ...baseData, ...steppedData };+ renderEditor();++ expect(screen.getByText("L2-3")).toBeTruthy();+ expect(screen.getByText("L5")).toBeTruthy();+ });++ test("highlights the clicked step's lines and toggles off", () => {+ node.data = { ...baseData, ...steppedData };+ renderEditor();++ const editor = () => screen.getByTestId("code-editor");+ // Baseline: jinja only (2 extensions), no active step.+ expect(editor().getAttribute("data-extension-count")).toBe("2");++ const stepButton = screen.getByRole("button", { name: /Open the page/ });+ fireEvent.click(stepButton);+ // jinja (2) + lineHighlight field + theme (2) = 4.+ expect(editor().getAttribute("data-extension-count")).toBe("4");+ expect(stepButton.getAttribute("aria-pressed")).toBe("true");++ fireEvent.click(stepButton);+ expect(editor().getAttribute("data-extension-count")).toBe("2");+ expect(stepButton.getAttribute("aria-pressed")).toBe("false");+ });+});++describe("CodeBlockEditor for a legacy block", () => {+ test("renders the inputs and code sections when goal is null", () => {+ renderEditor();++ expect(screen.getByText("Inputs")).toBeTruthy();+ expect(screen.getByText("Code Input")).toBeTruthy();+ expect(screen.queryByText("Goal")).toBeNull();+ expect(screen.queryByText(/Steps \(/)).toBeNull();+ expect(screen.queryAllByTestId("block-input-textarea")).toHaveLength(0);+ });++ test("treats a block missing the goal field entirely as legacy", () => {+ // Simulates pre-migration node data where the field is absent, not null.+ node.data = {+ ...baseData,+ prompt: undefined,+ } as unknown as CodeBlockNodeData;+ renderEditor();++ expect(screen.getByText("Code Input")).toBeTruthy();+ expect(screen.getByText("Inputs")).toBeTruthy();+ expect(screen.queryByText("Goal")).toBeNull();+ });+});++describe("CodeBlockEditor for a newly-added block from the node adder", () => {+ test("renders the code-first layout because the default goal is non-null", () => {+ node.data = { ...codeBlockNodeDefaultData, label: "code_block" };+ renderEditor();++ expect(screen.getByText("Goal")).toBeTruthy();+ // Steps are copilot-authored annotations, so a hand-added block has none yet.+ expect(screen.queryByText(/Steps \(/)).toBeNull();+ });+});++describe("CodeBlockEditor plain view", () => {+ test("shows goal and steps but not inputs or the code editor", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor(false, "plain");++ expect(screen.getByText("Goal")).toBeTruthy();+ expect(screen.getByText("What Skyvern will do")).toBeTruthy();+ expect(screen.getByText("Open the page")).toBeTruthy();+ // The readable action label is the per-step subtitle.+ expect(screen.getByText("Goto URL")).toBeTruthy();+ // Inputs and the code editor live outside the plain view now.+ expect(screen.queryByText("Inputs")).toBeNull();+ expect(screen.queryByTestId("code-editor")).toBeNull();+ });++ test("shows an empty hint when a code-first block has no steps", () => {+ node.data = { ...baseData, ...codeFirstData, steps: [] };+ renderEditor(false, "plain");++ expect(screen.getByText("What Skyvern will do")).toBeTruthy();+ expect(screen.getByText(/No steps yet/)).toBeTruthy();+ expect(screen.queryByTestId("code-editor")).toBeNull();+ });++ test("renders only the code editor when the view is code", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor(false, "code");++ expect(screen.getByTestId("code-editor")).toBeTruthy();+ expect(screen.queryByText("Goal")).toBeNull();+ expect(screen.queryByText("What Skyvern will do")).toBeNull();+ expect(screen.queryByText("Inputs")).toBeNull();+ });++ test("ignores the split view for a legacy block without a goal", () => {+ renderEditor(false, "plain");++ expect(screen.queryByText("What Skyvern will do")).toBeNull();+ expect(screen.getByText("Code Input")).toBeTruthy();+ });+});++describe("CodeBlockEditor without code-first access", () => {+ test("renders the legacy code layout even when the block carries a goal", () => {+ codeBlockAccess = false;+ node.data = { ...baseData, ...codeFirstData };+ renderEditor();++ expect(screen.getByText("Code Input")).toBeTruthy();+ expect(screen.queryByText("Goal")).toBeNull();+ expect(screen.queryByText(/Steps \(/)).toBeNull();+ });+});++describe("CodeBlockEditor generate gating", () => {+ test("enables regenerate in the editable live scope", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor(false);++ const button = screen.getByRole<HTMLButtonElement>("button", {+ name: "Regenerate block",+ });+ expect(button.disabled).toBe(false);+ });++ test("disables regenerate in a read-only comparison scope", () => {+ node.data = { ...baseData, ...codeFirstData };+ renderEditor(true);++ const button = screen.getByRole<HTMLButtonElement>("button", {+ name: "Regenerate block",+ });+ expect(button.disabled).toBe(true);+ });++ test("disables generate when the node is not editable", () => {+ node.data = { ...baseData, prompt: "Do a thing", steps: null };+ node.data.editable = false;+ renderEditor(false);++ const button = screen.getByRole<HTMLButtonElement>("button", {+ name: "Generate block",+ });+ expect(button.disabled).toBe(true);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.tsxindex 8806a25cf..00b0119d3 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockEditor.tsx@@ -1,63 +1,266 @@+import { ChevronDownIcon, MagicWandIcon } from "@radix-ui/react-icons";import { useReactFlow } from "@xyflow/react";+import { useMemo, useState } from "react";+import type { Extension } from "@uiw/react-codemirror";import { Label } from "@/components/ui/label";import { WorkflowBlockInputSet } from "@/components/WorkflowBlockInputSet";+import { WorkflowBlockInputTextarea } from "@/components/WorkflowBlockInputTextarea";+import { useFeatureFlag } from "@/hooks/useFeatureFlag";import { CodeEditor } from "@/routes/workflows/components/CodeEditor";+import { jinjaHighlight } from "@/routes/workflows/components/jinjaHighlight";+import { lineHighlight } from "@/routes/workflows/components/lineHighlight";import { useWorkflowScopeReadOnly } from "@/routes/workflows/editor/WorkflowScopeContext";+import type { CodeBlockStep } from "@/routes/workflows/types/workflowTypes";+import { useCopilotActionStore } from "@/store/useCopilotActionStore";import { deepEqualStringArrays } from "@/util/equality";+import { cn } from "@/util/utils";import { type AppNode, isWorkflowBlockNode } from "..";+import { CodeBlockPlainCard } from "./CodeBlockPlainCard";+import type { CodeBlockView } from "./CodeBlockViewToggle";import type { CodeBlockNode, CodeBlockNodeData } from "./types";import { useUpdate } from "../../useUpdate";-function CodeBlockEditor({ blockId }: { blockId: string }) {+function formatStepLines(step: CodeBlockStep): string {+ if (step.line_start == null) {+ return "";+ }+ if (step.line_end == null || step.line_end === step.line_start) {+ return `L${step.line_start}`;+ }+ return `L${step.line_start}-${step.line_end}`;+}++function CodeBlockEditor({+ blockId,+ view,+}: {+ blockId: string;+ view?: CodeBlockView;+}) {const rf = useReactFlow<AppNode>();const node = rf.getNode(blockId);if (!node || !isWorkflowBlockNode(node) || node.type !== "codeBlock") {return null;}- return <CodeBlockEditorBody blockId={blockId} node={node as CodeBlockNode} />;+ return (+ <CodeBlockEditorBody+ blockId={blockId}+ node={node as CodeBlockNode}+ view={view}+ />+ );}function CodeBlockEditorBody({blockId,node,+ view,}: {blockId: string;node: CodeBlockNode;+ view?: CodeBlockView;}) {const data = node.data;const { editable } = data;const update = useUpdate<CodeBlockNodeData>({ id: blockId, editable });const scopeReadOnly = useWorkflowScopeReadOnly();+ const codeFirstAccess = useFeatureFlag("CODE_BLOCK_ACCESS") === true;+ // Code-first layout needs the access flag plus a prompt; otherwise keep the legacy manual layout.+ const isCodeFirst = data.prompt != null && codeFirstAccess;+ const steps = data.steps ?? [];+ const [stepsOpen, setStepsOpen] = useState(true);+ const [activeStepIndex, setActiveStepIndex] = useState<number | null>(null);+ const activeStep =+ activeStepIndex != null ? (steps[activeStepIndex] ?? null) : null;+ const codeExtensions = useMemo<Array<Extension>>(() => {+ if (activeStep?.line_start == null) {+ return jinjaHighlight;+ }+ const activeLineExtensions = lineHighlight([+ {+ from: activeStep.line_start,+ to: activeStep.line_end ?? activeStep.line_start,+ variant: "active",+ },+ ]);+ return [+ ...jinjaHighlight,+ ...(Array.isArray(activeLineExtensions)+ ? activeLineExtensions+ : [activeLineExtensions]),+ ];+ }, [activeStep?.line_start, activeStep?.line_end]);- return (- <div data-testid="code-block-block-form" className="space-y-4">- <div className="space-y-2">- <Label className="text-xs text-slate-300">Inputs</Label>- <WorkflowBlockInputSet- nodeId={blockId}- onChange={(parameterKeys) => {- const newParameterKeys = Array.from(parameterKeys);- if (!deepEqualStringArrays(data.parameterKeys, newParameterKeys)) {- update({ parameterKeys: newParameterKeys });- }- }}- values={new Set(data.parameterKeys ?? [])}+ const requestBuild = useCopilotActionStore((state) => state.requestBuild);+ const requestCancel = useCopilotActionStore((state) => state.requestCancel);+ const generatingBlockLabel = useCopilotActionStore(+ (state) => state.generatingBlockLabel,+ );+ const isGenerating =+ generatingBlockLabel != null && generatingBlockLabel === data.label;+ const canGenerate =+ (data.prompt ?? "").trim().length > 0 &&+ !isGenerating &&+ editable &&+ !scopeReadOnly;+ const hasGenerated = steps.length > 0;++ const goalField = (+ <div className="space-y-2">+ <div className="flex items-center justify-between">+ <Label className="text-xs text-slate-300">Goal</Label>+ <button+ type="button"+ disabled={!canGenerate}+ aria-label={hasGenerated ? "Regenerate block" : "Generate block"}+ onClick={() =>+ requestBuild({ blockLabel: data.label, prompt: data.prompt ?? "" })+ }+ className={cn(+ "nodrag nopan flex items-center gap-1 rounded-md border border-slate-700 bg-slate-elevation1 px-2 py-0.5 text-xs text-slate-200",+ canGenerate+ ? "hover:bg-slate-elevation2"+ : "cursor-not-allowed opacity-50",+ )}+ >+ <MagicWandIcon className="size-3" />+ {isGenerating+ ? "Generating…"+ : hasGenerated+ ? "Regenerate"+ : "Generate"}+ </button>+ </div>+ <WorkflowBlockInputTextarea+ nodeId={blockId}+ onChange={(value) => update({ prompt: value })}+ value={data.prompt ?? ""}+ className="nopan text-xs"+ />+ </div>+ );++ const codeEditorElement = (+ <CodeEditor+ language="python"+ value={data.code}+ readOnly={scopeReadOnly}+ onChange={(value) => {+ update({ code: value });+ }}+ className="nopan"+ fontSize={8}+ extraExtensions={codeExtensions}+ />+ );++ const inputsField = (+ <div className="space-y-2">+ <Label className="text-xs text-slate-300">Inputs</Label>+ <WorkflowBlockInputSet+ nodeId={blockId}+ onChange={(parameterKeys) => {+ const newParameterKeys = Array.from(parameterKeys);+ if (!deepEqualStringArrays(data.parameterKeys, newParameterKeys)) {+ update({ parameterKeys: newParameterKeys });+ }+ }}+ values={new Set(data.parameterKeys ?? [])}+ />+ </div>+ );++ if (isCodeFirst && view === "plain") {+ return (+ <div data-testid="code-block-block-form" className="space-y-4">+ {goalField}+ <CodeBlockPlainCard+ steps={steps}+ generating={isGenerating}+ onStop={requestCancel}/></div>+ );+ }++ if (isCodeFirst && view === "code") {+ return (+ <div data-testid="code-block-block-form" className="space-y-4">+ {codeEditorElement}+ </div>+ );+ }++ return (+ <div data-testid="code-block-block-form" className="space-y-4">+ {isCodeFirst && goalField}+ {isCodeFirst && steps.length > 0 && (+ <div className="space-y-2">+ <button+ type="button"+ aria-expanded={stepsOpen}+ className="flex w-full items-center justify-between text-xs text-slate-300"+ onClick={() => setStepsOpen((open) => !open)}+ >+ <span>Steps ({steps.length})</span>+ <ChevronDownIcon+ className={cn(+ "size-4 transition-transform",+ stepsOpen && "rotate-180",+ )}+ />+ </button>+ {stepsOpen && (+ <ol className="space-y-1">+ {steps.map((step, index) => {+ const hasLines = step.line_start != null;+ const isActive = activeStepIndex === index;+ return (+ <li key={index}>+ <button+ type="button"+ disabled={!hasLines}+ aria-pressed={isActive}+ onClick={() =>+ setActiveStepIndex((current) =>+ current === index ? null : index,+ )+ }+ className={cn(+ "flex w-full items-center gap-2 rounded bg-slate-elevation1 px-2 py-1 text-left text-xs",+ hasLines && "hover:bg-slate-elevation2",+ isActive && "ring-1 ring-sky-400/60",+ !hasLines && "cursor-default",+ )}+ >+ <span className="w-5 shrink-0 tabular-nums text-slate-500">+ {index + 1}.+ </span>+ <span className="shrink-0 rounded border border-slate-700 px-1.5 py-0.5 text-[10px] text-slate-400">+ {step.action_type}+ </span>+ <span className="min-w-0 flex-1 truncate text-slate-300">+ {step.title ?? step.description ?? ""}+ </span>+ {hasLines && (+ <span className="shrink-0 text-[10px] tabular-nums text-slate-500">+ {formatStepLines(step)}+ </span>+ )}+ </button>+ </li>+ );+ })}+ </ol>+ )}+ </div>+ )}+ {inputsField}<div className="space-y-2"><Label className="text-xs text-slate-300">Code Input</Label>- <CodeEditor- language="python"- value={data.code}- readOnly={scopeReadOnly}- onChange={(value) => {- update({ code: value });- }}- className="nopan"- fontSize={8}- />+ {codeEditorElement}</div></div>);diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsxindex ee08b1e1a..6f784a69e 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockNode.tsx@@ -1,6 +1,8 @@import { Handle, NodeProps, Position } from "@xyflow/react";+import { useState } from "react";import { useParams } from "react-router-dom";+import { useFeatureFlag } from "@/hooks/useFeatureFlag";import { statusIsRunningOrQueued } from "@/routes/tasks/types";import { useWorkflowRunQuery } from "@/routes/workflows/hooks/useWorkflowRunQuery";import { useRecordingStore } from "@/store/useRecordingStore";@@ -10,6 +12,7 @@ import { useCollapseContext } from "../../collapse/CollapseContext";import { NodeBody } from "../../collapse/NodeBody";import { BuildModeOnly } from "../BuildModeOnly";import { CodeBlockEditor } from "./CodeBlockEditor";+import { CodeBlockViewToggle, type CodeBlockView } from "./CodeBlockViewToggle";import { NodeHeader } from "../components/NodeHeader";import type { CodeBlockNode } from "./types";@@ -19,6 +22,10 @@ function CodeBlockNode({ id, data }: NodeProps<CodeBlockNode>) {const { data: workflowRun } = useWorkflowRunQuery();const recordingStore = useRecordingStore();const { open } = useCollapseContext();+ const isCodeFirst = data.prompt != null;+ const codeFirstAccess = useFeatureFlag("CODE_BLOCK_ACCESS") === true;+ const showViewToggle = isCodeFirst && codeFirstAccess;+ const [view, setView] = useState<CodeBlockView>("plain");const workflowRunIsRunningOrQueued =workflowRun && statusIsRunningOrQueued(workflowRun);const thisBlockIsTargetted =@@ -46,7 +53,7 @@ function CodeBlockNode({ id, data }: NodeProps<CodeBlockNode>) {/><divclassName={cn(- "transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",+ "transform-origin-center w-[30rem] space-y-4 rounded-xl bg-slate-elevation3 px-6 py-4 transition-shadow motion-reduce:transition-none",open ? "shadow-md" : "shadow-sm",{"pointer-events-none": thisBlockIsPlaying,@@ -63,10 +70,18 @@ function CodeBlockNode({ id, data }: NodeProps<CodeBlockNode>) {totpIdentifier={null}totpUrl={null}type="code"+ viewToggle={+ showViewToggle ? (+ <CodeBlockViewToggle value={view} onChange={setView} />+ ) : undefined+ }/><NodeBody><BuildModeOnly>- <CodeBlockEditor blockId={id} />+ <CodeBlockEditor+ blockId={id}+ view={showViewToggle ? view : undefined}+ /></BuildModeOnly></NodeBody></div>diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockPlainCard.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockPlainCard.tsxnew file mode 100644index 000000000..8da1d5a51--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockPlainCard.tsx@@ -0,0 +1,102 @@+import { Cross2Icon, ReloadIcon } from "@radix-ui/react-icons";++import type { CodeBlockStep } from "@/routes/workflows/types/workflowTypes";+import { cn } from "@/util/utils";++import {+ getStepChipClassName,+ getStepIcon,+ getStepLabel,+} from "./stepPresentation";++type Props = {+ steps: Array<CodeBlockStep>;+ generating?: boolean;+ onStop?: () => void;+};++function CodeBlockPlainCard({ steps, generating = false, onStop }: Props) {+ return (+ <div data-testid="code-block-plain-card" className="space-y-3">+ <div className="flex items-center justify-between gap-2">+ <div className="text-sm font-semibold text-slate-200">+ What Skyvern will do+ </div>+ {generating && (+ <div className="flex items-center gap-2 text-xs text-slate-400">+ <span className="flex items-center gap-1">+ <ReloadIcon className="size-3 animate-spin" />+ Generating…+ </span>+ {onStop && (+ <button+ type="button"+ onClick={onStop}+ className="nodrag nopan flex items-center gap-1 rounded border border-slate-700 px-1.5 py-0.5 text-slate-300 hover:bg-slate-elevation2"+ >+ <Cross2Icon className="size-3" />+ Stop+ </button>+ )}+ </div>+ )}+ </div>+ {generating ? (+ <ol className="space-y-0" aria-busy="true">+ {[0, 1, 2].map((index) => (+ <li key={index} className="flex gap-3">+ <div className="flex flex-col items-center">+ <div className="size-8 shrink-0 animate-pulse rounded-lg bg-slate-elevation2" />+ {index < 2 && <div className="w-px flex-1 bg-slate-700/60" />}+ </div>+ <div className="min-w-0 flex-1 pb-4">+ <div className="h-3.5 w-2/3 animate-pulse rounded bg-slate-elevation2" />+ <div className="mt-1.5 h-2.5 w-1/3 animate-pulse rounded bg-slate-elevation2" />+ </div>+ </li>+ ))}+ </ol>+ ) : steps.length === 0 ? (+ <p className="rounded-lg border border-dashed border-slate-700/70 px-3 py-4 text-xs text-slate-400">+ No steps yet. Steps appear once Skyvern generates them.+ </p>+ ) : (+ <ol>+ {steps.map((step, index) => {+ const isLast = index === steps.length - 1;+ return (+ <li key={index} className="flex gap-3">+ <div className="flex flex-col items-center">+ <div+ className={cn(+ "flex size-8 shrink-0 items-center justify-center rounded-lg",+ getStepChipClassName(step.action_type),+ )}+ >+ {getStepIcon(step.action_type)}+ </div>+ {!isLast && <div className="w-px flex-1 bg-slate-700/60" />}+ </div>+ <div className={cn("min-w-0 flex-1", !isLast && "pb-4")}>+ <div className="flex items-baseline gap-2">+ <span className="shrink-0 text-xs tabular-nums text-slate-500">+ {index + 1}+ </span>+ <span className="text-sm font-medium text-slate-100">+ {step.title ?? step.description ?? ""}+ </span>+ </div>+ <p className="mt-0.5 text-xs text-slate-400">+ {getStepLabel(step.action_type)}+ </p>+ </div>+ </li>+ );+ })}+ </ol>+ )}+ </div>+ );+}++export { CodeBlockPlainCard };diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.test.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.test.tsxnew file mode 100644index 000000000..3501e78a4--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.test.tsx@@ -0,0 +1,31 @@+// @vitest-environment jsdom++import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, test, vi } from "vitest";++import { CodeBlockViewToggle } from "./CodeBlockViewToggle";++afterEach(cleanup);++describe("CodeBlockViewToggle", () => {+ test("marks the active segment and emits the other value on click", () => {+ const onChange = vi.fn();+ render(<CodeBlockViewToggle value="plain" onChange={onChange} />);++ const plain = screen.getByRole("button", { name: "Plain" });+ const code = screen.getByRole("button", { name: /Code/ });+ expect(plain.getAttribute("aria-pressed")).toBe("true");+ expect(code.getAttribute("aria-pressed")).toBe("false");++ fireEvent.click(code);+ expect(onChange).toHaveBeenCalledWith("code");+ });++ test("emits plain when the plain segment is clicked from code", () => {+ const onChange = vi.fn();+ render(<CodeBlockViewToggle value="code" onChange={onChange} />);++ fireEvent.click(screen.getByRole("button", { name: "Plain" }));+ expect(onChange).toHaveBeenCalledWith("plain");+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.tsxnew file mode 100644index 000000000..40b354caa--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/CodeBlockViewToggle.tsx@@ -0,0 +1,44 @@+import { CodeIcon } from "@radix-ui/react-icons";++import { cn } from "@/util/utils";++export type CodeBlockView = "plain" | "code";++type Props = {+ value: CodeBlockView;+ onChange: (value: CodeBlockView) => void;+};++const segmentClass = (active: boolean) =>+ cn(+ "flex items-center gap-1 rounded px-2 py-0.5 text-xs transition-colors",+ active+ ? "bg-slate-elevation3 text-slate-100"+ : "text-slate-400 hover:text-slate-200",+ );++function CodeBlockViewToggle({ value, onChange }: Props) {+ return (+ <div className="nodrag nopan flex items-center gap-0.5 rounded-md border border-slate-700 bg-slate-elevation1 p-0.5">+ <button+ type="button"+ aria-pressed={value === "plain"}+ onClick={() => onChange("plain")}+ className={segmentClass(value === "plain")}+ >+ Plain+ </button>+ <button+ type="button"+ aria-pressed={value === "code"}+ onClick={() => onChange("code")}+ className={segmentClass(value === "code")}+ >+ <CodeIcon className="size-3" />+ Code+ </button>+ </div>+ );+}++export { CodeBlockViewToggle };diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/stepPresentation.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/stepPresentation.tsxnew file mode 100644index 000000000..0b5dad62c--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/stepPresentation.tsx@@ -0,0 +1,35 @@+import type { ReactNode } from "react";++import { type ActionType, ReadableActionTypes } from "@/api/types";+import { getActionTypeIcon } from "@/routes/workflows/components/actionTypeIcons";++export function getStepIcon(actionType: string): ReactNode {+ return getActionTypeIcon(actionType);+}++export function getStepLabel(actionType: string): string {+ return ReadableActionTypes[actionType as ActionType] ?? "Step";+}++const chipTintByActionType: Record<string, string> = {+ goto_url: "bg-sky-500/10 text-sky-300",+ go_back: "bg-sky-500/10 text-sky-300",+ go_forward: "bg-sky-500/10 text-sky-300",+ reload_page: "bg-sky-500/10 text-sky-300",+ new_tab: "bg-sky-500/10 text-sky-300",+ switch_tab: "bg-sky-500/10 text-sky-300",+ close_page: "bg-sky-500/10 text-sky-300",+ scroll: "bg-sky-500/10 text-sky-300",+ extract: "bg-emerald-500/10 text-emerald-300",+ verification_code: "bg-emerald-500/10 text-emerald-300",+ complete: "bg-emerald-500/10 text-emerald-300",+ wait: "bg-amber-500/10 text-amber-300",+ solve_captcha: "bg-amber-500/10 text-amber-300",+ terminate: "bg-rose-500/10 text-rose-300",+};++const defaultChipTint = "bg-slate-500/10 text-slate-300";++export function getStepChipClassName(actionType: string): string {+ return chipTintByActionType[actionType] ?? defaultChipTint;+}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/types.tsindex e46d2cdec..41e309cb9 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/types.ts+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/CodeBlockNode/types.ts@@ -1,10 +1,15 @@import type { Node } from "@xyflow/react";import { NodeBaseData } from "../types";-import { debuggableWorkflowBlockTypes } from "@/routes/workflows/types/workflowTypes";+import {+ debuggableWorkflowBlockTypes,+ type CodeBlockStep,+} from "@/routes/workflows/types/workflowTypes";export type CodeBlockNodeData = NodeBaseData & {code: string;parameterKeys: Array<string> | null;+ prompt: string | null;+ steps: Array<CodeBlockStep> | null;};export type CodeBlockNode = Node<CodeBlockNodeData, "codeBlock">;@@ -27,5 +32,7 @@ export const codeBlockNodeDefaultData: CodeBlockNodeData = {code: codeLead,continueOnFailure: false,parameterKeys: null,+ prompt: "",+ steps: null,model: null,} as const;diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsxindex af2175b63..268454857 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx@@ -140,6 +140,7 @@ interface Props {totpUrl: string | null;transmutations?: Transmutations;type: WorkflowBlockType;+ viewToggle?: React.ReactNode;}type Payload = Record<string, unknown> & {@@ -234,6 +235,7 @@ function NodeHeader({totpUrl,transmutations,type,+ viewToggle,}: Props) {const log = useLogging();const mode = useWorkflowEditorMode();@@ -975,6 +977,7 @@ function NodeHeader({</div></div><div className="pointer-events-auto ml-auto flex items-center gap-2">+ {viewToggle}{extraActions}{thisBlockIsPlaying && (<div className="ml-auto">diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.test.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.test.tsxindex 61d5214e0..e9f2b55ec 100644--- a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.test.tsx@@ -24,33 +24,6 @@ vi.mock("@xyflow/react", async () => {};});-vi.mock("@/components/WorkflowBlockInputSet", () => ({- WorkflowBlockInputSet: ({- nodeId,- values,- onChange,- }: {- nodeId: string;- values: Set<string>;- onChange: (parameterKeys: Set<string>) => void;- }) => (- <div data-testid="workflow-block-input-set" data-node-id={nodeId}>- <button- type="button"- data-testid="add-param"- onClick={() => {- const next = new Set(values);- next.add("new_param");- onChange(next);- }}- >- add- </button>- <span data-testid="parameter-count">{values.size}</span>- </div>- ),-}));-vi.mock("@/routes/workflows/components/CodeEditor", () => ({CodeEditor: ({value,@@ -130,15 +103,13 @@ describe("CodeBlockBlockForm (SKY-9380)", () => {});test("renders the migrated fields the inline tile exposes", () => {- // Mirrors the inline CodeBlockNode JSX: Inputs set and a- // python CodeEditor. If a field disappears here it disappears from- // the sidebar UI.+ // Mirrors the inline CodeBlockNode JSX: the Inputs selector and a python+ // CodeEditor. If a field disappears here it disappears from the sidebar UI.mockGetNode.mockReturnValue(baseCodeBlockNode());render(<CodeBlockBlockForm blockId="code-1" />);- expect(screen.getByText("Inputs")).toBeDefined();expect(screen.getByText("Code Input")).toBeDefined();- expect(screen.getByTestId("workflow-block-input-set")).toBeDefined();+ expect(screen.getByText("Inputs")).toBeDefined();expect(screen.getByTestId("code-editor")).toBeDefined();expect(screen.getByTestId("code-editor").getAttribute("data-language"),@@ -157,35 +128,6 @@ describe("CodeBlockBlockForm (SKY-9380)", () => {});});- test("dispatches updateNodeData when parameter keys change", () => {- mockGetNode.mockReturnValue(baseCodeBlockNode());- render(<CodeBlockBlockForm blockId="code-1" />);-- fireEvent.click(screen.getByTestId("add-param"));-- expect(mockUpdateNodeData).toHaveBeenCalledWith("code-1", {- parameterKeys: ["new_param"],- });- });-- test("does not redispatch parameterKeys when the new set deep-equals the old", () => {- // Validation parity with the inline tile: the inline- // `WorkflowBlockInputSet.onChange` callback short-circuits via- // `deepEqualStringArrays` so identical-content sets do not bump- // node data and thereby preserve byte-identical YAML/JSON output.- mockGetNode.mockReturnValue(baseCodeBlockNode({ parameterKeys: ["a"] }));- render(<CodeBlockBlockForm blockId="code-1" />);-- // Re-emit a Set containing the same single value via mock add (will- // produce ["a","new_param"]) — the deep-equal short-circuit only- // skips when arrays are identical, which we verify by re-rendering- // with an unchanged value below. Here we assert the positive path.- fireEvent.click(screen.getByTestId("add-param"));- expect(mockUpdateNodeData).toHaveBeenCalledWith("code-1", {- parameterKeys: ["a", "new_param"],- });- });-test("does not dispatch updates when the node is not editable", () => {mockGetNode.mockReturnValue(baseCodeBlockNode({ editable: false }));render(<CodeBlockBlockForm blockId="code-1" />);@@ -214,4 +156,23 @@ describe("CodeBlockBlockForm (SKY-9380)", () => {expect(commit).toBeDefined();expect(commit?.()).toBe(true);});++ test("stamps the savedAt footer when code-first fields change", () => {+ const codeFirstFields = {+ prompt: "Open {{ url }}",+ steps: [{ description: "Open the page", action_type: "goto_url" }],+ };+ mockGetNode.mockReturnValue(baseCodeBlockNode(codeFirstFields));+ const { rerender } = render(<CodeBlockBlockForm blockId="code-1" />);++ mockGetNode.mockReturnValue(+ baseCodeBlockNode({ ...codeFirstFields, prompt: "Open {{ link }}" }),+ );+ rerender(<CodeBlockBlockForm blockId="code-1" />);+ vi.advanceTimersByTime(400);++ expect(+ useSidebarSaveStateStore.getState().getLastUpdatedAt("code-1"),+ ).not.toBeNull();+ });});diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.tsxindex aa31194e9..b003d0370 100644--- a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/CodeBlockBlockForm.tsx@@ -26,9 +26,16 @@ function CodeBlockBlockFormBody({blockId: string;node: CodeBlockNode;}) {- const { code, parameterKeys } = node.data;-- const value = useMemo(() => ({ code, parameterKeys }), [code, parameterKeys]);+ const { code, parameterKeys, prompt } = node.data;++ const value = useMemo(+ () => ({+ code,+ parameterKeys,+ prompt,+ }),+ [code, parameterKeys, prompt],+ );const { commit } = useDebouncedSidebarSave({blockId,value,diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex f75d41ff1..4d5ec494f 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -896,6 +896,8 @@ function convertToNode(...commonData,code: block.code,parameterKeys: block.parameters.map((p) => p.key),+ prompt: block.prompt ?? null,+ steps: block.steps ?? null,},};}@@ -2951,6 +2953,8 @@ function getWorkflowBlock(block_type: "code",parameter_keys: node.data.parameterKeys,code: node.data.code,+ prompt: node.data.prompt,+ steps: node.data.steps,};}case "download": {@@ -4281,6 +4285,8 @@ function convertBlocksToBlockYAML(block_type: "code",code: block.code,parameter_keys: block.parameters.map((p) => p.key),+ prompt: block.prompt,+ steps: block.steps,};return blockYaml;}diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.tsindex 412d6e867..12165c557 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts@@ -377,10 +377,20 @@ export type WhileLoopBlock = WorkflowBlockBase & {condition: BranchCriteria;};+export type CodeBlockStep = {+ title?: string | null;+ description?: string | null;+ action_type: string;+ line_start?: number | null;+ line_end?: number | null;+};+export type CodeBlock = WorkflowBlockBase & {block_type: "code";code: string;parameters: Array<WorkflowParameter>;+ prompt?: string | null;+ steps?: Array<CodeBlockStep> | null;};export type TextPromptBlock = WorkflowBlockBase & {diff --git a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.tsindex 21edfdef3..02e856261 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts@@ -1,5 +1,9 @@import { ProxyLocation, RunEngine } from "@/api/types";-import { WorkflowBlockType, WorkflowModel } from "./workflowTypes";+import {+ CodeBlockStep,+ WorkflowBlockType,+ WorkflowModel,+} from "./workflowTypes";export type WorkflowCreateYAMLRequest = {title: string;@@ -309,6 +313,8 @@ export type CodeBlockYAML = BlockYAMLBase & {block_type: "code";code: string;parameter_keys?: Array<string> | null;+ prompt?: string | null;+ steps?: Array<CodeBlockStep> | null;};export type TextPromptBlockYAML = BlockYAMLBase & {diff --git a/skyvern-frontend/src/routes/workflows/workflowBlockUtils.test.ts b/skyvern-frontend/src/routes/workflows/workflowBlockUtils.test.tsnew file mode 100644index 000000000..8f5860a8c--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/workflowBlockUtils.test.ts@@ -0,0 +1,70 @@+import { describe, expect, it } from "vitest";++import { buildCodeStepsByLabel } from "./workflowBlockUtils";+import type {+ CodeBlock,+ CodeBlockStep,+ ForLoopBlock,+ WorkflowBlock,+} from "./types/workflowTypes";++function codeBlock(+ label: string,+ steps: Array<CodeBlockStep> | null,+): CodeBlock {+ return {+ label,+ block_type: "code",+ output_parameter: { key: `${label}_output` },+ continue_on_failure: false,+ model: null,+ code: "",+ parameters: [],+ steps,+ } as unknown as CodeBlock;+}++function forLoop(+ label: string,+ loopBlocks: Array<WorkflowBlock>,+): ForLoopBlock {+ return {+ label,+ block_type: "for_loop",+ output_parameter: { key: `${label}_output` },+ continue_on_failure: false,+ model: null,+ loop_blocks: loopBlocks,+ } as unknown as ForLoopBlock;+}++describe("buildCodeStepsByLabel", () => {+ it("maps code block labels to their step outline", () => {+ const steps: Array<CodeBlockStep> = [+ { action_type: "goto", title: "Open page", line_start: 1, line_end: 1 },+ ];+ const map = buildCodeStepsByLabel([codeBlock("run_script", steps)]);+ expect(map.get("run_script")).toEqual(steps);+ expect(map.size).toBe(1);+ });++ it("descends into loop bodies", () => {+ const steps: Array<CodeBlockStep> = [+ { action_type: "click", description: "Click submit" },+ ];+ const map = buildCodeStepsByLabel([+ forLoop("loop", [codeBlock("nested_code", steps)]),+ ]);+ expect(map.get("nested_code")).toEqual(steps);+ expect(map.size).toBe(1);+ });++ it("skips code blocks with empty or null steps and non-code blocks", () => {+ const map = buildCodeStepsByLabel([+ codeBlock("empty", []),+ codeBlock("nullish", null),+ forLoop("loop", []),+ ]);+ expect(map.size).toBe(0);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/workflowBlockUtils.ts b/skyvern-frontend/src/routes/workflows/workflowBlockUtils.tsindex bde16f009..37062c5da 100644--- a/skyvern-frontend/src/routes/workflows/workflowBlockUtils.ts+++ b/skyvern-frontend/src/routes/workflows/workflowBlockUtils.ts@@ -1,5 +1,6 @@import {isNestedLoopWorkflowBlock,+ type CodeBlockStep,type WorkflowBlock,type WorkflowBlockType,} from "./types/workflowTypes";@@ -28,3 +29,30 @@ export function isBlockOfType<T extends WorkflowBlockType>(): block is Extract<WorkflowBlock, { block_type: T }> {return block?.block_type === type;}++/**+ * Map each code block's label to its definition step outline, descending into+ * loop bodies. The run timeline carries no step outline on the runtime block, so+ * it looks steps up here by label to render them beneath the code block.+ */+export function buildCodeStepsByLabel(+ blocks: Array<WorkflowBlock>,+): Map<string, Array<CodeBlockStep>> {+ const stepsByLabel = new Map<string, Array<CodeBlockStep>>();+ const visit = (items: Array<WorkflowBlock>) => {+ for (const block of items) {+ if (+ block.block_type === "code" &&+ block.steps &&+ block.steps.length > 0+ ) {+ stepsByLabel.set(block.label, block.steps);+ }+ if (isNestedLoopWorkflowBlock(block) && block.loop_blocks.length > 0) {+ visit(block.loop_blocks);+ }+ }+ };+ visit(blocks);+ return stepsByLabel;+}diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsxindex 8e96b9b00..d85b2705b 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx@@ -176,6 +176,11 @@ function WorkflowPostRunParameters() {<CodeBlockParameterscode={definitionBlock.code}parameters={definitionBlock.parameters}+ prompt={definitionBlock.prompt}+ steps={definitionBlock.steps}+ blockStatus={activeBlock.status}+ failureReason={activeBlock.failure_reason}+ actions={activeBlock.actions}/></div></div>diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimeline.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimeline.tsxindex 043e71271..da871e85b 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimeline.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimeline.tsx@@ -23,6 +23,7 @@ import {import { ThoughtCard } from "./ThoughtCard";import { WorkflowRunTimelineBlockItem } from "./WorkflowRunTimelineBlockItem";import { WorkflowRunTimelineUnexecutedBlockItem } from "./WorkflowRunTimelineUnexecutedBlockItem";+import { buildCodeStepsByLabel } from "../workflowBlockUtils";import {classifyUnexecutedDefinedBlocks,flattenTimelineChronologically,@@ -99,6 +100,13 @@ function WorkflowRunTimeline({() => buildBlockOrderIndex(workflowRunTimeline ?? []),[workflowRunTimeline],);+ const codeStepsByLabel = useMemo(+ () =>+ buildCodeStepsByLabel(+ workflowRun?.workflow?.workflow_definition?.blocks ?? [],+ ),+ [workflowRun],+ );// Track known item IDs so we can animate only newly-arrived itemsconst knownItemIdsRef = useRef<Set<string>>(new Set());@@ -230,6 +238,7 @@ function WorkflowRunTimeline({activeIteration={activeIteration}block={timelineItem.block}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onActionClick={onActionItemSelected}onBlockItemClick={onBlockItemSelected}onIterationClick={onIterationSelected}diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.test.tsxindex 9c8338434..6dc92abc2 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.test.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.test.tsx@@ -14,6 +14,7 @@ import type {WorkflowRunTimelineBlockItem as TimelineBlockItem,WorkflowRunTimelineItem,} from "../types/workflowRunTypes";+import type { CodeBlockStep } from "../types/workflowTypes";import { WorkflowRunTimelineBlockItem } from "./WorkflowRunTimelineBlockItem";function buildBlock(@@ -354,6 +355,128 @@ describe("WorkflowRunTimelineBlockItem", () => {);});+ it("appends code line and duration to recorded action summaries in code blocks", () => {+ const block = buildBlock({+ workflow_run_block_id: "wrb_code",+ block_type: "code",+ label: "run_script",+ actions: [+ // Newest-first payload, matching the task-action DESC convention.+ {+ action_id: "wrb_code_action_1",+ action_type: ActionTypes.Click,+ status: Status.Completed,+ reasoning: null,+ description: "locator.click #submit",+ output: { code_line: 3, duration_ms: 1500 },+ created_by: null,+ confidence_float: null,+ },+ {+ action_id: "wrb_code_action_0",+ action_type: ActionTypes.GotoUrl,+ status: Status.Completed,+ reasoning: null,+ description: "page.goto https://example.com",+ output: { code_line: 1, duration_ms: 65000 },+ created_by: null,+ confidence_float: null,+ },+ ] as unknown as WorkflowRunBlock["actions"],+ });++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ onActionClick={noop}+ onBlockItemClick={noop}+ />,+ );++ const gotoRow = screen.getByText(+ /page\.goto https:\/\/example\.com · line 1 · 1m 5s/,+ );+ const clickRow = screen.getByText(+ /locator\.click #submit · line 3 · 1\.5s/,+ );+ expect(+ gotoRow.compareDocumentPosition(clickRow) &+ Node.DOCUMENT_POSITION_FOLLOWING,+ ).toBeTruthy();+ });++ it("labels the synthetic code error row as Error instead of Screenshot", () => {+ const block = buildBlock({+ workflow_run_block_id: "wrb_code_failed",+ block_type: "code",+ label: "run_script",+ status: Status.Failed,+ actions: [+ {+ action_id: "wrb_code_failed_action_0",+ action_type: ActionTypes.NullAction,+ status: Status.Failed,+ reasoning: null,+ description: "code error at line 7",+ response: "ValueError: boom",+ output: { code_line: 7 },+ created_by: null,+ confidence_float: null,+ },+ ] as unknown as WorkflowRunBlock["actions"],+ });++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ onActionClick={noop}+ onBlockItemClick={noop}+ />,+ );++ expect(screen.getByText("Error")).toBeDefined();+ expect(screen.queryByText("Screenshot")).toBeNull();+ expect(screen.getByText(/ValueError: boom · line 7/)).toBeDefined();+ });++ it("keeps task block action rows unchanged even when output carries line metadata", () => {+ const block = buildBlock({+ workflow_run_block_id: "wrb_task_null_action",+ block_type: "task_v2",+ label: "Capture page",+ actions: [+ {+ action_id: "act_screenshot",+ action_type: ActionTypes.NullAction,+ status: Status.Failed,+ reasoning: "Capture failed",+ output: { code_line: 5, duration_ms: 2000 },+ created_by: null,+ confidence_float: null,+ },+ ] as unknown as WorkflowRunBlock["actions"],+ });++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ onActionClick={noop}+ onBlockItemClick={noop}+ />,+ );++ expect(screen.getByText("Screenshot")).toBeDefined();+ expect(screen.queryByText("Error")).toBeNull();+ expect(screen.getByText(/Capture failed/)).toBeDefined();+ expect(screen.queryByText(/line 5/)).toBeNull();+ });+it("keeps an iteration collapsed after the user clicks the chevron, even when an active descendant appears", () => {// Render an expanded iteration (groupIndex 0 default-opens), then user// collapses via chevron. Re-render the same component with an active@@ -408,4 +531,111 @@ describe("WorkflowRunTimelineBlockItem", () => {screen.getByRole("button", { name: /expand iteration/i }),).toBeDefined();});++ it("renders the code block step outline when the block has no recorded actions", () => {+ const block = buildBlock({+ workflow_run_block_id: "wrb_code_outline",+ block_type: "code",+ label: "run_script",+ actions: [],+ });+ const steps: Array<CodeBlockStep> = [+ {+ action_type: "goto",+ title: "Open the homepage",+ line_start: 1,+ line_end: 1,+ },+ {+ action_type: "click",+ description: "Click the top post",+ line_start: 3,+ line_end: 5,+ },+ ];++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ codeStepsByLabel={new Map([["run_script", steps]])}+ onActionClick={noop}+ onBlockItemClick={noop}+ />,+ );++ expect(screen.getByText(/Open the homepage/)).toBeDefined();+ expect(screen.getByText(/Click the top post/)).toBeDefined();+ expect(screen.getByText("goto")).toBeDefined();+ expect(screen.getByText("click")).toBeDefined();+ expect(screen.getByText("L1")).toBeDefined();+ expect(screen.getByText("L3-5")).toBeDefined();+ });++ it("selects the block when a code step row is clicked", () => {+ const onBlockItemClick = vi.fn();+ const block = buildBlock({+ workflow_run_block_id: "wrb_code_outline_click",+ block_type: "code",+ label: "run_script",+ actions: [],+ });+ const steps: Array<CodeBlockStep> = [+ { action_type: "goto", title: "Open the homepage", line_start: 1 },+ ];++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ codeStepsByLabel={new Map([["run_script", steps]])}+ onActionClick={noop}+ onBlockItemClick={onBlockItemClick}+ />,+ );++ fireEvent.click(screen.getByText(/Open the homepage/));+ expect(onBlockItemClick).toHaveBeenCalledWith(block);+ });++ it("prefers recorded actions over the step outline for code blocks", () => {+ const block = buildBlock({+ workflow_run_block_id: "wrb_code_actions_win",+ block_type: "code",+ label: "run_script",+ actions: [+ {+ action_id: "wrb_code_action_0",+ action_type: ActionTypes.GotoUrl,+ status: Status.Completed,+ reasoning: null,+ description: "page.goto https://example.com",+ output: { code_line: 1, duration_ms: 500 },+ created_by: null,+ confidence_float: null,+ },+ ] as unknown as WorkflowRunBlock["actions"],+ });+ const steps: Array<CodeBlockStep> = [+ { action_type: "goto", title: "Outline step that should be hidden" },+ ];++ render(+ <WorkflowRunTimelineBlockItem+ activeItem={block}+ block={block}+ subItems={[]}+ codeStepsByLabel={new Map([["run_script", steps]])}+ onActionClick={noop}+ onBlockItemClick={noop}+ />,+ );++ expect(+ screen.getByText(/page\.goto https:\/\/example\.com · line 1/),+ ).toBeDefined();+ expect(screen.queryByText("Outline step that should be hidden")).toBeNull();+ });});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.tsxindex b163a3470..7b1d9b7ac 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunTimelineBlockItem.tsx@@ -3,22 +3,12 @@ import {ChevronDownIcon,ChevronRightIcon,CrossCircledIcon,- CursorArrowIcon,- Cross2Icon,- DoubleArrowDownIcon,- DropdownMenuIcon,- FileTextIcon,- HandIcon,- InputIcon,- KeyboardIcon,- MagicWandIcon,ReloadIcon,} from "@radix-ui/react-icons";import { useEffect, useMemo, useRef, useState } from "react";import {type ActionsApiResponse,- type ActionType,ActionTypes,ReadableActionTypes,Status,@@ -28,6 +18,7 @@ import { formatDuration, toDuration } from "@/routes/workflows/utils";import { cn } from "@/util/utils";import { workflowBlockTitle } from "../editor/nodes/types";import { WorkflowBlockIcon } from "../editor/nodes/WorkflowBlockIcon";+import { actionTypeIcons as timelineActionIcons } from "../components/actionTypeIcons";import {isAction,isBlockItem,@@ -38,6 +29,7 @@ import {WorkflowRunBlock,WorkflowRunTimelineItem,} from "../types/workflowRunTypes";+import { CodeBlockStep } from "../types/workflowTypes";import {ActionItem,WorkflowRunOverviewActiveElement,@@ -52,6 +44,7 @@ type Props = {subItems: Array<WorkflowRunTimelineItem>;depth?: number;blockOrder?: ReadonlyMap<string, number>;+ codeStepsByLabel?: ReadonlyMap<string, Array<CodeBlockStep>>;onBlockItemClick: (block: WorkflowRunBlock) => void;onIterationClick?: (loopBlock: WorkflowRunBlock,@@ -79,44 +72,6 @@ const railHighlightStyle = {paddingLeft: `${RAIL_CONTENT_PADDING_PX}px`,};-const timelineActionIcons: Record<ActionType, React.ReactNode> = {- [ActionTypes.Click]: (- <WorkflowBlockIcon workflowBlockType="action" className="size-3.5" />- ),- [ActionTypes.Hover]: <HandIcon className="size-3.5" />,- [ActionTypes.InputText]: <InputIcon className="size-3.5" />,- [ActionTypes.DownloadFile]: (- <WorkflowBlockIcon workflowBlockType="file_download" className="size-3.5" />- ),- [ActionTypes.UploadFile]: (- <WorkflowBlockIcon workflowBlockType="file_upload" className="size-3.5" />- ),- [ActionTypes.SelectOption]: <DropdownMenuIcon className="size-3.5" />,- [ActionTypes.complete]: <CheckCircledIcon className="size-3.5" />,- [ActionTypes.wait]: (- <WorkflowBlockIcon workflowBlockType="wait" className="size-3.5" />- ),- [ActionTypes.terminate]: <CrossCircledIcon className="size-3.5" />,- [ActionTypes.SolveCaptcha]: <MagicWandIcon className="size-3.5" />,- [ActionTypes.extract]: (- <WorkflowBlockIcon workflowBlockType="extraction" className="size-3.5" />- ),- [ActionTypes.ReloadPage]: <ReloadIcon className="size-3.5" />,- [ActionTypes.Scroll]: <DoubleArrowDownIcon className="size-3.5" />,- [ActionTypes.KeyPress]: <KeyboardIcon className="size-3.5" />,- [ActionTypes.Move]: <CursorArrowIcon className="size-3.5" />,- [ActionTypes.NullAction]: <FileTextIcon className="size-3.5" />,- [ActionTypes.VerificationCode]: <KeyboardIcon className="size-3.5" />,- [ActionTypes.Drag]: <HandIcon className="size-3.5" />,- [ActionTypes.LeftMouse]: (- <WorkflowBlockIcon workflowBlockType="action" className="size-3.5" />- ),- [ActionTypes.GotoUrl]: (- <WorkflowBlockIcon workflowBlockType="goto_url" className="size-3.5" />- ),- [ActionTypes.ClosePage]: <Cross2Icon className="size-3.5" />,-};-function IndentRails({ depth }: { depth: number }) {// Render guide rails only for nested rows. Top-level rows should start with// content, not a phantom outer timeline rail.@@ -178,6 +133,54 @@ function getActionSummary(action: ActionsApiResponse): string | null {);}+function getRecordedActionMeta(action: ActionsApiResponse): {+ codeLine: number | null;+ durationMs: number | null;+} {+ const output = action.output;+ if (!output || typeof output !== "object" || Array.isArray(output)) {+ return { codeLine: null, durationMs: null };+ }+ const record = output as Record<string, unknown>;+ return {+ codeLine: typeof record.code_line === "number" ? record.code_line : null,+ durationMs:+ typeof record.duration_ms === "number" ? record.duration_ms : null,+ };+}++function formatActionDurationMs(durationMs: number): string {+ const seconds = durationMs / 1000;+ if (seconds >= 60) {+ return formatDuration(toDuration(seconds));+ }+ return `${seconds.toFixed(1).replace(/\.0$/, "")}s`;+}++type ActionRowPresentation = {+ label: string;+ summary: string | null;+};++// Design C rows for code blocks: recorded actions summarize as+// "<description> · line N · <duration>s"; the synthetic failure row+// (failed null_action) is labeled Error instead of Screenshot.+function getCodeActionRowPresentation(+ action: ActionsApiResponse,+): ActionRowPresentation {+ const isCodeError =+ action.status === Status.Failed &&+ action.action_type === ActionTypes.NullAction;+ const label = isCodeError ? "Error" : ReadableActionTypes[action.action_type];+ const { codeLine, durationMs } = getRecordedActionMeta(action);+ const parts = [+ getActionSummary(action) ?? normalizeInlineText(action.description),+ codeLine !== null ? `line ${codeLine}` : null,+ durationMs !== null ? formatActionDurationMs(durationMs) : null,+ ].filter((part): part is string => part !== null);+ return { label, summary: parts.length > 0 ? parts.join(" · ") : null };+}+function countSchemaFields(value: WorkflowRunBlock["data_schema"]): number {if (!value || typeof value !== "object" || Array.isArray(value)) return 0;const properties = "properties" in value ? value.properties : null;@@ -350,6 +353,7 @@ type TimelineSubItemsProps = {activeIteration?: number | null;depth: number;blockOrder?: ReadonlyMap<string, number>;+ codeStepsByLabel?: ReadonlyMap<string, Array<CodeBlockStep>>;onBlockItemClick: (block: WorkflowRunBlock) => void;onIterationClick?: (loopBlock: WorkflowRunBlock,@@ -368,6 +372,7 @@ function TimelineSubItems({activeIteration = null,depth,blockOrder,+ codeStepsByLabel,onBlockItemClick,onIterationClick,onActionClick,@@ -389,6 +394,7 @@ function TimelineSubItems({block={item.block}depth={depth}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onActionClick={onActionClick}onBlockItemClick={onBlockItemClick}onIterationClick={onIterationClick}@@ -439,6 +445,7 @@ function TimelineActionRows({}: TimelineActionRowsProps) {const actions = block.actions ?? [];const actionsTopDown = [...actions].reverse();+ const isCodeBlock = block.block_type === "code";if (actions.length === 0) return null;@@ -449,8 +456,12 @@ function TimelineActionRows({isAction(activeItem) && activeItem.action_id === action.action_id;const displayIndex = index + 1;const icon = timelineActionIcons[action.action_type];- const label = ReadableActionTypes[action.action_type];- const summary = getActionSummary(action);+ const { label, summary } = isCodeBlock+ ? getCodeActionRowPresentation(action)+ : {+ label: ReadableActionTypes[action.action_type],+ summary: getActionSummary(action),+ };return (<div@@ -503,11 +514,91 @@ function TimelineActionRows({);}+function formatCodeStepLines(step: CodeBlockStep): string | null {+ if (step.line_start == null) {+ return null;+ }+ if (step.line_end == null || step.line_end === step.line_start) {+ return `L${step.line_start}`;+ }+ return `L${step.line_start}-${step.line_end}`;+}++type TimelineCodeStepRowsProps = {+ block: WorkflowRunBlock;+ steps: Array<CodeBlockStep>;+ depth: number;+ onBlockItemClick: (block: WorkflowRunBlock) => void;+};++// Code blocks have no recorded actions to enumerate, so surface their+// definition step outline beneath the block instead.+function TimelineCodeStepRows({+ block,+ steps,+ depth,+ onBlockItemClick,+}: TimelineCodeStepRowsProps) {+ if (steps.length === 0) return null;++ return (+ <div className="space-y-1 py-1">+ {steps.map((step, index) => {+ const lines = formatCodeStepLines(step);+ const summary =+ normalizeInlineText(step.title) ??+ normalizeInlineText(step.description);++ return (+ <div key={index} className="flex min-h-[24px] items-stretch text-xs">+ <IndentRails depth={depth} />+ <div+ className={cn(+ "flex min-w-0 flex-1 items-center gap-1.5 rounded-r py-0.5 pr-1.5",+ "hover:bg-slate-800/60",+ )}+ style={railHighlightStyle}+ >+ <div className="size-4 shrink-0" />+ <button+ type="button"+ onClick={(event) => {+ event.stopPropagation();+ onBlockItemClick(block);+ }}+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded text-left outline-none focus-visible:ring-1 focus-visible:ring-white/40"+ >+ <span className="w-7 shrink-0 text-[10px] tabular-nums text-slate-500">+ #{index + 1}+ </span>+ <span className="shrink-0 rounded border border-slate-700 px-1.5 py-0.5 text-[10px] font-medium text-slate-400">+ {step.action_type}+ </span>+ {summary && (+ <span className="min-w-0 flex-1 truncate text-slate-500">+ · {summary}+ </span>+ )}+ {lines && (+ <span className="shrink-0 text-[10px] tabular-nums text-slate-500">+ {lines}+ </span>+ )}+ </button>+ </div>+ </div>+ );+ })}+ </div>+ );+}+function WorkflowRunTimelineBlockItem({activeItem,activeIteration = null,block,blockOrder,+ codeStepsByLabel,subItems,depth = 0,onBlockItemClick,@@ -531,6 +622,13 @@ function WorkflowRunTimelineBlockItem({const actionCount = actions.length;const hasActions = actionCount > 0;+ // Code blocks without recorded actions fall back to their definition step+ // outline so the timeline still reflects what the block was meant to do.+ const codeSteps =+ block.block_type === "code" && !hasActions+ ? (codeStepsByLabel?.get(block.label ?? "") ?? [])+ : [];+ const hasCodeSteps = codeSteps.length > 0;const isForLoopBlock = block.block_type === "for_loop";const isWhileLoopBlock = block.block_type === "while_loop";const isLoopBlock = isForLoopBlock || isWhileLoopBlock;@@ -546,7 +644,7 @@ function WorkflowRunTimelineBlockItem({// the runtime didn't model any child blocks under them (e.g. conditionals// whose "next" block is a flat sibling), showing a chevron that reveals// nothing is worse than no chevron at all.- const isContainer = hasRenderableNestedChildren || hasActions;+ const isContainer = hasRenderableNestedChildren || hasActions || hasCodeSteps;// The loop block itself is only "active" when no specific iteration is// selected — otherwise the iteration row owns the highlight.@@ -723,6 +821,14 @@ function WorkflowRunTimelineBlockItem({workflowRunIsFinalized={workflowRunIsFinalized}/>)}+ {hasCodeSteps && (+ <TimelineCodeStepRows+ block={block}+ steps={codeSteps}+ depth={depth + 1}+ onBlockItemClick={onBlockItemClick}+ />+ )}{isLoopBlock && loopIterationGroups.length > 0 ? (<LoopIterationRowsloopBlock={block}@@ -731,6 +837,7 @@ function WorkflowRunTimelineBlockItem({activeIteration={activeIteration}depth={depth + 1}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onBlockItemClick={onBlockItemClick}onIterationClick={onIterationClick}onActionClick={onActionClick}@@ -747,6 +854,7 @@ function WorkflowRunTimelineBlockItem({activeIteration={activeIteration}depth={depth + 1}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onActionClick={onActionClick}onBlockItemClick={onBlockItemClick}onIterationClick={onIterationClick}@@ -771,6 +879,7 @@ type LoopIterationRowsProps = {activeIteration?: number | null;depth: number;blockOrder?: ReadonlyMap<string, number>;+ codeStepsByLabel?: ReadonlyMap<string, Array<CodeBlockStep>>;onBlockItemClick: (block: WorkflowRunBlock) => void;onIterationClick?: (loopBlock: WorkflowRunBlock,@@ -790,6 +899,7 @@ function LoopIterationRows({activeIteration = null,depth,blockOrder,+ codeStepsByLabel,onBlockItemClick,onIterationClick,onActionClick,@@ -815,6 +925,7 @@ function LoopIterationRows({activeIteration={activeIteration}depth={depth}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onBlockItemClick={onBlockItemClick}onIterationClick={onIterationClick}onActionClick={onActionClick}@@ -837,6 +948,7 @@ type LoopIterationRowProps = {activeIteration?: number | null;depth: number;blockOrder?: ReadonlyMap<string, number>;+ codeStepsByLabel?: ReadonlyMap<string, Array<CodeBlockStep>>;onBlockItemClick: (block: WorkflowRunBlock) => void;onIterationClick?: (loopBlock: WorkflowRunBlock,@@ -858,6 +970,7 @@ function LoopIterationRow({activeIteration = null,depth,blockOrder,+ codeStepsByLabel,onBlockItemClick,onIterationClick,onActionClick,@@ -967,6 +1080,7 @@ function LoopIterationRow({activeIteration={activeIteration}depth={depth + 1}blockOrder={blockOrder}+ codeStepsByLabel={codeStepsByLabel}onActionClick={onActionClick}onBlockItemClick={onBlockItemClick}onIterationClick={onIterationClick}diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.test.tsxnew file mode 100644index 000000000..05bd1f52c--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.test.tsx@@ -0,0 +1,195 @@+// @vitest-environment jsdom++vi.mock("@/routes/workflows/components/CodeEditor", () => ({+ CodeEditor: ({+ value,+ extraExtensions,+ }: {+ value: string;+ extraExtensions?: Array<unknown>;+ }) => (+ <div+ data-testid="code-editor"+ data-extension-count={String(extraExtensions?.length ?? 0)}+ >+ {value}+ </div>+ ),+}));++import { cleanup, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import { ActionsApiResponse, ActionTypes, Status } from "@/api/types";+import { CodeBlockParameters } from "./CodeBlockParameters";++function buildAction(+ overrides: Partial<ActionsApiResponse> = {},+): ActionsApiResponse {+ return {+ action_id: "wrb_code_action_0",+ action_type: ActionTypes.Click,+ status: Status.Completed,+ task_id: null,+ step_id: null,+ step_order: null,+ action_order: 0,+ confidence_float: null,+ description: null,+ reasoning: null,+ intention: null,+ response: null,+ created_by: null,+ text: null,+ ...overrides,+ };+}++afterEach(() => {+ cleanup();+});++describe("CodeBlockParameters", () => {+ it("wires the jinja highlight into the code editor", () => {+ render(+ <CodeBlockParameters+ code="print('{{ name }}')"+ blockStatus={Status.Completed}+ failureReason={null}+ actions={[]}+ />,+ );++ expect(+ screen.getByTestId("code-editor").getAttribute("data-extension-count"),+ ).toBe("2");+ });++ it("surfaces the goal and steps when provided", () => {+ render(+ <CodeBlockParameters+ code="x = 1"+ prompt="Find the top post"+ steps={[+ {+ description: "Open Hacker News",+ action_type: "goto_url",+ line_start: 1,+ line_end: 1,+ },+ {+ description: "Read the top title",+ action_type: "extract",+ line_start: 2,+ line_end: 3,+ },+ ]}+ blockStatus={Status.Completed}+ failureReason={null}+ actions={[]}+ />,+ );++ expect(screen.getByText("Find the top post")).toBeDefined();+ expect(screen.getByText("Open Hacker News")).toBeDefined();+ expect(screen.getByText("L2-3")).toBeDefined();+ });++ it("highlights the failing line in the code editor", () => {+ render(+ <CodeBlockParameters+ code={"x = 1\nraise ValueError('boom')"}+ blockStatus={Status.Failed}+ failureReason="boom"+ actions={[+ buildAction({+ action_type: ActionTypes.NullAction,+ status: Status.Failed,+ response: "boom",+ output: { code_line: 2 },+ }),+ ]}+ />,+ );++ // jinja (2) + error lineHighlight field + theme (2) = 4.+ expect(+ screen.getByTestId("code-editor").getAttribute("data-extension-count"),+ ).toBe("4");+ });++ it("renders a failing line callout when the block failed and an action carries a code line", () => {+ render(+ <CodeBlockParameters+ code={"x = 1\nraise ValueError('boom')"}+ blockStatus={Status.Failed}+ failureReason="division by zero"+ actions={[+ buildAction({+ action_id: "wrb_code_action_1",+ action_type: ActionTypes.NullAction,+ status: Status.Failed,+ response: "boom",+ output: { code_line: 7 },+ }),+ buildAction({+ action_id: "wrb_code_action_0",+ output: { code_line: 2, duration_ms: 120 },+ }),+ ]}+ />,+ );++ expect(+ screen.getByText(/Failed at line 7: division by zero/),+ ).toBeDefined();+ });++ it("falls back to the failing action response when the block has no failure reason", () => {+ render(+ <CodeBlockParameters+ code="raise ValueError('boom')"+ blockStatus={Status.Failed}+ failureReason={null}+ actions={[+ buildAction({+ action_type: ActionTypes.NullAction,+ status: Status.Failed,+ response: "ValueError: boom",+ output: { code_line: 1 },+ }),+ ]}+ />,+ );++ expect(+ screen.getByText(/Failed at line 1: ValueError: boom/),+ ).toBeDefined();+ });++ it("renders no callout when the block completed", () => {+ render(+ <CodeBlockParameters+ code="x = 1"+ blockStatus={Status.Completed}+ failureReason={null}+ actions={[buildAction({ output: { code_line: 1, duration_ms: 50 } })]}+ />,+ );++ expect(screen.queryByText(/Failed at line/)).toBeNull();+ });++ it("renders no callout when no failed action carries a code line", () => {+ render(+ <CodeBlockParameters+ code="x = 1"+ blockStatus={Status.Failed}+ failureReason="timed out"+ actions={[buildAction({ status: Status.Failed, output: null })]}+ />,+ );++ expect(screen.queryByText(/Failed at line/)).toBeNull();+ });+});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.tsxindex bba1f117d..e5e7c30fd 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockInfo/CodeBlockParameters.tsx@@ -1,12 +1,80 @@+import { useMemo } from "react";+import type { Extension } from "@uiw/react-codemirror";++import { ActionsApiResponse, Status } from "@/api/types";import { CodeEditor } from "@/routes/workflows/components/CodeEditor";-import type { WorkflowParameter } from "@/routes/workflows/types/workflowTypes";+import { jinjaHighlight } from "@/routes/workflows/components/jinjaHighlight";+import { lineHighlight } from "@/routes/workflows/components/lineHighlight";+import type {+ CodeBlockStep,+ WorkflowParameter,+} from "@/routes/workflows/types/workflowTypes";type Props = {code: string;parameters?: Array<WorkflowParameter>;+ prompt?: string | null;+ steps?: Array<CodeBlockStep> | null;+ blockStatus?: Status | null;+ failureReason?: string | null;+ actions?: Array<ActionsApiResponse> | null;};-function CodeBlockParameters({ code, parameters }: Props) {+function getActionCodeLine(action: ActionsApiResponse): number | null {+ const output = action.output;+ if (!output || typeof output !== "object" || Array.isArray(output)) {+ return null;+ }+ const codeLine = (output as Record<string, unknown>).code_line;+ return typeof codeLine === "number" ? codeLine : null;+}++function formatStepLines(step: CodeBlockStep): string {+ if (step.line_start == null) {+ return "";+ }+ if (step.line_end == null || step.line_end === step.line_start) {+ return `L${step.line_start}`;+ }+ return `L${step.line_start}-${step.line_end}`;+}++function CodeBlockParameters({+ code,+ parameters,+ prompt,+ steps,+ blockStatus,+ failureReason,+ actions,+}: Props) {+ // Actions arrive newest-first, so the first failed action carrying a code+ // line is the one that stopped the run.+ const failingAction =+ blockStatus === Status.Failed+ ? (actions ?? []).find(+ (action) =>+ action.status === Status.Failed &&+ getActionCodeLine(action) !== null,+ )+ : undefined;+ const failingLine = failingAction ? getActionCodeLine(failingAction) : null;+ const failingReason = failureReason ?? failingAction?.response ?? null;+ const codeExtensions = useMemo<Array<Extension>>(() => {+ if (failingLine == null) {+ return jinjaHighlight;+ }+ const failingLineExtensions = lineHighlight([+ { from: failingLine, to: failingLine, variant: "error" },+ ]);+ return [+ ...jinjaHighlight,+ ...(Array.isArray(failingLineExtensions)+ ? failingLineExtensions+ : [failingLineExtensions]),+ ];+ }, [failingLine]);+return (<div className="space-y-4"><div className="flex gap-16">@@ -16,15 +84,69 @@ function CodeBlockParameters({ code, parameters }: Props) {The Python snippet executed for this block</h2></div>- <CodeEditor- className="w-full"- language="python"- value={code}- readOnly- minHeight="160px"- maxHeight="400px"- />+ <div className="flex w-full min-w-0 flex-col gap-2">+ {failingLine !== null && (+ <div className="rounded border border-destructive/40 bg-destructive/10 px-2.5 py-2 text-xs leading-relaxed text-destructive">+ {`Failed at line ${failingLine}${failingReason ? `: ${failingReason}` : ""}`}+ </div>+ )}+ <CodeEditor+ className="w-full"+ language="python"+ value={code}+ readOnly+ minHeight="160px"+ maxHeight="400px"+ extraExtensions={codeExtensions}+ />+ </div></div>+ {prompt ? (+ <div className="flex gap-16">+ <div className="w-80">+ <h1 className="text-lg">Goal</h1>+ <h2 className="text-base text-slate-400">+ What this block is meant to accomplish+ </h2>+ </div>+ <div className="flex w-full min-w-0 items-start text-sm text-slate-200">+ {prompt}+ </div>+ </div>+ ) : null}+ {steps && steps.length > 0 ? (+ <div className="flex gap-16">+ <div className="w-80">+ <h1 className="text-lg">Steps</h1>+ <h2 className="text-base text-slate-400">+ Plain-language outline of the code+ </h2>+ </div>+ <ol className="flex w-full min-w-0 flex-col gap-1">+ {steps.map((step, index) => (+ <li+ key={index}+ className="flex items-center gap-2 rounded border border-slate-700/40 bg-slate-elevation3 px-2.5 py-1.5 text-xs"+ >+ <span className="w-5 shrink-0 tabular-nums text-slate-500">+ {index + 1}.+ </span>+ <span className="shrink-0 rounded border border-slate-700 px-1.5 py-0.5 text-[10px] text-slate-400">+ {step.action_type}+ </span>+ <span className="min-w-0 flex-1 truncate text-slate-300">+ {step.title ?? step.description}+ </span>+ {step.line_start != null ? (+ <span className="shrink-0 text-[10px] tabular-nums text-slate-500">+ {formatStepLines(step)}+ </span>+ ) : null}+ </li>+ ))}+ </ol>+ </div>+ ) : null}{parameters && parameters.length > 0 ? (<div className="flex gap-16"><div className="w-80">diff --git a/skyvern-frontend/src/store/useCopilotActionStore.test.ts b/skyvern-frontend/src/store/useCopilotActionStore.test.tsnew file mode 100644index 000000000..31a7c1271--- /dev/null+++ b/skyvern-frontend/src/store/useCopilotActionStore.test.ts@@ -0,0 +1,38 @@+import { beforeEach, describe, expect, test } from "vitest";++import { useCopilotActionStore } from "./useCopilotActionStore";++beforeEach(() => {+ useCopilotActionStore.setState({+ pendingBuild: null,+ generatingBlockLabel: null,+ cancelNonce: 0,+ });+});++describe("useCopilotActionStore", () => {+ test("requestBuild arms a pending build and marks the block generating", () => {+ useCopilotActionStore+ .getState()+ .requestBuild({ blockLabel: "open_page", prompt: "open the page" });++ const state = useCopilotActionStore.getState();+ expect(state.pendingBuild).toEqual({+ blockLabel: "open_page",+ prompt: "open the page",+ });+ expect(state.generatingBlockLabel).toBe("open_page");+ });++ test("requestCancel clears the pending build so a queued build cannot still arm", () => {+ const store = useCopilotActionStore.getState();+ store.requestBuild({ blockLabel: "open_page", prompt: "open the page" });++ store.requestCancel();++ const state = useCopilotActionStore.getState();+ expect(state.pendingBuild).toBeNull();+ expect(state.generatingBlockLabel).toBeNull();+ expect(state.cancelNonce).toBe(1);+ });+});diff --git a/skyvern-frontend/src/store/useCopilotActionStore.ts b/skyvern-frontend/src/store/useCopilotActionStore.tsnew file mode 100644index 000000000..cb327d24a--- /dev/null+++ b/skyvern-frontend/src/store/useCopilotActionStore.ts@@ -0,0 +1,35 @@+import { create } from "zustand";++export type CopilotBlockBuildRequest = {+ blockLabel: string;+ prompt: string;+};++interface CopilotActionStore {+ // A pending request for the copilot to (re)build a single code block from its prompt.+ pendingBuild: CopilotBlockBuildRequest | null;+ // Label of the block currently generating, so the block can show a local busy state.+ generatingBlockLabel: string | null;+ // Bumped when the user stops an in-flight block generation.+ cancelNonce: number;+ requestBuild: (request: CopilotBlockBuildRequest) => void;+ clearPendingBuild: () => void;+ finishGenerating: () => void;+ requestCancel: () => void;+}++export const useCopilotActionStore = create<CopilotActionStore>((set) => ({+ pendingBuild: null,+ generatingBlockLabel: null,+ cancelNonce: 0,+ requestBuild: (request) =>+ set({ pendingBuild: request, generatingBlockLabel: request.blockLabel }),+ clearPendingBuild: () => set({ pendingBuild: null }),+ finishGenerating: () => set({ generatingBlockLabel: null }),+ requestCancel: () =>+ set((state) => ({+ pendingBuild: null,+ generatingBlockLabel: null,+ cancelNonce: state.cancelNonce + 1,+ })),+}));