Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-12474): open Copilot pane on Discover → Studio handoff (#7457)
Aaron Perez0ef393a2beae
diff --git a/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.test.ts b/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.test.tsindex e26b5a512..e0a57381b 100644--- a/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.test.ts+++ b/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.test.ts@@ -14,6 +14,7 @@ import {forgetDiscoverCopilotPrompt,readDiscoverCopilotPrompt,rememberDiscoverCopilotPrompt,+ shouldOpenCopilotPaneForHandoff,useDiscoverCopilotPromptRecovery,withoutDiscoverViaParam,} from "./discoverCopilotHandoff";@@ -193,6 +194,48 @@ describe("discoverCopilotHandoff", () => {});});+describe("shouldOpenCopilotPaneForHandoff", () => {+ it("opens the Copilot pane for a studio handoff with a seeded prompt", () => {+ expect(+ shouldOpenCopilotPaneForHandoff({+ embedded: true,+ hasInitialCopilotMessage: true,+ copilotPaneOpen: false,+ }),+ ).toBe(true);+ });++ it("does not open outside the studio shell (non-embedded editor)", () => {+ expect(+ shouldOpenCopilotPaneForHandoff({+ embedded: false,+ hasInitialCopilotMessage: true,+ copilotPaneOpen: false,+ }),+ ).toBe(false);+ });++ it("does not open when there is no seeded prompt", () => {+ expect(+ shouldOpenCopilotPaneForHandoff({+ embedded: true,+ hasInitialCopilotMessage: false,+ copilotPaneOpen: false,+ }),+ ).toBe(false);+ });++ it("is a no-op when the Copilot pane is already open", () => {+ expect(+ shouldOpenCopilotPaneForHandoff({+ embedded: true,+ hasInitialCopilotMessage: true,+ copilotPaneOpen: true,+ }),+ ).toBe(false);+ });+});+describe("withoutDiscoverViaParam", () => {it("strips a via=discover param but keeps other params", () => {expect(withoutDiscoverViaParam("?via=discover&cache-key-value=abc")).toBe(diff --git a/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.ts b/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.tsindex 57b71f369..5c862a04e 100644--- a/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.ts+++ b/skyvern-frontend/src/routes/workflows/discoverCopilotHandoff.ts@@ -103,6 +103,24 @@ export function useDiscoverCopilotPromptRecovery({};}+// In the studio shell the Copilot's visibility is the copilot pane, not the+// non-embedded `isCopilotOpen` state. A Discover → Studio handoff lands with the+// prompt seeded but only the default editor+browser panes open, so the pane must+// be opened explicitly to surface the handed-off prompt. Off in the legacy+// (non-embedded) editor, which already opens Copilot from the seed, and a no-op+// when the pane is already open (e.g. a shared ?panes=copilot link).+export function shouldOpenCopilotPaneForHandoff(params: {+ embedded: boolean;+ hasInitialCopilotMessage: boolean;+ copilotPaneOpen: boolean;+}): boolean {+ return (+ params.embedded &&+ params.hasInitialCopilotMessage &&+ !params.copilotPaneOpen+ );+}+// Drops `via=discover` from a location.search string once the seed prompt it// pointed at has been consumed, so a later remount of the editor (e.g. via// browser back/forward) can't make useViaEntryPointCapture re-firediff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsxindex 3ee3286b0..a5fbefd57 100644--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx@@ -173,6 +173,7 @@ import { WorkflowCopilotChat } from "../copilot/WorkflowCopilotChat";import { useStudioRunId } from "../studio/useStudioRunId";import { copilotRunId } from "./copilotRunId";import {+ shouldOpenCopilotPaneForHandoff,useDiscoverCopilotPromptRecovery,withoutDiscoverViaParam,} from "../discoverCopilotHandoff";@@ -402,6 +403,24 @@ function Workspace({location.search,navigate,]);+ // A handoff (Discover or the onboarding CTA) lands with the prompt seeded but+ // only the default editor+browser panes open; open the Copilot pane once on+ // mount so the handed-off prompt is visible (the non-embedded editor opens+ // Copilot via isCopilotOpen's initializer below instead). Thread the handoff+ // route state through the pane-open navigation: the CTA seeds the prompt via+ // location.state alone (Discover also has a sessionStorage fallback), so a+ // state-wiping open would drop it before the Copilot consumes it.+ useMountEffect(() => {+ if (+ shouldOpenCopilotPaneForHandoff({+ embedded,+ hasInitialCopilotMessage: Boolean(initialCopilotMessage),+ copilotPaneOpen: studioCopilotOpen,+ })+ ) {+ openStudioPane("copilot", { state: location.state });+ }+ });const cacheKeyValueParam = searchParams.get("cache-key-value");const headlessTurnDrainEnabled = ["1", "true"].includes((searchParams.get("copilotHeadlessTurnDrain") ?? "").toLowerCase(),diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsxindex 7047dd60e..3f30d9be7 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx@@ -2,12 +2,14 @@import { useLayoutEffect, useMemo } from "react";import { cleanup, fireEvent, render, screen } from "@testing-library/react";-import { MemoryRouter } from "react-router-dom";+import { MemoryRouter, useLocation } from "react-router-dom";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";+import { useMountEffect } from "@/hooks/useMountEffect";import { useStudioFirstRunStore } from "@/store/StudioFirstRunStore";import { useStudioShellStore } from "@/store/StudioShellStore";+import { shouldOpenCopilotPaneForHandoff } from "../discoverCopilotHandoff";import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";import { useStudioPanes } from "./useStudioPanes";@@ -132,6 +134,114 @@ describe("cold-entry default panes (the four contexts)", () => {});});+// Mirrors Workspace's mount-effect wiring for the handoff into the studio shell:+// open the Copilot pane once when a seeded prompt lands, threading the handoff+// route state through so the pane-open navigation does not wipe it. `threadState`+// lets a test reproduce the pre-fix bug where the state was dropped.+function HandoffProbe({+ embedded = true,+ hasInitialCopilotMessage = true,+ threadState = true,+}: {+ embedded?: boolean;+ hasInitialCopilotMessage?: boolean;+ threadState?: boolean;+}) {+ const location = useLocation();+ const { panes, openPane } = useStudioPanes();+ const copilotPaneOpen = panes.includes("copilot");+ const copilotMessage = (location.state as { copilotMessage?: string } | null)+ ?.copilotMessage;+ useMountEffect(() => {+ if (+ shouldOpenCopilotPaneForHandoff({+ embedded,+ hasInitialCopilotMessage,+ copilotPaneOpen,+ })+ ) {+ openPane("copilot", threadState ? { state: location.state } : undefined);+ }+ });+ return (+ <div>+ <output data-testid="panes">{panes.join(",")}</output>+ <output data-testid="copilot-message">{copilotMessage ?? ""}</output>+ </div>+ );+}++function renderHandoff(+ props: {+ embedded?: boolean;+ hasInitialCopilotMessage?: boolean;+ threadState?: boolean;+ } = {},+ entry: string | { pathname: string; search?: string; state?: unknown } = {+ pathname: "/workflows/wpid_1/studio",+ search: "?via=discover",+ },+) {+ return render(+ <MemoryRouter initialEntries={[entry]}>+ <StudioPaneDefaultsProvider hasBlocks={false}>+ <HandoffProbe {...props} />+ </StudioPaneDefaultsProvider>+ </MemoryRouter>,+ );+}++function messageText(): string {+ return screen.getByTestId("copilot-message").textContent ?? "";+}++describe("Discover → Studio handoff opens the Copilot pane", () => {+ test("a seeded handoff opens Copilot on top of the default editor+browser", () => {+ renderHandoff();+ expect(panesText()).toBe("editor,browser,copilot");+ });++ test("no handoff prompt leaves the default panes untouched", () => {+ renderHandoff({ hasInitialCopilotMessage: false });+ expect(panesText()).toBe("editor,browser");+ });++ test("an explicit ?panes=copilot handoff is left as-is (no duplicate open)", () => {+ renderHandoff(+ {},+ {+ pathname: "/workflows/wpid_1/studio",+ search: "?via=discover&panes=copilot",+ },+ );+ expect(panesText()).toBe("copilot");+ });++ test("the pane-open navigation preserves the handoff route state (CTA has no sessionStorage fallback)", () => {+ renderHandoff(+ {},+ {+ pathname: "/workflows/wpid_1/studio",+ state: { copilotMessage: "Fill out the contact form" },+ },+ );+ expect(panesText()).toBe("editor,browser,copilot");+ expect(messageText()).toBe("Fill out the contact form");+ });++ test("a state-wiping open would drop the seeded prompt (regression guard)", () => {+ renderHandoff(+ { threadState: false },+ {+ pathname: "/workflows/wpid_1/studio",+ state: { copilotMessage: "Fill out the contact form" },+ },+ );+ expect(panesText()).toBe("editor,browser,copilot");+ expect(messageText()).toBe("");+ });+});+describe("narrow-viewport clamp of shared links", () => {const FOUR_PANES ="/workflows/wpid_1/studio?panes=copilot,editor,browser,overview";