Skip to content

Automate browser based workflows with AI

Bring the onboarding questionnaire back after a refresh (SKY-17343) (#8706)

Aaron Perez63aa0be136ed
diff --git a/skyvern-frontend/src/components/onboarding/GetStartedModal.questionnaire.test.tsx b/skyvern-frontend/src/components/onboarding/GetStartedModal.questionnaire.test.tsx
index 930abae71..af2f6fa3d 100644
--- a/skyvern-frontend/src/components/onboarding/GetStartedModal.questionnaire.test.tsx
+++ b/skyvern-frontend/src/components/onboarding/GetStartedModal.questionnaire.test.tsx
@@ -246,6 +246,7 @@ beforeEach(() => {
afterEach(() => {
cleanup();
+ mocks.confirmed.mockReset();
vi.clearAllMocks();
vi.restoreAllMocks();
});
@@ -642,6 +643,88 @@ describe("GetStartedModal", () => {
expect(mocks.telemetry.questionnaireShown).not.toHaveBeenCalled();
});
+ it.each([
+ ["after a refresh", { questionnaire_prompted_at: promptedAt }],
+ ["when another tab reserved first", {}],
+ [
+ "after a legacy modal dismissal",
+ {
+ questionnaire_prompted_at: promptedAt,
+ modal_dismissed_at: "2026-08-26T00:00:00Z",
+ },
+ ],
+ ])("resumes an unanswered questionnaire %s", async (_, initial) => {
+ mocks.confirmed.mockResolvedValueOnce({
+ ...response({ ...initial, questionnaire_prompted_at: promptedAt }),
+ questionnaire_prompt_result: { status: "already_prompted" },
+ });
+ render(<TestModal initialState={{ ...baseState, ...initial }} />);
+
+ expect(
+ await screen.findByText("What do you want to automate?"),
+ ).toBeTruthy();
+ expect(mocks.telemetry.questionnaireShown).toHaveBeenCalledWith(
+ expect.objectContaining({ promptReason: "resume" }),
+ );
+ });
+
+ it("stays closed when another tab answered before the resume reserve", async () => {
+ mocks.confirmed.mockResolvedValueOnce({
+ ...response({
+ questionnaire_prompted_at: promptedAt,
+ questionnaire: questionnaire(),
+ }),
+ questionnaire_prompt_result: { status: "already_prompted" },
+ });
+ render(
+ <TestModal
+ initialState={{ ...baseState, questionnaire_prompted_at: promptedAt }}
+ />,
+ );
+ await waitFor(() => expect(mocks.confirmed).toHaveBeenCalledOnce());
+ await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
+ expect(mocks.telemetry.questionnaireShown).not.toHaveBeenCalled();
+ });
+
+ it("closes a resumed questionnaire when Skip finds it answered in another tab", async () => {
+ mocks.confirmed
+ .mockResolvedValueOnce({
+ ...response({ questionnaire_prompted_at: promptedAt }),
+ questionnaire_prompt_result: { status: "already_prompted" },
+ })
+ .mockResolvedValueOnce({ code: "questionnaire_revision_conflict" });
+ render(
+ <TestModal
+ initialState={{ ...baseState, questionnaire_prompted_at: promptedAt }}
+ />,
+ );
+ fireEvent.click(await screen.findByRole("button", { name: "Skip" }));
+
+ await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
+ expect(
+ screen.queryByText("We couldn't save your choice. Try again."),
+ ).toBeNull();
+ });
+
+ it("keeps a skipped questionnaire closed", async () => {
+ render(
+ <TestModal
+ initialState={{
+ ...baseState,
+ questionnaire_prompted_at: promptedAt,
+ questionnaire: questionnaire({
+ status: "skipped",
+ completed_at: null,
+ skipped_at: promptedAt,
+ }),
+ }}
+ />,
+ );
+ await act(async () => undefined);
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect(mocks.confirmed).not.toHaveBeenCalled();
+ });
+
it.each(["modal_dismissed_at", "first_save_at"] as const)(
"ignores a stale reservation when %s changes while pending",
async (field) => {
diff --git a/skyvern-frontend/src/components/onboarding/GetStartedModal.tsx b/skyvern-frontend/src/components/onboarding/GetStartedModal.tsx
index f131648ff..47d811717 100644
--- a/skyvern-frontend/src/components/onboarding/GetStartedModal.tsx
+++ b/skyvern-frontend/src/components/onboarding/GetStartedModal.tsx
@@ -198,7 +198,6 @@ function GetStartedModalForUser() {
owner.kind === "deciding" &&
!isLoading &&
state !== null &&
- state.questionnaire_prompted_at == null &&
state.questionnaire == null;
const questionnaireLocallyIneligible =
user?.createdAt == null ||
@@ -260,7 +259,11 @@ function GetStartedModalForUser() {
return;
}
if (questionnaireLocallyIneligible) {
- if (state.modal_dismissed_at !== null || state.first_save_at !== null) {
+ if (
+ state.modal_dismissed_at !== null ||
+ state.first_save_at !== null ||
+ state.questionnaire_prompted_at != null
+ ) {
setOwner({ kind: "closed" });
return;
}
@@ -321,6 +324,17 @@ function GetStartedModalForUser() {
setStep("templates");
}
setOwner({ kind: "editor" });
+ } else if (
+ result?.status === "already_prompted" &&
+ response.onboarding_state.questionnaire == null
+ ) {
+ // A reservation that was never answered (refresh, closed tab, or another tab reserving first).
+ OnboardingTelemetry.questionnaireShown({
+ primaryIntent: null,
+ promptReason: "resume",
+ organizationId: response.organization_id ?? null,
+ });
+ setOwner({ kind: "questionnaire", step: "intent" });
} else {
setOwner({ kind: "closed" });
}
@@ -539,6 +553,15 @@ function GetStartedModalForUser() {
try {
const response = await updateStateConfirmed({ questionnaire: patch });
if ("code" in response) {
+ // A skip at revision 0 conflicts only when another tab already answered or skipped.
+ if (
+ patch.action === "skip" &&
+ patch.expected_revision === 0 &&
+ response.code === "questionnaire_revision_conflict"
+ ) {
+ setOwner({ kind: "closed" });
+ return;
+ }
if (response.code === "project_owner_invalid")
throw new Error(response.code);
throw new Error(`Questionnaire confirmation failed: ${response.code}`);
diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx
index 814bcb04b..def6de3b5 100644
--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.test.tsx
@@ -45,7 +45,10 @@ const mocks = vi.hoisted(() => ({
workflow: {
title: "Test workflow",
workflow_definition: {
- blocks: [],
+ blocks: [{ block_type: "navigation", label: "block_1" }] as Array<{
+ block_type: string;
+ label: string;
+ }>,
parameters: [],
},
run_with: "agent",
@@ -374,6 +377,32 @@ describe("RunWorkflowForm browser session reuse override", () => {
});
});
+describe("RunWorkflowForm empty agent", () => {
+ test("an agent with no blocks cannot be run and says why", async () => {
+ const blocks = mocks.workflow.workflow_definition.blocks;
+ mocks.workflow.workflow_definition.blocks = [];
+ try {
+ renderRunWorkflowForm();
+ const runButton = await screen.findByRole("button", {
+ name: "Run agent",
+ });
+ expect(runButton.hasAttribute("disabled")).toBe(true);
+ expect(screen.getByText("This agent has no blocks yet")).toBeTruthy();
+ fireEvent.click(runButton);
+ expect(mocks.post).not.toHaveBeenCalled();
+ } finally {
+ mocks.workflow.workflow_definition.blocks = blocks;
+ }
+ });
+
+ test("an agent with one block is runnable", async () => {
+ renderRunWorkflowForm();
+ const runButton = await screen.findByRole("button", { name: "Run agent" });
+ expect(runButton.hasAttribute("disabled")).toBe(false);
+ expect(screen.queryByText("This agent has no blocks yet")).toBeNull();
+ });
+});
+
describe("getRunWorkflowRequestBody — flag-off browser-memory payload", () => {
test("flag-off omits start_fresh_browser and sends browser-session reuse", () => {
const body = getRunWorkflowRequestBody(
diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
index 9bc57831e..8ef926002 100644
--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx
@@ -609,6 +609,8 @@ function RunWorkflowForm({
[workflow],
);
const hasLoginBlockValidationError = loginBlocksWithoutCredentials.length > 0;
+ // Mirrors the backend, which fails a run whose top-level block list is empty.
+ const hasNoBlocks = workflow?.workflow_definition.blocks.length === 0;
const onboarding = useOnboardingStateOptional();
const credentialFallbackRetryEnabled =
useFeatureFlag(CREDENTIAL_FALLBACK_RETRY_FLAG) ?? false;
@@ -958,7 +960,8 @@ function RunWorkflowForm({
disabled={
runWorkflowMutation.isPending ||
hasLoginBlockValidationError ||
- hasBlockingParameterError
+ hasBlockingParameterError ||
+ hasNoBlocks
}
>
{runWorkflowMutation.isPending && (
@@ -972,6 +975,22 @@ function RunWorkflowForm({
</div>
</header>
+ {hasNoBlocks && (
+ <Alert>
+ <ExclamationTriangleIcon className="h-4 w-4" />
+ <AlertTitle>This agent has no blocks yet</AlertTitle>
+ <AlertDescription>
+ <Link
+ to={workflowEditorPath(workflowPermanentId, studioEnabled)}
+ className="underline hover:no-underline"
+ >
+ Add a block
+ </Link>{" "}
+ or ask Copilot to build the agent, then run it.
+ </AlertDescription>
+ </Alert>
+ )}
+
{hasLoginBlockValidationError && isActivation && (
<CredentialSetupPrompt
workflowPermanentId={workflowPermanentId}
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index 8305e9bc6..b91a67960 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -1197,6 +1197,20 @@ function FlowRenderer({
setGetSaveDataRef.current(constructSaveData);
}, [constructSaveData, readOnly]);
+ const hasBlockNode = nodes.some(isWorkflowBlockNode);
+ useEffect(() => {
+ if (readOnly) {
+ return;
+ }
+ useWorkflowHasChangesStore.setState({ editorHasBlocks: hasBlockNode });
+ }, [hasBlockNode, readOnly]);
+ useEffect(() => {
+ if (readOnly) {
+ return;
+ }
+ return () => useWorkflowHasChangesStore.setState({ editorHasBlocks: null });
+ }, [readOnly]);
+
async function handleSave(): Promise<boolean> {
// With the YAML editor open (e.g. the nav-blocker "Save changes" dialog),
// persist the parsed draft directly instead of the stale pre-edit canvas.
diff --git a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.test.tsx b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.test.tsx
index 1a7418da1..afccd6009 100644
--- a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.test.tsx
@@ -5039,3 +5039,70 @@ test("the legacy editor does not mount a second recording controller outside Cop
expect(screen.queryByTestId("standalone-recording-panel")).toBeNull();
queryClient.clear();
});
+
+test("the canvas publishes whether it has a block for the studio Run control", () => {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ const adder: AppNode = {
+ id: "adder",
+ type: "nodeAdder",
+ position: { x: 0, y: 0 },
+ data: {},
+ } as AppNode;
+ const block: AppNode = {
+ id: "block",
+ type: "codeBlock",
+ position: { x: 0, y: 0 },
+ data: { ...codeBlockNodeDefaultData, label: "block" },
+ };
+ let replaceNodes!: (nodes: AppNode[]) => void;
+ function Canvas() {
+ const [nodes, setNodes] = useState<AppNode[]>([adder]);
+ replaceNodes = setNodes;
+ return (
+ <FlowRenderer
+ nodes={nodes}
+ edges={[]}
+ setNodes={vi.fn()}
+ setEdges={vi.fn()}
+ onNodesChange={vi.fn()}
+ onEdgesChange={vi.fn()}
+ initialTitle="Live agent"
+ workflow={liveWorkflow}
+ />
+ );
+ }
+ workflowQueryMock.mockReturnValue({ data: liveWorkflow, isLoading: false });
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ const view = render(
+ <QueryClientProvider client={client}>
+ <MemoryRouter>
+ <ReactFlowProvider>
+ <DebugStoreContext.Provider
+ value={{ isDebugMode: false, blockRunsEnabled: false }}
+ >
+ <Canvas />
+ </DebugStoreContext.Provider>
+ </ReactFlowProvider>
+ </MemoryRouter>
+ </QueryClientProvider>,
+ );
+ try {
+ expect(useWorkflowHasChangesStore.getState().editorHasBlocks).toBe(false);
+ act(() => replaceNodes([adder, block]));
+ expect(useWorkflowHasChangesStore.getState().editorHasBlocks).toBe(true);
+ } finally {
+ view.unmount();
+ client.clear();
+ vi.unstubAllGlobals();
+ }
+ expect(useWorkflowHasChangesStore.getState().editorHasBlocks).toBeNull();
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx b/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx
index 893996eca..6af30f55b 100644
--- a/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/BrowserPaneHeader.tsx
@@ -108,6 +108,9 @@ export function BrowserPaneViewPills() {
liveSurface,
debugBrowserSessionId,
runId,
+ recordingAvailable,
+ screenshotsAvailable,
+ liveAvailable,
} = useBrowserPaneView();
const loadingBrowser = useSettingsStore((s) => s.isLoadingABrowser);
// Studio's stream never reports ready to the route, so isLoadingABrowser
@@ -188,34 +191,40 @@ export function BrowserPaneViewPills() {
aria-label="Browser view"
className="flex shrink-0 items-center gap-1"
>
- <ViewToggle
- active={view === "live"}
- onClick={() => setView("live")}
- compact={compact}
- label={finishedRun ? "Debug browser" : "Live"}
- title={finishedRun ? FINISHED_RUN_BROWSER_LABEL : undefined}
- icon={
- finishedRun ? (
- <GlobeIcon className="h-3 w-3" />
- ) : (
- <span className="h-1.5 w-1.5 rounded-full bg-success motion-safe:animate-pulse" />
- )
- }
- />
- <ViewToggle
- active={view === "recording"}
- onClick={() => setView("recording")}
- compact={compact}
- label="Recording"
- icon={<PlayIcon className="h-3 w-3" />}
- />
- <ViewToggle
- active={view === "screenshots"}
- onClick={() => setView("screenshots")}
- compact={compact}
- label="Screenshots"
- icon={<ImageIcon className="h-3 w-3" />}
- />
+ {liveAvailable ? (
+ <ViewToggle
+ active={view === "live"}
+ onClick={() => setView("live")}
+ compact={compact}
+ label={finishedRun ? "Debug browser" : "Live"}
+ title={finishedRun ? FINISHED_RUN_BROWSER_LABEL : undefined}
+ icon={
+ finishedRun ? (
+ <GlobeIcon className="h-3 w-3" />
+ ) : (
+ <span className="h-1.5 w-1.5 rounded-full bg-success motion-safe:animate-pulse" />
+ )
+ }
+ />
+ ) : null}
+ {recordingAvailable ? (
+ <ViewToggle
+ active={view === "recording"}
+ onClick={() => setView("recording")}
+ compact={compact}
+ label="Recording"
+ icon={<PlayIcon className="h-3 w-3" />}
+ />
+ ) : null}
+ {screenshotsAvailable ? (
+ <ViewToggle
+ active={view === "screenshots"}
+ onClick={() => setView("screenshots")}
+ compact={compact}
+ label="Screenshots"
+ icon={<ImageIcon className="h-3 w-3" />}
+ />
+ ) : null}
</div>
</>
);
diff --git a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx
index 94b0aacf2..9924e5617 100644
--- a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx
@@ -37,10 +37,18 @@ const mocks = vi.hoisted(() => ({
debugSession: undefined as unknown,
runs: [] as Array<{ workflow_run_id: string }>,
realScreenshot: false,
+ artifactsByUrl: {} as Record<string, Array<Record<string, unknown>>>,
}));
vi.mock("@/api/AxiosClient", () => ({
- getClient: async () => ({ get: async () => ({ data: [] }) }),
+ getClient: async () => ({
+ get: async (url: string) => ({
+ data:
+ Object.entries(mocks.artifactsByUrl).find(([path]) =>
+ url.includes(path),
+ )?.[1] ?? [],
+ }),
+ }),
}));
vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({
@@ -291,6 +299,7 @@ beforeEach(() => {
mocks.debugSession = undefined;
mocks.runs = [];
mocks.realScreenshot = false;
+ mocks.artifactsByUrl = {};
});
afterEach(() => {
@@ -332,7 +341,7 @@ describe("BrowserTab view machine", () => {
});
it("keeps a recording deep link pinned when frame hydration updates", async () => {
- seedRun({ status: Status.Failed });
+ seedRun({ status: Status.Failed, recordingUrl: "https://r.test/1.mp4" });
renderBrowserPane(
"/workflows/wpid_test/studio?wr=wr_1&active=wrb_1&view=recording",
);
@@ -764,13 +773,117 @@ describe("BrowserTab view machine", () => {
expect(startRecording).toHaveBeenCalledOnce();
});
- it("a pinned Recording view without a recording shows the empty state", () => {
+ it("hides replay pills a finished run has nothing for, and restores them as artifacts arrive", () => {
+ seedRun({ status: Status.Running, browserSessionId: "pbs_test" });
+ mocks.timeline = [];
+ mocks.debugSession = { browser_session_id: "pbs_test" };
+ const { rerenderPane } = renderBrowserPane(
+ `${STUDIO_PATH}&wr=wr_1&view=recording`,
+ );
+ // Artifacts are written at finalize, so a running run keeps both pills.
+ expect(screen.getByRole("button", { name: "Recording" })).toBeTruthy();
+ expect(screen.getByRole("button", { name: "Screenshots" })).toBeTruthy();
+
+ mocks.workflowRun = Object.assign({}, mocks.workflowRun, {
+ status: Status.Completed,
+ });
+ rerenderPane();
+ expect(screen.queryByRole("button", { name: "Recording" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Screenshots" })).toBeNull();
+ expect(screen.queryByText("No recording for this run")).toBeNull();
+ expect(screen.getByTestId("browser-pane-stream-slot")).toBeTruthy();
+
+ // A persistent session uploads its recording when it closes, after the run.
+ mocks.workflowRun = Object.assign({}, mocks.workflowRun, {
+ recording_urls: ["https://r.test/1.mp4"],
+ });
+ rerenderPane();
+ expect(screen.getByTestId("hero-recording")).toBeTruthy();
+ expect(screen.queryByRole("button", { name: "Screenshots" })).toBeNull();
+ });
+
+ it.each([
+ {
+ name: "an earlier block's LLM screenshot, none on the last block",
+ timeline: () => [
+ buildBlockItem(
+ buildBlock({
+ workflow_run_block_id: "wrb_B",
+ block_type: "text_prompt",
+ created_at: "2026-01-01T00:01:00Z",
+ }),
+ ),
+ buildBlockItem(buildBlock({ workflow_run_block_id: "wrb_A" })),
+ ],
+ artifacts: { "workflow_run_block/wrb_A/": "screenshot_llm" },
+ },
+ {
+ name: "an earlier step's screenshot, none on the last step",
+ timeline: () => [
+ buildBlockItem(
+ buildBlock({
+ actions: [
+ buildAction({
+ action_id: "act_2",
+ step_id: "step_2",
+ screenshot_artifact_id: null,
+ }),
+ buildAction({
+ action_id: "act_1",
+ step_id: "step_1",
+ screenshot_artifact_id: null,
+ }),
+ ],
+ }),
+ ),
+ ],
+ artifacts: { "step/step_1/": "screenshot_action" },
+ },
+ ])(
+ "keeps Screenshots for a finished run with $name",
+ async ({ timeline, artifacts }) => {
+ seedRun({
+ status: Status.Completed,
+ recordingUrl: "https://r.test/1.mp4",
+ });
+ mocks.timeline = timeline();
+ mocks.artifactsByUrl = Object.fromEntries(
+ Object.entries(artifacts).map(([url, type]) => [
+ url,
+ [{ artifact_id: "art_x", artifact_type: type }],
+ ]),
+ );
+ mocks.debugSession = { browser_session_id: "pbs_test" };
+ renderBrowserPane(`${STUDIO_PATH}&wr=wr_1`);
+ // Let any artifact lookups settle, so a pill kept only while loading fails.
+ await act(() => new Promise((resolve) => setTimeout(resolve, 50)));
+
+ expect(screen.getByRole("button", { name: "Screenshots" })).toBeTruthy();
+ },
+ );
+
+ it("never strands a finished run with nothing to replay and no debug browser on an endless warm-up", () => {
+ seedRun({ status: Status.Running, browserSessionId: "pbs_run" });
+ mocks.timeline = [];
+ const { rerenderPane } = renderBrowserPane(`${STUDIO_PATH}&wr=wr_1`);
+ fireEvent.click(screen.getByRole("button", { name: "Live" }));
+
+ mocks.workflowRun = Object.assign({}, mocks.workflowRun, {
+ status: Status.Completed,
+ });
+ rerenderPane();
+ expect(screen.queryByRole("button", { name: "Debug browser" })).toBeNull();
+ expect(screen.queryByText("Warming up your browser")).toBeNull();
+ expect(screen.getByText("No screenshots for this run")).toBeTruthy();
+ });
+
+ it("sends a remembered Recording view to Screenshots when the finished run has no recording", () => {
seedRun({ status: Status.Completed });
mocks.debugSession = { browser_session_id: "pbs_test" };
- renderBrowserPane(`${STUDIO_PATH}&wr=wr_1`);
+ renderBrowserPane(`${STUDIO_PATH}&wr=wr_1&view=recording`);
- fireEvent.click(screen.getByRole("button", { name: "Recording" }));
- expect(screen.getByText("No recording for this run")).toBeTruthy();
+ expect(screen.queryByRole("button", { name: "Recording" })).toBeNull();
+ expect(screen.getByTestId("hero-screenshot")).toBeTruthy();
});
it("keeps an archived recording's pill live and explains it in the body", () => {
@@ -921,6 +1034,7 @@ describe("BrowserTab pills and selection sync", () => {
it("marks the resolved view's pill as pressed", () => {
seedRun({ status: Status.Completed, recordingUrl: "https://r.test/1.mp4" });
+ mocks.debugSession = { browser_session_id: "pbs_test" };
renderBrowserPane(`${STUDIO_PATH}&wr=wr_1`);
expect(
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx
index 4170cef73..de4fb292f 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx
@@ -846,3 +846,40 @@ describe("RunStopButton against a retained run payload", () => {
expect(screen.queryByRole("button", { name: /Stop/ })).not.toBeNull();
});
});
+
+describe("RunStopButton on an agent with no blocks", () => {
+ afterEach(() => {
+ useWorkflowHasChangesStore.setState({ editorHasBlocks: null });
+ });
+
+ test("Run is disabled while the editor has no blocks and enables once one is added", () => {
+ workflowRunQueryMock.mockReturnValue({ data: undefined });
+ useWorkflowHasChangesStore.setState({ editorHasBlocks: false });
+ renderAt("/workflows/wpid_1/studio");
+
+ const runButton = screen.getByRole("button", { name: "Run" });
+ expect(runButton.hasAttribute("disabled")).toBe(true);
+ fireEvent.click(runButton);
+ expect(screen.queryByTestId("location")).toBeNull();
+
+ act(() => {
+ useWorkflowHasChangesStore.setState({ editorHasBlocks: true });
+ });
+ expect(runButton.hasAttribute("disabled")).toBe(false);
+ fireEvent.click(runButton);
+ expect(screen.getByTestId("location").textContent).toBe(
+ "/agents/wpid_1/run",
+ );
+ });
+
+ test("a live block run does not offer a full run once the editor has no blocks", () => {
+ useWorkflowHasChangesStore.setState({ editorHasBlocks: false });
+ renderAt("/workflows/wpid_1/studio?wr=wr_1&bl=Block%201");
+
+ const runButton = screen.getByRole("button", { name: /Run/ });
+ expect(runButton.hasAttribute("disabled")).toBe(true);
+ fireEvent.click(runButton);
+ expect(screen.queryByText("Start a full run?")).toBeNull();
+ expect(screen.queryByRole("button", { name: /Stop/ })).not.toBeNull();
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
index c878c0086..a9b9cfc7c 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
@@ -343,6 +343,9 @@ export function InputsToggle() {
);
}
+const NO_BLOCKS_RUN_TOOLTIP =
+ "Add a block or ask Copilot to build the agent before running";
+
// stopOnly: global (read-only) workflows can't start runs from the studio, but
// runs started elsewhere (e.g. the recipe pages run templates in place) still
// land here and must be stoppable — render Stop when active, nothing otherwise.
@@ -368,6 +371,11 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {
// ?bl= marks the URL run as a block run; a full run can start alongside it
// (they execute concurrently), so Run stays available next to Stop.
const isBlockRun = searchParams.has("bl");
+ // Follows the editor's live (unsaved) canvas. With no editor mounted it is null,
+ // leaving the check to the run form.
+ const hasNoBlocks = useWorkflowHasChangesStore(
+ (s) => s.editorHasBlocks === false,
+ );
const rerunEligible = Boolean(
workflowRun &&
runIsLogicallyFinal(workflowRun) &&
@@ -465,15 +473,20 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {
<>
{stopDialog}
<Dialog>
- <DialogTrigger asChild>
- <Button
- size="default"
- className="h-8 border border-transparent px-3"
- disabled={isRecording}
- >
- <PlayIcon className="mr-2 size-4" /> Run
- </Button>
- </DialogTrigger>
+ <ControlTooltip
+ content={hasNoBlocks ? NO_BLOCKS_RUN_TOOLTIP : "Run workflow"}
+ blocked={isRecording || hasNoBlocks}
+ >
+ <DialogTrigger asChild>
+ <Button
+ size="default"
+ className="h-8 border border-transparent px-3"
+ disabled={isRecording || hasNoBlocks}
+ >
+ <PlayIcon className="mr-2 size-4" /> Run
+ </Button>
+ </DialogTrigger>
+ </ControlTooltip>
<DialogContent>
<DialogHeader>
<DialogTitle>Start a full run?</DialogTitle>
@@ -503,16 +516,18 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {
return (
<ControlTooltip
content={
- rerunEligible
- ? "Re-run with this run's inputs (opens the run form pre-filled)"
- : "Run workflow"
+ hasNoBlocks
+ ? NO_BLOCKS_RUN_TOOLTIP
+ : rerunEligible
+ ? "Re-run with this run's inputs (opens the run form pre-filled)"
+ : "Run workflow"
}
- blocked={isRecording}
+ blocked={isRecording || hasNoBlocks}
>
<Button
size="default"
className="h-8 border border-transparent px-3"
- disabled={isRecording}
+ disabled={isRecording || hasNoBlocks}
onClick={startFullRun}
>
<PlayIcon className="mr-2 size-4" />
diff --git a/skyvern-frontend/src/routes/workflows/studio/browserPaneView.test.ts b/skyvern-frontend/src/routes/workflows/studio/browserPaneView.test.ts
index 238c28e45..d6709cd15 100644
--- a/skyvern-frontend/src/routes/workflows/studio/browserPaneView.test.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/browserPaneView.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";
-import { resolveBrowserPaneView, resolveLiveSurface } from "./browserPaneView";
+import {
+ resolveBrowserPaneView,
+ resolveLiveSurface,
+ resolveReplayAvailability,
+} from "./browserPaneView";
// Most cases inspect an open run; edit-context cases override inspectingRun.
const base = {
@@ -13,6 +17,9 @@ const base = {
runInDebugSession: false,
running: false,
hasRecording: false,
+ recordingAvailable: true,
+ screenshotsAvailable: true,
+ hasDebugSession: true,
failed: false,
};
@@ -54,6 +61,61 @@ describe("resolveBrowserPaneView", () => {
).toBe("screenshots");
});
+ it("sends a stored replay intent to a view the finished run actually has", () => {
+ const finished = { ...base, recordingAvailable: false };
+ expect(resolveBrowserPaneView({ ...finished, intent: "recording" })).toBe(
+ "screenshots",
+ );
+ expect(
+ resolveBrowserPaneView({
+ ...base,
+ intent: "screenshots",
+ screenshotsAvailable: false,
+ hasRecording: true,
+ }),
+ ).toBe("recording");
+ const empty = { ...finished, screenshotsAvailable: false };
+ for (const intent of ["auto", "recording", "screenshots"] as const) {
+ expect(resolveBrowserPaneView({ ...empty, intent })).toBe("live");
+ }
+ expect(resolveBrowserPaneView({ ...empty, scrubbing: true })).toBe("live");
+ expect(resolveBrowserPaneView({ ...empty, hasDebugSession: false })).toBe(
+ "screenshots",
+ );
+ });
+
+ it("honours a stored Live intent on a finished run only while a debug browser exists", () => {
+ const finished = { ...base, intent: "live" as const, hasRecording: true };
+ expect(resolveBrowserPaneView(finished)).toBe("live");
+ expect(
+ resolveBrowserPaneView({ ...finished, hasDebugSession: false }),
+ ).toBe("recording");
+ expect(
+ resolveBrowserPaneView({
+ ...finished,
+ hasDebugSession: false,
+ running: true,
+ }),
+ ).toBe("live");
+ });
+
+ it("keeps a finished run's Screenshots pill until its timeline has loaded", () => {
+ const finished = {
+ finalized: true,
+ recordingUrls: [],
+ recordingArchived: false,
+ hasScreenshots: false,
+ };
+ expect(
+ resolveReplayAvailability({ ...finished, timeline: undefined })
+ .screenshotsAvailable,
+ ).toBe(true);
+ expect(
+ resolveReplayAvailability({ ...finished, timeline: [] })
+ .screenshotsAvailable,
+ ).toBe(false);
+ });
+
it("overrides a stored replay intent when a recording starts", () => {
for (const intent of ["recording", "screenshots"] as const) {
expect(
diff --git a/skyvern-frontend/src/routes/workflows/studio/browserPaneView.ts b/skyvern-frontend/src/routes/workflows/studio/browserPaneView.ts
index 5ee9f8ff3..1d3c27cd8 100644
--- a/skyvern-frontend/src/routes/workflows/studio/browserPaneView.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/browserPaneView.ts
@@ -1,5 +1,7 @@
import type { BrowserPaneViewIntent } from "@/store/useStudioBrowserStore";
+import type { RunVisuals } from "./useRunVisuals";
+
export type BrowserPaneView = "live" | "recording" | "screenshots";
type ResolveBrowserPaneViewArgs = {
@@ -21,6 +23,11 @@ type ResolveBrowserPaneViewArgs = {
runInDebugSession: boolean;
running: boolean;
hasRecording: boolean;
+ // Whether the header offers the Recording / Screenshots pill for this run.
+ recordingAvailable: boolean;
+ screenshotsAvailable: boolean;
+ // Live without a debug session is an open-ended "warming up" spinner.
+ hasDebugSession: boolean;
failed: boolean;
};
@@ -33,6 +40,30 @@ type ResolveLiveSurfaceArgs = {
hasRunId: boolean;
};
+// Artifacts are written at finalize, so a run still going keeps both pills.
+// The timeline check avoids hiding Screenshots before its data has loaded.
+export function resolveReplayAvailability(
+ visuals: Pick<
+ RunVisuals,
+ | "finalized"
+ | "recordingUrls"
+ | "recordingArchived"
+ | "timeline"
+ | "hasScreenshots"
+ >,
+): { recordingAvailable: boolean; screenshotsAvailable: boolean } {
+ return {
+ recordingAvailable:
+ !visuals.finalized ||
+ visuals.recordingUrls.length > 0 ||
+ visuals.recordingArchived,
+ screenshotsAvailable:
+ !visuals.finalized ||
+ visuals.timeline === undefined ||
+ visuals.hasScreenshots,
+ };
+}
+
/**
* What the Live view shows: the shared debug-session singleton, or the
* inspected run's own per-run stream (running outside the debug session).
@@ -66,6 +97,9 @@ export function resolveBrowserPaneView({
runInDebugSession,
running,
hasRecording,
+ recordingAvailable,
+ screenshotsAvailable,
+ hasDebugSession,
failed,
}: ResolveBrowserPaneViewArgs): BrowserPaneView {
// An active recording outranks everything, stored replay intents included:
@@ -74,18 +108,20 @@ export function resolveBrowserPaneView({
if (recording || !inspectingRun) {
return "live";
}
- if (intent === "live") {
+ // A finished run's Live view is the debug browser; without one it would be an
+ // endless "warming up", so a stored Live intent falls through to the replays.
+ if (intent === "live" && (running || hasDebugSession)) {
return "live";
}
- // A pinned replay intent always presents its surface; when the run has no
- // recording/screenshots (yet), the pane body renders the empty state.
- if (intent === "recording") {
+ // A pinned replay intent presents its surface only while its pill is offered;
+ // a finished run with nothing to replay there falls through to the default.
+ if (intent === "recording" && recordingAvailable) {
return "recording";
}
- if (intent === "screenshots") {
+ if (intent === "screenshots" && screenshotsAvailable) {
return "screenshots";
}
- if (scrubbing) {
+ if (scrubbing && screenshotsAvailable) {
return "screenshots";
}
// System focus keeps Live only while the run is still on that browser; a
@@ -99,5 +135,15 @@ export function resolveBrowserPaneView({
if (running) {
return "live";
}
- return hasRecording && !failed ? "recording" : "screenshots";
+ if (hasRecording && !failed) {
+ return "recording";
+ }
+ if (screenshotsAvailable) {
+ return "screenshots";
+ }
+ if (recordingAvailable) {
+ return "recording";
+ }
+ // Nothing to replay: the debug browser if one exists, else the empty state.
+ return hasDebugSession ? "live" : "screenshots";
}
diff --git a/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts b/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts
index 4b7515df9..33e28e1e2 100644
--- a/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts
@@ -12,6 +12,7 @@ import {
import { useDebugSessionQuery } from "../hooks/useDebugSessionQuery";
import {
resolveBrowserPaneView,
+ resolveReplayAvailability,
resolveLiveSurface,
type BrowserPaneView,
} from "./browserPaneView";
@@ -35,6 +36,9 @@ type BrowserPaneViewState = {
// What the Live view shows: the shared debug-session singleton, or the
// inspected run's own per-run stream (running outside the debug session).
liveSurface: "debug" | "run";
+ recordingAvailable: boolean;
+ screenshotsAvailable: boolean;
+ liveAvailable: boolean;
};
/**
@@ -123,6 +127,9 @@ export function useBrowserPaneView(): BrowserPaneViewState {
visuals.workflowRun.browser_session_id === debugBrowserSessionId;
const blockRunInDebugSession = searchParams.has("bl") && runInDebugSession;
+ const { recordingAvailable, screenshotsAvailable } =
+ resolveReplayAvailability(visuals);
+
const view = resolveBrowserPaneView({
intent,
recording: isRecording,
@@ -133,6 +140,9 @@ export function useBrowserPaneView(): BrowserPaneViewState {
runInDebugSession,
running: visuals.running,
hasRecording: visuals.recordingUrls.length > 0,
+ recordingAvailable,
+ screenshotsAvailable,
+ hasDebugSession: debugBrowserSessionId != null,
failed: visuals.failed,
});
@@ -152,5 +162,8 @@ export function useBrowserPaneView(): BrowserPaneViewState {
debugBrowserSessionId,
runInDebugSession,
liveSurface,
+ recordingAvailable,
+ screenshotsAvailable,
+ liveAvailable: visuals.running || debugBrowserSessionId != null,
};
}
diff --git a/skyvern-frontend/src/routes/workflows/studio/useRunVisuals.test.tsx b/skyvern-frontend/src/routes/workflows/studio/useRunVisuals.test.tsx
index 01b55fb36..1ebd82685 100644
--- a/skyvern-frontend/src/routes/workflows/studio/useRunVisuals.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/useRunVisuals.test.tsx
@@ -13,7 +13,10 @@ import type {
WorkflowRunTimelineItem,
} from "../types/workflowRunTypes";
import { useRunVisuals } from "./useRunVisuals";
-import { resolveBrowserPaneView } from "./browserPaneView";
+import {
+ resolveBrowserPaneView,
+ resolveReplayAvailability,
+} from "./browserPaneView";
const { mocks, getClientMock } = vi.hoisted(() => ({
mocks: {
@@ -164,6 +167,24 @@ beforeEach(() => useRunViewStore.getState().reset());
describe("useRunVisuals loop-iteration threading", () => {
test("keeps the auto browser pane live across a retry delay until the run is final", () => {
seedLoopRun();
+ // The final attempt captured a screenshot, so its replay has a surface.
+ mocks.timeline = [
+ {
+ ...buildBlockItem(
+ buildBlock({
+ actions: [
+ {
+ action_id: "act_1",
+ step_id: "step_1",
+ action_order: 0,
+ screenshot_artifact_id: "art_1",
+ } as NonNullable<WorkflowRunBlock["actions"]>[number],
+ ],
+ }),
+ ),
+ attempt: 2,
+ },
+ ];
mocks.workflowRun = { status: Status.Running };
const { result, rerender } = renderHook(
() => {
@@ -180,6 +201,8 @@ describe("useRunVisuals loop-iteration threading", () => {
runInDebugSession: false,
running: visuals.running,
hasRecording: visuals.recordingUrls.length > 0,
+ ...resolveReplayAvailability(visuals),
+ hasDebugSession: true,
failed: visuals.failed,
}),
};
diff --git a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts b/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
index 13f8bab76..a611156c9 100644
--- a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
+++ b/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
@@ -71,6 +71,8 @@ type WorkflowHasChangesStore = {
// Reference-counted flag: multiple concurrent internal updates won't
// accidentally clear each other. Gate on > 0 in consumers.
internalUpdateCount: number;
+ // Whether the mounted editor canvas has any block node; null when no editor is mounted.
+ editorHasBlocks: boolean | null;
setGetSaveData: (getSaveData: () => SaveData) => void;
setHasChanges: (
hasChanges: boolean,
@@ -153,6 +155,7 @@ const useWorkflowHasChangesStore = create<WorkflowHasChangesStore>(
pendingRecordingId: null,
pendingRecordingWorkflowPermanentId: null,
internalUpdateCount: 0,
+ editorHasBlocks: null,
getSaveData: () => null,
hydrateSavedSettings: null,
setGetSaveData: (getSaveData: () => SaveData) => {
diff --git a/skyvern-frontend/src/util/onboarding/OnboardingTelemetry.ts b/skyvern-frontend/src/util/onboarding/OnboardingTelemetry.ts
index d22b47648..592096b9a 100644
--- a/skyvern-frontend/src/util/onboarding/OnboardingTelemetry.ts
+++ b/skyvern-frontend/src/util/onboarding/OnboardingTelemetry.ts
@@ -18,7 +18,7 @@ type TourLayer = 1 | 2;
type QuestionnaireShownInput = {
primaryIntent: QuestionnaireUserIntentV1 | null;
- promptReason: "initial";
+ promptReason: "initial" | "resume";
organizationId: string | null;
};
diff --git a/skyvern/forge/sdk/copilot/tools/__init__.py b/skyvern/forge/sdk/copilot/tools/__init__.py
index 13d9866e3..0929f5c57 100644
--- a/skyvern/forge/sdk/copilot/tools/__init__.py
+++ b/skyvern/forge/sdk/copilot/tools/__init__.py
@@ -1854,7 +1854,7 @@ async def inspect_page_for_composition_tool(
"source_browser_session_id": source_browser_session_id,
}
scrubbed = scrub_secrets_from_structure(copilot_ctx, stamped)
- model_result = _model_facing_inspect_result(scrubbed)
+ model_result = _model_facing_inspect_result(scrubbed, copilot_ctx=copilot_ctx)
record_tool_step_result_for_ctx(copilot_ctx, "inspect_page_for_composition", arguments, model_result)
return json.dumps(model_result)
diff --git a/skyvern/forge/sdk/copilot/tools/banned_blocks.py b/skyvern/forge/sdk/copilot/tools/banned_blocks.py
index a2284b151..9ac769b18 100644
--- a/skyvern/forge/sdk/copilot/tools/banned_blocks.py
+++ b/skyvern/forge/sdk/copilot/tools/banned_blocks.py
@@ -275,6 +275,16 @@ def _copilot_authoring_capability(ctx: AgentContext | None) -> AuthoringCapabili
return authoring_capability_from_policy(policy)
+_FILE_UPLOAD_ROUTES: tuple[dict[str, str], ...] = ({"route": "attach_authorized_file", "input": "file_url parameter"},)
+
+
+def upload_routes_for(ctx: AgentContext | None) -> list[dict[str, str]]:
+ """How a file input can be filled by a turn that may author code blocks, empty when it may not."""
+ if not _copilot_authoring_capability(ctx).code_blocks:
+ return []
+ return [dict(route) for route in _FILE_UPLOAD_ROUTES]
+
+
def _copilot_banned_block_types(ctx: AgentContext | None) -> frozenset[str]:
return _banned_block_types_for_capability(_copilot_authoring_capability(ctx))
diff --git a/skyvern/forge/sdk/copilot/tools/composition_capture.py b/skyvern/forge/sdk/copilot/tools/composition_capture.py
index ec8580f38..14deab6f8 100644
--- a/skyvern/forge/sdk/copilot/tools/composition_capture.py
+++ b/skyvern/forge/sdk/copilot/tools/composition_capture.py
@@ -99,6 +99,7 @@ from ._shared import (
_requested_capture_targets,
_workflow_verification_evidence,
)
+from .banned_blocks import upload_routes_for
from .blockers import _allows_post_run_current_page_inspection_budget_bypass
from .discovery import _resolve_discovery_entry_url
from .guardrails import _authority_tool_error
@@ -140,7 +141,18 @@ _COMPOSITION_VISUAL_SUMMARY_TIMEOUT_SECONDS = 10.0
_COMPOSITION_VISUAL_SUMMARY_PROMPT_NAME = "workflow-copilot-page-evidence-vision"
-def _model_facing_inspect_result(result: dict[str, Any]) -> dict[str, Any]:
+def _attach_field_upload_routes(data: dict[str, Any], upload_routes: list[dict[str, str]]) -> None:
+ if not upload_routes:
+ return
+ for form in data.get("forms") or []:
+ if not isinstance(form, dict):
+ continue
+ for field in form.get("fields") or []:
+ if isinstance(field, dict) and field.get("type") == "file":
+ field["upload_routes"] = [dict(route) for route in upload_routes]
+
+
+def _model_facing_inspect_result(result: dict[str, Any], *, copilot_ctx: AgentContext | None = None) -> dict[str, Any]:
"""Detach stored evidence, remove locator recommendations, and fit the complete model packet."""
if result.get("ok") is not True:
return result
@@ -148,6 +160,7 @@ def _model_facing_inspect_result(result: dict[str, Any]) -> dict[str, Any]:
data = shaped.get("data")
if isinstance(data, dict):
shaped["data"] = model_visible_composition_evidence(data)
+ _attach_field_upload_routes(shaped["data"], upload_routes_for(copilot_ctx))
if len(json.dumps(shaped)) <= _RECENT_TOOL_OUTPUT_CHAR_CAP:
return shaped
data = shaped.get("data")
@@ -1484,7 +1497,7 @@ async def _inspect_page_for_composition_under_custody(
await _bind_login_credential_for_observed_url(copilot_ctx, str(current_url), result)
if observation_step is not None:
result["observation_step"] = observation_step
- result = _model_facing_inspect_result(result)
+ result = _model_facing_inspect_result(result, copilot_ctx=copilot_ctx)
if visual_fallback_frame is not None:
workflow_run_id = evidence.get("workflow_run_id")
enqueue_screenshot(
diff --git a/skyvern/forge/sdk/copilot/tools/scouting.py b/skyvern/forge/sdk/copilot/tools/scouting.py
index 055789f23..090db0134 100644
--- a/skyvern/forge/sdk/copilot/tools/scouting.py
+++ b/skyvern/forge/sdk/copilot/tools/scouting.py
@@ -105,6 +105,7 @@ from ._shared import (
_same_page_ignoring_fragment,
_workflow_verification_evidence,
)
+from .banned_blocks import upload_routes_for
LOG = structlog.get_logger()
@@ -1409,11 +1410,22 @@ def _summary_disclosure_control(control: dict[str, Any], scrub_values: Sequence[
return summary
-def _summary_entry(text: str, control: dict[str, Any]) -> dict[str, Any]:
- return {"text": text, **_summary_element_facts(control)}
+def _summary_entry(
+ text: str, control: dict[str, Any], *, upload_routes: Sequence[dict[str, str]] = ()
+) -> dict[str, Any]:
+ entry: dict[str, Any] = {"text": text, **_summary_element_facts(control)}
+ if upload_routes and control.get("type") == "file":
+ entry["type"] = "file"
+ entry["upload_routes"] = [dict(route) for route in upload_routes]
+ return entry
-def _build_scout_page_summary(evidence: dict[str, Any], scrub_values: Sequence[str] = ()) -> dict[str, Any]:
+def _build_scout_page_summary(
+ evidence: dict[str, Any],
+ scrub_values: Sequence[str] = (),
+ *,
+ upload_routes: Sequence[dict[str, str]] = (),
+) -> dict[str, Any]:
forms_summary: list[dict[str, Any]] = []
for form in evidence.get("forms") or []:
if not isinstance(form, dict):
@@ -1424,7 +1436,7 @@ def _build_scout_page_summary(evidence: dict[str, Any], scrub_values: Sequence[s
{
"field_count": len(fields),
"fields": [
- _summary_entry(name, field)
+ _summary_entry(name, field, upload_routes=upload_routes)
for field, name in (
(field, _summary_field_name(field, scrub_values)) for field in fields[:_PAGE_SUMMARY_MAX_FIELDS]
)
@@ -1535,8 +1547,19 @@ def _build_scout_page_summary(evidence: dict[str, Any], scrub_values: Sequence[s
return page_summary
+def _selectorless_summary_entry(entry: dict[str, Any] | str) -> dict[str, Any] | str:
+ """The bare text an entry carries, or a text-plus-route entry when it carries an upload route."""
+ if not isinstance(entry, dict):
+ return entry
+ text = str(entry.get("text") or "")
+ upload_routes = entry.get("upload_routes")
+ if not upload_routes:
+ return text
+ return {"text": text, "type": entry.get("type"), "upload_routes": upload_routes}
+
+
def _drop_scout_page_summary_selectors(summary: dict[str, Any]) -> bool:
- """Collapse every control entry to the bare text it carries, and report whether anything changed."""
+ """Strip every control entry down to the facts selectors are not, and report whether anything changed."""
dropped = False
groups: list[Any] = [summary.get("navigation_targets"), summary.get("modal_dismiss_controls")]
for layer in summary.get("interaction_blocking_layers") or []:
@@ -1552,7 +1575,7 @@ def _drop_scout_page_summary_selectors(summary: dict[str, Any]) -> bool:
for entries in groups:
if not isinstance(entries, list):
continue
- collapsed = [str(entry.get("text") or "") if isinstance(entry, dict) else entry for entry in entries]
+ collapsed = [_selectorless_summary_entry(entry) for entry in entries]
if collapsed != entries:
entries[:] = collapsed
dropped = True
@@ -1636,7 +1659,9 @@ def _attach_scout_page_summary(ctx: AgentContext, result: dict[str, Any], page_e
if not isinstance(data, dict):
return
try:
- summary = _redact_summary_node(ctx, _build_scout_page_summary(page_evidence))
+ summary = _redact_summary_node(
+ ctx, _build_scout_page_summary(page_evidence, upload_routes=upload_routes_for(ctx))
+ )
if not isinstance(summary, dict):
return
data["page"] = summary
diff --git a/skyvern/webeye/skycdp/facade/elements.py b/skyvern/webeye/skycdp/facade/elements.py
index 7cdf9259f..68e2e9499 100644
--- a/skyvern/webeye/skycdp/facade/elements.py
+++ b/skyvern/webeye/skycdp/facade/elements.py
@@ -10,17 +10,20 @@ from __future__ import annotations
import asyncio
import base64
-from collections.abc import Awaitable
+from collections.abc import Awaitable, Callable
from pathlib import Path
-from typing import TYPE_CHECKING, Any, TypedDict
+from typing import TYPE_CHECKING, Any, TypedDict, TypeVar
import structlog
from skyvern.webeye.skycdp.errors import CdpError, CdpExecutionContextLost, CdpTimeoutError
from skyvern.webeye.skycdp.facade.evaluation import RemoteHandle, evaluate
+from skyvern.webeye.skycdp.facade.timeouts import DEFAULT_ACTION_TIMEOUT_MS, seconds_from_ms
LOG = structlog.get_logger()
+_T = TypeVar("_T")
+
class FilePayload(TypedDict):
name: str
@@ -69,6 +72,90 @@ async def _wait_presented(wait: Awaitable[Any]) -> None:
LOG.warning("skycdp could not wait for a frame to render before clicking", exc_info=True)
+# null when the element can never hold text, otherwise whether it is editable now. isContentEditable is
+# false on every form control, and readonly is read as the attribute because <select> has no readOnly property.
+_EDITABLE_JS = """
+function(allowSelect) {
+ const name = this.localName;
+ const control = name === 'input' || name === 'textarea' || (allowSelect && name === 'select');
+ if (!control && (name === 'select' || !this.isContentEditable)) return null;
+ return !this.matches(':disabled') && !(control && this.hasAttribute('readonly'));
+}
+"""
+
+
+# Playwright's fill rules by input type: text-like types take typed text, date/range-like types take an assigned
+# value plus input/change events, and every other type (checkbox, file, button...) cannot be filled. With checkOnly
+# it returns 'ok' after the refusals and touches nothing, so a refused fill never moves focus.
+_PREPARE_FILL_JS = """
+function([value, checkOnly]) {
+ if (this.localName === 'input') {
+ const type = this.type.toLowerCase();
+ const assigned = ['color', 'date', 'time', 'datetime-local', 'month', 'range', 'week'].includes(type);
+ const typed = ['', 'email', 'number', 'password', 'search', 'tel', 'text', 'url'].includes(type);
+ if (!assigned && !typed) return 'type:' + type;
+ if (type === 'number' && isNaN(Number(value.trim()))) return 'not-a-number';
+ if (checkOnly) return 'ok';
+ if (assigned) {
+ value = value.trim();
+ this.value = value;
+ if (this.value !== value) return 'malformed';
+ this.dispatchEvent(new Event('input', {bubbles: true, composed: true}));
+ this.dispatchEvent(new Event('change', {bubbles: true}));
+ return 'done';
+ }
+ this.select();
+ return type === 'number' ? 'trim' : 'typed';
+ }
+ if (checkOnly) return 'ok';
+ if (this.select) { this.select(); return 'typed'; }
+ const range = this.ownerDocument.createRange();
+ range.selectNodeContents(this);
+ const selection = this.ownerDocument.defaultView.getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+ return 'typed';
+}
+"""
+
+
+def _raise_if_refused(outcome: str) -> None:
+ if outcome == "malformed":
+ raise CdpError("fill: Malformed value")
+ if outcome == "not-a-number":
+ raise CdpError("fill: Cannot type text into input[type=number]")
+ if outcome.startswith("type:"):
+ raise CdpError(f'fill: Input of type "{outcome[5:]}" cannot be filled')
+
+
+def not_editable_error(name: str, timeout: float | None) -> CdpTimeoutError:
+ budget = DEFAULT_ACTION_TIMEOUT_MS if timeout is None else timeout
+ return CdpTimeoutError(f"{name}: element is not editable (read-only or disabled) within {budget}ms")
+
+
+async def wait_until_editable(
+ probe: Callable[[], Awaitable[_T | None]], *, timeout: float | None, on_deadline: Callable[[], CdpTimeoutError]
+) -> _T:
+ """Only the budget running out becomes ``on_deadline()``; a CdpTimeoutError the probe raises is an
+ unanswered CDP call and propagates as itself."""
+ probe_timeout: CdpTimeoutError | None = None
+
+ async def guarded() -> _T | None:
+ nonlocal probe_timeout
+ try:
+ return await probe()
+ except CdpTimeoutError as exc:
+ probe_timeout = exc
+ raise
+
+ try:
+ return await wait_for(guarded, timeout=seconds_from_ms(timeout), description="element to be editable")
+ except CdpTimeoutError as exc:
+ if exc is probe_timeout:
+ raise
+ raise on_deadline() from exc
+
+
_CLICK_POINT_JS = """
function() {
this.scrollIntoViewIfNeeded ? this.scrollIntoViewIfNeeded(false)
@@ -203,11 +290,16 @@ class ElementHandle(JSHandle):
)
async def is_editable(self) -> bool:
- return bool(
- await self._bound(
- "function() { return !this.disabled && !this.readOnly && this.isContentEditable !== false; }"
- )
- )
+ editable = await self._bound(_EDITABLE_JS, True)
+ if editable is None:
+ raise CdpError("Element is not an <input>, <textarea>, <select> or [contenteditable] element")
+ return bool(editable)
+
+ async def _fillable(self, name: str) -> bool:
+ editable = await self._bound(_EDITABLE_JS, False)
+ if editable is None:
+ raise CdpError(f"{name}: element is not an <input>, <textarea> or [contenteditable] element")
+ return bool(editable)
async def bounding_box(self) -> dict[str, float] | None:
box = await self._bound(
@@ -288,25 +380,28 @@ class ElementHandle(JSHandle):
await self._bound("function() { this.blur(); }")
async def fill(self, value: str, *, timeout: float | None = None, **_: Any) -> None:
- """Replace the element's content using only trusted events.
-
- Focus, select everything already there, then either commit the new text with
- ``Input.insertText`` or -- for an empty value -- delete the selection. Chrome raises the
- resulting ``input`` event itself, so a framework's change handler sees ``isTrusted`` true
- and keeps the value instead of reverting it on the next render.
- """
+ async def fillable() -> bool:
+ # wait_for retries a lost context, but a handle cannot follow a navigation, so fail now.
+ try:
+ return await self._fillable("fill")
+ except CdpExecutionContextLost as exc:
+ raise CdpError("fill: Element is not attached to the DOM") from exc
+
+ await wait_until_editable(fillable, timeout=timeout, on_deadline=lambda: not_editable_error("fill", timeout))
+ await self._commit_fill(value)
+
+ # Commits with trusted Input.insertText, or a Delete for an empty value, so a framework's input handler
+ # sees isTrusted and keeps the value instead of reverting it on the next render.
+ async def _commit_fill(self, value: str) -> None:
+ _raise_if_refused(await self._bound(_PREPARE_FILL_JS, [value, True]))
await self.scroll_into_view_if_needed()
await self.focus()
- await self._bound(
- """function() {
- if (this.select) { this.select(); return; }
- const range = this.ownerDocument.createRange();
- range.selectNodeContents(this);
- const selection = this.ownerDocument.defaultView.getSelection();
- selection.removeAllRanges();
- selection.addRange(range);
- }"""
- )
+ outcome = await self._bound(_PREPARE_FILL_JS, [value, False])
+ _raise_if_refused(outcome)
+ if outcome == "done":
+ return
+ if outcome == "trim":
+ value = value.strip()
keyboard = self._frame.page.keyboard
if value:
await keyboard.insert_text(value)
diff --git a/skyvern/webeye/skycdp/facade/locator.py b/skyvern/webeye/skycdp/facade/locator.py
index a238f070f..f3e964cbd 100644
--- a/skyvern/webeye/skycdp/facade/locator.py
+++ b/skyvern/webeye/skycdp/facade/locator.py
@@ -12,7 +12,13 @@ from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from skyvern.webeye.skycdp.errors import CdpError, CdpTimeoutError
-from skyvern.webeye.skycdp.facade.elements import ElementHandle, InputFiles, wait_for
+from skyvern.webeye.skycdp.facade.elements import (
+ ElementHandle,
+ InputFiles,
+ not_editable_error,
+ wait_for,
+ wait_until_editable,
+)
from skyvern.webeye.skycdp.facade.timeouts import DEFAULT_ACTION_TIMEOUT_MS, seconds_from_ms
if TYPE_CHECKING:
@@ -642,8 +648,36 @@ class Locator:
try:
return await self.element_handle(timeout=timeout)
except CdpTimeoutError as exc:
- budget = DEFAULT_ACTION_TIMEOUT_MS if timeout is None else timeout
- raise CdpTimeoutError(f"{name}: no element matched {self._selector!r} within {budget}ms") from exc
+ raise self._no_match_error(name, timeout) from exc
+
+ def _no_match_error(self, name: str, timeout: float | None) -> CdpTimeoutError:
+ budget = DEFAULT_ACTION_TIMEOUT_MS if timeout is None else timeout
+ return CdpTimeoutError(f"{name}: no element matched {self._selector!r} within {budget}ms")
+
+ async def _act_editable(self, name: str, timeout: float | None) -> ElementHandle:
+ """Resolution and editability share one budget, and every poll re-resolves so a re-rendered
+ element is seen. Each rejected handle is released, or a long refusal pins one remote object per poll."""
+ matched = False
+
+ async def resolve_editable() -> ElementHandle | None:
+ nonlocal matched
+ handle = await self._resolve()
+ matched = handle is not None
+ if handle is None:
+ return None
+ editable = False
+ try:
+ editable = await handle._fillable(name)
+ finally:
+ if not editable:
+ await handle.dispose()
+ return handle if editable else None
+
+ return await wait_until_editable(
+ resolve_editable,
+ timeout=timeout,
+ on_deadline=lambda: not_editable_error(name, timeout) if matched else self._no_match_error(name, timeout),
+ )
# -- reads --------------------------------------------------------------
@@ -722,11 +756,13 @@ class Locator:
async def blur(self, timeout: float | None = None) -> None:
await (await self._act("blur", timeout)).blur()
- async def fill(self, value: str, timeout: float | None = None) -> None:
- await (await self._act("fill", timeout)).fill(value)
+ # force and no_wait_after are accepted as Playwright's are, but force never skips the editability wait:
+ # text sent to a read-only field is silently dropped, which is the failure that wait exists to report.
+ async def fill(self, value: str, timeout: float | None = None, **_: Any) -> None:
+ await (await self._act_editable("fill", timeout))._commit_fill(value)
- async def clear(self, timeout: float | None = None) -> None:
- await (await self._act("clear", timeout)).fill("")
+ async def clear(self, timeout: float | None = None, **_: Any) -> None:
+ await (await self._act_editable("clear", timeout))._commit_fill("")
async def type(self, text: str, delay: float | None = None, timeout: float | None = None) -> None:
await (await self._act("type", timeout)).type(text, delay=delay)
diff --git a/tests/unit/test_copilot_scout_act_observe.py b/tests/unit/test_copilot_scout_act_observe.py
index 8e4817d51..a106a211d 100644
--- a/tests/unit/test_copilot_scout_act_observe.py
+++ b/tests/unit/test_copilot_scout_act_observe.py
@@ -42,7 +42,7 @@ from skyvern.forge.sdk.copilot.composition_evidence import (
has_witnessed_value_content,
parse_composition_structured,
)
-from skyvern.forge.sdk.copilot.config import CopilotConfig
+from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy, CopilotConfig
from skyvern.forge.sdk.copilot.context import (
CopilotContext,
SignedOutPageObservation,
@@ -67,6 +67,7 @@ from skyvern.forge.sdk.copilot.secret_scrub import (
from skyvern.forge.sdk.copilot.tools import _click_post_hook
from skyvern.forge.sdk.copilot.tools import mcp_hooks as mcp_hooks_module
from skyvern.forge.sdk.copilot.tools import scouting as scouting_module
+from skyvern.forge.sdk.copilot.tools.composition_capture import _model_facing_inspect_result
from skyvern.forge.sdk.copilot.tools.scouting import (
_SCOUT_RESULT_CHAR_CAP,
_SIGNED_OUT_TEXT_EXCERPT_CAP,
@@ -3373,3 +3374,125 @@ async def test_visible_effect_pre_frame_is_dropped_when_the_click_skips_its_post
assert held_during_dispatch == [True]
assert ctx.pending_scout_click_pre_frame is None
+
+
+_FILE_FIELD_EVIDENCE: dict[str, Any] = {
+ "page_title": "Certificate vault",
+ "forms": [
+ {
+ "id": "vault-form",
+ "fields": [
+ {
+ "name": "file",
+ "id": "certificate-file",
+ "label": "Certificate file",
+ "type": "file",
+ "required": True,
+ "selector_candidates": [{"selector": "#certificate-file"}],
+ },
+ {
+ "name": "notes",
+ "id": "notes",
+ "label": "Notes",
+ "type": "text",
+ "selector_candidates": [{"selector": "#notes"}],
+ },
+ ],
+ "submit_controls": [{"text": "Submit to vault", "selector_candidates": [{"selector": "#vault-submit"}]}],
+ }
+ ],
+}
+
+_EXPECTED_UPLOAD_ROUTES = [{"route": "attach_authorized_file", "input": "file_url parameter"}]
+
+
+def _upload_route_ctx(*, code_blocks: bool) -> CopilotContext:
+ return CopilotContext(
+ organization_id="o_upload_route",
+ workflow_id="w_upload_route",
+ workflow_permanent_id="wpid_upload_route",
+ workflow_yaml="workflow_definition:\n blocks: []\n",
+ browser_session_id=None,
+ stream=MagicMock(),
+ block_authoring_policy=(BlockAuthoringPolicy.STANDARD if code_blocks else BlockAuthoringPolicy.TASK_V3_PURE),
+ )
+
+
+def _scout_summary_fields(ctx: CopilotContext) -> list[dict[str, Any]]:
+ result: dict[str, Any] = {"ok": True, "data": {}}
+ scouting_module._attach_scout_page_summary(ctx, result, copy.deepcopy(_FILE_FIELD_EVIDENCE))
+ return result["data"]["page"]["forms"][0]["fields"]
+
+
+def test_upload_route_reaches_page_facts_when_code_blocks_are_authorized() -> None:
+ ctx = _upload_route_ctx(code_blocks=True)
+ assert ctx.authoring_capability.code_blocks is True
+
+ scouted_file, scouted_text = _scout_summary_fields(ctx)
+ assert scouted_file["text"] == "Certificate file"
+ assert scouted_file["type"] == "file"
+ assert scouted_file["upload_routes"] == _EXPECTED_UPLOAD_ROUTES
+ assert "upload_routes" not in scouted_text and "type" not in scouted_text
+
+ inspected = _model_facing_inspect_result({"ok": True, "data": copy.deepcopy(_FILE_FIELD_EVIDENCE)}, copilot_ctx=ctx)
+ inspected_file, inspected_text = inspected["data"]["forms"][0]["fields"]
+ assert inspected_file["type"] == "file"
+ assert inspected_file["upload_routes"] == _EXPECTED_UPLOAD_ROUTES
+ assert "upload_routes" not in inspected_text
+
+
+def test_upload_route_absent_from_page_facts_when_code_blocks_are_not_authorized() -> None:
+ ctx = _upload_route_ctx(code_blocks=False)
+ assert ctx.authoring_capability.code_blocks is False
+
+ scouted_file = _scout_summary_fields(ctx)[0]
+ assert scouted_file["text"] == "Certificate file"
+ assert "upload_routes" not in scouted_file
+ assert "type" not in scouted_file
+
+ inspected = _model_facing_inspect_result({"ok": True, "data": copy.deepcopy(_FILE_FIELD_EVIDENCE)}, copilot_ctx=ctx)
+ assert "upload_routes" not in inspected["data"]["forms"][0]["fields"][0]
+
+
+def _shedding_file_field_evidence() -> dict[str, Any]:
+ evidence = copy.deepcopy(_FILE_FIELD_EVIDENCE)
+ fields = evidence["forms"][0]["fields"]
+ for field in fields:
+ field["selector_candidates"] = [
+ {"selector": f"form#vault-form >> [data-testid='{field['id']}-candidate-{index}']", "match_count": 1}
+ for index in range(4)
+ ]
+ field["identity"] = {"tag": "input", "aria_label": f"{field['label']} for the records vault intake step"}
+ fields.extend(
+ {
+ "name": f"mailing_preference_{index}",
+ "id": f"mailing-preference-{index}",
+ "label": f"Account holder mailing preference {index}",
+ "type": "text",
+ "selector_candidates": [
+ {"selector": f"form#vault-form >> [data-testid='mailing-preference-{index}-candidate-{inner}']"}
+ for inner in range(4)
+ ],
+ "identity": {"tag": "input", "aria_label": f"Account holder mailing preference {index}"},
+ }
+ for index in range(8)
+ )
+ return evidence
+
+
+def test_upload_route_survives_the_scout_summary_selector_shed() -> None:
+ ctx = _upload_route_ctx(code_blocks=True)
+ evidence = _shedding_file_field_evidence()
+ assert len(json.dumps(scouting_module._build_scout_page_summary(evidence))) > _SCOUT_RESULT_CHAR_CAP
+
+ result: dict[str, Any] = {"ok": True, "data": {}}
+ scouting_module._attach_scout_page_summary(ctx, result, evidence)
+ page = result["data"]["page"]
+ assert "control_selectors" in page["shed"]
+
+ shed_file_field = page["forms"][0]["fields"][0]
+ assert shed_file_field["text"] == "Certificate file"
+ assert shed_file_field["type"] == "file"
+ assert shed_file_field["upload_routes"] == _EXPECTED_UPLOAD_ROUTES
+ assert "selector_candidates" not in shed_file_field and "identity" not in shed_file_field
+ assert page["forms"][0]["fields"][1] == "Notes"