Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-11550: Hide empty extra HTTP headers (#6966)
Aaron Perez5808d8dcf324
diff --git a/skyvern-frontend/src/routes/tasks/detail/TaskParameters.tsx b/skyvern-frontend/src/routes/tasks/detail/TaskParameters.tsxindex 45e0dad2f..3396a1ade 100644--- a/skyvern-frontend/src/routes/tasks/detail/TaskParameters.tsx+++ b/skyvern-frontend/src/routes/tasks/detail/TaskParameters.tsx@@ -10,6 +10,7 @@ import { CodeEditor } from "@/routes/workflows/components/CodeEditor";import { MAX_SCREENSHOT_SCROLLS_DEFAULT } from "@/routes/workflows/editor/nodes/Taskv2Node/types";import { useQuery } from "@tanstack/react-query";import { useFirstParam } from "@/hooks/useFirstParam";+import { hasExtraHttpHeaders } from "@/util/extraHttpHeaders";function TaskParameters() {const taskId = useFirstParam("taskId", "runId");@@ -38,6 +39,10 @@ function TaskParameters() {return <div>Error loading inputs</div>;}+ const showExtraHttpHeaders = hasExtraHttpHeaders(+ task.request.extra_http_headers,+ );+return (<section className="space-y-8 rounded-lg bg-slate-elevation3 px-6 py-5"><div className="flex gap-16">@@ -117,25 +122,23 @@ function TaskParameters() {maxHeight="500px"/></div>- <div className="flex gap-16">- <div className="w-72">- <h1 className="text-lg">Extra HTTP Headers</h1>- <h2 className="text-base text-slate-400">- Specify some self-defined HTTP requests headers- </h2>+ {showExtraHttpHeaders ? (+ <div className="flex gap-16">+ <div className="w-72">+ <h1 className="text-lg">Extra HTTP Headers</h1>+ <h2 className="text-base text-slate-400">+ Specify some self-defined HTTP requests headers+ </h2>+ </div>+ <div className="w-full">+ <KeyValueInput+ value={JSON.stringify(task.request.extra_http_headers)}+ readOnly={true}+ onChange={() => {}}+ />+ </div></div>- <div className="w-full">- <KeyValueInput- value={- task.request.extra_http_headers- ? JSON.stringify(task.request.extra_http_headers)- : null- }- readOnly={true}- onChange={() => {}}- />- </div>- </div>+ ) : null}<div className="flex gap-16"><div className="w-72"><h1 className="text-lg">Webhook Callback URL</h1>diff --git a/skyvern-frontend/src/routes/workflows/debugger/DebuggerPostRunParameters.tsx b/skyvern-frontend/src/routes/workflows/debugger/DebuggerPostRunParameters.tsxindex 354eb5b51..c5a91195a 100644--- a/skyvern-frontend/src/routes/workflows/debugger/DebuggerPostRunParameters.tsx+++ b/skyvern-frontend/src/routes/workflows/debugger/DebuggerPostRunParameters.tsx@@ -23,6 +23,7 @@ import { ProxyLocation } from "@/api/types";import { KeyValueInput } from "@/components/KeyValueInput";import { HelpTooltip } from "@/components/HelpTooltip";import { Switch } from "@/components/ui/switch";+import { hasExtraHttpHeaders } from "@/util/extraHttpHeaders";function DebuggerPostRunParameters() {const { workflowPermanentId } = useParams();@@ -89,6 +90,7 @@ function DebuggerPostRunParameters() {const extraHttpHeaders = isTaskV2? workflowRun.task_v2?.extra_http_headers: workflowRun.extra_http_headers;+ const showExtraHttpHeaders = hasExtraHttpHeaders(extraHttpHeaders);return (<div className="space-y-5">@@ -317,21 +319,21 @@ function DebuggerPostRunParameters() {}}/></div>- <div className="flex flex-col gap-2">- <div className="flex w-full items-center justify-start gap-2">- <h1 className="text-sm">Extra HTTP Headers</h1>- <HelpTooltip content="The extra HTTP headers for the workflow." />- </div>- <div className="w-full">- <KeyValueInput- value={- extraHttpHeaders ? JSON.stringify(extraHttpHeaders) : null- }- readOnly={true}- onChange={() => {}}- />+ {showExtraHttpHeaders ? (+ <div className="flex flex-col gap-2">+ <div className="flex w-full items-center justify-start gap-2">+ <h1 className="text-sm">Extra HTTP Headers</h1>+ <HelpTooltip content="The extra HTTP headers for the workflow." />+ </div>+ <div className="w-full">+ <KeyValueInput+ value={JSON.stringify(extraHttpHeaders)}+ readOnly={true}+ onChange={() => {}}+ />+ </div></div>- </div>+ ) : null}{workflowRun.browser_session_id ? (<div className="flex flex-col gap-2"><div className="flex w-full items-center justify-start gap-2">diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsxnew file mode 100644index 000000000..30bf8a5de--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsx@@ -0,0 +1,93 @@+// @vitest-environment jsdom++vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({+ useWorkflowRunWithWorkflowQuery: () => ({+ data: mocks.workflowRun,+ isLoading: false,+ }),+}));++vi.mock("../hooks/useWorkflowRunTimelineQuery", () => ({+ useWorkflowRunTimelineQuery: () => ({+ data: [],+ isLoading: false,+ }),+}));++vi.mock("./useActiveWorkflowRunItem", () => ({+ useActiveWorkflowRunItem: () => [null, vi.fn()],+}));++vi.mock("@/components/KeyValueInput", () => ({+ KeyValueInput: ({ value }: { value: string | null }) => (+ <div data-testid="key-value-input">{value}</div>+ ),+}));++vi.mock("@/components/ProxySelector", () => ({+ ProxySelector: () => <div data-testid="proxy-selector" />,+}));++import { cleanup, render, screen } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import { ProxyLocation } from "@/api/types";++import { WorkflowPostRunParameters } from "./WorkflowPostRunParameters";++const mocks = vi.hoisted(() => ({+ workflowRun: null as unknown,+}));++function buildWorkflowRun(extraHttpHeaders: Record<string, string> | null) {+ return {+ workflow_run_id: "wr_1",+ parameters: {},+ workflow: {+ workflow_definition: {+ blocks: [],+ parameters: [],+ },+ run_with: null,+ },+ task_v2: null,+ webhook_callback_url: null,+ proxy_location: ProxyLocation.Residential,+ extra_http_headers: extraHttpHeaders,+ browser_session_id: null,+ run_with: null,+ max_screenshot_scrolls: null,+ };+}++beforeEach(() => {+ mocks.workflowRun = buildWorkflowRun(null);+});++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++describe("WorkflowPostRunParameters extra HTTP headers", () => {+ it("hides default empty extra HTTP headers", () => {+ mocks.workflowRun = buildWorkflowRun({});++ render(<WorkflowPostRunParameters />);++ expect(screen.getByText("Other Agent Inputs")).toBeDefined();+ expect(screen.queryByText("Extra HTTP Headers")).toBeNull();+ expect(screen.queryByTestId("key-value-input")).toBeNull();+ });++ it("shows non-empty extra HTTP headers", () => {+ mocks.workflowRun = buildWorkflowRun({ "X-Trace-Id": "abc123" });++ render(<WorkflowPostRunParameters />);++ expect(screen.getByText("Extra HTTP Headers")).toBeDefined();+ expect(screen.getByTestId("key-value-input").textContent).toBe(+ '{"X-Trace-Id":"abc123"}',+ );+ });+});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsxindex d85b2705b..3c248f34c 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx@@ -26,6 +26,7 @@ import { HumanInteractionBlockParameters } from "./blockInfo/HumanInteractionBloimport { ConditionalBlockParameters } from "./blockInfo/ConditionalBlockParameters";import { Taskv2BlockParameters } from "./blockInfo/Taskv2BlockParameters";import { WhileLoopPostRunFields } from "../components/WhileLoopPostRunFields";+import { hasExtraHttpHeaders } from "@/util/extraHttpHeaders";function WorkflowPostRunParameters() {const { data: workflowRunTimeline, isLoading: workflowRunTimelineIsLoading } =@@ -75,6 +76,7 @@ function WorkflowPostRunParameters() {const extraHttpHeaders = isTaskV2? (workflowRun?.task_v2?.extra_http_headers ?? null): (workflowRun?.extra_http_headers ?? null);+ const showExtraHttpHeaders = hasExtraHttpHeaders(extraHttpHeaders);if (workflowRunIsLoading || workflowRunTimelineIsLoading) {return <div>Loading workflow inputs...</div>;@@ -402,20 +404,20 @@ function WorkflowPostRunParameters() {}}/></div>- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Extra HTTP Headers</h1>- </div>- <div className="w-full">- <KeyValueInput- value={- extraHttpHeaders ? JSON.stringify(extraHttpHeaders) : null- }- readOnly={true}- onChange={() => {}}- />+ {showExtraHttpHeaders ? (+ <div className="flex gap-16">+ <div className="w-80">+ <h1 className="text-lg">Extra HTTP Headers</h1>+ </div>+ <div className="w-full">+ <KeyValueInput+ value={JSON.stringify(extraHttpHeaders)}+ readOnly={true}+ onChange={() => {}}+ />+ </div></div>- </div>+ ) : null}{workflowRun.browser_session_id ? (<div className="flex gap-16"><div className="w-80">diff --git a/skyvern-frontend/src/util/extraHttpHeaders.test.ts b/skyvern-frontend/src/util/extraHttpHeaders.test.tsnew file mode 100644index 000000000..c07e7549c--- /dev/null+++ b/skyvern-frontend/src/util/extraHttpHeaders.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";++import { hasExtraHttpHeaders } from "./extraHttpHeaders";++describe("hasExtraHttpHeaders", () => {+ it("returns false for unset or empty header objects", () => {+ expect(hasExtraHttpHeaders(null)).toBe(false);+ expect(hasExtraHttpHeaders(undefined)).toBe(false);+ expect(hasExtraHttpHeaders({})).toBe(false);+ });++ it("returns true when at least one header is present", () => {+ expect(hasExtraHttpHeaders({ "X-Trace-Id": "abc123" })).toBe(true);+ });++ it("does not treat arrays as header objects", () => {+ expect(+ hasExtraHttpHeaders(["X-Trace-Id"] as unknown as Record<string, unknown>),+ ).toBe(false);+ });+});diff --git a/skyvern-frontend/src/util/extraHttpHeaders.ts b/skyvern-frontend/src/util/extraHttpHeaders.tsnew file mode 100644index 000000000..2bc80c04e--- /dev/null+++ b/skyvern-frontend/src/util/extraHttpHeaders.ts@@ -0,0 +1,13 @@+function hasExtraHttpHeaders(+ headers: Record<string, unknown> | null | undefined,+): headers is Record<string, unknown> {+ return (+ headers !== null &&+ headers !== undefined &&+ typeof headers === "object" &&+ !Array.isArray(headers) &&+ Object.keys(headers).length > 0+ );+}++export { hasExtraHttpHeaders };