Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Preserve onboarding example attribution (#SKY-16818) (#8633)
Cindy Li0e6274ff8cc8
diff --git a/skyvern-frontend/src/routes/tasks/create/CapabilityExamples.tsx b/skyvern-frontend/src/routes/tasks/create/CapabilityExamples.tsxindex 5a0a0aba0..b58a6c5a5 100644--- a/skyvern-frontend/src/routes/tasks/create/CapabilityExamples.tsx+++ b/skyvern-frontend/src/routes/tasks/create/CapabilityExamples.tsx@@ -22,7 +22,7 @@ import "./capabilityExamples.css";type Capability = "forms" | "extract" | "login" | "monitor" | "schedule";-type Example = { label: string; prompt: string; icon: ReactNode };+type Example = { id: string; label: string; prompt: string; icon: ReactNode };type Group = {capability: Capability;@@ -76,12 +76,14 @@ const GROUPS: ReadonlyArray<Group> = [),examples: [{+ id: "forms.apply_for_job",label: "Apply for a job",icon: <EnvelopeClosedIcon />,prompt:"Go to https://jobs.lever.co/leverdemo-8, find the first Solutions Engineer role in Toronto, and apply with the attached resume. Fill in the name and email, submit, and confirm the application went through.",},{+ id: "forms.get_quote",label: "Get a quote",icon: <FileTextIcon />,prompt:@@ -116,12 +118,14 @@ const GROUPS: ReadonlyArray<Group> = [),examples: [{+ id: "extract.scrape_catalog",label: "Scrape a catalog",icon: <TableIcon />,prompt:"Go to the vendor's product listing, page through every result, and collect the SKU, name, price, and stock level for each item.",},{+ id: "extract.extract_to_json",label: "Extract to JSON",icon: <CodeIcon />,prompt:@@ -168,12 +172,14 @@ const GROUPS: ReadonlyArray<Group> = [),examples: [{+ id: "login.download_invoices",label: "Download invoices",icon: <DownloadIcon />,prompt:"Log in to the supplier portal with the saved credentials and download every invoice from last month as PDF.",},{+ id: "login.export_report",label: "Export a report",icon: <LockClosedIcon />,prompt:@@ -213,12 +219,14 @@ const GROUPS: ReadonlyArray<Group> = [),examples: [{+ id: "monitor.watch_price",label: "Watch a price",icon: <GraphIcon className="size-[22px]" />,prompt:"Check the competitor's pricing page every morning and message me when the Pro plan price changes.",},{+ id: "monitor.track_shipment",label: "Track a shipment",icon: TruckIcon,prompt:@@ -247,12 +255,14 @@ const GROUPS: ReadonlyArray<Group> = [),examples: [{+ id: "schedule.weekly_summary",label: "Weekly summary",icon: <CalendarIcon />,prompt:"Log in to the analytics dashboard, download last week's report, and email it to the team.",},{+ id: "schedule.daily_sync",label: "Daily sync",icon: <ClockIcon />,prompt:@@ -265,7 +275,12 @@ const GROUPS: ReadonlyArray<Group> = [// Three groups on top, two centered beneath, at every width.const GROUP_ROWS = [GROUPS.slice(0, 3), GROUPS.slice(3)];-type Selection = { capability: Capability; label: string; prompt: string };+type Selection = {+ id: string;+ capability: Capability;+ label: string;+ prompt: string;+};type Props = {disabled?: boolean;@@ -296,6 +311,7 @@ function CapabilityExamples({ disabled = false, onSelect, onPreview }: Props) {onOpenChange={(open) => {if (open) {onPreview?.({+ id: example.id,capability: group.capability,label: example.label,});@@ -308,6 +324,7 @@ function CapabilityExamples({ disabled = false, onSelect, onPreview }: Props) {disabled={disabled}onClick={() =>onSelect({+ id: example.id,capability: group.capability,label: example.label,prompt: example.prompt,diff --git a/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx b/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsxindex 76799307d..7613ef3da 100644--- a/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx+++ b/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx@@ -17,7 +17,7 @@ import {type SVGProps,type TextareaHTMLAttributes,} from "react";-import { afterEach, describe, expect, test, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { ToastAction } from "@/components/ui/toast";import { toast } from "@/components/ui/use-toast";@@ -222,6 +222,10 @@ function renderPromptBox();}+beforeEach(() => {+ vi.stubGlobal("matchMedia", () => ({ matches: true }));+});+afterEach(() => {cleanup();sessionStorage.clear();@@ -234,6 +238,7 @@ afterEach(() => {authState.userId = "user-a";currentOrgState.organizationId = "org-a";vi.mocked(toast).mockReset();+ vi.unstubAllGlobals();});async function submitPrompt(text: string) {@@ -534,6 +539,124 @@ describe("PromptBox", () => {);});+ test("preserves an unedited redesign example through creation outcomes", async () => {+ mockPost.mockResolvedValue({+ data: {+ workflow_permanent_id: "wpid_example",+ workflow_definition: { blocks: [] },+ },+ });++ renderPromptBox(false, undefined, true);+ fireEvent.click(screen.getByRole("button", { name: "Apply for a job" }));+ fireEvent.click(screen.getByLabelText("submit-prompt"));++ await waitFor(() =>+ expect(mockPostHogCapture).toHaveBeenCalledWith(+ "home.agent_creation_succeeded",+ expect.objectContaining({ workflow_permanent_id: "wpid_example" }),+ ),+ );++ for (const event of [+ "home.agent_creation_submitted",+ "home.prompt_submitted",+ "home.agent_creation_succeeded",+ ]) {+ expect(mockPostHogCapture).toHaveBeenCalledWith(+ event,+ expect.objectContaining({+ source: "example",+ example: "forms.apply_for_job",+ example_edited: false,+ }),+ );+ }+ expect(JSON.stringify(mockPostHogCapture.mock.calls)).not.toContain(+ "Solutions Engineer",+ );+ });++ test("keeps example origin when the seeded prompt is edited", async () => {+ mockPost.mockResolvedValue({+ data: {+ workflow_permanent_id: "wpid_edited_example",+ workflow_definition: { blocks: [] },+ },+ });++ renderPromptBox(false, undefined, true);+ fireEvent.click(screen.getByRole("button", { name: "Scrape a catalog" }));+ const textarea = screen.getByRole("textbox");+ fireEvent.change(textarea, {+ target: {+ value: `${(textarea as HTMLTextAreaElement).value} Include URLs.`,+ },+ });+ fireEvent.click(screen.getByLabelText("submit-prompt"));++ await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));+ expect(mockPostHogCapture).toHaveBeenCalledWith(+ "home.agent_creation_submitted",+ expect.objectContaining({+ source: "example",+ example: "extract.scrape_catalog",+ example_edited: true,+ }),+ );+ });++ test("clears example attribution after an explicit reset", async () => {+ mockPost.mockResolvedValue({+ data: {+ workflow_permanent_id: "wpid_typed_replacement",+ workflow_definition: { blocks: [] },+ },+ });++ renderPromptBox(false, undefined, true);+ fireEvent.click(screen.getByRole("button", { name: "Get a quote" }));+ const textarea = screen.getByRole("textbox");+ fireEvent.change(textarea, { target: { value: "" } });+ fireEvent.change(textarea, { target: { value: "Check a public page" } });+ fireEvent.click(screen.getByLabelText("submit-prompt"));++ await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));+ const submitted = mockPostHogCapture.mock.calls.find(+ ([event]) => event === "home.agent_creation_submitted",+ )?.[1];+ expect(submitted).toMatchObject({+ source: "typed",+ variant: "revamp",+ });+ expect(submitted).not.toHaveProperty("example");+ expect(submitted).not.toHaveProperty("example_edited");+ });++ test("replaces attribution when a different example is selected", async () => {+ mockPost.mockResolvedValue({+ data: {+ workflow_permanent_id: "wpid_reselected_example",+ workflow_definition: { blocks: [] },+ },+ });++ renderPromptBox(false, undefined, true);+ fireEvent.click(screen.getByRole("button", { name: "Apply for a job" }));+ fireEvent.click(screen.getByRole("button", { name: "Get a quote" }));+ fireEvent.click(screen.getByLabelText("submit-prompt"));++ await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));+ expect(mockPostHogCapture).toHaveBeenCalledWith(+ "home.agent_creation_submitted",+ expect.objectContaining({+ source: "example",+ example: "forms.get_quote",+ example_edited: false,+ }),+ );+ });+test("reuses the shipped sample prompts for onboarding intent keys", () => {const ref = createRef<PromptBoxHandle>();renderPromptBox(false, ref);diff --git a/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx b/skyvern-frontend/src/routes/tasks/create/PromptBox.tsxindex 902d12da6..4bf50f853 100644--- a/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx+++ b/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx@@ -47,6 +47,7 @@ import { AxiosError, type AxiosResponse } from "axios";import {forwardRef,type ForwardedRef,+ useCallback,useEffect,useImperativeHandle,useRef,@@ -139,6 +140,7 @@ const exampleCases = [] as const;type ExamplePromptKey = (typeof exampleCases)[number]["key"];+type ExampleAttribution = { id: string; edited: boolean };const UPLOAD_RETENTION_DAYS = 30;// Mirrors MAX_ATTACHED_FILES_PER_MESSAGE on the copilot chat request.@@ -258,6 +260,9 @@ function PromptBoxImpl(const navigate = useNavigate();const studioEnabled = useWorkflowStudioEnabled();const [prompt, setPrompt] = useState<string>("");+ const [exampleAttribution, setExampleAttribution] = useState<+ ExampleAttribution | undefined+ >();const textareaRef = useRef<HTMLTextAreaElement>(null);const credentialGetter = useCredentialGetter();const queryClient = useQueryClient();@@ -295,12 +300,23 @@ function PromptBoxImpl(// double-click can slip past it; the ref is the synchronous guard.const submitInFlightRef = useRef(false);+ const updatePrompt = useCallback((value: string) => {+ setPrompt(value);+ setExampleAttribution((current) => {+ if (!value.trim()) return undefined;+ if (!current || current.edited) return current;+ return { ...current, edited: true };+ });+ }, []);+useImperativeHandle(ref, () => ({focusAndPrefillExample: (key) => {- const examplePrompt =- exampleCases.find((example) => example.key === key)?.prompt ??- exampleCases[0].prompt;- setPrompt((current) => (current.trim() ? current : examplePrompt));+ const selectedExample =+ exampleCases.find((example) => example.key === key) ?? exampleCases[0];+ if (!prompt.trim()) {+ setPrompt(selectedExample.prompt);+ setExampleAttribution({ id: selectedExample.key, edited: false });+ }textareaRef.current?.scrollIntoView?.({ block: "center" });textareaRef.current?.focus({ preventScroll: true });},@@ -553,25 +569,28 @@ function PromptBoxImpl(toggle: toggleSpeech,} = useSpeechToTextField({value: prompt,- onChange: setPrompt,+ onChange: updatePrompt,enabled: !promptImprovalIsPending && !isSubmitting,});const submitPrompt = ({prompt,- example,+ attribution,}: {prompt: string;- example?: string;+ attribution?: ExampleAttribution;}) => {if (submitInFlightRef.current || isSubmitting) {return;}submitInFlightRef.current = true;- const source = example ? "example" : "typed";+ const source = attribution ? "example" : "typed";+ const example = attribution?.id;+ const exampleEdited = attribution?.edited;const attempt = HomeTelemetry.agentCreationSubmitted({source,example,+ exampleEdited,handoff: enableCopilotHandoff,variant: minimal ? "revamp" : "legacy",});@@ -579,6 +598,7 @@ function PromptBoxImpl(attemptId: attempt.attemptId,source,example,+ exampleEdited,promptLength: prompt.length,handoff: enableCopilotHandoff,});@@ -632,7 +652,7 @@ function PromptBoxImpl(id="discover-prompt-input"className="min-h-0 resize-none border-0 bg-transparent px-4 py-0 leading-5 text-foreground shadow-none placeholder:text-muted-foreground hover:border-0 focus-visible:ring-0"value={prompt}- onChange={(e) => setPrompt(e.target.value)}+ onChange={(e) => updatePrompt(e.target.value)}placeholder="Enter your prompt..."/><ImprovePrompt@@ -644,7 +664,7 @@ function PromptBoxImpl(onEnd={() => {setPromptImprovalIsPending(false);}}- onImprove={(prompt) => setPrompt(prompt)}+ onImprove={updatePrompt}prompt={prompt}size="large"useCase="new_workflow"@@ -670,7 +690,7 @@ function PromptBoxImpl(disabled={!prompt.trim() || isSubmitting}className="flex items-center justify-center rounded-lg bg-cta p-2 text-cta-foreground shadow-sm transition-colors hover:bg-cta-hover disabled:pointer-events-none disabled:bg-cta/45 disabled:text-cta-foreground/65 disabled:shadow-none"onClick={() => {- submitPrompt({ prompt });+ submitPrompt({ prompt, attribution: exampleAttribution });}}>{isSubmitting ? (@@ -895,10 +915,13 @@ function PromptBoxImpl(label={example.label}disabled={isSubmitting}onClick={() => {- HomeTelemetry.exampleClicked({ label: example.label });+ HomeTelemetry.exampleClicked({+ example: example.key,+ label: example.label,+ });submitPrompt({prompt: example.prompt,- example: example.key,+ attribution: { id: example.key, edited: false },});}}/>@@ -958,7 +981,7 @@ function PromptBoxImpl(id="discover-prompt-input"className="max-h-[8rem] min-h-[4rem] resize-none overflow-y-auto border-0 bg-transparent px-3 py-3 leading-5 text-foreground shadow-none placeholder:text-muted-foreground hover:border-0 focus-visible:ring-0"value={prompt}- onChange={(e) => setPrompt(e.target.value)}+ onChange={(e) => updatePrompt(e.target.value)}onFocus={() => setPromptTouched(true)}cycling={!promptTouched}/>@@ -1066,7 +1089,7 @@ function PromptBoxImpl(disabled={!prompt.trim() || isSubmitting}className="flex size-8 items-center justify-center rounded-lg bg-cta text-cta-foreground shadow-sm transition-colors hover:bg-cta-hover disabled:pointer-events-none disabled:bg-cta/45 disabled:text-cta-foreground/65 disabled:shadow-none"onClick={() => {- submitPrompt({ prompt });+ submitPrompt({ prompt, attribution: exampleAttribution });}}>{isSubmitting ? (@@ -1088,14 +1111,22 @@ function PromptBoxImpl(disabled={isSubmitting}onSelect={(example) => {HomeTelemetry.exampleClicked({+ example: example.id,capability: example.capability,label: example.label,});setPrompt(example.prompt);+ setExampleAttribution({ id: example.id, edited: false });setPromptTouched(true);textareaRef.current?.focus();}}- onPreview={(example) => HomeTelemetry.examplePreviewShown(example)}+ onPreview={(example) =>+ HomeTelemetry.examplePreviewShown({+ example: example.id,+ capability: example.capability,+ label: example.label,+ })+ }/>{showHowItWorks ? (<div className="mt-6 flex w-full max-w-[54rem] flex-col gap-3.5 rounded-xl border border-border/70 bg-slate-elevation1/60 px-[18px] py-4 md:flex-row md:items-stretch">diff --git a/skyvern-frontend/src/util/homeTelemetry.ts b/skyvern-frontend/src/util/homeTelemetry.tsindex 44463d251..98ee6d407 100644--- a/skyvern-frontend/src/util/homeTelemetry.ts+++ b/skyvern-frontend/src/util/homeTelemetry.ts@@ -10,6 +10,7 @@ type AgentCreationAttempt = {handoff: boolean;variant: Variant;example?: string;+ exampleEdited?: boolean;};function capture(event: string, properties: Properties = {}): void {@@ -27,6 +28,9 @@ function attemptProperties(attempt: AgentCreationAttempt): Properties {handoff: attempt.handoff,variant: attempt.variant,...(attempt.example ? { example: attempt.example } : {}),+ ...(attempt.exampleEdited !== undefined+ ? { example_edited: attempt.exampleEdited }+ : {}),};}@@ -69,11 +73,16 @@ export const HomeTelemetry = {attemptId: string;source: "typed" | "example";example?: string;+ exampleEdited?: boolean;promptLength: number;handoff: boolean;}) => {- const { attemptId, ...properties } = input;- capture("prompt_submitted", { attempt_id: attemptId, ...properties });+ const { attemptId, exampleEdited, ...properties } = input;+ capture("prompt_submitted", {+ attempt_id: attemptId,+ ...properties,+ ...(exampleEdited !== undefined ? { example_edited: exampleEdited } : {}),+ });},agentCreationSubmitted: (input: Omit<AgentCreationAttempt, "attemptId">,@@ -95,10 +104,16 @@ export const HomeTelemetry = {...attemptProperties(attempt),error_category: errorCategory(error),}),- exampleClicked: (input: { capability?: string; label: string }) =>- capture("example_clicked", input),- examplePreviewShown: (input: { capability: string; label: string }) =>- capture("example_preview_shown", input),+ exampleClicked: (input: {+ example?: string;+ capability?: string;+ label: string;+ }) => capture("example_clicked", input),+ examplePreviewShown: (input: {+ example: string;+ capability: string;+ label: string;+ }) => capture("example_preview_shown", input),howItWorksToggled: (open: boolean) =>capture("how_it_works_toggled", { open }),addMenuOpened: () => capture("add_menu_opened"),