From 7f2413e06d4d1fad6f839dd4ba9ccde72c864e14 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Mon, 27 Jan 2025 21:47:09 +0800 Subject: [PATCH] Add advanced settings in prompt box (#1655) --- skyvern-frontend/src/api/types.ts | 6 + .../src/routes/tasks/create/PromptBox.tsx | 191 ++++++++++++------ 2 files changed, 134 insertions(+), 63 deletions(-) diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts index 608def33..07479917 100644 --- a/skyvern-frontend/src/api/types.ts +++ b/skyvern-frontend/src/api/types.ts @@ -257,3 +257,9 @@ export type ObserverTask = { output: Record | null; summary: string | null; }; + +export type Createv2TaskRequest = { + user_prompt: string; + webhook_callback_url?: string | null; + proxy_location?: ProxyLocation | null; +}; diff --git a/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx b/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx index 898f9374..2f1311b4 100644 --- a/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx +++ b/skyvern-frontend/src/routes/tasks/create/PromptBox.tsx @@ -1,5 +1,10 @@ import { getClient } from "@/api/AxiosClient"; -import { ObserverTask, TaskGenerationApiResponse } from "@/api/types"; +import { + Createv2TaskRequest, + ObserverTask, + ProxyLocation, + TaskGenerationApiResponse, +} from "@/api/types"; import img from "@/assets/promptBoxBg.png"; import { AutoResizingTextarea } from "@/components/AutoResizingTextarea/AutoResizingTextarea"; import { CartIcon } from "@/components/icons/CartIcon"; @@ -37,6 +42,8 @@ import { generateUniqueEmail, } from "../data/sampleTaskData"; import { ExampleCasePill } from "./ExampleCasePill"; +import { Input } from "@/components/ui/input"; +import { ProxySelector } from "@/components/ProxySelector"; function createTemplateTaskFromTaskGenerationParameters( values: TaskGenerationApiResponse, @@ -137,13 +144,24 @@ function PromptBox() { const [selectValue, setSelectValue] = useState<"v1" | "v2">("v2"); // Observer is the default const credentialGetter = useCredentialGetter(); const queryClient = useQueryClient(); + const [webhookCallbackUrl, setWebhookCallbackUrl] = useState( + null, + ); + const [proxyLocation, setProxyLocation] = useState( + ProxyLocation.Residential, + ); + const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); const startObserverCruiseMutation = useMutation({ mutationFn: async (prompt: string) => { const client = await getClient(credentialGetter, "v2"); - return client.post<{ user_prompt: string }, { data: ObserverTask }>( + return client.post( "/tasks", - { user_prompt: prompt }, + { + user_prompt: prompt, + webhook_callback_url: webhookCallbackUrl, + proxy_location: proxyLocation, + }, ); }, onSuccess: (response) => { @@ -190,10 +208,11 @@ function PromptBox() { .then((response) => response.data); }, onError: (error: AxiosError) => { + const detail = (error.response?.data as { detail?: string })?.detail; toast({ variant: "destructive", title: "Error creating task from prompt", - description: error.message, + description: detail ? detail : error.message, }); }, }); @@ -236,70 +255,116 @@ function PromptBox() { What task would you like to accomplish? -
- setPrompt(e.target.value)} - placeholder="Enter your prompt..." - /> - { + setSelectValue(value); + }} + > + + + + + +
+
+ Skyvern 1.0 +
+
+ Best for simple tasks +
-
- Best for simple tasks + + +
+
+ Skyvern 2.0 +
+
+ Best for complex tasks +
-
-
- -
-
- Skyvern 2.0 -
-
- Best for complex tasks -
-
-
-
- -
- {startObserverCruiseMutation.isPending || - getTaskFromPromptMutation.isPending || - saveTaskMutation.isPending ? ( - - ) : ( - { - if (selectValue === "v2") { - startObserverCruiseMutation.mutate(prompt); - return; - } - const taskGenerationResponse = - await getTaskFromPromptMutation.mutateAsync(prompt); - await saveTaskMutation.mutateAsync(taskGenerationResponse); - navigate("/tasks/create/from-prompt", { - state: { - data: taskGenerationResponse, - }, - }); + + + +
+ { + setShowAdvancedSettings((value) => !value); }} /> - )} +
+
+ {startObserverCruiseMutation.isPending || + getTaskFromPromptMutation.isPending || + saveTaskMutation.isPending ? ( + + ) : ( + { + if (selectValue === "v2") { + startObserverCruiseMutation.mutate(prompt); + return; + } + const taskGenerationResponse = + await getTaskFromPromptMutation.mutateAsync(prompt); + await saveTaskMutation.mutateAsync( + taskGenerationResponse, + ); + navigate("/tasks/create/from-prompt", { + state: { + data: taskGenerationResponse, + }, + }); + }} + /> + )} +
+ {showAdvancedSettings ? ( +
+
+
Advanced Settings
+
+
+
Webhook Callback URL
+
+ The URL of a webhook endpoint to send the extracted + information +
+
+ { + setWebhookCallbackUrl(event.target.value); + }} + /> +
+
+
+
Proxy Location
+
+ Route Skyvern through one of our available proxies. +
+
+ +
+
+
+ ) : null}