Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(workflow): ValidationBlock data_extraction_goal/data_schema frontend (#6067)
Aaron Perez93ca06e94b3d
diff --git a/skyvern-frontend/src/routes/workflows/editor/constants.ts b/skyvern-frontend/src/routes/workflows/editor/constants.tsindex e10b23d94..4d5b43aa6 100644--- a/skyvern-frontend/src/routes/workflows/editor/constants.ts+++ b/skyvern-frontend/src/routes/workflows/editor/constants.ts@@ -95,6 +95,7 @@ export const AI_IMPROVE_CONFIGS = {dataSchema: createAiImproveConfig("extraction", "data_schema"),},validation: {+ navigationGoal: createAiImproveConfig("validation", "navigation_goal"),completeCriterion: createAiImproveConfig("validation","complete_criterion",@@ -103,6 +104,11 @@ export const AI_IMPROVE_CONFIGS = {"validation","terminate_criterion",),+ dataExtractionGoal: createAiImproveConfig(+ "validation",+ "data_extraction_goal",+ ),+ dataSchema: createAiImproveConfig("validation", "data_schema"),},login: {navigationGoal: createAiImproveConfig("login", "navigation_goal"),diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsxindex 2856f4254..81a70c5fd 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx@@ -11,12 +11,13 @@ import { Label } from "@/components/ui/label";import { Switch } from "@/components/ui/switch";import { Separator } from "@/components/ui/separator";import { WorkflowBlockInputTextarea } from "@/components/WorkflowBlockInputTextarea";+import { WorkflowDataSchemaInputGroup } from "@/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup";import { BlockCodeEditor } from "@/routes/workflows/components/BlockCodeEditor";import { ErrorCodeMappingEditor } from "@/routes/workflows/editor/ErrorCodeMappingEditor";import { useBlockScriptStore } from "@/store/BlockScriptStore";import { Handle, NodeProps, Position, useEdges, useNodes } from "@xyflow/react";-import { helpTooltips } from "../../helpContent";-import { errorMappingExampleValue } from "../types";+import { helpTooltips, placeholders } from "../../helpContent";+import { dataSchemaExampleValue, errorMappingExampleValue } from "../types";import type { ValidationNode } from "./types";import { AppNode } from "..";import {@@ -131,11 +132,101 @@ function ValidationNode({ id, data, type }: NodeProps<ValidationNode>) {/></div><Separator />- <Accordion- type="single"- collapsible- onValueChange={() => rerender.bump()}- >+ <Accordion type="multiple" onValueChange={() => rerender.bump()}>+ <AccordionItem value="extraction">+ <AccordionTrigger className="py-0">Extraction</AccordionTrigger>+ <AccordionContent className="pl-[1.5rem] pr-1 pt-4">+ <div key={`${rerender.key}-extraction`} className="space-y-4">+ <div className="space-y-2">+ <div className="flex gap-2">+ <Label className="text-xs text-slate-300">+ Navigation Goal+ </Label>+ <HelpTooltip+ content={helpTooltips["validation"]["navigationGoal"]}+ />+ </div>+ <WorkflowBlockInputTextarea+ aiImprove={{+ useCase:+ AI_IMPROVE_CONFIGS.validation.navigationGoal.useCase,+ context: {+ ...AI_IMPROVE_CONFIGS.validation.navigationGoal+ .context,+ data_extraction_goal:+ data.dataExtractionGoal || undefined,+ complete_criterion:+ data.completeCriterion || undefined,+ terminate_criterion:+ data.terminateCriterion || undefined,+ },+ }}+ nodeId={id}+ onChange={(value) => {+ update({ navigationGoal: value });+ }}+ value={data.navigationGoal}+ placeholder={placeholders["validation"]["navigationGoal"]}+ className="nopan text-xs"+ />+ </div>+ <div className="space-y-2">+ <div className="flex gap-2">+ <Label className="text-xs text-slate-300">+ Data Extraction Goal+ </Label>+ <HelpTooltip+ content={+ helpTooltips["validation"]["dataExtractionGoal"]+ }+ />+ </div>+ <WorkflowBlockInputTextarea+ aiImprove={{+ useCase:+ AI_IMPROVE_CONFIGS.validation.dataExtractionGoal+ .useCase,+ context: {+ ...AI_IMPROVE_CONFIGS.validation.dataExtractionGoal+ .context,+ navigation_goal: data.navigationGoal || undefined,+ data_schema:+ data.dataSchema && data.dataSchema !== "null"+ ? data.dataSchema+ : undefined,+ complete_criterion:+ data.completeCriterion || undefined,+ terminate_criterion:+ data.terminateCriterion || undefined,+ },+ }}+ nodeId={id}+ onChange={(value) => {+ update({ dataExtractionGoal: value });+ }}+ value={data.dataExtractionGoal}+ placeholder={+ placeholders["validation"]["dataExtractionGoal"]+ }+ className="nopan text-xs"+ />+ </div>+ <WorkflowDataSchemaInputGroup+ exampleValue={dataSchemaExampleValue}+ onChange={(value) => {+ update({ dataSchema: value });+ }}+ value={data.dataSchema}+ suggestionContext={{+ data_extraction_goal: data.dataExtractionGoal,+ current_schema: data.dataSchema,+ complete_criterion: data.completeCriterion,+ terminate_criterion: data.terminateCriterion,+ }}+ />+ </div>+ </AccordionContent>+ </AccordionItem><AccordionItem value="advanced" className="border-b-0"><AccordionTrigger className="py-0">Advanced Settingsdiff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/types.tsindex d8ff2b935..0f483da2e 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/types.ts+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/types.ts@@ -5,8 +5,11 @@ export type ValidationNodeData = NodeBaseData & {completeCriterion: string;terminateCriterion: string;errorCodeMapping: string;+ navigationGoal: string;parameterKeys: Array<string>;disableCache: boolean;+ dataExtractionGoal: string;+ dataSchema: string;};export type ValidationNode = Node<ValidationNodeData, "validation">;@@ -17,11 +20,14 @@ export const validationNodeDefaultData: ValidationNodeData = {completeCriterion: "",terminateCriterion: "",errorCodeMapping: "null",+ navigationGoal: "",continueOnFailure: false,editable: true,parameterKeys: [],disableCache: false,model: null,+ dataExtractionGoal: "",+ dataSchema: "null",};export function isValidationNode(node: Node): node is ValidationNode {diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex a75700ff4..17b53453a 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -708,10 +708,18 @@ function convertToNode(data: {...commonData,errorCodeMapping: JSON.stringify(block.error_code_mapping, null, 2),+ navigationGoal: block.navigation_goal ?? "",completeCriterion: block.complete_criterion ?? "",terminateCriterion: block.terminate_criterion ?? "",parameterKeys: block.parameters.map((p) => p.key),disableCache: block.disable_cache ?? false,+ dataExtractionGoal: block.data_extraction_goal ?? "",+ dataSchema:+ block.data_schema == null+ ? "null"+ : typeof block.data_schema === "string"+ ? block.data_schema+ : JSON.stringify(block.data_schema, null, 2),},};}@@ -2483,6 +2491,7 @@ function getWorkflowBlock(return {...base,block_type: "validation",+ navigation_goal: node.data.navigationGoal || null,complete_criterion: node.data.completeCriterion,terminate_criterion: node.data.terminateCriterion,error_code_mapping: JSONParseSafe(node.data.errorCodeMapping) as Record<@@ -2490,6 +2499,9 @@ function getWorkflowBlock(string> | null,parameter_keys: node.data.parameterKeys,+ data_extraction_goal: node.data.dataExtractionGoal || null,+ data_schema: JSONSafeOrString(node.data.dataSchema),+ disable_cache: node.data.disableCache ?? false,};}case "human_interaction": {@@ -3964,10 +3976,14 @@ function convertBlocksToBlockYAML(const blockYaml: ValidationBlockYAML = {...base,block_type: "validation",+ navigation_goal: block.navigation_goal ?? null,complete_criterion: block.complete_criterion,terminate_criterion: block.terminate_criterion,error_code_mapping: block.error_code_mapping,parameter_keys: block.parameters.map((p) => p.key),+ data_extraction_goal: block.data_extraction_goal ?? null,+ data_schema: block.data_schema ?? null,+ disable_cache: block.disable_cache ?? false,};return blockYaml;}@@ -4421,6 +4437,23 @@ function getWorkflowErrors(nodes: Array<AppNode>): Array<string> {`${node.data.label}: At least one of completion or termination criteria must be provided`,);}+ if (+ node.data.dataExtractionGoal.trim().length > 0 &&+ node.data.navigationGoal.trim().length === 0+ ) {+ errors.push(+ `${node.data.label}: Navigation Goal is required when Data Extraction Goal is set`,+ );+ }+ if (node.data.dataSchema && node.data.dataSchema !== "null") {+ const result = TSON.parse(node.data.dataSchema);++ if (!result.success) {+ errors.push(+ `${node.data.label}: Data schema has invalid templated JSON: ${result.error ?? "-"}`,+ );+ }+ }});const interactionNodes = nodes.filter(isHumanInteractionNode);diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.tsindex c67754bf8..d955c1c72 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts@@ -436,11 +436,14 @@ export type FileURLParserBlock = WorkflowBlockBase & {export type ValidationBlock = WorkflowBlockBase & {block_type: "validation";+ navigation_goal?: string | null;complete_criterion: string | null;terminate_criterion: string | null;error_code_mapping: Record<string, string> | null;parameters: Array<WorkflowParameter>;disable_cache?: boolean;+ data_extraction_goal?: string | null;+ data_schema?: Record<string, unknown> | string | null;};export type HumanInteractionBlock = WorkflowBlockBase & {diff --git a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.tsindex 0ca686730..4cc022373 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts@@ -194,10 +194,14 @@ export type Taskv2BlockYAML = BlockYAMLBase & {export type ValidationBlockYAML = BlockYAMLBase & {block_type: "validation";+ navigation_goal?: string | null;complete_criterion: string | null;terminate_criterion: string | null;error_code_mapping: Record<string, string> | null;parameter_keys?: Array<string> | null;+ data_extraction_goal?: string | null;+ data_schema?: Record<string, unknown> | string | null;+ disable_cache?: boolean;};export type HumanInteractionBlockYAML = BlockYAMLBase & {