Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Change how parameters look in task node (#851)
Kerem Yilmazbd12625fb9e9
diff --git a/skyvern-frontend/package-lock.json b/skyvern-frontend/package-lock.jsonindex f6fba3fed..c97fee720 100644--- a/skyvern-frontend/package-lock.json+++ b/skyvern-frontend/package-lock.json@@ -35,6 +35,7 @@"axios": "^1.6.8","class-variance-authority": "^0.7.0","clsx": "^2.1.0",+ "cmdk": "^1.0.0","cors": "^2.8.5","embla-carousel-react": "^8.0.0","express": "^4.19.2",@@ -3856,6 +3857,19 @@"node": ">=6"}},+ "node_modules/cmdk": {+ "version": "1.0.0",+ "resolved": "https://registry.npmjs.org/cmdk/-/cmdk-1.0.0.tgz",+ "integrity": "sha512-gDzVf0a09TvoJ5jnuPvygTB77+XdOSwEmJ88L6XPFPlv7T3RxbP9jgenfylrAMD0+Le1aO0nVjQUzl2g+vjz5Q==",+ "dependencies": {+ "@radix-ui/react-dialog": "1.0.5",+ "@radix-ui/react-primitive": "1.0.3"+ },+ "peerDependencies": {+ "react": "^18.0.0",+ "react-dom": "^18.0.0"+ }+ },"node_modules/codemirror": {"version": "6.0.1","resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.1.tgz",diff --git a/skyvern-frontend/package.json b/skyvern-frontend/package.jsonindex a75780c59..cbdb3dcfc 100644--- a/skyvern-frontend/package.json+++ b/skyvern-frontend/package.json@@ -43,6 +43,7 @@"axios": "^1.6.8","class-variance-authority": "^0.7.0","clsx": "^2.1.0",+ "cmdk": "^1.0.0","cors": "^2.8.5","embla-carousel-react": "^8.0.0","express": "^4.19.2",diff --git a/skyvern-frontend/src/components/ui/command.tsx b/skyvern-frontend/src/components/ui/command.tsxnew file mode 100644index 000000000..bbd300645--- /dev/null+++ b/skyvern-frontend/src/components/ui/command.tsx@@ -0,0 +1,153 @@+import * as React from "react";+import { type DialogProps } from "@radix-ui/react-dialog";+import { MagnifyingGlassIcon } from "@radix-ui/react-icons";+import { Command as CommandPrimitive } from "cmdk";++import { cn } from "@/util/utils";+import { Dialog, DialogContent } from "@/components/ui/dialog";++const Command = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive>+>(({ className, ...props }, ref) => (+ <CommandPrimitive+ ref={ref}+ className={cn(+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",+ className,+ )}+ {...props}+ />+));+Command.displayName = CommandPrimitive.displayName;++interface CommandDialogProps extends DialogProps {}++const CommandDialog = ({ children, ...props }: CommandDialogProps) => {+ return (+ <Dialog {...props}>+ <DialogContent className="overflow-hidden p-0">+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ {children}+ </Command>+ </DialogContent>+ </Dialog>+ );+};++const CommandInput = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Input>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>+>(({ className, ...props }, ref) => (+ <div className="flex items-center border-b px-3" cmdk-input-wrapper="">+ <MagnifyingGlassIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" />+ <CommandPrimitive.Input+ ref={ref}+ className={cn(+ "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",+ className,+ )}+ {...props}+ />+ </div>+));++CommandInput.displayName = CommandPrimitive.Input.displayName;++const CommandList = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.List>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.List+ ref={ref}+ className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}+ {...props}+ />+));++CommandList.displayName = CommandPrimitive.List.displayName;++const CommandEmpty = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Empty>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>+>((props, ref) => (+ <CommandPrimitive.Empty+ ref={ref}+ className="py-6 text-center text-sm"+ {...props}+ />+));++CommandEmpty.displayName = CommandPrimitive.Empty.displayName;++const CommandGroup = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Group>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Group+ ref={ref}+ className={cn(+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",+ className,+ )}+ {...props}+ />+));++CommandGroup.displayName = CommandPrimitive.Group.displayName;++const CommandSeparator = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Separator>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Separator+ ref={ref}+ className={cn("-mx-1 h-px bg-border", className)}+ {...props}+ />+));+CommandSeparator.displayName = CommandPrimitive.Separator.displayName;++const CommandItem = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Item+ ref={ref}+ className={cn(+ "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",+ className,+ )}+ {...props}+ />+));++CommandItem.displayName = CommandPrimitive.Item.displayName;++const CommandShortcut = ({+ className,+ ...props+}: React.HTMLAttributes<HTMLSpanElement>) => {+ return (+ <span+ className={cn(+ "ml-auto text-xs tracking-widest text-muted-foreground",+ className,+ )}+ {...props}+ />+ );+};+CommandShortcut.displayName = "CommandShortcut";++export {+ Command,+ CommandDialog,+ CommandInput,+ CommandList,+ CommandEmpty,+ CommandGroup,+ CommandItem,+ CommandShortcut,+ CommandSeparator,+};diff --git a/skyvern-frontend/src/components/ui/multi-select.tsx b/skyvern-frontend/src/components/ui/multi-select.tsxnew file mode 100644index 000000000..84b38ae17--- /dev/null+++ b/skyvern-frontend/src/components/ui/multi-select.tsx@@ -0,0 +1,338 @@+import * as React from "react";+import { cva, type VariantProps } from "class-variance-authority";++import {+ CheckIcon,+ Cross2Icon,+ CrossCircledIcon,+ ChevronDownIcon,+} from "@radix-ui/react-icons";++import { cn } from "@/util/utils";+import { Separator } from "@/components/ui/separator";+import { Button } from "@/components/ui/button";+import { Badge } from "@/components/ui/badge";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";+import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ CommandSeparator,+} from "@/components/ui/command";++/**+ * Variants for the multi-select component to handle different styles.+ * Uses class-variance-authority (cva) to define different styles based on "variant" prop.+ */+const multiSelectVariants = cva("m-1", {+ variants: {+ variant: {+ default: "border-foreground/10 text-foreground bg-card hover:bg-card/80",+ secondary:+ "border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80",+ destructive:+ "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",+ inverted: "inverted",+ },+ },+ defaultVariants: {+ variant: "default",+ },+});++/**+ * Props for MultiSelect component+ */+interface MultiSelectProps+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,+ VariantProps<typeof multiSelectVariants> {+ /**+ * An array of option objects to be displayed in the multi-select component.+ * Each option object has a label, value, and an optional icon.+ */+ options: {+ /** The text to display for the option. */+ label: string;+ /** The unique value associated with the option. */+ value: string;+ /** Optional icon component to display alongside the option. */+ icon?: React.ComponentType<{ className?: string }>;+ }[];++ /**+ * Callback function triggered when the selected values change.+ * Receives an array of the new selected values.+ */+ onValueChange: (value: string[]) => void;++ /** The default selected values when the component mounts. */+ value: string[];++ /**+ * Placeholder text to be displayed when no values are selected.+ * Optional, defaults to "Select options".+ */+ placeholder?: string;++ /**+ * Maximum number of items to display. Extra selected items will be summarized.+ * Optional, defaults to 3.+ */+ maxCount?: number;++ /**+ * The modality of the popover. When set to true, interaction with outside elements+ * will be disabled and only popover content will be visible to screen readers.+ * Optional, defaults to false.+ */+ modalPopover?: boolean;++ /**+ * Additional class names to apply custom styles to the multi-select component.+ * Optional, can be used to add custom styles.+ */+ className?: string;+}++export const MultiSelect = React.forwardRef<+ HTMLButtonElement,+ MultiSelectProps+>(+ (+ {+ options,+ onValueChange,+ variant,+ value,+ placeholder = "Select options",+ maxCount = 3,+ modalPopover = false,+ className,+ ...props+ },+ ref,+ ) => {+ const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);++ const handleInputKeyDown = (+ event: React.KeyboardEvent<HTMLInputElement>,+ ) => {+ if (event.key === "Enter") {+ setIsPopoverOpen(true);+ } else if (event.key === "Backspace" && !event.currentTarget.value) {+ const newSelectedValues = [...value];+ newSelectedValues.pop();+ onValueChange(newSelectedValues);+ }+ };++ const toggleOption = (option: string) => {+ const newSelectedValues = value.includes(option)+ ? value.filter((v) => v !== option)+ : [...value, option];+ onValueChange(newSelectedValues);+ };++ const handleClear = () => {+ onValueChange([]);+ };++ const handleTogglePopover = () => {+ setIsPopoverOpen((prev) => !prev);+ };++ const clearExtraOptions = () => {+ const newSelectedValues = value.slice(0, maxCount);+ onValueChange(newSelectedValues);+ };++ const toggleAll = () => {+ if (value.length === options.length) {+ handleClear();+ } else {+ const allValues = options.map((option) => option.value);+ onValueChange(allValues);+ }+ };++ return (+ <Popover+ open={isPopoverOpen}+ onOpenChange={setIsPopoverOpen}+ modal={modalPopover}+ >+ <PopoverTrigger asChild>+ <Button+ ref={ref}+ {...props}+ onClick={handleTogglePopover}+ className={cn(+ "flex h-auto min-h-10 w-full items-center justify-between rounded-md border bg-inherit p-1 hover:bg-inherit",+ className,+ )}+ >+ {value.length > 0 ? (+ <div className="flex w-full items-center justify-between">+ <div className="flex flex-wrap items-center">+ {value.slice(0, maxCount).map((value) => {+ const option = options.find((o) => o.value === value);+ const IconComponent = option?.icon;+ return (+ <Badge+ key={value}+ className={cn(multiSelectVariants({ variant }))}+ >+ {IconComponent && (+ <IconComponent className="mr-2 h-4 w-4" />+ )}+ {option?.label}+ <CrossCircledIcon+ className="ml-2 h-4 w-4 cursor-pointer"+ onClick={(event) => {+ event.stopPropagation();+ toggleOption(value);+ }}+ />+ </Badge>+ );+ })}+ {value.length > maxCount && (+ <Badge+ className={cn(+ "border-foreground/1 bg-transparent text-foreground hover:bg-transparent",+ multiSelectVariants({ variant }),+ )}+ >+ {`+ ${value.length - maxCount} more`}+ <CrossCircledIcon+ className="ml-2 h-4 w-4 cursor-pointer"+ onClick={(event) => {+ event.stopPropagation();+ clearExtraOptions();+ }}+ />+ </Badge>+ )}+ </div>+ <div className="flex items-center justify-between">+ <Cross2Icon+ className="mx-2 h-4 cursor-pointer text-muted-foreground"+ onClick={(event) => {+ event.stopPropagation();+ handleClear();+ }}+ />+ <Separator+ orientation="vertical"+ className="flex h-full min-h-6"+ />+ <ChevronDownIcon className="mx-2 h-4 cursor-pointer text-muted-foreground" />+ </div>+ </div>+ ) : (+ <div className="mx-auto flex w-full items-center justify-between">+ <span className="mx-3 text-sm text-muted-foreground">+ {placeholder}+ </span>+ <ChevronDownIcon className="mx-2 h-4 cursor-pointer text-muted-foreground" />+ </div>+ )}+ </Button>+ </PopoverTrigger>+ <PopoverContent+ className="w-auto p-0"+ align="start"+ onEscapeKeyDown={() => setIsPopoverOpen(false)}+ >+ <Command>+ <CommandInput+ placeholder="Search..."+ onKeyDown={handleInputKeyDown}+ />+ <CommandList>+ <CommandEmpty>No results found.</CommandEmpty>+ <CommandGroup>+ <CommandItem+ key="all"+ onSelect={toggleAll}+ className="cursor-pointer"+ >+ <div+ className={cn(+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",+ value.length === options.length+ ? "bg-primary text-primary-foreground"+ : "opacity-50 [&_svg]:invisible",+ )}+ >+ <CheckIcon className="h-4 w-4" />+ </div>+ <span>(Select All)</span>+ </CommandItem>+ {options.map((option) => {+ const isSelected = value.includes(option.value);+ return (+ <CommandItem+ key={option.value}+ onSelect={() => toggleOption(option.value)}+ className="cursor-pointer"+ >+ <div+ className={cn(+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",+ isSelected+ ? "bg-primary text-primary-foreground"+ : "opacity-50 [&_svg]:invisible",+ )}+ >+ <CheckIcon className="h-4 w-4" />+ </div>+ {option.icon && (+ <option.icon className="mr-2 h-4 w-4 text-muted-foreground" />+ )}+ <span>{option.label}</span>+ </CommandItem>+ );+ })}+ </CommandGroup>+ <CommandSeparator />+ <CommandGroup>+ <div className="flex items-center justify-between">+ {value.length > 0 && (+ <>+ <CommandItem+ onSelect={handleClear}+ className="flex-1 cursor-pointer justify-center"+ >+ Clear+ </CommandItem>+ <Separator+ orientation="vertical"+ className="flex h-full min-h-6"+ />+ </>+ )}+ <CommandItem+ onSelect={() => setIsPopoverOpen(false)}+ className="max-w-full flex-1 cursor-pointer justify-center"+ >+ Close+ </CommandItem>+ </div>+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ );+ },+);++MultiSelect.displayName = "MultiSelect";diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNodeParametersPanel.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNodeParametersPanel.tsxindex 3e526c907..db0e8f8e2 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNodeParametersPanel.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNodeParametersPanel.tsx@@ -1,6 +1,4 @@-import { Checkbox } from "@/components/ui/checkbox";-import { useWorkflowParametersState } from "../../useWorkflowParametersState";-import { Label } from "@/components/ui/label";+import { MultiSelect } from "@/components/ui/multi-select";import {Tooltip,TooltipContent,@@ -8,6 +6,7 @@ import {TooltipTrigger,} from "@/components/ui/tooltip";import { QuestionMarkCircledIcon } from "@radix-ui/react-icons";+import { useWorkflowParametersState } from "../../useWorkflowParametersState";type Props = {availableOutputParameters: Array<string>;@@ -25,15 +24,12 @@ function TaskNodeParametersPanel({.map((parameter) => parameter.key).concat(availableOutputParameters);- function toggleParameter(key: string) {- if (parameters.includes(key)) {- onParametersChange(- parameters.filter((parameterKey) => parameterKey !== key),- );- } else {- onParametersChange([...parameters, key]);- }- }+ const options = keys.map((key) => {+ return {+ label: key,+ value: key,+ };+ });return (<div className="space-y-4">@@ -50,33 +46,13 @@ function TaskNodeParametersPanel({</Tooltip></TooltipProvider></header>- <div className="flex flex-wrap gap-2">- {keys.map((key) => {- return (- <div- key={key}- className="flex cursor-pointer items-center gap-2 rounded-sm bg-slate-elevation1 px-3 py-2"- id={key}- >- <Checkbox- checked={parameters.includes(key)}- onCheckedChange={() => {- toggleParameter(key);- }}- />- <Label- htmlFor={key}- className="cursor-pointer text-xs"- onClick={() => {- toggleParameter(key);- }}- >- {key}- </Label>- </div>- );- })}- </div>+ <MultiSelect+ defaultValue={parameters}+ value={parameters}+ onValueChange={onParametersChange}+ options={options}+ maxCount={50}+ /></div>);}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/EditableNodeTitle.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/EditableNodeTitle.tsxindex e228ed1bb..b0d13eb2c 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/EditableNodeTitle.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/EditableNodeTitle.tsx@@ -42,7 +42,6 @@ function EditableNodeTitle({<HorizontallyResizingInputdisabled={!editable}size={1}- autoFocusclassName={cn("nopan w-min border-0 p-0", inputClassName)}onBlur={(event) => {if (!editable) {diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex 6f836f6d5..a43d06615 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -658,6 +658,17 @@ function getOutputParameterKey(label: string) {return label + "_output";}+function isOutputParameterKey(value: string) {+ return value.endsWith("_output");+}++function getBlockNameOfOutputParameterKey(value: string) {+ if (isOutputParameterKey(value)) {+ return value.substring(0, value.length - 7);+ }+ return value;+}+function getUpdatedNodesAfterLabelUpdateForParameterKeys(id: string,newLabel: string,@@ -765,4 +776,6 @@ export {getUpdatedNodesAfterLabelUpdateForParameterKeys,getAdditionalParametersForEmailBlock,getLabelForExistingNode,+ isOutputParameterKey,+ getBlockNameOfOutputParameterKey,};