Skip to content

Automate browser based workflows with AI

Re-apply data_schema support for natural language loop blocks (SKY-7055) — frontend (#4881)

Celal Zamanoğlufec135550d8c
diff --git a/skyvern-frontend/src/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup.tsx b/skyvern-frontend/src/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup.tsx
index 863012a44..9a5612be4 100644
--- a/skyvern-frontend/src/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup.tsx
+++ b/skyvern-frontend/src/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup.tsx
@@ -34,6 +34,7 @@ type Props = {
onChange: (value: string) => void;
suggestionContext: Record<string, unknown>;
exampleValue: Record<string, unknown>;
+ helpTooltip?: string;
};
function WorkflowDataSchemaInputGroup({
@@ -41,6 +42,7 @@ function WorkflowDataSchemaInputGroup({
onChange,
suggestionContext,
exampleValue,
+ helpTooltip,
}: Props) {
const credentialGetter = useCredentialGetter();
const [generateWithAIActive, setGenerateWithAIActive] = useState(false);
@@ -91,7 +93,9 @@ function WorkflowDataSchemaInputGroup({
<div className="flex gap-4">
<div className="flex gap-2">
<Label className="text-xs text-slate-300">Data Schema</Label>
- <HelpTooltip content={helpTooltips["task"]["dataSchema"]} />
+ <HelpTooltip
+ content={helpTooltip ?? helpTooltips["task"]["dataSchema"]}
+ />
</div>
<Checkbox
checked={value !== "null"}
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index 8f2700cf8..18ec02dc5 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -406,6 +406,26 @@ function FlowRenderer({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [targettedBlockLabel]);
+ // Re-layout when a loop node's header height changes (e.g., data schema toggled)
+ useEffect(() => {
+ const handleLoopHeaderResized = () => {
+ // Delay to let React process the updateNodeData state change
+ setTimeout(() => {
+ const currentNodes = reactFlowInstance.getNodes() as Array<AppNode>;
+ const currentEdges = reactFlowInstance.getEdges();
+ debouncedLayoutForDimensions(currentNodes, currentEdges);
+ }, 10);
+ };
+
+ window.addEventListener("loop-header-resized", handleLoopHeaderResized);
+ return () => {
+ window.removeEventListener(
+ "loop-header-resized",
+ handleLoopHeaderResized,
+ );
+ };
+ }, [reactFlowInstance, debouncedLayoutForDimensions]);
+
useEffect(() => {
const topLevelBlocks = getWorkflowBlocks(nodes, edges);
const debuggable = topLevelBlocks.filter((block) =>
diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
index a927a5d65..29ffacec9 100644
--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
@@ -728,6 +728,28 @@ function Workspace({
};
}, [getNodes, getEdges, setNodes, setEdges, blockLabel]);
+ // Re-layout when a loop node's header height changes (e.g., data schema toggled)
+ useEffect(() => {
+ const handleLoopHeaderResized = () => {
+ setTimeout(() => {
+ const currentNodes = getNodes() as Array<AppNode>;
+ const currentEdges = getEdges();
+
+ const layoutedElements = layout(currentNodes, currentEdges, blockLabel);
+ setNodes(layoutedElements.nodes);
+ setEdges(layoutedElements.edges);
+ }, 10);
+ };
+
+ window.addEventListener("loop-header-resized", handleLoopHeaderResized);
+ return () => {
+ window.removeEventListener(
+ "loop-header-resized",
+ handleLoopHeaderResized,
+ );
+ };
+ }, [getNodes, getEdges, setNodes, setEdges, blockLabel]);
+
function addNode({
nodeType,
previous,
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx
index 2af492407..0f48e207d 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx
@@ -1,10 +1,19 @@
+import { useEffect, useRef } from "react";
import { HelpTooltip } from "@/components/HelpTooltip";
import { Label } from "@/components/ui/label";
import { WorkflowBlockInput } from "@/components/WorkflowBlockInput";
+import { WorkflowDataSchemaInputGroup } from "@/components/DataSchemaInputGroup/WorkflowDataSchemaInputGroup";
import type { Node } from "@xyflow/react";
-import { Handle, NodeProps, Position, useNodes } from "@xyflow/react";
+import {
+ Handle,
+ NodeProps,
+ Position,
+ useNodes,
+ useReactFlow,
+} from "@xyflow/react";
import { AppNode } from "..";
import { helpTooltips } from "../../helpContent";
+import { dataSchemaExampleValue } from "../types";
import type { LoopNode } from "./types";
import { useIsFirstBlockInWorkflow } from "../../hooks/useIsFirstNodeInWorkflow";
import { Checkbox } from "@/components/ui/checkbox";
@@ -36,6 +45,28 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {
const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });
const children = nodes.filter((node) => node.parentId === id);
const recordingStore = useRecordingStore();
+ const headerRef = useRef<HTMLDivElement>(null);
+ const { updateNodeData } = useReactFlow();
+ const lastHeaderHeight = useRef<number | undefined>(undefined);
+
+ useEffect(() => {
+ const el = headerRef.current;
+ if (!el) return;
+
+ const observer = new ResizeObserver(() => {
+ // Use offsetHeight to include padding (py-4 = 32px) in the measurement
+ const height = Math.round(el.offsetHeight);
+ if (lastHeaderHeight.current !== height) {
+ lastHeaderHeight.current = height;
+ updateNodeData(id, { _headerHeight: height });
+ // Trigger re-layout after React processes the data update
+ window.dispatchEvent(new Event("loop-header-resized"));
+ }
+ });
+
+ observer.observe(el);
+ return () => observer.disconnect();
+ }, [id, updateNodeData]);
const furthestDownChild: Node | null = children.reduce(
(acc, child) => {
@@ -84,6 +115,7 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {
>
<div className="flex w-full justify-center">
<div
+ ref={headerRef}
className={cn(
"transform-origin-center w-[30rem] space-y-4 rounded-lg bg-slate-elevation3 px-6 py-4 transition-all",
{
@@ -122,6 +154,17 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {
}}
/>
</div>
+ <WorkflowDataSchemaInputGroup
+ value={data.dataSchema}
+ onChange={(value) => {
+ update({ dataSchema: value });
+ }}
+ suggestionContext={{
+ loop_variable_reference: data.loopVariableReference,
+ }}
+ exampleValue={dataSchemaExampleValue}
+ helpTooltip="Specify a format for extracted data in JSON. Only applies when the loop value is natural language — ignored for parameter references."
+ />
<div className="space-y-2">
<div className="space-y-2">
<div className="flex justify-between">
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/types.ts
index 5c62c06c4..f10b052f5 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/types.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/types.ts
@@ -8,6 +8,8 @@ export type LoopNodeData = NodeBaseData & {
completeIfEmpty: boolean;
continueOnFailure: boolean;
nextLoopOnFailure?: boolean;
+ dataSchema: string;
+ _headerHeight?: number; // internal: measured header card height for layout
};
export type LoopNode = Node<LoopNodeData, "loop">;
@@ -22,6 +24,7 @@ export const loopNodeDefaultData: LoopNodeData = {
continueOnFailure: false,
nextLoopOnFailure: false,
model: null,
+ dataSchema: "null",
} as const;
export function isLoopNode(node: Node): node is LoopNode {
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index 11c2bfa93..629b158da 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -297,7 +297,16 @@ function layout(
const nodeLabel = isWorkflowBlockNode(node) ? node.data.label : undefined;
const isTargetted =
targettedBlockLabel && nodeLabel === targettedBlockLabel;
- const marginy = isTargetted ? 225 + TARGETTED_BLOCK_EXTRA_MARGIN : 225;
+ // Use measured header height when available, fall back to 225 for initial render.
+ // Add 28px to account for outer container (border-2 + p-2 = 10px) + gap (16px) + buffer.
+ const headerHeight = isLoopNode(node) ? node.data._headerHeight : undefined;
+ const baseMargin = headerHeight ? headerHeight + 28 : 225;
+ // Only add extra margin for the status row when using the fallback height,
+ // since the measured height already includes the status row content.
+ const marginy =
+ isTargetted && !headerHeight
+ ? baseMargin + TARGETTED_BLOCK_EXTRA_MARGIN
+ : baseMargin;
const layouted = layoutUtil(
childNodesWithResetPositions,
childEdges,
@@ -506,9 +515,11 @@ function convertToNode(
navigationGoal: block.navigation_goal ?? "",
dataExtractionGoal: block.data_extraction_goal ?? "",
dataSchema:
- typeof block.data_schema === "string"
- ? block.data_schema
- : JSON.stringify(block.data_schema, null, 2),
+ block.data_schema == null
+ ? "null"
+ : typeof block.data_schema === "string"
+ ? block.data_schema
+ : JSON.stringify(block.data_schema, null, 2),
errorCodeMapping: JSON.stringify(block.error_code_mapping, null, 2),
allowDownloads: block.complete_on_download ?? false,
downloadSuffix: block.download_suffix ?? null,
@@ -653,9 +664,11 @@ function convertToNode(
url: block.url ?? "",
dataExtractionGoal: block.data_extraction_goal ?? "",
dataSchema:
- typeof block.data_schema === "string"
- ? block.data_schema
- : JSON.stringify(block.data_schema, null, 2),
+ block.data_schema == null
+ ? "null"
+ : typeof block.data_schema === "string"
+ ? block.data_schema
+ : JSON.stringify(block.data_schema, null, 2),
parameterKeys: block.parameters.map((p) => p.key),
maxRetries: block.max_retries ?? null,
maxStepsOverride: block.max_steps_per_run ?? null,
@@ -778,6 +791,12 @@ function convertToNode(
loopVariableReference: loopVariableReference,
completeIfEmpty: block.complete_if_empty,
nextLoopOnFailure: block.next_loop_on_failure,
+ dataSchema:
+ block.data_schema == null
+ ? "null"
+ : typeof block.data_schema === "string"
+ ? block.data_schema
+ : JSON.stringify(block.data_schema, null, 2),
},
};
}
@@ -2514,6 +2533,7 @@ function getOrderedChildrenBlocks(
loop_blocks: loopChildren,
loop_variable_reference: currentNode.data.loopVariableReference,
complete_if_empty: currentNode.data.completeIfEmpty,
+ data_schema: JSONSafeOrString(currentNode.data.dataSchema),
});
} else {
children.push(getWorkflowBlock(currentNode, nodes, edges));
@@ -2550,6 +2570,7 @@ function getOrderedChildrenBlocks(
loop_blocks: loopChildren,
loop_variable_reference: node.data.loopVariableReference,
complete_if_empty: node.data.completeIfEmpty,
+ data_schema: JSONSafeOrString(node.data.dataSchema),
});
includedIds.add(node.id);
return;
@@ -2615,6 +2636,7 @@ function getWorkflowBlocksUtil(
loop_blocks: getOrderedChildrenBlocks(nodes, edges, node.id),
loop_variable_reference: node.data.loopVariableReference,
complete_if_empty: node.data.completeIfEmpty,
+ data_schema: JSONSafeOrString(node.data.dataSchema),
},
];
}
@@ -3722,6 +3744,7 @@ function convertBlocksToBlockYAML(
loop_blocks: convertBlocksToBlockYAML(block.loop_blocks),
loop_variable_reference: block.loop_variable_reference,
complete_if_empty: block.complete_if_empty,
+ data_schema: block.data_schema,
};
return blockYaml;
}
diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
index c50d3fca3..e28d60ad5 100644
--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts
@@ -352,6 +352,7 @@ export type ForLoopBlock = WorkflowBlockBase & {
loop_blocks: Array<WorkflowBlock>;
loop_variable_reference: string | null;
complete_if_empty: boolean;
+ data_schema?: Record<string, unknown> | string | null;
};
export type CodeBlock = WorkflowBlockBase & {
diff --git a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
index fa2ca1739..95e7b1006 100644
--- a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts
@@ -360,6 +360,7 @@ export type ForLoopBlockYAML = BlockYAMLBase & {
loop_blocks: Array<BlockYAML>;
loop_variable_reference: string | null;
complete_if_empty: boolean;
+ data_schema?: Record<string, unknown> | string | null;
};
export type BranchCriteriaYAML = {