Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-10192): clarify credential variable in selector UI (#6156)
Trevor Cheung61878c09a1e8
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginBlockCredentialSelector.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginBlockCredentialSelector.tsxindex e09e864c3..f5673d27e 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginBlockCredentialSelector.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginBlockCredentialSelector.tsx@@ -27,6 +27,8 @@ import {parameterIsBitwardenCredential,parameterIsOnePasswordCredential,parameterIsAzureVaultCredential,+ isAutoGeneratedCredentialKey,+ computeWrappedCredentialIds,} from "../../types";type Props = {@@ -131,33 +133,67 @@ function LoginBlockCredentialSelector({return !credentialIdsInVault.has(selectedCredentialId);}, [selectedCredentialId, credentialIdsInVault]);+ // User-authored credential variables (custom-key Skyvern params, or workflow+ // credential_id params) surface their variable name; auto-generated keys keep+ // the plain credential-name render.+ const selectedCredentialVariable = useMemo(() => {+ if (!value || !selectedCredentialId) return undefined;++ const param = workflowParameters.find((p) => p.key === value);+ if (!param) return undefined;++ const isUserAuthored =+ (param.parameterType === "credential" &&+ parameterIsSkyvernCredential(param) &&+ !isAutoGeneratedCredentialKey(param.key)) ||+ (param.parameterType === "workflow" &&+ param.dataType === "credential_id");+ if (!isUserAuthored) return undefined;++ const credentialName = credentials.find(+ (c) => c.credential_id === selectedCredentialId,+ )?.name;+ if (!credentialName || credentialName === param.key) return undefined;+ return { key: param.key, credentialName };+ }, [value, selectedCredentialId, workflowParameters, credentials]);++ const wrappedCredentialIds = useMemo(+ () => computeWrappedCredentialIds(credentialParameters),+ [credentialParameters],+ );+if (isCloud && isLoading) {return <Skeleton className="h-8 w-full" />;}- const credentialOptions = credentials.map((credential) => ({- label: credential.name,- value: credential.credential_id,- type: "credential" as const,- hasBrowserProfile: !!credential.browser_profile_id,- browserProfileUrl: credential.tested_url ?? null,- totpIdentifier:- credential.credential_type === "password" &&- "totp_identifier" in credential.credential- ? (credential.credential.totp_identifier ?? null)- : null,- }));-- // Only show non-Skyvern credential parameters (Bitwarden, 1Password, Azure Vault)- // Skyvern credential parameters should never be shown - the actual credential is displayed directly- const externalVaultParameterOptions = credentialParameters+ const credentialOptions = credentials+ .filter((credential) => !wrappedCredentialIds.has(credential.credential_id))+ .map((credential) => ({+ label: credential.name,+ value: credential.credential_id,+ type: "credential" as const,+ hasBrowserProfile: !!credential.browser_profile_id,+ browserProfileUrl: credential.tested_url ?? null,+ totpIdentifier:+ credential.credential_type === "password" &&+ "totp_identifier" in credential.credential+ ? (credential.credential.totp_identifier ?? null)+ : null,+ }));++ // Auto-generated Skyvern wrappers are hidden (they back a direct credential+ // pick); user-authored Skyvern params and external vault params are listed.+ // Workflow credential_id params are authored in the Parameters panel, not here.+ const credentialParameterOptions = credentialParameters.filter((parameter) => {- // Never show Skyvern credential parameters- if (parameterIsSkyvernCredential(parameter)) {+ if (+ parameterIsSkyvernCredential(parameter) &&+ isAutoGeneratedCredentialKey(parameter.key)+ ) {return false;}- // Show Bitwarden, 1Password, Azure Vault credential parametersreturn (+ parameterIsSkyvernCredential(parameter) ||parameterIsBitwardenCredential(parameter) ||parameterIsOnePasswordCredential(parameter) ||parameterIsAzureVaultCredential(parameter)@@ -169,14 +205,27 @@ function LoginBlockCredentialSelector({type: "parameter" as const,}));- const options = [...credentialOptions, ...externalVaultParameterOptions];+ const options = [...credentialOptions, ...credentialParameterOptions];++ // When the active value is a param-key option (any user-authored param, incl.+ // wrapped Skyvern credentials), the controlled value must be the key — not the+ // resolved credentialId, whose row is filtered out of credentialOptions and so+ // has no matching SelectItem. Keep this independent of selectedCredentialVariable,+ // which is suppressed when key === credential name but still needs a valid value.+ const valueIsParameterOption = options.some(+ (option) => option.type === "parameter" && option.value === value,+ );return (<><Selectkey={value ?? "no-credential"}value={- isCredentialMissing ? undefined : (selectedCredentialId ?? value)+ isCredentialMissing+ ? undefined+ : valueIsParameterOption+ ? value+ : (selectedCredentialId ?? value)}onValueChange={(newValue) => {if (newValue === "new") {@@ -191,10 +240,12 @@ function LoginBlockCredentialSelector({.filter((node) => node.id !== nodeId).filter(isLoginNode);- // Check if current value references a Skyvern credential+ // Only auto-gen wrappers are garbage-collected on switch; user-authored+ // params are intentional named variables and must survive.const currentParameter = workflowParameters.find((parameter) => {if (parameter.parameterType !== "credential") return false;if (!parameterIsSkyvernCredential(parameter)) return false;+ if (!isAutoGeneratedCredentialKey(parameter.key)) return false;return parameter.key === value;});@@ -284,8 +335,8 @@ function LoginBlockCredentialSelector({<SelectTriggerclassName={isCredentialMissing- ? "w-full border-red-500 text-red-500"- : "w-full"+ ? "h-auto min-h-10 w-full border-red-500 text-red-500"+ : "h-auto min-h-10 w-full"}>{isCredentialMissing ? (@@ -293,6 +344,14 @@ function LoginBlockCredentialSelector({<ExclamationTriangleIcon className="size-4" /><span>Credential not found</span></div>+ ) : selectedCredentialVariable ? (+ <div className="flex min-w-0 flex-col items-start text-left">+ <span className="truncate">{selectedCredentialVariable.key}</span>+ <span className="truncate text-xs text-muted-foreground">+ defaults to credential:{" "}+ {selectedCredentialVariable.credentialName}+ </span>+ </div>) : (<SelectValue placeholder="Select a credential" />)}diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterEditPanel.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterEditPanel.tsxindex 079858f35..1fede4a7b 100644--- a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterEditPanel.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterEditPanel.tsx@@ -28,6 +28,7 @@ import {parameterIsOnePasswordCredential,ParametersState,parameterIsAzureVaultCredential,+ AUTO_GENERATED_CREDENTIAL_KEY_PATTERN,} from "../types";import { getDefaultValueForParameterType } from "../workflowEditorUtils";import { validateBitwardenLoginCredential } from "./util";@@ -812,6 +813,22 @@ function WorkflowParameterEditPanel({});return;}+ // `credentials`/`credentials_N` keys are reserved for the Login+ // block's auto-generated credential wrappers — letting a user author+ // one would make the auto-gen-vs-user-authored provenance heuristic+ // ambiguous. Block only when the key is newly set to a reserved name.+ if (+ (type === "credential" || isCredentialSelected) &&+ key !== initialValues?.key &&+ AUTO_GENERATED_CREDENTIAL_KEY_PATTERN.test(key)+ ) {+ toast({+ variant: "destructive",+ title: "Failed to save parameter",+ description: `"${key}" is reserved for auto-generated credential variables. Please choose a different key.`,+ });+ return;+ }// Handle workflow parameters (non-credential)if (type === "workflow" && !isCredentialSelected) {diff --git a/skyvern-frontend/src/routes/workflows/editor/types.test.ts b/skyvern-frontend/src/routes/workflows/editor/types.test.tsnew file mode 100644index 000000000..047116630--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/editor/types.test.ts@@ -0,0 +1,68 @@+import { describe, expect, it } from "vitest";+import {+ CredentialParameterState,+ computeWrappedCredentialIds,+ isAutoGeneratedCredentialKey,+} from "./types";++describe("isAutoGeneratedCredentialKey", () => {+ it("matches the auto-generated key scheme", () => {+ expect(isAutoGeneratedCredentialKey("credentials")).toBe(true);+ expect(isAutoGeneratedCredentialKey("credentials_1")).toBe(true);+ expect(isAutoGeneratedCredentialKey("credentials_42")).toBe(true);+ });++ it("does not match user-authored keys", () => {+ expect(isAutoGeneratedCredentialKey("my_login")).toBe(false);+ expect(isAutoGeneratedCredentialKey("prod_credentials")).toBe(false);+ expect(isAutoGeneratedCredentialKey("credentials_")).toBe(false);+ expect(isAutoGeneratedCredentialKey("credentialsX")).toBe(false);+ });+});++describe("computeWrappedCredentialIds", () => {+ const skyvern = (+ key: string,+ credentialId: string,+ ): CredentialParameterState => ({+ key,+ parameterType: "credential",+ credentialId,+ });++ it("wraps only user-authored Skyvern credential params", () => {+ const params = [+ skyvern("credentials", "cred-auto"),+ skyvern("credentials_1", "cred-auto-2"),+ skyvern("my_login", "cred-user"),+ ];+ const wrapped = computeWrappedCredentialIds(params);+ expect(wrapped.has("cred-user")).toBe(true);+ expect(wrapped.has("cred-auto")).toBe(false);+ expect(wrapped.has("cred-auto-2")).toBe(false);+ });++ it("ignores non-Skyvern credential params", () => {+ const params: Array<CredentialParameterState> = [+ {+ key: "bw_login",+ parameterType: "credential",+ collectionId: "c",+ itemId: "i",+ urlParameterKey: null,+ },+ {+ key: "op_login",+ parameterType: "onepassword",+ vaultId: "v",+ itemId: "i",+ },+ ];+ expect(computeWrappedCredentialIds(params).size).toBe(0);+ });++ it("wraps a user param even when its key equals the credential name", () => {+ const wrapped = computeWrappedCredentialIds([skyvern("Github", "cred-gh")]);+ expect(wrapped.has("cred-gh")).toBe(true);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/types.ts b/skyvern-frontend/src/routes/workflows/editor/types.tsindex 96a2d17ab..018fe2b8e 100644--- a/skyvern-frontend/src/routes/workflows/editor/types.ts+++ b/skyvern-frontend/src/routes/workflows/editor/types.ts@@ -1,5 +1,11 @@import { WorkflowParameterValueType } from "../types/workflowTypes";+// Keys the Login block auto-generates when a user picks a credential directly+// (`credentials`, `credentials_1`, …). Used as the provenance signal that tells+// auto-generated wrappers apart from user-authored credential variables. The+// Parameters panel rejects new keys matching this pattern so the signal stays sound.+export const AUTO_GENERATED_CREDENTIAL_KEY_PATTERN = /^credentials(_\d+)?$/;+export type BitwardenLoginCredential = {key: string;description?: string | null;@@ -68,6 +74,24 @@ export type CredentialParameterState =| OnePasswordCredential| AzureVaultCredential;+export function isAutoGeneratedCredentialKey(key: string): boolean {+ return AUTO_GENERATED_CREDENTIAL_KEY_PATTERN.test(key);+}++// credentialIds wrapped by a user-authored (non-auto-gen) Skyvern credential param.+// Their raw credential row is redundant with the variable's own entry, so the+// Login selector drops it from the direct-credential options.+export function computeWrappedCredentialIds(+ credentialParameters: Array<CredentialParameterState>,+): Set<string> {+ return new Set(+ credentialParameters+ .filter(parameterIsSkyvernCredential)+ .filter((p) => !isAutoGeneratedCredentialKey(p.key))+ .map((p) => p.credentialId),+ );+}+export type ParametersState = Array<| {key: string;