Update Copy to cURL buttons to reference the new Runs API spec (#3765)

Co-authored-by: Shuchang Zheng <wintonzheng0325@gmail.com>
This commit is contained in:
Marc Kelechava
2025-10-30 01:26:45 -07:00
committed by GitHub
parent 5ec885ddd1
commit a87a255b7b
8 changed files with 310 additions and 53 deletions

View File

@@ -42,7 +42,7 @@ import { useBlockScriptsQuery } from "@/routes/workflows/hooks/useBlockScriptsQu
import { constructCacheKeyValueFromParameters } from "@/routes/workflows/editor/utils";
import { useWorkflowQuery } from "@/routes/workflows/hooks/useWorkflowQuery";
import { type ApiCommandOptions } from "@/util/apiCommands";
import { apiBaseUrl } from "@/util/env";
import { runsApiBaseUrl } from "@/util/env";
import { MAX_SCREENSHOT_SCROLLS_DEFAULT } from "./editor/nodes/Taskv2Node/types";
import { getLabelForWorkflowParameterType } from "./editor/workflowEditorUtils";
@@ -167,6 +167,25 @@ function getRunWorkflowRequestBody(
return body;
}
// Transform RunWorkflowRequestBody to match WorkflowRunRequest schema for Runs API v2
function transformToWorkflowRunRequest(
body: RunWorkflowRequestBody,
workflowId: string,
) {
const { data, webhook_callback_url, ...rest } = body;
const transformed: Record<string, unknown> = {
workflow_id: workflowId,
parameters: data,
...rest,
};
if (webhook_callback_url) {
transformed.webhook_url = webhook_callback_url;
}
return transformed;
}
type RunWorkflowFormType = Record<string, unknown> & {
webhookCallbackUrl: string;
proxyLocation: ProxyLocation;
@@ -807,14 +826,22 @@ function RunWorkflowForm({
values,
workflowParameters,
);
const transformedBody = transformToWorkflowRunRequest(
body,
workflowPermanentId,
);
// Build headers - x-max-steps-override is optional and can be added manually if needed
const headers: Record<string, string> = {
"Content-Type": "application/json",
"x-api-key": apiCredential ?? "<your-api-key>",
};
return {
method: "POST",
url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,
body,
headers: {
"Content-Type": "application/json",
"x-api-key": apiCredential ?? "<your-api-key>",
},
url: `${runsApiBaseUrl}/run/workflows`,
body: transformedBody,
headers,
} satisfies ApiCommandOptions;
}}
/>

View File

@@ -21,7 +21,7 @@ import { Skeleton } from "@/components/ui/skeleton";
import { toast } from "@/components/ui/use-toast";
import { useApiCredential } from "@/hooks/useApiCredential";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { apiBaseUrl } from "@/util/env";
import { runsApiBaseUrl } from "@/util/env";
import {
CodeIcon,
FileIcon,
@@ -312,20 +312,34 @@ function WorkflowRun() {
<div className="flex gap-2">
<ApiWebhookActionsMenu
getOptions={() =>
({
getOptions={() => {
// Build headers - x-max-steps-override is optional and can be added manually if needed
const headers: Record<string, string> = {
"Content-Type": "application/json",
"x-api-key": apiCredential ?? "<your-api-key>",
};
const body: Record<string, unknown> = {
workflow_id: workflowPermanentId,
parameters: workflowRun?.parameters,
proxy_location: proxyLocation,
};
if (maxScreenshotScrolls !== null) {
body.max_screenshot_scrolls = maxScreenshotScrolls;
}
if (workflowRun?.webhook_callback_url) {
body.webhook_url = workflowRun.webhook_callback_url;
}
return {
method: "POST",
url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,
body: {
data: workflowRun?.parameters,
proxy_location: "RESIDENTIAL",
},
headers: {
"Content-Type": "application/json",
"x-api-key": apiCredential ?? "<your-api-key>",
},
}) satisfies ApiCommandOptions
}
url: `${runsApiBaseUrl}/run/workflows`,
body,
headers,
} satisfies ApiCommandOptions;
}}
webhookDisabled={workflowRunIsLoading || !workflowRunIsFinalized}
onTestWebhook={() => setReplayOpen(true)}
/>