Skip to content

Automate browser based workflows with AI

Keep Copilot on the right during recording (#8596)

Cindy Lifc02544ef34b
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx
index 544b04c51..a15c8140a 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx
@@ -9,7 +9,10 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { type StudioPaneId } from "./panes";
import { paneAccessibleName } from "./paneMeta";
import { paneExpansionKeyframes } from "./paneLayout";
-import { panesAfterRecordingTransition } from "./recordingPaneLifecycle";
+import {
+ advanceRecordingStopLifecycle,
+ panesAfterRecordingTransition,
+} from "./recordingPaneLifecycle";
import { EmbeddedBrowserOverlays, StudioPane } from "./StudioShell";
vi.mock("./useRunVisuals", () => ({
@@ -41,7 +44,7 @@ describe("panesAfterRecordingTransition", () => {
test("replaces the Editor with Browser and Copilot when recording starts", () => {
expect(
panesAfterRecordingTransition(["overview", "editor"], "started"),
- ).toEqual(["overview", "copilot", "browser"]);
+ ).toEqual(["overview", "browser", "copilot"]);
});
test("replaces Browser with Editor when a recording starts processing", () => {
@@ -50,13 +53,61 @@ describe("panesAfterRecordingTransition", () => {
["overview", "copilot", "browser"],
"processing",
),
- ).toEqual(["overview", "copilot", "editor"]);
+ ).toEqual(["overview", "editor", "copilot"]);
});
- test("restores Editor but leaves Browser open when recording ends without processing", () => {
+ test("restores Editor but leaves Browser open when recording is discarded", () => {
expect(
panesAfterRecordingTransition(["copilot", "browser"], "ended"),
- ).toEqual(["copilot", "browser", "editor"]);
+ ).toEqual(["browser", "editor", "copilot"]);
+ });
+
+ test("remembers zero-action Done without leaking into the next Discard", () => {
+ let lifecycle = advanceRecordingStopLifecycle(false, {
+ isRecording: true,
+ wasRecording: false,
+ finishRequested: false,
+ processingRecording: false,
+ });
+
+ lifecycle = advanceRecordingStopLifecycle(lifecycle.finishWasRequested, {
+ isRecording: true,
+ wasRecording: true,
+ finishRequested: true,
+ processingRecording: true,
+ });
+ expect(lifecycle).toEqual({
+ finishWasRequested: true,
+ transition: null,
+ });
+
+ lifecycle = advanceRecordingStopLifecycle(lifecycle.finishWasRequested, {
+ isRecording: false,
+ wasRecording: true,
+ finishRequested: false,
+ processingRecording: false,
+ });
+ expect(lifecycle).toEqual({
+ finishWasRequested: false,
+ transition: "processing",
+ });
+
+ lifecycle = advanceRecordingStopLifecycle(lifecycle.finishWasRequested, {
+ isRecording: true,
+ wasRecording: false,
+ finishRequested: false,
+ processingRecording: false,
+ });
+ lifecycle = advanceRecordingStopLifecycle(lifecycle.finishWasRequested, {
+ isRecording: false,
+ wasRecording: true,
+ finishRequested: false,
+ processingRecording: false,
+ });
+ expect(lifecycle).toEqual({
+ finishWasRequested: false,
+ transition: "ended",
+ });
});
test("does not duplicate panes already in the requested layout", () => {
@@ -65,7 +116,7 @@ describe("panesAfterRecordingTransition", () => {
["copilot", "browser", "editor"],
"started",
),
- ).toEqual(["copilot", "browser"]);
+ ).toEqual(["browser", "copilot"]);
});
});
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
index 4ca8c5ac1..a0013f655 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
@@ -71,7 +71,10 @@ import {
} from "./panes";
import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";
import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";
-import { panesAfterRecordingTransition } from "./recordingPaneLifecycle";
+import {
+ advanceRecordingStopLifecycle,
+ panesAfterRecordingTransition,
+} from "./recordingPaneLifecycle";
import {
StudioPaneCompactContext,
StudioShellContext,
@@ -919,9 +922,20 @@ function StudioStage(props: StudioWorkspaceProps) {
finishRequested || isCommitting || recordedBlocksPending;
const prevIsRecordingRef = useRef(false);
const prevProcessingRef = useRef(false);
+ const finishWasRequestedRef = useRef(false);
useEffect(() => {
const wasRecording = prevIsRecordingRef.current;
const wasProcessing = prevProcessingRef.current;
+ const stopLifecycle = advanceRecordingStopLifecycle(
+ finishWasRequestedRef.current,
+ {
+ isRecording,
+ wasRecording,
+ finishRequested,
+ processingRecording,
+ },
+ );
+ finishWasRequestedRef.current = stopLifecycle.finishWasRequested;
if (processingRecording && !wasProcessing) {
restoreExpandedPane();
if (finishRequested || isCommitting || wasRecording) {
@@ -934,10 +948,12 @@ function StudioStage(props: StudioWorkspaceProps) {
// Recording → live browser + Copilot guidance.
restoreExpandedPane();
setOpenPanes(panesAfterRecordingTransition(panes, "started"));
- } else if (!isRecording && wasRecording && !processingRecording) {
- // Discarded recording → restore the canvas without closing Browser.
+ } else if (stopLifecycle.transition !== null) {
+ // Done removes Browser; Discard restores the canvas without closing it.
restoreExpandedPane();
- setOpenPanes(panesAfterRecordingTransition(panes, "ended"));
+ setOpenPanes(
+ panesAfterRecordingTransition(panes, stopLifecycle.transition),
+ );
}
prevIsRecordingRef.current = isRecording;
prevProcessingRef.current = processingRecording;
diff --git a/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts b/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts
index a73bdccab..9a996d006 100644
--- a/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts
@@ -2,21 +2,53 @@ import { type StudioPaneId } from "./panes";
type RecordingPaneTransition = "started" | "processing" | "ended";
+export function advanceRecordingStopLifecycle(
+ finishWasRequested: boolean,
+ state: {
+ isRecording: boolean;
+ wasRecording: boolean;
+ finishRequested: boolean;
+ processingRecording: boolean;
+ },
+): {
+ finishWasRequested: boolean;
+ transition: RecordingPaneTransition | null;
+} {
+ let nextFinishWasRequested =
+ state.isRecording && !state.wasRecording ? false : finishWasRequested;
+ if (state.finishRequested) {
+ nextFinishWasRequested = true;
+ }
+ const transition =
+ !state.isRecording && state.wasRecording && !state.processingRecording
+ ? nextFinishWasRequested
+ ? "processing"
+ : "ended"
+ : null;
+ if (!state.isRecording && !state.processingRecording) {
+ nextFinishWasRequested = false;
+ }
+ return { finishWasRequested: nextFinishWasRequested, transition };
+}
+
export function panesAfterRecordingTransition(
panes: readonly StudioPaneId[],
transition: RecordingPaneTransition,
): StudioPaneId[] {
+ const hadCopilot = panes.includes("copilot");
const next = panes.filter((pane) => {
if (transition === "started") {
- return pane !== "editor";
+ return pane !== "editor" && pane !== "copilot";
}
if (transition === "processing") {
- return pane !== "browser";
+ return pane !== "browser" && pane !== "copilot";
}
- return true;
+ return pane !== "copilot";
});
const requiredPanes: StudioPaneId[] =
- transition === "started" ? ["copilot", "browser"] : ["editor"];
+ transition === "started"
+ ? ["browser", "copilot"]
+ : ["editor", ...(hadCopilot ? (["copilot"] as const) : [])];
for (const pane of requiredPanes) {
if (!next.includes(pane)) {