Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Your commit message
Prakash Maheshwaran69ec20299f86
diff --git a/skyvern-frontend/src/components/CopyApiCommandDropdown.tsx b/skyvern-frontend/src/components/CopyApiCommandDropdown.tsxnew file mode 100644index 000000000..57dd40dbb--- /dev/null+++ b/skyvern-frontend/src/components/CopyApiCommandDropdown.tsx@@ -0,0 +1,59 @@+import { CopyIcon } from "@radix-ui/react-icons";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { Button } from "@/components/ui/button";+import { useToast } from "@/components/ui/use-toast";+import { copyText } from "@/util/copyText";+import {+ type ApiRequest,+ getCurlCommand,+ getPowerShellCommand,+} from "@/util/apiCommands";++interface Props {+ getRequest: () => ApiRequest;+}++function CopyApiCommandDropdown({ getRequest }: Props) {+ const { toast } = useToast();++ const handleCopy = async (type: "curl" | "powershell") => {+ const request = getRequest();+ const text =+ type === "curl" ? getCurlCommand(request) : getPowerShellCommand(request);+ await copyText(text);+ toast({+ variant: "success",+ title: "Copied to Clipboard",+ description:+ type === "curl"+ ? "The cURL command has been copied to your clipboard."+ : "The PowerShell command has been copied to your clipboard.",+ });+ };++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="secondary">+ <CopyIcon className="mr-2 h-4 w-4" />+ Copy API Command+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem onSelect={() => handleCopy("curl")}>+ Copy cURL (Unix/Linux/macOS)+ </DropdownMenuItem>+ <DropdownMenuItem onSelect={() => handleCopy("powershell")}>+ Copy PowerShell (Windows)+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ );+}++export { CopyApiCommandDropdown };diff --git a/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx b/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsxindex 8631daa3e..cf697f22a 100644--- a/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx+++ b/skyvern-frontend/src/routes/tasks/create/CreateNewTaskForm.tsx@@ -20,14 +20,12 @@ import { toast } from "@/components/ui/use-toast";import { useApiCredential } from "@/hooks/useApiCredential";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { CodeEditor } from "@/routes/workflows/components/CodeEditor";-import { copyText } from "@/util/copyText";import { apiBaseUrl } from "@/util/env";import { zodResolver } from "@hookform/resolvers/zod";-import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons";+import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons";import { ToastAction } from "@radix-ui/react-toast";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { AxiosError } from "axios";-import fetchToCurl from "fetch-to-curl";import { useState } from "react";import { useForm, useFormState } from "react-hook-form";import { Link } from "react-router-dom";@@ -39,6 +37,7 @@ import {} from "./taskFormTypes";import { ProxySelector } from "@/components/ProxySelector";import { Switch } from "@/components/ui/switch";+import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown";type Props = {initialValues: CreateNewTaskFormValues;};@@ -622,30 +621,17 @@ function CreateNewTaskForm({ initialValues }: Props) {</TaskFormSection><div className="flex justify-end gap-3">- <Button- type="button"- variant="secondary"- onClick={async () => {- const curl = fetchToCurl({- method: "POST",- url: `${apiBaseUrl}/tasks`,- body: createTaskRequestObject(form.getValues()),- headers: {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- },- });- copyText(curl).then(() => {- toast({- title: "Copied cURL",- description: "cURL copied to clipboard",- });- });- }}- >- <CopyIcon className="mr-2 h-4 w-4" />- cURL- </Button>+ <CopyApiCommandDropdown+ getRequest={() => ({+ method: "POST",+ url: `${apiBaseUrl}/tasks`,+ body: createTaskRequestObject(form.getValues()),+ headers: {+ "Content-Type": "application/json",+ "x-api-key": apiCredential ?? "<your-api-key>",+ },+ })}+ /><Button type="submit" disabled={mutation.isPending}>{mutation.isPending && (<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />diff --git a/skyvern-frontend/src/routes/tasks/create/SavedTaskForm.tsx b/skyvern-frontend/src/routes/tasks/create/SavedTaskForm.tsxindex 8b6e7ac9a..9d8e466ed 100644--- a/skyvern-frontend/src/routes/tasks/create/SavedTaskForm.tsx+++ b/skyvern-frontend/src/routes/tasks/create/SavedTaskForm.tsx@@ -16,14 +16,12 @@ import { useApiCredential } from "@/hooks/useApiCredential";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { CodeEditor } from "@/routes/workflows/components/CodeEditor";import { SubmitEvent } from "@/types";-import { copyText } from "@/util/copyText";import { apiBaseUrl } from "@/util/env";import { zodResolver } from "@hookform/resolvers/zod";-import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons";+import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons";import { ToastAction } from "@radix-ui/react-toast";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { AxiosError } from "axios";-import fetchToCurl from "fetch-to-curl";import { useState } from "react";import { useForm, useFormState } from "react-hook-form";import { Link, useParams } from "react-router-dom";@@ -33,6 +31,7 @@ import { TaskFormSection } from "./TaskFormSection";import { savedTaskFormSchema, SavedTaskFormValues } from "./taskFormTypes";import { OrganizationApiResponse, ProxyLocation } from "@/api/types";import { ProxySelector } from "@/components/ProxySelector";+import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown";type Props = {initialValues: SavedTaskFormValues;@@ -737,31 +736,17 @@ function SavedTaskForm({ initialValues }: Props) {</TaskFormSection><div className="flex justify-end gap-3">- <Button- type="button"- variant="secondary"- onClick={async () => {- const curl = fetchToCurl({- method: "POST",- url: `${apiBaseUrl}/tasks`,- body: createTaskRequestObject(form.getValues()),- headers: {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- },- });- copyText(curl).then(() => {- toast({- variant: "success",- title: "Copied successfully",- description: "cURL copied to clipboard",- });- });- }}- >- <CopyIcon className="mr-2 h-4 w-4" />- cURL- </Button>+ <CopyApiCommandDropdown+ getRequest={() => ({+ method: "POST",+ url: `${apiBaseUrl}/tasks`,+ body: createTaskRequestObject(form.getValues()),+ headers: {+ "Content-Type": "application/json",+ "x-api-key": apiCredential ?? "<your-api-key>",+ },+ })}+ /><Buttontype="submit"name="save"diff --git a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsxindex 129552777..13389b091 100644--- a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx+++ b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx@@ -24,11 +24,10 @@ import { useApiCredential } from "@/hooks/useApiCredential";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { CodeEditor } from "@/routes/workflows/components/CodeEditor";import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";-import { copyText } from "@/util/copyText";import { apiBaseUrl } from "@/util/env";-import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons";+import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";-import fetchToCurl from "fetch-to-curl";+import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown";import { Link, Outlet, useParams } from "react-router-dom";import { statusIsFinalized } from "../types";import { useTaskQuery } from "./hooks/useTaskQuery";@@ -180,34 +179,17 @@ function TaskDetails() {)}</div><div className="flex items-center gap-2">- <Button- variant="secondary"- onClick={() => {- if (!task) {- return;- }- const curl = fetchToCurl({- method: "POST",- url: `${apiBaseUrl}/tasks`,- body: createTaskRequestObject(task),- headers: {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- },- });- copyText(curl).then(() => {- toast({- variant: "success",- title: "Copied to Clipboard",- description:- "The cURL command has been copied to your clipboard.",- });- });- }}- >- <CopyIcon className="mr-2 h-4 w-4" />- cURL- </Button>+ <CopyApiCommandDropdown+ getRequest={() => ({+ method: "POST",+ url: `${apiBaseUrl}/tasks`,+ body: task ? createTaskRequestObject(task) : undefined,+ headers: {+ "Content-Type": "application/json",+ "x-api-key": apiCredential ?? "<your-api-key>",+ },+ })}+ />{taskIsRunningOrQueued && (<Dialog><DialogTrigger asChild>diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsxindex b7974a7b0..540c702f0 100644--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx@@ -14,11 +14,10 @@ import { Input } from "@/components/ui/input";import { toast } from "@/components/ui/use-toast";import { useApiCredential } from "@/hooks/useApiCredential";import { useCredentialGetter } from "@/hooks/useCredentialGetter";-import { copyText } from "@/util/copyText";import { apiBaseUrl } from "@/util/env";-import { CopyIcon, PlayIcon, ReloadIcon } from "@radix-ui/react-icons";+import { PlayIcon, ReloadIcon } from "@radix-ui/react-icons";import { useMutation, useQueryClient } from "@tanstack/react-query";-import fetchToCurl from "fetch-to-curl";+import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown";import { useForm } from "react-hook-form";import { useNavigate, useParams } from "react-router-dom";import { z } from "zod";@@ -333,39 +332,20 @@ function RunWorkflowForm({</div><div className="flex justify-end gap-2">- <Button- type="button"- variant="secondary"- onClick={() => {- const values = form.getValues();- const body = getRunWorkflowRequestBody(- values,+ <CopyApiCommandDropdown+ getRequest={() => ({+ method: "POST",+ url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,+ body: getRunWorkflowRequestBody(+ form.getValues(),workflowParameters,- );-- const curl = fetchToCurl({- method: "POST",- url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,- body,- headers: {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- },- });-- copyText(curl).then(() => {- toast({- variant: "success",- title: "Copied to Clipboard",- description:- "The cURL command has been copied to your clipboard.",- });- });- }}- >- <CopyIcon className="mr-2 h-4 w-4" />- cURL- </Button>+ ),+ headers: {+ "Content-Type": "application/json",+ "x-api-key": apiCredential ?? "<your-api-key>",+ },+ })}+ /><Button type="submit" disabled={runWorkflowMutation.isPending}>{runWorkflowMutation.isPending && (<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsxindex d8b2df086..93f3d8fa2 100644--- a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx+++ b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx@@ -17,17 +17,15 @@ import { Skeleton } from "@/components/ui/skeleton";import { toast } from "@/components/ui/use-toast";import { useApiCredential } from "@/hooks/useApiCredential";import { useCredentialGetter } from "@/hooks/useCredentialGetter";-import { copyText } from "@/util/copyText";import { apiBaseUrl } from "@/util/env";import {- CopyIcon,FileIcon,Pencil2Icon,PlayIcon,ReloadIcon,} from "@radix-ui/react-icons";import { useMutation, useQueryClient } from "@tanstack/react-query";-import fetchToCurl from "fetch-to-curl";+import { CopyApiCommandDropdown } from "@/components/CopyApiCommandDropdown";import { Link, Outlet, useParams, useSearchParams } from "react-router-dom";import { statusIsFinalized, statusIsRunningOrQueued } from "../tasks/types";import { useWorkflowQuery } from "./hooks/useWorkflowQuery";@@ -183,37 +181,20 @@ function WorkflowRun() {</div><div className="flex gap-2">- <Button- variant="secondary"- onClick={() => {- if (!workflowRun) {- return;- }- const curl = fetchToCurl({- method: "POST",- url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,- body: {- data: workflowRun?.parameters,- proxy_location: "RESIDENTIAL",- },- headers: {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- },- });- copyText(curl).then(() => {- toast({- variant: "success",- title: "Copied to Clipboard",- description:- "The cURL command has been copied to your clipboard.",- });- });- }}- >- <CopyIcon className="mr-2 h-4 w-4" />- cURL- </Button>+ <CopyApiCommandDropdown+ getRequest={() => ({+ method: "POST",+ url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,+ body: {+ data: workflowRun?.parameters,+ proxy_location: "RESIDENTIAL",+ },+ headers: {+ "Content-Type": "application/json",+ "x-api-key": apiCredential ?? "<your-api-key>",+ },+ })}+ /><Button asChild variant="secondary"><Link to={`/workflows/${workflowPermanentId}/edit`}><Pencil2Icon className="mr-2 h-4 w-4" />diff --git a/skyvern-frontend/src/util/apiCommands.ts b/skyvern-frontend/src/util/apiCommands.tsnew file mode 100644index 000000000..ddbe1554c--- /dev/null+++ b/skyvern-frontend/src/util/apiCommands.ts@@ -0,0 +1,32 @@+import fetchToCurl from "fetch-to-curl";++export type ApiRequest = {+ method: string;+ url: string;+ body?: unknown;+ headers: Record<string, string>;+};++export function getCurlCommand(request: ApiRequest): string {+ return fetchToCurl(request);+}++export function getPowerShellCommand(request: ApiRequest): string {+ const { method, url, headers, body } = request;+ const headerLines = Object.entries(headers)+ .map(([key, value]) => ` '${key}' = '${value}'`)+ .join("\n");+ const bodyJson = body ? JSON.stringify(body, null, 2) : undefined;+ const bodyLine = bodyJson+ ? ` Body = '${bodyJson.replace(/'/g, "''")}'\n`+ : "";+ return (+ `$Params = @{\n` ++ ` Uri = '${url}'\n` ++ ` Method = '${method}'\n` ++ ` Headers = @{\n${headerLines}\n }\n` ++ bodyLine ++ `}\n` ++ `Invoke-RestMethod @Params`+ );+}