Skip to content

Automate browser based workflows with AI

feat: autocomplete parameter names in workflow text blocks (#5293)

Celal Zamanoğlu0df44b7c1832
diff --git a/skyvern-frontend/src/components/ParameterAutocompleteDropdown.tsx b/skyvern-frontend/src/components/ParameterAutocompleteDropdown.tsx
new file mode 100644
index 000000000..d16727cab
--- /dev/null
+++ b/skyvern-frontend/src/components/ParameterAutocompleteDropdown.tsx
@@ -0,0 +1,134 @@
+import { useEffect, useRef } from "react";
+import { createPortal } from "react-dom";
+import type {
+ AvailableParameter,
+ ParameterCategory,
+} from "@/hooks/useAvailableParameters";
+
+type Props = {
+ items: AvailableParameter[];
+ selectedIndex: number;
+ anchorPosition: { top: number; left: number };
+ visible: boolean;
+ onSelect: (key: string) => void;
+ onDismiss: () => void;
+};
+
+const CATEGORY_LABELS: Record<ParameterCategory, string> = {
+ parameter: "Parameters",
+ output: "Block Outputs",
+ system: "System",
+};
+
+const CATEGORY_ORDER: ParameterCategory[] = ["parameter", "output", "system"];
+
+function groupByCategory(
+ items: AvailableParameter[],
+): Map<ParameterCategory, AvailableParameter[]> {
+ const groups = new Map<ParameterCategory, AvailableParameter[]>();
+ for (const item of items) {
+ const group = groups.get(item.category) ?? [];
+ group.push(item);
+ groups.set(item.category, group);
+ }
+ return groups;
+}
+
+function ParameterAutocompleteDropdown({
+ items,
+ selectedIndex,
+ anchorPosition,
+ visible,
+ onSelect,
+ onDismiss,
+}: Props) {
+ const listRef = useRef<HTMLDivElement>(null);
+ const selectedRef = useRef<HTMLDivElement>(null);
+
+ // Scroll the selected item into view
+ useEffect(() => {
+ selectedRef.current?.scrollIntoView({ block: "nearest" });
+ }, [selectedIndex]);
+
+ // Dismiss on outside click or scroll (prevents position drift in React Flow canvas)
+ useEffect(() => {
+ if (!visible) return;
+
+ const handleMouseDown = (e: MouseEvent) => {
+ if (listRef.current && !listRef.current.contains(e.target as Node)) {
+ onDismiss();
+ }
+ };
+ const handleScroll = (e: Event) => {
+ // Ignore scroll events from within the dropdown itself (e.g. scrollIntoView)
+ if (listRef.current && listRef.current.contains(e.target as Node)) {
+ return;
+ }
+ onDismiss();
+ };
+ document.addEventListener("mousedown", handleMouseDown);
+ document.addEventListener("scroll", handleScroll, true);
+ return () => {
+ document.removeEventListener("mousedown", handleMouseDown);
+ document.removeEventListener("scroll", handleScroll, true);
+ };
+ }, [visible, onDismiss]);
+
+ if (!visible || items.length === 0) return null;
+
+ const grouped = groupByCategory(items);
+ let flatIndex = 0;
+
+ const content = (
+ <div
+ ref={listRef}
+ className="fixed z-[9999] max-h-64 w-64 overflow-y-auto rounded-md border border-border bg-slate-elevation1 py-1 shadow-lg"
+ style={{
+ top: anchorPosition.top,
+ left: anchorPosition.left,
+ }}
+ >
+ {CATEGORY_ORDER.map((category) => {
+ const group = grouped.get(category);
+ if (!group || group.length === 0) return null;
+ return (
+ <div key={category}>
+ <div className="px-2 py-1 text-[0.625rem] font-medium uppercase tracking-wide text-muted-foreground">
+ {CATEGORY_LABELS[category]}
+ </div>
+ {group.map((param) => {
+ const currentIndex = flatIndex++;
+ const isSelected = currentIndex === selectedIndex;
+ return (
+ <div
+ key={`${category}-${param.key}`}
+ ref={isSelected ? selectedRef : undefined}
+ className={`cursor-pointer px-2 py-1.5 text-xs ${
+ isSelected
+ ? "bg-slate-elevation2 text-foreground"
+ : "text-muted-foreground hover:bg-slate-elevation2"
+ }`}
+ onMouseDown={(e) => {
+ e.preventDefault(); // Prevent blur on the input
+ onSelect(param.key);
+ }}
+ >
+ <div className="font-mono">{param.key}</div>
+ {param.description && (
+ <div className="text-[0.625rem] text-muted-foreground">
+ {param.description}
+ </div>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ );
+ })}
+ </div>
+ );
+
+ return createPortal(content, document.body);
+}
+
+export { ParameterAutocompleteDropdown };
diff --git a/skyvern-frontend/src/components/ParameterGhostText.tsx b/skyvern-frontend/src/components/ParameterGhostText.tsx
new file mode 100644
index 000000000..a697f5a2e
--- /dev/null
+++ b/skyvern-frontend/src/components/ParameterGhostText.tsx
@@ -0,0 +1,83 @@
+import type { CSSProperties, RefObject } from "react";
+
+type Props = {
+ ghostText: string;
+ textBeforeCursor: string;
+ inputRef: RefObject<HTMLTextAreaElement | HTMLInputElement | null>;
+ variant: "input" | "textarea";
+};
+
+function ParameterGhostText({
+ ghostText,
+ textBeforeCursor,
+ inputRef,
+ variant,
+}: Props) {
+ if (!ghostText || !inputRef.current) return null;
+
+ const el = inputRef.current;
+ const computed = window.getComputedStyle(el);
+
+ const baseStyle: CSSProperties = {
+ position: "absolute",
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ pointerEvents: "none",
+ overflow: "hidden",
+ fontFamily: computed.fontFamily,
+ fontSize: computed.fontSize,
+ fontWeight: computed.fontWeight,
+ lineHeight: computed.lineHeight,
+ letterSpacing: computed.letterSpacing,
+ paddingTop: computed.paddingTop,
+ paddingRight: computed.paddingRight,
+ paddingBottom: computed.paddingBottom,
+ paddingLeft: computed.paddingLeft,
+ borderWidth: computed.borderWidth,
+ borderColor: "transparent",
+ borderStyle: computed.borderStyle,
+ };
+
+ if (variant === "input") {
+ return (
+ <div
+ style={{
+ ...baseStyle,
+ display: "flex",
+ alignItems: "center",
+ }}
+ aria-hidden="true"
+ >
+ <div
+ style={{
+ whiteSpace: "pre",
+ transform: `translateX(-${el.scrollLeft}px)`,
+ }}
+ >
+ <span style={{ visibility: "hidden" }}>{textBeforeCursor}</span>
+ <span className="text-muted-foreground/50">{ghostText}</span>
+ </div>
+ </div>
+ );
+ }
+
+ return (
+ <div style={baseStyle} aria-hidden="true">
+ <div
+ style={{
+ whiteSpace: "pre-wrap",
+ wordWrap: "break-word",
+ overflowWrap: "break-word",
+ transform: `translateY(-${el.scrollTop}px)`,
+ }}
+ >
+ <span style={{ visibility: "hidden" }}>{textBeforeCursor}</span>
+ <span className="text-muted-foreground/50">{ghostText}</span>
+ </div>
+ </div>
+ );
+}
+
+export { ParameterGhostText };
diff --git a/skyvern-frontend/src/components/WorkflowBlockInput.tsx b/skyvern-frontend/src/components/WorkflowBlockInput.tsx
index 3e98037b2..be90c6090 100644
--- a/skyvern-frontend/src/components/WorkflowBlockInput.tsx
+++ b/skyvern-frontend/src/components/WorkflowBlockInput.tsx
@@ -4,6 +4,9 @@ import { cn } from "@/util/utils";
import { Input } from "./ui/input";
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
import { WorkflowBlockParameterSelect } from "@/routes/workflows/editor/nodes/WorkflowBlockParameterSelect";
+import { useParameterAutocomplete } from "@/hooks/useParameterAutocomplete";
+import { ParameterAutocompleteDropdown } from "./ParameterAutocompleteDropdown";
+import { ParameterGhostText } from "./ParameterGhostText";
type Props = Omit<React.ComponentProps<typeof Input>, "onChange"> & {
onChange: (value: string) => void;
@@ -15,6 +18,7 @@ function WorkflowBlockInput(props: Props) {
const { nodeId, onChange, type, value, hideParameterSelect, ...inputProps } =
props;
const [showPassword, setShowPassword] = useState(false);
+ const inputRef = useRef<HTMLInputElement>(null);
// Buffer input value locally so keystrokes update the DOM immediately
// without waiting for the React Flow store roundtrip (which can reset the
@@ -33,10 +37,32 @@ function WorkflowBlockInput(props: Props) {
const isPasswordField = type === "password";
const actualType = isPasswordField && showPassword ? "text" : type;
+ const autocomplete = useParameterAutocomplete({
+ nodeId,
+ value: String(localValue),
+ inputRef,
+ variant: "input",
+ });
+
+ const handleAutocompleteSelect = (key: string) => {
+ const { newValue, cursorPos } = autocomplete.buildSelectedValue(key);
+ isLocalChangeRef.current = true;
+ setLocalValue(newValue);
+ onChange(newValue);
+ autocomplete.dismiss();
+ setTimeout(() => {
+ if (inputRef.current) {
+ inputRef.current.focus();
+ inputRef.current.setSelectionRange(cursorPos, cursorPos);
+ }
+ }, 0);
+ };
+
return (
<div className="relative">
<Input
{...inputProps}
+ ref={inputRef}
value={localValue}
type={actualType}
className={cn(
@@ -48,6 +74,31 @@ function WorkflowBlockInput(props: Props) {
setLocalValue(event.target.value);
onChange(event.target.value);
}}
+ onKeyDown={(e) => {
+ if (autocomplete.isOpen) {
+ const handled = autocomplete.handleKeyDown(e);
+ if (handled && (e.key === "Enter" || e.key === "Tab")) {
+ const param = autocomplete.getSelectedParameter();
+ if (param) {
+ handleAutocompleteSelect(param.key);
+ }
+ }
+ }
+ }}
+ />
+ <ParameterGhostText
+ ghostText={autocomplete.ghostText}
+ textBeforeCursor={autocomplete.textBeforeCursor}
+ inputRef={inputRef}
+ variant="input"
+ />
+ <ParameterAutocompleteDropdown
+ items={autocomplete.filteredItems}
+ selectedIndex={autocomplete.selectedIndex}
+ anchorPosition={autocomplete.anchorPosition}
+ visible={autocomplete.isOpen}
+ onSelect={handleAutocompleteSelect}
+ onDismiss={autocomplete.dismiss}
/>
{(isPasswordField || !hideParameterSelect) && (
<div className="absolute right-0 top-0 flex cursor-pointer items-center justify-center">
diff --git a/skyvern-frontend/src/components/WorkflowBlockInputTextarea.tsx b/skyvern-frontend/src/components/WorkflowBlockInputTextarea.tsx
index a69af17b7..a40d04c36 100644
--- a/skyvern-frontend/src/components/WorkflowBlockInputTextarea.tsx
+++ b/skyvern-frontend/src/components/WorkflowBlockInputTextarea.tsx
@@ -5,6 +5,9 @@ import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
import { WorkflowBlockParameterSelect } from "@/routes/workflows/editor/nodes/WorkflowBlockParameterSelect";
import { useEffect, useRef, useState } from "react";
import { useDebouncedCallback } from "use-debounce";
+import { useParameterAutocomplete } from "@/hooks/useParameterAutocomplete";
+import { ParameterAutocompleteDropdown } from "./ParameterAutocompleteDropdown";
+import { ParameterGhostText } from "./ParameterGhostText";
import { ImprovePrompt } from "./ImprovePrompt";
@@ -77,6 +80,26 @@ function WorkflowBlockInputTextarea(props: Props) {
doOnChange(value);
};
+ const autocomplete = useParameterAutocomplete({
+ nodeId,
+ value: String(internalValue),
+ inputRef: textareaRef,
+ variant: "textarea",
+ });
+
+ const handleAutocompleteSelect = (key: string) => {
+ const { newValue, cursorPos } = autocomplete.buildSelectedValue(key);
+ setInternalValue(newValue);
+ doOnChange(newValue);
+ autocomplete.dismiss();
+ setTimeout(() => {
+ if (textareaRef.current) {
+ textareaRef.current.focus();
+ textareaRef.current.setSelectionRange(cursorPos, cursorPos);
+ }
+ }, 0);
+ };
+
return (
<div className="relative">
<AutoResizingTextarea
@@ -91,9 +114,34 @@ function WorkflowBlockInputTextarea(props: Props) {
}}
onClick={handleTextareaSelect}
onKeyUp={handleTextareaSelect}
+ onKeyDown={(e) => {
+ if (autocomplete.isOpen) {
+ const handled = autocomplete.handleKeyDown(e);
+ if (handled && (e.key === "Enter" || e.key === "Tab")) {
+ const param = autocomplete.getSelectedParameter();
+ if (param) {
+ handleAutocompleteSelect(param.key);
+ }
+ }
+ }
+ }}
onSelect={handleTextareaSelect}
className={cn(`${aiImprove ? "pr-12" : "pr-9"}`, props.className)}
/>
+ <ParameterGhostText
+ ghostText={autocomplete.ghostText}
+ textBeforeCursor={autocomplete.textBeforeCursor}
+ inputRef={textareaRef}
+ variant="textarea"
+ />
+ <ParameterAutocompleteDropdown
+ items={autocomplete.filteredItems}
+ selectedIndex={autocomplete.selectedIndex}
+ anchorPosition={autocomplete.anchorPosition}
+ visible={autocomplete.isOpen}
+ onSelect={handleAutocompleteSelect}
+ onDismiss={autocomplete.dismiss}
+ />
<div className="absolute right-1 top-0 flex size-9 items-center justify-end">
<div className="flex items-center justify-center gap-1">
diff --git a/skyvern-frontend/src/hooks/useAvailableParameters.ts b/skyvern-frontend/src/hooks/useAvailableParameters.ts
new file mode 100644
index 000000000..abbe7d8dc
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useAvailableParameters.ts
@@ -0,0 +1,61 @@
+import { useEdges, useNodes } from "@xyflow/react";
+import { useMemo } from "react";
+import { useWorkflowParametersStore } from "@/store/WorkflowParametersStore";
+import { AppNode } from "@/routes/workflows/editor/nodes";
+import {
+ getAvailableOutputParameterKeys,
+ isNodeInsideForLoop,
+} from "@/routes/workflows/editor/workflowEditorUtils";
+import {
+ GLOBAL_RESERVED_PARAMETERS,
+ LOOP_RESERVED_PARAMETERS,
+} from "@/routes/workflows/editor/constants";
+
+export type ParameterCategory = "parameter" | "output" | "system";
+
+export type AvailableParameter = {
+ key: string;
+ category: ParameterCategory;
+ description?: string;
+};
+
+function useAvailableParameters(nodeId: string): AvailableParameter[] {
+ const { parameters: workflowParameters } = useWorkflowParametersStore();
+ const nodes = useNodes<AppNode>();
+ const edges = useEdges();
+
+ return useMemo(() => {
+ const items: AvailableParameter[] = [];
+
+ for (const param of workflowParameters) {
+ items.push({ key: param.key, category: "parameter" });
+ }
+
+ const outputKeys = getAvailableOutputParameterKeys(nodes, edges, nodeId);
+ for (const key of outputKeys) {
+ items.push({ key, category: "output" });
+ }
+
+ for (const param of GLOBAL_RESERVED_PARAMETERS) {
+ items.push({
+ key: param.key,
+ category: "system",
+ description: param.description,
+ });
+ }
+
+ if (isNodeInsideForLoop(nodes, nodeId)) {
+ for (const param of LOOP_RESERVED_PARAMETERS) {
+ items.push({
+ key: param.key,
+ category: "system",
+ description: param.description,
+ });
+ }
+ }
+
+ return items;
+ }, [workflowParameters, nodes, edges, nodeId]);
+}
+
+export { useAvailableParameters };
diff --git a/skyvern-frontend/src/hooks/useParameterAutocomplete.ts b/skyvern-frontend/src/hooks/useParameterAutocomplete.ts
new file mode 100644
index 000000000..3a40828b3
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useParameterAutocomplete.ts
@@ -0,0 +1,291 @@
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { getTextareaCaretCoordinates } from "@/util/caretPosition";
+import {
+ useAvailableParameters,
+ type AvailableParameter,
+} from "./useAvailableParameters";
+
+type AnchorPosition = {
+ top: number;
+ left: number;
+};
+
+type AutocompleteState = {
+ isOpen: boolean;
+ filterText: string;
+ /** Character index of the `{{` that opened autocomplete */
+ triggerStart: number;
+ anchorPosition: AnchorPosition;
+ selectedIndex: number;
+};
+
+const INITIAL_STATE: AutocompleteState = {
+ isOpen: false,
+ filterText: "",
+ triggerStart: -1,
+ anchorPosition: { top: 0, left: 0 },
+ selectedIndex: 0,
+};
+
+/**
+ * Scan backwards from `cursorPos` to find an unmatched `{{`.
+ * Returns the index of the first `{` or -1 if not found.
+ */
+function findTriggerStart(value: string, cursorPos: number): number {
+ const before = value.substring(0, cursorPos);
+ const lastOpen = before.lastIndexOf("{{");
+ if (lastOpen === -1) return -1;
+
+ // Check there's no closing `}}` between the `{{` and cursor
+ const between = value.substring(lastOpen + 2, cursorPos);
+ if (between.includes("}}")) return -1;
+
+ // Don't trigger if there's a space right after {{
+ if (between.length > 0 && between[0] === " ") return -1;
+
+ // Don't trigger if the cursor is inside an already-closed `{{...}}`
+ // e.g. `{{current_}}` with cursor before `}}` — the param is already closed
+ const after = value.substring(cursorPos);
+ const nextClose = after.indexOf("}}");
+ const nextOpen = after.indexOf("{{");
+ if (nextClose !== -1 && (nextOpen === -1 || nextClose < nextOpen)) {
+ return -1;
+ }
+
+ return lastOpen;
+}
+
+type UseParameterAutocompleteOptions = {
+ nodeId: string;
+ value: string;
+ inputRef: React.RefObject<HTMLTextAreaElement | HTMLInputElement | null>;
+ variant: "textarea" | "input";
+};
+
+function useParameterAutocomplete({
+ nodeId,
+ value,
+ inputRef,
+ variant,
+}: UseParameterAutocompleteOptions) {
+ const allParameters = useAvailableParameters(nodeId);
+ const [state, setState] = useState<AutocompleteState>(INITIAL_STATE);
+
+ // Keep a ref to the latest state for use in event handlers
+ const stateRef = useRef(state);
+ stateRef.current = state;
+
+ const filteredItems = useMemo(() => {
+ if (!state.isOpen) return [];
+ const filter = state.filterText.toLowerCase();
+ if (!filter) return allParameters;
+ const matches = allParameters.filter((p) =>
+ p.key.toLowerCase().includes(filter),
+ );
+ // Prefix matches first so the default selection (index 0) shows ghost text
+ matches.sort((a, b) => {
+ const aPrefix = a.key.toLowerCase().startsWith(filter) ? 0 : 1;
+ const bPrefix = b.key.toLowerCase().startsWith(filter) ? 0 : 1;
+ return aPrefix - bPrefix;
+ });
+ return matches;
+ }, [state.isOpen, state.filterText, allParameters]);
+
+ const dismiss = useCallback(() => {
+ setState(INITIAL_STATE);
+ }, []);
+
+ const computeAnchorPosition = useCallback((): AnchorPosition => {
+ const el = inputRef.current;
+ if (!el) return { top: 0, left: 0 };
+
+ const rect = el.getBoundingClientRect();
+
+ if (variant === "textarea") {
+ const textarea = el as HTMLTextAreaElement;
+ const caretCoords = getTextareaCaretCoordinates(
+ textarea,
+ textarea.selectionStart,
+ );
+ return {
+ top:
+ rect.top +
+ caretCoords.top +
+ parseInt(getComputedStyle(el).lineHeight || "20", 10),
+ left: rect.left + caretCoords.left,
+ };
+ }
+
+ // For single-line inputs, position below the input
+ return {
+ top: rect.bottom + 2,
+ left: rect.left,
+ };
+ }, [inputRef, variant]);
+
+ /**
+ * Called on every value/cursor change to detect or update the `{{` trigger.
+ */
+ const updateAutocomplete = useCallback(() => {
+ const el = inputRef.current;
+ if (!el) {
+ dismiss();
+ return;
+ }
+
+ // Only trigger autocomplete when the element is focused — avoid false
+ // positives from programmatic value changes (e.g. "+" button, AI improve).
+ if (document.activeElement !== el) {
+ if (stateRef.current.isOpen) dismiss();
+ return;
+ }
+
+ const cursorPos = el.selectionStart ?? 0;
+ const triggerStart = findTriggerStart(value, cursorPos);
+
+ if (triggerStart === -1) {
+ if (stateRef.current.isOpen) {
+ dismiss();
+ }
+ return;
+ }
+
+ const filterText = value.substring(triggerStart + 2, cursorPos);
+
+ setState({
+ isOpen: true,
+ filterText,
+ triggerStart,
+ anchorPosition: computeAnchorPosition(),
+ selectedIndex: 0,
+ });
+ }, [value, inputRef, dismiss, computeAnchorPosition]);
+
+ // Re-evaluate autocomplete state whenever the value changes
+ useEffect(() => {
+ // Use a microtask so the DOM has updated cursor position
+ const id = requestAnimationFrame(() => {
+ updateAutocomplete();
+ });
+ return () => cancelAnimationFrame(id);
+ }, [updateAutocomplete]);
+
+ /**
+ * Build the new value after selecting a parameter.
+ * Replaces `{{filterText` with `{{selectedKey}}`.
+ */
+ const buildSelectedValue = useCallback(
+ (parameterKey: string): { newValue: string; cursorPos: number } => {
+ const { triggerStart } = stateRef.current;
+ const el = inputRef.current;
+ const cursorPos = el?.selectionStart ?? value.length;
+ const replacement = `{{${parameterKey}}}`;
+ const before = value.substring(0, triggerStart);
+ const after = value.substring(cursorPos);
+ const newValue = before + replacement + after;
+ return {
+ newValue,
+ cursorPos: triggerStart + replacement.length,
+ };
+ },
+ [value, inputRef],
+ );
+
+ /**
+ * Intercept keyboard events when autocomplete is open.
+ * Returns true if the event was handled (caller should preventDefault).
+ */
+ const handleKeyDown = useCallback(
+ (e: React.KeyboardEvent): boolean => {
+ if (!stateRef.current.isOpen || filteredItems.length === 0) return false;
+
+ switch (e.key) {
+ case "ArrowDown": {
+ e.preventDefault();
+ e.stopPropagation();
+ setState((prev) => ({
+ ...prev,
+ selectedIndex:
+ prev.selectedIndex < filteredItems.length - 1
+ ? prev.selectedIndex + 1
+ : 0,
+ }));
+ return true;
+ }
+ case "ArrowUp": {
+ e.preventDefault();
+ e.stopPropagation();
+ setState((prev) => ({
+ ...prev,
+ selectedIndex:
+ prev.selectedIndex > 0
+ ? prev.selectedIndex - 1
+ : filteredItems.length - 1,
+ }));
+ return true;
+ }
+ case "Enter":
+ case "Tab": {
+ e.preventDefault();
+ e.stopPropagation();
+ return true; // Handled — caller will call selectParameter
+ }
+ case "Escape": {
+ e.preventDefault();
+ e.stopPropagation();
+ dismiss();
+ return true;
+ }
+ default:
+ return false;
+ }
+ },
+ [filteredItems.length, dismiss],
+ );
+
+ /**
+ * Returns the currently highlighted parameter for Enter/Tab selection,
+ * or null if nothing is highlighted.
+ */
+ const getSelectedParameter = useCallback((): AvailableParameter | null => {
+ if (!stateRef.current.isOpen || filteredItems.length === 0) return null;
+ return filteredItems[stateRef.current.selectedIndex] ?? null;
+ }, [filteredItems]);
+
+ // Ghost text: the untyped remainder of the selected parameter key + closing `}}`
+ const ghostText = useMemo(() => {
+ if (!state.isOpen || filteredItems.length === 0) return "";
+ const selected = filteredItems[state.selectedIndex];
+ if (!selected) return "";
+ const filter = state.filterText.toLowerCase();
+ // Only show ghost text when the selected item is a prefix match
+ if (selected.key.toLowerCase().startsWith(filter)) {
+ return selected.key.substring(state.filterText.length) + "}}";
+ }
+ return "";
+ }, [state.isOpen, state.filterText, state.selectedIndex, filteredItems]);
+
+ // Text before cursor — used to position the ghost text overlay
+ const textBeforeCursor = useMemo(() => {
+ if (!state.isOpen) return "";
+ const cursorPos = state.triggerStart + 2 + state.filterText.length;
+ return value.substring(0, cursorPos);
+ }, [state.isOpen, state.triggerStart, state.filterText, value]);
+
+ return {
+ isOpen: state.isOpen,
+ filterText: state.filterText,
+ anchorPosition: state.anchorPosition,
+ selectedIndex: state.selectedIndex,
+ filteredItems,
+ ghostText,
+ textBeforeCursor,
+ dismiss,
+ handleKeyDown,
+ buildSelectedValue,
+ getSelectedParameter,
+ updateAutocomplete,
+ };
+}
+
+export { useParameterAutocomplete };
diff --git a/skyvern-frontend/src/routes/workflows/editor/constants.ts b/skyvern-frontend/src/routes/workflows/editor/constants.ts
index 4793dd213..e10b23d94 100644
--- a/skyvern-frontend/src/routes/workflows/editor/constants.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/constants.ts
@@ -15,6 +15,37 @@ export const SMTP_PASSWORD_AWS_KEY = "SKYVERN_SMTP_PASSWORD_SES";
export const EMAIL_BLOCK_SENDER = "[email protected]";
+// Reserved parameters that are always available
+// See: skyvern/forge/sdk/workflow/models/parameter.py RESERVED_PARAMETER_KEYS
+export const GLOBAL_RESERVED_PARAMETERS = [
+ { key: "current_date", description: "Current UTC date (YYYY-MM-DD format)" },
+ {
+ key: "workflow_run_outputs",
+ description: "JSON of all block outputs collected so far",
+ },
+ {
+ key: "workflow_run_summary",
+ description: "Merged summary of all block outputs",
+ },
+ { key: "workflow_run_id", description: "Unique ID of the current run" },
+ { key: "workflow_id", description: "The workflow's ID" },
+ {
+ key: "workflow_permanent_id",
+ description: "The workflow's permanent ID",
+ },
+ { key: "workflow_title", description: "The workflow's title" },
+] as const;
+
+// Reserved parameters only available inside loop blocks
+export const LOOP_RESERVED_PARAMETERS = [
+ { key: "current_value", description: "The current item being iterated" },
+ { key: "current_item", description: "Alias for current_value" },
+ {
+ key: "current_index",
+ description: "Zero-based index of the current iteration",
+ },
+] as const;
+
export const BITWARDEN_CLIENT_ID_AWS_SECRET_KEY = "SKYVERN_BITWARDEN_CLIENT_ID";
export const BITWARDEN_CLIENT_SECRET_AWS_SECRET_KEY =
"SKYVERN_BITWARDEN_CLIENT_SECRET";
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowBlockParameterSelect.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowBlockParameterSelect.tsx
index 3960c617b..5a40751f9 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowBlockParameterSelect.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowBlockParameterSelect.tsx
@@ -5,43 +5,16 @@ import {
getAvailableOutputParameterKeys,
isNodeInsideForLoop,
} from "../workflowEditorUtils";
+import {
+ GLOBAL_RESERVED_PARAMETERS,
+ LOOP_RESERVED_PARAMETERS,
+} from "../constants";
import { PlusIcon } from "@radix-ui/react-icons";
import { SwitchBar } from "@/components/SwitchBar";
import { useState } from "react";
import { ScrollArea } from "@/components/ui/scroll-area";
import { ScrollAreaViewport } from "@radix-ui/react-scroll-area";
-// Reserved parameters that are always available
-// See: skyvern/forge/sdk/workflow/models/parameter.py RESERVED_PARAMETER_KEYS
-const GLOBAL_RESERVED_PARAMETERS = [
- { key: "current_date", description: "Current UTC date (YYYY-MM-DD format)" },
- {
- key: "workflow_run_outputs",
- description: "JSON of all block outputs collected so far",
- },
- {
- key: "workflow_run_summary",
- description: "Merged summary of all block outputs",
- },
- { key: "workflow_run_id", description: "Unique ID of the current run" },
- { key: "workflow_id", description: "The workflow's ID" },
- {
- key: "workflow_permanent_id",
- description: "The workflow's permanent ID",
- },
- { key: "workflow_title", description: "The workflow's title" },
-];
-
-// Reserved parameters only available inside loop blocks
-const LOOP_RESERVED_PARAMETERS = [
- { key: "current_value", description: "The current item being iterated" },
- { key: "current_item", description: "Alias for current_value" },
- {
- key: "current_index",
- description: "Zero-based index of the current iteration",
- },
-];
-
type Props = {
nodeId: string;
onAdd: (parameterKey: string) => void;
diff --git a/skyvern-frontend/src/util/caretPosition.ts b/skyvern-frontend/src/util/caretPosition.ts
new file mode 100644
index 000000000..ef6e11ea5
--- /dev/null
+++ b/skyvern-frontend/src/util/caretPosition.ts
@@ -0,0 +1,91 @@
+const MIRROR_STYLES = [
+ "direction",
+ "boxSizing",
+ "width",
+ "height",
+ "overflowX",
+ "overflowY",
+ "borderTopWidth",
+ "borderRightWidth",
+ "borderBottomWidth",
+ "borderLeftWidth",
+ "borderStyle",
+ "paddingTop",
+ "paddingRight",
+ "paddingBottom",
+ "paddingLeft",
+ "fontStyle",
+ "fontVariant",
+ "fontWeight",
+ "fontStretch",
+ "fontSize",
+ "fontSizeAdjust",
+ "lineHeight",
+ "fontFamily",
+ "textAlign",
+ "textTransform",
+ "textIndent",
+ "textDecoration",
+ "letterSpacing",
+ "wordSpacing",
+ "tabSize",
+ "MozTabSize",
+ "whiteSpace",
+ "wordWrap",
+ "wordBreak",
+] as const;
+
+type CaretCoordinates = {
+ top: number;
+ left: number;
+};
+
+/**
+ * Compute pixel coordinates of the caret at `position` inside a textarea
+ * using the "mirror div" technique.
+ */
+function getTextareaCaretCoordinates(
+ element: HTMLTextAreaElement,
+ position: number,
+): CaretCoordinates {
+ const mirror = document.createElement("div");
+ mirror.id = "caret-mirror";
+
+ document.body.appendChild(mirror);
+
+ const style = mirror.style;
+ const computed = window.getComputedStyle(element);
+
+ style.position = "absolute";
+ style.visibility = "hidden";
+ style.whiteSpace = "pre-wrap";
+ style.wordWrap = "break-word";
+ style.overflow = "hidden";
+
+ for (const prop of MIRROR_STYLES) {
+ // Use bracket notation — camelCase works with style[prop] but not
+ // setProperty/getPropertyValue (which require kebab-case).
+ (style as unknown as Record<string, string>)[prop] =
+ (computed as unknown as Record<string, string>)[prop] ?? "";
+ }
+
+ // Copy the text up to the caret position
+ mirror.textContent = element.value.substring(0, position);
+
+ // Add a span at the caret position to measure its offset
+ const span = document.createElement("span");
+ span.textContent = element.value.substring(position) || ".";
+ mirror.appendChild(span);
+
+ const coordinates: CaretCoordinates = {
+ top: span.offsetTop - element.scrollTop,
+ left: span.offsetLeft - element.scrollLeft,
+ };
+
+ document.body.removeChild(mirror);
+
+ return coordinates;
+}
+
+export { getTextareaCaretCoordinates };
+export type { CaretCoordinates };