Skip to content

Automate browser based workflows with AI

feat(SKY-9316): pre-fill debugger Run dialog with last-used values (#5724)

Shuchang Zhengbbea8ed67ed3
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx
index 2fbaf7aa8..ff5ea3b93 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx
@@ -32,6 +32,7 @@ import {
type Parameter,
} from "@/routes/workflows/types/workflowTypes";
import { getInitialValues } from "@/routes/workflows/utils";
+import { useDebuggerLastRunValuesStore } from "@/store/DebuggerLastRunValuesStore";
import { useBlockOutputStore } from "@/store/BlockOutputStore";
import { useDebugStore } from "@/store/useDebugStore";
import { useRecordingStore } from "@/store/useRecordingStore";
@@ -565,7 +566,16 @@ function NodeHeader({
// If there are any workflow parameters, always prompt the user
// The backend requires all params to be specified for each run
if (workflowParameters.length > 0) {
- const currentValues = getInitialValues(location, workflowParameters);
+ const lastRunValues = workflowPermanentId
+ ? useDebuggerLastRunValuesStore
+ .getState()
+ .getLastRunValues(workflowPermanentId)
+ : null;
+ const currentValues = getInitialValues(
+ location,
+ workflowParameters,
+ lastRunValues,
+ );
setCurrentParamValues(currentValues);
setParametersToPrompt(workflowParameters);
setShowParamsDialog(true);
@@ -744,6 +754,11 @@ function NodeHeader({
},
{
onSuccess: () => {
+ if (workflowPermanentId) {
+ useDebuggerLastRunValuesStore
+ .getState()
+ .setLastRunValues(workflowPermanentId, values);
+ }
// Close dialog on success - navigation also happens in mutation's onSuccess
setShowParamsDialog(false);
},
diff --git a/skyvern-frontend/src/routes/workflows/utils.ts b/skyvern-frontend/src/routes/workflows/utils.ts
index 616ac1c7e..2cc8e8ffb 100644
--- a/skyvern-frontend/src/routes/workflows/utils.ts
+++ b/skyvern-frontend/src/routes/workflows/utils.ts
@@ -4,43 +4,73 @@ import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";
type Location = ReturnType<typeof useLocation>;
+const getDefaultFormValueForParameter = (
+ parameter: WorkflowParameter,
+): unknown => {
+ const hasDefaultValue =
+ parameter.default_value !== null && parameter.default_value !== undefined;
+ if (!hasDefaultValue) {
+ return undefined;
+ }
+ if (parameter.workflow_parameter_type === "json") {
+ if (typeof parameter.default_value === "string") {
+ return parameter.default_value;
+ }
+ return JSON.stringify(parameter.default_value, null, 2);
+ }
+ if (parameter.workflow_parameter_type === "boolean") {
+ return (
+ parameter.default_value === "true" || parameter.default_value === true
+ );
+ }
+ return parameter.default_value;
+};
+
+const getDefaultsFromWorkflowParameters = (
+ workflowParameters: WorkflowParameter[],
+): Record<string, unknown> => {
+ return workflowParameters.reduce(
+ (acc, parameter) => {
+ const defaultValue = getDefaultFormValueForParameter(parameter);
+ acc[parameter.key] =
+ defaultValue !== undefined
+ ? defaultValue
+ : parameter.workflow_parameter_type === "string"
+ ? ""
+ : null;
+ return acc;
+ },
+ {} as Record<string, unknown>,
+ );
+};
+
export const getInitialValues = (
location: Location,
workflowParameters: WorkflowParameter[],
-) => {
- const iv = location.state?.data
- ? location.state.data
- : workflowParameters?.reduce(
- (acc, curr) => {
- const hasDefaultValue =
- curr.default_value !== null && curr.default_value !== undefined;
- if (hasDefaultValue) {
- // Handle JSON parameters
- if (curr.workflow_parameter_type === "json") {
- if (typeof curr.default_value === "string") {
- acc[curr.key] = curr.default_value;
- } else {
- acc[curr.key] = JSON.stringify(curr.default_value, null, 2);
- }
- return acc;
- }
- if (curr.workflow_parameter_type === "boolean") {
- // Backend stores as strings, convert to boolean for frontend
- acc[curr.key] =
- curr.default_value === "true" || curr.default_value === true;
- return acc;
- }
- acc[curr.key] = curr.default_value;
- return acc;
- }
- // For string parameters, keep empty string instead of null to match run form behavior
- acc[curr.key] = curr.workflow_parameter_type === "string" ? "" : null;
- return acc;
- },
- {} as Record<string, unknown>,
- );
-
- return iv as Record<string, unknown>;
+ lastRunValues?: Record<string, unknown> | null,
+): Record<string, unknown> => {
+ if (location.state?.data) {
+ return location.state.data as Record<string, unknown>;
+ }
+
+ const defaults = getDefaultsFromWorkflowParameters(workflowParameters);
+
+ if (!lastRunValues) {
+ return defaults;
+ }
+
+ return workflowParameters.reduce<Record<string, unknown>>(
+ (acc, parameter) => {
+ acc[parameter.key] = Object.prototype.hasOwnProperty.call(
+ lastRunValues,
+ parameter.key,
+ )
+ ? lastRunValues[parameter.key]
+ : defaults[parameter.key];
+ return acc;
+ },
+ {},
+ );
};
export interface Duration {
diff --git a/skyvern-frontend/src/store/DebuggerLastRunValuesStore.ts b/skyvern-frontend/src/store/DebuggerLastRunValuesStore.ts
new file mode 100644
index 000000000..1bf7e46df
--- /dev/null
+++ b/skyvern-frontend/src/store/DebuggerLastRunValuesStore.ts
@@ -0,0 +1,27 @@
+import { create } from "zustand";
+
+interface DebuggerLastRunValuesStore {
+ valuesByWorkflowId: Record<string, Record<string, unknown>>;
+ getLastRunValues: (
+ workflowPermanentId: string,
+ ) => Record<string, unknown> | null;
+ setLastRunValues: (
+ workflowPermanentId: string,
+ values: Record<string, unknown>,
+ ) => void;
+}
+
+export const useDebuggerLastRunValuesStore = create<DebuggerLastRunValuesStore>(
+ (set, get) => ({
+ valuesByWorkflowId: {},
+ getLastRunValues: (workflowPermanentId) =>
+ get().valuesByWorkflowId[workflowPermanentId] ?? null,
+ setLastRunValues: (workflowPermanentId, values) =>
+ set((state) => ({
+ valuesByWorkflowId: {
+ ...state.valuesByWorkflowId,
+ [workflowPermanentId]: values,
+ },
+ })),
+ }),
+);