Task creation UI updates (#886)
This commit is contained in:
BIN
skyvern-frontend/src/assets/promptBoxBg.png
Normal file
BIN
skyvern-frontend/src/assets/promptBoxBg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 246 KiB |
42
skyvern-frontend/src/components/SwitchBar.tsx
Normal file
42
skyvern-frontend/src/components/SwitchBar.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { cn } from "@/util/utils";
|
||||||
|
|
||||||
|
type Option = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
options: Option[];
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function SwitchBar({ options, value, onChange }: Props) {
|
||||||
|
return (
|
||||||
|
<div className="flex w-fit gap-1 rounded-sm border border-slate-700 p-2">
|
||||||
|
{options.map((option) => {
|
||||||
|
const selected = option.value === value;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={option.value}
|
||||||
|
className={cn(
|
||||||
|
"cursor-pointer rounded-sm px-3 py-2 text-xs hover:bg-slate-700",
|
||||||
|
{
|
||||||
|
"bg-slate-700": selected,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
if (!selected) {
|
||||||
|
onChange(option.value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { SwitchBar };
|
||||||
200
skyvern-frontend/src/routes/tasks/create/PromptBox.tsx
Normal file
200
skyvern-frontend/src/routes/tasks/create/PromptBox.tsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import { getClient } from "@/api/AxiosClient";
|
||||||
|
import { TaskGenerationApiResponse } from "@/api/types";
|
||||||
|
import img from "@/assets/promptBoxBg.png";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { toast } from "@/components/ui/use-toast";
|
||||||
|
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
||||||
|
import { PaperPlaneIcon, ReloadIcon } from "@radix-ui/react-icons";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { stringify as convertToYAML } from "yaml";
|
||||||
|
|
||||||
|
function createTaskFromTaskGenerationParameters(
|
||||||
|
values: TaskGenerationApiResponse,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
url: values.url,
|
||||||
|
navigation_goal: values.navigation_goal,
|
||||||
|
data_extraction_goal: values.data_extraction_goal,
|
||||||
|
proxy_location: "RESIDENTIAL",
|
||||||
|
navigation_payload: values.navigation_payload,
|
||||||
|
extracted_information_schema: values.extracted_information_schema,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTemplateTaskFromTaskGenerationParameters(
|
||||||
|
values: TaskGenerationApiResponse,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
title: values.suggested_title ?? "Untitled Task",
|
||||||
|
description: "",
|
||||||
|
is_saved_task: true,
|
||||||
|
webhook_callback_url: null,
|
||||||
|
proxy_location: "RESIDENTIAL",
|
||||||
|
workflow_definition: {
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
parameter_type: "workflow",
|
||||||
|
workflow_parameter_type: "json",
|
||||||
|
key: "navigation_payload",
|
||||||
|
default_value: JSON.stringify(values.navigation_payload),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
block_type: "task",
|
||||||
|
label: values.suggested_title ?? "Untitled Task",
|
||||||
|
url: values.url,
|
||||||
|
navigation_goal: values.navigation_goal,
|
||||||
|
data_extraction_goal: values.data_extraction_goal,
|
||||||
|
data_schema: values.extracted_information_schema,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const examplePrompts = [
|
||||||
|
"What is the top post on hackernews?",
|
||||||
|
"Navigate to Google Finance and search for AAPL",
|
||||||
|
];
|
||||||
|
|
||||||
|
function PromptBox() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [prompt, setPrompt] = useState<string>("");
|
||||||
|
const credentialGetter = useCredentialGetter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const getTaskFromPromptMutation = useMutation({
|
||||||
|
mutationFn: async (prompt: string) => {
|
||||||
|
const client = await getClient(credentialGetter);
|
||||||
|
return client
|
||||||
|
.post<
|
||||||
|
{ prompt: string },
|
||||||
|
{ data: TaskGenerationApiResponse }
|
||||||
|
>("/generate/task", { prompt })
|
||||||
|
.then((response) => response.data);
|
||||||
|
},
|
||||||
|
onError: (error: AxiosError) => {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error creating task from prompt",
|
||||||
|
description: error.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const saveTaskMutation = useMutation({
|
||||||
|
mutationFn: async (params: TaskGenerationApiResponse) => {
|
||||||
|
const client = await getClient(credentialGetter);
|
||||||
|
const templateTask =
|
||||||
|
createTemplateTaskFromTaskGenerationParameters(params);
|
||||||
|
const yaml = convertToYAML(templateTask);
|
||||||
|
return client.post("/workflows", yaml, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/plain",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["savedTasks"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error: AxiosError) => {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error saving task",
|
||||||
|
description: error.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const runTaskMutation = useMutation({
|
||||||
|
mutationFn: async (params: TaskGenerationApiResponse) => {
|
||||||
|
const client = await getClient(credentialGetter);
|
||||||
|
const data = createTaskFromTaskGenerationParameters(params);
|
||||||
|
return client.post<
|
||||||
|
ReturnType<typeof createTaskFromTaskGenerationParameters>,
|
||||||
|
{ data: { task_id: string } }
|
||||||
|
>("/tasks", data);
|
||||||
|
},
|
||||||
|
onSuccess: (response) => {
|
||||||
|
navigate(`/tasks/${response.data.task_id}/actions`);
|
||||||
|
},
|
||||||
|
onError: (error: AxiosError) => {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error running task",
|
||||||
|
description: error.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className="rounded-sm py-[4.25rem]"
|
||||||
|
style={{
|
||||||
|
background: `url(${img}) 50% / cover no-repeat`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col items-center gap-7">
|
||||||
|
<span className="text-2xl">
|
||||||
|
What task would you like to accomplish?
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
className="flex w-[35rem] max-w-xl items-center rounded-xl border border-slate-700 py-2 pr-4"
|
||||||
|
style={{
|
||||||
|
background: "rgba(248, 250, 252, 0.05)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Textarea
|
||||||
|
className="min-h-0 resize-none rounded-xl border-transparent px-4 text-slate-400 hover:border-transparent focus-visible:ring-0"
|
||||||
|
value={prompt}
|
||||||
|
onChange={(e) => setPrompt(e.target.value)}
|
||||||
|
placeholder="Enter your prompt..."
|
||||||
|
rows={1}
|
||||||
|
/>
|
||||||
|
<div className="h-full">
|
||||||
|
{getTaskFromPromptMutation.isPending ||
|
||||||
|
saveTaskMutation.isPending ||
|
||||||
|
runTaskMutation.isPending ? (
|
||||||
|
<ReloadIcon className="h-6 w-6 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<PaperPlaneIcon
|
||||||
|
className="h-6 w-6 cursor-pointer"
|
||||||
|
onClick={async () => {
|
||||||
|
const taskGenerationResponse =
|
||||||
|
await getTaskFromPromptMutation.mutateAsync(prompt);
|
||||||
|
await saveTaskMutation.mutateAsync(taskGenerationResponse);
|
||||||
|
await runTaskMutation.mutateAsync(taskGenerationResponse);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-4 rounded-sm bg-slate-elevation1 p-4">
|
||||||
|
{examplePrompts.map((examplePrompt) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={examplePrompt}
|
||||||
|
className="cursor-pointer rounded-sm bg-slate-elevation3 px-4 py-3 hover:bg-slate-elevation5"
|
||||||
|
onClick={() => {
|
||||||
|
setPrompt(examplePrompt);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{examplePrompt}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PromptBox };
|
||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@@ -26,6 +25,7 @@ import {
|
|||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { toast } from "@/components/ui/use-toast";
|
import { toast } from "@/components/ui/use-toast";
|
||||||
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
||||||
|
import { cn } from "@/util/utils";
|
||||||
import { DotsHorizontalIcon, ReloadIcon } from "@radix-ui/react-icons";
|
import { DotsHorizontalIcon, ReloadIcon } from "@radix-ui/react-icons";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -43,6 +43,7 @@ function SavedTaskCard({ workflowId, title, url, description }: Props) {
|
|||||||
const credentialGetter = useCredentialGetter();
|
const credentialGetter = useCredentialGetter();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [hovering, setHovering] = useState(false);
|
||||||
|
|
||||||
const deleteTaskMutation = useMutation({
|
const deleteTaskMutation = useMutation({
|
||||||
mutationFn: async (id: string) => {
|
mutationFn: async (id: string) => {
|
||||||
@@ -73,29 +74,42 @@ function SavedTaskCard({ workflowId, title, url, description }: Props) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card
|
||||||
<CardHeader>
|
className="border-0"
|
||||||
<CardTitle className="flex items-center justify-between">
|
onMouseEnter={() => setHovering(true)}
|
||||||
|
onMouseLeave={() => setHovering(false)}
|
||||||
|
onMouseOver={() => setHovering(true)}
|
||||||
|
onMouseOut={() => setHovering(false)}
|
||||||
|
>
|
||||||
|
<CardHeader
|
||||||
|
className={cn("rounded-t-md bg-slate-elevation1", {
|
||||||
|
"bg-slate-900": hovering,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<CardTitle className="flex items-center justify-between font-normal">
|
||||||
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
|
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
|
||||||
{title}
|
{title}
|
||||||
</span>
|
</span>
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog
|
||||||
<DropdownMenu>
|
open={open}
|
||||||
|
onOpenChange={() => {
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownMenu modal={false}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<DotsHorizontalIcon className="cursor-pointer" />
|
<DotsHorizontalIcon className="cursor-pointer" />
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-56">
|
<DropdownMenuContent className="w-56">
|
||||||
<DropdownMenuLabel>Template Actions</DropdownMenuLabel>
|
<DropdownMenuLabel>Template Actions</DropdownMenuLabel>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DialogTrigger asChild>
|
<DropdownMenuItem
|
||||||
<DropdownMenuItem
|
onSelect={() => {
|
||||||
onSelect={() => {
|
setOpen(true);
|
||||||
setOpen(true);
|
}}
|
||||||
}}
|
>
|
||||||
>
|
Delete Template
|
||||||
Delete Template
|
</DropdownMenuItem>
|
||||||
</DropdownMenuItem>
|
|
||||||
</DialogTrigger>
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
@@ -106,7 +120,12 @@ function SavedTaskCard({ workflowId, title, url, description }: Props) {
|
|||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="secondary" onClick={() => setOpen(false)}>
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => {
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -125,12 +144,17 @@ function SavedTaskCard({ workflowId, title, url, description }: Props) {
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap">
|
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap text-slate-400">
|
||||||
{url}
|
{url}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent
|
<CardContent
|
||||||
className="h-48 cursor-pointer overflow-scroll hover:bg-muted/40"
|
className={cn(
|
||||||
|
"h-36 cursor-pointer overflow-scroll rounded-b-md bg-slate-elevation3 p-4 text-sm text-slate-300",
|
||||||
|
{
|
||||||
|
"bg-slate-800": hovering,
|
||||||
|
},
|
||||||
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(workflowId);
|
navigate(workflowId);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { stringify as convertToYAML } from "yaml";
|
import { stringify as convertToYAML } from "yaml";
|
||||||
import { SavedTaskCard } from "./SavedTaskCard";
|
import { SavedTaskCard } from "./SavedTaskCard";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { cn } from "@/util/utils";
|
||||||
|
|
||||||
function createEmptyTaskTemplate() {
|
function createEmptyTaskTemplate() {
|
||||||
return {
|
return {
|
||||||
@@ -49,6 +51,7 @@ function createEmptyTaskTemplate() {
|
|||||||
function SavedTasks() {
|
function SavedTasks() {
|
||||||
const credentialGetter = useCredentialGetter();
|
const credentialGetter = useCredentialGetter();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [hovering, setHovering] = useState(false);
|
||||||
|
|
||||||
const { data } = useQuery<Array<WorkflowApiResponse>>({
|
const { data } = useQuery<Array<WorkflowApiResponse>>({
|
||||||
queryKey: ["savedTasks"],
|
queryKey: ["savedTasks"],
|
||||||
@@ -99,20 +102,36 @@ function SavedTasks() {
|
|||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-4 gap-4">
|
<div className="grid grid-cols-4 gap-4">
|
||||||
<Card
|
<Card
|
||||||
onClick={() => {
|
className="border-0"
|
||||||
if (mutation.isPending) {
|
onMouseEnter={() => setHovering(true)}
|
||||||
return;
|
onMouseLeave={() => setHovering(false)}
|
||||||
}
|
onMouseOver={() => setHovering(true)}
|
||||||
mutation.mutate();
|
onMouseOut={() => setHovering(false)}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<CardHeader>
|
<CardHeader
|
||||||
<CardTitle>New Template</CardTitle>
|
className={cn("rounded-t-md bg-slate-elevation1", {
|
||||||
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap">
|
"bg-slate-900": hovering,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<CardTitle className="font-normal">New Template</CardTitle>
|
||||||
|
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap text-slate-400">
|
||||||
Create your own template
|
Create your own template
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex h-48 cursor-pointer items-center justify-center hover:bg-muted/40">
|
<CardContent
|
||||||
|
className={cn(
|
||||||
|
"flex h-36 cursor-pointer items-center justify-center rounded-b-md bg-slate-elevation3 p-4 text-sm text-slate-300",
|
||||||
|
{
|
||||||
|
"bg-slate-800": hovering,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
if (mutation.isPending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mutation.mutate();
|
||||||
|
}}
|
||||||
|
>
|
||||||
{!mutation.isPending && <PlusIcon className="h-12 w-12" />}
|
{!mutation.isPending && <PlusIcon className="h-12 w-12" />}
|
||||||
{mutation.isPending && (
|
{mutation.isPending && (
|
||||||
<ReloadIcon className="h-12 w-12 animate-spin" />
|
<ReloadIcon className="h-12 w-12 animate-spin" />
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
import { cn } from "@/util/utils";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
body: string;
|
||||||
|
onClick: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function TaskTemplateCard({ title, description, body, onClick }: Props) {
|
||||||
|
const [hovering, setHovering] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
className="border-0"
|
||||||
|
onMouseEnter={() => setHovering(true)}
|
||||||
|
onMouseLeave={() => setHovering(false)}
|
||||||
|
onMouseOver={() => setHovering(true)}
|
||||||
|
onMouseOut={() => setHovering(false)}
|
||||||
|
>
|
||||||
|
<CardHeader
|
||||||
|
className={cn("rounded-t-md bg-slate-elevation1", {
|
||||||
|
"bg-slate-900": hovering,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<CardTitle className="font-normal">{title}</CardTitle>
|
||||||
|
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap text-slate-400">
|
||||||
|
{description}
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent
|
||||||
|
className={cn(
|
||||||
|
"h-36 cursor-pointer rounded-b-md bg-slate-elevation3 p-4 text-sm text-slate-300",
|
||||||
|
{
|
||||||
|
"bg-slate-800": hovering,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
onClick();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { TaskTemplateCard };
|
||||||
@@ -1,35 +1,11 @@
|
|||||||
import { SampleCase } from "../types";
|
|
||||||
import {
|
|
||||||
Card,
|
|
||||||
CardContent,
|
|
||||||
CardDescription,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle,
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { SavedTasks } from "./SavedTasks";
|
|
||||||
import { getSample } from "../data/sampleTaskData";
|
import { getSample } from "../data/sampleTaskData";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { SampleCase } from "../types";
|
||||||
|
import { PromptBox } from "./PromptBox";
|
||||||
|
import { SavedTasks } from "./SavedTasks";
|
||||||
|
import { SwitchBar } from "@/components/SwitchBar";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import {
|
import { TaskTemplateCard } from "./TaskTemplateCard";
|
||||||
InfoCircledIcon,
|
|
||||||
PaperPlaneIcon,
|
|
||||||
ReloadIcon,
|
|
||||||
} from "@radix-ui/react-icons";
|
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
|
||||||
import { getClient } from "@/api/AxiosClient";
|
|
||||||
import { AxiosError } from "axios";
|
|
||||||
import { toast } from "@/components/ui/use-toast";
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
||||||
import { TaskGenerationApiResponse } from "@/api/types";
|
|
||||||
import { stringify as convertToYAML } from "yaml";
|
|
||||||
|
|
||||||
const examplePrompts = [
|
|
||||||
"What is the top post on hackernews?",
|
|
||||||
"Navigate to Google Finance and search for AAPL",
|
|
||||||
];
|
|
||||||
|
|
||||||
const templateSamples: {
|
const templateSamples: {
|
||||||
[key in SampleCase]: {
|
[key in SampleCase]: {
|
||||||
@@ -63,228 +39,52 @@ const templateSamples: {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function createTemplateTaskFromTaskGenerationParameters(
|
const templateSwitchOptions = [
|
||||||
values: TaskGenerationApiResponse,
|
{
|
||||||
) {
|
label: "Skyvern Templates",
|
||||||
return {
|
value: "skyvern",
|
||||||
title: values.suggested_title ?? "Untitled Task",
|
},
|
||||||
description: "",
|
{
|
||||||
is_saved_task: true,
|
label: "My Templates",
|
||||||
webhook_callback_url: null,
|
value: "user",
|
||||||
proxy_location: "RESIDENTIAL",
|
},
|
||||||
workflow_definition: {
|
];
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
parameter_type: "workflow",
|
|
||||||
workflow_parameter_type: "json",
|
|
||||||
key: "navigation_payload",
|
|
||||||
default_value: JSON.stringify(values.navigation_payload),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
blocks: [
|
|
||||||
{
|
|
||||||
block_type: "task",
|
|
||||||
label: values.suggested_title ?? "Untitled Task",
|
|
||||||
url: values.url,
|
|
||||||
navigation_goal: values.navigation_goal,
|
|
||||||
data_extraction_goal: values.data_extraction_goal,
|
|
||||||
data_schema: values.extracted_information_schema,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTaskFromTaskGenerationParameters(
|
|
||||||
values: TaskGenerationApiResponse,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
url: values.url,
|
|
||||||
navigation_goal: values.navigation_goal,
|
|
||||||
data_extraction_goal: values.data_extraction_goal,
|
|
||||||
proxy_location: "RESIDENTIAL",
|
|
||||||
navigation_payload: values.navigation_payload,
|
|
||||||
extracted_information_schema: values.extracted_information_schema,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function TaskTemplates() {
|
function TaskTemplates() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [prompt, setPrompt] = useState<string>("");
|
const [templateSwitchValue, setTemplateSwitchValue] =
|
||||||
const credentialGetter = useCredentialGetter();
|
useState<(typeof templateSwitchOptions)[number]["value"]>("skyvern");
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
const getTaskFromPromptMutation = useMutation({
|
|
||||||
mutationFn: async (prompt: string) => {
|
|
||||||
const client = await getClient(credentialGetter);
|
|
||||||
return client
|
|
||||||
.post<
|
|
||||||
{ prompt: string },
|
|
||||||
{ data: TaskGenerationApiResponse }
|
|
||||||
>("/generate/task", { prompt })
|
|
||||||
.then((response) => response.data);
|
|
||||||
},
|
|
||||||
onError: (error: AxiosError) => {
|
|
||||||
toast({
|
|
||||||
variant: "destructive",
|
|
||||||
title: "Error creating task from prompt",
|
|
||||||
description: error.message,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const saveTaskMutation = useMutation({
|
|
||||||
mutationFn: async (params: TaskGenerationApiResponse) => {
|
|
||||||
const client = await getClient(credentialGetter);
|
|
||||||
const templateTask =
|
|
||||||
createTemplateTaskFromTaskGenerationParameters(params);
|
|
||||||
const yaml = convertToYAML(templateTask);
|
|
||||||
return client.post("/workflows", yaml, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "text/plain",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["savedTasks"],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error: AxiosError) => {
|
|
||||||
toast({
|
|
||||||
variant: "destructive",
|
|
||||||
title: "Error saving task",
|
|
||||||
description: error.message,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const runTaskMutation = useMutation({
|
|
||||||
mutationFn: async (params: TaskGenerationApiResponse) => {
|
|
||||||
const client = await getClient(credentialGetter);
|
|
||||||
const data = createTaskFromTaskGenerationParameters(params);
|
|
||||||
return client.post<
|
|
||||||
ReturnType<typeof createTaskFromTaskGenerationParameters>,
|
|
||||||
{ data: { task_id: string } }
|
|
||||||
>("/tasks", data);
|
|
||||||
},
|
|
||||||
onSuccess: (response) => {
|
|
||||||
navigate(`/tasks/${response.data.task_id}/actions`);
|
|
||||||
},
|
|
||||||
onError: (error: AxiosError) => {
|
|
||||||
toast({
|
|
||||||
variant: "destructive",
|
|
||||||
title: "Error running task",
|
|
||||||
description: error.message,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="space-y-8">
|
||||||
<Alert variant="warning">
|
<PromptBox />
|
||||||
<InfoCircledIcon className="h-4 w-4" />
|
<section>
|
||||||
<AlertTitle>
|
<SwitchBar
|
||||||
Have a complicated workflow you would like to automate?
|
value={templateSwitchValue}
|
||||||
</AlertTitle>
|
onChange={setTemplateSwitchValue}
|
||||||
<AlertDescription>
|
options={templateSwitchOptions}
|
||||||
<a
|
/>
|
||||||
href="https://meetings.hubspot.com/skyvern/demo"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="ml-auto underline underline-offset-2"
|
|
||||||
>
|
|
||||||
Book a demo {"->"}
|
|
||||||
</a>
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
<section className="py-4">
|
|
||||||
<header>
|
|
||||||
<h1 className="mb-2 text-3xl">Try a prompt</h1>
|
|
||||||
</header>
|
|
||||||
<p className="text-sm">
|
|
||||||
We will generate a task for you automatically.
|
|
||||||
</p>
|
|
||||||
<Separator className="mb-8 mt-2" />
|
|
||||||
<div className="mx-auto flex max-w-xl items-center rounded-xl border pr-4">
|
|
||||||
<Textarea
|
|
||||||
className="resize-none rounded-xl border-transparent p-2 font-mono text-sm hover:border-transparent focus-visible:ring-0"
|
|
||||||
value={prompt}
|
|
||||||
onChange={(e) => setPrompt(e.target.value)}
|
|
||||||
placeholder="Enter your prompt..."
|
|
||||||
/>
|
|
||||||
<div className="h-full">
|
|
||||||
{getTaskFromPromptMutation.isPending ||
|
|
||||||
saveTaskMutation.isPending ||
|
|
||||||
runTaskMutation.isPending ? (
|
|
||||||
<ReloadIcon className="h-6 w-6 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<PaperPlaneIcon
|
|
||||||
className="h-6 w-6 cursor-pointer"
|
|
||||||
onClick={async () => {
|
|
||||||
const taskGenerationResponse =
|
|
||||||
await getTaskFromPromptMutation.mutateAsync(prompt);
|
|
||||||
await saveTaskMutation.mutateAsync(taskGenerationResponse);
|
|
||||||
await runTaskMutation.mutateAsync(taskGenerationResponse);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="mt-4 flex flex-wrap justify-center gap-4">
|
|
||||||
{examplePrompts.map((examplePrompt) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={examplePrompt}
|
|
||||||
className="cursor-pointer rounded-xl border p-2 text-sm text-muted-foreground"
|
|
||||||
onClick={() => {
|
|
||||||
setPrompt(examplePrompt);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{examplePrompt}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
<section className="py-4">
|
<section>
|
||||||
<header>
|
{templateSwitchValue === "skyvern" ? (
|
||||||
<h1 className="text-3xl">Your Templates</h1>
|
<div className="grid grid-cols-4 gap-4">
|
||||||
</header>
|
{Object.entries(templateSamples).map(([sampleKey, sample]) => {
|
||||||
<p className="mt-1 text-sm">Your saved task templates</p>
|
return (
|
||||||
<Separator className="mb-8 mt-2" />
|
<TaskTemplateCard
|
||||||
<SavedTasks />
|
key={sampleKey}
|
||||||
</section>
|
title={sample.title}
|
||||||
<section className="py-4">
|
description={getSample(sampleKey as SampleCase).url}
|
||||||
<header>
|
body={sample.description}
|
||||||
<h1 className="text-3xl">Skyvern Templates</h1>
|
|
||||||
</header>
|
|
||||||
<p className="mt-1 text-sm">
|
|
||||||
Sample tasks that showcase Skyvern's capabilities
|
|
||||||
</p>
|
|
||||||
<Separator className="mb-8 mt-2" />
|
|
||||||
<div className="grid grid-cols-4 gap-4">
|
|
||||||
{Object.entries(templateSamples).map(([sampleKey, sample]) => {
|
|
||||||
return (
|
|
||||||
<Card key={sampleKey}>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>{sample.title}</CardTitle>
|
|
||||||
<CardDescription className="overflow-hidden text-ellipsis whitespace-nowrap">
|
|
||||||
{getSample(sampleKey as SampleCase).url}
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent
|
|
||||||
className="h-48 cursor-pointer hover:bg-muted/40"
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(sampleKey);
|
navigate(`/create/${sampleKey}`);
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
{sample.description}
|
);
|
||||||
</CardContent>
|
})}
|
||||||
</Card>
|
</div>
|
||||||
);
|
) : (
|
||||||
})}
|
<SavedTasks />
|
||||||
</div>
|
)}
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user